@spotlightjs/spotlight 3.0.2 → 4.0.0

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/bin/run.js CHANGED
@@ -5,7 +5,7 @@ import { join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { inflateRawSync } from "node:zlib";
7
7
  import { setContext, startSpan } from "@sentry/node";
8
- import { setupSidecar } from "@spotlightjs/sidecar";
8
+ import { parseCLIArgs, setupSidecar } from "@spotlightjs/sidecar";
9
9
  import "./instrument.js";
10
10
  const require = Module.createRequire(import.meta.url);
11
11
  let sea = null;
@@ -21,40 +21,47 @@ const homeDir = process.env.HOME || process.env.USERPROFILE;
21
21
  setContext("CLI", {
22
22
  sea: sea.isSea(),
23
23
  // TODO: Be less naive with path obscuring
24
- argv: process.argv.map(arg => arg.replace(homeDir, "~")),
24
+ argv: process.argv.map((arg) => arg.replace(homeDir, "~")),
25
25
  });
26
26
 
27
27
  const withTracing =
28
28
  (fn, spanArgs = {}) =>
29
29
  (...args) =>
30
- startSpan({ name: fn.name, attributes: { args }, ...spanArgs }, () => fn(...args));
30
+ startSpan({ name: fn.name, attributes: { args }, ...spanArgs }, () =>
31
+ fn(...args)
32
+ );
31
33
 
32
34
  const readAsset = withTracing(
33
35
  sea.isSea()
34
- ? name => Buffer.from(sea.getRawAsset(name))
36
+ ? (name) => Buffer.from(sea.getRawAsset(name))
35
37
  : (() => {
36
- const ASSET_DIR = join(fileURLToPath(import.meta.url), "../../dist/overlay/");
38
+ const ASSET_DIR = join(
39
+ fileURLToPath(import.meta.url),
40
+ "../../dist/overlay/"
41
+ );
37
42
 
38
- return name => readFileSync(join(ASSET_DIR, name));
43
+ return (name) => readFileSync(join(ASSET_DIR, name));
39
44
  })(),
40
- { name: "readAsset", op: "cli.asset.read" },
45
+ { name: "readAsset", op: "cli.asset.read" }
41
46
  );
42
47
 
43
- startSpan({ name: "Spotlight CLI", op: "cli" }, () => {
48
+ startSpan({ name: "Spotlight CLI", op: "cli" }, async () => {
44
49
  startSpan({ name: "ASCII Art", op: "cli.art.ascii" }, () => {
45
- const MAX_COLS = process.stdout.columns;
46
- if (!process.stdout.isTTY || MAX_COLS < 35) return;
47
- let stdoutBuffer = "";
50
+ const MAX_COLS = process.stderr.columns;
51
+ if (!process.stderr.isTTY || MAX_COLS < 35) return;
52
+ let stderrBuffer = "";
48
53
 
49
- const data = startSpan({ name: "Inflate ASCII Art Data", op: "cli.art.ascii.inflate" }, () =>
50
- Uint8Array.from(
51
- inflateRawSync(
52
- Buffer.from(
53
- "bY7LCgMxFEK9L5MwDDSL9P//1DJMKGXowoUcUaFZOk8dU2Op9+qZVkYQoFsaEqA6PZxxma1AoMG+TiONTgcfAd741YxxVf8gCzCgWcYB7OSj9sjW7t2/eKxKAxkIYv8NqL3FpVY25CmjrBSuDw==",
54
- "base64",
55
- ),
56
- ),
57
- ),
54
+ const data = startSpan(
55
+ { name: "Inflate ASCII Art Data", op: "cli.art.ascii.inflate" },
56
+ () =>
57
+ Uint8Array.from(
58
+ inflateRawSync(
59
+ Buffer.from(
60
+ "bY7LCgMxFEK9L5MwDDSL9P//1DJMKGXowoUcUaFZOk8dU2Op9+qZVkYQoFsaEqA6PZxxma1AoMG+TiONTgcfAd741YxxVf8gCzCgWcYB7OSj9sjW7t2/eKxKAxkIYv8NqL3FpVY25CmjrBSuDw==",
61
+ "base64"
62
+ )
63
+ )
64
+ )
58
65
  );
59
66
  const E = "\x1b[";
60
67
  const C = `${E}38;5;`;
@@ -71,7 +78,7 @@ startSpan({ name: "Spotlight CLI", op: "cli" }, () => {
71
78
  let r = 0;
72
79
  for (let p of data) {
73
80
  if (p === 255) {
74
- stdoutBuffer += NL;
81
+ stderrBuffer += NL;
75
82
  c = col = 0;
76
83
  if (line++ === 5) {
77
84
  factor = factor / -3;
@@ -81,39 +88,67 @@ startSpan({ name: "Spotlight CLI", op: "cli" }, () => {
81
88
  } else {
82
89
  while (p-- >= 0 && col < MAX_COLS) {
83
90
  if (col < lim - 1) {
84
- stdoutBuffer += M_COL;
91
+ stderrBuffer += M_COL;
85
92
  } else if (col === lim - 1) {
86
- stdoutBuffer += F_COL;
93
+ stderrBuffer += F_COL;
87
94
  } else if (col === lim + r) {
88
- stdoutBuffer += `${RESET}${BOLD}`;
95
+ stderrBuffer += `${RESET}${BOLD}`;
89
96
  }
90
- stdoutBuffer += c ? (col >= 35 ? "#" : "s") : " ";
97
+ stderrBuffer += c ? (col >= 35 ? "#" : "s") : " ";
91
98
  col++;
92
99
  }
93
100
  c = !c;
94
101
  }
95
102
  }
96
- stdoutBuffer += NL;
97
- process.stdout.write(stdoutBuffer);
103
+ stderrBuffer += NL;
104
+ process.stderr.write(stderrBuffer);
98
105
  });
99
106
 
100
- startSpan({ name: "Setup Sidecar", op: "cli.setup.sidecar" }, () => {
101
- const port = process.argv.length >= 3 ? Number(process.argv[2]) : undefined;
102
- const MANIFEST_NAME = "manifest.json";
103
- const ENTRY_POINT_NAME = "src/index.html";
104
- const basePath = process.cwd();
105
- const filesToServe = Object.create(null);
107
+ await startSpan(
108
+ { name: "Setup Sidecar", op: "cli.setup.sidecar" },
109
+ async () => {
110
+ const args = parseCLIArgs();
111
+ if (args.help) {
112
+ console.log(`
113
+ Usage: spotlight [options]
114
+
115
+ Options:
116
+ -p, --port <port> Port to listen on (default: 8969)
117
+ --stdio-mcp Enable MCP stdio transport
118
+ -d, --debug Enable debug logging
119
+ -h, --help Show this help message
106
120
 
107
- startSpan({ name: "Setup Server Assets", op: "cli.setup.sidecar.assets" }, () => {
108
- // Following the guide here: https://vite.dev/guide/backend-integration.html
109
- const manifest = JSON.parse(readAsset(MANIFEST_NAME));
110
- filesToServe[ENTRY_POINT_NAME] = readAsset(ENTRY_POINT_NAME);
111
- const entries = Object.values(manifest);
112
- for (const entry of entries) {
113
- filesToServe[entry.file] = readAsset(entry.file);
121
+ Examples:
122
+ spotlight # Start on default port 8969
123
+ spotlight --port 3000 # Start on port 3000
124
+ spotlight -p 3000 -d # Start on port 3000 with debug logging
125
+ `);
126
+ process.exit(0);
114
127
  }
115
- });
128
+ const MANIFEST_NAME = "manifest.json";
129
+ const ENTRY_POINT_NAME = "src/index.html";
130
+ const basePath = process.cwd();
131
+ const filesToServe = Object.create(null);
116
132
 
117
- setupSidecar({ port, basePath, filesToServe, isStandalone: true });
118
- });
133
+ startSpan(
134
+ { name: "Setup Server Assets", op: "cli.setup.sidecar.assets" },
135
+ () => {
136
+ // Following the guide here: https://vite.dev/guide/backend-integration.html
137
+ const manifest = JSON.parse(readAsset(MANIFEST_NAME));
138
+ filesToServe[ENTRY_POINT_NAME] = readAsset(ENTRY_POINT_NAME);
139
+ const entries = Object.values(manifest);
140
+ for (const entry of entries) {
141
+ filesToServe[entry.file] = readAsset(entry.file);
142
+ }
143
+ }
144
+ );
145
+
146
+ await setupSidecar({
147
+ ...args,
148
+ basePath,
149
+ filesToServe,
150
+ isStandalone: true,
151
+ });
152
+ }
153
+ );
119
154
  });