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
17 changes: 3 additions & 14 deletions apps/code-infra-dashboard/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
{
"extends": "../../tsconfig.options.json",
"compilerOptions": {
"target": "ES2022",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"outDir": "./build",
"composite": true
"outDir": "build",
"allowJs": true
},
"include": ["src", "functions"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@octokit/rest": "^22.0.0",
"@tsconfig/node22": "^22.0.2",
"@types/node": "^22.18.8",
"@types/babel__core": "^7.20.5",
"@types/semver": "^7.7.1",
"@typescript-eslint/eslint-plugin": "8.45.0",
"@typescript-eslint/parser": "^8.45.0",
Expand Down
18 changes: 3 additions & 15 deletions packages/babel-plugin-minify-errors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
{
"extends": "../../tsconfig.js.json",
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"outDir": "./build",
"noEmit": true,
"composite": true
"outDir": "build"
},
"include": ["."],
"exclude": ["node_modules", "build", "__fixtures__"]
"include": ["*.js", "vite.config.mts"]
}
15 changes: 2 additions & 13 deletions packages/babel-plugin-resolve-imports/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
{
"extends": "../../tsconfig.js.json",
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"outDir": "./build",
"noEmit": true,
"composite": true
"outDir": "build"
},
"include": ["."],
"exclude": ["node_modules", "build", "__fixtures__"]
Expand Down
15 changes: 2 additions & 13 deletions packages/bundle-size-checker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
{
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"target": "ES2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"outDir": "./build",
"noEmit": true,
"composite": true
"outDir": "build"
},
"include": ["src"],
"exclude": ["node_modules", "build"]
Expand Down
2 changes: 0 additions & 2 deletions packages/code-infra/bin/code-infra.mjs

This file was deleted.

24 changes: 16 additions & 8 deletions packages/code-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"./markdownlint": "./src/markdownlint/index.mjs"
},
"bin": {
"code-infra": "./bin/code-infra.mjs"
"code-infra": "./src/bin/code-infra.mjs"
},
"scripts": {
"build-tsdown": "node ./src/bin/code-infra.mjs build-new --bundle esm",
"build-rslib": "node ./src/bin/code-infra.mjs build-new --bundler rslib",
"typescript": "tsc -p tsconfig.json",
"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 All @@ -45,6 +47,7 @@
"@octokit/auth-action": "^6.0.1",
"@octokit/rest": "^22.0.0",
"@pnpm/find-workspace-dir": "^1000.1.3",
"@swc/helpers": "^0.5.17",
"babel-plugin-optimize-clsx": "^2.6.2",
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
Expand All @@ -68,6 +71,7 @@
"postcss-styled-syntax": "^0.7.1",
"regexp.escape": "^2.0.1",
"resolve-pkg-maps": "^1.0.0",
"rsbuild-plugin-dts": "^0.14.0",
"semver": "^7.7.2",
"stylelint-config-standard": "^39.0.0",
"typescript-eslint": "^8.45.0",
Expand All @@ -76,8 +80,18 @@
"peerDependencies": {
"eslint": "^9.0.0",
"prettier": "^3.5.3",
"@rslib/core": "^0.14.0",
"tsdown": "^0.15.5",
"typescript": "^5.0.0"
},
"peerDependenciesMeta": {
"@rslib/core": {
"optional": true
},
"tsdown": {
"optional": true
}
},
"devDependencies": {
"@types/babel__core": "^7.20.5",
"@types/babel__preset-env": "^7.10.0",
Expand All @@ -90,15 +104,9 @@
"@typescript-eslint/rule-tester": "^8.45.0",
"eslint": "^9.36.0",
"prettier": "^3.6.2",
"tsdown": "^0.15.6",
"typescript-eslint": "^8.45.0"
},
"files": [
"bin",
"build",
"src",
"README.md",
"LICENSE"
],
"publishConfig": {
"access": "public"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/code-infra/src/bin/code-infra.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from '../cli/index.mjs';

run();
135 changes: 135 additions & 0 deletions packages/code-infra/src/bundlers/rslib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import * as fs from 'node:fs/promises';
import { builtinModules } from 'node:module';
import { build as rslib } from '@rslib/core';

import {
generateEntriesFromExports,
getTsConfigPath,
getVersionEnvVariables,
} from '../utils/build.mjs';

/**
* Findings -
* 1. Bundleless option is buggy. We cannot have `entry1/index.ts` and `entry2/index.ts`.
* 2. For some reason, typings are only generated for esm build and not cjs build.
*/

/**
* @typedef {import('../cli/cmdBuildNew.mjs').BaseArgs} Args
*/

/**
* @typedef {import('../cli/cmdBuildNew.mjs').PackageJson} PackageJson
*/

/**
* @param {Args} args
* @param {PackageJson} pkgJson
* @returns {Promise<void>}
*/
export async function build(args, pkgJson) {
const cwd = process.cwd();

const outDir = /** @type {any} */ (pkgJson.publishConfig)?.directory;
await fs.rm(outDir, {
recursive: true,
force: true,
});

const [exportEntries, , binEntries] = await generateEntriesFromExports(
pkgJson.exports ?? {},
pkgJson.bin ?? {},
{ cwd },
);
const externals = new Set([
...Object.keys(pkgJson.dependencies || {}),
...Object.keys(pkgJson.peerDependencies || {}),
]);
/**
* @type {(string|RegExp)[]}
*/
const externalsArray = Array.from(externals);
externalsArray.push(new RegExp(`^(${externalsArray.join('|')})/`));
externalsArray.push(/^node:/);
externalsArray.push(...builtinModules);

const tsconfigPath = await getTsConfigPath(cwd);
const bannerText = `/**
* ${pkgJson.name} v${pkgJson.version}
*
* @license ${pkgJson.license ?? 'MIT'}
* This source code is licensed under the ${pkgJson.license} license found in the
* LICENSE file in the root directory of this source tree.
*/
`;

/**
* @type {import('@rslib/core').LibConfig}
*/
const baseLibOptions = {
banner: {
js: bannerText,
css: bannerText,
},
bundle: true,
autoExternal: true,
externalHelpers: true,
autoExtension: true,
dts: {
autoExtension: true,
distPath: outDir,
},
};

const instance = await rslib(
{
mode: 'production',
root: cwd,
logLevel: args.verbose ? 'info' : 'warn',
source: {
entry: exportEntries,
tsconfigPath: tsconfigPath ?? undefined,
define: {
...getVersionEnvVariables(/** @type {string} */ (pkgJson.version)),
},
},
lib: [
{
...baseLibOptions,
format: 'esm',
},
{
...baseLibOptions,
format: 'cjs',
},
{
...baseLibOptions,
source: {
entry: binEntries,
},
format: pkgJson.type === 'module' ? 'esm' : 'cjs',
bundle: true,
dts: false,
},
],
output: {
legalComments: 'inline',
target: 'web',
distPath: {
root: outDir,
},
externals: externalsArray,
minify: false,
filename: {
js: '[name].js',
},
},
},
{
root: cwd,
},
);
const res = await instance.build();
await fs.writeFile('build/manifest.json', `${JSON.stringify(res.stats?.toJson({}), null, 2)}\n`);
await res.close();
}
Loading
Loading