@angular-devkit/build-webpack 0.1302.0-rc.0 → 0.1302.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-webpack",
3
- "version": "0.1302.0-rc.0",
3
+ "version": "0.1302.2",
4
4
  "description": "Webpack Builder for Architect",
5
5
  "experimental": true,
6
6
  "main": "src/index.js",
7
7
  "typings": "src/index.d.ts",
8
8
  "builders": "builders.json",
9
9
  "dependencies": {
10
- "@angular-devkit/architect": "0.1302.0-rc.0",
10
+ "@angular-devkit/architect": "0.1302.2",
11
11
  "rxjs": "6.6.7"
12
12
  },
13
13
  "peerDependencies": {
package/src/utils.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
+ import { Compilation, Configuration } from 'webpack';
8
9
  export interface EmittedFiles {
9
10
  id?: string;
10
11
  name?: string;
@@ -13,4 +14,5 @@ export interface EmittedFiles {
13
14
  asset?: boolean;
14
15
  extension: string;
15
16
  }
16
- export declare function getEmittedFiles(compilation: import('webpack').Compilation): EmittedFiles[];
17
+ export declare function getEmittedFiles(compilation: Compilation): EmittedFiles[];
18
+ export declare function getWebpackConfig(configPath: string): Promise<Configuration>;
package/src/utils.js CHANGED
@@ -26,8 +26,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getEmittedFiles = void 0;
29
+ exports.getWebpackConfig = exports.getEmittedFiles = void 0;
30
+ const fs_1 = require("fs");
30
31
  const path = __importStar(require("path"));
32
+ const url_1 = require("url");
31
33
  function getEmittedFiles(compilation) {
32
34
  var _a;
33
35
  const files = [];
@@ -59,3 +61,49 @@ function getEmittedFiles(compilation) {
59
61
  return files;
60
62
  }
61
63
  exports.getEmittedFiles = getEmittedFiles;
64
+ /**
65
+ * This uses a dynamic import to load a module which may be ESM.
66
+ * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
67
+ * will currently, unconditionally downlevel dynamic import into a require call.
68
+ * require calls cannot load ESM code and will result in a runtime error. To workaround
69
+ * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
70
+ * Once TypeScript provides support for keeping the dynamic import this workaround can
71
+ * be dropped.
72
+ *
73
+ * @param modulePath The path of the module to load.
74
+ * @returns A Promise that resolves to the dynamically imported module.
75
+ */
76
+ function loadEsmModule(modulePath) {
77
+ return new Function('modulePath', `return import(modulePath);`)(modulePath);
78
+ }
79
+ async function getWebpackConfig(configPath) {
80
+ if (!(0, fs_1.existsSync)(configPath)) {
81
+ throw new Error(`Webpack configuration file ${configPath} does not exist.`);
82
+ }
83
+ switch (path.extname(configPath)) {
84
+ case '.mjs':
85
+ // Load the ESM configuration file using the TypeScript dynamic import workaround.
86
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
87
+ // changed to a direct dynamic import.
88
+ return (await loadEsmModule((0, url_1.pathToFileURL)(configPath))).default;
89
+ case '.cjs':
90
+ return require(configPath);
91
+ default:
92
+ // The file could be either CommonJS or ESM.
93
+ // CommonJS is tried first then ESM if loading fails.
94
+ try {
95
+ return require(configPath);
96
+ }
97
+ catch (e) {
98
+ if (e.code === 'ERR_REQUIRE_ESM') {
99
+ // Load the ESM configuration file using the TypeScript dynamic import workaround.
100
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
101
+ // changed to a direct dynamic import.
102
+ return (await loadEsmModule((0, url_1.pathToFileURL)(configPath)))
103
+ .default;
104
+ }
105
+ throw e;
106
+ }
107
+ }
108
+ }
109
+ exports.getWebpackConfig = getWebpackConfig;
@@ -6,25 +6,6 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
9
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
11
  };
@@ -104,5 +85,5 @@ function runWebpack(config, context, options = {}) {
104
85
  exports.runWebpack = runWebpack;
105
86
  exports.default = (0, architect_1.createBuilder)((options, context) => {
106
87
  const configPath = (0, path_1.resolve)(context.workspaceRoot, options.webpackConfig);
107
- return (0, rxjs_1.from)(Promise.resolve().then(() => __importStar(require(configPath)))).pipe((0, operators_1.switchMap)(({ default: config }) => runWebpack(config, context)));
88
+ return (0, rxjs_1.from)((0, utils_1.getWebpackConfig)(configPath)).pipe((0, operators_1.switchMap)((config) => runWebpack(config, context)));
108
89
  });
@@ -6,25 +6,6 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
9
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
11
  };
@@ -99,5 +80,5 @@ function runWebpackDevServer(config, context, options = {}) {
99
80
  exports.runWebpackDevServer = runWebpackDevServer;
100
81
  exports.default = (0, architect_1.createBuilder)((options, context) => {
101
82
  const configPath = (0, path_1.resolve)(context.workspaceRoot, options.webpackConfig);
102
- return (0, rxjs_1.from)(Promise.resolve().then(() => __importStar(require(configPath)))).pipe((0, operators_1.switchMap)(({ default: config }) => runWebpackDevServer(config, context)));
83
+ return (0, rxjs_1.from)((0, utils_1.getWebpackConfig)(configPath)).pipe((0, operators_1.switchMap)((config) => runWebpackDevServer(config, context)));
103
84
  });