├── .editorconfig
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .npmignore
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE.md
├── LICENSE
├── README.md
├── bower.json
├── dist
├── amd
│ └── aurelia-loader-webpack.js
├── commonjs
│ └── aurelia-loader-webpack.js
├── es2015
│ └── aurelia-loader-webpack.js
├── es2017
│ └── aurelia-loader-webpack.js
├── native-modules
│ └── aurelia-loader-webpack.js
├── system
│ ├── aurelia-loader-webpack.d.ts
│ └── aurelia-loader-webpack.js
└── types
│ └── aurelia-loader-webpack.d.ts
├── doc
├── CHANGELOG.md
└── MAINTAINER.md
├── package-lock.json
├── package.json
├── rollup.config.js
├── src
├── aurelia-loader-webpack.ts
└── webpack-runtime.d.ts
├── tsconfig.build.json
├── tsconfig.json
└── typings.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Unix-style newlines with a newline ending every file
7 | [*]
8 | end_of_line = lf
9 | insert_final_newline = true
10 |
11 | # 2 space indentation
12 | [**.*]
13 | indent_style = space
14 | indent_size = 2
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: main
2 | on: [push]
3 |
4 | jobs:
5 |
6 | ci:
7 | timeout-minutes: 10
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v2
11 | - uses: actions/setup-node@v1
12 | with:
13 | node-version: 14
14 | - run: npm ci
15 | - run: npm run cut-release
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | jspm_packages
3 | bower_components
4 | .idea
5 | .DS_STORE
6 | build/reports
7 | .npmrc
8 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | jspm_packages
2 | bower_components
3 | .idea
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | We'd love for you to contribute and to make this project even better than it is today! If this interests you, please begin by reading [our contributing guidelines](https://github.com/DurandalProject/about/blob/master/CONTRIBUTING.md). The contributing document will provide you with all the information you need to get started. Once you have read that, you will need to also [sign our CLA](http://goo.gl/forms/dI8QDDSyKR) before we can accept a Pull Request from you. More information on the process is included in the [contributor's guide](https://github.com/DurandalProject/about/blob/master/CONTRIBUTING.md).
4 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
19 | **I'm submitting a bug report**
20 | **I'm submitting a feature request**
21 |
22 | * **Library Version:**
23 | major.minor.patch-pre
24 |
25 |
26 | **Please tell us about your environment:**
27 | * **Operating System:**
28 | OSX 10.x|Linux (distro)|Windows [7|8|8.1|10]
29 |
30 | * **Node Version:**
31 | 6.2.0
32 |
36 |
37 | * **NPM Version:**
38 | 3.8.9
39 |
43 |
44 | * **JSPM OR Webpack AND Version**
45 | JSPM 0.16.32 | webpack 2.1.0-beta.17
46 |
52 |
53 | * **Browser:**
54 | all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView
55 |
56 | * **Language:**
57 | all | TypeScript X.X | ESNext
58 |
59 |
60 | **Current behavior:**
61 |
62 |
63 | **Expected/desired behavior:**
64 |
71 |
72 |
73 | * **What is the expected behavior?**
74 |
75 |
76 | * **What is the motivation / use case for changing the behavior?**
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2010 - 2016 Blue Spire Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | [](https://opensource.org/licenses/MIT)
8 | [](https://www.npmjs.com/package/aurelia-loader-webpack)
9 | 
10 | [](https://discourse.aurelia.io)
11 | [](https://twitter.com/intent/follow?screen_name=aureliaeffect)
12 | [](https://discord.gg/RBtyM6u)
13 |
14 | # aurelia-loader-webpack
15 |
16 | This library is part of the [Aurelia](http://www.aurelia.io/) platform and contains an implementation of Aurelia's loader interface to enable webpack.
17 |
18 | > To keep up to date on [Aurelia](http://www.aurelia.io/), please visit and subscribe to [the official blog](http://blog.aurelia.io/) and [our email list](http://eepurl.com/ces50j). We also invite you to [follow us on twitter](https://twitter.com/aureliaeffect). If you have questions look around our [Discourse forums](https://discourse.aurelia.io/), chat in our [community on Discord](https://discord.gg/RBtyM6u) or use [stack overflow](http://stackoverflow.com/search?q=aurelia). Documentation can be found [in our developer hub](http://aurelia.io/docs).
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aurelia-loader-webpack",
3 | "version": "2.2.6",
4 | "description": "An implementation of Aurelia's loader interface to enable webpack.",
5 | "keywords": [
6 | "aurelia",
7 | "webpack",
8 | "loader"
9 | ],
10 | "homepage": "http://aurelia.io",
11 | "main": "dist/commonjs/aurelia-loader-webpack.js",
12 | "moduleType": "node",
13 | "bugs": {
14 | "url": "https://github.com/aurelia/loader-webpack/issues"
15 | },
16 | "license": "MIT",
17 | "author": "Rob Eisenberg (http://robeisenberg.com/)",
18 | "repository": {
19 | "type": "git",
20 | "url": "http://github.com/aurelia/loader-webpack"
21 | },
22 | "dependencies": {
23 | "aurelia-loader": "^1.0.0",
24 | "aurelia-metadata": "^1.0.0",
25 | "aurelia-pal": "^1.0.0",
26 | "aurelia-path": "^1.0.0"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/dist/amd/aurelia-loader-webpack.js:
--------------------------------------------------------------------------------
1 | define('aurelia-loader-webpack', ['exports', 'aurelia-loader', 'aurelia-metadata', 'aurelia-pal'], function (exports, aureliaLoader, aureliaMetadata, aureliaPal) { 'use strict';
2 |
3 | /******************************************************************************
4 | Copyright (c) Microsoft Corporation.
5 |
6 | Permission to use, copy, modify, and/or distribute this software for any
7 | purpose with or without fee is hereby granted.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 | PERFORMANCE OF THIS SOFTWARE.
16 | ***************************************************************************** */
17 | /* global Reflect, Promise */
18 |
19 | var extendStatics = function(d, b) {
20 | extendStatics = Object.setPrototypeOf ||
21 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23 | return extendStatics(d, b);
24 | };
25 |
26 | function __extends(d, b) {
27 | if (typeof b !== "function" && b !== null)
28 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29 | extendStatics(d, b);
30 | function __() { this.constructor = d; }
31 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32 | }
33 |
34 | function __awaiter(thisArg, _arguments, P, generator) {
35 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36 | return new (P || (P = Promise))(function (resolve, reject) {
37 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40 | step((generator = generator.apply(thisArg, _arguments || [])).next());
41 | });
42 | }
43 |
44 | function __generator(thisArg, body) {
45 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
46 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47 | function verb(n) { return function (v) { return step([n, v]); }; }
48 | function step(op) {
49 | if (f) throw new TypeError("Generator is already executing.");
50 | while (_) try {
51 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52 | if (y = 0, t) op = [op[0] & 2, t.value];
53 | switch (op[0]) {
54 | case 0: case 1: t = op; break;
55 | case 4: _.label++; return { value: op[1], done: false };
56 | case 5: _.label++; y = op[1]; op = [0]; continue;
57 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
58 | default:
59 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63 | if (t[2]) _.ops.pop();
64 | _.trys.pop(); continue;
65 | }
66 | op = body.call(thisArg, _);
67 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69 | }
70 | }
71 |
72 | /**
73 | * An implementation of the TemplateLoader interface implemented with text-based loading.
74 | */
75 | var TextTemplateLoader = /** @class */ (function () {
76 | function TextTemplateLoader() {
77 | }
78 | /**
79 | * Loads a template.
80 | * @param loader The loader that is requesting the template load.
81 | * @param entry The TemplateRegistryEntry to load and populate with a template.
82 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
83 | */
84 | TextTemplateLoader.prototype.loadTemplate = function (loader, entry) {
85 | return __awaiter(this, void 0, void 0, function () {
86 | var text;
87 | return __generator(this, function (_a) {
88 | switch (_a.label) {
89 | case 0: return [4 /*yield*/, loader.loadText(entry.address)];
90 | case 1:
91 | text = _a.sent();
92 | entry.template = aureliaPal.DOM.createTemplateFromMarkup(text);
93 | return [2 /*return*/];
94 | }
95 | });
96 | });
97 | };
98 | return TextTemplateLoader;
99 | }());
100 | function ensureOriginOnExports(moduleExports, moduleId) {
101 | var target = moduleExports;
102 | var key;
103 | var exportedValue;
104 | if (target.__useDefault) {
105 | target = target.default;
106 | }
107 | aureliaMetadata.Origin.set(target, new aureliaMetadata.Origin(moduleId, 'default'));
108 | if (typeof target === 'object') {
109 | for (key in target) {
110 | exportedValue = target[key];
111 | if (typeof exportedValue === 'function') {
112 | aureliaMetadata.Origin.set(exportedValue, new aureliaMetadata.Origin(moduleId, key));
113 | }
114 | }
115 | }
116 | return moduleExports;
117 | }
118 | /**
119 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
120 | */
121 | var WebpackLoader = /** @class */ (function (_super) {
122 | __extends(WebpackLoader, _super);
123 | function WebpackLoader() {
124 | var _this = _super.call(this) || this;
125 | _this.moduleRegistry = Object.create(null);
126 | _this.loaderPlugins = Object.create(null);
127 | _this.modulesBeingLoaded = new Map();
128 | _this.useTemplateLoader(new TextTemplateLoader());
129 | _this.addPlugin('template-registry-entry', {
130 | fetch: function (moduleId) { return __awaiter(_this, void 0, void 0, function () {
131 | var HmrContext, entry;
132 | var _this = this;
133 | return __generator(this, function (_a) {
134 | switch (_a.label) {
135 | case 0:
136 | // HMR:
137 | if (module.hot) {
138 | if (!this.hmrContext) {
139 | HmrContext = require('aurelia-hot-module-reload').HmrContext;
140 | this.hmrContext = new HmrContext(this);
141 | }
142 | module.hot.accept(moduleId, function () { return __awaiter(_this, void 0, void 0, function () {
143 | return __generator(this, function (_a) {
144 | switch (_a.label) {
145 | case 0: return [4 /*yield*/, this.hmrContext.handleViewChange(moduleId)];
146 | case 1:
147 | _a.sent();
148 | return [2 /*return*/];
149 | }
150 | });
151 | }); });
152 | }
153 | entry = this.getOrCreateTemplateRegistryEntry(moduleId);
154 | if (!!entry.templateIsLoaded) return [3 /*break*/, 2];
155 | return [4 /*yield*/, this.templateLoader.loadTemplate(this, entry)];
156 | case 1:
157 | _a.sent();
158 | _a.label = 2;
159 | case 2: return [2 /*return*/, entry];
160 | }
161 | });
162 | }); }
163 | });
164 | aureliaPal.PLATFORM.eachModule = function (callback) {
165 | var registry = __webpack_require__.c;
166 | var cachedModuleIds = Object.getOwnPropertyNames(registry);
167 | cachedModuleIds
168 | // Note: we use .some here like a .forEach that can be "break"ed out of.
169 | // It will stop iterating only when a truthy value is returned.
170 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
171 | // and this is to keep it consistent with that.
172 | .some(function (moduleId) {
173 | var moduleExports = registry[moduleId].exports;
174 | if (typeof moduleExports === 'object') {
175 | return callback(moduleId, moduleExports);
176 | }
177 | return false;
178 | });
179 | };
180 | return _this;
181 | }
182 | WebpackLoader.prototype._import = function (address, defaultHMR) {
183 | if (defaultHMR === void 0) { defaultHMR = true; }
184 | return __awaiter(this, void 0, void 0, function () {
185 | var addressParts, moduleId, loaderPlugin, plugin_1, asyncModuleId, callback;
186 | var _this = this;
187 | return __generator(this, function (_a) {
188 | switch (_a.label) {
189 | case 0:
190 | addressParts = address.split('!');
191 | moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
192 | loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
193 | if (!loaderPlugin) return [3 /*break*/, 2];
194 | plugin_1 = this.loaderPlugins[loaderPlugin];
195 | if (!plugin_1) {
196 | throw new Error("Plugin " + loaderPlugin + " is not registered in the loader.");
197 | }
198 | if (module.hot && plugin_1.hot) {
199 | module.hot.accept(moduleId, function () { return plugin_1.hot(moduleId); });
200 | }
201 | return [4 /*yield*/, plugin_1.fetch(moduleId)];
202 | case 1: return [2 /*return*/, _a.sent()];
203 | case 2:
204 | if (__webpack_require__.m[moduleId]) {
205 | if (defaultHMR && module.hot && this.hmrContext) {
206 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
207 | }
208 | return [2 /*return*/, __webpack_require__(moduleId)];
209 | }
210 | asyncModuleId = "async!" + moduleId;
211 | if (!__webpack_require__.m[asyncModuleId]) return [3 /*break*/, 4];
212 | if (defaultHMR && module.hot && this.hmrContext) {
213 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
214 | module.hot.accept(asyncModuleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
215 | }
216 | callback = __webpack_require__(asyncModuleId);
217 | return [4 /*yield*/, new Promise(callback)];
218 | case 3: return [2 /*return*/, _a.sent()];
219 | case 4: throw new Error("Unable to find module with ID: " + moduleId);
220 | }
221 | });
222 | });
223 | };
224 | /**
225 | * Maps a module id to a source.
226 | * @param id The module id.
227 | * @param source The source to map the module to.
228 | */
229 | WebpackLoader.prototype.map = function (id, source) { };
230 | /**
231 | * Normalizes a module id.
232 | * @param moduleId The module id to normalize.
233 | * @param relativeTo What the module id should be normalized relative to.
234 | * @return The normalized module id.
235 | */
236 | WebpackLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
237 | return moduleId;
238 | };
239 | /**
240 | * Normalizes a module id.
241 | * @param moduleId The module id to normalize.
242 | * @param relativeTo What the module id should be normalized relative to.
243 | * @return The normalized module id.
244 | */
245 | WebpackLoader.prototype.normalize = function (moduleId, relativeTo) {
246 | return Promise.resolve(moduleId);
247 | };
248 | /**
249 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
250 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
251 | */
252 | WebpackLoader.prototype.useTemplateLoader = function (templateLoader) {
253 | this.templateLoader = templateLoader;
254 | };
255 | /**
256 | * Loads a collection of modules.
257 | * @param ids The set of module ids to load.
258 | * @return A Promise for an array of loaded modules.
259 | */
260 | WebpackLoader.prototype.loadAllModules = function (ids) {
261 | var _this = this;
262 | return Promise.all(ids.map(function (id) { return _this.loadModule(id); }));
263 | };
264 | /**
265 | * Loads a module.
266 | * @param moduleId The module ID to load.
267 | * @return A Promise for the loaded module.
268 | */
269 | WebpackLoader.prototype.loadModule = function (moduleId, defaultHMR) {
270 | if (defaultHMR === void 0) { defaultHMR = true; }
271 | return __awaiter(this, void 0, void 0, function () {
272 | var existing, beingLoaded, moduleExports;
273 | return __generator(this, function (_a) {
274 | switch (_a.label) {
275 | case 0:
276 | existing = this.moduleRegistry[moduleId];
277 | if (existing) {
278 | return [2 /*return*/, existing];
279 | }
280 | beingLoaded = this.modulesBeingLoaded.get(moduleId);
281 | if (beingLoaded) {
282 | return [2 /*return*/, beingLoaded];
283 | }
284 | beingLoaded = this._import(moduleId, defaultHMR);
285 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
286 | return [4 /*yield*/, beingLoaded];
287 | case 1:
288 | moduleExports = _a.sent();
289 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
290 | this.modulesBeingLoaded.delete(moduleId);
291 | return [2 /*return*/, moduleExports];
292 | }
293 | });
294 | });
295 | };
296 | /**
297 | * Loads a template.
298 | * @param url The url of the template to load.
299 | * @return A Promise for a TemplateRegistryEntry containing the template.
300 | */
301 | WebpackLoader.prototype.loadTemplate = function (url) {
302 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
303 | };
304 | /**
305 | * Loads a text-based resource.
306 | * @param url The url of the text file to load.
307 | * @return A Promise for text content.
308 | */
309 | WebpackLoader.prototype.loadText = function (url) {
310 | return __awaiter(this, void 0, void 0, function () {
311 | var result, defaultExport;
312 | return __generator(this, function (_a) {
313 | switch (_a.label) {
314 | case 0: return [4 /*yield*/, this.loadModule(url, false)];
315 | case 1:
316 | result = _a.sent();
317 | defaultExport = result && result.__esModule ? result.default : result;
318 | if (this.isCssLoaderModule(defaultExport)) {
319 | // we're dealing with a file loaded using the css-loader:
320 | return [2 /*return*/, this.getCssText(defaultExport)];
321 | }
322 | return [2 /*return*/, typeof result === "string" ? result : defaultExport];
323 | }
324 | });
325 | });
326 | };
327 | /**
328 | * Check if a loaded module is a css-loader module
329 | * @param o The loaded module
330 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
331 | */
332 | WebpackLoader.prototype.isCssLoaderModule = function (o) {
333 | return o instanceof Array && o[0] instanceof Array && o.hasOwnProperty('toString');
334 | };
335 | /**
336 | * Get CSS text from loaded css-loader module
337 | * @param cssLoaderModule The {@link CssLoaderModule}
338 | * @returns The css content with potential source map references
339 | */
340 | WebpackLoader.prototype.getCssText = function (cssLoaderModule) {
341 | var result = cssLoaderModule.toString();
342 | // If some css-loader modules include source maps,
343 | // ensure /*# sourceURL=[...] */ is removed to avoid chrome devtools problems
344 | if (cssLoaderModule.some(function (m) { return m[3]; })) {
345 | result = result.replace(/^\/\*# sourceURL=.* \*\/\s*\n/gm, "");
346 | }
347 | return result;
348 | };
349 | /**
350 | * Alters a module id so that it includes a plugin loader.
351 | * @param url The url of the module to load.
352 | * @param pluginName The plugin to apply to the module id.
353 | * @return The plugin-based module id.
354 | */
355 | WebpackLoader.prototype.applyPluginToUrl = function (url, pluginName) {
356 | return pluginName + "!" + url;
357 | };
358 | /**
359 | * Registers a plugin with the loader.
360 | * @param pluginName The name of the plugin.
361 | * @param implementation The plugin implementation.
362 | */
363 | WebpackLoader.prototype.addPlugin = function (pluginName, implementation) {
364 | this.loaderPlugins[pluginName] = implementation;
365 | };
366 | return WebpackLoader;
367 | }(aureliaLoader.Loader));
368 | aureliaPal.PLATFORM.Loader = WebpackLoader;
369 |
370 | exports.TextTemplateLoader = TextTemplateLoader;
371 | exports.WebpackLoader = WebpackLoader;
372 | exports.ensureOriginOnExports = ensureOriginOnExports;
373 |
374 | Object.defineProperty(exports, '__esModule', { value: true });
375 |
376 | });
377 |
--------------------------------------------------------------------------------
/dist/commonjs/aurelia-loader-webpack.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, '__esModule', { value: true });
4 |
5 | var aureliaLoader = require('aurelia-loader');
6 | var aureliaMetadata = require('aurelia-metadata');
7 | var aureliaPal = require('aurelia-pal');
8 |
9 | /******************************************************************************
10 | Copyright (c) Microsoft Corporation.
11 |
12 | Permission to use, copy, modify, and/or distribute this software for any
13 | purpose with or without fee is hereby granted.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 | PERFORMANCE OF THIS SOFTWARE.
22 | ***************************************************************************** */
23 | /* global Reflect, Promise */
24 |
25 | var extendStatics = function(d, b) {
26 | extendStatics = Object.setPrototypeOf ||
27 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29 | return extendStatics(d, b);
30 | };
31 |
32 | function __extends(d, b) {
33 | if (typeof b !== "function" && b !== null)
34 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
35 | extendStatics(d, b);
36 | function __() { this.constructor = d; }
37 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
38 | }
39 |
40 | function __awaiter(thisArg, _arguments, P, generator) {
41 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42 | return new (P || (P = Promise))(function (resolve, reject) {
43 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46 | step((generator = generator.apply(thisArg, _arguments || [])).next());
47 | });
48 | }
49 |
50 | function __generator(thisArg, body) {
51 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
52 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
53 | function verb(n) { return function (v) { return step([n, v]); }; }
54 | function step(op) {
55 | if (f) throw new TypeError("Generator is already executing.");
56 | while (_) try {
57 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58 | if (y = 0, t) op = [op[0] & 2, t.value];
59 | switch (op[0]) {
60 | case 0: case 1: t = op; break;
61 | case 4: _.label++; return { value: op[1], done: false };
62 | case 5: _.label++; y = op[1]; op = [0]; continue;
63 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
64 | default:
65 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
66 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
67 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
68 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
69 | if (t[2]) _.ops.pop();
70 | _.trys.pop(); continue;
71 | }
72 | op = body.call(thisArg, _);
73 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
74 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
75 | }
76 | }
77 |
78 | /**
79 | * An implementation of the TemplateLoader interface implemented with text-based loading.
80 | */
81 | var TextTemplateLoader = /** @class */ (function () {
82 | function TextTemplateLoader() {
83 | }
84 | /**
85 | * Loads a template.
86 | * @param loader The loader that is requesting the template load.
87 | * @param entry The TemplateRegistryEntry to load and populate with a template.
88 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
89 | */
90 | TextTemplateLoader.prototype.loadTemplate = function (loader, entry) {
91 | return __awaiter(this, void 0, void 0, function () {
92 | var text;
93 | return __generator(this, function (_a) {
94 | switch (_a.label) {
95 | case 0: return [4 /*yield*/, loader.loadText(entry.address)];
96 | case 1:
97 | text = _a.sent();
98 | entry.template = aureliaPal.DOM.createTemplateFromMarkup(text);
99 | return [2 /*return*/];
100 | }
101 | });
102 | });
103 | };
104 | return TextTemplateLoader;
105 | }());
106 | function ensureOriginOnExports(moduleExports, moduleId) {
107 | var target = moduleExports;
108 | var key;
109 | var exportedValue;
110 | if (target.__useDefault) {
111 | target = target.default;
112 | }
113 | aureliaMetadata.Origin.set(target, new aureliaMetadata.Origin(moduleId, 'default'));
114 | if (typeof target === 'object') {
115 | for (key in target) {
116 | exportedValue = target[key];
117 | if (typeof exportedValue === 'function') {
118 | aureliaMetadata.Origin.set(exportedValue, new aureliaMetadata.Origin(moduleId, key));
119 | }
120 | }
121 | }
122 | return moduleExports;
123 | }
124 | /**
125 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
126 | */
127 | var WebpackLoader = /** @class */ (function (_super) {
128 | __extends(WebpackLoader, _super);
129 | function WebpackLoader() {
130 | var _this = _super.call(this) || this;
131 | _this.moduleRegistry = Object.create(null);
132 | _this.loaderPlugins = Object.create(null);
133 | _this.modulesBeingLoaded = new Map();
134 | _this.useTemplateLoader(new TextTemplateLoader());
135 | _this.addPlugin('template-registry-entry', {
136 | fetch: function (moduleId) { return __awaiter(_this, void 0, void 0, function () {
137 | var HmrContext, entry;
138 | var _this = this;
139 | return __generator(this, function (_a) {
140 | switch (_a.label) {
141 | case 0:
142 | // HMR:
143 | if (module.hot) {
144 | if (!this.hmrContext) {
145 | HmrContext = require('aurelia-hot-module-reload').HmrContext;
146 | this.hmrContext = new HmrContext(this);
147 | }
148 | module.hot.accept(moduleId, function () { return __awaiter(_this, void 0, void 0, function () {
149 | return __generator(this, function (_a) {
150 | switch (_a.label) {
151 | case 0: return [4 /*yield*/, this.hmrContext.handleViewChange(moduleId)];
152 | case 1:
153 | _a.sent();
154 | return [2 /*return*/];
155 | }
156 | });
157 | }); });
158 | }
159 | entry = this.getOrCreateTemplateRegistryEntry(moduleId);
160 | if (!!entry.templateIsLoaded) return [3 /*break*/, 2];
161 | return [4 /*yield*/, this.templateLoader.loadTemplate(this, entry)];
162 | case 1:
163 | _a.sent();
164 | _a.label = 2;
165 | case 2: return [2 /*return*/, entry];
166 | }
167 | });
168 | }); }
169 | });
170 | aureliaPal.PLATFORM.eachModule = function (callback) {
171 | var registry = __webpack_require__.c;
172 | var cachedModuleIds = Object.getOwnPropertyNames(registry);
173 | cachedModuleIds
174 | // Note: we use .some here like a .forEach that can be "break"ed out of.
175 | // It will stop iterating only when a truthy value is returned.
176 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
177 | // and this is to keep it consistent with that.
178 | .some(function (moduleId) {
179 | var moduleExports = registry[moduleId].exports;
180 | if (typeof moduleExports === 'object') {
181 | return callback(moduleId, moduleExports);
182 | }
183 | return false;
184 | });
185 | };
186 | return _this;
187 | }
188 | WebpackLoader.prototype._import = function (address, defaultHMR) {
189 | if (defaultHMR === void 0) { defaultHMR = true; }
190 | return __awaiter(this, void 0, void 0, function () {
191 | var addressParts, moduleId, loaderPlugin, plugin_1, asyncModuleId, callback;
192 | var _this = this;
193 | return __generator(this, function (_a) {
194 | switch (_a.label) {
195 | case 0:
196 | addressParts = address.split('!');
197 | moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
198 | loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
199 | if (!loaderPlugin) return [3 /*break*/, 2];
200 | plugin_1 = this.loaderPlugins[loaderPlugin];
201 | if (!plugin_1) {
202 | throw new Error("Plugin " + loaderPlugin + " is not registered in the loader.");
203 | }
204 | if (module.hot && plugin_1.hot) {
205 | module.hot.accept(moduleId, function () { return plugin_1.hot(moduleId); });
206 | }
207 | return [4 /*yield*/, plugin_1.fetch(moduleId)];
208 | case 1: return [2 /*return*/, _a.sent()];
209 | case 2:
210 | if (__webpack_require__.m[moduleId]) {
211 | if (defaultHMR && module.hot && this.hmrContext) {
212 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
213 | }
214 | return [2 /*return*/, __webpack_require__(moduleId)];
215 | }
216 | asyncModuleId = "async!" + moduleId;
217 | if (!__webpack_require__.m[asyncModuleId]) return [3 /*break*/, 4];
218 | if (defaultHMR && module.hot && this.hmrContext) {
219 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
220 | module.hot.accept(asyncModuleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
221 | }
222 | callback = __webpack_require__(asyncModuleId);
223 | return [4 /*yield*/, new Promise(callback)];
224 | case 3: return [2 /*return*/, _a.sent()];
225 | case 4: throw new Error("Unable to find module with ID: " + moduleId);
226 | }
227 | });
228 | });
229 | };
230 | /**
231 | * Maps a module id to a source.
232 | * @param id The module id.
233 | * @param source The source to map the module to.
234 | */
235 | WebpackLoader.prototype.map = function (id, source) { };
236 | /**
237 | * Normalizes a module id.
238 | * @param moduleId The module id to normalize.
239 | * @param relativeTo What the module id should be normalized relative to.
240 | * @return The normalized module id.
241 | */
242 | WebpackLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
243 | return moduleId;
244 | };
245 | /**
246 | * Normalizes a module id.
247 | * @param moduleId The module id to normalize.
248 | * @param relativeTo What the module id should be normalized relative to.
249 | * @return The normalized module id.
250 | */
251 | WebpackLoader.prototype.normalize = function (moduleId, relativeTo) {
252 | return Promise.resolve(moduleId);
253 | };
254 | /**
255 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
256 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
257 | */
258 | WebpackLoader.prototype.useTemplateLoader = function (templateLoader) {
259 | this.templateLoader = templateLoader;
260 | };
261 | /**
262 | * Loads a collection of modules.
263 | * @param ids The set of module ids to load.
264 | * @return A Promise for an array of loaded modules.
265 | */
266 | WebpackLoader.prototype.loadAllModules = function (ids) {
267 | var _this = this;
268 | return Promise.all(ids.map(function (id) { return _this.loadModule(id); }));
269 | };
270 | /**
271 | * Loads a module.
272 | * @param moduleId The module ID to load.
273 | * @return A Promise for the loaded module.
274 | */
275 | WebpackLoader.prototype.loadModule = function (moduleId, defaultHMR) {
276 | if (defaultHMR === void 0) { defaultHMR = true; }
277 | return __awaiter(this, void 0, void 0, function () {
278 | var existing, beingLoaded, moduleExports;
279 | return __generator(this, function (_a) {
280 | switch (_a.label) {
281 | case 0:
282 | existing = this.moduleRegistry[moduleId];
283 | if (existing) {
284 | return [2 /*return*/, existing];
285 | }
286 | beingLoaded = this.modulesBeingLoaded.get(moduleId);
287 | if (beingLoaded) {
288 | return [2 /*return*/, beingLoaded];
289 | }
290 | beingLoaded = this._import(moduleId, defaultHMR);
291 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
292 | return [4 /*yield*/, beingLoaded];
293 | case 1:
294 | moduleExports = _a.sent();
295 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
296 | this.modulesBeingLoaded.delete(moduleId);
297 | return [2 /*return*/, moduleExports];
298 | }
299 | });
300 | });
301 | };
302 | /**
303 | * Loads a template.
304 | * @param url The url of the template to load.
305 | * @return A Promise for a TemplateRegistryEntry containing the template.
306 | */
307 | WebpackLoader.prototype.loadTemplate = function (url) {
308 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
309 | };
310 | /**
311 | * Loads a text-based resource.
312 | * @param url The url of the text file to load.
313 | * @return A Promise for text content.
314 | */
315 | WebpackLoader.prototype.loadText = function (url) {
316 | return __awaiter(this, void 0, void 0, function () {
317 | var result, defaultExport;
318 | return __generator(this, function (_a) {
319 | switch (_a.label) {
320 | case 0: return [4 /*yield*/, this.loadModule(url, false)];
321 | case 1:
322 | result = _a.sent();
323 | defaultExport = result && result.__esModule ? result.default : result;
324 | if (this.isCssLoaderModule(defaultExport)) {
325 | // we're dealing with a file loaded using the css-loader:
326 | return [2 /*return*/, this.getCssText(defaultExport)];
327 | }
328 | return [2 /*return*/, typeof result === "string" ? result : defaultExport];
329 | }
330 | });
331 | });
332 | };
333 | /**
334 | * Check if a loaded module is a css-loader module
335 | * @param o The loaded module
336 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
337 | */
338 | WebpackLoader.prototype.isCssLoaderModule = function (o) {
339 | return o instanceof Array && o[0] instanceof Array && o.hasOwnProperty('toString');
340 | };
341 | /**
342 | * Get CSS text from loaded css-loader module
343 | * @param cssLoaderModule The {@link CssLoaderModule}
344 | * @returns The css content with potential source map references
345 | */
346 | WebpackLoader.prototype.getCssText = function (cssLoaderModule) {
347 | var result = cssLoaderModule.toString();
348 | // If some css-loader modules include source maps,
349 | // ensure /*# sourceURL=[...] */ is removed to avoid chrome devtools problems
350 | if (cssLoaderModule.some(function (m) { return m[3]; })) {
351 | result = result.replace(/^\/\*# sourceURL=.* \*\/\s*\n/gm, "");
352 | }
353 | return result;
354 | };
355 | /**
356 | * Alters a module id so that it includes a plugin loader.
357 | * @param url The url of the module to load.
358 | * @param pluginName The plugin to apply to the module id.
359 | * @return The plugin-based module id.
360 | */
361 | WebpackLoader.prototype.applyPluginToUrl = function (url, pluginName) {
362 | return pluginName + "!" + url;
363 | };
364 | /**
365 | * Registers a plugin with the loader.
366 | * @param pluginName The name of the plugin.
367 | * @param implementation The plugin implementation.
368 | */
369 | WebpackLoader.prototype.addPlugin = function (pluginName, implementation) {
370 | this.loaderPlugins[pluginName] = implementation;
371 | };
372 | return WebpackLoader;
373 | }(aureliaLoader.Loader));
374 | aureliaPal.PLATFORM.Loader = WebpackLoader;
375 |
376 | exports.TextTemplateLoader = TextTemplateLoader;
377 | exports.WebpackLoader = WebpackLoader;
378 | exports.ensureOriginOnExports = ensureOriginOnExports;
379 |
--------------------------------------------------------------------------------
/dist/es2015/aurelia-loader-webpack.js:
--------------------------------------------------------------------------------
1 | import { Loader } from 'aurelia-loader';
2 | import { Origin } from 'aurelia-metadata';
3 | import { PLATFORM, DOM } from 'aurelia-pal';
4 |
5 | /******************************************************************************
6 | Copyright (c) Microsoft Corporation.
7 |
8 | Permission to use, copy, modify, and/or distribute this software for any
9 | purpose with or without fee is hereby granted.
10 |
11 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 | PERFORMANCE OF THIS SOFTWARE.
18 | ***************************************************************************** */
19 |
20 | function __awaiter(thisArg, _arguments, P, generator) {
21 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22 | return new (P || (P = Promise))(function (resolve, reject) {
23 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26 | step((generator = generator.apply(thisArg, _arguments || [])).next());
27 | });
28 | }
29 |
30 | /**
31 | * An implementation of the TemplateLoader interface implemented with text-based loading.
32 | */
33 | class TextTemplateLoader {
34 | /**
35 | * Loads a template.
36 | * @param loader The loader that is requesting the template load.
37 | * @param entry The TemplateRegistryEntry to load and populate with a template.
38 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
39 | */
40 | loadTemplate(loader, entry) {
41 | return __awaiter(this, void 0, void 0, function* () {
42 | const text = yield loader.loadText(entry.address);
43 | entry.template = DOM.createTemplateFromMarkup(text);
44 | });
45 | }
46 | }
47 | function ensureOriginOnExports(moduleExports, moduleId) {
48 | let target = moduleExports;
49 | let key;
50 | let exportedValue;
51 | if (target.__useDefault) {
52 | target = target.default;
53 | }
54 | Origin.set(target, new Origin(moduleId, 'default'));
55 | if (typeof target === 'object') {
56 | for (key in target) {
57 | exportedValue = target[key];
58 | if (typeof exportedValue === 'function') {
59 | Origin.set(exportedValue, new Origin(moduleId, key));
60 | }
61 | }
62 | }
63 | return moduleExports;
64 | }
65 | /**
66 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
67 | */
68 | class WebpackLoader extends Loader {
69 | constructor() {
70 | super();
71 | this.moduleRegistry = Object.create(null);
72 | this.loaderPlugins = Object.create(null);
73 | this.modulesBeingLoaded = new Map();
74 | this.useTemplateLoader(new TextTemplateLoader());
75 | this.addPlugin('template-registry-entry', {
76 | fetch: (moduleId) => __awaiter(this, void 0, void 0, function* () {
77 | // HMR:
78 | if (module.hot) {
79 | if (!this.hmrContext) {
80 | // Note: Please do NOT import aurelia-hot-module-reload statically at the top of file.
81 | // We don't want to bundle it when not using --hot, in particular in production builds.
82 | // Webpack will evaluate the `if (module.hot)` above at build time
83 | // and will include (or not) aurelia-hot-module-reload accordingly.
84 | const { HmrContext } = require('aurelia-hot-module-reload');
85 | this.hmrContext = new HmrContext(this);
86 | }
87 | module.hot.accept(moduleId, () => __awaiter(this, void 0, void 0, function* () {
88 | yield this.hmrContext.handleViewChange(moduleId);
89 | }));
90 | }
91 | const entry = this.getOrCreateTemplateRegistryEntry(moduleId);
92 | if (!entry.templateIsLoaded) {
93 | yield this.templateLoader.loadTemplate(this, entry);
94 | }
95 | return entry;
96 | })
97 | });
98 | PLATFORM.eachModule = callback => {
99 | const registry = __webpack_require__.c;
100 | const cachedModuleIds = Object.getOwnPropertyNames(registry);
101 | cachedModuleIds
102 | // Note: we use .some here like a .forEach that can be "break"ed out of.
103 | // It will stop iterating only when a truthy value is returned.
104 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
105 | // and this is to keep it consistent with that.
106 | .some(moduleId => {
107 | const moduleExports = registry[moduleId].exports;
108 | if (typeof moduleExports === 'object') {
109 | return callback(moduleId, moduleExports);
110 | }
111 | return false;
112 | });
113 | };
114 | }
115 | _import(address, defaultHMR = true) {
116 | return __awaiter(this, void 0, void 0, function* () {
117 | const addressParts = address.split('!');
118 | const moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
119 | const loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
120 | if (loaderPlugin) {
121 | const plugin = this.loaderPlugins[loaderPlugin];
122 | if (!plugin) {
123 | throw new Error(`Plugin ${loaderPlugin} is not registered in the loader.`);
124 | }
125 | if (module.hot && plugin.hot) {
126 | module.hot.accept(moduleId, () => plugin.hot(moduleId));
127 | }
128 | return yield plugin.fetch(moduleId);
129 | }
130 | if (__webpack_require__.m[moduleId]) {
131 | if (defaultHMR && module.hot && this.hmrContext) {
132 | module.hot.accept(moduleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
133 | }
134 | return __webpack_require__(moduleId);
135 | }
136 | const asyncModuleId = `async!${moduleId}`;
137 | if (__webpack_require__.m[asyncModuleId]) {
138 | if (defaultHMR && module.hot && this.hmrContext) {
139 | module.hot.accept(moduleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
140 | module.hot.accept(asyncModuleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
141 | }
142 | const callback = __webpack_require__(asyncModuleId);
143 | return yield new Promise(callback);
144 | }
145 | throw new Error(`Unable to find module with ID: ${moduleId}`);
146 | });
147 | }
148 | /**
149 | * Maps a module id to a source.
150 | * @param id The module id.
151 | * @param source The source to map the module to.
152 | */
153 | map(id, source) { }
154 | /**
155 | * Normalizes a module id.
156 | * @param moduleId The module id to normalize.
157 | * @param relativeTo What the module id should be normalized relative to.
158 | * @return The normalized module id.
159 | */
160 | normalizeSync(moduleId, relativeTo) {
161 | return moduleId;
162 | }
163 | /**
164 | * Normalizes a module id.
165 | * @param moduleId The module id to normalize.
166 | * @param relativeTo What the module id should be normalized relative to.
167 | * @return The normalized module id.
168 | */
169 | normalize(moduleId, relativeTo) {
170 | return Promise.resolve(moduleId);
171 | }
172 | /**
173 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
174 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
175 | */
176 | useTemplateLoader(templateLoader) {
177 | this.templateLoader = templateLoader;
178 | }
179 | /**
180 | * Loads a collection of modules.
181 | * @param ids The set of module ids to load.
182 | * @return A Promise for an array of loaded modules.
183 | */
184 | loadAllModules(ids) {
185 | return Promise.all(ids.map(id => this.loadModule(id)));
186 | }
187 | /**
188 | * Loads a module.
189 | * @param moduleId The module ID to load.
190 | * @return A Promise for the loaded module.
191 | */
192 | loadModule(moduleId, defaultHMR = true) {
193 | return __awaiter(this, void 0, void 0, function* () {
194 | let existing = this.moduleRegistry[moduleId];
195 | if (existing) {
196 | return existing;
197 | }
198 | let beingLoaded = this.modulesBeingLoaded.get(moduleId);
199 | if (beingLoaded) {
200 | return beingLoaded;
201 | }
202 | beingLoaded = this._import(moduleId, defaultHMR);
203 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
204 | const moduleExports = yield beingLoaded;
205 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
206 | this.modulesBeingLoaded.delete(moduleId);
207 | return moduleExports;
208 | });
209 | }
210 | /**
211 | * Loads a template.
212 | * @param url The url of the template to load.
213 | * @return A Promise for a TemplateRegistryEntry containing the template.
214 | */
215 | loadTemplate(url) {
216 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
217 | }
218 | /**
219 | * Loads a text-based resource.
220 | * @param url The url of the text file to load.
221 | * @return A Promise for text content.
222 | */
223 | loadText(url) {
224 | return __awaiter(this, void 0, void 0, function* () {
225 | const result = yield this.loadModule(url, false);
226 | // css-loader could use esModule:true
227 | const defaultExport = result && result.__esModule ? result.default : result;
228 | if (this.isCssLoaderModule(defaultExport)) {
229 | // we're dealing with a file loaded using the css-loader:
230 | return this.getCssText(defaultExport);
231 | }
232 | return typeof result === "string" ? result : defaultExport;
233 | });
234 | }
235 | /**
236 | * Check if a loaded module is a css-loader module
237 | * @param o The loaded module
238 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
239 | */
240 | isCssLoaderModule(o) {
241 | return o instanceof Array && o[0] instanceof Array && o.hasOwnProperty('toString');
242 | }
243 | /**
244 | * Get CSS text from loaded css-loader module
245 | * @param cssLoaderModule The {@link CssLoaderModule}
246 | * @returns The css content with potential source map references
247 | */
248 | getCssText(cssLoaderModule) {
249 | let result = cssLoaderModule.toString();
250 | // If some css-loader modules include source maps,
251 | // ensure /*# sourceURL=[...] */ is removed to avoid chrome devtools problems
252 | if (cssLoaderModule.some(m => m[3])) {
253 | result = result.replace(/^\/\*# sourceURL=.* \*\/\s*\n/gm, "");
254 | }
255 | return result;
256 | }
257 | /**
258 | * Alters a module id so that it includes a plugin loader.
259 | * @param url The url of the module to load.
260 | * @param pluginName The plugin to apply to the module id.
261 | * @return The plugin-based module id.
262 | */
263 | applyPluginToUrl(url, pluginName) {
264 | return `${pluginName}!${url}`;
265 | }
266 | /**
267 | * Registers a plugin with the loader.
268 | * @param pluginName The name of the plugin.
269 | * @param implementation The plugin implementation.
270 | */
271 | addPlugin(pluginName, implementation) {
272 | this.loaderPlugins[pluginName] = implementation;
273 | }
274 | }
275 | PLATFORM.Loader = WebpackLoader;
276 |
277 | export { TextTemplateLoader, WebpackLoader, ensureOriginOnExports };
278 |
--------------------------------------------------------------------------------
/dist/es2017/aurelia-loader-webpack.js:
--------------------------------------------------------------------------------
1 | import { Loader } from 'aurelia-loader';
2 | import { Origin } from 'aurelia-metadata';
3 | import { PLATFORM, DOM } from 'aurelia-pal';
4 |
5 | /**
6 | * An implementation of the TemplateLoader interface implemented with text-based loading.
7 | */
8 | class TextTemplateLoader {
9 | /**
10 | * Loads a template.
11 | * @param loader The loader that is requesting the template load.
12 | * @param entry The TemplateRegistryEntry to load and populate with a template.
13 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
14 | */
15 | async loadTemplate(loader, entry) {
16 | const text = await loader.loadText(entry.address);
17 | entry.template = DOM.createTemplateFromMarkup(text);
18 | }
19 | }
20 | function ensureOriginOnExports(moduleExports, moduleId) {
21 | let target = moduleExports;
22 | let key;
23 | let exportedValue;
24 | if (target.__useDefault) {
25 | target = target.default;
26 | }
27 | Origin.set(target, new Origin(moduleId, 'default'));
28 | if (typeof target === 'object') {
29 | for (key in target) {
30 | exportedValue = target[key];
31 | if (typeof exportedValue === 'function') {
32 | Origin.set(exportedValue, new Origin(moduleId, key));
33 | }
34 | }
35 | }
36 | return moduleExports;
37 | }
38 | /**
39 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
40 | */
41 | class WebpackLoader extends Loader {
42 | constructor() {
43 | super();
44 | this.moduleRegistry = Object.create(null);
45 | this.loaderPlugins = Object.create(null);
46 | this.modulesBeingLoaded = new Map();
47 | this.useTemplateLoader(new TextTemplateLoader());
48 | this.addPlugin('template-registry-entry', {
49 | fetch: async (moduleId) => {
50 | // HMR:
51 | if (module.hot) {
52 | if (!this.hmrContext) {
53 | // Note: Please do NOT import aurelia-hot-module-reload statically at the top of file.
54 | // We don't want to bundle it when not using --hot, in particular in production builds.
55 | // Webpack will evaluate the `if (module.hot)` above at build time
56 | // and will include (or not) aurelia-hot-module-reload accordingly.
57 | const { HmrContext } = require('aurelia-hot-module-reload');
58 | this.hmrContext = new HmrContext(this);
59 | }
60 | module.hot.accept(moduleId, async () => {
61 | await this.hmrContext.handleViewChange(moduleId);
62 | });
63 | }
64 | const entry = this.getOrCreateTemplateRegistryEntry(moduleId);
65 | if (!entry.templateIsLoaded) {
66 | await this.templateLoader.loadTemplate(this, entry);
67 | }
68 | return entry;
69 | }
70 | });
71 | PLATFORM.eachModule = callback => {
72 | const registry = __webpack_require__.c;
73 | const cachedModuleIds = Object.getOwnPropertyNames(registry);
74 | cachedModuleIds
75 | // Note: we use .some here like a .forEach that can be "break"ed out of.
76 | // It will stop iterating only when a truthy value is returned.
77 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
78 | // and this is to keep it consistent with that.
79 | .some(moduleId => {
80 | const moduleExports = registry[moduleId].exports;
81 | if (typeof moduleExports === 'object') {
82 | return callback(moduleId, moduleExports);
83 | }
84 | return false;
85 | });
86 | };
87 | }
88 | async _import(address, defaultHMR = true) {
89 | const addressParts = address.split('!');
90 | const moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
91 | const loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
92 | if (loaderPlugin) {
93 | const plugin = this.loaderPlugins[loaderPlugin];
94 | if (!plugin) {
95 | throw new Error(`Plugin ${loaderPlugin} is not registered in the loader.`);
96 | }
97 | if (module.hot && plugin.hot) {
98 | module.hot.accept(moduleId, () => plugin.hot(moduleId));
99 | }
100 | return await plugin.fetch(moduleId);
101 | }
102 | if (__webpack_require__.m[moduleId]) {
103 | if (defaultHMR && module.hot && this.hmrContext) {
104 | module.hot.accept(moduleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
105 | }
106 | return __webpack_require__(moduleId);
107 | }
108 | const asyncModuleId = `async!${moduleId}`;
109 | if (__webpack_require__.m[asyncModuleId]) {
110 | if (defaultHMR && module.hot && this.hmrContext) {
111 | module.hot.accept(moduleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
112 | module.hot.accept(asyncModuleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
113 | }
114 | const callback = __webpack_require__(asyncModuleId);
115 | return await new Promise(callback);
116 | }
117 | throw new Error(`Unable to find module with ID: ${moduleId}`);
118 | }
119 | /**
120 | * Maps a module id to a source.
121 | * @param id The module id.
122 | * @param source The source to map the module to.
123 | */
124 | map(id, source) { }
125 | /**
126 | * Normalizes a module id.
127 | * @param moduleId The module id to normalize.
128 | * @param relativeTo What the module id should be normalized relative to.
129 | * @return The normalized module id.
130 | */
131 | normalizeSync(moduleId, relativeTo) {
132 | return moduleId;
133 | }
134 | /**
135 | * Normalizes a module id.
136 | * @param moduleId The module id to normalize.
137 | * @param relativeTo What the module id should be normalized relative to.
138 | * @return The normalized module id.
139 | */
140 | normalize(moduleId, relativeTo) {
141 | return Promise.resolve(moduleId);
142 | }
143 | /**
144 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
145 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
146 | */
147 | useTemplateLoader(templateLoader) {
148 | this.templateLoader = templateLoader;
149 | }
150 | /**
151 | * Loads a collection of modules.
152 | * @param ids The set of module ids to load.
153 | * @return A Promise for an array of loaded modules.
154 | */
155 | loadAllModules(ids) {
156 | return Promise.all(ids.map(id => this.loadModule(id)));
157 | }
158 | /**
159 | * Loads a module.
160 | * @param moduleId The module ID to load.
161 | * @return A Promise for the loaded module.
162 | */
163 | async loadModule(moduleId, defaultHMR = true) {
164 | let existing = this.moduleRegistry[moduleId];
165 | if (existing) {
166 | return existing;
167 | }
168 | let beingLoaded = this.modulesBeingLoaded.get(moduleId);
169 | if (beingLoaded) {
170 | return beingLoaded;
171 | }
172 | beingLoaded = this._import(moduleId, defaultHMR);
173 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
174 | const moduleExports = await beingLoaded;
175 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
176 | this.modulesBeingLoaded.delete(moduleId);
177 | return moduleExports;
178 | }
179 | /**
180 | * Loads a template.
181 | * @param url The url of the template to load.
182 | * @return A Promise for a TemplateRegistryEntry containing the template.
183 | */
184 | loadTemplate(url) {
185 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
186 | }
187 | /**
188 | * Loads a text-based resource.
189 | * @param url The url of the text file to load.
190 | * @return A Promise for text content.
191 | */
192 | async loadText(url) {
193 | const result = await this.loadModule(url, false);
194 | // css-loader could use esModule:true
195 | const defaultExport = result && result.__esModule ? result.default : result;
196 | if (this.isCssLoaderModule(defaultExport)) {
197 | // we're dealing with a file loaded using the css-loader:
198 | return this.getCssText(defaultExport);
199 | }
200 | return typeof result === "string" ? result : defaultExport;
201 | }
202 | /**
203 | * Check if a loaded module is a css-loader module
204 | * @param o The loaded module
205 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
206 | */
207 | isCssLoaderModule(o) {
208 | return o instanceof Array && o[0] instanceof Array && o.hasOwnProperty('toString');
209 | }
210 | /**
211 | * Get CSS text from loaded css-loader module
212 | * @param cssLoaderModule The {@link CssLoaderModule}
213 | * @returns The css content with potential source map references
214 | */
215 | getCssText(cssLoaderModule) {
216 | let result = cssLoaderModule.toString();
217 | // If some css-loader modules include source maps,
218 | // ensure /*# sourceURL=[...] */ is removed to avoid chrome devtools problems
219 | if (cssLoaderModule.some(m => m[3])) {
220 | result = result.replace(/^\/\*# sourceURL=.* \*\/\s*\n/gm, "");
221 | }
222 | return result;
223 | }
224 | /**
225 | * Alters a module id so that it includes a plugin loader.
226 | * @param url The url of the module to load.
227 | * @param pluginName The plugin to apply to the module id.
228 | * @return The plugin-based module id.
229 | */
230 | applyPluginToUrl(url, pluginName) {
231 | return `${pluginName}!${url}`;
232 | }
233 | /**
234 | * Registers a plugin with the loader.
235 | * @param pluginName The name of the plugin.
236 | * @param implementation The plugin implementation.
237 | */
238 | addPlugin(pluginName, implementation) {
239 | this.loaderPlugins[pluginName] = implementation;
240 | }
241 | }
242 | PLATFORM.Loader = WebpackLoader;
243 |
244 | export { TextTemplateLoader, WebpackLoader, ensureOriginOnExports };
245 |
--------------------------------------------------------------------------------
/dist/native-modules/aurelia-loader-webpack.js:
--------------------------------------------------------------------------------
1 | import { Loader } from 'aurelia-loader';
2 | import { Origin } from 'aurelia-metadata';
3 | import { PLATFORM, DOM } from 'aurelia-pal';
4 |
5 | /******************************************************************************
6 | Copyright (c) Microsoft Corporation.
7 |
8 | Permission to use, copy, modify, and/or distribute this software for any
9 | purpose with or without fee is hereby granted.
10 |
11 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 | PERFORMANCE OF THIS SOFTWARE.
18 | ***************************************************************************** */
19 | /* global Reflect, Promise */
20 |
21 | var extendStatics = function(d, b) {
22 | extendStatics = Object.setPrototypeOf ||
23 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
25 | return extendStatics(d, b);
26 | };
27 |
28 | function __extends(d, b) {
29 | if (typeof b !== "function" && b !== null)
30 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
31 | extendStatics(d, b);
32 | function __() { this.constructor = d; }
33 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34 | }
35 |
36 | function __awaiter(thisArg, _arguments, P, generator) {
37 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38 | return new (P || (P = Promise))(function (resolve, reject) {
39 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42 | step((generator = generator.apply(thisArg, _arguments || [])).next());
43 | });
44 | }
45 |
46 | function __generator(thisArg, body) {
47 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
48 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
49 | function verb(n) { return function (v) { return step([n, v]); }; }
50 | function step(op) {
51 | if (f) throw new TypeError("Generator is already executing.");
52 | while (_) try {
53 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
54 | if (y = 0, t) op = [op[0] & 2, t.value];
55 | switch (op[0]) {
56 | case 0: case 1: t = op; break;
57 | case 4: _.label++; return { value: op[1], done: false };
58 | case 5: _.label++; y = op[1]; op = [0]; continue;
59 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
60 | default:
61 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
62 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
63 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
64 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
65 | if (t[2]) _.ops.pop();
66 | _.trys.pop(); continue;
67 | }
68 | op = body.call(thisArg, _);
69 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
70 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
71 | }
72 | }
73 |
74 | /**
75 | * An implementation of the TemplateLoader interface implemented with text-based loading.
76 | */
77 | var TextTemplateLoader = /** @class */ (function () {
78 | function TextTemplateLoader() {
79 | }
80 | /**
81 | * Loads a template.
82 | * @param loader The loader that is requesting the template load.
83 | * @param entry The TemplateRegistryEntry to load and populate with a template.
84 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
85 | */
86 | TextTemplateLoader.prototype.loadTemplate = function (loader, entry) {
87 | return __awaiter(this, void 0, void 0, function () {
88 | var text;
89 | return __generator(this, function (_a) {
90 | switch (_a.label) {
91 | case 0: return [4 /*yield*/, loader.loadText(entry.address)];
92 | case 1:
93 | text = _a.sent();
94 | entry.template = DOM.createTemplateFromMarkup(text);
95 | return [2 /*return*/];
96 | }
97 | });
98 | });
99 | };
100 | return TextTemplateLoader;
101 | }());
102 | function ensureOriginOnExports(moduleExports, moduleId) {
103 | var target = moduleExports;
104 | var key;
105 | var exportedValue;
106 | if (target.__useDefault) {
107 | target = target.default;
108 | }
109 | Origin.set(target, new Origin(moduleId, 'default'));
110 | if (typeof target === 'object') {
111 | for (key in target) {
112 | exportedValue = target[key];
113 | if (typeof exportedValue === 'function') {
114 | Origin.set(exportedValue, new Origin(moduleId, key));
115 | }
116 | }
117 | }
118 | return moduleExports;
119 | }
120 | /**
121 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
122 | */
123 | var WebpackLoader = /** @class */ (function (_super) {
124 | __extends(WebpackLoader, _super);
125 | function WebpackLoader() {
126 | var _this = _super.call(this) || this;
127 | _this.moduleRegistry = Object.create(null);
128 | _this.loaderPlugins = Object.create(null);
129 | _this.modulesBeingLoaded = new Map();
130 | _this.useTemplateLoader(new TextTemplateLoader());
131 | _this.addPlugin('template-registry-entry', {
132 | fetch: function (moduleId) { return __awaiter(_this, void 0, void 0, function () {
133 | var HmrContext, entry;
134 | var _this = this;
135 | return __generator(this, function (_a) {
136 | switch (_a.label) {
137 | case 0:
138 | // HMR:
139 | if (module.hot) {
140 | if (!this.hmrContext) {
141 | HmrContext = require('aurelia-hot-module-reload').HmrContext;
142 | this.hmrContext = new HmrContext(this);
143 | }
144 | module.hot.accept(moduleId, function () { return __awaiter(_this, void 0, void 0, function () {
145 | return __generator(this, function (_a) {
146 | switch (_a.label) {
147 | case 0: return [4 /*yield*/, this.hmrContext.handleViewChange(moduleId)];
148 | case 1:
149 | _a.sent();
150 | return [2 /*return*/];
151 | }
152 | });
153 | }); });
154 | }
155 | entry = this.getOrCreateTemplateRegistryEntry(moduleId);
156 | if (!!entry.templateIsLoaded) return [3 /*break*/, 2];
157 | return [4 /*yield*/, this.templateLoader.loadTemplate(this, entry)];
158 | case 1:
159 | _a.sent();
160 | _a.label = 2;
161 | case 2: return [2 /*return*/, entry];
162 | }
163 | });
164 | }); }
165 | });
166 | PLATFORM.eachModule = function (callback) {
167 | var registry = __webpack_require__.c;
168 | var cachedModuleIds = Object.getOwnPropertyNames(registry);
169 | cachedModuleIds
170 | // Note: we use .some here like a .forEach that can be "break"ed out of.
171 | // It will stop iterating only when a truthy value is returned.
172 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
173 | // and this is to keep it consistent with that.
174 | .some(function (moduleId) {
175 | var moduleExports = registry[moduleId].exports;
176 | if (typeof moduleExports === 'object') {
177 | return callback(moduleId, moduleExports);
178 | }
179 | return false;
180 | });
181 | };
182 | return _this;
183 | }
184 | WebpackLoader.prototype._import = function (address, defaultHMR) {
185 | if (defaultHMR === void 0) { defaultHMR = true; }
186 | return __awaiter(this, void 0, void 0, function () {
187 | var addressParts, moduleId, loaderPlugin, plugin_1, asyncModuleId, callback;
188 | var _this = this;
189 | return __generator(this, function (_a) {
190 | switch (_a.label) {
191 | case 0:
192 | addressParts = address.split('!');
193 | moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
194 | loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
195 | if (!loaderPlugin) return [3 /*break*/, 2];
196 | plugin_1 = this.loaderPlugins[loaderPlugin];
197 | if (!plugin_1) {
198 | throw new Error("Plugin " + loaderPlugin + " is not registered in the loader.");
199 | }
200 | if (module.hot && plugin_1.hot) {
201 | module.hot.accept(moduleId, function () { return plugin_1.hot(moduleId); });
202 | }
203 | return [4 /*yield*/, plugin_1.fetch(moduleId)];
204 | case 1: return [2 /*return*/, _a.sent()];
205 | case 2:
206 | if (__webpack_require__.m[moduleId]) {
207 | if (defaultHMR && module.hot && this.hmrContext) {
208 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
209 | }
210 | return [2 /*return*/, __webpack_require__(moduleId)];
211 | }
212 | asyncModuleId = "async!" + moduleId;
213 | if (!__webpack_require__.m[asyncModuleId]) return [3 /*break*/, 4];
214 | if (defaultHMR && module.hot && this.hmrContext) {
215 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
216 | module.hot.accept(asyncModuleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
217 | }
218 | callback = __webpack_require__(asyncModuleId);
219 | return [4 /*yield*/, new Promise(callback)];
220 | case 3: return [2 /*return*/, _a.sent()];
221 | case 4: throw new Error("Unable to find module with ID: " + moduleId);
222 | }
223 | });
224 | });
225 | };
226 | /**
227 | * Maps a module id to a source.
228 | * @param id The module id.
229 | * @param source The source to map the module to.
230 | */
231 | WebpackLoader.prototype.map = function (id, source) { };
232 | /**
233 | * Normalizes a module id.
234 | * @param moduleId The module id to normalize.
235 | * @param relativeTo What the module id should be normalized relative to.
236 | * @return The normalized module id.
237 | */
238 | WebpackLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
239 | return moduleId;
240 | };
241 | /**
242 | * Normalizes a module id.
243 | * @param moduleId The module id to normalize.
244 | * @param relativeTo What the module id should be normalized relative to.
245 | * @return The normalized module id.
246 | */
247 | WebpackLoader.prototype.normalize = function (moduleId, relativeTo) {
248 | return Promise.resolve(moduleId);
249 | };
250 | /**
251 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
252 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
253 | */
254 | WebpackLoader.prototype.useTemplateLoader = function (templateLoader) {
255 | this.templateLoader = templateLoader;
256 | };
257 | /**
258 | * Loads a collection of modules.
259 | * @param ids The set of module ids to load.
260 | * @return A Promise for an array of loaded modules.
261 | */
262 | WebpackLoader.prototype.loadAllModules = function (ids) {
263 | var _this = this;
264 | return Promise.all(ids.map(function (id) { return _this.loadModule(id); }));
265 | };
266 | /**
267 | * Loads a module.
268 | * @param moduleId The module ID to load.
269 | * @return A Promise for the loaded module.
270 | */
271 | WebpackLoader.prototype.loadModule = function (moduleId, defaultHMR) {
272 | if (defaultHMR === void 0) { defaultHMR = true; }
273 | return __awaiter(this, void 0, void 0, function () {
274 | var existing, beingLoaded, moduleExports;
275 | return __generator(this, function (_a) {
276 | switch (_a.label) {
277 | case 0:
278 | existing = this.moduleRegistry[moduleId];
279 | if (existing) {
280 | return [2 /*return*/, existing];
281 | }
282 | beingLoaded = this.modulesBeingLoaded.get(moduleId);
283 | if (beingLoaded) {
284 | return [2 /*return*/, beingLoaded];
285 | }
286 | beingLoaded = this._import(moduleId, defaultHMR);
287 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
288 | return [4 /*yield*/, beingLoaded];
289 | case 1:
290 | moduleExports = _a.sent();
291 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
292 | this.modulesBeingLoaded.delete(moduleId);
293 | return [2 /*return*/, moduleExports];
294 | }
295 | });
296 | });
297 | };
298 | /**
299 | * Loads a template.
300 | * @param url The url of the template to load.
301 | * @return A Promise for a TemplateRegistryEntry containing the template.
302 | */
303 | WebpackLoader.prototype.loadTemplate = function (url) {
304 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
305 | };
306 | /**
307 | * Loads a text-based resource.
308 | * @param url The url of the text file to load.
309 | * @return A Promise for text content.
310 | */
311 | WebpackLoader.prototype.loadText = function (url) {
312 | return __awaiter(this, void 0, void 0, function () {
313 | var result, defaultExport;
314 | return __generator(this, function (_a) {
315 | switch (_a.label) {
316 | case 0: return [4 /*yield*/, this.loadModule(url, false)];
317 | case 1:
318 | result = _a.sent();
319 | defaultExport = result && result.__esModule ? result.default : result;
320 | if (this.isCssLoaderModule(defaultExport)) {
321 | // we're dealing with a file loaded using the css-loader:
322 | return [2 /*return*/, this.getCssText(defaultExport)];
323 | }
324 | return [2 /*return*/, typeof result === "string" ? result : defaultExport];
325 | }
326 | });
327 | });
328 | };
329 | /**
330 | * Check if a loaded module is a css-loader module
331 | * @param o The loaded module
332 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
333 | */
334 | WebpackLoader.prototype.isCssLoaderModule = function (o) {
335 | return o instanceof Array && o[0] instanceof Array && o.hasOwnProperty('toString');
336 | };
337 | /**
338 | * Get CSS text from loaded css-loader module
339 | * @param cssLoaderModule The {@link CssLoaderModule}
340 | * @returns The css content with potential source map references
341 | */
342 | WebpackLoader.prototype.getCssText = function (cssLoaderModule) {
343 | var result = cssLoaderModule.toString();
344 | // If some css-loader modules include source maps,
345 | // ensure /*# sourceURL=[...] */ is removed to avoid chrome devtools problems
346 | if (cssLoaderModule.some(function (m) { return m[3]; })) {
347 | result = result.replace(/^\/\*# sourceURL=.* \*\/\s*\n/gm, "");
348 | }
349 | return result;
350 | };
351 | /**
352 | * Alters a module id so that it includes a plugin loader.
353 | * @param url The url of the module to load.
354 | * @param pluginName The plugin to apply to the module id.
355 | * @return The plugin-based module id.
356 | */
357 | WebpackLoader.prototype.applyPluginToUrl = function (url, pluginName) {
358 | return pluginName + "!" + url;
359 | };
360 | /**
361 | * Registers a plugin with the loader.
362 | * @param pluginName The name of the plugin.
363 | * @param implementation The plugin implementation.
364 | */
365 | WebpackLoader.prototype.addPlugin = function (pluginName, implementation) {
366 | this.loaderPlugins[pluginName] = implementation;
367 | };
368 | return WebpackLoader;
369 | }(Loader));
370 | PLATFORM.Loader = WebpackLoader;
371 |
372 | export { TextTemplateLoader, WebpackLoader, ensureOriginOnExports };
373 |
--------------------------------------------------------------------------------
/dist/system/aurelia-loader-webpack.d.ts:
--------------------------------------------------------------------------------
1 | import { Loader, TemplateRegistryEntry, LoaderPlugin } from 'aurelia-loader';
2 | export declare type LoaderPlugin = {
3 | fetch: (address: string) => Promise | TemplateRegistryEntry;
4 | };
5 | /**
6 | * An implementation of the TemplateLoader interface implemented with text-based loading.
7 | */
8 | export declare class TextTemplateLoader {
9 | /**
10 | * Loads a template.
11 | * @param loader The loader that is requesting the template load.
12 | * @param entry The TemplateRegistryEntry to load and populate with a template.
13 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
14 | */
15 | loadTemplate(loader: Loader, entry: TemplateRegistryEntry): Promise;
16 | }
17 | export declare function ensureOriginOnExports(moduleExports: any, moduleId: string): any;
18 | /**
19 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
20 | */
21 | export declare class WebpackLoader extends Loader {
22 | moduleRegistry: any;
23 | loaderPlugins: {
24 | [name: string]: LoaderPlugin & {
25 | hot?: ((moduleId: string) => void) | undefined;
26 | };
27 | };
28 | modulesBeingLoaded: Map>;
29 | templateLoader: TextTemplateLoader;
30 | hmrContext: {
31 | handleModuleChange(moduleId: string, hot: Webpack.WebpackHotModule): Promise;
32 | handleViewChange(moduleId: string): Promise;
33 | };
34 | constructor();
35 | _import(address: string, defaultHMR?: boolean): Promise;
36 | /**
37 | * Maps a module id to a source.
38 | * @param id The module id.
39 | * @param source The source to map the module to.
40 | */
41 | map(id: string, source: any): void;
42 | /**
43 | * Normalizes a module id.
44 | * @param moduleId The module id to normalize.
45 | * @param relativeTo What the module id should be normalized relative to.
46 | * @return The normalized module id.
47 | */
48 | normalizeSync(moduleId: string, relativeTo: string): string;
49 | /**
50 | * Normalizes a module id.
51 | * @param moduleId The module id to normalize.
52 | * @param relativeTo What the module id should be normalized relative to.
53 | * @return The normalized module id.
54 | */
55 | normalize(moduleId: string, relativeTo: string): Promise;
56 | /**
57 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
58 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
59 | */
60 | useTemplateLoader(templateLoader: TextTemplateLoader): void;
61 | /**
62 | * Loads a collection of modules.
63 | * @param ids The set of module ids to load.
64 | * @return A Promise for an array of loaded modules.
65 | */
66 | loadAllModules(ids: Array): Promise;
67 | /**
68 | * Loads a module.
69 | * @param moduleId The module ID to load.
70 | * @return A Promise for the loaded module.
71 | */
72 | loadModule(moduleId: string, defaultHMR?: boolean): Promise;
73 | /**
74 | * Loads a template.
75 | * @param url The url of the template to load.
76 | * @return A Promise for a TemplateRegistryEntry containing the template.
77 | */
78 | loadTemplate(url: string): Promise;
79 | /**
80 | * Loads a text-based resource.
81 | * @param url The url of the text file to load.
82 | * @return A Promise for text content.
83 | */
84 | loadText(url: string): Promise;
85 | /**
86 | * Alters a module id so that it includes a plugin loader.
87 | * @param url The url of the module to load.
88 | * @param pluginName The plugin to apply to the module id.
89 | * @return The plugin-based module id.
90 | */
91 | applyPluginToUrl(url: string, pluginName: string): string;
92 | /**
93 | * Registers a plugin with the loader.
94 | * @param pluginName The name of the plugin.
95 | * @param implementation The plugin implementation.
96 | */
97 | addPlugin(pluginName: string, implementation: LoaderPlugin): void;
98 | }
99 |
--------------------------------------------------------------------------------
/dist/system/aurelia-loader-webpack.js:
--------------------------------------------------------------------------------
1 | System.register(["aurelia-metadata", "aurelia-loader", "aurelia-pal"], function (exports_1, context_1) {
2 | "use strict";
3 | var __extends = (this && this.__extends) || (function () {
4 | var extendStatics = Object.setPrototypeOf ||
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 | return function (d, b) {
8 | extendStatics(d, b);
9 | function __() { this.constructor = d; }
10 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
11 | };
12 | })();
13 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14 | return new (P || (P = Promise))(function (resolve, reject) {
15 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
18 | step((generator = generator.apply(thisArg, _arguments || [])).next());
19 | });
20 | };
21 | var __generator = (this && this.__generator) || function (thisArg, body) {
22 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24 | function verb(n) { return function (v) { return step([n, v]); }; }
25 | function step(op) {
26 | if (f) throw new TypeError("Generator is already executing.");
27 | while (_) try {
28 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29 | if (y = 0, t) op = [op[0] & 2, t.value];
30 | switch (op[0]) {
31 | case 0: case 1: t = op; break;
32 | case 4: _.label++; return { value: op[1], done: false };
33 | case 5: _.label++; y = op[1]; op = [0]; continue;
34 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
35 | default:
36 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40 | if (t[2]) _.ops.pop();
41 | _.trys.pop(); continue;
42 | }
43 | op = body.call(thisArg, _);
44 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46 | }
47 | };
48 | var aurelia_metadata_1, aurelia_loader_1, aurelia_pal_1, TextTemplateLoader, WebpackLoader;
49 | var __moduleName = context_1 && context_1.id;
50 | function ensureOriginOnExports(moduleExports, moduleId) {
51 | var target = moduleExports;
52 | var key;
53 | var exportedValue;
54 | if (target.__useDefault) {
55 | target = target.default;
56 | }
57 | aurelia_metadata_1.Origin.set(target, new aurelia_metadata_1.Origin(moduleId, 'default'));
58 | if (typeof target === 'object') {
59 | for (key in target) {
60 | exportedValue = target[key];
61 | if (typeof exportedValue === 'function') {
62 | aurelia_metadata_1.Origin.set(exportedValue, new aurelia_metadata_1.Origin(moduleId, key));
63 | }
64 | }
65 | }
66 | return moduleExports;
67 | }
68 | exports_1("ensureOriginOnExports", ensureOriginOnExports);
69 | return {
70 | setters: [
71 | function (aurelia_metadata_1_1) {
72 | aurelia_metadata_1 = aurelia_metadata_1_1;
73 | },
74 | function (aurelia_loader_1_1) {
75 | aurelia_loader_1 = aurelia_loader_1_1;
76 | },
77 | function (aurelia_pal_1_1) {
78 | aurelia_pal_1 = aurelia_pal_1_1;
79 | }
80 | ],
81 | execute: function () {
82 | /**
83 | * An implementation of the TemplateLoader interface implemented with text-based loading.
84 | */
85 | TextTemplateLoader = /** @class */ (function () {
86 | function TextTemplateLoader() {
87 | }
88 | /**
89 | * Loads a template.
90 | * @param loader The loader that is requesting the template load.
91 | * @param entry The TemplateRegistryEntry to load and populate with a template.
92 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
93 | */
94 | TextTemplateLoader.prototype.loadTemplate = function (loader, entry) {
95 | return __awaiter(this, void 0, void 0, function () {
96 | var text;
97 | return __generator(this, function (_a) {
98 | switch (_a.label) {
99 | case 0: return [4 /*yield*/, loader.loadText(entry.address)];
100 | case 1:
101 | text = _a.sent();
102 | entry.template = aurelia_pal_1.DOM.createTemplateFromMarkup(text);
103 | return [2 /*return*/];
104 | }
105 | });
106 | });
107 | };
108 | return TextTemplateLoader;
109 | }());
110 | exports_1("TextTemplateLoader", TextTemplateLoader);
111 | /**
112 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
113 | */
114 | WebpackLoader = /** @class */ (function (_super) {
115 | __extends(WebpackLoader, _super);
116 | function WebpackLoader() {
117 | var _this = _super.call(this) || this;
118 | _this.moduleRegistry = Object.create(null);
119 | _this.loaderPlugins = Object.create(null);
120 | _this.modulesBeingLoaded = new Map();
121 | _this.useTemplateLoader(new TextTemplateLoader());
122 | _this.addPlugin('template-registry-entry', {
123 | fetch: function (moduleId) { return __awaiter(_this, void 0, void 0, function () {
124 | var HmrContext, entry;
125 | var _this = this;
126 | return __generator(this, function (_a) {
127 | switch (_a.label) {
128 | case 0:
129 | // HMR:
130 | if (module.hot) {
131 | if (!this.hmrContext) {
132 | HmrContext = require('aurelia-hot-module-reload').HmrContext;
133 | this.hmrContext = new HmrContext(this);
134 | }
135 | module.hot.accept(moduleId, function () { return __awaiter(_this, void 0, void 0, function () {
136 | return __generator(this, function (_a) {
137 | switch (_a.label) {
138 | case 0: return [4 /*yield*/, this.hmrContext.handleViewChange(moduleId)];
139 | case 1:
140 | _a.sent();
141 | return [2 /*return*/];
142 | }
143 | });
144 | }); });
145 | }
146 | entry = this.getOrCreateTemplateRegistryEntry(moduleId);
147 | if (!!entry.templateIsLoaded) return [3 /*break*/, 2];
148 | return [4 /*yield*/, this.templateLoader.loadTemplate(this, entry)];
149 | case 1:
150 | _a.sent();
151 | _a.label = 2;
152 | case 2: return [2 /*return*/, entry];
153 | }
154 | });
155 | }); }
156 | });
157 | aurelia_pal_1.PLATFORM.eachModule = function (callback) {
158 | var registry = __webpack_require__.c;
159 | var cachedModuleIds = Object.getOwnPropertyNames(registry);
160 | cachedModuleIds
161 | // Note: we use .some here like a .forEach that can be "break"ed out of.
162 | // It will stop iterating only when a truthy value is returned.
163 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
164 | // and this is to keep it consistent with that.
165 | .some(function (moduleId) {
166 | var moduleExports = registry[moduleId].exports;
167 | if (typeof moduleExports === 'object') {
168 | return callback(moduleId, moduleExports);
169 | }
170 | return false;
171 | });
172 | };
173 | return _this;
174 | }
175 | WebpackLoader.prototype._import = function (address, defaultHMR) {
176 | if (defaultHMR === void 0) { defaultHMR = true; }
177 | return __awaiter(this, void 0, void 0, function () {
178 | var addressParts, moduleId, loaderPlugin, plugin_1, asyncModuleId, callback;
179 | var _this = this;
180 | return __generator(this, function (_a) {
181 | switch (_a.label) {
182 | case 0:
183 | addressParts = address.split('!');
184 | moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
185 | loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
186 | if (!loaderPlugin) return [3 /*break*/, 2];
187 | plugin_1 = this.loaderPlugins[loaderPlugin];
188 | if (!plugin_1) {
189 | throw new Error("Plugin " + loaderPlugin + " is not registered in the loader.");
190 | }
191 | if (module.hot && plugin_1.hot) {
192 | module.hot.accept(moduleId, function () { return plugin_1.hot(moduleId); });
193 | }
194 | return [4 /*yield*/, plugin_1.fetch(moduleId)];
195 | case 1: return [2 /*return*/, _a.sent()];
196 | case 2:
197 | if (__webpack_require__.m[moduleId]) {
198 | if (defaultHMR && module.hot && this.hmrContext) {
199 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
200 | }
201 | return [2 /*return*/, __webpack_require__(moduleId)];
202 | }
203 | asyncModuleId = "async!" + moduleId;
204 | if (!__webpack_require__.m[asyncModuleId]) return [3 /*break*/, 4];
205 | if (defaultHMR && module.hot && this.hmrContext) {
206 | module.hot.accept(moduleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
207 | module.hot.accept(asyncModuleId, function () { return _this.hmrContext.handleModuleChange(moduleId, module.hot); });
208 | }
209 | callback = __webpack_require__(asyncModuleId);
210 | return [4 /*yield*/, new Promise(callback)];
211 | case 3: return [2 /*return*/, _a.sent()];
212 | case 4: throw new Error("Unable to find module with ID: " + moduleId);
213 | }
214 | });
215 | });
216 | };
217 | /**
218 | * Maps a module id to a source.
219 | * @param id The module id.
220 | * @param source The source to map the module to.
221 | */
222 | WebpackLoader.prototype.map = function (id, source) { };
223 | /**
224 | * Normalizes a module id.
225 | * @param moduleId The module id to normalize.
226 | * @param relativeTo What the module id should be normalized relative to.
227 | * @return The normalized module id.
228 | */
229 | WebpackLoader.prototype.normalizeSync = function (moduleId, relativeTo) {
230 | return moduleId;
231 | };
232 | /**
233 | * Normalizes a module id.
234 | * @param moduleId The module id to normalize.
235 | * @param relativeTo What the module id should be normalized relative to.
236 | * @return The normalized module id.
237 | */
238 | WebpackLoader.prototype.normalize = function (moduleId, relativeTo) {
239 | return Promise.resolve(moduleId);
240 | };
241 | /**
242 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
243 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
244 | */
245 | WebpackLoader.prototype.useTemplateLoader = function (templateLoader) {
246 | this.templateLoader = templateLoader;
247 | };
248 | /**
249 | * Loads a collection of modules.
250 | * @param ids The set of module ids to load.
251 | * @return A Promise for an array of loaded modules.
252 | */
253 | WebpackLoader.prototype.loadAllModules = function (ids) {
254 | var _this = this;
255 | return Promise.all(ids.map(function (id) { return _this.loadModule(id); }));
256 | };
257 | /**
258 | * Loads a module.
259 | * @param moduleId The module ID to load.
260 | * @return A Promise for the loaded module.
261 | */
262 | WebpackLoader.prototype.loadModule = function (moduleId, defaultHMR) {
263 | if (defaultHMR === void 0) { defaultHMR = true; }
264 | return __awaiter(this, void 0, void 0, function () {
265 | var existing, beingLoaded, moduleExports;
266 | return __generator(this, function (_a) {
267 | switch (_a.label) {
268 | case 0:
269 | existing = this.moduleRegistry[moduleId];
270 | if (existing) {
271 | return [2 /*return*/, existing];
272 | }
273 | beingLoaded = this.modulesBeingLoaded.get(moduleId);
274 | if (beingLoaded) {
275 | return [2 /*return*/, beingLoaded];
276 | }
277 | beingLoaded = this._import(moduleId, defaultHMR);
278 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
279 | return [4 /*yield*/, beingLoaded];
280 | case 1:
281 | moduleExports = _a.sent();
282 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
283 | this.modulesBeingLoaded.delete(moduleId);
284 | return [2 /*return*/, moduleExports];
285 | }
286 | });
287 | });
288 | };
289 | /**
290 | * Loads a template.
291 | * @param url The url of the template to load.
292 | * @return A Promise for a TemplateRegistryEntry containing the template.
293 | */
294 | WebpackLoader.prototype.loadTemplate = function (url) {
295 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
296 | };
297 | /**
298 | * Loads a text-based resource.
299 | * @param url The url of the text file to load.
300 | * @return A Promise for text content.
301 | */
302 | WebpackLoader.prototype.loadText = function (url) {
303 | return __awaiter(this, void 0, void 0, function () {
304 | var result, defaultExport;
305 | return __generator(this, function (_a) {
306 | switch (_a.label) {
307 | case 0: return [4 /*yield*/, this.loadModule(url, false)];
308 | case 1:
309 | result = _a.sent();
310 | defaultExport = result && result.__esModule ? result.default : result;
311 | if (defaultExport instanceof Array && defaultExport[0] instanceof Array && defaultExport.hasOwnProperty('toString')) {
312 | // we're dealing with a file loaded using the css-loader:
313 | return [2 /*return*/, defaultExport.toString()];
314 | }
315 | return [2 /*return*/, result];
316 | }
317 | });
318 | });
319 | };
320 | /**
321 | * Alters a module id so that it includes a plugin loader.
322 | * @param url The url of the module to load.
323 | * @param pluginName The plugin to apply to the module id.
324 | * @return The plugin-based module id.
325 | */
326 | WebpackLoader.prototype.applyPluginToUrl = function (url, pluginName) {
327 | return pluginName + "!" + url;
328 | };
329 | /**
330 | * Registers a plugin with the loader.
331 | * @param pluginName The name of the plugin.
332 | * @param implementation The plugin implementation.
333 | */
334 | WebpackLoader.prototype.addPlugin = function (pluginName, implementation) {
335 | this.loaderPlugins[pluginName] = implementation;
336 | };
337 | return WebpackLoader;
338 | }(aurelia_loader_1.Loader));
339 | exports_1("WebpackLoader", WebpackLoader);
340 | aurelia_pal_1.PLATFORM.Loader = WebpackLoader;
341 | }
342 | };
343 | });
344 |
--------------------------------------------------------------------------------
/dist/types/aurelia-loader-webpack.d.ts:
--------------------------------------------------------------------------------
1 | import { Loader, LoaderPlugin as AureliaLoaderPlugin, TemplateRegistryEntry } from 'aurelia-loader';
2 | export declare type LoaderPlugin = {
3 | fetch: (address: string) => Promise | TemplateRegistryEntry;
4 | };
5 | /**
6 | * An implementation of the TemplateLoader interface implemented with text-based loading.
7 | */
8 | export declare class TextTemplateLoader {
9 | /**
10 | * Loads a template.
11 | * @param loader The loader that is requesting the template load.
12 | * @param entry The TemplateRegistryEntry to load and populate with a template.
13 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
14 | */
15 | loadTemplate(loader: Loader, entry: TemplateRegistryEntry): Promise;
16 | }
17 | export declare function ensureOriginOnExports(moduleExports: any, moduleId: string): any;
18 | /**
19 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
20 | */
21 | export declare class WebpackLoader extends Loader {
22 | moduleRegistry: any;
23 | loaderPlugins: {
24 | [name: string]: AureliaLoaderPlugin & {
25 | hot?: (moduleId: string) => void;
26 | };
27 | };
28 | modulesBeingLoaded: Map>;
29 | templateLoader: TextTemplateLoader;
30 | hmrContext: {
31 | handleModuleChange(moduleId: string, hot: WebpackHotModule): Promise;
32 | handleViewChange(moduleId: string): Promise;
33 | };
34 | constructor();
35 | _import(address: string, defaultHMR?: boolean): Promise;
36 | /**
37 | * Maps a module id to a source.
38 | * @param id The module id.
39 | * @param source The source to map the module to.
40 | */
41 | map(id: string, source: any): void;
42 | /**
43 | * Normalizes a module id.
44 | * @param moduleId The module id to normalize.
45 | * @param relativeTo What the module id should be normalized relative to.
46 | * @return The normalized module id.
47 | */
48 | normalizeSync(moduleId: string, relativeTo: string): string;
49 | /**
50 | * Normalizes a module id.
51 | * @param moduleId The module id to normalize.
52 | * @param relativeTo What the module id should be normalized relative to.
53 | * @return The normalized module id.
54 | */
55 | normalize(moduleId: string, relativeTo: string): Promise;
56 | /**
57 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
58 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
59 | */
60 | useTemplateLoader(templateLoader: TextTemplateLoader): void;
61 | /**
62 | * Loads a collection of modules.
63 | * @param ids The set of module ids to load.
64 | * @return A Promise for an array of loaded modules.
65 | */
66 | loadAllModules(ids: Array): Promise;
67 | /**
68 | * Loads a module.
69 | * @param moduleId The module ID to load.
70 | * @return A Promise for the loaded module.
71 | */
72 | loadModule(moduleId: string, defaultHMR?: boolean): Promise;
73 | /**
74 | * Loads a template.
75 | * @param url The url of the template to load.
76 | * @return A Promise for a TemplateRegistryEntry containing the template.
77 | */
78 | loadTemplate(url: string): Promise;
79 | /**
80 | * Loads a text-based resource.
81 | * @param url The url of the text file to load.
82 | * @return A Promise for text content.
83 | */
84 | loadText(url: string): Promise;
85 | /**
86 | * Check if a loaded module is a css-loader module
87 | * @param o The loaded module
88 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
89 | */
90 | private isCssLoaderModule;
91 | /**
92 | * Get CSS text from loaded css-loader module
93 | * @param cssLoaderModule The {@link CssLoaderModule}
94 | * @returns The css content with potential source map references
95 | */
96 | private getCssText;
97 | /**
98 | * Alters a module id so that it includes a plugin loader.
99 | * @param url The url of the module to load.
100 | * @param pluginName The plugin to apply to the module id.
101 | * @return The plugin-based module id.
102 | */
103 | applyPluginToUrl(url: string, pluginName: string): string;
104 | /**
105 | * Registers a plugin with the loader.
106 | * @param pluginName The name of the plugin.
107 | * @param implementation The plugin implementation.
108 | */
109 | addPlugin(pluginName: string, implementation: AureliaLoaderPlugin): void;
110 | }
111 | export declare type HotModuleStatus = 'idle' | 'check' | 'watch' | 'watch-delay' | 'prepare' | 'ready' | 'dispose' | 'apply' | 'abort' | 'fail';
112 | export interface WebpackHotModule {
113 | /**
114 | * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
115 | */
116 | accept(dependencies: string[], callback: (updatedDependencies: Array) => void): void;
117 | /**
118 | * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
119 | */
120 | accept(dependency: string, callback: () => void): void;
121 | /**
122 | * Accept code updates for this module without notification of parents. This should only be used if the module doesn’t export anything. The errHandler can be used to handle errors that occur while loading the updated module.
123 | */
124 | accept(errHandler?: (e: Error) => void): void;
125 | /**
126 | * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
127 | */
128 | decline(dependencies: string[]): void;
129 | /**
130 | * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
131 | */
132 | decline(dependency: string): void;
133 | /**
134 | * Flag the current module as not update-able. If updated the update code would fail with code "decline".
135 | */
136 | decline(): void;
137 | /**
138 | * Add a one time handler, which is executed when the current module code is replaced. Here you should destroy/remove any persistent resource you have claimed/created. If you want to transfer state to the new module, add it to data object. The data will be available at module.hot.data on the new module.
139 | */
140 | dispose(callback: (data: any) => void): void;
141 | /**
142 | * Add a one time handler, which is executed when the current module code is replaced. Here you should destroy/remove any persistent resource you have claimed/created. If you want to transfer state to the new module, add it to data object. The data will be available at module.hot.data on the new module.
143 | */
144 | addDisposeHandler(callback: (data: any) => void): void;
145 | /**
146 | * Remove a dispose handler.
147 | * This can useful to add a temporary dispose handler. You could i. e. replace code while in the middle of a multi-step async function.
148 | */
149 | removeDisposeHandler(callback: (data: any) => void): void;
150 | /**
151 | * Throws an exceptions if status() is not idle.
152 | * Check all currently loaded modules for updates and apply updates if found.
153 | * If no update was found, the callback is called with null.
154 | * If autoApply is truthy the callback will be called with all modules that were disposed. apply() is automatically called with autoApply as options parameter.
155 | * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
156 | */
157 | check(autoApply: boolean, callback: (err: Error, outdatedModules: any[]) => void): void;
158 | /**
159 | * Throws an exceptions if status() is not idle.
160 | * Check all currently loaded modules for updates and apply updates if found.
161 | * If no update was found, the callback is called with null.
162 | * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
163 | */
164 | check(callback: (err: Error, outdatedModules: NodeModule[]) => void): void;
165 | /**
166 | * Continue the update process.
167 | * If status() != "ready" it throws an error.
168 | */
169 | apply(options: HotOptions, callback: (err: Error, outdatedModules: any[]) => void): void;
170 | apply(callback: (err: Error, outdatedModules: any[]) => void): void;
171 | /**
172 | * Return one of idle, check, watch, watch-delay, prepare, ready, dispose, apply, abort or fail.
173 | *
174 | * - `idle`
175 | * The HMR is waiting for your call the check(). When you call it the status will change to check.
176 | *
177 | * - `check`
178 | * The HMR is checking for updates. If it doesn’t find updates it will change back to idle. If updates were found it will go through the steps prepare, dispose and apply. Than back to idle.
179 | *
180 | * - `watch`
181 | * The HMR is in watch mode and will automatically be notified about changes. After the first change it will change to watch-delay and wait for a specified time to start the update process. Any change will reset the timeout, to accumulate more changes. When the update process is started it will go through the steps prepare, dispose and apply. Than back to watch or watch-delay if changes were detected while updating.
182 | *
183 | * - `prepare`
184 | * The HMR is prepare stuff for the update. This may means that it’s downloading something.
185 | *
186 | * - `ready`
187 | * An update is available and prepared. Call apply() to continue.
188 | *
189 | * - `dispose`
190 | * The HMR is calling the dispose handlers of modules that will be replaced.
191 | *
192 | * - `apply`
193 | * The HMR is calling the accept handlers of the parents of replaced modules, than it requires the self accepted modules.
194 | *
195 | * - `abort`
196 | * A update cannot apply, but the system is still in a (old) consistent state.
197 | *
198 | * - `fail`
199 | * A update has thrown an exception in the middle of the process, and the system is (maybe) in a inconsistent state. The system should be restarted.
200 | */
201 | status(): HotModuleStatus;
202 | /**
203 | * Register a callback on status change.
204 | */
205 | status(callback: (status: HotModuleStatus) => void): void;
206 | /**
207 | * Register a callback on status change.
208 | */
209 | addStatusHandler(callback: (status: HotModuleStatus) => void): void;
210 | /**
211 | * Data from the previous version of this module, if set and disposed using the dispose() handler.
212 | */
213 | data?: any;
214 | }
215 | export interface HotOptions {
216 | /**
217 | * If true the update process continues even if some modules are not accepted (and would bubble to the entry point).
218 | */
219 | ignoreUnaccepted?: boolean;
220 | }
221 |
--------------------------------------------------------------------------------
/doc/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ### [2.2.5](https://github.com/aurelia/loader-webpack/compare/2.2.4...2.2.5) (2022-09-09)
6 |
7 |
8 | ### Bug Fixes
9 |
10 | * remove /*# sourceURL= */ from css-loader content ([8f12aed](https://github.com/aurelia/loader-webpack/commit/8f12aed))
11 |
12 | ## [2.2.4](https://github.com/aurelia/loader-webpack/compare/2.2.4...2.2.3) (2021-07-31)
13 |
14 |
15 | ### Others
16 |
17 | * include typings in release ([7c898b6](https://github.com/aurelia/loader-webpack/commit/7c898b6))
18 |
19 | ## [2.2.3](https://github.com/aurelia/loader-webpack/compare/2.2.2...2.2.3) (2021-07-25)
20 |
21 |
22 | ### Bug Fixes
23 |
24 | * returns object instead of string ([7c898b6](https://github.com/aurelia/loader-webpack/commit/7c898b6))
25 |
26 | ## [2.2.2](https://github.com/aurelia/loader-webpack/compare/2.2.1...2.2.2) (2020-10-20)
27 |
28 |
29 | ### Bug Fixes
30 |
31 | * fix compatibility with latest css-loader v4 ([29fc07a](https://github.com/aurelia/loader-webpack/commit/29fc07a)), closes [aurelia/cli#1186](https://github.com/aurelia/cli/issues/1186) [aurelia/webpack-plugin#168](https://github.com/aurelia/webpack-plugin/issues/168)
32 |
33 |
34 |
35 | ## [2.2.1](https://github.com/aurelia/loader-webpack/compare/2.1.0...2.2.1) (2018-06-19)
36 |
37 |
38 | ### Bug Fixes
39 |
40 | * **eachModule:** shortcircuit the iteration when callback returns true ([d5a6d73](https://github.com/aurelia/loader-webpack/commit/d5a6d73))
41 | * **loader-webpack:** handle HMR changes also in async modules ([#40](https://github.com/aurelia/loader-webpack/issues/40)) ([36c5de3](https://github.com/aurelia/loader-webpack/commit/36c5de3))
42 |
43 |
44 |
45 | ## [1.0.3](https://github.com/aurelia/loader-webpack/compare/1.0.2...v1.0.3) (2016-09-22)
46 |
47 |
48 | ### Bug Fixes
49 |
50 | * **index:** delete the empty cache element if failed to __webpack_require__ ([13fb8b8](https://github.com/aurelia/loader-webpack/commit/13fb8b8)), closes [#18](https://github.com/aurelia/loader-webpack/issues/18)
51 |
52 |
53 |
54 | ## [1.0.2](https://github.com/aurelia/loader-webpack/compare/1.0.1...v1.0.2) (2016-07-29)
55 |
56 |
57 | ### Bug Fixes
58 |
59 | * **index:** incorrect contextual "this" reference ([bf29b49](https://github.com/aurelia/loader-webpack/commit/bf29b49))
60 |
61 |
62 |
63 | ## [1.0.1](https://github.com/aurelia/loader-webpack/compare/1.0.0...v1.0.1) (2016-07-29)
64 |
65 |
66 | ### Bug Fixes
67 |
68 | * **index:** cache loading Promises and fix lazy loading ([26e1a74](https://github.com/aurelia/loader-webpack/commit/26e1a74)), closes [#15](https://github.com/aurelia/loader-webpack/issues/15)
69 |
70 |
71 |
72 | ## [1.0.0](https://github.com/aurelia/loader-webpack/compare/1.0.0-rc.1.0.0...v1.0.0) (2016-07-27)
73 |
74 |
75 | ### Features
76 |
77 | * **index:** expose ensureOriginOnExports and simplify loadModule ([b6a3ed0](https://github.com/aurelia/loader-webpack/commit/b6a3ed0))
78 | * **index:** further simplify loadModule ([4fe5405](https://github.com/aurelia/loader-webpack/commit/4fe5405))
79 | * **index:** implement PLATFORM.eachModule ([a942c57](https://github.com/aurelia/loader-webpack/commit/a942c57))
80 |
81 |
82 |
83 | ## [1.0.0-rc.1.0.0](https://github.com/aurelia/loader-webpack/compare/1.0.0-beta.2.0.1...v1.0.0-rc.1.0.0) (2016-06-22)
84 |
85 |
86 |
87 | ### 1.0.0-beta.1.0.3 (2016-06-09)
88 |
89 |
90 | #### Features
91 |
92 | * **index:**
93 | * support css-loader ([c767f849](http://github.com/aurelia/loader-webpack/commit/c767f849ed7375990db105fb559a46b325c3e4e1))
94 | * use a named chunk ([12ab2481](http://github.com/aurelia/loader-webpack/commit/12ab2481b1ebbfbc8cbf68c4ad8dcbaabd44d852))
95 |
96 |
97 | ### 1.0.0-beta.1.0.2 (2016-05-10)
98 |
99 |
100 | ### 1.0.0-beta.1.0.1 (2016-04-13)
101 |
102 |
103 | #### Bug Fixes
104 |
105 | * **index:** ensure correct cache lookup ([b9c9aa55](http://github.com/aurelia/loader-webpack/commit/b9c9aa5511df0b3b7f5615d5368e6c34e96a0175))
106 |
107 |
108 | #### Features
109 |
110 | * **index:** implement PLATFORM.eachModule for webpack ([9bd90f47](http://github.com/aurelia/loader-webpack/commit/9bd90f47f83f848f11106b2f3996125b37be7997))
111 |
112 |
113 | ### 1.0.0-beta.1.0.0 (2016-03-22)
114 |
115 | * Update to Babel 6
116 |
117 | ### 0.1.2 (2016-03-01)
118 |
119 |
120 | #### Bug Fixes
121 |
122 | * **all:** remove core-js dependency ([dfb7784a](http://github.com/aurelia/loader-webpack/commit/dfb7784a622604a31a99f605692b5db5916d5750))
123 |
124 |
125 | ### 0.1.1 (2016-02-25)
126 |
--------------------------------------------------------------------------------
/doc/MAINTAINER.md:
--------------------------------------------------------------------------------
1 | ## Workflow releasing a new version
2 |
3 | 1. Update: pull latest master with `git pull`
4 | 2. Cut release: Run `npm run cut-release`. Example:
5 |
6 | ```shell
7 | # automatic detection based on commit
8 | npm run cut-release
9 | # manual version control
10 | npm run cut-release -- -- --release-as minor
11 | ```
12 | 3. Commit: `git add .` and then `git commit chore(release): prepare release vXXX` where `XXX` is the new version
13 | 4. Tag: `git tag -a XXX -m 'prepare release XXX'` where `XXX` is the version
14 | 5. Push to remote repo: `git push --follow-tags`
15 | 6. Publish: Run `npm publish` to release the new version
16 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aurelia-loader-webpack",
3 | "version": "2.2.5",
4 | "description": "An implementation of Aurelia's loader interface to enable webpack.",
5 | "keywords": [
6 | "aurelia",
7 | "webpack",
8 | "loader"
9 | ],
10 | "homepage": "http://aurelia.io",
11 | "bugs": {
12 | "url": "https://github.com/aurelia/loader-webpack/issues"
13 | },
14 | "license": "MIT",
15 | "author": "Bazyli Brzóska (https://invent.life/)",
16 | "main": "dist/commonjs/aurelia-loader-webpack.js",
17 | "typings": "dist/types/aurelia-loader-webpack.d.ts",
18 | "repository": {
19 | "type": "git",
20 | "url": "http://github.com/aurelia/loader-webpack"
21 | },
22 | "files": [
23 | "dist",
24 | "doc/CHANGELOG.md",
25 | "bowser.json",
26 | "typings.json"
27 | ],
28 | "scripts": {
29 | "build": "rollup -c",
30 | "postbuild": "tsc --declaration --emitDeclarationOnly",
31 | "changelog": "standard-version -t \"\" -i doc/CHANGELOG.md --skip.commit --skip.tag",
32 | "precut-release": "npm run build",
33 | "cut-release": "npm run changelog"
34 | },
35 | "dependencies": {
36 | "aurelia-hot-module-reload": "^0.3.0",
37 | "aurelia-loader": "^1.0.0",
38 | "aurelia-metadata": "^1.0.2",
39 | "aurelia-pal": "^1.1.1"
40 | },
41 | "devDependencies": {
42 | "@rollup/plugin-typescript": "^8.2.3",
43 | "@types/node": "^16.4.2",
44 | "rollup": "^2.54.0",
45 | "standard-version": "^9.5.0",
46 | "tslib": "^2.4.0",
47 | "typescript": "^4.0.2"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import typescript from '@rollup/plugin-typescript';
2 | import pkg from './package.json';
3 |
4 | const externals = Object.keys(pkg.dependencies);
5 |
6 | export default [{
7 | input: 'src/aurelia-loader-webpack.ts',
8 | output: [
9 | { file: `dist/amd/${pkg.name}.js`, format: 'amd', amd: { id: pkg.name } },
10 | { file: `dist/commonjs/${pkg.name}.js`, format: 'cjs' },
11 | { file: `dist/native-modules/${pkg.name}.js`, format: 'es' },
12 | ],
13 | plugins: [
14 | typescript()
15 | ],
16 | external: externals,
17 | }, {
18 | input: 'src/aurelia-loader-webpack.ts',
19 | output: [
20 | { file: `dist/es2015/${pkg.name}.js`, format: 'es' },
21 | { file: `dist/es2017/${pkg.name}.js`, format: 'es' },
22 | ],
23 | plugins: [
24 | typescript({
25 | target: 'es2015'
26 | })
27 | ],
28 | external: externals,
29 | }, {
30 | input: 'src/aurelia-loader-webpack.ts',
31 | output: [
32 | { file: `dist/es2017/${pkg.name}.js`, format: 'es' },
33 | ],
34 | plugins: [
35 | typescript({
36 | target: 'es2017'
37 | })
38 | ],
39 | external: externals,
40 | }];
41 |
--------------------------------------------------------------------------------
/src/aurelia-loader-webpack.ts:
--------------------------------------------------------------------------------
1 | import { Loader, LoaderPlugin as AureliaLoaderPlugin, TemplateRegistryEntry } from 'aurelia-loader';
2 | import { Origin } from 'aurelia-metadata';
3 | import { DOM, PLATFORM } from 'aurelia-pal';
4 |
5 | /** @internal */
6 | declare global {
7 | const __webpack_require__: import('./webpack-runtime').__webpack_require__;
8 | interface NodeModule {
9 | hot: WebpackHotModule;
10 | }
11 | }
12 |
13 | type CssLoaderModuleItem = [
14 | srcModule: string,
15 | cssContent: string,
16 | mediaAtRule?: string,
17 | sourceMap?: {
18 | version: number;
19 | names: string[];
20 | sourceRoot: string;
21 | sources: string[];
22 | sourcesContent: string[];
23 | mappings: string;
24 | },
25 | supportsAtRule?: string,
26 | layerAtRule?: string,
27 | ];
28 |
29 | type CssLoaderModule = CssLoaderModuleItem[] & {
30 | toString(): string;
31 | i: Function;
32 | }
33 |
34 | export type LoaderPlugin = { fetch: (address: string) => Promise | TemplateRegistryEntry };
35 |
36 | /**
37 | * An implementation of the TemplateLoader interface implemented with text-based loading.
38 | */
39 | export class TextTemplateLoader {
40 | /**
41 | * Loads a template.
42 | * @param loader The loader that is requesting the template load.
43 | * @param entry The TemplateRegistryEntry to load and populate with a template.
44 | * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
45 | */
46 | async loadTemplate(loader: Loader, entry: TemplateRegistryEntry) {
47 | const text = await loader.loadText(entry.address);
48 | entry.template = DOM.createTemplateFromMarkup(text);
49 | }
50 | }
51 |
52 | export function ensureOriginOnExports(moduleExports: any, moduleId: string) {
53 | let target = moduleExports;
54 | let key;
55 | let exportedValue;
56 |
57 | if (target.__useDefault) {
58 | target = target.default;
59 | }
60 |
61 | Origin.set(target, new Origin(moduleId, 'default'));
62 |
63 | if (typeof target === 'object') {
64 | for (key in target) {
65 | exportedValue = target[key];
66 |
67 | if (typeof exportedValue === 'function') {
68 | Origin.set(exportedValue, new Origin(moduleId, key));
69 | }
70 | }
71 | }
72 |
73 | return moduleExports;
74 | }
75 |
76 | /**
77 | * A default implementation of the Loader abstraction which works with webpack (extended common-js style).
78 | */
79 | export class WebpackLoader extends Loader {
80 | moduleRegistry = Object.create(null);
81 | loaderPlugins = Object.create(null) as { [name: string]: AureliaLoaderPlugin & { hot?: (moduleId: string) => void } };
82 | modulesBeingLoaded = new Map>();
83 | templateLoader: TextTemplateLoader;
84 | hmrContext: {
85 | handleModuleChange(moduleId: string, hot: WebpackHotModule): Promise,
86 | handleViewChange(moduleId: string): Promise
87 | };
88 |
89 | constructor() {
90 | super();
91 |
92 | this.useTemplateLoader(new TextTemplateLoader());
93 |
94 | this.addPlugin('template-registry-entry', {
95 | fetch: async (moduleId: string) => {
96 | // HMR:
97 | if (module.hot) {
98 | if (!this.hmrContext) {
99 | // Note: Please do NOT import aurelia-hot-module-reload statically at the top of file.
100 | // We don't want to bundle it when not using --hot, in particular in production builds.
101 | // Webpack will evaluate the `if (module.hot)` above at build time
102 | // and will include (or not) aurelia-hot-module-reload accordingly.
103 | const { HmrContext } = require('aurelia-hot-module-reload');
104 | this.hmrContext = new HmrContext(this as any);
105 | }
106 | module.hot.accept(moduleId, async () => {
107 | await this.hmrContext.handleViewChange(moduleId);
108 | });
109 | }
110 |
111 | const entry = this.getOrCreateTemplateRegistryEntry(moduleId);
112 | if (!entry.templateIsLoaded) {
113 | await this.templateLoader.loadTemplate(this, entry);
114 | }
115 | return entry;
116 | }
117 | } as AureliaLoaderPlugin);
118 |
119 | PLATFORM.eachModule = callback => {
120 | const registry = __webpack_require__.c;
121 | const cachedModuleIds = Object.getOwnPropertyNames(registry);
122 | cachedModuleIds
123 | // Note: we use .some here like a .forEach that can be "break"ed out of.
124 | // It will stop iterating only when a truthy value is returned.
125 | // Even though the docs say "true" explicitly, loader-default also goes by truthy
126 | // and this is to keep it consistent with that.
127 | .some(moduleId => {
128 | const moduleExports = registry[moduleId].exports;
129 | if (typeof moduleExports === 'object') {
130 | return callback(moduleId, moduleExports);
131 | }
132 | return false;
133 | });
134 | };
135 | }
136 |
137 | async _import(address: string, defaultHMR = true): Promise {
138 | const addressParts = address.split('!');
139 | const moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
140 | const loaderPlugin = addressParts.length === 1 ? addressParts[0] : null;
141 |
142 | if (loaderPlugin) {
143 | const plugin = this.loaderPlugins[loaderPlugin];
144 | if (!plugin) {
145 | throw new Error(`Plugin ${loaderPlugin} is not registered in the loader.`);
146 | }
147 | if (module.hot && plugin.hot) {
148 | module.hot.accept(moduleId, () => plugin.hot!(moduleId));
149 | }
150 | return await plugin.fetch(moduleId);
151 | }
152 |
153 | if (__webpack_require__.m[moduleId]) {
154 | if (defaultHMR && module.hot && this.hmrContext) {
155 | module.hot.accept(moduleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
156 | }
157 | return __webpack_require__(moduleId);
158 | }
159 |
160 | const asyncModuleId = `async!${moduleId}`;
161 |
162 | if (__webpack_require__.m[asyncModuleId]) {
163 | if (defaultHMR && module.hot && this.hmrContext) {
164 | module.hot.accept(moduleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
165 | module.hot.accept(asyncModuleId, () => this.hmrContext.handleModuleChange(moduleId, module.hot));
166 | }
167 | const callback = __webpack_require__(asyncModuleId) as (callback: (moduleExports: any) => void) => void;
168 | return await new Promise(callback);
169 | }
170 |
171 | throw new Error(`Unable to find module with ID: ${moduleId}`);
172 | }
173 |
174 | /**
175 | * Maps a module id to a source.
176 | * @param id The module id.
177 | * @param source The source to map the module to.
178 | */
179 | map(id: string, source: any) {}
180 |
181 | /**
182 | * Normalizes a module id.
183 | * @param moduleId The module id to normalize.
184 | * @param relativeTo What the module id should be normalized relative to.
185 | * @return The normalized module id.
186 | */
187 | normalizeSync(moduleId: string, relativeTo: string) {
188 | return moduleId;
189 | }
190 |
191 | /**
192 | * Normalizes a module id.
193 | * @param moduleId The module id to normalize.
194 | * @param relativeTo What the module id should be normalized relative to.
195 | * @return The normalized module id.
196 | */
197 | normalize(moduleId: string, relativeTo: string) {
198 | return Promise.resolve(moduleId);
199 | }
200 |
201 | /**
202 | * Instructs the loader to use a specific TemplateLoader instance for loading templates
203 | * @param templateLoader The instance of TemplateLoader to use for loading templates.
204 | */
205 | useTemplateLoader(templateLoader: TextTemplateLoader) {
206 | this.templateLoader = templateLoader;
207 | }
208 |
209 | /**
210 | * Loads a collection of modules.
211 | * @param ids The set of module ids to load.
212 | * @return A Promise for an array of loaded modules.
213 | */
214 | loadAllModules(ids: Array) {
215 | return Promise.all(
216 | ids.map(id => this.loadModule(id))
217 | );
218 | }
219 |
220 | /**
221 | * Loads a module.
222 | * @param moduleId The module ID to load.
223 | * @return A Promise for the loaded module.
224 | */
225 | async loadModule(moduleId: string, defaultHMR = true) {
226 | let existing = this.moduleRegistry[moduleId];
227 | if (existing) {
228 | return existing;
229 | }
230 | let beingLoaded = this.modulesBeingLoaded.get(moduleId);
231 | if (beingLoaded) {
232 | return beingLoaded;
233 | }
234 | beingLoaded = this._import(moduleId, defaultHMR);
235 | this.modulesBeingLoaded.set(moduleId, beingLoaded);
236 | const moduleExports = await beingLoaded;
237 | this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
238 | this.modulesBeingLoaded.delete(moduleId);
239 | return moduleExports;
240 | }
241 |
242 | /**
243 | * Loads a template.
244 | * @param url The url of the template to load.
245 | * @return A Promise for a TemplateRegistryEntry containing the template.
246 | */
247 | loadTemplate(url: string) {
248 | return this.loadModule(this.applyPluginToUrl(url, 'template-registry-entry'), false);
249 | }
250 |
251 | /**
252 | * Loads a text-based resource.
253 | * @param url The url of the text file to load.
254 | * @return A Promise for text content.
255 | */
256 | async loadText(url: string) {
257 | const result = await this.loadModule(url, false);
258 | // css-loader could use esModule:true
259 | const defaultExport = result && result.__esModule ? result.default : result;
260 | if (this.isCssLoaderModule(defaultExport)) {
261 | // we're dealing with a file loaded using the css-loader:
262 | return this.getCssText(defaultExport);
263 | }
264 | return typeof result === "string" ? result : defaultExport;
265 | }
266 |
267 | /**
268 | * Check if a loaded module is a css-loader module
269 | * @param o The loaded module
270 | * @returns `true` when {@link o} is a {@link CssLoaderModule}; otherwise false
271 | */
272 | private isCssLoaderModule(o: any): o is CssLoaderModule {
273 | return o instanceof Array && o[0] instanceof Array && o.hasOwnProperty('toString');
274 | }
275 |
276 | /**
277 | * Get CSS text from loaded css-loader module
278 | * @param cssLoaderModule The {@link CssLoaderModule}
279 | * @returns The css content with potential source map references
280 | */
281 | private getCssText(cssLoaderModule: CssLoaderModule): string {
282 | let result = cssLoaderModule.toString();
283 |
284 | // If some css-loader modules include source maps,
285 | // ensure /*# sourceURL=[...] */ is removed to avoid chrome devtools problems
286 | if (cssLoaderModule.some(m => m[3])) {
287 | result = result.replace(/^\/\*# sourceURL=.* \*\/\s*\n/gm, "");
288 | }
289 |
290 | return result;
291 | }
292 |
293 | /**
294 | * Alters a module id so that it includes a plugin loader.
295 | * @param url The url of the module to load.
296 | * @param pluginName The plugin to apply to the module id.
297 | * @return The plugin-based module id.
298 | */
299 | applyPluginToUrl(url: string, pluginName: string) {
300 | return `${pluginName}!${url}`;
301 | }
302 |
303 | /**
304 | * Registers a plugin with the loader.
305 | * @param pluginName The name of the plugin.
306 | * @param implementation The plugin implementation.
307 | */
308 | addPlugin(pluginName: string, implementation: AureliaLoaderPlugin) {
309 | this.loaderPlugins[pluginName] = implementation;
310 | }
311 | }
312 |
313 | (PLATFORM as any).Loader = WebpackLoader;
314 |
315 | export type HotModuleStatus = 'idle' | 'check' | 'watch' | 'watch-delay' | 'prepare' | 'ready' | 'dispose' | 'apply' | 'abort' | 'fail';
316 | export interface WebpackHotModule {
317 | /**
318 | * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
319 | */
320 | accept(dependencies: string[], callback: (updatedDependencies: Array) => void): void;
321 | /**
322 | * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
323 | */
324 | accept(dependency: string, callback: () => void): void;
325 | /**
326 | * Accept code updates for this module without notification of parents. This should only be used if the module doesn’t export anything. The errHandler can be used to handle errors that occur while loading the updated module.
327 | */
328 | accept(errHandler?: (e: Error) => void): void;
329 |
330 | /**
331 | * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
332 | */
333 | decline(dependencies: string[]): void;
334 | /**
335 | * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
336 | */
337 | decline(dependency: string): void;
338 | /**
339 | * Flag the current module as not update-able. If updated the update code would fail with code "decline".
340 | */
341 | decline(): void;
342 |
343 | /**
344 | * Add a one time handler, which is executed when the current module code is replaced. Here you should destroy/remove any persistent resource you have claimed/created. If you want to transfer state to the new module, add it to data object. The data will be available at module.hot.data on the new module.
345 | */
346 | dispose(callback: (data: any) => void): void;
347 | /**
348 | * Add a one time handler, which is executed when the current module code is replaced. Here you should destroy/remove any persistent resource you have claimed/created. If you want to transfer state to the new module, add it to data object. The data will be available at module.hot.data on the new module.
349 | */
350 | addDisposeHandler(callback: (data: any) => void): void;
351 |
352 | /**
353 | * Remove a dispose handler.
354 | * This can useful to add a temporary dispose handler. You could i. e. replace code while in the middle of a multi-step async function.
355 | */
356 | removeDisposeHandler(callback: (data: any) => void): void;
357 |
358 | /**
359 | * Throws an exceptions if status() is not idle.
360 | * Check all currently loaded modules for updates and apply updates if found.
361 | * If no update was found, the callback is called with null.
362 | * If autoApply is truthy the callback will be called with all modules that were disposed. apply() is automatically called with autoApply as options parameter.
363 | * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
364 | */
365 | check(autoApply: boolean, callback: (err: Error, outdatedModules: any[]) => void): void;
366 | /**
367 | * Throws an exceptions if status() is not idle.
368 | * Check all currently loaded modules for updates and apply updates if found.
369 | * If no update was found, the callback is called with null.
370 | * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
371 | */
372 | check(callback: (err: Error, outdatedModules: NodeModule[]) => void): void;
373 |
374 | /**
375 | * Continue the update process.
376 | * If status() != "ready" it throws an error.
377 | */
378 | apply(options: HotOptions, callback: (err: Error, outdatedModules: any[]) => void): void;
379 | apply(callback: (err: Error, outdatedModules: any[]) => void): void;
380 |
381 | /**
382 | * Return one of idle, check, watch, watch-delay, prepare, ready, dispose, apply, abort or fail.
383 | *
384 | * - `idle`
385 | * The HMR is waiting for your call the check(). When you call it the status will change to check.
386 | *
387 | * - `check`
388 | * The HMR is checking for updates. If it doesn’t find updates it will change back to idle. If updates were found it will go through the steps prepare, dispose and apply. Than back to idle.
389 | *
390 | * - `watch`
391 | * The HMR is in watch mode and will automatically be notified about changes. After the first change it will change to watch-delay and wait for a specified time to start the update process. Any change will reset the timeout, to accumulate more changes. When the update process is started it will go through the steps prepare, dispose and apply. Than back to watch or watch-delay if changes were detected while updating.
392 | *
393 | * - `prepare`
394 | * The HMR is prepare stuff for the update. This may means that it’s downloading something.
395 | *
396 | * - `ready`
397 | * An update is available and prepared. Call apply() to continue.
398 | *
399 | * - `dispose`
400 | * The HMR is calling the dispose handlers of modules that will be replaced.
401 | *
402 | * - `apply`
403 | * The HMR is calling the accept handlers of the parents of replaced modules, than it requires the self accepted modules.
404 | *
405 | * - `abort`
406 | * A update cannot apply, but the system is still in a (old) consistent state.
407 | *
408 | * - `fail`
409 | * A update has thrown an exception in the middle of the process, and the system is (maybe) in a inconsistent state. The system should be restarted.
410 | */
411 | status(): HotModuleStatus;
412 |
413 | /**
414 | * Register a callback on status change.
415 | */
416 | status(callback: (status: HotModuleStatus) => void): void;
417 | /**
418 | * Register a callback on status change.
419 | */
420 | addStatusHandler(callback: (status: HotModuleStatus) => void): void;
421 |
422 | /**
423 | * Data from the previous version of this module, if set and disposed using the dispose() handler.
424 | */
425 | data?: any;
426 | }
427 |
428 | export interface HotOptions {
429 | /**
430 | * If true the update process continues even if some modules are not accepted (and would bubble to the entry point).
431 | */
432 | ignoreUnaccepted?: boolean;
433 | }
434 |
--------------------------------------------------------------------------------
/src/webpack-runtime.d.ts:
--------------------------------------------------------------------------------
1 | export type __webpack_require__ = {
2 | (moduleId: string): any;
3 | /**
4 | * require.ensure method
5 | */
6 | e(chunkId: string): Promise;
7 | /**
8 | * Object containing available Webpack modules
9 | */
10 | m: { [name: string]: any; [number: number]: any; };
11 | /**
12 | * The module cache (already loaded modules)
13 | */
14 | c: { [name: string]: any; [number: number]: any; };
15 | /**
16 | * Identity function for calling harmory imports with the correct context
17 | */
18 | i(value: T): T;
19 | /**
20 | * Define getter function for harmory exports
21 | */
22 | d any>(exports: T, name: string, getter: Y): T & { name: Y };
23 | /**
24 | * getDefaultExport function for compatibility with non-harmony modules
25 | */
26 | n(module: any): any;
27 | o: typeof Object.prototype.hasOwnProperty;
28 | /**
29 | * __webpack_public_path__
30 | */
31 | p: string;
32 | /**
33 | * on error function for async loading
34 | */
35 | oe(err: Error): void;
36 | /**
37 | * entry module ID
38 | */
39 | s: number | string;
40 | };
41 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "exclude": [
4 | ".vscode",
5 | "dist",
6 | "doc",
7 | "node_modules",
8 | "test",
9 | "build"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "esnext",
5 | "lib": ["ES2015", "DOM"],
6 | "moduleResolution": "node",
7 | "noUnusedParameters": false,
8 | "types": ["node"],
9 | "stripInternal": true,
10 | "declaration": true,
11 | "declarationDir": "dist/types"
12 | },
13 | "exclude": [
14 | ".vscode",
15 | "dist",
16 | "doc",
17 | "node_modules",
18 | "build"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/typings.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aurelia-loader-webpack",
3 | "main": "dist/types/aurelia-loader-webpack.d.ts"
4 | }
5 |
--------------------------------------------------------------------------------