Skip to content

Commit 0c8ac9e

Browse files
committed
Fixes vulnerabilities in package-lock.json files, and introduces git commit pre-hooks to sanitize package-lock files.
1 parent b12129c commit 0c8ac9e

File tree

5 files changed

+3549
-989
lines changed

5 files changed

+3549
-989
lines changed

.githooks/pre-commit

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
# Copyright 2025 The MathWorks, Inc.
3+
# Pre-commit hook to run all scripts in the scripts folder
4+
# Called by "git commit" with no arguments.
5+
6+
# Path to the scripts directory
7+
# Get the directory where this script is located
8+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9+
SCRIPTS_DIR="$SCRIPT_DIR/scripts"
10+
11+
# Check if the scripts directory exists
12+
if [ ! -d "$SCRIPTS_DIR" ]; then
13+
echo "Error: Scripts directory not found at $SCRIPTS_DIR"
14+
exit 1
15+
fi
16+
17+
echo "Running pre-commit scripts from $SCRIPTS_DIR"
18+
19+
# Find all executable scripts in the scripts directory and sort them alphabetically
20+
for script in $(find "$SCRIPTS_DIR" -type f -executable | sort); do
21+
script_name=$(basename "$script")
22+
echo "Running $script_name..."
23+
24+
# Execute the script
25+
sh "$script"
26+
27+
# Check the exit code
28+
if [ $? -ne 0 ]; then
29+
echo "Error: $script_name failed. Commit aborted."
30+
exit 1
31+
fi
32+
33+
echo "$script_name completed successfully."
34+
done
35+
36+
echo "All pre-commit scripts completed successfully."
37+
exit 0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Copyright 2025 The MathWorks, Inc.
3+
# Pre-commit hook to replace MathWorks NPM registry URLs with public NPM registry
4+
5+
# Find all package.json, .npmrc, and other relevant files
6+
echo "Executing pre-commit hook: sanitize-npm-registry"
7+
FILES=$( git diff --cached --name-only --diff-filter=ACM | grep -E '(.*.json)')
8+
9+
if [ -z "$FILES" ]; then
10+
exit 0
11+
fi
12+
13+
# Replace the MathWorks NPM registry URL with the public NPM registry
14+
for FILE in $FILES; do
15+
# Skip if file doesn't exist (it may have been deleted)
16+
[ -f "$FILE" ] || continue
17+
18+
echo "Sanitizing NPM registry URL in $FILE"
19+
20+
# Replace the URL in the file
21+
sed -i.bak 's|https://.*/artifactory/api/npm/npm-repos/|https://registry.npmjs.org/|g' "$FILE"
22+
23+
# Remove backup file
24+
rm -f "${FILE}.bak"
25+
26+
# Stage the modified file
27+
git add "$FILE"
28+
29+
echo "Sanitization complete for $FILE"
30+
done
31+
32+
exit 0

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
*.egg-info
22
.eggs
33
__pycache__
4+
__uvcache__
5+
.ipynb_checkpoints/
6+
*.ipynb
47
build
58
dist
69
.venv

src/jupyter_matlab_labextension/src/lezer-matlab/package-lock.json

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)