@lark-apaas/fullstack-cli 1.1.71-alpha.20261103033524 → 1.1.71-alpha.20261103070436

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/dist/index.js +132 -43
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -23,8 +23,12 @@ npm install --save-dev @lark-apaas/fullstack-cli
23
23
 
24
24
  `fullstack-cli upgrade deps` 升级 NestJS/Express DataPaaS SDK 时,会先读取目标 SDK 已发布的 `peerDependencies.drizzle-orm`,同步迁移应用的精确 Drizzle 依赖。默认升级、`--version` 和灰度目标均使用各自 SDK 的契约;升级到旧 SDK 时不会强制安装 `0.45.2`。
25
25
 
26
+ 范围或标签目标由原生 `npm outdated` 的 `wanted` 结果确定,沿用项目 npm 配置、默认标签和当前 Node/npm 版本的选择规则;不再对 `npm view` 返回的版本自行排序取最大值。未指定 `--version` 时使用原生 `npm update`,保留应用声明的版本范围;显式版本和灰度目标使用 `npm install`。
27
+
26
28
  迁移先备份应用的 `package.json`、`package-lock.json` 和 `node_modules`,仅重解受影响 SDK/Drizzle 的锁记录,再执行原生 `npm ci`。所有 npm 命令保留应用原目录及 `.npmrc`;不使用 `--force` 或 `--legacy-peer-deps`。原来放在 `devDependencies` 中的 Drizzle 保留原位置,缺少声明时添加到 `dependencies`。安装失败会恢复这三个备份;生命周期脚本对项目外部的副作用不在恢复范围内。
27
29
 
30
+ 生成新锁后、安装前会核对实际 SDK/Drizzle peer 与计划一致,并确认未选择升级的 SDK 版本未变。其他依赖约束使原生 npm 解析偏离计划时,迁移报错并恢复备份。
31
+
28
32
  `--dry-run` 只读取元数据和展示计划。灰度目标 SDK 已安装但 Drizzle 声明或锁记录仍旧时也会修复;两者一致时不重复安装。`--packages` 排除的根 SDK 如果与新 peer 冲突,会在修改文件前报错,提示一起升级相关 SDK。无法解析契约、非精确 peer、npm shrinkwrap 或不支持的锁文件格式也会在迁移前停止。
29
33
 
30
34
  在仓库中运行真实 npm 安装回归:`yarn workspace @lark-apaas/fullstack-cli test:peer-migration`。该测试启动临时本地 registry,覆盖旧应用升级、回滚到旧 SDK、灰度 peer 修复、锁文件重装及失败恢复,不访问生产 registry。
@@ -416,3 +420,8 @@ MIT
416
420
  CLI 不注入 MCP UI 检查命令;主工程保留原有 client/server 检查,UI 由 Agent 按独立配置执行标准 tsc/eslint。
417
421
 
418
422
  存量 sync 不改写 ESLint 源码;UI 全局排除项由平台 ESLint 预设提供。TS 仅向已有显式 `exclude` 数组追加目录,保留注释和原项;依赖继承且未显式声明 `exclude` 的自定义配置保持不变并提示人工调整。自定义检查命令保留。lint.js 和 build.sh 仍由平台脚本模板维护,不依赖预设包中的脚本执行入口。
