@pgpmjs/env 2.9.1 → 2.9.3

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/config.d.ts CHANGED
@@ -19,3 +19,20 @@ export declare const loadConfigSync: (cwd?: string) => PgpmOptions;
19
19
  * Moved from PgpmPackage class for better reusability
20
20
  */
21
21
  export declare const resolvePgpmPath: (cwd?: string) => string | undefined;
22
+ /**
23
+ * Resolve the path to a pnpm workspace by finding pnpm-workspace.yaml
24
+ */
25
+ export declare const resolvePnpmWorkspace: (cwd?: string) => string | undefined;
26
+ /**
27
+ * Resolve the path to a lerna workspace by finding lerna.json
28
+ */
29
+ export declare const resolveLernaWorkspace: (cwd?: string) => string | undefined;
30
+ /**
31
+ * Resolve the path to an npm workspace by finding package.json with workspaces field
32
+ */
33
+ export declare const resolveNpmWorkspace: (cwd?: string) => string | undefined;
34
+ export type WorkspaceType = 'pgpm' | 'pnpm' | 'lerna' | 'npm';
35
+ /**
36
+ * Resolve workspace path based on workspace type
37
+ */
38
+ export declare const resolveWorkspaceByType: (cwd: string, workspaceType: WorkspaceType) => string | undefined;
package/config.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.resolvePgpmPath = exports.loadConfigSync = exports.loadConfigSyncFromDir = exports.loadConfigFileSync = void 0;
36
+ exports.resolveWorkspaceByType = exports.resolveNpmWorkspace = exports.resolveLernaWorkspace = exports.resolvePnpmWorkspace = exports.resolvePgpmPath = exports.loadConfigSync = exports.loadConfigSyncFromDir = exports.loadConfigFileSync = void 0;
37
37
  const fs = __importStar(require("fs"));
38
38
  const path = __importStar(require("path"));
39
39
  const utils_1 = require("./utils");
@@ -106,3 +106,69 @@ const resolvePgpmPath = (cwd = process.cwd()) => {
106
106
  return undefined;
107
107
  };
108
108
  exports.resolvePgpmPath = resolvePgpmPath;
109
+ /**
110
+ * Resolve the path to a pnpm workspace by finding pnpm-workspace.yaml
111
+ */
112
+ const resolvePnpmWorkspace = (cwd = process.cwd()) => {
113
+ try {
114
+ return (0, utils_1.walkUp)(cwd, 'pnpm-workspace.yaml');
115
+ }
116
+ catch {
117
+ return undefined;
118
+ }
119
+ };
120
+ exports.resolvePnpmWorkspace = resolvePnpmWorkspace;
121
+ /**
122
+ * Resolve the path to a lerna workspace by finding lerna.json
123
+ */
124
+ const resolveLernaWorkspace = (cwd = process.cwd()) => {
125
+ try {
126
+ return (0, utils_1.walkUp)(cwd, 'lerna.json');
127
+ }
128
+ catch {
129
+ return undefined;
130
+ }
131
+ };
132
+ exports.resolveLernaWorkspace = resolveLernaWorkspace;
133
+ /**
134
+ * Resolve the path to an npm workspace by finding package.json with workspaces field
135
+ */
136
+ const resolveNpmWorkspace = (cwd = process.cwd()) => {
137
+ let currentDir = path.resolve(cwd);
138
+ const root = path.parse(currentDir).root;
139
+ while (currentDir !== root) {
140
+ const packageJsonPath = path.join(currentDir, 'package.json');
141
+ if (fs.existsSync(packageJsonPath)) {
142
+ try {
143
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
144
+ if (packageJson.workspaces) {
145
+ return currentDir;
146
+ }
147
+ }
148
+ catch {
149
+ // Ignore JSON parse errors
150
+ }
151
+ }
152
+ currentDir = path.dirname(currentDir);
153
+ }
154
+ return undefined;
155
+ };
156
+ exports.resolveNpmWorkspace = resolveNpmWorkspace;
157
+ /**
158
+ * Resolve workspace path based on workspace type
159
+ */
160
+ const resolveWorkspaceByType = (cwd, workspaceType) => {
161
+ switch (workspaceType) {
162
+ case 'pgpm':
163
+ return (0, exports.resolvePgpmPath)(cwd);
164
+ case 'pnpm':
165
+ return (0, exports.resolvePnpmWorkspace)(cwd);
166
+ case 'lerna':
167
+ return (0, exports.resolveLernaWorkspace)(cwd);
168
+ case 'npm':
169
+ return (0, exports.resolveNpmWorkspace)(cwd);
170
+ default:
171
+ return undefined;
172
+ }
173
+ };
174
+ exports.resolveWorkspaceByType = resolveWorkspaceByType;
package/esm/config.js CHANGED
@@ -66,3 +66,65 @@ export const resolvePgpmPath = (cwd = process.cwd()) => {
66
66
  }
