|
1 |
| -import { posix as path } from 'path'; |
| 1 | +import platformPath, { posix as path } from 'path'; |
2 | 2 | import { platform } from 'os';
|
3 | 3 | import fs from 'fs';
|
4 | 4 |
|
@@ -31,7 +31,7 @@ const exists = uri => {
|
31 | 31 | };
|
32 | 32 |
|
33 | 33 | const normalizeId = id => {
|
34 |
| - if (IS_WINDOWS && typeof id === 'string') { |
| 34 | + if ((IS_WINDOWS && typeof id === 'string') || VOLUME.test(id)) { |
35 | 35 | return slash(id.replace(VOLUME, ''));
|
36 | 36 | }
|
37 | 37 |
|
@@ -65,27 +65,32 @@ export default function alias(options = {}) {
|
65 | 65 |
|
66 | 66 | const entry = options[toReplace];
|
67 | 67 |
|
68 |
| - const updatedId = importeeId.replace(toReplace, entry); |
| 68 | + let updatedId = normalizeId(importeeId.replace(toReplace, entry)); |
69 | 69 |
|
70 | 70 | if (isFilePath(updatedId)) {
|
71 | 71 | const directory = path.dirname(importerId);
|
72 | 72 |
|
73 | 73 | // Resolve file names
|
74 | 74 | const filePath = path.resolve(directory, updatedId);
|
75 |
| - const match = resolve.map(ext => `${filePath}${ext}`) |
| 75 | + const match = resolve.map(ext => (endsWith(ext, filePath) ? filePath : `${filePath}${ext}`)) |
76 | 76 | .find(exists);
|
77 | 77 |
|
78 | 78 | if (match) {
|
79 |
| - return match; |
80 |
| - } |
81 |
| - |
| 79 | + updatedId = match; |
82 | 80 | // To keep the previous behaviour we simply return the file path
|
83 | 81 | // with extension
|
84 |
| - if (endsWith('.js', filePath)) { |
85 |
| - return filePath; |
| 82 | + } else if (endsWith('.js', filePath)) { |
| 83 | + updatedId = filePath; |
| 84 | + } else { |
| 85 | + updatedId = filePath + '.js'; |
86 | 86 | }
|
| 87 | + } |
87 | 88 |
|
88 |
| - return filePath + '.js'; |
| 89 | + // if alias is windows absoulate path return platform |
| 90 | + // resolved path or rollup on windows will throw: |
| 91 | + // [TypeError: Cannot read property 'specifier' of undefined] |
| 92 | + if (VOLUME.test(entry)) { |
| 93 | + return platformPath.resolve(updatedId); |
89 | 94 | }
|
90 | 95 |
|
91 | 96 | return updatedId;
|
|
0 commit comments