@hublo/sentinel 1.4.0-alpha.22 → 1.4.0-alpha.24

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.
@@ -15,14 +15,12 @@ import {
15
15
  palette,
16
16
  registerAdapters,
17
17
  resolve,
18
- resolveBin
19
- } from "../chunk-SIGFE5KL.js";
18
+ resolveContext
19
+ } from "../chunk-U744PK2U.js";
20
20
  import {
21
- WORKSPACE_ROOT_MARKER,
22
21
  ensureWorkspacePrep,
23
22
  findWorkspaceRoot,
24
23
  inspectWorkspacePrep,
25
- moduleName,
26
24
  readOwnVersion,
27
25
  readProjectPackageJson
28
26
  } from "../chunk-NW6UHNYX.js";
@@ -30,102 +28,15 @@ import {
30
28
  // bin/sentinel.ts
31
29
  import { program } from "commander";
32
30
 
33
- // src/core/context.ts
34
- import { existsSync } from "node:fs";
35
- import { join as join2 } from "node:path";
36
-
37
- // src/core/discover-modules.ts
38
- import { execFileSync } from "node:child_process";
39
- import { mkdtempSync, readFileSync, rmSync } from "node:fs";
40
- import { tmpdir } from "node:os";
41
- import { join } from "node:path";
42
- function runNx(cwd2, args) {
43
- const nx = resolveBin(cwd2, "nx") ?? "nx";
44
- try {
45
- return execFileSync(nx, args, {
46
- cwd: cwd2,
47
- encoding: "utf8",
48
- env: { ...process.env, NX_DAEMON: "false" }
49
- });
50
- } catch (error) {
51
- const message = error instanceof Error ? error.message : String(error);
52
- throw new Error(
53
- `sentinel: could not run nx (${message}). Is nx installed in this workspace, and are you at its root?`,
54
- { cause: error }
55
- );
56
- }
57
- }
58
- function readGraph(cwd2) {
59
- const dir = mkdtempSync(join(tmpdir(), "sentinel-nx-"));
60
- const file = join(dir, "graph.json");
61
- try {
62
- runNx(cwd2, ["graph", "--file", file]);
63
- const parsed = JSON.parse(readFileSync(file, "utf8"));
64
- const nodes = parsed.graph?.nodes;
65
- if (!nodes || typeof nodes !== "object") {
66
- throw new Error(
67
- "sentinel: unexpected nx graph output (no graph.nodes); the installed nx version may be incompatible."
68
- );
69
- }
70
- return Object.entries(nodes).map(([name, node]) => ({
71
- name,
72
- root: join(cwd2, node.data.root)
73
- }));
74
- } finally {
75
- rmSync(dir, { recursive: true, force: true });
76
- }
77
- }
78
- function discoverModules(cwd2, options = {}) {
79
- const modules = readGraph(cwd2);
80
- if (!options.affected) return modules;
81
- const affected = new Set(
82
- JSON.parse(runNx(cwd2, ["show", "projects", "--affected", "--json"]))
83
- );
84
- return modules.filter((module) => affected.has(module.name));
85
- }
86
-
87
- // src/core/context.ts
88
- var MODULE_MARKERS = ["package.json", "project.json"];
89
- function isModuleDir(cwd2) {
90
- return MODULE_MARKERS.some((marker) => existsSync(join2(cwd2, marker)));
91
- }
92
- function resolveContext(cwd2, opts2) {
93
- const atRoot = existsSync(join2(cwd2, WORKSPACE_ROOT_MARKER));
94
- if (!atRoot && isModuleDir(cwd2)) {
95
- if (opts2.module) {
96
- throw new Error(
97
- "You are in a module directory: drop --module (the context is the current module)."
98
- );
99
- }
100
- if (opts2.ci) {
101
- throw new Error("--ci selects the affected set from the workspace root; run it there.");
102
- }
103
- const name = moduleName(cwd2);
104
- return { modules: [{ name, root: cwd2 }], scope: "cwd-module" };
105
- }
106
- if (atRoot) {
107
- if (opts2.module) {
108
- const found = discoverModules(cwd2).find((module) => module.name === opts2.module);
109
- if (!found) throw new Error(`module "${opts2.module}" not found in the workspace.`);
110
- return { modules: [found], scope: "named-module" };
111
- }
112
- if (opts2.ci) return { modules: discoverModules(cwd2, { affected: true }), scope: "affected" };
113
- return { modules: discoverModules(cwd2), scope: "all" };
114
- }
115
- throw new Error(
116
- `Run sentinel from a module directory or the workspace root (found neither ${MODULE_MARKERS.join("/")} nor ${WORKSPACE_ROOT_MARKER} here).`
117
- );
118
- }
119
-
120
31
  // src/roles/build/declined.ts
121
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
122
- import { join as join3 } from "node:path";
32
+ import { existsSync, readFileSync } from "node:fs";
33
+ import { join } from "node:path";
123
34
  var DEPRECATED_NX_BUILDER = "@nx/webpack:webpack";
124
35
  function buildsWithDeprecatedExecutor(cwd2) {
125
- const projectJson = join3(cwd2, "project.json");
126
- if (!existsSync2(projectJson)) return false;
36
+ const projectJson = join(cwd2, "project.json");
37
+ if (!existsSync(projectJson)) return false;
127
38
  try {
128
- const project = JSON.parse(readFileSync2(projectJson, "utf8"));
39
+ const project = JSON.parse(readFileSync(projectJson, "utf8"));
129
40
  return project.targets?.build?.executor === DEPRECATED_NX_BUILDER;
130
41
  } catch {
131
42
  return false;