@westbayberry/dg 1.1.0 → 1.1.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.
@@ -4,7 +4,8 @@ import { homedir as homedir7, userInfo } from "node:os";
4
4
 
5
5
  // src/shims/install.ts
6
6
  import { homedir as homedir5 } from "node:os";
7
- import { join as join4 } from "node:path";
7
+ import { join as join4, dirname as dirname2 } from "node:path";
8
+ import { fileURLToPath } from "node:url";
8
9
  import { chmodSync, chownSync, existsSync as existsSync4, readdirSync, readFileSync as readFileSync3, statSync as statSync2, appendFileSync as appendFileSync2, writeFileSync as writeFileSync3 } from "node:fs";
9
10
  import { spawnSync } from "node:child_process";
10
11
  import { randomBytes } from "node:crypto";
@@ -119,9 +120,23 @@ if [ -n "\${DG_SHIM_ACTIVE:-}" ]; then
119
120
  echo "dg: real __ECOSYSTEM__ not found on PATH" >&2
120
121
  exit 127
121
122
  fi
122
- DG_SHIM_ACTIVE="$(cat "$HOME/.dg/state/shim-nonce" 2>/dev/null)" \\
123
- DG_SHIM_PARENT_PATH="$PATH" \\
124
- exec dg __wrap __ECOSYSTEM__ "$@"
123
+ nonce=$(cat "$HOME/.dg/state/shim-nonce" 2>/dev/null)
124
+ dg_entry=$(cat "$HOME/.dg/state/dg-entry" 2>/dev/null)
125
+ if [ -n "$dg_entry" ] && [ -x "$dg_entry" ]; then
126
+ DG_SHIM_ACTIVE="$nonce" DG_SHIM_PARENT_PATH="$PATH" exec "$dg_entry" __wrap __ECOSYSTEM__ "$@"
127
+ fi
128
+ cleaned_path=$(printf '%s' "$PATH" | awk -v RS=':' -v ORS=':' '$0 != ENVIRON["HOME"]"/.dg/shims"' | sed 's/:$//')
129
+ dg_bin=$(PATH="$cleaned_path" command -v dg)
130
+ if [ -n "$dg_bin" ]; then
131
+ DG_SHIM_ACTIVE="$nonce" DG_SHIM_PARENT_PATH="$PATH" exec "$dg_bin" __wrap __ECOSYSTEM__ "$@"
132
+ fi
133
+ real_bin=$(PATH="$cleaned_path" command -v __ECOSYSTEM__)
134
+ if [ -n "$real_bin" ]; then
135
+ printf '%s dg unresolved; passthrough __ECOSYSTEM__\\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null)" >> "$HOME/.dg/state/bypass.log" 2>/dev/null
136
+ exec "$real_bin" "$@"
137
+ fi
138
+ echo "dg: neither dg nor real __ECOSYSTEM__ found on PATH" >&2
139
+ exit 127
125
140
  `;
126
141
  var WINDOWS_SHIM_BODY = `@echo off
127
142
  setlocal enabledelayedexpansion
@@ -139,13 +154,41 @@ if not "%DG_SHIM_ACTIVE%"=="" (
139
154
  echo dg: real __ECOSYSTEM__ not found on PATH 1>&2
140
155
  exit /b 127
141
156
  )
142
- if exist "%USERPROFILE%\\.dg\\state\\shim-nonce" (
143
- set /p DG_SHIM_NONCE=<"%USERPROFILE%\\.dg\\state\\shim-nonce"
144
- set "DG_SHIM_ACTIVE=!DG_SHIM_NONCE!"
145
- )
157
+ set "DG_SHIM_NONCE="
158
+ if exist "%USERPROFILE%\\.dg\\state\\shim-nonce" set /p DG_SHIM_NONCE=<"%USERPROFILE%\\.dg\\state\\shim-nonce"
159
+ set "DG_ENTRY="
160
+ if exist "%USERPROFILE%\\.dg\\state\\dg-entry" set /p DG_ENTRY=<"%USERPROFILE%\\.dg\\state\\dg-entry"
161
+ set "DG_SHIM_ACTIVE=!DG_SHIM_NONCE!"
146
162
  set "DG_SHIM_PARENT_PATH=%PATH%"
