Skip to content

Commit

Permalink
chore(commonjs): switch to fdir for fewer dependencies
Browse files Browse the repository at this point in the history
BREAKING CHANGES: directories listed in dynamicRequireTargets now require a trailing slash
  • Loading branch information
benmccann committed Jun 27, 2024
1 parent 8550c4b commit 0defec6
Show file tree
Hide file tree
Showing 9 changed files with 5,080 additions and 4,275 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@
"test/"
]
},
"packageManager": "pnpm@8.15.8+sha512.d1a029e1a447ad90bc96cd58b0fad486d2993d531856396f7babf2d83eb1823bb83c5a3d0fc18f675b2d10321d49eb161fece36fe8134aa5823ecd215feed392"
"packageManager": "pnpm@9.4.0"
}
2 changes: 1 addition & 1 deletion packages/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"glob": "^10.4.1",
"fdir": "^6.1.1",
"is-reference": "1.2.1",
"magic-string": "^0.30.3"
},
Expand Down
11 changes: 8 additions & 3 deletions packages/commonjs/src/dynamic-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join, resolve, dirname } from 'path';

import getCommonDir from 'commondir';

import { glob } from 'glob';
import { fdir } from 'fdir';

import { getVirtualPathForDynamicRequirePath, normalizePathSlashes } from './utils';

Expand Down Expand Up @@ -41,8 +41,13 @@ export function getDynamicRequireModules(patterns, dynamicRequireRoot) {
isNegated
? dynamicRequireModules.delete(targetPath)
: dynamicRequireModules.set(targetPath, resolvedPath);
for (const path of glob
.sync(isNegated ? pattern.substr(1) : pattern)
// eslint-disable-next-line new-cap
for (const path of new fdir()
.withBasePath()
.withDirs()
.glob(isNegated ? pattern.substr(1) : pattern)
.crawl()
.sync()
.sort((a, b) => a.localeCompare(b, 'en'))) {
const resolvedPath = resolve(path);
const requirePath = normalizePathSlashes(resolvedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module.exports = {
},
pluginOptions: {
dynamicRequireTargets: [
'fixtures/function/dynamic-require-instances/direct',
'fixtures/function/dynamic-require-instances/direct/',
'fixtures/function/dynamic-require-instances/direct/index.js',
'fixtures/function/dynamic-require-instances/package',
'fixtures/function/dynamic-require-instances/package/',
'fixtures/function/dynamic-require-instances/package/main.js'
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports = {
},
pluginOptions: {
dynamicRequireTargets: [
'fixtures/function/dynamic-require-package',
'fixtures/function/dynamic-require-package/sub',
'fixtures/function/dynamic-require-package/node_modules/custom-module'
'fixtures/function/dynamic-require-package/',
'fixtures/function/dynamic-require-package/sub/',
'fixtures/function/dynamic-require-package/node_modules/custom-module/'
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module.exports = {
},
pluginOptions: {
dynamicRequireTargets: [
'fixtures/function/dynamic-require-resolve-index',
'fixtures/function/dynamic-require-resolve-index/sub',
'fixtures/function/dynamic-require-resolve-index/node_modules/custom-module'
'fixtures/function/dynamic-require-resolve-index/',
'fixtures/function/dynamic-require-resolve-index/sub/',
'fixtures/function/dynamic-require-resolve-index/node_modules/custom-module/'
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
},
pluginOptions: {
dynamicRequireTargets: [
'fixtures/function/dynamic-require-resolve-reference/node_modules/{custom-module,custom-module2}{,/*.js}'
'fixtures/function/dynamic-require-resolve-reference/node_modules/{custom-module,custom-module2}{/,/*.js}'
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module.exports = {
},
pluginOptions: {
dynamicRequireTargets: [
'fixtures/function/dynamic-require-slash-access',
'fixtures/function/dynamic-require-slash-access/sub',
'fixtures/function/dynamic-require-slash-access/node_modules/custom-module',
'fixtures/function/dynamic-require-slash-access/',
'fixtures/function/dynamic-require-slash-access/sub/',
'fixtures/function/dynamic-require-slash-access/node_modules/custom-module/',
'fixtures/function/dynamic-require-slash-access/node_modules/custom-module2/*.js'
]
}
Expand Down
Loading

0 comments on commit 0defec6

Please sign in to comment.