@angular-devkit/architect 0.1302.0-rc.0 → 0.1302.0-rc.1
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.
|
@@ -28,6 +28,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.WorkspaceNodeModulesArchitectHost = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
|
+
const url_1 = require("url");
|
|
31
32
|
const v8_1 = require("v8");
|
|
32
33
|
const internal_1 = require("../src/internal");
|
|
33
34
|
function clone(obj) {
|
|
@@ -166,7 +167,7 @@ class WorkspaceNodeModulesArchitectHost {
|
|
|
166
167
|
return metadata;
|
|
167
168
|
}
|
|
168
169
|
async loadBuilder(info) {
|
|
169
|
-
const builder =
|
|
170
|
+
const builder = await getBuilder(info.import);
|
|
170
171
|
if (builder[internal_1.BuilderSymbol]) {
|
|
171
172
|
return builder;
|
|
172
173
|
}
|
|
@@ -178,3 +179,45 @@ class WorkspaceNodeModulesArchitectHost {
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
exports.WorkspaceNodeModulesArchitectHost = WorkspaceNodeModulesArchitectHost;
|
|
182
|
+
/**
|
|
183
|
+
* This uses a dynamic import to load a module which may be ESM.
|
|
184
|
+
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
|
|
185
|
+
* will currently, unconditionally downlevel dynamic import into a require call.
|
|
186
|
+
* require calls cannot load ESM code and will result in a runtime error. To workaround
|
|
187
|
+
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
|
|
188
|
+
* Once TypeScript provides support for keeping the dynamic import this workaround can
|
|
189
|
+
* be dropped.
|
|
190
|
+
*
|
|
191
|
+
* @param modulePath The path of the module to load.
|
|
192
|
+
* @returns A Promise that resolves to the dynamically imported module.
|
|
193
|
+
*/
|
|
194
|
+
function loadEsmModule(modulePath) {
|
|
195
|
+
return new Function('modulePath', `return import(modulePath);`)(modulePath);
|
|
196
|
+
}
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
async function getBuilder(builderPath) {
|
|
199
|
+
switch (path.extname(builderPath)) {
|
|
200
|
+
case '.mjs':
|
|
201
|
+
// Load the ESM configuration file using the TypeScript dynamic import workaround.
|
|
202
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
203
|
+
// changed to a direct dynamic import.
|
|
204
|
+
return (await loadEsmModule((0, url_1.pathToFileURL)(builderPath))).default;
|
|
205
|
+
case '.cjs':
|
|
206
|
+
return require(builderPath);
|
|
207
|
+
default:
|
|
208
|
+
// The file could be either CommonJS or ESM.
|
|
209
|
+
// CommonJS is tried first then ESM if loading fails.
|
|
210
|
+
try {
|
|
211
|
+
return require(builderPath);
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
if (e.code === 'ERR_REQUIRE_ESM') {
|
|
215
|
+
// Load the ESM configuration file using the TypeScript dynamic import workaround.
|
|
216
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
217
|
+
// changed to a direct dynamic import.
|
|
218
|
+
return (await loadEsmModule((0, url_1.pathToFileURL)(builderPath))).default;
|
|
219
|
+
}
|
|
220
|
+
throw e;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-devkit/architect",
|
|
3
|
-
"version": "0.1302.0-rc.
|
|
3
|
+
"version": "0.1302.0-rc.1",
|
|
4
4
|
"description": "Angular Build Facade",
|
|
5
5
|
"experimental": true,
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"typings": "src/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@angular-devkit/core": "13.2.0-rc.
|
|
9
|
+
"@angular-devkit/core": "13.2.0-rc.1",
|
|
10
10
|
"rxjs": "6.6.7"
|
|
11
11
|
},
|
|
12
12
|
"builders": "./builders/builders.json",
|