Skip to content

Commit

Permalink
fix(bundling): pass tsConfig from project when --bundle=false so the …
Browse files Browse the repository at this point in the history
…correct file is applied (#16006)
  • Loading branch information
jaysoo committed Mar 31, 2023
1 parent ad37d77 commit 47c671c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Expand Up @@ -71,6 +71,7 @@ export function buildEsbuildOptions(
context.projectName,
context,
{
initialTsConfigFileName: options.tsConfig,
initialEntryPoints: entryPoints,
recursive: true,
}
Expand Down Expand Up @@ -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,
});
Expand Down
28 changes: 17 additions & 11 deletions packages/esbuild/src/utils/get-entry-points.ts
Expand Up @@ -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;
}

Expand All @@ -14,35 +15,40 @@ export function getEntryPoints(
context: ExecutorContext,
options: GetEntryPointsOptions = {}
): string[] {
const tsconfigCandidates = [
'tsconfig.app.json',
'tsconfig.lib.json',
'tsconfig.json',
'tsconfig.base.json',
];
const entryPoints = options.initialEntryPoints
? new Set(options.initialEntryPoints)
: new Set<string>();
const seenProjects = new Set<string>();

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) => {
// 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',
];
if (tsConfigFileName) tsconfigCandidates.unshift(tsConfigFileName);
const foundTsConfig = 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 (foundTsConfig) {
const tsconfig = readJsonFile(
path.join(project.data.root, tsconfigFileName)
path.join(project.data.root, foundTsConfig)
);
const projectFiles = glob
.sync(tsconfig.include ?? [], {
Expand All @@ -65,7 +71,7 @@ export function getEntryPoints(
}
};

findEntryPoints(projectName);
findEntryPoints(projectName, options.initialTsConfigFileName);

return Array.from(entryPoints);
}

0 comments on commit 47c671c

Please sign in to comment.