@nx/angular 17.2.0-beta.9 → 17.2.0-canary.20231207-b8d24e6

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.
Files changed (41) hide show
  1. package/executors.d.ts +2 -1
  2. package/executors.js +2 -1
  3. package/executors.json +10 -5
  4. package/package.json +10 -10
  5. package/src/builders/dev-server/dev-server.impl.js +65 -24
  6. package/src/builders/utilities/module-federation.js +1 -1
  7. package/src/builders/webpack-browser/webpack-browser.impl.js +2 -1
  8. package/src/builders/webpack-server/webpack-server.impl.js +2 -1
  9. package/src/executors/application/application.impl.d.ts +9 -0
  10. package/src/executors/application/application.impl.js +28 -0
  11. package/src/executors/application/schema.d.ts +7 -0
  12. package/src/executors/application/schema.json +612 -0
  13. package/src/executors/browser-esbuild/browser-esbuild.impl.d.ts +2 -3
  14. package/src/executors/browser-esbuild/browser-esbuild.impl.js +15 -6
  15. package/src/executors/browser-esbuild/schema.d.ts +3 -1
  16. package/src/executors/browser-esbuild/schema.json +30 -0
  17. package/src/executors/module-federation-dev-server/lib/build-static-remotes.d.ts +7 -0
  18. package/src/executors/module-federation-dev-server/lib/build-static-remotes.js +49 -0
  19. package/src/executors/module-federation-dev-server/lib/index.d.ts +4 -0
  20. package/src/executors/module-federation-dev-server/lib/index.js +7 -0
  21. package/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +2 -0
  22. package/src/executors/module-federation-dev-server/lib/normalize-options.js +20 -0
  23. package/src/executors/module-federation-dev-server/lib/start-dev-remotes.d.ts +9 -0
  24. package/src/executors/module-federation-dev-server/lib/start-dev-remotes.js +29 -0
  25. package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.d.ts +12 -0
  26. package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.js +48 -0
  27. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +3 -0
  28. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +110 -0
  29. package/src/{builders → executors}/module-federation-dev-server/schema.json +9 -3
  30. package/src/executors/utilities/buildable-libs.d.ts +6 -0
  31. package/src/executors/{browser-esbuild/lib → utilities}/buildable-libs.js +3 -4
  32. package/src/executors/utilities/esbuild-extensions.d.ts +6 -0
  33. package/src/executors/utilities/esbuild-extensions.js +27 -0
  34. package/src/executors/utilities/module-loader.d.ts +15 -0
  35. package/src/executors/utilities/module-loader.js +52 -0
  36. package/src/executors/utilities/ng-compiler-cli.d.ts +0 -14
  37. package/src/executors/utilities/ng-compiler-cli.js +3 -23
  38. package/src/builders/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -5
  39. package/src/builders/module-federation-dev-server/module-federation-dev-server.impl.js +0 -232
  40. package/src/executors/browser-esbuild/lib/buildable-libs.d.ts +0 -9
  41. /package/src/{builders → executors}/module-federation-dev-server/schema.d.ts +0 -0
@@ -2,6 +2,7 @@
2
2
  "$schema": "http://json-schema.org/draft-07/schema",
3
3
  "title": "Schema for Nx ESBuild Executor",
4
4
  "description": "Nx ESBuild Executor supporting Incremental Builds.",
5
+ "examplesFile": "../../../docs/browser-esbuild-examples.md",
5
6
  "outputCapture": "direct-nodejs",
6
7
  "type": "object",
