@nx/rollup 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
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 +1 -1
- package/migrations.json +1 -29
- package/package.json +8 -8
- package/plugin.d.ts +1 -1
- package/plugin.js +2 -1
- package/src/executors/rollup/lib/normalize.js +3 -1
- package/src/executors/rollup/rollup.impl.d.ts +1 -1
- package/src/executors/rollup/schema.d.ts +12 -11
- package/src/executors/rollup/schema.json +7 -3
- package/src/generators/configuration/configuration.js +152 -47
- package/src/generators/configuration/schema.json +2 -2
- package/src/generators/convert-to-inferred/convert-to-inferred.js +2 -2
- package/src/generators/convert-to-inferred/lib/add-plugin-registrations.js +2 -2
- package/src/generators/convert-to-inferred/lib/extract-rollup-config-from-executor-options.js +6 -2
- package/src/generators/init/init.js +11 -1
- package/src/plugins/plugin.d.ts +7 -1
- package/src/plugins/plugin.js +79 -36
- package/src/plugins/with-nx/normalize-options.js +5 -0
- package/src/plugins/with-nx/with-nx-options.d.ts +10 -0
- package/src/plugins/with-nx/with-nx.js +19 -4
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag.d.ts +0 -2
- package/src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag.js +0 -17
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +0 -2
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +0 -29
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://circleci.com/gh/nrwl/nx)
|
|
11
11
|
[]()
|
|
12
|
-
[](https://www.npmjs.com/package/nx)
|
|
13
13
|
[]()
|
|
14
14
|
[](http://commitizen.github.io/cz-cli/)
|
|
15
15
|
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
package/migrations.json
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"update-16-0-0-add-nx-packages": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "16.0.0-beta.1",
|
|
6
|
-
"description": "Replace @nrwl/rollup with @nx/rollup",
|
|
7
|
-
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
8
|
-
},
|
|
9
|
-
"update-16-3-3-add-babel-upward-root-mode-flag": {
|
|
10
|
-
"cli": "nx",
|
|
11
|
-
"version": "16.3.3-beta.0",
|
|
12
|
-
"description": "Add babelUpwardRootMode if not already defined",
|
|
13
|
-
"implementation": "./src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag"
|
|
14
|
-
},
|
|
15
|
-
"explicitly-set-projects-to-update-buildable-deps": {
|
|
16
|
-
"cli": "nx",
|
|
17
|
-
"version": "16.6.0-beta.0",
|
|
18
|
-
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
|
|
19
|
-
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
2
|
+
"generators": {},
|
|
22
3
|
"packageJsonUpdates": {
|
|
23
|
-
"18.2.0": {
|
|
24
|
-
"version": "18.2.0-beta.1",
|
|
25
|
-
"packages": {
|
|
26
|
-
"core-js": {
|
|
27
|
-
"version": "3.36.1",
|
|
28
|
-
"alwaysAddToPackageJson": false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
4
|
"19.0.0": {
|
|
33
5
|
"version": "19.0.0-beta.0",
|
|
34
6
|
"packages": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rollup",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-31313-387cdca",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Rollup contains executors and generators that support building applications using Rollup.",
|
|
6
6
|
"repository": {
|
|
@@ -29,27 +29,27 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@nx/devkit": "0.0.0-pr-31313-387cdca",
|
|
33
|
+
"@nx/js": "0.0.0-pr-31313-387cdca",
|
|
32
34
|
"@rollup/plugin-babel": "^6.0.4",
|
|
33
35
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
34
36
|
"@rollup/plugin-image": "^3.0.3",
|
|
35
37
|
"@rollup/plugin-json": "^6.1.0",
|
|
36
38
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
39
|
+
"@rollup/plugin-typescript": "^12.1.0",
|
|
37
40
|
"autoprefixer": "^10.4.9",
|
|
38
|
-
"minimatch": "9.0.3",
|
|
39
41
|
"picocolors": "^1.1.0",
|
|
42
|
+
"picomatch": "4.0.2",
|
|
40
43
|
"postcss": "^8.4.38",
|
|
41
44
|
"rollup": "^4.14.0",
|
|
42
45
|
"rollup-plugin-copy": "^3.5.0",
|
|
43
46
|
"rollup-plugin-postcss": "^4.0.2",
|
|
44
47
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
45
|
-
"tslib": "^2.3.0"
|
|
46
|
-
"@nx/devkit": "0.0.0-pr-31222-862e973",
|
|
47
|
-
"@nx/js": "0.0.0-pr-31222-862e973",
|
|
48
|
-
"@nrwl/rollup": "0.0.0-pr-31222-862e973"
|
|
48
|
+
"tslib": "^2.3.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
53
|
+
"types": "./index.d.ts",
|
|
54
|
+
"type": "commonjs"
|
|
55
55
|
}
|
package/plugin.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createNodes, RollupPluginOptions } from './src/plugins/plugin';
|
|
1
|
+
export { createNodes, createNodesV2, RollupPluginOptions, } 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; } });
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.normalizeRollupExecutorOptions = normalizeRollupExecutorOptions;
|
|
4
4
|
exports.normalizePluginPath = normalizePluginPath;
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
6
7
|
function normalizeRollupExecutorOptions(options, context) {
|
|
7
8
|
const { root } = context;
|
|
9
|
+
const skipTypeCheck = (0, ts_solution_setup_1.isUsingTsSolutionSetup)() ? true : options.skipTypeCheck;
|
|
8
10
|
return {
|
|
9
11
|
...options,
|
|
10
12
|
rollupConfig: []
|
|
@@ -12,7 +14,7 @@ function normalizeRollupExecutorOptions(options, context) {
|
|
|
12
14
|
.filter(Boolean)
|
|
13
15
|
.map((p) => normalizePluginPath(p, root)),
|
|
14
16
|
projectRoot: context.projectGraph.nodes[context.projectName].data.root,
|
|
15
|
-
skipTypeCheck:
|
|
17
|
+
skipTypeCheck: skipTypeCheck || false,
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
function normalizePluginPath(pluginPath, root) {
|
|
@@ -2,6 +2,6 @@ import * as rollup from 'rollup';
|
|
|
2
2
|
import { type ExecutorContext } from '@nx/devkit';
|
|
3
3
|
import { RollupExecutorOptions } from './schema';
|
|
4
4
|
import { NormalizedRollupExecutorOptions } from './lib/normalize';
|
|
5
|
-
export declare function rollupExecutor(rawOptions: RollupExecutorOptions, context: ExecutorContext): AsyncGenerator<unknown, any,
|
|
5
|
+
export declare function rollupExecutor(rawOptions: RollupExecutorOptions, context: ExecutorContext): AsyncGenerator<unknown, any, any>;
|
|
6
6
|
export declare function createRollupOptions(options: NormalizedRollupExecutorOptions, context: ExecutorContext): Promise<rollup.RollupOptions | rollup.RollupOptions[]>;
|
|
7
7
|
export default rollupExecutor;
|
|
@@ -15,22 +15,23 @@ export interface Globals {
|
|
|
15
15
|
export interface RollupExecutorOptions {
|
|
16
16
|
outputPath: string;
|
|
17
17
|
tsConfig: string;
|
|
18
|
-
allowJs?: boolean;
|
|
19
|
-
project: string;
|
|
20
18
|
main: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
external?: string[] | 'all' | 'none';
|
|
24
|
-
rollupConfig?: string | string[];
|
|
25
|
-
watch?: boolean;
|
|
19
|
+
additionalEntryPoints?: string[];
|
|
20
|
+
allowJs?: boolean;
|
|
26
21
|
assets?: any[];
|
|
22
|
+
babelUpwardRootMode?: boolean;
|
|
23
|
+
buildLibsFromSource?: boolean;
|
|
24
|
+
compiler?: 'babel' | 'tsc' | 'swc';
|
|
27
25
|
deleteOutputPath?: boolean;
|
|
26
|
+
external?: string[] | 'all' | 'none';
|
|
27
|
+
extractCss?: boolean | string;
|
|
28
28
|
format?: ('cjs' | 'esm')[];
|
|
29
|
-
compiler?: 'babel' | 'tsc' | 'swc';
|
|
30
|
-
javascriptEnabled?: boolean;
|
|
31
29
|
generateExportsField?: boolean;
|
|
32
|
-
|
|
30
|
+
javascriptEnabled?: boolean;
|
|
31
|
+
project?: string;
|
|
32
|
+
outputFileName?: string;
|
|
33
|
+
rollupConfig?: string | string[];
|
|
33
34
|
skipTypeCheck?: boolean;
|
|
34
|
-
babelUpwardRootMode?: boolean;
|
|
35
35
|
skipTypeField?: boolean;
|
|
36
|
+
watch?: boolean;
|
|
36
37
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 2,
|
|
3
3
|
"outputCapture": "direct-nodejs",
|
|
4
|
-
"title": "Web Library Rollup Target
|
|
4
|
+
"title": "Web Library Rollup Target",
|
|
5
5
|
"description": "Packages a library for different web usages (ESM, CommonJS).",
|
|
6
6
|
"cli": "nx",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
9
|
"project": {
|
|
10
10
|
"type": "string",
|
|
11
|
-
"description": "The path to package.json file."
|
|
12
|
-
"x-priority": "important"
|
|
11
|
+
"description": "The path to package.json file."
|
|
13
12
|
},
|
|
14
13
|
"main": {
|
|
15
14
|
"type": "string",
|
|
@@ -138,6 +137,11 @@
|
|
|
138
137
|
},
|
|
139
138
|
"x-priority": "important"
|
|
140
139
|
},
|
|
140
|
+
"buildLibsFromSource": {
|
|
141
|
+
"type": "boolean",
|
|
142
|
+
"description": "Read buildable libraries from source instead of building them separately.",
|
|
143
|
+
"default": true
|
|
144
|
+
},
|
|
141
145
|
"skipTypeCheck": {
|
|
142
146
|
"type": "boolean",
|
|
143
147
|
"description": "Whether to skip TypeScript type checking.",
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.configurationGenerator = configurationGenerator;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
6
|
-
const init_1 = require("../init/init");
|
|
7
5
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
6
|
+
const js_1 = require("@nx/js");
|
|
7
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
8
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
9
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
10
|
+
const posix_1 = require("node:path/posix");
|
|
11
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
12
|
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
9
13
|
const has_plugin_1 = require("../../utils/has-plugin");
|
|
14
|
+
const init_1 = require("../init/init");
|
|
15
|
+
let ts;
|
|
10
16
|
async function configurationGenerator(tree, options) {
|
|
11
17
|
const tasks = [];
|
|
12
18
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -17,43 +23,65 @@ async function configurationGenerator(tree, options) {
|
|
|
17
23
|
if (!options.skipPackageJson) {
|
|
18
24
|
tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
|
|
19
25
|
}
|
|
26
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
27
|
+
let outputConfig;
|
|
20
28
|
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
21
|
-
createRollupConfig(tree, options);
|
|
29
|
+
outputConfig = createRollupConfig(tree, options, isTsSolutionSetup);
|
|
22
30
|
}
|
|
23
31
|
else {
|
|
24
32
|
options.buildTarget ??= 'build';
|
|
25
33
|
checkForTargetConflicts(tree, options);
|
|
26
|
-
addBuildTarget(tree, options);
|
|
34
|
+
addBuildTarget(tree, options, isTsSolutionSetup);
|
|
35
|
+
}
|
|
36
|
+
updatePackageJson(tree, options, outputConfig, isTsSolutionSetup);
|
|
37
|
+
if (isTsSolutionSetup) {
|
|
38
|
+
updateTsConfig(tree, options);
|
|
27
39
|
}
|
|
28
|
-
addPackageJson(tree, options);
|
|
29
40
|
if (!options.skipFormat) {
|
|
30
41
|
await (0, devkit_1.formatFiles)(tree);
|
|
31
42
|
}
|
|
32
43
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
33
44
|
}
|
|
34
|
-
function createRollupConfig(tree, options) {
|
|
45
|
+
function createRollupConfig(tree, options, isTsSolutionSetup) {
|
|
35
46
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
47
|
+
const main = options.main
|
|
48
|
+
? `./${(0, posix_1.relative)(project.root, options.main)}`
|
|
49
|
+
: './src/index.ts';
|
|
50
|
+
const outputPath = isTsSolutionSetup
|
|
51
|
+
? './dist'
|
|
52
|
+
: (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(project.root), 'dist', project.root === '.' ? project.name : project.root);
|
|
36
53
|
const buildOptions = {
|
|
37
|
-
outputPath
|
|
54
|
+
outputPath,
|
|
38
55
|
compiler: options.compiler ?? 'babel',
|
|
39
|
-
main
|
|
40
|
-
tsConfig: options.tsConfig
|
|
56
|
+
main,
|
|
57
|
+
tsConfig: options.tsConfig
|
|
58
|
+
? `./${(0, posix_1.relative)(project.root, options.tsConfig)}`
|
|
59
|
+
: './tsconfig.lib.json',
|
|
60
|
+
};
|
|
61
|
+
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rollup.config.cjs'), `const { withNx } = require('@nx/rollup/with-nx');
|
|
62
|
+
|
|
63
|
+
module.exports = withNx(
|
|
64
|
+
{
|
|
65
|
+
main: '${buildOptions.main}',
|
|
66
|
+
outputPath: '${buildOptions.outputPath}',
|
|
67
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
68
|
+
compiler: '${buildOptions.compiler}',
|
|
69
|
+
format: ${JSON.stringify(options.format ?? ['esm'])},${!isTsSolutionSetup
|
|
70
|
+
? `
|
|
71
|
+
assets: [{ input: '{projectRoot}', output: '.', glob:'*.md' }],`
|
|
72
|
+
: ''}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
|
76
|
+
// e.g.
|
|
77
|
+
// output: { sourcemap: true },
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
`);
|
|
81
|
+
return {
|
|
82
|
+
main: (0, devkit_1.joinPathFragments)(project.root, main),
|
|
83
|
+
outputPath: (0, devkit_1.joinPathFragments)(project.root, outputPath),
|
|
41
84
|
};
|
|
42
|
-
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rollup.config.js'), (0, devkit_1.stripIndents) `
|
|
43
|
-
const { withNx } = require('@nx/rollup/with-nx');
|
|
44
|
-
|
|
45
|
-
module.exports = withNx({
|
|
46
|
-
main: '${buildOptions.main}',
|
|
47
|
-
outputPath: '${buildOptions.outputPath}',
|
|
48
|
-
tsConfig: '${buildOptions.tsConfig}',
|
|
49
|
-
compiler: '${buildOptions.compiler}',
|
|
50
|
-
format: ${JSON.stringify(options.format ?? ['esm'])},
|
|
51
|
-
assets:[{ input: '.', output: '.', glob:'*.md'}],
|
|
52
|
-
}, {
|
|
53
|
-
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
|
54
|
-
// e.g.
|
|
55
|
-
// output: { sourcemap: true },
|
|
56
|
-
});`);
|
|
57
85
|
}
|
|
58
86
|
function checkForTargetConflicts(tree, options) {
|
|
59
87
|
if (options.skipValidation)
|
|
@@ -63,48 +91,102 @@ function checkForTargetConflicts(tree, options) {
|
|
|
63
91
|
throw new Error(`Project "${options.project}" already has a ${options.buildTarget} target. Pass --skipValidation to ignore this error.`);
|
|
64
92
|
}
|
|
65
93
|
}
|
|
66
|
-
function
|
|
94
|
+
function updatePackageJson(tree, options, outputConfig, isTsSolutionSetup) {
|
|
67
95
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
68
|
-
const packageJsonPath = (0,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
|
|
96
|
+
const packageJsonPath = (0, posix_1.join)(project.root, 'package.json');
|
|
97
|
+
let packageJson;
|
|
98
|
+
if (tree.exists(packageJsonPath)) {
|
|
99
|
+
if (!isTsSolutionSetup) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
packageJson = {
|
|
106
|
+
name: options.importPath || (0, get_import_path_1.getImportPath)(tree, options.project),
|
|
73
107
|
version: '0.0.1',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (isTsSolutionSetup) {
|
|
111
|
+
let main;
|
|
112
|
+
let outputPath;
|
|
113
|
+
if (outputConfig) {
|
|
114
|
+
({ main, outputPath } = outputConfig);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// target must exist if we don't receive an outputConfig
|
|
118
|
+
const projectTarget = project.targets[options.buildTarget];
|
|
119
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
120
|
+
const mergedTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, (projectTarget.executor
|
|
121
|
+
? nxJson.targetDefaults?.[projectTarget.executor]
|
|
122
|
+
: undefined) ?? nxJson.targetDefaults?.[options.buildTarget]);
|
|
123
|
+
({ main, outputPath } = mergedTarget.options);
|
|
124
|
+
}
|
|
125
|
+
// the file must exist in the TS solution setup
|
|
126
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
127
|
+
packageJson = (0, js_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
128
|
+
main,
|
|
129
|
+
outputPath,
|
|
130
|
+
projectRoot: project.root,
|
|
131
|
+
rootDir: (0, posix_1.dirname)(main),
|
|
132
|
+
generateExportsField: true,
|
|
133
|
+
packageJsonPath,
|
|
134
|
+
format: options.format ?? ['esm'],
|
|
135
|
+
outputFileExtensionForCjs: '.cjs.js',
|
|
136
|
+
outputFileExtensionForEsm: '.esm.js',
|
|
137
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
74
138
|
});
|
|
139
|
+
// rollup has a specific declaration file generation not handled by the util above,
|
|
140
|
+
// adjust accordingly
|
|
141
|
+
const typingsFile = (packageJson.module ?? packageJson.main).replace(/\.js$/, '.d.ts');
|
|
142
|
+
packageJson.types = typingsFile;
|
|
143
|
+
packageJson.exports['.'].types = typingsFile;
|
|
75
144
|
}
|
|
145
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
76
146
|
}
|
|
77
|
-
function addBuildTarget(tree, options) {
|
|
147
|
+
function addBuildTarget(tree, options, isTsSolutionSetup) {
|
|
78
148
|
(0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/rollup:rollup', options.buildTarget);
|
|
79
149
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
80
150
|
const prevBuildOptions = project.targets?.[options.buildTarget]?.options;
|
|
151
|
+
options.tsConfig ??=
|
|
152
|
+
prevBuildOptions?.tsConfig ??
|
|
153
|
+
(0, devkit_1.joinPathFragments)(project.root, 'tsconfig.lib.json');
|
|
154
|
+
let outputPath = prevBuildOptions?.outputPath;
|
|
155
|
+
if (!outputPath) {
|
|
156
|
+
outputPath = isTsSolutionSetup
|
|
157
|
+
? (0, devkit_1.joinPathFragments)(project.root, 'dist')
|
|
158
|
+
: (0, devkit_1.joinPathFragments)('dist', project.root === '.' ? project.name : project.root);
|
|
159
|
+
}
|
|
81
160
|
const buildOptions = {
|
|
82
161
|
main: options.main ??
|
|
83
162
|
prevBuildOptions?.main ??
|
|
84
163
|
(0, devkit_1.joinPathFragments)(project.root, 'src/index.ts'),
|
|
85
|
-
outputPath
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
additionalEntryPoints: prevBuildOptions?.additionalEntryPoints,
|
|
91
|
-
generateExportsField: prevBuildOptions?.generateExportsField,
|
|
164
|
+
outputPath,
|
|
165
|
+
tsConfig: options.tsConfig,
|
|
166
|
+
// TODO(leo): see if we can use this when updating the package.json for the new setup
|
|
167
|
+
// additionalEntryPoints: prevBuildOptions?.additionalEntryPoints,
|
|
168
|
+
// generateExportsField: prevBuildOptions?.generateExportsField,
|
|
92
169
|
compiler: options.compiler ?? 'babel',
|
|
93
170
|
project: `${project.root}/package.json`,
|
|
94
171
|
external: options.external,
|
|
95
|
-
format: options.format,
|
|
172
|
+
format: options.format ?? isTsSolutionSetup ? ['esm'] : undefined,
|
|
96
173
|
};
|
|
97
174
|
if (options.rollupConfig) {
|
|
98
175
|
buildOptions.rollupConfig = options.rollupConfig;
|
|
99
176
|
}
|
|
100
|
-
if (
|
|
101
|
-
buildOptions.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
177
|
+
if (!isTsSolutionSetup) {
|
|
178
|
+
buildOptions.additionalEntryPoints =
|
|
179
|
+
prevBuildOptions?.additionalEntryPoints;
|
|
180
|
+
buildOptions.generateExportsField = prevBuildOptions?.generateExportsField;
|
|
181
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'README.md'))) {
|
|
182
|
+
buildOptions.assets = [
|
|
183
|
+
{
|
|
184
|
+
glob: `${project.root}/README.md`,
|
|
185
|
+
input: '.',
|
|
186
|
+
output: '.',
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
}
|
|
108
190
|
}
|
|
109
191
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, {
|
|
110
192
|
...project,
|
|
@@ -118,4 +200,27 @@ function addBuildTarget(tree, options) {
|
|
|
118
200
|
},
|
|
119
201
|
});
|
|
120
202
|
}
|
|
203
|
+
function updateTsConfig(tree, options) {
|
|
204
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
205
|
+
const tsconfigPath = options.tsConfig ?? (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.lib.json');
|
|
206
|
+
if (!tree.exists(tsconfigPath)) {
|
|
207
|
+
throw new Error(`The '${tsconfigPath}' file doesn't exist. Provide the 'tsConfig' option with the correct path pointing to the tsconfig file to use for builds.`);
|
|
208
|
+
}
|
|
209
|
+
if (!ts) {
|
|
210
|
+
ts = (0, ensure_typescript_1.ensureTypescript)();
|
|
211
|
+
}
|
|
212
|
+
const parsedTsConfig = (0, js_1.readTsConfig)(tsconfigPath, {
|
|
213
|
+
...ts.sys,
|
|
214
|
+
readFile: (p) => tree.read(p, 'utf-8'),
|
|
215
|
+
fileExists: (p) => tree.exists(p),
|
|
216
|
+
});
|
|
217
|
+
(0, devkit_1.updateJson)(tree, tsconfigPath, (json) => {
|
|
218
|
+
if (parsedTsConfig.options.module === ts.ModuleKind.NodeNext) {
|
|
219
|
+
json.compilerOptions ??= {};
|
|
220
|
+
json.compilerOptions.module = 'esnext';
|
|
221
|
+
json.compilerOptions.moduleResolution = 'bundler';
|
|
222
|
+
}
|
|
223
|
+
return json;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
121
226
|
exports.default = configurationGenerator;
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"main": {
|
|
27
27
|
"type": "string",
|
|
28
|
-
"description": "Path relative to the workspace root for the main entry file. Defaults to '<projectRoot>/src/
|
|
28
|
+
"description": "Path relative to the workspace root for the main entry file. Defaults to '<projectRoot>/src/index.ts'.",
|
|
29
29
|
"alias": "entryFile",
|
|
30
30
|
"x-priority": "important"
|
|
31
31
|
},
|
|
32
32
|
"tsConfig": {
|
|
33
33
|
"type": "string",
|
|
34
|
-
"description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to '<projectRoot>/tsconfig.
|
|
34
|
+
"description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to '<projectRoot>/tsconfig.lib.json'.",
|
|
35
35
|
"x-priority": "important"
|
|
36
36
|
},
|
|
37
37
|
"skipFormat": {
|
|
@@ -47,11 +47,11 @@ async function convertToInferred(tree, options) {
|
|
|
47
47
|
// If users have this set erroneously, then it will continue to not work.
|
|
48
48
|
(target.outputs[0] === '{options.outputPath}' ||
|
|
49
49
|
target.outputs[0] === '{workspaceRoot}/{options.outputPath}')) {
|
|
50
|
-
// If only the default `options.outputPath` is set as output, remove it and use path inferred from `rollup.config.
|
|
50
|
+
// If only the default `options.outputPath` is set as output, remove it and use path inferred from `rollup.config.cjs`.
|
|
51
51
|
delete target.outputs;
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
|
-
// Otherwise, replace `options.outputPath` with what is inferred from `rollup.config.
|
|
54
|
+
// Otherwise, replace `options.outputPath` with what is inferred from `rollup.config.cjs`.
|
|
55
55
|
target.outputs = target.outputs.map((output) =>
|
|
56
56
|
// Again, "{projectRoot}/{options.outputPath}" is an invalid output for Rollup.
|
|
57
57
|
output === '{options.outputPath}' ||
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addPluginRegistrations = addPluginRegistrations;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const picomatch = require("picomatch");
|
|
6
6
|
async function addPluginRegistrations(tree, projectTargets, projects, pluginPath) {
|
|
7
7
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
8
8
|
for (const [project, options] of projectTargets.entries()) {
|
|
@@ -20,7 +20,7 @@ async function addPluginRegistrations(tree, projectTargets, projects, pluginPath
|
|
|
20
20
|
nxJson.plugins.push(plugin);
|
|
21
21
|
}
|
|
22
22
|
else if (existingPlugin.include) {
|
|
23
|
-
if (!existingPlugin.include.some((include) => (
|
|
23
|
+
if (!existingPlugin.include.some((include) => picomatch(include)(projectIncludeGlob))) {
|
|
24
24
|
existingPlugin.include.push(projectIncludeGlob);
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/generators/convert-to-inferred/lib/extract-rollup-config-from-executor-options.js
CHANGED
|
@@ -17,9 +17,13 @@ function extractRollupConfigFromExecutorOptions(tree, options, configurations, p
|
|
|
17
17
|
? [options.rollupConfig]
|
|
18
18
|
: [];
|
|
19
19
|
delete options.rollupConfig;
|
|
20
|
-
// Resolve conflict with rollup.config.js if
|
|
20
|
+
// Resolve conflict with rollup.config.cjs or rollup.config.js if they exist.
|
|
21
21
|
for (let i = 0; i < oldRollupConfig.length; i++) {
|
|
22
22
|
const file = oldRollupConfig[i];
|
|
23
|
+
if (file === './rollup.config.cjs') {
|
|
24
|
+
tree.rename((0, devkit_1.joinPathFragments)(projectRoot, 'rollup.config.cjs'), (0, devkit_1.joinPathFragments)(projectRoot, `rollup.migrated.config.cjs`));
|
|
25
|
+
oldRollupConfig.splice(i, 1, './rollup.migrated.config.cjs');
|
|
26
|
+
}
|
|
23
27
|
if (file === './rollup.config.js') {
|
|
24
28
|
tree.rename((0, devkit_1.joinPathFragments)(projectRoot, 'rollup.config.js'), (0, devkit_1.joinPathFragments)(projectRoot, `rollup.migrated.config.js`));
|
|
25
29
|
oldRollupConfig.splice(i, 1, './rollup.migrated.config.js');
|
|
@@ -82,7 +86,7 @@ function extractRollupConfigFromExecutorOptions(tree, options, configurations, p
|
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
|
-
tree.write((0, devkit_1.joinPathFragments)(projectRoot, `rollup.config.
|
|
89
|
+
tree.write((0, devkit_1.joinPathFragments)(projectRoot, `rollup.config.cjs`), createNewRollupConfig(oldRollupConfig, defaultOptions, configurationOptions));
|
|
86
90
|
return defaultOptions;
|
|
87
91
|
}
|
|
88
92
|
function createNewRollupConfig(oldRollupConfig, defaultOptions, configurationOptions, singleConfiguration = false) {
|
|
@@ -20,8 +20,18 @@ async function rollupInitGenerator(tree, schema) {
|
|
|
20
20
|
task = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions);
|
|
21
21
|
}
|
|
22
22
|
if (schema.addPlugin) {
|
|
23
|
-
await (0, add_plugin_1.
|
|
23
|
+
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rollup/plugin', plugin_1.createNodesV2, {
|
|
24
24
|
buildTargetName: ['build', 'rollup:build', 'rollup-build'],
|
|
25
|
+
buildDepsTargetName: [
|
|
26
|
+
'build-deps',
|
|
27
|
+
'rollup:build-deps',
|
|
28
|
+
'rollup-build-deps',
|
|
29
|
+
],
|
|
30
|
+
watchDepsTargetName: [
|
|
31
|
+
'watch-deps',
|
|
32
|
+
'rollup:watch-deps',
|
|
33
|
+
'rollup-watch-deps',
|
|
34
|
+
],
|
|
25
35
|
}, schema.updatePackageScripts);
|
|
26
36
|
}
|
|
27
37
|
if (!schema.skipFormat) {
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { type CreateDependencies, type CreateNodes } from '@nx/devkit';
|
|
1
|
+
import { type CreateDependencies, type CreateNodes, CreateNodesV2 } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
4
|
+
*/
|
|
2
5
|
export declare const createDependencies: CreateDependencies;
|
|
3
6
|
export interface RollupPluginOptions {
|
|
4
7
|
buildTargetName?: string;
|
|
8
|
+
buildDepsTargetName?: string;
|
|
9
|
+
watchDepsTargetName?: string;
|
|
5
10
|
}
|
|
6
11
|
export declare const createNodes: CreateNodes<RollupPluginOptions>;
|
|
12
|
+
export declare const createNodesV2: CreateNodesV2<RollupPluginOptions>;
|
package/src/plugins/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
|
3
|
+
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
|
4
4
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const fs_1 = require("fs");
|
|
@@ -8,48 +8,68 @@ const devkit_1 = require("@nx/devkit");
|
|
|
8
8
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
9
9
|
const js_1 = require("@nx/js");
|
|
10
10
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
12
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
13
|
+
const util_1 = require("@nx/js/src/plugins/typescript/util");
|
|
14
|
+
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
15
|
+
function readTargetsCache(cachePath) {
|
|
14
16
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
15
17
|
}
|
|
16
|
-
function writeTargetsToCache() {
|
|
17
|
-
|
|
18
|
-
(0, devkit_1.writeJsonFile)(cachePath, {
|
|
19
|
-
...oldCache,
|
|
20
|
-
...targetsCache,
|
|
21
|
-
});
|
|
18
|
+
function writeTargetsToCache(cachePath, results) {
|
|
19
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
22
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
23
|
+
*/
|
|
23
24
|
const createDependencies = () => {
|
|
24
|
-
writeTargetsToCache();
|
|
25
25
|
return [];
|
|
26
26
|
};
|
|
27
27
|
exports.createDependencies = createDependencies;
|
|
28
|
+
const rollupConfigGlob = '**/rollup.config.{js,cjs,mjs,ts,cts,mts}';
|
|
28
29
|
exports.createNodes = [
|
|
29
|
-
|
|
30
|
+
rollupConfigGlob,
|
|
30
31
|
async (configFilePath, options, context) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
|
33
|
+
return createNodesInternal(configFilePath, normalizeOptions(options), context, {}, (0, ts_solution_setup_1.isUsingTsSolutionSetup)());
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
exports.createNodesV2 = [
|
|
37
|
+
rollupConfigGlob,
|
|
38
|
+
async (configFilePaths, options, context) => {
|
|
39
|
+
const normalizedOptions = normalizeOptions(options);
|
|
40
|
+
const optionsHash = (0, file_hasher_1.hashObject)(normalizedOptions);
|
|
41
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rollup-${optionsHash}.hash`);
|
|
42
|
+
const targetsCache = readTargetsCache(cachePath);
|
|
43
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
|
44
|
+
try {
|
|
45
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, _, context) => createNodesInternal(configFile, normalizedOptions, context, targetsCache, isTsSolutionSetup), configFilePaths, normalizedOptions, context);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
writeTargetsToCache(cachePath, targetsCache);
|
|
38
49
|
}
|
|
39
|
-
options = normalizeOptions(options);
|
|
40
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
|
41
|
-
targetsCache[hash] ??= await buildRollupTarget(configFilePath, projectRoot, options, context);
|
|
42
|
-
return {
|
|
43
|
-
projects: {
|
|
44
|
-
[projectRoot]: {
|
|
45
|
-
root: projectRoot,
|
|
46
|
-
targets: targetsCache[hash],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
50
|
},
|
|
51
51
|
];
|
|
52
|
-
async function
|
|
52
|
+
async function createNodesInternal(configFilePath, options, context, targetsCache, isTsSolutionSetup) {
|
|
53
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
54
|
+
const fullyQualifiedProjectRoot = (0, path_1.join)(context.workspaceRoot, projectRoot);
|
|
55
|
+
// Do not create a project if package.json and project.json do not exist
|
|
56
|
+
const siblingFiles = (0, fs_1.readdirSync)(fullyQualifiedProjectRoot);
|
|
57
|
+
if (!siblingFiles.includes('package.json') &&
|
|
58
|
+
!siblingFiles.includes('project.json')) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
|
62
|
+
targetsCache[hash] ??= await buildRollupTarget(configFilePath, projectRoot, options, context, isTsSolutionSetup);
|
|
63
|
+
return {
|
|
64
|
+
projects: {
|
|
65
|
+
[projectRoot]: {
|
|
66
|
+
root: projectRoot,
|
|
67
|
+
targets: targetsCache[hash],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async function buildRollupTarget(configFilePath, projectRoot, options, context, isTsSolutionSetup) {
|
|
53
73
|
let loadConfigFile;
|
|
54
74
|
try {
|
|
55
75
|
// Try to load the workspace version of rollup first (it should already exist).
|
|
@@ -66,13 +86,15 @@ async function buildRollupTarget(configFilePath, projectRoot, options, context)
|
|
|
66
86
|
// Fallback to our own if needed.
|
|
67
87
|
loadConfigFile = require('rollup/loadConfigFile').loadConfigFile;
|
|
68
88
|
}
|
|
89
|
+
const isTsConfig = configFilePath.endsWith('ts');
|
|
90
|
+
const tsConfigPlugin = '@rollup/plugin-typescript';
|
|
69
91
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
70
|
-
const rollupConfig = (await loadConfigFile((0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath), {}, true // Enable watch mode so that rollup properly reloads config files without reusing a cached version
|
|
92
|
+
const rollupConfig = (await loadConfigFile((0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath), isTsConfig ? { configPlugin: tsConfigPlugin } : {}, true // Enable watch mode so that rollup properly reloads config files without reusing a cached version
|
|
71
93
|
)).options;
|
|
72
94
|
const outputs = getOutputs(rollupConfig, projectRoot);
|
|
73
95
|
const targets = {};
|
|
74
96
|
targets[options.buildTargetName] = {
|
|
75
|
-
command: `rollup -c ${(0, path_1.basename)(configFilePath)}`,
|
|
97
|
+
command: `rollup -c ${(0, path_1.basename)(configFilePath)}${isTsConfig ? ` --configPlugin ${tsConfigPlugin}` : ''}`,
|
|
76
98
|
options: { cwd: projectRoot },
|
|
77
99
|
cache: true,
|
|
78
100
|
dependsOn: [`^${options.buildTargetName}`],
|
|
@@ -83,7 +105,26 @@ async function buildRollupTarget(configFilePath, projectRoot, options, context)
|
|
|
83
105
|
{ externalDependencies: ['rollup'] },
|
|
84
106
|
],
|
|
85
107
|
outputs,
|
|
108
|
+
metadata: {
|
|
109
|
+
technologies: ['rollup'],
|
|
110
|
+
description: 'Run Rollup',
|
|
111
|
+
help: {
|
|
112
|
+
command: `${pmc.exec} rollup --help`,
|
|
113
|
+
example: {
|
|
114
|
+
options: {
|
|
115
|
+
sourcemap: true,
|
|
116
|
+
watch: true,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
86
121
|
};
|
|
122
|
+
if (isTsSolutionSetup) {
|
|
123
|
+
targets[options.buildTargetName].syncGenerators = [
|
|
124
|
+
'@nx/js:typescript-sync',
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
(0, util_1.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
|
|
87
128
|
return targets;
|
|
88
129
|
}
|
|
89
130
|
function getOutputs(rollupConfigs, projectRoot) {
|
|
@@ -113,7 +154,9 @@ function getOutputs(rollupConfigs, projectRoot) {
|
|
|
113
154
|
return Array.from(outputs);
|
|
114
155
|
}
|
|
115
156
|
function normalizeOptions(options) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
157
|
+
return {
|
|
158
|
+
buildTargetName: options.buildTargetName ?? 'build',
|
|
159
|
+
buildDepsTargetName: options.buildDepsTargetName ?? 'build-deps',
|
|
160
|
+
watchDepsTargetName: options.watchDepsTargetName ?? 'watch-deps',
|
|
161
|
+
};
|
|
119
162
|
}
|
|
@@ -5,10 +5,15 @@ const node_path_1 = require("node:path");
|
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const js_1 = require("@nx/js");
|
|
8
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
9
|
function normalizeOptions(projectRoot, sourceRoot, options) {
|
|
9
10
|
if (global.NX_GRAPH_CREATION)
|
|
10
11
|
return options;
|
|
11
12
|
normalizeRelativePaths(projectRoot, options);
|
|
13
|
+
// New TS Solution already has a typecheck target
|
|
14
|
+
if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)()) {
|
|
15
|
+
options.skipTypeCheck = true;
|
|
16
|
+
}
|
|
12
17
|
return {
|
|
13
18
|
...options,
|
|
14
19
|
additionalEntryPoints: (0, js_1.createEntryPoints)(options.additionalEntryPoints, devkit_1.workspaceRoot),
|
|
@@ -15,6 +15,10 @@ export interface RollupWithNxPluginOptions {
|
|
|
15
15
|
* Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode
|
|
16
16
|
*/
|
|
17
17
|
babelUpwardRootMode?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Build the libraries from source. Default is `true`.
|
|
20
|
+
*/
|
|
21
|
+
buildLibsFromSource?: boolean;
|
|
18
22
|
/**
|
|
19
23
|
* Which compiler to use.
|
|
20
24
|
*/
|
|
@@ -76,6 +80,12 @@ export interface RollupWithNxPluginOptions {
|
|
|
76
80
|
* The path to tsconfig file.
|
|
77
81
|
*/
|
|
78
82
|
tsConfig: string;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to generate a package.json file in the output path. It's not supported when the workspace is
|
|
85
|
+
* set up with TypeScript Project References along with the package managers' Workspaces feature. Otherwise,
|
|
86
|
+
* it defaults to `true`.
|
|
87
|
+
*/
|
|
88
|
+
generatePackageJson?: boolean;
|
|
79
89
|
}
|
|
80
90
|
export interface AssetGlobPattern {
|
|
81
91
|
glob: string;
|
|
@@ -16,6 +16,7 @@ const generate_package_json_1 = require("../package-json/generate-package-json")
|
|
|
16
16
|
const get_project_node_1 = require("./get-project-node");
|
|
17
17
|
const delete_output_1 = require("../delete-output");
|
|
18
18
|
const normalize_options_1 = require("./normalize-options");
|
|
19
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
19
20
|
// These use require because the ES import isn't correct.
|
|
20
21
|
const commonjs = require('@rollup/plugin-commonjs');
|
|
21
22
|
const image = require('@rollup/plugin-image');
|
|
@@ -42,7 +43,9 @@ dependencies) {
|
|
|
42
43
|
const options = (0, normalize_options_1.normalizeOptions)(projectNode.data.root, projectNode.data.sourceRoot, rawOptions);
|
|
43
44
|
const useBabel = options.compiler === 'babel';
|
|
44
45
|
const useSwc = options.compiler === 'swc';
|
|
45
|
-
const tsConfigPath =
|
|
46
|
+
const tsConfigPath = options.buildLibsFromSource || global.NX_GRAPH_CREATION
|
|
47
|
+
? (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, options.tsConfig)
|
|
48
|
+
: (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, devkit_1.workspaceRoot, projectRoot, dependencies);
|
|
46
49
|
const tsConfigFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
|
|
47
50
|
const tsConfig = ts.parseJsonConfigFileContent(tsConfigFile.config, ts.sys, (0, node_path_1.dirname)(tsConfigPath));
|
|
48
51
|
if (!options.format || !options.format.length) {
|
|
@@ -119,6 +122,18 @@ dependencies) {
|
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
if (!global.NX_GRAPH_CREATION) {
|
|
125
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
|
126
|
+
if (isTsSolutionSetup) {
|
|
127
|
+
if (options.generatePackageJson) {
|
|
128
|
+
throw new Error(`Setting 'generatePackageJson: true' is not supported with the current TypeScript setup. Update the 'package.json' file at the project root as needed and unset the 'generatePackageJson' option.`);
|
|
129
|
+
}
|
|
130
|
+
if (options.generateExportsField) {
|
|
131
|
+
throw new Error(`Setting 'generateExportsField: true' is not supported with the current TypeScript setup. Set 'exports' field in the 'package.json' file at the project root and unset the 'generateExportsField' option.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
options.generatePackageJson ??= true;
|
|
136
|
+
}
|
|
122
137
|
finalConfig.plugins = [
|
|
123
138
|
copy({
|
|
124
139
|
targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
|
|
@@ -128,7 +143,7 @@ dependencies) {
|
|
|
128
143
|
// Needed to generate type definitions, even if we're using babel or swc.
|
|
129
144
|
require('rollup-plugin-typescript2')({
|
|
130
145
|
check: !options.skipTypeCheck,
|
|
131
|
-
tsconfig:
|
|
146
|
+
tsconfig: tsConfigPath,
|
|
132
147
|
tsconfigOverride: {
|
|
133
148
|
compilerOptions: createTsCompilerOptions(projectRoot, tsConfig, options, dependencies),
|
|
134
149
|
},
|
|
@@ -173,8 +188,8 @@ dependencies) {
|
|
|
173
188
|
}),
|
|
174
189
|
commonjs(),
|
|
175
190
|
(0, analyze_1.analyze)(),
|
|
176
|
-
(0, generate_package_json_1.generatePackageJson)(options, packageJson),
|
|
177
|
-
];
|
|
191
|
+
options.generatePackageJson && (0, generate_package_json_1.generatePackageJson)(options, packageJson),
|
|
192
|
+
].filter(Boolean);
|
|
178
193
|
if (Array.isArray(rollupConfig.plugins)) {
|
|
179
194
|
finalConfig.plugins.push(...rollupConfig.plugins);
|
|
180
195
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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/rollup', '@nx/rollup');
|
|
8
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
9
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = default_1;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
-
async function default_1(tree) {
|
|
7
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', (options, projectName, targetName, _configurationName) => {
|
|
8
|
-
if (options.babelUpwardRootMode !== undefined) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
12
|
-
projectConfiguration.targets[targetName].options.babelUpwardRootMode =
|
|
13
|
-
true;
|
|
14
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
15
|
-
});
|
|
16
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
17
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = default_1;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executors = new Set(['@nx/rollup:rollup', '@nrwl/rollup:rollup']);
|
|
6
|
-
async function default_1(tree) {
|
|
7
|
-
// use project graph to get the expanded target configurations
|
|
8
|
-
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
9
|
-
for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
|
|
10
|
-
if (projectData.projectType !== 'library') {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
for (const [targetName, target] of Object.entries(projectData.targets || {})) {
|
|
14
|
-
if (!executors.has(target.executor)) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
if (!target.options ||
|
|
18
|
-
target.options.updateBuildableProjectDepsInPackageJson === undefined) {
|
|
19
|
-
// read the project configuration to write the explicit project configuration
|
|
20
|
-
// and avoid writing the expanded target configuration
|
|
21
|
-
const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
22
|
-
project.targets[targetName].options ??= {};
|
|
23
|
-
project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
|
|
24
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
29
|
-
}
|