Skip to content

Commit 492ae5e

Browse files
liadyclaude
andauthored
Improve codebase quality: fix bugs, modernize code, add CI (#131)
* Improve codebase quality: fix bugs, modernize code, add CI Bug fixes: - Fix error-handling bug in index.js where forEach loop called utils.error() (which throws) on every iteration with a shadowed variable - Fix loose equality (==) to strict (===) in containsPattern and test - Remove unnecessary regex 'g' flag on regexes used with .test(), eliminating brittle lastIndex state management Modernization: - Use Array.includes() instead of indexOf() !== -1 - Use Array.flat() instead of reduce(concat) - Use arrow functions in utility callbacks Tooling: - Add ESLint 'lint' script to package.json - Change 'test' script from watch mode to lint+unit (CI-friendly) - Add eqeqeq ESLint rule to prevent future loose equality - Add GitHub Actions CI workflow (Node 14/16/18/20 matrix) - Update mock-fs from v4 to v5 for Node.js 22 compatibility (fixes 8 pre-existing test failures) https://claude.ai/code/session_017GbwKxDk7oJN3tXXKSbUDg * fix(ci): drop Node 14 and handle OpenSSL 3.0 in Node 18+ - Remove Node 14 from CI matrix (EOL, npm 6 can't parse lockfile v3) - Set --openssl-legacy-provider for Node 18+ to fix webpack 4's use of the removed md4 hash algorithm (ERR_OSSL_EVP_UNSUPPORTED) https://claude.ai/code/session_017GbwKxDk7oJN3tXXKSbUDg --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 39c8086 commit 492ae5e

7 files changed

Lines changed: 5808 additions & 4755 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ module.exports = {
1111
},
1212
rules: {
1313
'no-prototype-builtins': 0,
14+
eqeqeq: ['error', 'always'],
1415
},
1516
};

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [16, 18, 20]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- run: npm install
21+
- run: npm run lint
22+
- run: npm run unit
23+
env:
24+
NODE_OPTIONS: ${{ matrix.node-version >= 18 && '--openssl-legacy-provider' || '' }}

index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const utils = require('./utils');
22

3-
const scopedModuleRegex = new RegExp(
4-
'@[a-zA-Z0-9][\\w-.]+/[a-zA-Z0-9][\\w-.]+([a-zA-Z0-9./]+)?',
5-
'g'
6-
);
3+
const scopedModuleRegex =
4+
/@[a-zA-Z0-9][\w-.]+\/[a-zA-Z0-9][\w-.]+([a-zA-Z0-9./]+)?/;
75

86
function getModuleName(request, includeAbsolutePaths) {
97
let req = request;
@@ -14,8 +12,6 @@ function getModuleName(request, includeAbsolutePaths) {
1412
}
1513
// check if scoped module
1614
if (scopedModuleRegex.test(req)) {
17-
// reset regexp
18-
scopedModuleRegex.lastIndex = 0;
1915
return req.split(delimiter, 2).join(delimiter);
2016
}
2117
return req.split(delimiter)[0];
@@ -25,10 +21,7 @@ module.exports = function nodeExternals(options) {
2521
options = options || {};
2622
const mistakes = utils.validateOptions(options) || [];
2723
if (mistakes.length) {
28-
mistakes.forEach((mistake) => {
29-
utils.error(mistakes.map((mistake) => mistake.message));
30-
utils.log(mistake.message);
31-
});
24+
utils.error(mistakes.map((mistake) => mistake.message));
3225
}
3326
const webpackInternalAllowlist = [/^webpack\/container\/reference\//];
3427
const allowlist = []

0 commit comments

Comments
 (0)