From d34674a0c65ef625327bf1c91b5d33013bf85853 Mon Sep 17 00:00:00 2001 From: Evan Gillogley Date: Fri, 16 Jun 2023 13:25:45 +0100 Subject: [PATCH] fix(web): readd skipTypeField previously removed and needs to be readded back since nx should always support esm modules with cjs dependencies. Forcing modern libraries to be not in esm format isn't good practice --- docs/generated/packages/rollup/executors/rollup.json | 5 +++++ .../rollup/src/executors/rollup/lib/update-package-json.ts | 5 +++-- packages/rollup/src/executors/rollup/schema.d.ts | 1 + packages/rollup/src/executors/rollup/schema.json | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/generated/packages/rollup/executors/rollup.json b/docs/generated/packages/rollup/executors/rollup.json index 35183f237417d7..2e0c5501f0f0e2 100644 --- a/docs/generated/packages/rollup/executors/rollup.json +++ b/docs/generated/packages/rollup/executors/rollup.json @@ -169,6 +169,11 @@ "type": "boolean", "description": "Whether to skip TypeScript type checking.", "default": false + }, + "skipTypeField": { + "type": "boolean", + "description": "Prevent type field from being added to package json. Use this if you have an esm library with common js imports.", + "default": false } }, "required": ["tsConfig", "main", "outputPath"], 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 992749df0d3213..79843aa988085a 100644 --- a/packages/rollup/src/executors/rollup/lib/update-package-json.ts +++ b/packages/rollup/src/executors/rollup/lib/update-package-json.ts @@ -45,8 +45,9 @@ export function updatePackageJson( packageJson.main = './index.cjs'; exports['.']['require'] = './index.cjs'; } - - packageJson.type = options.format.includes('esm') ? 'module' : 'commonjs'; + if (!options.skipTypeField) { + packageJson.type = options.format.includes('esm') ? 'module' : 'commonjs'; + } // Support for older TS versions < 4.5 packageJson.types = types; diff --git a/packages/rollup/src/executors/rollup/schema.d.ts b/packages/rollup/src/executors/rollup/schema.d.ts index ffef9aa4be9a3c..750d186e3abf16 100644 --- a/packages/rollup/src/executors/rollup/schema.d.ts +++ b/packages/rollup/src/executors/rollup/schema.d.ts @@ -33,4 +33,5 @@ export interface RollupExecutorOptions { generateExportsField?: boolean; skipTypeCheck?: boolean; babelUpwardRootMode?: boolean; + skipTypeField?: boolean; } diff --git a/packages/rollup/src/executors/rollup/schema.json b/packages/rollup/src/executors/rollup/schema.json index 6510c4c224152e..acdb038fb9e0c5 100644 --- a/packages/rollup/src/executors/rollup/schema.json +++ b/packages/rollup/src/executors/rollup/schema.json @@ -156,6 +156,11 @@ "type": "boolean", "description": "Whether to skip TypeScript type checking.", "default": false + }, + "skipTypeField": { + "type": "boolean", + "description": "Prevent type field from being added to package json. Use this if you have an esm library with common js imports.", + "default": false } }, "required": ["tsConfig", "main", "outputPath"],