Skip to content

Commit d5ba75e

Browse files
committed
[code-infra][icons] Revert to using wildcard export paths
This is to fix the issues with TS/VSCode breaking on trying to index ~11000 subpaths - mui#48364
1 parent 71fdf6b commit d5ba75e

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

packages/mui-icons-material/scripts/merge-package-json.mjs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,45 @@ import url from 'url';
66
const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));
77
const packageDir = path.resolve(currentDirectory, '..');
88

9+
// Wildcard exports keep the published package.json small (~10 lines instead of
10+
// ~10k explicit subpath entries). The flat list balloons the file enough that
11+
// the TypeScript language server stalls or crashes when indexing
12+
// package.json for auto-imports. See https://github.com/mui/material-ui/issues/48364
13+
// and https://github.com/microsoft/TypeScript/issues/60854.
14+
const wildcardExports = {
15+
'./package.json': './package.json',
16+
'.': {
17+
require: './index.js',
18+
import: './index.mjs',
19+
default: './index.mjs',
20+
},
21+
'./*': {
22+
require: './*.js',
23+
import: './*.mjs',
24+
default: './*.mjs',
25+
},
26+
};
27+
928
/**
1029
* Reads `package.json` and `lib/package.json`, then creates a new package.json
11-
* where all fields come from the root `package.json` but the `exports` field
12-
* is copied over from `lib/package.json`.
30+
* where all fields come from `lib/package.json` (so build-time fields like
31+
* `main` point at `./index.js`), with a few metadata fields pulled from the
32+
* root `package.json`. The `exports` field is overridden with a wildcard form.
1333
*/
1434
async function run() {
1535
const rootPackageJsonPath = path.resolve(packageDir, 'package.json');
16-
const libPackageJsonPath = path.resolve(packageDir, 'lib/package.json');
1736
const buildPackageJsonPath = path.resolve(packageDir, 'build/package.json');
1837

19-
const [rootPackageJson, libPackageJson] = await Promise.all([
20-
fs.readFile(rootPackageJsonPath, 'utf8').then((content) => JSON.parse(content)),
21-
fs.readFile(libPackageJsonPath, 'utf8').then((content) => JSON.parse(content)),
22-
]);
38+
const rootPackageJson = await fs
39+
.readFile(rootPackageJsonPath, 'utf8')
40+
.then((content) => JSON.parse(content));
2341

2442
const mergedPackageJson = {
2543
...rootPackageJson,
26-
exports: libPackageJson.exports,
44+
exports: wildcardExports,
2745
};
46+
mergedPackageJson.main = './index.js';
47+
mergedPackageJson.types = './index.d.ts';
2848
delete mergedPackageJson.publishConfig?.directory;
2949
// Remove fields that shouldn't be in the published package
3050
delete mergedPackageJson.devDependencies;

0 commit comments

Comments
 (0)