Skip to content

Commit 983c0ca

Browse files
resolve currentPath (#4591)
* resolve currentPath * Try modified test * Add test Co-authored-by: undefined <undefined> Co-authored-by: Lukas Taegert-Atkinson <[email protected]> Co-authored-by: Lukas Taegert-Atkinson <[email protected]>
1 parent fc08bcc commit 983c0ca

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Chunk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ export default class Chunk {
464464
});
465465
const currentPath = `${currentDir}/${fileName}`;
466466
const { preserveModulesRoot } = options;
467-
if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) {
467+
if (preserveModulesRoot && resolve(currentPath).startsWith(preserveModulesRoot)) {
468468
path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, '');
469469
} else {
470470
path = relative(preserveModulesRelativeDir, currentPath);

test/chunking-form/samples/preserve-modules-root/_config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ module.exports = {
77
options: {
88
input: ['src/under-build.js', 'src/below/module.js'],
99
plugins: [
10+
{
11+
name: 'convert-slashes',
12+
// This simulates converted slashes as used by e.g. Vite
13+
async resolveId(source, importer, options) {
14+
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
15+
return { ...resolved, id: resolved.id.replace(/\\/g, '/') };
16+
}
17+
},
1018
resolve({
1119
moduleDirectories: ['custom_modules']
1220
}),

0 commit comments

Comments
 (0)