Commit de8bdac7 by 张立顺

chore: postinstall 自动安装 packageUsedCar 依赖

Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 86174213
...@@ -2,20 +2,33 @@ ...@@ -2,20 +2,33 @@
# 环境初始化(SAAS+V5.8.3 等含二手车分包的分支) # 环境初始化(SAAS+V5.8.3 等含二手车分包的分支)
克隆或切换分支并 `git pull` 后: 克隆或切换分支并 `git pull` 后,在项目根目录执行:
```bash
npm install
```
根目录 `npm install` 会自动通过 `postinstall` 安装 `packageUsedCar` 依赖(含 `glsk-map-jssdk`)。也可执行 `npm run setup`,效果相同。
可选校验:
```bash ```bash
npm run verify:npm-config # 检查 project.config 引用的 package.json 是否存在 npm run verify:npm-config # 检查 project.config 引用的 package.json 是否存在
npm run setup # 安装主包 + packageUsedCar 依赖
``` ```
微信开发者工具:**工具 → 构建 npm**(主包与 `packageUsedCar` 分包均需构建)。 微信开发者工具:**工具 → 构建 npm**(主包与 `packageUsedCar` 分包均需构建)。`npm install` 只安装 `node_modules`,不会生成 `miniprogram_npm`。
若报错 `packageUsedCar/package.json not found`: 若报错 `packageUsedCar/package.json not found`:
```bash ```bash
git checkout HEAD -- project.config.json packageUsedCar/package.json packageUsedCar/package-lock.json git checkout HEAD -- project.config.json packageUsedCar/package.json packageUsedCar/package-lock.json
npm run setup npm install
```
若报错 `node_modules of ... packageUsedCar/package.json is not found`:
```bash
npm install
``` ```
然后在开发者工具中重新「构建 npm」;仍异常可 **清缓存 → 全部清除** 后重开项目。 然后在开发者工具中重新「构建 npm」;仍异常可 **清缓存 → 全部清除** 后重开项目。
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"hasInstallScript": true,
"dependencies": { "dependencies": {
"@vant/weapp": "^1.10.24", "@vant/weapp": "^1.10.24",
"dayjs": "^1.11.11", "dayjs": "^1.11.11",
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
"prettier-plugin-mp": "^2.5.0" "prettier-plugin-mp": "^2.5.0"
}, },
"scripts": { "scripts": {
"setup": "npm install && node scripts/setup-package-used-car.mjs", "postinstall": "node scripts/setup-package-used-car.mjs",
"setup": "npm install",
"verify:npm-config": "node scripts/verify-npm-config.mjs", "verify:npm-config": "node scripts/verify-npm-config.mjs",
"test": "node --test packageDynamicForm/tests/**/*.test.mjs tabIndex/tests/**/*.test.mjs packageEquity/tests/**/*.test.mjs tabWorkOrder/pages/createOrder/tests/**/*.test.mjs tests/**/*.test.mjs", "test": "node --test packageDynamicForm/tests/**/*.test.mjs tabIndex/tests/**/*.test.mjs packageEquity/tests/**/*.test.mjs tabWorkOrder/pages/createOrder/tests/**/*.test.mjs tests/**/*.test.mjs",
"test:tabIndex": "node --test tabIndex/tests/**/*.test.mjs", "test:tabIndex": "node --test tabIndex/tests/**/*.test.mjs",
......
/** /**
* @file 在 packageUsedCar 目录安装 npm 依赖。 * @file 在 packageUsedCar 目录安装 npm 依赖(由根目录 postinstall 触发)。
* 避免 Windows 下 `npm install --prefix packageUsedCar` 与 lockfile 兼容问题。 * 避免 Windows 下 `npm install --prefix packageUsedCar` 与 lockfile 兼容问题。
*/ */
import { execSync } from 'child_process' import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path' import path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
...@@ -11,5 +12,11 @@ const packageUsedCarDir = path.resolve( ...@@ -11,5 +12,11 @@ const packageUsedCarDir = path.resolve(
'..', '..',
'packageUsedCar' 'packageUsedCar'
) )
const packageJsonPath = path.join(packageUsedCarDir, 'package.json')
if (!fs.existsSync(packageJsonPath)) {
console.log('[setup-package-used-car] skip: packageUsedCar/package.json 不存在')
process.exit(0)
}
execSync('npm install', { cwd: packageUsedCarDir, stdio: 'inherit' }) execSync('npm install', { cwd: packageUsedCarDir, stdio: 'inherit' })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!