From ce38d3321c089ca7d75f09e2811819f21b8a3ab0 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Fri, 31 Mar 2023 10:16:50 -0600 Subject: [PATCH] fix(js): remove thirdparty default and normalize it based on bundle closed #15954 --- .../packages/esbuild/executors/esbuild.json | 3 +-- .../executors/esbuild/lib/normalize.spec.ts | 17 ++++++++++++++++ .../src/executors/esbuild/lib/normalize.ts | 20 ++++++++++++++++++- .../esbuild/src/executors/esbuild/schema.json | 3 +-- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/generated/packages/esbuild/executors/esbuild.json b/docs/generated/packages/esbuild/executors/esbuild.json index fefe3987839969..9f54aec9435126 100644 --- a/docs/generated/packages/esbuild/executors/esbuild.json +++ b/docs/generated/packages/esbuild/executors/esbuild.json @@ -154,8 +154,7 @@ }, "thirdParty": { "type": "boolean", - "description": "Includes third-party packages in the bundle (i.e. npm packages).", - "default": true + "description": "Includes third-party packages in the bundle (i.e. npm packages)." }, "dependenciesFieldType": { "type": "string", diff --git a/packages/esbuild/src/executors/esbuild/lib/normalize.spec.ts b/packages/esbuild/src/executors/esbuild/lib/normalize.spec.ts index 4f9fed0b307fa8..93e128696ce409 100644 --- a/packages/esbuild/src/executors/esbuild/lib/normalize.spec.ts +++ b/packages/esbuild/src/executors/esbuild/lib/normalize.spec.ts @@ -137,4 +137,21 @@ describe('normalizeOptions', () => { external: [], }); }); + + it('should override thirdParty if bundle:false', () => { + expect( + normalizeOptions( + { + main: 'apps/myapp/src/index.ts', + outputPath: 'dist/apps/myapp', + tsConfig: 'apps/myapp/tsconfig.app.json', + generatePackageJson: true, + bundle: false, + thirdParty: true, + assets: [], + }, + context + ) + ).toEqual(expect.objectContaining({ thirdParty: false })); + }); }); diff --git a/packages/esbuild/src/executors/esbuild/lib/normalize.ts b/packages/esbuild/src/executors/esbuild/lib/normalize.ts index e1114e9ef7b433..67de72e6f39afa 100644 --- a/packages/esbuild/src/executors/esbuild/lib/normalize.ts +++ b/packages/esbuild/src/executors/esbuild/lib/normalize.ts @@ -3,7 +3,8 @@ import { EsBuildExecutorOptions, NormalizedEsBuildExecutorOptions, } from '../schema'; -import { ExecutorContext, joinPathFragments } from '@nrwl/devkit'; +import { ExecutorContext, joinPathFragments, logger } from '@nrwl/devkit'; +import chalk = require('chalk'); export function normalizeOptions( options: EsBuildExecutorOptions, @@ -20,6 +21,21 @@ export function normalizeOptions( ), ]; + if (!options.bundle && options.thirdParty) { + logger.info( + chalk.yellow( + `Your build has conflicting options, ${chalk.bold( + 'bundle:false' + )} and ${chalk.bold( + 'thirdParty:true' + )}. Your package.json depedencies might not be generated correctly so we added an update ${chalk.bold( + 'thirdParty:false' + )}` + ) + ); + } + + const thirdParty = !options.bundle ? false : options.thirdParty; if (options.additionalEntryPoints?.length > 0) { const { outputFileName, ...rest } = options; if (outputFileName) { @@ -29,6 +45,7 @@ export function normalizeOptions( } return { ...rest, + thirdParty, assets, external: options.external ?? [], singleEntry: false, @@ -40,6 +57,7 @@ export function normalizeOptions( } else { return { ...options, + thirdParty, assets, external: options.external ?? [], singleEntry: true, diff --git a/packages/esbuild/src/executors/esbuild/schema.json b/packages/esbuild/src/executors/esbuild/schema.json index 5675e1764d9431..1c7bf4def3bc5f 100644 --- a/packages/esbuild/src/executors/esbuild/schema.json +++ b/packages/esbuild/src/executors/esbuild/schema.json @@ -129,8 +129,7 @@ }, "thirdParty": { "type": "boolean", - "description": "Includes third-party packages in the bundle (i.e. npm packages).", - "default": true + "description": "Includes third-party packages in the bundle (i.e. npm packages)." }, "dependenciesFieldType": { "type": "string",