@nx/webpack 19.3.0 → 19.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generators.json +1 -1
- package/package.json +4 -4
- package/plugin.d.ts +1 -1
- package/plugin.js +2 -1
- package/src/plugins/plugin.d.ts +5 -1
- package/src/plugins/plugin.js +62 -41
package/generators.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"init": {
|
|
6
6
|
"factory": "./src/generators/init/init#webpackInitGeneratorInternal",
|
|
7
7
|
"schema": "./src/generators/init/schema.json",
|
|
8
|
-
"description": "Initialize the `@
|
|
8
|
+
"description": "Initialize the `@nx/webpack` plugin.",
|
|
9
9
|
"aliases": ["ng-add"],
|
|
10
10
|
"hidden": true
|
|
11
11
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/webpack",
|
|
3
|
-
"version": "19.3.
|
|
3
|
+
"version": "19.3.1",
|
|
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": {
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"webpack-dev-server": "^4.9.3",
|
|
65
65
|
"webpack-node-externals": "^3.0.0",
|
|
66
66
|
"webpack-subresource-integrity": "^5.1.0",
|
|
67
|
-
"@nx/devkit": "19.3.
|
|
68
|
-
"@nx/js": "19.3.
|
|
69
|
-
"@nrwl/webpack": "19.3.
|
|
67
|
+
"@nx/devkit": "19.3.1",
|
|
68
|
+
"@nx/js": "19.3.1",
|
|
69
|
+
"@nrwl/webpack": "19.3.1"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
package/plugin.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createNodes } from './src/plugins/plugin';
|
|
1
|
+
export { createNodes, createNodesV2, type WebpackPluginOptions, } from './src/plugins/plugin';
|
package/plugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = void 0;
|
|
3
|
+
exports.createNodesV2 = exports.createNodes = void 0;
|
|
4
4
|
var plugin_1 = require("./src/plugins/plugin");
|
|
5
5
|
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
6
|
+
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { CreateDependencies, CreateNodes } from '@nx/devkit';
|
|
1
|
+
import { CreateDependencies, CreateNodes, CreateNodesV2 } from '@nx/devkit';
|
|
2
2
|
export interface WebpackPluginOptions {
|
|
3
3
|
buildTargetName?: string;
|
|
4
4
|
serveTargetName?: string;
|
|
5
5
|
serveStaticTargetName?: string;
|
|
6
6
|
previewTargetName?: string;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
10
|
+
*/
|
|
8
11
|
export declare const createDependencies: CreateDependencies;
|
|
12
|
+
export declare const createNodesV2: CreateNodesV2<WebpackPluginOptions>;
|
|
9
13
|
export declare const createNodes: CreateNodes<WebpackPluginOptions>;
|
package/src/plugins/plugin.js
CHANGED
|
@@ -1,61 +1,74 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
|
3
|
+
exports.createNodes = exports.createNodesV2 = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
6
6
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
|
+
const js_1 = require("@nx/js");
|
|
7
8
|
const fs_1 = require("fs");
|
|
9
|
+
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
10
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
11
|
+
const path_1 = require("path");
|
|
8
12
|
const read_webpack_options_1 = require("../utils/webpack/read-webpack-options");
|
|
9
13
|
const resolve_user_defined_webpack_config_1 = require("../utils/webpack/resolve-user-defined-webpack-config");
|
|
10
|
-
|
|
11
|
-
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
12
|
-
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
13
|
-
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'webpack.hash');
|
|
14
|
-
const targetsCache = readTargetsCache();
|
|
15
|
-
function readTargetsCache() {
|
|
14
|
+
function readTargetsCache(cachePath) {
|
|
16
15
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
17
16
|
}
|
|
18
|
-
function writeTargetsToCache() {
|
|
19
|
-
|
|
20
|
-
(0, devkit_1.writeJsonFile)(cachePath, {
|
|
21
|
-
...oldCache,
|
|
22
|
-
...targetsCache,
|
|
23
|
-
});
|
|
17
|
+
function writeTargetsToCache(cachePath, results) {
|
|
18
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
24
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
22
|
+
*/
|
|
25
23
|
const createDependencies = () => {
|
|
26
|
-
writeTargetsToCache();
|
|
27
24
|
return [];
|
|
28
25
|
};
|
|
29
26
|
exports.createDependencies = createDependencies;
|
|
27
|
+
const webpackConfigGlob = '**/webpack.config.{js,ts,mjs,cjs}';
|
|
28
|
+
exports.createNodesV2 = [
|
|
29
|
+
webpackConfigGlob,
|
|
30
|
+
async (configFilePaths, options, context) => {
|
|
31
|
+
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
|
32
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `webpack-${optionsHash}.hash`);
|
|
33
|
+
const targetsCache = readTargetsCache(cachePath);
|
|
34
|
+
const normalizedOptions = normalizeOptions(options);
|
|
35
|
+
try {
|
|
36
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, normalizedOptions, context);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
writeTargetsToCache(cachePath, targetsCache);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
];
|
|
30
43
|
exports.createNodes = [
|
|
31
|
-
|
|
44
|
+
webpackConfigGlob,
|
|
32
45
|
async (configFilePath, options, context) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
options.serveStaticTargetName ??= 'serve-static';
|
|
37
|
-
options.previewTargetName ??= 'preview';
|
|
38
|
-
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
39
|
-
// Do not create a project if package.json and project.json isn't there.
|
|
40
|
-
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
41
|
-
if (!siblingFiles.includes('package.json') &&
|
|
42
|
-
!siblingFiles.includes('project.json')) {
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
|
46
|
-
const targets = targetsCache[hash]
|
|
47
|
-
? targetsCache[hash]
|
|
48
|
-
: await createWebpackTargets(configFilePath, projectRoot, options, context);
|
|
49
|
-
return {
|
|
50
|
-
projects: {
|
|
51
|
-
[projectRoot]: {
|
|
52
|
-
projectType: 'application',
|
|
53
|
-
targets,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
};
|
|
46
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
|
47
|
+
const normalizedOptions = normalizeOptions(options);
|
|
48
|
+
return createNodesInternal(configFilePath, normalizedOptions, context, {});
|
|
57
49
|
},
|
|
58
50
|
];
|
|
51
|
+
async function createNodesInternal(configFilePath, options, context, targetsCache) {
|
|
52
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
53
|
+
// Do not create a project if package.json and project.json isn't there.
|
|
54
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
55
|
+
if (!siblingFiles.includes('package.json') &&
|
|
56
|
+
!siblingFiles.includes('project.json')) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
|
60
|
+
targetsCache[hash] ??= await createWebpackTargets(configFilePath, projectRoot, options, context);
|
|
61
|
+
const { targets, metadata } = targetsCache[hash];
|
|
62
|
+
return {
|
|
63
|
+
projects: {
|
|
64
|
+
[projectRoot]: {
|
|
65
|
+
projectType: 'application',
|
|
66
|
+
targets,
|
|
67
|
+
metadata,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
59
72
|
async function createWebpackTargets(configFilePath, projectRoot, options, context) {
|
|
60
73
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
61
74
|
const webpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
|
|
@@ -105,7 +118,7 @@ async function createWebpackTargets(configFilePath, projectRoot, options, contex
|
|
|
105
118
|
spa: true,
|
|
106
119
|
},
|
|
107
120
|
};
|
|
108
|
-
return targets;
|
|
121
|
+
return { targets, metadata: {} };
|
|
109
122
|
}
|
|
110
123
|
function normalizeOutputPath(outputPath, projectRoot) {
|
|
111
124
|
if (!outputPath) {
|
|
@@ -135,3 +148,11 @@ function normalizeOutputPath(outputPath, projectRoot) {
|
|
|
135
148
|
}
|
|
136
149
|
}
|
|
137
150
|
}
|
|
151
|
+
function normalizeOptions(options) {
|
|
152
|
+
return {
|
|
153
|
+
buildTargetName: options.buildTargetName ?? 'build',
|
|
154
|
+
serveTargetName: options.serveTargetName ?? 'serve',
|
|
155
|
+
serveStaticTargetName: options.serveStaticTargetName ?? 'serve-static',
|
|
156
|
+
previewTargetName: options.previewTargetName ?? 'preview',
|
|
157
|
+
};
|
|
158
|
+
}
|