Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(commonjs): change dynamicRequireRoot to normalizedDynamicRequireRoot && tweak related tests #1508

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading