@nx/rspack 0.0.0-pr-28218-5048fd1
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 +22 -0
- package/README.md +117 -0
- package/executors.json +35 -0
- package/generators.json +31 -0
- package/migrations.json +98 -0
- package/module-federation.d.ts +1 -0
- package/module-federation.js +4 -0
- package/package.json +49 -0
- package/plugin.d.ts +2 -0
- package/plugin.js +6 -0
- package/src/executors/dev-server/dev-server.impl.d.ts +6 -0
- package/src/executors/dev-server/dev-server.impl.js +50 -0
- package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
- package/src/executors/dev-server/lib/get-dev-server-config.js +69 -0
- package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
- package/src/executors/dev-server/lib/serve-path.js +44 -0
- package/src/executors/dev-server/schema.d.ts +12 -0
- package/src/executors/dev-server/schema.json +45 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +6 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +177 -0
- package/src/executors/module-federation-dev-server/schema.d.ts +18 -0
- package/src/executors/module-federation-dev-server/schema.json +98 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +21 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +214 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +79 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +12 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +244 -0
- package/src/executors/module-federation-static-server/schema.d.ts +3 -0
- package/src/executors/module-federation-static-server/schema.json +14 -0
- package/src/executors/rspack/rspack.impl.d.ts +6 -0
- package/src/executors/rspack/rspack.impl.js +118 -0
- package/src/executors/rspack/schema.d.ts +34 -0
- package/src/executors/rspack/schema.json +177 -0
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
- package/src/executors/ssr-dev-server/schema.d.ts +11 -0
- package/src/executors/ssr-dev-server/schema.json +36 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +38 -0
- package/src/generators/application/application.d.ts +3 -0
- package/src/generators/application/application.js +90 -0
- package/src/generators/application/lib/create-ts-config.d.ts +3 -0
- package/src/generators/application/lib/create-ts-config.js +49 -0
- package/src/generators/application/lib/normalize-options.d.ts +5 -0
- package/src/generators/application/lib/normalize-options.js +42 -0
- package/src/generators/application/schema.d.ts +16 -0
- package/src/generators/application/schema.json +98 -0
- package/src/generators/configuration/configuration.d.ts +4 -0
- package/src/generators/configuration/configuration.js +79 -0
- package/src/generators/configuration/schema.d.ts +12 -0
- package/src/generators/configuration/schema.json +73 -0
- package/src/generators/init/init.d.ts +5 -0
- package/src/generators/init/init.js +71 -0
- package/src/generators/init/schema.d.ts +11 -0
- package/src/generators/init/schema.json +31 -0
- package/src/generators/preset/preset.d.ts +3 -0
- package/src/generators/preset/preset.js +34 -0
- package/src/generators/preset/schema.d.ts +18 -0
- package/src/generators/preset/schema.json +71 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +9 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/plugins/generate-package-json-plugin.d.ts +12 -0
- package/src/plugins/generate-package-json-plugin.js +46 -0
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +149 -0
- package/src/utils/config.d.ts +17 -0
- package/src/utils/config.js +22 -0
- package/src/utils/create-compiler.d.ts +7 -0
- package/src/utils/create-compiler.js +33 -0
- package/src/utils/generator-utils.d.ts +34 -0
- package/src/utils/generator-utils.js +444 -0
- package/src/utils/get-copy-patterns.d.ts +9 -0
- package/src/utils/get-copy-patterns.js +22 -0
- package/src/utils/jest-utils.d.ts +1 -0
- package/src/utils/jest-utils.js +8 -0
- package/src/utils/mode-utils.d.ts +2 -0
- package/src/utils/mode-utils.js +6 -0
- package/src/utils/model.d.ts +6 -0
- package/src/utils/model.js +2 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +4 -0
- package/src/utils/module-federation/build-static.remotes.js +69 -0
- package/src/utils/module-federation/dependencies.d.ts +6 -0
- package/src/utils/module-federation/dependencies.js +56 -0
- package/src/utils/module-federation/get-remotes-for-host.d.ts +16 -0
- package/src/utils/module-federation/get-remotes-for-host.js +99 -0
- package/src/utils/module-federation/index.d.ts +6 -0
- package/src/utils/module-federation/index.js +9 -0
- package/src/utils/module-federation/models/index.d.ts +47 -0
- package/src/utils/module-federation/models/index.js +2 -0
- package/src/utils/module-federation/package-json.d.ts +8 -0
- package/src/utils/module-federation/package-json.js +12 -0
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +13 -0
- package/src/utils/module-federation/parse-static-remotes-config.js +34 -0
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +3 -0
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +54 -0
- package/src/utils/module-federation/public-api.d.ts +8 -0
- package/src/utils/module-federation/public-api.js +20 -0
- package/src/utils/module-federation/remotes.d.ts +19 -0
- package/src/utils/module-federation/remotes.js +77 -0
- package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
- package/src/utils/module-federation/secondary-entry-points.js +104 -0
- package/src/utils/module-federation/share.d.ts +48 -0
- package/src/utils/module-federation/share.js +235 -0
- package/src/utils/module-federation/start-remote-proxies.d.ts +5 -0
- package/src/utils/module-federation/start-remote-proxies.js +45 -0
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +5 -0
- package/src/utils/module-federation/start-ssr-remote-proxies.js +59 -0
- package/src/utils/module-federation/typescript.d.ts +4 -0
- package/src/utils/module-federation/typescript.js +53 -0
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +8 -0
- package/src/utils/module-federation/with-module-federation/package-json.js +12 -0
- package/src/utils/module-federation/with-module-federation/utils.d.ts +12 -0
- package/src/utils/module-federation/with-module-federation/utils.js +76 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +3 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +55 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +8 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +70 -0
- package/src/utils/normalize-assets.d.ts +1 -0
- package/src/utils/normalize-assets.js +42 -0
- package/src/utils/read-rspack-options.d.ts +10 -0
- package/src/utils/read-rspack-options.js +37 -0
- package/src/utils/resolve-user-defined-rspack-config.d.ts +3 -0
- package/src/utils/resolve-user-defined-rspack-config.js +38 -0
- package/src/utils/versions.d.ts +21 -0
- package/src/utils/versions.js +24 -0
- package/src/utils/with-nx.d.ts +3 -0
- package/src/utils/with-nx.js +187 -0
- package/src/utils/with-react.d.ts +3 -0
- package/src/utils/with-react.js +69 -0
- package/src/utils/with-web.d.ts +9 -0
- package/src/utils/with-web.js +106 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "Init",
|
|
4
|
+
"title": "Nx Rspack Init Generator",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"description": "Rspack init generator.",
|
|
7
|
+
"properties": {
|
|
8
|
+
"framework": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The UI framework used by the project.",
|
|
11
|
+
"enum": ["none", "react", "web", "nest"],
|
|
12
|
+
"alias": ["uiFramework"]
|
|
13
|
+
},
|
|
14
|
+
"style": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "The style solution to use.",
|
|
17
|
+
"enum": ["none", "css", "scss", "less", "styl"]
|
|
18
|
+
},
|
|
19
|
+
"rootProject": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"x-priority": "internal"
|
|
22
|
+
},
|
|
23
|
+
"keepExistingVersions": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"x-priority": "internal",
|
|
26
|
+
"description": "Keep existing dependencies versions",
|
|
27
|
+
"default": false
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"required": []
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const application_1 = tslib_1.__importDefault(require("../application/application"));
|
|
7
|
+
async function default_1(tree, options) {
|
|
8
|
+
const appTask = (0, application_1.default)(tree, {
|
|
9
|
+
...options,
|
|
10
|
+
// Since `--style` is not passed down to custom preset, we're using individual flags for now.
|
|
11
|
+
style: options.sass
|
|
12
|
+
? 'scss'
|
|
13
|
+
: options.less
|
|
14
|
+
? 'less'
|
|
15
|
+
: options.stylus
|
|
16
|
+
? 'styl'
|
|
17
|
+
: 'css',
|
|
18
|
+
});
|
|
19
|
+
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
20
|
+
json.scripts ??= {};
|
|
21
|
+
json.scripts.build ??= 'npx nx build';
|
|
22
|
+
json.scripts.start ??= 'npx nx serve';
|
|
23
|
+
json.scripts.lint ??= 'npx nx lint';
|
|
24
|
+
json.scripts.test ??= 'npx nx test';
|
|
25
|
+
json.scripts.e2e ??= 'npx nx e2e e2e';
|
|
26
|
+
return json;
|
|
27
|
+
});
|
|
28
|
+
if (options.rootProject) {
|
|
29
|
+
// Remove these folders so projects will be generated at the root.
|
|
30
|
+
tree.delete('apps');
|
|
31
|
+
tree.delete('libs');
|
|
32
|
+
}
|
|
33
|
+
return appTask;
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface PresetGeneratorSchema {
|
|
2
|
+
name: string;
|
|
3
|
+
framework?: Framework;
|
|
4
|
+
less?: boolean;
|
|
5
|
+
sass?: boolean;
|
|
6
|
+
stylus?: boolean;
|
|
7
|
+
unitTestRunner?: 'none' | 'jest';
|
|
8
|
+
e2eTestRunner?: 'none' | 'cypress';
|
|
9
|
+
directory?: string;
|
|
10
|
+
tags?: string;
|
|
11
|
+
rootProject?: boolean;
|
|
12
|
+
monorepo?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NormalizedSchema extends PresetGeneratorSchema {
|
|
16
|
+
appProjectRoot: string;
|
|
17
|
+
e2eProjectName: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "Preset",
|
|
4
|
+
"title": "Standalone React and rspack preset",
|
|
5
|
+
"description": "React + Rspack preset generator.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-priority": "important"
|
|
16
|
+
},
|
|
17
|
+
"framework": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "The framework to use for the application.",
|
|
20
|
+
"enum": ["none", "react", "web", "nest"],
|
|
21
|
+
"alias": ["uiFramework"],
|
|
22
|
+
"x-priority": "important",
|
|
23
|
+
"default": "react"
|
|
24
|
+
},
|
|
25
|
+
"less": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"description": "Use less for styling."
|
|
28
|
+
},
|
|
29
|
+
"sass": {
|
|
30
|
+
"type": "boolean",
|
|
31
|
+
"description": "Use sass for styling."
|
|
32
|
+
},
|
|
33
|
+
"stylus": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"description": "Use stylus for styling."
|
|
36
|
+
},
|
|
37
|
+
"unitTestRunner": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "The unit test runner to use.",
|
|
40
|
+
"enum": ["none", "jest"],
|
|
41
|
+
"default": "jest"
|
|
42
|
+
},
|
|
43
|
+
"e2eTestRunner": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"description": "The e2e test runner to use.",
|
|
46
|
+
"enum": ["none", "cypress"],
|
|
47
|
+
"default": "cypress"
|
|
48
|
+
},
|
|
49
|
+
"directory": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "The directory to nest the app under."
|
|
52
|
+
},
|
|
53
|
+
"tags": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"description": "Add tags to the project (used for linting).",
|
|
56
|
+
"alias": "t"
|
|
57
|
+
},
|
|
58
|
+
"monorepo": {
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"description": "Creates an integrated monorepo.",
|
|
61
|
+
"default": false,
|
|
62
|
+
"aliases": ["integrated"]
|
|
63
|
+
},
|
|
64
|
+
"rootProject": {
|
|
65
|
+
"type": "boolean",
|
|
66
|
+
"x-priority": "internal",
|
|
67
|
+
"default": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"required": ["name"]
|
|
71
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./generators/configuration/configuration"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./generators/init/init"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./utils/config"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./utils/with-nx"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./utils/with-react"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./utils/with-web"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = replacePackage;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
6
|
+
async function replacePackage(tree) {
|
|
7
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/rspack', '@nx/rspack');
|
|
8
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { type Compiler, type RspackPluginInstance } from '@rspack/core';
|
|
3
|
+
export declare class GeneratePackageJsonPlugin implements RspackPluginInstance {
|
|
4
|
+
private readonly options;
|
|
5
|
+
private readonly context;
|
|
6
|
+
private readonly projectGraph;
|
|
7
|
+
constructor(options: {
|
|
8
|
+
tsConfig: string;
|
|
9
|
+
outputFileName: string;
|
|
10
|
+
}, context: ExecutorContext);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratePackageJsonPlugin = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
7
|
+
const pluginName = 'GeneratePackageJsonPlugin';
|
|
8
|
+
class GeneratePackageJsonPlugin {
|
|
9
|
+
constructor(options, context) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.projectGraph = context.projectGraph;
|
|
13
|
+
}
|
|
14
|
+
apply(compiler) {
|
|
15
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
16
|
+
compilation.hooks.processAssets.tap({
|
|
17
|
+
name: pluginName,
|
|
18
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
|
19
|
+
}, () => {
|
|
20
|
+
const helperDependencies = (0, js_1.getHelperDependenciesFromProjectGraph)(this.context.root, this.context.projectName, this.projectGraph);
|
|
21
|
+
const importHelpers = !!(0, js_1.readTsConfig)(this.options.tsConfig).options
|
|
22
|
+
.importHelpers;
|
|
23
|
+
const shouldAddHelperDependency = importHelpers &&
|
|
24
|
+
helperDependencies.every((dep) => dep.target !== js_1.HelperDependency.tsc);
|
|
25
|
+
if (shouldAddHelperDependency) {
|
|
26
|
+
helperDependencies.push({
|
|
27
|
+
type: 'static',
|
|
28
|
+
source: this.context.projectName,
|
|
29
|
+
target: js_1.HelperDependency.tsc,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const packageJson = (0, js_1.createPackageJson)(this.context.projectName, this.projectGraph, {
|
|
33
|
+
target: this.context.targetName,
|
|
34
|
+
root: this.context.root,
|
|
35
|
+
isProduction: true,
|
|
36
|
+
helperDependencies: helperDependencies.map((dep) => dep.target),
|
|
37
|
+
});
|
|
38
|
+
packageJson.main = packageJson.main ?? this.options.outputFileName;
|
|
39
|
+
compilation.emitAsset('package.json', new webpack_sources_1.RawSource((0, devkit_1.serializeJson)(packageJson)));
|
|
40
|
+
const packageManager = (0, devkit_1.detectPackageManager)(this.context.root);
|
|
41
|
+
compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new webpack_sources_1.RawSource((0, js_1.createLockFile)(packageJson, this.projectGraph, packageManager)));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.GeneratePackageJsonPlugin = GeneratePackageJsonPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateDependencies, CreateNodesV2 } from '@nx/devkit';
|
|
2
|
+
export interface RspackPluginOptions {
|
|
3
|
+
buildTargetName?: string;
|
|
4
|
+
serveTargetName?: string;
|
|
5
|
+
serveStaticTargetName?: string;
|
|
6
|
+
previewTargetName?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const createDependencies: CreateDependencies;
|
|
9
|
+
export declare const createNodesV2: CreateNodesV2<RspackPluginOptions>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodesV2 = exports.createDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
6
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
|
+
const js_1 = require("@nx/js");
|
|
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");
|
|
12
|
+
const read_rspack_options_1 = require("../utils/read-rspack-options");
|
|
13
|
+
const resolve_user_defined_rspack_config_1 = require("../utils/resolve-user-defined-rspack-config");
|
|
14
|
+
function readTargetsCache(cachePath) {
|
|
15
|
+
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
16
|
+
}
|
|
17
|
+
function writeTargetsToCache(cachePath, results) {
|
|
18
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
19
|
+
}
|
|
20
|
+
const createDependencies = () => {
|
|
21
|
+
return [];
|
|
22
|
+
};
|
|
23
|
+
exports.createDependencies = createDependencies;
|
|
24
|
+
const rspackConfigGlob = '**/rspack.config.{js,ts,mjs,mts,cjs,cts}';
|
|
25
|
+
exports.createNodesV2 = [
|
|
26
|
+
rspackConfigGlob,
|
|
27
|
+
async (configFilePaths, options, context) => {
|
|
28
|
+
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
|
29
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rspack-${optionsHash}.hash`);
|
|
30
|
+
const targetsCache = readTargetsCache(cachePath);
|
|
31
|
+
try {
|
|
32
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, options, context);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
writeTargetsToCache(cachePath, targetsCache);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
async function createNodesInternal(configFilePath, options, context, targetsCache) {
|
|
40
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
41
|
+
// Do not create a project if package.json and project.json isn't there.
|
|
42
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
43
|
+
if (!siblingFiles.includes('package.json') &&
|
|
44
|
+
!siblingFiles.includes('project.json')) {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
const normalizedOptions = normalizeOptions(options);
|
|
48
|
+
// We do not want to alter how the hash is calculated, so appending the config file path to the hash
|
|
49
|
+
// to prevent vite/vitest files overwriting the target cache created by the other
|
|
50
|
+
const hash = (await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, normalizedOptions, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))])) + configFilePath;
|
|
51
|
+
targetsCache[hash] ??= await createRspackTargets(configFilePath, projectRoot, normalizedOptions, context);
|
|
52
|
+
const { targets, metadata } = targetsCache[hash];
|
|
53
|
+
return {
|
|
54
|
+
projects: {
|
|
55
|
+
[projectRoot]: {
|
|
56
|
+
root: projectRoot,
|
|
57
|
+
targets,
|
|
58
|
+
metadata,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function createRspackTargets(configFilePath, projectRoot, options, context) {
|
|
64
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
65
|
+
const rspackConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
|
|
66
|
+
const rspackOptions = await (0, read_rspack_options_1.readRspackOptions)(rspackConfig);
|
|
67
|
+
const outputPath = normalizeOutputPath(rspackOptions.output?.path, projectRoot);
|
|
68
|
+
const targets = {};
|
|
69
|
+
targets[options.buildTargetName] = {
|
|
70
|
+
command: `rspack build`,
|
|
71
|
+
options: { cwd: projectRoot, args: ['--node-env=production'] },
|
|
72
|
+
cache: true,
|
|
73
|
+
dependsOn: [`^${options.buildTargetName}`],
|
|
74
|
+
inputs: 'production' in namedInputs
|
|
75
|
+
? [
|
|
76
|
+
'production',
|
|
77
|
+
'^production',
|
|
78
|
+
{
|
|
79
|
+
externalDependencies: ['@rspack/cli'],
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
: [
|
|
83
|
+
'default',
|
|
84
|
+
'^default',
|
|
85
|
+
{
|
|
86
|
+
externalDependencies: ['@rspack/cli'],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
outputs: [outputPath],
|
|
90
|
+
};
|
|
91
|
+
targets[options.serveTargetName] = {
|
|
92
|
+
command: `rspack serve`,
|
|
93
|
+
options: {
|
|
94
|
+
cwd: projectRoot,
|
|
95
|
+
args: ['--node-env=development'],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
targets[options.previewTargetName] = {
|
|
99
|
+
command: `rspack serve`,
|
|
100
|
+
options: {
|
|
101
|
+
cwd: projectRoot,
|
|
102
|
+
args: ['--node-env=production'],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
targets[options.serveStaticTargetName] = {
|
|
106
|
+
executor: '@nx/web:file-server',
|
|
107
|
+
options: {
|
|
108
|
+
buildTarget: options.buildTargetName,
|
|
109
|
+
spa: true,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
return { targets, metadata: {} };
|
|
113
|
+
}
|
|
114
|
+
function normalizeOptions(options) {
|
|
115
|
+
options ??= {};
|
|
116
|
+
options.buildTargetName ??= 'build';
|
|
117
|
+
options.serveTargetName ??= 'serve';
|
|
118
|
+
options.previewTargetName ??= 'preview';
|
|
119
|
+
options.serveStaticTargetName ??= 'serve-static';
|
|
120
|
+
return options;
|
|
121
|
+
}
|
|
122
|
+
function normalizeOutputPath(outputPath, projectRoot) {
|
|
123
|
+
if (!outputPath) {
|
|
124
|
+
// If outputPath is undefined, use rspack's default `dist` directory.
|
|
125
|
+
if (projectRoot === '.') {
|
|
126
|
+
return `{projectRoot}/dist`;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return `{workspaceRoot}/dist/{projectRoot}`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if ((0, path_1.isAbsolute)(outputPath)) {
|
|
134
|
+
/**
|
|
135
|
+
* If outputPath is absolute, we need to resolve it relative to the workspaceRoot first.
|
|
136
|
+
* After that, we can use the relative path to the workspaceRoot token {workspaceRoot} to generate the output path.
|
|
137
|
+
*/
|
|
138
|
+
return `{workspaceRoot}/${(0, path_1.relative)(devkit_1.workspaceRoot, (0, path_1.resolve)(devkit_1.workspaceRoot, outputPath))}`;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
if (outputPath.startsWith('..')) {
|
|
142
|
+
return (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, outputPath));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return (0, path_1.join)('{projectRoot}', outputPath);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import type { Configuration } from '@rspack/core';
|
|
3
|
+
import { SharedConfigContext } from './model';
|
|
4
|
+
export declare const nxRspackComposablePlugin = "nxRspackComposablePlugin";
|
|
5
|
+
export declare function isNxRspackComposablePlugin(a: unknown): a is AsyncNxComposableRspackPlugin;
|
|
6
|
+
export interface NxRspackExecutionContext {
|
|
7
|
+
options: unknown;
|
|
8
|
+
context: ExecutorContext;
|
|
9
|
+
configuration?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface NxComposableRspackPlugin {
|
|
12
|
+
(config: Configuration, ctx: NxRspackExecutionContext): Configuration;
|
|
13
|
+
}
|
|
14
|
+
export interface AsyncNxComposableRspackPlugin {
|
|
15
|
+
(config: Configuration, ctx: NxRspackExecutionContext): Configuration | Promise<Configuration>;
|
|
16
|
+
}
|
|
17
|
+
export declare function composePlugins(...plugins: any[]): (config: Configuration, ctx: SharedConfigContext) => Promise<Configuration>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nxRspackComposablePlugin = void 0;
|
|
4
|
+
exports.isNxRspackComposablePlugin = isNxRspackComposablePlugin;
|
|
5
|
+
exports.composePlugins = composePlugins;
|
|
6
|
+
exports.nxRspackComposablePlugin = 'nxRspackComposablePlugin';
|
|
7
|
+
function isNxRspackComposablePlugin(a) {
|
|
8
|
+
return a?.[exports.nxRspackComposablePlugin] === true;
|
|
9
|
+
}
|
|
10
|
+
function composePlugins(...plugins) {
|
|
11
|
+
return Object.defineProperty(async function combined(config, ctx) {
|
|
12
|
+
for (const plugin of plugins) {
|
|
13
|
+
const fn = await plugin;
|
|
14
|
+
config = await fn(config, ctx);
|
|
15
|
+
}
|
|
16
|
+
return config;
|
|
17
|
+
}, exports.nxRspackComposablePlugin, {
|
|
18
|
+
value: true,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
writable: false,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { Compiler, MultiCompiler } from '@rspack/core';
|
|
3
|
+
import { RspackExecutorSchema } from '../executors/rspack/schema';
|
|
4
|
+
export declare function createCompiler(options: RspackExecutorSchema & {
|
|
5
|
+
devServer?: any;
|
|
6
|
+
}, context: ExecutorContext): Promise<Compiler | MultiCompiler>;
|
|
7
|
+
export declare function isMultiCompiler(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCompiler = createCompiler;
|
|
4
|
+
exports.isMultiCompiler = isMultiCompiler;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const core_1 = require("@rspack/core");
|
|
7
|
+
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const resolve_user_defined_rspack_config_1 = require("./resolve-user-defined-rspack-config");
|
|
9
|
+
async function createCompiler(options, context) {
|
|
10
|
+
const pathToConfig = path.join(context.root, options.rspackConfig);
|
|
11
|
+
let userDefinedConfig = {};
|
|
12
|
+
if (options.tsConfig) {
|
|
13
|
+
userDefinedConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)(pathToConfig, options.tsConfig);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
userDefinedConfig = await Promise.resolve(`${pathToConfig}`).then(s => tslib_1.__importStar(require(s))).then((x) => x.default || x);
|
|
17
|
+
}
|
|
18
|
+
if (typeof userDefinedConfig.then === 'function') {
|
|
19
|
+
userDefinedConfig = await userDefinedConfig;
|
|
20
|
+
}
|
|
21
|
+
let config = {};
|
|
22
|
+
if (typeof userDefinedConfig === 'function') {
|
|
23
|
+
config = await userDefinedConfig({ devServer: options.devServer }, { options, context });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
config = userDefinedConfig;
|
|
27
|
+
config.devServer ??= options.devServer;
|
|
28
|
+
}
|
|
29
|
+
return (0, core_1.rspack)(config);
|
|
30
|
+
}
|
|
31
|
+
function isMultiCompiler(compiler) {
|
|
32
|
+
return 'compilers' in compiler;
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
import { ConfigurationSchema } from '../generators/configuration/schema';
|
|
3
|
+
import { Framework } from '../generators/init/schema';
|
|
4
|
+
export type Target = 'build' | 'serve';
|
|
5
|
+
export type TargetFlags = Partial<Record<Target, boolean>>;
|
|
6
|
+
export type UserProvidedTargetName = Partial<Record<Target, string>>;
|
|
7
|
+
export type ValidFoundTargetName = Partial<Record<Target, string>>;
|
|
8
|
+
export declare function findExistingTargetsInProject(targets: {
|
|
9
|
+
[targetName: string]: TargetConfiguration;
|
|
10
|
+
}, userProvidedTargets?: UserProvidedTargetName): {
|
|
11
|
+
validFoundTargetName: ValidFoundTargetName;
|
|
12
|
+
projectContainsUnsupportedExecutor: boolean;
|
|
13
|
+
userProvidedTargetIsUnsupported: TargetFlags;
|
|
14
|
+
alreadyHasNxRspackTargets: TargetFlags;
|
|
15
|
+
};
|
|
16
|
+
export declare function addOrChangeBuildTarget(tree: Tree, options: ConfigurationSchema, target: string): void;
|
|
17
|
+
export declare function addOrChangeServeTarget(tree: Tree, options: ConfigurationSchema, target: string): void;
|
|
18
|
+
export declare function writeRspackConfigFile(tree: Tree, options: ConfigurationSchema, stylePreprocessorOptions?: {
|
|
19
|
+
includePaths?: string[];
|
|
20
|
+
}): void;
|
|
21
|
+
export declare function deleteWebpackConfig(tree: Tree, projectRoot: string, webpackConfigFilePath?: string): void;
|
|
22
|
+
export declare function moveAndEditIndexHtml(tree: Tree, options: ConfigurationSchema, buildTarget: string): void;
|
|
23
|
+
export declare function normalizeViteConfigFilePathWithTree(tree: Tree, projectRoot: string, configFile?: string): string;
|
|
24
|
+
export declare function getViteConfigPathForProject(tree: Tree, projectName: string, target?: string): string;
|
|
25
|
+
export declare function handleUnsupportedUserProvidedTargets(userProvidedTargetIsUnsupported: TargetFlags, userProvidedTargetName: UserProvidedTargetName, validFoundTargetName: ValidFoundTargetName, framework: Framework): Promise<void>;
|
|
26
|
+
export declare function handleUnknownExecutors(projectName: string): Promise<void>;
|
|
27
|
+
export declare function determineFrameworkAndTarget(tree: Tree, options: ConfigurationSchema, projectRoot: string, targets: {
|
|
28
|
+
[targetName: string]: TargetConfiguration<any>;
|
|
29
|
+
}): {
|
|
30
|
+
target: 'node' | 'web';
|
|
31
|
+
framework?: Framework;
|
|
32
|
+
};
|
|
33
|
+
export declare function determineMain(tree: Tree, options: ConfigurationSchema): string;
|
|
34
|
+
export declare function determineTsConfig(tree: Tree, options: ConfigurationSchema): string;
|