@hublo/sentinel 1.7.0-alpha.2 → 1.7.0-alpha.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.
@@ -0,0 +1,313 @@
1
+ import {
2
+ parseJsonc
3
+ } from "./chunk-QXFCZON7.js";
4
+
5
+ // src/shared/resolve-bin.ts
6
+ import { existsSync } from "node:fs";
7
+ import { createRequire } from "node:module";
8
+ import { delimiter, dirname, join } from "node:path";
9
+ var require2 = createRequire(import.meta.url);
10
+ function resolveBin(fromDir, name) {
11
+ let dir = fromDir;
12
+ for (; ; ) {
13
+ const candidate = join(dir, "node_modules", ".bin", name);
14
+ if (existsSync(candidate)) return candidate;
15
+ const parent = dirname(dir);
16
+ if (parent === dir) return void 0;
17
+ dir = parent;
18
+ }
19
+ }
20
+ function binFromOwnInstall(packageName, binName) {
21
+ try {
22
+ const manifest = require2.resolve(`${packageName}/package.json`);
23
+ const bin = require2(manifest).bin;
24
+ const relative = typeof bin === "string" ? bin : bin?.[binName];
25
+ if (!relative) return void 0;
26
+ const executable = join(dirname(manifest), relative);
27
+ return existsSync(executable) ? executable : void 0;
28
+ } catch {
29
+ return void 0;
30
+ }
31
+ }
32
+ function binSearchPath(cwd) {
33
+ return [`${cwd}${delimiter}node_modules/.bin (and parents)`, "sentinel's own install"].join(
34
+ " then "
35
+ );
36
+ }
37
+ function scriptPath(cwd, path) {
38
+ const bins = [];
39
+ let dir = cwd;
40
+ for (; ; ) {
41
+ bins.push(join(dir, "node_modules", ".bin"));
42
+ const parent = dirname(dir);
43
+ if (parent === dir) break;
44
+ dir = parent;
45
+ }
46
+ return [...bins, path].filter(Boolean).join(delimiter);
47
+ }
48
+
49
+ // src/roles/test/written-file-formatter.ts
50
+ import { existsSync as existsSync3 } from "node:fs";
51
+ import { dirname as dirname3, join as join4 } from "node:path";
52
+
53
+ // src/roles/format/read-adoption.ts
54
+ import { existsSync as existsSync2, readFileSync } from "node:fs";
55
+ import { join as join2 } from "node:path";
56
+
57
+ // src/roles/format/config-policy.ts
58
+ var FORMAT_CONFIG_FILE = ".oxfmtrc.json";
59
+ var FORMAT_SCRIPT_NAME = "format";
60
+ var PROVENANCE_KEY = "$sentinel";
61
+ var PERMITTED_LOCAL_KEYS = [
62
+ "useTabs",
63
+ "tabWidth",
64
+ "printWidth",
65
+ "semi",
66
+ "singleQuote",
67
+ "jsxSingleQuote",
68
+ "trailingComma",
69
+ "quoteProps",
70
+ "bracketSpacing",
71
+ "bracketSameLine",
72
+ "arrowParens",
73
+ "endOfLine",
74
+ "objectWrap",
75
+ "proseWrap",
76
+ "experimentalOperatorPosition"
77
+ ];
78
+ var ALWAYS_LOCAL_KEYS = ["ignorePatterns", "overrides"];
79
+ var OWNED_WHEN_SET_KEYS = ["sortImports"];
80
+ var FORMAT_DEFAULT_IGNORES = ["**/*.toml"];
81
+ var PRETTIER_CONFIG_FILES = [
82
+ ".prettierrc",
83
+ ".prettierrc.json",
84
+ ".prettierrc.json5",
85
+ ".prettierrc.yml",
86
+ ".prettierrc.yaml",
87
+ ".prettierrc.js",
88
+ ".prettierrc.cjs",
89
+ ".prettierrc.mjs",
90
+ "prettier.config.js",
91
+ "prettier.config.cjs",
92
+ "prettier.config.mjs"
93
+ ];
94
+ function formatTargets() {
95
+ return {
96
+ [FORMAT_SCRIPT_NAME]: {
97
+ cache: true,
98
+ inputs: ["default", `{projectRoot}/${FORMAT_CONFIG_FILE}`]
99
+ },
100
+ [`${FORMAT_SCRIPT_NAME}:fix`]: { cache: false }
101
+ };
102
+ }
103
+
104
+ // src/roles/format/presets/base.json
105
+ var base_default = {
106
+ printWidth: 80,
107
+ semi: false,
108
+ singleQuote: true,
109
+ trailingComma: "all",
110
+ sortPackageJson: false,
111
+ sortImports: false
112
+ };
113
+
114
+ // src/roles/format/presets/nest-imports.json
115
+ var nest_imports_default = {
116
+ customGroups: [
117
+ {
118
+ groupName: "workspace",
119
+ elementNamePattern: ["@hublo/**", "@shared/**", "@front/**", "@network/**"]
120
+ }
121
+ ],
122
+ groups: ["builtin", "external", "workspace", ["parent", "index"], "sibling"],
123
+ newlinesBetween: true,
124
+ order: "asc",
125
+ ignoreCase: false
126
+ };
127
+
128
+ // src/roles/format/preset-data.ts
129
+ var FORMAT_PRESETS = ["base", "svelte", "nest"];
130
+ function hasFormatPreset(name) {
131
+ return FORMAT_PRESETS.includes(name);
132
+ }
133
+ function formatPresetName(declared) {
134
+ if (declared === "svelte") return "svelte";
135
+ if (declared === "nest") return "nest";
136
+ return "base";
137
+ }
138
+ function formatPresetFor(preset) {
139
+ const base = base_default;
140
+ const name = formatPresetName(preset);
141
+ if (name === "svelte") return { ...base, svelte: true };
142
+ if (name === "nest") return { ...base, sortImports: nest_imports_default };
143
+ return base;
144
+ }
145
+
146
+ // src/roles/format/read-adoption.ts
147
+ var NOT_ADOPTED = (configFile, unreadable = null) => ({
148
+ configFile,
149
+ preset: null,
150
+ adopted: false,
151
+ conformant: false,
152
+ drift: [],
153
+ local: {},
154
+ presetVersion: null,
155
+ effective: {},
156
+ unreadable
157
+ });
158
+ function sameValue(a, b) {
159
+ return JSON.stringify(a) === JSON.stringify(b);
160
+ }
161
+ function readFormatAdoption(cwd) {
162
+ const path = join2(cwd, FORMAT_CONFIG_FILE);
163
+ if (!existsSync2(path)) return NOT_ADOPTED(null);
164
+ let parsed;
165
+ try {
166
+ parsed = parseJsonc(readFileSync(path, "utf8"), FORMAT_CONFIG_FILE);
167
+ } catch (error) {
168
+ const reason = error instanceof Error ? error.message : String(error);
169
+ return NOT_ADOPTED(FORMAT_CONFIG_FILE, `${FORMAT_CONFIG_FILE} could not be parsed (${reason})`);
170
+ }
171
+ const provenance = parsed[PROVENANCE_KEY];
172
+ if (!provenance || typeof provenance.preset !== "string") return NOT_ADOPTED(FORMAT_CONFIG_FILE);
173
+ if (!hasFormatPreset(provenance.preset)) {
174
+ return NOT_ADOPTED(
175
+ FORMAT_CONFIG_FILE,
176
+ `${FORMAT_CONFIG_FILE} declares the format preset "${provenance.preset}", which sentinel does not ship (shipped: ${FORMAT_PRESETS.join(", ")}). Re-run \`sentinel --init --format\`.`
177
+ );
178
+ }
179
+ const declaredLocal = Array.isArray(provenance.local) ? provenance.local : [];
180
+ const preset = formatPresetFor(provenance.preset);
181
+ const drift = [];
182
+ const local = {};
183
+ for (const [key, expected] of Object.entries(preset)) {
184
+ if (declaredLocal.includes(key)) {
185
+ local[key] = parsed[key];
186
+ continue;
187
+ }
188
+ if (!(key in parsed) || !sameValue(parsed[key], expected)) drift.push(key);
189
+ }
190
+ for (const key of declaredLocal) {
191
+ if (!(key in preset)) local[key] = parsed[key];
192
+ }
193
+ for (const key of ALWAYS_LOCAL_KEYS) {
194
+ if (key in parsed) local[key] = parsed[key];
195
+ }
196
+ return {
197
+ configFile: FORMAT_CONFIG_FILE,
198
+ preset: provenance.preset,
199
+ adopted: true,
200
+ conformant: drift.length === 0,
201
+ drift,
202
+ local,
203
+ presetVersion: typeof provenance.version === "string" ? provenance.version : null,
204
+ effective: parsed,
205
+ unreadable: null
206
+ };
207
+ }
208
+
209
+ // src/roles/format/resolve-oxfmt.ts
210
+ import { readFileSync as readFileSync2 } from "node:fs";
211
+ import { createRequire as createRequire2 } from "node:module";
212
+ import { dirname as dirname2, join as join3 } from "node:path";
213
+ function resolveOxfmt(cwd) {
214
+ return resolveBin(cwd, "oxfmt") ?? binFromOwnInstall("oxfmt", "oxfmt");
215
+ }
216
+ function oxfmtRejects(key, value) {
217
+ const schema = configSchema();
218
+ const property = schema?.properties?.[key];
219
+ if (!property) return false;
220
+ const definition = resolveRef(schema, property);
221
+ if (Array.isArray(definition.enum)) return !definition.enum.includes(value);
222
+ if (definition.type === "boolean") return typeof value !== "boolean";
223
+ if (definition.type === "integer" || definition.type === "number")
224
+ return typeof value !== "number";
225
+ return false;
226
+ }
227
+ function resolveRef(schema, node) {
228
+ const ref = node.$ref ?? node.allOf?.[0]?.$ref;
229
+ const name = ref?.startsWith("#/definitions/") ? ref.slice("#/definitions/".length) : void 0;
230
+ return (name ? schema.definitions?.[name] : void 0) ?? node;
231
+ }
232
+ var cachedSchema;
233
+ function configSchema() {
234
+ if (cachedSchema !== void 0) return cachedSchema ?? void 0;
235
+ cachedSchema = readConfigSchema() ?? null;
236
+ return cachedSchema ?? void 0;
237
+ }
238
+ function readConfigSchema() {
239
+ try {
240
+ const manifest = createRequire2(import.meta.url).resolve("oxfmt/package.json");
241
+ const schemaPath = join3(dirname2(manifest), "configuration_schema.json");
242
+ return JSON.parse(readFileSync2(schemaPath, "utf8"));
243
+ } catch {
244
+ return void 0;
245
+ }
246
+ }
247
+
248
+ // src/roles/test/written-file-formatter.ts
249
+ var PRETTIER_CONFIGS = [
250
+ ".prettierrc",
251
+ ".prettierrc.json",
252
+ ".prettierrc.json5",
253
+ ".prettierrc.yaml",
254
+ ".prettierrc.yml",
255
+ ".prettierrc.js",
256
+ ".prettierrc.cjs",
257
+ ".prettierrc.mjs",
258
+ ".prettierrc.toml",
259
+ "prettier.config.js",
260
+ "prettier.config.cjs",
261
+ "prettier.config.mjs"
262
+ ];
263
+ function prettierConfigFrom(cwd) {
264
+ let dir = cwd;
265
+ for (; ; ) {
266
+ for (const name of PRETTIER_CONFIGS) {
267
+ if (existsSync3(join4(dir, name))) return join4(dir, name);
268
+ }
269
+ const parent = dirname3(dir);
270
+ if (parent === dir) return void 0;
271
+ dir = parent;
272
+ }
273
+ }
274
+ function writtenFileFormatter(cwd) {
275
+ if (readFormatAdoption(cwd).configFile !== null) {
276
+ const oxfmt = resolveOxfmt(cwd);
277
+ if (oxfmt !== void 0) {
278
+ return { bin: oxfmt, args: ["--write"], origin: "this module's own oxfmt config" };
279
+ }
280
+ }
281
+ const config = prettierConfigFrom(cwd);
282
+ const prettier = resolveBin(cwd, "prettier");
283
+ if (config !== void 0 && prettier !== void 0) {
284
+ return {
285
+ bin: prettier,
286
+ args: ["--write", "--log-level", "warn"],
287
+ origin: `the workspace's Prettier`
288
+ };
289
+ }
290
+ return void 0;
291
+ }
292
+
293
+ export {
294
+ resolveBin,
295
+ binFromOwnInstall,
296
+ binSearchPath,
297
+ scriptPath,
298
+ FORMAT_CONFIG_FILE,
299
+ FORMAT_SCRIPT_NAME,
300
+ PROVENANCE_KEY,
301
+ PERMITTED_LOCAL_KEYS,
302
+ ALWAYS_LOCAL_KEYS,
303
+ OWNED_WHEN_SET_KEYS,
304
+ FORMAT_DEFAULT_IGNORES,
305
+ PRETTIER_CONFIG_FILES,
306
+ formatTargets,
307
+ formatPresetName,
308
+ formatPresetFor,
309
+ readFormatAdoption,
310
+ resolveOxfmt,
311
+ oxfmtRejects,
312
+ writtenFileFormatter
313
+ };
package/dist/index.js CHANGED
@@ -6,11 +6,12 @@ import {
6
6
  registerAdapters,
7
7
  resolve,
8
8
  setDefaultRunner
9
- } from "./chunk-EETHWJBF.js";
9
+ } from "./chunk-CTSBAGVM.js";
10
+ import "./chunk-ETVNZUU4.js";
10
11
  import {
11
12
  BaseAdapter
12
- } from "./chunk-Z3JI7ZWX.js";
13
- import "./chunk-4UUL4SEW.js";
13
+ } from "./chunk-P6KTBQ2Q.js";
14
+ import "./chunk-ZFG6P27V.js";
14
15
  import "./chunk-ZNANJEMK.js";
