@ldsg/cli 0.3.36 → 0.3.38

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.
package/CHANGELOG.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@ldsg/cli",
3
3
  "entries": [
4
+ {
5
+ "version": "0.3.38",
6
+ "tag": "@ldsg/cli_v0.3.38",
7
+ "date": "Tue, 18 Aug 2026 14:37:55 GMT",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "发布更新"
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@ldsg/apaas-to-runtime\" to `0.3.38`"
17
+ },
18
+ {
19
+ "comment": "Updating dependency \"@ldsg/constants\" to `0.3.38`"
20
+ },
21
+ {
22
+ "comment": "Updating dependency \"@ldsg/types\" to `0.3.38`"
23
+ },
24
+ {
25
+ "comment": "Updating dependency \"@ldsg/utils\" to `0.3.38`"
26
+ }
27
+ ]
28
+ }
29
+ },
30
+ {
31
+ "version": "0.3.37",
32
+ "tag": "@ldsg/cli_v0.3.37",
33
+ "date": "Tue, 11 Aug 2026 13:18:52 GMT",
34
+ "comments": {
35
+ "patch": [
36
+ {
37
+ "comment": "发布更新"
38
+ }
39
+ ],
40
+ "dependency": [
41
+ {
42
+ "comment": "Updating dependency \"@ldsg/apaas-to-runtime\" to `0.3.37`"
43
+ },
44
+ {
45
+ "comment": "Updating dependency \"@ldsg/constants\" to `0.3.37`"
46
+ },
47
+ {
48
+ "comment": "Updating dependency \"@ldsg/types\" to `0.3.37`"
49
+ },
50
+ {
51
+ "comment": "Updating dependency \"@ldsg/utils\" to `0.3.37`"
52
+ }
53
+ ]
54
+ }
55
+ },
4
56
  {
5
57
  "version": "0.3.36",
6
58
  "tag": "@ldsg/cli_v0.3.36",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change Log - @ldsg/cli
2
2
 
3
- This log was last generated on Mon, 10 Aug 2026 15:47:31 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 18 Aug 2026 14:37:55 GMT and should not be manually modified.
4
+
5
+ ## 0.3.38
6
+ Tue, 18 Aug 2026 14:37:55 GMT
7
+
8
+ ### Patches
9
+
10
+ - 发布更新
11
+
12
+ ## 0.3.37
13
+ Tue, 11 Aug 2026 13:18:52 GMT
14
+
15
+ ### Patches
16
+
17
+ - 发布更新
4
18
 
5
19
  ## 0.3.36
6
20
  Mon, 10 Aug 2026 15:47:31 GMT
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const js_yaml_1 = __importDefault(require("js-yaml"));
7
+ const add_pnpm_overrides_1 = require("../utils/add-pnpm-overrides");
8
+ describe("addPnpmOverrides", () => {
9
+ const baseFiles = [
10
+ {
11
+ path: "package.json",
12
+ data: {
13
+ dependencies: {
14
+ graphql: "^16.9.0",
15
+ "graphql-middleware": "^6.1.35",
16
+ "graphql-shield": "^7.6.5",
17
+ "other-dep": "^1.0.0",
18
+ },
19
+ },
20
+ },
21
+ {
22
+ path: "pnpm-workspace.yaml",
23
+ data: 'packages:\n - "handlers/*"\n',
24
+ },
25
+ {
26
+ path: "tsconfig.json",
27
+ data: { compilerOptions: { target: "esnext" } },
28
+ },
29
+ ];
30
+ it("should add overrides with versions from package.json dependencies", () => {
31
+ const result = (0, add_pnpm_overrides_1.addPnpmOverrides)(baseFiles, ["graphql", "graphql-middleware", "graphql-shield"]);
32
+ expect(result.path).toBe("pnpm-workspace.yaml");
33
+ const parsed = js_yaml_1.default.load(result.data);
34
+ expect(parsed.packages).toEqual(["handlers/*"]);
35
+ expect(parsed.overrides).toEqual({
36
+ graphql: "^16.9.0",
37
+ "graphql-middleware": "^6.1.35",
38
+ "graphql-shield": "^7.6.5",
39
+ });
40
+ });
41
+ it("should skip deps not found in package.json", () => {
42
+ const result = (0, add_pnpm_overrides_1.addPnpmOverrides)(baseFiles, ["graphql", "nonexistent-dep"]);
43
+ const parsed = js_yaml_1.default.load(result.data);
44
+ expect(parsed.overrides).toEqual({
45
+ graphql: "^16.9.0",
46
+ });
47
+ });
48
+ it("should add empty overrides when no matching deps", () => {
49
+ const result = (0, add_pnpm_overrides_1.addPnpmOverrides)(baseFiles, ["nonexistent-dep"]);
50
+ const parsed = js_yaml_1.default.load(result.data);
51
+ expect(parsed.overrides).toEqual({});
52
+ });
53
+ it("should preserve existing packages config", () => {
54
+ const filesWithCustomPackages = baseFiles.map((f) => f.path === "pnpm-workspace.yaml"
55
+ ? {
56
+ path: "pnpm-workspace.yaml",
57
+ data: 'packages:\n - "apps/*"\n - "libs/*"\n',
58
+ }
59
+ : f);
60
+ const result = (0, add_pnpm_overrides_1.addPnpmOverrides)(filesWithCustomPackages, ["graphql"]);
61
+ const parsed = js_yaml_1.default.load(result.data);
62
+ expect(parsed.packages).toEqual(["apps/*", "libs/*"]);
63
+ expect(parsed.overrides).toEqual({ graphql: "^16.9.0" });
64
+ });
65
+ it("should throw when pnpm-workspace.yaml is missing", () => {
66
+ const filesWithoutWorkspace = baseFiles.filter((f) => f.path !== "pnpm-workspace.yaml");
67
+ expect(() => (0, add_pnpm_overrides_1.addPnpmOverrides)(filesWithoutWorkspace, ["graphql"])).toThrow("pnpm-workspace.yaml not found");
68
+ });
69
+ it("should mutate the original pnpm-workspace.yaml file object", () => {
70
+ const files = JSON.parse(JSON.stringify(baseFiles));
71
+ const workspaceFile = files.find((f) => f.path === "pnpm-workspace.yaml");
72
+ (0, add_pnpm_overrides_1.addPnpmOverrides)(files, ["graphql"]);
73
+ expect(workspaceFile.data).toContain("overrides");
74
+ expect(workspaceFile.data).toContain("graphql");
75
+ });
76
+ });
77
+ //# sourceMappingURL=add-pnpm-overrides.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-pnpm-overrides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AAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,qBAAqB,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;QAExF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,qCAAgB,EAAC,qBAAqB,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CACxE,+BAA+B,CAChC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACpE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;QACpD,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;QAE/E,IAAA,qCAAgB,EAAC,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QAErC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAClD,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface FileInAppModule {
2
+ path: string;
3
+ data: string | Record<string, unknown>;
4
+ }
5
+ export declare const addPnpmOverrides: (files: FileInAppModule[], depNames: string[]) => FileInAppModule;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addPnpmOverrides = void 0;
7
+ const js_yaml_1 = __importDefault(require("js-yaml"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const addPnpmOverrides = (files, depNames) => {
10
+ const packageJsonFile = files.find((file) => file.path === "package.json");
11
+ const pnpmWorkspaceFile = files.find((file) => file.path === "pnpm-workspace.yaml");
12
+ if (!pnpmWorkspaceFile) {
13
+ throw new Error("pnpm-workspace.yaml not found in template files");
14
+ }
15
+ const pnpmWorkspace = js_yaml_1.default.load(lodash_1.default.isString(pnpmWorkspaceFile.data) ? pnpmWorkspaceFile.data : "");
16
+ const overrides = {};
17
+ for (const dep of depNames) {
18
+ const version = lodash_1.default.get(packageJsonFile, `data.dependencies["${dep}"]`);
19
+ if (version) {
20
+ overrides[dep] = version;
21
+ }
22
+ }
23
+ pnpmWorkspace.overrides = overrides;
24
+ pnpmWorkspaceFile.data = js_yaml_1.default.dump(pnpmWorkspace);
25
+ return pnpmWorkspaceFile;
26
+ };
27
+ exports.addPnpmOverrides = addPnpmOverrides;
28
+ //# sourceMappingURL=add-pnpm-overrides.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-pnpm-overrides.js","sourceRoot":"","sources":["../../src/utils/add-pnpm-overrides.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA2B;AAC3B,oDAAuB;AAehB,MAAM,gBAAgB,GAAG,CAAC,KAAwB,EAAE,QAAkB,EAAmB,EAAE;IAChG,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;IAC3E,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;IAEpF,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,aAAa,GAAG,iBAAI,CAAC,IAAI,CAC7B,gBAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CACtC,CAAC;IAE7B,MAAM,SAAS,GAA2B,EAAE,CAAC;IAC7C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,sBAAsB,GAAG,IAAI,CAAC,CAAC;QACtE,IAAI,OAAO,EAAE,CAAC;YACZ,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;IACpC,iBAAiB,CAAC,IAAI,GAAG,iBAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAElD,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAxBW,QAAA,gBAAgB,oBAwB3B"}
@@ -6,23 +6,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getExtendAppDataParamsUsingNpmLdsgModule = void 0;
7
7
  const constants_1 = require("@ldsg/constants");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
+ const add_pnpm_overrides_1 = require("./add-pnpm-overrides");
9
10
  const getExtendAppDataParamsUsingNpmLdsgModule = async (params) => {
10
11
  const { appData } = params;
11
12
  const packageJsonFile = constants_1.FILES_IN_APP_TEMPLATE_MODULE.find((file) => file.path === "package.json");
12
13
  lodash_1.default.set(packageJsonFile, 'data.dependencies["@ldsg/create-app"]', "latest");
13
14
  lodash_1.default.set(packageJsonFile, 'data.dependencies["@ldsg/opentelemetry-node"]', "latest");
14
- lodash_1.default.set(packageJsonFile, "data.overrides", {
15
- graphql: "$graphql",
16
- "graphql-middleware": "$graphql-middleware",
17
- "graphql-shield": "$graphql-shield",
18
- });
19
- lodash_1.default.set(packageJsonFile, "data.workspaces", ["handlers/*"]);
20
- lodash_1.default.set(packageJsonFile, "data.scripts.build", "npm run build --workspaces && tsc --project tsconfig.json");
15
+ const graphqlDeps = ["graphql", "graphql-middleware", "graphql-shield"];
16
+ const pnpmWorkspaceFile = (0, add_pnpm_overrides_1.addPnpmOverrides)(constants_1.FILES_IN_APP_TEMPLATE_MODULE, graphqlDeps);
21
17
  let res = {
22
18
  appData,
23
19
  extraAppData: {
24
- reuseMainAppDependencies: ["graphql", "graphql-middleware", "graphql-shield"],
25
- filesInAppModele: [...constants_1.FILES_IN_APP_TEMPLATE_MODULE, packageJsonFile],
20
+ reuseMainAppDependencies: graphqlDeps,
21
+ filesInAppModele: [...constants_1.FILES_IN_APP_TEMPLATE_MODULE, packageJsonFile, pnpmWorkspaceFile],
26
22
  },
27
23
  };
28
24
  return res;
@@ -1 +1 @@
1
- {"version":3,"file":"get-extend-app-data-params-using-npm-ldsg-module.js","sourceRoot":"","sources":["../../src/utils/get-extend-app-data-params-using-npm-ldsg-module.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA+D;AAE/D,oDAAuB;AAGhB,MAAM,wCAAwC,GAA2B,KAAK,EAAE,MAAM,EAAE,EAAE;IAC/F,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE3B,MAAM,eAAe,GAAG,wCAA4B,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;IAKlG,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,uCAAuC,EAAE,QAAQ,CAAC,CAAC;IAC1E,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,+CAA+C,EAAE,QAAQ,CAAC,CAAC;IAClF,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,gBAAgB,EAAE;QACvC,OAAO,EAAE,UAAU;QACnB,oBAAoB,EAAE,qBAAqB;QAC3C,gBAAgB,EAAE,iBAAiB;KACpC,CAAC,CAAC;IACH,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAC1D,gBAAC,CAAC,GAAG,CACH,eAAe,EACf,oBAAoB,EACpB,2DAA2D,CAC5D,CAAC;IAEF,IAAI,GAAG,GAAwB;QAC7B,OAAO;QACP,YAAY,EAAE;YACZ,wBAAwB,EAAE,CAAC,SAAS,EAAE,oBAAoB,EAAE,gBAAgB,CAAC;YAC7E,gBAAgB,EAAE,CAAC,GAAG,wCAA4B,EAAE,eAAe,CAAC;SACrE;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AA/BW,QAAA,wCAAwC,4CA+BnD"}
1
+ {"version":3,"file":"get-extend-app-data-params-using-npm-ldsg-module.js","sourceRoot":"","sources":["../../src/utils/get-extend-app-data-params-using-npm-ldsg-module.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA+D;AAE/D,oDAAuB;AAEvB,6DAAwD;AAEjD,MAAM,wCAAwC,GAA2B,KAAK,EAAE,MAAM,EAAE,EAAE;IAC/F,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE3B,MAAM,eAAe,GAAG,wCAA4B,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;IAKlG,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,uCAAuC,EAAE,QAAQ,CAAC,CAAC;IAC1E,gBAAC,CAAC,GAAG,CAAC,eAAe,EAAE,+CAA+C,EAAE,QAAQ,CAAC,CAAC;IAMlF,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;IACxE,MAAM,iBAAiB,GAAG,IAAA,qCAAgB,EAAC,wCAA4B,EAAE,WAAW,CAAC,CAAC;IAEtF,IAAI,GAAG,GAAwB;QAC7B,OAAO;QACP,YAAY,EAAE;YACZ,wBAAwB,EAAE,WAAW;YACrC,gBAAgB,EAAE,CAAC,GAAG,wCAA4B,EAAE,eAAe,EAAE,iBAAiB,CAAC;SACxF;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AA3BW,QAAA,wCAAwC,4CA2BnD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/cli",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "ISC",
@@ -16,13 +16,16 @@
16
16
  "axios": "^1.7.9",
17
17
  "commander": "^12.0.0",
18
18
  "fs-extra": "^11.3.0",
19
- "@ldsg/apaas-to-runtime": "0.3.36",
20
- "@ldsg/constants": "0.3.36",
21
- "@ldsg/utils": "0.3.36"
19
+ "js-yaml": "^4.1.0",
20
+ "@ldsg/apaas-to-runtime": "0.3.38",
21
+ "@ldsg/types": "0.3.38",
22
+ "@ldsg/utils": "0.3.38",
23
+ "@ldsg/constants": "0.3.38"
22
24
  },
23
25
  "devDependencies": {
24
26
  "@types/fs-extra": "^11.0.4",
25
27
  "@types/jest": "^30.0.0",
28
+ "@types/js-yaml": "^4.0.9",
26
29
  "@types/lodash": "^4.14.202",
27
30
  "@types/node": "^24.1.0",
28
31
  "@types/supertest": "^6.0.3",
@@ -35,8 +38,7 @@
35
38
  "ts-jest": "^29.4.1",
36
39
  "ts-node": "^10.9.2",
37
40
  "tslib": "^2.8.1",
38
- "typescript": "^5.3.3",
39
- "@ldsg/types": "0.3.36"
41
+ "typescript": "^5.3.3"
40
42
  },
41
43
  "scripts": {
42
44
  "build": "tsc --project tsconfig.build.json",
@@ -0,0 +1,2 @@
1
+ Invoking: oxfmt --write src/
2
+ Finished in 89ms on 23 files using 4 threads.
@@ -0,0 +1,91 @@
1
+ import yaml from "js-yaml";
2
+ import { addPnpmOverrides } from "../utils/add-pnpm-overrides";
3
+
4
+ describe("addPnpmOverrides", () => {
5
+ const baseFiles = [
6
+ {
7
+ path: "package.json",
8
+ data: {
9
+ dependencies: {
10
+ graphql: "^16.9.0",
11
+ "graphql-middleware": "^6.1.35",
12
+ "graphql-shield": "^7.6.5",
13
+ "other-dep": "^1.0.0",
14
+ },
15
+ },
16
+ },
17
+ {
18
+ path: "pnpm-workspace.yaml",
19
+ data: 'packages:\n - "handlers/*"\n',
20
+ },
21
+ {
22
+ path: "tsconfig.json",
23
+ data: { compilerOptions: { target: "esnext" } },
24
+ },
25
+ ];
26
+
27
+ it("should add overrides with versions from package.json dependencies", () => {
28
+ const result = addPnpmOverrides(baseFiles, ["graphql", "graphql-middleware", "graphql-shield"]);
29
+
30
+ expect(result.path).toBe("pnpm-workspace.yaml");
31
+
32
+ const parsed = yaml.load(result.data as string) as Record<string, unknown>;
33
+ expect(parsed.packages).toEqual(["handlers/*"]);
34
+ expect(parsed.overrides).toEqual({
35
+ graphql: "^16.9.0",
36
+ "graphql-middleware": "^6.1.35",
37
+ "graphql-shield": "^7.6.5",
38
+ });
39
+ });
40
+
41
+ it("should skip deps not found in package.json", () => {
42
+ const result = addPnpmOverrides(baseFiles, ["graphql", "nonexistent-dep"]);
43
+
44
+ const parsed = yaml.load(result.data as string) as Record<string, unknown>;
45
+ expect(parsed.overrides).toEqual({
46
+ graphql: "^16.9.0",
47
+ });
48
+ });
49
+
50
+ it("should add empty overrides when no matching deps", () => {
51
+ const result = addPnpmOverrides(baseFiles, ["nonexistent-dep"]);
52
+
53
+ const parsed = yaml.load(result.data as string) as Record<string, unknown>;
54
+ expect(parsed.overrides).toEqual({});
55
+ });
56
+
57
+ it("should preserve existing packages config", () => {
58
+ const filesWithCustomPackages = baseFiles.map((f) =>
59
+ f.path === "pnpm-workspace.yaml"
60
+ ? {
61
+ path: "pnpm-workspace.yaml",
62
+ data: 'packages:\n - "apps/*"\n - "libs/*"\n',
63
+ }
64
+ : f,
65
+ );
66
+
67
+ const result = addPnpmOverrides(filesWithCustomPackages, ["graphql"]);
68
+
69
+ const parsed = yaml.load(result.data as string) as Record<string, unknown>;
70
+ expect(parsed.packages).toEqual(["apps/*", "libs/*"]);
71
+ expect(parsed.overrides).toEqual({ graphql: "^16.9.0" });
72
+ });
73
+
74
+ it("should throw when pnpm-workspace.yaml is missing", () => {
75
+ const filesWithoutWorkspace = baseFiles.filter((f) => f.path !== "pnpm-workspace.yaml");
76
+
77
+ expect(() => addPnpmOverrides(filesWithoutWorkspace, ["graphql"])).toThrow(
78
+ "pnpm-workspace.yaml not found",
79
+ );
80
+ });
81
+
82
+ it("should mutate the original pnpm-workspace.yaml file object", () => {
83
+ const files = JSON.parse(JSON.stringify(baseFiles));
84
+ const workspaceFile = files.find((f: any) => f.path === "pnpm-workspace.yaml");
85
+
86
+ addPnpmOverrides(files, ["graphql"]);
87
+
88
+ expect(workspaceFile.data).toContain("overrides");
89
+ expect(workspaceFile.data).toContain("graphql");
90
+ });
91
+ });
@@ -0,0 +1,41 @@
1
+ import yaml from "js-yaml";
2
+ import _ from "lodash";
3
+
4
+ export interface FileInAppModule {
5
+ path: string;
6
+ data: string | Record<string, unknown>;
7
+ }
8
+
9
+ /**
10
+ * 向 pnpm-workspace.yaml 中添加 overrides 配置
11
+ * 版本号从指定 package.json 的 dependencies 中读取
12
+ *
13
+ * @param files - 应用模板文件列表
14
+ * @param depNames - 需要添加 overrides 的依赖名
15
+ * @returns 修改后的 pnpm-workspace.yaml 文件对象
16
+ */
17
+ export const addPnpmOverrides = (files: FileInAppModule[], depNames: string[]): FileInAppModule => {
18
+ const packageJsonFile = files.find((file) => file.path === "package.json");
19
+ const pnpmWorkspaceFile = files.find((file) => file.path === "pnpm-workspace.yaml");
20
+
21
+ if (!pnpmWorkspaceFile) {
22
+ throw new Error("pnpm-workspace.yaml not found in template files");
23
+ }
24
+
25
+ const pnpmWorkspace = yaml.load(
26
+ _.isString(pnpmWorkspaceFile.data) ? pnpmWorkspaceFile.data : "",
27
+ ) as Record<string, unknown>;
28
+
29
+ const overrides: Record<string, string> = {};
30
+ for (const dep of depNames) {
31
+ const version = _.get(packageJsonFile, `data.dependencies["${dep}"]`);
32
+ if (version) {
33
+ overrides[dep] = version;
34
+ }
35
+ }
36
+
37
+ pnpmWorkspace.overrides = overrides;
38
+ pnpmWorkspaceFile.data = yaml.dump(pnpmWorkspace);
39
+
40
+ return pnpmWorkspaceFile;
41
+ };
@@ -2,6 +2,7 @@ import { FILES_IN_APP_TEMPLATE_MODULE } from "@ldsg/constants";
2
2
  import { ExtendAppDataParams } from "@ldsg/utils";
3
3
  import _ from "lodash";
4
4
  import { GetExtendAppDataParams } from "../types/get-extend-app-data-params";
5
+ import { addPnpmOverrides } from "./add-pnpm-overrides";
5
6
 
6
7
  export const getExtendAppDataParamsUsingNpmLdsgModule: GetExtendAppDataParams = async (params) => {
7
8
  const { appData } = params;
@@ -13,23 +14,19 @@ export const getExtendAppDataParamsUsingNpmLdsgModule: GetExtendAppDataParams =
13
14
  */
14
15
  _.set(packageJsonFile, 'data.dependencies["@ldsg/create-app"]', "latest");
15
16
  _.set(packageJsonFile, 'data.dependencies["@ldsg/opentelemetry-node"]', "latest");
16
- _.set(packageJsonFile, "data.overrides", {
17
- graphql: "$graphql",
18
- "graphql-middleware": "$graphql-middleware",
19
- "graphql-shield": "$graphql-shield",
20
- });
21
- _.set(packageJsonFile, "data.workspaces", ["handlers/*"]);
22
- _.set(
23
- packageJsonFile,
24
- "data.scripts.build",
25
- "npm run build --workspaces && tsc --project tsconfig.json",
26
- );
17
+
18
+ /**
19
+ * 通过 pnpm-workspace.yaml 的 overrides 统一 graphql 相关依赖版本
20
+ * 版本号从 package.json 的 dependencies 中读取
21
+ */
22
+ const graphqlDeps = ["graphql", "graphql-middleware", "graphql-shield"];
23
+ const pnpmWorkspaceFile = addPnpmOverrides(FILES_IN_APP_TEMPLATE_MODULE, graphqlDeps);
27
24
 
28
25
  let res: ExtendAppDataParams = {
29
26
  appData,
30
27
  extraAppData: {
31
- reuseMainAppDependencies: ["graphql", "graphql-middleware", "graphql-shield"],
32
- filesInAppModele: [...FILES_IN_APP_TEMPLATE_MODULE, packageJsonFile],
28
+ reuseMainAppDependencies: graphqlDeps,
29
+ filesInAppModele: [...FILES_IN_APP_TEMPLATE_MODULE, packageJsonFile, pnpmWorkspaceFile],
33
30
  },
34
31
  };
35
32