Skip to content

Commit 37a05b5

Browse files
chore(all): prepare release 2.0.0-rc.3
1 parent 457ee6f commit 37a05b5

13 files changed

Lines changed: 119 additions & 24 deletions

dist/AureliaDependenciesPlugin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ class ParserPlugin {
6565
// PLATFORM.moduleName('some-module')
6666
return addDependency(param1.string, expr.range);
6767
}
68-
let chunk;
6968
let options;
7069
let param2 = parser.evaluateExpression(arg2);
7170
if (param2.isString()) {
7271
// Async module dependency
7372
// PLATFORM.moduleName('some-module', 'chunk name');
74-
chunk = param2.string;
73+
options = { chunk: param2.string };
7574
}
7675
else if (arg2.type === "ObjectExpression") {
7776
// Module dependency with extended options
@@ -84,7 +83,7 @@ class ParserPlugin {
8483
switch (prop.key.name) {
8584
case "chunk":
8685
if (value.isString())
87-
chunk = value.string;
86+
options.chunk = value.string;
8887
break;
8988
case "exports":
9089
if (value.isArray() && value.items.every(v => v.isString()))
@@ -97,7 +96,7 @@ class ParserPlugin {
9796
// Unknown PLATFORM.moduleName() signature
9897
return;
9998
}
100-
return addDependency(chunk ? `async?lazy&name=${chunk}!${param1.string}` : param1.string, expr.range, options);
99+
return addDependency(param1.string, expr.range, options);
101100
});
102101
}
103102
}

