@nx/rollup 19.4.0-beta.0 → 19.4.0-beta.2

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/generators.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "init": {
6
6
  "factory": "./src/generators/init/init#rollupInitGenerator",
7
7
  "schema": "./src/generators/init/schema.json",
8
- "description": "Initialize the `@nrwl/rollup` plugin.",
8
+ "description": "Initialize the `@nx/rollup` plugin.",
9
9
  "aliases": ["ng-add"],
10
10
  "hidden": true
11
11
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/rollup",
3
- "version": "19.4.0-beta.0",
3
+ "version": "19.4.0-beta.2",
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,15 +37,16 @@
37
37
  "autoprefixer": "^10.4.9",
38
38
  "babel-plugin-transform-async-to-promises": "^0.8.15",
39
39
  "chalk": "^4.1.0",
40
+ "minimatch": "9.0.3",
40
41
  "postcss": "^8.4.38",
41
42
  "rollup": "^4.14.0",
42
43
  "rollup-plugin-copy": "^3.5.0",
43
44
  "rollup-plugin-postcss": "^4.0.2",
44
45
  "rollup-plugin-typescript2": "^0.36.0",
45
46
  "tslib": "^2.3.0",
46
- "@nx/devkit": "19.4.0-beta.0",
47
- "@nx/js": "19.4.0-beta.0",
48
- "@nrwl/rollup": "19.4.0-beta.0"
47
+ "@nx/devkit": "19.4.0-beta.2",
48
+ "@nx/js": "19.4.0-beta.2",
49
+ "@nrwl/rollup": "19.4.0-beta.2"
49
50
  },
