@nx/rollup 0.0.0-pr-28667-37ba4e7 → 0.0.0-pr-28682-017d55a
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": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-28682-017d55a",
|
|
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": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"rollup-plugin-postcss": "^4.0.2",
|
|
44
44
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
45
45
|
"tslib": "^2.3.0",
|
|
46
|
-
"@nx/devkit": "0.0.0-pr-
|
|
47
|
-
"@nx/js": "0.0.0-pr-
|
|
46
|
+
"@nx/devkit": "0.0.0-pr-28682-017d55a",
|
|
47
|
+
"@nx/js": "0.0.0-pr-28682-017d55a"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -2,12 +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 target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
6
|
+
const js_1 = require("@nx/js");
|
|
5
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");
|
|
6
9
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
10
|
+
const posix_1 = require("node:path/posix");
|
|
11
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
9
12
|
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
10
13
|
const has_plugin_1 = require("../../utils/has-plugin");
|
|
14
|
+
const init_1 = require("../init/init");
|
|
15
|
+
let ts;
|
|
11
16
|
async function configurationGenerator(tree, options) {
|
|
12
17
|
const tasks = [];
|
|
13
18
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -18,30 +23,40 @@ async function configurationGenerator(tree, options) {
|
|
|
18
23
|
if (!options.skipPackageJson) {
|
|
19
24
|
tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
|
|
20
25
|
}
|
|
26
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
27
|
+
let outputConfig;
|
|
21
28
|
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
22
|
-
createRollupConfig(tree, options);
|
|
29
|
+
outputConfig = createRollupConfig(tree, options, isTsSolutionSetup);
|
|
23
30
|
}
|
|
24
31
|
else {
|
|
25
32
|
options.buildTarget ??= 'build';
|
|
26
33
|
checkForTargetConflicts(tree, options);
|
|
27
|
-
addBuildTarget(tree, options);
|
|
34
|
+
addBuildTarget(tree, options, isTsSolutionSetup);
|
|
35
|
+
}
|
|
36
|
+
updatePackageJson(tree, options, outputConfig, isTsSolutionSetup);
|
|
37
|
+
if (isTsSolutionSetup) {
|
|
38
|
+
updateTsConfig(tree, options);
|
|
28
39
|
}
|
|
29
|
-
addPackageJson(tree, options);
|
|
30
40
|
if (!options.skipFormat) {
|
|
31
41
|
await (0, devkit_1.formatFiles)(tree);
|
|
32
42
|
}
|
|
33
43
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
34
44
|
}
|
|
35
|
-
function createRollupConfig(tree, options) {
|
|
36
|
-
const isUsingTsPlugin = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
45
|
+
function createRollupConfig(tree, options, isTsSolutionSetup) {
|
|
37
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);
|
|
38
53
|
const buildOptions = {
|
|
39
|
-
outputPath
|
|
40
|
-
? './dist'
|
|
41
|
-
: (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(project.root), 'dist', project.root === '.' ? project.name : project.root),
|
|
54
|
+
outputPath,
|
|
42
55
|
compiler: options.compiler ?? 'babel',
|
|
43
|
-
main
|
|
44
|
-
tsConfig: options.tsConfig
|
|
56
|
+
main,
|
|
57
|
+
tsConfig: options.tsConfig
|
|
58
|
+
? `./${(0, posix_1.relative)(project.root, options.tsConfig)}`
|
|
59
|
+
: './tsconfig.lib.json',
|
|
45
60
|
};
|
|
46
61
|
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rollup.config.js'), `const { withNx } = require('@nx/rollup/with-nx');
|
|
47
62
|
|
|
@@ -51,8 +66,10 @@ module.exports = withNx(
|
|
|
51
66
|
outputPath: '${buildOptions.outputPath}',
|
|
52
67
|
tsConfig: '${buildOptions.tsConfig}',
|
|
53
68
|
compiler: '${buildOptions.compiler}',
|
|
54
|
-
format: ${JSON.stringify(options.format ?? ['esm'])}
|
|
55
|
-
|
|
69
|
+
format: ${JSON.stringify(options.format ?? ['esm'])},${!isTsSolutionSetup
|
|
70
|
+
? `
|
|
71
|
+
assets: [{ input: '.', output: '.', glob:'*.md' }],`
|
|
72
|
+
: ''}
|
|
56
73
|
},
|
|
57
74
|
{
|
|
58
75
|
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
|
@@ -61,6 +78,10 @@ module.exports = withNx(
|
|
|
61
78
|
}
|
|
62
79
|
);
|
|
63
80
|
`);
|
|
81
|
+
return {
|
|
82
|
+
main: (0, devkit_1.joinPathFragments)(project.root, main),
|
|
83
|
+
outputPath: (0, devkit_1.joinPathFragments)(project.root, outputPath),
|
|
84
|
+
};
|
|
64
85
|
}
|
|
65
86
|
function checkForTargetConflicts(tree, options) {
|
|
66
87
|
if (options.skipValidation)
|
|
@@ -70,48 +91,99 @@ function checkForTargetConflicts(tree, options) {
|
|
|
70
91
|
throw new Error(`Project "${options.project}" already has a ${options.buildTarget} target. Pass --skipValidation to ignore this error.`);
|
|
71
92
|
}
|
|
72
93
|
}
|
|
73
|
-
function
|
|
94
|
+
function updatePackageJson(tree, options, outputConfig, isTsSolutionSetup) {
|
|
74
95
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
75
|
-
const packageJsonPath = (0,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(
|
|
79
|
-
|
|
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),
|
|
80
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
|
+
packageJson = (0, js_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
126
|
+
main,
|
|
127
|
+
outputPath,
|
|
128
|
+
projectRoot: project.root,
|
|
129
|
+
rootDir: (0, posix_1.dirname)(main),
|
|
130
|
+
generateExportsField: true,
|
|
131
|
+
packageJsonPath,
|
|
132
|
+
format: options.format ?? ['esm'],
|
|
133
|
+
outputFileExtensionForCjs: '.cjs.js',
|
|
134
|
+
outputFileExtensionForEsm: '.esm.js',
|
|
81
135
|
});
|
|
136
|
+
// rollup has a specific declaration file generation not handled by the util above,
|
|
137
|
+
// adjust accordingly
|
|
138
|
+
const typingsFile = (packageJson.module ?? packageJson.main).replace(/\.js$/, '.d.ts');
|
|
139
|
+
packageJson.types = typingsFile;
|
|
140
|
+
packageJson.exports['.'].types = typingsFile;
|
|
82
141
|
}
|
|
142
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
83
143
|
}
|
|
84
|
-
function addBuildTarget(tree, options) {
|
|
144
|
+
function addBuildTarget(tree, options, isTsSolutionSetup) {
|
|
85
145
|
(0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/rollup:rollup', options.buildTarget);
|
|
86
146
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
87
147
|
const prevBuildOptions = project.targets?.[options.buildTarget]?.options;
|
|
148
|
+
options.tsConfig ??=
|
|
149
|
+
prevBuildOptions?.tsConfig ??
|
|
150
|
+
(0, devkit_1.joinPathFragments)(project.root, 'tsconfig.lib.json');
|
|
151
|
+
let outputPath = prevBuildOptions?.outputPath;
|
|
152
|
+
if (!outputPath) {
|
|
153
|
+
outputPath = isTsSolutionSetup
|
|
154
|
+
? (0, devkit_1.joinPathFragments)(project.root, 'dist')
|
|
155
|
+
: (0, devkit_1.joinPathFragments)('dist', project.root === '.' ? project.name : project.root);
|
|
156
|
+
}
|
|
88
157
|
const buildOptions = {
|
|
89
158
|
main: options.main ??
|
|
90
159
|
prevBuildOptions?.main ??
|
|
91
160
|
(0, devkit_1.joinPathFragments)(project.root, 'src/index.ts'),
|
|
92
|
-
outputPath
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
additionalEntryPoints: prevBuildOptions?.additionalEntryPoints,
|
|
98
|
-
generateExportsField: prevBuildOptions?.generateExportsField,
|
|
161
|
+
outputPath,
|
|
162
|
+
tsConfig: options.tsConfig,
|
|
163
|
+
// TODO(leo): see if we can use this when updating the package.json for the new setup
|
|
164
|
+
// additionalEntryPoints: prevBuildOptions?.additionalEntryPoints,
|
|
165
|
+
// generateExportsField: prevBuildOptions?.generateExportsField,
|
|
99
166
|
compiler: options.compiler ?? 'babel',
|
|
100
167
|
project: `${project.root}/package.json`,
|
|
101
168
|
external: options.external,
|
|
102
|
-
format: options.format,
|
|
169
|
+
format: options.format ?? isTsSolutionSetup ? ['esm'] : undefined,
|
|
103
170
|
};
|
|
104
171
|
if (options.rollupConfig) {
|
|
105
172
|
buildOptions.rollupConfig = options.rollupConfig;
|
|
106
173
|
}
|
|
107
|
-
if (
|
|
108
|
-
buildOptions.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
174
|
+
if (!isTsSolutionSetup) {
|
|
175
|
+
buildOptions.additionalEntryPoints =
|
|
176
|
+
prevBuildOptions?.additionalEntryPoints;
|
|
177
|
+
buildOptions.generateExportsField = prevBuildOptions?.generateExportsField;
|
|
178
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'README.md'))) {
|
|
179
|
+
buildOptions.assets = [
|
|
180
|
+
{
|
|
181
|
+
glob: `${project.root}/README.md`,
|
|
182
|
+
input: '.',
|
|
183
|
+
output: '.',
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
}
|
|
115
187
|
}
|
|
116
188
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, {
|
|
117
189
|
...project,
|
|
@@ -125,4 +197,27 @@ function addBuildTarget(tree, options) {
|
|
|
125
197
|
},
|
|
126
198
|
});
|
|
127
199
|
}
|
|
200
|
+
function updateTsConfig(tree, options) {
|
|
201
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
202
|
+
const tsconfigPath = options.tsConfig ?? (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.lib.json');
|
|
203
|
+
if (!tree.exists(tsconfigPath)) {
|
|
204
|
+
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.`);
|
|
205
|
+
}
|
|
206
|
+
if (!ts) {
|
|
207
|
+
ts = (0, ensure_typescript_1.ensureTypescript)();
|
|
208
|
+
}
|
|
209
|
+
const parsedTsConfig = (0, js_1.readTsConfig)(tsconfigPath, {
|
|
210
|
+
...ts.sys,
|
|
211
|
+
readFile: (p) => tree.read(p, 'utf-8'),
|
|
212
|
+
fileExists: (p) => tree.exists(p),
|
|
213
|
+
});
|
|
214
|
+
(0, devkit_1.updateJson)(tree, tsconfigPath, (json) => {
|
|
215
|
+
if (parsedTsConfig.options.module === ts.ModuleKind.NodeNext) {
|
|
216
|
+
json.compilerOptions ??= {};
|
|
217
|
+
json.compilerOptions.module = 'esnext';
|
|
218
|
+
json.compilerOptions.moduleResolution = 'bundler';
|
|
219
|
+
}
|
|
220
|
+
return json;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
128
223
|
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": {
|
|
@@ -76,6 +76,12 @@ export interface RollupWithNxPluginOptions {
|
|
|
76
76
|
* The path to tsconfig file.
|
|
77
77
|
*/
|
|
78
78
|
tsConfig: string;
|
|
79
|
+
/**
|
|
80
|
+
* Whether to generate a package.json file in the output path. It's not supported when the workspace is
|
|
81
|
+
* set up with TypeScript Project References along with the package managers' Workspaces feature. Otherwise,
|
|
82
|
+
* it defaults to `true`.
|
|
83
|
+
*/
|
|
84
|
+
generatePackageJson?: boolean;
|
|
79
85
|
}
|
|
80
86
|
export interface AssetGlobPattern {
|
|
81
87
|
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');
|
|
@@ -119,6 +120,18 @@ dependencies) {
|
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
if (!global.NX_GRAPH_CREATION) {
|
|
123
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
|
124
|
+
if (isTsSolutionSetup) {
|
|
125
|
+
if (options.generatePackageJson) {
|
|
126
|
+
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.`);
|
|
127
|
+
}
|
|
128
|
+
if (options.generateExportsField) {
|
|
129
|
+
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.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
options.generatePackageJson ??= true;
|
|
134
|
+
}
|
|
122
135
|
finalConfig.plugins = [
|
|
123
136
|
copy({
|
|
124
137
|
targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
|
|
@@ -173,7 +186,7 @@ dependencies) {
|
|
|
173
186
|
}),
|
|
174
187
|
commonjs(),
|
|
175
188
|
(0, analyze_1.analyze)(),
|
|
176
|
-
(0, generate_package_json_1.generatePackageJson)(options, packageJson),
|
|
189
|
+
options.generatePackageJson && (0, generate_package_json_1.generatePackageJson)(options, packageJson),
|
|
177
190
|
];
|
|
178
191
|
if (Array.isArray(rollupConfig.plugins)) {
|
|
179
192
|
finalConfig.plugins.push(...rollupConfig.plugins);
|