From 942f6fc2eaa4138675a31bc9d86610a696f8f9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 2 Oct 2024 14:24:39 +0200 Subject: [PATCH] fix(js): throw an error when generating a publishable lib with `--bundler=none` (#28221) ## Current Behavior Generating a JS publishable library with `--bundler=none` results in the generator silently switching the `bundler` to `tsc` and generating a `build` target. ## Expected Behavior Trying to generate a JS publishable library with `--bundler=none` should throw an error. ## Related Issue(s) Fixes # --- packages/js/src/generators/library/library.ts | 4 +++- packages/nest/src/generators/library/lib/normalize-options.ts | 2 +- packages/node/src/generators/library/library.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 747e809ea350c..5d790a88ac8ed 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -856,7 +856,9 @@ async function normalizeOptions( } if (options.bundler === 'none') { - options.bundler = 'tsc'; + throw new Error( + `Publishable libraries can't be generated with "--bundler=none". Please select a valid bundler.` + ); } } diff --git a/packages/nest/src/generators/library/lib/normalize-options.ts b/packages/nest/src/generators/library/lib/normalize-options.ts index f3b84309e0ef7..8b1f1673c3902 100644 --- a/packages/nest/src/generators/library/lib/normalize-options.ts +++ b/packages/nest/src/generators/library/lib/normalize-options.ts @@ -64,7 +64,7 @@ export function toJsLibraryGeneratorOptions( ): JsLibraryGeneratorSchema { return { name: options.name, - bundler: options?.buildable ? 'tsc' : 'none', + bundler: options.buildable || options.publishable ? 'tsc' : 'none', directory: options.directory, importPath: options.importPath, linter: options.linter, diff --git a/packages/node/src/generators/library/library.ts b/packages/node/src/generators/library/library.ts index d2dc70409a2d6..4eec1209d3c8c 100644 --- a/packages/node/src/generators/library/library.ts +++ b/packages/node/src/generators/library/library.ts @@ -59,7 +59,7 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) { const libraryInstall = await jsLibraryGenerator(tree, { ...options, - bundler: schema.buildable ? 'tsc' : 'none', + bundler: schema.buildable || schema.publishable ? 'tsc' : 'none', includeBabelRc: schema.babelJest, importPath: options.importPath, testEnvironment: 'node',