@react-perfscope/vite 0.7.0 → 1.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/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -26,9 +26,13 @@ module.exports = __toCommonJS(index_exports);
|
|
|
26
26
|
var VIRTUAL_ID = "\0virtual:react-perfscope-bootstrap";
|
|
27
27
|
var VIRTUAL_URL = "/@react-perfscope-bootstrap.js";
|
|
28
28
|
function reactPerfscope(_opts) {
|
|
29
|
+
let base = "";
|
|
29
30
|
return {
|
|
30
31
|
name: "react-perfscope",
|
|
31
32
|
apply: "serve",
|
|
33
|
+
configResolved(config) {
|
|
34
|
+
base = config.base.endsWith("/") ? config.base.slice(0, -1) : config.base;
|
|
35
|
+
},
|
|
32
36
|
config(config) {
|
|
33
37
|
var _a, _b;
|
|
34
38
|
config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
@@ -60,7 +64,7 @@ function reactPerfscope(_opts) {
|
|
|
60
64
|
return [
|
|
61
65
|
{
|
|
62
66
|
tag: "script",
|
|
63
|
-
attrs: { type: "module", src: VIRTUAL_URL },
|
|
67
|
+
attrs: { type: "module", src: base + VIRTUAL_URL },
|
|
64
68
|
injectTo: "head-prepend"
|
|
65
69
|
}
|
|
66
70
|
];
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, HtmlTagDescriptor } from 'vite'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6 (position, host, disabled, etc.).\n}\n\nconst VIRTUAL_ID = '\\0virtual:react-perfscope-bootstrap'\nconst VIRTUAL_URL = '/@react-perfscope-bootstrap.js'\n\n/**\n * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry\n * during dev mode. The injected script imports the meta package which\n * bootstraps a recorder + render collector + UI mount.\n *\n * Implementation: Vite does NOT transform inline `<script type=\"module\">`\n * content, so writing `import 'react-perfscope/auto'` directly into a tag\n * fails (the browser can't resolve bare specifiers). Instead we expose a\n * virtual module via `resolveId`/`load` and inject a `<script src>` that\n * points at it — Vite's module-loading pipeline transforms the module body\n * (where the bare specifier IS resolved) before delivering it.\n */\nexport default function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin {\n return {\n name: 'react-perfscope',\n apply: 'serve',\n config(config) {\n // Force-bundle the perfscope packages as deps so @vitejs/plugin-react\n // (and similar transforms) see them as node_modules — otherwise the\n // workspace-linked dist files get pulled through Fast Refresh, which\n // throws \"can't detect preamble\" because our bootstrap runs before\n // the React plugin's preamble. We only list packages we expect the\n // consumer to actually have in package.json — `react-perfscope` is\n // the user-facing dep, `/auto` is its side-effect entry. Vite's\n // optimizer follows transitive imports (core/react/ui) automatically.\n config.optimizeDeps ??= {}\n config.optimizeDeps.include ??= []\n const toInclude = ['react-perfscope', 'react-perfscope/auto']\n for (const dep of toInclude) {\n if (!config.optimizeDeps.include.includes(dep)) {\n config.optimizeDeps.include.push(dep)\n }\n }\n // The JS Self-Profiling API (used to attribute long tasks to the\n // developer's own functions) only initializes when the document is\n // served with this response header. Set it for all dev responses so\n // attribution works with zero config; it's a no-op where the browser\n // lacks the API. We merge rather than overwrite any user-set headers.\n config.server ??= {}\n config.server.headers ??= {}\n if (!('Document-Policy' in config.server.headers)) {\n config.server.headers['Document-Policy'] = 'js-profiling'\n }\n return config\n },\n resolveId(id) {\n if (id === VIRTUAL_URL) return VIRTUAL_ID\n return null\n },\n load(id) {\n if (id === VIRTUAL_ID) {\n return `import 'react-perfscope/auto'`\n }\n return null\n },\n transformIndexHtml(_html: string): HtmlTagDescriptor[] {\n return [\n {\n tag: 'script',\n attrs: { type: 'module', src: VIRTUAL_URL },\n injectTo: 'head-prepend',\n },\n ]\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAM,aAAa;AACnB,IAAM,cAAc;AAcL,SAAR,eAAgC,OAA6C;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, HtmlTagDescriptor } from 'vite'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6 (position, host, disabled, etc.).\n}\n\nconst VIRTUAL_ID = '\\0virtual:react-perfscope-bootstrap'\nconst VIRTUAL_URL = '/@react-perfscope-bootstrap.js'\n\n/**\n * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry\n * during dev mode. The injected script imports the meta package which\n * bootstraps a recorder + render collector + UI mount.\n *\n * Implementation: Vite does NOT transform inline `<script type=\"module\">`\n * content, so writing `import 'react-perfscope/auto'` directly into a tag\n * fails (the browser can't resolve bare specifiers). Instead we expose a\n * virtual module via `resolveId`/`load` and inject a `<script src>` that\n * points at it — Vite's module-loading pipeline transforms the module body\n * (where the bare specifier IS resolved) before delivering it.\n */\nexport default function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin {\n // Vite does not rewrite plugin-injected tag URLs with `base`, so the\n // injected src must carry the prefix itself; the dev server strips base\n // before plugin resolution, so resolveId still matches the bare URL.\n let base = ''\n return {\n name: 'react-perfscope',\n apply: 'serve',\n configResolved(config) {\n base = config.base.endsWith('/') ? config.base.slice(0, -1) : config.base\n },\n config(config) {\n // Force-bundle the perfscope packages as deps so @vitejs/plugin-react\n // (and similar transforms) see them as node_modules — otherwise the\n // workspace-linked dist files get pulled through Fast Refresh, which\n // throws \"can't detect preamble\" because our bootstrap runs before\n // the React plugin's preamble. We only list packages we expect the\n // consumer to actually have in package.json — `react-perfscope` is\n // the user-facing dep, `/auto` is its side-effect entry. Vite's\n // optimizer follows transitive imports (core/react/ui) automatically.\n config.optimizeDeps ??= {}\n config.optimizeDeps.include ??= []\n const toInclude = ['react-perfscope', 'react-perfscope/auto']\n for (const dep of toInclude) {\n if (!config.optimizeDeps.include.includes(dep)) {\n config.optimizeDeps.include.push(dep)\n }\n }\n // The JS Self-Profiling API (used to attribute long tasks to the\n // developer's own functions) only initializes when the document is\n // served with this response header. Set it for all dev responses so\n // attribution works with zero config; it's a no-op where the browser\n // lacks the API. We merge rather than overwrite any user-set headers.\n config.server ??= {}\n config.server.headers ??= {}\n if (!('Document-Policy' in config.server.headers)) {\n config.server.headers['Document-Policy'] = 'js-profiling'\n }\n return config\n },\n resolveId(id) {\n if (id === VIRTUAL_URL) return VIRTUAL_ID\n return null\n },\n load(id) {\n if (id === VIRTUAL_ID) {\n return `import 'react-perfscope/auto'`\n }\n return null\n },\n transformIndexHtml(_html: string): HtmlTagDescriptor[] {\n return [\n {\n tag: 'script',\n attrs: { type: 'module', src: base + VIRTUAL_URL },\n injectTo: 'head-prepend',\n },\n ]\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAM,aAAa;AACnB,IAAM,cAAc;AAcL,SAAR,eAAgC,OAA6C;AAIlF,MAAI,OAAO;AACX,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,eAAe,QAAQ;AACrB,aAAO,OAAO,KAAK,SAAS,GAAG,IAAI,OAAO,KAAK,MAAM,GAAG,EAAE,IAAI,OAAO;AAAA,IACvE;AAAA,IACA,OAAO,QAAQ;AAhCnB;AAyCM,aAAO,iBAAP,OAAO,eAAiB,CAAC;AACzB,mBAAO,cAAa,YAApB,GAAoB,UAAY,CAAC;AACjC,YAAM,YAAY,CAAC,mBAAmB,sBAAsB;AAC5D,iBAAW,OAAO,WAAW;AAC3B,YAAI,CAAC,OAAO,aAAa,QAAQ,SAAS,GAAG,GAAG;AAC9C,iBAAO,aAAa,QAAQ,KAAK,GAAG;AAAA,QACtC;AAAA,MACF;AAMA,aAAO,WAAP,OAAO,SAAW,CAAC;AACnB,mBAAO,QAAO,YAAd,GAAc,UAAY,CAAC;AAC3B,UAAI,EAAE,qBAAqB,OAAO,OAAO,UAAU;AACjD,eAAO,OAAO,QAAQ,iBAAiB,IAAI;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,IAAI;AACZ,UAAI,OAAO,YAAa,QAAO;AAC/B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACP,UAAI,OAAO,YAAY;AACrB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,mBAAmB,OAAoC;AACrD,aAAO;AAAA,QACL;AAAA,UACE,KAAK;AAAA,UACL,OAAO,EAAE,MAAM,UAAU,KAAK,OAAO,YAAY;AAAA,UACjD,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
var VIRTUAL_ID = "\0virtual:react-perfscope-bootstrap";
|
|
3
3
|
var VIRTUAL_URL = "/@react-perfscope-bootstrap.js";
|
|
4
4
|
function reactPerfscope(_opts) {
|
|
5
|
+
let base = "";
|
|
5
6
|
return {
|
|
6
7
|
name: "react-perfscope",
|
|
7
8
|
apply: "serve",
|
|
9
|
+
configResolved(config) {
|
|
10
|
+
base = config.base.endsWith("/") ? config.base.slice(0, -1) : config.base;
|
|
11
|
+
},
|
|
8
12
|
config(config) {
|
|
9
13
|
var _a, _b;
|
|
10
14
|
config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
@@ -36,7 +40,7 @@ function reactPerfscope(_opts) {
|
|
|
36
40
|
return [
|
|
37
41
|
{
|
|
38
42
|
tag: "script",
|
|
39
|
-
attrs: { type: "module", src: VIRTUAL_URL },
|
|
43
|
+
attrs: { type: "module", src: base + VIRTUAL_URL },
|
|
40
44
|
injectTo: "head-prepend"
|
|
41
45
|
}
|
|
42
46
|
];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, HtmlTagDescriptor } from 'vite'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6 (position, host, disabled, etc.).\n}\n\nconst VIRTUAL_ID = '\\0virtual:react-perfscope-bootstrap'\nconst VIRTUAL_URL = '/@react-perfscope-bootstrap.js'\n\n/**\n * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry\n * during dev mode. The injected script imports the meta package which\n * bootstraps a recorder + render collector + UI mount.\n *\n * Implementation: Vite does NOT transform inline `<script type=\"module\">`\n * content, so writing `import 'react-perfscope/auto'` directly into a tag\n * fails (the browser can't resolve bare specifiers). Instead we expose a\n * virtual module via `resolveId`/`load` and inject a `<script src>` that\n * points at it — Vite's module-loading pipeline transforms the module body\n * (where the bare specifier IS resolved) before delivering it.\n */\nexport default function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin {\n return {\n name: 'react-perfscope',\n apply: 'serve',\n config(config) {\n // Force-bundle the perfscope packages as deps so @vitejs/plugin-react\n // (and similar transforms) see them as node_modules — otherwise the\n // workspace-linked dist files get pulled through Fast Refresh, which\n // throws \"can't detect preamble\" because our bootstrap runs before\n // the React plugin's preamble. We only list packages we expect the\n // consumer to actually have in package.json — `react-perfscope` is\n // the user-facing dep, `/auto` is its side-effect entry. Vite's\n // optimizer follows transitive imports (core/react/ui) automatically.\n config.optimizeDeps ??= {}\n config.optimizeDeps.include ??= []\n const toInclude = ['react-perfscope', 'react-perfscope/auto']\n for (const dep of toInclude) {\n if (!config.optimizeDeps.include.includes(dep)) {\n config.optimizeDeps.include.push(dep)\n }\n }\n // The JS Self-Profiling API (used to attribute long tasks to the\n // developer's own functions) only initializes when the document is\n // served with this response header. Set it for all dev responses so\n // attribution works with zero config; it's a no-op where the browser\n // lacks the API. We merge rather than overwrite any user-set headers.\n config.server ??= {}\n config.server.headers ??= {}\n if (!('Document-Policy' in config.server.headers)) {\n config.server.headers['Document-Policy'] = 'js-profiling'\n }\n return config\n },\n resolveId(id) {\n if (id === VIRTUAL_URL) return VIRTUAL_ID\n return null\n },\n load(id) {\n if (id === VIRTUAL_ID) {\n return `import 'react-perfscope/auto'`\n }\n return null\n },\n transformIndexHtml(_html: string): HtmlTagDescriptor[] {\n return [\n {\n tag: 'script',\n attrs: { type: 'module', src: VIRTUAL_URL },\n injectTo: 'head-prepend',\n },\n ]\n },\n }\n}\n"],"mappings":";AAMA,IAAM,aAAa;AACnB,IAAM,cAAc;AAcL,SAAR,eAAgC,OAA6C;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, HtmlTagDescriptor } from 'vite'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6 (position, host, disabled, etc.).\n}\n\nconst VIRTUAL_ID = '\\0virtual:react-perfscope-bootstrap'\nconst VIRTUAL_URL = '/@react-perfscope-bootstrap.js'\n\n/**\n * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry\n * during dev mode. The injected script imports the meta package which\n * bootstraps a recorder + render collector + UI mount.\n *\n * Implementation: Vite does NOT transform inline `<script type=\"module\">`\n * content, so writing `import 'react-perfscope/auto'` directly into a tag\n * fails (the browser can't resolve bare specifiers). Instead we expose a\n * virtual module via `resolveId`/`load` and inject a `<script src>` that\n * points at it — Vite's module-loading pipeline transforms the module body\n * (where the bare specifier IS resolved) before delivering it.\n */\nexport default function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin {\n // Vite does not rewrite plugin-injected tag URLs with `base`, so the\n // injected src must carry the prefix itself; the dev server strips base\n // before plugin resolution, so resolveId still matches the bare URL.\n let base = ''\n return {\n name: 'react-perfscope',\n apply: 'serve',\n configResolved(config) {\n base = config.base.endsWith('/') ? config.base.slice(0, -1) : config.base\n },\n config(config) {\n // Force-bundle the perfscope packages as deps so @vitejs/plugin-react\n // (and similar transforms) see them as node_modules — otherwise the\n // workspace-linked dist files get pulled through Fast Refresh, which\n // throws \"can't detect preamble\" because our bootstrap runs before\n // the React plugin's preamble. We only list packages we expect the\n // consumer to actually have in package.json — `react-perfscope` is\n // the user-facing dep, `/auto` is its side-effect entry. Vite's\n // optimizer follows transitive imports (core/react/ui) automatically.\n config.optimizeDeps ??= {}\n config.optimizeDeps.include ??= []\n const toInclude = ['react-perfscope', 'react-perfscope/auto']\n for (const dep of toInclude) {\n if (!config.optimizeDeps.include.includes(dep)) {\n config.optimizeDeps.include.push(dep)\n }\n }\n // The JS Self-Profiling API (used to attribute long tasks to the\n // developer's own functions) only initializes when the document is\n // served with this response header. Set it for all dev responses so\n // attribution works with zero config; it's a no-op where the browser\n // lacks the API. We merge rather than overwrite any user-set headers.\n config.server ??= {}\n config.server.headers ??= {}\n if (!('Document-Policy' in config.server.headers)) {\n config.server.headers['Document-Policy'] = 'js-profiling'\n }\n return config\n },\n resolveId(id) {\n if (id === VIRTUAL_URL) return VIRTUAL_ID\n return null\n },\n load(id) {\n if (id === VIRTUAL_ID) {\n return `import 'react-perfscope/auto'`\n }\n return null\n },\n transformIndexHtml(_html: string): HtmlTagDescriptor[] {\n return [\n {\n tag: 'script',\n attrs: { type: 'module', src: base + VIRTUAL_URL },\n injectTo: 'head-prepend',\n },\n ]\n },\n }\n}\n"],"mappings":";AAMA,IAAM,aAAa;AACnB,IAAM,cAAc;AAcL,SAAR,eAAgC,OAA6C;AAIlF,MAAI,OAAO;AACX,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,eAAe,QAAQ;AACrB,aAAO,OAAO,KAAK,SAAS,GAAG,IAAI,OAAO,KAAK,MAAM,GAAG,EAAE,IAAI,OAAO;AAAA,IACvE;AAAA,IACA,OAAO,QAAQ;AAhCnB;AAyCM,aAAO,iBAAP,OAAO,eAAiB,CAAC;AACzB,mBAAO,cAAa,YAApB,GAAoB,UAAY,CAAC;AACjC,YAAM,YAAY,CAAC,mBAAmB,sBAAsB;AAC5D,iBAAW,OAAO,WAAW;AAC3B,YAAI,CAAC,OAAO,aAAa,QAAQ,SAAS,GAAG,GAAG;AAC9C,iBAAO,aAAa,QAAQ,KAAK,GAAG;AAAA,QACtC;AAAA,MACF;AAMA,aAAO,WAAP,OAAO,SAAW,CAAC;AACnB,mBAAO,QAAO,YAAd,GAAc,UAAY,CAAC;AAC3B,UAAI,EAAE,qBAAqB,OAAO,OAAO,UAAU;AACjD,eAAO,OAAO,QAAQ,iBAAiB,IAAI;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,IAAI;AACZ,UAAI,OAAO,YAAa,QAAO;AAC/B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACP,UAAI,OAAO,YAAY;AACrB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,mBAAmB,OAAoC;AACrD,aAAO;AAAA,QACL;AAAA,UACE,KAAK;AAAA,UACL,OAAO,EAAE,MAAM,UAAU,KAAK,OAAO,YAAY;AAAA,UACjD,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-perfscope/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Vite plugin that auto-mounts react-perfscope in dev.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
},
|
|
45
48
|
"scripts": {
|
|
46
49
|
"build": "tsup && node scripts/prepend-dts-refs.mjs",
|
|
47
50
|
"typecheck": "tsc --noEmit"
|