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
  • Loading branch information
jaysoo committed Mar 31, 2023
1 parent 77f2d0a commit bdfb2b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
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
17 changes: 11 additions & 6 deletions packages/esbuild/src/utils/get-entry-points.ts
Original file line number Diff line number Diff line change
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,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<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) => {
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 ?? [], {
Expand All @@ -65,7 +70,7 @@ export function getEntryPoints(
}
};

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

return Array.from(entryPoints);
}

0 comments on commit bdfb2b3

Please sign in to comment.