Skip to content

Commit

Permalink
chore(resolve-template): change package.json resource object path
Browse files Browse the repository at this point in the history
  • Loading branch information
niieani committed Jun 9, 2016
1 parent 32fdadc commit 6e6c74b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,28 @@ To see the ways resources can be declared inside `package.json` see the followin
{
...
"aurelia": {
"resources": [
// relative to your /src:
"some-resource.js",
"another.html",
"items/another-without-extension",
"build": {
"resources": [
// relative to your /src:
"some-resource.js",
"another.html",
"items/another-without-extension",

// make the file and its dependencies lazy-load from a separate bundle:
{ "path": "external-module/file.html", lazy: true, bundle: "some-bundle" },
{ "path": [], lazy: true, bundle: "some-bundle" },

// include external resource (and its module's dependencies)
"aurelia-templating-resources/compose"

// include package (and its module's dependencies):
"bootstrap"
],

// make the file and its dependencies lazy-load from a separate bundle:
{ "path": "external-module/file.html", lazy: true, bundle: "some-bundle" },
{ "path": [], lazy: true, bundle: "some-bundle" },

// include external resource (and its module's dependencies)
"aurelia-templating-resources/compose"

// include package (and its module's dependencies):
"bootstrap"
],

// you may also override package's root directory in case the file is located at a different place from either the child of main or module's root directory
"moduleRootOverride": {
"aurelia-templating-resources": "dist/es2015"
// you may also override package's root directory in case the file is located at a different place from either the child of main or module's root directory
"moduleRootOverride": {
"aurelia-templating-resources": "dist/es2015"
}
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/resolve-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ async function processAll(options) {

// try to load any resources explicitly defined in package.json:
// this is done last so that bundle overrides will take over
if (baseVendorPkg.aurelia && baseVendorPkg.aurelia.resources) {
for (let resource of baseVendorPkg.aurelia.resources) {
if (baseVendorPkg.aurelia && baseVendorPkg.aurelia.build && baseVendorPkg.aurelia.build.resources) {
for (let resource of baseVendorPkg.aurelia.build.resources) {
let fromPaths = resource instanceof Object ? [resource.path] : [resource];
if (fromPaths[0] instanceof Array) {
fromPaths = fromPaths[0];
}
for (let fromPath of fromPaths) {
let moduleName = fromPath.split(path.sep)[0];
let rootAlias = resource.root ? path.resolve(options.root, 'node_modules', moduleName, resource.root) : undefined;
if (!rootAlias && baseVendorPkg.aurelia.moduleRootOverride && baseVendorPkg.aurelia.moduleRootOverride[moduleName]) {
rootAlias = path.resolve(options.root, 'node_modules', moduleName, baseVendorPkg.aurelia.moduleRootOverride[moduleName]);
if (!rootAlias && baseVendorPkg.aurelia.build.moduleRootOverride && baseVendorPkg.aurelia.build.moduleRootOverride[moduleName]) {
rootAlias = path.resolve(options.root, 'node_modules', moduleName, baseVendorPkg.aurelia.build.moduleRootOverride[moduleName]);
}
assign(dependencies, await getDependency(fromPath, options.src, options.src, [nodeModules], null, packageJson, options.lazy || resource.lazy, options.bundle || resource.bundle, rootAlias));
}
Expand Down Expand Up @@ -353,21 +353,21 @@ async function getDependency(fromPath, relativeParent, srcPath, nodeModulesList,
packagesOwnNodeModules = ownPath;
} catch (_) {}

if (vendorPkg.aurelia && vendorPkg.aurelia.resources) {
for (let resource of vendorPkg.aurelia.resources) {
if (vendorPkg.aurelia && vendorPkg.aurelia.build && vendorPkg.aurelia.build.resources) {
for (let resource of vendorPkg.aurelia.build.resources) {
let resourcePath = resource instanceof Object ? resource.path : resource;
let useRootAlias = rootAlias;
// least important: package's global override
if (vendorPkg.aurelia.moduleRootOverride && vendorPkg.aurelia.moduleRootOverride[moduleName]) {
useRootAlias = path.resolve(modulePath, vendorPkg.aurelia.moduleRootOverride[moduleName]);
if (vendorPkg.aurelia.build.moduleRootOverride && vendorPkg.aurelia.build.moduleRootOverride[moduleName]) {
useRootAlias = path.resolve(modulePath, vendorPkg.aurelia.build.moduleRootOverride[moduleName]);
}
// second least important: package resource's override
if (resource.root) {
useRootAlias = path.resolve(modulePath, resource.root);
}
// most important: parent-most package's override
if (baseVendorPkg && baseVendorPkg.aurelia && baseVendorPkg.aurelia.moduleRootOverride && baseVendorPkg.aurelia.moduleRootOverride[moduleName]) {
useRootAlias = path.resolve(modulePath, baseVendorPkg.aurelia.moduleRootOverride[moduleName]);
if (baseVendorPkg && baseVendorPkg.aurelia && baseVendorPkg.aurelia.build.moduleRootOverride && baseVendorPkg.aurelia.build.moduleRootOverride[moduleName]) {
useRootAlias = path.resolve(modulePath, baseVendorPkg.aurelia.build.moduleRootOverride[moduleName]);
}
if (useRootAlias === modulePath) {
useRootAlias = null;
Expand Down

0 comments on commit 6e6c74b

Please sign in to comment.