Skip to content

Commit

Permalink
chore(all): prepare release 3.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Feb 27, 2018
1 parent 93f7aff commit 99fe0dc
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 59 deletions.
14 changes: 8 additions & 6 deletions dist/AureliaDependenciesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const IncludeDependency_1 = require("./IncludeDependency");
const BasicEvaluatedExpression = require("webpack/lib/BasicEvaluatedExpression");
const TAP_NAME = "Aurelia:Dependencies";
class AureliaDependency extends IncludeDependency_1.IncludeDependency {
constructor(request, range, options) {
super(request, options);
Expand All @@ -27,10 +28,11 @@ class ParserPlugin {
// The parser will only apply "call PLATFORM.moduleName" on free variables.
// So we must first trick it into thinking PLATFORM.moduleName is an unbound identifier
// in the various situations where it is not.
const hooks = parser.hooks;
// This covers native ES module, for example:
// import { PLATFORM } from "aurelia-pal";
// PLATFORM.moduleName("id");
parser.plugin("evaluate Identifier imported var.moduleName", (expr) => {
hooks.evaluateIdentifier.tap("imported var.moduleName", TAP_NAME, (expr) => {
if (expr.property.name === "moduleName" &&
expr.object.name === "PLATFORM" &&
expr.object.type === "Identifier") {
Expand All @@ -44,7 +46,7 @@ class ParserPlugin {
// Or (note: no renaming supported):
// const PLATFORM = require("aurelia-pal").PLATFORM;
// PLATFORM.moduleName("id");
parser.plugin("evaluate MemberExpression", (expr) => {
hooks.evaluate.tap("MemberExpression", TAP_NAME, expr => {
if (expr.property.name === "moduleName" &&
(expr.object.type === "MemberExpression" && expr.object.property.name === "PLATFORM" ||
expr.object.type === "Identifier" && expr.object.name === "PLATFORM")) {
Expand All @@ -53,7 +55,7 @@ class ParserPlugin {
return undefined;
});
for (let method of this.methods) {
parser.plugin("call " + method, (expr) => {
hooks.call.tap(method, TAP_NAME, (expr) => {
if (expr.arguments.length === 0 || expr.arguments.length > 2)
return;
let [arg1, arg2] = expr.arguments;
Expand Down Expand Up @@ -109,12 +111,12 @@ class AureliaDependenciesPlugin {
this.parserPlugin = new ParserPlugin(methods);
}
apply(compiler) {
compiler.plugin("compilation", (compilation, params) => {
compiler.hooks.compilation.tap(TAP_NAME, (compilation, params) => {
const normalModuleFactory = params.normalModuleFactory;
compilation.dependencyFactories.set(AureliaDependency, normalModuleFactory);
compilation.dependencyTemplates.set(AureliaDependency, new Template());
normalModuleFactory.plugin("parser", parser => {
parser.apply(this.parserPlugin);
normalModuleFactory.hooks.parser.for("javascript/auto").tap(TAP_NAME, parser => {
this.parserPlugin.apply(parser);
});
});
}
Expand Down
22 changes: 10 additions & 12 deletions dist/AureliaPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ class AureliaPlugin {
}
if (opts.includeAll) {
// Grab everything approach
compiler.apply(
// This plugin ensures that everything in /src is included in the bundle.
// This prevents splitting in several chunks but is super easy to use and setup,
// no change in existing code or PLATFORM.nameModule() calls are required.
new GlobDependenciesPlugin_1.GlobDependenciesPlugin({ [emptyEntryModule]: opts.includeAll + "/**" }));
new GlobDependenciesPlugin_1.GlobDependenciesPlugin({ [emptyEntryModule]: opts.includeAll + "/**" }).apply(compiler);
needsEmptyEntry = true;
}
else if (opts.aureliaApp) {
Expand All @@ -122,7 +121,7 @@ class AureliaPlugin {
let aureliaModules = dllRefPlugins.map(plugin => {
let content = plugin["options"].manifest.content;
return Object.keys(content)
.map(k => content[k].meta["aurelia-id"])
.map(k => content[k].buildMeta["aurelia-id"])
.filter(id => !!id);
});
globalDependencies = globalDependencies.concat(...aureliaModules);
Expand All @@ -140,7 +139,7 @@ class AureliaPlugin {
rules.push({ test: /\.html?$/i, use: "aurelia-webpack-plugin/html-requires-loader" });
}
if (!opts.noInlineView) {
compiler.apply(new InlineViewDependenciesPlugin_1.InlineViewDependenciesPlugin());
new InlineViewDependenciesPlugin_1.InlineViewDependenciesPlugin().apply(compiler);
}
if (globalDependencies.length > 0) {
dependencies[emptyEntryModule] = globalDependencies;
Expand All @@ -149,25 +148,24 @@ class AureliaPlugin {
if (needsEmptyEntry) {
this.addEntry(compiler.options, emptyEntryModule);
}
compiler.apply(
// Aurelia libs contain a few global defines to cut out unused features
new webpack_1.DefinePlugin(defines),
new webpack_1.DefinePlugin(defines).apply(compiler);
// Adds some dependencies that are not documented by `PLATFORM.moduleName`
new ModuleDependenciesPlugin_1.ModuleDependenciesPlugin(dependencies),
new ModuleDependenciesPlugin_1.ModuleDependenciesPlugin(dependencies).apply(compiler);
// This plugin traces dependencies in code that are wrapped in PLATFORM.moduleName() calls
new AureliaDependenciesPlugin_1.AureliaDependenciesPlugin(...opts.moduleMethods),
new AureliaDependenciesPlugin_1.AureliaDependenciesPlugin(...opts.moduleMethods).apply(compiler);
// This plugin adds dependencies traced by html-requires-loader
// Note: the config extension point for this one is html-requires-loader.attributes.
new HtmlDependenciesPlugin_1.HtmlDependenciesPlugin(),
new HtmlDependenciesPlugin_1.HtmlDependenciesPlugin().apply(compiler);
// This plugin looks for companion files by swapping extensions,
// e.g. the view of a ViewModel. @useView and co. should use PLATFORM.moduleName().
// We use it always even with `includeAll` because libs often don't `@useView` (they should).
new ConventionDependenciesPlugin_1.ConventionDependenciesPlugin(opts.viewsFor, opts.viewsExtensions),
new ConventionDependenciesPlugin_1.ConventionDependenciesPlugin(opts.viewsFor, opts.viewsExtensions).apply(compiler);
// This plugin preserves module names for dynamic loading by aurelia-loader
new PreserveModuleNamePlugin_1.PreserveModuleNamePlugin(dllPlugin),
new PreserveModuleNamePlugin_1.PreserveModuleNamePlugin(dllPlugin).apply(compiler);
// This plugin supports preserving specific exports names when dynamically loading modules
// with aurelia-loader, while still enabling tree shaking all other exports.
new PreserveExportsPlugin_1.PreserveExportsPlugin());
new PreserveExportsPlugin_1.PreserveExportsPlugin().apply(compiler);
}
addEntry(options, modules) {
let webpackEntry = options.entry;
Expand Down
5 changes: 3 additions & 2 deletions dist/BaseIncludePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Object.defineProperty(exports, "__esModule", { value: true });
const IncludeDependency_1 = require("./IncludeDependency");
const NullDependency = require("webpack/lib/dependencies/NullDependency");
const TAP_NAME = "Aurelia:BaseInclude";
class BaseIncludePlugin {
apply(compiler) {
compiler.plugin("compilation", (compilation, data) => {
compiler.hooks.compilation.tap(TAP_NAME, (compilation, data) => {
const normalModuleFactory = data.normalModuleFactory;
compilation.dependencyFactories.set(IncludeDependency_1.IncludeDependency, normalModuleFactory);
compilation.dependencyTemplates.set(IncludeDependency_1.IncludeDependency, new NullDependency.Template());
normalModuleFactory.plugin("parser", parser => {
normalModuleFactory.hooks.parser.for("javascript/auto").tap(TAP_NAME, parser => {
function addDependency(request) {
let options = typeof request === 'object' ? request : undefined;
let name = options ? options.name : request;
Expand Down
2 changes: 1 addition & 1 deletion dist/ConventionDependenciesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ConventionDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin
}
parser(compilation, parser, addDependency) {
const root = path.resolve();
parser.plugin("program", () => {
parser.hooks.program.tap("Aurelia:ConventionDependencies", () => {
const { resource: file, rawRequest } = parser.state.current;
if (!file)
return;
Expand Down
7 changes: 4 additions & 3 deletions dist/DistPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
// This plugin tries to convert a request containing `/dist/xxx/` to the configured distribution if it exists.
// For example new DistPlugin('native-modules') will turn
// ./dist/commonjs/aurelia-framework.js
Expand All @@ -9,7 +10,6 @@
// if the alternate distribution does not exist.
// The alias configuration above will fail the build if a third party lib also uses ./dist/commonjs
// but does not include a ./dist/native-modules
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DistPlugin {
constructor(dist) {
Expand All @@ -18,12 +18,13 @@ class DistPlugin {
apply(resolver) {
if (!this.dist)
return;
resolver.plugin("before-described-resolve", (request, cb) => {
resolver.getHook("before-described-resolve")
.tapAsync("Aurelia:Dist", (request, resolveContext, cb) => {
// If the request contains /dist/xxx/, try /dist/{dist}/ first
let rewritten = request.request.replace(/\/dist\/[^/]+\//i, this.dist);
if (rewritten !== request.request) {
let newRequest = Object.assign({}, request, { request: rewritten });
resolver.doResolve("described-resolve", newRequest, "try alternate " + this.dist, cb);
resolver.doResolve(resolver.getHook("described-resolve"), newRequest, "try alternate " + this.dist, {}, cb);
}
else
cb(); // Path does not contain /dist/xxx/, continue normally
Expand Down
17 changes: 8 additions & 9 deletions dist/GlobDependenciesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const BaseIncludePlugin_1 = require("./BaseIncludePlugin");
const minimatch_1 = require("minimatch");
const path = require("path");
const TAP_NAME = "Aurelia:GlobDependencies";
function* findFiles(root, glob, fs) {
// An easiest, naive approach consist of listing all files and then pass them through minimatch.
// This is a bad idea as `root` typically includes node_modules, which can contain *lots* of files.
Expand Down Expand Up @@ -47,19 +48,17 @@ class GlobDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
const hashKeys = Object.getOwnPropertyNames(this.hash);
if (hashKeys.length === 0)
return;
compiler.plugin("before-compile", (params, cb) => {
compiler.hooks.beforeCompile.tapPromise(TAP_NAME, () => {
// Map the modules passed in ctor to actual resources (files) so that we can
// recognize them no matter what the rawRequest was (loaders, relative paths, etc.)
this.modules = {};
const resolve = compiler.resolvers.normal.resolve.bind(compiler.resolvers.normal, null, this.root);
let countdown = hashKeys.length;
for (let module of hashKeys) {
resolve(module, (err, resource) => {
const resolver = compiler.resolverFactory.get("normal", {});
return Promise.all(hashKeys.map(module => new Promise(resolve => {
resolver.resolve(null, this.root, module, {}, (err, resource) => {
this.modules[resource] = this.hash[module];
if (--countdown === 0)
cb();
resolve();
});
}
})));
});
super.apply(compiler);
}
Expand All @@ -70,7 +69,7 @@ class GlobDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
const normalizers = resolveFolders.map(x => path.relative(this.root, x))
.filter(x => !x.startsWith(".."))
.map(x => new RegExp("^" + x + "/", "ig"));
parser.plugin("program", () => {
parser.hooks.program.tap(TAP_NAME, () => {
const globs = this.modules[parser.state.module.resource];
if (!globs)
return;
Expand Down
2 changes: 1 addition & 1 deletion dist/HtmlDependenciesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const BaseIncludePlugin_1 = require("./BaseIncludePlugin");
const html_requires_loader_1 = require("./html-requires-loader");
class HtmlDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
parser(compilation, parser, addDependency) {
parser.plugin("program", () => {
parser.hooks.program.tap("Aurelia:HtmlDependencies", () => {
const deps = parser.state.current[html_requires_loader_1.htmlSymbol];
if (!deps)
return;
Expand Down
7 changes: 4 additions & 3 deletions dist/InlineViewDependenciesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const BaseIncludePlugin_1 = require("./BaseIncludePlugin");
const BasicEvaluatedExpression = require("webpack/lib/BasicEvaluatedExpression");
const htmlLoader = require("./html-requires-loader");
const TAP_NAME = "Aurelia:InlineViewDependencies";
class InlineViewDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
parser(compilation, parser, add) {
// The parser will only apply "call inlineView" on free variables.
Expand All @@ -13,7 +14,7 @@ class InlineViewDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin
// This covers native ES module, for example:
// import { inlineView } from "aurelia-framework";
// inlineView("<template>");
parser.plugin("evaluate Identifier imported var", (expr) => {
parser.hooks.evaluateIdentifier.tap("imported var", TAP_NAME, (expr) => {
if (expr.name === "inlineView") {
return new BasicEvaluatedExpression().setIdentifier("inlineView").setRange(expr.range);
}
Expand All @@ -25,13 +26,13 @@ class InlineViewDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin
// Or (note: no renaming supported):
// const inlineView = require("aurelia-framework").inlineView;
// inlineView("<template>");
parser.plugin("evaluate MemberExpression", (expr) => {
parser.hooks.evaluate.tap("MemberExpression", TAP_NAME, expr => {
if (expr.property.name === "inlineView") {
return new BasicEvaluatedExpression().setIdentifier("inlineView").setRange(expr.range);
}
return undefined;
});
parser.plugin("call inlineView", (expr) => {
parser.hooks.call.tap("inlineView", TAP_NAME, expr => {
if (expr.arguments.length !== 1)
return;
let arg1 = expr.arguments[0];
Expand Down
17 changes: 8 additions & 9 deletions dist/ModuleDependenciesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const BaseIncludePlugin_1 = require("./BaseIncludePlugin");
const path = require("path");
const TAP_NAME = "Aurelia:ModuleDependencies";
;
class ModuleDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
/**
Expand Down Expand Up @@ -29,24 +30,22 @@ class ModuleDependenciesPlugin extends BaseIncludePlugin_1.BaseIncludePlugin {
const hashKeys = Object.getOwnPropertyNames(this.hash);
if (hashKeys.length === 0)
return;
compiler.plugin("before-compile", (params, cb) => {
compiler.hooks.beforeCompile.tapPromise(TAP_NAME, () => {
// Map the modules passed in ctor to actual resources (files) so that we can
// recognize them no matter what the rawRequest was (loaders, relative paths, etc.)
this.modules = {};
const resolve = compiler.resolvers.normal.resolve.bind(compiler.resolvers.normal, null, this.root);
let countdown = hashKeys.length;
for (let module of hashKeys) {
resolve(module, (err, resource) => {
const resolver = compiler.resolverFactory.get("normal", {});
return Promise.all(hashKeys.map(module => new Promise(resolve => {
resolver.resolve(null, this.root, module, {}, (err, resource) => {
this.modules[resource] = this.hash[module];
if (--countdown === 0)
cb();
resolve();
});
}
})));
});
super.apply(compiler);
}
parser(compilation, parser, addDependency) {
parser.plugin("program", () => {
parser.hooks.program.tap(TAP_NAME, () => {
// We try to match the resource, or the initial module request.
const deps = this.modules[parser.state.module.resource];
if (deps)
Expand Down
5 changes: 3 additions & 2 deletions dist/PreserveExportsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.dependencyImports = Symbol();
const moduleExports = Symbol();
const nativeIsUsed = Symbol();
const TAP_NAME = "Aurelia:PreserveExports";
function getModuleExports(module) {
let set = module[moduleExports];
if (!set) {
Expand All @@ -18,8 +19,8 @@ function getModuleExports(module) {
}
class PreserveExportsPlugin {
apply(compiler) {
compiler.plugin("compilation", compilation => {
compilation.plugin("finish-modules", modules => {
compiler.hooks.compilation.tap(TAP_NAME, compilation => {
compilation.hooks.finishModules.tap(TAP_NAME, modules => {
for (let module of modules) {
for (let reason of module.reasons) {
let dep = reason.dependency;
Expand Down
11 changes: 6 additions & 5 deletions dist/PreserveModuleNamePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
exports.preserveModuleName = Symbol();
const TAP_NAME = "Aurelia:PreserveModuleName";
// This plugins preserves the module names of IncludeDependency and
// AureliaDependency so that they can be dynamically requested by
// aurelia-loader.
Expand All @@ -12,8 +13,8 @@ class PreserveModuleNamePlugin {
this.isDll = isDll;
}
apply(compiler) {
compiler.plugin("compilation", compilation => {
compilation.plugin("before-module-ids", modules => {
compiler.hooks.compilation.tap(TAP_NAME, compilation => {
compilation.hooks.beforeModuleIds.tap(TAP_NAME, modules => {
let { modules: roots, extensions, alias } = compilation.options.resolve;
roots = roots.map(x => path.resolve(x));
const normalizers = extensions.map(x => new RegExp(x.replace(/\./g, "\\.") + "$", "i"));
Expand Down Expand Up @@ -48,8 +49,8 @@ class PreserveModuleNamePlugin {
if (/^async[?!]/.test(realModule.rawRequest))
id = "async!" + id;
id = id.replace(/\\/g, "/");
if (module.meta)
module.meta["aurelia-id"] = id;
if (module.buildMeta)
module.buildMeta["aurelia-id"] = id;
if (!this.isDll)
module.id = id;
}
Expand All @@ -64,7 +65,7 @@ function getPreservedModules(modules) {
// Some modules might have [preserveModuleName] already set, see ConventionDependenciesPlugin.
let value = m[exports.preserveModuleName];
for (let r of m.reasons) {
if (!r.dependency[exports.preserveModuleName])
if (!r.dependency || !r.dependency[exports.preserveModuleName])
continue;
value = true;
let req = removeLoaders(r.dependency.request);
Expand Down
Loading

0 comments on commit 99fe0dc

Please sign in to comment.