Skip to content

Commit bfe5ed5

Browse files
committed
fix: remove stale nested @wordpress/data copy breaking types under node 20
1 parent 864a717 commit bfe5ed5

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

scripts/fix-nested-types.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88
* packages are dev-time only (no runtime effect), it's safe to just delete the stray
99
* nested copy after every install so TypeScript falls back to the correct, hoisted one.
1010
*/
11+
/**
12+
* @types/wordpress__block-editor (a community DefinitelyTyped package, still needed since
13+
* @wordpress/block-editor doesn't ship its own native types) bundles its own old, nested
14+
* @wordpress/data@9.x. Whether npm actually resolves block-primitives' own '@wordpress/data'
15+
* import against that stale nested copy instead of the real, hoisted 10.x one turned out to
16+
* depend on which npm version does the install (reproduced failing under Node 20/npm 10.1,
17+
* passing under Node 22's bundled npm) - so this can't be relied on to just work everywhere.
18+
* Deleting the stale nested copy after every install makes resolution consistent regardless.
19+
*/
1120
const fs = require('fs');
1221
const path = require('path');
1322

14-
const staleTypesPath = path.join(
15-
__dirname,
16-
'..',
17-
'packages',
18-
'block-primitives',
19-
'node_modules',
20-
'@types',
21-
'react',
22-
);
23+
const staleNestedPaths = [
24+
['packages', 'block-primitives', 'node_modules', '@types', 'react'],
25+
['node_modules', '@types', 'wordpress__block-editor', 'node_modules', '@wordpress', 'data'],
26+
];
2327

24-
fs.rmSync(staleTypesPath, { recursive: true, force: true });
28+
for (const segments of staleNestedPaths) {
29+
fs.rmSync(path.join(__dirname, '..', ...segments), { recursive: true, force: true });
30+
}

0 commit comments

Comments
 (0)