Skip to content

Commit 4a5536d

Browse files
author
Willson Haw
committed
fix(build-resources): Fix module resolution for symlinks
1 parent f04f62b commit 4a5536d

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

dist/build-resources.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,23 @@ var moduleRootOverride = {};
218218
var modulePaths = [];
219219
var moduleNames = [];
220220

221+
function installedRootModulePaths() {
222+
return fileSystem.readdirSync(path.join(optionsGlobal.root, 'node_modules')).filter(function (dir) {
223+
return !/^\./.test(dir);
224+
}).map(function (dir) {
225+
return path.resolve(optionsGlobal.root, 'node_modules', dir);
226+
});
227+
}
228+
221229
function installedLocalModulePaths() {
222230
return execa('npm', ['ls', '--parseable'], { cwd: optionsGlobal.root }).then(function (res) {
223-
return res.stdout.split('\n').filter(function (line, i) {
231+
return installedRootModulePaths().concat(res.stdout.split('\n').filter(function (line, i) {
224232
return i !== 0 && !!line;
225-
});
233+
}));
226234
}).catch(function (res) {
227-
return res.stdout.split('\n').filter(function (line, i) {
235+
return installedRootModulePaths().concat(res.stdout.split('\n').filter(function (line, i) {
228236
return i !== 0 && !!line;
229-
});
237+
}));
230238
});
231239
}
232240

@@ -417,8 +425,8 @@ function processFromPath(resources, fromPath, resource, packagePath, relativeToD
417425
resources[fromPathCss] = (0, _assign2.default)({}, resource, realPath, overrideBlock || {});
418426
}
419427
} else {
420-
console.error('Unable to resolve', fromPath);
421-
}
428+
console.error('Unable to resolve', fromPath);
429+
}
422430
}
423431

424432
function getResourcesOfPackage() {
@@ -539,11 +547,11 @@ function fixRelativeFromPath(fromPath, realSrcPath, realParentPath, externalModu
539547
if (modulePathIndex !== -1) {
540548
return fromPath;
541549
} else {
542-
if (fromPath.indexOf('.') == 0) {
543-
fromPath = path.joinSafe('./', path.relative(realSrcPath, realParentPath), fromPath);
544-
}
545-
return externalModule ? path.join(externalModule, fromPath) : fromPath;
550+
if (fromPath.indexOf('.') == 0) {
551+
fromPath = path.joinSafe('./', path.relative(realSrcPath, realParentPath), fromPath);
546552
}
553+
return externalModule ? path.join(externalModule, fromPath) : fromPath;
554+
}
547555
}
548556

549557
function resolveTemplateResources(htmlFilePath, srcPath, externalModule) {

src/build-resources.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ let moduleRootOverride = {};
2222
let modulePaths = [];
2323
let moduleNames = [];
2424

25+
function installedRootModulePaths() {
26+
return fileSystem.readdirSync(path.join(optionsGlobal.root, 'node_modules'))
27+
.filter(dir => !(/^\./.test(dir)))
28+
.map(dir => path.resolve(optionsGlobal.root, 'node_modules', dir));
29+
}
30+
2531
function installedLocalModulePaths() {
2632
return execa('npm', ['ls', '--parseable'], { cwd: optionsGlobal.root })
27-
.then(res => res.stdout.split('\n').filter((line, i) => i !== 0 && !!line))
28-
.catch(res => res.stdout.split('\n').filter((line, i) => i !== 0 && !!line));
33+
.then(res => installedRootModulePaths().concat(res.stdout.split('\n').filter((line, i) => i !== 0 && !!line)))
34+
.catch(res => installedRootModulePaths().concat(res.stdout.split('\n').filter((line, i) => i !== 0 && !!line)));
2935
}
3036

3137
function getFilesRecursively(targetDir, extension) {

0 commit comments

Comments
 (0)