Commit 3fd22477 by liimin

chore(mp): lane 名字真源落 appId、sync 回收 lane 规范字段、workspace 排除内嵌子包

- apps/mp/manifest.json:4 个 lane 的 appId 从 PLACEHOLDER 换成源工程
  project.config.json 的实测值(usedcar wx570d9331f9ace0bd / sales wxe10067a63c1856ac /
  store wxc50d04ae5aa9984a / points wx7ce755e425603084),并记下 sales 的
  glsx-common-sdk Version 已本地化
- scripts/sync-mp-apps.mjs:模板刻意不写 "type": "module"(lane 自带代码与 node 测试
  都是 CommonJS,带上会全红,也让 devtool 构建 npm 的清单与源工程不一致);
  lint 收窄为 eslint src、main 固定 app.js;对已存在的 lane 只回收规范字段并打印
  drift,不覆盖业务字段;ESLint 配置由 .js 改 .mjs 自证 ESM(4 个 lane 同步)
- pnpm-workspace.yaml:排除 apps/mp/usedcar/packageUsedCar —— 它是微信「构建 npm」的
  输入、依赖来自 glsx 私有源,成为 workspace 成员会让整仓 install 失败;
  必须写精确路径,通配会让 turbo 把整个 mp lane 一起排掉
- 三个 lane 的 package.json 补齐第三方依赖声明,lockfile 落定
  @vant/weapp / dayjs / number-precision / rfdc / glsx-applet-component@1.1.29 /
  glsk-map-jssdk@0.1.1 / miniprogram-automator(根 package.json 里
  miniprogram-automator>jimp 的 override 随门禁提交一起落盘)
