@cedarjs/cli-helpers 5.0.0-canary.2542 → 5.0.0-canary.2543

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.
@@ -0,0 +1,4 @@
1
+ import type { PackageManager } from '@cedarjs/project-config/packageManager';
2
+ export type AddWorkspaceDirResult = 'exists' | 'added';
3
+ export declare function addWorkspaceDir(baseDir: string, packagePath: string, pm: PackageManager): AddWorkspaceDirResult;
4
+ //# sourceMappingURL=workspaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../../src/packageManager/workspaces.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAE5E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEtD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,cAAc,GACjB,qBAAqB,CAMvB"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var workspaces_exports = {};
30
+ __export(workspaces_exports, {
31
+ addWorkspaceDir: () => addWorkspaceDir
32
+ });
33
+ module.exports = __toCommonJS(workspaces_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
35
+ var import_node_path = __toESM(require("node:path"), 1);
36
+ function addWorkspaceDir(baseDir, packagePath, pm) {
37
+ if (pm === "pnpm") {
38
+ return addPnpmWorkspaceDir(baseDir, packagePath);
39
+ }
40
+ return addPackageJsonWorkspaceDir(baseDir, packagePath);
41
+ }
42
+ function addPnpmWorkspaceDir(baseDir, packagePath) {
43
+ const yamlPath = import_node_path.default.join(baseDir, "pnpm-workspace.yaml");
44
+ if (!import_node_fs.default.existsSync(yamlPath)) {
45
+ throw new Error("Invalid workspace config in " + yamlPath);
46
+ }
47
+ const content = import_node_fs.default.readFileSync(yamlPath, "utf8");
48
+ const packageEntry = ` - ${packagePath}`;
49
+ if (content.includes(packageEntry)) {
50
+ return "exists";
51
+ }
52
+ const match = content.match(/^(packages:[\s\S]*?)(?=^\w|(?![\\s\\S]))/m);
53
+ if (!match) {
54
+ throw new Error("Invalid workspace config in " + yamlPath);
55
+ }
56
+ const packagesSection = match[1];
57
+ const lines = packagesSection.split("\n");
58
+ const lastPackageLine = lines.map((line, i) => ({ line, i })).filter(({ line }) => line.trimStart().startsWith("- ")).pop();
59
+ if (!lastPackageLine) {
60
+ throw new Error("Invalid workspace config in " + yamlPath);
61
+ }
62
+ const insertAfter = lastPackageLine.i;
63
+ lines.splice(insertAfter + 1, 0, packageEntry);
64
+ const updatedContent = content.replace(packagesSection, lines.join("\n"));
65
+ import_node_fs.default.writeFileSync(yamlPath, updatedContent, "utf8");
66
+ return "added";
67
+ }
68
+ function addPackageJsonWorkspaceDir(baseDir, packagePath) {
69
+ const pkgPath = import_node_path.default.join(baseDir, "package.json");
70
+ const pkg = JSON.parse(import_node_fs.default.readFileSync(pkgPath, "utf8"));
71
+ if (!Array.isArray(pkg.workspaces)) {
72
+ throw new Error("Invalid workspace config in " + pkgPath);
73
+ }
74
+ const hasWildcardPackagesWorkspace = pkg.workspaces.includes("packages/*");
75
+ const hasNamedPackagesWorkspace = pkg.workspaces.includes(packagePath);
76
+ const hasOtherNamedPackages = pkg.workspaces.some(
77
+ (workspace) => workspace.startsWith("packages/") && workspace !== packagePath
78
+ );
79
+ if (hasWildcardPackagesWorkspace || hasNamedPackagesWorkspace) {
80
+ return "exists";
81
+ }
82
+ if (hasOtherNamedPackages) {
83
+ pkg.workspaces.push(packagePath);
84
+ } else {
85
+ pkg.workspaces.push("packages/*");
86
+ }
87
+ import_node_fs.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
88
+ return "added";
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ addWorkspaceDir
93
+ });
@@ -0,0 +1,4 @@
1
+ import type { PackageManager } from '@cedarjs/project-config/packageManager';
2
+ export type AddWorkspaceDirResult = 'exists' | 'added';
3
+ export declare function addWorkspaceDir(baseDir: string, packagePath: string, pm: PackageManager): AddWorkspaceDirResult;
4
+ //# sourceMappingURL=workspaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../src/packageManager/workspaces.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAE5E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEtD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,cAAc,GACjB,qBAAqB,CAMvB"}
@@ -0,0 +1,59 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ function addWorkspaceDir(baseDir, packagePath, pm) {
4
+ if (pm === "pnpm") {
5
+ return addPnpmWorkspaceDir(baseDir, packagePath);
6
+ }
7
+ return addPackageJsonWorkspaceDir(baseDir, packagePath);
8
+ }
9
+ function addPnpmWorkspaceDir(baseDir, packagePath) {
10
+ const yamlPath = path.join(baseDir, "pnpm-workspace.yaml");
11
+ if (!fs.existsSync(yamlPath)) {
12
+ throw new Error("Invalid workspace config in " + yamlPath);
13
+ }
14
+ const content = fs.readFileSync(yamlPath, "utf8");
15
+ const packageEntry = ` - ${packagePath}`;
16
+ if (content.includes(packageEntry)) {
17
+ return "exists";
18
+ }
19
+ const match = content.match(/^(packages:[\s\S]*?)(?=^\w|(?![\\s\\S]))/m);
20
+ if (!match) {
21
+ throw new Error("Invalid workspace config in " + yamlPath);
22
+ }
23
+ const packagesSection = match[1];
24
+ const lines = packagesSection.split("\n");
25
+ const lastPackageLine = lines.map((line, i) => ({ line, i })).filter(({ line }) => line.trimStart().startsWith("- ")).pop();
26
+ if (!lastPackageLine) {
27
+ throw new Error("Invalid workspace config in " + yamlPath);
28
+ }
29
+ const insertAfter = lastPackageLine.i;
30
+ lines.splice(insertAfter + 1, 0, packageEntry);
31
+ const updatedContent = content.replace(packagesSection, lines.join("\n"));
32
+ fs.writeFileSync(yamlPath, updatedContent, "utf8");
33
+ return "added";
34
+ }
35
+ function addPackageJsonWorkspaceDir(baseDir, packagePath) {
36
+ const pkgPath = path.join(baseDir, "package.json");
37
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
38
+ if (!Array.isArray(pkg.workspaces)) {
39
+ throw new Error("Invalid workspace config in " + pkgPath);
40
+ }
41
+ const hasWildcardPackagesWorkspace = pkg.workspaces.includes("packages/*");
42
+ const hasNamedPackagesWorkspace = pkg.workspaces.includes(packagePath);
43
+ const hasOtherNamedPackages = pkg.workspaces.some(
44
+ (workspace) => workspace.startsWith("packages/") && workspace !== packagePath
45
+ );
46
+ if (hasWildcardPackagesWorkspace || hasNamedPackagesWorkspace) {
47
+ return "exists";
48
+ }
49
+ if (hasOtherNamedPackages) {
50
+ pkg.workspaces.push(packagePath);
51
+ } else {
52
+ pkg.workspaces.push("packages/*");
53
+ }
54
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
55
+ return "added";
56
+ }
57
+ export {
58
+ addWorkspaceDir
59
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-helpers",
3
- "version": "5.0.0-canary.2542",
3
+ "version": "5.0.0-canary.2543",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -78,6 +78,16 @@
78
78
  "types": "./dist/cjs/packageManager/display.d.ts",
79
79
  "default": "./dist/cjs/packageManager/display.js"
80
80
  }
