Skip to content

Commit f4ae534

Browse files
Merge pull request #7 from NullVoxPopuli/fix-up-dirs
Fix ../ globs
2 parents ea41a3c + 392de72 commit f4ae534

File tree

4 files changed

+214
-159
lines changed

4 files changed

+214
-159
lines changed

ember-classic-import-meta-glob/addon/index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* globals requirejs */
22
import { assert } from '@ember/debug';
33

4-
import pico from 'picomatch';
4+
import normalizePath from 'path-normalize';
5+
import pico from 'picomatch/posix';
56

67
/**
78
* Only supported usage:
@@ -68,13 +69,14 @@ export function importMetaGlob(glob, options, modulePath) {
6869
let globsArray = Array.isArray(glob) ? glob : [glob];
6970

7071
[...globsArray].forEach((g) => {
71-
let extensionless = g.replace(/\.\w{2,3}$/, '');
72+
let extensionless = g.replace(/\.\{?\w{2,}\}?$/, '');
7273

7374
globsArray.push(extensionless);
7475
});
7576

7677
let fullGlobs = globsArray.map((g) => {
77-
return `${currentDir}/${g.replace(/^.\//, '')}`;
78+
// Collapses ./ and ../
79+
return normalizePath(`${currentDir}/${g}`, /* allowAboveRoot */ false);
7880
});
7981
let isMatch = pico(fullGlobs);
8082
let matches = allModules.filter(isMatch);
@@ -112,6 +114,13 @@ function isEscapingApp(path) {
112114
let preUpCount = 0;
113115
let upCount = 0;
114116

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+
115124
for (let part of parts) {
116125
if (part === '..') {
117126
upCount++;

ember-classic-import-meta-glob/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"ember-auto-import": "^2.7.2",
5858
"ember-cli-babel": "^8.2.0",
5959
"ember-cli-babel-plugin-helpers": "^1.1.1",
60+
"path-normalize": "^6.0.13",
6061
"picomatch": "^4.0.2"
6162
}
6263
}

0 commit comments

Comments
 (0)