7
8
  "properties": {
@@ -441,6 +442,35 @@
441
442
  "type": "boolean",
442
443
  "description": "Read buildable libraries from source instead of building them separately.",
443
444
  "default": true
445
+ },
446
+ "plugins": {
447
+ "description": "A list of ESBuild plugins. _Note: this is only supported in Angular versions >= 17.0.0_.",
448
+ "type": "array",
449
+ "items": {
450
+ "oneOf": [
451
+ {
452
+ "type": "object",
453
+ "properties": {
454
+ "path": {
455
+ "type": "string",
456
+ "description": "The path to the plugin. Relative to the workspace root."
457
+ },
458
+ "options": {
459
+ "type": "object",
460
+ "description": "The options to provide to the plugin.",
461
+ "properties": {},
462
+ "additionalProperties": true
463
+ }
464
+ },
465
+ "additionalProperties": false,
466
+ "required": ["path"]
467
+ },
468
+ {
469
+ "type": "string",
470
+ "description": "The path to the plugin. Relative to the workspace root."
471
+ }
472
+ ]
473
+ }
444
474
  }
445
475
  },
446
476
  "additionalProperties": false,
@@ -0,0 +1,7 @@
1
+ import { type Schema } from '../schema';
2
+ import { type ExecutorContext } from '@nx/devkit';
3
+ export declare function buildStaticRemotes(remotes: {
4
+ remotePorts: any[];
5
+ staticRemotes: string[];
6
+ devRemotes: string[];
7
+ }, nxBin: any, context: ExecutorContext, options: Schema): Promise<void>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildStaticRemotes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const child_process_1 = require("child_process");
6
+ async function buildStaticRemotes(remotes, nxBin, context, options) {
7
+ if (!remotes.staticRemotes ||
8
+ (Array.isArray(remotes.staticRemotes) && !remotes.staticRemotes.length)) {
9
+ return;
10
+ }
11
+ const mappedLocationOfRemotes = {};
12
+ for (const app of remotes.staticRemotes) {
13
+ mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${app}`;
14
+ }
15
+ process.env.NX_MF_DEV_SERVER_STATIC_REMOTES = JSON.stringify(mappedLocationOfRemotes);
16
+ await new Promise((res) => {
17
+ devkit_1.logger.info(`NX Building ${remotes.staticRemotes.length} static remotes...`);
18
+ const staticProcess = (0, child_process_1.fork)(nxBin, [
19
+ 'run-many',
20
+ `--target=build`,
21
+ `--projects=${remotes.staticRemotes.join(',')}`,
22
+ ...(context.configurationName
23
+ ? [`--configuration=${context.configurationName}`]
24
+ : []),
25
+ ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
26
+ ], {
27
+ cwd: context.root,
28
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
29
+ });
30
+ staticProcess.stdout.on('data', (data) => {
31
+ const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
32
+ const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
33
+ if (stdoutString.includes('Successfully ran target build')) {
34
+ staticProcess.stdout.removeAllListeners('data');
35
+ devkit_1.logger.info(`NX Built ${remotes.staticRemotes.length} static remotes`);
36
+ res();
37
+ }
38
+ });
39
+ staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
40
+ staticProcess.on('exit', (code) => {
41
+ if (code !== 0) {
42
+ throw new Error(`Remotes failed to build. See above for errors.`);
43
+ }
44
+ });
45
+ process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
46
+ process.on('exit', () => staticProcess.kill('SIGTERM'));
47
+ });
48
+ }
49
+ exports.buildStaticRemotes = buildStaticRemotes;
@@ -0,0 +1,4 @@
1
+ export * from './build-static-remotes';
2
+ export * from './normalize-options';
3
+ export * from './start-dev-remotes';
4
+ export * from './start-static-remotes-file-server';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./build-static-remotes"), exports);
5
+ tslib_1.__exportStar(require("./normalize-options"), exports);
6
+ tslib_1.__exportStar(require("./start-dev-remotes"), exports);
7
+ tslib_1.__exportStar(require("./start-static-remotes-file-server"), exports);
@@ -0,0 +1,2 @@
1
+ import type { NormalizedSchema, Schema } from '../schema';
2
+ export declare function normalizeOptions(schema: Schema): NormalizedSchema;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ function normalizeOptions(schema) {
5
+ let buildTarget = schema.buildTarget;
6
+ if (schema.browserTarget) {
7
+ buildTarget ??= schema.browserTarget;
8
+ delete schema.browserTarget;
9
+ }
10
+ return {
11
+ ...schema,
12
+ buildTarget,
13
+ host: schema.host ?? 'localhost',
14
+ port: schema.port ?? 4200,
15
+ liveReload: schema.liveReload ?? true,
16
+ open: schema.open ?? false,
17
+ ssl: schema.ssl ?? false,
18
+ };
19
+ }
20
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,9 @@
1
+ import { type Schema } from '../schema';
2
+ import { type ExecutorContext, type ProjectConfiguration } from '@nx/devkit';
3
+ export declare function startDevRemotes(remotes: {
4
+ remotePorts: any[];
5
+ staticRemotes: string[];
6
+ devRemotes: string[];
7
+ }, workspaceProjects: Record<string, ProjectConfiguration>, options: Schema, context: ExecutorContext): Promise<AsyncIterable<{
8
+ success: boolean;
9
+ }>[]>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startDevRemotes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function startDevRemotes(remotes, workspaceProjects, options, context) {
6
+ const devRemotesIters = [];
7
+ for (const app of remotes.devRemotes) {
8
+ if (!workspaceProjects[app].targets?.['serve']) {
9
+ throw new Error(`Could not find "serve" target in "${app}" project.`);
10
+ }
11
+ else if (!workspaceProjects[app].targets?.['serve'].executor) {
12
+ throw new Error(`Could not find executor for "serve" target in "${app}" project.`);
13
+ }
14
+ const [collection, executor] = workspaceProjects[app].targets['serve'].executor.split(':');
15
+ const isUsingModuleFederationDevServerExecutor = executor.includes('module-federation-dev-server');
16
+ devRemotesIters.push(await (0, devkit_1.runExecutor)({
17
+ project: app,
18
+ target: 'serve',
19
+ configuration: context.configurationName,
20
+ }, {
21
+ verbose: options.verbose ?? false,
22
+ ...(isUsingModuleFederationDevServerExecutor
23
+ ? { isInitialHost: false }
24
+ : {}),
25
+ }, context));
26
+ }
27
+ return devRemotesIters;
28
+ }
29
+ exports.startDevRemotes = startDevRemotes;
@@ -0,0 +1,12 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
2
+ import { type Schema } from '../schema';
3
+ export declare function startStaticRemotesFileServer(remotes: {
4
+ remotePorts: any[];
5
+ staticRemotes: string[];
6
+ devRemotes: string[];
7
+ }, context: ExecutorContext, options: Schema): AsyncGenerator<{
8
+ success: boolean;
9
+ baseUrl: string;
10
+ }, {
11
+ success: boolean;
12
+ }, unknown>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startStaticRemotesFileServer = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
6
+ const path_1 = require("path");
7
+ const fs_1 = require("fs");
8
+ function startStaticRemotesFileServer(remotes, context, options) {
9
+ let shouldMoveToCommonLocation = false;
10
+ let commonOutputDirectory;
11
+ for (const app of remotes.staticRemotes) {
12
+ const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
13
+ const directoryOfOutputPath = (0, path_1.dirname)(outputPath);
14
+ if (!commonOutputDirectory) {
15
+ commonOutputDirectory = directoryOfOutputPath;
16
+ }
17
+ else if (commonOutputDirectory !== directoryOfOutputPath ||
18
+ !outputPath.endsWith(app)) {
19
+ shouldMoveToCommonLocation = true;
20
+ }
21
+ }
22
+ if (shouldMoveToCommonLocation) {
23
+ commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-remotes');
24
+ for (const app of remotes.staticRemotes) {
25
+ const outputPath = context.projectGraph.nodes[app].data.targets['build'].options
26
+ .outputPath;
27
+ (0, fs_1.cpSync)(outputPath, (0, path_1.join)(commonOutputDirectory, app), {
28
+ force: true,
29
+ recursive: true,
30
+ });
31
+ }
32
+ }
33
+ const staticRemotesIter = (0, file_server_impl_1.default)({
34
+ cors: true,
35
+ watch: false,
36
+ staticFilePath: commonOutputDirectory,
37
+ parallel: false,
38
+ spa: false,
39
+ withDeps: false,
40
+ host: options.host,
41
+ port: options.staticRemotesPort,
42
+ ssl: options.ssl,
43
+ sslCert: options.sslCert,
44
+ sslKey: options.sslKey,
45
+ }, context);
46
+ return staticRemotesIter;
47
+ }
48
+ exports.startStaticRemotesFileServer = startStaticRemotesFileServer;
@@ -0,0 +1,3 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
2
+ import { type Schema } from './schema';
3
+ export default function moduleFederationDevServerExecutor(schema: Schema, context: ExecutorContext): AsyncGenerator<any, any, undefined>;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const lib_1 = require("./lib");
5
+ const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
6
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
+ const module_federation_1 = require("@nx/webpack/src/utils/module-federation");
8
+ const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
9
+ const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
10
+ const ngcli_adapter_1 = require("nx/src/adapter/ngcli-adapter");
11
+ const dev_server_impl_1 = require("../../builders/dev-server/dev-server.impl");
12
+ const module_federation_2 = require("../../builders/utilities/module-federation");
13
+ const path_1 = require("path");
14
+ const fs_1 = require("fs");
15
+ async function* moduleFederationDevServerExecutor(schema, context) {
16
+ // Force Node to resolve to look for the nx binary that is inside node_modules
17
+ const nxBin = require.resolve('nx/bin/nx');
18
+ const options = (0, lib_1.normalizeOptions)(schema);
19
+ options.staticRemotesPort ??= options.port + 1;
20
+ const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(context.projectGraph);
21
+ const project = workspaceProjects[context.projectName];
22
+ const currIter = options.static
23
+ ? (0, file_server_impl_1.default)({
24
+ port: options.port,
25
+ host: options.host,
26
+ ssl: options.ssl,
27
+ buildTarget: options.buildTarget,
28
+ parallel: false,
29
+ spa: false,
30
+ withDeps: false,
31
+ cors: true,
32
+ }, context)
33
+ : (0, rxjs_for_await_1.eachValueFrom)((0, dev_server_impl_1.executeDevServerBuilder)(options, await (0, ngcli_adapter_1.createBuilderContext)({
34
+ builderName: '@nx/angular:webpack-browser',
35
+ description: 'Build a browser application',
36
+ optionSchema: await Promise.resolve().then(() => require('../../builders/webpack-browser/schema.json')),
37
+ }, context)));
38
+ if (options.isInitialHost === false) {
39
+ return yield* currIter;
40
+ }
41
+ let pathToManifestFile = (0, path_1.join)(context.root, project.sourceRoot, 'assets/module-federation.manifest.json');
42
+ if (options.pathToManifestFile) {
43
+ const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
44
+ if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
45
+ throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
46
+ }
47
+ else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
48
+ throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
49
+ }
50
+ pathToManifestFile = userPathToManifestFile;
51
+ }
52
+ (0, module_federation_2.validateDevRemotes)(options, workspaceProjects);
53
+ const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(project.targets.build.options.tsConfig, context.root, project.root, 'angular');
54
+ const remotes = (0, module_federation_1.getRemotes)(options.devRemotes, options.skipRemotes, moduleFederationConfig, {
55
+ projectName: project.name,
56
+ projectGraph: context.projectGraph,
57
+ root: context.root,
58
+ }, pathToManifestFile);
59
+ if (remotes.devRemotes.length > 0 && !schema.staticRemotesPort) {
60
+ options.staticRemotesPort = options.devRemotes.reduce((portToUse, r) => {
61
+ const remotePort = context.projectGraph.nodes[r].data.targets['serve'].options.port;
62
+ if (remotePort >= portToUse) {
63
+ return remotePort + 1;
64
+ }
65
+ else {
66
+ return portToUse;
67
+ }
68
+ }, options.staticRemotesPort);
69
+ }
70
+ await (0, lib_1.buildStaticRemotes)(remotes, nxBin, context, options);
71
+ const devRemoteIters = await (0, lib_1.startDevRemotes)(remotes, workspaceProjects, options, context);
72
+ const staticRemotesIter = remotes.staticRemotes.length > 0
73
+ ? (0, lib_1.startStaticRemotesFileServer)(remotes, context, options)
74
+ : undefined;
75
+ const removeBaseUrlEmission = (iter) => (0, async_iterable_1.mapAsyncIterable)(iter, (v) => ({
76
+ ...v,
77
+ baseUrl: undefined,
78
+ }));
79
+ return yield* (0, async_iterable_1.combineAsyncIterables)(removeBaseUrlEmission(currIter), ...devRemoteIters.map(removeBaseUrlEmission), ...(staticRemotesIter ? [removeBaseUrlEmission(staticRemotesIter)] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
80
+ if (!options.isInitialHost) {
81
+ done();
82
+ return;
83
+ }
84
+ if (remotes.remotePorts.length === 0) {
85
+ devkit_1.logger.info(`NX All remotes started, server ready at http://localhost:${options.port}`);
86
+ next({ success: true, baseUrl: `http://localhost:${options.port}` });
87
+ done();
88
+ return;
89
+ }
90
+ try {
91
+ const portsToWaitFor = staticRemotesIter
92
+ ? [options.staticRemotesPort, ...remotes.remotePorts]
93
+ : [...remotes.remotePorts];
94
+ await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
95
+ retries: 480,
96
+ retryDelay: 2500,
97
+ host: 'localhost',
98
+ })));
99
+ devkit_1.logger.info(`NX All remotes started, server ready at http://localhost:${options.port}`);
100
+ next({ success: true, baseUrl: `http://localhost:${options.port}` });
101
+ }
102
+ catch {
103
+ throw new Error(`Timed out waiting for remote to start. Check above for any errors.`);
104
+ }
105
+ finally {
106
+ done();
107
+ }
108
+ }));
109
+ }
110
+ exports.default = moduleFederationDevServerExecutor;
@@ -1,8 +1,7 @@
1
1
  {
2
- "version": 2,
3
- "outputCapture": "direct-nodejs",
4
2
  "$schema": "http://json-schema.org/draft-07/schema",
5
3
  "title": "Schema for Module Federation Dev Server",
4
+ "outputCapture": "direct-nodejs",
6
5
  "description": "The module-federation-dev-server executor is reserved exclusively for use with host Module Federation applications. It allows the user to specify which remote applications should be served with the host.",
7
6
  "type": "object",
8
7
  "presets": [
@@ -149,6 +148,13 @@
149
148
  }
150
149
  },
