Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bundling): pass tsConfig from project when --bundle=false so the correct file is applied #16006

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 17 additions & 11 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,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);
}