15
16
  import "./chunk-THTXP2QU.js";
16
17
  import "./chunk-4EIY7TTR.js";
@@ -1,105 +1,30 @@
1
+ import {
2
+ LEGACY_ENTRY,
3
+ appliedOptions,
4
+ diffConfigs,
5
+ extendsList,
6
+ isBaseEntry,
7
+ isStackPresetEntry,
8
+ remainder
9
+ } from "./chunk-ETVNZUU4.js";
1
10
  import {
2
11
  binFromOwnInstall,
3
- resolveBin
4
- } from "./chunk-4UUL4SEW.js";
12
+ resolveBin,
13
+ writtenFileFormatter
14
+ } from "./chunk-ZFG6P27V.js";
5
15
  import {
6
16
  parseJsonc
7
17
  } from "./chunk-QXFCZON7.js";
8
18
 
9
19
  // src/roles/typescript/migrate/migrate.ts
10
- import { execFileSync } from "node:child_process";
20
+ import { execFileSync, spawnSync } from "node:child_process";
11
21
  import { existsSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
12
22
  import { createRequire } from "node:module";
13
23
  import { dirname as dirname2, join, relative as relative2, resolve as resolve2 } from "node:path";
14
24
  import { stripComments } from "jsonc-parser";
15
25
 
16
- // src/roles/typescript/migrate/compare.ts
17
- var STRICT_FAMILY = [
18
- "alwaysStrict",
19
- "noImplicitAny",
20
- "noImplicitThis",
21
- "strictBindCallApply",
22
- "strictBuiltinIteratorReturn",
23
- "strictFunctionTypes",
24
- "strictNullChecks",
25
- "strictPropertyInitialization",
26
- "useUnknownInCatchVariables"
27
- ];
28
- var CASE_INSENSITIVE = /* @__PURE__ */ new Set([
29
- "jsx",
30
- "lib",
31
- "module",
32
- "moduleDetection",
33
- "moduleResolution",
34
- "target"
35
- ]);
36
- function targetYear(target) {
37
- const name = typeof target === "string" ? target.toLowerCase() : "es5";
38
- if (name === "esnext") return Number.MAX_SAFE_INTEGER;
39
- const year = Number(name.replace(/^es/, ""));
40
- return Number.isFinite(year) ? year : 5;
41
- }
42
- function comparable(key, value) {
43
- const json = JSON.stringify(value) ?? "undefined";
44
- return CASE_INSENSITIVE.has(key) ? json.toLowerCase() : json;
45
- }
46
- function appliedOptions(config) {
47
- const options = new Map(Object.entries(config.compilerOptions ?? {}));
48
- options.delete("paths");
49
- const derive = (key, value) => {
50
- if (!options.has(key)) options.set(key, value);
51
- };
52
- if (options.get("strict") === true) for (const key of STRICT_FAMILY) derive(key, true);
53
- derive("allowJs", false);
54
- if (options.get("esModuleInterop") === true) derive("allowSyntheticDefaultImports", true);
55
- if (options.get("verbatimModuleSyntax") === true) derive("isolatedModules", true);
56
- if (options.get("isolatedModules") === true) derive("preserveConstEnums", true);
57
- derive("useDefineForClassFields", targetYear(options.get("target")) >= 2022);
58
- return new Map([...options].map(([key, value]) => [key, comparable(key, value)]));
59
- }
60
- function diffConfigs(before, after) {
61
- const was = appliedOptions(before);
62
- const now = appliedOptions(after);
63
- const differences = [];
64
- for (const key of /* @__PURE__ */ new Set([...was.keys(), ...now.keys()])) {
65
- if (was.get(key) !== now.get(key)) {
66
- differences.push({ key: `compilerOptions.${key}`, before: was.get(key), after: now.get(key) });
67
- }
68
- }
69
- for (const key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
70
- if (key === "compilerOptions") continue;
71
- const left = JSON.stringify(before[key]);
72
- const right = JSON.stringify(after[key]);
73
- if (left !== right) differences.push({ key, before: left, after: right });
74
- }
75
- return differences;
76
- }
77
- function remainder(effective, layers, ownKeys) {
78
- const applied = appliedOptions(effective);
79
- const given = appliedOptions(layers);
80
- const written = [];
81
- for (const [key, value] of applied) {
82
- if (ownKeys.has(key) || given.get(key) === value) continue;
83
- written.push({ key, value: effective.compilerOptions?.[key] ?? JSON.parse(value) });
84
- }
85
- return written;
86
- }
87
-
88
26
  // src/roles/typescript/migrate/detach.ts
89
27
  import { dirname, posix, relative, resolve, sep } from "node:path";
90
- var BASE_FILE = "tsconfig.base.json";
91
- var LEGACY_ENTRY = "@hublo/sentinel/typescript/legacy";
92
- function isBaseEntry(entry) {
93
- return entry === BASE_FILE || entry.endsWith(`/${BASE_FILE}`);
94
- }
95
- function isStackPresetEntry(entry) {
96
- return /^@hublo\/sentinel\/(?:typescript|tsconfig)\/(?!legacy$)[a-z-]+$/.test(entry);
97
- }
98
- function extendsList(config) {
99
- const value = config.extends;
100
- if (typeof value === "string") return [value];
101
- return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
102
- }
103
28
  function rebaseTarget(target, pathsRoot, directory) {
104
29
  const moved = relative(directory, resolve(pathsRoot, target)).split(sep).join(posix.sep);
105
30
  const kept = target.endsWith("/") && !moved.endsWith("/") ? `${moved}/` : moved;
@@ -415,6 +340,31 @@ function restoreInterrupted(moduleRoot, tracked, notes, workspaceRoot) {
415
340
  }
416
341
  }
417
342
  }
