Skip to content

Commit

Permalink
resolve currentPath (#4591)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Aug 11, 2022
1 parent fc08bcc commit 983c0ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions test/chunking-form/samples/preserve-modules-root/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}),
Expand Down

0 comments on commit 983c0ca

Please sign in to comment.