@abbox/inspector 0.0.0-stage → 0.3.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/README.md +51 -2
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +8 -0
- package/dist/host/client-bridge.d.ts +13 -0
- package/dist/host/client-bridge.d.ts.map +1 -0
- package/dist/host/client-bridge.js +75 -0
- package/dist/host/host-bridge.d.ts +34 -0
- package/dist/host/host-bridge.d.ts.map +1 -0
- package/dist/host/host-bridge.js +59 -0
- package/dist/host/origin-aliases.d.ts +3 -0
- package/dist/host/origin-aliases.d.ts.map +1 -0
- package/dist/host/origin-aliases.js +13 -0
- package/dist/host/validate.d.ts +8 -0
- package/dist/host/validate.d.ts.map +1 -0
- package/dist/host/validate.js +13 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/instrument/babel-plugin.d.ts +8 -0
- package/dist/instrument/babel-plugin.d.ts.map +1 -0
- package/dist/instrument/babel-plugin.js +26 -0
- package/dist/instrument/constants.d.ts +10 -0
- package/dist/instrument/constants.d.ts.map +1 -0
- package/dist/instrument/constants.js +17 -0
- package/dist/ir-match.d.ts +34 -0
- package/dist/ir-match.d.ts.map +1 -0
- package/dist/ir-match.js +129 -0
- package/dist/next/babel-config.cjs +40 -0
- package/dist/next/index.d.ts +3 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +2 -0
- package/dist/next/preview-env.d.ts +15 -0
- package/dist/next/preview-env.d.ts.map +1 -0
- package/dist/next/preview-env.js +39 -0
- package/dist/next/webpack-instrumentation.cjs +82 -0
- package/dist/next/with-abbox-inspector.d.ts +31 -0
- package/dist/next/with-abbox-inspector.d.ts.map +1 -0
- package/dist/next/with-abbox-inspector.js +92 -0
- package/dist/protocol.d.ts +92 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +12 -0
- package/dist/react/AbboxInspectorBoot.d.ts +3 -0
- package/dist/react/AbboxInspectorBoot.d.ts.map +1 -0
- package/dist/react/AbboxInspectorBoot.js +10 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +66 -0
- package/dist/runtime/element-ref.d.ts +4 -0
- package/dist/runtime/element-ref.d.ts.map +1 -0
- package/dist/runtime/element-ref.js +14 -0
- package/dist/runtime/inspector.d.ts +18 -0
- package/dist/runtime/inspector.d.ts.map +1 -0
- package/dist/runtime/inspector.js +137 -0
- package/dist/runtime/metadata.d.ts +6 -0
- package/dist/runtime/metadata.d.ts.map +1 -0
- package/dist/runtime/metadata.js +81 -0
- package/dist/runtime/overlay.d.ts +12 -0
- package/dist/runtime/overlay.d.ts.map +1 -0
- package/dist/runtime/overlay.js +104 -0
- package/dist/vite-plugin.d.ts +8 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +29 -0
- package/docs/TRUST.md +25 -0
- package/docs/architecture.md +21 -0
- package/docs/implementation-report.md +23 -0
- package/docs/integration.md +21 -0
- package/docs/known-limitations.md +8 -0
- package/docs/nextjs-integration.md +35 -0
- package/package.json +90 -4
- package/src/next/babel-config.cjs +40 -0
- package/src/next/webpack-instrumentation.cjs +82 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply Abbox JSX instrumentation via webpack + babel-loader on selected app sources.
|
|
3
|
+
* Does not use babel.config.js, so Next.js keeps SWC (and next/font) for excluded files
|
|
4
|
+
* such as app/layout.tsx.
|
|
5
|
+
*/
|
|
6
|
+
const fs = require("node:fs");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
const { createRequire } = require("node:module");
|
|
9
|
+
|
|
10
|
+
const LAYOUT_BASENAMES = new Set(["layout.tsx", "layout.jsx"]);
|
|
11
|
+
|
|
12
|
+
function resolveInspectorBabelPlugin(rootDir) {
|
|
13
|
+
const req = createRequire(path.join(rootDir, "package.json"));
|
|
14
|
+
try {
|
|
15
|
+
return req.resolve("@abbox/inspector/babel");
|
|
16
|
+
} catch {
|
|
17
|
+
return req.resolve("abbox-inspector/babel");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function resolveBabelLoader(rootDir) {
|
|
22
|
+
const req = createRequire(path.join(rootDir, "package.json"));
|
|
23
|
+
return req.resolve("babel-loader");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function resolveNextBabelPreset(rootDir) {
|
|
27
|
+
const req = createRequire(path.join(rootDir, "package.json"));
|
|
28
|
+
return req.resolve("next/babel");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function collectIncludeDirs(rootDir) {
|
|
32
|
+
return ["app", "components", "src", "pages"]
|
|
33
|
+
.map((segment) => path.join(rootDir, segment))
|
|
34
|
+
.filter((dir) => fs.existsSync(dir));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isRootLayoutResource(resourcePath) {
|
|
38
|
+
const base = path.basename(resourcePath);
|
|
39
|
+
if (!LAYOUT_BASENAMES.has(base)) return false;
|
|
40
|
+
const parent = path.basename(path.dirname(resourcePath));
|
|
41
|
+
return parent === "app" || parent === "src/app";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {import('webpack').Configuration} webpackConfig
|
|
46
|
+
* @param {{ dir: string }} options
|
|
47
|
+
*/
|
|
48
|
+
function applyAbboxWebpackInstrumentation(webpackConfig, options) {
|
|
49
|
+
const rootDir = options.dir ?? process.cwd();
|
|
50
|
+
const pluginPath = resolveInspectorBabelPlugin(rootDir);
|
|
51
|
+
const babelLoader = resolveBabelLoader(rootDir);
|
|
52
|
+
const nextBabel = resolveNextBabelPreset(rootDir);
|
|
53
|
+
const includeDirs = collectIncludeDirs(rootDir);
|
|
54
|
+
|
|
55
|
+
if (includeDirs.length === 0) {
|
|
56
|
+
return webpackConfig;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const rule = {
|
|
60
|
+
test: /\.(tsx|jsx)$/,
|
|
61
|
+
include: (resourcePath) =>
|
|
62
|
+
includeDirs.some((dir) => resourcePath.startsWith(dir)) &&
|
|
63
|
+
!isRootLayoutResource(resourcePath),
|
|
64
|
+
exclude: [/node_modules/],
|
|
65
|
+
use: {
|
|
66
|
+
loader: babelLoader,
|
|
67
|
+
options: {
|
|
68
|
+
babelrc: false,
|
|
69
|
+
configFile: false,
|
|
70
|
+
presets: [nextBabel],
|
|
71
|
+
plugins: [[pluginPath, { rootDir }]],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
webpackConfig.module = webpackConfig.module ?? { rules: [] };
|
|
77
|
+
webpackConfig.module.rules = webpackConfig.module.rules ?? [];
|
|
78
|
+
webpackConfig.module.rules.unshift(rule);
|
|
79
|
+
return webpackConfig;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = { applyAbboxWebpackInstrumentation, isRootLayoutResource };
|