From a26b00aef0a445e4eec9c9194dc52a85958661a8 Mon Sep 17 00:00:00 2001 From: TrickyPi <530257315@qq.com> Date: Sun, 28 May 2023 21:47:33 +0800 Subject: [PATCH] fix(commonjs): change dynamicRequireRoot to normalizedDynamicRequireRoot && tweak related tests --- packages/commonjs/src/index.js | 8 ++++---- packages/commonjs/test/test.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index dedda0a01..99a92a8d5 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -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.` }, diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.js index 948151c0e..fc8d4934c 100644 --- a/packages/commonjs/test/test.js +++ b/packages/commonjs/test/test.js @@ -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 }); });