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

perf(scripts-task): turn off path aliases within generate-api task, make isUsingPathAliasesForDx lazy => improve d.ts generation speed by ~60% #30990

Merged
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
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: re-genearate api.md as result of perf improvements to generate-api task",
"packageName": "@fluentui/react-field",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Field: ForwardRefComponent<FieldProps>;
export const fieldClassNames: SlotClassNames<FieldSlots>;

// @public (undocumented)
export const FieldContextProvider: React_2.Provider<Readonly<Pick<FieldState, "orientation" | "required" | "size" | "validationState" | "generatedControlId"> & {
export const FieldContextProvider: React_2.Provider<Readonly<Pick<FieldState, "required" | "size" | "orientation" | "validationState" | "generatedControlId"> & {
labelFor?: string | undefined;
labelId?: string | undefined;
validationMessageId?: string | undefined;
Expand Down Expand Up @@ -81,7 +81,7 @@ export const renderField_unstable: (state: FieldState, contextValues: FieldConte
export const useField_unstable: (props: FieldProps, ref: React_2.Ref<HTMLDivElement>) => FieldState;

// @public (undocumented)
export const useFieldContext_unstable: () => Readonly<Pick<FieldState, "orientation" | "required" | "size" | "validationState" | "generatedControlId"> & {
export const useFieldContext_unstable: () => Readonly<Pick<FieldState, "required" | "size" | "orientation" | "validationState" | "generatedControlId"> & {
labelFor?: string | undefined;
labelId?: string | undefined;
validationMessageId?: string | undefined;
Expand Down
5 changes: 3 additions & 2 deletions scripts/tasks/src/generate-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export function generateApi() {
}

function generateTypeDeclarations() {
const { isUsingPathAliasesForDx, tsConfigFileForCompilation } = getTsPathAliasesConfigUsedOnlyForDx();
const { tsConfigFileForCompilation } = getTsPathAliasesConfigUsedOnlyForDx();
const cmd = [
'tsc',
`-p ./${tsConfigFileForCompilation}`,
'--emitDeclarationOnly',
isUsingPathAliasesForDx ? '--baseUrl .' : null,
// turn off path aliases.
'--baseUrl .',
]
.filter(Boolean)
.join(' ');
Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/src/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function prepareTsTaskConfig(options: TscTaskOptions) {

const { isUsingPathAliasesForDx, tsConfigFileForCompilation } = getTsPathAliasesConfigUsedOnlyForDx();

if (isUsingPathAliasesForDx) {
if (isUsingPathAliasesForDx()) {
logger.info(`📣 TSC: Project is using TS path aliases for DX. Disabling aliases for build.`);
options.baseUrl = '.';
options.rootDir = './src';
Expand Down
13 changes: 8 additions & 5 deletions scripts/tasks/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,27 @@ export function getTsPathAliasesConfig() {

export function getTsPathAliasesConfigUsedOnlyForDx() {
const tsConfigFilesWithAliases = ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json'];
const tsConfigBaseFilesForDx = ['tsconfig.base.v8.json', 'tsconfig.base.all.json'];
const cwd = process.cwd();
const tsConfigPath = path.join(cwd, `./tsconfig.json`);

if (!fs.existsSync(tsConfigPath)) {
throw new Error(`${tsConfigPath} doesn't exist`);
}

const tsConfig = JSON.parse(stripJsonComments(fs.readFileSync(tsConfigPath, 'utf-8')));
const isUsingPathAliasesForDx =
tsConfig.extends && tsConfigBaseFilesForDx.some(relativeFilePath => tsConfig.extends.endsWith(relativeFilePath));

const tsConfigFileForCompilation = tsConfigFilesWithAliases.find(fileName => fs.existsSync(path.join(cwd, fileName)));

if (!tsConfigFileForCompilation) {
throw new Error(`no tsconfig from one of [${tsConfigFilesWithAliases}] found!`);
}

const isUsingPathAliasesForDx = () => {
const tsConfigBaseFilesForDx = ['tsconfig.base.v8.json', 'tsconfig.base.all.json'];
const tsConfig = JSON.parse(stripJsonComments(fs.readFileSync(tsConfigPath, 'utf-8')));
return Boolean(
tsConfig.extends && tsConfigBaseFilesForDx.some(relativeFilePath => tsConfig.extends.endsWith(relativeFilePath)),
);
};

return { isUsingPathAliasesForDx, tsConfigFileForCompilation };
}

Expand Down
Loading