UNPKG

9.63 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 var desc = Object.getOwnPropertyDescriptor(m, k);
12 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13 desc = { enumerable: true, get: function() { return m[k]; } };
14 }
15 Object.defineProperty(o, k2, desc);
16}) : (function(o, m, k, k2) {
17 if (k2 === undefined) k2 = k;
18 o[k2] = m[k];
19}));
20var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21 Object.defineProperty(o, "default", { enumerable: true, value: v });
22}) : function(o, v) {
23 o["default"] = v;
24});
25var __importStar = (this && this.__importStar) || function (mod) {
26 if (mod && mod.__esModule) return mod;
27 var result = {};
28 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29 __setModuleDefault(result, mod);
30 return result;
31};
32Object.defineProperty(exports, "__esModule", { value: true });
33exports.default = exports.angularWebpackLoader = void 0;
34const path = __importStar(require("path"));
35const symbol_1 = require("./symbol");
36const JS_FILE_REGEXP = /\.[cm]?js$/;
37function angularWebpackLoader(content, map) {
38 const callback = this.async();
39 if (!callback) {
40 throw new Error('Invalid webpack version');
41 }
42 const fileEmitter = this[symbol_1.AngularPluginSymbol];
43 if (!fileEmitter || typeof fileEmitter !== 'object') {
44 if (JS_FILE_REGEXP.test(this.resourcePath)) {
45 // Passthrough for JS files when no plugin is used
46 this.callback(undefined, content, map);
47 return;
48 }
49 callback(new Error('The Angular Webpack loader requires the AngularWebpackPlugin.'));
50 return;
51 }
52 fileEmitter
53 .emit(this.resourcePath)
54 .then((result) => {
55 if (!result) {
56 if (JS_FILE_REGEXP.test(this.resourcePath)) {
57 // Return original content for JS files if not compiled by TypeScript ("allowJs")
58 this.callback(undefined, content, map);
59 }
60 else {
61 // File is not part of the compilation
62 const message = `${this.resourcePath} is missing from the TypeScript compilation. ` +
63 `Please make sure it is in your tsconfig via the 'files' or 'include' property.`;
64 callback(new Error(message));
65 }
66 return;
67 }
68 result.dependencies.forEach((dependency) => this.addDependency(dependency));
69 let resultContent = result.content || '';
70 let resultMap;
71 if (result.map) {
72 resultContent = resultContent.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
73 resultMap = JSON.parse(result.map);
74 resultMap.sources = resultMap.sources.map((source) => path.join(path.dirname(this.resourcePath), source));
75 }
76 callback(undefined, resultContent, resultMap);
77 })
78 .catch((err) => {
79 // The below is needed to hide stacktraces from users.
80 const message = err instanceof Error ? err.message : err;
81 callback(new Error(message));
82 });
83}
84exports.angularWebpackLoader = angularWebpackLoader;
85exports.default = angularWebpackLoader;
86//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvbmd0b29scy93ZWJwYWNrL3NyYy9pdnkvbG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRUgsMkNBQTZCO0FBRTdCLHFDQUFzRTtBQUV0RSxNQUFNLGNBQWMsR0FBRyxZQUFZLENBQUM7QUFFcEMsU0FBZ0Isb0JBQW9CLENBQStCLE9BQWUsRUFBRSxHQUFXO0lBQzdGLE1BQU0sUUFBUSxHQUFHLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM5QixJQUFJLENBQUMsUUFBUSxFQUFFO1FBQ2IsTUFBTSxJQUFJLEtBQUssQ0FBQyx5QkFBeUIsQ0FBQyxDQUFDO0tBQzV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