Skip to content

Commit 30eb24f

Browse files
committed
feat(build-resources): add all dependencies as build resources by default
1 parent eded984 commit 30eb24f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/build-resources.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function getPackageAureliaResources(packageJson) {
104104

105105
function getPackageMainDir(packagePath) {
106106
const packageJson = getPackageJson(packagePath);
107-
const packageMain = packageJson.main || packageJson.browser;
107+
const packageMain = packageJson.aurelia && packageJson.aurelia.main && packageJson.aurelia.main['native-modules'] || packageJson.main || packageJson.browser;
108108
return packageMain ? path.dirname(path.join(packagePath, packageMain)) : null;
109109
}
110110

@@ -283,12 +283,26 @@ function getResourcesOfPackage(resources = {}, packagePath = undefined, relative
283283
// recursively load resources of all 'dependencies' defined in package.json:
284284
if (packageJson.dependencies) {
285285
for (let moduleName of Object.getOwnPropertyNames(packageJson.dependencies)) {
286-
let modulePathIndex = moduleNames.indexOf(moduleName);
286+
const modulePathIndex = moduleNames.indexOf(moduleName);
287287
if (modulePathIndex !== -1) {
288-
let modulePath = modulePaths[modulePathIndex];
288+
const modulePath = modulePaths[modulePathIndex];
289289
getResourcesOfPackage(resources, modulePath, undefined, undefined /* might add defaults from plugin config */, moduleName);
290290
}
291291
}
292+
293+
if (!externalModule) {
294+
// iterate again, now to add modules themselves if not yet added:
295+
for (let moduleName of Object.getOwnPropertyNames(packageJson.dependencies)) {
296+
const modulePathIndex = moduleNames.indexOf(moduleName);
297+
if (modulePathIndex !== -1) {
298+
const modulePath = modulePaths[modulePathIndex];
299+
// add the module itself
300+
if (!resources[moduleName] && getPackageMainDir(modulePath)) {
301+
resources[moduleName] = { path: moduleName, source: moduleName, moduleName, modulePath };
302+
}
303+
}
304+
}
305+
}
292306
}
293307
}
294308
}

test/build-resources.js

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ var filesExpectedToLoad = [
4444
'node_modules/aurelia-templating-resources/dist/commonjs/compose.js',
4545
'node_modules/aurelia-templating-resources/dist/commonjs/sub/sub.js',
4646
'node_modules/aurelia-templating-resources/dist/commonjs/sub/sub.js',
47+
'aurelia-bootstrapper',
48+
'aurelia-templating-resources',
4749
'src/c.js',
4850
'src/style.css',
4951
'src/d.js',
@@ -93,6 +95,8 @@ var expectedRequireStrings = [
9395
'aurelia-templating-resources/compose.js',
9496
'aurelia-templating-resources/sub/sub',
9597
'aurelia-templating-resources/sub/sub.js',
98+
'aurelia-bootstrapper',
99+
'aurelia-templating-resources',
96100
'c.js',
97101
'style.css',
98102
'./d',

0 commit comments

Comments
 (0)