@mizchi/vlmkit-capture 0.7.0 → 0.8.1

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.
Files changed (39) hide show
  1. package/dist/batch-prescan.d.mts +51 -0
  2. package/dist/batch-prescan.mjs +66 -0
  3. package/dist/capture-config.d.mts +50 -0
  4. package/dist/capture-config.mjs +164 -0
  5. package/dist/capturer.d.mts +45 -0
  6. package/dist/capturer.mjs +94 -0
  7. package/dist/cloudflare-quick-actions.d.mts +114 -0
  8. package/dist/cloudflare-quick-actions.mjs +142 -0
  9. package/dist/crater-client.d.mts +159 -0
  10. package/dist/crater-client.mjs +362 -0
  11. package/dist/crater-smoke.d.mts +98 -0
  12. package/dist/crater-smoke.mjs +269 -0
  13. package/dist/crater-wasm.d.mts +65 -0
  14. package/dist/crater-wasm.mjs +132 -0
  15. package/{src/detection-types.ts → dist/detection-types.d.mts} +4 -2
  16. package/dist/detection-types.mjs +1 -0
  17. package/dist/index.d.mts +12 -0
  18. package/dist/index.mjs +11 -0
  19. package/dist/playwright-analyzer.d.mts +38 -0
  20. package/dist/playwright-analyzer.mjs +117 -0
  21. package/dist/playwright-launch-error.d.mts +7 -0
  22. package/dist/playwright-launch-error.mjs +25 -0
  23. package/dist/prescanner.d.mts +39 -0
  24. package/dist/prescanner.mjs +61 -0
  25. package/dist/viewport-discovery.d.mts +114 -0
  26. package/dist/viewport-discovery.mjs +294 -0
  27. package/package.json +18 -6
  28. package/src/batch-prescan.ts +0 -115
  29. package/src/capture-config.ts +0 -219
  30. package/src/capturer.ts +0 -138
  31. package/src/cloudflare-quick-actions.ts +0 -304
  32. package/src/crater-client.ts +0 -537
  33. package/src/crater-smoke.ts +0 -336
  34. package/src/crater-wasm.ts +0 -260
  35. package/src/index.ts +0 -157
  36. package/src/playwright-analyzer.ts +0 -180
  37. package/src/playwright-launch-error.ts +0 -41
  38. package/src/prescanner.ts +0 -123
  39. package/src/viewport-discovery.ts +0 -455