343
+ function formatWritten(moduleRoot, files, notes, options) {
344
+ const proved = files.filter(
345
+ (one) => options.write ? one.kept : one.configDifferences?.length === 0 && one.resolutionDifferences?.length === 0
346
+ );
347
+ if (proved.length === 0) return;
348
+ const formatter = writtenFileFormatter(moduleRoot);
349
+ if (formatter === void 0) {
350
+ notes.push(
351
+ "no style is declared by this module or its workspace: run your formatter over the rewritten tsconfig before committing"
352
+ );
353
+ return;
354
+ }
355
+ if (!options.write) {
356
+ notes.push(`the rewritten tsconfig would be formatted with ${formatter.origin}`);
357
+ return;
358
+ }
359
+ const written = proved.map((one) => resolve2(options.workspaceRoot, one.file));
360
+ const pass = spawnSync(formatter.bin, [...formatter.args, ...written], {
361
+ cwd: moduleRoot,
362
+ encoding: "utf8"
363
+ });
364
+ notes.push(
365
+ pass.status === 0 ? `formatted the rewritten tsconfig with ${formatter.origin}` : `${formatter.origin} could not run over the rewritten tsconfig: run it before committing`
366
+ );
367
+ }
418
368
  function isOwnModule(folder) {
419
369
  return existsSync(join(folder, "package.json")) || existsSync(join(folder, "project.json"));
420
370
  }
