Skip to content
Open
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
4 changes: 2 additions & 2 deletions apps/code-infra-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"@types/semver": "7.8.0",
"@types/ssh2": "1.15.5",
"baseline-browser-mapping": "2.11.16",
"typescript": "6.0.3"
"typescript": "7.0.2"
},
"scripts": {
"dev": "next dev --turbopack -p 3000",
"build": "next build",
"start": "next start",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"browserslist": {
"production": [
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"@types/react-dom": "19.2.4",
"@wooorm/starry-night": "3.10.0",
"serve": "14.2.6",
"typescript": "6.0.3"
"typescript": "7.0.2"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@
"@types/semver": "^7.8.0",
"@typescript-eslint/eslint-plugin": "^8.68.0",
"@typescript-eslint/parser": "^8.68.0",
"@typescript/native-preview": "^7.0.0-dev.20260707.2",
"@typescript/native": "npm:typescript@^7.0.2",
"eslint": "^10.9.1",
"jsdom": "^28.1.0",
"prettier": "3.9.6",
"pretty-quick": "^4.2.2",
"semver": "^7.8.5",
"tsx": "^4.23.12"
"tsx": "^4.23.12",
"typescript": "npm:@typescript/typescript6@^6.0.2"
},
"devDependencies": {
"@babel/plugin-transform-react-constant-elements": "7.29.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-display-name/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"scripts": {
"test": "jest",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"dependencies": {
"@babel/helper-module-imports": "^7.29.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-minify-errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"scripts": {
"test": "pnpm -w test --project @mui/internal-babel-plugin-minify-errors",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"dependencies": {
"@babel/helper-module-imports": "^7.29.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-resolve-imports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"directory": "packages/babel-plugin-resolve-imports"
},
"scripts": {
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"dependencies": {
"resolve": "^1.22.12"
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"build": "code-infra build --flat --tsgo --bundle esm",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"dependencies": {
"@babel/runtime": "^7.29.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/bundle-size-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"directory": "packages/bundle-size-checker"
},
"scripts": {
"build": "tsgo -p tsconfig.build.json",
"build": "tsc -p tsconfig.build.json",
"test": "pnpm -w test --project @mui/internal-bundle-size-checker",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"sideEffects": false,
"exports": {
Expand Down
10 changes: 4 additions & 6 deletions packages/code-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"code-infra": "./bin/code-infra.mjs"
},
"scripts": {
"build": "tsgo -p tsconfig.build.json",
"typescript": "tsgo -noEmit",
"build": "tsc -p tsconfig.build.json",
"typescript": "tsc -noEmit",
"test": "pnpm -w test --project @mui/internal-code-infra",
"test:copy": "rm -rf build && node bin/code-infra.mjs copy-files --glob \"src/cli/*.mjs\" --glob \"src/eslint/**/*.mjs:esm\""
},
Expand Down Expand Up @@ -148,15 +148,11 @@
},
"peerDependencies": {
"@next/eslint-plugin-next": "*",
"@typescript/native-preview": ">=7.0.0-dev.0",
"eslint": "^9.0.0 || ^10.0.0",
"prettier": "^3.0.0",
"typescript": "^5.0.0 || ^6.0.0"
},
"peerDependenciesMeta": {
"@typescript/native-preview": {
"optional": true
},
"typescript": {
"optional": true
}
Expand All @@ -174,12 +170,14 @@
"@types/yargs": "17.0.35",
"@typescript-eslint/parser": "8.68.0",
"@typescript-eslint/rule-tester": "8.68.0",
"@typescript/native": "npm:typescript@7.0.2",
"eslint": "10.9.1",
"get-port": "7.2.0",
"prettier": "3.9.6",
"remark": "15.0.1",
"remark-mdx": "3.1.1",
"serve": "14.2.6",
"typescript": "npm:@typescript/typescript6@6.0.2",
"typescript-eslint": "8.68.0"
},
"files": [
Expand Down
6 changes: 3 additions & 3 deletions packages/code-infra/src/cli/cmdBuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { readPnpmConfig } from '../utils/pnpm.mjs';
* @property {string[]} ignore - Globs to be ignored by Babel.
* @property {string[]} [copy] - Files/Directories to be copied. Can be a glob pattern.
* @property {boolean} [enableReactCompiler] - Whether to use the React compiler.
* @property {boolean} [tsgo] - Whether to build types using typescript native (tsgo).
* @property {boolean} [tsgo] - Whether to build types using the native TypeScript compiler.
* @property {boolean} [flat] - Deprecated no-op; flat builds are always used.
* @property {boolean} expand - Whether to enumerate glob patterns in exports/imports into concrete entries.
*/
Expand Down Expand Up @@ -229,9 +229,9 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
})
.option('tsgo', {
type: 'boolean',
default: process.env.MUI_USE_TSGO,
default: false,
description:
'Uses tsgo cli instead of tsc for type generation. Can also be set via env var "MUI_USE_TSGO"',
'Use the native TypeScript compiler instead of the TS6 JS compiler for type generation',
})
.option('flat', {
type: 'boolean',
Expand Down
94 changes: 55 additions & 39 deletions packages/code-infra/src/utils/typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,82 @@ import { getOutExtension, mapConcurrently } from '../utils/build.mjs';
const $$ = $({ stdio: 'inherit' });

/**
* Checks if tsgo CLI is available in the workspace's node_modules.
* @param {string} cwd - The current working directory to start searching from.
* @returns {Promise<string | null>} - The path to tsgo if found, null otherwise.
* Finds a CLI shim in a directory's node_modules/.bin.
* @param {string} dir
* @param {string} name
* @returns {Promise<string | null>}
*/
async function findTsgo(cwd) {
const workspaceDir = await findWorkspaceDir(cwd);
if (!workspaceDir) {
return null;
}
const tsgoPath = path.join(workspaceDir, 'node_modules', '.bin', 'tsgo');
const exists = await fs.stat(tsgoPath).then(
async function findBin(dir, name) {
const binPath = path.join(dir, 'node_modules', '.bin', name);
const exists = await fs.stat(binPath).then(
(stat) => stat.isFile(),
() => false,
);
return exists ? tsgoPath : null;
return exists ? binPath : null;
}

/**
* Resolves the native/JS TypeScript CLI pair from the workspace root's
* `node_modules/.bin`: tsgo/tsc when the legacy `tsgo` shim exists, tsc/tsc6
* otherwise, with bare `tsc` from PATH as the JS fallback.
*
* @param {string} cwd
* @returns {Promise<{ native: string | null, js: string }>}
*/
async function findTscPair(cwd) {
const workspaceDir = await findWorkspaceDir(cwd);
if (!workspaceDir) {
return { native: null, js: 'tsc' };
}

const [tsgo, tsc, tsc6] = await Promise.all([
findBin(workspaceDir, 'tsgo'),
findBin(workspaceDir, 'tsc'),
findBin(workspaceDir, 'tsc6'),
]);
if (tsgo) {
return { native: tsgo, js: 'tsc' };
}
return { native: tsc, js: tsc6 ?? 'tsc' };
}

/**
* Emits TypeScript declaration files.
* @param {string} tsconfig - The path to the tsconfig.json file.
* @param {string} outDir - The output directory for the declaration files.
* @param {Object} options
* @param {boolean} [options.useTsgo] - Whether to use typescript native (tsgo).
* @param {boolean} [options.useTsgo] - Whether to use the native TypeScript compiler.
*/
export async function emitDeclarations(tsconfig, outDir, options) {
const { useTsgo = false } = options ?? {};
const tsconfigDir = path.dirname(tsconfig);
const rootDir = path.resolve(tsconfigDir, './src');

const tsgoPath = useTsgo ? await findTsgo(tsconfigDir) : null;
const pair = await findTscPair(tsconfigDir);
const tsgoPath = useTsgo ? pair.native : null;
if (useTsgo && !tsgoPath) {
throw new Error(
'--tsgo flag was passed or MUI_USE_TSGO environment was set but no tsgo cli was found. Either remove the flag to use tsc or install the native package "@typescript/native-preview" at the workspace level to use tsgo.',
'--tsgo flag was passed but no native TypeScript cli was found. Either remove the flag to use the JS compiler or install TypeScript 7 at the workspace root, as "typescript@^7" or under an alias such as "@typescript/native".',
);
}

if (tsgoPath) {
console.log('Using tsgo for declaration emit');
await $$`${tsgoPath}
-p ${tsconfig}
--rootDir ${rootDir}
--outDir ${outDir}
--declaration
--emitDeclarationOnly
--noEmit false
--composite false
--incremental false
--declarationMap false`;
} else {
await $$`tsc
-p ${tsconfig}
--rootDir ${rootDir}
--outDir ${outDir}
--declaration
--emitDeclarationOnly
--noEmit false
--composite false
--incremental false
--declarationMap false`;
}
const tscPath = tsgoPath ?? pair.js;
console.log(
tsgoPath
? `Using ts-native for declaration emit: ${tscPath}`
: `Using ${tscPath} for declaration emit`,
);

await $$`${tscPath}
-p ${tsconfig}
--rootDir ${rootDir}
--outDir ${outDir}
--declaration
--emitDeclarationOnly
--noEmit false
--composite false
--incremental false
--declarationMap false`;
}

/**
Expand Down Expand Up @@ -198,7 +214,7 @@ export async function moveAndTransformDeclarations({ inputDir, buildDir, bundles
* @param {string} param0.buildDir - The build directory.
* @param {string} param0.cwd - The current working directory.
* @param {boolean} param0.skipTsc - Whether to skip running TypeScript compiler (tsc) for building types.
* @param {boolean} [param0.useTsgo=false] - Whether to build types using typescript native (tsgo).
* @param {boolean} [param0.useTsgo=false] - Whether to build types using the native TypeScript compiler.
* @param {'module' | 'commonjs'} [param0.packageType] - The package.json type field.
*/
export async function createTypes({
Expand Down
6 changes: 3 additions & 3 deletions packages/docs-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"test": "pnpm -w test --project @mui/internal-docs-infra",
"test:watch": "pnpm -w test:watch --project @mui/internal-docs-infra",
"test:coverage": "pnpm -w test --project @mui/internal-docs-infra --coverage --coverage.include=packages/docs-infra --coverage.exclude=packages/docs-infra/docs --coverage.exclude=packages/docs-infra/build --coverage.exclude=packages/docs-infra/scripts",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"dependencies": {
"@babel/runtime": "^7.29.7",
Expand Down Expand Up @@ -147,6 +147,7 @@
"remark-stringify": "^11.0.0",
"remark-typography": "^0.8.1",
"sucrase": "^3.35.1",
"typescript": "npm:@typescript/typescript6@6.0.2",
"typescript-api-extractor": "1.0.0-beta.6",
"uint8-to-base64": "^0.2.1",
"unified": "^11.0.5",
Expand Down Expand Up @@ -184,8 +185,7 @@
"next": "^15.0.0 || ^16.0.0",
"prettier": "^3.0.0",
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
"typescript": "^6.0.2"
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
Expand Down
2 changes: 1 addition & 1 deletion packages/netlify-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/node": "22.20.1"
},
"scripts": {
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"scripts": {
"build": "code-infra build --flat --tsgo",
"test": "pnpm -w test --project @mui/internal-test-utils",
"typescript": "tsgo -noEmit"
"typescript": "tsc -noEmit"
},
"dependencies": {
"@types/chai-dom": "^1.11.3",
Expand Down
Loading
Loading