@@ -1,336 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Crater BiDi smoke check.
4
- *
5
- * Verifies the minimum backend contract used by vlmkit:
6
- * connection, viewport/content load, PNG capture, paint tree capture,
7
- * computed-style capture, and responsive breakpoint discovery.
8
- */
9
- import { fileURLToPath } from "node:url";
10
- import { resolve } from "node:path";
11
- import { handleCliError } from "@mizchi/vlmkit-core/cli-error.ts";
12
- import { BOLD, CYAN, DIM, GREEN, RED, RESET, YELLOW } from "@mizchi/vlmkit-core/terminal-colors.ts";
13
- import {
14
- CraterClient,
15
- DEFAULT_BIDI_URL,
16
- isCraterAvailable,
17
- resolveCraterBidiUrl,
18
- } from "./crater-client.ts";
19
-
20
- export interface CraterSmokeClient {
21
- connect(): Promise<void>;
22
- close(): Promise<void>;
23
- setViewport(width: number, height: number): Promise<void>;
24
- setContent(html: string): Promise<void>;
25
- capturePng(): Promise<{ png: Buffer; width: number; height: number }>;
26
- capturePaintTree(): Promise<unknown>;
27
- captureComputedStyles?(properties: string[]): Promise<Map<string, Record<string, string>>>;
28
- getResponsiveBreakpoints?(options?: {
29
- mode?: "live-inline" | "html-inline";
30
- axis?: "width";
31
- includeDiagnostics?: boolean;
32
- }): Promise<{ breakpoints: unknown[] }>;
33
- getRequiredTestViewports?(): Promise<{ viewports: Array<{ width: number; reason: string }> }>;
34
- getCssRuleViewportMap?(viewportWidths?: number[]): Promise<{ rules: unknown[] }>;
35
- getComputedStylesWithState?(
36
- selector: string,
37
- forcedStates: string[],
38
- properties: string[],
39
- ): Promise<{ normal: Record<string, string>; forced: Record<string, string>; diff: Array<{ property: string; normal: string; forced: string }> }>;
40
- batchRender?(
41
- baseHtml: string,
42
- viewport: { width: number; height: number },
43
- variants: Array<{ id: string; mutations: Array<{ selector: string; property: string; action?: "remove" | { override: string } }> }>,
44
- ): Promise<{ results: Array<{ id: string; paintTree?: unknown }> }>;
45
- }
46
-
47
- export type CraterSmokeStatus = "pass" | "skip" | "fail";
48
-
49
- export interface CraterSmokeCheck {
50
- name: string;
51
- status: CraterSmokeStatus;
52
- elapsedMs: number;
53
- message: string;
54
- }
55
-
56
- export interface CraterSmokeReport {
57
- status: CraterSmokeStatus;
58
- url: string;
59
- checks: CraterSmokeCheck[];
60
- elapsedMs: number;
61
- }
62
-
63
- export interface CraterSmokeOptions {
64
- url?: string;
65
- html?: string;
66
- viewport?: { width: number; height: number };
67
- requireAvailable?: boolean;
68
- /**
69
- * When true, also exercises rendering-heavy v0.18.0 APIs (batchRender).
70
- * Metadata-only v0.18.0 checks (`getRequiredTestViewports`,
71
- * `getCssRuleViewportMap`, `getComputedStylesWithState`) always run when the
72
- * client exposes them — they are cheap RPC round-trips.
73
- */
74
- deep?: boolean;
75
- isAvailable?: (url: string) => Promise<boolean>;
76
- createClient?: (url: string) => CraterSmokeClient;
77
- }
78
-
79
- const DEFAULT_HTML = `<!doctype html>
80
- <html>
81
- <head>
82
- <style>
83
- body { margin: 0; font-family: system-ui; }
84
- main { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 24px; }
85
- button { padding: 10px 14px; border-radius: 8px; background: #2563eb; color: white; border: 0; }
86
- button:hover { background: #1d4ed8; text-decoration: underline; }
87
- @media (min-width: 700px) { main { max-width: 680px; } }
88
- </style>
89
- </head>
90
- <body>
91
- <main><h1>Crater smoke</h1><button>OK</button></main>
92
- </body>
93
- </html>`;
94
-
95
- function now(): number {
96
- return Date.now();
97
- }
98
-
99
- function makeCheck(
100
- name: string,
101
- status: CraterSmokeStatus,
102
- start: number,
103
- message: string,
104
- ): CraterSmokeCheck {
105
- return { name, status, elapsedMs: now() - start, message };
106
- }
107
-
108
- function reportStatus(checks: CraterSmokeCheck[]): CraterSmokeStatus {
109
- if (checks.some((check) => check.status === "fail")) return "fail";
110
- if (checks.some((check) => check.status === "skip")) return "skip";
111
- return "pass";
112
- }
113
-
114
- function assertPaintTree(tree: unknown): void {
115
- if (!tree || typeof tree !== "object") {
116
- throw new Error("paint tree is empty");
117
- }
118
- }
119
-
120
- export async function runCraterBidiSmoke(
121
- options: CraterSmokeOptions = {},
122
- ): Promise<CraterSmokeReport> {
123
- const url = options.url ?? DEFAULT_BIDI_URL;
124
- const requireAvailable = options.requireAvailable ?? false;
125
- const start = now();
126
- const checks: CraterSmokeCheck[] = [];
127
- const available = await (options.isAvailable ?? isCraterAvailable)(url);
128
- if (!available) {
129
- checks.push(makeCheck(
130
- "availability",
131
- requireAvailable ? "fail" : "skip",
132
- start,
133
- `Crater BiDi is not available at ${url}`,
134
- ));
135
- return { status: reportStatus(checks), url, checks, elapsedMs: now() - start };
136
- }
137
-
138
- const client = (options.createClient ?? ((u: string) => new CraterClient(u)))(url);
139
- let connected = false;
140
- async function runCheck(name: string, fn: () => Promise<string>): Promise<boolean> {
141
- const checkStart = now();
142
- try {
143
- const message = await fn();
144
- checks.push(makeCheck(name, "pass", checkStart, message));
145
- return true;
146
- } catch (error) {
147
- checks.push(makeCheck(name, "fail", checkStart, String(error)));
148
- return false;
149
- }
150
- }
151
-
152
- try {
153
- connected = await runCheck("connect", async () => {
154
- await client.connect();
155
- return "connected";
156
- });
157
- if (!connected) return { status: "fail", url, checks, elapsedMs: now() - start };
158
-
159
- const viewport = options.viewport ?? { width: 800, height: 480 };
160
- if (!await runCheck("load", async () => {
161
- await client.setViewport(viewport.width, viewport.height);
162
- await client.setContent(options.html ?? DEFAULT_HTML);
163
- return `loaded ${viewport.width}x${viewport.height}`;
164
- })) {
165
- return { status: "fail", url, checks, elapsedMs: now() - start };
166
- }
167
-
168
- if (!await runCheck("capture-png", async () => {
169
- const result = await client.capturePng();
170
- if (result.width <= 0 || result.height <= 0 || result.png.length === 0) {
171
- throw new Error("PNG capture returned empty data");
172
- }
173
- return `captured ${result.width}x${result.height}, ${result.png.length} bytes`;
174
- })) {
175
- return { status: "fail", url, checks, elapsedMs: now() - start };
176
- }
177
-
178
- if (!await runCheck("paint-tree", async () => {
179
- assertPaintTree(await client.capturePaintTree());
180
- return "paint tree captured";
181
- })) {
182
- return { status: "fail", url, checks, elapsedMs: now() - start };
183
- }
184
-
185
- if (client.captureComputedStyles) {
186
- if (!await runCheck("computed-styles", async () => {
187
- const styles = await client.captureComputedStyles!(["display", "color", "background-color"]);
188
- return `computed styles captured (${styles.size} selector(s))`;
189
- })) {
190
- return { status: "fail", url, checks, elapsedMs: now() - start };
191
- }
192
- }
193
-
194
- if (client.getResponsiveBreakpoints) {
195
- if (!await runCheck("responsive-breakpoints", async () => {
196
- const result = await client.getResponsiveBreakpoints!({
197
- mode: "live-inline",
198
- axis: "width",
199
- includeDiagnostics: true,
200
- });
201
- return `breakpoint API returned ${result.breakpoints.length} breakpoint(s)`;
202
- })) {
203
- return { status: "fail", url, checks, elapsedMs: now() - start };
204
- }
205
- }
206
-
207
- if (client.getRequiredTestViewports) {
208
- if (!await runCheck("required-test-viewports", async () => {
209
- const result = await client.getRequiredTestViewports!();
210
- return `viewport intelligence returned ${result.viewports.length} viewport(s)`;
211
- })) {
212
- return { status: "fail", url, checks, elapsedMs: now() - start };
213
- }
214
- }
215
-
216
- if (client.getCssRuleViewportMap) {
217
- if (!await runCheck("css-rule-viewport-map", async () => {
218
- const result = await client.getCssRuleViewportMap!();
219
- return `rule/viewport map returned ${result.rules.length} rule(s)`;
220
- })) {
221
- return { status: "fail", url, checks, elapsedMs: now() - start };
222
- }
223
- }
224
-
225
- if (client.getComputedStylesWithState) {
226
- if (!await runCheck("computed-styles-with-state", async () => {
227
- const result = await client.getComputedStylesWithState!(
228
- "button",
229
- ["hover"],
230
- ["background-color", "text-decoration"],
231
- );
232
- const diffCount = result.diff?.length ?? 0;
233
- return `forced-state API returned ${diffCount} diff(s)`;
234
- })) {
235
- return { status: "fail", url, checks, elapsedMs: now() - start };
236
- }
237
- }
238
-
239
- if (options.deep && client.batchRender) {
240
- if (!await runCheck("batch-render", async () => {
241
- const result = await client.batchRender!(
242
- options.html ?? DEFAULT_HTML,
243
- options.viewport ?? viewport,
244
- [{
245
- id: "no-op",
246
- mutations: [{ selector: "button", property: "color", action: { override: "white" } }],
247
- }],
248
- );
249
- return `batch render returned ${result.results.length} variant(s)`;
250
- })) {
251
- return { status: "fail", url, checks, elapsedMs: now() - start };
252
- }
253
- }
254
- } finally {
255
- if (connected) {
256
- const closeStart = now();
257
- try {
258
- await client.close();
259
- checks.push(makeCheck("close", "pass", closeStart, "closed"));
260
- } catch (error) {
261
- checks.push(makeCheck("close", "fail", closeStart, String(error)));
262
- }
263
- }
264
- }
265
-
266
- return { status: reportStatus(checks), url, checks, elapsedMs: now() - start };
267
- }
268
-
269
- export function formatCraterSmokeReport(report: CraterSmokeReport): string {
270
- const lines: string[] = [];
271
- const color = report.status === "pass" ? GREEN : report.status === "skip" ? YELLOW : RED;
272
- lines.push(`${BOLD}${CYAN}vlmkit check crater${RESET}`);
273
- lines.push(`${DIM}url: ${report.url}${RESET}`);
274
- lines.push("");
275
- lines.push(`status: ${color}${report.status}${RESET}`);
276
- for (const check of report.checks) {
277
- const icon = check.status === "pass" ? `${GREEN}PASS${RESET}`
278
- : check.status === "skip" ? `${YELLOW}SKIP${RESET}`
279
- : `${RED}FAIL${RESET}`;
280
- lines.push(` ${icon} ${check.name.padEnd(22)} ${String(check.elapsedMs).padStart(5)}ms ${DIM}${check.message}${RESET}`);
281
- }
282
- lines.push(`${DIM}elapsed: ${report.elapsedMs}ms${RESET}`);
283
- return lines.join("\n");
284
- }
285
-
286
- function printUsage(exitCode: number): never {
287
- console.log("Usage: vlmkit check crater [options]");
288
- console.log("Options:");
289
- console.log(" --url <ws-url> Crater BiDi URL (default: ws://127.0.0.1:9222)");
290
- console.log(" --require Fail if Crater is unavailable");
291
- console.log(" --deep Exercise heavier v0.18.0 APIs (batchRender)");
292
- console.log(" --json Print JSON report");
293
- process.exit(exitCode);
294
- }
295
-
296
- export function parseCraterSmokeArgs(
297
- argv: string[],
298
- env: NodeJS.ProcessEnv | Partial<NodeJS.ProcessEnv> = process.env,
299
- ) {
300
- let url = resolveCraterBidiUrl({ env });
301
- let requireAvailable = false;
302
- let deep = false;
303
- let json = false;
304
- for (let i = 0; i < argv.length; i++) {
305
- const arg = argv[i];
306
- if (arg === "--help" || arg === "-h" || arg === "help") printUsage(0);
307
- else if (arg === "--url") url = argv[++i] ?? DEFAULT_BIDI_URL;
308
- else if (arg === "--require") requireAvailable = true;
309
- else if (arg === "--deep") deep = true;
310
- else if (arg === "--json") json = true;
311
- }
312
- return { url, requireAvailable, deep, json };
313
- }
314
-
315
- async function main(argv = process.argv.slice(2)): Promise<void> {
316
- const args = parseCraterSmokeArgs(argv);
317
- const report = await runCraterBidiSmoke({
318
- url: args.url,
319
- requireAvailable: args.requireAvailable,
320
- deep: args.deep,
321
- });
322
- if (args.json) {
323
- console.log(JSON.stringify(report, null, 2));
324
- } else {
325
- console.log(formatCraterSmokeReport(report));
326
- }
327
- if (report.status === "fail" || (args.requireAvailable && report.status === "skip")) {
328
- process.exit(1);
329
- }
330
- }
331
-
332
- const isCliEntry = process.env.__VRT_DISPATCHER_LEAF__ === "crater-smoke" ||
333
- (process.argv[1] ? resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false);
334
- if (isCliEntry) {
335
- main().catch(handleCliError);
336
- }
@@ -1,260 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { pathToFileURL } from "node:url";
3
-
4
- export const CRATER_WASM_MODULE_ENV = "VLMKIT_CRATER_WASM_MODULE";
5
-
6
- export interface CraterWasmViewport {
7
- width: number;
8
- height: number;
9
- label?: string;
10
- }
11
-
12
- export interface CraterBoxRect {
13
- top: number;
14
- right: number;
15
- bottom: number;
16
- left: number;
17
- }
18
-
19
- export interface CraterLayoutNode {
20
- id: string;
21
- x: number;
22
- y: number;
23
- width: number;
24
- height: number;
25
- margin: CraterBoxRect;
26
- padding: CraterBoxRect;
27
- border: CraterBoxRect;
28
- children: CraterLayoutNode[];
29
- }
30
-
31
- export interface CraterLayoutRootBox {
32
- x: number;
33
- y: number;
34
- width: number;
35
- height: number;
36
- }
37
-
38
- export interface CraterLayoutDiagnostics {
39
- nodeCount: number;
40
- maxDepth: number;
41
- rootBox: CraterLayoutRootBox;
42
- }
43
-
44
- export interface CraterWasmRenderRequest {
45
- html: string;
46
- viewport: CraterWasmViewport;
47
- }
48
-
49
- export interface CraterWasmRenderResult {
50
- backend: "crater-wasm";
51
- viewport: CraterWasmViewport;
52
- layout: CraterLayoutNode;
53
- rawJson: string;
54
- elapsedMs: number;
55
- diagnostics: CraterLayoutDiagnostics;
56
- }
57
-
58
- export interface CraterWasmModule {
59
- renderHtmlToJsonForWpt(
60
- html: string,
61
- width: number,
62
- height: number,
63
- ): string | Promise<string>;
64
- }
65
-
66
- export interface CraterWasmLayoutBackend {
67
- kind: "crater-wasm-layout";
68
- renderLayout(request: CraterWasmRenderRequest): Promise<CraterWasmRenderResult>;
69
- }
70
-
71
- export interface LoadCraterWasmModuleOptions {
72
- modulePath?: string;
73
- env?: Partial<Record<typeof CRATER_WASM_MODULE_ENV | "CRATER_WASM_MODULE", string | undefined>>;
74
- cwd?: string;
75
- }
76
-
77
- export function createCraterWasmLayoutBackend(
78
- module: CraterWasmModule,
79
- ): CraterWasmLayoutBackend {
80
- assertCraterWasmModule(module);
81
- return {
82
- kind: "crater-wasm-layout",
83
- async renderLayout(request) {
84
- if (typeof request.html !== "string") {
85
- throw new Error("Crater WASM render request requires html");
86
- }
87
- const viewport = normalizeViewport(request.viewport);
88
- const started = Date.now();
89
- const rawJson = await module.renderHtmlToJsonForWpt(
90
- request.html,
91
- viewport.width,
92
- viewport.height,
93
- );
94
- if (typeof rawJson !== "string") {
95
- throw new Error("Crater WASM renderHtmlToJsonForWpt must return a JSON string");
96
- }
97
- const layout = normalizeCraterLayoutJson(rawJson);
98
- return {
99
- backend: "crater-wasm",
100
- viewport,
101
- layout,
102
- rawJson,
103
- elapsedMs: Date.now() - started,
104
- diagnostics: summarizeCraterLayout(layout),
105
- };
106
- },
107
- };
108
- }
109
-
110
- export async function loadCraterWasmModule(
111
- options: LoadCraterWasmModuleOptions = {},
112
- ): Promise<CraterWasmModule> {
113
- const modulePath = options.modulePath
114
- ?? options.env?.[CRATER_WASM_MODULE_ENV]
115
- ?? options.env?.CRATER_WASM_MODULE;
116
- if (!modulePath) {
117
- throw new Error(`${CRATER_WASM_MODULE_ENV} is required to load the Crater WASM backend`);
118
- }
119
- const loaded = await import(toImportSpecifier(modulePath, options.cwd));
120
- return assertCraterWasmModule(loaded);
121
- }
122
-
123
- export function normalizeCraterLayoutJson(raw: string | unknown): CraterLayoutNode {
124
- const value = typeof raw === "string" ? parseLayoutJson(raw) : raw;
125
- return normalizeCraterLayoutNode(value, "$");
126
- }
127
-
128
- export function summarizeCraterLayout(layout: CraterLayoutNode): CraterLayoutDiagnostics {
129
- let nodeCount = 0;
130
- let maxDepth = 0;
131
-
132
- function visit(node: CraterLayoutNode, depth: number): void {
133
- nodeCount += 1;
134
- maxDepth = Math.max(maxDepth, depth);
135
- for (const child of node.children) {
136
- visit(child, depth + 1);
137
- }
138
- }
139
-
140
- visit(layout, 1);
141
- return {
142
- nodeCount,
143
- maxDepth,
144
- rootBox: {
145
- x: layout.x,
146
- y: layout.y,
147
- width: layout.width,
148
- height: layout.height,
149
- },
150
- };
151
- }
152
-
153
- function parseLayoutJson(raw: string): unknown {
154
- try {
155
- return JSON.parse(raw) as unknown;
156
- } catch (error) {
157
- throw new Error(`Invalid Crater layout JSON: ${errorMessage(error)}`);
158
- }
159
- }
160
-
161
- function normalizeCraterLayoutNode(value: unknown, path: string): CraterLayoutNode {
162
- const record = asRecord(value, path);
163
- const children = record.children;
164
- if (!Array.isArray(children)) {
165
- throw new Error(`${path} missing children array`);
166
- }
167
- return {
168
- id: readString(record, "id", path),
169
- x: readNumber(record, "x", path),
170
- y: readNumber(record, "y", path),
171
- width: readNumber(record, "width", path),
172
- height: readNumber(record, "height", path),
173
- margin: normalizeBoxRect(record.margin, `${path}.margin`),
174
- padding: normalizeBoxRect(record.padding, `${path}.padding`),
175
- border: normalizeBoxRect(record.border, `${path}.border`),
176
- children: children.map((child, index) => normalizeCraterLayoutNode(child, `${path}.children[${index}]`)),
177
- };
178
- }
179
-
180
- function normalizeBoxRect(value: unknown, path: string): CraterBoxRect {
181
- const record = asRecord(value, path);
182
- return {
183
- top: readNumber(record, "top", path),
184
- right: readNumber(record, "right", path),
185
- bottom: readNumber(record, "bottom", path),
186
- left: readNumber(record, "left", path),
187
- };
188
- }
189
-
190
- function normalizeViewport(viewport: CraterWasmViewport): CraterWasmViewport {
191
- if (!viewport || typeof viewport !== "object") {
192
- throw new Error("Crater WASM render request requires viewport");
193
- }
194
- const width = Number(viewport.width);
195
- const height = Number(viewport.height);
196
- if (!Number.isFinite(width) || width <= 0) {
197
- throw new Error("Crater WASM viewport.width must be a positive number");
198
- }
199
- if (!Number.isFinite(height) || height <= 0) {
200
- throw new Error("Crater WASM viewport.height must be a positive number");
201
- }
202
- return {
203
- width,
204
- height,
205
- ...(typeof viewport.label === "string" ? { label: viewport.label } : {}),
206
- };
207
- }
208
-
209
- function readString(record: Record<string, unknown>, key: string, path: string): string {
210
- const value = record[key];
211
- if (typeof value !== "string") {
212
- throw new Error(`${path} missing string ${key}`);
213
- }
214
- return value;
215
- }
216
-
217
- function readNumber(record: Record<string, unknown>, key: string, path: string): number {
218
- const value = record[key];
219
- if (typeof value !== "number" || !Number.isFinite(value)) {
220
- throw new Error(`${path} missing numeric ${key}`);
221
- }
222
- return value;
223
- }
224
-
225
- function asRecord(value: unknown, path: string): Record<string, unknown> {
226
- if (!value || typeof value !== "object" || Array.isArray(value)) {
227
- throw new Error(`${path} must be an object`);
228
- }
229
- return value as Record<string, unknown>;
230
- }
231
-
232
- function assertCraterWasmModule(value: unknown): CraterWasmModule {
233
- const record = asRecord(value, "Crater WASM module");
234
- const render = record.renderHtmlToJsonForWpt;
235
- if (typeof render !== "function") {
236
- throw new Error("Crater WASM module must export renderHtmlToJsonForWpt(html, width, height)");
237
- }
238
- return {
239
- renderHtmlToJsonForWpt: render as CraterWasmModule["renderHtmlToJsonForWpt"],
240
- };
241
- }
242
-
243
- function toImportSpecifier(modulePath: string, cwd = process.cwd()): string {
244
- if (isUrlSpecifier(modulePath) || isBareSpecifier(modulePath)) {
245
- return modulePath;
246
- }
247
- return pathToFileURL(resolve(cwd, modulePath)).href;
248
- }
249
-
250
- function isUrlSpecifier(value: string): boolean {
251
- return /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(value);
252
- }
253
-
254
- function isBareSpecifier(value: string): boolean {
255
- return !value.startsWith(".") && !value.startsWith("/") && !value.startsWith("~");
256
- }
257
-
258
- function errorMessage(error: unknown): string {
259
- return error instanceof Error ? error.message : String(error);
260
- }