Skip to content

Commit 14f91b3

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 346b01f commit 14f91b3

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
@@ -21,7 +21,15 @@ const bundleTypes = {
2121
};
2222

2323
async function run(argv) {
24-
const { bundle, largeFiles, outDir: outDirBase, verbose, cjsDir } = argv;
24+
const {
25+
bundle,
26+
largeFiles,
27+
outDir: outDirBase,
28+
verbose,
29+
cjsDir,
30+
babelIgnore,
31+
babelFlag: babelFlags,
32+
} = argv;
2533

2634
if (!validBundles.includes(bundle)) {
2735
throw new TypeError(
@@ -32,11 +40,16 @@ async function run(argv) {
3240
const packageJsonPath = path.resolve('./package.json');
3341
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf8' }));
3442

35-
const babelRuntimeVersion = packageJson.dependencies?.['@babel/runtime'];
43+
let babelRuntimeVersion = packageJson.dependencies['@babel/runtime'];
3644
if (!babelRuntimeVersion) {
3745
throw new Error(
3846
'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.',
3947
);
48+
} else if (babelRuntimeVersion === 'catalog:') {
49+
// resolve the version from the given package
50+
const { stdout: listedBabelRuntime } = await exec('pnpm list "@babel/runtime" --json');
51+
const jsonListedDependencies = JSON.parse(listedBabelRuntime);
52+
babelRuntimeVersion = jsonListedDependencies[0].dependencies['@babel/runtime'].version;
4053
}
4154

4255
const babelConfigPath = path.resolve(getWorkspaceRoot(), 'babel.config.js');
@@ -46,11 +59,13 @@ async function run(argv) {
4659
'**/*.test.js',
4760
'**/*.test.ts',
4861
'**/*.test.tsx',
62+
'**/*.spec.js',
4963
'**/*.spec.ts',
5064
'**/*.spec.tsx',
5165
'**/*.d.ts',
5266
'**/*.test/*.*',
5367
'**/test-cases/*.*',
68+
...babelIgnore,
5469
];
5570

5671
const outFileExtension = '.js';
@@ -68,7 +83,7 @@ async function run(argv) {
6883
MUI_BUILD_VERBOSE: verbose,
6984
MUI_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
7085
MUI_OUT_FILE_EXTENSION: outFileExtension,
71-
...(await getVersionEnvVariables(packageJson)),
86+
...getVersionEnvVariables(packageJson),
7287
};
7388

7489
const babelArgs = [
@@ -82,6 +97,7 @@ async function run(argv) {
8297
'--ignore',
8398
// Need to put these patterns in quotes otherwise they might be evaluated by the used terminal.
8499
`"${ignore.join('","')}"`,
100+
...babelFlags,
85101
];
86102

87103
if (outFileExtension !== '.js') {
@@ -153,7 +169,14 @@ yargs(process.argv.slice(2))
153169
description: 'The directory to copy the cjs files to.',
154170
})
155171
.option('out-dir', { default: './build', type: 'string' })
156-
.option('verbose', { type: 'boolean' });
172+
.option('babel-ignore', { type: 'string', array: true, default: [] })
173+
.option('verbose', { type: 'boolean' })
174+
.option('babel-flag', {
175+
type: 'string',
176+
array: true,
177+
default: [],
178+
description: 'Additional flags to pass to babel cli.',
179+
});
157180
},
158181
handler: run,
159182
})

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)