Skip to content

Commit

Permalink
feat(bundling): remove deprecated UMD format support for rollup (#12426)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored Oct 6, 2022
1 parent 5e293eb commit dda9ea1
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 141 deletions.
28 changes: 2 additions & 26 deletions docs/generated/packages/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand Down
24 changes: 0 additions & 24 deletions docs/generated/packages/web.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
3 changes: 0 additions & 3 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecutorEvent>(
buildTarget,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?$/,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions packages/rollup/src/executors/rollup/rollup.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
30 changes: 3 additions & 27 deletions packages/rollup/src/executors/rollup/rollup.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] ?? [])
Expand Down Expand Up @@ -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,
},
Expand All @@ -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 || [])
Expand All @@ -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(
Expand Down Expand Up @@ -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'];
}
Expand Down
4 changes: 1 addition & 3 deletions packages/rollup/src/executors/rollup/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
28 changes: 2 additions & 26 deletions packages/rollup/src/executors/rollup/schema.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -41,7 +41,7 @@
"alias": "f",
"items": {
"type": "string",
"enum": ["esm", "umd", "cjs"]
"enum": ["esm", "cjs"]
}
},
"external": {
Expand Down Expand Up @@ -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)",
Expand Down
6 changes: 6 additions & 0 deletions packages/web/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/executors/rollup/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
24 changes: 0 additions & 24 deletions packages/web/src/executors/rollup/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Loading

1 comment on commit dda9ea1

@vercel
Copy link

@vercel vercel bot commented on dda9ea1 Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.