@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
@@ -0,0 +1,86 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxRollupProject",
4
+ "cli": "nx",
5
+ "title": "Add Rollup Configuration to a project",
6
+ "description": "Add Rollup Configuration to a project.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "description": "The name of the project.",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-dropdown": "project",
17
+ "x-prompt": "What is the name of the project to set up a rollup for?",
18
+ "x-priority": "important"
19
+ },
20
+ "compiler": {
21
+ "type": "string",
22
+ "enum": ["babel", "swc", "tsc"],
23
+ "description": "The compiler to use to build source.",
24
+ "default": "babel"
25
+ },
26
+ "main": {
27
+ "type": "string",
28
+ "description": "Path relative to the workspace root for the main entry file. Defaults to '<projectRoot>/src/main.ts'.",
29
+ "alias": "entryFile",
30
+ "x-priority": "important"
31
+ },
32
+ "tsConfig": {
33
+ "type": "string",
34
+ "description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to '<projectRoot>/tsconfig.app.json'.",
35
+ "x-priority": "important"
36
+ },
37
+ "skipFormat": {
38
+ "description": "Skip formatting files.",
39
+ "type": "boolean",
40
+ "default": false,
41
+ "x-priority": "internal"
42
+ },
43
+ "skipPackageJson": {
44
+ "type": "boolean",
45
+ "default": false,
46
+ "description": "Do not add dependencies to `package.json`.",
47
+ "x-priority": "internal"
48
+ },
49
+ "skipValidation": {
50
+ "type": "boolean",
51
+ "default": false,
52
+ "description": "Do not perform any validation on existing project.",
53
+ "x-priority": "internal"
54
+ },
55
+ "importPath": {
56
+ "type": "string",
57
+ "description": "The library name used to import it, like `@myorg/my-awesome-lib`."
58
+ },
59
+ "external": {
60
+ "type": "array",
61
+ "description": "A list of external modules that will not be bundled (`react`, `react-dom`, etc.).",
62
+ "items": {
63
+ "type": "string"
64
+ }
65
+ },
66
+ "rollupConfig": {
67
+ "type": "string",
68
+ "description": "Path relative to workspace root to a custom rollup file that takes a config object and returns an updated config."
69
+ },
70
+ "buildTarget": {
71
+ "description": "The build target to add.",
72
+ "type": "string",
73
+ "default": "build"
74
+ },
75
+ "format": {
76
+ "description": "The format to build the library (esm or cjs).",
77
+ "type": "array",
78
+ "items": {
79
+ "type": "string",
80
+ "enum": ["esm", "cjs"]
81
+ },
82
+ "default": ["esm"]
83
+ }
84
+ },
85
+ "required": []
86
+ }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function rollupInitGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export default rollupInitGenerator;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rollupInitGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
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
+ }
26
+ async function rollupInitGenerator(tree, schema) {
27
+ let task = () => { };
28
+ if (!schema.skipPackageJson) {
29
+ task = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/rollup': versions_1.nxVersion }, undefined, schema.keepExistingVersions);
30
+ }
31
+ schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
32
+ if (schema.addPlugin) {
33
+ addPlugin(tree);
34
+ }
35
+ if (schema.updatePackageScripts) {
36
+ await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
37
+ }
38
+ if (!schema.skipFormat) {
39
+ await (0, devkit_1.formatFiles)(tree);
40
+ }
41
+ return task;
42
+ }
43
+ exports.rollupInitGenerator = rollupInitGenerator;
44
+ exports.default = rollupInitGenerator;
@@ -0,0 +1,7 @@
1
+ export interface Schema {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
7
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxWebpackInit",
4
+ "cli": "nx",
5
+ "title": "Init Webpack Plugin",
6
+ "description": "Init Webpack Plugin.",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "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
+ }
31
+ },
32
+ "required": []
33
+ }
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const add_babel_inputs_1 = require("@nx/js/src/utils/add-babel-inputs");
5
+ async function default_1(tree) {
6
+ (0, add_babel_inputs_1.addBabelInputs)(tree);
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ }
9
+ exports.default = default_1;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function replacePackage(tree: Tree): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/rollup', '@nx/rollup');
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ }
9
+ exports.default = replacePackage;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
+ async function default_1(tree) {
6
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', (options, projectName, targetName, _configurationName) => {
7
+ if (options.babelUpwardRootMode !== undefined) {
8
+ return;
9
+ }
10
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
11
+ projectConfiguration.targets[targetName].options.babelUpwardRootMode =
12
+ true;
13
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
14
+ });
15
+ await (0, devkit_1.formatFiles)(tree);
16
+ }
17
+ exports.default = default_1;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const executors = new Set(['@nx/rollup:rollup', '@nrwl/rollup:rollup']);
5
+ async function default_1(tree) {
6
+ // use project graph to get the expanded target configurations
7
+ const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
8
+ for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
9
+ if (projectData.projectType !== 'library') {
10
+ continue;
11
+ }
12
+ for (const [targetName, target] of Object.entries(projectData.targets || {})) {
13
+ if (!executors.has(target.executor)) {
14
+ continue;
15
+ }
16
+ if (!target.options ||
17
+ target.options.updateBuildableProjectDepsInPackageJson === undefined) {
18
+ // read the project configuration to write the explicit project configuration
19
+ // and avoid writing the expanded target configuration
20
+ const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
21
+ project.targets[targetName].options ??= {};
22
+ project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
23
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
24
+ }
25
+ }
26
+ }
27
+ await (0, devkit_1.formatFiles)(tree);
28
+ }
29
+ exports.default = default_1;
@@ -0,0 +1,6 @@
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>;
@@ -0,0 +1,104 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
+ export type EnsureDependenciesOptions = {
3
+ compiler?: 'babel' | 'swc' | 'tsc';
4
+ };
5
+ export declare function ensureDependencies(tree: Tree, options: EnsureDependenciesOptions): GeneratorCallback;
@@ -0,0 +1,17 @@
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
+ 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
+ });
14
+ }
15
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { tslib: versions_2.tsLibVersion });
16
+ }
17
+ exports.ensureDependencies = ensureDependencies;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Delete an output directory, but error out if it's the root of the project.
3
+ */
4
+ export declare function deleteOutputDir(root: string, outputPath: string): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteOutputDir = void 0;
4
+ const path = require("path");
5
+ const fs_1 = require("fs");
6
+ /**
7
+ * Delete an output directory, but error out if it's the root of the project.
8
+ */
9
+ function deleteOutputDir(root, outputPath) {
10
+ const resolvedOutputPath = path.resolve(root, outputPath);
11
+ if (resolvedOutputPath === root) {
12
+ throw new Error('Output path MUST not be project root directory!');
13
+ }
14
+ (0, fs_1.rmSync)(resolvedOutputPath, { recursive: true, force: true });
15
+ }
16
+ exports.deleteOutputDir = deleteOutputDir;
@@ -0,0 +1,3 @@
1
+ export declare const nxVersion: any;
2
+ export declare const swcLoaderVersion = "0.1.15";
3
+ export declare const tsLibVersion = "^2.3.0";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
4
+ exports.nxVersion = require('../../package.json').version;
5
+ exports.swcLoaderVersion = '0.1.15';
6
+ exports.tsLibVersion = '^2.3.0';