From 983c0cac83727a13af834fe79dfeef89da4fb84b Mon Sep 17 00:00:00 2001 From: cleverpp Date: Thu, 11 Aug 2022 13:35:01 +0800 Subject: [PATCH] resolve currentPath (#4591) * resolve currentPath * Try modified test * Add test Co-authored-by: undefined Co-authored-by: Lukas Taegert-Atkinson Co-authored-by: Lukas Taegert-Atkinson --- src/Chunk.ts | 2 +- .../samples/preserve-modules-root/_config.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Chunk.ts b/src/Chunk.ts index 11e6e3035dd..bb7fdee3484 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -464,7 +464,7 @@ export default class Chunk { }); const currentPath = `${currentDir}/${fileName}`; const { preserveModulesRoot } = options; - if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) { + if (preserveModulesRoot && resolve(currentPath).startsWith(preserveModulesRoot)) { path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, ''); } else { path = relative(preserveModulesRelativeDir, currentPath); diff --git a/test/chunking-form/samples/preserve-modules-root/_config.js b/test/chunking-form/samples/preserve-modules-root/_config.js index 61ff285d344..5518c9c5483 100644 --- a/test/chunking-form/samples/preserve-modules-root/_config.js +++ b/test/chunking-form/samples/preserve-modules-root/_config.js @@ -7,6 +7,14 @@ module.exports = { options: { input: ['src/under-build.js', 'src/below/module.js'], plugins: [ + { + name: 'convert-slashes', + // This simulates converted slashes as used by e.g. Vite + async resolveId(source, importer, options) { + const resolved = await this.resolve(source, importer, { ...options, skipSelf: true }); + return { ...resolved, id: resolved.id.replace(/\\/g, '/') }; + } + }, resolve({ moduleDirectories: ['custom_modules'] }),