Skip to content

Commit fdbe637

Browse files
committed
build: add postinstall patching system for node_modules fixes
Introduces a mechanism to apply patches to node_modules after npm install: - Adds `tools/scripts/apply_patches` script to apply all patches in `etc/patches/` - Adds `postinstall` script to package.json to auto-apply patches on install - Add patch for `unified-message-control` to fix bug where trailing spaces in lint disable comments disabled all lint rules instead of just the specified rule --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: passed - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 94be096 commit fdbe637

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/index.js b/index.js
2+
--- a/index.js
3+
+++ b/index.js
4+
@@ -75,7 +75,7 @@ function messageControl(options) {
5+
if (!mark || mark.name !== options.name) {
6+
return
7+
}
8+
9+
- ruleIds = mark.attributes.split(/\s/g)
10+
+ ruleIds = mark.attributes.split(/\s/g).filter(Boolean)
11+
verb = ruleIds.shift()
12+
next = parent.children[position + 1]
13+
pos = mark.node.position && mark.node.position.start

lib/node_modules/@stdlib/_tools/lint/filenames/lib/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
".mjs",
2929
".mk",
3030
".ndjson",
31+
".patch",
3132
".pem",
3233
".png",
3334
".py",

lib/node_modules/@stdlib/_tools/lint/filenames/lib/lint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ var SPECIAL = require( './special.json' );
3030

3131
// VARIABLES //
3232

33-
// Only allow alphanumeric characters, `.`, `_`, or `-`:
34-
var BANNED_CHARS = /[^a-zA-Z0-9._-]/; // If this is changed, be sure to update the associated error message
33+
// Only allow alphanumeric characters, `.`, `_`, `-`, or `+`:
34+
var BANNED_CHARS = /[^a-zA-Z0-9._+-]/; // If this is changed, be sure to update the associated error message
3535

3636

3737
// MAIN //
@@ -99,7 +99,7 @@ function lint( arr ) {
9999
if ( BANNED_CHARS.test( fname ) ) {
100100
out.push({
101101
'name': arr[ i ],
102-
'error': 'filename must only contain the following characters: [a-zA-Z0-9._-].'
102+
'error': 'filename must only contain the following characters: [a-zA-Z0-9._+-].'
103103
});
104104
continue;
105105
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"benchmark": "make benchmark",
4343
"clean": "make clean",
4444
"check-deps": "make check-deps",
45-
"check-licenses": "make check-licenses"
45+
"check-licenses": "make check-licenses",
46+
"postinstall": "tools/scripts/apply_patches"
4647
},
4748
"homepage": "https://github.com/stdlib-js/stdlib",
4849
"repository": {

tools/scripts/apply_patches

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2025 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
# Apply patches to node_modules after npm install.
20+
#
21+
# Patches follow the naming convention: <package-name>+<version>.patch
22+
# where <package-name> uses the npm package name with / replaced by +
23+
# (e.g., unified-message-control+1.0.4.patch)
24+
25+
# Get the root directory:
26+
root_dir="$(git rev-parse --show-toplevel)"
27+
28+
# Patches directory:
29+
patches_dir="${root_dir}/etc/patches"
30+
31+
# Apply each patch:
32+
for patch in "${patches_dir}"/*.patch; do
33+
if [[ -f "${patch}" ]]; then
34+
# Extract package name from filename (everything before the +version.patch)...
35+
filename=$(basename "${patch}")
36+
package_name="${filename%%+*}"
37+
38+
# Apply the patch (silently skip if already applied):
39+
git apply --directory="node_modules/${package_name}" "${patch}" 2>/dev/null || true
40+
fi
41+
done

0 commit comments

Comments
 (0)