@nx/rollup 0.0.0-pr-22179-271588f

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.
Files changed (48) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/executors.json +9 -0
  4. package/generators.json +19 -0
  5. package/index.d.ts +7 -0
  6. package/index.js +11 -0
  7. package/migrations.json +29 -0
  8. package/package.json +64 -0
  9. package/plugin.d.ts +1 -0
  10. package/plugin.js +5 -0
  11. package/src/executors/rollup/lib/analyze-plugin.d.ts +4 -0
  12. package/src/executors/rollup/lib/analyze-plugin.js +25 -0
  13. package/src/executors/rollup/lib/normalize.d.ts +11 -0
  14. package/src/executors/rollup/lib/normalize.js +86 -0
  15. package/src/executors/rollup/lib/run-rollup.d.ts +4 -0
  16. package/src/executors/rollup/lib/run-rollup.js +15 -0
  17. package/src/executors/rollup/lib/swc-plugin.d.ts +2 -0
  18. package/src/executors/rollup/lib/swc-plugin.js +20 -0
  19. package/src/executors/rollup/lib/update-package-json.d.ts +3 -0
  20. package/src/executors/rollup/lib/update-package-json.js +93 -0
  21. package/src/executors/rollup/rollup.impl.d.ts +13 -0
  22. package/src/executors/rollup/rollup.impl.js +288 -0
  23. package/src/executors/rollup/schema.d.ts +36 -0
  24. package/src/executors/rollup/schema.json +182 -0
  25. package/src/generators/configuration/configuration.d.ts +4 -0
  26. package/src/generators/configuration/configuration.js +94 -0
  27. package/src/generators/configuration/schema.d.ts +14 -0
  28. package/src/generators/configuration/schema.json +86 -0
  29. package/src/generators/init/init.d.ts +4 -0
  30. package/src/generators/init/init.js +44 -0
  31. package/src/generators/init/schema.d.ts +7 -0
  32. package/src/generators/init/schema.json +33 -0
  33. package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
  34. package/src/migrations/update-15-0-0/add-babel-inputs.js +9 -0
  35. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  36. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  37. 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 +2 -0
  38. package/src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag.js +17 -0
  39. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
  40. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +29 -0
  41. package/src/plugins/plugin.d.ts +6 -0
  42. package/src/plugins/plugin.js +104 -0
  43. package/src/utils/ensure-dependencies.d.ts +5 -0
  44. package/src/utils/ensure-dependencies.js +17 -0
  45. package/src/utils/fs.d.ts +4 -0
  46. package/src/utils/fs.js +16 -0
  47. package/src/utils/versions.d.ts +3 -0
  48. package/src/utils/versions.js +6 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017-2023 Narwhal Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
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>
7
+
8
+ <div style="text-align: center;">
9
+
10
+ [![CircleCI](https://circleci.com/gh/nrwl/nx.svg?style=svg)](https://circleci.com/gh/nrwl/nx)
11
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
12
+ [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nx/workspace)
13
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
14
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
15
+ [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
16
+ [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
17
+
18
+ </div>
19
+
20
+
21
+ <hr>
22
+
23
+ # Nx: Smart Monorepos · Fast CI
24
+
25
+ Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
26
+
27
+ This package is a [Rollup plugin for Nx](https://nx.dev/packages/rollup).
28
+
29
+ ## Getting Started
30
+
31
+ ### Creating an Nx Workspace
32
+
33
+ **Using `npx`**
34
+
35
+ ```bash
36
+ npx create-nx-workspace
37
+ ```
38
+
39
+ **Using `npm init`**
40
+
41
+ ```bash
42
+ npm init nx-workspace
43
+ ```
44
+
45
+ **Using `yarn create`**
46
+
47
+ ```bash
48
+ yarn create nx-workspace
49
+ ```
50
+
51
+ ### Adding Nx to an Existing Repository
52
+
53
+ Run:
54
+
55
+ ```bash
56
+ npx nx@latest init
57
+ ```
58
+
59
+ ## Documentation & Resources
60
+
61
+ - [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
62
+ - [Intro to Nx](https://nx.dev/getting-started/intro)
63
+ - [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
64
+ - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
65
+
66
+ <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 Monorepos · Fast CI"></a></p>
68
+
package/executors.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "executors": {
3
+ "rollup": {
4
+ "implementation": "./src/executors/rollup/rollup.impl",
5
+ "schema": "./src/executors/rollup/schema.json",
6
+ "description": "Bundle a package using Rollup."
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "Nx rollup",
3
+ "version": "0.1",
4
+ "generators": {
5
+ "init": {
6
+ "factory": "./src/generators/init/init#rollupInitGenerator",
7
+ "schema": "./src/generators/init/schema.json",
8
+ "description": "Initialize the `@nrwl/rollup` plugin.",
9
+ "aliases": ["ng-add"],
10
+ "hidden": true
11
+ },
12
+ "configuration": {
13
+ "aliases": ["rollup-project"],
14
+ "factory": "./src/generators/configuration/configuration",
15
+ "schema": "./src/generators/configuration/schema.json",
16
+ "description": "Add rollup configuration to a project."
17
+ }
18
+ }
19
+ }
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { configurationGenerator } from './src/generators/configuration/configuration';
2
+ export { configurationGenerator };
3
+ /** @deprecated Use `configurationGenerator` instead. */
4
+ export declare const rollupProjectGenerator: typeof configurationGenerator;
5
+ export * from './src/generators/init/init';
6
+ export type { AssetGlobPattern, Globals, RollupExecutorOptions, } from './src/executors/rollup/schema';
7
+ export * from './src/executors/rollup/rollup.impl';
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rollupProjectGenerator = exports.configurationGenerator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const configuration_1 = require("./src/generators/configuration/configuration");
6
+ Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
7
+ // Exported for backwards compatibility in case a plugin is using the old name.
8
+ /** @deprecated Use `configurationGenerator` instead. */
9
+ exports.rollupProjectGenerator = configuration_1.configurationGenerator;
10
+ tslib_1.__exportStar(require("./src/generators/init/init"), exports);
11
+ tslib_1.__exportStar(require("./src/executors/rollup/rollup.impl"), exports);
@@ -0,0 +1,29 @@
1
+ {
2
+ "generators": {
3
+ "add-babel-inputs": {
4
+ "cli": "nx",
5
+ "version": "15.0.0-beta.0",
6
+ "description": "Adds babel.config.json to the hash of all tasks",
7
+ "factory": "./src/migrations/update-15-0-0/add-babel-inputs"
8
+ },
9
+ "update-16-0-0-add-nx-packages": {
10
+ "cli": "nx",
11
+ "version": "16.0.0-beta.1",
12
+ "description": "Replace @nrwl/rollup with @nx/rollup",
13
+ "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
14
+ },
15
+ "update-16-3-3-add-babel-upward-root-mode-flag": {
16
+ "cli": "nx",
17
+ "version": "16.3.3-beta.0",
18
+ "description": "Add babelUpwardRootMode if not already defined",
19
+ "implementation": "./src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag"
20
+ },
21
+ "explicitly-set-projects-to-update-buildable-deps": {
22
+ "cli": "nx",
23
+ "version": "16.6.0-beta.0",
24
+ "description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
25
+ "factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
26
+ }
27
+ },
28
+ "packageJsonUpdates": {}
29
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@nx/rollup",
3
+ "version": "0.0.0-pr-22179-271588f",
4
+ "private": false,
5
+ "description": "The Nx Plugin for Rollup contains executors and generators that support building applications using Rollup.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/nrwl/nx.git",
9
+ "directory": "packages/rollup"
10
+ },
11
+ "keywords": [
12
+ "Monorepo",
13
+ "Rollup",
14
+ "Web",
15
+ "CLI"
16
+ ],
17
+ "main": "./index.js",
18
+ "typings": "./index.d.ts",
19
+ "author": "Victor Savkin",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/nrwl/nx/issues"
23
+ },
24
+ "homepage": "https://nx.dev",
25
+ "generators": "./generators.json",
26
+ "executors": "./executors.json",
27
+ "ng-update": {
28
+ "requirements": {},
29
+ "migrations": "./migrations.json"
30
+ },
31
+ "dependencies": {
32
+ "@rollup/plugin-babel": "^5.3.0",
33
+ "@rollup/plugin-commonjs": "^20.0.0",
34
+ "@rollup/plugin-image": "^2.1.0",
35
+ "@rollup/plugin-json": "^4.1.0",
36
+ "@rollup/plugin-node-resolve": "^13.0.4",
37
+ "autoprefixer": "^10.4.9",
38
+ "babel-plugin-transform-async-to-promises": "^0.8.15",
39
+ "chalk": "^4.1.0",
40
+ "postcss": "^8.4.14",
41
+ "rollup": "^2.56.2",
42
+ "rollup-plugin-copy": "^3.4.0",
43
+ "rollup-plugin-peer-deps-external": "^2.2.4",
44
+ "rollup-plugin-postcss": "^4.0.1",
45
+ "rollup-plugin-typescript2": "0.36.0",
46
+ "rxjs": "^7.8.0",
47
+ "tslib": "^2.3.0",
48
+ "@nx/devkit": "0.0.0-pr-22179-271588f",
49
+ "@nx/js": "0.0.0-pr-22179-271588f",
50
+ "@nrwl/rollup": "0.0.0-pr-22179-271588f"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "exports": {
56
+ "./package.json": "./package.json",
57
+ ".": "./index.js",
58
+ "./executors.json": "./executors.json",
59
+ "./generators.json": "./generators.json",
60
+ "./migrations.json": "./migrations.json",
61
+ "./plugin": "./plugin.js"
62
+ },
63
+ "type": "commonjs"
64
+ }
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodes, RollupPluginOptions } from './src/plugins/plugin';
package/plugin.js ADDED
@@ -0,0 +1,5 @@
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; } });
@@ -0,0 +1,4 @@
1
+ export declare function analyze(): {
2
+ name: string;
3
+ renderChunk(source: any, chunk: any): void;
4
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyze = void 0;
4
+ const chalk = require("chalk");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const formatBytes = (bytes) => {
7
+ if (bytes === 0)
8
+ return '0 Byte';
9
+ const k = 1000;
10
+ const dm = 3;
11
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
12
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
13
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
14
+ };
15
+ function analyze() {
16
+ return {
17
+ name: 'rollup-plugin-nx-analyzer',
18
+ renderChunk(source, chunk) {
19
+ const sourceBytes = formatBytes(source.length);
20
+ const fileName = chunk.fileName;
21
+ devkit_1.logger.info(` ${chalk.bold(fileName)} ${chalk.cyan(sourceBytes)}`);
22
+ },
23
+ };
24
+ }
25
+ exports.analyze = analyze;
@@ -0,0 +1,11 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import type { AssetGlobPattern, RollupExecutorOptions } from '../schema';
3
+ export interface NormalizedRollupExecutorOptions extends RollupExecutorOptions {
4
+ entryRoot: string;
5
+ projectRoot: string;
6
+ assets: AssetGlobPattern[];
7
+ rollupConfig: string[];
8
+ }
9
+ export declare function normalizeRollupExecutorOptions(options: RollupExecutorOptions, context: ExecutorContext, sourceRoot: string): NormalizedRollupExecutorOptions;
10
+ export declare function normalizePluginPath(pluginPath: void | string, root: string): string;
11
+ export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string): AssetGlobPattern[];
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAssets = exports.normalizePluginPath = exports.normalizeRollupExecutorOptions = void 0;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ const devkit_1 = require("@nx/devkit");
7
+ const js_1 = require("@nx/js");
8
+ function normalizeRollupExecutorOptions(options, context, sourceRoot) {
9
+ const { root } = context;
10
+ const main = `${root}/${options.main}`;
11
+ const entryRoot = (0, path_1.dirname)(main);
12
+ const project = options.project
13
+ ? `${root}/${options.project}`
14
+ : (0, path_1.join)(root, 'package.json');
15
+ const projectRoot = (0, path_1.dirname)(project);
16
+ const outputPath = `${root}/${options.outputPath}`;
17
+ return {
18
+ ...options,
19
+ // de-dupe formats
20
+ format: Array.from(new Set(options.format)),
21
+ rollupConfig: []
22
+ .concat(options.rollupConfig)
23
+ .filter(Boolean)
24
+ .map((p) => normalizePluginPath(p, root)),
25
+ assets: options.assets
26
+ ? normalizeAssets(options.assets, root, sourceRoot)
27
+ : undefined,
28
+ main,
29
+ entryRoot,
30
+ project,
31
+ projectRoot,
32
+ outputPath,
33
+ skipTypeCheck: options.skipTypeCheck || false,
34
+ additionalEntryPoints: (0, js_1.createEntryPoints)(options.additionalEntryPoints, context.root),
35
+ };
36
+ }
37
+ exports.normalizeRollupExecutorOptions = normalizeRollupExecutorOptions;
38
+ function normalizePluginPath(pluginPath, root) {
39
+ if (!pluginPath) {
40
+ return '';
41
+ }
42
+ try {
43
+ return require.resolve(pluginPath);
44
+ }
45
+ catch {
46
+ return (0, path_1.resolve)(root, pluginPath);
47
+ }
48
+ }
49
+ exports.normalizePluginPath = normalizePluginPath;
50
+ function normalizeAssets(assets, root, sourceRoot) {
51
+ return assets.map((asset) => {
52
+ if (typeof asset === 'string') {
53
+ const assetPath = (0, devkit_1.normalizePath)(asset);
54
+ const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
55
+ const resolvedSourceRoot = (0, path_1.resolve)(root, sourceRoot);
56
+ if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
57
+ throw new Error(`The ${resolvedAssetPath} asset path must start with the project source root: ${sourceRoot}`);
58
+ }
59
+ const isDirectory = (0, fs_1.statSync)(resolvedAssetPath).isDirectory();
60
+ const input = isDirectory
61
+ ? resolvedAssetPath
62
+ : (0, path_1.dirname)(resolvedAssetPath);
63
+ const output = (0, path_1.relative)(resolvedSourceRoot, (0, path_1.resolve)(root, input));
64
+ const glob = isDirectory ? '**/*' : (0, path_1.basename)(resolvedAssetPath);
65
+ return {
66
+ input,
67
+ output,
68
+ glob,
69
+ };
70
+ }
71
+ else {
72
+ if (asset.output.startsWith('..')) {
73
+ throw new Error('An asset cannot be written to a location outside of the output path.');
74
+ }
75
+ const assetPath = (0, devkit_1.normalizePath)(asset.input);
76
+ const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
77
+ return {
78
+ ...asset,
79
+ input: resolvedAssetPath,
80
+ // Now we remove starting slash to make Webpack place it from the output root.
81
+ output: asset.output.replace(/^\//, ''),
82
+ };
83
+ }
84
+ });
85
+ }
86
+ exports.normalizeAssets = normalizeAssets;
@@ -0,0 +1,4 @@
1
+ import * as rollup from 'rollup';
2
+ export declare function runRollup(options: rollup.RollupOptions): import("rxjs").Observable<{
3
+ success: boolean;
4
+ }>;
@@ -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;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'rollup';
2
+ export declare function swc(): Plugin;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.swc = void 0;
4
+ function swc() {
5
+ const { transform } = require('@swc/core');
6
+ return {
7
+ name: 'nx-swc',
8
+ transform(code, filename) {
9
+ return transform(code, {
10
+ filename,
11
+ jsc: {
12
+ transform: {
13
+ react: { runtime: 'automatic' },
14
+ },
15
+ },
16
+ });
17
+ },
18
+ };
19
+ }
20
+ exports.swc = swc;
@@ -0,0 +1,3 @@
1
+ import { PackageJson } from 'nx/src/utils/package-json';
2
+ import { NormalizedRollupExecutorOptions } from './normalize';
3
+ export declare function updatePackageJson(options: NormalizedRollupExecutorOptions, packageJson: PackageJson): void;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updatePackageJson = void 0;
4
+ const path_1 = require("path");
5
+ const fileutils_1 = require("nx/src/utils/fileutils");
6
+ const fs_1 = require("fs");
7
+ const devkit_1 = require("@nx/devkit");
8
+ // TODO(jack): Use updatePackageJson from @nx/js instead.
9
+ function updatePackageJson(options, packageJson) {
10
+ const hasEsmFormat = options.format.includes('esm');
11
+ const hasCjsFormat = options.format.includes('cjs');
12
+ if (options.generateExportsField) {
13
+ packageJson.exports =
14
+ typeof packageJson.exports === 'string' ? {} : { ...packageJson.exports };
15
+ packageJson.exports['./package.json'] = './package.json';
16
+ }
17
+ if (hasEsmFormat) {
18
+ const esmExports = getExports({
19
+ ...options,
20
+ fileExt: '.esm.js',
21
+ });
22
+ packageJson.module = esmExports['.'];
23
+ if (!hasCjsFormat) {
24
+ if (!options.skipTypeField)
25
+ packageJson.type = 'module';
26
+ packageJson.main ??= esmExports['.'];
27
+ }
28
+ if (options.generateExportsField) {
29
+ for (const [exportEntry, filePath] of Object.entries(esmExports)) {
30
+ packageJson.exports[exportEntry] = hasCjsFormat
31
+ ? // If CJS format is used, make sure `import` (from Node) points to same instance of the package.
32
+ // Otherwise, packages that are required to be singletons (like React, RxJS, etc.) will break.
33
+ // Reserve `module` entry for bundlers to accommodate tree-shaking.
34
+ { [hasCjsFormat ? 'module' : 'import']: filePath }
35
+ : filePath;
36
+ }
37
+ }
38
+ }
39
+ if (hasCjsFormat) {
40
+ const cjsExports = getExports({
41
+ ...options,
42
+ fileExt: '.cjs.js',
43
+ });
44
+ packageJson.main = cjsExports['.'];
45
+ if (!hasEsmFormat) {
46
+ packageJson.type = 'commonjs';
47
+ }
48
+ if (options.generateExportsField) {
49
+ for (const [exportEntry, filePath] of Object.entries(cjsExports)) {
50
+ if (hasEsmFormat) {
51
+ // If ESM format used, make sure `import` (from Node) points to a wrapped
52
+ // version of CJS file to ensure the package remains a singleton.
53
+ // TODO(jack): This can be made into a rollup plugin to re-use in Vite.
54
+ const relativeFile = (0, path_1.parse)(filePath).base;
55
+ const fauxEsmFilePath = filePath.replace(/\.cjs\.js$/, '.cjs.mjs');
56
+ packageJson.exports[exportEntry]['import'] ??= fauxEsmFilePath;
57
+ packageJson.exports[exportEntry]['default'] ??= filePath;
58
+ // Re-export from relative CJS file, and Node will synthetically export it as ESM.
59
+ // Make sure both ESM and CJS point to same instance of the package because libs like React, RxJS, etc. requires it.
60
+ // Also need a special .cjs.default.js file that re-exports the `default` from CJS, or else
61
+ // default import in Node will not work.
62
+ (0, fs_1.writeFileSync)((0, path_1.join)(options.outputPath, filePath.replace(/\.cjs\.js$/, '.cjs.default.js')), `exports._default = require('./${(0, path_1.parse)(filePath).base}').default;`);
63
+ (0, fs_1.writeFileSync)((0, path_1.join)(options.outputPath, fauxEsmFilePath),
64
+ // Re-export from relative CJS file, and Node will synthetically export it as ESM.
65
+ (0, devkit_1.stripIndents) `
66
+ export * from './${relativeFile}';
67
+ export { _default as default } from './${relativeFile.replace(/\.cjs\.js$/, '.cjs.default.js')}';
68
+ `);
69
+ }
70
+ else {
71
+ packageJson.exports[exportEntry] = filePath;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ (0, fileutils_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
77
+ }
78
+ exports.updatePackageJson = updatePackageJson;
79
+ function getExports(options) {
80
+ const mainFile = options.outputFileName
81
+ ? options.outputFileName.replace(/\.[tj]s$/, '')
82
+ : (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
83
+ const exports = {
84
+ '.': './' + mainFile + options.fileExt,
85
+ };
86
+ if (options.additionalEntryPoints) {
87
+ for (const file of options.additionalEntryPoints) {
88
+ const { name: fileName } = (0, path_1.parse)(file);
89
+ exports['./' + fileName] = './' + fileName + options.fileExt;
90
+ }
91
+ }
92
+ return exports;
93
+ }
@@ -0,0 +1,13 @@
1
+ import * as rollup from 'rollup';
2
+ import type { ExecutorContext } from '@nx/devkit';
3
+ import { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
4
+ import type { PackageJson } from 'nx/src/utils/package-json';
5
+ import { RollupExecutorOptions } from './schema';
6
+ import { NormalizedRollupExecutorOptions } from './lib/normalize';
7
+ export type RollupExecutorEvent = {
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[]>;
13
+ export default rollupExecutor;