前端初始化
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
import { u as DiagnosticReporter } from "../diagnostic-wduO7saY.mjs";
|
||||
|
||||
//#region src/reporters/dev.d.ts
|
||||
/**
|
||||
* Creates a reporter for browser code under Vite dev: it forwards each
|
||||
* diagnostic over `import.meta.hot.send('nostics:report', ...)` so the
|
||||
* dev-server collector can file it. Outside Vite (`import.meta.hot` absent) it
|
||||
* warns once and does nothing.
|
||||
*/
|
||||
declare function createDevReporter(): DiagnosticReporter;
|
||||
//#endregion
|
||||
export { createDevReporter };
|
||||
//# sourceMappingURL=dev.d.mts.map
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
//#region src/reporters/dev.ts
|
||||
/**
|
||||
* Creates a reporter for browser code under Vite dev: it forwards each
|
||||
* diagnostic over `import.meta.hot.send('nostics:report', ...)` so the
|
||||
* dev-server collector can file it. Outside Vite (`import.meta.hot` absent) it
|
||||
* warns once and does nothing.
|
||||
*/
|
||||
/* @__NO_SIDE_EFFECTS__ */
|
||||
function createDevReporter() {
|
||||
return (diagnostic) => {
|
||||
if (import.meta.hot && typeof import.meta.hot.send === "function") import.meta.hot.send("nostics:report", diagnostic.toJSON());
|
||||
else console.warn("[nostics]: import.meta.hot.send() is not available. This must be running on Vite.");
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
export { createDevReporter };
|
||||
|
||||
//# sourceMappingURL=dev.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"dev.mjs","names":[],"sources":["../../src/reporters/dev.ts"],"sourcesContent":["import type { DiagnosticReporter } from '../diagnostic'\n\n/**\n * Creates a reporter for browser code under Vite dev: it forwards each\n * diagnostic over `import.meta.hot.send('nostics:report', ...)` so the\n * dev-server collector can file it. Outside Vite (`import.meta.hot` absent) it\n * warns once and does nothing.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function createDevReporter(): DiagnosticReporter {\n return (diagnostic) => {\n if (import.meta.hot && typeof import.meta.hot.send === 'function') {\n import.meta.hot.send('nostics:report', diagnostic.toJSON())\n }\n else {\n console.warn(\n '[nostics]: import.meta.hot.send() is not available. This must be running on Vite.',\n )\n }\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,oBAAwC;CACtD,QAAQ,eAAe;EACrB,IAAI,OAAO,KAAK,OAAO,OAAO,OAAO,KAAK,IAAI,SAAS,YACrD,OAAO,KAAK,IAAI,KAAK,kBAAkB,WAAW,OAAO,CAAC;OAG1D,QAAQ,KACN,mFACF;CAEJ;AACF"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { u as DiagnosticReporter } from "../diagnostic-wduO7saY.mjs";
|
||||
|
||||
//#region src/reporters/fetch.d.ts
|
||||
/**
|
||||
* Creates a reporter that POSTs each diagnostic as JSON to the given URL.
|
||||
* Errors are swallowed so reporting never throws into user code.
|
||||
*/
|
||||
declare function createFetchReporter(url: string): DiagnosticReporter;
|
||||
//#endregion
|
||||
export { createFetchReporter };
|
||||
//# sourceMappingURL=fetch.d.mts.map
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
//#region src/reporters/fetch.ts
|
||||
/**
|
||||
* Creates a reporter that POSTs each diagnostic as JSON to the given URL.
|
||||
* Errors are swallowed so reporting never throws into user code.
|
||||
*/
|
||||
/* @__NO_SIDE_EFFECTS__ */
|
||||
function createFetchReporter(url) {
|
||||
return (diagnostic) => {
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(diagnostic)
|
||||
}).catch(() => {});
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
export { createFetchReporter };
|
||||
|
||||
//# sourceMappingURL=fetch.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fetch.mjs","names":[],"sources":["../../src/reporters/fetch.ts"],"sourcesContent":["import type { DiagnosticReporter } from '../diagnostic'\n\n/**\n * Creates a reporter that POSTs each diagnostic as JSON to the given URL.\n * Errors are swallowed so reporting never throws into user code.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function createFetchReporter(url: string): DiagnosticReporter {\n return (diagnostic) => {\n fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(diagnostic),\n }).catch(() => {})\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,oBAAoB,KAAiC;CACnE,QAAQ,eAAe;EACrB,MAAM,KAAK;GACT,QAAQ;GACR,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,MAAM,KAAK,UAAU,UAAU;EACjC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;CACnB;AACF"}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import { u as DiagnosticReporter } from "../diagnostic-wduO7saY.mjs";
|
||||
|
||||
//#region src/reporters/node.d.ts
|
||||
interface FileReporterOptions {
|
||||
/**
|
||||
* Path to the log file.
|
||||
* @default '.nostics.log'
|
||||
*/
|
||||
logFile?: string;
|
||||
/**
|
||||
* Stack frames matching ANY of these patterns are removed from
|
||||
* `diagnostic.stack` before it is written to the log file. Useful to strip
|
||||
* `node_modules` and Node internals. The `Error: ...` header line is
|
||||
* always preserved.
|
||||
*
|
||||
* Pass an empty array to keep every frame.
|
||||
* @default [/\/node_modules\//i]
|
||||
*/
|
||||
excludeStackFrames?: readonly RegExp[];
|
||||
}
|
||||
/**
|
||||
* Creates a reporter that appends diagnostics as NDJSON to a local file.
|
||||
* Each diagnostic is written as a single JSON line. The diagnostic's `stack`
|
||||
* (if present) is included in the payload; noisy frames can be removed via
|
||||
* {@link FileReporterOptions.excludeStackFrames}.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { defineDiagnostics } from 'nostics'
|
||||
* import { createFileReporter } from 'nostics/reporters/node'
|
||||
*
|
||||
* const diagnostics = defineDiagnostics({
|
||||
* codes: { ... },
|
||||
* reporters: [createFileReporter({
|
||||
* excludeStackFrames: [/\/node_modules\//, /\(node:/],
|
||||
* })],
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
declare function createFileReporter(options?: FileReporterOptions): DiagnosticReporter;
|
||||
//#endregion
|
||||
export { FileReporterOptions, createFileReporter };
|
||||
//# sourceMappingURL=node.d.mts.map
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { appendFileSync } from "node:fs";
|
||||
//#region src/reporters/node.ts
|
||||
const DEFAULT_EXCLUDE_STACK_FRAMES = [/\/node_modules\//i];
|
||||
function applyExcludeStackFrames(raw, exclude) {
|
||||
const [header, ...frames] = raw.split("\n");
|
||||
return [header, ...frames.filter((frame) => !exclude.some((re) => re.test(frame)))].join("\n");
|
||||
}
|
||||
/**
|
||||
* Creates a reporter that appends diagnostics as NDJSON to a local file.
|
||||
* Each diagnostic is written as a single JSON line. The diagnostic's `stack`
|
||||
* (if present) is included in the payload; noisy frames can be removed via
|
||||
* {@link FileReporterOptions.excludeStackFrames}.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { defineDiagnostics } from 'nostics'
|
||||
* import { createFileReporter } from 'nostics/reporters/node'
|
||||
*
|
||||
* const diagnostics = defineDiagnostics({
|
||||
* codes: { ... },
|
||||
* reporters: [createFileReporter({
|
||||
* excludeStackFrames: [/\/node_modules\//, /\(node:/],
|
||||
* })],
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
/* @__NO_SIDE_EFFECTS__ */
|
||||
function createFileReporter(options) {
|
||||
const logFile = options?.logFile ?? ".nostics.log";
|
||||
const excludeStackFrames = options?.excludeStackFrames ?? DEFAULT_EXCLUDE_STACK_FRAMES;
|
||||
return (diagnostic) => {
|
||||
try {
|
||||
const d = diagnostic;
|
||||
const base = typeof d.toJSON === "function" ? d.toJSON() : { ...d };
|
||||
if (d.stack) base.stack = excludeStackFrames?.length ? applyExcludeStackFrames(d.stack, excludeStackFrames) : d.stack;
|
||||
appendFileSync(logFile, `${JSON.stringify(base)}\n`);
|
||||
} catch (err) {
|
||||
console.error(`[nostics]: Failed to write log to "${logFile}":`, err);
|
||||
}
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
export { createFileReporter };
|
||||
|
||||
//# sourceMappingURL=node.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.mjs","names":[],"sources":["../../src/reporters/node.ts"],"sourcesContent":["import type { Diagnostic, DiagnosticReporter } from '../diagnostic'\nimport { appendFileSync } from 'node:fs'\n\nexport interface FileReporterOptions {\n /**\n * Path to the log file.\n * @default '.nostics.log'\n */\n logFile?: string\n\n /**\n * Stack frames matching ANY of these patterns are removed from\n * `diagnostic.stack` before it is written to the log file. Useful to strip\n * `node_modules` and Node internals. The `Error: ...` header line is\n * always preserved.\n *\n * Pass an empty array to keep every frame.\n * @default [/\\/node_modules\\//i]\n */\n excludeStackFrames?: readonly RegExp[]\n}\n\nconst DEFAULT_EXCLUDE_STACK_FRAMES: readonly RegExp[] = [/\\/node_modules\\//i]\n\nfunction applyExcludeStackFrames(raw: string, exclude: readonly RegExp[]): string {\n const [header, ...frames] = raw.split('\\n')\n return [header, ...frames.filter(frame => !exclude.some(re => re.test(frame)))].join('\\n')\n}\n\n/**\n * Creates a reporter that appends diagnostics as NDJSON to a local file.\n * Each diagnostic is written as a single JSON line. The diagnostic's `stack`\n * (if present) is included in the payload; noisy frames can be removed via\n * {@link FileReporterOptions.excludeStackFrames}.\n *\n * @example\n * ```ts\n * import { defineDiagnostics } from 'nostics'\n * import { createFileReporter } from 'nostics/reporters/node'\n *\n * const diagnostics = defineDiagnostics({\n * codes: { ... },\n * reporters: [createFileReporter({\n * excludeStackFrames: [/\\/node_modules\\//, /\\(node:/],\n * })],\n * })\n * ```\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function createFileReporter(options?: FileReporterOptions): DiagnosticReporter {\n const logFile = options?.logFile ?? '.nostics.log'\n const excludeStackFrames = options?.excludeStackFrames ?? DEFAULT_EXCLUDE_STACK_FRAMES\n return (diagnostic) => {\n try {\n const d = diagnostic as Diagnostic & Record<string, unknown>\n const base: Record<string, unknown>\n = typeof d.toJSON === 'function' ? (d.toJSON() as Record<string, unknown>) : { ...d }\n if (d.stack) {\n base.stack = excludeStackFrames?.length\n ? applyExcludeStackFrames(d.stack, excludeStackFrames)\n : d.stack\n }\n appendFileSync(logFile, `${JSON.stringify(base)}\\n`)\n }\n catch (err: unknown) {\n console.error(`[nostics]: Failed to write log to \"${logFile}\":`, err)\n }\n }\n}\n"],"mappings":";;AAsBA,MAAM,+BAAkD,CAAC,mBAAmB;AAE5E,SAAS,wBAAwB,KAAa,SAAoC;CAChF,MAAM,CAAC,QAAQ,GAAG,UAAU,IAAI,MAAM,IAAI;CAC1C,OAAO,CAAC,QAAQ,GAAG,OAAO,QAAO,UAAS,CAAC,QAAQ,MAAK,OAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;AAC3F;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,mBAAmB,SAAmD;CACpF,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,qBAAqB,SAAS,sBAAsB;CAC1D,QAAQ,eAAe;EACrB,IAAI;GACF,MAAM,IAAI;GACV,MAAM,OACF,OAAO,EAAE,WAAW,aAAc,EAAE,OAAO,IAAgC,EAAE,GAAG,EAAE;GACtF,IAAI,EAAE,OACJ,KAAK,QAAQ,oBAAoB,SAC7B,wBAAwB,EAAE,OAAO,kBAAkB,IACnD,EAAE;GAER,eAAe,SAAS,GAAG,KAAK,UAAU,IAAI,EAAE,GAAG;EACrD,SACO,KAAc;GACnB,QAAQ,MAAM,sCAAsC,QAAQ,KAAK,GAAG;EACtE;CACF;AACF"}
|
||||
Reference in New Issue
Block a user