@nx/webpack 0.0.0-pr-22870-9ecd080 → 0.0.0-pr-26623-78cbba7
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/generators.json +0 -5
- package/index.d.ts +1 -3
- package/index.js +1 -5
- package/package.json +4 -5
- package/src/executors/dev-server/dev-server.impl.js +1 -7
- package/src/executors/webpack/webpack.impl.js +0 -5
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +1 -1
- package/src/plugins/plugin.js +4 -4
- package/src/plugins/webpack-nx-build-coordination-plugin.js +1 -8
- package/src/generators/convert-config-to-webpack-plugin/convert-config-to-webpack-plugin.d.ts +0 -7
- package/src/generators/convert-config-to-webpack-plugin/convert-config-to-webpack-plugin.js +0 -89
- package/src/generators/convert-config-to-webpack-plugin/lib/extract-webpack-options.d.ts +0 -6
- package/src/generators/convert-config-to-webpack-plugin/lib/extract-webpack-options.js +0 -106
- package/src/generators/convert-config-to-webpack-plugin/lib/normalize-path-options.d.ts +0 -2
- package/src/generators/convert-config-to-webpack-plugin/lib/normalize-path-options.js +0 -75
- package/src/generators/convert-config-to-webpack-plugin/lib/utils.d.ts +0 -1
- package/src/generators/convert-config-to-webpack-plugin/lib/utils.js +0 -14
- package/src/generators/convert-config-to-webpack-plugin/lib/validate-project.d.ts +0 -9
- package/src/generators/convert-config-to-webpack-plugin/lib/validate-project.js +0 -44
- package/src/generators/convert-config-to-webpack-plugin/schema.json +0 -19
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +0 -29
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +0 -59
package/generators.json
CHANGED
|
@@ -15,11 +15,6 @@
|
|
|
15
15
|
"schema": "./src/generators/configuration/schema.json",
|
|
16
16
|
"description": "Add webpack configuration to a project.",
|
|
17
17
|
"hidden": true
|
|
18
|
-
},
|
|
19
|
-
"convert-config-to-webpack-plugin": {
|
|
20
|
-
"factory": "./src/generators/convert-config-to-webpack-plugin/convert-config-to-webpack-plugin",
|
|
21
|
-
"schema": "./src/generators/convert-config-to-webpack-plugin/schema.json",
|
|
22
|
-
"description": "Convert the project to use the `NxAppWebpackPlugin` and `NxReactWebpackPlugin`."
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
20
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { configurationGenerator } from './src/generators/configuration/configuration';
|
|
2
2
|
import { NxAppWebpackPlugin } from './src/plugins/nx-webpack-plugin/nx-app-webpack-plugin';
|
|
3
3
|
import { NxTsconfigPathsWebpackPlugin as _NxTsconfigPathsWebpackPlugin } from './src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin';
|
|
4
|
-
|
|
5
|
-
import { useLegacyNxPlugin } from './src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin';
|
|
6
|
-
export { configurationGenerator, convertConfigToWebpackPluginGenerator, useLegacyNxPlugin, };
|
|
4
|
+
export { configurationGenerator };
|
|
7
5
|
/** @deprecated Use `configurationGenerator` instead. */
|
|
8
6
|
export declare const webpackProjectGenerator: typeof configurationGenerator;
|
|
9
7
|
/** @deprecated Use NxAppWebpackPlugin from `@nx/webpack/app-plugin` instead. */
|
package/index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webpackInitGenerator = exports.NxTsconfigPathsWebpackPlugin = exports.NxWebpackPlugin = exports.webpackProjectGenerator = exports.
|
|
3
|
+
exports.webpackInitGenerator = exports.NxTsconfigPathsWebpackPlugin = exports.NxWebpackPlugin = exports.webpackProjectGenerator = exports.configurationGenerator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const configuration_1 = require("./src/generators/configuration/configuration");
|
|
6
6
|
Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
|
|
7
7
|
const nx_app_webpack_plugin_1 = require("./src/plugins/nx-webpack-plugin/nx-app-webpack-plugin");
|
|
8
8
|
const nx_tsconfig_paths_webpack_plugin_1 = require("./src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin");
|
|
9
|
-
const convert_config_to_webpack_plugin_1 = require("./src/generators/convert-config-to-webpack-plugin/convert-config-to-webpack-plugin");
|
|
10
|
-
Object.defineProperty(exports, "convertConfigToWebpackPluginGenerator", { enumerable: true, get: function () { return convert_config_to_webpack_plugin_1.convertConfigToWebpackPluginGenerator; } });
|
|
11
|
-
const use_legacy_nx_plugin_1 = require("./src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin");
|
|
12
|
-
Object.defineProperty(exports, "useLegacyNxPlugin", { enumerable: true, get: function () { return use_legacy_nx_plugin_1.useLegacyNxPlugin; } });
|
|
13
9
|
// Exported for backwards compatibility in case a plugin is using the old name.
|
|
14
10
|
/** @deprecated Use `configurationGenerator` instead. */
|
|
15
11
|
exports.webpackProjectGenerator = configuration_1.configurationGenerator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/webpack",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-26623-78cbba7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Webpack contains executors and generators that support building applications using Webpack.",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/core": "^7.23.2",
|
|
34
|
-
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
35
34
|
"ajv": "^8.12.0",
|
|
36
35
|
"autoprefixer": "^10.4.9",
|
|
37
36
|
"babel-loader": "^9.1.2",
|
|
@@ -65,9 +64,9 @@
|
|
|
65
64
|
"webpack-dev-server": "^4.9.3",
|
|
66
65
|
"webpack-node-externals": "^3.0.0",
|
|
67
66
|
"webpack-subresource-integrity": "^5.1.0",
|
|
68
|
-
"@nx/devkit": "0.0.0-pr-
|
|
69
|
-
"@nx/js": "0.0.0-pr-
|
|
70
|
-
"@nrwl/webpack": "0.0.0-pr-
|
|
67
|
+
"@nx/devkit": "0.0.0-pr-26623-78cbba7",
|
|
68
|
+
"@nx/js": "0.0.0-pr-26623-78cbba7",
|
|
69
|
+
"@nrwl/webpack": "0.0.0-pr-26623-78cbba7"
|
|
71
70
|
},
|
|
72
71
|
"publishConfig": {
|
|
73
72
|
"access": "public"
|
|
@@ -50,13 +50,7 @@ async function* devServerExecutor(serveOptions, context) {
|
|
|
50
50
|
}
|
|
51
51
|
else if (userDefinedWebpackConfig) {
|
|
52
52
|
// New behavior, we want the webpack config to export object
|
|
53
|
-
|
|
54
|
-
if (typeof userDefinedWebpackConfig === 'function') {
|
|
55
|
-
config = await userDefinedWebpackConfig(process.env.NODE_ENV, {});
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
config = userDefinedWebpackConfig;
|
|
59
|
-
}
|
|
53
|
+
config = userDefinedWebpackConfig;
|
|
60
54
|
config.devServer ??= devServer;
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -41,11 +41,6 @@ async function getWebpackConfigs(options, context) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
else if (userDefinedWebpackConfig) {
|
|
44
|
-
if (typeof userDefinedWebpackConfig === 'function') {
|
|
45
|
-
// assume it's an async standard webpack config function
|
|
46
|
-
// https://webpack.js.org/configuration/configuration-types/#exporting-a-promise
|
|
47
|
-
return await userDefinedWebpackConfig(process.env.NODE_ENV, {});
|
|
48
|
-
}
|
|
49
44
|
// New behavior, we want the webpack config to export object
|
|
50
45
|
return userDefinedWebpackConfig;
|
|
51
46
|
}
|
|
@@ -47,7 +47,7 @@ function normalizeOptions(options) {
|
|
|
47
47
|
originalTargetOptions);
|
|
48
48
|
}
|
|
49
49
|
const sourceRoot = projectNode.data.sourceRoot ?? projectNode.data.root;
|
|
50
|
-
if (!
|
|
50
|
+
if (!options.main) {
|
|
51
51
|
throw new Error(`Missing "main" option for the entry file. Set this option in your Nx webpack plugin.`);
|
|
52
52
|
}
|
|
53
53
|
return {
|
package/src/plugins/plugin.js
CHANGED
|
@@ -150,9 +150,9 @@ function normalizeOutputPath(outputPath, projectRoot) {
|
|
|
150
150
|
}
|
|
151
151
|
function normalizeOptions(options) {
|
|
152
152
|
return {
|
|
153
|
-
buildTargetName: options
|
|
154
|
-
serveTargetName: options
|
|
155
|
-
serveStaticTargetName: options
|
|
156
|
-
previewTargetName: options
|
|
153
|
+
buildTargetName: options.buildTargetName ?? 'build',
|
|
154
|
+
serveTargetName: options.serveTargetName ?? 'serve',
|
|
155
|
+
serveStaticTargetName: options.serveStaticTargetName ?? 'serve-static',
|
|
156
|
+
previewTargetName: options.previewTargetName ?? 'preview',
|
|
157
157
|
};
|
|
158
158
|
}
|
|
@@ -13,14 +13,7 @@ class WebpackNxBuildCoordinationPlugin {
|
|
|
13
13
|
if (!skipInitialBuild) {
|
|
14
14
|
this.buildChangedProjects();
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
this.startWatchingBuildableLibs();
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
output_1.output.warn({
|
|
21
|
-
title: 'Nx Daemon is not enabled. Buildable libs will not be rebuilt on file changes.',
|
|
22
|
-
});
|
|
23
|
-
}
|
|
16
|
+
this.startWatchingBuildableLibs();
|
|
24
17
|
}
|
|
25
18
|
apply(compiler) {
|
|
26
19
|
compiler.hooks.beforeCompile.tapPromise('IncrementalDevServerPlugin', async () => {
|
package/src/generators/convert-config-to-webpack-plugin/convert-config-to-webpack-plugin.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
interface Schema {
|
|
3
|
-
project?: string;
|
|
4
|
-
skipFormat?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function convertConfigToWebpackPluginGenerator(tree: Tree, options: Schema): Promise<void>;
|
|
7
|
-
export default convertConfigToWebpackPluginGenerator;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertConfigToWebpackPluginGenerator = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
-
const extract_webpack_options_1 = require("./lib/extract-webpack-options");
|
|
7
|
-
const normalize_path_options_1 = require("./lib/normalize-path-options");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const validate_project_1 = require("./lib/validate-project");
|
|
10
|
-
// Make text JSON compatible
|
|
11
|
-
const preprocessText = (text) => {
|
|
12
|
-
return text
|
|
13
|
-
.replace(/(\w+):/g, '"$1":') // Quote property names
|
|
14
|
-
.replace(/'/g, '"') // Convert single quotes to double quotes
|
|
15
|
-
.replace(/,(\s*[}\]])/g, '$1') // Remove trailing commas
|
|
16
|
-
.replace(/(\r\n|\n|\r|\t)/gm, ''); // Remove newlines and tabs
|
|
17
|
-
};
|
|
18
|
-
async function convertConfigToWebpackPluginGenerator(tree, options) {
|
|
19
|
-
let migrated = 0;
|
|
20
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
21
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/webpack:webpack', (currentTargetOptions, projectName, targetName, configurationName) => {
|
|
22
|
-
if (options.project && projectName !== options.project) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (!configurationName) {
|
|
26
|
-
const project = projects.get(projectName);
|
|
27
|
-
const target = project.targets[targetName];
|
|
28
|
-
const hasError = (0, validate_project_1.validateProject)(tree, project);
|
|
29
|
-
if (hasError) {
|
|
30
|
-
throw new Error(hasError);
|
|
31
|
-
}
|
|
32
|
-
const webpackConfigPath = currentTargetOptions?.webpackConfig || '';
|
|
33
|
-
if (webpackConfigPath && tree.exists(webpackConfigPath)) {
|
|
34
|
-
let { withNxConfig: webpackOptions, withReactConfig } = (0, extract_webpack_options_1.extractWebpackOptions)(tree, webpackConfigPath);
|
|
35
|
-
// if webpackOptions === undefined
|
|
36
|
-
// withNx was not found in the webpack.config.js file so we should skip this project
|
|
37
|
-
if (webpackOptions !== undefined) {
|
|
38
|
-
let parsedOptions = {};
|
|
39
|
-
if (webpackOptions) {
|
|
40
|
-
parsedOptions = JSON.parse(preprocessText(webpackOptions.getText()));
|
|
41
|
-
parsedOptions = (0, normalize_path_options_1.normalizePathOptions)(project.root, parsedOptions);
|
|
42
|
-
}
|
|
43
|
-
target.options.standardWebpackConfigFunction = true;
|
|
44
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
|
45
|
-
const { dir, name, ext } = (0, path_1.parse)(webpackConfigPath);
|
|
46
|
-
tree.rename(webpackConfigPath, `${(0, devkit_1.joinPathFragments)(dir, `${name}.old${ext}`)}`);
|
|
47
|
-
tree.write(webpackConfigPath, (0, devkit_1.stripIndents) `
|
|
48
|
-
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
|
|
49
|
-
const { NxReactWebpackPlugin } = require('@nx/react/webpack-plugin');
|
|
50
|
-
const { useLegacyNxPlugin } = require('@nx/webpack');
|
|
51
|
-
|
|
52
|
-
// This file was migrated using @nx/webpack:convert-config-to-webpack-plugin from your './webpack.config.old.js'
|
|
53
|
-
// Please check that the options here are correct as they were moved from the old webpack.config.js to this file.
|
|
54
|
-
const options = ${webpackOptions ? JSON.stringify(parsedOptions, null, 2) : '{}'};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @type{import('webpack').WebpackOptionsNormalized}
|
|
58
|
-
*/
|
|
59
|
-
module.exports = async () => ({
|
|
60
|
-
plugins: [
|
|
61
|
-
${webpackOptions
|
|
62
|
-
? 'new NxAppWebpackPlugin(options)'
|
|
63
|
-
: 'new NxAppWebpackPlugin()'},
|
|
64
|
-
${withReactConfig
|
|
65
|
-
? `new NxReactWebpackPlugin(${withReactConfig.getText()})`
|
|
66
|
-
: `new NxReactWebpackPlugin({
|
|
67
|
-
// Uncomment this line if you don't want to use SVGR
|
|
68
|
-
// See: https://react-svgr.com/
|
|
69
|
-
// svgr: false
|
|
70
|
-
})`},
|
|
71
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
72
|
-
await useLegacyNxPlugin(require('./webpack.config.old'), options),
|
|
73
|
-
],
|
|
74
|
-
});
|
|
75
|
-
`);
|
|
76
|
-
migrated++;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
if (migrated === 0) {
|
|
82
|
-
throw new Error('Could not find any projects to migrate.');
|
|
83
|
-
}
|
|
84
|
-
if (!options.skipFormat) {
|
|
85
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.convertConfigToWebpackPluginGenerator = convertConfigToWebpackPluginGenerator;
|
|
89
|
-
exports.default = convertConfigToWebpackPluginGenerator;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractWebpackOptions = void 0;
|
|
4
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
|
-
const ts = require("typescript");
|
|
6
|
-
function extractWebpackOptions(tree, webpackConfigPath) {
|
|
7
|
-
const source = tree.read(webpackConfigPath).toString('utf-8');
|
|
8
|
-
const ast = tsquery_1.tsquery.ast(source);
|
|
9
|
-
const withNxQuery = 'CallExpression:has(Identifier[name="withNx"])';
|
|
10
|
-
const withReactQuery = 'CallExpression:has(Identifier[name="withReact"])';
|
|
11
|
-
const withWebQuery = 'CallExpression:has(Identifier[name="withWeb"])';
|
|
12
|
-
const withNxCall = (0, tsquery_1.tsquery)(ast, withNxQuery);
|
|
13
|
-
const withReactCall = (0, tsquery_1.tsquery)(ast, withReactQuery);
|
|
14
|
-
const withWebCall = (0, tsquery_1.tsquery)(ast, withWebQuery);
|
|
15
|
-
// If the config is empty set to empty string to avoid undefined. Undefined is used to check if the withNx exists inside of the config file.
|
|
16
|
-
let withNxConfig, withReactConfig;
|
|
17
|
-
withWebCall.forEach((node) => {
|
|
18
|
-
const argument = node.arguments[0] || '';
|
|
19
|
-
withNxConfig = argument; // Since withWeb and withNx use the same config object and both should not exist in the same file, we can reuse the withNxConfig variable.
|
|
20
|
-
});
|
|
21
|
-
withNxCall.forEach((node) => {
|
|
22
|
-
const argument = node.arguments[0] || ''; // The first argument is the config object
|
|
23
|
-
withNxConfig = argument;
|
|
24
|
-
});
|
|
25
|
-
withReactCall.forEach((node) => {
|
|
26
|
-
const argument = node.arguments[0] || '';
|
|
27
|
-
withReactConfig = argument;
|
|
28
|
-
});
|
|
29
|
-
if (withNxConfig !== undefined) {
|
|
30
|
-
// Only remove the withNx and withReact calls if they exist
|
|
31
|
-
let updatedSource = removeCallExpressions(source, [
|
|
32
|
-
'withNx',
|
|
33
|
-
'withReact',
|
|
34
|
-
'withWeb',
|
|
35
|
-
]);
|
|
36
|
-
updatedSource = removeImportDeclarations(updatedSource, 'withNx', '@nx/webpack');
|
|
37
|
-
updatedSource = removeImportDeclarations(updatedSource, 'withWeb', '@nx/webpack');
|
|
38
|
-
updatedSource = removeImportDeclarations(updatedSource, 'withReact', '@nx/react');
|
|
39
|
-
tree.write(webpackConfigPath, updatedSource);
|
|
40
|
-
}
|
|
41
|
-
return { withNxConfig, withReactConfig };
|
|
42
|
-
}
|
|
43
|
-
exports.extractWebpackOptions = extractWebpackOptions;
|
|
44
|
-
function removeCallExpressions(source, functionNames) {
|
|
45
|
-
let modifiedSource = source;
|
|
46
|
-
functionNames.forEach((functionName) => {
|
|
47
|
-
const callExpressionQuery = `CallExpression:has(Identifier[name="composePlugins"]) > CallExpression:has(Identifier[name="${functionName}"])`;
|
|
48
|
-
modifiedSource = tsquery_1.tsquery.replace(modifiedSource, callExpressionQuery, () => {
|
|
49
|
-
return ''; // Removes the entire CallExpression
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
return modifiedSource;
|
|
53
|
-
}
|
|
54
|
-
function removeImportDeclarations(source, importName, moduleName) {
|
|
55
|
-
const sourceFile = tsquery_1.tsquery.ast(source);
|
|
56
|
-
const modifiedStatements = sourceFile.statements
|
|
57
|
-
.map((statement) => {
|
|
58
|
-
if (!ts.isVariableStatement(statement))
|
|
59
|
-
return statement;
|
|
60
|
-
const declarationList = statement.declarationList;
|
|
61
|
-
const newDeclarations = declarationList.declarations
|
|
62
|
-
.map((declaration) => {
|
|
63
|
-
if (!ts.isVariableDeclaration(declaration) ||
|
|
64
|
-
!declaration.initializer)
|
|
65
|
-
return declaration;
|
|
66
|
-
if (ts.isCallExpression(declaration.initializer) &&
|
|
67
|
-
ts.isIdentifier(declaration.initializer.expression)) {
|
|
68
|
-
const callExpr = declaration.initializer.expression;
|
|
69
|
-
if (callExpr.text === 'require' &&
|
|
70
|
-
declaration.initializer.arguments[0]
|
|
71
|
-
?.getText()
|
|
72
|
-
.replace(/['"]/g, '') === moduleName) {
|
|
73
|
-
if (ts.isObjectBindingPattern(declaration.name)) {
|
|
74
|
-
const bindingElements = declaration.name.elements.filter((element) => {
|
|
75
|
-
const elementName = element.name.getText();
|
|
76
|
-
return elementName !== importName;
|
|
77
|
-
});
|
|
78
|
-
if (bindingElements.length > 0) {
|
|
79
|
-
const newBindingPattern = ts.factory.updateObjectBindingPattern(declaration.name, bindingElements);
|
|
80
|
-
// Update the variable declaration with the new binding pattern without the specified import name
|
|
81
|
-
return ts.factory.updateVariableDeclaration(declaration, newBindingPattern, declaration.exclamationToken, declaration.type, declaration.initializer);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return null; // Remove this declaration entirely if no bindings remain
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return declaration;
|
|
90
|
-
})
|
|
91
|
-
.filter(Boolean);
|
|
92
|
-
if (newDeclarations.length > 0) {
|
|
93
|
-
const newDeclarationList = ts.factory.updateVariableDeclarationList(declarationList, newDeclarations);
|
|
94
|
-
return ts.factory.updateVariableStatement(statement, statement.modifiers, newDeclarationList);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
return null; // Remove the entire statement
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
.filter(Boolean);
|
|
101
|
-
// Use printer to format the source code and rewrite the modified
|
|
102
|
-
const newSourceFile = ts.factory.updateSourceFile(sourceFile, modifiedStatements);
|
|
103
|
-
const printer = ts.createPrinter();
|
|
104
|
-
const formattedSource = printer.printFile(newSourceFile);
|
|
105
|
-
return formattedSource;
|
|
106
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizePathOptions = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
const executorFieldsToNormalize = [
|
|
6
|
-
'outputPath',
|
|
7
|
-
'index',
|
|
8
|
-
'main',
|
|
9
|
-
'assets',
|
|
10
|
-
'tsConfig',
|
|
11
|
-
'styles',
|
|
12
|
-
'babelConfig',
|
|
13
|
-
'additionalEntryPoints',
|
|
14
|
-
'scripts',
|
|
15
|
-
'fileReplacements',
|
|
16
|
-
'postcssConfig',
|
|
17
|
-
'stylePreprocessorOptions',
|
|
18
|
-
'publicPath',
|
|
19
|
-
];
|
|
20
|
-
function normalizePathOptions(projectRoot, options) {
|
|
21
|
-
for (const [key, value] of Object.entries(options)) {
|
|
22
|
-
if (!executorFieldsToNormalize.includes(key)) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
options[key] = normalizePath(projectRoot, key, value);
|
|
26
|
-
}
|
|
27
|
-
return options;
|
|
28
|
-
}
|
|
29
|
-
exports.normalizePathOptions = normalizePathOptions;
|
|
30
|
-
function normalizePath(projectRoot, key, value) {
|
|
31
|
-
if (!value)
|
|
32
|
-
return value;
|
|
33
|
-
switch (key) {
|
|
34
|
-
case 'assets':
|
|
35
|
-
return value.map((asset) => {
|
|
36
|
-
if (typeof asset === 'string') {
|
|
37
|
-
return (0, utils_1.toProjectRelativePath)(asset, projectRoot);
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...asset,
|
|
41
|
-
input: (0, utils_1.toProjectRelativePath)(asset.input, projectRoot),
|
|
42
|
-
output: (0, utils_1.toProjectRelativePath)(asset.output, projectRoot),
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
case 'styles':
|
|
46
|
-
case 'scripts':
|
|
47
|
-
return value.map((item) => {
|
|
48
|
-
if (typeof item === 'string') {
|
|
49
|
-
return (0, utils_1.toProjectRelativePath)(item, projectRoot);
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
...item,
|
|
53
|
-
input: (0, utils_1.toProjectRelativePath)(item.input, projectRoot),
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
case 'additionalEntryPoints':
|
|
57
|
-
return value.map((entry) => {
|
|
58
|
-
return {
|
|
59
|
-
...entry,
|
|
60
|
-
entryPath: (0, utils_1.toProjectRelativePath)(entry.entryPath, projectRoot),
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
case 'fileReplacements':
|
|
64
|
-
return value.map((replacement) => {
|
|
65
|
-
return {
|
|
66
|
-
replace: (0, utils_1.toProjectRelativePath)(replacement.replace, projectRoot),
|
|
67
|
-
with: (0, utils_1.toProjectRelativePath)(replacement.with, projectRoot),
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
default:
|
|
71
|
-
return Array.isArray(value)
|
|
72
|
-
? value.map((item) => (0, utils_1.toProjectRelativePath)(item, projectRoot))
|
|
73
|
-
: (0, utils_1.toProjectRelativePath)(value, projectRoot);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function toProjectRelativePath(path: string, projectRoot: string): string;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toProjectRelativePath = void 0;
|
|
4
|
-
const posix_1 = require("path/posix");
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function toProjectRelativePath(path, projectRoot) {
|
|
7
|
-
if (projectRoot === '.') {
|
|
8
|
-
// workspace and project root are the same, we normalize it to ensure it
|
|
9
|
-
return path.startsWith('.') ? path : `./${path}`;
|
|
10
|
-
}
|
|
11
|
-
const relativePath = (0, posix_1.relative)((0, posix_1.resolve)(devkit_1.workspaceRoot, projectRoot), (0, posix_1.resolve)(devkit_1.workspaceRoot, path));
|
|
12
|
-
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
13
|
-
}
|
|
14
|
-
exports.toProjectRelativePath = toProjectRelativePath;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
2
|
-
/**
|
|
3
|
-
* Validates the project to ensure it can be migrated
|
|
4
|
-
*
|
|
5
|
-
* @param tree The virtaul file system
|
|
6
|
-
* @param project the project configuration object for the project
|
|
7
|
-
* @returns A string if there is an error, otherwise undefined
|
|
8
|
-
*/
|
|
9
|
-
export declare function validateProject(tree: Tree, project: ProjectConfiguration): string;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateProject = void 0;
|
|
4
|
-
function hasAnotherWebpackConfig(tree, projectRoot) {
|
|
5
|
-
const files = tree.children(projectRoot);
|
|
6
|
-
const projectJsonString = tree.read(`${projectRoot}/project.json`, 'utf-8');
|
|
7
|
-
for (const file of files) {
|
|
8
|
-
if (file !== 'webpack.config.js' &&
|
|
9
|
-
file.endsWith('.js') &&
|
|
10
|
-
file.includes('webpack.config') &&
|
|
11
|
-
projectJsonString.includes(file) &&
|
|
12
|
-
tree.exists(`${projectRoot}/webpack.config.js`)) {
|
|
13
|
-
return 'Cannot convert a project with multiple webpack config files. Please consolidate them into a single webpack.config.js file.';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function isNestProject(project) {
|
|
18
|
-
for (const target in project.targets) {
|
|
19
|
-
if (project.targets[target].executor === '@nx/js:node') {
|
|
20
|
-
return `The project ${project.name} is using the '@nx/js:node' executor. At the moment, we do not support migrating such projects.`;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Validates the project to ensure it can be migrated
|
|
26
|
-
*
|
|
27
|
-
* @param tree The virtaul file system
|
|
28
|
-
* @param project the project configuration object for the project
|
|
29
|
-
* @returns A string if there is an error, otherwise undefined
|
|
30
|
-
*/
|
|
31
|
-
function validateProject(tree, project) {
|
|
32
|
-
const containsMfeExecutor = Object.keys(project.targets).some((target) => {
|
|
33
|
-
return [
|
|
34
|
-
'@nx/react:module-federation-dev-server',
|
|
35
|
-
'@nx/angular:module-federation-dev-server',
|
|
36
|
-
].includes(project.targets[target].executor);
|
|
37
|
-
});
|
|
38
|
-
if (containsMfeExecutor) {
|
|
39
|
-
return `The project ${project.name} is using Module Federation. At the moment, we don't support migrating projects that use Module Federation.`;
|
|
40
|
-
}
|
|
41
|
-
const hasAnotherConfig = hasAnotherWebpackConfig(tree, project.root);
|
|
42
|
-
return hasAnotherConfig || isNestProject(project);
|
|
43
|
-
}
|
|
44
|
-
exports.validateProject = validateProject;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/schema",
|
|
3
|
-
"$id": "NxWebpackConvertConfigToWebpackPlugin",
|
|
4
|
-
"description": "Convert existing Webpack project(s) using `@nx/webpack:webpack` executor that uses `withNx` to use `NxAppWebpackPlugin`. Defaults to migrating all projects. Pass '--project' to migrate only one target.",
|
|
5
|
-
"title": "Convert Webpack project using withNx to NxAppWebpackPlugin",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"properties": {
|
|
8
|
-
"project": {
|
|
9
|
-
"type": "string",
|
|
10
|
-
"description": "The project to convert from using the `@nx/webpack:webpack` executor and `withNx` plugin to use `NxAppWebpackPlugin`.",
|
|
11
|
-
"x-priority": "important"
|
|
12
|
-
},
|
|
13
|
-
"skipFormat": {
|
|
14
|
-
"type": "boolean",
|
|
15
|
-
"description": "Whether to format files at the end of the migration.",
|
|
16
|
-
"default": false
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NxWebpackExecutionContext } from '../../utils/config';
|
|
2
|
-
import { NxAppWebpackPluginOptions } from '../nx-webpack-plugin/nx-app-webpack-plugin-options';
|
|
3
|
-
import { Configuration } from 'webpack';
|
|
4
|
-
/**
|
|
5
|
-
* This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
|
|
6
|
-
* Initially the webpack config would be passed to the legacy plugin function and the options would be passed as a second argument.
|
|
7
|
-
* example:
|
|
8
|
-
* module.exports = composePlugins(
|
|
9
|
-
withNx(),
|
|
10
|
-
(config) => {
|
|
11
|
-
return config;
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
|
|
16
|
-
Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
|
|
17
|
-
The context options are created and passed to the legacy plugin function.
|
|
18
|
-
|
|
19
|
-
module.exports = async () => ({
|
|
20
|
-
plugins: [
|
|
21
|
-
...otherPlugins,
|
|
22
|
-
await nxUseLegacyPlugin(require({path}), options),
|
|
23
|
-
],
|
|
24
|
-
});
|
|
25
|
-
* @param fn The legacy plugin function usually from `combinedPlugins`
|
|
26
|
-
* @param executorOptions The options passed usually inside the executor or the config file
|
|
27
|
-
* @returns Webpack configuration
|
|
28
|
-
*/
|
|
29
|
-
export declare function useLegacyNxPlugin(fn: (config: Configuration, ctx: NxWebpackExecutionContext) => Promise<Configuration>, executorOptions: NxAppWebpackPluginOptions): Promise<(config: Configuration) => Promise<Configuration>>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLegacyNxPlugin = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const normalize_options_1 = require("../nx-webpack-plugin/lib/normalize-options");
|
|
6
|
-
/**
|
|
7
|
-
* This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
|
|
8
|
-
* Initially the webpack config would be passed to the legacy plugin function and the options would be passed as a second argument.
|
|
9
|
-
* example:
|
|
10
|
-
* module.exports = composePlugins(
|
|
11
|
-
withNx(),
|
|
12
|
-
(config) => {
|
|
13
|
-
return config;
|
|
14
|
-
}
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
|
|
18
|
-
Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
|
|
19
|
-
The context options are created and passed to the legacy plugin function.
|
|
20
|
-
|
|
21
|
-
module.exports = async () => ({
|
|
22
|
-
plugins: [
|
|
23
|
-
...otherPlugins,
|
|
24
|
-
await nxUseLegacyPlugin(require({path}), options),
|
|
25
|
-
],
|
|
26
|
-
});
|
|
27
|
-
* @param fn The legacy plugin function usually from `combinedPlugins`
|
|
28
|
-
* @param executorOptions The options passed usually inside the executor or the config file
|
|
29
|
-
* @returns Webpack configuration
|
|
30
|
-
*/
|
|
31
|
-
async function useLegacyNxPlugin(fn, executorOptions) {
|
|
32
|
-
if (global.NX_GRAPH_CREATION) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const options = (0, normalize_options_1.normalizeOptions)(executorOptions);
|
|
36
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
37
|
-
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
38
|
-
const project = projectGraph.nodes[projectName];
|
|
39
|
-
const targetName = process.env.NX_TASK_TARGET_TARGET;
|
|
40
|
-
const context = {
|
|
41
|
-
cwd: process.cwd(),
|
|
42
|
-
isVerbose: process.env.NX_VERBOSE_LOGGING === 'true',
|
|
43
|
-
root: project.data.root,
|
|
44
|
-
projectGraph: (0, devkit_1.readCachedProjectGraph)(),
|
|
45
|
-
target: project.data.targets[targetName],
|
|
46
|
-
targetName: targetName,
|
|
47
|
-
projectName: projectName,
|
|
48
|
-
};
|
|
49
|
-
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION;
|
|
50
|
-
return async (config) => {
|
|
51
|
-
const ctx = {
|
|
52
|
-
context,
|
|
53
|
-
options: options,
|
|
54
|
-
configuration,
|
|
55
|
-
};
|
|
56
|
-
return await fn(config, ctx);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
exports.useLegacyNxPlugin = useLegacyNxPlugin;
|