@nx/rollup 18.1.1 → 18.2.0-beta.0

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": "18.1.1",
3
+ "version": "18.2.0-beta.0",
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,11 +43,10 @@
43
43
  "rollup-plugin-peer-deps-external": "^2.2.4",
44
44
  "rollup-plugin-postcss": "^4.0.1",
45
45
  "rollup-plugin-typescript2": "0.36.0",
46
- "rxjs": "^7.8.0",
47
46
  "tslib": "^2.3.0",
48
- "@nx/devkit": "18.1.1",
49
- "@nx/js": "18.1.1",
50
- "@nrwl/rollup": "18.1.1"
47
+ "@nx/devkit": "18.2.0-beta.0",
48
+ "@nx/js": "18.2.0-beta.0",
49
+ "@nrwl/rollup": "18.2.0-beta.0"
51
50
  },
52
51
  "publishConfig": {
53
52
  "access": "public"
@@ -1,13 +1,15 @@
1
1
  import * as rollup from 'rollup';
2
- import type { ExecutorContext } from '@nx/devkit';
2
+ import { type ExecutorContext } from '@nx/devkit';
3
3
  import { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
4
4
  import type { PackageJson } from 'nx/src/utils/package-json';
5
5
  import { RollupExecutorOptions } from './schema';
6
6
  import { NormalizedRollupExecutorOptions } from './lib/normalize';
7
- export type RollupExecutorEvent = {
7
+ export declare function rollupExecutor(rawOptions: RollupExecutorOptions, context: ExecutorContext): AsyncGenerator<never, AsyncIterable<unknown> | {
8
8
  success: boolean;
9
- outfile?: string;
10
- };
11
- export declare function rollupExecutor(rawOptions: RollupExecutorOptions, context: ExecutorContext): AsyncGenerator<RollupExecutorEvent, any, undefined>;
12
- export declare function createRollupOptions(options: NormalizedRollupExecutorOptions, dependencies: DependentBuildableProjectNode[], context: ExecutorContext, packageJson: PackageJson, sourceRoot: string, npmDeps: string[]): Promise<rollup.InputOptions[]>;
9
+ outfile: string;
10
+ } | {
11
+ success: boolean;
12
+ outfile?: undefined;
13
+ }, unknown>;
14
+ export declare function createRollupOptions(options: NormalizedRollupExecutorOptions, dependencies: DependentBuildableProjectNode[], context: ExecutorContext, packageJson: PackageJson, sourceRoot: string, npmDeps: string[]): Promise<rollup.RollupOptions>;
13
15
  export default rollupExecutor;
@@ -6,21 +6,18 @@ 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");
12
9
  const autoprefixer = require("autoprefixer");
13
10
  const devkit_1 = require("@nx/devkit");
14
11
  const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
15
12
  const plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
16
13
  const type_definitions_1 = require("@nx/js/src/plugins/rollup/type-definitions");
17
- const run_rollup_1 = require("./lib/run-rollup");
18
14
  const normalize_1 = require("./lib/normalize");
19
15
  const analyze_plugin_1 = require("./lib/analyze-plugin");
20
16
  const fs_1 = require("../../utils/fs");
21
17
  const swc_plugin_1 = require("./lib/swc-plugin");
22
18
  const update_package_json_1 = require("./lib/update-package-json");
23
19
  const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
20
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
24
21
  // These use require because the ES import isn't correct.
25
22
  const commonjs = require('@rollup/plugin-commonjs');
26
23
  const image = require('@rollup/plugin-image');
@@ -32,7 +29,7 @@ async function* rollupExecutor(rawOptions, context) {
32
29
  process.env.NODE_ENV ??= 'production';
33
30
  const project = context.projectsConfigurations.projects[context.projectName];
34
31
  const sourceRoot = project.sourceRoot;
35
- const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName, true);
32
+ const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName, true);
36
33
  const options = (0, normalize_1.normalizeRollupExecutorOptions)(rawOptions, context, sourceRoot);
37
34
  const packageJson = (0, devkit_1.readJsonFile)(options.project);
38
35
  const npmDeps = (context.projectGraph.dependencies[context.projectName] ?? [])
@@ -41,8 +38,9 @@ async function* rollupExecutor(rawOptions, context) {
41
38
  const rollupOptions = await createRollupOptions(options, dependencies, context, packageJson, sourceRoot, npmDeps);
42
39
  const outfile = resolveOutfile(context, options);
43
40
  if (options.watch) {
44
- const watcher = rollup.watch(rollupOptions);
45
- return yield* (0, rxjs_for_await_1.eachValueFrom)(new rxjs_1.Observable((obs) => {
41
+ // region Watch build
42
+ return (0, async_iterable_1.createAsyncIterable)(({ next }) => {
43
+ const watcher = rollup.watch(rollupOptions);
46
44
  watcher.on('event', (data) => {
47
45
  if (data.code === 'START') {
48
46
  devkit_1.logger.info(`Bundling ${context.projectName}...`);
@@ -50,46 +48,49 @@ async function* rollupExecutor(rawOptions, context) {
50
48
  else if (data.code === 'END') {
51
49
  (0, update_package_json_1.updatePackageJson)(options, packageJson);
52
50
  devkit_1.logger.info('Bundle complete. Watching for file changes...');
53
- obs.next({ success: true, outfile });
51
+ next({ success: true, outfile });
54
52
  }
55
53
  else if (data.code === 'ERROR') {
56
54
  devkit_1.logger.error(`Error during bundle: ${data.error.message}`);
57
- obs.next({ success: false });
55
+ next({ success: false });
58
56
  }
59
57
  });
60
- // Teardown logic. Close watcher when unsubscribed.
61
- return () => watcher.close();
62
- }));
58
+ const processExitListener = (signal) => () => {
59
+ watcher.close();
60
+ };
61
+ process.once('SIGTERM', processExitListener);
62
+ process.once('SIGINT', processExitListener);
63
+ process.once('SIGQUIT', processExitListener);
64
+ });
65
+ // endregion
63
66
  }
64
67
  else {
65
- devkit_1.logger.info(`Bundling ${context.projectName}...`);
66
- // Delete output path before bundling
67
- if (options.deleteOutputPath) {
68
- (0, fs_1.deleteOutputDir)(context.root, options.outputPath);
68
+ // region Single build
69
+ try {
70
+ devkit_1.logger.info(`Bundling ${context.projectName}...`);
71
+ // Delete output path before bundling
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 };
69
88
  }
70
- const start = process.hrtime.bigint();
71
- return (0, rxjs_1.from)(rollupOptions)
72
- .pipe((0, operators_1.concatMap)((opts) => (0, run_rollup_1.runRollup)(opts).pipe((0, operators_1.catchError)((e) => {
73
- devkit_1.logger.error(`Error during bundle: ${e}`);
74
- return (0, rxjs_1.of)({ success: false });
75
- }))), (0, operators_1.scan)((acc, result) => {
76
- if (!acc.success)
77
- return acc;
78
- return result;
79
- }, { success: true, outfile }), (0, operators_1.last)(), (0, operators_1.tap)({
80
- next: (result) => {
81
- if (result.success) {
82
- const end = process.hrtime.bigint();
83
- const duration = `${(Number(end - start) / 1000000000).toFixed(2)}s`;
84
- (0, update_package_json_1.updatePackageJson)(options, packageJson);
85
- devkit_1.logger.info(`⚡ Done in ${duration}`);
86
- }
87
- else {
88
- devkit_1.logger.error(`Bundle failed: ${context.projectName}`);
89
- }
90
- },
91
- }))
92
- .toPromise();
89
+ catch {
90
+ devkit_1.logger.error(`Bundle failed: ${context.projectName}`);
91
+ return { success: false };
92
+ }
93
+ // endregion
93
94
  }
94
95
  }
95
96
  exports.rollupExecutor = rollupExecutor;
@@ -116,133 +117,117 @@ async function createRollupOptions(options, dependencies, context, packageJson,
116
117
  }
117
118
  options.format = ['cjs'];
118
119
  }
119
- const _rollupOptions = options.format.map(async (format, idx) => {
120
- // Either we're generating only one format, so we should bundle types
121
- // OR we are generating dual formats, so only bundle types for CJS.
122
- const shouldBundleTypes = options.format.length === 1 || format === 'cjs';
123
- const plugins = [
124
- copy({
125
- targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
126
- }),
127
- image(),
128
- json(),
129
- (useTsc || shouldBundleTypes) &&
130
- require('rollup-plugin-typescript2')({
131
- check: !options.skipTypeCheck,
132
- tsconfig: options.tsConfig,
133
- tsconfigOverride: {
134
- compilerOptions: createTsCompilerOptions(config, dependencies, options),
135
- },
136
- }),
137
- shouldBundleTypes &&
138
- (0, type_definitions_1.typeDefinitions)({
139
- main: options.main,
140
- projectRoot: options.projectRoot,
141
- }),
142
- peerDepsExternal({
143
- packageJsonPath: options.project,
144
- }),
145
- postcss({
146
- inject: true,
147
- extract: options.extractCss,
148
- autoModules: true,
149
- plugins: [autoprefixer],
150
- use: {
151
- less: {
152
- javascriptEnabled: options.javascriptEnabled,
153
- },
120
+ const plugins = [
121
+ copy({
122
+ targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
123
+ }),
124
+ image(),
125
+ json(),
126
+ // Needed to generate type definitions, even if we're using babel or swc.
127
+ require('rollup-plugin-typescript2')({
128
+ check: !options.skipTypeCheck,
129
+ tsconfig: options.tsConfig,
130
+ tsconfigOverride: {
131
+ compilerOptions: createTsCompilerOptions(config, dependencies, options),
132
+ },
133
+ }),
134
+ (0, type_definitions_1.typeDefinitions)({
135
+ main: options.main,
136
+ projectRoot: options.projectRoot,
137
+ }),
138
+ peerDepsExternal({
139
+ packageJsonPath: options.project,
140
+ }),
141
+ postcss({
142
+ inject: true,
143
+ extract: options.extractCss,
144
+ autoModules: true,
145
+ plugins: [autoprefixer],
146
+ use: {
147
+ less: {
148
+ javascriptEnabled: options.javascriptEnabled,
154
149
  },
155
- }),
156
- (0, plugin_node_resolve_1.default)({
157
- preferBuiltins: true,
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,
167
+ },
168
+ cwd: (0, path_1.join)(context.root, sourceRoot),
169
+ rootMode: options.babelUpwardRootMode ? 'upward' : undefined,
170
+ babelrc: true,
158
171
  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/,
159
175
  }),
160
- useSwc && (0, swc_plugin_1.swc)(),
161
- useBabel &&
162
- (0, plugin_babel_1.getBabelInputPlugin)({
163
- // Lets `@nx/js/babel` preset know that we are packaging.
164
- caller: {
165
- // @ts-ignore
166
- // Ignoring type checks for caller since we have custom attributes
167
- isNxPackage: true,
168
- // Always target esnext and let rollup handle cjs
169
- supportsStaticESM: true,
170
- isModern: true,
171
- },
172
- cwd: (0, path_1.join)(context.root, sourceRoot),
173
- rootMode: options.babelUpwardRootMode ? 'upward' : undefined,
174
- babelrc: true,
175
- extensions: fileExtensions,
176
- babelHelpers: 'bundled',
177
- skipPreflightCheck: true, // pre-flight check may yield false positives and also slows down the build
178
- exclude: /node_modules/,
179
- plugins: [
180
- format === 'esm'
181
- ? undefined
182
- : require.resolve('babel-plugin-transform-async-to-promises'),
183
- ].filter(Boolean),
184
- }),
185
- commonjs(),
186
- (0, analyze_plugin_1.analyze)(),
187
- ];
188
- let externalPackages = [
189
- ...Object.keys(packageJson.dependencies || {}),
190
- ...Object.keys(packageJson.peerDependencies || {}),
191
- ]; // If external is set to none, include all dependencies and peerDependencies in externalPackages
192
- if (options.external === 'all') {
193
- externalPackages = externalPackages
194
- .concat(dependencies.map((d) => d.name))
195
- .concat(npmDeps);
176
+ commonjs(),
177
+ (0, analyze_plugin_1.analyze)(),
178
+ ];
179
+ let externalPackages = [
180
+ ...Object.keys(packageJson.dependencies || {}),
181
+ ...Object.keys(packageJson.peerDependencies || {}),
182
+ ]; // If external is set to none, include all dependencies and peerDependencies in externalPackages
183
+ if (options.external === 'all') {
184
+ externalPackages = externalPackages
185
+ .concat(dependencies.map((d) => d.name))
186
+ .concat(npmDeps);
187
+ }
188
+ else if (Array.isArray(options.external) && options.external.length > 0) {
189
+ externalPackages = externalPackages.concat(options.external);
190
+ }
191
+ externalPackages = [...new Set(externalPackages)];
192
+ const mainEntryFileName = options.outputFileName || options.main;
193
+ const input = {};
194
+ input[(0, path_1.parse)(mainEntryFileName).name] = options.main;
195
+ options.additionalEntryPoints.forEach((entry) => {
196
+ input[(0, path_1.parse)(entry).name] = entry;
197
+ });
198
+ const rollupConfig = {
199
+ input,
200
+ output: options.format.map((format) => ({
201
+ format,
202
+ dir: `${options.outputPath}`,
203
+ name: (0, devkit_1.names)(context.projectName).className,
204
+ entryFileNames: `[name].${format}.js`,
205
+ chunkFileNames: `[name].${format}.js`,
206
+ })),
207
+ external: (id) => {
208
+ return externalPackages.some((name) => id === name || id.startsWith(`${name}/`)); // Could be a deep import
209
+ },
210
+ plugins,
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);
196
218
  }
197
- else if (Array.isArray(options.external) && options.external.length > 0) {
198
- externalPackages = externalPackages.concat(options.external);
219
+ else {
220
+ finalConfig = {
221
+ ...finalConfig,
222
+ ...config,
223
+ plugins: [
224
+ ...(finalConfig.plugins?.length > 0 ? finalConfig.plugins : []),
225
+ ...(config.plugins?.length > 0 ? config.plugins : []),
226
+ ],
227
+ };
199
228
  }
200
- externalPackages = [...new Set(externalPackages)];
201
- const mainEntryFileName = options.outputFileName || options.main;
202
- const input = {};
203
- input[(0, path_1.parse)(mainEntryFileName).name] = options.main;
204
- options.additionalEntryPoints.forEach((entry) => {
205
- input[(0, path_1.parse)(entry).name] = entry;
206
- });
207
- const rollupConfig = {
208
- input,
209
- output: {
210
- format,
211
- dir: `${options.outputPath}`,
212
- name: (0, devkit_1.names)(context.projectName).className,
213
- entryFileNames: `[name].${format}.js`,
214
- chunkFileNames: `[name].${format}.js`,
215
- },
216
- external: (id) => {
217
- return externalPackages.some((name) => id === name || id.startsWith(`${name}/`)); // Could be a deep import
218
- },
219
- plugins,
220
- };
221
- const userDefinedRollupConfigs = options.rollupConfig.map((plugin) => (0, config_utils_1.loadConfigFile)(plugin));
222
- let finalConfig = rollupConfig;
223
- for (const _config of userDefinedRollupConfigs) {
224
- const config = await _config;
225
- if (typeof config === 'function') {
226
- finalConfig = config(finalConfig, options);
227
- }
228
- else {
229
- finalConfig = {
230
- ...finalConfig,
231
- ...config,
232
- plugins: [
233
- ...(finalConfig.plugins?.length > 0 ? finalConfig.plugins : []),
234
- ...(config.plugins?.length > 0 ? config.plugins : []),
235
- ],
236
- };
237
- }
238
- }
239
- return finalConfig;
240
- });
241
- const rollupOptions = [];
242
- for (const rollupOption of _rollupOptions) {
243
- rollupOptions.push(await rollupOption);
244
229
  }
245
- return rollupOptions;
230
+ return finalConfig;
246
231
  }
247
232
  exports.createRollupOptions = createRollupOptions;
248
233
  function createTsCompilerOptions(config, dependencies, options) {
@@ -5,13 +5,20 @@ const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("@nx/js/src/utils/versions");
6
6
  const versions_2 = require("./versions");
7
7
  function ensureDependencies(tree, options) {
8
- if (options.compiler === 'swc') {
9
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
10
- '@swc/helpers': versions_1.swcHelpersVersion,
11
- '@swc/core': versions_1.swcCoreVersion,
12
- 'swc-loader': versions_2.swcLoaderVersion,
13
- });
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 });
14
22
  }
15
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { tslib: versions_2.tsLibVersion });
16
23
  }
17
24
  exports.ensureDependencies = ensureDependencies;
@@ -1,3 +1,4 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const swcLoaderVersion = "0.1.15";
3
3
  export declare const tsLibVersion = "^2.3.0";
4
+ export declare const coreJsVersion = "^3.36.1";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
3
+ exports.coreJsVersion = 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';
@@ -1,4 +0,0 @@
1
- import * as rollup from 'rollup';
2
- export declare function runRollup(options: rollup.RollupOptions): import("rxjs").Observable<{
3
- success: boolean;
4
- }>;
@@ -1,15 +0,0 @@
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;