提交 c2923781 authored 作者: 王鹏飞's avatar 王鹏飞

fix: verify vite 8 admin compatibility

上级 cc31773c
......@@ -16,6 +16,7 @@ Currently available root commands:
- `pnpm install`
- `pnpm dev:admin`
- `pnpm build:admin`
- `pnpm test:admin`
- `pnpm lint:admin` — the inherited admin script uses `--fix`; inspect its diff and do not run it for read-only validation.
Learning commands (`dev:learning`, `build:learning`, `test:learning`, and `lint:learning`) and root verification commands are planned, but do not exist until their corresponding Stage 0 tasks create them.
......
......@@ -8,7 +8,8 @@
"build": "vite build",
"build:dev": "vite build --mode development",
"preview": "vite preview",
"lint": "eslint --ext .js,.jsx,.ts,.tsx --fix --ignore-path .gitignore ./src"
"lint": "eslint --ext .js,.jsx,.ts,.tsx --fix --ignore-path .gitignore ./src",
"test": "node --test src/store/storage-import.test.mjs"
},
"dependencies": {
"@ant-design/icons": "^5.4.0",
......
import { configureStore, combineReducers } from '@reduxjs/toolkit';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/es/storage'; // defaults to localStorage for web
import storage from './storage'; // defaults to localStorage for web
import * as reducers from './modules';
const persistConfig = {
......
import assert from 'node:assert/strict'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
import { readFile } from 'node:fs/promises'
import { createServer } from 'vite'
test('Redux Persist storage uses the ESM entry required by Vite 8 interop', async () => {
const source = await readFile(new URL('./index.js', import.meta.url), 'utf8')
const appRoot = fileURLToPath(new URL('../..', import.meta.url))
assert.match(source, /import storage from 'redux-persist\/es\/storage'/)
test('Redux Persist storage loaded by Vite round-trips and removes local values', async () => {
const originalSelf = Object.getOwnPropertyDescriptor(globalThis, 'self')
const values = new Map()
const localStorage = {
getItem(key) {
return values.has(key) ? values.get(key) : null
},
setItem(key, value) {
values.set(key, String(value))
},
removeItem(key) {
values.delete(key)
},
}
Object.defineProperty(globalThis, 'self', {
configurable: true,
value: { localStorage },
})
const vite = await createServer({
appType: 'custom',
configFile: false,
logLevel: 'error',
optimizeDeps: { noDiscovery: true },
root: appRoot,
server: { hmr: false, middlewareMode: true, ws: false },
ssr: { noExternal: ['redux-persist'] },
})
try {
const { default: storage } = await vite.ssrLoadModule('/src/store/storage.js')
assert.equal(typeof storage.getItem, 'function')
assert.equal(typeof storage.setItem, 'function')
assert.equal(typeof storage.removeItem, 'function')
await storage.setItem('redux-persist-test', 'saved value')
assert.equal(await storage.getItem('redux-persist-test'), 'saved value')
await storage.removeItem('redux-persist-test')
assert.equal(await storage.getItem('redux-persist-test'), null)
} finally {
await vite.close()
if (originalSelf) {
Object.defineProperty(globalThis, 'self', originalSelf)
} else {
delete globalThis.self
}
}
})
import storage from 'redux-persist/es/storage'
export default storage
......@@ -132,7 +132,7 @@ git rm package-lock.json
Do not move `AGENTS.md`, `docs`, `.gitignore`, `.agents`, `.claude`, `readme.md`, or `skills-lock.json`.
- [ ] **Step 3: Rename the admin package without changing its dependencies**
- [ ] **Step 3: Rename the admin package and apply the approved Vite 8 compatibility updates**
Modify the first fields of `apps/admin/package.json`:
......@@ -145,7 +145,9 @@ Modify the first fields of `apps/admin/package.json`:
}
```
Keep all existing dependencies and scripts in that file unchanged during this task.
Use pnpm 11.13.1 at the workspace root. Update the admin build stack to Vite ^8.1.5 and @vitejs/plugin-react ^6.0.3, remove @vitejs/plugin-react-swc, and remove the explicit @rollup/rollup-linux-x64-gnu optionalDependency so pnpm resolves the platform binding. Add the admin `test` command for the Redux Persist compatibility characterization.
Keep the legacy React 18 and Ant Design 5 application dependencies on their current major-version baseline. Isolate Redux Persist's `redux-persist/es/storage` import in a local ESM module and characterize it through Vite SSR with a map-backed `self.localStorage`; the test must assert the storage methods exist and round-trip/remove a value.
- [ ] **Step 4: Create the workspace root package**
......@@ -160,7 +162,8 @@ Create `package.json`:
"scripts": {
"dev:admin": "pnpm --filter @ebook/admin dev",
"build:admin": "pnpm --filter @ebook/admin build",
"lint:admin": "pnpm --filter @ebook/admin lint"
"lint:admin": "pnpm --filter @ebook/admin lint",
"test:admin": "pnpm --filter @ebook/admin test"
}
}
```
......@@ -171,6 +174,10 @@ Create `pnpm-workspace.yaml`:
packages:
- apps/*
- packages/*
allowBuilds:
es5-ext: false
esbuild: true
```
- [ ] **Step 5: Install from the workspace root and generate the single lockfile**
......@@ -178,20 +185,21 @@ packages:
Run:
```bash
pnpm install
pnpm install --force
```
Expected: exit 0, root `pnpm-lock.yaml` exists, and `apps/admin/node_modules` is linked by pnpm.
Expected: exit 0 with pnpm 11.13.1, root `pnpm-lock.yaml` exists, `apps/admin/node_modules` is linked by pnpm, and no ignored-build-script warning is printed. `esbuild` is explicitly allowed; `es5-ext` is explicitly denied because its informational postinstall is not needed for the admin build.
- [ ] **Step 6: Verify the mechanically moved admin still builds**
Run:
```bash
pnpm test:admin
pnpm build:admin
```
Expected: exit 0. At this task boundary the output may still be `apps/admin/dist`; the output is changed in Task 2.
Expected: both commands exit 0. The ESM Redux Persist compatibility test loads the local storage module through Vite and verifies local-storage behavior. At this task boundary the output may still be `apps/admin/dist`; the output is changed in Task 2.
- [ ] **Step 7: Commit the workspace migration**
......
......@@ -6,6 +6,7 @@
"scripts": {
"dev:admin": "pnpm --filter @ebook/admin dev",
"build:admin": "pnpm --filter @ebook/admin build",
"lint:admin": "pnpm --filter @ebook/admin lint"
"lint:admin": "pnpm --filter @ebook/admin lint",
"test:admin": "pnpm --filter @ebook/admin test"
}
}
......@@ -3,5 +3,5 @@ packages:
- packages/*
allowBuilds:
es5-ext: true
es5-ext: false
esbuild: true
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论