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 duplicated content due to symlinks #1505

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 7 additions & 3 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,19 @@ class Bundler extends EventEmitter {
}

async resolveAsset(name, parent) {
let {path} = await this.resolver.resolve(name, parent);
return this.getLoadedAsset(path);
let {path, realpath} = await this.resolver.resolve(name, parent);
return this.getLoadedAsset(path, realpath);
}

getLoadedAsset(path) {
getLoadedAsset(path, realpath) {
if (this.loadedAssets.has(path)) {
return this.loadedAssets.get(path);
}

if (this.loadedAssets.has(realpath)) {
return this.loadedAssets.get(realpath);
}

let asset = this.parser.getAsset(path, this.options);
this.loadedAssets.set(path, asset);

Expand Down
3 changes: 2 additions & 1 deletion src/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ class Resolver {
// Try all supported extensions
for (let f of this.expandFile(file, extensions, pkg)) {
if (await this.isFile(f)) {
return {path: f, pkg};
let realpath = await fs.realpath(f);
return {path: f, realpath, pkg};
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/integration/resolver/barsym.js
11 changes: 11 additions & 0 deletions test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ describe('resolver', function() {
);
assert.equal(resolved.pkg.name, 'foo');
});

it('should resolve a symlinked path and provide the realpath', async function() {
let resolved = await resolver.resolve(
'./barsym',
path.join(rootDir, 'foo.js')
);

assert.equal(resolved.path, path.join(rootDir, 'barsym.js'));
assert.equal(resolved.realpath, path.join(rootDir, 'bar.js'));
assert.equal(resolved.pkg.name, 'resolver');
});
});

describe('builtins', function() {
Expand Down