diff --git a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts index 063a8bd30d7c94..beacfa222de8a2 100644 --- a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts +++ b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts @@ -71,6 +71,7 @@ export function buildEsbuildOptions( context.projectName, context, { + initialTsConfigFileName: options.tsConfig, initialEntryPoints: entryPoints, recursive: true, } @@ -105,6 +106,7 @@ export function buildEsbuildOptions( } else { // Otherwise, just transpile the project source files. Any workspace lib will need to be published separately. esbuildOptions.entryPoints = getEntryPoints(context.projectName, context, { + initialTsConfigFileName: options.tsConfig, initialEntryPoints: entryPoints, recursive: false, }); diff --git a/packages/esbuild/src/utils/get-entry-points.ts b/packages/esbuild/src/utils/get-entry-points.ts index 3604ff226ef267..211f3ac5b57e4c 100644 --- a/packages/esbuild/src/utils/get-entry-points.ts +++ b/packages/esbuild/src/utils/get-entry-points.ts @@ -6,6 +6,7 @@ import * as glob from 'fast-glob'; export interface GetEntryPointsOptions { recursive?: boolean; initialEntryPoints?: string[]; + initialTsConfigFileName?: string; onProjectFilesMatched?: (projectName: string, files: string[]) => void; } @@ -14,35 +15,39 @@ export function getEntryPoints( context: ExecutorContext, options: GetEntryPointsOptions = {} ): string[] { + // Known files we generate from our generators. Only one of these should be used to build the project. const tsconfigCandidates = [ 'tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json', - 'tsconfig.base.json', ]; const entryPoints = options.initialEntryPoints ? new Set(options.initialEntryPoints) : new Set(); const seenProjects = new Set(); - const findEntryPoints = (projectName: string): void => { + const findEntryPoints = ( + projectName: string, + tsConfigFileName?: string + ): void => { if (seenProjects.has(projectName)) return; seenProjects.add(projectName); const project = context.projectGraph?.nodes[projectName]; if (!project) return; - const tsconfigFileName = tsconfigCandidates.find((f) => { + tsConfigFileName ??= tsconfigCandidates.find((f) => { try { return fs.statSync(path.join(project.data.root, f)).isFile(); } catch { return false; } }); + // Workspace projects may not be a TS project, so skip reading source files if tsconfig is not found. - if (tsconfigFileName) { + if (tsConfigFileName) { const tsconfig = readJsonFile( - path.join(project.data.root, tsconfigFileName) + path.join(project.data.root, tsConfigFileName) ); const projectFiles = glob .sync(tsconfig.include ?? [], { @@ -65,7 +70,7 @@ export function getEntryPoints( } }; - findEntryPoints(projectName); + findEntryPoints(projectName, options.initialTsConfigFileName); return Array.from(entryPoints); }