81
+ },
82
+ "./packageManager/workspaces": {
83
+ "import": {
84
+ "types": "./dist/packageManager/workspaces.d.ts",
85
+ "default": "./dist/packageManager/workspaces.js"
86
+ },
87
+ "default": {
88
+ "types": "./dist/cjs/packageManager/workspaces.d.ts",
89
+ "default": "./dist/cjs/packageManager/workspaces.js"
90
+ }
81
91
  }
82
92
  },
83
93
  "types": "./dist/index.d.ts",
@@ -95,8 +105,8 @@
95
105
  },
96
106
  "dependencies": {
97
107
  "@babel/core": "^7.26.10",
98
- "@cedarjs/project-config": "5.0.0-canary.2542",
99
- "@cedarjs/telemetry": "5.0.0-canary.2542",
108
+ "@cedarjs/project-config": "5.0.0-canary.2543",
109
+ "@cedarjs/telemetry": "5.0.0-canary.2543",
100
110
  "@listr2/prompt-adapter-enquirer": "4.2.1",
101
111
  "@opentelemetry/api": "1.9.1",
102
112
  "ansis": "4.2.0",
@@ -115,7 +125,7 @@
115
125
  "yargs-parser": "21.1.1"
116
126
  },
117
127
  "devDependencies": {
118
- "@cedarjs/framework-tools": "5.0.0-canary.2542",
128
+ "@cedarjs/framework-tools": "5.0.0-canary.2543",
119
129
  "@types/dotenv-defaults": "^5.0.0",
120
130
  "@types/lodash": "4.17.24",
121
131
  "@types/pascalcase": "1.0.3",