@nx/rollup 21.2.1 → 21.2.3
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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/rollup",
|
3
|
-
"version": "21.2.
|
3
|
+
"version": "21.2.3",
|
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,8 +29,8 @@
|
|
29
29
|
"migrations": "./migrations.json"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@nx/devkit": "21.2.
|
33
|
-
"@nx/js": "21.2.
|
32
|
+
"@nx/devkit": "21.2.3",
|
33
|
+
"@nx/js": "21.2.3",
|
34
34
|
"@rollup/plugin-babel": "^6.0.4",
|
35
35
|
"@rollup/plugin-commonjs": "^25.0.7",
|
36
36
|
"@rollup/plugin-image": "^3.0.3",
|
@@ -155,6 +155,11 @@
|
|
155
155
|
"sourceMap": {
|
156
156
|
"description": "Output sourcemaps.",
|
157
157
|
"type": "boolean"
|
158
|
+
},
|
159
|
+
"useLegacyTypescriptPlugin": {
|
160
|
+
"type": "boolean",
|
161
|
+
"description": "Use rollup-plugin-typescript2 instead of @rollup/plugin-typescript.",
|
162
|
+
"default": true
|
158
163
|
}
|
159
164
|
},
|
160
165
|
"required": ["tsConfig", "main", "outputPath"],
|
@@ -80,6 +80,10 @@ export interface RollupWithNxPluginOptions {
|
|
80
80
|
* The path to tsconfig file.
|
81
81
|
*/
|
82
82
|
tsConfig: string;
|
83
|
+
/**
|
84
|
+
* Use rollup-plugin-typescript2 instead of @rollup/plugin-typescript.
|
85
|
+
*/
|
86
|
+
useLegacyTypescriptPlugin?: boolean;
|
83
87
|
/**
|
84
88
|
* Whether to generate a package.json file in the output path. It's not supported when the workspace is
|
85
89
|
* set up with TypeScript Project References along with the package managers' Workspaces feature. Otherwise,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import * as rollup from 'rollup';
|
2
1
|
import { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
|
2
|
+
import * as rollup from 'rollup';
|
3
3
|
import { RollupWithNxPluginOptions } from './with-nx-options';
|
4
4
|
export declare function withNx(rawOptions: RollupWithNxPluginOptions, rollupConfig?: rollup.RollupOptions, dependencies?: DependentBuildableProjectNode[]): rollup.RollupOptions;
|
@@ -1,22 +1,21 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.withNx = withNx;
|
4
|
-
const node_fs_1 = require("node:fs");
|
5
|
-
const node_path_1 = require("node:path");
|
6
|
-
const ts = require("typescript");
|
7
|
-
const plugin_babel_1 = require("@rollup/plugin-babel");
|
8
|
-
const autoprefixer = require("autoprefixer");
|
9
4
|
const devkit_1 = require("@nx/devkit");
|
5
|
+
const type_definitions_1 = require("@nx/js/src/plugins/rollup/type-definitions");
|
10
6
|
const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
8
|
+
const plugin_babel_1 = require("@rollup/plugin-babel");
|
11
9
|
const plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
|
12
|
-
const
|
10
|
+
const autoprefixer = require("autoprefixer");
|
11
|
+
const node_fs_1 = require("node:fs");
|
12
|
+
const node_path_1 = require("node:path");
|
13
13
|
const analyze_1 = require("../analyze");
|
14
|
-
const
|
14
|
+
const delete_output_1 = require("../delete-output");
|
15
15
|
const generate_package_json_1 = require("../package-json/generate-package-json");
|
16
|
+
const swc_1 = require("../swc");
|
16
17
|
const get_project_node_1 = require("./get-project-node");
|
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");
|
20
19
|
// These use require because the ES import isn't correct.
|
21
20
|
const commonjs = require('@rollup/plugin-commonjs');
|
22
21
|
const image = require('@rollup/plugin-image');
|
@@ -24,6 +23,18 @@ const json = require('@rollup/plugin-json');
|
|
24
23
|
const copy = require('rollup-plugin-copy');
|
25
24
|
const postcss = require('rollup-plugin-postcss');
|
26
25
|
const fileExtensions = ['.js', '.jsx', '.ts', '.tsx'];
|
26
|
+
let ts;
|
27
|
+
function ensureTypeScript() {
|
28
|
+
if (!ts) {
|
29
|
+
try {
|
30
|
+
ts = require('typescript');
|
31
|
+
}
|
32
|
+
catch (e) {
|
33
|
+
throw new Error('TypeScript is required for the @nx/rollup plugin. Please install it in your workspace.');
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return ts;
|
37
|
+
}
|
27
38
|
function withNx(rawOptions, rollupConfig = {},
|
28
39
|
// Passed by @nx/rollup:rollup executor to previous behavior of remapping tsconfig paths based on buildable dependencies remains intact.
|
29
40
|
dependencies) {
|
@@ -40,12 +51,14 @@ dependencies) {
|
|
40
51
|
const result = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(undefined, projectGraph, devkit_1.workspaceRoot, projectNode.name, process.env.NX_TASK_TARGET_TARGET, process.env.NX_TASK_TARGET_CONFIGURATION, true);
|
41
52
|
dependencies = result.dependencies;
|
42
53
|
}
|
43
|
-
const
|
54
|
+
const projectSourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data);
|
55
|
+
const options = (0, normalize_options_1.normalizeOptions)(projectNode.data.root, projectSourceRoot, rawOptions);
|
44
56
|
const useBabel = options.compiler === 'babel';
|
45
57
|
const useSwc = options.compiler === 'swc';
|
46
58
|
const tsConfigPath = options.buildLibsFromSource || global.NX_GRAPH_CREATION
|
47
59
|
? (0, node_path_1.join)(devkit_1.workspaceRoot, options.tsConfig)
|
48
60
|
: (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, devkit_1.workspaceRoot, projectRoot, dependencies);
|
61
|
+
ensureTypeScript();
|
49
62
|
const tsConfigFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
|
50
63
|
const tsConfig = ts.parseJsonConfigFileContent(tsConfigFile.config, ts.sys, (0, node_path_1.dirname)(tsConfigPath));
|
51
64
|
if (!options.format || !options.format.length) {
|
@@ -122,6 +135,8 @@ dependencies) {
|
|
122
135
|
};
|
123
136
|
}
|
124
137
|
if (!global.NX_GRAPH_CREATION) {
|
138
|
+
// Ensure TypeScript is available before any plugin initialization
|
139
|
+
ensureTypeScript();
|
125
140
|
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
126
141
|
if (isTsSolutionSetup) {
|
127
142
|
if (options.generatePackageJson) {
|
@@ -134,20 +149,50 @@ dependencies) {
|
|
134
149
|
else {
|
135
150
|
options.generatePackageJson ??= true;
|
136
151
|
}
|
152
|
+
const compilerOptions = createTsCompilerOptions(projectRoot, tsConfig, options, dependencies);
|
153
|
+
compilerOptions.outDir = Array.isArray(finalConfig.output)
|
154
|
+
? finalConfig.output[0].dir
|
155
|
+
: finalConfig.output.dir;
|
137
156
|
finalConfig.plugins = [
|
138
157
|
copy({
|
139
158
|
targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
|
140
159
|
}),
|
141
160
|
image(),
|
142
161
|
json(),
|
143
|
-
//
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
162
|
+
// TypeScript compilation and declaration generation
|
163
|
+
// TODO(v22): Change default value of useLegacyTypescriptPlugin to false for Nx 22
|
164
|
+
options.useLegacyTypescriptPlugin !== false
|
165
|
+
? (() => {
|
166
|
+
// TODO(v23): Remove in Nx 23
|
167
|
+
// Show deprecation warning
|
168
|
+
devkit_1.logger.warn(`rollup-plugin-typescript2 usage is deprecated and will be removed in Nx 23. ` +
|
169
|
+
`Set 'useLegacyTypescriptPlugin: false' to use the official @rollup/plugin-typescript.`);
|
170
|
+
return require('rollup-plugin-typescript2')({
|
171
|
+
check: !options.skipTypeCheck,
|
172
|
+
tsconfig: tsConfigPath,
|
173
|
+
tsconfigOverride: {
|
174
|
+
compilerOptions,
|
175
|
+
},
|
176
|
+
});
|
177
|
+
})()
|
178
|
+
: (() => {
|
179
|
+
// @rollup/plugin-typescript needs outDir and declarationDir to match Rollup's output directory
|
180
|
+
const { outDir, declarationDir, ...tsCompilerOptions } = compilerOptions;
|
181
|
+
const rollupOutputDir = Array.isArray(finalConfig.output)
|
182
|
+
? finalConfig.output[0].dir
|
183
|
+
: finalConfig.output.dir;
|
184
|
+
return require('@rollup/plugin-typescript')({
|
185
|
+
tsconfig: tsConfigPath,
|
186
|
+
compilerOptions: {
|
187
|
+
...tsCompilerOptions,
|
188
|
+
outDir: rollupOutputDir,
|
189
|
+
declarationDir: rollupOutputDir,
|
190
|
+
},
|
191
|
+
declaration: true,
|
192
|
+
declarationMap: !!options.sourceMap,
|
193
|
+
noEmitOnError: !options.skipTypeCheck,
|
194
|
+
});
|
195
|
+
})(),
|
151
196
|
(0, type_definitions_1.typeDefinitions)({
|
152
197
|
projectRoot,
|
153
198
|
}),
|
@@ -178,7 +223,7 @@ dependencies) {
|
|
178
223
|
supportsStaticESM: true,
|
179
224
|
isModern: true,
|
180
225
|
},
|
181
|
-
cwd: (0, node_path_1.join)(devkit_1.workspaceRoot,
|
226
|
+
cwd: (0, node_path_1.join)(devkit_1.workspaceRoot, projectSourceRoot),
|
182
227
|
rootMode: options.babelUpwardRootMode ? 'upward' : undefined,
|
183
228
|
babelrc: true,
|
184
229
|
extensions: fileExtensions,
|
@@ -224,6 +269,7 @@ function createTsCompilerOptions(projectRoot, config, options, dependencies) {
|
|
224
269
|
declaration: true,
|
225
270
|
paths: compilerOptionPaths,
|
226
271
|
};
|
272
|
+
ensureTypeScript();
|
227
273
|
if (config.options.module === ts.ModuleKind.CommonJS) {
|
228
274
|
compilerOptions['module'] = 'ESNext';
|
229
275
|
}
|
@@ -241,6 +287,7 @@ function convertCopyAssetsToRollupOptions(outputPath, assets) {
|
|
241
287
|
: undefined;
|
242
288
|
}
|
243
289
|
function readCompatibleFormats(config) {
|
290
|
+
ensureTypeScript();
|
244
291
|
switch (config.options.module) {
|
245
292
|
case ts.ModuleKind.CommonJS:
|
246
293
|
case ts.ModuleKind.UMD:
|