@@ -481,6 +431,7 @@ function migrateModule(moduleRoot, options) {
481
431
  files.push(migrateTsconfig(folder, target, names, options));
482
432
  }
483
433
  }
434
+ formatWritten(moduleRoot, files, notes, options);
484
435
  const refused = files.filter((one) => !one.kept);
485
436
  const notAdopted = files.every((one) => one.reason?.includes("no sentinel preset") === true);
486
437
  if (notAdopted) {
@@ -7,8 +7,8 @@ import {
7
7
  readTestAdoption,
8
8
  resolveVitest,
9
9
  suiteOf
10
- } from "./chunk-Z3JI7ZWX.js";
11
- import "./chunk-4UUL4SEW.js";
10
+ } from "./chunk-P6KTBQ2Q.js";
11
+ import "./chunk-ZFG6P27V.js";
12
12
  import "./chunk-ZNANJEMK.js";
13
13
  import "./chunk-O7REVMOC.js";
14
14
  import "./chunk-H4HAFJFZ.js";
@@ -78,13 +78,24 @@ It keeps nothing unless tsc agrees, and restores the file otherwise:
78
78
  not printed: the base printed `alwaysStrict`, `allowJs: false` and `isolatedModules`, and the
79
79
  presets leave them to `strict`, the default and `verbatimModuleSyntax`. Same compilation,
