tencil 0.5.0 → 0.6.1
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/cli.mjs +50 -3
- package/dist/{cloud-Ez2olqK0.d.mts → cloud-CIAGUsk2.d.mts} +1 -1
- package/dist/{index-DzR4m_IL.d.mts → index-B0phpEz9.d.mts} +114 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +1 -1
- package/dist/next-loader.cjs +163 -0
- package/dist/next.d.mts +14 -0
- package/dist/next.mjs +45 -0
- package/dist/overlay.global.js +155 -30
- package/dist/react.d.mts +1 -1
- package/dist/{server-DZUEgjla.mjs → server-CbF3t-Cx.mjs} +134 -13
- package/dist/vite.d.mts +10 -2
- package/dist/vite.mjs +156 -1
- package/package.json +11 -4
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as parsePairingInput, a as detectAgents, c as savedProvider, f as VERSION, g as exchangePairingCredential, h as createLocalPairingCode, i as PROVIDERS, m as DEFAULT_T3_URL, n as probeDaemon, o as providerLabel, p as CredentialStore, r as startDaemon, s as saveProvider, t as DEFAULT_PORT, u as defaultDataDir, v as withoutNpmEnv, y as loadAgentSdk } from "./server-
|
|
2
|
+
import { _ as parsePairingInput, a as detectAgents, c as savedProvider, f as VERSION, g as exchangePairingCredential, h as createLocalPairingCode, i as PROVIDERS, m as DEFAULT_T3_URL, n as probeDaemon, o as providerLabel, p as CredentialStore, r as startDaemon, s as saveProvider, t as DEFAULT_PORT, u as defaultDataDir, v as withoutNpmEnv, y as loadAgentSdk } from "./server-CbF3t-Cx.mjs";
|
|
3
3
|
import { t as DEFAULT_CLOUD_URL } from "./cloud-CiwIrP1h.mjs";
|
|
4
4
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import { existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -631,6 +631,34 @@ function addTencilToBody(source) {
|
|
|
631
631
|
else edited = `${source.slice(0, close)}<Tencil />${source.slice(close)}`;
|
|
632
632
|
return addImport(edited, `import { Tencil } from ${style.quote}tencil/react${style.quote}${style.semi}`);
|
|
633
633
|
}
|
|
634
|
+
/**
|
|
635
|
+
* `export default nextConfig` → `export default withTencil(nextConfig)`, plus
|
|
636
|
+
* the import. Wraps whatever is exported, including another plugin's wrapper.
|
|
637
|
+
*/
|
|
638
|
+
function addWithTencil(source) {
|
|
639
|
+
if (/["']tencil\/next["']/.test(source)) return source;
|
|
640
|
+
const style = detectStyle(source);
|
|
641
|
+
const exported = /^export\s+default\s+/m.exec(source);
|
|
642
|
+
if (!exported) return null;
|
|
643
|
+
const start = exported.index + exported[0].length;
|
|
644
|
+
const end = expressionEnd(source, start);
|
|
645
|
+
if (end === -1) return null;
|
|
646
|
+
const expression = source.slice(start, end).trimEnd();
|
|
647
|
+
if (!expression || /^(?:function|class|async)\b/.test(expression)) return null;
|
|
648
|
+
return addImport(`${source.slice(0, start)}withTencil(${expression})${source.slice(start + expression.length)}`, `import { withTencil } from ${style.quote}tencil/next${style.quote}${style.semi}`);
|
|
649
|
+
}
|
|
650
|
+
/** Where the expression starting at `start` ends: `;`, or a newline outside brackets. */
|
|
651
|
+
function expressionEnd(source, start) {
|
|
652
|
+
for (let i = start; i < source.length; i++) {
|
|
653
|
+
const char = source[i];
|
|
654
|
+
if (char === "\"" || char === "'" || char === "`") i = skipString(source, i);
|
|
655
|
+
else if (char === "(" || char === "[" || char === "{") {
|
|
656
|
+
i = matchBracket(source, i);
|
|
657
|
+
if (i === -1) return -1;
|
|
658
|
+
} else if (char === ";" || char === "\n") return i;
|
|
659
|
+
}
|
|
660
|
+
return source.length;
|
|
661
|
+
}
|
|
634
662
|
/** Index of the bracket closing the one at `open`, skipping strings and comments. */
|
|
635
663
|
function matchBracket(source, open) {
|
|
636
664
|
const pairs = {
|
|
@@ -840,8 +868,14 @@ function hunks(lines, context = 2) {
|
|
|
840
868
|
//#endregion
|
|
841
869
|
//#region src/init/run-init.ts
|
|
842
870
|
const SCRIPT_TAG = "<script src=\"http://localhost:4747/tencil.js\" async><\/script>";
|
|
871
|
+
const NEXT_CONFIGS = [
|
|
872
|
+
"next.config.ts",
|
|
873
|
+
"next.config.mts",
|
|
874
|
+
"next.config.mjs",
|
|
875
|
+
"next.config.js"
|
|
876
|
+
];
|
|
843
877
|
/** Work out the edits without touching the disk. */
|
|
844
|
-
async function planInit(root) {
|
|
878
|
+
async function planInit(root, options = {}) {
|
|
845
879
|
const framework = await detectFramework(root);
|
|
846
880
|
const edits = [];
|
|
847
881
|
const manual = [];
|
|
@@ -872,6 +906,19 @@ async function planInit(root) {
|
|
|
872
906
|
break;
|
|
873
907
|
case "unknown": manual.push(`${framework.reason} Load this in development only: ${SCRIPT_TAG}`);
|
|
874
908
|
}
|
|
909
|
+
if (options.cloud && (framework.kind === "next-app" || framework.kind === "next-pages")) {
|
|
910
|
+
const config = NEXT_CONFIGS.map((name) => join(root, name)).find((path) => existsSync(path));
|
|
911
|
+
if (config) {
|
|
912
|
+
const before = await readFile(config, "utf8");
|
|
913
|
+
const after = addWithTencil(before);
|
|
914
|
+
if (after === null) manual.push(`Wrap the exported config in \`withTencil()\` from \`tencil/next\` (in ${relative(root, config)})`);
|
|
915
|
+
else if (after !== before) edits.push({
|
|
916
|
+
path: config,
|
|
917
|
+
before,
|
|
918
|
+
after
|
|
919
|
+
});
|
|
920
|
+
} else manual.push("Create next.config.ts that exports `withTencil({})` from `tencil/next`");
|
|
921
|
+
}
|
|
875
922
|
return {
|
|
876
923
|
framework,
|
|
877
924
|
edits,
|
|
@@ -880,7 +927,7 @@ async function planInit(root) {
|
|
|
880
927
|
}
|
|
881
928
|
async function runInit(options) {
|
|
882
929
|
const log = options.log ?? console.log;
|
|
883
|
-
const plan = await planInit(options.root);
|
|
930
|
+
const plan = await planInit(options.root, { cloud: options.cloud });
|
|
884
931
|
log(`\n ${pc.bold("Tencil")} ${pc.dim("·")} ${describe(plan.framework)}\n`);
|
|
885
932
|
for (const edit of plan.edits) {
|
|
886
933
|
log(` ${pc.bold(relative(options.root, edit.path))}`);
|
|
@@ -68,6 +68,51 @@ declare const MessageRole: z.ZodEnum<{
|
|
|
68
68
|
system: "system";
|
|
69
69
|
}>;
|
|
70
70
|
type MessageRole = z.infer<typeof MessageRole>;
|
|
71
|
+
declare const Delivery: z.ZodObject<{
|
|
72
|
+
status: z.ZodEnum<{
|
|
73
|
+
queued: "queued";
|
|
74
|
+
pushed: "pushed";
|
|
75
|
+
deploying: "deploying";
|
|
76
|
+
live: "live";
|
|
77
|
+
"deploy-failed": "deploy-failed";
|
|
78
|
+
"no-changes": "no-changes";
|
|
79
|
+
failed: "failed";
|
|
80
|
+
}>;
|
|
81
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
82
|
+
queuePosition: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
commit: z.ZodOptional<z.ZodObject<{
|
|
84
|
+
sha: z.ZodString;
|
|
85
|
+
url: z.ZodString;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
pullRequest: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
number: z.ZodNumber;
|
|
89
|
+
url: z.ZodString;
|
|
90
|
+
opened: z.ZodDefault<z.ZodBoolean>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
previewUrl: z.ZodOptional<z.ZodString>;
|
|
93
|
+
logsUrl: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
type Delivery = z.infer<typeof Delivery>;
|
|
96
|
+
/**
|
|
97
|
+
* One thing a provider did during the current turn, for the overlay to show
|
|
98
|
+
* under "Working…": Tencil Cloud starting a sandbox, cloning, installing, then
|
|
99
|
+
* the agent's tool calls (nested under the agent step through `parentId`).
|
|
100
|
+
*/
|
|
101
|
+
declare const ThreadStep: z.ZodObject<{
|
|
102
|
+
id: z.ZodString;
|
|
103
|
+
label: z.ZodString;
|
|
104
|
+
status: z.ZodEnum<{
|
|
105
|
+
failed: "failed";
|
|
106
|
+
running: "running";
|
|
107
|
+
done: "done";
|
|
108
|
+
skipped: "skipped";
|
|
109
|
+
}>;
|
|
110
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
111
|
+
parentId: z.ZodOptional<z.ZodString>;
|
|
112
|
+
startedAt: z.ZodString;
|
|
113
|
+
endedAt: z.ZodOptional<z.ZodString>;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
type ThreadStep = z.infer<typeof ThreadStep>;
|
|
71
116
|
/**
|
|
72
117
|
* A conversation Tencil tracks, backed by one provider thread. Owned and
|
|
73
118
|
* persisted by the bridge. Pinned threads sit on an element of a page;
|
|
@@ -136,6 +181,44 @@ declare const Thread: z.ZodObject<{
|
|
|
136
181
|
threadId: z.ZodOptional<z.ZodString>;
|
|
137
182
|
url: z.ZodOptional<z.ZodString>;
|
|
138
183
|
}, z.core.$strip>;
|
|
184
|
+
delivery: z.ZodOptional<z.ZodObject<{
|
|
185
|
+
status: z.ZodEnum<{
|
|
186
|
+
queued: "queued";
|
|
187
|
+
pushed: "pushed";
|
|
188
|
+
deploying: "deploying";
|
|
189
|
+
live: "live";
|
|
190
|
+
"deploy-failed": "deploy-failed";
|
|
191
|
+
"no-changes": "no-changes";
|
|
192
|
+
failed: "failed";
|
|
193
|
+
}>;
|
|
194
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
195
|
+
queuePosition: z.ZodOptional<z.ZodNumber>;
|
|
196
|
+
commit: z.ZodOptional<z.ZodObject<{
|
|
197
|
+
sha: z.ZodString;
|
|
198
|
+
url: z.ZodString;
|
|
199
|
+
}, z.core.$strip>>;
|
|
200
|
+
pullRequest: z.ZodOptional<z.ZodObject<{
|
|
201
|
+
number: z.ZodNumber;
|
|
202
|
+
url: z.ZodString;
|
|
203
|
+
opened: z.ZodDefault<z.ZodBoolean>;
|
|
204
|
+
}, z.core.$strip>>;
|
|
205
|
+
previewUrl: z.ZodOptional<z.ZodString>;
|
|
206
|
+
logsUrl: z.ZodOptional<z.ZodString>;
|
|
207
|
+
}, z.core.$strip>>;
|
|
208
|
+
steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
209
|
+
id: z.ZodString;
|
|
210
|
+
label: z.ZodString;
|
|
211
|
+
status: z.ZodEnum<{
|
|
212
|
+
failed: "failed";
|
|
213
|
+
running: "running";
|
|
214
|
+
done: "done";
|
|
215
|
+
skipped: "skipped";
|
|
216
|
+
}>;
|
|
217
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
218
|
+
parentId: z.ZodOptional<z.ZodString>;
|
|
219
|
+
startedAt: z.ZodString;
|
|
220
|
+
endedAt: z.ZodOptional<z.ZodString>;
|
|
221
|
+
}, z.core.$strip>>>;
|
|
139
222
|
createdAt: z.ZodString;
|
|
140
223
|
updatedAt: z.ZodString;
|
|
141
224
|
}, z.core.$strip>;
|
|
@@ -182,6 +265,24 @@ type ProviderProject = z.infer<typeof ProviderProject>;
|
|
|
182
265
|
//#endregion
|
|
183
266
|
//#region ../protocol/src/messages.d.ts
|
|
184
267
|
declare const PROTOCOL_VERSION = 1;
|
|
268
|
+
/** How the overlay signs in to Tencil Cloud: OAuth 2.1 authorization code with PKCE. */
|
|
269
|
+
interface CloudSignIn {
|
|
270
|
+
authorizeUrl: string;
|
|
271
|
+
tokenUrl: string;
|
|
272
|
+
clientId: string;
|
|
273
|
+
/** A Tencil Cloud page that posts the code back to the overlay (`tencil:oauth`). */
|
|
274
|
+
redirectUri: string;
|
|
275
|
+
scope?: string;
|
|
276
|
+
}
|
|
277
|
+
/** Who is signed in to Tencil Cloud, and what they may do on this project. */
|
|
278
|
+
interface Viewer {
|
|
279
|
+
name: string;
|
|
280
|
+
/** GitHub login. */
|
|
281
|
+
login?: string;
|
|
282
|
+
avatarUrl?: string;
|
|
283
|
+
/** `read`: can see pins, not make or answer them (no write access to the repository). */
|
|
284
|
+
access: 'write' | 'read';
|
|
285
|
+
}
|
|
185
286
|
declare const ProviderInfo: z.ZodObject<{
|
|
186
287
|
id: z.ZodString;
|
|
187
288
|
label: z.ZodString;
|
|
@@ -225,6 +326,14 @@ type ServerMessage = {
|
|
|
225
326
|
provider: ProviderInfo;
|
|
226
327
|
settings: ProjectSettings;
|
|
227
328
|
threads: Thread[];
|
|
329
|
+
/** Tencil Cloud only: who is signed in. */
|
|
330
|
+
viewer?: Viewer;
|
|
331
|
+
} |
|
|
332
|
+
/** Tencil Cloud: sign in first (no token, or one it no longer accepts). */
|
|
333
|
+
{
|
|
334
|
+
type: 'auth.required';
|
|
335
|
+
signIn: CloudSignIn;
|
|
336
|
+
reason?: string;
|
|
228
337
|
} | {
|
|
229
338
|
type: 'provider.status';
|
|
230
339
|
provider: ProviderInfo;
|
|
@@ -336,6 +445,10 @@ interface ThreadSink {
|
|
|
336
445
|
status(status: Exclude<ThreadStatus, 'starting' | 'draft'>, detail?: string): void;
|
|
337
446
|
/** Provider no longer has this thread (deleted/archived on its side). */
|
|
338
447
|
gone(): void;
|
|
448
|
+
/** Tencil Cloud: where the run's commit is (pushed, deploying, live, …). */
|
|
449
|
+
delivery?(delivery: Delivery): void;
|
|
450
|
+
/** A step of the current turn (sandbox, clone, a tool call…); upsert by `id`. */
|
|
451
|
+
step?(step: ThreadStep): void;
|
|
339
452
|
}
|
|
340
453
|
//#endregion
|
|
341
|
-
export {
|
|
454
|
+
export { Thread as a, Viewer as i, ProviderOption as n, ElementContext as o, ServerMessage as r, Provider as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as Thread, i as Viewer, n as ProviderOption, o as ElementContext, r as ServerMessage, t as Provider } from "./index-B0phpEz9.mjs";
|
|
2
2
|
//#region ../bridge/src/project-providers.d.ts
|
|
3
3
|
/** What a project picked in the overlay's settings. */
|
|
4
4
|
interface SavedProjectSettings {
|
|
@@ -80,6 +80,8 @@ interface ThreadStore {
|
|
|
80
80
|
//#region ../bridge/src/bridge.d.ts
|
|
81
81
|
interface BridgeClient {
|
|
82
82
|
send(message: ServerMessage): void;
|
|
83
|
+
/** Tencil Cloud: who this connection signed in as, echoed in `ready`. */
|
|
84
|
+
viewer?: Viewer;
|
|
83
85
|
}
|
|
84
86
|
interface BridgeOptions {
|
|
85
87
|
providers: ProjectProviders;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as renderPrompt, S as Bridge, b as ProjectResolver, d as projectStorePath, l as FileThreadStore, n as probeDaemon, r as startDaemon, t as DEFAULT_PORT, u as defaultDataDir, w as stripContext, x as projectRoot } from "./server-
|
|
1
|
+
import { C as renderPrompt, S as Bridge, b as ProjectResolver, d as projectStorePath, l as FileThreadStore, n as probeDaemon, r as startDaemon, t as DEFAULT_PORT, u as defaultDataDir, w as stripContext, x as projectRoot } from "./server-CbF3t-Cx.mjs";
|
|
2
2
|
export { Bridge, DEFAULT_PORT, ProjectResolver, FileThreadStore as ThreadStore, defaultDataDir, probeDaemon, projectRoot, projectStorePath, renderPrompt, startDaemon, stripContext };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
let node_fs = require("node:fs");
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
//#region src/integrations/source-attributes.ts
|
|
4
|
+
/** Files whose JSX gets source attributes. */
|
|
5
|
+
const JSX_FILE = /\.[jt]sx$/;
|
|
6
|
+
/** Host elements that never get picked, or must stay untouched. */
|
|
7
|
+
const SKIP = /* @__PURE__ */ new Set([
|
|
8
|
+
"html",
|
|
9
|
+
"head",
|
|
10
|
+
"meta",
|
|
11
|
+
"link",
|
|
12
|
+
"script",
|
|
13
|
+
"style",
|
|
14
|
+
"title",
|
|
15
|
+
"base",
|
|
16
|
+
"noscript",
|
|
17
|
+
"template",
|
|
18
|
+
"slot"
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* Tags every host element (`<button>`, not `<Button>`) with where it's written,
|
|
22
|
+
* `data-tencil-src="src/card.tsx:42:7"`, and the component it's in,
|
|
23
|
+
* `data-tencil-component="Card"`. Production builds drop React's dev source
|
|
24
|
+
* info, so this is how a pin on a preview still knows its file and line.
|
|
25
|
+
*
|
|
26
|
+
* Paths are relative to `root`, the repository root, because that's what the
|
|
27
|
+
* cloud agent checks out. Returns undefined when there's nothing to tag or the
|
|
28
|
+
* file doesn't parse (the bundler will report that itself).
|
|
29
|
+
*/
|
|
30
|
+
async function addSourceAttributes(code, id, root) {
|
|
31
|
+
const file = id.replace(/[?#].*$/, "");
|
|
32
|
+
if (!JSX_FILE.test(file) || file.includes(`${node_path.sep}node_modules${node_path.sep}`) || file.includes("\0")) return;
|
|
33
|
+
const path = (0, node_path.relative)(root, file).split(node_path.sep).join("/");
|
|
34
|
+
if (path.startsWith("..")) return void 0;
|
|
35
|
+
const { parseSync } = await import("oxc-parser");
|
|
36
|
+
const parsed = parseSync(file, code, {
|
|
37
|
+
lang: file.endsWith(".tsx") ? "tsx" : "jsx",
|
|
38
|
+
sourceType: "module"
|
|
39
|
+
});
|
|
40
|
+
if (parsed.errors.length > 0) return void 0;
|
|
41
|
+
const lines = lineStarts(code);
|
|
42
|
+
const inserts = [];
|
|
43
|
+
visit(parsed.program, void 0, (node) => {
|
|
44
|
+
const opening = node;
|
|
45
|
+
const tag = opening.name.type === "JSXIdentifier" ? opening.name.name : void 0;
|
|
46
|
+
if (!tag || !/^[a-z]/.test(tag) || SKIP.has(tag)) return;
|
|
47
|
+
if (opening.attributes.some(isTencilAttribute)) return;
|
|
48
|
+
const { line, column } = position(lines, opening.start);
|
|
49
|
+
return `${path}:${line}:${column}`;
|
|
50
|
+
}, inserts);
|
|
51
|
+
if (inserts.length === 0) return void 0;
|
|
52
|
+
const { default: MagicString } = await import("magic-string");
|
|
53
|
+
const output = new MagicString(code);
|
|
54
|
+
for (const insert of inserts) output.appendLeft(insert.at, insert.text);
|
|
55
|
+
return {
|
|
56
|
+
code: output.toString(),
|
|
57
|
+
map: output.generateMap({
|
|
58
|
+
source: file,
|
|
59
|
+
includeContent: true,
|
|
60
|
+
hires: "boundary"
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Walks the AST, tracking the component each JSX element is written in. */
|
|
65
|
+
function visit(node, component, sourceOf, inserts) {
|
|
66
|
+
let current = component;
|
|
67
|
+
const named = componentName(node);
|
|
68
|
+
if (named) current = named;
|
|
69
|
+
if (node.type === "JSXOpeningElement") {
|
|
70
|
+
const source = sourceOf(node);
|
|
71
|
+
if (source) {
|
|
72
|
+
const name = node.name.end;
|
|
73
|
+
const attributes = [`data-tencil-src={${JSON.stringify(source)}}`];
|
|
74
|
+
if (current) attributes.push(`data-tencil-component={${JSON.stringify(current)}}`);
|
|
75
|
+
inserts.push({
|
|
76
|
+
at: name,
|
|
77
|
+
text: ` ${attributes.join(" ")}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const key in node) {
|
|
82
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
83
|
+
const value = node[key];
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
for (const child of value) if (isNode(child)) visit(child, current, sourceOf, inserts);
|
|
86
|
+
} else if (isNode(value)) visit(value, current, sourceOf, inserts);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** `function Card()`, `const Card = () =>`, `const Card = memo(…)`, `class Card`. */
|
|
90
|
+
function componentName(node) {
|
|
91
|
+
let name;
|
|
92
|
+
if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") name = node.id?.name;
|
|
93
|
+
else if (node.type === "VariableDeclarator") {
|
|
94
|
+
const init = node.init;
|
|
95
|
+
if (init && (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression" || init.type === "CallExpression")) name = node.id.name;
|
|
96
|
+
}
|
|
97
|
+
return name && /^[A-Z]/.test(name) ? name : void 0;
|
|
98
|
+
}
|
|
99
|
+
function isTencilAttribute(attribute) {
|
|
100
|
+
const name = attribute.name;
|
|
101
|
+
return attribute.type === "JSXAttribute" && name?.name === "data-tencil-src";
|
|
102
|
+
}
|
|
103
|
+
function isNode(value) {
|
|
104
|
+
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
105
|
+
}
|
|
106
|
+
function lineStarts(code) {
|
|
107
|
+
const starts = [0];
|
|
108
|
+
for (let i = 0; i < code.length; i++) if (code[i] === "\n") starts.push(i + 1);
|
|
109
|
+
return starts;
|
|
110
|
+
}
|
|
111
|
+
/** 1-based line and column of an offset. */
|
|
112
|
+
function position(starts, offset) {
|
|
113
|
+
let low = 0;
|
|
114
|
+
let high = starts.length - 1;
|
|
115
|
+
while (low < high) {
|
|
116
|
+
const middle = low + high + 1 >> 1;
|
|
117
|
+
if (starts[middle] <= offset) low = middle;
|
|
118
|
+
else high = middle - 1;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
line: low + 1,
|
|
122
|
+
column: offset - starts[low] + 1
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const WORKSPACE_FILES = [
|
|
126
|
+
"pnpm-workspace.yaml",
|
|
127
|
+
"turbo.json",
|
|
128
|
+
"nx.json",
|
|
129
|
+
"lerna.json"
|
|
130
|
+
];
|
|
131
|
+
/**
|
|
132
|
+
* The repository a build runs in: the nearest folder with `.git`, else the
|
|
133
|
+
* outermost workspace root (some hosts build without `.git`), else `start`.
|
|
134
|
+
*/
|
|
135
|
+
function repositoryRoot(start) {
|
|
136
|
+
let workspace;
|
|
137
|
+
for (let dir = start;; dir = (0, node_path.dirname)(dir)) {
|
|
138
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(dir, ".git"))) return dir;
|
|
139
|
+
if (WORKSPACE_FILES.some((name) => (0, node_fs.existsSync)((0, node_path.join)(dir, name))) || hasWorkspaces(dir)) workspace = dir;
|
|
140
|
+
if ((0, node_path.dirname)(dir) === dir) return workspace ?? start;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function hasWorkspaces(dir) {
|
|
144
|
+
try {
|
|
145
|
+
return "workspaces" in JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(dir, "package.json"), "utf8"));
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/integrations/next-loader.ts
|
|
152
|
+
let root;
|
|
153
|
+
/**
|
|
154
|
+
* webpack / Turbopack loader for `withTencil`: adds `data-tencil-src` to the
|
|
155
|
+
* elements of a .jsx/.tsx file before Next compiles it.
|
|
156
|
+
*/
|
|
157
|
+
function tencilSourceLoader(source) {
|
|
158
|
+
const callback = this.async();
|
|
159
|
+
root ??= repositoryRoot(this.rootContext ?? process.cwd());
|
|
160
|
+
addSourceAttributes(source, this.resourcePath, root).then((result) => result ? callback(null, result.code, result.map) : callback(null, source), (error) => callback(error));
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
module.exports = tencilSourceLoader;
|
package/dist/next.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as TencilCloudOptions } from "./cloud-CIAGUsk2.mjs";
|
|
2
|
+
//#region src/integrations/next.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Wrap `next.config` for Tencil Cloud preview builds: every element gets a
|
|
5
|
+
* `data-tencil-src` attribute with its file and line, because production React
|
|
6
|
+
* keeps no source info. Without TENCIL_CLOUD, in development and on production
|
|
7
|
+
* deployments the config comes back untouched.
|
|
8
|
+
*
|
|
9
|
+
* export default withTencil(nextConfig);
|
|
10
|
+
*/
|
|
11
|
+
export declare function withTencil<T extends object>(config?: T, options?: {
|
|
12
|
+
cloud?: TencilCloudOptions;
|
|
13
|
+
}): T;
|
|
14
|
+
//#endregion
|
package/dist/next.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { r as resolveCloudBuild } from "./cloud-CiwIrP1h.mjs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
//#region src/integrations/next.ts
|
|
4
|
+
/**
|
|
5
|
+
* Wrap `next.config` for Tencil Cloud preview builds: every element gets a
|
|
6
|
+
* `data-tencil-src` attribute with its file and line, because production React
|
|
7
|
+
* keeps no source info. Without TENCIL_CLOUD, in development and on production
|
|
8
|
+
* deployments the config comes back untouched.
|
|
9
|
+
*
|
|
10
|
+
* export default withTencil(nextConfig);
|
|
11
|
+
*/
|
|
12
|
+
function withTencil(config = {}, options = {}) {
|
|
13
|
+
if (process.env.NODE_ENV === "development") return config;
|
|
14
|
+
if (resolveCloudBuild(process.env, options.cloud).kind !== "on") return config;
|
|
15
|
+
return addSourceLoader(config);
|
|
16
|
+
}
|
|
17
|
+
function addSourceLoader(config) {
|
|
18
|
+
const loader = fileURLToPath(new URL("./next-loader.cjs", import.meta.url));
|
|
19
|
+
const rule = { loaders: [loader] };
|
|
20
|
+
return {
|
|
21
|
+
...config,
|
|
22
|
+
turbopack: {
|
|
23
|
+
...config.turbopack,
|
|
24
|
+
rules: {
|
|
25
|
+
...config.turbopack?.rules,
|
|
26
|
+
"*.tsx": rule,
|
|
27
|
+
"*.jsx": rule
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
webpack(webpackConfig, context) {
|
|
31
|
+
const result = config.webpack ? config.webpack(webpackConfig, context) : webpackConfig;
|
|
32
|
+
result.module ??= {};
|
|
33
|
+
result.module.rules ??= [];
|
|
34
|
+
result.module.rules.unshift({
|
|
35
|
+
test: /\.[jt]sx$/,
|
|
36
|
+
exclude: /node_modules/,
|
|
37
|
+
enforce: "pre",
|
|
38
|
+
use: [{ loader }]
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { withTencil };
|