@githumbi/grabby 0.1.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/CHANGELOG.md +11 -0
- package/LICENSE +22 -0
- package/README.md +262 -0
- package/builders.json +14 -0
- package/dist/angular/index.d.ts +279 -0
- package/dist/angular/index.js +5145 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/babel-plugin/index.cjs +95 -0
- package/dist/babel-plugin/index.cjs.map +1 -0
- package/dist/babel-plugin/index.d.cts +28 -0
- package/dist/babel-plugin/index.d.ts +28 -0
- package/dist/babel-plugin/index.js +60 -0
- package/dist/babel-plugin/index.js.map +1 -0
- package/dist/builder/builders/application/index.js +141 -0
- package/dist/builder/builders/application/index.js.map +1 -0
- package/dist/builder/builders/application/schema.json +7 -0
- package/dist/builder/builders/dev-server/index.js +137 -0
- package/dist/builder/builders/dev-server/index.js.map +1 -0
- package/dist/builder/builders/dev-server/schema.json +26 -0
- package/dist/builder/index.js +2 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/package.json +1 -0
- package/dist/chunk-6CBIOKZV.cjs +45 -0
- package/dist/chunk-6CBIOKZV.cjs.map +1 -0
- package/dist/chunk-M3DOFJA7.js +45 -0
- package/dist/chunk-M3DOFJA7.js.map +1 -0
- package/dist/cli/index.js +406 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/index.cjs +5081 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +96 -0
- package/dist/core/index.d.ts +96 -0
- package/dist/core/index.js +5081 -0
- package/dist/core/index.js.map +1 -0
- package/dist/esbuild-plugin/index.cjs +134 -0
- package/dist/esbuild-plugin/index.cjs.map +1 -0
- package/dist/esbuild-plugin/index.d.cts +21 -0
- package/dist/esbuild-plugin/index.d.ts +21 -0
- package/dist/esbuild-plugin/index.js +96 -0
- package/dist/esbuild-plugin/index.js.map +1 -0
- package/dist/export/index.cjs +166 -0
- package/dist/export/index.cjs.map +1 -0
- package/dist/export/index.d.cts +86 -0
- package/dist/export/index.d.ts +86 -0
- package/dist/export/index.js +137 -0
- package/dist/export/index.js.map +1 -0
- package/dist/grabby.global.js +635 -0
- package/dist/live/index.cjs +30 -0
- package/dist/live/index.cjs.map +1 -0
- package/dist/live/index.d.cts +20 -0
- package/dist/live/index.d.ts +20 -0
- package/dist/live/index.js +30 -0
- package/dist/live/index.js.map +1 -0
- package/dist/loader.global.js +1 -0
- package/dist/plugin/index.cjs +229 -0
- package/dist/plugin/index.cjs.map +1 -0
- package/dist/plugin/index.d.cts +76 -0
- package/dist/plugin/index.d.ts +76 -0
- package/dist/plugin/index.js +186 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/react/index.d.ts +290 -0
- package/dist/react/index.js +5110 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-CMgpkvBz.d.cts +265 -0
- package/dist/types-CMgpkvBz.d.ts +265 -0
- package/package.json +191 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk6CBIOKZVcjs = require('../chunk-6CBIOKZV.cjs');
|
|
5
|
+
|
|
6
|
+
// src/live.ts
|
|
7
|
+
function initGrabbyLive(options) {
|
|
8
|
+
const opts = { ...options, mode: "live" };
|
|
9
|
+
let loaded = null;
|
|
10
|
+
const load = () => loaded ??= Promise.resolve().then(() => _interopRequireWildcard(require("../core/index.cjs"))).then(({ init }) => init(opts));
|
|
11
|
+
let pending = false;
|
|
12
|
+
try {
|
|
13
|
+
pending = !!localStorage.getItem("grabby:v1:outbox");
|
|
14
|
+
} catch (e) {
|
|
15
|
+
}
|
|
16
|
+
const ready = _chunk6CBIOKZVcjs.consumeFeedbackLink.call(void 0, options.projectKey) || pending ? load() : Promise.resolve(null);
|
|
17
|
+
return {
|
|
18
|
+
ready,
|
|
19
|
+
show: async () => {
|
|
20
|
+
_chunk6CBIOKZVcjs.startFeedbackSession.call(void 0, );
|
|
21
|
+
const api = await load();
|
|
22
|
+
api.show();
|
|
23
|
+
return api;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.initGrabbyLive = initGrabbyLive;
|
|
30
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/githumbi/Documents/angular-grab/packages/grabby/dist/live/index.cjs","../../src/live.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACYO,SAAS,cAAA,CAAe,OAAA,EAAkE;AAC/F,EAAA,MAAM,KAAA,EAA+B,EAAE,GAAG,OAAA,EAAS,IAAA,EAAM,OAAO,CAAA;AAChE,EAAA,IAAI,OAAA,EAAoC,IAAA;AACxC,EAAA,MAAM,KAAA,EAAO,CAAA,EAAA,GAAO,OAAA,IAAW,4DAAA,CAAO,mBAAc,GAAA,CAAE,IAAA,CAAK,CAAC,EAAE,KAAK,CAAA,EAAA,GAAM,IAAA,CAAK,IAAI,CAAC,CAAA;AAEnF,EAAA,IAAI,QAAA,EAAU,KAAA;AACd,EAAA,IAAI;AAAE,IAAA,QAAA,EAAU,CAAC,CAAC,YAAA,CAAa,OAAA,CAAQ,kBAAkB,CAAA;AAAA,EAAG,EAAA,UAAQ;AAAA,EAAe;AAEnF,EAAA,MAAM,MAAA,EAAQ,mDAAA,OAAoB,CAAQ,UAAU,EAAA,GAAK,QAAA,EAAU,IAAA,CAAK,EAAA,EAAI,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAA;AAChG,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,IAAA,EAAM,MAAA,CAAA,EAAA,GAAY;AAChB,MAAA,oDAAA,CAAqB;AACrB,MAAA,MAAM,IAAA,EAAM,MAAM,IAAA,CAAK,CAAA;AACvB,MAAA,GAAA,CAAI,IAAA,CAAK,CAAA;AACT,MAAA,OAAO,GAAA;AAAA,IACT;AAAA,EACF,CAAA;AACF;ADTA;AACE;AACF,wCAAC","file":"/Users/githumbi/Documents/angular-grab/packages/grabby/dist/live/index.cjs","sourcesContent":[null,"import type { GrabbyOptions, GrabbyAPI } from './core/types';\nimport { consumeFeedbackLink, startFeedbackSession } from './core/live/activation';\n\nexport interface LiveHandle {\n /** Start a feedback session and load Grabby, e.g. from your own \"Give feedback\" button. */\n show(): Promise<GrabbyAPI>;\n /** Resolves with the API once loaded, or null while the visitor isn't in a feedback session. */\n ready: Promise<GrabbyAPI | null>;\n}\n\n/**\n * Live mode for bundler users, without the weight: this entry is tiny and\n * imports the rest of Grabby only for visitors who opened a feedback link.\n *\n * import { initGrabbyLive } from '@githumbi/grabby/live';\n * initGrabbyLive({ server: 'https://feedback.example.com', projectKey: 'pk_…' });\n */\nexport function initGrabbyLive(options: Partial<GrabbyOptions> & { server: string }): LiveHandle {\n const opts: Partial<GrabbyOptions> = { ...options, mode: 'live' };\n let loaded: Promise<GrabbyAPI> | null = null;\n const load = () => (loaded ??= import('./core/index').then(({ init }) => init(opts)));\n\n let pending = false;\n try { pending = !!localStorage.getItem('grabby:v1:outbox'); } catch { /* ignore */ }\n\n const ready = consumeFeedbackLink(options.projectKey) || pending ? load() : Promise.resolve(null);\n return {\n ready,\n show: async () => {\n startFeedbackSession();\n const api = await load();\n api.show();\n return api;\n },\n };\n}\n\nexport type { GrabbyOptions, GrabbyAPI };\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { G as GrabbyAPI, a as GrabbyOptions } from '../types-CMgpkvBz.cjs';
|
|
2
|
+
|
|
3
|
+
interface LiveHandle {
|
|
4
|
+
/** Start a feedback session and load Grabby, e.g. from your own "Give feedback" button. */
|
|
5
|
+
show(): Promise<GrabbyAPI>;
|
|
6
|
+
/** Resolves with the API once loaded, or null while the visitor isn't in a feedback session. */
|
|
7
|
+
ready: Promise<GrabbyAPI | null>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Live mode for bundler users, without the weight: this entry is tiny and
|
|
11
|
+
* imports the rest of Grabby only for visitors who opened a feedback link.
|
|
12
|
+
*
|
|
13
|
+
* import { initGrabbyLive } from '@githumbi/grabby/live';
|
|
14
|
+
* initGrabbyLive({ server: 'https://feedback.example.com', projectKey: 'pk_…' });
|
|
15
|
+
*/
|
|
16
|
+
declare function initGrabbyLive(options: Partial<GrabbyOptions> & {
|
|
17
|
+
server: string;
|
|
18
|
+
}): LiveHandle;
|
|
19
|
+
|
|
20
|
+
export { GrabbyAPI, GrabbyOptions, type LiveHandle, initGrabbyLive };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { G as GrabbyAPI, a as GrabbyOptions } from '../types-CMgpkvBz.js';
|
|
2
|
+
|
|
3
|
+
interface LiveHandle {
|
|
4
|
+
/** Start a feedback session and load Grabby, e.g. from your own "Give feedback" button. */
|
|
5
|
+
show(): Promise<GrabbyAPI>;
|
|
6
|
+
/** Resolves with the API once loaded, or null while the visitor isn't in a feedback session. */
|
|
7
|
+
ready: Promise<GrabbyAPI | null>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Live mode for bundler users, without the weight: this entry is tiny and
|
|
11
|
+
* imports the rest of Grabby only for visitors who opened a feedback link.
|
|
12
|
+
*
|
|
13
|
+
* import { initGrabbyLive } from '@githumbi/grabby/live';
|
|
14
|
+
* initGrabbyLive({ server: 'https://feedback.example.com', projectKey: 'pk_…' });
|
|
15
|
+
*/
|
|
16
|
+
declare function initGrabbyLive(options: Partial<GrabbyOptions> & {
|
|
17
|
+
server: string;
|
|
18
|
+
}): LiveHandle;
|
|
19
|
+
|
|
20
|
+
export { GrabbyAPI, GrabbyOptions, type LiveHandle, initGrabbyLive };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
consumeFeedbackLink,
|
|
3
|
+
startFeedbackSession
|
|
4
|
+
} from "../chunk-M3DOFJA7.js";
|
|
5
|
+
|
|
6
|
+
// src/live.ts
|
|
7
|
+
function initGrabbyLive(options) {
|
|
8
|
+
const opts = { ...options, mode: "live" };
|
|
9
|
+
let loaded = null;
|
|
10
|
+
const load = () => loaded ??= import("../core/index.js").then(({ init }) => init(opts));
|
|
11
|
+
let pending = false;
|
|
12
|
+
try {
|
|
13
|
+
pending = !!localStorage.getItem("grabby:v1:outbox");
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
const ready = consumeFeedbackLink(options.projectKey) || pending ? load() : Promise.resolve(null);
|
|
17
|
+
return {
|
|
18
|
+
ready,
|
|
19
|
+
show: async () => {
|
|
20
|
+
startFeedbackSession();
|
|
21
|
+
const api = await load();
|
|
22
|
+
api.show();
|
|
23
|
+
return api;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
initGrabbyLive
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/live.ts"],"sourcesContent":["import type { GrabbyOptions, GrabbyAPI } from './core/types';\nimport { consumeFeedbackLink, startFeedbackSession } from './core/live/activation';\n\nexport interface LiveHandle {\n /** Start a feedback session and load Grabby, e.g. from your own \"Give feedback\" button. */\n show(): Promise<GrabbyAPI>;\n /** Resolves with the API once loaded, or null while the visitor isn't in a feedback session. */\n ready: Promise<GrabbyAPI | null>;\n}\n\n/**\n * Live mode for bundler users, without the weight: this entry is tiny and\n * imports the rest of Grabby only for visitors who opened a feedback link.\n *\n * import { initGrabbyLive } from '@githumbi/grabby/live';\n * initGrabbyLive({ server: 'https://feedback.example.com', projectKey: 'pk_…' });\n */\nexport function initGrabbyLive(options: Partial<GrabbyOptions> & { server: string }): LiveHandle {\n const opts: Partial<GrabbyOptions> = { ...options, mode: 'live' };\n let loaded: Promise<GrabbyAPI> | null = null;\n const load = () => (loaded ??= import('./core/index').then(({ init }) => init(opts)));\n\n let pending = false;\n try { pending = !!localStorage.getItem('grabby:v1:outbox'); } catch { /* ignore */ }\n\n const ready = consumeFeedbackLink(options.projectKey) || pending ? load() : Promise.resolve(null);\n return {\n ready,\n show: async () => {\n startFeedbackSession();\n const api = await load();\n api.show();\n return api;\n },\n };\n}\n\nexport type { GrabbyOptions, GrabbyAPI };\n"],"mappings":";;;;;;AAiBO,SAAS,eAAe,SAAkE;AAC/F,QAAM,OAA+B,EAAE,GAAG,SAAS,MAAM,OAAO;AAChE,MAAI,SAAoC;AACxC,QAAM,OAAO,MAAO,WAAW,OAAO,kBAAc,EAAE,KAAK,CAAC,EAAE,KAAK,MAAM,KAAK,IAAI,CAAC;AAEnF,MAAI,UAAU;AACd,MAAI;AAAE,cAAU,CAAC,CAAC,aAAa,QAAQ,kBAAkB;AAAA,EAAG,QAAQ;AAAA,EAAe;AAEnF,QAAM,QAAQ,oBAAoB,QAAQ,UAAU,KAAK,UAAU,KAAK,IAAI,QAAQ,QAAQ,IAAI;AAChG,SAAO;AAAA,IACL;AAAA,IACA,MAAM,YAAY;AAChB,2BAAqB;AACrB,YAAM,MAAM,MAAM,KAAK;AACvB,UAAI,KAAK;AACT,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{(()=>{let e=document.currentScript;if(!e)return;let n="grabby:v1:live",r=e.dataset.projectKey,o=!1;function l(){try{if(sessionStorage.getItem(n)==="1")return!0}catch{}let t=new URL(location.href).searchParams.get("grabby");return!!t&&(!r||t===r)}function a(){if(o)return;o=!0;let t=document.createElement("script");t.src=e.src.replace(/loader\.global\.js(\?.*)?$/,"grabby.global.js");for(let[g,c]of Object.entries(e.dataset))c!==void 0&&(t.dataset[g]=c);e.nonce&&(t.nonce=e.nonce),e.crossOrigin&&(t.crossOrigin=e.crossOrigin);let i=e.dataset.integrity;i&&(t.integrity=i,t.crossOrigin="anonymous"),document.head.appendChild(t)}let s=!1;try{s=!!localStorage.getItem("grabby:v1:outbox")}catch{}if(e.dataset.mode!=="live"||l()||s){a();return}window.grabby={show(){try{sessionStorage.setItem(n,"1")}catch{}a()}}})();})();
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/plugin/index.ts
|
|
31
|
+
var plugin_exports = {};
|
|
32
|
+
__export(plugin_exports, {
|
|
33
|
+
default: () => plugin_default,
|
|
34
|
+
esbuild: () => esbuild,
|
|
35
|
+
rolldown: () => rolldown,
|
|
36
|
+
rollup: () => rollup,
|
|
37
|
+
rspack: () => rspack,
|
|
38
|
+
stampJsx: () => stampJsx,
|
|
39
|
+
stampVue: () => stampVue,
|
|
40
|
+
unplugin: () => unplugin,
|
|
41
|
+
vite: () => vite,
|
|
42
|
+
webpack: () => webpack
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
45
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
46
|
+
var import_unplugin = require("unplugin");
|
|
47
|
+
|
|
48
|
+
// src/babel-plugin/index.ts
|
|
49
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
50
|
+
|
|
51
|
+
// src/core/adapters/stamp.ts
|
|
52
|
+
var SOURCE_ATTRIBUTE = "data-grabby-loc";
|
|
53
|
+
|
|
54
|
+
// src/babel-plugin/index.ts
|
|
55
|
+
var SKIP = /* @__PURE__ */ new Set(["Fragment", "StrictMode", "Suspense", "SuspenseList", "Profiler"]);
|
|
56
|
+
function grabbyBabelPlugin(options = {}) {
|
|
57
|
+
const attribute = options.attribute ?? SOURCE_ATTRIBUTE;
|
|
58
|
+
const rootDir = options.rootDir ?? process.cwd();
|
|
59
|
+
return function grabbyReactSource({ types: t }) {
|
|
60
|
+
return {
|
|
61
|
+
name: "grabby-react-source",
|
|
62
|
+
visitor: {
|
|
63
|
+
JSXOpeningElement(nodePath, state) {
|
|
64
|
+
const filename = state.filename ?? state.file?.opts?.filename;
|
|
65
|
+
if (!filename || filename.includes("node_modules")) return;
|
|
66
|
+
const node = nodePath.node;
|
|
67
|
+
if (node.name?.type === "JSXNamespacedName") return;
|
|
68
|
+
const name = elementName(node.name);
|
|
69
|
+
if (name && SKIP.has(name)) return;
|
|
70
|
+
const already = node.attributes.some(
|
|
71
|
+
(attr) => attr.type === "JSXAttribute" && attr.name?.name === attribute
|
|
72
|
+
);
|
|
73
|
+
if (already) return;
|
|
74
|
+
const loc = node.loc?.start;
|
|
75
|
+
if (!loc) return;
|
|
76
|
+
const relative = import_node_path.default.relative(rootDir, filename).split(import_node_path.default.sep).join("/");
|
|
77
|
+
const component = componentName(node.name);
|
|
78
|
+
const value = `${relative}:${loc.line}:${loc.column + 1}${component ? `:${component}` : ""}`;
|
|
79
|
+
node.attributes.unshift(
|
|
80
|
+
t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(value))
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function componentName(name) {
|
|
88
|
+
if (!name) return null;
|
|
89
|
+
if (name.type === "JSXIdentifier") return /^[A-Z]/.test(name.name) ? name.name : null;
|
|
90
|
+
if (name.type === "JSXMemberExpression") {
|
|
91
|
+
const object = name.object?.type === "JSXIdentifier" ? name.object.name : componentName(name.object);
|
|
92
|
+
return object && name.property?.name ? `${object}.${name.property.name}` : null;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function elementName(name) {
|
|
97
|
+
if (!name) return null;
|
|
98
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
99
|
+
if (name.type === "JSXMemberExpression") return elementName(name.property);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/plugin/jsx.ts
|
|
104
|
+
var babel = null;
|
|
105
|
+
async function stampJsx(code, file, rootDir, attribute) {
|
|
106
|
+
if (!code.includes("<")) return null;
|
|
107
|
+
babel ??= await import("@babel/core");
|
|
108
|
+
const typescript = /\.tsx?$/.test(file);
|
|
109
|
+
const result = await babel.transformAsync(code, {
|
|
110
|
+
filename: file,
|
|
111
|
+
babelrc: false,
|
|
112
|
+
configFile: false,
|
|
113
|
+
sourceMaps: true,
|
|
114
|
+
compact: false,
|
|
115
|
+
parserOpts: { plugins: typescript ? ["jsx", "typescript", "decorators-legacy"] : ["jsx"] },
|
|
116
|
+
plugins: [grabbyBabelPlugin({ rootDir, attribute })]
|
|
117
|
+
});
|
|
118
|
+
if (!result?.code) return null;
|
|
119
|
+
return { code: result.code, map: result.map };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/plugin/vue.ts
|
|
123
|
+
var NODE_ELEMENT = 1;
|
|
124
|
+
var TAG_ELEMENT = 0;
|
|
125
|
+
var compiler;
|
|
126
|
+
async function loadCompiler() {
|
|
127
|
+
if (compiler !== void 0) return compiler;
|
|
128
|
+
try {
|
|
129
|
+
compiler = await import("vue/compiler-sfc");
|
|
130
|
+
} catch {
|
|
131
|
+
compiler = null;
|
|
132
|
+
}
|
|
133
|
+
return compiler;
|
|
134
|
+
}
|
|
135
|
+
async function stampVue(code, relativePath, attribute = SOURCE_ATTRIBUTE) {
|
|
136
|
+
if (!code.includes("<template")) return null;
|
|
137
|
+
const sfc = await loadCompiler();
|
|
138
|
+
if (!sfc) return null;
|
|
139
|
+
let template;
|
|
140
|
+
try {
|
|
141
|
+
template = sfc.parse(code, { filename: relativePath }).descriptor.template;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
if (!template?.ast || template.lang && template.lang !== "html") return null;
|
|
146
|
+
const inserts = [];
|
|
147
|
+
const visit = (node) => {
|
|
148
|
+
if (node.type === NODE_ELEMENT && node.tagType === TAG_ELEMENT && node.tag) {
|
|
149
|
+
const at = node.loc.start.offset + 1 + node.tag.length;
|
|
150
|
+
const alreadyStamped = node.props?.some((p) => p.name === attribute);
|
|
151
|
+
if (!alreadyStamped && code.slice(node.loc.start.offset, at) === `<${node.tag}`) {
|
|
152
|
+
const { line, column } = node.loc.start;
|
|
153
|
+
inserts.push({ at, text: ` ${attribute}="${relativePath}:${line}:${column}"` });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
node.children?.forEach(visit);
|
|
157
|
+
};
|
|
158
|
+
visit(template.ast);
|
|
159
|
+
if (inserts.length === 0) return null;
|
|
160
|
+
let out = code;
|
|
161
|
+
for (const { at, text } of inserts.sort((a, b) => b.at - a.at)) {
|
|
162
|
+
out = out.slice(0, at) + text + out.slice(at);
|
|
163
|
+
}
|
|
164
|
+
return { code: out, map: null };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/plugin/index.ts
|
|
168
|
+
var DEFAULT_INCLUDE = /\.(jsx|tsx|vue)$/;
|
|
169
|
+
var DEFAULT_EXCLUDE = /[\\/]node_modules[\\/]/;
|
|
170
|
+
function isProduction() {
|
|
171
|
+
return typeof process !== "undefined" && process.env.NODE_ENV === "production";
|
|
172
|
+
}
|
|
173
|
+
var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
174
|
+
let rootDir = options.rootDir ?? process.cwd();
|
|
175
|
+
const include = options.include ?? DEFAULT_INCLUDE;
|
|
176
|
+
const exclude = options.exclude ?? DEFAULT_EXCLUDE;
|
|
177
|
+
let enabled = options.includeSourceInBuild === true || !isProduction();
|
|
178
|
+
const relative = (file) => import_node_path2.default.relative(rootDir, file).split(import_node_path2.default.sep).join("/");
|
|
179
|
+
return {
|
|
180
|
+
name: "grabby-source",
|
|
181
|
+
enforce: "pre",
|
|
182
|
+
transformInclude(id) {
|
|
183
|
+
if (!enabled) return false;
|
|
184
|
+
const [file, query] = id.split("?");
|
|
185
|
+
if (!include.test(file) || exclude.test(file)) return false;
|
|
186
|
+
if (file.endsWith(".vue") && query) return false;
|
|
187
|
+
return true;
|
|
188
|
+
},
|
|
189
|
+
async transform(code, id) {
|
|
190
|
+
const file = id.split("?")[0];
|
|
191
|
+
if (file.endsWith(".vue")) return stampVue(code, relative(file), options.attribute);
|
|
192
|
+
return stampJsx(code, file, rootDir, options.attribute);
|
|
193
|
+
},
|
|
194
|
+
vite: {
|
|
195
|
+
configResolved(config) {
|
|
196
|
+
enabled = options.includeSourceInBuild === true || config.command === "serve";
|
|
197
|
+
if (!options.rootDir) rootDir = config.root;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
webpack(compiler2) {
|
|
201
|
+
enabled = options.includeSourceInBuild === true || compiler2.options.mode !== "production";
|
|
202
|
+
if (!options.rootDir && compiler2.context) rootDir = compiler2.context;
|
|
203
|
+
},
|
|
204
|
+
rspack(compiler2) {
|
|
205
|
+
enabled = options.includeSourceInBuild === true || compiler2.options.mode !== "production";
|
|
206
|
+
if (!options.rootDir && compiler2.context) rootDir = compiler2.context;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
var vite = unplugin.vite;
|
|
211
|
+
var webpack = unplugin.webpack;
|
|
212
|
+
var rspack = unplugin.rspack;
|
|
213
|
+
var rollup = unplugin.rollup;
|
|
214
|
+
var rolldown = unplugin.rolldown;
|
|
215
|
+
var esbuild = unplugin.esbuild;
|
|
216
|
+
var plugin_default = { vite, webpack, rspack, rollup, rolldown, esbuild };
|
|
217
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
218
|
+
0 && (module.exports = {
|
|
219
|
+
esbuild,
|
|
220
|
+
rolldown,
|
|
221
|
+
rollup,
|
|
222
|
+
rspack,
|
|
223
|
+
stampJsx,
|
|
224
|
+
stampVue,
|
|
225
|
+
unplugin,
|
|
226
|
+
vite,
|
|
227
|
+
webpack
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/index.ts","../../src/babel-plugin/index.ts","../../src/core/adapters/stamp.ts","../../src/plugin/jsx.ts","../../src/plugin/vue.ts"],"sourcesContent":["import path from 'node:path';\nimport { createUnplugin } from 'unplugin';\nimport { stampJsx } from './jsx';\nimport { stampVue } from './vue';\n\nexport interface GrabbyPluginOptions {\n /** Paths are stamped relative to this. Default: the bundler's project root */\n rootDir?: string;\n /** Files to stamp. Default: .jsx, .tsx and .vue */\n include?: RegExp;\n /** Files to leave alone. Default: /node_modules/ */\n exclude?: RegExp;\n /** Attribute to stamp. Default: \"data-grabby-loc\" */\n attribute?: string;\n /**\n * Also stamp production builds. Off by default, since stamps expose source\n * paths in the page; turn it on when collecting feedback on a deployed\n * site and you want comments to carry file:line.\n */\n includeSourceInBuild?: boolean;\n}\n\nconst DEFAULT_INCLUDE = /\\.(jsx|tsx|vue)$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n\nfunction isProduction(): boolean {\n return typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n}\n\n/**\n * Adds a `data-grabby-loc=\"file:line:col\"` attribute to every element in\n * JSX/TSX and Vue templates so Grabby can say exactly where an element was\n * written. Svelte needs nothing (its dev build carries locations already)\n * and Angular uses the Grabby builders instead.\n */\nexport const unplugin = createUnplugin<GrabbyPluginOptions | undefined>((options = {}) => {\n // The bundler's own root beats cwd: dev servers are often started from\n // elsewhere (a monorepo root, an IDE), which would give ../../ paths.\n let rootDir = options.rootDir ?? process.cwd();\n const include = options.include ?? DEFAULT_INCLUDE;\n const exclude = options.exclude ?? DEFAULT_EXCLUDE;\n let enabled = options.includeSourceInBuild === true || !isProduction();\n\n const relative = (file: string) => path.relative(rootDir, file).split(path.sep).join('/');\n\n return {\n name: 'grabby-source',\n enforce: 'pre',\n\n transformInclude(id) {\n if (!enabled) return false;\n const [file, query] = id.split('?');\n if (!include.test(file) || exclude.test(file)) return false;\n // Vue sub-requests (?vue&type=style…) are blocks of a file we've already stamped.\n if (file.endsWith('.vue') && query) return false;\n return true;\n },\n\n async transform(code, id) {\n const file = id.split('?')[0];\n if (file.endsWith('.vue')) return stampVue(code, relative(file), options.attribute);\n return stampJsx(code, file, rootDir, options.attribute);\n },\n\n vite: {\n configResolved(config) {\n enabled = options.includeSourceInBuild === true || config.command === 'serve';\n if (!options.rootDir) rootDir = config.root;\n },\n },\n webpack(compiler) {\n enabled = options.includeSourceInBuild === true || compiler.options.mode !== 'production';\n if (!options.rootDir && compiler.context) rootDir = compiler.context;\n },\n rspack(compiler) {\n enabled = options.includeSourceInBuild === true || compiler.options.mode !== 'production';\n if (!options.rootDir && compiler.context) rootDir = compiler.context;\n },\n };\n});\n\n/** `plugins: [grabby.vite(), react()]` */\nexport const vite = unplugin.vite;\n/** `plugins: [grabby.webpack()]` (Next.js: in `next.config.js` → webpack) */\nexport const webpack = unplugin.webpack;\nexport const rspack = unplugin.rspack;\nexport const rollup = unplugin.rollup;\nexport const rolldown = unplugin.rolldown;\nexport const esbuild = unplugin.esbuild;\n\nexport { stampJsx } from './jsx';\nexport { stampVue } from './vue';\n\nexport default { vite, webpack, rspack, rollup, rolldown, esbuild };\n","import path from 'node:path';\nimport { SOURCE_ATTRIBUTE } from '../core/adapters/stamp';\n\nexport interface GrabbyBabelOptions {\n /** Paths are stamped relative to this. Default: process.cwd() */\n rootDir?: string;\n /** Attribute to stamp. Default: \"data-grabby-loc\" */\n attribute?: string;\n}\n\n/** React built-ins that take no DOM props, so stamping them does nothing useful. */\nconst SKIP = new Set(['Fragment', 'StrictMode', 'Suspense', 'SuspenseList', 'Profiler']);\n\n/**\n * Stamps every JSX element with its `file:line:column` so grabby can\n * report where a grabbed element was written.\n *\n * Wire it through @vitejs/plugin-react:\n *\n * react({ babel: { plugins: [grabbyBabelPlugin()] } })\n *\n * The attribute is prepended, so a `{...props}` spread still wins. That's\n * deliberate: for `<Button />` the stamp travels with the props onto the\n * rendered DOM node, and the grab points at the page rather than the library.\n */\nexport function grabbyBabelPlugin(options: GrabbyBabelOptions = {}) {\n const attribute = options.attribute ?? SOURCE_ATTRIBUTE;\n const rootDir = options.rootDir ?? process.cwd();\n\n return function grabbyReactSource({ types: t }: { types: any }) {\n return {\n name: 'grabby-react-source',\n visitor: {\n JSXOpeningElement(nodePath: any, state: any) {\n const filename: string | undefined = state.filename ?? state.file?.opts?.filename;\n if (!filename || filename.includes('node_modules')) return;\n\n const node = nodePath.node;\n if (node.name?.type === 'JSXNamespacedName') return;\n\n const name = elementName(node.name);\n if (name && SKIP.has(name)) return;\n\n const already = node.attributes.some(\n (attr: any) => attr.type === 'JSXAttribute' && attr.name?.name === attribute,\n );\n if (already) return;\n\n const loc = node.loc?.start;\n if (!loc) return;\n\n const relative = path.relative(rootDir, filename).split(path.sep).join('/');\n // Components also record their name: production builds minify\n // function names, so the fiber would only say \"vu\" or \"M\".\n const component = componentName(node.name);\n const value = `${relative}:${loc.line}:${loc.column + 1}${component ? `:${component}` : ''}`;\n\n node.attributes.unshift(\n t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(value)),\n );\n },\n },\n };\n };\n}\n\n/** `Card`, `Table.Row`: capitalised or member JSX names; native tags return null. */\nfunction componentName(name: any): string | null {\n if (!name) return null;\n if (name.type === 'JSXIdentifier') return /^[A-Z]/.test(name.name) ? name.name : null;\n if (name.type === 'JSXMemberExpression') {\n const object = name.object?.type === 'JSXIdentifier' ? name.object.name : componentName(name.object);\n return object && name.property?.name ? `${object}.${name.property.name}` : null;\n }\n return null;\n}\n\nfunction elementName(name: any): string | null {\n if (!name) return null;\n if (name.type === 'JSXIdentifier') return name.name;\n if (name.type === 'JSXMemberExpression') return elementName(name.property);\n return null;\n}\n\nexport default grabbyBabelPlugin;\n","export const SOURCE_ATTRIBUTE = 'data-grabby-loc';\n\nconst LOCATION = /^(.*?):(\\d+):(\\d+)(?::([A-Za-z_$][\\w$.]*))?$/;\n\n/**\n * Reads the `file:line:column` stamp the Grabby build plugin puts on elements\n * (JSX and Vue templates), walking up to the nearest ancestor that has one.\n */\nexport function resolveSource(element: Element): {\n filePath: string | null;\n line: number | null;\n column: number | null;\n} {\n let current: Element | null = element;\n while (current) {\n const raw = current.getAttribute?.(SOURCE_ATTRIBUTE);\n if (raw) return parseLocation(raw);\n current = current.parentElement;\n }\n return { filePath: null, line: null, column: null };\n}\n\nfunction parseLocation(raw: string): {\n filePath: string | null;\n line: number | null;\n column: number | null;\n} {\n const match = LOCATION.exec(raw);\n if (!match) return { filePath: raw, line: null, column: null };\n return { filePath: match[1], line: Number(match[2]), column: Number(match[3]) };\n}\n\nexport interface Stamp {\n file: string;\n line: number | null;\n column: number | null;\n /** The component written at that spot (`<Card …>`), when it was a component. */\n name: string | null;\n}\n\n/** The stamp on this exact element (not an ancestor's), if it has one. */\nexport function ownStamp(element: Element | null): Stamp | null {\n const raw = element?.getAttribute?.(SOURCE_ATTRIBUTE);\n if (!raw) return null;\n const match = LOCATION.exec(raw);\n if (!match) return { file: raw, line: null, column: null, name: null };\n return { file: match[1], line: Number(match[2]), column: Number(match[3]), name: match[4] ?? null };\n}\n\n/** True when the page was built with the Grabby source plugin. */\nexport function hasSourceStamps(): boolean {\n try {\n return document.querySelector(`[${SOURCE_ATTRIBUTE}]`) !== null;\n } catch {\n return false;\n }\n}\n","import { grabbyBabelPlugin } from '../babel-plugin';\n\nlet babel: typeof import('@babel/core') | null = null;\n\n/**\n * Re-emits JSX with a `data-grabby-loc` stamp on every element. It runs its\n * own Babel pass and leaves the JSX in place, so whatever compiles JSX next\n * (Babel, SWC, Oxc, esbuild, Solid's compiler) is unaffected.\n */\nexport async function stampJsx(code: string, file: string, rootDir: string, attribute?: string) {\n if (!code.includes('<')) return null;\n babel ??= await import('@babel/core');\n const typescript = /\\.tsx?$/.test(file);\n const result = await babel.transformAsync(code, {\n filename: file,\n babelrc: false,\n configFile: false,\n sourceMaps: true,\n compact: false,\n parserOpts: { plugins: typescript ? ['jsx', 'typescript', 'decorators-legacy'] : ['jsx'] },\n plugins: [grabbyBabelPlugin({ rootDir, attribute })],\n });\n if (!result?.code) return null;\n return { code: result.code, map: result.map };\n}\n","import { SOURCE_ATTRIBUTE } from '../core/adapters/stamp';\n\ninterface TemplateNode {\n type: number;\n tag?: string;\n tagType?: number;\n loc: { start: { offset: number; line: number; column: number } };\n props?: Array<{ type: number; name: string }>;\n children?: TemplateNode[];\n}\n\nconst NODE_ELEMENT = 1;\nconst TAG_ELEMENT = 0;\n\ntype SfcCompiler = { parse: (code: string, opts: { filename: string }) => { descriptor: { template: { lang?: string; ast?: TemplateNode } | null } } };\nlet compiler: SfcCompiler | null | undefined;\n\nasync function loadCompiler(): Promise<SfcCompiler | null> {\n if (compiler !== undefined) return compiler;\n try {\n compiler = (await import('vue/compiler-sfc')) as unknown as SfcCompiler;\n } catch {\n compiler = null;\n }\n return compiler;\n}\n\n/**\n * Stamps every native element in a Vue SFC template with `file:line:col`.\n * Component tags are left alone: their attributes fall through onto the\n * child's root element and would overwrite the child's own, more precise\n * stamp. Uses the app's own `vue/compiler-sfc`, so it always matches the\n * installed Vue version.\n */\nexport async function stampVue(code: string, relativePath: string, attribute = SOURCE_ATTRIBUTE) {\n if (!code.includes('<template')) return null;\n const sfc = await loadCompiler();\n if (!sfc) return null;\n\n let template;\n try {\n template = sfc.parse(code, { filename: relativePath }).descriptor.template;\n } catch {\n return null;\n }\n // Pug and other template languages have no HTML AST to stamp.\n if (!template?.ast || (template.lang && template.lang !== 'html')) return null;\n\n const inserts: Array<{ at: number; text: string }> = [];\n const visit = (node: TemplateNode) => {\n if (node.type === NODE_ELEMENT && node.tagType === TAG_ELEMENT && node.tag) {\n const at = node.loc.start.offset + 1 + node.tag.length;\n const alreadyStamped = node.props?.some((p) => p.name === attribute);\n // Guard against offsets that don't line up with the source.\n if (!alreadyStamped && code.slice(node.loc.start.offset, at) === `<${node.tag}`) {\n const { line, column } = node.loc.start;\n inserts.push({ at, text: ` ${attribute}=\"${relativePath}:${line}:${column}\"` });\n }\n }\n node.children?.forEach(visit);\n };\n visit(template.ast);\n if (inserts.length === 0) return null;\n\n let out = code;\n for (const { at, text } of inserts.sort((a, b) => b.at - a.at)) {\n out = out.slice(0, at) + text + out.slice(at);\n }\n return { code: out, map: null };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AS,WAAU,OAAO;AAAA,MACzC;AAAA,IACF;AAAA,IACA,QAAQC,WAAU;AAChB,gBAAU,QAAQ,yBAAyB,QAAQA,UAAS,QAAQ,SAAS;AAC7E,UAAI,CAAC,QAAQ,WAAWA,UAAS,QAAS,WAAUA,UAAS;AAAA,IAC/D;AAAA,IACA,OAAOA,WAAU;AACf,gBAAU,QAAQ,yBAAyB,QAAQA,UAAS,QAAQ,SAAS;AAC7E,UAAI,CAAC,QAAQ,WAAWA,UAAS,QAAS,WAAUA,UAAS;AAAA,IAC/D;AAAA,EACF;AACF,CAAC;AAGM,IAAM,OAAO,SAAS;AAEtB,IAAM,UAAU,SAAS;AACzB,IAAM,SAAS,SAAS;AACxB,IAAM,SAAS,SAAS;AACxB,IAAM,WAAW,SAAS;AAC1B,IAAM,UAAU,SAAS;AAKhC,IAAO,iBAAQ,EAAE,MAAM,SAAS,QAAQ,QAAQ,UAAU,QAAQ;","names":["import_node_path","path","path","compiler"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as _esbuild from 'esbuild';
|
|
2
|
+
import * as _rollup from 'rollup';
|
|
3
|
+
import * as _unplugin from 'unplugin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Re-emits JSX with a `data-grabby-loc` stamp on every element. It runs its
|
|
7
|
+
* own Babel pass and leaves the JSX in place, so whatever compiles JSX next
|
|
8
|
+
* (Babel, SWC, Oxc, esbuild, Solid's compiler) is unaffected.
|
|
9
|
+
*/
|
|
10
|
+
declare function stampJsx(code: string, file: string, rootDir: string, attribute?: string): Promise<{
|
|
11
|
+
code: string;
|
|
12
|
+
map: {
|
|
13
|
+
version: number;
|
|
14
|
+
sources: string[];
|
|
15
|
+
names: string[];
|
|
16
|
+
sourceRoot?: string | undefined;
|
|
17
|
+
sourcesContent?: string[] | undefined;
|
|
18
|
+
mappings: string;
|
|
19
|
+
file: string;
|
|
20
|
+
} | null | undefined;
|
|
21
|
+
} | null>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Stamps every native element in a Vue SFC template with `file:line:col`.
|
|
25
|
+
* Component tags are left alone: their attributes fall through onto the
|
|
26
|
+
* child's root element and would overwrite the child's own, more precise
|
|
27
|
+
* stamp. Uses the app's own `vue/compiler-sfc`, so it always matches the
|
|
28
|
+
* installed Vue version.
|
|
29
|
+
*/
|
|
30
|
+
declare function stampVue(code: string, relativePath: string, attribute?: string): Promise<{
|
|
31
|
+
code: string;
|
|
32
|
+
map: null;
|
|
33
|
+
} | null>;
|
|
34
|
+
|
|
35
|
+
interface GrabbyPluginOptions {
|
|
36
|
+
/** Paths are stamped relative to this. Default: the bundler's project root */
|
|
37
|
+
rootDir?: string;
|
|
38
|
+
/** Files to stamp. Default: .jsx, .tsx and .vue */
|
|
39
|
+
include?: RegExp;
|
|
40
|
+
/** Files to leave alone. Default: /node_modules/ */
|
|
41
|
+
exclude?: RegExp;
|
|
42
|
+
/** Attribute to stamp. Default: "data-grabby-loc" */
|
|
43
|
+
attribute?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Also stamp production builds. Off by default, since stamps expose source
|
|
46
|
+
* paths in the page; turn it on when collecting feedback on a deployed
|
|
47
|
+
* site and you want comments to carry file:line.
|
|
48
|
+
*/
|
|
49
|
+
includeSourceInBuild?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Adds a `data-grabby-loc="file:line:col"` attribute to every element in
|
|
53
|
+
* JSX/TSX and Vue templates so Grabby can say exactly where an element was
|
|
54
|
+
* written. Svelte needs nothing (its dev build carries locations already)
|
|
55
|
+
* and Angular uses the Grabby builders instead.
|
|
56
|
+
*/
|
|
57
|
+
declare const unplugin: _unplugin.UnpluginInstance<GrabbyPluginOptions | undefined, boolean>;
|
|
58
|
+
/** `plugins: [grabby.vite(), react()]` */
|
|
59
|
+
declare const vite: (options?: GrabbyPluginOptions | undefined) => _unplugin.VitePlugin<any> | _unplugin.VitePlugin<any>[];
|
|
60
|
+
/** `plugins: [grabby.webpack()]` (Next.js: in `next.config.js` → webpack) */
|
|
61
|
+
declare const webpack: (options?: GrabbyPluginOptions | undefined) => WebpackPluginInstance;
|
|
62
|
+
declare const rspack: (options?: GrabbyPluginOptions | undefined) => RspackPluginInstance;
|
|
63
|
+
declare const rollup: (options?: GrabbyPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
64
|
+
declare const rolldown: (options?: GrabbyPluginOptions | undefined) => _unplugin.RolldownPlugin<any> | _unplugin.RolldownPlugin<any>[];
|
|
65
|
+
declare const esbuild: (options?: GrabbyPluginOptions | undefined) => _esbuild.Plugin;
|
|
66
|
+
|
|
67
|
+
declare const _default: {
|
|
68
|
+
vite: (options?: GrabbyPluginOptions | undefined) => _unplugin.VitePlugin<any> | _unplugin.VitePlugin<any>[];
|
|
69
|
+
webpack: (options?: GrabbyPluginOptions | undefined) => WebpackPluginInstance;
|
|
70
|
+
rspack: (options?: GrabbyPluginOptions | undefined) => RspackPluginInstance;
|
|
71
|
+
rollup: (options?: GrabbyPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
72
|
+
rolldown: (options?: GrabbyPluginOptions | undefined) => _unplugin.RolldownPlugin<any> | _unplugin.RolldownPlugin<any>[];
|
|
73
|
+
esbuild: (options?: GrabbyPluginOptions | undefined) => _esbuild.Plugin;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { type GrabbyPluginOptions, _default as default, esbuild, rolldown, rollup, rspack, stampJsx, stampVue, unplugin, vite, webpack };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as _esbuild from 'esbuild';
|
|
2
|
+
import * as _rollup from 'rollup';
|
|
3
|
+
import * as _unplugin from 'unplugin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Re-emits JSX with a `data-grabby-loc` stamp on every element. It runs its
|
|
7
|
+
* own Babel pass and leaves the JSX in place, so whatever compiles JSX next
|
|
8
|
+
* (Babel, SWC, Oxc, esbuild, Solid's compiler) is unaffected.
|
|
9
|
+
*/
|
|
10
|
+
declare function stampJsx(code: string, file: string, rootDir: string, attribute?: string): Promise<{
|
|
11
|
+
code: string;
|
|
12
|
+
map: {
|
|
13
|
+
version: number;
|
|
14
|
+
sources: string[];
|
|
15
|
+
names: string[];
|
|
16
|
+
sourceRoot?: string | undefined;
|
|
17
|
+
sourcesContent?: string[] | undefined;
|
|
18
|
+
mappings: string;
|
|
19
|
+
file: string;
|
|
20
|
+
} | null | undefined;
|
|
21
|
+
} | null>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Stamps every native element in a Vue SFC template with `file:line:col`.
|
|
25
|
+
* Component tags are left alone: their attributes fall through onto the
|
|
26
|
+
* child's root element and would overwrite the child's own, more precise
|
|
27
|
+
* stamp. Uses the app's own `vue/compiler-sfc`, so it always matches the
|
|
28
|
+
* installed Vue version.
|
|
29
|
+
*/
|
|
30
|
+
declare function stampVue(code: string, relativePath: string, attribute?: string): Promise<{
|
|
31
|
+
code: string;
|
|
32
|
+
map: null;
|
|
33
|
+
} | null>;
|
|
34
|
+
|
|
35
|
+
interface GrabbyPluginOptions {
|
|
36
|
+
/** Paths are stamped relative to this. Default: the bundler's project root */
|
|
37
|
+
rootDir?: string;
|
|
38
|
+
/** Files to stamp. Default: .jsx, .tsx and .vue */
|
|
39
|
+
include?: RegExp;
|
|
40
|
+
/** Files to leave alone. Default: /node_modules/ */
|
|
41
|
+
exclude?: RegExp;
|
|
42
|
+
/** Attribute to stamp. Default: "data-grabby-loc" */
|
|
43
|
+
attribute?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Also stamp production builds. Off by default, since stamps expose source
|
|
46
|
+
* paths in the page; turn it on when collecting feedback on a deployed
|
|
47
|
+
* site and you want comments to carry file:line.
|
|
48
|
+
*/
|
|
49
|
+
includeSourceInBuild?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Adds a `data-grabby-loc="file:line:col"` attribute to every element in
|
|
53
|
+
* JSX/TSX and Vue templates so Grabby can say exactly where an element was
|
|
54
|
+
* written. Svelte needs nothing (its dev build carries locations already)
|
|
55
|
+
* and Angular uses the Grabby builders instead.
|
|
56
|
+
*/
|
|
57
|
+
declare const unplugin: _unplugin.UnpluginInstance<GrabbyPluginOptions | undefined, boolean>;
|
|
58
|
+
/** `plugins: [grabby.vite(), react()]` */
|
|
59
|
+
declare const vite: (options?: GrabbyPluginOptions | undefined) => _unplugin.VitePlugin<any> | _unplugin.VitePlugin<any>[];
|
|
60
|
+
/** `plugins: [grabby.webpack()]` (Next.js: in `next.config.js` → webpack) */
|
|
61
|
+
declare const webpack: (options?: GrabbyPluginOptions | undefined) => WebpackPluginInstance;
|
|
62
|
+
declare const rspack: (options?: GrabbyPluginOptions | undefined) => RspackPluginInstance;
|
|
63
|
+
declare const rollup: (options?: GrabbyPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
64
|
+
declare const rolldown: (options?: GrabbyPluginOptions | undefined) => _unplugin.RolldownPlugin<any> | _unplugin.RolldownPlugin<any>[];
|
|
65
|
+
declare const esbuild: (options?: GrabbyPluginOptions | undefined) => _esbuild.Plugin;
|
|
66
|
+
|
|
67
|
+
declare const _default: {
|
|
68
|
+
vite: (options?: GrabbyPluginOptions | undefined) => _unplugin.VitePlugin<any> | _unplugin.VitePlugin<any>[];
|
|
69
|
+
webpack: (options?: GrabbyPluginOptions | undefined) => WebpackPluginInstance;
|
|
70
|
+
rspack: (options?: GrabbyPluginOptions | undefined) => RspackPluginInstance;
|
|
71
|
+
rollup: (options?: GrabbyPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
72
|
+
rolldown: (options?: GrabbyPluginOptions | undefined) => _unplugin.RolldownPlugin<any> | _unplugin.RolldownPlugin<any>[];
|
|
73
|
+
esbuild: (options?: GrabbyPluginOptions | undefined) => _esbuild.Plugin;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { type GrabbyPluginOptions, _default as default, esbuild, rolldown, rollup, rspack, stampJsx, stampVue, unplugin, vite, webpack };
|