@nx/rollup 17.0.4 → 17.0.6
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 +4 -9
- package/migrations.json +1 -11
- package/package.json +7 -5
- package/src/executors/rollup/lib/run-rollup.d.ts +4 -0
- package/src/executors/rollup/lib/run-rollup.js +15 -0
- package/src/executors/rollup/lib/update-package-json.js +1 -2
- package/src/executors/rollup/rollup.impl.d.ts +6 -9
- package/src/executors/rollup/rollup.impl.js +143 -162
- package/src/generators/configuration/configuration.d.ts +2 -2
- package/src/generators/configuration/configuration.js +6 -12
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.js +15 -30
- package/src/generators/init/schema.d.ts +1 -4
- package/src/generators/init/schema.json +7 -18
- package/src/utils/versions.d.ts +0 -1
- package/src/utils/versions.js +1 -2
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -5
- package/src/plugins/plugin.d.ts +0 -6
- package/src/plugins/plugin.js +0 -104
- package/src/utils/ensure-dependencies.d.ts +0 -5
- package/src/utils/ensure-dependencies.js +0 -24
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
<p style="text-align: center;">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
-
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
-
</picture>
|
|
6
|
-
</p>
|
|
1
|
+
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
|
|
7
2
|
|
|
8
3
|
<div style="text-align: center;">
|
|
9
4
|
|
|
@@ -20,9 +15,9 @@
|
|
|
20
15
|
|
|
21
16
|
<hr>
|
|
22
17
|
|
|
23
|
-
# Nx: Smart
|
|
18
|
+
# Nx: Smart, Fast and Extensible Build System
|
|
24
19
|
|
|
25
|
-
Nx is a build system with
|
|
20
|
+
Nx is a next generation build system with first class monorepo support and powerful integrations.
|
|
26
21
|
|
|
27
22
|
This package is a [Rollup plugin for Nx](https://nx.dev/packages/rollup).
|
|
28
23
|
|
|
@@ -64,5 +59,5 @@ npx nx@latest init
|
|
|
64
59
|
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
65
60
|
|
|
66
61
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
67
|
-
width="100%" alt="Nx - Smart
|
|
62
|
+
width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
|
|
68
63
|
|
package/migrations.json
CHANGED
|
@@ -25,15 +25,5 @@
|
|
|
25
25
|
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
"packageJsonUpdates": {
|
|
29
|
-
"18.2.0": {
|
|
30
|
-
"version": "18.2.0-beta.1",
|
|
31
|
-
"packages": {
|
|
32
|
-
"core-js": {
|
|
33
|
-
"version": "3.36.1",
|
|
34
|
-
"alwaysAddToPackageJson": false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
28
|
+
"packageJsonUpdates": {}
|
|
39
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rollup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v17.0.6",
|
|
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": {
|
|
@@ -37,16 +37,18 @@
|
|
|
37
37
|
"autoprefixer": "^10.4.9",
|
|
38
38
|
"babel-plugin-transform-async-to-promises": "^0.8.15",
|
|
39
39
|
"chalk": "^4.1.0",
|
|
40
|
+
"fast-glob": "^3.2.7",
|
|
40
41
|
"postcss": "^8.4.14",
|
|
41
42
|
"rollup": "^2.56.2",
|
|
42
43
|
"rollup-plugin-copy": "^3.4.0",
|
|
43
44
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
44
45
|
"rollup-plugin-postcss": "^4.0.1",
|
|
45
|
-
"rollup-plugin-typescript2": "0.
|
|
46
|
+
"rollup-plugin-typescript2": "0.34.1",
|
|
47
|
+
"rxjs": "^7.8.0",
|
|
46
48
|
"tslib": "^2.3.0",
|
|
47
|
-
"@nx/devkit": "
|
|
48
|
-
"@nx/js": "
|
|
49
|
-
"@nrwl/rollup": "
|
|
49
|
+
"@nx/devkit": "v17.0.6",
|
|
50
|
+
"@nx/js": "v17.0.6",
|
|
51
|
+
"@nrwl/rollup": "v17.0.6"
|
|
50
52
|
},
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"access": "public"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runRollup = void 0;
|
|
4
|
+
const rollup = require("rollup");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const operators_1 = require("rxjs/operators");
|
|
7
|
+
function runRollup(options) {
|
|
8
|
+
return (0, rxjs_1.from)(rollup.rollup(options)).pipe((0, operators_1.switchMap)((bundle) => {
|
|
9
|
+
const outputOptions = Array.isArray(options.output)
|
|
10
|
+
? options.output
|
|
11
|
+
: [options.output];
|
|
12
|
+
return (0, rxjs_1.from)(Promise.all(outputOptions.map((o) => bundle.write(o))));
|
|
13
|
+
}), (0, operators_1.map)(() => ({ success: true })));
|
|
14
|
+
}
|
|
15
|
+
exports.runRollup = runRollup;
|
|
@@ -21,8 +21,7 @@ function updatePackageJson(options, packageJson) {
|
|
|
21
21
|
});
|
|
22
22
|
packageJson.module = esmExports['.'];
|
|
23
23
|
if (!hasCjsFormat) {
|
|
24
|
-
|
|
25
|
-
packageJson.type = 'module';
|
|
24
|
+
packageJson.type = 'module';
|
|
26
25
|
packageJson.main ??= esmExports['.'];
|
|
27
26
|
}
|
|
28
27
|
if (options.generateExportsField) {
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import * as rollup from 'rollup';
|
|
2
|
-
import {
|
|
2
|
+
import type { ExecutorContext } from '@nx/devkit';
|
|
3
3
|
import { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
|
|
4
|
-
import type { PackageJson } from 'nx/src/utils/package-json';
|
|
5
4
|
import { RollupExecutorOptions } from './schema';
|
|
6
5
|
import { NormalizedRollupExecutorOptions } from './lib/normalize';
|
|
7
|
-
export
|
|
6
|
+
export type RollupExecutorEvent = {
|
|
8
7
|
success: boolean;
|
|
9
|
-
outfile
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, unknown>;
|
|
14
|
-
export declare function createRollupOptions(options: NormalizedRollupExecutorOptions, dependencies: DependentBuildableProjectNode[], context: ExecutorContext, packageJson: PackageJson, sourceRoot: string, npmDeps: string[]): Promise<rollup.RollupOptions>;
|
|
8
|
+
outfile?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function rollupExecutor(rawOptions: RollupExecutorOptions, context: ExecutorContext): AsyncGenerator<RollupExecutorEvent, any, undefined>;
|
|
11
|
+
export declare function createRollupOptions(options: NormalizedRollupExecutorOptions, dependencies: DependentBuildableProjectNode[], context: ExecutorContext, packageJson: any, sourceRoot: string, npmDeps: string[]): rollup.InputOptions[];
|
|
15
12
|
export default rollupExecutor;
|
|
@@ -6,18 +6,20 @@ const rollup = require("rollup");
|
|
|
6
6
|
const peerDepsExternal = require("rollup-plugin-peer-deps-external");
|
|
7
7
|
const plugin_babel_1 = require("@rollup/plugin-babel");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const rxjs_1 = require("rxjs");
|
|
10
|
+
const operators_1 = require("rxjs/operators");
|
|
11
|
+
const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
|
|
9
12
|
const autoprefixer = require("autoprefixer");
|
|
10
13
|
const devkit_1 = require("@nx/devkit");
|
|
11
14
|
const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
|
|
12
15
|
const plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
|
|
13
|
-
const
|
|
16
|
+
const run_rollup_1 = require("./lib/run-rollup");
|
|
14
17
|
const normalize_1 = require("./lib/normalize");
|
|
15
18
|
const analyze_plugin_1 = require("./lib/analyze-plugin");
|
|
16
19
|
const fs_1 = require("../../utils/fs");
|
|
17
20
|
const swc_plugin_1 = require("./lib/swc-plugin");
|
|
18
21
|
const update_package_json_1 = require("./lib/update-package-json");
|
|
19
|
-
const
|
|
20
|
-
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
22
|
+
const type_definitions_1 = require("@nx/js/src/plugins/rollup/type-definitions");
|
|
21
23
|
// These use require because the ES import isn't correct.
|
|
22
24
|
const commonjs = require('@rollup/plugin-commonjs');
|
|
23
25
|
const image = require('@rollup/plugin-image');
|
|
@@ -29,18 +31,17 @@ async function* rollupExecutor(rawOptions, context) {
|
|
|
29
31
|
process.env.NODE_ENV ??= 'production';
|
|
30
32
|
const project = context.projectsConfigurations.projects[context.projectName];
|
|
31
33
|
const sourceRoot = project.sourceRoot;
|
|
32
|
-
const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName, true);
|
|
34
|
+
const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName, true);
|
|
33
35
|
const options = (0, normalize_1.normalizeRollupExecutorOptions)(rawOptions, context, sourceRoot);
|
|
34
36
|
const packageJson = (0, devkit_1.readJsonFile)(options.project);
|
|
35
37
|
const npmDeps = (context.projectGraph.dependencies[context.projectName] ?? [])
|
|
36
38
|
.filter((d) => d.target.startsWith('npm:'))
|
|
37
39
|
.map((d) => d.target.slice(4));
|
|
38
|
-
const rollupOptions =
|
|
40
|
+
const rollupOptions = createRollupOptions(options, dependencies, context, packageJson, sourceRoot, npmDeps);
|
|
39
41
|
const outfile = resolveOutfile(context, options);
|
|
40
42
|
if (options.watch) {
|
|
41
|
-
|
|
42
|
-
return (0,
|
|
43
|
-
const watcher = rollup.watch(rollupOptions);
|
|
43
|
+
const watcher = rollup.watch(rollupOptions);
|
|
44
|
+
return yield* (0, rxjs_for_await_1.eachValueFrom)(new rxjs_1.Observable((obs) => {
|
|
44
45
|
watcher.on('event', (data) => {
|
|
45
46
|
if (data.code === 'START') {
|
|
46
47
|
devkit_1.logger.info(`Bundling ${context.projectName}...`);
|
|
@@ -48,54 +49,51 @@ async function* rollupExecutor(rawOptions, context) {
|
|
|
48
49
|
else if (data.code === 'END') {
|
|
49
50
|
(0, update_package_json_1.updatePackageJson)(options, packageJson);
|
|
50
51
|
devkit_1.logger.info('Bundle complete. Watching for file changes...');
|
|
51
|
-
next({ success: true, outfile });
|
|
52
|
+
obs.next({ success: true, outfile });
|
|
52
53
|
}
|
|
53
54
|
else if (data.code === 'ERROR') {
|
|
54
55
|
devkit_1.logger.error(`Error during bundle: ${data.error.message}`);
|
|
55
|
-
next({ success: false });
|
|
56
|
+
obs.next({ success: false });
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
process.once('SIGTERM', processExitListener);
|
|
62
|
-
process.once('SIGINT', processExitListener);
|
|
63
|
-
process.once('SIGQUIT', processExitListener);
|
|
64
|
-
});
|
|
65
|
-
// endregion
|
|
59
|
+
// Teardown logic. Close watcher when unsubscribed.
|
|
60
|
+
return () => watcher.close();
|
|
61
|
+
}));
|
|
66
62
|
}
|
|
67
63
|
else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (options.deleteOutputPath) {
|
|
73
|
-
(0, fs_1.deleteOutputDir)(context.root, options.outputPath);
|
|
74
|
-
}
|
|
75
|
-
const start = process.hrtime.bigint();
|
|
76
|
-
const bundle = await rollup.rollup(rollupOptions);
|
|
77
|
-
const output = Array.isArray(rollupOptions.output)
|
|
78
|
-
? rollupOptions.output
|
|
79
|
-
: [rollupOptions.output];
|
|
80
|
-
for (const o of output) {
|
|
81
|
-
await bundle.write(o);
|
|
82
|
-
}
|
|
83
|
-
const end = process.hrtime.bigint();
|
|
84
|
-
const duration = `${(Number(end - start) / 1_000_000_000).toFixed(2)}s`;
|
|
85
|
-
(0, update_package_json_1.updatePackageJson)(options, packageJson);
|
|
86
|
-
devkit_1.logger.info(`⚡ Done in ${duration}`);
|
|
87
|
-
return { success: true, outfile };
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
devkit_1.logger.error(`Bundle failed: ${context.projectName}`);
|
|
91
|
-
return { success: false };
|
|
64
|
+
devkit_1.logger.info(`Bundling ${context.projectName}...`);
|
|
65
|
+
// Delete output path before bundling
|
|
66
|
+
if (options.deleteOutputPath) {
|
|
67
|
+
(0, fs_1.deleteOutputDir)(context.root, options.outputPath);
|
|
92
68
|
}
|
|
93
|
-
|
|
69
|
+
const start = process.hrtime.bigint();
|
|
70
|
+
return (0, rxjs_1.from)(rollupOptions)
|
|
71
|
+
.pipe((0, operators_1.concatMap)((opts) => (0, run_rollup_1.runRollup)(opts).pipe((0, operators_1.catchError)((e) => {
|
|
72
|
+
devkit_1.logger.error(`Error during bundle: ${e}`);
|
|
73
|
+
return (0, rxjs_1.of)({ success: false });
|
|
74
|
+
}))), (0, operators_1.scan)((acc, result) => {
|
|
75
|
+
if (!acc.success)
|
|
76
|
+
return acc;
|
|
77
|
+
return result;
|
|
78
|
+
}, { success: true, outfile }), (0, operators_1.last)(), (0, operators_1.tap)({
|
|
79
|
+
next: (result) => {
|
|
80
|
+
if (result.success) {
|
|
81
|
+
const end = process.hrtime.bigint();
|
|
82
|
+
const duration = `${(Number(end - start) / 1000000000).toFixed(2)}s`;
|
|
83
|
+
(0, update_package_json_1.updatePackageJson)(options, packageJson);
|
|
84
|
+
devkit_1.logger.info(`⚡ Done in ${duration}`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
devkit_1.logger.error(`Bundle failed: ${context.projectName}`);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
}))
|
|
91
|
+
.toPromise();
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
94
|
exports.rollupExecutor = rollupExecutor;
|
|
97
95
|
// -----------------------------------------------------------------------------
|
|
98
|
-
|
|
96
|
+
function createRollupOptions(options, dependencies, context, packageJson, sourceRoot, npmDeps) {
|
|
99
97
|
const useBabel = options.compiler === 'babel';
|
|
100
98
|
const useTsc = options.compiler === 'tsc';
|
|
101
99
|
const useSwc = options.compiler === 'swc';
|
|
@@ -105,129 +103,112 @@ async function createRollupOptions(options, dependencies, context, packageJson,
|
|
|
105
103
|
if (!options.format || !options.format.length) {
|
|
106
104
|
options.format = readCompatibleFormats(config);
|
|
107
105
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
extract: options.extractCss,
|
|
144
|
-
autoModules: true,
|
|
145
|
-
plugins: [autoprefixer],
|
|
146
|
-
use: {
|
|
147
|
-
less: {
|
|
148
|
-
javascriptEnabled: options.javascriptEnabled,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
}),
|
|
152
|
-
(0, plugin_node_resolve_1.default)({
|
|
153
|
-
preferBuiltins: true,
|
|
154
|
-
extensions: fileExtensions,
|
|
155
|
-
}),
|
|
156
|
-
useSwc && (0, swc_plugin_1.swc)(),
|
|
157
|
-
useBabel &&
|
|
158
|
-
(0, plugin_babel_1.getBabelInputPlugin)({
|
|
159
|
-
// Lets `@nx/js/babel` preset know that we are packaging.
|
|
160
|
-
caller: {
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
// Ignoring type checks for caller since we have custom attributes
|
|
163
|
-
isNxPackage: true,
|
|
164
|
-
// Always target esnext and let rollup handle cjs
|
|
165
|
-
supportsStaticESM: true,
|
|
166
|
-
isModern: true,
|
|
106
|
+
return options.format.map((format, idx) => {
|
|
107
|
+
// Either we're generating only one format, so we should bundle types
|
|
108
|
+
// OR we are generating dual formats, so only bundle types for CJS.
|
|
109
|
+
const shouldBundleTypes = options.format.length === 1 || format === 'cjs';
|
|
110
|
+
const plugins = [
|
|
111
|
+
copy({
|
|
112
|
+
targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
|
|
113
|
+
}),
|
|
114
|
+
image(),
|
|
115
|
+
json(),
|
|
116
|
+
(useTsc || shouldBundleTypes) &&
|
|
117
|
+
require('rollup-plugin-typescript2')({
|
|
118
|
+
check: !options.skipTypeCheck,
|
|
119
|
+
tsconfig: options.tsConfig,
|
|
120
|
+
tsconfigOverride: {
|
|
121
|
+
compilerOptions: createTsCompilerOptions(config, dependencies, options),
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
shouldBundleTypes &&
|
|
125
|
+
(0, type_definitions_1.typeDefinitions)({
|
|
126
|
+
main: options.main,
|
|
127
|
+
projectRoot: options.projectRoot,
|
|
128
|
+
}),
|
|
129
|
+
peerDepsExternal({
|
|
130
|
+
packageJsonPath: options.project,
|
|
131
|
+
}),
|
|
132
|
+
postcss({
|
|
133
|
+
inject: true,
|
|
134
|
+
extract: options.extractCss,
|
|
135
|
+
autoModules: true,
|
|
136
|
+
plugins: [autoprefixer],
|
|
137
|
+
use: {
|
|
138
|
+
less: {
|
|
139
|
+
javascriptEnabled: options.javascriptEnabled,
|
|
140
|
+
},
|
|
167
141
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
142
|
+
}),
|
|
143
|
+
(0, plugin_node_resolve_1.default)({
|
|
144
|
+
preferBuiltins: true,
|
|
171
145
|
extensions: fileExtensions,
|
|
172
|
-
babelHelpers: 'bundled',
|
|
173
|
-
skipPreflightCheck: true, // pre-flight check may yield false positives and also slows down the build
|
|
174
|
-
exclude: /node_modules/,
|
|
175
146
|
}),
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
external
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const userDefinedRollupConfigs = options.rollupConfig.map((plugin) => (0, config_utils_1.loadConfigFile)(plugin));
|
|
213
|
-
let finalConfig = rollupConfig;
|
|
214
|
-
for (const _config of userDefinedRollupConfigs) {
|
|
215
|
-
const config = await _config;
|
|
216
|
-
if (typeof config === 'function') {
|
|
217
|
-
finalConfig = config(finalConfig, options);
|
|
147
|
+
useSwc && (0, swc_plugin_1.swc)(),
|
|
148
|
+
useBabel &&
|
|
149
|
+
(0, plugin_babel_1.getBabelInputPlugin)({
|
|
150
|
+
// Lets `@nx/js/babel` preset know that we are packaging.
|
|
151
|
+
caller: {
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
// Ignoring type checks for caller since we have custom attributes
|
|
154
|
+
isNxPackage: true,
|
|
155
|
+
// Always target esnext and let rollup handle cjs
|
|
156
|
+
supportsStaticESM: true,
|
|
157
|
+
isModern: true,
|
|
158
|
+
},
|
|
159
|
+
cwd: (0, path_1.join)(context.root, sourceRoot),
|
|
160
|
+
rootMode: options.babelUpwardRootMode ? 'upward' : undefined,
|
|
161
|
+
babelrc: true,
|
|
162
|
+
extensions: fileExtensions,
|
|
163
|
+
babelHelpers: 'bundled',
|
|
164
|
+
skipPreflightCheck: true,
|
|
165
|
+
exclude: /node_modules/,
|
|
166
|
+
plugins: [
|
|
167
|
+
format === 'esm'
|
|
168
|
+
? undefined
|
|
169
|
+
: require.resolve('babel-plugin-transform-async-to-promises'),
|
|
170
|
+
].filter(Boolean),
|
|
171
|
+
}),
|
|
172
|
+
commonjs(),
|
|
173
|
+
(0, analyze_plugin_1.analyze)(),
|
|
174
|
+
];
|
|
175
|
+
let externalPackages = [
|
|
176
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
177
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
178
|
+
]; // If external is set to none, include all dependencies and peerDependencies in externalPackages
|
|
179
|
+
if (options.external === 'all') {
|
|
180
|
+
externalPackages = externalPackages
|
|
181
|
+
.concat(dependencies.map((d) => d.name))
|
|
182
|
+
.concat(npmDeps);
|
|
218
183
|
}
|
|
219
|
-
else {
|
|
220
|
-
|
|
221
|
-
...finalConfig,
|
|
222
|
-
...config,
|
|
223
|
-
plugins: [
|
|
224
|
-
...(finalConfig.plugins?.length > 0 ? finalConfig.plugins : []),
|
|
225
|
-
...(config.plugins?.length > 0 ? config.plugins : []),
|
|
226
|
-
],
|
|
227
|
-
};
|
|
184
|
+
else if (Array.isArray(options.external) && options.external.length > 0) {
|
|
185
|
+
externalPackages = externalPackages.concat(options.external);
|
|
228
186
|
}
|
|
229
|
-
|
|
230
|
-
|
|
187
|
+
externalPackages = [...new Set(externalPackages)];
|
|
188
|
+
const mainEntryFileName = options.outputFileName || options.main;
|
|
189
|
+
const input = {};
|
|
190
|
+
input[(0, path_1.parse)(mainEntryFileName).name] = options.main;
|
|
191
|
+
options.additionalEntryPoints.forEach((entry) => {
|
|
192
|
+
input[(0, path_1.parse)(entry).name] = entry;
|
|
193
|
+
});
|
|
194
|
+
const rollupConfig = {
|
|
195
|
+
input,
|
|
196
|
+
output: {
|
|
197
|
+
format,
|
|
198
|
+
dir: `${options.outputPath}`,
|
|
199
|
+
name: (0, devkit_1.names)(context.projectName).className,
|
|
200
|
+
entryFileNames: `[name].${format}.js`,
|
|
201
|
+
chunkFileNames: `[name].${format}.js`,
|
|
202
|
+
},
|
|
203
|
+
external: (id) => {
|
|
204
|
+
return externalPackages.some((name) => id === name || id.startsWith(`${name}/`)); // Could be a deep import
|
|
205
|
+
},
|
|
206
|
+
plugins,
|
|
207
|
+
};
|
|
208
|
+
return options.rollupConfig.reduce((currentConfig, plugin) => {
|
|
209
|
+
return require(plugin)(currentConfig, options);
|
|
210
|
+
}, rollupConfig);
|
|
211
|
+
});
|
|
231
212
|
}
|
|
232
213
|
exports.createRollupOptions = createRollupOptions;
|
|
233
214
|
function createTsCompilerOptions(config, dependencies, options) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Tree
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
2
|
import { RollupProjectSchema } from './schema';
|
|
3
|
-
export declare function configurationGenerator(tree: Tree, options: RollupProjectSchema): Promise<GeneratorCallback>;
|
|
3
|
+
export declare function configurationGenerator(tree: Tree, options: RollupProjectSchema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
4
4
|
export default configurationGenerator;
|
|
@@ -4,21 +4,16 @@ exports.configurationGenerator = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
6
6
|
const init_1 = require("../init/init");
|
|
7
|
-
const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
|
|
8
|
-
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
9
7
|
async function configurationGenerator(tree, options) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
8
|
+
const task = await (0, init_1.rollupInitGenerator)(tree, {
|
|
9
|
+
...options,
|
|
10
|
+
skipFormat: true,
|
|
11
|
+
});
|
|
15
12
|
options.buildTarget ??= 'build';
|
|
16
13
|
checkForTargetConflicts(tree, options);
|
|
17
14
|
addBuildTarget(tree, options);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
15
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
16
|
+
return task;
|
|
22
17
|
}
|
|
23
18
|
exports.configurationGenerator = configurationGenerator;
|
|
24
19
|
function checkForTargetConflicts(tree, options) {
|
|
@@ -30,7 +25,6 @@ function checkForTargetConflicts(tree, options) {
|
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
function addBuildTarget(tree, options) {
|
|
33
|
-
(0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/rollup:rollup', options.buildTarget);
|
|
34
28
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
35
29
|
const packageJsonPath = (0, devkit_1.joinPathFragments)(project.root, 'package.json');
|
|
36
30
|
if (!tree.exists(packageJsonPath)) {
|
|
@@ -2,38 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rollupInitGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const versions_1 = require("
|
|
6
|
-
const
|
|
7
|
-
const plugin_1 = require("../../plugins/plugin");
|
|
8
|
-
function addPlugin(tree) {
|
|
9
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
10
|
-
nxJson.plugins ??= [];
|
|
11
|
-
for (const plugin of nxJson.plugins) {
|
|
12
|
-
if (typeof plugin === 'string'
|
|
13
|
-
? plugin === '@nx/rollup/plugin'
|
|
14
|
-
: plugin.plugin === '@nx/rollup/plugin') {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
nxJson.plugins.push({
|
|
19
|
-
plugin: '@nx/rollup/plugin',
|
|
20
|
-
options: {
|
|
21
|
-
buildTargetName: 'build',
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
25
|
-
}
|
|
5
|
+
const versions_1 = require("@nx/js/src/utils/versions");
|
|
6
|
+
const versions_2 = require("../../utils/versions");
|
|
26
7
|
async function rollupInitGenerator(tree, schema) {
|
|
27
|
-
let task
|
|
28
|
-
if (
|
|
29
|
-
task = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
8
|
+
let task;
|
|
9
|
+
if (schema.compiler === 'swc') {
|
|
10
|
+
task = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
11
|
+
'@nx/rollup': versions_2.nxVersion,
|
|
12
|
+
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
13
|
+
'@swc/core': versions_1.swcCoreVersion,
|
|
14
|
+
'swc-loader': versions_2.swcLoaderVersion,
|
|
15
|
+
});
|
|
34
16
|
}
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
else {
|
|
18
|
+
task = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
19
|
+
'@nx/rollup': versions_2.nxVersion,
|
|
20
|
+
tslib: versions_2.tsLibVersion,
|
|
21
|
+
});
|
|
37
22
|
}
|
|
38
23
|
if (!schema.skipFormat) {
|
|
39
24
|
await (0, devkit_1.formatFiles)(tree);
|
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"$id": "NxWebpackInit",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"title": "Init Webpack Plugin",
|
|
6
6
|
"description": "Init Webpack Plugin.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
+
"compiler": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"enum": ["babel", "swc", "tsc"],
|
|
12
|
+
"description": "The compiler to initialize for.",
|
|
13
|
+
"default": "babel"
|
|
14
|
+
},
|
|
9
15
|
"skipFormat": {
|
|
10
16
|
"description": "Skip formatting files.",
|
|
11
17
|
"type": "boolean",
|
|
12
18
|
"default": false
|
|
13
|
-
},
|
|
14
|
-
"skipPackageJson": {
|
|
15
|
-
"description": "Do not add dependencies to `package.json`.",
|
|
16
|
-
"type": "boolean",
|
|
17
|
-
"default": false
|
|
18
|
-
},
|
|
19
|
-
"keepExistingVersions": {
|
|
20
|
-
"type": "boolean",
|
|
21
|
-
"x-priority": "internal",
|
|
22
|
-
"description": "Keep existing dependencies versions",
|
|
23
|
-
"default": false
|
|
24
|
-
},
|
|
25
|
-
"updatePackageScripts": {
|
|
26
|
-
"type": "boolean",
|
|
27
|
-
"x-priority": "internal",
|
|
28
|
-
"description": "Update `package.json` scripts with inferred targets",
|
|
29
|
-
"default": false
|
|
30
19
|
}
|
|
31
20
|
},
|
|
32
21
|
"required": []
|
package/src/utils/versions.d.ts
CHANGED
package/src/utils/versions.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.swcLoaderVersion = '0.1.15';
|
|
6
6
|
exports.tsLibVersion = '^2.3.0';
|
|
7
|
-
exports.coreJsVersion = '^3.36.1';
|
package/plugin.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createNodes, RollupPluginOptions } from './src/plugins/plugin';
|
package/plugin.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = void 0;
|
|
4
|
-
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
-
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
package/src/plugins/plugin.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type CreateDependencies, type CreateNodes } from '@nx/devkit';
|
|
2
|
-
export declare const createDependencies: CreateDependencies;
|
|
3
|
-
export interface RollupPluginOptions {
|
|
4
|
-
buildTargetName?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const createNodes: CreateNodes<RollupPluginOptions>;
|
package/src/plugins/plugin.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
-
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
9
|
-
const js_1 = require("@nx/js");
|
|
10
|
-
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
11
|
-
const loadConfigFile = require("rollup/dist/loadConfigFile");
|
|
12
|
-
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'rollup.hash');
|
|
13
|
-
const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
|
14
|
-
const calculatedTargets = {};
|
|
15
|
-
function readTargetsCache() {
|
|
16
|
-
return (0, devkit_1.readJsonFile)(cachePath);
|
|
17
|
-
}
|
|
18
|
-
function writeTargetsToCache(targets) {
|
|
19
|
-
(0, devkit_1.writeJsonFile)(cachePath, targets);
|
|
20
|
-
}
|
|
21
|
-
const createDependencies = () => {
|
|
22
|
-
writeTargetsToCache(calculatedTargets);
|
|
23
|
-
return [];
|
|
24
|
-
};
|
|
25
|
-
exports.createDependencies = createDependencies;
|
|
26
|
-
exports.createNodes = [
|
|
27
|
-
'**/rollup.config.{js,cjs,mjs}',
|
|
28
|
-
async (configFilePath, options, context) => {
|
|
29
|
-
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
30
|
-
const fullyQualifiedProjectRoot = (0, path_1.join)(context.workspaceRoot, projectRoot);
|
|
31
|
-
// Do not create a project if package.json and project.json do not exist
|
|
32
|
-
const siblingFiles = (0, fs_1.readdirSync)(fullyQualifiedProjectRoot);
|
|
33
|
-
if (!siblingFiles.includes('package.json') &&
|
|
34
|
-
!siblingFiles.includes('project.json')) {
|
|
35
|
-
return {};
|
|
36
|
-
}
|
|
37
|
-
options = normalizeOptions(options);
|
|
38
|
-
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
|
|
39
|
-
(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
|
|
40
|
-
]);
|
|
41
|
-
const targets = targetsCache[hash]
|
|
42
|
-
? targetsCache[hash]
|
|
43
|
-
: await buildRollupTarget(configFilePath, projectRoot, options, context);
|
|
44
|
-
calculatedTargets[hash] = targets;
|
|
45
|
-
return {
|
|
46
|
-
projects: {
|
|
47
|
-
[projectRoot]: {
|
|
48
|
-
root: projectRoot,
|
|
49
|
-
targets,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
async function buildRollupTarget(configFilePath, projectRoot, options, context) {
|
|
56
|
-
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
57
|
-
const rollupConfig = (await loadConfigFile((0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath))).options;
|
|
58
|
-
const outputs = getOutputs(rollupConfig, projectRoot);
|
|
59
|
-
const targets = {};
|
|
60
|
-
targets[options.buildTargetName] = {
|
|
61
|
-
command: `rollup -c ${(0, path_1.basename)(configFilePath)}`,
|
|
62
|
-
options: { cwd: projectRoot },
|
|
63
|
-
cache: true,
|
|
64
|
-
dependsOn: [`^${options.buildTargetName}`],
|
|
65
|
-
inputs: [
|
|
66
|
-
...('production' in namedInputs
|
|
67
|
-
? ['production', '^production']
|
|
68
|
-
: ['default', '^default']),
|
|
69
|
-
],
|
|
70
|
-
outputs,
|
|
71
|
-
};
|
|
72
|
-
return targets;
|
|
73
|
-
}
|
|
74
|
-
function getOutputs(rollupConfigs, projectRoot) {
|
|
75
|
-
const outputs = new Set();
|
|
76
|
-
for (const rollupConfig of rollupConfigs) {
|
|
77
|
-
if (rollupConfig.output) {
|
|
78
|
-
const rollupConfigOutputs = [];
|
|
79
|
-
if (Array.isArray(rollupConfig.output)) {
|
|
80
|
-
rollupConfigOutputs.push(...rollupConfig.output);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
rollupConfigOutputs.push(rollupConfig.output);
|
|
84
|
-
}
|
|
85
|
-
for (const output of rollupConfigOutputs) {
|
|
86
|
-
const outputPathFromConfig = output.dir
|
|
87
|
-
? output.dir
|
|
88
|
-
: output.file
|
|
89
|
-
? (0, path_1.dirname)(output.file)
|
|
90
|
-
: 'dist';
|
|
91
|
-
const outputPath = projectRoot === '.'
|
|
92
|
-
? (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, outputPathFromConfig)
|
|
93
|
-
: (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, projectRoot, outputPathFromConfig);
|
|
94
|
-
outputs.add(outputPath);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return Array.from(outputs);
|
|
99
|
-
}
|
|
100
|
-
function normalizeOptions(options) {
|
|
101
|
-
options ??= {};
|
|
102
|
-
options.buildTargetName ??= 'build';
|
|
103
|
-
return options;
|
|
104
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureDependencies = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const versions_1 = require("@nx/js/src/utils/versions");
|
|
6
|
-
const versions_2 = require("./versions");
|
|
7
|
-
function ensureDependencies(tree, options) {
|
|
8
|
-
switch (options.compiler) {
|
|
9
|
-
case 'swc':
|
|
10
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
11
|
-
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
12
|
-
'@swc/core': versions_1.swcCoreVersion,
|
|
13
|
-
'swc-loader': versions_2.swcLoaderVersion,
|
|
14
|
-
});
|
|
15
|
-
case 'babel':
|
|
16
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
17
|
-
'core-js': versions_2.coreJsVersion, // needed for preset-env to work
|
|
18
|
-
tslib: versions_2.tsLibVersion,
|
|
19
|
-
});
|
|
20
|
-
default:
|
|
21
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { tslib: versions_2.tsLibVersion });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.ensureDependencies = ensureDependencies;
|