@mui/internal-code-infra 0.0.3-canary.0 → 0.0.3-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/cli/cmdBuild.mjs +11 -12
- package/src/utils/build.mjs +50 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.0.3-canary.
|
|
3
|
+
"version": "0.0.3-canary.1",
|
|
4
4
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"semver": "^7.7.2",
|
|
59
59
|
"typescript-eslint": "^8.40.0",
|
|
60
60
|
"yargs": "^18.0.0",
|
|
61
|
-
"@mui/internal-babel-plugin-display-name": "1.0.4-canary.6",
|
|
62
61
|
"@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.7",
|
|
62
|
+
"@mui/internal-babel-plugin-display-name": "1.0.4-canary.6",
|
|
63
63
|
"@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.19"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
93
|
},
|
|
94
|
-
"gitSha": "
|
|
94
|
+
"gitSha": "2159d7ef17d0ea7ff2ba98c5df9f6519fcaccfbe",
|
|
95
95
|
"scripts": {
|
|
96
96
|
"typescript": "tsc -p tsconfig.json",
|
|
97
97
|
"test": "pnpm -w test --project @mui/internal-code-infra",
|
package/src/cli/cmdBuild.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { $ } from 'execa';
|
|
|
3
3
|
import set from 'lodash-es/set.js';
|
|
4
4
|
import * as fs from 'node:fs/promises';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
|
-
import { getOutExtension, isMjsBuild } from '../utils/build.mjs';
|
|
6
|
+
import { getOutExtension, isMjsBuild, validatePkgJson } from '../utils/build.mjs';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @typedef {Object} Args
|
|
@@ -16,6 +16,7 @@ import { getOutExtension, isMjsBuild } from '../utils/build.mjs';
|
|
|
16
16
|
* @property {boolean} skipTsc - Whether to build types for the package.
|
|
17
17
|
* @property {boolean} skipBabelRuntimeCheck - Whether to skip checking for Babel runtime dependencies in the package.
|
|
18
18
|
* @property {boolean} skipPackageJson - Whether to skip generating the package.json file in the bundle output.
|
|
19
|
+
* @property {boolean} skipMainCheck - Whether to skip checking for main field in package.json.
|
|
19
20
|
* @property {string[]} ignore - Globs to be ignored by Babel.
|
|
20
21
|
*/
|
|
21
22
|
|
|
@@ -291,6 +292,12 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
291
292
|
type: 'boolean',
|
|
292
293
|
default: false,
|
|
293
294
|
description: 'Skip generating the package.json file in the bundle output.',
|
|
295
|
+
})
|
|
296
|
+
.option('skipMainCheck', {
|
|
297
|
+
// Currently added only to support @mui/icons-material. To be removed separately.
|
|
298
|
+
type: 'boolean',
|
|
299
|
+
default: false,
|
|
300
|
+
description: 'Skip checking for main field in package.json.',
|
|
294
301
|
});
|
|
295
302
|
},
|
|
296
303
|
async handler(args) {
|
|
@@ -310,17 +317,9 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
310
317
|
const cwd = process.cwd();
|
|
311
318
|
const pkgJsonPath = path.join(cwd, 'package.json');
|
|
312
319
|
const packageJson = JSON.parse(await fs.readFile(pkgJsonPath, { encoding: 'utf8' }));
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
`No build directory specified in "${packageJson.name}" package.json. Specify it in the "publishConfig.directory" field.`,
|
|
317
|
-
);
|
|
318
|
-
}
|
|
319
|
-
if (packageJson.private === false) {
|
|
320
|
-
throw new Error(
|
|
321
|
-
`Remove the field "private": false from "${packageJson.name}" package.json. This is redundant.`,
|
|
322
|
-
);
|
|
323
|
-
}
|
|
320
|
+
validatePkgJson(packageJson, { skipMainCheck: args.skipMainCheck });
|
|
321
|
+
|
|
322
|
+
const buildDirBase = /** @type {string} */ (packageJson.publishConfig?.directory);
|
|
324
323
|
const buildDir = path.join(cwd, buildDirBase);
|
|
325
324
|
|
|
326
325
|
console.log(`Selected output directory: "${buildDirBase}"`);
|
package/src/utils/build.mjs
CHANGED
|
@@ -18,3 +18,53 @@ export function getOutExtension(bundle, isType = false) {
|
|
|
18
18
|
}
|
|
19
19
|
return bundle === 'esm' ? '.mjs' : '.js';
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validates the package.json before building.
|
|
24
|
+
* @param {Record<string, any>} packageJson
|
|
25
|
+
* @param {Object} [options]
|
|
26
|
+
* @param {boolean} [options.skipMainCheck=false] - Whether to skip checking for main field in package.json.
|
|
27
|
+
*/
|
|
28
|
+
export function validatePkgJson(packageJson, options = {}) {
|
|
29
|
+
const { skipMainCheck = false } = options;
|
|
30
|
+
/**
|
|
31
|
+
* @type {string[]}
|
|
32
|
+
*/
|
|
33
|
+
const errors = [];
|
|
34
|
+
const buildDirBase = packageJson.publishConfig?.directory;
|
|
35
|
+
if (!buildDirBase) {
|
|
36
|
+
errors.push(
|
|
37
|
+
`No build directory specified in "${packageJson.name}" package.json. Specify it in the "publishConfig.directory" field.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (packageJson.private === false) {
|
|
41
|
+
errors.push(
|
|
42
|
+
`Remove the field "private": false from "${packageJson.name}" package.json. This is redundant.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!skipMainCheck) {
|
|
47
|
+
if (packageJson.main) {
|
|
48
|
+
errors.push(
|
|
49
|
+
`Remove the field "main" from "${packageJson.name}" package.json. Add it as "exports["."]" instead.`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (packageJson.module) {
|
|
54
|
+
errors.push(
|
|
55
|
+
`Remove the field "module" from "${packageJson.name}" package.json. Add it as "exports["."]" instead.`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (packageJson.types || packageJson.typings) {
|
|
60
|
+
errors.push(
|
|
61
|
+
`Remove the field "types/typings" from "${packageJson.name}" package.json. Add it as "exports["."]" instead.`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (errors.length > 0) {
|
|
67
|
+
const error = new Error(errors.join('\n'));
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|