151
150
  "additionalProperties": false,
152
- "anyOf": [{ "required": ["buildTarget"] }, { "required": ["browserTarget"] }],
151
+ "anyOf": [
152
+ {
153
+ "required": ["buildTarget"]
154
+ },
155
+ {
156
+ "required": ["browserTarget"]
157
+ }
158
+ ],
153
159
  "examplesFile": "../../../docs/module-federation-dev-server-examples.md"
154
160
  }
@@ -0,0 +1,6 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
2
+ import { type DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
3
+ export declare function createTmpTsConfigForBuildableLibs(tsConfigPath: string, context: ExecutorContext): {
4
+ tsConfigPath: string;
5
+ dependencies: DependentBuildableProjectNode[];
6
+ };
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTmpTsConfigForBuildableLibs = void 0;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
5
6
  const path_1 = require("path");
6
- const devkit_1 = require("@nx/devkit");
7
- function createTmpTsConfigForBuildableLibs(tsConfigPath, context, options) {
7
+ function createTmpTsConfigForBuildableLibs(tsConfigPath, context) {
8
8
  let dependencies;
9
- const result = (0, buildable_libs_utils_1.calculateProjectDependencies)(options?.projectGraph ?? (0, devkit_1.readCachedProjectGraph)(), context.root, context.projectName, options?.target ?? context.targetName, context.configurationName);
9
+ const result = (0, buildable_libs_utils_1.calculateProjectDependencies)(context.projectGraph ?? (0, devkit_1.readCachedProjectGraph)(), context.root, context.projectName, context.targetName, context.configurationName);
10
10
  dependencies = result.dependencies;
11
11
  const tmpTsConfigPath = (0, buildable_libs_utils_1.createTmpTsConfig)((0, path_1.join)(context.root, tsConfigPath), context.root, result.target.data.root, dependencies);
12
12
  process.env.NX_TSCONFIG_PATH = tmpTsConfigPath;
13
- // Angular EsBuild Builder appends the workspaceRoot to the config path, so remove it.
14
13
  const tmpTsConfigPathWithoutWorkspaceRoot = tmpTsConfigPath.replace(context.root, '');
15
14
  return { tsConfigPath: tmpTsConfigPathWithoutWorkspaceRoot, dependencies };
16
15
  }
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'esbuild';
2
+ export type PluginSpec = {
3
+ path: string;
4
+ options: any;
5
+ };
6
+ export declare function loadPlugins(plugins: string[] | PluginSpec[] | undefined, tsConfig: string): Promise<Plugin[]>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadPlugins = void 0;
4
+ const internal_1 = require("@nx/js/src/internal");
5
+ const module_loader_1 = require("./module-loader");
6
+ async function loadPlugins(plugins, tsConfig) {
7
+ if (!plugins?.length) {
8
+ return [];
9
+ }
10
+ const cleanupTranspiler = (0, internal_1.registerTsProject)(tsConfig);
11
+ try {
12
+ return await Promise.all(plugins.map((plugin) => loadPlugin(plugin)));
13
+ }
14
+ finally {
15
+ cleanupTranspiler();
16
+ }
17
+ }
18
+ exports.loadPlugins = loadPlugins;
19
+ async function loadPlugin(pluginSpec) {
20
+ const pluginPath = typeof pluginSpec === 'string' ? pluginSpec : pluginSpec.path;
21
+ let plugin = await (0, module_loader_1.loadModule)(pluginPath);
22
+ if (typeof plugin === 'function') {
23
+ plugin =
24
+ typeof pluginSpec === 'object' ? plugin(pluginSpec.options) : plugin();
25
+ }
26
+ return plugin;
27
+ }
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ export declare function loadModule<T = any>(path: string): Promise<T>;
3
+ /**
4
+ * This uses a dynamic import to load a module which may be ESM.
5
+ * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
6
+ * will currently, unconditionally downlevel dynamic import into a require call.
7
+ * require calls cannot load ESM code and will result in a runtime error. To workaround
8
+ * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
9
+ * Once TypeScript provides support for keeping the dynamic import this workaround can
10
+ * be dropped.
11
+ *
12
+ * @param modulePath The path of the module to load.
13
+ * @returns A Promise that resolves to the dynamically imported module.
14
+ */
15
+ export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadEsmModule = exports.loadModule = void 0;
4
+ const path_1 = require("path");
5
+ const node_url_1 = require("node:url");
6
+ async function loadModule(path) {
7
+ switch ((0, path_1.extname)(path)) {
8
+ case '.mjs': {
9
+ const result = await loadEsmModule((0, node_url_1.pathToFileURL)(path));
10
+ return result.default ?? result;
11
+ }
12
+ case '.cjs': {
13
+ const result = require(path);
14
+ return result.default ?? result;
15
+ }
16
+ default:
17
+ // it can be CommonJS or ESM, try both
18
+ try {
19
+ const result = require(path);
20
+ return result.default ?? result;
21
+ }
22
+ catch (e) {
23
+ if (e.code === 'ERR_REQUIRE_ESM') {
24
+ const result = await loadEsmModule((0, node_url_1.pathToFileURL)(path));
25
+ return result.default ?? result;
26
+ }
27
+ throw e;
28
+ }
29
+ }
30
+ }
31
+ exports.loadModule = loadModule;
32
+ /**
33
+ * Lazily compiled dynamic import loader function.
34
+ */
35
+ let load;
36
+ /**
37
+ * This uses a dynamic import to load a module which may be ESM.
38
+ * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
39
+ * will currently, unconditionally downlevel dynamic import into a require call.
40
+ * require calls cannot load ESM code and will result in a runtime error. To workaround
41
+ * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
42
+ * Once TypeScript provides support for keeping the dynamic import this workaround can
43
+ * be dropped.
44
+ *
45
+ * @param modulePath The path of the module to load.
46
+ * @returns A Promise that resolves to the dynamically imported module.
47
+ */
48
+ function loadEsmModule(modulePath) {
49
+ load ??= new Function('modulePath', `return import(modulePath);`);
50
+ return load(modulePath);
51
+ }
52
+ exports.loadEsmModule = loadEsmModule;
@@ -1,15 +1 @@
1
- /// <reference types="node" />
2
1
  export declare function ngCompilerCli(): Promise<typeof import('@angular/compiler-cli')>;
3
- /**
4
- * This uses a dynamic import to load a module which may be ESM.
5
- * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
6
- * will currently, unconditionally downlevel dynamic import into a require call.
7
- * require calls cannot load ESM code and will result in a runtime error. To workaround
8
- * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
9
- * Once TypeScript provides support for keeping the dynamic import this workaround can
10
- * be dropped.
11
- *
12
- * @param modulePath The path of the module to load.
13
- * @returns A Promise that resolves to the dynamically imported module.
14
- */
15
- export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;
@@ -1,28 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadEsmModule = exports.ngCompilerCli = void 0;
3
+ exports.ngCompilerCli = void 0;
4
+ const module_loader_1 = require("./module-loader");
4
5
  function ngCompilerCli() {
5
- return loadEsmModule('@angular/compiler-cli');
6
+ return (0, module_loader_1.loadEsmModule)('@angular/compiler-cli');
6
7
  }
7
8
  exports.ngCompilerCli = ngCompilerCli;
8
- /**
9
- * Lazily compiled dynamic import loader function.
10
- */
11
- let load;
12
- /**
13
- * This uses a dynamic import to load a module which may be ESM.
14
- * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
15
- * will currently, unconditionally downlevel dynamic import into a require call.
16
- * require calls cannot load ESM code and will result in a runtime error. To workaround
17
- * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
18
- * Once TypeScript provides support for keeping the dynamic import this workaround can
19
- * be dropped.
20
- *
21
- * @param modulePath The path of the module to load.
22
- * @returns A Promise that resolves to the dynamically imported module.
23
- */
24
- function loadEsmModule(modulePath) {
25
- load ??= new Function('modulePath', `return import(modulePath);`);
26
- return load(modulePath);
27
- }
28
- exports.loadEsmModule = loadEsmModule;
@@ -1,5 +0,0 @@
1
- import type { Schema } from './schema';
2
- import { executeDevServerBuilder } from '../dev-server/dev-server.impl';
3
- export declare function executeModuleFederationDevServerBuilder(schema: Schema, context: import('@angular-devkit/architect').BuilderContext): ReturnType<typeof executeDevServerBuilder | any>;
4
- declare const _default: any;
5
- export default _default;