67
67
  return undefined;
68
68
  };
69
+ /**
70
+ * Resolve the path to a pnpm workspace by finding pnpm-workspace.yaml
71
+ */
72
+ export const resolvePnpmWorkspace = (cwd = process.cwd()) => {
73
+ try {
74
+ return walkUp(cwd, 'pnpm-workspace.yaml');
75
+ }
76
+ catch {
77
+ return undefined;
78
+ }
79
+ };
80
+ /**
81
+ * Resolve the path to a lerna workspace by finding lerna.json
82
+ */
83
+ export const resolveLernaWorkspace = (cwd = process.cwd()) => {
84
+ try {
85
+ return walkUp(cwd, 'lerna.json');
86
+ }
87
+ catch {
88
+ return undefined;
89
+ }
90
+ };
91
+ /**
92
+ * Resolve the path to an npm workspace by finding package.json with workspaces field
93
+ */
94
+ export const resolveNpmWorkspace = (cwd = process.cwd()) => {
95
+ let currentDir = path.resolve(cwd);
96
+ const root = path.parse(currentDir).root;
97
+ while (currentDir !== root) {
98
+ const packageJsonPath = path.join(currentDir, 'package.json');
99
+ if (fs.existsSync(packageJsonPath)) {
100
+ try {
101
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
102
+ if (packageJson.workspaces) {
103
+ return currentDir;
104
+ }
105
+ }
106
+ catch {
107
+ // Ignore JSON parse errors
108
+ }
109
+ }
110
+ currentDir = path.dirname(currentDir);
111
+ }
112
+ return undefined;
113
+ };
114
+ /**
115
+ * Resolve workspace path based on workspace type
116
+ */
117
+ export const resolveWorkspaceByType = (cwd, workspaceType) => {
118
+ switch (workspaceType) {
119
+ case 'pgpm':
120
+ return resolvePgpmPath(cwd);
121
+ case 'pnpm':
122
+ return resolvePnpmWorkspace(cwd);
123
+ case 'lerna':
124
+ return resolveLernaWorkspace(cwd);
125
+ case 'npm':
126
+ return resolveNpmWorkspace(cwd);
127
+ default:
128
+ return undefined;
129
+ }
130
+ };
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { getEnvOptions, getConnEnvOptions, getDeploymentEnvOptions } from './merge';
2
- export { loadConfigSync, loadConfigSyncFromDir, loadConfigFileSync, resolvePgpmPath } from './config';
2
+ export { loadConfigSync, loadConfigSyncFromDir, loadConfigFileSync, resolvePgpmPath, resolvePnpmWorkspace, resolveLernaWorkspace, resolveNpmWorkspace, resolveWorkspaceByType } from './config';
3
3
  export { getEnvVars, getNodeEnv, parseEnvBoolean } from './env';
4
4
  export { walkUp, mergeArraysUnique } from './utils';
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { getEnvOptions, getConnEnvOptions, getDeploymentEnvOptions } from './merge';
2
- export { loadConfigSync, loadConfigSyncFromDir, loadConfigFileSync, resolvePgpmPath } from './config';
2
+ export { loadConfigSync, loadConfigSyncFromDir, loadConfigFileSync, resolvePgpmPath, resolvePnpmWorkspace, resolveLernaWorkspace, resolveNpmWorkspace, resolveWorkspaceByType } from './config';
3
+ export type { WorkspaceType } from './config';
3
4
  export { getEnvVars, getNodeEnv, parseEnvBoolean } from './env';