80
80
  different output, so the comparison derives those options the way tsc does
81
- (`src/roles/typescript/migrate/compare.ts`);
81
+ (`src/roles/typescript/compare.ts`);
82
82
  - every module and type reference tsc resolves, file by file, lands on the same file.
83
83
 
84
+ A kept tsconfig is then formatted with the style the module states (its `.oxfmtrc.json`, else
85
+ the workspace's Prettier), the same rule `--init --test` follows: whitespace only, after tsc agreed.
86
+
84
87
  It refuses, and writes nothing, for a module not adopted yet (run `--init --typescript` first), a
85
88
  tsconfig with comments, and a module whose installed sentinel has no `legacy`. A nested folder
86
89
  that is a module of its own is named and left to its own run.
87
90
 
91
+ Once migrated, `--inspect` lists the compromises the module takes from `legacy` under
92
+ `inherited compromises (debt to remove)`: the options the stack preset does not set and the module
93
+ does not set itself, the ones that apply, each against the value the standard would apply
94
+ (`noImplicitAny — false, where the standard says true, inherited from …/legacy`). `--json` carries
95
+ the same lists as data: `standardOverrides` and `legacyCompromises`, each item with `rule`,
96
+ `value` and `standard`. The debt left the base, and stays
97
+ visible module by module until the module removes the `legacy` line.
98
+
88
99
  What it does not prove is tsc's view only: the Nx project graph still reads the root base's
89
100
  `paths`, and esbuild and Vite resolve each file through its nearest tsconfig. The base stays
90
101
  until every module is detached, and the module's own build, test and lint are its proof.
@@ -222,3 +233,12 @@ it would hand it to the workspace tsconfig this module extends
222
233
  ```
223
234
 
224
235
  It is not reported as drift by `--inspect` either, so a module that legitimately overrides the base does not read as non-conformant forever.
236
+
237
+ Not drift, but not hidden either: `--inspect` lists it under `differs from the repo standard`,
238
+ with both values. An option a preset took over from the base (`fromBase`) and that the module
239
+ sets to another value is this module departing from the standard, and that is worth seeing:
240
+
241
+ ```
242
+ differs from the repo standard (kept by --init, not drift):
243
+ • verbatimModuleSyntax — false, where the nest preset says true
244
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hublo/sentinel",
3
- "version": "1.7.0-alpha.2",
3
+ "version": "1.7.0-alpha.4",
4
4
  "description": "One CLI that guards code health across Hublo repos: shared lint/typescript/build/test presets, static & dynamic analysis, and architecture checks.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,50 +0,0 @@
1
- // src/shared/resolve-bin.ts
2
- import { existsSync } from "node:fs";
3
- import { createRequire } from "node:module";
4
- import { delimiter, dirname, join } from "node:path";
5
- var require2 = createRequire(import.meta.url);
6
- function resolveBin(fromDir, name) {
7
- let dir = fromDir;
8
- for (; ; ) {
9
- const candidate = join(dir, "node_modules", ".bin", name);
10
- if (existsSync(candidate)) return candidate;
11
- const parent = dirname(dir);
12
- if (parent === dir) return void 0;
13
- dir = parent;
14
- }
15
- }
16
- function binFromOwnInstall(packageName, binName) {
17
- try {
18
- const manifest = require2.resolve(`${packageName}/package.json`);
19
- const bin = require2(manifest).bin;
20
- const relative = typeof bin === "string" ? bin : bin?.[binName];
21
- if (!relative) return void 0;
22
- const executable = join(dirname(manifest), relative);
23
- return existsSync(executable) ? executable : void 0;
24
- } catch {
25
- return void 0;
26
- }
27
- }
28
- function binSearchPath(cwd) {
29
- return [`${cwd}${delimiter}node_modules/.bin (and parents)`, "sentinel's own install"].join(
30
- " then "
31
- );
32
- }
33
- function scriptPath(cwd, path) {
34
- const bins = [];
35
- let dir = cwd;
36
- for (; ; ) {
37
- bins.push(join(dir, "node_modules", ".bin"));
38
- const parent = dirname(dir);
39
- if (parent === dir) break;
40
- dir = parent;
41
- }
42
- return [...bins, path].filter(Boolean).join(delimiter);
43
- }
44
-
45
- export {
46
- resolveBin,
47
- binFromOwnInstall,
48
- binSearchPath,
49
- scriptPath
50
- };