147
- dg __wrap __ECOSYSTEM__ %*
148
- exit /b %errorlevel%
163
+ if defined DG_ENTRY (
164
+ if exist "!DG_ENTRY!" (
165
+ node "!DG_ENTRY!" __wrap __ECOSYSTEM__ %*
166
+ exit /b !errorlevel!
167
+ )
168
+ )
169
+ set "_dg_cli="
170
+ for /f "tokens=*" %%i in ('where dg 2^>nul') do (
171
+ echo %%i | findstr /v /c:"%USERPROFILE%\\.dg\\shims" >nul && (
172
+ if not defined _dg_cli set "_dg_cli=%%i"
173
+ )
174
+ )
175
+ if defined _dg_cli (
176
+ "!_dg_cli!" __wrap __ECOSYSTEM__ %*
177
+ exit /b !errorlevel!
178
+ )
179
+ set "_dg_realpm="
180
+ for /f "tokens=*" %%i in ('where __ECOSYSTEM__ 2^>nul') do (
181
+ echo %%i | findstr /v /c:"%USERPROFILE%\\.dg\\shims" >nul && (
182
+ if not defined _dg_realpm set "_dg_realpm=%%i"
183
+ )
184
+ )
185
+ if defined _dg_realpm (
186
+ >>"%USERPROFILE%\\.dg\\state\\bypass.log" echo dg unresolved; passthrough __ECOSYSTEM__
187
+ "!_dg_realpm!" %*
188
+ exit /b !errorlevel!
189
+ )
190
+ echo dg: neither dg nor real __ECOSYSTEM__ found on PATH 1>&2
191
+ exit /b 127
149
192
  `;
150
193
  function renderShim(opts) {
151
194
  const body = opts.platform === "windows" ? WINDOWS_SHIM_BODY : UNIX_SHIM_BODY;
@@ -310,6 +353,18 @@ function realBinaryCachePath() {
310
353
  }
311
354
 
312
355
  // src/shims/install.ts
356
+ function currentDgEntry() {
357
+ try {
358
+ const entry = join4(dirname2(fileURLToPath(import.meta.url)), "index.mjs");
359
+ if (existsSync4(entry)) return entry;
360
+ } catch {
361
+ }
362
+ try {
363
+ return walkPathExcludingShimDir("dg");
364
+ } catch {
365
+ return null;
366
+ }
367
+ }
313
368
  function chownIfNeeded(path, uid, gid) {
314
369
  if (uid === void 0 || gid === void 0) return;
315
370
  if (process.platform === "win32") return;
@@ -399,6 +454,12 @@ function installShims(opts = {}) {
399
454
  const noncePathResolved = join4(stateDir, "shim-nonce");
400
455
  safeWriteFile(noncePathResolved, nonce, 384);
401
456
  chownIfNeeded(noncePathResolved, opts.targetUid, opts.targetGid);
457
+ const dgEntry = currentDgEntry();
458
+ const dgEntryPathResolved = join4(stateDir, "dg-entry");
459
+ if (dgEntry) {
460
+ safeWriteFile(dgEntryPathResolved, dgEntry + "\n", 420);
461
+ chownIfNeeded(dgEntryPathResolved, opts.targetUid, opts.targetGid);
462
+ }
402
463
  const shimsCreated = [];
403
464
  for (const eco of ECOSYSTEMS) {
404
465
  const filename = shimFilename(eco, platform);
@@ -448,6 +509,7 @@ function installShims(opts = {}) {
448
509
  rcOutcomes,
449
510
  nonceFile: noncePathResolved,
450
511
  cacheFile: cachePathResolved,
512
+ dgEntry: dgEntry ?? null,
451
513
  nodeVersion: process.version,
452
514
  dgVersion: process.env.DG_CLI_VERSION ?? "unknown"
453
515
  };
@@ -467,7 +529,7 @@ function installShims(opts = {}) {
467
529
 
468
530
  // src/python-hook/install.ts
469
531
  import { existsSync as existsSync5, readFileSync as readFileSync4, unlinkSync as unlinkSync2, readdirSync as readdirSync2, statSync as statSync3 } from "node:fs";
470
- import { dirname as dirname2, join as join5, resolve } from "node:path";
532
+ import { dirname as dirname3, join as join5, resolve } from "node:path";
471
533
  import { spawnSync as spawnSync2 } from "node:child_process";
472
534
  import { homedir as homedir6 } from "node:os";
473
535
  var SUPPORTED_PYTHON_VERSIONS = [
@@ -482,14 +544,14 @@ var SUPPORTED_PYTHON_VERSIONS = [
482
544
  function moduleAssetDir() {
483
545
  const scriptPath = process.argv[1] ?? "";
484
546
  const candidates = [
485
- resolve(dirname2(scriptPath), "python-hook"),
486
- resolve(dirname2(scriptPath), "..", "python-hook"),
487
- resolve(dirname2(scriptPath), "src", "python-hook")
547
+ resolve(dirname3(scriptPath), "python-hook"),
548
+ resolve(dirname3(scriptPath), "..", "python-hook"),
549
+ resolve(dirname3(scriptPath), "src", "python-hook")
488
550
  ];
489
551
  for (const c of candidates) {
490
552
  if (existsSync5(join5(c, "dg_pip_hook.py"))) return c;
491
553
  }
492
- return resolve(dirname2(scriptPath));
554
+ return resolve(dirname3(scriptPath));
493
555
  }
494
556
  function probeUserSite(pythonName) {
495
557
  try {
@@ -634,8 +696,8 @@ async function main() {
634
696
  emit(" Run `dg uninstall` to remove everything.");
635
697
  } catch (err) {
636
698
  emit("\u2139\uFE0F Dependency Guardian installed.");
637
- emit(` Automatic shim wiring did not complete: ${err.message}`);
638
- emit(" Run `dg init` to retry manually.");
699
+ emit(` Setup did not complete: ${err.message}`);
700
+ emit(" Reinstall with `npm install -g @westbayberry/dg` to retry.");
639
701
  }
640
702
  }
641
703
  void main();
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@westbayberry/dg",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
+ "type": "module",
4
5
  "description": "Supply chain security scanner for npm and Python dependencies — 35 behavioral detectors catch zero-day attacks CVE databases miss. 99.66% catch rate on 155K packages.",
5
6
  "bin": {
6
7
  "dependency-guardian": "dist/index.mjs",