@pgpmjs/env 2.9.2 → 2.9.4

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/env.js CHANGED
@@ -30,7 +30,9 @@ const getEnvVars = (env = process.env) => {
30
30
  // New connections.app and connections.admin env vars
31
31
  DB_CONNECTIONS_APP_USER, DB_CONNECTIONS_APP_PASSWORD, DB_CONNECTIONS_ADMIN_USER, DB_CONNECTIONS_ADMIN_PASSWORD, PORT, SERVER_HOST, SERVER_TRUST_PROXY, SERVER_ORIGIN, SERVER_STRICT_AUTH, PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, BUCKET_PROVIDER, BUCKET_NAME, AWS_REGION, AWS_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_SECRET_KEY, AWS_SECRET_ACCESS_KEY, MINIO_ENDPOINT, DEPLOYMENT_USE_TX, DEPLOYMENT_FAST, DEPLOYMENT_USE_PLAN, DEPLOYMENT_CACHE, DEPLOYMENT_TO_CHANGE, MIGRATIONS_CODEGEN_USE_TX,
32
32
  // Jobs-related env vars
33
- JOBS_SCHEMA, JOBS_SUPPORT_ANY, JOBS_SUPPORTED, INTERNAL_GATEWAY_URL, INTERNAL_JOBS_CALLBACK_URL, INTERNAL_JOBS_CALLBACK_PORT } = env;
33
+ JOBS_SCHEMA, JOBS_SUPPORT_ANY, JOBS_SUPPORTED, INTERNAL_GATEWAY_URL, INTERNAL_JOBS_CALLBACK_URL, INTERNAL_JOBS_CALLBACK_PORT,
34
+ // Error output formatting env vars
35
+ PGPM_ERROR_QUERY_HISTORY_LIMIT, PGPM_ERROR_MAX_LENGTH, PGPM_ERROR_VERBOSE } = env;
34
36
  return {
35
37
  db: {
36
38
  ...(PGROOTDATABASE && { rootDb: PGROOTDATABASE }),
@@ -137,6 +139,11 @@ const getEnvVars = (env = process.env) => {
137
139
  })
138
140
  }
139
141
  })
142
+ },
143
+ errorOutput: {
144
+ ...(PGPM_ERROR_QUERY_HISTORY_LIMIT && { queryHistoryLimit: parseEnvNumber(PGPM_ERROR_QUERY_HISTORY_LIMIT) }),
145
+ ...(PGPM_ERROR_MAX_LENGTH && { maxLength: parseEnvNumber(PGPM_ERROR_MAX_LENGTH) }),
146
+ ...(PGPM_ERROR_VERBOSE && { verbose: (0, exports.parseEnvBoolean)(PGPM_ERROR_VERBOSE) }),
140
147
  }
141
148
  };
142
149
  };
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/env.js CHANGED
@@ -26,7 +26,9 @@ export const getEnvVars = (env = process.env) => {
26
26
  // New connections.app and connections.admin env vars
27
27
  DB_CONNECTIONS_APP_USER, DB_CONNECTIONS_APP_PASSWORD, DB_CONNECTIONS_ADMIN_USER, DB_CONNECTIONS_ADMIN_PASSWORD, PORT, SERVER_HOST, SERVER_TRUST_PROXY, SERVER_ORIGIN, SERVER_STRICT_AUTH, PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, BUCKET_PROVIDER, BUCKET_NAME, AWS_REGION, AWS_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_SECRET_KEY, AWS_SECRET_ACCESS_KEY, MINIO_ENDPOINT, DEPLOYMENT_USE_TX, DEPLOYMENT_FAST, DEPLOYMENT_USE_PLAN, DEPLOYMENT_CACHE, DEPLOYMENT_TO_CHANGE, MIGRATIONS_CODEGEN_USE_TX,
28
28
  // Jobs-related env vars
29
- JOBS_SCHEMA, JOBS_SUPPORT_ANY, JOBS_SUPPORTED, INTERNAL_GATEWAY_URL, INTERNAL_JOBS_CALLBACK_URL, INTERNAL_JOBS_CALLBACK_PORT } = env;
29
+ JOBS_SCHEMA, JOBS_SUPPORT_ANY, JOBS_SUPPORTED, INTERNAL_GATEWAY_URL, INTERNAL_JOBS_CALLBACK_URL, INTERNAL_JOBS_CALLBACK_PORT,
30
+ // Error output formatting env vars
31
+ PGPM_ERROR_QUERY_HISTORY_LIMIT, PGPM_ERROR_MAX_LENGTH, PGPM_ERROR_VERBOSE } = env;
30
32
  return {
31
33
  db: {
32
34
  ...(PGROOTDATABASE && { rootDb: PGROOTDATABASE }),
@@ -133,6 +135,11 @@ export const getEnvVars = (env = process.env) => {
133
135
  })
134
136
  }
135
137
  })
138
+ },
139
+ errorOutput: {
140
+ ...(PGPM_ERROR_QUERY_HISTORY_LIMIT && { queryHistoryLimit: parseEnvNumber(PGPM_ERROR_QUERY_HISTORY_LIMIT) }),
141
+ ...(PGPM_ERROR_MAX_LENGTH && { maxLength: parseEnvNumber(PGPM_ERROR_MAX_LENGTH) }),
142
+ ...(PGPM_ERROR_VERBOSE && { verbose: parseEnvBoolean(PGPM_ERROR_VERBOSE) }),
136
143
  }
137
144
  };
138
145
  };
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.2",
3
+ "version": "2.9.4",
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.14.0",
32
+ "@pgpmjs/types": "^2.14.1",
33
33
  "deepmerge": "^4.3.1"
34
34
  },
35
35
  "keywords": [
@@ -43,5 +43,5 @@
43
43
  "devDependencies": {
44
44
  "makage": "^0.1.10"
45
45
  },
46
- "gitHead": "f2f9c9851beff3214790dfca371e4ca7f6c1373f"
46
+ "gitHead": "cb4af2cf6c23dad24cd951c232d3e2006b81aa3d"
47
47
  }