|
1 | 1 | /* globals requirejs */
|
2 | 2 | import { assert } from '@ember/debug';
|
3 | 3 |
|
4 |
| -import pico from 'picomatch'; |
| 4 | +import normalizePath from 'path-normalize'; |
| 5 | +import pico from 'picomatch/posix'; |
5 | 6 |
|
6 | 7 | /**
|
7 | 8 | * Only supported usage:
|
@@ -68,13 +69,14 @@ export function importMetaGlob(glob, options, modulePath) {
|
68 | 69 | let globsArray = Array.isArray(glob) ? glob : [glob];
|
69 | 70 |
|
70 | 71 | [...globsArray].forEach((g) => {
|
71 |
| - let extensionless = g.replace(/\.\w{2,3}$/, ''); |
| 72 | + let extensionless = g.replace(/\.\{?\w{2,}\}?$/, ''); |
72 | 73 |
|
73 | 74 | globsArray.push(extensionless);
|
74 | 75 | });
|
75 | 76 |
|
76 | 77 | let fullGlobs = globsArray.map((g) => {
|
77 |
| - return `${currentDir}/${g.replace(/^.\//, '')}`; |
| 78 | + // Collapses ./ and ../ |
| 79 | + return normalizePath(`${currentDir}/${g}`, /* allowAboveRoot */ false); |
78 | 80 | });
|
79 | 81 | let isMatch = pico(fullGlobs);
|
80 | 82 | let matches = allModules.filter(isMatch);
|
@@ -112,6 +114,13 @@ function isEscapingApp(path) {
|
112 | 114 | let preUpCount = 0;
|
113 | 115 | let upCount = 0;
|
114 | 116 |
|
| 117 | + // normalizePath will return the right-most path segment if you ../ |
| 118 | + // too many times. This is wrong for us. |
| 119 | + // a plain 'module-name' (no slashes) is not importable in ember. |
| 120 | + if (parts.length === 1) { |
| 121 | + return true; |
| 122 | + } |
| 123 | + |
115 | 124 | for (let part of parts) {
|
116 | 125 | if (part === '..') {
|
117 | 126 | upCount++;
|
|
0 commit comments