@nx/webpack 17.0.5 → 17.0.6
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/LICENSE +1 -1
- package/README.md +4 -9
- package/generators.json +2 -2
- package/index.d.ts +1 -3
- package/index.js +2 -7
- package/migrations.json +0 -6
- package/package.json +5 -6
- package/src/executors/dev-server/dev-server.impl.js +17 -31
- package/src/executors/dev-server/lib/get-dev-server-config.d.ts +3 -2
- package/src/executors/dev-server/lib/get-dev-server-config.js +26 -18
- package/src/executors/dev-server/schema.d.ts +8 -8
- package/src/executors/webpack/lib/get-webpack-config.d.ts +5 -0
- package/src/executors/webpack/lib/get-webpack-config.js +16 -0
- package/src/executors/webpack/lib/normalize-options.d.ts +2 -1
- package/src/executors/webpack/lib/normalize-options.js +53 -9
- package/src/executors/webpack/schema.d.ts +7 -10
- package/src/executors/webpack/schema.json +50 -30
- package/src/executors/webpack/webpack.impl.js +16 -36
- package/src/generators/configuration/configuration.d.ts +2 -3
- package/src/generators/configuration/configuration.js +23 -95
- package/src/generators/configuration/schema.d.ts +0 -1
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +0 -1
- package/src/generators/init/init.js +23 -48
- package/src/generators/init/schema.d.ts +2 -4
- package/src/generators/init/schema.json +13 -18
- package/src/plugins/generate-package-json-plugin.d.ts +4 -6
- package/src/plugins/generate-package-json-plugin.js +14 -11
- package/src/utils/config.d.ts +6 -11
- package/src/utils/config.js +13 -48
- package/src/utils/get-client-environment.js +1 -4
- package/src/utils/module-federation/dependencies.js +3 -15
- package/src/utils/module-federation/get-remotes-for-host.d.ts +1 -2
- package/src/utils/module-federation/get-remotes-for-host.js +7 -11
- package/src/utils/module-federation/remotes.js +1 -1
- package/src/utils/module-federation/secondary-entry-points.js +1 -1
- package/src/utils/module-federation/typescript.js +9 -14
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +2 -2
- package/src/utils/webpack/custom-webpack.d.ts +2 -0
- package/src/utils/webpack/{resolve-user-defined-webpack-config.js → custom-webpack.js} +8 -14
- package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
- package/src/utils/webpack/interpolate-env-variables-to-index.js +1 -4
- package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
- package/src/utils/with-nx.d.ts +58 -4
- package/src/utils/with-nx.js +362 -22
- package/src/utils/with-web.d.ts +2 -2
- package/src/utils/with-web.js +488 -9
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -5
- package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +0 -2
- package/src/migrations/update-17-2-1/webpack-config-setup.js +0 -31
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +0 -8
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +0 -31
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +0 -5
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +0 -318
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +0 -5
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +0 -372
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +0 -53
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +0 -78
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +0 -1
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +0 -35
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +0 -3
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +0 -42
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +0 -4
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +0 -148
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +0 -73
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +0 -117
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +0 -216
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +0 -2
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +0 -17
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +0 -48
- package/src/plugins/plugin.d.ts +0 -9
- package/src/plugins/plugin.js +0 -132
- package/src/utils/ensure-dependencies.d.ts +0 -6
- package/src/utils/ensure-dependencies.js +0 -27
- package/src/utils/has-plugin.d.ts +0 -2
- package/src/utils/has-plugin.js +0 -11
- package/src/utils/webpack/read-webpack-options.d.ts +0 -10
- package/src/utils/webpack/read-webpack-options.js +0 -41
- package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +0 -3
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"$id": "NxWebpackInit",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"title": "Init Webpack Plugin",
|
|
6
6
|
"description": "Initialize the Webpack Plugin.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
9
|
+
"uiFramework": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "UI Framework to use for Webpack.",
|
|
12
|
+
"enum": ["react", "none"],
|
|
13
|
+
"x-prompt": "What UI framework plugin should Webpack use?"
|
|
13
14
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"compiler": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"enum": ["babel", "swc", "tsc"],
|
|
18
|
+
"description": "The compiler to initialize for.",
|
|
19
|
+
"default": "babel"
|
|
18
20
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"x-priority": "internal",
|
|
22
|
-
"description": "Keep existing dependencies versions",
|
|
23
|
-
"default": false
|
|
24
|
-
},
|
|
25
|
-
"updatePackageScripts": {
|
|
21
|
+
"skipFormat": {
|
|
22
|
+
"description": "Skip formatting files.",
|
|
26
23
|
"type": "boolean",
|
|
27
|
-
"x-priority": "internal",
|
|
28
|
-
"description": "Update `package.json` scripts with inferred targets",
|
|
29
24
|
"default": false
|
|
30
25
|
}
|
|
31
26
|
},
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { type Compiler, type WebpackPluginInstance } from 'webpack';
|
|
2
|
-
import {
|
|
2
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
3
3
|
export declare class GeneratePackageJsonPlugin implements WebpackPluginInstance {
|
|
4
4
|
private readonly options;
|
|
5
|
+
private readonly context;
|
|
6
|
+
private readonly projectGraph;
|
|
5
7
|
constructor(options: {
|
|
6
8
|
tsConfig: string;
|
|
7
9
|
outputFileName: string;
|
|
8
|
-
|
|
9
|
-
projectName: string;
|
|
10
|
-
targetName: string;
|
|
11
|
-
projectGraph: ProjectGraph;
|
|
12
|
-
});
|
|
10
|
+
}, context: ExecutorContext);
|
|
13
11
|
apply(compiler: Compiler): void;
|
|
14
12
|
}
|
|
@@ -4,10 +4,13 @@ exports.GeneratePackageJsonPlugin = void 0;
|
|
|
4
4
|
const webpack_1 = require("webpack");
|
|
5
5
|
const js_1 = require("@nx/js");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const js_2 = require("@nx/js");
|
|
7
8
|
const pluginName = 'GeneratePackageJsonPlugin';
|
|
8
9
|
class GeneratePackageJsonPlugin {
|
|
9
|
-
constructor(options) {
|
|
10
|
+
constructor(options, context) {
|
|
10
11
|
this.options = options;
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.projectGraph = context.projectGraph;
|
|
11
14
|
}
|
|
12
15
|
apply(compiler) {
|
|
13
16
|
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
@@ -15,28 +18,28 @@ class GeneratePackageJsonPlugin {
|
|
|
15
18
|
name: pluginName,
|
|
16
19
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
|
17
20
|
}, () => {
|
|
18
|
-
const helperDependencies = (0,
|
|
19
|
-
const importHelpers = !!(0,
|
|
21
|
+
const helperDependencies = (0, js_2.getHelperDependenciesFromProjectGraph)(this.context.root, this.context.projectName, this.projectGraph);
|
|
22
|
+
const importHelpers = !!(0, js_2.readTsConfig)(this.options.tsConfig).options
|
|
20
23
|
.importHelpers;
|
|
21
24
|
const shouldAddHelperDependency = importHelpers &&
|
|
22
|
-
helperDependencies.every((dep) => dep.target !==
|
|
25
|
+
helperDependencies.every((dep) => dep.target !== js_2.HelperDependency.tsc);
|
|
23
26
|
if (shouldAddHelperDependency) {
|
|
24
27
|
helperDependencies.push({
|
|
25
28
|
type: 'static',
|
|
26
|
-
source: this.
|
|
27
|
-
target:
|
|
29
|
+
source: this.context.projectName,
|
|
30
|
+
target: js_2.HelperDependency.tsc,
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
|
-
const packageJson = (0, js_1.createPackageJson)(this.
|
|
31
|
-
target: this.
|
|
32
|
-
root: this.
|
|
33
|
+
const packageJson = (0, js_1.createPackageJson)(this.context.projectName, this.projectGraph, {
|
|
34
|
+
target: this.context.targetName,
|
|
35
|
+
root: this.context.root,
|
|
33
36
|
isProduction: true,
|
|
34
37
|
helperDependencies: helperDependencies.map((dep) => dep.target),
|
|
35
38
|
});
|
|
36
39
|
packageJson.main = packageJson.main ?? this.options.outputFileName;
|
|
37
40
|
compilation.emitAsset('package.json', new webpack_1.sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
|
|
38
|
-
const packageManager = (0, devkit_1.detectPackageManager)(this.
|
|
39
|
-
compilation.emitAsset((0,
|
|
41
|
+
const packageManager = (0, devkit_1.detectPackageManager)(this.context.root);
|
|
42
|
+
compilation.emitAsset((0, js_2.getLockFileName)(packageManager), new webpack_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.projectGraph, packageManager)));
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
}
|
package/src/utils/config.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { Configuration } from 'webpack';
|
|
3
3
|
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
4
|
+
/** @deprecated use withNx and withWeb plugins directly */
|
|
5
|
+
export declare function getBaseWebpackPartial(options: NormalizedWebpackExecutorOptions, context?: ExecutorContext): Configuration;
|
|
6
6
|
export interface NxWebpackExecutionContext {
|
|
7
7
|
options: NormalizedWebpackExecutorOptions;
|
|
8
8
|
context: ExecutorContext;
|
|
9
|
-
configuration?: string;
|
|
10
9
|
}
|
|
11
|
-
export interface
|
|
10
|
+
export interface NxWebpackPlugin {
|
|
12
11
|
(config: Configuration, ctx: NxWebpackExecutionContext): Configuration;
|
|
13
12
|
}
|
|
14
|
-
export interface
|
|
13
|
+
export interface AsyncNxWebpackPlugin {
|
|
15
14
|
(config: Configuration, ctx: NxWebpackExecutionContext): Configuration | Promise<Configuration>;
|
|
16
15
|
}
|
|
17
|
-
export declare function composePlugins(...plugins: (
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
export declare function composePluginsSync(...plugins: NxComposableWebpackPlugin[]): ((config: Configuration, ctx: NxWebpackExecutionContext) => Configuration) & {
|
|
21
|
-
nxWebpackComposablePlugin: boolean;
|
|
22
|
-
};
|
|
16
|
+
export declare function composePlugins(...plugins: (NxWebpackPlugin | AsyncNxWebpackPlugin | Promise<NxWebpackPlugin | AsyncNxWebpackPlugin>)[]): (config: Configuration, ctx: NxWebpackExecutionContext) => Promise<Configuration>;
|
|
17
|
+
export declare function composePluginsSync(...plugins: NxWebpackPlugin[]): (config: Configuration, ctx: NxWebpackExecutionContext) => Configuration;
|
package/src/utils/config.js
CHANGED
|
@@ -1,66 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.composePluginsSync = exports.composePlugins = exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
exports.composePluginsSync = exports.composePlugins = exports.getBaseWebpackPartial = void 0;
|
|
4
|
+
const with_nx_1 = require("./with-nx");
|
|
5
|
+
const with_web_1 = require("./with-web");
|
|
6
|
+
/** @deprecated use withNx and withWeb plugins directly */
|
|
7
|
+
function getBaseWebpackPartial(options, context) {
|
|
8
|
+
const config = {};
|
|
9
|
+
const configure = composePluginsSync((0, with_nx_1.withNx)(), (0, with_web_1.withWeb)());
|
|
10
|
+
return configure(config, { options, context });
|
|
8
11
|
}
|
|
9
|
-
exports.
|
|
12
|
+
exports.getBaseWebpackPartial = getBaseWebpackPartial;
|
|
10
13
|
function composePlugins(...plugins) {
|
|
11
|
-
return
|
|
12
|
-
// Webpack may be calling us as a standard config function.
|
|
13
|
-
// Build up Nx context from environment variables.
|
|
14
|
-
// This is to enable `@nx/webpack/plugin` to work with existing projects.
|
|
15
|
-
if (ctx['env']) {
|
|
16
|
-
ensureNxWebpackExecutionContext(ctx);
|
|
17
|
-
// Build this from scratch since what webpack passes us is the env, not config,
|
|
18
|
-
// and `withNX()` creates a new config object anyway.
|
|
19
|
-
config = {};
|
|
20
|
-
}
|
|
14
|
+
return async function combined(config, ctx) {
|
|
21
15
|
for (const plugin of plugins) {
|
|
22
16
|
const fn = await plugin;
|
|
23
17
|
config = await fn(config, ctx);
|
|
24
18
|
}
|
|
25
19
|
return config;
|
|
26
|
-
}
|
|
27
|
-
[exports.nxWebpackComposablePlugin]: true,
|
|
28
|
-
});
|
|
20
|
+
};
|
|
29
21
|
}
|
|
30
22
|
exports.composePlugins = composePlugins;
|
|
31
23
|
function composePluginsSync(...plugins) {
|
|
32
|
-
return
|
|
24
|
+
return function combined(config, ctx) {
|
|
33
25
|
for (const plugin of plugins) {
|
|
34
26
|
config = plugin(config, ctx);
|
|
35
27
|
}
|
|
36
28
|
return config;
|
|
37
|
-
}, {
|
|
38
|
-
[exports.nxWebpackComposablePlugin]: true,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
exports.composePluginsSync = composePluginsSync;
|
|
42
|
-
function ensureNxWebpackExecutionContext(ctx) {
|
|
43
|
-
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
44
|
-
const targetName = process.env.NX_TASK_TARGET_TARGET;
|
|
45
|
-
const configurationName = process.env.NX_TASK_TARGET_CONFIGURATION;
|
|
46
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
47
|
-
const projectNode = projectGraph.nodes[projectName];
|
|
48
|
-
ctx.options ??= {
|
|
49
|
-
root: devkit_1.workspaceRoot,
|
|
50
|
-
projectRoot: projectNode.data.root,
|
|
51
|
-
sourceRoot: projectNode.data.sourceRoot ?? projectNode.data.root,
|
|
52
|
-
// These aren't actually needed since NxWebpackPlugin and withNx both support them being undefined.
|
|
53
|
-
assets: undefined,
|
|
54
|
-
outputPath: undefined,
|
|
55
|
-
tsConfig: undefined,
|
|
56
|
-
outputFileName: undefined,
|
|
57
|
-
};
|
|
58
|
-
ctx.context ??= {
|
|
59
|
-
projectName,
|
|
60
|
-
targetName,
|
|
61
|
-
configurationName,
|
|
62
|
-
cwd: process.cwd(),
|
|
63
|
-
root: devkit_1.workspaceRoot,
|
|
64
|
-
isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
|
|
65
29
|
};
|
|
66
30
|
}
|
|
31
|
+
exports.composePluginsSync = composePluginsSync;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getClientEnvironment = void 0;
|
|
4
|
-
// Prevent sensitive keys from being bundled when source code uses entire `process.env` object rather than individual keys (e.g. `process.env.NX_FOO`).
|
|
5
|
-
// TODO(v19): Only env vars prefixed with NX_PUBLIC should be bundled. This is a breaking change so we won't do it in v18.
|
|
6
|
-
const excludedKeys = ['NX_CLOUD_ACCESS_TOKEN', 'NX_CLOUD_ENCRYPTION_KEY'];
|
|
7
4
|
function getClientEnvironment(mode) {
|
|
8
5
|
// Grab NODE_ENV and NX_* environment variables and prepare them to be
|
|
9
6
|
// injected into the application via DefinePlugin in webpack configuration.
|
|
10
7
|
const NX_APP = /^NX_/i;
|
|
11
8
|
const raw = Object.keys(process.env)
|
|
12
|
-
.filter((key) =>
|
|
9
|
+
.filter((key) => NX_APP.test(key))
|
|
13
10
|
.reduce((env, key) => {
|
|
14
11
|
env[key] = process.env[key];
|
|
15
12
|
return env;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDependentPackagesForProject = void 0;
|
|
4
4
|
const typescript_1 = require("./typescript");
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
function getDependentPackagesForProject(projectGraph, name) {
|
|
7
6
|
const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
|
|
8
7
|
return {
|
|
@@ -35,22 +34,11 @@ function collectDependencies(projectGraph, name, dependencies = {
|
|
|
35
34
|
return dependencies;
|
|
36
35
|
}
|
|
37
36
|
function getLibraryImportPath(library, projectGraph) {
|
|
38
|
-
let buildLibsFromSource = true;
|
|
39
|
-
if (process.env.NX_BUILD_LIBS_FROM_SOURCE) {
|
|
40
|
-
buildLibsFromSource = process.env.NX_BUILD_LIBS_FROM_SOURCE === 'true';
|
|
41
|
-
}
|
|
42
|
-
const libraryNode = projectGraph.nodes[library];
|
|
43
|
-
let sourceRoots = [libraryNode.data.sourceRoot];
|
|
44
|
-
if (!buildLibsFromSource && process.env.NX_BUILD_TARGET) {
|
|
45
|
-
const buildTarget = (0, devkit_1.parseTargetString)(process.env.NX_BUILD_TARGET, projectGraph);
|
|
46
|
-
sourceRoots = (0, devkit_1.getOutputsForTargetAndConfiguration)(buildTarget, {}, libraryNode);
|
|
47
|
-
}
|
|
48
37
|
const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
|
|
38
|
+
const sourceRoot = projectGraph.nodes[library].data.sourceRoot;
|
|
49
39
|
for (const [key, value] of Object.entries(tsConfigPathMappings)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return key;
|
|
53
|
-
}
|
|
40
|
+
if (value.find((path) => path.startsWith(sourceRoot))) {
|
|
41
|
+
return key;
|
|
54
42
|
}
|
|
55
43
|
}
|
|
56
44
|
return undefined;
|
|
@@ -7,8 +7,7 @@ interface ModuleFederationExecutorContext {
|
|
|
7
7
|
}
|
|
8
8
|
export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
|
|
9
9
|
staticRemotes: string[];
|
|
10
|
-
devRemotes:
|
|
11
|
-
dynamicRemotes: any[];
|
|
10
|
+
devRemotes: string[];
|
|
12
11
|
remotePorts: any[];
|
|
13
12
|
};
|
|
14
13
|
export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
|
|
@@ -9,7 +9,6 @@ const path_1 = require("path");
|
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
|
|
11
11
|
const remotes = [];
|
|
12
|
-
const dynamicRemotes = [];
|
|
13
12
|
if (pathToManifestFile && (0, fs_1.existsSync)(pathToManifestFile)) {
|
|
14
13
|
const moduleFederationManifestJson = (0, fs_1.readFileSync)(pathToManifestFile, 'utf-8');
|
|
15
14
|
if (moduleFederationManifestJson) {
|
|
@@ -19,13 +18,13 @@ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
|
|
|
19
18
|
// }
|
|
20
19
|
const parsedManifest = JSON.parse(moduleFederationManifestJson);
|
|
21
20
|
if (Object.keys(parsedManifest).every((key) => typeof key === 'string' && typeof parsedManifest[key] === 'string')) {
|
|
22
|
-
|
|
21
|
+
remotes.push(...Object.keys(parsedManifest));
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
const staticRemotes = config.remotes?.map((r) => (Array.isArray(r) ? r[0] : r)) ?? [];
|
|
27
26
|
remotes.push(...staticRemotes);
|
|
28
|
-
return
|
|
27
|
+
return remotes;
|
|
29
28
|
}
|
|
30
29
|
function collectRemoteProjects(remote, collected, context) {
|
|
31
30
|
const remoteProject = context.projectGraph.nodes[remote]?.data;
|
|
@@ -36,33 +35,30 @@ function collectRemoteProjects(remote, collected, context) {
|
|
|
36
35
|
const remoteProjectRoot = remoteProject.root;
|
|
37
36
|
const remoteProjectTsConfig = remoteProject.targets['build'].options.tsConfig;
|
|
38
37
|
const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
|
|
39
|
-
const
|
|
38
|
+
const remoteProjectRemotes = extractRemoteProjectsFromConfig(remoteProjectConfig);
|
|
40
39
|
remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
|
|
41
40
|
}
|
|
42
41
|
function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile) {
|
|
43
42
|
const collectedRemotes = new Set();
|
|
44
|
-
const
|
|
43
|
+
const remotes = extractRemoteProjectsFromConfig(config, pathToManifestFile);
|
|
45
44
|
remotes.forEach((r) => collectRemoteProjects(r, collectedRemotes, context));
|
|
46
45
|
const remotesToSkip = new Set((0, find_matching_projects_1.findMatchingProjects)(skipRemotes, context.projectGraph.nodes) ?? []);
|
|
47
46
|
if (remotesToSkip.size > 0) {
|
|
48
47
|
devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
|
|
49
48
|
}
|
|
50
49
|
const knownRemotes = Array.from(collectedRemotes).filter((r) => !remotesToSkip.has(r));
|
|
51
|
-
|
|
52
|
-
devkit_1.logger.info(`NX Starting module federation dev-server for ${chalk.bold(context.projectName)} with ${[...knownRemotes, ...knownDynamicRemotes].length} remotes`);
|
|
50
|
+
devkit_1.logger.info(`NX Starting module federation dev-server for ${chalk.bold(context.projectName)} with ${knownRemotes.length} remotes`);
|
|
53
51
|
const devServeApps = new Set(!devRemotes
|
|
54
52
|
? []
|
|
55
53
|
: Array.isArray(devRemotes)
|
|
56
54
|
? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
|
|
57
55
|
: (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
|
|
58
56
|
const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
|
|
59
|
-
const devServeRemotes =
|
|
60
|
-
const
|
|
61
|
-
const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
|
|
57
|
+
const devServeRemotes = knownRemotes.filter((r) => devServeApps.has(r));
|
|
58
|
+
const remotePorts = knownRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
|
|
62
59
|
return {
|
|
63
60
|
staticRemotes,
|
|
64
61
|
devRemotes: devServeRemotes,
|
|
65
|
-
dynamicRemotes: staticDynamicRemotes,
|
|
66
62
|
remotePorts,
|
|
67
63
|
};
|
|
68
64
|
}
|
|
@@ -39,7 +39,7 @@ function handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal) {
|
|
|
39
39
|
: '';
|
|
40
40
|
// if the remote is defined with anything other than http then we assume it's a promise based remote
|
|
41
41
|
// In that case we should use what the user provides as the remote location
|
|
42
|
-
if (
|
|
42
|
+
if (remoteLocation.startsWith('http')) {
|
|
43
43
|
return `${globalPrefix}${baseRemote}/remoteEntry.${remoteEntryExt}`;
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
@@ -6,7 +6,7 @@ const fs_1 = require("fs");
|
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const nx_1 = require("@nx/devkit/nx");
|
|
8
8
|
let { readModulePackageJson } = (0, nx_1.requireNx)();
|
|
9
|
-
// TODO: Remove this in Nx
|
|
9
|
+
// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
|
|
10
10
|
readModulePackageJson =
|
|
11
11
|
readModulePackageJson ??
|
|
12
12
|
require('nx/src/utils/package-json').readModulePackageJson;
|
|
@@ -4,23 +4,18 @@ exports.getRootTsConfigPath = exports.readTsConfig = exports.readTsPathMappings
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
let tsConfig
|
|
8
|
-
let tsPathMappings
|
|
7
|
+
let tsConfig;
|
|
8
|
+
let tsPathMappings;
|
|
9
9
|
function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
|
|
10
|
-
if (tsPathMappings
|
|
11
|
-
return tsPathMappings
|
|
10
|
+
if (tsPathMappings) {
|
|
11
|
+
return tsPathMappings;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {}).forEach(([alias, paths]) => {
|
|
18
|
-
tsPathMappings.set(tsConfigPath, {
|
|
19
|
-
...tsPathMappings.get(tsConfigPath),
|
|
20
|
-
[alias]: paths.map((path) => path.replace(/^\.\//, '')),
|
|
21
|
-
});
|
|
13
|
+
tsConfig ??= readTsConfiguration(tsConfigPath);
|
|
14
|
+
tsPathMappings = {};
|
|
15
|
+
Object.entries(tsConfig.options?.paths ?? {}).forEach(([alias, paths]) => {
|
|
16
|
+
tsPathMappings[alias] = paths.map((path) => path.replace(/^\.\//, ''));
|
|
22
17
|
});
|
|
23
|
-
return tsPathMappings
|
|
18
|
+
return tsPathMappings;
|
|
24
19
|
}
|
|
25
20
|
exports.readTsPathMappings = readTsPathMappings;
|
|
26
21
|
function readTsConfiguration(tsConfigPath) {
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const swcLoaderVersion = "0.1.15";
|
|
3
3
|
export declare const tsLibVersion = "^2.3.0";
|
|
4
|
-
export declare const webpackCliVersion = "^5.1.4";
|
|
5
4
|
export declare const reactRefreshWebpackPluginVersion = "^0.5.7";
|
|
6
5
|
export declare const svgrWebpackVersion = "^8.0.1";
|
|
7
6
|
export declare const reactRefreshVersion = "^0.10.0";
|
|
7
|
+
export declare const urlLoaderVersion = "^4.1.1";
|
package/src/utils/versions.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.urlLoaderVersion = exports.reactRefreshVersion = exports.svgrWebpackVersion = exports.reactRefreshWebpackPluginVersion = exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.swcLoaderVersion = '0.1.15';
|
|
6
6
|
exports.tsLibVersion = '^2.3.0';
|
|
7
|
-
exports.webpackCliVersion = '^5.1.4';
|
|
8
7
|
// React apps
|
|
9
8
|
exports.reactRefreshWebpackPluginVersion = '^0.5.7';
|
|
10
9
|
exports.svgrWebpackVersion = '^8.0.1';
|
|
11
10
|
exports.reactRefreshVersion = '^0.10.0';
|
|
11
|
+
exports.urlLoaderVersion = '^4.1.1';
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isRegistered = exports.resolveCustomWebpackConfig = void 0;
|
|
4
4
|
const internal_1 = require("@nx/js/src/internal");
|
|
5
|
-
function
|
|
6
|
-
/** Skip require cache and return latest content */
|
|
7
|
-
reload = false) {
|
|
8
|
-
if (reload) {
|
|
9
|
-
// Clear cache if the path is in the cache
|
|
10
|
-
if (require.cache[path]) {
|
|
11
|
-
// Clear all entries because config may import other modules
|
|
12
|
-
for (const k of Object.keys(require.cache)) {
|
|
13
|
-
delete require.cache[k];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
5
|
+
function resolveCustomWebpackConfig(path, tsConfig) {
|
|
17
6
|
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
|
|
18
7
|
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
|
|
19
8
|
if (!/\.(ts|mts|cts)$/.test(path)) {
|
|
@@ -36,4 +25,9 @@ reload = false) {
|
|
|
36
25
|
: maybeCustomWebpackConfig;
|
|
37
26
|
return customWebpackConfig;
|
|
38
27
|
}
|
|
39
|
-
exports.
|
|
28
|
+
exports.resolveCustomWebpackConfig = resolveCustomWebpackConfig;
|
|
29
|
+
function isRegistered() {
|
|
30
|
+
return (require.extensions['.ts'] != undefined ||
|
|
31
|
+
require.extensions['.tsx'] != undefined);
|
|
32
|
+
}
|
|
33
|
+
exports.isRegistered = isRegistered;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const devkit_1 = require("@nx/devkit");
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
const stylusLoader = require("stylus-loader");
|
|
6
|
-
// TOOD(
|
|
6
|
+
// TOOD(v18): Remove this file and stylus support.
|
|
7
7
|
function default_1(source) {
|
|
8
|
-
devkit_1.logger.warn(`Stylus is support is deprecated and will be removed in Nx
|
|
8
|
+
devkit_1.logger.warn(`Stylus is support is deprecated and will be removed in Nx 18. We recommend that you migrate to Sass by renaming \`.styl\` files to \`.scss\` and ensuring that the content is valid Sass.`);
|
|
9
9
|
return stylusLoader.call(this, source);
|
|
10
10
|
}
|
|
11
11
|
exports.default = default_1;
|
|
@@ -7,11 +7,8 @@ function interpolateEnvironmentVariablesToIndex(contents, deployUrl) {
|
|
|
7
7
|
}
|
|
8
8
|
exports.interpolateEnvironmentVariablesToIndex = interpolateEnvironmentVariablesToIndex;
|
|
9
9
|
const NX_PREFIX = /^NX_/i;
|
|
10
|
-
// Prevent sensitive keys from being bundled when source code uses entire `process.env` object rather than individual keys (e.g. `process.env.NX_FOO`).
|
|
11
|
-
// TODO(v19): Only env vars prefixed with NX_PUBLIC should be bundled. This is a breaking change so we won't do it in v18.
|
|
12
|
-
const excludedKeys = ['NX_CLOUD_ACCESS_TOKEN', 'NX_CLOUD_ENCRYPTION_KEY'];
|
|
13
10
|
function isNxEnvironmentKey(x) {
|
|
14
|
-
return
|
|
11
|
+
return NX_PREFIX.test(x);
|
|
15
12
|
}
|
|
16
13
|
function getClientEnvironment(deployUrl) {
|
|
17
14
|
return Object.keys(process.env)
|
|
@@ -122,7 +122,7 @@ function PostcssCliResources(options) {
|
|
|
122
122
|
const resourceCache = new Map();
|
|
123
123
|
return Promise.all(urlDeclarations.map(async (decl) => {
|
|
124
124
|
const value = decl.value;
|
|
125
|
-
const urlRegex = /url(
|
|
125
|
+
const urlRegex = /url\(\s*(?:"([^"]+)"|'([^']+)'|(.+?))\s*\)/g;
|
|
126
126
|
const segments = [];
|
|
127
127
|
let match;
|
|
128
128
|
let lastIndex = 0;
|
|
@@ -131,7 +131,7 @@ function PostcssCliResources(options) {
|
|
|
131
131
|
const inputFile = decl.source && decl.source.input.file;
|
|
132
132
|
const context = (inputFile && path.dirname(inputFile)) || loader.context;
|
|
133
133
|
while ((match = urlRegex.exec(value))) {
|
|
134
|
-
const originalUrl = match[2];
|
|
134
|
+
const originalUrl = match[1] || match[2] || match[3];
|
|
135
135
|
let processedUrl;
|
|
136
136
|
try {
|
|
137
137
|
processedUrl = await process(originalUrl, context, resourceCache);
|
package/src/utils/with-nx.d.ts
CHANGED
|
@@ -1,8 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
1
|
+
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
|
2
|
+
import { NxWebpackPlugin } from './config';
|
|
3
|
+
export interface WithNxOptions {
|
|
4
|
+
skipTypeChecking?: boolean;
|
|
5
|
+
}
|
|
4
6
|
/**
|
|
5
7
|
* @param {WithNxOptions} pluginOptions
|
|
6
8
|
* @returns {NxWebpackPlugin}
|
|
7
9
|
*/
|
|
8
|
-
export declare function withNx(pluginOptions?: WithNxOptions):
|
|
10
|
+
export declare function withNx(pluginOptions?: WithNxOptions): NxWebpackPlugin;
|
|
11
|
+
export declare function createLoaderFromCompiler(options: NormalizedWebpackExecutorOptions): {
|
|
12
|
+
test: RegExp;
|
|
13
|
+
loader: string;
|
|
14
|
+
exclude: RegExp;
|
|
15
|
+
options: {
|
|
16
|
+
cwd: string;
|
|
17
|
+
emitDecoratorMetadata: boolean;
|
|
18
|
+
isModern: boolean;
|
|
19
|
+
isTest: boolean;
|
|
20
|
+
envName: string;
|
|
21
|
+
cacheDirectory: boolean;
|
|
22
|
+
cacheCompression: boolean;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
test: RegExp;
|
|
26
|
+
loader: string;
|
|
27
|
+
exclude: RegExp;
|
|
28
|
+
options: {
|
|
29
|
+
jsc: {
|
|
30
|
+
parser: {
|
|
31
|
+
syntax: string;
|
|
32
|
+
decorators: boolean;
|
|
33
|
+
tsx: boolean;
|
|
34
|
+
};
|
|
35
|
+
transform: {
|
|
36
|
+
react: {
|
|
37
|
+
runtime: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
loose: boolean;
|
|
41
|
+
};
|
|
42
|
+
configFile?: undefined;
|
|
43
|
+
transpileOnly?: undefined;
|
|
44
|
+
experimentalWatchApi?: undefined;
|
|
45
|
+
getCustomTransformers?: undefined;
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
48
|
+
test: RegExp;
|
|
49
|
+
loader: string;
|
|
50
|
+
exclude: RegExp;
|
|
51
|
+
options: {
|
|
52
|
+
configFile: string;
|
|
53
|
+
transpileOnly: boolean;
|
|
54
|
+
experimentalWatchApi: boolean;
|
|
55
|
+
getCustomTransformers: (program: any) => {
|
|
56
|
+
before: any;
|
|
57
|
+
after: any;
|
|
58
|
+
afterDeclarations: any;
|
|
59
|
+
};
|
|
60
|
+
jsc?: undefined;
|
|
61
|
+
};
|
|
62
|
+
};
|