4
5
  export { walkUp, mergeArraysUnique } from './utils';
5
6
  export type { PgpmOptions, PgTestConnectionOptions, DeploymentOptions } from '@pgpmjs/types';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeArraysUnique = exports.walkUp = exports.parseEnvBoolean = exports.getNodeEnv = exports.getEnvVars = exports.resolvePgpmPath = exports.loadConfigFileSync = exports.loadConfigSyncFromDir = exports.loadConfigSync = exports.getDeploymentEnvOptions = exports.getConnEnvOptions = exports.getEnvOptions = void 0;
3
+ exports.mergeArraysUnique = exports.walkUp = exports.parseEnvBoolean = exports.getNodeEnv = exports.getEnvVars = exports.resolveWorkspaceByType = exports.resolveNpmWorkspace = exports.resolveLernaWorkspace = exports.resolvePnpmWorkspace = exports.resolvePgpmPath = exports.loadConfigFileSync = exports.loadConfigSyncFromDir = exports.loadConfigSync = exports.getDeploymentEnvOptions = exports.getConnEnvOptions = exports.getEnvOptions = void 0;
4
4
  var merge_1 = require("./merge");
5
5
  Object.defineProperty(exports, "getEnvOptions", { enumerable: true, get: function () { return merge_1.getEnvOptions; } });
6
6
  Object.defineProperty(exports, "getConnEnvOptions", { enumerable: true, get: function () { return merge_1.getConnEnvOptions; } });
@@ -10,6 +10,10 @@ Object.defineProperty(exports, "loadConfigSync", { enumerable: true, get: functi
10
10
  Object.defineProperty(exports, "loadConfigSyncFromDir", { enumerable: true, get: function () { return config_1.loadConfigSyncFromDir; } });
11
11
  Object.defineProperty(exports, "loadConfigFileSync", { enumerable: true, get: function () { return config_1.loadConfigFileSync; } });
12
12
  Object.defineProperty(exports, "resolvePgpmPath", { enumerable: true, get: function () { return config_1.resolvePgpmPath; } });
13
+ Object.defineProperty(exports, "resolvePnpmWorkspace", { enumerable: true, get: function () { return config_1.resolvePnpmWorkspace; } });
14
+ Object.defineProperty(exports, "resolveLernaWorkspace", { enumerable: true, get: function () { return config_1.resolveLernaWorkspace; } });
15
+ Object.defineProperty(exports, "resolveNpmWorkspace", { enumerable: true, get: function () { return config_1.resolveNpmWorkspace; } });
16
+ Object.defineProperty(exports, "resolveWorkspaceByType", { enumerable: true, get: function () { return config_1.resolveWorkspaceByType; } });
13
17
  var env_1 = require("./env");
14
18
  Object.defineProperty(exports, "getEnvVars", { enumerable: true, get: function () { return env_1.getEnvVars; } });
15
19
  Object.defineProperty(exports, "getNodeEnv", { enumerable: true, get: function () { return env_1.getNodeEnv; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/env",
3
- "version": "2.9.1",
3
+ "version": "2.9.3",
4
4
  "author": "Dan Lynch <Dan Lynch>",
5
5
  "description": "PGPM environment management",
6
6
  "main": "index.js",
@@ -29,7 +29,7 @@
29
29
  "test:watch": "jest --watch"
30
30
  },
31
31
  "dependencies": {
32
- "@pgpmjs/types": "^2.13.0",
32
+ "@pgpmjs/types": "^2.14.0",
33
33
  "deepmerge": "^4.3.1"
34
34
  },
35
35
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "env"
42
42
  ],
43
43
  "devDependencies": {
44
- "makage": "^0.1.9"
44
+ "makage": "^0.1.10"
45
45
  },
46
- "gitHead": "14ed679aeb6172e013c817b8a458e5bee68ab492"
46
+ "gitHead": "ba5bbacf7ccc1980cba10bf3f45ebb0ca639fb79"
47
47
  }