|
4 | 4 | * resolutions are needed to run the tests. The vite-ecosystem-ci, though, sets the resolutions in |
5 | 5 | * the root package.json. |
6 | 6 | */ |
7 | | -import { readFile, writeFile } from 'node:fs/promises'; |
| 7 | +import { writeFile } from 'node:fs/promises'; |
8 | 8 | import { dirname, resolve } from 'node:path'; |
9 | 9 | import { fileURLToPath } from 'node:url'; |
10 | 10 |
|
11 | 11 | // eslint-disable-next-line depend/ban-dependencies |
12 | 12 | import { execaCommand } from 'execa'; |
13 | 13 |
|
| 14 | +import { EXISTING_RESOLUTIONS } from './existing-resolutions.js'; |
| 15 | + |
14 | 16 | const filename = fileURLToPath(import.meta.url); |
15 | 17 | const __dirname = dirname(filename); |
16 | 18 |
|
17 | 19 | const sandbox = process.argv[2] ?? 'react-vite/default-ts'; |
18 | 20 |
|
19 | | -const rootPackageJsonPath = resolve(__dirname, '../../package.json'); |
20 | 21 | const sandboxPackageJsonPath = resolve( |
21 | 22 | __dirname, |
22 | | - `../../storybook-sandboxes/${sandbox.replace('/', '-')}/package.json` |
| 23 | + `../../../storybook-sandboxes/${sandbox.replace('/', '-')}/package.json` |
23 | 24 | ); |
24 | 25 |
|
25 | | -const rootPackageJson = JSON.parse(await readFile(rootPackageJsonPath, 'utf-8')); |
26 | | -const sandboxPackageJson = JSON.parse(await readFile(sandboxPackageJsonPath, 'utf-8')); |
| 26 | +const { default: rootPkgJson } = await import('../../package.json', { with: { type: 'json' } }); |
| 27 | +const { default: sandboxPkgJson } = await import(sandboxPackageJsonPath, { |
| 28 | + with: { type: 'json' }, |
| 29 | +}); |
27 | 30 |
|
28 | | -const resolutions = rootPackageJson.resolutions |
| 31 | +// copy resolutions from root package.json to sandbox package.json, excluding the known resolutions we have internally in our repo |
| 32 | +// ecosystem-ci will add resolutions to the root package.json, and we want to propagate ONLY those to the sandbox package.json |
| 33 | +const resolutionsToCopy = rootPkgJson.resolutions |
29 | 34 | ? Object.fromEntries( |
30 | | - Object.entries(rootPackageJson.resolutions).filter(([_, v]) => !v.includes('patch:')) |
| 35 | + Object.entries(rootPkgJson.resolutions).filter(([pkg]) => !EXISTING_RESOLUTIONS.has(pkg)) |
31 | 36 | ) |
32 | 37 | : {}; |
33 | 38 |
|
34 | | -sandboxPackageJson.resolutions = { |
35 | | - ...(sandboxPackageJson.resolutions ?? {}), |
36 | | - ...resolutions, |
| 39 | +sandboxPkgJson.resolutions = { |
| 40 | + ...(sandboxPkgJson.resolutions ?? {}), |
| 41 | + ...resolutionsToCopy, |
37 | 42 | }; |
38 | 43 |
|
39 | | -await writeFile(sandboxPackageJsonPath, JSON.stringify(sandboxPackageJson, null, 2)); |
40 | | -const sandboxDir = dirname(sandboxPackageJsonPath); |
| 44 | +await writeFile(sandboxPackageJsonPath, JSON.stringify(sandboxPkgJson, null, 2)); |
41 | 45 |
|
| 46 | +const sandboxDir = dirname(sandboxPackageJsonPath); |
42 | 47 | await execaCommand('yarn add playwright', { cwd: sandboxDir, shell: true }); |
43 | 48 | await execaCommand('yarn playwright install', { cwd: sandboxDir, shell: true }); |
0 commit comments