@vaharoni/devops 1.2.6 → 1.2.8

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.
@@ -1,8 +1,8 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync, spawn } from "child_process";
3
3
  import fs from "fs";
4
- import { globSync } from "glob";
5
4
  import { allSupportedEnvs } from "../libs/k8s-constants";
5
+ import { globEnvYamlFiles } from "../libs/discovery";
6
6
  export class CLICommandParser {
7
7
  command;
8
8
  args;
@@ -207,7 +207,7 @@ export class CommandExecutor {
207
207
  _checkEnvYamlFiles() {
208
208
  if (!this.checkEnvYaml)
209
209
  return;
210
- const envYamlFiles = globSync("**/env.yaml");
210
+ const envYamlFiles = globEnvYamlFiles();
211
211
  const checkEnvCmd = new CommandExecutor(`devops env _validate ${envYamlFiles.join(" ")}`, { env: this.env, quiet: true, checkEnvYaml: false });
212
212
  checkEnvCmd.exec();
213
213
  }
@@ -1,6 +1,6 @@
1
- import { globSync } from "glob";
2
1
  import { deleteMonorepoSecret, getMonorepoSecretStr, setMonorepoSecret, } from "../../libs/k8s-secrets-manager";
3
2
  import { CombinedEnvValidator } from "../../libs/validate-env";
3
+ import { globEnvYamlFiles } from "../../libs/discovery";
4
4
  import { CLICommandParser, dotEnvFilesForEnv, printUsageAndExit, } from "../common";
5
5
  const oneLiner = "Commands to manipulate env variables";
6
6
  const keyExamples = `
@@ -28,7 +28,7 @@ function run(cmdObj) {
28
28
  const [command, ...rest] = cmdObj.args;
29
29
  switch (command) {
30
30
  case "validate": {
31
- const envYamlFiles = globSync("**/env.yaml");
31
+ const envYamlFiles = globEnvYamlFiles();
32
32
  // We have to have a _validate so that we go through a CommandExecutor which injects env variables into the process
33
33
  cmdObj
34
34
  .executorFromEnv(`devops env _validate ${envYamlFiles.join(" ")}`, { quiet: false })
@@ -2,4 +2,5 @@ import type { SupportedLanguages, WorkspaceIndex } from "../../types";
2
2
  export declare function workspaces(): WorkspaceIndex;
3
3
  export declare function workspaceDirectoryForLanguage(language: SupportedLanguages): Record<string, import("../..").PackageData>;
4
4
  export declare function getWorkspace(workspaceName: string): import("../..").WorkspaceIndexEntry;
5
+ export declare function globEnvYamlFiles(): string[];
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/discovery/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKtE,wBAAgB,UAAU,mBA8BzB;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,kBAAkB,+CASzE;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,uCAQjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/discovery/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAOtE,wBAAgB,UAAU,mBA8BzB;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,kBAAkB,+CASzE;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,uCAQjD;AAED,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAQ3C"}
@@ -1,6 +1,9 @@
1
1
  import chalk from "chalk";
2
+ import { globSync } from "glob";
3
+ import path from "path";
2
4
  import { nodeWorkspaces } from "./process-package-json";
3
5
  import { pythonWorkspaces } from "./process-pyproject-toml";
6
+ const rootPath = process.env.MONOREPO_ROOT || process.cwd();
4
7
  const _workspaces = {};
5
8
  let _workspacesLoaded = false;
6
9
  export function workspaces() {
@@ -53,3 +56,10 @@ export function getWorkspace(workspaceName) {
53
56
  }
54
57
  return workspace;
55
58
  }
59
+ export function globEnvYamlFiles() {
60
+ const allWorkspaces = workspaces();
61
+ const workspacePaths = [
62
+ ...new Set(Object.values(allWorkspaces).map((w) => w.rootPath)),
63
+ ];
64
+ return workspacePaths.flatMap((wsPath) => globSync(path.join(rootPath, wsPath, "**/env.yaml")));
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"process-pyproject-toml.d.ts","sourceRoot":"","sources":["../../../src/libs/discovery/process-pyproject-toml.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AASxE,wBAAgB,gBAAgB,gCAqC/B"}
1
+ {"version":3,"file":"process-pyproject-toml.d.ts","sourceRoot":"","sources":["../../../src/libs/discovery/process-pyproject-toml.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAUxE,wBAAgB,gBAAgB,gCAkD/B"}
@@ -1,40 +1,49 @@
1
1
  import chalk from "chalk";
2
+ import fs from "fs";
2
3
  import { globSync } from "glob";
3
4
  import { packageFilePythonSchema } from "../../types";
4
5
  import { PackageDataProcessor } from "./process-common";
5
6
  import TOML from "@iarna/toml";
6
7
  import path from "path";
7
8
  const rootPath = process.env.MONOREPO_ROOT || process.cwd();
9
+ const rootPyprojectPath = path.join(rootPath, "pyproject.toml");
8
10
  const _workspaces = {};
9
11
  let _workspacesLoaded = false;
10
12
  export function pythonWorkspaces() {
11
- if (!_workspacesLoaded) {
12
- const allPyprojectTomls = globSync(path.join(rootPath, "**/*/pyproject.toml"));
13
- const processor = new PackageDataProcessor({
14
- language: "python",
15
- pathList: allPyprojectTomls,
16
- zodSchema: packageFilePythonSchema,
17
- fileParser: TOML.parse,
18
- nameExtractor: (data) => data.project.name,
19
- });
20
- processor
21
- .convert((data) => {
22
- const deployment = data.tool?.devops?.deployment;
23
- const scripts = data.tool?.devops?.scripts;
24
- const dependencyNames = data.project.dependencies ?? [];
25
- return {
26
- scripts,
27
- deployment,
28
- dependencyNames: processor.filterDependencies(dependencyNames),
29
- };
30
- })
31
- .forEach((pkgData) => {
32
- _workspaces[pkgData.name] = pkgData;
33
- });
34
- console.warn(chalk.yellow(
35
- // prettier-ignore
36
- `Python workspace discovery initialized. Workspaces found: ${Object.keys(_workspaces).join(", ")}`));
13
+ if (_workspacesLoaded)
14
+ return _workspaces;
15
+ // No root pyproject.toml means no Python workspaces - skip discovery
16
+ if (!fs.existsSync(rootPyprojectPath)) {
37
17
  _workspacesLoaded = true;
18
+ return _workspaces;
38
19
  }
20
+ const rootPyproject = TOML.parse(fs.readFileSync(rootPyprojectPath, "utf8"));
21
+ const workspaceMembers = rootPyproject?.tool?.uv?.workspace?.members ?? [];
22
+ const allPyprojectTomls = workspaceMembers.flatMap((member) => globSync(path.join(rootPath, member, "pyproject.toml")));
23
+ const processor = new PackageDataProcessor({
24
+ language: "python",
25
+ pathList: allPyprojectTomls,
26
+ zodSchema: packageFilePythonSchema,
27
+ fileParser: TOML.parse,
28
+ nameExtractor: (data) => data.project.name,
29
+ });
30
+ processor
31
+ .convert((data) => {
32
+ const deployment = data.tool?.devops?.deployment;
33
+ const scripts = data.tool?.devops?.scripts;
34
+ const dependencyNames = data.project.dependencies ?? [];
35
+ return {
36
+ scripts,
37
+ deployment,
38
+ dependencyNames: processor.filterDependencies(dependencyNames),
39
+ };
40
+ })
41
+ .forEach((pkgData) => {
42
+ _workspaces[pkgData.name] = pkgData;
43
+ });
44
+ console.warn(chalk.yellow(
45
+ // prettier-ignore
46
+ `Python workspace discovery initialized. Workspaces found: ${Object.keys(_workspaces).join(", ")}`));
47
+ _workspacesLoaded = true;
39
48
  return _workspaces;
40
49
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vaharoni/devops",
3
3
  "type": "module",
4
- "version": "1.2.6",
4
+ "version": "1.2.8",
5
5
  "description": "Devops utility",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
package/src/cli/common.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import chalk from "chalk";
2
2
  import { execSync, spawn, type StdioOptions } from "child_process";
3
3
  import fs from "fs";
4
- import { globSync } from "glob";
5
4
  import { allSupportedEnvs } from "../libs/k8s-constants";
5
+ import { globEnvYamlFiles } from "../libs/discovery";
6
6
 
7
7
  type ParsedArgs<TBoolKeys extends readonly string[], TParamKeys extends readonly string[]> = {
8
8
  args: string[];
@@ -294,7 +294,7 @@ export class CommandExecutor {
294
294
 
295
295
  _checkEnvYamlFiles() {
296
296
  if (!this.checkEnvYaml) return;
297
- const envYamlFiles = globSync("**/env.yaml");
297
+ const envYamlFiles = globEnvYamlFiles();
298
298
  const checkEnvCmd = new CommandExecutor(
299
299
  `devops env _validate ${envYamlFiles.join(" ")}`,
300
300
  { env: this.env, quiet: true, checkEnvYaml: false }
@@ -1,10 +1,10 @@
1
- import { globSync } from "glob";
2
1
  import {
3
2
  deleteMonorepoSecret,
4
3
  getMonorepoSecretStr,
5
4
  setMonorepoSecret,
6
5
  } from "../../libs/k8s-secrets-manager";
7
6
  import { CombinedEnvValidator } from "../../libs/validate-env";
7
+ import { globEnvYamlFiles } from "../../libs/discovery";
8
8
  import {
9
9
  CLICommandParser,
10
10
  dotEnvFilesForEnv,
@@ -38,7 +38,7 @@ function run(cmdObj: CLICommandParser) {
38
38
  const [command, ...rest] = cmdObj.args;
39
39
  switch (command) {
40
40
  case "validate": {
41
- const envYamlFiles = globSync("**/env.yaml");
41
+ const envYamlFiles = globEnvYamlFiles();
42
42
 
43
43
  // We have to have a _validate so that we go through a CommandExecutor which injects env variables into the process
44
44
  cmdObj
@@ -1,8 +1,12 @@
1
1
  import chalk from "chalk";
2
+ import { globSync } from "glob";
3
+ import path from "path";
2
4
  import { nodeWorkspaces } from "./process-package-json";
3
5
  import { pythonWorkspaces } from "./process-pyproject-toml";
4
6
  import type { SupportedLanguages, WorkspaceIndex } from "../../types";
5
7
 
8
+ const rootPath = process.env.MONOREPO_ROOT || process.cwd();
9
+
6
10
  const _workspaces: WorkspaceIndex = {};
7
11
  let _workspacesLoaded = false;
8
12
 
@@ -58,3 +62,13 @@ export function getWorkspace(workspaceName: string) {
58
62
  }
59
63
  return workspace;
60
64
  }
65
+
66
+ export function globEnvYamlFiles(): string[] {
67
+ const allWorkspaces = workspaces();
68
+ const workspacePaths = [
69
+ ...new Set(Object.values(allWorkspaces).map((w) => w.rootPath)),
70
+ ];
71
+ return workspacePaths.flatMap((wsPath) =>
72
+ globSync(path.join(rootPath, wsPath, "**/env.yaml"))
73
+ );
74
+ }
@@ -1,4 +1,5 @@
1
1
  import chalk from "chalk";
2
+ import fs from "fs";
2
3
  import { globSync } from "glob";
3
4
  import { packageFilePythonSchema, type PackageData } from "../../types";
4
5
  import { PackageDataProcessor } from "./process-common";
@@ -6,44 +7,58 @@ import TOML from "@iarna/toml";
6
7
  import path from "path";
7
8
 
8
9
  const rootPath = process.env.MONOREPO_ROOT || process.cwd();
10
+ const rootPyprojectPath = path.join(rootPath, "pyproject.toml");
9
11
  const _workspaces: Record<string, PackageData> = {};
10
12
  let _workspacesLoaded = false;
11
13
 
12
14
  export function pythonWorkspaces() {
13
- if (!_workspacesLoaded) {
14
- const allPyprojectTomls = globSync(
15
- path.join(rootPath, "**/*/pyproject.toml")
16
- );
17
- const processor = new PackageDataProcessor({
18
- language: "python",
19
- pathList: allPyprojectTomls,
20
- zodSchema: packageFilePythonSchema,
21
- fileParser: TOML.parse,
22
- nameExtractor: (data) => data.project.name,
23
- });
15
+ if (_workspacesLoaded) return _workspaces;
24
16
 
25
- processor
26
- .convert((data) => {
27
- const deployment = data.tool?.devops?.deployment;
28
- const scripts = data.tool?.devops?.scripts;
29
- const dependencyNames = data.project.dependencies ?? [];
30
- return {
31
- scripts,
32
- deployment,
33
- dependencyNames: processor.filterDependencies(dependencyNames),
34
- };
35
- })
36
- .forEach((pkgData) => {
37
- _workspaces[pkgData.name] = pkgData;
38
- });
39
-
40
- console.warn(
41
- chalk.yellow(
42
- // prettier-ignore
43
- `Python workspace discovery initialized. Workspaces found: ${Object.keys(_workspaces).join(", ")}`
44
- )
45
- );
17
+ // No root pyproject.toml means no Python workspaces - skip discovery
18
+ if (!fs.existsSync(rootPyprojectPath)) {
46
19
  _workspacesLoaded = true;
20
+ return _workspaces;
47
21
  }
22
+
23
+ const rootPyproject = TOML.parse(
24
+ fs.readFileSync(rootPyprojectPath, "utf8")
25
+ ) as { tool?: { uv?: { workspace?: { members?: string[] } } } };
26
+ const workspaceMembers: string[] =
27
+ rootPyproject?.tool?.uv?.workspace?.members ?? [];
28
+
29
+ const allPyprojectTomls = workspaceMembers.flatMap((member) =>
30
+ globSync(path.join(rootPath, member, "pyproject.toml"))
31
+ );
32
+
33
+ const processor = new PackageDataProcessor({
34
+ language: "python",
35
+ pathList: allPyprojectTomls,
36
+ zodSchema: packageFilePythonSchema,
37
+ fileParser: TOML.parse,
38
+ nameExtractor: (data) => data.project.name,
39
+ });
40
+
41
+ processor
42
+ .convert((data) => {
43
+ const deployment = data.tool?.devops?.deployment;
44
+ const scripts = data.tool?.devops?.scripts;
45
+ const dependencyNames = data.project.dependencies ?? [];
46
+ return {
47
+ scripts,
48
+ deployment,
49
+ dependencyNames: processor.filterDependencies(dependencyNames),
50
+ };
51
+ })
52
+ .forEach((pkgData) => {
53
+ _workspaces[pkgData.name] = pkgData;
54
+ });
55
+
56
+ console.warn(
57
+ chalk.yellow(
58
+ // prettier-ignore
59
+ `Python workspace discovery initialized. Workspaces found: ${Object.keys(_workspaces).join(", ")}`
60
+ )
61
+ );
62
+ _workspacesLoaded = true;
48
63
  return _workspaces;
49
64
  }