@nx/angular 21.1.1 → 21.1.3
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/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<p style="text-align: center;">
|
2
2
|
<picture>
|
3
3
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
4
|
-
<img alt="Nx - Smart
|
4
|
+
<img alt="Nx - Smart Repos · Fast Builds" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
5
5
|
</picture>
|
6
6
|
</p>
|
7
7
|
|
@@ -20,9 +20,9 @@
|
|
20
20
|
|
21
21
|
<hr>
|
22
22
|
|
23
|
-
# Nx: Smart
|
23
|
+
# Nx: Smart Repos · Fast Builds
|
24
24
|
|
25
|
-
|
25
|
+
An AI-first build platform that connects everything from your editor to CI. Helping you deliver fast, without breaking things.
|
26
26
|
|
27
27
|
This package is an [Angular plugin for Nx](https://nx.dev/nx-api/angular).
|
28
28
|
|
@@ -64,5 +64,5 @@ npx nx@latest init
|
|
64
64
|
- [Blog Posts About Nx](https://nx.dev/blog)
|
65
65
|
|
66
66
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
67
|
-
width="100%" alt="Nx - Smart
|
67
|
+
width="100%" alt="Nx - Smart Repos · Fast Builds"></a></p>
|
68
68
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { extname } from 'node:path';
|
2
|
+
|
1
3
|
let resolveRemoteUrl;
|
2
4
|
/**
|
3
5
|
* @deprecated Use Runtime Helpers from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.
|
@@ -104,10 +106,15 @@ async function loadRemoteContainer(remoteName) {
|
|
104
106
|
const remoteUrl = remoteUrlDefinitions
|
105
107
|
? remoteUrlDefinitions[remoteName]
|
106
108
|
: await resolveRemoteUrl(remoteName);
|
107
|
-
|
108
|
-
|
109
|
-
|
109
|
+
const url = new URL(remoteUrl);
|
110
|
+
const ext = extname(url.pathname);
|
111
|
+
const needsRemoteEntry = !['.js', '.mjs', '.json'].includes(ext);
|
112
|
+
if (needsRemoteEntry) {
|
113
|
+
url.pathname = url.pathname.endsWith('/')
|
114
|
+
? `${url.pathname}remoteEntry.mjs`
|
115
|
+
: `${url.pathname}/remoteEntry.mjs`;
|
110
116
|
}
|
117
|
+
const containerUrl = url.href;
|
111
118
|
const container = await loadModule(containerUrl);
|
112
119
|
await container.init(__webpack_share_scopes__.default);
|
113
120
|
remoteContainerMap.set(remoteName, container);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"nx-angular-mf.mjs","sources":["../../../../packages/angular/mf/mf.ts","../../../../packages/angular/mf/nx-angular-mf.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"file":"nx-angular-mf.mjs","sources":["../../../../packages/angular/mf/mf.ts","../../../../packages/angular/mf/nx-angular-mf.ts"],"sourcesContent":["import { extname } from 'node:path';\n\nexport type ResolveRemoteUrlFunction = (\n remoteName: string\n) => string | Promise<string>;\n\ndeclare const __webpack_init_sharing__: (scope: 'default') => Promise<void>;\ndeclare const __webpack_share_scopes__: { default: unknown };\n\nlet resolveRemoteUrl: ResolveRemoteUrlFunction;\n\n/**\n * @deprecated Use Runtime Helpers from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n */\nexport function setRemoteUrlResolver(\n _resolveRemoteUrl: ResolveRemoteUrlFunction\n) {\n resolveRemoteUrl = _resolveRemoteUrl;\n}\n\nlet remoteUrlDefinitions: Record<string, string>;\n\n/**\n * @deprecated Use init() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n * If you have a remote app called `my-remote-app` and you want to use the `http://localhost:4201/mf-manifest.json` as the remote url, you should change it from:\n * ```ts\n * import { setRemoteDefinitions } from '@nx/angular/mf';\n *\n * setRemoteDefinitions({\n * 'my-remote-app': 'http://localhost:4201/mf-manifest.json'\n * });\n * ```\n * to use init():\n * ```ts\n * import { init } from '@module-federation/enhanced/runtime';\n *\n * init({\n * name: 'host',\n * remotes: [{\n * name: 'my-remote-app',\n * entry: 'http://localhost:4201/mf-manifest.json'\n * }]\n * });\n * ```\n */\nexport function setRemoteDefinitions(definitions: Record<string, string>) {\n remoteUrlDefinitions = definitions;\n}\n\n/**\n * @deprecated Use registerRemotes() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n * If you set a remote app with `setRemoteDefinition` such as:\n * ```ts\n * import { setRemoteDefinition } from '@nx/angular/mf';\n *\n * setRemoteDefinition(\n * 'my-remote-app',\n * 'http://localhost:4201/mf-manifest.json'\n * );\n * ```\n * change it to use registerRemotes():\n * ```ts\n * import { registerRemotes } from '@module-federation/enhanced/runtime';\n *\n * registerRemotes([\n * {\n * name: 'my-remote-app',\n * entry: 'http://localhost:4201/mf-manifest.json'\n * }\n * ]);\n * ```\n */\nexport function setRemoteDefinition(remoteName: string, remoteUrl: string) {\n remoteUrlDefinitions ??= {};\n remoteUrlDefinitions[remoteName] = remoteUrl;\n}\n\nlet remoteModuleMap = new Map<string, unknown>();\nlet remoteContainerMap = new Map<string, unknown>();\n\n/**\n * @deprecated Use loadRemote() from '@module-federation/enhanced/runtime' instead. This will be removed in Nx 22.\n * If you set a load a remote with `loadRemoteModule` such as:\n * ```ts\n * import { loadRemoteModule } from '@nx/angular/mf';\n *\n * loadRemoteModule('my-remote-app', './Module').then(m => m.RemoteEntryModule);\n * ```\n * change it to use loadRemote():\n * ```ts\n * import { loadRemote } from '@module-federation/enhanced/runtime';\n *\n * loadRemote<typeof import('my-remote-app/Module')>('my-remote-app/Module').then(m => m.RemoteEntryModule);\n * ```\n */\nexport async function loadRemoteModule(remoteName: string, moduleName: string) {\n const remoteModuleKey = `${remoteName}:${moduleName}`;\n if (remoteModuleMap.has(remoteModuleKey)) {\n return remoteModuleMap.get(remoteModuleKey);\n }\n\n const container = remoteContainerMap.has(remoteName)\n ? remoteContainerMap.get(remoteName)\n : await loadRemoteContainer(remoteName);\n\n const factory = await container.get(moduleName);\n const Module = factory();\n\n remoteModuleMap.set(remoteModuleKey, Module);\n\n return Module;\n}\n\nfunction loadModule(url: string) {\n return import(/* webpackIgnore:true */ url);\n}\n\nlet initialSharingScopeCreated = false;\n\nasync function loadRemoteContainer(remoteName: string) {\n if (!resolveRemoteUrl && !remoteUrlDefinitions) {\n throw new Error(\n 'Call setRemoteDefinitions or setRemoteUrlResolver to allow Dynamic Federation to find the remote apps correctly.'\n );\n }\n\n if (!initialSharingScopeCreated) {\n initialSharingScopeCreated = true;\n await __webpack_init_sharing__('default');\n }\n\n const remoteUrl = remoteUrlDefinitions\n ? remoteUrlDefinitions[remoteName]\n : await resolveRemoteUrl(remoteName);\n\n const url = new URL(remoteUrl);\n const ext = extname(url.pathname);\n\n const needsRemoteEntry = !['.js', '.mjs', '.json'].includes(ext);\n\n if (needsRemoteEntry) {\n url.pathname = url.pathname.endsWith('/')\n ? `${url.pathname}remoteEntry.mjs`\n : `${url.pathname}/remoteEntry.mjs`;\n }\n\n const containerUrl = url.href;\n\n const container = await loadModule(containerUrl);\n await container.init(__webpack_share_scopes__.default);\n\n remoteContainerMap.set(remoteName, container);\n return container;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AASA,IAAI,gBAA0C;AAE9C;;AAEG;AACG,SAAU,oBAAoB,CAClC,iBAA2C,EAAA;IAE3C,gBAAgB,GAAG,iBAAiB;AACtC;AAEA,IAAI,oBAA4C;AAEhD;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,oBAAoB,CAAC,WAAmC,EAAA;IACtE,oBAAoB,GAAG,WAAW;AACpC;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACa,SAAA,mBAAmB,CAAC,UAAkB,EAAE,SAAiB,EAAA;IACvE,oBAAoB,KAAK,EAAE;AAC3B,IAAA,oBAAoB,CAAC,UAAU,CAAC,GAAG,SAAS;AAC9C;AAEA,IAAI,eAAe,GAAG,IAAI,GAAG,EAAmB;AAChD,IAAI,kBAAkB,GAAG,IAAI,GAAG,EAAmB;AAEnD;;;;;;;;;;;;;;AAcG;AACI,eAAe,gBAAgB,CAAC,UAAkB,EAAE,UAAkB,EAAA;AAC3E,IAAA,MAAM,eAAe,GAAG,CAAA,EAAG,UAAU,CAAI,CAAA,EAAA,UAAU,EAAE;AACrD,IAAA,IAAI,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE;AACxC,QAAA,OAAO,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC;;AAG7C,IAAA,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,UAAU;AACjD,UAAE,kBAAkB,CAAC,GAAG,CAAC,UAAU;AACnC,UAAE,MAAM,mBAAmB,CAAC,UAAU,CAAC;IAEzC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC;AAC/C,IAAA,MAAM,MAAM,GAAG,OAAO,EAAE;AAExB,IAAA,eAAe,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC;AAE5C,IAAA,OAAO,MAAM;AACf;AAEA,SAAS,UAAU,CAAC,GAAW,EAAA;AAC7B,IAAA,OAAO,gCAAgC,GAAG,CAAC;AAC7C;AAEA,IAAI,0BAA0B,GAAG,KAAK;AAEtC,eAAe,mBAAmB,CAAC,UAAkB,EAAA;AACnD,IAAA,IAAI,CAAC,gBAAgB,IAAI,CAAC,oBAAoB,EAAE;AAC9C,QAAA,MAAM,IAAI,KAAK,CACb,kHAAkH,CACnH;;IAGH,IAAI,CAAC,0BAA0B,EAAE;QAC/B,0BAA0B,GAAG,IAAI;AACjC,QAAA,MAAM,wBAAwB,CAAC,SAAS,CAAC;;IAG3C,MAAM,SAAS,GAAG;AAChB,UAAE,oBAAoB,CAAC,UAAU;AACjC,UAAE,MAAM,gBAAgB,CAAC,UAAU,CAAC;AAEtC,IAAA,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAEjC,IAAA,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;IAEhE,IAAI,gBAAgB,EAAE;QACpB,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG;AACtC,cAAE,CAAA,EAAG,GAAG,CAAC,QAAQ,CAAiB,eAAA;AAClC,cAAE,CAAG,EAAA,GAAG,CAAC,QAAQ,kBAAkB;;AAGvC,IAAA,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI;AAE7B,IAAA,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC;IAChD,MAAM,SAAS,CAAC,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC;AAEtD,IAAA,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC;AAC7C,IAAA,OAAO,SAAS;AAClB;;ACzJA;;AAEG;;;;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/angular",
|
3
|
-
"version": "21.1.
|
3
|
+
"version": "21.1.3",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
6
6
|
"repository": {
|
@@ -67,14 +67,14 @@
|
|
67
67
|
"semver": "^7.5.3",
|
68
68
|
"tslib": "^2.3.0",
|
69
69
|
"webpack-merge": "^5.8.0",
|
70
|
-
"@nx/devkit": "21.1.
|
71
|
-
"@nx/js": "21.1.
|
72
|
-
"@nx/eslint": "21.1.
|
73
|
-
"@nx/webpack": "21.1.
|
74
|
-
"@nx/rspack": "21.1.
|
75
|
-
"@nx/module-federation": "21.1.
|
76
|
-
"@nx/web": "21.1.
|
77
|
-
"@nx/workspace": "21.1.
|
70
|
+
"@nx/devkit": "21.1.3",
|
71
|
+
"@nx/js": "21.1.3",
|
72
|
+
"@nx/eslint": "21.1.3",
|
73
|
+
"@nx/webpack": "21.1.3",
|
74
|
+
"@nx/rspack": "21.1.3",
|
75
|
+
"@nx/module-federation": "21.1.3",
|
76
|
+
"@nx/web": "21.1.3",
|
77
|
+
"@nx/workspace": "21.1.3",
|
78
78
|
"piscina": "^4.4.0"
|
79
79
|
},
|
80
80
|
"peerDependencies": {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { type
|
1
|
+
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
2
2
|
import type { ConvertToRspackSchema } from './schema';
|
3
3
|
export declare function convertToRspack(tree: Tree, schema: ConvertToRspackSchema): Promise<GeneratorCallback>;
|
4
4
|
export default convertToRspack;
|
@@ -2,15 +2,16 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.convertToRspack = convertToRspack;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
6
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
7
|
+
const enquirer_1 = require("enquirer");
|
8
|
+
const path_1 = require("path");
|
9
|
+
const posix_1 = require("path/posix");
|
5
10
|
const versions_1 = require("../../utils/versions");
|
6
11
|
const create_config_1 = require("./lib/create-config");
|
7
12
|
const get_custom_webpack_config_1 = require("./lib/get-custom-webpack-config");
|
8
13
|
const update_tsconfig_1 = require("./lib/update-tsconfig");
|
9
14
|
const validate_supported_executor_1 = require("./lib/validate-supported-executor");
|
10
|
-
const posix_1 = require("path/posix");
|
11
|
-
const path_1 = require("path");
|
12
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
13
|
-
const enquirer_1 = require("enquirer");
|
14
15
|
const SUPPORTED_EXECUTORS = [
|
15
16
|
'@angular-devkit/build-angular:browser',
|
16
17
|
'@angular-devkit/build-angular:dev-server',
|
@@ -169,10 +170,6 @@ function handleBuildTargetOptions(tree, options, newConfigurationOptions, root)
|
|
169
170
|
customWebpackConfigPath = options.customWebpackConfig.path;
|
170
171
|
delete options.customWebpackConfig;
|
171
172
|
}
|
172
|
-
if (options.outputs) {
|
173
|
-
// handled by the Rspack inference plugin
|
174
|
-
delete options.outputs;
|
175
|
-
}
|
176
173
|
for (const [key, value] of Object.entries(options)) {
|
177
174
|
let optionName = key;
|
178
175
|
let optionValue = key in PATH_NORMALIZER ? PATH_NORMALIZER[key](tree, value, root) : value;
|
@@ -252,8 +249,9 @@ async function convertToRspack(tree, schema) {
|
|
252
249
|
root: project.root,
|
253
250
|
};
|
254
251
|
const configurationOptions = {};
|
255
|
-
|
256
|
-
|
252
|
+
let buildTarget;
|
253
|
+
let serveTarget;
|
254
|
+
const targetsToRemove = [];
|
257
255
|
let customWebpackConfigPath;
|
258
256
|
(0, validate_supported_executor_1.validateSupportedBuildExecutor)(Object.values(project.targets));
|
259
257
|
let projectServePort = DEFAULT_PORT;
|
@@ -267,14 +265,15 @@ async function convertToRspack(tree, schema) {
|
|
267
265
|
handleBuildTargetOptions(tree, configuration, configurationOptions[configurationName], project.root);
|
268
266
|
}
|
269
267
|
}
|
270
|
-
|
268
|
+
buildTarget = { name: targetName, config: target };
|
269
|
+
targetsToRemove.push(targetName);
|
271
270
|
}
|
272
271
|
else if (target.executor === '@angular-devkit/build-angular:server' ||
|
273
272
|
target.executor === '@nx/angular:webpack-server') {
|
274
273
|
createConfigOptions.ssr ??= {};
|
275
274
|
createConfigOptions.ssr.entry ??= normalizeFromProjectRoot(tree, target.options.main, project.root);
|
276
275
|
createConfigOptions.server = './src/main.server.ts';
|
277
|
-
|
276
|
+
targetsToRemove.push(targetName);
|
278
277
|
}
|
279
278
|
else if (target.executor === '@angular-devkit/build-angular:dev-server' ||
|
280
279
|
target.executor === '@nx/angular:dev-server' ||
|
@@ -282,7 +281,7 @@ async function convertToRspack(tree, schema) {
|
|
282
281
|
createConfigOptions.devServer = {};
|
283
282
|
if (target.options) {
|
284
283
|
handleDevServerTargetOptions(tree, target.options, createConfigOptions.devServer, project.root);
|
285
|
-
if (target.options.port !== DEFAULT_PORT) {
|
284
|
+
if (target.options.port && target.options.port !== DEFAULT_PORT) {
|
286
285
|
projectServePort = target.options.port;
|
287
286
|
}
|
288
287
|
}
|
@@ -293,7 +292,8 @@ async function convertToRspack(tree, schema) {
|
|
293
292
|
handleDevServerTargetOptions(tree, configuration, configurationOptions[configurationName].devServer, project.root);
|
294
293
|
}
|
295
294
|
}
|
296
|
-
|
295
|
+
serveTarget = { name: targetName, config: target };
|
296
|
+
targetsToRemove.push(targetName);
|
297
297
|
}
|
298
298
|
else if (target.executor === '@angular-devkit/build-angular:prerender') {
|
299
299
|
if (target.options) {
|
@@ -314,11 +314,11 @@ async function convertToRspack(tree, schema) {
|
|
314
314
|
}
|
315
315
|
}
|
316
316
|
}
|
317
|
-
|
317
|
+
targetsToRemove.push(targetName);
|
318
318
|
}
|
319
319
|
else if (target.executor === '@angular-devkit/build-angular:app-shell') {
|
320
320
|
createConfigOptions.appShell = true;
|
321
|
-
|
321
|
+
targetsToRemove.push(targetName);
|
322
322
|
}
|
323
323
|
}
|
324
324
|
const customWebpackConfigInfo = customWebpackConfigPath
|
@@ -326,20 +326,169 @@ async function convertToRspack(tree, schema) {
|
|
326
326
|
: undefined;
|
327
327
|
(0, create_config_1.createConfig)(tree, createConfigOptions, configurationOptions, customWebpackConfigInfo?.normalizedPathToCustomWebpackConfig, customWebpackConfigInfo?.isWebpackConfigFunction);
|
328
328
|
(0, update_tsconfig_1.updateTsconfig)(tree, project.root);
|
329
|
-
for (const targetName of
|
329
|
+
for (const targetName of targetsToRemove) {
|
330
330
|
delete project.targets[targetName];
|
331
331
|
}
|
332
|
-
if (projectServePort !== DEFAULT_PORT) {
|
333
|
-
project.targets.serve ??= {};
|
334
|
-
project.targets.serve.options ??= {};
|
335
|
-
project.targets.serve.options.port = projectServePort;
|
336
|
-
}
|
337
332
|
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
333
|
+
// ensure plugin is registered
|
338
334
|
const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
339
335
|
await rspackInitGenerator(tree, {
|
340
336
|
addPlugin: true,
|
341
337
|
framework: 'angular',
|
342
338
|
});
|
339
|
+
// find the inferred target names
|
340
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
341
|
+
let inferredBuildTargetName = 'build';
|
342
|
+
let inferredServeTargetName = 'serve';
|
343
|
+
const pluginRegistration = nxJson.plugins.find((p) => typeof p === 'string' ? false : p.plugin === '@nx/rspack/plugin');
|
344
|
+
if (pluginRegistration) {
|
345
|
+
inferredBuildTargetName =
|
346
|
+
pluginRegistration.options.buildTargetName ?? inferredBuildTargetName;
|
347
|
+
inferredServeTargetName =
|
348
|
+
pluginRegistration.options.serveTargetName ?? inferredServeTargetName;
|
349
|
+
}
|
350
|
+
if (buildTarget) {
|
351
|
+
// these are all replaced by the inferred task
|
352
|
+
delete buildTarget.config.options;
|
353
|
+
delete buildTarget.config.configurations;
|
354
|
+
delete buildTarget.config.defaultConfiguration;
|
355
|
+
delete buildTarget.config.executor;
|
356
|
+
const shouldOverrideInputs = (inputs) => {
|
357
|
+
if (!inputs?.length) {
|
358
|
+
return false;
|
359
|
+
}
|
360
|
+
if (inputs.length === 2) {
|
361
|
+
// check whether the existing inputs would match the inferred task
|
362
|
+
// inputs with the exception of the @rspack/cli external dependency
|
363
|
+
// which webpack tasks wouldn't have
|
364
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(project.root, {
|
365
|
+
nxJsonConfiguration: nxJson,
|
366
|
+
configFiles: [],
|
367
|
+
workspaceRoot: devkit_1.workspaceRoot,
|
368
|
+
});
|
369
|
+
if ('production' in namedInputs) {
|
370
|
+
return !['production', '^production'].every((input) => inputs.includes(input));
|
371
|
+
}
|
372
|
+
return !['default', '^default'].every((input) => inputs.includes(input));
|
373
|
+
}
|
374
|
+
return true;
|
375
|
+
};
|
376
|
+
if (shouldOverrideInputs(buildTarget.config.inputs)) {
|
377
|
+
// keep existing inputs and add the @rspack/cli external dependency
|
378
|
+
buildTarget.config.inputs = [
|
379
|
+
...buildTarget.config.inputs,
|
380
|
+
{ externalDependencies: ['@rspack/cli'] },
|
381
|
+
];
|
382
|
+
}
|
383
|
+
else {
|
384
|
+
delete buildTarget.config.inputs;
|
385
|
+
}
|
386
|
+
if (buildTarget.config.cache) {
|
387
|
+
delete buildTarget.config.cache;
|
388
|
+
}
|
389
|
+
if (buildTarget.config.dependsOn?.length === 1 &&
|
390
|
+
buildTarget.config.dependsOn[0] === `^${buildTarget.name}`) {
|
391
|
+
delete buildTarget.config.dependsOn;
|
392
|
+
}
|
393
|
+
else if (buildTarget.config.dependsOn) {
|
394
|
+
buildTarget.config.dependsOn = buildTarget.config.dependsOn.map((dep) => dep === `^${buildTarget.name}` ? `^${inferredBuildTargetName}` : dep);
|
395
|
+
}
|
396
|
+
const newOutputPath = (0, devkit_1.joinPathFragments)(project.root, createConfigOptions.outputPath.base);
|
397
|
+
const shouldOverrideOutputs = (outputs) => {
|
398
|
+
if (!outputs?.length) {
|
399
|
+
// this means the target was wrongly configured, so, we don't override
|
400
|
+
// anything and let the inferred outputs be used
|
401
|
+
return false;
|
402
|
+
}
|
403
|
+
if (outputs.length === 1) {
|
404
|
+
if (outputs[0] === '{options.outputPath}') {
|
405
|
+
// the inferred task output is created after the createConfig
|
406
|
+
// outputPath option, so we don't need to keep this
|
407
|
+
return false;
|
408
|
+
}
|
409
|
+
const normalizedOutputPath = outputs[0]
|
410
|
+
.replace('{workspaceRoot}/', '')
|
411
|
+
.replace('{projectRoot}', project.root)
|
412
|
+
.replace('{projectName}', '');
|
413
|
+
if (normalizedOutputPath === newOutputPath ||
|
414
|
+
normalizedOutputPath.replace(/\/browser\/?$/, '') === newOutputPath) {
|
415
|
+
return false;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
return true;
|
419
|
+
};
|
420
|
+
const normalizeOutput = (path, workspaceRoot, projectRoot) => {
|
421
|
+
const fullProjectRoot = (0, path_1.resolve)(workspaceRoot, projectRoot);
|
422
|
+
const fullPath = (0, path_1.resolve)(workspaceRoot, path);
|
423
|
+
const pathRelativeToProjectRoot = (0, devkit_1.normalizePath)((0, path_1.relative)(fullProjectRoot, fullPath));
|
424
|
+
if (pathRelativeToProjectRoot.startsWith('..')) {
|
425
|
+
return (0, devkit_1.joinPathFragments)('{workspaceRoot}', (0, path_1.relative)(workspaceRoot, fullPath));
|
426
|
+
}
|
427
|
+
return (0, devkit_1.joinPathFragments)('{projectRoot}', pathRelativeToProjectRoot);
|
428
|
+
};
|
429
|
+
if (shouldOverrideOutputs(buildTarget.config.outputs)) {
|
430
|
+
buildTarget.config.outputs = buildTarget.config.outputs.map((output) => {
|
431
|
+
if (output === '{options.outputPath}') {
|
432
|
+
// the target won't have an outputPath option, so we replace it with the new output path
|
433
|
+
return normalizeOutput(newOutputPath, devkit_1.workspaceRoot, project.root);
|
434
|
+
}
|
435
|
+
const normalizedOutputPath = output
|
436
|
+
.replace('{workspaceRoot}/', '')
|
437
|
+
.replace('{projectRoot}', project.root)
|
438
|
+
.replace('{projectName}', '');
|
439
|
+
if (/\/browser\/?$/.test(normalizedOutputPath) &&
|
440
|
+
normalizedOutputPath.replace(/\/browser\/?$/, '') === newOutputPath) {
|
441
|
+
return normalizeOutput(newOutputPath, devkit_1.workspaceRoot, project.root);
|
442
|
+
}
|
443
|
+
return output;
|
444
|
+
});
|
445
|
+
}
|
446
|
+
else {
|
447
|
+
delete buildTarget.config.outputs;
|
448
|
+
}
|
449
|
+
if (buildTarget.config.syncGenerators?.length === 1 &&
|
450
|
+
buildTarget.config.syncGenerators[0] === '@nx/js:typescript-sync') {
|
451
|
+
delete buildTarget.config.syncGenerators;
|
452
|
+
}
|
453
|
+
else if (buildTarget.config.syncGenerators?.length) {
|
454
|
+
buildTarget.config.syncGenerators = Array.from(new Set([
|
455
|
+
...buildTarget.config.syncGenerators,
|
456
|
+
'@nx/js:typescript-sync',
|
457
|
+
]));
|
458
|
+
}
|
459
|
+
if (Object.keys(buildTarget.config).length) {
|
460
|
+
// there's extra target metadata left that wouldn't be inferred, we keep it
|
461
|
+
project.targets[inferredBuildTargetName] = buildTarget.config;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
if (serveTarget) {
|
465
|
+
delete serveTarget.config.options;
|
466
|
+
delete serveTarget.config.configurations;
|
467
|
+
delete serveTarget.config.defaultConfiguration;
|
468
|
+
delete serveTarget.config.executor;
|
469
|
+
if (serveTarget.config.continuous) {
|
470
|
+
delete serveTarget.config.continuous;
|
471
|
+
}
|
472
|
+
if (serveTarget.config.syncGenerators?.length === 1 &&
|
473
|
+
serveTarget.config.syncGenerators[0] === '@nx/js:typescript-sync') {
|
474
|
+
delete serveTarget.config.syncGenerators;
|
475
|
+
}
|
476
|
+
else if (serveTarget.config.syncGenerators?.length) {
|
477
|
+
serveTarget.config.syncGenerators = Array.from(new Set([
|
478
|
+
...serveTarget.config.syncGenerators,
|
479
|
+
'@nx/js:typescript-sync',
|
480
|
+
]));
|
481
|
+
}
|
482
|
+
if (projectServePort !== DEFAULT_PORT) {
|
483
|
+
serveTarget.config.options = {};
|
484
|
+
serveTarget.config.options.port = projectServePort;
|
485
|
+
}
|
486
|
+
if (Object.keys(serveTarget.config).length) {
|
487
|
+
// there's extra target metadata left that wouldn't be inferred, we keep it
|
488
|
+
project.targets[inferredServeTargetName] = serveTarget.config;
|
489
|
+
}
|
490
|
+
}
|
491
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
343
492
|
// This is needed to prevent a circular execution of the build target
|
344
493
|
const rootPkgJson = (0, devkit_1.readJson)(tree, 'package.json');
|
345
494
|
if (rootPkgJson.scripts?.build === 'nx build') {
|