- scripts/check-boundaries.mjs 本次只是换行格式对齐,mp 规则口径未变
1 parent fb94f03f
{ {
"note": "【mp lane 名字唯一真源】这里定义所有原生小程序 lane 的目录名与元信息。dir 同时决定目录名 apps/mp/<dir> 与包名 @uj/mp-<dir>。名字已定稿(2026-11-06 超人拍板),后续若需改名改本文件的 dir / displayName / appId / backend / source 字段,再跑 `pnpm mp:sync` 即可重建脚手架(`--prune` 清旧目录)。`source` 字段记录该 lane 真实代码来自哪个 GitLab 仓库,供物理迁入时对照;`backend` 为后端家族提示,精确的 scrm/dj project 码在物理迁移真实请求层时再落定。", "note": "【mp lane 名字唯一真源】这里定义所有原生小程序 lane 的目录名与元信息。dir 同时决定目录名 apps/mp/<dir> 与包名 @uj/mp-<dir>。名字已定稿(2026-11-06 超人拍板),后续若需改名改本文件的 dir / displayName / appId / backend / source 字段,再跑 `pnpm mp:sync` 即可重建脚手架(`--prune` 清旧目录)。`source` 字段记录该 lane 真实代码来自哪个 GitLab 仓库,供物理迁入时对照;appId 取自各源工程 project.config.json(2026-11-06 迁入时核对)。`backend` 为后端家族提示,精确的 scrm/dj project 码在物理迁移真实请求层时再落定。",
"apps": [ "apps": [
{ {
"dir": "usedcar", "dir": "usedcar",
"displayName": "二手车 / 车精品小程序", "displayName": "二手车 / 车精品小程序",
"appId": "wx_usedcar_PLACEHOLDER", "appId": "wx570d9331f9ace0bd",
"backend": "saas_plus 家族(dj-car-boutique-work-wechat);双后端 scrm + dj,project 码待物理迁移时确认", "backend": "saas_plus 家族(dj-car-boutique-work-wechat);双后端 scrm + dj,project 码待物理迁移时确认",
"source": "dj-car-boutique-work-wechat" "source": "dj-car-boutique-work-wechat"
}, },
{ {
"dir": "sales", "dir": "sales",
"displayName": "车生活小程序(SCRM)", "displayName": "车生活小程序(SCRM)",
"appId": "wx_sales_PLACEHOLDER", "appId": "wxe10067a63c1856ac",
"backend": "glsx SCRM(miniprogram-scrm-carlife,已依赖 glsx-common-sdk)", "backend": "glsx SCRM(miniprogram-scrm-carlife);glsx-common-sdk 的 Version 已换成本地 utils/versionConfig.js",
"source": "miniprogram-scrm-carlife" "source": "miniprogram-scrm-carlife"
}, },
{ {
"dir": "store", "dir": "store",
"displayName": "门店助手小程序", "displayName": "门店助手小程序",
"appId": "wx_store_PLACEHOLDER", "appId": "wxc50d04ae5aa9984a",
"backend": "saas_plus 家族(store-assistant-assemble);双后端 scrm + dj(djSecretKey)", "backend": "saas_plus 家族(store-assistant-assemble);双后端 scrm + dj(djSecretKey)",
"source": "store-assistant-assemble" "source": "store-assistant-assemble"
}, },
{ {
"dir": "points", "dir": "points",
"displayName": "积分商城小程序", "displayName": "积分商城小程序",
"appId": "wx_points_PLACEHOLDER", "appId": "wx7ce755e425603084",
"backend": "scrm-shopmall(points-mall,单后端,与 web points 同构)", "backend": "scrm-shopmall(points-mall,单后端,与 web points 同构)",
"source": "points-mall" "source": "points-mall"
} }
......
...@@ -2,18 +2,21 @@ ...@@ -2,18 +2,21 @@
"name": "@uj/mp-points", "name": "@uj/mp-points",
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"lint": "eslint src" "lint": "eslint src"
}, },
"dependencies": { "dependencies": {
"@uj/api-core": "workspace:*" "@uj/api-core": "workspace:*",
"glsx-applet-component": "^1.1.24",
"glsx-map-sdk": "^0.2.0",
"number-precision": "^1.6.0"
}, },
"devDependencies": { "devDependencies": {
"@uj/contracts": "workspace:*", "@uj/contracts": "workspace:*",
"@uj/eslint-config": "workspace:*", "@uj/eslint-config": "workspace:*",
"@uj/typescript-config": "workspace:*", "@uj/typescript-config": "workspace:*",
"typescript": "catalog:" "typescript": "catalog:"
} },
"main": "app.js"
} }
...@@ -4,6 +4,12 @@ packages: ...@@ -4,6 +4,12 @@ packages:
# apps/web/subapps/system 子应用 @uj/web-system(系统管理域) # apps/web/subapps/system 子应用 @uj/web-system(系统管理域)
# apps/web/subapps/store 子应用 @uj/web-store(门店业务域) # apps/web/subapps/store 子应用 @uj/web-store(门店业务域)
- 'apps/**' - 'apps/**'
# 排除 mp lane 内部的原生 npm 子包(目前只有 apps/mp/usedcar/packageUsedCar):
# 它们是微信「构建 npm」的输入,依赖来自 glsx 私有源;一旦成为 workspace 成员,
# 整仓 pnpm install 会因解析不到私有包而失败(依赖模型见交接决策 1)。
# 必须写精确路径:写成 '!apps/mp/*/*' 这类通配时,turbo 的 glob 会把整个 mp lane
# 一起排掉(表现为 pnpm typecheck 里 4 个 @uj/mp-* 任务消失)。新增 lane 若带内嵌子包,逐条追加。
- '!apps/mp/usedcar/packageUsedCar'
# 共享包层:一个目录 = 一个可独立发布单元 # 共享包层:一个目录 = 一个可独立发布单元
- 'packages/**' - 'packages/**'
......
...@@ -113,7 +113,8 @@ const MP_RULES = [ ...@@ -113,7 +113,8 @@ const MP_RULES = [
{ {
id: 'host-runtime', id: 'host-runtime',
re: /@uj\/platform-core/, re: /@uj\/platform-core/,
message: '小程序引用了 host 独占运行时 @uj/platform-core;请改用 @uj/api-core(createWxSender)。', message:
'小程序引用了 host 独占运行时 @uj/platform-core;请改用 @uj/api-core(createWxSender)。',
}, },
{ {
id: 'web-sdk', id: 'web-sdk',
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* mp lane 名字真源的消费端。 * mp lane 名字真源的消费端。
* *
* 唯一真源:apps/mp/manifest.json(定义所有原生小程序 lane 的 dir / displayName / appId / backend)。 * 唯一真源:apps/mp/manifest.json(定义所有原生小程序 lane 的 dir / displayName / appId / backend)。
* 本脚本依据 manifest 为每个小程序生成 / 同步脚手架(package.json / tsconfig.json / eslint.config.js / src/index.ts)。 * 本脚本依据 manifest 为每个小程序生成 / 同步脚手架(package.json / tsconfig.json / eslint.config.mjs / src/index.ts)。
* *
* 用法: * 用法:
* node scripts/sync-mp-apps.mjs # 新增缺失的 lane、同步包名,不删除多余目录(仅警告) * node scripts/sync-mp-apps.mjs # 新增缺失的 lane、同步包名,不删除多余目录(仅警告)
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* 改名流程:改 manifest 的 dir -> 跑本脚本(旧目录会告警)-> 加 --prune 清掉旧目录。 * 改名流程:改 manifest 的 dir -> 跑本脚本(旧目录会告警)-> 加 --prune 清掉旧目录。
*/ */
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, rmSync } from 'node:fs'; import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, rmSync, renameSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path'; import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
...@@ -35,8 +35,12 @@ function templatePackageJson(dir) { ...@@ -35,8 +35,12 @@ function templatePackageJson(dir) {
name: `@uj/mp-${dir}`, name: `@uj/mp-${dir}`,
version: '0.0.0', version: '0.0.0',
private: true, private: true,
type: 'module', // 原生小程序入口;lint 只扫 src(工具链不管 mp 业务 js,见根 eslint.config.js 的 ignores)。
scripts: { typecheck: 'tsc --noEmit', lint: 'eslint .' }, // 刻意不写 "type": "module":mp 自带代码与它自己的 node 测试都是 CommonJS 口径
// (utils/lib/*.js 用 module.exports),带上 type 会让这些测试全红,
// 也会让 devtool「构建 npm」看到的清单和源工程不一致。ESLint 配置改用 .mjs 后缀自证 ESM。
main: 'app.js',
scripts: { typecheck: 'tsc --noEmit', lint: 'eslint src' },
dependencies: { '@uj/api-core': 'workspace:*' }, dependencies: { '@uj/api-core': 'workspace:*' },
devDependencies: { devDependencies: {
'@uj/contracts': 'workspace:*', '@uj/contracts': 'workspace:*',
...@@ -165,13 +169,32 @@ for (const app of apps) { ...@@ -165,13 +169,32 @@ for (const app of apps) {
mkdirSync(srcDir, { recursive: true }); mkdirSync(srcDir, { recursive: true });
const pkgPath = join(appDir, 'package.json'); const pkgPath = join(appDir, 'package.json');
const expectedName = `@uj/mp-${dir}`;
if (existsSync(pkgPath)) { if (existsSync(pkgPath)) {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
if (pkg.name !== expectedName) { const expected = templatePackageJson(dir);
pkg.name = expectedName; const drift = [];
if (pkg.name !== expected.name) {
pkg.name = expected.name;
drift.push(`name -> ${expected.name}`);
}
// 物理迁入的 lane 带着原工程 package.json 的字段,这里只回收 lane 规范项,不动业务字段。
if ('type' in pkg) {
delete pkg.type;
drift.push('删除 type(mp 代码与其自带测试按 CommonJS 口径)');
}
if (pkg.main !== expected.main) {
pkg.main = expected.main;
drift.push(`main -> ${expected.main}`);
}
for (const [script, command] of Object.entries(expected.scripts)) {
if (pkg.scripts?.[script] !== command) {
pkg.scripts = { ...pkg.scripts, [script]: command };
drift.push(`scripts.${script} -> ${command}`);
}
}
if (drift.length) {
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`); writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
console.log(`同步 name -> ${expectedName} (${dir})`); console.log(`同步 ${dir}/package.json: ${drift.join(', ')}`);
} }
} else { } else {
writeFileSync(pkgPath, `${JSON.stringify(templatePackageJson(dir), null, 2)}\n`); writeFileSync(pkgPath, `${JSON.stringify(templatePackageJson(dir), null, 2)}\n`);
...@@ -182,10 +205,17 @@ for (const app of apps) { ...@@ -182,10 +205,17 @@ for (const app of apps) {
if (!existsSync(tsconfigPath)) { if (!existsSync(tsconfigPath)) {
writeFileSync(tsconfigPath, `${JSON.stringify(templateTsconfig(), null, 2)}\n`); writeFileSync(tsconfigPath, `${JSON.stringify(templateTsconfig(), null, 2)}\n`);
} }
const eslintPath = join(appDir, 'eslint.config.js'); const eslintPath = join(appDir, 'eslint.config.mjs');
if (!existsSync(eslintPath)) { if (!existsSync(eslintPath)) {
const legacyPath = join(appDir, 'eslint.config.js');
if (existsSync(legacyPath)) {
// lane 不再带 package.json type,.js 会被当 CJS -> 必须换成 .mjs 后缀自证 ESM。
renameSync(legacyPath, eslintPath);
console.log(`重命名 ${dir}/eslint.config.js -> eslint.config.mjs`);
} else {
writeFileSync(eslintPath, templateEslint()); writeFileSync(eslintPath, templateEslint());
} }
}
const indexPath = join(srcDir, 'index.ts'); const indexPath = join(srcDir, 'index.ts');
if (!existsSync(indexPath)) { if (!existsSync(indexPath)) {
writeFileSync(indexPath, templateIndexTs(dir, displayName)); writeFileSync(indexPath, templateIndexTs(dir, displayName));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!