vite-plugin-observe 1.0.0 → 1.0.2
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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
function viteObserverPlugin(options = {}) {
|
|
27
27
|
const { type = "default", serverPrefix = "", sourcePrefix = "", scripts = [] } = options;
|
|
28
|
-
const errorReportUrl = `${serverPrefix}/
|
|
28
|
+
const errorReportUrl = `${serverPrefix}/runtimeError`;
|
|
29
29
|
const sourceUrl = sourcePrefix || "https://appgo-app-prod.bj.bcebos.com/mali/js";
|
|
30
30
|
const defaultScripts = type === "default" ? [
|
|
31
31
|
{
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport type { PluginOptions } from './types';\n\nexport default function viteObserverPlugin(options: PluginOptions = {}): Plugin {\n const { type = 'default', serverPrefix = '', sourcePrefix = '', scripts = [] } = options;\n\n const errorReportUrl = `${serverPrefix}/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport type { PluginOptions } from './types';\n\nexport default function viteObserverPlugin(options: PluginOptions = {}): Plugin {\n const { type = 'default', serverPrefix = '', sourcePrefix = '', scripts = [] } = options;\n\n const errorReportUrl = `${serverPrefix}/runtimeError`;\n\n const sourceUrl = sourcePrefix || 'https://appgo-app-prod.bj.bcebos.com/mali/js';\n\n const defaultScripts =\n type === 'default'\n ? [\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n attrs: {\n src: `${sourceUrl}/error.js`,\n },\n },\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n attrs: {\n src: `${sourceUrl}/inspector.js`,\n },\n },\n ]\n : [\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n children: `\n (function() {\n function reportError(error) {\n fetch(\"${errorReportUrl}\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n timestamp: Date.now(),\n userAgent: navigator.userAgent,\n ...error\n })\n }).catch(() => {});\n }\n\n window.addEventListener('error', e => {\n reportError({\n type: 'error',\n message: e?.message,\n stack: e.error?.stack,\n filename: e?.filename,\n lineno: e?.lineno,\n colno: e?.colno,\n error: e?.error,\n });\n });\n\n window.addEventListener('unhandledrejection', e => {\n reportError({\n type: 'unhandledrejection',\n message: e.reason?.message ?? e.reason,\n stack: e.reason?.stack ?? '',\n filename: window.location.href,\n });\n });\n })();\n `,\n },\n ];\n\n return {\n name: 'vite-plugin-observe',\n apply: 'serve',\n configureServer(server) {\n server.middlewares.use((req, res, next) => {\n if (req.url === errorReportUrl && req.method === 'POST') {\n let body = '';\n req.on('data', (chunk) => (body += chunk));\n req.on('end', () => {\n try {\n const { type, message, stack, filename, lineno, colno } = JSON.parse(body);\n console.error(`${new Date().toLocaleString()} ${type}: ${message}`);\n if (filename) console.error(`${filename}:${lineno ?? ''}:${colno ?? ''}`);\n if (stack) console.error(stack);\n } catch (e) {\n console.error(`${new Date().toLocaleString()} error: ${e}`);\n }\n res.statusCode = 204;\n res.end();\n });\n } else {\n next();\n }\n });\n },\n\n transformIndexHtml() {\n return [\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n children: `window.__ERROR_REPORT_URL__ = '${errorReportUrl}';`,\n },\n ...defaultScripts,\n ...scripts,\n ];\n },\n };\n}\n\nexport type { PluginOptions } from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGe,SAAR,mBAAoC,UAAyB,CAAC,GAAW;AAC5E,QAAM,EAAE,OAAO,WAAW,eAAe,IAAI,eAAe,IAAI,U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AAO,SAAQ,MAAM,KAAK;AAAA,YAClC,SAAS,GAAG;AACR,sBAAQ,MAAM,IAAG,oBAAI,KAAK,GAAE,eAAe,CAAC,WAAW,CAAC,EAAE;AAAA,YAC9D;AACA,gBAAI,aAAa;AACjB,gBAAI,IAAI;AAAA,UACZ,CAAC;AAAA,QACL,OAAO;AACH,eAAK;AAAA,QACT;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,IAEA,qBAAqB;AACjB,aAAO;AAAA,QACH;AAAA,UACI,KAAK;AAAA,UACL,UAAU;AAAA,UACV,UAAU,kCAAkC,cAAc;AAAA,QAC9D;AAAA,QACA,GAAG;AAAA,QACH,GAAG;AAAA,MACP;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["type"]}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
function viteObserverPlugin(options = {}) {
|
|
3
3
|
const { type = "default", serverPrefix = "", sourcePrefix = "", scripts = [] } = options;
|
|
4
|
-
const errorReportUrl = `${serverPrefix}/
|
|
4
|
+
const errorReportUrl = `${serverPrefix}/runtimeError`;
|
|
5
5
|
const sourceUrl = sourcePrefix || "https://appgo-app-prod.bj.bcebos.com/mali/js";
|
|
6
6
|
const defaultScripts = type === "default" ? [
|
|
7
7
|
{
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport type { PluginOptions } from './types';\n\nexport default function viteObserverPlugin(options: PluginOptions = {}): Plugin {\n const { type = 'default', serverPrefix = '', sourcePrefix = '', scripts = [] } = options;\n\n const errorReportUrl = `${serverPrefix}/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport type { PluginOptions } from './types';\n\nexport default function viteObserverPlugin(options: PluginOptions = {}): Plugin {\n const { type = 'default', serverPrefix = '', sourcePrefix = '', scripts = [] } = options;\n\n const errorReportUrl = `${serverPrefix}/runtimeError`;\n\n const sourceUrl = sourcePrefix || 'https://appgo-app-prod.bj.bcebos.com/mali/js';\n\n const defaultScripts =\n type === 'default'\n ? [\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n attrs: {\n src: `${sourceUrl}/error.js`,\n },\n },\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n attrs: {\n src: `${sourceUrl}/inspector.js`,\n },\n },\n ]\n : [\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n children: `\n (function() {\n function reportError(error) {\n fetch(\"${errorReportUrl}\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n timestamp: Date.now(),\n userAgent: navigator.userAgent,\n ...error\n })\n }).catch(() => {});\n }\n\n window.addEventListener('error', e => {\n reportError({\n type: 'error',\n message: e?.message,\n stack: e.error?.stack,\n filename: e?.filename,\n lineno: e?.lineno,\n colno: e?.colno,\n error: e?.error,\n });\n });\n\n window.addEventListener('unhandledrejection', e => {\n reportError({\n type: 'unhandledrejection',\n message: e.reason?.message ?? e.reason,\n stack: e.reason?.stack ?? '',\n filename: window.location.href,\n });\n });\n })();\n `,\n },\n ];\n\n return {\n name: 'vite-plugin-observe',\n apply: 'serve',\n configureServer(server) {\n server.middlewares.use((req, res, next) => {\n if (req.url === errorReportUrl && req.method === 'POST') {\n let body = '';\n req.on('data', (chunk) => (body += chunk));\n req.on('end', () => {\n try {\n const { type, message, stack, filename, lineno, colno } = JSON.parse(body);\n console.error(`${new Date().toLocaleString()} ${type}: ${message}`);\n if (filename) console.error(`${filename}:${lineno ?? ''}:${colno ?? ''}`);\n if (stack) console.error(stack);\n } catch (e) {\n console.error(`${new Date().toLocaleString()} error: ${e}`);\n }\n res.statusCode = 204;\n res.end();\n });\n } else {\n next();\n }\n });\n },\n\n transformIndexHtml() {\n return [\n {\n tag: 'script',\n injectTo: 'head-prepend' as const,\n children: `window.__ERROR_REPORT_URL__ = '${errorReportUrl}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