@archie/devtools 0.0.15 → 0.0.17
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/client/client.d.mts +8 -1
- package/dist/client/client.d.ts +8 -1
- package/dist/client/client.js +29 -32
- package/dist/client/client.mjs +31 -35
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +22 -4
- package/dist/index.mjs +55 -30
- package/package.json +2 -2
- package/dist/chunk-QZ7TP4HQ.mjs +0 -7
package/dist/client/client.d.mts
CHANGED
|
@@ -26,7 +26,8 @@ type InjectOptions = {
|
|
|
26
26
|
/**
|
|
27
27
|
* Where to load the inspector script from.
|
|
28
28
|
* - "remote" (default): load from REMOTE_INSPECTOR_SCRIPT_URL with a dynamic hash to avoid cache.
|
|
29
|
-
* - "local": load from
|
|
29
|
+
* - "local": load from `localScriptUrl` (default `/_archie/inspector.js`), served by `archieDevTools()`
|
|
30
|
+
* when `VITE_ARCHIE_LOCAL_INSPECTOR=true` in the host Vite app. You can also pass `localScriptUrl` directly.
|
|
30
31
|
*/
|
|
31
32
|
scriptSource?: 'remote' | 'local';
|
|
32
33
|
/**
|
|
@@ -35,6 +36,12 @@ type InjectOptions = {
|
|
|
35
36
|
* Example: 'https://my-cdn.com/inspector.standalone.js'
|
|
36
37
|
*/
|
|
37
38
|
scriptUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* URL for the inspector script when `scriptSource` is `"local"`.
|
|
41
|
+
* Defaults to `/_archie/inspector.js` (middleware from `archieDevTools()` in dev).
|
|
42
|
+
* Override if you host the file elsewhere, e.g. `'http://localhost:4000/inspector.js'`.
|
|
43
|
+
*/
|
|
44
|
+
localScriptUrl?: string;
|
|
38
45
|
};
|
|
39
46
|
|
|
40
47
|
interface ArchieRouteObjectLike {
|
package/dist/client/client.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ type InjectOptions = {
|
|
|
26
26
|
/**
|
|
27
27
|
* Where to load the inspector script from.
|
|
28
28
|
* - "remote" (default): load from REMOTE_INSPECTOR_SCRIPT_URL with a dynamic hash to avoid cache.
|
|
29
|
-
* - "local": load from
|
|
29
|
+
* - "local": load from `localScriptUrl` (default `/_archie/inspector.js`), served by `archieDevTools()`
|
|
30
|
+
* when `VITE_ARCHIE_LOCAL_INSPECTOR=true` in the host Vite app. You can also pass `localScriptUrl` directly.
|
|
30
31
|
*/
|
|
31
32
|
scriptSource?: 'remote' | 'local';
|
|
32
33
|
/**
|
|
@@ -35,6 +36,12 @@ type InjectOptions = {
|
|
|
35
36
|
* Example: 'https://my-cdn.com/inspector.standalone.js'
|
|
36
37
|
*/
|
|
37
38
|
scriptUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* URL for the inspector script when `scriptSource` is `"local"`.
|
|
41
|
+
* Defaults to `/_archie/inspector.js` (middleware from `archieDevTools()` in dev).
|
|
42
|
+
* Override if you host the file elsewhere, e.g. `'http://localhost:4000/inspector.js'`.
|
|
43
|
+
*/
|
|
44
|
+
localScriptUrl?: string;
|
|
38
45
|
};
|
|
39
46
|
|
|
40
47
|
interface ArchieRouteObjectLike {
|
package/dist/client/client.js
CHANGED
|
@@ -9114,6 +9114,16 @@ function DndProvider({ children }) {
|
|
|
9114
9114
|
// src/client/useArchieDevToolsRuntime.ts
|
|
9115
9115
|
var import_react21 = require("react");
|
|
9116
9116
|
|
|
9117
|
+
// src/client/archieLocalInspectorEnv.ts
|
|
9118
|
+
var import_meta = {};
|
|
9119
|
+
function readArchieLocalInspectorFlag() {
|
|
9120
|
+
try {
|
|
9121
|
+
return import_meta.env?.VITE_ARCHIE_LOCAL_INSPECTOR === "true";
|
|
9122
|
+
} catch {
|
|
9123
|
+
return false;
|
|
9124
|
+
}
|
|
9125
|
+
}
|
|
9126
|
+
|
|
9117
9127
|
// src/client/inject-inspector/archieOrigins.ts
|
|
9118
9128
|
var ARCHIE_HOST_ORIGINS = [
|
|
9119
9129
|
"https://app.dev.archie-platform.com",
|
|
@@ -9169,10 +9179,10 @@ function isLocalDev(referrer) {
|
|
|
9169
9179
|
}
|
|
9170
9180
|
}
|
|
9171
9181
|
function injectInspector(opts = {}) {
|
|
9172
|
-
if (typeof document === "undefined") return
|
|
9182
|
+
if (typeof document === "undefined") return;
|
|
9173
9183
|
const id = opts.id ?? DEFAULT_SCRIPT_ID;
|
|
9174
9184
|
const existing = document.getElementById(id);
|
|
9175
|
-
if (existing) return
|
|
9185
|
+
if (existing) return;
|
|
9176
9186
|
const win = typeof window !== "undefined" ? window : null;
|
|
9177
9187
|
if (win) {
|
|
9178
9188
|
const referrer = typeof document.referrer === "string" ? document.referrer : "";
|
|
@@ -9210,36 +9220,23 @@ function injectInspector(opts = {}) {
|
|
|
9210
9220
|
win["__ARCHIE_INSPECTOR_TARGET_ORIGIN__"] = target;
|
|
9211
9221
|
}
|
|
9212
9222
|
}
|
|
9213
|
-
const
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
}
|
|
9221
|
-
return import(
|
|
9222
|
-
/* @vite-ignore */
|
|
9223
|
-
"./inspector.js"
|
|
9224
|
-
).then((m) => {
|
|
9225
|
-
try {
|
|
9226
|
-
m.default();
|
|
9227
|
-
} catch (err) {
|
|
9223
|
+
const useLocal = opts.scriptSource === "local";
|
|
9224
|
+
const scriptUrl = useLocal ? opts.localScriptUrl ?? "/_archie/inspector.js" : getInspectorScriptUrl(opts.scriptUrl ?? REMOTE_INSPECTOR_SCRIPT_URL, true);
|
|
9225
|
+
const script = document.createElement("script");
|
|
9226
|
+
script.id = id;
|
|
9227
|
+
script.src = scriptUrl;
|
|
9228
|
+
if (useLocal) {
|
|
9229
|
+
script.onerror = () => {
|
|
9228
9230
|
if (typeof console !== "undefined" && console.error) {
|
|
9229
|
-
console.error(
|
|
9231
|
+
console.error(
|
|
9232
|
+
"[Archie DevTools] Failed to load local inspector from",
|
|
9233
|
+
scriptUrl,
|
|
9234
|
+
"\u2014 is archieDevTools() registered in your vite.config?"
|
|
9235
|
+
);
|
|
9230
9236
|
}
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
script.id = id;
|
|
9235
|
-
document.head.appendChild(script);
|
|
9236
|
-
return script;
|
|
9237
|
-
}).catch((err) => {
|
|
9238
|
-
if (typeof console !== "undefined" && console.error) {
|
|
9239
|
-
console.error("[Archie DevTools] Failed to load inspector:", err);
|
|
9240
|
-
}
|
|
9241
|
-
throw err;
|
|
9242
|
-
});
|
|
9237
|
+
};
|
|
9238
|
+
}
|
|
9239
|
+
document.head.appendChild(script);
|
|
9243
9240
|
}
|
|
9244
9241
|
|
|
9245
9242
|
// src/client/route-listener/routeListener.ts
|
|
@@ -9348,9 +9345,9 @@ function useArchieDevToolsRuntime({
|
|
|
9348
9345
|
}
|
|
9349
9346
|
const unsubscribe = setupArchieRouteListener(router);
|
|
9350
9347
|
if (inspector !== false) {
|
|
9351
|
-
const
|
|
9348
|
+
const useLocalInspector = readArchieLocalInspectorFlag();
|
|
9352
9349
|
injectInspector({
|
|
9353
|
-
scriptSource:
|
|
9350
|
+
...useLocalInspector ? { scriptSource: "local" } : { scriptSource: "remote" },
|
|
9354
9351
|
...inspectorOptionsRef.current
|
|
9355
9352
|
});
|
|
9356
9353
|
}
|
package/dist/client/client.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
|
|
3
|
+
var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
|
|
4
4
|
|
|
5
5
|
// src/client/dnd/DndProvider.tsx
|
|
6
6
|
import { useCallback as useCallback9, useEffect as useEffect13 } from "react";
|
|
@@ -9080,6 +9080,15 @@ function DndProvider({ children }) {
|
|
|
9080
9080
|
// src/client/useArchieDevToolsRuntime.ts
|
|
9081
9081
|
import { useEffect as useEffect14, useRef as useRef11 } from "react";
|
|
9082
9082
|
|
|
9083
|
+
// src/client/archieLocalInspectorEnv.ts
|
|
9084
|
+
function readArchieLocalInspectorFlag() {
|
|
9085
|
+
try {
|
|
9086
|
+
return import.meta.env?.VITE_ARCHIE_LOCAL_INSPECTOR === "true";
|
|
9087
|
+
} catch {
|
|
9088
|
+
return false;
|
|
9089
|
+
}
|
|
9090
|
+
}
|
|
9091
|
+
|
|
9083
9092
|
// src/client/inject-inspector/archieOrigins.ts
|
|
9084
9093
|
var ARCHIE_HOST_ORIGINS = [
|
|
9085
9094
|
"https://app.dev.archie-platform.com",
|
|
@@ -9135,10 +9144,10 @@ function isLocalDev(referrer) {
|
|
|
9135
9144
|
}
|
|
9136
9145
|
}
|
|
9137
9146
|
function injectInspector(opts = {}) {
|
|
9138
|
-
if (typeof document === "undefined") return
|
|
9147
|
+
if (typeof document === "undefined") return;
|
|
9139
9148
|
const id = opts.id ?? DEFAULT_SCRIPT_ID;
|
|
9140
9149
|
const existing = document.getElementById(id);
|
|
9141
|
-
if (existing) return
|
|
9150
|
+
if (existing) return;
|
|
9142
9151
|
const win = typeof window !== "undefined" ? window : null;
|
|
9143
9152
|
if (win) {
|
|
9144
9153
|
const referrer = typeof document.referrer === "string" ? document.referrer : "";
|
|
@@ -9176,36 +9185,23 @@ function injectInspector(opts = {}) {
|
|
|
9176
9185
|
win["__ARCHIE_INSPECTOR_TARGET_ORIGIN__"] = target;
|
|
9177
9186
|
}
|
|
9178
9187
|
}
|
|
9179
|
-
const
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
}
|
|
9187
|
-
return import(
|
|
9188
|
-
/* @vite-ignore */
|
|
9189
|
-
"./inspector.js"
|
|
9190
|
-
).then((m) => {
|
|
9191
|
-
try {
|
|
9192
|
-
m.default();
|
|
9193
|
-
} catch (err) {
|
|
9188
|
+
const useLocal = opts.scriptSource === "local";
|
|
9189
|
+
const scriptUrl = useLocal ? opts.localScriptUrl ?? "/_archie/inspector.js" : getInspectorScriptUrl(opts.scriptUrl ?? REMOTE_INSPECTOR_SCRIPT_URL, true);
|
|
9190
|
+
const script = document.createElement("script");
|
|
9191
|
+
script.id = id;
|
|
9192
|
+
script.src = scriptUrl;
|
|
9193
|
+
if (useLocal) {
|
|
9194
|
+
script.onerror = () => {
|
|
9194
9195
|
if (typeof console !== "undefined" && console.error) {
|
|
9195
|
-
console.error(
|
|
9196
|
+
console.error(
|
|
9197
|
+
"[Archie DevTools] Failed to load local inspector from",
|
|
9198
|
+
scriptUrl,
|
|
9199
|
+
"\u2014 is archieDevTools() registered in your vite.config?"
|
|
9200
|
+
);
|
|
9196
9201
|
}
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
script.id = id;
|
|
9201
|
-
document.head.appendChild(script);
|
|
9202
|
-
return script;
|
|
9203
|
-
}).catch((err) => {
|
|
9204
|
-
if (typeof console !== "undefined" && console.error) {
|
|
9205
|
-
console.error("[Archie DevTools] Failed to load inspector:", err);
|
|
9206
|
-
}
|
|
9207
|
-
throw err;
|
|
9208
|
-
});
|
|
9202
|
+
};
|
|
9203
|
+
}
|
|
9204
|
+
document.head.appendChild(script);
|
|
9209
9205
|
}
|
|
9210
9206
|
|
|
9211
9207
|
// src/client/route-listener/routeListener.ts
|
|
@@ -9314,9 +9310,9 @@ function useArchieDevToolsRuntime({
|
|
|
9314
9310
|
}
|
|
9315
9311
|
const unsubscribe = setupArchieRouteListener(router);
|
|
9316
9312
|
if (inspector !== false) {
|
|
9317
|
-
const
|
|
9313
|
+
const useLocalInspector = readArchieLocalInspectorFlag();
|
|
9318
9314
|
injectInspector({
|
|
9319
|
-
scriptSource:
|
|
9315
|
+
...useLocalInspector ? { scriptSource: "local" } : { scriptSource: "remote" },
|
|
9320
9316
|
...inspectorOptionsRef.current
|
|
9321
9317
|
});
|
|
9322
9318
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedConfig } from 'vite';
|
|
1
|
+
import { ResolvedConfig, ViteDevServer } from 'vite';
|
|
2
2
|
|
|
3
3
|
interface ArchieDevToolsOptions {
|
|
4
4
|
/**
|
|
@@ -17,6 +17,7 @@ interface ArchieDevToolsPlugin {
|
|
|
17
17
|
enforce?: 'pre' | 'post';
|
|
18
18
|
config?: () => object;
|
|
19
19
|
configResolved?: (config: ResolvedConfig) => void;
|
|
20
|
+
configureServer?: (server: ViteDevServer) => void;
|
|
20
21
|
transform?: (code: string, id: string) => Promise<{
|
|
21
22
|
code: string;
|
|
22
23
|
map?: object | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedConfig } from 'vite';
|
|
1
|
+
import { ResolvedConfig, ViteDevServer } from 'vite';
|
|
2
2
|
|
|
3
3
|
interface ArchieDevToolsOptions {
|
|
4
4
|
/**
|
|
@@ -17,6 +17,7 @@ interface ArchieDevToolsPlugin {
|
|
|
17
17
|
enforce?: 'pre' | 'post';
|
|
18
18
|
config?: () => object;
|
|
19
19
|
configResolved?: (config: ResolvedConfig) => void;
|
|
20
|
+
configureServer?: (server: ViteDevServer) => void;
|
|
20
21
|
transform?: (code: string, id: string) => Promise<{
|
|
21
22
|
code: string;
|
|
22
23
|
map?: object | null;
|
package/dist/index.js
CHANGED
|
@@ -28,11 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
33
|
archieDevTools: () => archieDevTools
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_node_fs = require("fs");
|
|
37
|
+
var import_node_path = require("path");
|
|
36
38
|
|
|
37
39
|
// src/client/dnd/virtual/dndScopeVirtualModule.ts
|
|
38
40
|
var INTERNAL_DND_SCOPE_IMPORT_SOURCE = "virtual:archie-devtools/dnd-scope";
|
|
@@ -96,7 +98,8 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
|
|
|
96
98
|
} else {
|
|
97
99
|
continue;
|
|
98
100
|
}
|
|
99
|
-
|
|
101
|
+
const key = /^[a-zA-Z_$][\w$]*$/.test(keyName) ? t.identifier(keyName) : t.stringLiteral(keyName);
|
|
102
|
+
props.push(t.objectProperty(key, value));
|
|
100
103
|
}
|
|
101
104
|
return t.objectExpression(props);
|
|
102
105
|
}
|
|
@@ -483,6 +486,7 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
483
486
|
}
|
|
484
487
|
|
|
485
488
|
// src/index.ts
|
|
489
|
+
var LOCAL_INSPECTOR_SERVE_PATH = "/_archie/inspector.js";
|
|
486
490
|
function archieDevTools(options = {}) {
|
|
487
491
|
const {
|
|
488
492
|
debug = false,
|
|
@@ -510,6 +514,20 @@ function archieDevTools(options = {}) {
|
|
|
510
514
|
configResolved(config) {
|
|
511
515
|
includeHostSourceRef = !config.isProduction;
|
|
512
516
|
},
|
|
517
|
+
configureServer(server) {
|
|
518
|
+
server.middlewares.use(LOCAL_INSPECTOR_SERVE_PATH, (_req, res) => {
|
|
519
|
+
const standaloneFile = (0, import_node_path.join)(__dirname, "../src/client/inject-inspector/inspector.standalone.js");
|
|
520
|
+
try {
|
|
521
|
+
const content = (0, import_node_fs.readFileSync)(standaloneFile, "utf-8");
|
|
522
|
+
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
523
|
+
res.setHeader("Cache-Control", "no-store");
|
|
524
|
+
res.end(content);
|
|
525
|
+
} catch {
|
|
526
|
+
res.statusCode = 404;
|
|
527
|
+
res.end("Not found");
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
},
|
|
513
531
|
async transform(code, id) {
|
|
514
532
|
if (!/\.[jt]sx$/.test(id) || /node_modules/.test(id)) return null;
|
|
515
533
|
try {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// node_modules/tsup/assets/esm_shims.js
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
5
|
+
var getDirname = () => path.dirname(getFilename());
|
|
6
|
+
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { readFileSync } from "fs";
|
|
10
|
+
import { join } from "path";
|
|
2
11
|
|
|
3
12
|
// src/client/dnd/virtual/dndScopeVirtualModule.ts
|
|
4
13
|
var INTERNAL_DND_SCOPE_IMPORT_SOURCE = "virtual:archie-devtools/dnd-scope";
|
|
@@ -62,7 +71,8 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
|
|
|
62
71
|
} else {
|
|
63
72
|
continue;
|
|
64
73
|
}
|
|
65
|
-
|
|
74
|
+
const key = /^[a-zA-Z_$][\w$]*$/.test(keyName) ? t.identifier(keyName) : t.stringLiteral(keyName);
|
|
75
|
+
props.push(t.objectProperty(key, value));
|
|
66
76
|
}
|
|
67
77
|
return t.objectExpression(props);
|
|
68
78
|
}
|
|
@@ -129,16 +139,16 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
|
|
|
129
139
|
return {
|
|
130
140
|
name: "babel-plugin-dnd-auto",
|
|
131
141
|
visitor: {
|
|
132
|
-
ExportDefaultDeclaration(
|
|
142
|
+
ExportDefaultDeclaration(path2, state) {
|
|
133
143
|
const filename = state.filename ?? "";
|
|
134
144
|
if (fileExclude.test(filename)) return;
|
|
135
145
|
if (fileMatch && !fileMatch.test(filename)) return;
|
|
136
|
-
const { declaration } =
|
|
146
|
+
const { declaration } = path2.node;
|
|
137
147
|
if (!t.isFunctionDeclaration(declaration)) return;
|
|
138
148
|
const componentName = declaration.id?.name ?? "Component";
|
|
139
149
|
const scopeCounter = { n: 0 };
|
|
140
150
|
let didTransform = false;
|
|
141
|
-
|
|
151
|
+
path2.traverse({
|
|
142
152
|
ReturnStatement(retPath) {
|
|
143
153
|
const fnParent = retPath.getFunctionParent();
|
|
144
154
|
if (fnParent?.node !== declaration) return;
|
|
@@ -208,8 +218,8 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
208
218
|
function computeNodeId(file, line, col, componentName) {
|
|
209
219
|
return `${file}:${line}:${col}:${componentName}`;
|
|
210
220
|
}
|
|
211
|
-
function isMovable(
|
|
212
|
-
const elPath =
|
|
221
|
+
function isMovable(path2) {
|
|
222
|
+
const elPath = path2.parentPath;
|
|
213
223
|
if (!elPath) return false;
|
|
214
224
|
const parentEl = elPath.parentPath;
|
|
215
225
|
if (!parentEl || !parentEl.isJSXElement()) return false;
|
|
@@ -218,8 +228,8 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
218
228
|
);
|
|
219
229
|
return siblings.length >= 2;
|
|
220
230
|
}
|
|
221
|
-
function getParentNodeId(
|
|
222
|
-
const elPath =
|
|
231
|
+
function getParentNodeId(path2, file) {
|
|
232
|
+
const elPath = path2.parentPath;
|
|
223
233
|
if (!elPath) return null;
|
|
224
234
|
let ancestor = elPath.parentPath;
|
|
225
235
|
while (ancestor) {
|
|
@@ -323,10 +333,10 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
323
333
|
return {
|
|
324
334
|
name: "babel-plugin-editor-meta",
|
|
325
335
|
visitor: {
|
|
326
|
-
CallExpression(
|
|
336
|
+
CallExpression(path2, state) {
|
|
327
337
|
const filename = state.filename ?? "";
|
|
328
338
|
if (fileExclude.test(filename)) return;
|
|
329
|
-
const callee =
|
|
339
|
+
const callee = path2.node.callee;
|
|
330
340
|
let isCreateElement = false;
|
|
331
341
|
let isCloneElement = false;
|
|
332
342
|
if (t.isIdentifier(callee, { name: "createElement" })) {
|
|
@@ -339,7 +349,7 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
339
349
|
isCloneElement = true;
|
|
340
350
|
}
|
|
341
351
|
if (!isCreateElement && !isCloneElement) return;
|
|
342
|
-
const args =
|
|
352
|
+
const args = path2.node.arguments;
|
|
343
353
|
if (args.length < 2) return;
|
|
344
354
|
if (isCreateElement && !t.isStringLiteral(args[0])) return;
|
|
345
355
|
const propsArg = args[1];
|
|
@@ -364,37 +374,37 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
364
374
|
[t.objectExpression([t.spreadElement(propsArg)])]
|
|
365
375
|
);
|
|
366
376
|
},
|
|
367
|
-
JSXOpeningElement(
|
|
377
|
+
JSXOpeningElement(path2, state) {
|
|
368
378
|
const filename = state.filename ?? "";
|
|
369
379
|
if (fileExclude.test(filename)) return;
|
|
370
|
-
const existing =
|
|
380
|
+
const existing = path2.node.attributes.find(
|
|
371
381
|
(a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name, { name: "__editorMeta" })
|
|
372
382
|
);
|
|
373
383
|
if (existing) return;
|
|
374
|
-
const loc =
|
|
384
|
+
const loc = path2.node.loc?.start;
|
|
375
385
|
if (!loc) return;
|
|
376
386
|
const root = state.file.opts.root ?? "";
|
|
377
387
|
const file = root ? nodePath.relative(root, filename) : filename;
|
|
378
388
|
const line = loc.line;
|
|
379
389
|
const col = loc.column + 1;
|
|
380
|
-
const componentName = getJSXTagName(
|
|
390
|
+
const componentName = getJSXTagName(path2.node);
|
|
381
391
|
if (!componentName) return;
|
|
382
|
-
const isHostLikeMemberExpression = isHostLikeMemberExpressionName(
|
|
392
|
+
const isHostLikeMemberExpression = isHostLikeMemberExpressionName(path2.node.name);
|
|
383
393
|
const isHostElement = componentName[0] === componentName[0].toLowerCase();
|
|
384
|
-
sanitizeSpreadAttributes(
|
|
385
|
-
if (hasTruthyAsChildProp(
|
|
394
|
+
sanitizeSpreadAttributes(path2.node.attributes);
|
|
395
|
+
if (hasTruthyAsChildProp(path2.node.attributes)) {
|
|
386
396
|
return;
|
|
387
397
|
}
|
|
388
398
|
let rootName = null;
|
|
389
|
-
if (t.isJSXIdentifier(
|
|
390
|
-
rootName =
|
|
391
|
-
} else if (t.isJSXMemberExpression(
|
|
392
|
-
let cur =
|
|
399
|
+
if (t.isJSXIdentifier(path2.node.name)) {
|
|
400
|
+
rootName = path2.node.name.name;
|
|
401
|
+
} else if (t.isJSXMemberExpression(path2.node.name)) {
|
|
402
|
+
let cur = path2.node.name;
|
|
393
403
|
while (t.isJSXMemberExpression(cur)) cur = cur.object;
|
|
394
404
|
if (t.isJSXIdentifier(cur)) rootName = cur.name;
|
|
395
405
|
}
|
|
396
406
|
if (rootName) {
|
|
397
|
-
const binding =
|
|
407
|
+
const binding = path2.scope.getBinding(rootName);
|
|
398
408
|
if (binding) {
|
|
399
409
|
const bp = binding.path;
|
|
400
410
|
if (bp.isImportSpecifier() || bp.isImportDefaultSpecifier() || bp.isImportNamespaceSpecifier()) {
|
|
@@ -405,14 +415,14 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
405
415
|
if (isPackageImport(src) && !isHostLikeMemberExpression) return;
|
|
406
416
|
}
|
|
407
417
|
}
|
|
408
|
-
const programScope =
|
|
418
|
+
const programScope = path2.scope.getProgramParent();
|
|
409
419
|
if (binding.scope !== programScope) return;
|
|
410
420
|
}
|
|
411
421
|
}
|
|
412
422
|
const nodeId = computeNodeId(file, line, col, componentName);
|
|
413
|
-
const movable = isMovable(
|
|
414
|
-
const parentNodeId = getParentNodeId(
|
|
415
|
-
const staticPropsObj = extractStaticProps(
|
|
423
|
+
const movable = isMovable(path2);
|
|
424
|
+
const parentNodeId = getParentNodeId(path2, file);
|
|
425
|
+
const staticPropsObj = extractStaticProps(path2.node.attributes);
|
|
416
426
|
const metaObj = t.objectExpression([
|
|
417
427
|
t.objectProperty(t.identifier("nodeId"), t.stringLiteral(nodeId)),
|
|
418
428
|
t.objectProperty(t.identifier("file"), t.stringLiteral(file)),
|
|
@@ -430,14 +440,14 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
430
440
|
)
|
|
431
441
|
]);
|
|
432
442
|
if (isHostElement && includeHostSourceRef) {
|
|
433
|
-
|
|
443
|
+
path2.node.attributes.push(
|
|
434
444
|
t.jsxAttribute(
|
|
435
445
|
t.jsxIdentifier("data-archie-source-ref"),
|
|
436
446
|
t.stringLiteral(`${file}::${line}::${col}`)
|
|
437
447
|
)
|
|
438
448
|
);
|
|
439
449
|
}
|
|
440
|
-
|
|
450
|
+
path2.node.attributes.push(
|
|
441
451
|
t.jsxAttribute(
|
|
442
452
|
t.jsxIdentifier("__editorMeta"),
|
|
443
453
|
t.jsxExpressionContainer(metaObj)
|
|
@@ -449,6 +459,7 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
449
459
|
}
|
|
450
460
|
|
|
451
461
|
// src/index.ts
|
|
462
|
+
var LOCAL_INSPECTOR_SERVE_PATH = "/_archie/inspector.js";
|
|
452
463
|
function archieDevTools(options = {}) {
|
|
453
464
|
const {
|
|
454
465
|
debug = false,
|
|
@@ -476,6 +487,20 @@ function archieDevTools(options = {}) {
|
|
|
476
487
|
configResolved(config) {
|
|
477
488
|
includeHostSourceRef = !config.isProduction;
|
|
478
489
|
},
|
|
490
|
+
configureServer(server) {
|
|
491
|
+
server.middlewares.use(LOCAL_INSPECTOR_SERVE_PATH, (_req, res) => {
|
|
492
|
+
const standaloneFile = join(__dirname, "../src/client/inject-inspector/inspector.standalone.js");
|
|
493
|
+
try {
|
|
494
|
+
const content = readFileSync(standaloneFile, "utf-8");
|
|
495
|
+
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
496
|
+
res.setHeader("Cache-Control", "no-store");
|
|
497
|
+
res.end(content);
|
|
498
|
+
} catch {
|
|
499
|
+
res.statusCode = 404;
|
|
500
|
+
res.end("Not found");
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
},
|
|
479
504
|
async transform(code, id) {
|
|
480
505
|
if (!/\.[jt]sx$/.test(id) || /node_modules/.test(id)) return null;
|
|
481
506
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archie/devtools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "DevTools for Archie generated applications - Route synchronization and editor communication",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -72,4 +72,4 @@
|
|
|
72
72
|
"react-dom": ">=18.0.0",
|
|
73
73
|
"react-router-dom": ">=6.4.0"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
package/dist/chunk-QZ7TP4HQ.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
__publicField
|
|
7
|
-
};
|