Skip to content

Commit b265f19

Browse files
author
Brijesh Bittu
committed
[code-infra] Accomodate build requirements from mui-x
* Allow passing of extra flags to the babel-cli * Check existence of package files (like license, changelogs etc) before copying them.
1 parent b59579a commit b265f19

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

scripts/build.mjs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ const bundleTypes = {
2525
};
2626

2727
async function run(argv) {
28-
const { bundle, largeFiles, outDir: outDirBase, verbose, cjsDir } = argv;
28+
const {
29+
bundle,
30+
largeFiles,
31+
outDir: outDirBase,
32+
verbose,
33+
cjsDir,
34+
babelIgnore,
35+
babelFlag: babelFlags,
36+
} = argv;
2937

3038
if (!validBundles.includes(bundle)) {
3139
throw new TypeError(
@@ -36,11 +44,16 @@ async function run(argv) {
3644
const packageJsonPath = path.resolve('./package.json');
3745
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf8' }));
3846

39-
const babelRuntimeVersion = packageJson.dependencies?.['@babel/runtime'];
47+
let babelRuntimeVersion = packageJson.dependencies['@babel/runtime'];
4048
if (!babelRuntimeVersion) {
4149
throw new Error(
4250
'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.',
4351
);
52+
} else if (babelRuntimeVersion === 'catalog:') {
53+
// resolve the version from the given package
54+
const { stdout: listedBabelRuntime } = await exec('pnpm list "@babel/runtime" --json');
55+
const jsonListedDependencies = JSON.parse(listedBabelRuntime);
56+
babelRuntimeVersion = jsonListedDependencies[0].dependencies['@babel/runtime'].version;
4457
}
4558

4659
const babelConfigPath = path.resolve(getWorkspaceRoot(), 'babel.config.js');
@@ -50,11 +63,13 @@ async function run(argv) {
5063
'**/*.test.js',
5164
'**/*.test.ts',
5265
'**/*.test.tsx',
66+
'**/*.spec.js',
5367
'**/*.spec.ts',
5468
'**/*.spec.tsx',
5569
'**/*.d.ts',
5670
'**/*.test/*.*',
5771
'**/test-cases/*.*',
72+
...babelIgnore,
5873
];
5974

6075
let outFileExtension = '.js';
@@ -78,7 +93,7 @@ async function run(argv) {
7893
MUI_BUILD_VERBOSE: verbose,
7994
MUI_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
8095
MUI_OUT_FILE_EXTENSION: outFileExtension,
81-
...(await getVersionEnvVariables(packageJson)),
96+
...getVersionEnvVariables(packageJson),
8297
};
8398

8499
const babelArgs = [
@@ -92,6 +107,7 @@ async function run(argv) {
92107
'--ignore',
93108
// Need to put these patterns in quotes otherwise they might be evaluated by the used terminal.
94109
`"${ignore.join('","')}"`,
110+
...babelFlags,
95111
];
96112

97113
if (outFileExtension !== '.js') {
@@ -161,7 +177,14 @@ yargs(process.argv.slice(2))
161177
description: 'The directory to copy the cjs files to.',
162178
})
163179
.option('out-dir', { default: './build', type: 'string' })
164-
.option('verbose', { type: 'boolean' });
180+
.option('babel-ignore', { type: 'string', array: true, default: [] })
181+
.option('verbose', { type: 'boolean' })
182+
.option('babel-flag', {
183+
type: 'string',
184+
array: true,
185+
default: [],
186+
description: 'Additional flags to pass to babel cli.',
187+
});
165188
},
166189
handler: run,
167190
})

scripts/copyFiles.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,28 @@ async function run() {
3434
const extraFiles = process.argv.slice(2);
3535
try {
3636
const packageData = await createPackageFile(true);
37+
const defaultFiles = ['README.md'];
3738

38-
let changlogPath;
39-
if (await fileExists(path.join(packagePath, './CHANGELOG.md'))) {
40-
changlogPath = './CHANGELOG.md';
41-
} else {
42-
changlogPath = '../../CHANGELOG.md';
43-
}
39+
const packageOrRootFiles = [
40+
['LICENSE', '../../LICENSE'],
41+
['CHANGELOG.md', '../../CHANGELOG.md'],
42+
];
43+
44+
await Promise.all(
45+
packageOrRootFiles.map(async (files) => {
46+
for (const file of files) {
47+
const sourcePath = path.join(packagePath, file);
48+
// eslint-disable-next-line no-await-in-loop
49+
if (await fileExists(sourcePath)) {
50+
defaultFiles.push(file);
51+
break;
52+
}
53+
}
54+
}),
55+
);
4456

4557
await Promise.all(
46-
['./README.md', changlogPath, '../../LICENSE', ...extraFiles].map(async (file) => {
58+
[...defaultFiles, ...extraFiles].map(async (file) => {
4759
const [sourcePath, targetPath] = file.split(':');
4860
await includeFileInBuild(sourcePath, targetPath);
4961
}),

0 commit comments

Comments
 (0)