50
51
  "publishConfig": {
51
52
  "access": "public"
@@ -4,9 +4,10 @@ exports.convertToInferred = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
6
  const extract_rollup_config_from_executor_options_1 = require("./lib/extract-rollup-config-from-executor-options");
7
+ const add_plugin_registrations_1 = require("./lib/add-plugin-registrations");
7
8
  async function convertToInferred(tree, options) {
8
- let migrated = 0;
9
- const projects = (0, devkit_1.getProjects)(tree);
9
+ const migratedProjects = new Map();
10
+ let projects = (0, devkit_1.getProjects)(tree);
10
11
  (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', (_, projectName, targetName, configurationName) => {
11
12
  if (options.project && projectName !== options.project)
12
13
  return;
@@ -62,23 +63,13 @@ async function convertToInferred(tree, options) {
62
63
  if (Object.keys(target).length === 0)
63
64
  delete project.targets[targetName];
64
65
  (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
65
- nxJson.plugins ??= [];
66
- if (!nxJson.plugins.some((p) => typeof p === 'string'
67
- ? p === '@nx/rollup/plugin'
68
- : p.plugin === '@nx/rollup/plugin')) {
69
- nxJson.plugins.push({
70
- plugin: '@nx/rollup/plugin',
71
- options: {
72
- targetName: 'build',
73
- },
74
- });
75
- }
76
- (0, devkit_1.updateNxJson)(tree, nxJson);
77
- migrated++;
66
+ migratedProjects.set(projectName, { buildTargetName: targetName });
78
67
  });
79
- if (migrated === 0) {
68
+ if (migratedProjects.size === 0) {
80
69
  throw new Error('Could not find any targets to migrate.');
81
70
  }
71
+ projects = (0, devkit_1.getProjects)(tree);
72
+ await (0, add_plugin_registrations_1.addPluginRegistrations)(tree, migratedProjects, projects, '@nx/rollup/plugin');
82
73
  if (!options.skipFormat) {
83
74
  await (0, devkit_1.formatFiles)(tree);
84
75
  }
@@ -0,0 +1,2 @@
1
+ import { type ProjectConfiguration, type Tree } from '@nx/devkit';
2
+ export declare function addPluginRegistrations<T>(tree: Tree, projectTargets: Map<string, T>, projects: Map<string, ProjectConfiguration>, pluginPath: string): Promise<void>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addPluginRegistrations = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const minimatch_1 = require("minimatch");
6
+ async function addPluginRegistrations(tree, projectTargets, projects, pluginPath) {
7
+ const nxJson = (0, devkit_1.readNxJson)(tree);
8
+ for (const [project, options] of projectTargets.entries()) {
9
+ const existingPlugin = nxJson.plugins?.find((plugin) => typeof plugin !== 'string' &&
10
+ plugin.plugin === pluginPath &&
11
+ Object.keys(options).every((key) => plugin.options[key] === options[key]));
12
+ const projectIncludeGlob = `${projects.get(project).root}/**/*`;
13
+ if (!existingPlugin) {
14
+ nxJson.plugins ??= [];
15
+ const plugin = {
16
+ plugin: pluginPath,
17
+ options,
18
+ include: [projectIncludeGlob],
19
+ };
20
+ nxJson.plugins.push(plugin);
21
+ }
22
+ else if (existingPlugin.include) {
23
+ if (!existingPlugin.include.some((include) => (0, minimatch_1.minimatch)(projectIncludeGlob, include, { dot: true }))) {
24
+ existingPlugin.include.push(projectIncludeGlob);
25
+ }
26
+ }
27
+ }
28
+ if (!areProjectsUsingTheExecutorLeft(projects)) {
29
+ // all projects have been migrated, if there's only one plugin registration
30
+ // left, remove its "include" property
31
+ const pluginRegistrations = nxJson.plugins?.filter((plugin) => typeof plugin !== 'string' && plugin.plugin === pluginPath);
32
+ if (pluginRegistrations?.length === 1) {
33
+ for (const plugin of pluginRegistrations) {
34
+ delete plugin.include;
35
+ }
36
+ }
37
+ }
38
+ (0, devkit_1.updateNxJson)(tree, nxJson);
39
+ }
40
+ exports.addPluginRegistrations = addPluginRegistrations;
41
+ function areProjectsUsingTheExecutorLeft(projects) {
42
+ return Array.from(projects.values()).some((project) => Object.values(project.targets ?? {}).some((target) => target.executor === '@nx/rollup:rollup'));
43
+ }
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractRollupConfigFromExecutorOptions = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const normalize_path_options_1 = require("./normalize-path-options");
6
+ const aliases = {
7
+ entryFile: 'main',
8
+ exports: 'generateExportsField',
9
+ f: 'format',
10
+ };
6
11
  function extractRollupConfigFromExecutorOptions(tree, options, configurations, projectRoot) {
7
12
  (0, normalize_path_options_1.normalizePathOptions)(projectRoot, options);
8
- let newRollupConfigContent;
9
13
  const hasConfigurations = !!configurations && Object.keys(configurations).length > 0;
10
14
  const oldRollupConfig = Array.isArray(options.rollupConfig)
11
15
  ? options.rollupConfig
@@ -26,27 +30,77 @@ function extractRollupConfigFromExecutorOptions(tree, options, configurations, p
26
30
  if (key === 'watch')
27
31
  continue;
28
32
  delete options[key];
29
- defaultOptions[key] = value;
33
+ if (aliases[key]) {
34
+ defaultOptions[aliases[key]] = value;
35
+ }
36
+ else {
37
+ defaultOptions[key] = value;
38
+ }
30
39
  }
40
+ let configurationOptions;
31
41
  if (hasConfigurations) {
32
- const configurationOptions = {};
42
+ configurationOptions = {};
33
43
  for (const [key, value] of Object.entries(configurations)) {
44
+ let newConfigFileName;
45
+ let oldRollupConfigForConfiguration;
34
46
  for (const [optionKey, optionValue] of Object.entries(value)) {
35
47
  if (optionKey === 'watch')
36
48
  continue;
49
+ /**
50
+ * If a configuration lists rollupConfig as an option
51
+ * Collect the options and set up a new file to point to
52
+ * Set the `--config` option to the new file
53
+ */
54
+ if (optionKey === 'rollupConfig') {
55
+ oldRollupConfigForConfiguration = Array.isArray(optionValue)
56
+ ? optionValue
57
+ : optionValue
58
+ ? [optionValue]
59
+ : [];
60
+ newConfigFileName = `rollup.${key}.config.js`;
61
+ for (let i = 0; i < oldRollupConfigForConfiguration.length; i++) {
62
+ const file = oldRollupConfigForConfiguration[i];
63
+ if (file === newConfigFileName) {
64
+ tree.rename((0, devkit_1.joinPathFragments)(projectRoot, newConfigFileName), (0, devkit_1.joinPathFragments)(projectRoot, `rollup.${key}.migrated.config.js`));
65
+ oldRollupConfigForConfiguration.splice(i, 1, `./rollup.${key}.migrated.config.js`);
66
+ }
67
+ }
68
+ delete value[optionKey];
69
+ value['config'] = newConfigFileName;
70
+ continue;
71
+ }
37
72
  delete value[optionKey];
38
73
  configurationOptions[key] ??= {};
39
74
  configurationOptions[key][optionKey] = optionValue;
40
75
  }
76
+ /**
77
+ * Only if we encountered a rollupConfig in the current configuration
78
+ * should we write a new config file, containing all the config values
79
+ */
80
+ if (newConfigFileName) {
81
+ tree.write((0, devkit_1.joinPathFragments)(projectRoot, newConfigFileName), createNewRollupConfig(oldRollupConfigForConfiguration, defaultOptions, configurationOptions[key], true));
82
+ }
41
83
  }
42
- newRollupConfigContent = (0, devkit_1.stripIndents) `
84
+ }
85
+ tree.write((0, devkit_1.joinPathFragments)(projectRoot, `rollup.config.js`), createNewRollupConfig(oldRollupConfig, defaultOptions, configurationOptions));
86
+ return defaultOptions;
87
+ }
88
+ exports.extractRollupConfigFromExecutorOptions = extractRollupConfigFromExecutorOptions;
89
+ function createNewRollupConfig(oldRollupConfig, defaultOptions, configurationOptions, singleConfiguration = false) {
90
+ if (configurationOptions) {
91
+ return (0, devkit_1.stripIndents) `
43
92
  const { withNx } = require('@nx/rollup/with-nx');
44
93
 
45
94
  // These options were migrated by @nx/rollup:convert-to-inferred from project.json
46
- const configValues = ${JSON.stringify({
47
- default: defaultOptions,
48
- ...configurationOptions,
49
- }, null, 2)};
95
+ const configValues = ${JSON.stringify(singleConfiguration
96
+ ? {
97
+ ...defaultOptions,
98
+ ...configurationOptions,
99
+ }
100
+ : {
101
+ default: defaultOptions,
102
+ ...configurationOptions,
103
+ }, null, 2)};
50
104
 
51
105
  // Determine the correct configValue to use based on the configuration
52
106
  const nxConfiguration = process.env.NX_TASK_TARGET_CONFIGURATION ?? 'default';
@@ -71,7 +125,7 @@ function extractRollupConfigFromExecutorOptions(tree, options, configurations, p
71
125
  `;
72
126
  }
73
127
  else {
74
- newRollupConfigContent = (0, devkit_1.stripIndents) `
128
+ return (0, devkit_1.stripIndents) `
75
129
  const { withNx } = require('@nx/rollup/with-nx');
76
130
 
77
131
  // These options were migrated by @nx/rollup:convert-to-inferred from project.json
@@ -91,7 +145,4 @@ function extractRollupConfigFromExecutorOptions(tree, options, configurations, p
91
145
  module.exports = config;
92
146
  `;
93
147
  }
94
- tree.write((0, devkit_1.joinPathFragments)(projectRoot, `rollup.config.js`), newRollupConfigContent);
95
- return defaultOptions;
96
148
  }
97
- exports.extractRollupConfigFromExecutorOptions = extractRollupConfigFromExecutorOptions;
@@ -1,23 +1,76 @@
1
1
  export interface RollupWithNxPluginOptions {
2
+ /**
3
+ * Additional entry-points to add to exports field in the package.json file.
4
+ * */
2
5
  additionalEntryPoints?: string[];
6
+ /**
7
+ * Allow JavaScript files to be compiled.
8
+ */
3
9
  allowJs?: boolean;
10
+ /**
11
+ * List of static assets.
12
+ */
4
13
  assets?: any[];
14
+ /**
15
+ * Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode
16
+ */
5
17
  babelUpwardRootMode?: boolean;
18
+ /**
19
+ * Which compiler to use.
20
+ */
6
21
  compiler?: 'babel' | 'tsc' | 'swc';
22
+ /**
23
+ * Delete the output path before building. Defaults to true.
24
+ */
7
25
  deleteOutputPath?: boolean;
26
+ /**
27
+ * A list of external modules that will not be bundled (`react`, `react-dom`, etc.). Can also be set to `all` (bundle nothing) or `none` (bundle everything).
28
+ */
8
29
  external?: string[] | 'all' | 'none';
30
+ /**
31
+ * CSS files will be extracted to the output folder. Alternatively custom filename can be provided (e.g. styles.css)
32
+ */
9
33
  extractCss?: boolean | string;
34
+ /**
35
+ * List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).
36
+ */
10
37
  format?: ('cjs' | 'esm')[];
38
+ /**
39
+ * Update the output package.json file's 'exports' field. This field is used by Node and bundles.
40
+ */
11
41
  generateExportsField?: boolean;
42
+ /**
43
+ * Sets `javascriptEnabled` option for less loader
44
+ */
12
45
  javascriptEnabled?: boolean;
46
+ /**
47
+ * The path to the entry file, relative to project.
48
+ */
13
49
  main: string;
14
- /** @deprecated Do not set this. The package.json file in project root is detected automatically. */
50
+ /**
51
+ * The path to package.json file.
52
+ * @deprecated Do not set this. The package.json file in project root is detected automatically.
53
+ */
15
54
  project?: string;
55
+ /**
56
+ * Name of the main output file. Defaults same basename as 'main' file.
57
+ */
16
58
  outputFileName?: string;
59
+ /**
60
+ * The output path of the generated files.
61
+ */
17
62
  outputPath: string;
18
- rollupConfig?: string | string[];
63
+ /**
64
+ * Whether to skip TypeScript type checking.
65
+ */
19
66
  skipTypeCheck?: boolean;
67
+ /**
68
+ * Prevents 'type' field from being added to compiled package.json file. Use this if you are having an issue with this field.
69
+ */
20
70
  skipTypeField?: boolean;
71
+ /**
72
+ * The path to tsconfig file.
73
+ */
21
74
  tsConfig: string;
22
75
  }
23
76
  export interface AssetGlobPattern {