Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Fix alias discrepancy with Webpack #64

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log

.nyc_output
dist
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ export default function alias(options = {}) {
} else if (endsWith('.js', filePath)) {
updatedId = filePath;
} else {
updatedId = filePath + '.js';
const indexFilePath = posix.resolve(directory, `${updatedId}/index`);
const defaultMatch = resolve.map(ext => `${indexFilePath}${ext}`).find(exists);
if (defaultMatch) {
updatedId = defaultMatch;
} else {
updatedId = filePath + '.js';
}
}
}

Expand Down
Empty file added test/files/Svelte/index.svelte
Empty file.
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ test('Platform path.resolve(\'file-without-extension\') aliasing', (t) => {
t.is(resolved, path.resolve('./test/files/aliasMe.js'));
});

test('Platform path.resolve(\'just-a-folder\') aliasing', (t) => {
// this what used in RSvelte
const result = alias({
resolve: ['.svelte', '.js'],
entries:[
{find:'test', replacement:path.resolve('./test/files/Svelte')}
]
});

const resolved = result.resolveId('test', posix.resolve(DIRNAME, './files/index.js'));

t.is(resolved, path.resolve('./test/files/Svelte/index.svelte'));
});

test('Windows absolute path aliasing', (t) => {
const result = alias({
entries:[
Expand Down