@inspecto-dev/plugin 0.3.6 → 0.3.8
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/README.md +2 -1
- package/dist/astro.cjs +2243 -0
- package/dist/astro.cjs.map +1 -0
- package/dist/astro.d.cts +17 -0
- package/dist/astro.d.ts +17 -0
- package/dist/astro.js +2212 -0
- package/dist/astro.js.map +1 -0
- package/dist/index.cjs +430 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +428 -17
- package/dist/index.js.map +1 -1
- package/dist/legacy/rspack/index.cjs +33 -21
- package/dist/legacy/rspack/index.cjs.map +1 -1
- package/dist/legacy/rspack/index.js +33 -21
- package/dist/legacy/rspack/index.js.map +1 -1
- package/dist/legacy/rspack/loader.cjs +404 -3
- package/dist/legacy/rspack/loader.cjs.map +1 -1
- package/dist/legacy/rspack/loader.js +400 -3
- package/dist/legacy/rspack/loader.js.map +1 -1
- package/dist/legacy/webpack4/index.cjs +22 -10
- package/dist/legacy/webpack4/index.cjs.map +1 -1
- package/dist/legacy/webpack4/index.js +22 -10
- package/dist/legacy/webpack4/index.js.map +1 -1
- package/dist/legacy/webpack4/loader.cjs +404 -3
- package/dist/legacy/webpack4/loader.cjs.map +1 -1
- package/dist/legacy/webpack4/loader.js +400 -3
- package/dist/legacy/webpack4/loader.js.map +1 -1
- package/dist/rollup.cjs +430 -17
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +428 -17
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +430 -17
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.js +428 -17
- package/dist/rspack.js.map +1 -1
- package/dist/vite.cjs +430 -17
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +428 -17
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +430 -17
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +428 -17
- package/dist/webpack.js.map +1 -1
- package/package.json +10 -3
package/dist/rollup.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'vite';
|
|
2
2
|
import 'unplugin';
|
|
3
3
|
export { UnpluginOptions } from '@inspecto-dev/types';
|
|
4
|
-
export { default, esbuildPlugin, rollupPlugin, rspackPlugin, transformJsx, unplugin, vitePlugin, webpackPlugin } from './index.cjs';
|
|
4
|
+
export { default, esbuildPlugin, rollupPlugin, rspackPlugin, transformAstro, transformJsx, transformRouter, unplugin, vitePlugin, webpackPlugin } from './index.cjs';
|
|
5
5
|
import 'magic-string';
|
package/dist/rollup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'vite';
|
|
2
2
|
import 'unplugin';
|
|
3
3
|
export { UnpluginOptions } from '@inspecto-dev/types';
|
|
4
|
-
export { default, esbuildPlugin, rollupPlugin, rspackPlugin, transformJsx, unplugin, vitePlugin, webpackPlugin } from './index.js';
|
|
4
|
+
export { default, esbuildPlugin, rollupPlugin, rspackPlugin, transformAstro, transformJsx, transformRouter, unplugin, vitePlugin, webpackPlugin } from './index.js';
|
|
5
5
|
import 'magic-string';
|
package/dist/rollup.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a,
|
|
2
|
+
get: (a, b2) => (typeof require !== "undefined" ? require : a)[b2]
|
|
3
3
|
}) : x)(function(x) {
|
|
4
4
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
@@ -80,14 +80,14 @@ function extractTransformFilePath(requestId) {
|
|
|
80
80
|
wrapped: filePath !== requestId
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function shouldTransform(filePath,
|
|
83
|
+
function shouldTransform(filePath, _options) {
|
|
84
84
|
const resolvedFilePath = extractTransformFilePath(filePath).filePath;
|
|
85
85
|
if (process.env["NODE_ENV"] === "production") return false;
|
|
86
86
|
if (resolvedFilePath.includes("node_modules")) return false;
|
|
87
87
|
if (resolvedFilePath.startsWith("\0")) return false;
|
|
88
88
|
if (/[/\\](dist|build|\.next|\.nuxt)[/\\]/.test(resolvedFilePath)) return false;
|
|
89
89
|
const ext = resolvedFilePath.split(".").pop()?.toLowerCase();
|
|
90
|
-
if (ext && !["js", "jsx", "ts", "tsx", "mjs", "mts", "vue"].includes(ext)) {
|
|
90
|
+
if (ext && !["js", "jsx", "ts", "tsx", "mjs", "mts", "vue", "svelte", "astro"].includes(ext)) {
|
|
91
91
|
return false;
|
|
92
92
|
}
|
|
93
93
|
return true;
|
|
@@ -248,7 +248,7 @@ function transformVue(options) {
|
|
|
248
248
|
if (escapeTagsSet.has(tagName)) return;
|
|
249
249
|
if (tagName === "template" && node === ast.children[0]) return;
|
|
250
250
|
const alreadyHasAttr = node.props.some(
|
|
251
|
-
(
|
|
251
|
+
(p2) => p2.type === NodeTypes.ATTRIBUTE && p2.name === attributeName
|
|
252
252
|
);
|
|
253
253
|
if (alreadyHasAttr) return;
|
|
254
254
|
const loc = node.loc;
|
|
@@ -285,6 +285,387 @@ function walkElement(node, visitor) {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
// src/transform/transform-svelte.ts
|
|
289
|
+
import MagicString3 from "magic-string";
|
|
290
|
+
import { parse as parseSvelte } from "svelte/compiler";
|
|
291
|
+
function walk(node, visitor) {
|
|
292
|
+
if (!node || typeof node !== "object") return;
|
|
293
|
+
visitor.enter(node);
|
|
294
|
+
for (const key in node) {
|
|
295
|
+
if (key === "parent" || key === "prev" || key === "next") continue;
|
|
296
|
+
const value = node[key];
|
|
297
|
+
if (Array.isArray(value)) {
|
|
298
|
+
value.forEach((child) => {
|
|
299
|
+
if (child && typeof child === "object") walk(child, visitor);
|
|
300
|
+
});
|
|
301
|
+
} else if (value && typeof value === "object") {
|
|
302
|
+
walk(value, visitor);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function transformSvelte(options) {
|
|
307
|
+
const { filePath, source, escapeTags, attributeName = "data-inspecto" } = options;
|
|
308
|
+
const escapeTagsSet = buildEscapeTagsSet(escapeTags);
|
|
309
|
+
let replacedContent = source;
|
|
310
|
+
const scriptRegex = /<script(?:\s+[a-zA-Z-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]*))?)?>[\s\S]*?<\/script>/gi;
|
|
311
|
+
const styleRegex = /<style(?:\s+[a-zA-Z-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]*))?)?>[\s\S]*?<\/style>/gi;
|
|
312
|
+
const scriptMatches = source.match(scriptRegex) || [];
|
|
313
|
+
const styleMatches = source.match(styleRegex) || [];
|
|
314
|
+
[...scriptMatches, ...styleMatches].forEach((match) => {
|
|
315
|
+
replacedContent = replacedContent.replace(match, " ".repeat(match.length));
|
|
316
|
+
});
|
|
317
|
+
let ast;
|
|
318
|
+
try {
|
|
319
|
+
ast = parseSvelte(replacedContent);
|
|
320
|
+
} catch {
|
|
321
|
+
return { code: source, map: null, changed: false };
|
|
322
|
+
}
|
|
323
|
+
const s2 = new MagicString3(source);
|
|
324
|
+
let changed = false;
|
|
325
|
+
function countLines(text, position) {
|
|
326
|
+
let lines = 0;
|
|
327
|
+
for (let i2 = 0; i2 < position; i2++) {
|
|
328
|
+
if (text[i2] === "\n") lines++;
|
|
329
|
+
}
|
|
330
|
+
return lines;
|
|
331
|
+
}
|
|
332
|
+
const root = ast.html || ast.fragment || ast;
|
|
333
|
+
walk(root, {
|
|
334
|
+
enter(node) {
|
|
335
|
+
if (node.type === "Element" || node.type === "RegularElement" || node.type === "InlineComponent" || node.type === "Component") {
|
|
336
|
+
const tagName = node.name || "";
|
|
337
|
+
if (tagName && !escapeTagsSet.has(tagName.toLowerCase()) && !node.attributes?.some((attr) => attr.name === attributeName)) {
|
|
338
|
+
const insertPosition = node.start + tagName.length + 1;
|
|
339
|
+
const line = countLines(source, node.start) + 1;
|
|
340
|
+
const lastNewLine = source.lastIndexOf("\n", node.start - 1);
|
|
341
|
+
const column = lastNewLine === -1 ? node.start + 1 : node.start - lastNewLine;
|
|
342
|
+
const attrValue = formatAttrValue(filePath, line, column);
|
|
343
|
+
const addition = ` ${attributeName}="${attrValue}"`;
|
|
344
|
+
s2.appendLeft(insertPosition, addition);
|
|
345
|
+
changed = true;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
return {
|
|
351
|
+
code: s2.toString(),
|
|
352
|
+
map: changed ? s2.generateMap({ source: filePath, includeContent: true }) : null,
|
|
353
|
+
changed
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/transform/transform-astro.ts
|
|
358
|
+
import MagicString4 from "magic-string";
|
|
359
|
+
|
|
360
|
+
// ../../node_modules/.pnpm/@astrojs+compiler@3.0.1/node_modules/@astrojs/compiler/dist/chunk-W5DTLHV4.js
|
|
361
|
+
import g from "crypto";
|
|
362
|
+
import _ from "fs";
|
|
363
|
+
import { TextDecoder as b, TextEncoder as v } from "util";
|
|
364
|
+
globalThis.fs || Object.defineProperty(globalThis, "fs", { value: _ });
|
|
365
|
+
globalThis.process || Object.defineProperties(globalThis, "process", { value: process });
|
|
366
|
+
globalThis.crypto || Object.defineProperty(globalThis, "crypto", { value: g.webcrypto ? g.webcrypto : { getRandomValues(m2) {
|
|
367
|
+
return g.randomFillSync(m2);
|
|
368
|
+
} } });
|
|
369
|
+
globalThis.performance || Object.defineProperty(globalThis, "performance", { value: { now() {
|
|
370
|
+
let [m2, o] = process.hrtime();
|
|
371
|
+
return m2 * 1e3 + o / 1e6;
|
|
372
|
+
} } });
|
|
373
|
+
var y = new v("utf-8");
|
|
374
|
+
var w = new b("utf-8");
|
|
375
|
+
var d = class {
|
|
376
|
+
constructor() {
|
|
377
|
+
this.argv = ["js"], this.env = {}, this.exit = (t) => {
|
|
378
|
+
t !== 0 && console.warn("exit code:", t);
|
|
379
|
+
}, this._exitPromise = new Promise((t) => {
|
|
380
|
+
this._resolveExitPromise = t;
|
|
381
|
+
}), this._pendingEvent = null, this._scheduledTimeouts = /* @__PURE__ */ new Map(), this._nextCallbackTimeoutID = 1;
|
|
382
|
+
let o = (t, e) => {
|
|
383
|
+
this.mem.setUint32(t + 0, e, true), this.mem.setUint32(t + 4, Math.floor(e / 4294967296), true);
|
|
384
|
+
}, n = (t) => {
|
|
385
|
+
let e = this.mem.getUint32(t + 0, true), s2 = this.mem.getInt32(t + 4, true);
|
|
386
|
+
return e + s2 * 4294967296;
|
|
387
|
+
}, r = (t) => {
|
|
388
|
+
let e = this.mem.getFloat64(t, true);
|
|
389
|
+
if (e === 0) return;
|
|
390
|
+
if (!isNaN(e)) return e;
|
|
391
|
+
let s2 = this.mem.getUint32(t, true);
|
|
392
|
+
return this._values[s2];
|
|
393
|
+
}, l = (t, e) => {
|
|
394
|
+
if (typeof e == "number" && e !== 0) {
|
|
395
|
+
if (isNaN(e)) {
|
|
396
|
+
this.mem.setUint32(t + 4, 2146959360, true), this.mem.setUint32(t, 0, true);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
this.mem.setFloat64(t, e, true);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (e === void 0) {
|
|
403
|
+
this.mem.setFloat64(t, 0, true);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
let i2 = this._ids.get(e);
|
|
407
|
+
i2 === void 0 && (i2 = this._idPool.pop(), i2 === void 0 && (i2 = this._values.length), this._values[i2] = e, this._goRefCounts[i2] = 0, this._ids.set(e, i2)), this._goRefCounts[i2]++;
|
|
408
|
+
let a = 0;
|
|
409
|
+
switch (typeof e) {
|
|
410
|
+
case "object":
|
|
411
|
+
e !== null && (a = 1);
|
|
412
|
+
break;
|
|
413
|
+
case "string":
|
|
414
|
+
a = 2;
|
|
415
|
+
break;
|
|
416
|
+
case "symbol":
|
|
417
|
+
a = 3;
|
|
418
|
+
break;
|
|
419
|
+
case "function":
|
|
420
|
+
a = 4;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
this.mem.setUint32(t + 4, 2146959360 | a, true), this.mem.setUint32(t, i2, true);
|
|
424
|
+
}, c = (t) => {
|
|
425
|
+
let e = n(t + 0), s2 = n(t + 8);
|
|
426
|
+
return new Uint8Array(this._inst.exports.mem.buffer, e, s2);
|
|
427
|
+
}, f2 = (t) => {
|
|
428
|
+
let e = n(t + 0), s2 = n(t + 8), i2 = new Array(s2);
|
|
429
|
+
for (let a = 0; a < s2; a++) i2[a] = r(e + a * 8);
|
|
430
|
+
return i2;
|
|
431
|
+
}, u = (t) => {
|
|
432
|
+
let e = n(t + 0), s2 = n(t + 8);
|
|
433
|
+
return w.decode(new DataView(this._inst.exports.mem.buffer, e, s2));
|
|
434
|
+
}, h = Date.now() - performance.now();
|
|
435
|
+
this.importObject = { gojs: { "runtime.wasmExit": (t) => {
|
|
436
|
+
t >>>= 0;
|
|
437
|
+
let e = this.mem.getInt32(t + 8, true);
|
|
438
|
+
this.exited = true, delete this._inst, delete this._values, delete this._goRefCounts, delete this._ids, delete this._idPool, this.exit(e);
|
|
439
|
+
}, "runtime.wasmWrite": (t) => {
|
|
440
|
+
t >>>= 0;
|
|
441
|
+
let e = n(t + 8), s2 = n(t + 16), i2 = this.mem.getInt32(t + 24, true);
|
|
442
|
+
_.writeSync(e, new Uint8Array(this._inst.exports.mem.buffer, s2, i2));
|
|
443
|
+
}, "runtime.resetMemoryDataView": (t) => {
|
|
444
|
+
t >>>= 0, this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
445
|
+
}, "runtime.nanotime1": (t) => {
|
|
446
|
+
t >>>= 0, o(t + 8, (h + performance.now()) * 1e6);
|
|
447
|
+
}, "runtime.walltime": (t) => {
|
|
448
|
+
t >>>= 0;
|
|
449
|
+
let e = (/* @__PURE__ */ new Date()).getTime();
|
|
450
|
+
o(t + 8, e / 1e3), this.mem.setInt32(t + 16, e % 1e3 * 1e6, true);
|
|
451
|
+
}, "runtime.scheduleTimeoutEvent": (t) => {
|
|
452
|
+
t >>>= 0;
|
|
453
|
+
let e = this._nextCallbackTimeoutID;
|
|
454
|
+
this._nextCallbackTimeoutID++, this._scheduledTimeouts.set(e, setTimeout(() => {
|
|
455
|
+
for (this._resume(); this._scheduledTimeouts.has(e); ) console.warn("scheduleTimeoutEvent: missed timeout event"), this._resume();
|
|
456
|
+
}, n(t + 8) + 1)), this.mem.setInt32(t + 16, e, true);
|
|
457
|
+
}, "runtime.clearTimeoutEvent": (t) => {
|
|
458
|
+
t >>>= 0;
|
|
459
|
+
let e = this.mem.getInt32(t + 8, true);
|
|
460
|
+
clearTimeout(this._scheduledTimeouts.get(e)), this._scheduledTimeouts.delete(e);
|
|
461
|
+
}, "runtime.getRandomData": (t) => {
|
|
462
|
+
t >>>= 0, globalThis.crypto.getRandomValues(c(t + 8));
|
|
463
|
+
}, "syscall/js.finalizeRef": (t) => {
|
|
464
|
+
t >>>= 0;
|
|
465
|
+
let e = this.mem.getUint32(t + 8, true);
|
|
466
|
+
if (this._goRefCounts[e]--, this._goRefCounts[e] === 0) {
|
|
467
|
+
let s2 = this._values[e];
|
|
468
|
+
this._values[e] = null, this._ids.delete(s2), this._idPool.push(e);
|
|
469
|
+
}
|
|
470
|
+
}, "syscall/js.stringVal": (t) => {
|
|
471
|
+
t >>>= 0, l(t + 24, u(t + 8));
|
|
472
|
+
}, "syscall/js.valueGet": (t) => {
|
|
473
|
+
t >>>= 0;
|
|
474
|
+
let e = Reflect.get(r(t + 8), u(t + 16));
|
|
475
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 32, e);
|
|
476
|
+
}, "syscall/js.valueSet": (t) => {
|
|
477
|
+
t >>>= 0, Reflect.set(r(t + 8), u(t + 16), r(t + 32));
|
|
478
|
+
}, "syscall/js.valueDelete": (t) => {
|
|
479
|
+
t >>>= 0, Reflect.deleteProperty(r(t + 8), u(t + 16));
|
|
480
|
+
}, "syscall/js.valueIndex": (t) => {
|
|
481
|
+
t >>>= 0, l(t + 24, Reflect.get(r(t + 8), n(t + 16)));
|
|
482
|
+
}, "syscall/js.valueSetIndex": (t) => {
|
|
483
|
+
t >>>= 0, Reflect.set(r(t + 8), n(t + 16), r(t + 24));
|
|
484
|
+
}, "syscall/js.valueCall": (t) => {
|
|
485
|
+
t >>>= 0;
|
|
486
|
+
try {
|
|
487
|
+
let e = r(t + 8), s2 = Reflect.get(e, u(t + 16)), i2 = f2(t + 32), a = Reflect.apply(s2, e, i2);
|
|
488
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 56, a), this.mem.setUint8(t + 64, 1);
|
|
489
|
+
} catch (e) {
|
|
490
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 56, e), this.mem.setUint8(t + 64, 0);
|
|
491
|
+
}
|
|
492
|
+
}, "syscall/js.valueInvoke": (t) => {
|
|
493
|
+
t >>>= 0;
|
|
494
|
+
try {
|
|
495
|
+
let e = r(t + 8), s2 = f2(t + 16), i2 = Reflect.apply(e, void 0, s2);
|
|
496
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 40, i2), this.mem.setUint8(t + 48, 1);
|
|
497
|
+
} catch (e) {
|
|
498
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 40, e), this.mem.setUint8(t + 48, 0);
|
|
499
|
+
}
|
|
500
|
+
}, "syscall/js.valueNew": (t) => {
|
|
501
|
+
t >>>= 0;
|
|
502
|
+
try {
|
|
503
|
+
let e = r(t + 8), s2 = f2(t + 16), i2 = Reflect.construct(e, s2);
|
|
504
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 40, i2), this.mem.setUint8(t + 48, 1);
|
|
505
|
+
} catch (e) {
|
|
506
|
+
t = this._inst.exports.getsp() >>> 0, l(t + 40, e), this.mem.setUint8(t + 48, 0);
|
|
507
|
+
}
|
|
508
|
+
}, "syscall/js.valueLength": (t) => {
|
|
509
|
+
t >>>= 0, o(t + 16, Number.parseInt(r(t + 8).length));
|
|
510
|
+
}, "syscall/js.valuePrepareString": (t) => {
|
|
511
|
+
t >>>= 0;
|
|
512
|
+
let e = y.encode(String(r(t + 8)));
|
|
513
|
+
l(t + 16, e), o(t + 24, e.length);
|
|
514
|
+
}, "syscall/js.valueLoadString": (t) => {
|
|
515
|
+
t >>>= 0;
|
|
516
|
+
let e = r(t + 8);
|
|
517
|
+
c(t + 16).set(e);
|
|
518
|
+
}, "syscall/js.valueInstanceOf": (t) => {
|
|
519
|
+
t >>>= 0, this.mem.setUint8(t + 24, r(t + 8) instanceof r(t + 16) ? 1 : 0);
|
|
520
|
+
}, "syscall/js.copyBytesToGo": (t) => {
|
|
521
|
+
t >>>= 0;
|
|
522
|
+
let e = c(t + 8), s2 = r(t + 32);
|
|
523
|
+
if (!(s2 instanceof Uint8Array || s2 instanceof Uint8ClampedArray)) {
|
|
524
|
+
this.mem.setUint8(t + 48, 0);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
let i2 = s2.subarray(0, e.length);
|
|
528
|
+
e.set(i2), o(t + 40, i2.length), this.mem.setUint8(t + 48, 1);
|
|
529
|
+
}, "syscall/js.copyBytesToJS": (t) => {
|
|
530
|
+
t >>>= 0;
|
|
531
|
+
let e = r(t + 8), s2 = c(t + 16);
|
|
532
|
+
if (!(e instanceof Uint8Array || e instanceof Uint8ClampedArray)) {
|
|
533
|
+
this.mem.setUint8(t + 48, 0);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
let i2 = s2.subarray(0, e.length);
|
|
537
|
+
e.set(i2), o(t + 40, i2.length), this.mem.setUint8(t + 48, 1);
|
|
538
|
+
}, debug: (t) => {
|
|
539
|
+
console.log(t);
|
|
540
|
+
} } };
|
|
541
|
+
}
|
|
542
|
+
async run(o) {
|
|
543
|
+
if (!(o instanceof WebAssembly.Instance)) throw new Error("Go.run: WebAssembly.Instance expected");
|
|
544
|
+
this._inst = o, this.mem = new DataView(this._inst.exports.mem.buffer), this._values = [Number.NaN, 0, null, true, false, globalThis, this], this._goRefCounts = new Array(this._values.length).fill(Number.POSITIVE_INFINITY), this._ids = /* @__PURE__ */ new Map([[0, 1], [null, 2], [true, 3], [false, 4], [globalThis, 5], [this, 6]]), this._idPool = [], this.exited = false;
|
|
545
|
+
let n = 4096, r = (h) => {
|
|
546
|
+
let t = n, e = y.encode(`${h}\0`);
|
|
547
|
+
return new Uint8Array(this.mem.buffer, n, e.length).set(e), n += e.length, n % 8 !== 0 && (n += 8 - n % 8), t;
|
|
548
|
+
}, l = this.argv.length, c = [];
|
|
549
|
+
this.argv.forEach((h) => {
|
|
550
|
+
c.push(r(h));
|
|
551
|
+
}), c.push(0), Object.keys(this.env).sort().forEach((h) => {
|
|
552
|
+
c.push(r(`${h}=${this.env[h]}`));
|
|
553
|
+
}), c.push(0);
|
|
554
|
+
let u = n;
|
|
555
|
+
c.forEach((h) => {
|
|
556
|
+
this.mem.setUint32(n, h, true), this.mem.setUint32(n + 4, 0, true), n += 8;
|
|
557
|
+
}), this._inst.exports.run(l, u), this.exited && this._resolveExitPromise(), await this._exitPromise;
|
|
558
|
+
}
|
|
559
|
+
_resume() {
|
|
560
|
+
if (this.exited) throw new Error("Go program has already exited");
|
|
561
|
+
this._inst.exports.resume(), this.exited && this._resolveExitPromise();
|
|
562
|
+
}
|
|
563
|
+
_makeFuncWrapper(o) {
|
|
564
|
+
let n = this;
|
|
565
|
+
return function() {
|
|
566
|
+
let r = { id: o, this: this, args: arguments };
|
|
567
|
+
return n._pendingEvent = r, n._resume(), r.result;
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// ../../node_modules/.pnpm/@astrojs+compiler@3.0.1/node_modules/@astrojs/compiler/dist/node/sync.js
|
|
573
|
+
import { readFileSync as p } from "fs";
|
|
574
|
+
import { fileURLToPath as m } from "url";
|
|
575
|
+
function i() {
|
|
576
|
+
return s || (s = f()), s;
|
|
577
|
+
}
|
|
578
|
+
var s;
|
|
579
|
+
var w2 = (e, t) => i().parse(e, t);
|
|
580
|
+
function f() {
|
|
581
|
+
let e = new d(), t = v2(m(new URL("../astro.wasm", import.meta.url)), e.importObject);
|
|
582
|
+
e.run(t);
|
|
583
|
+
let o = globalThis["@astrojs/compiler"];
|
|
584
|
+
return { transform: (n, a) => {
|
|
585
|
+
try {
|
|
586
|
+
return o.transform(n, a || {});
|
|
587
|
+
} catch (r) {
|
|
588
|
+
throw s = void 0, r;
|
|
589
|
+
}
|
|
590
|
+
}, parse: (n, a) => {
|
|
591
|
+
try {
|
|
592
|
+
let r = o.parse(n, a || {});
|
|
593
|
+
return { ...r, ast: JSON.parse(r.ast) };
|
|
594
|
+
} catch (r) {
|
|
595
|
+
throw s = void 0, r;
|
|
596
|
+
}
|
|
597
|
+
}, convertToTSX: (n, a) => {
|
|
598
|
+
try {
|
|
599
|
+
let r = o.convertToTSX(n, a || {});
|
|
600
|
+
return { ...r, map: JSON.parse(r.map) };
|
|
601
|
+
} catch (r) {
|
|
602
|
+
throw s = void 0, r;
|
|
603
|
+
}
|
|
604
|
+
} };
|
|
605
|
+
}
|
|
606
|
+
function v2(e, t) {
|
|
607
|
+
let o = p(e);
|
|
608
|
+
return new WebAssembly.Instance(new WebAssembly.Module(o), t);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/transform/transform-astro.ts
|
|
612
|
+
function walk2(node, visitor) {
|
|
613
|
+
if (!node || typeof node !== "object") return;
|
|
614
|
+
visitor.enter(node);
|
|
615
|
+
if (Array.isArray(node.children)) {
|
|
616
|
+
for (const child of node.children) {
|
|
617
|
+
walk2(child, visitor);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function transformAstro(options) {
|
|
622
|
+
const { filePath, source, escapeTags, attributeName = "data-inspecto" } = options;
|
|
623
|
+
const escapeTagsSet = buildEscapeTagsSet(escapeTags);
|
|
624
|
+
let ast;
|
|
625
|
+
try {
|
|
626
|
+
ast = w2(source, { position: true }).ast;
|
|
627
|
+
} catch (_err) {
|
|
628
|
+
return { code: source, map: null, changed: false };
|
|
629
|
+
}
|
|
630
|
+
const s2 = new MagicString4(source);
|
|
631
|
+
let changed = false;
|
|
632
|
+
walk2(ast, {
|
|
633
|
+
enter(node) {
|
|
634
|
+
if (node.type === "element" || node.type === "component") {
|
|
635
|
+
const tagName = node.name;
|
|
636
|
+
if (tagName && !escapeTagsSet.has(tagName) && !node.attributes?.some((attr) => attr.name === attributeName)) {
|
|
637
|
+
const startOffset = node.position?.start?.offset ?? -1;
|
|
638
|
+
if (startOffset === -1) return;
|
|
639
|
+
let tagStartIndex = startOffset;
|
|
640
|
+
while (tagStartIndex >= 0 && source[tagStartIndex] !== "<") {
|
|
641
|
+
tagStartIndex--;
|
|
642
|
+
}
|
|
643
|
+
if (tagStartIndex >= 0) {
|
|
644
|
+
const substringAfterTag = source.substring(tagStartIndex);
|
|
645
|
+
const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
646
|
+
const strictRegex = new RegExp(`^<\\s*${escapedTagName}(?=\\s|/|>)`, "i");
|
|
647
|
+
const strictMatch = substringAfterTag.match(strictRegex);
|
|
648
|
+
if (strictMatch) {
|
|
649
|
+
const insertPosition = tagStartIndex + strictMatch[0].length;
|
|
650
|
+
const line = node.position.start.line;
|
|
651
|
+
const column = node.position.start.column;
|
|
652
|
+
const attrValue = formatAttrValue(filePath, line, column);
|
|
653
|
+
const addition = ` ${attributeName}="${attrValue}"`;
|
|
654
|
+
s2.appendLeft(insertPosition, addition);
|
|
655
|
+
changed = true;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
return {
|
|
663
|
+
code: s2.toString(),
|
|
664
|
+
map: changed ? s2.generateMap({ source: filePath, includeContent: true }) : null,
|
|
665
|
+
changed
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
288
669
|
// src/transform/index.ts
|
|
289
670
|
function transformRouter(options) {
|
|
290
671
|
const { filePath, source, projectRoot, pluginOptions } = options;
|
|
@@ -309,6 +690,22 @@ function transformRouter(options) {
|
|
|
309
690
|
attributeName: pluginOptions.attributeName
|
|
310
691
|
});
|
|
311
692
|
}
|
|
693
|
+
if (ext === ".svelte") {
|
|
694
|
+
return transformSvelte({
|
|
695
|
+
filePath,
|
|
696
|
+
source,
|
|
697
|
+
escapeTags: pluginOptions.escapeTags,
|
|
698
|
+
attributeName: pluginOptions.attributeName
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
if (ext === ".astro") {
|
|
702
|
+
return transformAstro({
|
|
703
|
+
filePath,
|
|
704
|
+
source,
|
|
705
|
+
escapeTags: pluginOptions.escapeTags,
|
|
706
|
+
attributeName: pluginOptions.attributeName
|
|
707
|
+
});
|
|
708
|
+
}
|
|
312
709
|
return null;
|
|
313
710
|
}
|
|
314
711
|
|
|
@@ -451,7 +848,7 @@ function isDebugEnabled(namespace) {
|
|
|
451
848
|
if (typeof process === "undefined" || !process.env) return false;
|
|
452
849
|
const debugEnv = process.env.DEBUG;
|
|
453
850
|
if (!debugEnv) return false;
|
|
454
|
-
const namespaces = debugEnv.split(",").map((
|
|
851
|
+
const namespaces = debugEnv.split(",").map((s2) => s2.trim());
|
|
455
852
|
for (const ns of namespaces) {
|
|
456
853
|
if (ns === "*") return true;
|
|
457
854
|
if (ns.endsWith("*")) {
|
|
@@ -607,7 +1004,7 @@ function readJsonSafely(filePath) {
|
|
|
607
1004
|
}
|
|
608
1005
|
return null;
|
|
609
1006
|
}
|
|
610
|
-
function resolveTargetTool(config,
|
|
1007
|
+
function resolveTargetTool(config, _ide = "vscode") {
|
|
611
1008
|
const defaultProvider = config["provider.default"];
|
|
612
1009
|
if (defaultProvider) {
|
|
613
1010
|
const tool = defaultProvider.split(".")[0];
|
|
@@ -715,7 +1112,7 @@ function resolveIntents(serverPrompts) {
|
|
|
715
1112
|
configLogger.warn(`Intent "${item.id}" is missing required "aiIntent".`);
|
|
716
1113
|
continue;
|
|
717
1114
|
}
|
|
718
|
-
const existingIdx = merged.findIndex((
|
|
1115
|
+
const existingIdx = merged.findIndex((i2) => i2.id === item.id);
|
|
719
1116
|
if (existingIdx !== -1) {
|
|
720
1117
|
if (item.enabled === false) {
|
|
721
1118
|
merged.splice(existingIdx, 1);
|
|
@@ -759,7 +1156,7 @@ function watchConfig(onReload, cwd = process.cwd(), gitRoot) {
|
|
|
759
1156
|
});
|
|
760
1157
|
watcher.unref();
|
|
761
1158
|
watchers.push(watcher);
|
|
762
|
-
} catch (
|
|
1159
|
+
} catch (_e) {
|
|
763
1160
|
}
|
|
764
1161
|
}
|
|
765
1162
|
}
|
|
@@ -800,6 +1197,9 @@ function launchURI(uri) {
|
|
|
800
1197
|
}
|
|
801
1198
|
|
|
802
1199
|
// src/server/dispatch-runtime.ts
|
|
1200
|
+
function normalizeIdeToken(value) {
|
|
1201
|
+
return (value ?? "").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1202
|
+
}
|
|
803
1203
|
function resolvePromptDispatchRuntime(state) {
|
|
804
1204
|
const userConfig = loadUserConfigSync(false, state.cwd, state.projectRoot);
|
|
805
1205
|
const resolvedTarget = resolveTargetTool(userConfig);
|
|
@@ -841,7 +1241,11 @@ function dispatchPromptThroughIde(runtime, payload) {
|
|
|
841
1241
|
};
|
|
842
1242
|
}
|
|
843
1243
|
function resolveFinalIde(configuredIde, activeIde, activeIdeScheme) {
|
|
844
|
-
|
|
1244
|
+
const configuredIdeMatchesActiveScheme = Boolean(configuredIde) && Boolean(activeIdeScheme) && normalizeIdeToken(configuredIde) === normalizeIdeToken(activeIdeScheme);
|
|
1245
|
+
if (configuredIdeMatchesActiveScheme) {
|
|
1246
|
+
return activeIdeScheme;
|
|
1247
|
+
}
|
|
1248
|
+
if (configuredIde && activeIdeScheme && normalizeIdeToken(activeIdeScheme).includes(normalizeIdeToken(configuredIde)) === false) {
|
|
845
1249
|
return configuredIde;
|
|
846
1250
|
}
|
|
847
1251
|
return configuredIde || activeIdeScheme || activeIde || "vscode";
|
|
@@ -1151,8 +1555,12 @@ var VSCODE_FAMILY_SCHEMES = [
|
|
|
1151
1555
|
"vscodium",
|
|
1152
1556
|
"codebuddy",
|
|
1153
1557
|
"codebuddy-cn",
|
|
1558
|
+
"codebuddycn",
|
|
1154
1559
|
"antigravity"
|
|
1155
1560
|
];
|
|
1561
|
+
function normalizeIdeToken2(value) {
|
|
1562
|
+
return (value ?? "").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1563
|
+
}
|
|
1156
1564
|
function handleOpenFileRequest(body, serverState2) {
|
|
1157
1565
|
const absolutePath = resolveWorkspacePath(body.file, serverState2.cwd);
|
|
1158
1566
|
assertPathWithinIdeOpenScope(absolutePath, serverState2.projectRoot);
|
|
@@ -1160,8 +1568,9 @@ function handleOpenFileRequest(body, serverState2) {
|
|
|
1160
1568
|
const configuredIde = userConfig.ide;
|
|
1161
1569
|
const activeIde = serverState2.ideInfo?.ide;
|
|
1162
1570
|
const activeIdeScheme = serverState2.ideInfo?.scheme;
|
|
1163
|
-
const
|
|
1164
|
-
|
|
1571
|
+
const configuredIdeMatchesActiveScheme = Boolean(configuredIde) && Boolean(activeIdeScheme) && normalizeIdeToken2(configuredIde) === normalizeIdeToken2(activeIdeScheme);
|
|
1572
|
+
const rawEditorHint = configuredIdeMatchesActiveScheme ? activeIdeScheme : configuredIde || activeIde || activeIdeScheme || "code";
|
|
1573
|
+
if (configuredIde && activeIdeScheme && normalizeIdeToken2(activeIdeScheme).includes(normalizeIdeToken2(configuredIde)) === false) {
|
|
1165
1574
|
serverLogger2.warn(
|
|
1166
1575
|
`Active IDE is ${activeIdeScheme}, but config forces ${configuredIde}. Using configured IDE.`
|
|
1167
1576
|
);
|
|
@@ -1306,14 +1715,14 @@ async function startServer() {
|
|
|
1306
1715
|
if (fs5.existsSync(portFile)) {
|
|
1307
1716
|
try {
|
|
1308
1717
|
portData = JSON.parse(fs5.readFileSync(portFile, "utf-8"));
|
|
1309
|
-
} catch (
|
|
1718
|
+
} catch (_e) {
|
|
1310
1719
|
}
|
|
1311
1720
|
}
|
|
1312
1721
|
const rootHash = crypto2.createHash("md5").update(serverState.projectRoot).digest("hex");
|
|
1313
1722
|
portData[rootHash] = port;
|
|
1314
1723
|
fs5.writeFileSync(portFile, JSON.stringify(portData, null, 2), "utf-8");
|
|
1315
|
-
} catch (
|
|
1316
|
-
serverLogger4.warn("Failed to write port file:",
|
|
1724
|
+
} catch (_e) {
|
|
1725
|
+
serverLogger4.warn("Failed to write port file:", _e);
|
|
1317
1726
|
}
|
|
1318
1727
|
process.once("exit", () => {
|
|
1319
1728
|
try {
|
|
@@ -1386,7 +1795,7 @@ async function handleRequest(url, req, res) {
|
|
|
1386
1795
|
let body;
|
|
1387
1796
|
try {
|
|
1388
1797
|
body = JSON.parse(await readBody(req));
|
|
1389
|
-
} catch (
|
|
1798
|
+
} catch (_e) {
|
|
1390
1799
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
1391
1800
|
res.end(JSON.stringify({ error: "Invalid JSON body" }));
|
|
1392
1801
|
return;
|
|
@@ -1569,7 +1978,7 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
|
|
|
1569
1978
|
}
|
|
1570
1979
|
compiler.hooks.compilation.tap("inspecto-overlay", (compilation) => {
|
|
1571
1980
|
const HtmlWebpackPlugin = compiler.options.plugins.find(
|
|
1572
|
-
(
|
|
1981
|
+
(p2) => p2 && p2.constructor && p2.constructor.name === "HtmlWebpackPlugin"
|
|
1573
1982
|
);
|
|
1574
1983
|
if (HtmlWebpackPlugin) {
|
|
1575
1984
|
const hooks = HtmlWebpackPlugin.constructor.getHooks(compilation);
|
|
@@ -1613,7 +2022,7 @@ function injectRspack(compiler, serverPortFn, resolveClientModule2) {
|
|
|
1613
2022
|
new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {}).apply(compiler);
|
|
1614
2023
|
compiler.hooks.compilation.tap("inspecto-overlay", (compilation) => {
|
|
1615
2024
|
const HtmlRspackPlugin = compiler.options.plugins.find(
|
|
1616
|
-
(
|
|
2025
|
+
(p2) => p2 && p2.constructor && p2.constructor.name === "HtmlRspackPlugin"
|
|
1617
2026
|
);
|
|
1618
2027
|
if (HtmlRspackPlugin) {
|
|
1619
2028
|
const hooks = HtmlRspackPlugin.constructor.getHooks(compilation);
|
|
@@ -1771,7 +2180,9 @@ export {
|
|
|
1771
2180
|
esbuildPlugin,
|
|
1772
2181
|
rollupPlugin,
|
|
1773
2182
|
rspackPlugin,
|
|
2183
|
+
transformAstro,
|
|
1774
2184
|
transformJsx,
|
|
2185
|
+
transformRouter,
|
|
1775
2186
|
unplugin,
|
|
1776
2187
|
vitePlugin,
|
|
1777
2188
|
webpackPlugin
|