Skip to content

Commit

Permalink
fix(commonjs): change dynamicRequireRoot to normalizedDynamicRequireR…
Browse files Browse the repository at this point in the history
…oot && tweak related tests (#1508)
  • Loading branch information
TrickyPi authored Jun 10, 2023
1 parent 8af989a commit 7cedfae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/commonjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ export default function commonjs(options = {}) {
!isEsModule && (dynamicRequireModules.has(normalizedId) || strictRequiresFilter(id));

const checkDynamicRequire = (position) => {
const normalizedRequireRoot = normalizePathSlashes(dynamicRequireRoot);
const normalizedDynamicRequireRoot = normalizePathSlashes(dynamicRequireRoot);

if (normalizedId.indexOf(normalizedRequireRoot) !== 0) {
if (normalizedId.indexOf(normalizedDynamicRequireRoot) !== 0) {
this.error(
{
code: 'DYNAMIC_REQUIRE_OUTSIDE_ROOT',
normalizedId,
dynamicRequireRoot,
message: `"${normalizedId}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${normalizedRequireRoot}". You should set dynamicRequireRoot to "${dirname(
normalizedDynamicRequireRoot,
message: `"${normalizedId}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${normalizedDynamicRequireRoot}". You should set dynamicRequireRoot to "${dirname(
normalizedId
)}" or one of its parent directories.`
},
Expand Down
4 changes: 2 additions & 2 deletions packages/commonjs/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ test('throws when there is a dynamic require from outside dynamicRequireRoot', a
t.like(error, {
message: `"${id}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${dynamicRequireRoot}". You should set dynamicRequireRoot to "${minimalDynamicRequireRoot}" or one of its parent directories.`,
pluginCode: 'DYNAMIC_REQUIRE_OUTSIDE_ROOT',
id,
dynamicRequireRoot
normalizedId: id,
normalizedDynamicRequireRoot: dynamicRequireRoot
});
});

Expand Down

0 comments on commit 7cedfae

Please sign in to comment.