|
8 | 8 | * packages are dev-time only (no runtime effect), it's safe to just delete the stray |
9 | 9 | * nested copy after every install so TypeScript falls back to the correct, hoisted one. |
10 | 10 | */ |
| 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 | + */ |
11 | 20 | const fs = require('fs'); |
12 | 21 | const path = require('path'); |
13 | 22 |
|
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 | +]; |
23 | 27 |
|
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