Skip to content

Commit ef2c940

Browse files
authored
[code-infra] Make getVersionEnvVariables reusable for other repos (mui#45562)
1 parent 6e28b19 commit ef2c940

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

scripts/build.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import childProcess from 'child_process';
2-
import glob from 'fast-glob';
32
import path from 'path';
43
import { promisify } from 'util';
54
import yargs from 'yargs';
@@ -67,7 +66,7 @@ async function run(argv) {
6766
MUI_BUILD_VERBOSE: verbose,
6867
MUI_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
6968
MUI_OUT_FILE_EXTENSION: outFileExtension,
70-
...(await getVersionEnvVariables()),
69+
...(await getVersionEnvVariables(packageJson)),
7170
};
7271

7372
const babelArgs = [

scripts/utils.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path';
22
import url from 'url';
3-
import fs from 'fs/promises';
43

54
/**
65
* Returns the full path of the root directory of this repository.
@@ -15,12 +14,10 @@ export function getWorkspaceRoot() {
1514
/**
1615
* Returns the version and destructured values of the version as env variables to be replaced.
1716
*/
18-
export async function getVersionEnvVariables() {
19-
const packageJsonData = await fs.readFile(path.resolve('./package.json'), 'utf8');
20-
const { version = null } = JSON.parse(packageJsonData);
21-
17+
export function getVersionEnvVariables(pkgJson) {
18+
const version = pkgJson.version;
2219
if (!version) {
23-
throw new Error('Could not find the version in the package.json');
20+
throw new Error('No version found in package.json');
2421
}
2522

2623
const [versionNumber, prerelease] = version.split('-');

0 commit comments

Comments
 (0)