423
+
424
+
425
+ ### 本地 Node18/npm 升级对照
426
+
427
+ `yarn test:npm-selection` 独立执行真实 registry、native npm 与 CLI 升级目标对照,不由常规测试入口自动发现。需要 Node18 与配套 npm(>=9)。当前运行进程为 Node18 时自动使用它;其他版本需设置 `NPM_TEST_NODE18`。npm 默认定位该 Node 同安装的 `lib/node_modules/npm/bin/npm-cli.js`,也可通过 `NPM_TEST_NODE18` 和 `NPM_TEST_NPM_CLI` 指定本地工具;测试仅访问自己创建的 loopback registry,安装缓存、tarball 与临时项目均在系统临时目录,结束后关闭 registry 并删除项目。套件实际验证项目 `.npmrc`、默认范围与 engines 选择、精确高版本失败时的恢复;工具缺失会失败而非跳过。
package/dist/index.js CHANGED
@@ -3659,6 +3659,7 @@ function resolveGrayscaleVersions(_cwd, configJson) {
3659
3659
  // src/commands/upgrade/deps/drizzle-peer-migration.ts
3660
3660
  import { spawnSync as spawnSync4 } from "child_process";
3661
3661
  import fs13 from "fs";
3662
+ import os from "os";
3662
3663
  import path10 from "path";
3663
3664
  var dataPaasSdks = /* @__PURE__ */ new Set([
3664
3665
  "@lark-apaas/fullstack-nestjs-core",
@@ -3667,33 +3668,83 @@ var dataPaasSdks = /* @__PURE__ */ new Set([
3667
3668
  "@lark-apaas/express-datapaas"
3668
3669
  ]);
3669
3670
  var versionPattern = /^(\d+)\.(\d+)\.(\d+)(?:-([\da-zA-Z.-]+))?(?:\+[\da-zA-Z.-]+)?$/;
3670
- function compareVersions(a, b) {
3671
- const left = a.match(versionPattern);
3672
- const right = b.match(versionPattern);
3673
- for (let index = 1; index <= 3; index++) {
3674
- const difference = Number(left[index]) - Number(right[index]);
3675
- if (difference) return difference;
3676
- }
3677
- if (!left[4] || !right[4]) return Number(!left[4]) - Number(!right[4]);
3678
- const leftParts = left[4].split(".");
3679
- const rightParts = right[4].split(".");
3680
- for (let index = 0; index < Math.max(leftParts.length, rightParts.length); index++) {
3681
- const l = leftParts[index];
3682
- const r = rightParts[index];
3683
- if (l === r) continue;
3684
- if (l === void 0 || r === void 0) return l === void 0 ? -1 : 1;
3685
- const lNumeric = /^\d+$/.test(l);
3686
- const rNumeric = /^\d+$/.test(r);
3687
- if (lNumeric && rNumeric) return Number(l) - Number(r);
3688
- if (lNumeric !== rNumeric) return lNumeric ? -1 : 1;
3689
- return l < r ? -1 : 1;
3671
+ function resolvePublishedVersions(targets, cwd) {
3672
+ if (!targets.length) return /* @__PURE__ */ new Map();
3673
+ const exactVersions = new Map(
3674
+ targets.filter((target) => versionPattern.test(target.version)).map(({ pkg: pkg2, version }) => [pkg2, version])
3675
+ );
3676
+ targets = targets.filter((target) => !exactVersions.has(target.pkg));
3677
+ if (!targets.length) return exactVersions;
3678
+ const prefix = spawnSync4("npm", ["prefix"], {
3679
+ cwd,
3680
+ encoding: "utf8",
3681
+ timeout: 3e4,
3682
+ stdio: ["ignore", "pipe", "pipe"]
3683
+ });
3684
+ const projectPrefix = prefix.stdout?.toString().trim();
3685
+ if (prefix.error || prefix.status !== 0 || !projectPrefix || !path10.isAbsolute(projectPrefix))
3686
+ throw new Error(
3687
+ "Cannot locate npm project configuration for SDK resolution"
3688
+ );
3689
+ const resolver = fs13.mkdtempSync(
3690
+ path10.join(os.tmpdir(), "fullstack-sdk-resolver-")
3691
+ );
3692
+ try {
3693
+ fs13.writeFileSync(
3694
+ path10.join(resolver, "package.json"),
3695
+ JSON.stringify({
3696
+ name: "fullstack-sdk-resolver",
3697
+ private: true,
3698
+ dependencies: Object.fromEntries(
3699
+ targets.map(({ pkg: pkg2, version }) => [pkg2, version])
3700
+ )
3701
+ })
3702
+ );
3703
+ const npmrc = path10.join(projectPrefix, ".npmrc");
3704
+ if (fs13.existsSync(npmrc))
3705
+ fs13.symlinkSync(npmrc, path10.join(resolver, ".npmrc"));
3706
+ const result = spawnSync4(
3707
+ "npm",
3708
+ [
3709
+ "outdated",
3710
+ "--json",
3711
+ "--long",
3712
+ "--workspaces=false",
3713
+ `--prefix=${resolver}`
3714
+ ],
3715
+ {
3716
+ cwd,
3717
+ encoding: "utf8",
3718
+ timeout: 3e4,
3719
+ stdio: ["ignore", "pipe", "pipe"]
3720
+ }
3721
+ );
3722
+ if (result.error || result.status !== 0 && result.status !== 1)
3723
+ throw new Error("Cannot resolve SDK targets with native npm outdated");
3724
+ let metadata;
3725
+ try {
3726
+ metadata = JSON.parse(result.stdout?.toString() || "null");
3727
+ } catch {
3728
+ throw new Error("Invalid native npm target metadata");
3729
+ }
3730
+ return new Map([
3731
+ ...exactVersions,
3732
+ ...targets.map(({ pkg: pkg2, version }) => {
3733
+ const wanted = metadata?.[pkg2]?.wanted;
3734
+ if (typeof wanted !== "string" || !versionPattern.test(wanted))
3735
+ throw new Error(`Missing native npm target for ${pkg2}@${version}`);
3736
+ return [pkg2, wanted];
3737
+ })
3738
+ ]);
3739
+ } finally {
3740
+ fs13.rmSync(resolver, { recursive: true, force: true });
3690
3741
  }
3691
- return 0;
3692
3742
  }
3693
3743
  function readPublishedSdk(pkg2, selector, cwd) {
3744
+ const version = versionPattern.test(selector) ? selector : resolvePublishedVersions([{ pkg: pkg2, version: selector }], cwd).get(pkg2);
3694
3745
  const result = spawnSync4(
3695
3746
  "npm",
3696
- ["view", `${pkg2}@${selector}`, "version", "peerDependencies", "--json"],
3747
+ ["view", `${pkg2}@${version}`, "version", "peerDependencies", "--json"],
3697
3748
  {
3698
3749
  cwd,
3699
3750
  encoding: "utf8",
@@ -3715,20 +3766,24 @@ function readPublishedSdk(pkg2, selector, cwd) {
3715
3766
  const candidates = (Array.isArray(metadata) ? metadata : [metadata]).map(
3716
3767
  (candidate) => typeof candidate === "string" ? { version: candidate } : candidate
3717
3768
  );
3718
- if (!candidates.length || candidates.some(
3719
- (candidate) => !candidate || typeof candidate.version !== "string" || !versionPattern.test(candidate.version)
3769
+ if (candidates.length !== 1 || candidates.some(
3770
+ (candidate) => !candidate || typeof candidate.version !== "string" || candidate.version !== version
3720
3771
  )) {
3721
3772
  throw new Error(`Missing published version for ${pkg2}@${selector}`);
3722
3773
  }
3723
- return candidates.sort((a, b) => compareVersions(a.version, b.version)).pop();
3774
+ return candidates[0];
3724
3775
  }
3725
3776
  function planDrizzlePeerMigration(targets, manifest, cwd, onlyIfPeerNeedsRepair = false) {
3726
3777
  if (!targets.some((target) => dataPaasSdks.has(target.pkg))) return void 0;
3727
3778
  const selected = new Map(targets.map((target) => [target.pkg, target.version]));
3779
+ const registryTargets = targets.filter(
3780
+ (target) => isRegistrySelector(target.version)
3781
+ );
3782
+ const resolvedVersions = resolvePublishedVersions(registryTargets, cwd);
3728
3783
  const publishedTargets = new Map(
3729
- targets.filter((target) => isRegistrySelector(target.version)).map((target) => [
3784
+ registryTargets.map((target) => [
3730
3785
  target.pkg,
3731
- readPublishedSdk(target.pkg, target.version, cwd)
3786
+ readPublishedSdk(target.pkg, resolvedVersions.get(target.pkg), cwd)
3732
3787
  ])
3733
3788
  );
3734
3789
  for (const target of targets) {
@@ -3796,11 +3851,9 @@ function readOptionalJson(filename) {
3796
3851
  }
3797
3852
  }
3798
3853
  function installSelector(requested, resolved) {
3799
- if (requested.startsWith("^") || requested.startsWith("~"))
3800
- return `${requested[0]}${resolved}`;
3801
- if (versionPattern.test(requested) || /^[a-zA-Z][\w.-]*$/.test(requested) || requested === "*")
3854
+ if (versionPattern.test(requested) || /^[a-zA-Z][\w.-]*$/.test(requested))
3802
3855
  return resolved;
3803
- return `${requested} >=${resolved}`;
3856
+ return requested;
3804
3857
  }
3805
3858
  function isRegistrySelector(selector) {
3806
3859
  return !/^(?:[a-z][\w+.-]*:|\.?\.?\/|\/|git@)/i.test(selector) && !selector.includes("/") && selector !== "." && selector !== "..";
@@ -3843,7 +3896,7 @@ var affectedPackages = [
3843
3896
  "@lark-apaas/express-datapaas",
3844
3897
  "drizzle-orm"
3845
3898
  ];
3846
- function applyDrizzlePeerMigration(targets, cwd) {
3899
+ function applyDrizzlePeerMigration(targets, cwd, command = "install") {
3847
3900
  const manifestPath = path11.join(cwd, "package.json");
3848
3901
  const lockPath = path11.join(cwd, "package-lock.json");
3849
3902
  const modulesPath = path11.join(cwd, "node_modules");
@@ -3857,6 +3910,18 @@ function applyDrizzlePeerMigration(targets, cwd) {
3857
3910
  const originalLock = fs14.existsSync(lockPath) ? fs14.readFileSync(lockPath) : void 0;
3858
3911
  const manifest = JSON.parse(originalManifest.toString());
3859
3912
  const lock = originalLock ? JSON.parse(originalLock.toString()) : void 0;
3913
+ const selectedNames = new Set(
3914
+ targets.map(
3915
+ (target) => target.slice(0, target.indexOf("@", target.startsWith("@") ? 1 : 0))
3916
+ )
3917
+ );
3918
+ const retainedVersions = /* @__PURE__ */ new Map();
3919
+ for (const pkg2 of affectedPackages) {
3920
+ if (pkg2 === "drizzle-orm" || selectedNames.has(pkg2)) continue;
3921
+ const installedPath = path11.join(modulesPath, pkg2, "package.json");
3922
+ const version = fs14.existsSync(installedPath) ? JSON.parse(fs14.readFileSync(installedPath, "utf8")).version : lock?.packages?.[`node_modules/${pkg2}`]?.version;
3923
+ if (typeof version === "string") retainedVersions.set(pkg2, version);
3924
+ }
3860
3925
  if (lock && (![2, 3].includes(lock.lockfileVersion) || !lock.packages || typeof lock.packages !== "object" || Array.isArray(lock.packages))) {
3861
3926
  throw new Error(
3862
3927
  "Drizzle peer migration requires npm lockfileVersion 2 or 3; regenerate the lockfile with the current SDKs before upgrading."
@@ -3875,11 +3940,6 @@ function applyDrizzlePeerMigration(targets, cwd) {
3875
3940
  }
3876
3941
  if (!declared) (manifest.dependencies ?? (manifest.dependencies = {}))["drizzle-orm"] = peer;
3877
3942
  if (lock) {
3878
- const selectedNames = new Set(
3879
- targets.map(
3880
- (target) => target.slice(0, target.indexOf("@", target.startsWith("@") ? 1 : 0))
3881
- )
3882
- );
3883
3943
  const retainedNames = affectedPackages.filter(
3884
3944
  (name) => name !== "drizzle-orm" && !selectedNames.has(name) && [
3885
3945
  "dependencies",
@@ -3927,9 +3987,38 @@ function applyDrizzlePeerMigration(targets, cwd) {
3927
3987
  if (lock) fs14.writeFileSync(lockPath, JSON.stringify(lock, null, 2) + "\n");
3928
3988
  const sdkTargets = targets.filter((target) => target !== peerTarget);
3929
3989
  runNpm(
3930
- ["install", "--package-lock-only", "--ignore-scripts", ...sdkTargets],
3990
+ [
3991
+ command,
3992
+ "--package-lock-only",
3993
+ "--ignore-scripts",
3994
+ ...sdkTargets.map(
3995
+ (target) => command === "update" ? target.slice(
3996
+ 0,
3997
+ target.indexOf("@", target.startsWith("@") ? 1 : 0)
3998
+ ) : target
3999
+ )
4000
+ ],
3931
4001
  cwd
3932
4002
  );
4003
+ const resolvedLock = JSON.parse(fs14.readFileSync(lockPath, "utf8"));
4004
+ if (resolvedLock.packages?.["node_modules/drizzle-orm"]?.version !== peer)
4005
+ throw new Error("Native npm resolution changed the planned Drizzle peer");
4006
+ for (const pkg2 of affectedPackages) {
4007
+ if (pkg2 === "drizzle-orm" || ![
4008
+ "dependencies",
4009
+ "devDependencies",
4010
+ "optionalDependencies",
4011
+ "peerDependencies"
4012
+ ].some((section) => manifest[section]?.[pkg2] !== void 0))
4013
+ continue;
4014
+ const sdk = resolvedLock.packages?.[`node_modules/${pkg2}`];
4015
+ if (sdk?.peerDependencies?.["drizzle-orm"] !== peer)
4016
+ throw new Error(
4017
+ `Native npm resolution changed the planned Drizzle peer for ${pkg2}`
4018
+ );
4019
+ if (retainedVersions.has(pkg2) && sdk.version !== retainedVersions.get(pkg2))
4020
+ throw new Error(`Native npm resolution changed unselected SDK ${pkg2}`);
4021
+ }
3933
4022
  runNpm(["ci"], cwd);
3934
4023
  } catch (error) {
3935
4024
  try {
@@ -4027,7 +4116,7 @@ function upgradePackages(packages, version, cwd, dryRun = false) {
4027
4116
  `[fullstack-cli] ${dryRun ? "Would install" : "Installing"} ${migration.join(" ")}`
4028
4117
  );
4029
4118
  if (dryRun) return;
4030
- applyDrizzlePeerMigration(migration, cwd);
4119
+ applyDrizzlePeerMigration(migration, cwd, version ? "install" : "update");
4031
4120
  return;
4032
4121
  }
4033
4122
  if (dryRun) {
@@ -5420,7 +5509,7 @@ import { execFile } from "child_process";
5420
5509
  // src/commands/component/registry-preparer.ts
5421
5510
  import fs20 from "fs";
5422
5511
  import path17 from "path";
5423
- import os from "os";
5512
+ import os2 from "os";
5424
5513
 
5425
5514
  // src/commands/component/service.ts
5426
5515
  import { mapValues } from "es-toolkit";
@@ -5479,7 +5568,7 @@ async function sendInstallEvent(key) {
5479
5568
  }
5480
5569
 
5481
5570
  // src/commands/component/registry-preparer.ts
5482
- var REGISTRY_TEMP_DIR = path17.join(os.tmpdir(), "miaoda-registry");
5571
+ var REGISTRY_TEMP_DIR = path17.join(os2.tmpdir(), "miaoda-registry");
5483
5572
  function parseComponentKey(key) {
5484
5573
  const match = key.match(/^@([^/]+)\/(.+)$/);
5485
5574
  if (!match) {
@@ -8870,7 +8959,7 @@ function camelToKebab(str) {
8870
8959
 
8871
8960
  // src/commands/build/upload-static.handler.ts
8872
8961
  import * as fs32 from "fs";
8873
- import * as os2 from "os";
8962
+ import * as os3 from "os";
8874
8963
  import * as path27 from "path";
8875
8964
  import { execFileSync } from "child_process";
8876
8965
  function readCredentialsFromEnv() {
@@ -8929,7 +9018,7 @@ async function uploadStatic(options) {
8929
9018
  ({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
8930
9019
  }
8931
9020
  console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
8932
- const confPath = path27.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
9021
+ const confPath = path27.join(os3.tmpdir(), `.tosutilconfig-static-${process.pid}`);
8933
9022
  fs32.writeFileSync(confPath, "");
8934
9023
  try {
8935
9024
  console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.71-alpha.20261103033524",
3
+ "version": "1.1.71-alpha.20261103070436",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,8 @@
16
16
  "test": "vitest run",
17
17
  "test:watch": "vitest",
18
18
  "test:peer-migration": "node scripts/smoke-drizzle-peer-migration.mjs",
19
- "prepublishOnly": "npm run build"
19
+ "prepublishOnly": "npm run build",
20
+ "test:npm-selection": "vitest run --config vitest.npm.config.ts"
20
21
  },
21
22
  "keywords": [
22
23
  "fullstack",