Skip to content

Commit

Permalink
perf(scripts-task): turn off path aliases within generate-api task, m…
Browse files Browse the repository at this point in the history
…ake isUsingPathAliasesForDx lazy => improve d.ts generation speed by ~60% (#30990)
  • Loading branch information
Hotell authored Apr 11, 2024
1 parent 60063f3 commit 0e56f62
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
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"
}
4 changes: 2 additions & 2 deletions packages/react-components/react-field/etc/react-field.api.md
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

0 comments on commit 0e56f62

Please sign in to comment.