dist/AureliaPlugin.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ const ConventionDependenciesPlugin_1 = require("./ConventionDependenciesPlugin")
66
const DistPlugin_1 = require("./DistPlugin");
77
const GlobDependenciesPlugin_1 = require("./GlobDependenciesPlugin");
88
const HtmlDependenciesPlugin_1 = require("./HtmlDependenciesPlugin");
9+
const InlineViewDependenciesPlugin_1 = require("./InlineViewDependenciesPlugin");
910
const ModuleDependenciesPlugin_1 = require("./ModuleDependenciesPlugin");
1011
const PreserveExportsPlugin_1 = require("./PreserveExportsPlugin");
1112
const PreserveModuleNamePlugin_1 = require("./PreserveModuleNamePlugin");
1213
const SubFolderPlugin_1 = require("./SubFolderPlugin");
1314
// See comments inside the module to understand why this is used
14-
const emptyEntryModule = "aurelia-webpack-plugin/dist/aurelia-entry";
15+
const emptyEntryModule = "aurelia-webpack-plugin/runtime/empty-entry";
1516
class AureliaPlugin {
1617
constructor(options = {}) {
1718
this.options = Object.assign({
1819
includeAll: false,
19-
aureliaApp: "main",
2020
aureliaConfig: ["standard", "developmentLogging"],
2121
dist: "native-modules",
2222
features: {},
2323
moduleMethods: [],
2424
noHtmlLoader: false,
25+
// Undocumented safety switch
26+
noInlineView: false,
2527
noModulePathResolve: false,
2628
noWebpackLoader: false,
2729
// Ideally we would like _not_ to process conventions in node_modules,
@@ -45,6 +47,8 @@ class AureliaPlugin {
4547
const opts = this.options;
4648
const features = opts.features;
4749
let needsEmptyEntry = false;
50+
let dllPlugin = compiler.options.plugins.some(p => p instanceof webpack_1.DllPlugin);
51+
let dllRefPlugins = compiler.options.plugins.filter(p => p instanceof webpack_1.DllReferencePlugin);
4852
// Make sure the loaders are easy to load at the root like `aurelia-webpack-plugin/html-resource-loader`
4953
let resolveLoader = compiler.options.resolveLoader;
5054
let alias = resolveLoader.alias || (resolveLoader.alias = {});
@@ -57,6 +61,11 @@ class AureliaPlugin {
5761
resolveLoader.symlinks = false;
5862
compiler.options.resolve.symlinks = false;
5963
}
64+
// If we aren't building a DLL, "main" is the default entry point
65+
// Note that the 'in' check is because someone may explicitly set aureliaApp to undefined
66+
if (!dllPlugin && !("aureliaApp" in opts)) {
67+
opts.aureliaApp = "main";
68+
}
6069
// Uses DefinePlugin to cut out optional features
6170
const defines = {
6271
AURELIA_WEBPACK_2_0: "true"
@@ -107,8 +116,6 @@ class AureliaPlugin {
107116
// When using includeAll, we assume it's already included
108117
globalDependencies.push({ name: opts.aureliaApp, exports: ["configure"] });
109118
}
110-
let dllPlugin = compiler.options.plugins.some(p => p instanceof webpack_1.DllPlugin);
111-
let dllRefPlugins = compiler.options.plugins.filter(p => p instanceof webpack_1.DllReferencePlugin);
112119
if (!dllPlugin && dllRefPlugins.length > 0) {
113120
// Creates delegated entries for all Aurelia modules in DLLs.
114121
// This is required for aurelia-loader-webpack to find them.
@@ -122,10 +129,7 @@ class AureliaPlugin {
122129
}
123130
if (!dllPlugin && !opts.noWebpackLoader) {
124131
// Setup aurelia-loader-webpack as the module loader
125-
// Note that code inside aurelia-loader-webpack performs PLATFORM.Loader = WebpackLoader;
126-
// Since this runs very early, before any other Aurelia code, we need "aurelia-polyfills"
127-
// for older platforms (e.g. `Map` is undefined in IE 10-).
128-
this.addEntry(compiler.options, ["aurelia-polyfills", "aurelia-loader-webpack"]);
132+
this.addEntry(compiler.options, ["aurelia-webpack-plugin/runtime/pal-loader-entry"]);
129133
}
130134
if (!opts.noHtmlLoader) {
131135
// Ensure that we trace HTML dependencies (always required because of 3rd party libs)
@@ -135,6 +139,9 @@ class AureliaPlugin {
135139
// because it will process the file first, before any other loader.
136140
rules.push({ test: /\.html?$/i, use: "aurelia-webpack-plugin/html-requires-loader" });
137141
}
142+
if (!opts.noInlineView) {
143+
compiler.apply(new InlineViewDependenciesPlugin_1.InlineViewDependenciesPlugin());
144+
}
138145
if (globalDependencies.length > 0) {
139146
dependencies[emptyEntryModule] = globalDependencies;
140147
needsEmptyEntry = true;
@@ -186,6 +193,7 @@ function getPAL(target) {
186193
switch (target) {
187194
case "web": return "aurelia-pal-browser";
188195
case "webworker": return "aurelia-pal-worker";
196+
case "electron-renderer": return "aurelia-pal-browser";
189197
default: return "aurelia-pal-nodejs";
190198
}
191199
}

dist/IncludeDependency.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const ModuleDependency = require("webpack/lib/dependencies/ModuleDependency");
66
const NullDependency = require("webpack/lib/dependencies/NullDependency");
77
class IncludeDependency extends ModuleDependency {
88
constructor(request, options) {
9-
super(request);
9+
let chunk = options && options.chunk;
10+
super(chunk ? `async?lazy&name=${chunk}!${request}` : request);
1011
this.options = options;
1112
}
1213
get type() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
// This plugins tries to detect @inlineView('<template>...</template>') and process its dependencies
4+
// like HtmlDependenciesPlugin does.
5+
const BaseIncludePlugin_1 = require("./BaseIncludePlugin");
6+
const BasicEvaluatedExpression = require("webpack/lib/BasicEvaluatedExpression");
7+
const htmlLoader = require("./html-requires-loader");
8+
class InlineViewDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
9+
parser(compilation, parser, add) {
10+
// The parser will only apply "call inlineView" on free variables.
11+
// So we must first trick it into thinking inlineView is an unbound identifier
12+
// in the various situations where it is not.
13+
// This covers native ES module, for example:
14+
// import { inlineView } from "aurelia-framework";
15+
// inlineView("<template>");
16+
parser.plugin("evaluate Identifier imported var", (expr) => {
17+
if (expr.name === "inlineView") {
18+
return new BasicEvaluatedExpression().setIdentifier("inlineView").setRange(expr.range);
19+
}
20+
return undefined;
21+
});
22+
// This covers commonjs modules, for example:
23+
// const _aurelia = require("aurelia-framework");
24+
// _aurelia.inlineView("<template>");
25+
// Or (note: no renaming supported):
26+
// const inlineView = require("aurelia-framework").inlineView;
27+
// inlineView("<template>");
28+
parser.plugin("evaluate MemberExpression", (expr) => {
29+
if (expr.property.name === "inlineView") {
30+
return new BasicEvaluatedExpression().setIdentifier("inlineView").setRange(expr.range);
31+
}
32+
return undefined;
33+
});
34+
parser.plugin("call inlineView", (expr) => {
35+
if (expr.arguments.length !== 1)
36+
return;
37+
let arg1 = expr.arguments[0];
38+
let param1 = parser.evaluateExpression(arg1);
39+
if (!param1.isString())
40+
return;
41+
let modules;
42+
try {
43+
modules = htmlLoader.modules(param1.string);
44+
}
45+
catch (e) {
46+
return;
47+
}
48+
modules.forEach(add);
49+
});
50+
}
51+
}
52+
exports.InlineViewDependenciesPlugin = InlineViewDependenciesPlugin;

dist/PreserveModuleNamePlugin.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ class PreserveModuleNamePlugin {
1717
let { modules: roots, extensions, alias } = compilation.options.resolve;
1818
roots = roots.map(x => path.resolve(x));
1919
const normalizers = extensions.map(x => new RegExp(x.replace(/\./g, "\\.") + "$", "i"));
20+
// ModuleConcatenationPlugin merges modules into new ConcatenatedModule
21+
let modulesBeforeConcat = modules.slice();
22+
for (let i = 0; i < modulesBeforeConcat.length; i++) {
23+
let m = modulesBeforeConcat[i];
24+
// We don't `import ConcatenatedModule` and then `m instanceof ConcatenatedModule`
25+
// because it was introduced in Webpack 3.0 and we're still compatible with 2.x at the moment.
26+
if (m.constructor.name === "ConcatenatedModule")
27+
modulesBeforeConcat.splice(i--, 1, ...m["modules"]);
28+
}
2029
for (let module of getPreservedModules(modules)) {
2130
let preserve = module[exports.preserveModuleName];
2231
let id = typeof preserve === "string" ? preserve : null;
2332
// No absolute request to preserve, we try to normalize the module resource
2433
if (!id && module.resource)
25-
id = fixNodeModule(module, modules) ||
34+
id = fixNodeModule(module, modulesBeforeConcat) ||
2635
makeModuleRelative(roots, module.resource) ||
2736
aliasRelative(alias, module.resource);
2837
if (!id)

dist/html-requires-loader.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ const parse = require("html-loader/lib/attributesParser");
33
const _htmlSymbol = Symbol("HTML dependencies");
44
function loader(content) {
55
this.cacheable && this.cacheable();
6-
this._module[_htmlSymbol] =
7-
parse(content, (tag, attr) => {
8-
const attrs = loader.attributes[tag];
9-
return attrs && attrs.includes(attr);
10-
})
11-
.filter(attr => !/(^|[^\\])\$\{/.test(attr.value))
12-
.map(attr => attr.value);
6+
this._module[_htmlSymbol] = loader.modules(content);
137
return content;
148
}
159
(function (loader) {
1610
loader.htmlSymbol = _htmlSymbol;
1711
loader.attributes = {
1812
"require": ["from"],
1913
"compose": ["view", "view-model"],
14+
"router-view": ["layout-view", "layout-view-model"],
2015
};
16+
function modules(html) {
17+
return parse(html, (tag, attr) => {
18+
const attrs = loader.attributes[tag];
19+
return attrs && attrs.includes(attr);
20+
})
21+
.filter(attr => !/(^|[^\\])\$\{/.test(attr.value))
22+
.map(attr => attr.value);
23+
}
24+
loader.modules = modules;
2125
})(loader || (loader = {}));
2226
module.exports = loader;

dist/types/AureliaPlugin.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Options {
1414
polyfills?: Polyfills;
1515
};
1616
noHtmlLoader: boolean;
17+
noInlineView: boolean;
1718
noModulePathResolve: boolean;
1819
noWebpackLoader: boolean;
1920
moduleMethods: string[];

dist/types/BaseIncludePlugin.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export declare type AddDependency = (request: string, options?: DependencyOptions) => void;
1+
export declare type AddDependency = (request: string | DependencyOptionsEx) => void;
22
export declare class BaseIncludePlugin {
33
apply(compiler: Webpack.Compiler): void;
44
parser(compilation: Webpack.Compilation, parser: Webpack.Parser, add: AddDependency): void;

dist/types/IncludeDependency.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ModuleDependency = require("webpack/lib/dependencies/ModuleDependency");
22
import NullDependency = require("webpack/lib/dependencies/NullDependency");
33
export declare class IncludeDependency extends ModuleDependency {
4-
private options;
4+
private options?;
55
constructor(request: string, options?: DependencyOptions);
66
readonly type: string;
77
getReference(): {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { BaseIncludePlugin, AddDependency } from "./BaseIncludePlugin";
2+
export declare class InlineViewDependenciesPlugin extends BaseIncludePlugin {
3+
parser(compilation: Webpack.Compilation, parser: Webpack.Parser, add: AddDependency): void;
4+
}

0 commit comments

Comments
 (0)