From 575c6a152f4d167343bc30e83730cea9ff311c69 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 5 May 2023 05:23:59 -0400 Subject: [PATCH] feat(react): support allowJs customization in the rollup executor (#16789) --- .../packages/rollup/executors/rollup.json | 10 +++---- .../rollup/lib/update-package-json.spec.ts | 26 ------------------- .../rollup/lib/update-package-json.ts | 4 +-- .../src/executors/rollup/rollup.impl.ts | 6 ++--- .../rollup/src/executors/rollup/schema.d.ts | 3 +-- .../rollup/src/executors/rollup/schema.json | 10 +++---- 6 files changed, 15 insertions(+), 44 deletions(-) diff --git a/docs/generated/packages/rollup/executors/rollup.json b/docs/generated/packages/rollup/executors/rollup.json index 96cc44def2428..f9c10f29d3087 100644 --- a/docs/generated/packages/rollup/executors/rollup.json +++ b/docs/generated/packages/rollup/executors/rollup.json @@ -57,6 +57,11 @@ "x-completion-glob": "tsconfig.*.json", "x-priority": "important" }, + "allowJs": { + "type": "boolean", + "description": "Allow JavaScript files to be compiled.", + "default": false + }, "format": { "type": "array", "description": "List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).", @@ -154,11 +159,6 @@ "type": "boolean", "description": "Generate package.json with 'exports' field. This field defines entry points in the package and is used by Node and the TypeScript compiler.", "default": false - }, - "skipTypeField": { - "type": "boolean", - "description": "Prevents 'type' field from being added to compiled package.json file. Only use this if you are having an issue with this field.", - "default": false } }, "required": ["tsConfig", "main", "outputPath"], diff --git a/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts b/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts index 1ef3663611dc7..e783760c55b88 100644 --- a/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts +++ b/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts @@ -265,30 +265,4 @@ describe('updatePackageJson', () => { spy.mockRestore(); }); }); - - describe('skipTypeField', () => { - it('should not add "type" field in package.json', () => { - const spy = jest.spyOn(utils, 'writeJsonFile'); - - updatePackageJson( - { - ...commonOptions, - format: ['esm'], - skipTypeField: true, - }, - sharedContext, - { type: 'app', name: 'test', data: {} as any }, - [], - {} as unknown as PackageJson - ); - - expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), { - main: './index.js', - module: './index.js', - types: './index.d.ts', - }); - - spy.mockRestore(); - }); - }); }); 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 84645d173eaca..992749df0d321 100644 --- a/packages/rollup/src/executors/rollup/lib/update-package-json.ts +++ b/packages/rollup/src/executors/rollup/lib/update-package-json.ts @@ -46,9 +46,7 @@ export function updatePackageJson( exports['.']['require'] = './index.cjs'; } - if (!options.skipTypeField) { - packageJson.type = options.format.includes('esm') ? 'module' : 'commonjs'; - } + 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/rollup.impl.ts b/packages/rollup/src/executors/rollup/rollup.impl.ts index 5d295c1235974..ea583abcd9860 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.ts @@ -313,13 +313,13 @@ export function createRollupOptions( function createTsCompilerOptions( config: ts.ParsedCommandLine, - dependencies, - options + dependencies: DependentBuildableProjectNode[], + options: NormalizedRollupExecutorOptions ) { const compilerOptionPaths = computeCompilerOptionsPaths(config, dependencies); const compilerOptions = { rootDir: options.projectRoot, - allowJs: false, + allowJs: options.allowJs, declaration: true, paths: compilerOptionPaths, }; diff --git a/packages/rollup/src/executors/rollup/schema.d.ts b/packages/rollup/src/executors/rollup/schema.d.ts index a2bc5d5689f27..f5034297affdc 100644 --- a/packages/rollup/src/executors/rollup/schema.d.ts +++ b/packages/rollup/src/executors/rollup/schema.d.ts @@ -15,6 +15,7 @@ export interface Globals { export interface RollupExecutorOptions { outputPath: string; tsConfig: string; + allowJs?: boolean; project: string; main: string; outputFileName?: string; @@ -29,7 +30,5 @@ export interface RollupExecutorOptions { format?: string[]; compiler?: 'babel' | 'tsc' | 'swc'; javascriptEnabled?: boolean; - // 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 a9035a8defbc9..b4faad2986b4e 100644 --- a/packages/rollup/src/executors/rollup/schema.json +++ b/packages/rollup/src/executors/rollup/schema.json @@ -54,6 +54,11 @@ "x-completion-glob": "tsconfig.*.json", "x-priority": "important" }, + "allowJs": { + "type": "boolean", + "description": "Allow JavaScript files to be compiled.", + "default": false + }, "format": { "type": "array", "description": "List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).", @@ -141,11 +146,6 @@ "type": "boolean", "description": "Generate package.json with 'exports' field. This field defines entry points in the package and is used by Node and the TypeScript compiler.", "default": false - }, - "skipTypeField": { - "type": "boolean", - "description": "Prevents 'type' field from being added to compiled package.json file. Only use this if you are having an issue with this field.", - "default": false } }, "required": ["tsConfig", "main", "outputPath"],