tempo-sdk 0.0.24 → 0.0.25
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/{chunk-GLTGROU6.js → chunk-NGR2MIC6.js} +164 -3
- package/dist/chunk-NGR2MIC6.js.map +1 -0
- package/dist/index.js +204 -14
- package/dist/index.js.map +1 -1
- package/dist/nextjs/plugin.cjs +7 -1
- package/dist/nextjs/plugin.cjs.map +1 -1
- package/dist/nextjs/plugin.js +1 -1
- package/dist/nextjs-loader.cjs +46 -13
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/nextjs.cjs +166 -4
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.d.cts +13 -1
- package/dist/nextjs.d.ts +13 -1
- package/dist/nextjs.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-GLTGROU6.js.map +0 -1
|
@@ -1,7 +1,164 @@
|
|
|
1
1
|
// nextjs.ts
|
|
2
2
|
import { existsSync, realpathSync } from "fs";
|
|
3
3
|
import { createRequire } from "module";
|
|
4
|
-
import { dirname, resolve } from "path";
|
|
4
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
5
|
+
|
|
6
|
+
// host-identity.ts
|
|
7
|
+
import { readFileSync } from "fs";
|
|
8
|
+
import { resolve } from "path";
|
|
9
|
+
|
|
10
|
+
// package.json
|
|
11
|
+
var package_default = {
|
|
12
|
+
name: "tempo-sdk",
|
|
13
|
+
version: "0.0.25",
|
|
14
|
+
type: "module",
|
|
15
|
+
description: "Tempo SDK \u2014 Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types",
|
|
16
|
+
exports: {
|
|
17
|
+
".": {
|
|
18
|
+
types: "./dist/index.d.ts",
|
|
19
|
+
import: "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./canvas": {
|
|
22
|
+
types: "./dist/canvas/index.d.ts",
|
|
23
|
+
import: "./dist/canvas/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./canvas/interact-projection": {
|
|
26
|
+
types: "./dist/canvas/interact-projection.d.ts",
|
|
27
|
+
import: "./dist/canvas/interact-projection.js"
|
|
28
|
+
},
|
|
29
|
+
"./canvas/parser": {
|
|
30
|
+
types: "./dist/canvas/parser.d.ts",
|
|
31
|
+
import: "./dist/canvas/parser.js"
|
|
32
|
+
},
|
|
33
|
+
"./canvas/editor": {
|
|
34
|
+
types: "./dist/canvas/editor.d.ts",
|
|
35
|
+
import: "./dist/canvas/editor.js"
|
|
36
|
+
},
|
|
37
|
+
"./assets": {
|
|
38
|
+
types: "./dist/assets/index.d.ts",
|
|
39
|
+
import: "./dist/assets/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./assets/parser": {
|
|
42
|
+
types: "./dist/assets/parser.d.ts",
|
|
43
|
+
import: "./dist/assets/parser.js"
|
|
44
|
+
},
|
|
45
|
+
"./assets/editor": {
|
|
46
|
+
types: "./dist/assets/editor.d.ts",
|
|
47
|
+
import: "./dist/assets/editor.js"
|
|
48
|
+
},
|
|
49
|
+
"./nextjs": {
|
|
50
|
+
types: "./dist/nextjs.d.ts",
|
|
51
|
+
import: "./dist/nextjs.js",
|
|
52
|
+
require: "./dist/nextjs.cjs"
|
|
53
|
+
},
|
|
54
|
+
"./nextjs/plugin": {
|
|
55
|
+
types: "./dist/nextjs/plugin.d.ts",
|
|
56
|
+
import: "./dist/nextjs/plugin.js"
|
|
57
|
+
},
|
|
58
|
+
"./expo": {
|
|
59
|
+
types: "./dist/expo-babel-plugin.d.ts",
|
|
60
|
+
import: "./dist/expo-babel-plugin.js",
|
|
61
|
+
require: "./dist/expo-babel-plugin.cjs"
|
|
62
|
+
},
|
|
63
|
+
"./expo/plugin": {
|
|
64
|
+
types: "./dist/expo/plugin.d.ts",
|
|
65
|
+
import: "./dist/expo/plugin.js",
|
|
66
|
+
require: "./dist/expo/plugin.cjs"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
files: [
|
|
70
|
+
"dist"
|
|
71
|
+
],
|
|
72
|
+
scripts: {
|
|
73
|
+
clean: "rm -rf dist",
|
|
74
|
+
build: "pnpm run clean && tsup",
|
|
75
|
+
"build:if-missing": "test -f dist/index.js || pnpm run build",
|
|
76
|
+
prepare: "pnpm run build",
|
|
77
|
+
prepublishOnly: "pnpm build",
|
|
78
|
+
demo: "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
|
|
79
|
+
"demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
|
|
80
|
+
test: "vitest run",
|
|
81
|
+
"test:browser": "vitest run canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts",
|
|
82
|
+
"test:watch": "vitest",
|
|
83
|
+
"test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
|
|
84
|
+
"test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
|
|
85
|
+
"test:nextjs:production": "vitest run nextjs-production.test.ts",
|
|
86
|
+
"test:nextjs": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts nextjs-e2e-correctness.test.ts nextjs-production.test.ts"
|
|
87
|
+
},
|
|
88
|
+
dependencies: {
|
|
89
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
90
|
+
"oxc-parser": "^0.110.0"
|
|
91
|
+
},
|
|
92
|
+
peerDependencies: {
|
|
93
|
+
"@babel/core": "^7.0.0",
|
|
94
|
+
next: "^13 || ^14 || ^15 || ^16",
|
|
95
|
+
react: "^18 || ^19",
|
|
96
|
+
vite: "^5 || ^6 || ^7 || ^8"
|
|
97
|
+
},
|
|
98
|
+
peerDependenciesMeta: {
|
|
99
|
+
"@babel/core": {
|
|
100
|
+
optional: true
|
|
101
|
+
},
|
|
102
|
+
next: {
|
|
103
|
+
optional: true
|
|
104
|
+
},
|
|
105
|
+
vite: {
|
|
106
|
+
optional: true
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
devDependencies: {
|
|
110
|
+
"@babel/core": "^7.29.0",
|
|
111
|
+
"@babel/types": "^7.29.0",
|
|
112
|
+
"@modules/annotation": "workspace:*",
|
|
113
|
+
"@modules/file-parser": "workspace:*",
|
|
114
|
+
"@types/babel__core": "^7.20.5",
|
|
115
|
+
"@types/node": "^25.0.8",
|
|
116
|
+
"@types/react": "catalog:",
|
|
117
|
+
"@types/react-dom": "catalog:",
|
|
118
|
+
"@vitejs/plugin-react": "catalog:",
|
|
119
|
+
playwright: "^1.58.2",
|
|
120
|
+
"react-dom": "catalog:",
|
|
121
|
+
tsup: "^8.5.1",
|
|
122
|
+
typescript: "catalog:",
|
|
123
|
+
vite: "catalog:",
|
|
124
|
+
vitest: "catalog:"
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// host-identity.ts
|
|
129
|
+
var TEMPO_HOST_IDENTITY_CONTRACT_VERSION = 1;
|
|
130
|
+
var TEMPO_WORKSPACE_NONCE_ENV = "TEMPO_WORKSPACE_NONCE";
|
|
131
|
+
var WORKSPACE_NONCE_RELATIVE_PATH = ".tempo/workspace-nonce";
|
|
132
|
+
var MAX_WORKSPACE_NONCE_LENGTH = 128;
|
|
133
|
+
function normalizeWorkspaceNonce(value) {
|
|
134
|
+
const nonce = value?.trim() ?? "";
|
|
135
|
+
return nonce.length > 0 && nonce.length <= MAX_WORKSPACE_NONCE_LENGTH ? nonce : "";
|
|
136
|
+
}
|
|
137
|
+
function readTempoWorkspaceNonce(root = process.cwd()) {
|
|
138
|
+
const fromEnvironment = normalizeWorkspaceNonce(
|
|
139
|
+
process.env[TEMPO_WORKSPACE_NONCE_ENV]
|
|
140
|
+
);
|
|
141
|
+
if (fromEnvironment) return fromEnvironment;
|
|
142
|
+
try {
|
|
143
|
+
return normalizeWorkspaceNonce(
|
|
144
|
+
readFileSync(resolve(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
|
|
145
|
+
);
|
|
146
|
+
} catch {
|
|
147
|
+
return "";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function createTempoHostIdentity(framework, options = {}) {
|
|
151
|
+
return {
|
|
152
|
+
tempoHost: true,
|
|
153
|
+
contractVersion: TEMPO_HOST_IDENTITY_CONTRACT_VERSION,
|
|
154
|
+
workspaceNonce: readTempoWorkspaceNonce(options.root),
|
|
155
|
+
sdkVersion: package_default.version,
|
|
156
|
+
pluginActive: options.pluginActive ?? Boolean(process.env.TEMPO),
|
|
157
|
+
framework
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// nextjs.ts
|
|
5
162
|
var TURBOPACK_RULE_KEY = "*.{tsx,jsx}";
|
|
6
163
|
var requireFromHere = createRequire(
|
|
7
164
|
typeof import.meta.url === "string" && import.meta.url.length > 0 ? import.meta.url : __filename
|
|
@@ -103,7 +260,7 @@ function tempoProjectRoot() {
|
|
|
103
260
|
if (cachedTempoProjectRoot !== null) return cachedTempoProjectRoot;
|
|
104
261
|
let dir = process.cwd();
|
|
105
262
|
while (true) {
|
|
106
|
-
if (existsSync(
|
|
263
|
+
if (existsSync(resolve2(dir, "package.json"))) break;
|
|
107
264
|
const parent = dirname(dir);
|
|
108
265
|
if (parent === dir) break;
|
|
109
266
|
dir = parent;
|
|
@@ -116,6 +273,9 @@ function tempoProjectRoot() {
|
|
|
116
273
|
cachedTempoProjectRoot = canonical;
|
|
117
274
|
return canonical;
|
|
118
275
|
}
|
|
276
|
+
function tempoHostIdentity() {
|
|
277
|
+
return createTempoHostIdentity("nextjs");
|
|
278
|
+
}
|
|
119
279
|
function _resetTempoProjectRoot() {
|
|
120
280
|
cachedTempoProjectRoot = null;
|
|
121
281
|
}
|
|
@@ -169,9 +329,10 @@ var _internal = {
|
|
|
169
329
|
|
|
170
330
|
export {
|
|
171
331
|
tempoProjectRoot,
|
|
332
|
+
tempoHostIdentity,
|
|
172
333
|
_resetTempoProjectRoot,
|
|
173
334
|
tempoNextjsPlugin,
|
|
174
335
|
nextjs_default,
|
|
175
336
|
_internal
|
|
176
337
|
};
|
|
177
|
-
//# sourceMappingURL=chunk-
|
|
338
|
+
//# sourceMappingURL=chunk-NGR2MIC6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../nextjs.ts","../host-identity.ts","../package.json"],"sourcesContent":["/**\n * Next.js plugin that registers the tempo-annotate loader for Webpack and\n * Turbopack. Mirrors the user-facing pattern of `@next/mdx`: a higher-order\n * function that takes plugin options, returns a function that takes the user's\n * `next.config`, and returns a new config with the plugin's loader rules\n * merged in.\n *\n * See SPEC_NEXTJS.md (in this directory) for the full design rationale.\n *\n * @example\n * ```js\n * // next.config.js\n * const tempoNextjsPlugin = require(\"tempo-sdk/nextjs\");\n * module.exports = tempoNextjsPlugin()({ reactStrictMode: true });\n * ```\n */\n\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type { ElementInfo, PropValue } from \"@modules/annotation\";\nimport {\n createTempoHostIdentity,\n type TempoHostIdentity,\n} from \"./host-identity.ts\";\n\n// ---------------------------------------------------------------------------\n// Types. We keep these minimal and self-contained rather than depending on\n// Next.js types — the plugin file is loaded by `next.config.js` evaluation,\n// before `next` itself is fully resolved in some environments.\n// ---------------------------------------------------------------------------\n\nexport type ComputeAnnotatedProps = (\n info: ElementInfo,\n filepath: string,\n modifiedtsMs: number,\n) => Record<string, PropValue>;\n\nexport interface TempoNextjsOptions {\n /** Path to a JS/TS module that default-exports a `ComputeAnnotatedProps`\n * function. Resolved relative to the project root (CWD where the user\n * invokes `next dev` / `next build`). Turbopack does not allow function-\n * valued loader options, so this must be a path. */\n computeAnnotatedPropsModule?: string;\n\n /** File patterns to include. Default: `[\"**\\/*.tsx\", \"**\\/*.jsx\"]`. */\n include?: string | RegExp | Array<string | RegExp>;\n\n /** File patterns to exclude. Default: `[\"**\\/node_modules\\/**\"]`. */\n exclude?: string | RegExp | Array<string | RegExp>;\n\n /** Auto-inject `<meta name=\"tempo-project-root\">` into JSX `<head>`.\n * Default: `true`. */\n autoInjectRootMeta?: boolean;\n\n /** Run the loader during production builds too. Default: `false`. */\n productionBuild?: boolean;\n}\n\ninterface TurbopackRule {\n condition?: unknown;\n loaders?: Array<{ loader: string; options?: unknown } | string>;\n}\n\ninterface TurbopackConfig {\n rules?: Record<string, TurbopackRule | TurbopackRule[]>;\n [key: string]: unknown;\n}\n\ninterface NextConfigLike {\n webpack?:\n | ((\n config: unknown,\n context: { dev: boolean; [k: string]: unknown },\n ) => unknown)\n | null;\n turbopack?: TurbopackConfig;\n experimental?: { turbo?: TurbopackConfig; [k: string]: unknown };\n [key: string]: unknown;\n}\n\ntype NextConfigInput = NextConfigLike | undefined;\n\ninterface WebpackHookContext {\n dev: boolean;\n [key: string]: unknown;\n}\n\ninterface WebpackConfigLike {\n module?: { rules?: unknown[] };\n [key: string]: unknown;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nconst TURBOPACK_RULE_KEY = \"*.{tsx,jsx}\";\n\nconst requireFromHere = createRequire(\n typeof import.meta.url === \"string\" && import.meta.url.length > 0\n ? import.meta.url\n : __filename,\n);\n\nfunction resolveLoaderPath(): string {\n // Production: dist/nextjs.{js,cjs} sits next to dist/nextjs-loader.cjs.\n // Development: source nextjs.ts sits at <pkg>/nextjs.ts; the built\n // loader is at <pkg>/dist/nextjs-loader.cjs. Try both so unit tests\n // running directly against the .ts source file still find the loader.\n for (const candidate of [\"./nextjs-loader.cjs\", \"./dist/nextjs-loader.cjs\"]) {\n try {\n return requireFromHere.resolve(candidate);\n } catch {\n // try next candidate\n }\n }\n throw new Error(\n \"tempo-sdk/nextjs: could not resolve nextjs-loader.cjs. \" +\n \"Run `pnpm build` in the tempo-sdk package to produce the dist/ output.\",\n );\n}\n\ninterface NextVersionInfo {\n major: number;\n minor: number;\n}\n\nfunction detectNextVersion(): NextVersionInfo | null {\n try {\n const pkg = requireFromHere(\"next/package.json\") as { version: string };\n const m = /^(\\d+)\\.(\\d+)/.exec(pkg.version);\n if (!m) return null;\n return { major: Number(m[1]), minor: Number(m[2]) };\n } catch {\n return null;\n }\n}\n\n/** Should the wrapper write to `experimental.turbo` instead of `turbopack`? */\nfunction useExperimentalTurbo(version: NextVersionInfo | null): boolean {\n if (!version) return false;\n if (version.major < 15) return true;\n if (version.major === 15 && version.minor < 3) return true;\n return false;\n}\n\n/** Should the wrapper omit Turbopack registration entirely? Some pre-13 versions\n * error on unknown config keys. */\nfunction shouldOmitTurbopack(version: NextVersionInfo | null): boolean {\n if (!version) return false;\n return version.major < 13;\n}\n\nfunction buildTurbopackRule(\n loaderPath: string,\n options: TempoNextjsOptions,\n): TurbopackRule {\n const loaderOptions: Record<string, unknown> = {};\n if (options.computeAnnotatedPropsModule !== undefined) {\n loaderOptions.computeAnnotatedPropsModule =\n options.computeAnnotatedPropsModule;\n }\n if (options.autoInjectRootMeta !== undefined) {\n loaderOptions.autoInjectRootMeta = options.autoInjectRootMeta;\n }\n\n // {all: [{not: \"foreign\"}, \"development\"]} — exclude node_modules / Next\n // internals AND only run during `next dev`. The \"development\" condition is\n // a Turbopack built-in; it matches both `next dev` and `next build` in dev\n // mode but is inert during a production `next build`.\n const condition = options.productionBuild\n ? { not: \"foreign\" }\n : { all: [{ not: \"foreign\" }, \"development\"] };\n\n return {\n condition,\n loaders: [{ loader: loaderPath, options: loaderOptions }],\n };\n}\n\nfunction mergeTurbopackRules(\n existing: TurbopackConfig | undefined,\n newRule: TurbopackRule,\n): TurbopackConfig {\n const existingRule = existing?.rules?.[TURBOPACK_RULE_KEY];\n let mergedRule: TurbopackRule | TurbopackRule[];\n if (!existingRule) {\n mergedRule = newRule;\n } else if (Array.isArray(existingRule)) {\n mergedRule = [...existingRule, newRule];\n } else {\n mergedRule = [existingRule, newRule];\n }\n return {\n ...existing,\n rules: {\n ...existing?.rules,\n [TURBOPACK_RULE_KEY]: mergedRule,\n },\n };\n}\n\nfunction buildWebpackHook(\n loaderPath: string,\n options: TempoNextjsOptions,\n userWebpack: NextConfigLike[\"webpack\"],\n): NonNullable<NextConfigLike[\"webpack\"]> {\n const loaderOptions: Record<string, unknown> = {};\n if (options.computeAnnotatedPropsModule !== undefined) {\n loaderOptions.computeAnnotatedPropsModule =\n options.computeAnnotatedPropsModule;\n }\n if (options.autoInjectRootMeta !== undefined) {\n loaderOptions.autoInjectRootMeta = options.autoInjectRootMeta;\n }\n\n const allowProduction = options.productionBuild === true;\n\n return (configIn, context) => {\n const config = configIn as WebpackConfigLike;\n const ctx = context as WebpackHookContext;\n if (ctx.dev || allowProduction) {\n config.module ??= {};\n config.module.rules ??= [];\n config.module.rules.push({\n test: /\\.(tsx|jsx)$/,\n exclude: /node_modules/,\n enforce: \"pre\",\n use: [{ loader: loaderPath, options: loaderOptions }],\n });\n }\n if (typeof userWebpack === \"function\") {\n return userWebpack(config, context);\n }\n return config;\n };\n}\n\n// ---------------------------------------------------------------------------\n// tempoProjectRoot — sync helper for Pages Router users (Section 6.4)\n// ---------------------------------------------------------------------------\n\nlet cachedTempoProjectRoot: string | null = null;\n\n/**\n * Returns the canonical project root that the Tempo loader uses to compute\n * `data-tempo-filepath` values. Use this in `pages/_document.tsx` to set the\n * content of `<meta name=\"tempo-project-root\">`, ensuring the manual meta tag\n * value matches what the loader produces.\n */\nexport function tempoProjectRoot(): string {\n if (cachedTempoProjectRoot !== null) return cachedTempoProjectRoot;\n\n // Walk upward from CWD looking for the nearest package.json. CWD is what\n // Next.js itself uses as the project root when the user invokes\n // `next dev` / `next build` — the loader's `rootContext` matches.\n let dir = process.cwd();\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (existsSync(resolve(dir, \"package.json\"))) break;\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n let canonical = dir;\n try {\n canonical = realpathSync.native(dir);\n } catch {\n // Keep `dir` as fallback.\n }\n cachedTempoProjectRoot = canonical;\n return canonical;\n}\n\n/** Request-time identity for a Next route served by a Tempo-enabled host. */\nexport function tempoHostIdentity(): TempoHostIdentity {\n return createTempoHostIdentity(\"nextjs\");\n}\n\n/** Reset the cached project root. For tests only. */\nexport function _resetTempoProjectRoot(): void {\n cachedTempoProjectRoot = null;\n}\n\n// ---------------------------------------------------------------------------\n// tempoNextjsPlugin — the wrapper\n// ---------------------------------------------------------------------------\n\n/**\n * Higher-order function that wraps a Next.js config to register the\n * tempo-annotate loader with both Webpack and Turbopack. No-op when\n * `process.env.TEMPO` is not set.\n *\n * @example\n * ```js\n * // next.config.js\n * const tempoNextjsPlugin = require(\"tempo-sdk/nextjs\");\n * module.exports = tempoNextjsPlugin()({ reactStrictMode: true });\n * ```\n */\nexport function tempoNextjsPlugin(\n pluginOptions: TempoNextjsOptions = {},\n): (inputConfig?: NextConfigLike) => NextConfigLike {\n return (inputConfigArg?: NextConfigLike): NextConfigLike => {\n const inputConfig: NextConfigLike = inputConfigArg ?? {};\n\n if (!process.env.TEMPO) return inputConfig;\n\n // Routed through `_internal.*` so unit tests can spy on these helpers\n // without rewiring the imports.\n const loaderPath = _internal.resolveLoaderPath();\n const version = _internal.detectNextVersion();\n const omitTurbopack = _internal.shouldOmitTurbopack(version);\n const useExperimental = _internal.useExperimentalTurbo(version);\n\n const newRule = buildTurbopackRule(loaderPath, pluginOptions);\n\n const existingTurbo = useExperimental\n ? inputConfig.experimental?.turbo\n : inputConfig.turbopack;\n const mergedTurbo = mergeTurbopackRules(existingTurbo, newRule);\n\n const webpackHook = buildWebpackHook(\n loaderPath,\n pluginOptions,\n inputConfig.webpack ?? null,\n );\n\n const next: NextConfigLike = {\n ...inputConfig,\n webpack: webpackHook,\n };\n\n // Tempo-owned build cache: the supervisor always points managed Next hosts\n // at `.next/tempo`, isolating them from the user's own `next dev` cache.\n // A suffixed sibling is selected only after Next reports a lock conflict\n // for the stable directory. Runs outside Tempo never receive this variable.\n const distDirOverride = process.env.TEMPO_NEXT_DIST_DIR;\n if (distDirOverride) {\n next.distDir = distDirOverride;\n }\n\n if (!omitTurbopack) {\n if (useExperimental) {\n next.experimental = {\n ...inputConfig.experimental,\n turbo: mergedTurbo,\n };\n } else {\n next.turbopack = mergedTurbo;\n }\n }\n\n return next;\n };\n}\n\nexport default tempoNextjsPlugin;\n\n// ---------------------------------------------------------------------------\n// Type re-exports for users writing custom strategies.\n// ---------------------------------------------------------------------------\n\nexport type { ElementInfo, PropValue } from \"@modules/annotation\";\n\n// Internal exports used by tests.\nexport const _internal = {\n buildTurbopackRule,\n mergeTurbopackRules,\n buildWebpackHook,\n detectNextVersion,\n useExperimentalTurbo,\n shouldOmitTurbopack,\n resolveLoaderPath,\n};\n","import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport sdkPackage from \"./package.json\" with { type: \"json\" };\n\nexport const TEMPO_HOST_IDENTITY_ENDPOINT = \"/__tempo/identity\";\nexport const TEMPO_HOST_IDENTITY_CAPABILITY_HEADER =\n \"x-tempo-host-identity\";\nexport const TEMPO_HOST_IDENTITY_CONTRACT_VERSION = 1;\nexport const TEMPO_WORKSPACE_NONCE_ENV = \"TEMPO_WORKSPACE_NONCE\";\nexport const TEMPO_WORKSPACE_NONCE_META_NAME = \"tempo-workspace-nonce\";\n\nconst WORKSPACE_NONCE_RELATIVE_PATH = \".tempo/workspace-nonce\";\nconst MAX_WORKSPACE_NONCE_LENGTH = 128;\n\nexport type TempoHostFramework = \"vite\" | \"nextjs\";\n\nexport interface TempoHostIdentity {\n tempoHost: true;\n contractVersion: number;\n workspaceNonce: string;\n sdkVersion: string;\n pluginActive: boolean;\n framework: TempoHostFramework;\n}\n\nfunction normalizeWorkspaceNonce(value: string | undefined): string {\n const nonce = value?.trim() ?? \"\";\n return nonce.length > 0 && nonce.length <= MAX_WORKSPACE_NONCE_LENGTH\n ? nonce\n : \"\";\n}\n\nexport function readTempoWorkspaceNonce(root = process.cwd()): string {\n const fromEnvironment = normalizeWorkspaceNonce(\n process.env[TEMPO_WORKSPACE_NONCE_ENV],\n );\n if (fromEnvironment) return fromEnvironment;\n try {\n return normalizeWorkspaceNonce(\n readFileSync(resolve(root, WORKSPACE_NONCE_RELATIVE_PATH), \"utf-8\"),\n );\n } catch {\n return \"\";\n }\n}\n\nexport function createTempoHostIdentity(\n framework: TempoHostFramework,\n options: { root?: string; pluginActive?: boolean } = {},\n): TempoHostIdentity {\n return {\n tempoHost: true,\n contractVersion: TEMPO_HOST_IDENTITY_CONTRACT_VERSION,\n workspaceNonce: readTempoWorkspaceNonce(options.root),\n sdkVersion: sdkPackage.version,\n pluginActive: options.pluginActive ?? Boolean(process.env.TEMPO),\n framework,\n };\n}\n","{\n \"name\": \"tempo-sdk\",\n \"version\": \"0.0.25\",\n \"type\": \"module\",\n \"description\": \"Tempo SDK — Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./canvas\": {\n \"types\": \"./dist/canvas/index.d.ts\",\n \"import\": \"./dist/canvas/index.js\"\n },\n \"./canvas/interact-projection\": {\n \"types\": \"./dist/canvas/interact-projection.d.ts\",\n \"import\": \"./dist/canvas/interact-projection.js\"\n },\n \"./canvas/parser\": {\n \"types\": \"./dist/canvas/parser.d.ts\",\n \"import\": \"./dist/canvas/parser.js\"\n },\n \"./canvas/editor\": {\n \"types\": \"./dist/canvas/editor.d.ts\",\n \"import\": \"./dist/canvas/editor.js\"\n },\n \"./assets\": {\n \"types\": \"./dist/assets/index.d.ts\",\n \"import\": \"./dist/assets/index.js\"\n },\n \"./assets/parser\": {\n \"types\": \"./dist/assets/parser.d.ts\",\n \"import\": \"./dist/assets/parser.js\"\n },\n \"./assets/editor\": {\n \"types\": \"./dist/assets/editor.d.ts\",\n \"import\": \"./dist/assets/editor.js\"\n },\n \"./nextjs\": {\n \"types\": \"./dist/nextjs.d.ts\",\n \"import\": \"./dist/nextjs.js\",\n \"require\": \"./dist/nextjs.cjs\"\n },\n \"./nextjs/plugin\": {\n \"types\": \"./dist/nextjs/plugin.d.ts\",\n \"import\": \"./dist/nextjs/plugin.js\"\n },\n \"./expo\": {\n \"types\": \"./dist/expo-babel-plugin.d.ts\",\n \"import\": \"./dist/expo-babel-plugin.js\",\n \"require\": \"./dist/expo-babel-plugin.cjs\"\n },\n \"./expo/plugin\": {\n \"types\": \"./dist/expo/plugin.d.ts\",\n \"import\": \"./dist/expo/plugin.js\",\n \"require\": \"./dist/expo/plugin.cjs\"\n }\n },\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"clean\": \"rm -rf dist\",\n \"build\": \"pnpm run clean && tsup\",\n \"build:if-missing\": \"test -f dist/index.js || pnpm run build\",\n \"prepare\": \"pnpm run build\",\n \"prepublishOnly\": \"pnpm build\",\n \"demo\": \"TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev\",\n \"demo:nextjs\": \"TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev\",\n \"test\": \"vitest run\",\n \"test:browser\": \"vitest run canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts\",\n \"test:watch\": \"vitest\",\n \"test:nextjs:unit\": \"vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts\",\n \"test:nextjs:integration\": \"vitest run nextjs-e2e-correctness.test.ts\",\n \"test:nextjs:production\": \"vitest run nextjs-production.test.ts\",\n \"test:nextjs\": \"vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts nextjs-e2e-correctness.test.ts nextjs-production.test.ts\"\n },\n \"dependencies\": {\n \"@rollup/pluginutils\": \"^5.1.0\",\n \"oxc-parser\": \"^0.110.0\"\n },\n \"peerDependencies\": {\n \"@babel/core\": \"^7.0.0\",\n \"next\": \"^13 || ^14 || ^15 || ^16\",\n \"react\": \"^18 || ^19\",\n \"vite\": \"^5 || ^6 || ^7 || ^8\"\n },\n \"peerDependenciesMeta\": {\n \"@babel/core\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"vite\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@babel/core\": \"^7.29.0\",\n \"@babel/types\": \"^7.29.0\",\n \"@modules/annotation\": \"workspace:*\",\n \"@modules/file-parser\": \"workspace:*\",\n \"@types/babel__core\": \"^7.20.5\",\n \"@types/node\": \"^25.0.8\",\n \"@types/react\": \"catalog:\",\n \"@types/react-dom\": \"catalog:\",\n \"@vitejs/plugin-react\": \"catalog:\",\n \"playwright\": \"^1.58.2\",\n \"react-dom\": \"catalog:\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"catalog:\",\n \"vite\": \"catalog:\",\n \"vitest\": \"catalog:\"\n }\n}\n"],"mappings":";AAiBA,SAAS,YAAY,oBAAoB;AACzC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,WAAAA,gBAAe;;;ACnBjC,SAAS,oBAAoB;AAC7B,SAAS,eAAe;;;ACDxB;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,aAAe;AAAA,EACf,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,MACV,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,gCAAgC;AAAA,MAC9B,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AAAA,MACjB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AAAA,MACjB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,MACV,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AAAA,MACjB,OAAS;AAAA,MACT,QAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AA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BACd,gBAAoC,CAAC,GACa;AAClD,SAAO,CAAC,mBAAoD;AAC1D,UAAM,cAA8B,kBAAkB,CAAC;AAEvD,QAAI,CAAC,QAAQ,IAAI,MAAO,QAAO;AAI/B,UAAM,aAAa,UAAU,kBAAkB;AAC/C,UAAM,UAAU,UAAU,kBAAkB;AAC5C,UAAM,gBAAgB,UAAU,oBAAoB,OAAO;AAC3D,UAAM,kBAAkB,UAAU,qBAAqB,OAAO;AAE9D,UAAM,UAAU,mBAAmB,YAAY,aAAa;AAE5D,UAAM,gBAAgB,kBAClB,YAAY,cAAc,QAC1B,YAAY;AAChB,UAAM,cAAc,oBAAoB,eAAe,OAAO;AAE9D,UAAM,cAAc;AAAA,MAClB;AAAA,MACA;AAAA,MACA,YAAY,WAAW;AAAA,IACzB;AAEA,UAAM,OAAuB;AAAA,MAC3B,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AAMA,UAAM,kBAAkB,QAAQ,IAAI;AACpC,QAAI,iBAAiB;AACnB,WAAK,UAAU;AAAA,IACjB;AAEA,QAAI,CAAC,eAAe;AAClB,UAAI,iBAAiB;AACnB,aAAK,eAAe;AAAA,UAClB,GAAG,YAAY;AAAA,UACf,OAAO;AAAA,QACT;AAAA,MACF,OAAO;AACL,aAAK,YAAY;AAAA,MACnB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,iBAAQ;AASR,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":["resolve","resolve"]}
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
// index.ts
|
|
6
6
|
import {
|
|
7
7
|
existsSync,
|
|
8
|
-
readFileSync,
|
|
8
|
+
readFileSync as readFileSync2,
|
|
9
9
|
realpathSync as realpathSync2,
|
|
10
10
|
statSync as statSync2,
|
|
11
11
|
watch as watchFileSystem
|
|
12
12
|
} from "fs";
|
|
13
13
|
import { createRequire } from "module";
|
|
14
|
-
import { dirname, isAbsolute, join, relative as relative2, resolve } from "path";
|
|
14
|
+
import { dirname, isAbsolute, join, relative as relative2, resolve as resolve2 } from "path";
|
|
15
15
|
import { fileURLToPath } from "url";
|
|
16
16
|
import { createFilter } from "@rollup/pluginutils";
|
|
17
17
|
|
|
@@ -299,6 +299,164 @@ function createHmrGenerationFence() {
|
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
// host-identity.ts
|
|
303
|
+
import { readFileSync } from "fs";
|
|
304
|
+
import { resolve } from "path";
|
|
305
|
+
|
|
306
|
+
// package.json
|
|
307
|
+
var package_default = {
|
|
308
|
+
name: "tempo-sdk",
|
|
309
|
+
version: "0.0.25",
|
|
310
|
+
type: "module",
|
|
311
|
+
description: "Tempo SDK \u2014 Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types",
|
|
312
|
+
exports: {
|
|
313
|
+
".": {
|
|
314
|
+
types: "./dist/index.d.ts",
|
|
315
|
+
import: "./dist/index.js"
|
|
316
|
+
},
|
|
317
|
+
"./canvas": {
|
|
318
|
+
types: "./dist/canvas/index.d.ts",
|
|
319
|
+
import: "./dist/canvas/index.js"
|
|
320
|
+
},
|
|
321
|
+
"./canvas/interact-projection": {
|
|
322
|
+
types: "./dist/canvas/interact-projection.d.ts",
|
|
323
|
+
import: "./dist/canvas/interact-projection.js"
|
|
324
|
+
},
|
|
325
|
+
"./canvas/parser": {
|
|
326
|
+
types: "./dist/canvas/parser.d.ts",
|
|
327
|
+
import: "./dist/canvas/parser.js"
|
|
328
|
+
},
|
|
329
|
+
"./canvas/editor": {
|
|
330
|
+
types: "./dist/canvas/editor.d.ts",
|
|
331
|
+
import: "./dist/canvas/editor.js"
|
|
332
|
+
},
|
|
333
|
+
"./assets": {
|
|
334
|
+
types: "./dist/assets/index.d.ts",
|
|
335
|
+
import: "./dist/assets/index.js"
|
|
336
|
+
},
|
|
337
|
+
"./assets/parser": {
|
|
338
|
+
types: "./dist/assets/parser.d.ts",
|
|
339
|
+
import: "./dist/assets/parser.js"
|
|
340
|
+
},
|
|
341
|
+
"./assets/editor": {
|
|
342
|
+
types: "./dist/assets/editor.d.ts",
|
|
343
|
+
import: "./dist/assets/editor.js"
|
|
344
|
+
},
|
|
345
|
+
"./nextjs": {
|
|
346
|
+
types: "./dist/nextjs.d.ts",
|
|
347
|
+
import: "./dist/nextjs.js",
|
|
348
|
+
require: "./dist/nextjs.cjs"
|
|
349
|
+
},
|
|
350
|
+
"./nextjs/plugin": {
|
|
351
|
+
types: "./dist/nextjs/plugin.d.ts",
|
|
352
|
+
import: "./dist/nextjs/plugin.js"
|
|
353
|
+
},
|
|
354
|
+
"./expo": {
|
|
355
|
+
types: "./dist/expo-babel-plugin.d.ts",
|
|
356
|
+
import: "./dist/expo-babel-plugin.js",
|
|
357
|
+
require: "./dist/expo-babel-plugin.cjs"
|
|
358
|
+
},
|
|
359
|
+
"./expo/plugin": {
|
|
360
|
+
types: "./dist/expo/plugin.d.ts",
|
|
361
|
+
import: "./dist/expo/plugin.js",
|
|
362
|
+
require: "./dist/expo/plugin.cjs"
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
files: [
|
|
366
|
+
"dist"
|
|
367
|
+
],
|
|
368
|
+
scripts: {
|
|
369
|
+
clean: "rm -rf dist",
|
|
370
|
+
build: "pnpm run clean && tsup",
|
|
371
|
+
"build:if-missing": "test -f dist/index.js || pnpm run build",
|
|
372
|
+
prepare: "pnpm run build",
|
|
373
|
+
prepublishOnly: "pnpm build",
|
|
374
|
+
demo: "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
|
|
375
|
+
"demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
|
|
376
|
+
test: "vitest run",
|
|
377
|
+
"test:browser": "vitest run canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts",
|
|
378
|
+
"test:watch": "vitest",
|
|
379
|
+
"test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
|
|
380
|
+
"test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
|
|
381
|
+
"test:nextjs:production": "vitest run nextjs-production.test.ts",
|
|
382
|
+
"test:nextjs": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts nextjs-e2e-correctness.test.ts nextjs-production.test.ts"
|
|
383
|
+
},
|
|
384
|
+
dependencies: {
|
|
385
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
386
|
+
"oxc-parser": "^0.110.0"
|
|
387
|
+
},
|
|
388
|
+
peerDependencies: {
|
|
389
|
+
"@babel/core": "^7.0.0",
|
|
390
|
+
next: "^13 || ^14 || ^15 || ^16",
|
|
391
|
+
react: "^18 || ^19",
|
|
392
|
+
vite: "^5 || ^6 || ^7 || ^8"
|
|
393
|
+
},
|
|
394
|
+
peerDependenciesMeta: {
|
|
395
|
+
"@babel/core": {
|
|
396
|
+
optional: true
|
|
397
|
+
},
|
|
398
|
+
next: {
|
|
399
|
+
optional: true
|
|
400
|
+
},
|
|
401
|
+
vite: {
|
|
402
|
+
optional: true
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
devDependencies: {
|
|
406
|
+
"@babel/core": "^7.29.0",
|
|
407
|
+
"@babel/types": "^7.29.0",
|
|
408
|
+
"@modules/annotation": "workspace:*",
|
|
409
|
+
"@modules/file-parser": "workspace:*",
|
|
410
|
+
"@types/babel__core": "^7.20.5",
|
|
411
|
+
"@types/node": "^25.0.8",
|
|
412
|
+
"@types/react": "catalog:",
|
|
413
|
+
"@types/react-dom": "catalog:",
|
|
414
|
+
"@vitejs/plugin-react": "catalog:",
|
|
415
|
+
playwright: "^1.58.2",
|
|
416
|
+
"react-dom": "catalog:",
|
|
417
|
+
tsup: "^8.5.1",
|
|
418
|
+
typescript: "catalog:",
|
|
419
|
+
vite: "catalog:",
|
|
420
|
+
vitest: "catalog:"
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// host-identity.ts
|
|
425
|
+
var TEMPO_HOST_IDENTITY_ENDPOINT = "/__tempo/identity";
|
|
426
|
+
var TEMPO_HOST_IDENTITY_CAPABILITY_HEADER = "x-tempo-host-identity";
|
|
427
|
+
var TEMPO_HOST_IDENTITY_CONTRACT_VERSION = 1;
|
|
428
|
+
var TEMPO_WORKSPACE_NONCE_ENV = "TEMPO_WORKSPACE_NONCE";
|
|
429
|
+
var TEMPO_WORKSPACE_NONCE_META_NAME = "tempo-workspace-nonce";
|
|
430
|
+
var WORKSPACE_NONCE_RELATIVE_PATH = ".tempo/workspace-nonce";
|
|
431
|
+
var MAX_WORKSPACE_NONCE_LENGTH = 128;
|
|
432
|
+
function normalizeWorkspaceNonce(value) {
|
|
433
|
+
const nonce = value?.trim() ?? "";
|
|
434
|
+
return nonce.length > 0 && nonce.length <= MAX_WORKSPACE_NONCE_LENGTH ? nonce : "";
|
|
435
|
+
}
|
|
436
|
+
function readTempoWorkspaceNonce(root = process.cwd()) {
|
|
437
|
+
const fromEnvironment = normalizeWorkspaceNonce(
|
|
438
|
+
process.env[TEMPO_WORKSPACE_NONCE_ENV]
|
|
439
|
+
);
|
|
440
|
+
if (fromEnvironment) return fromEnvironment;
|
|
441
|
+
try {
|
|
442
|
+
return normalizeWorkspaceNonce(
|
|
443
|
+
readFileSync(resolve(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
|
|
444
|
+
);
|
|
445
|
+
} catch {
|
|
446
|
+
return "";
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function createTempoHostIdentity(framework, options = {}) {
|
|
450
|
+
return {
|
|
451
|
+
tempoHost: true,
|
|
452
|
+
contractVersion: TEMPO_HOST_IDENTITY_CONTRACT_VERSION,
|
|
453
|
+
workspaceNonce: readTempoWorkspaceNonce(options.root),
|
|
454
|
+
sdkVersion: package_default.version,
|
|
455
|
+
pluginActive: options.pluginActive ?? Boolean(process.env.TEMPO),
|
|
456
|
+
framework
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
302
460
|
// missed-change-sweep.ts
|
|
303
461
|
var MISSED_CHANGE_WATCHER_GRACE_MS = 1e3;
|
|
304
462
|
var MISSED_CHANGE_MAX_EMITS_PER_REVISION = 3;
|
|
@@ -379,8 +537,8 @@ function createRapidHotUpdateReplay(options) {
|
|
|
379
537
|
previous.release = void 0;
|
|
380
538
|
if (previous.expiry) cancel(previous.expiry);
|
|
381
539
|
} else {
|
|
382
|
-
burst.gate = new Promise((
|
|
383
|
-
burst.release =
|
|
540
|
+
burst.gate = new Promise((resolve3) => {
|
|
541
|
+
burst.release = resolve3;
|
|
384
542
|
});
|
|
385
543
|
}
|
|
386
544
|
burst.expiry = schedule(() => burst.release?.(), quietMs * 2);
|
|
@@ -654,6 +812,12 @@ function hasRootMetaTag(html) {
|
|
|
654
812
|
function hasSourceIdentityRootMetaTag(html) {
|
|
655
813
|
return /<meta[^>]+name=["']tempo-source-identity-root["'][^>]*>/i.test(html);
|
|
656
814
|
}
|
|
815
|
+
function hasWorkspaceNonceMetaTag(html) {
|
|
816
|
+
return new RegExp(
|
|
817
|
+
`<meta[^>]+name=["']${TEMPO_WORKSPACE_NONCE_META_NAME}["'][^>]*>`,
|
|
818
|
+
"i"
|
|
819
|
+
).test(html);
|
|
820
|
+
}
|
|
657
821
|
function isSameError(left, right) {
|
|
658
822
|
return left.type === right.type && left.message === right.message && left.loc?.line === right.loc?.line && left.loc?.column === right.loc?.column;
|
|
659
823
|
}
|
|
@@ -709,10 +873,10 @@ function createErrorServer(onErrorFile) {
|
|
|
709
873
|
return server;
|
|
710
874
|
}
|
|
711
875
|
function readBody(req) {
|
|
712
|
-
return new Promise((
|
|
876
|
+
return new Promise((resolve3, reject) => {
|
|
713
877
|
const chunks = [];
|
|
714
878
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
715
|
-
req.on("end", () =>
|
|
879
|
+
req.on("end", () => resolve3(Buffer.concat(chunks).toString()));
|
|
716
880
|
req.on("error", reject);
|
|
717
881
|
});
|
|
718
882
|
}
|
|
@@ -732,10 +896,10 @@ function readGeneratedCanvasPaths(source) {
|
|
|
732
896
|
return [...paths];
|
|
733
897
|
}
|
|
734
898
|
async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
|
|
735
|
-
const wrapperPath =
|
|
899
|
+
const wrapperPath = resolve2(server.config.root, ".tempo", "tempo-host.tsx");
|
|
736
900
|
let wrapperSource;
|
|
737
901
|
try {
|
|
738
|
-
wrapperSource =
|
|
902
|
+
wrapperSource = readFileSync2(wrapperPath, "utf8");
|
|
739
903
|
} catch (error) {
|
|
740
904
|
throw new Error(
|
|
741
905
|
`Canvas host wrapper is unavailable at ${wrapperPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -778,6 +942,18 @@ function writeCanvasRegistrationResponseHeaders(res) {
|
|
|
778
942
|
function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
|
|
779
943
|
const url = req.url;
|
|
780
944
|
if (!url?.startsWith("/__tempo/")) return next();
|
|
945
|
+
if (url === TEMPO_HOST_IDENTITY_ENDPOINT && req.method === "GET") {
|
|
946
|
+
const identity = createTempoHostIdentity("vite", {
|
|
947
|
+
root: viteServer.config?.root,
|
|
948
|
+
pluginActive: true
|
|
949
|
+
});
|
|
950
|
+
res.statusCode = 200;
|
|
951
|
+
res.setHeader("Cache-Control", "no-store");
|
|
952
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
953
|
+
res.setHeader(TEMPO_HOST_IDENTITY_CAPABILITY_HEADER, "1");
|
|
954
|
+
res.end(JSON.stringify(identity));
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
781
957
|
if (url === CANVAS_HOST_REGISTRATION_ENDPOINT && req.method === "OPTIONS") {
|
|
782
958
|
writeCanvasRegistrationResponseHeaders(res);
|
|
783
959
|
res.writeHead(204, {
|
|
@@ -867,7 +1043,7 @@ function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs,
|
|
|
867
1043
|
const errorFiles = listErrorFiles();
|
|
868
1044
|
for (const errorFile of errorFiles) {
|
|
869
1045
|
const cleanFile = fsPathFromModuleId(errorFile);
|
|
870
|
-
const file = isAbsolute(cleanFile) ? cleanFile :
|
|
1046
|
+
const file = isAbsolute(cleanFile) ? cleanFile : resolve2(server.config.root, cleanFile);
|
|
871
1047
|
if (!files.has(file)) files.set(file, []);
|
|
872
1048
|
}
|
|
873
1049
|
return files.entries();
|
|
@@ -1038,7 +1214,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1038
1214
|
if (before === void 0) return false;
|
|
1039
1215
|
let source;
|
|
1040
1216
|
try {
|
|
1041
|
-
source =
|
|
1217
|
+
source = readFileSync2(file, "utf8");
|
|
1042
1218
|
} catch {
|
|
1043
1219
|
return false;
|
|
1044
1220
|
}
|
|
@@ -1129,7 +1305,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1129
1305
|
const unresolvedImportWatchTarget = (unresolved) => {
|
|
1130
1306
|
return unresolved.packageName ? packageWatchTarget(
|
|
1131
1307
|
unresolved
|
|
1132
|
-
) :
|
|
1308
|
+
) : resolve2(
|
|
1133
1309
|
dirname(cleanModuleId(unresolved.importer)),
|
|
1134
1310
|
cleanModuleId(unresolved.specifier)
|
|
1135
1311
|
);
|
|
@@ -1218,7 +1394,7 @@ function tempoVitePlugin(options = {}) {
|
|
|
1218
1394
|
if (isRelativeImportSpecifier(unresolved.specifier)) {
|
|
1219
1395
|
const suffixIndex = unresolved.specifier.search(/[?#]/);
|
|
1220
1396
|
const relativePath = suffixIndex < 0 ? unresolved.specifier : unresolved.specifier.slice(0, suffixIndex);
|
|
1221
|
-
const candidate =
|
|
1397
|
+
const candidate = resolve2(
|
|
1222
1398
|
dirname(cleanModuleId(unresolved.importer)),
|
|
1223
1399
|
relativePath
|
|
1224
1400
|
);
|
|
@@ -1378,7 +1554,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1378
1554
|
command = resolvedConfig.command;
|
|
1379
1555
|
canonicalRoot = resolveCanonicalRoot(resolvedConfig.root);
|
|
1380
1556
|
sourceIdentityRoot = options.sourceIdentityRoot ? resolveCanonicalRoot(
|
|
1381
|
-
|
|
1557
|
+
resolve2(resolvedConfig.root, options.sourceIdentityRoot)
|
|
1382
1558
|
) : canonicalRoot;
|
|
1383
1559
|
},
|
|
1384
1560
|
configureServer(server) {
|
|
@@ -1534,6 +1710,20 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1534
1710
|
injectTo: "head"
|
|
1535
1711
|
});
|
|
1536
1712
|
}
|
|
1713
|
+
const workspaceNonce = createTempoHostIdentity("vite", {
|
|
1714
|
+
root: canonicalRoot,
|
|
1715
|
+
pluginActive: true
|
|
1716
|
+
}).workspaceNonce;
|
|
1717
|
+
if (workspaceNonce && !hasWorkspaceNonceMetaTag(html)) {
|
|
1718
|
+
tags.push({
|
|
1719
|
+
tag: "meta",
|
|
1720
|
+
attrs: {
|
|
1721
|
+
name: TEMPO_WORKSPACE_NONCE_META_NAME,
|
|
1722
|
+
content: workspaceNonce
|
|
1723
|
+
},
|
|
1724
|
+
injectTo: "head"
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1537
1727
|
const requestPath = context?.originalUrl ?? context?.path;
|
|
1538
1728
|
const isDeclarativeCanvasHost = requestPath ? isDeclarativeCanvasHostRequest(requestPath) : false;
|
|
1539
1729
|
if (requestPath && !isDeclarativeCanvasHost) {
|
|
@@ -1564,7 +1754,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
|
|
|
1564
1754
|
try {
|
|
1565
1755
|
const filepath = relative2(canonicalRoot, cleanId);
|
|
1566
1756
|
const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
|
|
1567
|
-
const rawSource =
|
|
1757
|
+
const rawSource = readFileSync2(cleanId, "utf8");
|
|
1568
1758
|
const sourceVersion = sourceVersionHash(rawSource);
|
|
1569
1759
|
defaultExportIdentityByFile.set(
|
|
1570
1760
|
canonicalIdentityKey(cleanId),
|