diff --git a/docs/generated/packages/rollup.json b/docs/generated/packages/rollup.json index ba038d8100b65..901e22db97732 100644 --- a/docs/generated/packages/rollup.json +++ b/docs/generated/packages/rollup.json @@ -117,7 +117,7 @@ "implementation": "/packages/rollup/src/executors/rollup/rollup.impl.ts", "schema": { "title": "Web Library Rollup Target (Experimental)", - "description": "Packages a library for different web usages (`UMD`, `ESM`, `CJS`).", + "description": "Packages a library for different web usages (ESM, CommonJS).", "cli": "nx", "type": "object", "properties": { @@ -156,7 +156,7 @@ "type": "array", "description": "List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).", "alias": "f", - "items": { "type": "string", "enum": ["esm", "umd", "cjs"] } + "items": { "type": "string", "enum": ["esm", "cjs"] } }, "external": { "type": "array", @@ -197,30 +197,6 @@ ], "description": "Path to a function which takes a rollup config and returns an updated rollup config." }, - "umdName": { - "type": "string", - "description": "The name of your module in `UMD` format. Defaulted to your project name." - }, - "globals": { - "description": "A mapping of node modules to their `UMD` global names. Used by the `UMD` bundle.", - "type": "array", - "items": { - "type": "object", - "properties": { - "moduleId": { - "type": "string", - "description": "The node module to map from (e.g. `react-dom`)." - }, - "global": { - "type": "string", - "description": "The global name to map to (e.g. `ReactDOM`)." - } - }, - "additionalProperties": false, - "required": ["moduleId", "global"] - }, - "default": [] - }, "extractCss": { "type": ["boolean", "string"], "description": "CSS files will be extracted to the output folder. Alternatively custom filename can be provided (e.g. styles.css)", diff --git a/docs/generated/packages/web.json b/docs/generated/packages/web.json index 0b80248a789ee..90e19b4cd2bf4 100644 --- a/docs/generated/packages/web.json +++ b/docs/generated/packages/web.json @@ -752,30 +752,6 @@ ], "description": "Path to a function which takes a rollup config and returns an updated rollup config." }, - "umdName": { - "type": "string", - "description": "The name of your module in `UMD` format. Defaulted to your project name." - }, - "globals": { - "description": "A mapping of node modules to their `UMD` global names. Used by the `UMD` bundle.", - "type": "array", - "items": { - "type": "object", - "properties": { - "moduleId": { - "type": "string", - "description": "The node module to map from (e.g. `react-dom`)." - }, - "global": { - "type": "string", - "description": "The global name to map to (e.g. `ReactDOM`)." - } - }, - "additionalProperties": false, - "required": ["moduleId", "global"] - }, - "default": [] - }, "extractCss": { "type": ["boolean", "string"], "description": "CSS files will be extracted to the output folder. Alternatively custom filename can be provided (e.g. styles.css)", diff --git a/packages/js/src/executors/node/node.impl.ts b/packages/js/src/executors/node/node.impl.ts index d54b71ceaeff2..7eed294a70f44 100644 --- a/packages/js/src/executors/node/node.impl.ts +++ b/packages/js/src/executors/node/node.impl.ts @@ -192,9 +192,6 @@ async function* startBuild( ) { const buildTarget = parseTargetString(options.buildTarget); - // TODO(jack): [Nx 14] Remove this line once we generate `development` configuration by default + add migration for it if missing - buildTarget.configuration ??= ''; - yield* await runExecutor( buildTarget, { diff --git a/packages/rollup/src/executors/rollup/lib/update-package-json.ts b/packages/rollup/src/executors/rollup/lib/update-package-json.ts index 23fdb088d3d61..88848cadf1fcb 100644 --- a/packages/rollup/src/executors/rollup/lib/update-package-json.ts +++ b/packages/rollup/src/executors/rollup/lib/update-package-json.ts @@ -17,8 +17,7 @@ export function updatePackageJson( packageJson: PackageJson ) { const hasEsmFormat = options.format.includes('esm'); - const hasCjsFormat = - options.format.includes('umd') || options.format.includes('cjs'); + const hasCjsFormat = options.format.includes('cjs'); const types = `./${relative(options.entryRoot, options.main).replace( /\.[jt]sx?$/, @@ -54,7 +53,7 @@ export function updatePackageJson( // Support for older TS versions < 4.5 packageJson.types = types; - // TODO(jack): remove this for Nx 15 + // TODO(jack): remove this for Nx 16 if (options.generateExportsField) { packageJson.exports = { ...packageJson.exports, diff --git a/packages/rollup/src/executors/rollup/rollup.impl.spec.ts b/packages/rollup/src/executors/rollup/rollup.impl.spec.ts index 919f5705f1e8d..502257a7ee89b 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.spec.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.spec.ts @@ -49,18 +49,14 @@ describe('rollupExecutor', () => { { dir: '/root/dist/ui', format: 'esm', - globals: { 'react/jsx-runtime': 'jsxRuntime' }, name: 'Example', - inlineDynamicImports: false, chunkFileNames: '[name].js', entryFileNames: '[name].js', }, { dir: '/root/dist/ui', format: 'cjs', - globals: { 'react/jsx-runtime': 'jsxRuntime' }, name: 'Example', - inlineDynamicImports: false, chunkFileNames: '[name].cjs', entryFileNames: '[name].cjs', }, diff --git a/packages/rollup/src/executors/rollup/rollup.impl.ts b/packages/rollup/src/executors/rollup/rollup.impl.ts index 9823cc42ed4e4..75f1498e88c4f 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.ts @@ -62,16 +62,6 @@ export async function* rollupExecutor( sourceRoot ); - // TODO(jack): Remove UMD in Nx 15 - if (options.format.includes('umd')) { - if (options.format.includes('cjs')) { - throw new Error( - 'Cannot use both UMD and CJS. We recommend you use ESM or CJS.' - ); - } else { - logger.warn('UMD format is deprecated and will be removed in Nx 15'); - } - } const packageJson = readJsonFile(options.project); const npmDeps = (context.projectGraph.dependencies[context.projectName] ?? []) @@ -253,7 +243,7 @@ export function createRollupOptions( // @ts-ignore // Ignoring type checks for caller since we have custom attributes isNxPackage: true, - // Always target esnext and let rollup handle cjs/umd + // Always target esnext and let rollup handle cjs supportsStaticESM: true, isModern: true, }, @@ -274,16 +264,6 @@ export function createRollupOptions( analyze(), ]; - const globals = options.globals - ? options.globals.reduce( - (acc, item) => { - acc[item.moduleId] = item.global; - return acc; - }, - { 'react/jsx-runtime': 'jsxRuntime' } - ) - : { 'react/jsx-runtime': 'jsxRuntime' }; - const externalPackages = dependencies .map((d) => d.name) .concat(options.external || []) @@ -296,14 +276,11 @@ export function createRollupOptions( } : options.main, output: { - globals, format, dir: `${options.outputPath}`, - name: options.umdName || names(context.projectName).className, + name: names(context.projectName).className, entryFileNames: `[name].${format === 'esm' ? 'js' : 'cjs'}`, chunkFileNames: `[name].${format === 'esm' ? 'js' : 'cjs'}`, - // umd doesn't support code-split bundles - inlineDynamicImports: format === 'umd', }, external: (id) => externalPackages.some( @@ -356,10 +333,9 @@ function convertCopyAssetsToRollupOptions( function readCompatibleFormats(config: ts.ParsedCommandLine) { switch (config.options.module) { case ts.ModuleKind.CommonJS: - return ['cjs']; case ts.ModuleKind.UMD: case ts.ModuleKind.AMD: - return ['umd']; + return ['cjs']; default: return ['esm']; } diff --git a/packages/rollup/src/executors/rollup/schema.d.ts b/packages/rollup/src/executors/rollup/schema.d.ts index f37011ec3731f..45dcf6b930c49 100644 --- a/packages/rollup/src/executors/rollup/schema.d.ts +++ b/packages/rollup/src/executors/rollup/schema.d.ts @@ -19,19 +19,17 @@ export interface RollupExecutorOptions { main: string; outputFileName?: string; extractCss?: boolean | string; - globals?: Globals[]; external?: string[]; rollupConfig?: string | string[]; watch?: boolean; assets?: any[]; updateBuildableProjectDepsInPackageJson?: boolean; buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies'; - umdName?: string; deleteOutputPath?: boolean; format?: string[]; compiler?: 'babel' | 'tsc' | 'swc'; javascriptEnabled?: boolean; - // TODO(jack): remove this for Nx 15 + // TODO(jack): remove this for Nx 16 skipTypeField?: boolean; generateExportsField?: boolean; } diff --git a/packages/rollup/src/executors/rollup/schema.json b/packages/rollup/src/executors/rollup/schema.json index 7dcf00f61e77a..53fef888a0538 100644 --- a/packages/rollup/src/executors/rollup/schema.json +++ b/packages/rollup/src/executors/rollup/schema.json @@ -1,6 +1,6 @@ { "title": "Web Library Rollup Target (Experimental)", - "description": "Packages a library for different web usages (`UMD`, `ESM`, `CJS`).", + "description": "Packages a library for different web usages (ESM, CommonJS).", "cli": "nx", "type": "object", "properties": { @@ -41,7 +41,7 @@ "alias": "f", "items": { "type": "string", - "enum": ["esm", "umd", "cjs"] + "enum": ["esm", "cjs"] } }, "external": { @@ -85,30 +85,6 @@ ], "description": "Path to a function which takes a rollup config and returns an updated rollup config." }, - "umdName": { - "type": "string", - "description": "The name of your module in `UMD` format. Defaulted to your project name." - }, - "globals": { - "description": "A mapping of node modules to their `UMD` global names. Used by the `UMD` bundle.", - "type": "array", - "items": { - "type": "object", - "properties": { - "moduleId": { - "type": "string", - "description": "The node module to map from (e.g. `react-dom`)." - }, - "global": { - "type": "string", - "description": "The global name to map to (e.g. `ReactDOM`)." - } - }, - "additionalProperties": false, - "required": ["moduleId", "global"] - }, - "default": [] - }, "extractCss": { "type": ["boolean", "string"], "description": "CSS files will be extracted to the output folder. Alternatively custom filename can be provided (e.g. styles.css)", diff --git a/packages/web/migrations.json b/packages/web/migrations.json index f8d7b7421d8e2..c98353c5e43d1 100644 --- a/packages/web/migrations.json +++ b/packages/web/migrations.json @@ -74,6 +74,12 @@ "version": "15.0.0-beta.0", "description": "Adds babel.config.json to the hash of all tasks", "factory": "./src/migrations/update-15-0-0/add-babel-inputs" + }, + "update-rollup-executor": { + "cli": "nx", + "version": "15.0.0-beta.1", + "description": "Update usages of rollup executors to @nrwl/rollup", + "factory": "./src/migrations/update-15-0-0/update-rollup-executor" } }, "packageJsonUpdates": { diff --git a/packages/web/src/executors/rollup/schema.d.ts b/packages/web/src/executors/rollup/schema.d.ts index 528b1b5345025..ce0906a8a6a90 100644 --- a/packages/web/src/executors/rollup/schema.d.ts +++ b/packages/web/src/executors/rollup/schema.d.ts @@ -23,7 +23,7 @@ export interface WebRollupOptions { format: string[]; compiler?: Compiler; javascriptEnabled?: boolean; - // TODO(jack): remove this for Nx 15 + // TODO(jack): remove this for Nx 16 skipTypeField?: boolean; generateExportsField?: boolean; } diff --git a/packages/web/src/executors/rollup/schema.json b/packages/web/src/executors/rollup/schema.json index bd9c2274668b3..7543f5e1c1777 100644 --- a/packages/web/src/executors/rollup/schema.json +++ b/packages/web/src/executors/rollup/schema.json @@ -81,30 +81,6 @@ ], "description": "Path to a function which takes a rollup config and returns an updated rollup config." }, - "umdName": { - "type": "string", - "description": "The name of your module in `UMD` format. Defaulted to your project name." - }, - "globals": { - "description": "A mapping of node modules to their `UMD` global names. Used by the `UMD` bundle.", - "type": "array", - "items": { - "type": "object", - "properties": { - "moduleId": { - "type": "string", - "description": "The node module to map from (e.g. `react-dom`)." - }, - "global": { - "type": "string", - "description": "The global name to map to (e.g. `ReactDOM`)." - } - }, - "additionalProperties": false, - "required": ["moduleId", "global"] - }, - "default": [] - }, "extractCss": { "type": ["boolean", "string"], "description": "CSS files will be extracted to the output folder. Alternatively custom filename can be provided (e.g. styles.css)", diff --git a/packages/web/src/migrations/update-15-0-0/update-rollup-executor.spec.ts b/packages/web/src/migrations/update-15-0-0/update-rollup-executor.spec.ts new file mode 100644 index 0000000000000..24ec5ee6421d9 --- /dev/null +++ b/packages/web/src/migrations/update-15-0-0/update-rollup-executor.spec.ts @@ -0,0 +1,104 @@ +import { + addProjectConfiguration, + readProjectConfiguration, +} from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; + +import update from './update-rollup-executor'; + +describe('Migration: @nrwl/rollup', () => { + it(`should update usage of rollup executor`, async () => { + let tree = createTreeWithEmptyWorkspace(); + + addProjectConfiguration(tree, 'mylib', { + root: 'libs/mylib', + sourceRoot: 'libs/mylib/src', + projectType: 'library', + targets: { + build: { + executor: '@nrwl/web:rollup', + options: {}, + }, + }, + }); + await update(tree); + + expect(readProjectConfiguration(tree, 'mylib')).toEqual({ + $schema: '../../node_modules/nx/schemas/project-schema.json', + name: 'mylib', + root: 'libs/mylib', + sourceRoot: 'libs/mylib/src', + projectType: 'library', + targets: { + build: { + executor: '@nrwl/rollup:rollup', + options: {}, + }, + }, + }); + }); + + it(`should replace umd with cjs`, async () => { + let tree = createTreeWithEmptyWorkspace(); + + addProjectConfiguration(tree, 'lib1', { + root: 'libs/lib1', + sourceRoot: 'libs/lib1/src', + projectType: 'library', + targets: { + build: { + executor: '@nrwl/web:rollup', + options: { + formats: ['umd'], + }, + }, + }, + }); + addProjectConfiguration(tree, 'lib2', { + root: 'libs/lib2', + sourceRoot: 'libs/lib2/src', + projectType: 'library', + targets: { + build: { + executor: '@nrwl/rollup:rollup', + options: { + formats: ['esm', 'cjs', 'umd'], + }, + }, + }, + }); + + await update(tree); + + expect(readProjectConfiguration(tree, 'lib1')).toEqual({ + $schema: '../../node_modules/nx/schemas/project-schema.json', + name: 'lib1', + root: 'libs/lib1', + sourceRoot: 'libs/lib1/src', + projectType: 'library', + targets: { + build: { + executor: '@nrwl/rollup:rollup', + options: { + formats: ['cjs'], + }, + }, + }, + }); + expect(readProjectConfiguration(tree, 'lib2')).toEqual({ + $schema: '../../node_modules/nx/schemas/project-schema.json', + name: 'lib2', + root: 'libs/lib2', + sourceRoot: 'libs/lib2/src', + projectType: 'library', + targets: { + build: { + executor: '@nrwl/rollup:rollup', + options: { + formats: ['esm', 'cjs'], + }, + }, + }, + }); + }); +}); diff --git a/packages/web/src/migrations/update-15-0-0/update-rollup-executor.ts b/packages/web/src/migrations/update-15-0-0/update-rollup-executor.ts new file mode 100644 index 0000000000000..9bbd2c9ba418e --- /dev/null +++ b/packages/web/src/migrations/update-15-0-0/update-rollup-executor.ts @@ -0,0 +1,42 @@ +import { + formatFiles, + getProjects, + Tree, + updateProjectConfiguration, +} from '@nrwl/devkit'; + +export default async function update(host: Tree) { + const projects = getProjects(host); + + for (const [name, config] of projects.entries()) { + let updated = false; + + if (config?.targets?.build?.executor === '@nrwl/web:rollup') { + config.targets.build.executor = '@nrwl/rollup:rollup'; + updated = true; + } + + if (config?.targets?.build?.options?.formats?.includes('umd')) { + config.targets.build.options.formats = + config.targets.build.options.formats.reduce((acc, x) => { + const format = x === 'umd' ? 'cjs' : x; + + if (format === 'cjs') { + if (!acc.includes('cjs')) acc.push(format); + } else { + acc.push(format); + } + + return acc; + }, []); + + updated = true; + } + + if (updated) { + updateProjectConfiguration(host, name, config); + } + } + + await formatFiles(host); +}