@mui/internal-code-infra 0.0.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.0.2",
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",
@@ -31,6 +31,7 @@
31
31
  "@eslint/compat": "^1.3.2",
32
32
  "@eslint/js": "^9.34.0",
33
33
  "@next/eslint-plugin-next": "^15.5.0",
34
+ "@octokit/auth-action": "^6.0.1",
34
35
  "@octokit/rest": "^22.0.0",
35
36
  "@pnpm/find-workspace-dir": "^1000.1.2",
36
37
  "babel-plugin-optimize-clsx": "^2.6.2",
@@ -57,9 +58,9 @@
57
58
  "semver": "^7.7.2",
58
59
  "typescript-eslint": "^8.40.0",
59
60
  "yargs": "^18.0.0",
60
- "@mui/internal-babel-plugin-resolve-imports": "2.0.5",
61
- "@mui/internal-babel-plugin-minify-errors": "2.0.6",
62
- "@mui/internal-babel-plugin-display-name": "1.0.2"
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
+ "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.19"
63
64
  },
64
65
  "peerDependencies": {
65
66
  "eslint": "^9.0.0",
@@ -90,6 +91,7 @@
90
91
  "publishConfig": {
91
92
  "access": "public"
92
93
  },
94
+ "gitSha": "2159d7ef17d0ea7ff2ba98c5df9f6519fcaccfbe",
93
95
  "scripts": {
94
96
  "typescript": "tsc -p tsconfig.json",
95
97
  "test": "pnpm -w test --project @mui/internal-code-infra",
@@ -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
 
@@ -209,6 +210,20 @@ async function writePackageJson({ packageJson, bundles, outputDir, cwd, addTypes
209
210
  }
210
211
  });
211
212
 
213
+ // default condition should come last
214
+ Object.keys(newExports).forEach((key) => {
215
+ const exportVal = newExports[key];
216
+ if (exportVal && typeof exportVal === 'object' && (exportVal.import || exportVal.require)) {
217
+ const defaultExport = exportVal.import || exportVal.require;
218
+ if (exportVal.import) {
219
+ delete exportVal.import;
220
+ } else if (exportVal.require) {
221
+ delete exportVal.require;
222
+ }
223
+ exportVal.default = defaultExport;
224
+ }
225
+ });
226
+
212
227
  packageJson.exports = newExports;
213
228
 
214
229
  await fs.writeFile(
@@ -277,6 +292,12 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
277
292
  type: 'boolean',
278
293
  default: false,
279
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.',
280
301
  });
281
302
  },
282
303
  async handler(args) {
@@ -296,17 +317,9 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
296
317
  const cwd = process.cwd();
297
318
  const pkgJsonPath = path.join(cwd, 'package.json');
298
319
  const packageJson = JSON.parse(await fs.readFile(pkgJsonPath, { encoding: 'utf8' }));
299
- const buildDirBase = packageJson.publishConfig?.directory;
300
- if (!buildDirBase) {
301
- throw new Error(
302
- `No build directory specified in "${packageJson.name}" package.json. Specify it in the "publishConfig.directory" field.`,
303
- );
304
- }
305
- if (packageJson.private === false) {
306
- throw new Error(
307
- `Remove the field "private": false from "${packageJson.name}" package.json. This is redundant.`,
308
- );
309
- }
320
+ validatePkgJson(packageJson, { skipMainCheck: args.skipMainCheck });
321
+
322
+ const buildDirBase = /** @type {string} */ (packageJson.publishConfig?.directory);
310
323
  const buildDir = path.join(cwd, buildDirBase);
311
324
 
312
325
  console.log(`Selected output directory: "${buildDirBase}"`);
@@ -12,8 +12,13 @@ import * as fs from 'node:fs/promises';
12
12
  import * as semver from 'semver';
13
13
  import gitUrlParse from 'git-url-parse';
14
14
  import { $ } from 'execa';
15
+ import { createActionAuth } from '@octokit/auth-action';
15
16
  import { getWorkspacePackages, publishPackages } from './pnpm.mjs';
16
17
 
18
+ function getOctokit() {
19
+ return new Octokit({ authStrategy: createActionAuth });
20
+ }
21
+
17
22
  /**
18
23
  * @typedef {Object} Args
19
24
  * @property {boolean} dry-run Run in dry-run mode without publishing
@@ -92,14 +97,14 @@ async function parseChangelog(changelogPath, version) {
92
97
 
93
98
  /**
94
99
  * Check if GitHub release already exists
95
- * @param {Octokit} octokit - GitHub API client
96
100
  * @param {string} owner - Repository owner
97
101
  * @param {string} repo - Repository name
98
102
  * @param {string} version - Version to check
99
103
  * @returns {Promise<boolean>} True if release exists
100
104
  */
101
- async function checkGitHubReleaseExists(octokit, owner, repo, version) {
105
+ async function checkGitHubReleaseExists(owner, repo, version) {
102
106
  try {
107
+ const octokit = getOctokit();
103
108
  await octokit.repos.getReleaseByTag({ owner, repo, tag: `v${version}` });
104
109
  return true;
105
110
  } catch (/** @type {any} */ error) {
@@ -184,18 +189,8 @@ async function validateGitHubRelease(version) {
184
189
  const repoInfo = await getRepositoryInfo();
185
190
  console.log(`šŸ“‚ Repository: ${repoInfo.owner}/${repoInfo.repo}`);
186
191
 
187
- // Check if release already exists on GitHub
188
- const octokit = new Octokit({
189
- auth: process.env.GITHUB_TOKEN,
190
- });
191
-
192
192
  console.log(`šŸ” Checking if GitHub release v${validVersion} already exists...`);
193
- const releaseExists = await checkGitHubReleaseExists(
194
- octokit,
195
- repoInfo.owner,
196
- repoInfo.repo,
197
- validVersion,
198
- );
193
+ const releaseExists = await checkGitHubReleaseExists(repoInfo.owner, repoInfo.repo, validVersion);
199
194
 
200
195
  if (releaseExists) {
201
196
  throw new Error(`GitHub release v${validVersion} already exists`);
@@ -233,12 +228,9 @@ async function publishToNpm(packages, options) {
233
228
  async function createRelease(version, changelogContent, repoInfo) {
234
229
  console.log('\nšŸš€ Creating GitHub draft release...');
235
230
 
236
- const octokit = new Octokit({
237
- auth: process.env.GITHUB_TOKEN,
238
- });
239
-
240
231
  const sha = await getCurrentGitSha();
241
232
 
233
+ const octokit = getOctokit();
242
234
  await octokit.repos.createRelease({
243
235
  owner: repoInfo.owner,
244
236
  repo: repoInfo.repo,
@@ -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
+ }