tempo-sdk 0.0.6 → 0.0.7

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../nextjs.ts"],"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\";\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?: ((config: unknown, context: { dev: boolean; [k: string]: unknown }) => unknown) | 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(import.meta.url);\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 = 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 = 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/** 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 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"],"mappings":";AAiBA,SAAS,YAAY,oBAAoB;AACzC,SAAS,qBAAqB;AAC9B,SAAS,SAAS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3
+ import { createRequire } from "module";
4
+ import { dirname, resolve } from "path";
5
+ var TURBOPACK_RULE_KEY = "*.{tsx,jsx}";
6
+ var requireFromHere = createRequire(import.meta.url);
7
+ function resolveLoaderPath() {
8
+ for (const candidate of ["./nextjs-loader.cjs", "./dist/nextjs-loader.cjs"]) {
9
+ try {
10
+ return requireFromHere.resolve(candidate);
11
+ } catch {
12
+ }
13
+ }
14
+ throw new Error(
15
+ "tempo-sdk/nextjs: could not resolve nextjs-loader.cjs. Run `pnpm build` in the tempo-sdk package to produce the dist/ output."
16
+ );
17
+ }
18
+ function detectNextVersion() {
19
+ try {
20
+ const pkg = requireFromHere("next/package.json");
21
+ const match = /^(\d+)\.(\d+)/.exec(pkg.version ?? "");
22
+ if (!match) return null;
23
+ return { major: Number(match[1]), minor: Number(match[2]) };
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ function useExperimentalTurbo(version) {
29
+ if (!version) return false;
30
+ if (version.major < 15) return true;
31
+ if (version.major === 15 && version.minor < 3) return true;
32
+ return false;
33
+ }
34
+ function shouldOmitTurbopack(version) {
35
+ if (!version) return false;
36
+ return version.major < 13;
37
+ }
38
+ function buildTurbopackRule(loaderPath, options) {
39
+ const loaderOptions = {};
40
+ if (options.computeAnnotatedPropsModule !== void 0) {
41
+ loaderOptions.computeAnnotatedPropsModule = options.computeAnnotatedPropsModule;
42
+ }
43
+ if (options.autoInjectRootMeta !== void 0) {
44
+ loaderOptions.autoInjectRootMeta = options.autoInjectRootMeta;
45
+ }
46
+ const condition = options.productionBuild ? { not: "foreign" } : { all: [{ not: "foreign" }, "development"] };
47
+ return {
48
+ condition,
49
+ loaders: [{ loader: loaderPath, options: loaderOptions }]
50
+ };
51
+ }
52
+ function mergeTurbopackRules(existing, newRule) {
53
+ const existingRule = existing?.rules?.[TURBOPACK_RULE_KEY];
54
+ let mergedRule;
55
+ if (!existingRule) {
56
+ mergedRule = newRule;
57
+ } else if (Array.isArray(existingRule)) {
58
+ mergedRule = [...existingRule, newRule];
59
+ } else {
60
+ mergedRule = [existingRule, newRule];
61
+ }
62
+ return {
63
+ ...existing,
64
+ rules: {
65
+ ...existing?.rules,
66
+ [TURBOPACK_RULE_KEY]: mergedRule
67
+ }
68
+ };
69
+ }
70
+ function buildWebpackHook(loaderPath, options, userWebpack) {
71
+ const loaderOptions = {};
72
+ if (options.computeAnnotatedPropsModule !== void 0) {
73
+ loaderOptions.computeAnnotatedPropsModule = options.computeAnnotatedPropsModule;
74
+ }
75
+ if (options.autoInjectRootMeta !== void 0) {
76
+ loaderOptions.autoInjectRootMeta = options.autoInjectRootMeta;
77
+ }
78
+ const allowProduction = options.productionBuild === true;
79
+ return (configIn, context) => {
80
+ var _a;
81
+ const config = configIn;
82
+ if (context.dev || allowProduction) {
83
+ config.module ?? (config.module = {});
84
+ (_a = config.module).rules ?? (_a.rules = []);
85
+ config.module.rules.push({
86
+ test: /\.(tsx|jsx)$/,
87
+ exclude: /node_modules/,
88
+ enforce: "pre",
89
+ use: [{ loader: loaderPath, options: loaderOptions }]
90
+ });
91
+ }
92
+ if (typeof userWebpack === "function") {
93
+ return userWebpack(config, context);
94
+ }
95
+ return config;
96
+ };
97
+ }
98
+ var cachedTempoProjectRoot = null;
99
+ function tempoProjectRoot() {
100
+ if (cachedTempoProjectRoot !== null) return cachedTempoProjectRoot;
101
+ let dir = process.cwd();
102
+ while (true) {
103
+ if (existsSync(resolve(dir, "package.json"))) break;
104
+ const parent = dirname(dir);
105
+ if (parent === dir) break;
106
+ dir = parent;
107
+ }
108
+ let canonical = dir;
109
+ try {
110
+ canonical = realpathSync.native(dir);
111
+ } catch {
112
+ }
113
+ cachedTempoProjectRoot = canonical;
114
+ return canonical;
115
+ }
116
+ function _resetTempoProjectRoot() {
117
+ cachedTempoProjectRoot = null;
118
+ }
119
+ function tempoNextjsPlugin(pluginOptions = {}) {
120
+ return (inputConfigArg) => {
121
+ const inputConfig = inputConfigArg ?? {};
122
+ if (!process.env.TEMPO) return inputConfig;
123
+ const loaderPath = _internal.resolveLoaderPath();
124
+ const version = _internal.detectNextVersion();
125
+ const omitTurbopack = _internal.shouldOmitTurbopack(version);
126
+ const useExperimental = _internal.useExperimentalTurbo(version);
127
+ const newRule = buildTurbopackRule(loaderPath, pluginOptions);
128
+ const existingTurbo = useExperimental ? inputConfig.experimental?.turbo : inputConfig.turbopack;
129
+ const mergedTurbo = mergeTurbopackRules(existingTurbo, newRule);
130
+ const webpackHook = buildWebpackHook(
131
+ loaderPath,
132
+ pluginOptions,
133
+ inputConfig.webpack ?? null
134
+ );
135
+ const next = {
136
+ ...inputConfig,
137
+ webpack: webpackHook
138
+ };
139
+ if (!omitTurbopack) {
140
+ if (useExperimental) {
141
+ next.experimental = {
142
+ ...inputConfig.experimental,
143
+ turbo: mergedTurbo
144
+ };
145
+ } else {
146
+ next.turbopack = mergedTurbo;
147
+ }
148
+ }
149
+ return next;
150
+ };
151
+ }
152
+ var _internal = {
153
+ buildTurbopackRule,
154
+ mergeTurbopackRules,
155
+ buildWebpackHook,
156
+ detectNextVersion,
157
+ useExperimentalTurbo,
158
+ shouldOmitTurbopack,
159
+ resolveLoaderPath
160
+ };
161
+
162
+ export {
163
+ tempoProjectRoot,
164
+ _resetTempoProjectRoot,
165
+ tempoNextjsPlugin,
166
+ _internal
167
+ };
168
+ //# sourceMappingURL=chunk-G4OYWYQA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../nextjs.ts"],"sourcesContent":["import { existsSync, realpathSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type { ElementInfo, PropValue } from \"@modules/annotation\";\n\nexport type { ElementInfo, PropValue } from \"@modules/annotation\";\n\nexport type ComputeAnnotatedProps = (\n info: ElementInfo,\n filepath: string,\n modifiedtsMs: number,\n) => Record<string, PropValue>;\n\nexport interface TempoNextjsOptions {\n computeAnnotatedPropsModule?: string;\n include?: string | RegExp | Array<string | RegExp>;\n exclude?: string | RegExp | Array<string | RegExp>;\n autoInjectRootMeta?: boolean;\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: {\n dev: boolean;\n [key: string]: unknown;\n },\n ) => unknown)\n | null;\n turbopack?: TurbopackConfig;\n experimental?: {\n turbo?: TurbopackConfig;\n [key: string]: unknown;\n };\n [key: string]: unknown;\n}\n\nconst TURBOPACK_RULE_KEY = \"*.{tsx,jsx}\";\n\nconst requireFromHere = createRequire(import.meta.url);\n\nfunction resolveLoaderPath(): string {\n for (const candidate of [\"./nextjs-loader.cjs\", \"./dist/nextjs-loader.cjs\"]) {\n try {\n return requireFromHere.resolve(candidate);\n } catch {\n // Try the next build/publish shape.\n }\n }\n throw new Error(\n \"tempo-sdk/nextjs: could not resolve nextjs-loader.cjs. 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 match = /^(\\d+)\\.(\\d+)/.exec(pkg.version ?? \"\");\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n } catch {\n return null;\n }\n}\n\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\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 const condition = options.productionBuild\n ? { not: \"foreign\" }\n : { all: [{ not: \"foreign\" }, \"development\"] };\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 const allowProduction = options.productionBuild === true;\n\n return (configIn, context) => {\n const config = configIn as {\n module?: {\n rules?: unknown[];\n };\n };\n if (context.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\nlet cachedTempoProjectRoot: string | null = null;\n\nexport function tempoProjectRoot(): string {\n if (cachedTempoProjectRoot !== null) return cachedTempoProjectRoot;\n let dir = process.cwd();\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 // Fall back to the resolved directory.\n }\n cachedTempoProjectRoot = canonical;\n return canonical;\n}\n\nexport function _resetTempoProjectRoot(): void {\n cachedTempoProjectRoot = null;\n}\n\nexport function tempoNextjsPlugin(\n pluginOptions: TempoNextjsOptions = {},\n): (inputConfig?: NextConfigLike) => NextConfigLike {\n return (inputConfigArg) => {\n const inputConfig = inputConfigArg ?? {};\n if (!process.env.TEMPO) return inputConfig;\n\n const loaderPath = _internal.resolveLoaderPath();\n const version = _internal.detectNextVersion();\n const omitTurbopack = _internal.shouldOmitTurbopack(version);\n const useExperimental = _internal.useExperimentalTurbo(version);\n const newRule = buildTurbopackRule(loaderPath, pluginOptions);\n const existingTurbo = useExperimental\n ? inputConfig.experimental?.turbo\n : inputConfig.turbopack;\n const mergedTurbo = mergeTurbopackRules(existingTurbo, newRule);\n const webpackHook = buildWebpackHook(\n loaderPath,\n pluginOptions,\n inputConfig.webpack ?? null,\n );\n const next: NextConfigLike = {\n ...inputConfig,\n webpack: webpackHook,\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 const _internal = {\n buildTurbopackRule,\n mergeTurbopackRules,\n buildWebpackHook,\n detectNextVersion,\n useExperimentalTurbo,\n shouldOmitTurbopack,\n resolveLoaderPath,\n};\n"],"mappings":";AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,eAAe;AAgDjC,IAAM,qBAAqB;AAE3B,IAAM,kBAAkB,cAAc,YAAY,GAAG;AAErD,SAAS,oBAA4B;AACnC,aAAW,aAAa,CAAC,uBAAuB,0BAA0B,GAAG;AAC3E,QAAI;AACF,aAAO,gBAAgB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;AAAA,EAER;AACA,2BAAyB;AACzB,SAAO;AACT;AAEO,SAAS,yBAA+B;AAC7C,2BAAyB;AAC3B;AAEO,SAAS,kBACd,gBAAoC,CAAC,GACa;AAClD,SAAO,CAAC,mBAAmB;AACzB,UAAM,cAAc,kBAAkB,CAAC;AACvC,QAAI,CAAC,QAAQ,IAAI,MAAO,QAAO;AAE/B,UAAM,aAAa,UAAU,kBAAkB;AAC/C,UAAM,UAAU,UAAU,kBAAkB;AAC5C,UAAM,gBAAgB,UAAU,oBAAoB,OAAO;AAC3D,UAAM,kBAAkB,UAAU,qBAAqB,OAAO;AAC9D,UAAM,UAAU,mBAAmB,YAAY,aAAa;AAC5D,UAAM,gBAAgB,kBAClB,YAAY,cAAc,QAC1B,YAAY;AAChB,UAAM,cAAc,oBAAoB,eAAe,OAAO;AAC9D,UAAM,cAAc;AAAA,MAClB;AAAA,MACA;AAAA,MACA,YAAY,WAAW;AAAA,IACzB;AACA,UAAM,OAAuB;AAAA,MAC3B,GAAG;AAAA,MACH,SAAS;AAAA,IACX;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;AAEO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
@@ -0,0 +1,170 @@
1
+ // nextjs.ts
2
+ import { existsSync, realpathSync } from "fs";
3
+ import { createRequire } from "module";
4
+ import { dirname, resolve } from "path";
5
+ var TURBOPACK_RULE_KEY = "*.{tsx,jsx}";
6
+ var requireFromHere = createRequire(
7
+ typeof __filename !== "undefined" ? __filename : import.meta.url
8
+ );
9
+ function resolveLoaderPath() {
10
+ for (const candidate of ["./nextjs-loader.cjs", "./dist/nextjs-loader.cjs"]) {
11
+ try {
12
+ return requireFromHere.resolve(candidate);
13
+ } catch {
14
+ }
15
+ }
16
+ throw new Error(
17
+ "tempo-sdk/nextjs: could not resolve nextjs-loader.cjs. Run `pnpm build` in the tempo-sdk package to produce the dist/ output."
18
+ );
19
+ }
20
+ function detectNextVersion() {
21
+ try {
22
+ const pkg = requireFromHere("next/package.json");
23
+ const match = /^(\d+)\.(\d+)/.exec(pkg.version ?? "");
24
+ if (!match) return null;
25
+ return { major: Number(match[1]), minor: Number(match[2]) };
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+ function useExperimentalTurbo(version) {
31
+ if (!version) return false;
32
+ if (version.major < 15) return true;
33
+ if (version.major === 15 && version.minor < 3) return true;
34
+ return false;
35
+ }
36
+ function shouldOmitTurbopack(version) {
37
+ if (!version) return false;
38
+ return version.major < 13;
39
+ }
40
+ function buildTurbopackRule(loaderPath, options) {
41
+ const loaderOptions = {};
42
+ if (options.computeAnnotatedPropsModule !== void 0) {
43
+ loaderOptions.computeAnnotatedPropsModule = options.computeAnnotatedPropsModule;
44
+ }
45
+ if (options.autoInjectRootMeta !== void 0) {
46
+ loaderOptions.autoInjectRootMeta = options.autoInjectRootMeta;
47
+ }
48
+ const condition = options.productionBuild ? { not: "foreign" } : { all: [{ not: "foreign" }, "development"] };
49
+ return {
50
+ condition,
51
+ loaders: [{ loader: loaderPath, options: loaderOptions }]
52
+ };
53
+ }
54
+ function mergeTurbopackRules(existing, newRule) {
55
+ const existingRule = existing?.rules?.[TURBOPACK_RULE_KEY];
56
+ let mergedRule;
57
+ if (!existingRule) {
58
+ mergedRule = newRule;
59
+ } else if (Array.isArray(existingRule)) {
60
+ mergedRule = [...existingRule, newRule];
61
+ } else {
62
+ mergedRule = [existingRule, newRule];
63
+ }
64
+ return {
65
+ ...existing,
66
+ rules: {
67
+ ...existing?.rules,
68
+ [TURBOPACK_RULE_KEY]: mergedRule
69
+ }
70
+ };
71
+ }
72
+ function buildWebpackHook(loaderPath, options, userWebpack) {
73
+ const loaderOptions = {};
74
+ if (options.computeAnnotatedPropsModule !== void 0) {
75
+ loaderOptions.computeAnnotatedPropsModule = options.computeAnnotatedPropsModule;
76
+ }
77
+ if (options.autoInjectRootMeta !== void 0) {
78
+ loaderOptions.autoInjectRootMeta = options.autoInjectRootMeta;
79
+ }
80
+ const allowProduction = options.productionBuild === true;
81
+ return (configIn, context) => {
82
+ var _a;
83
+ const config = configIn;
84
+ if (context.dev || allowProduction) {
85
+ config.module ?? (config.module = {});
86
+ (_a = config.module).rules ?? (_a.rules = []);
87
+ config.module.rules.push({
88
+ test: /\.(tsx|jsx)$/,
89
+ exclude: /node_modules/,
90
+ enforce: "pre",
91
+ use: [{ loader: loaderPath, options: loaderOptions }]
92
+ });
93
+ }
94
+ if (typeof userWebpack === "function") {
95
+ return userWebpack(config, context);
96
+ }
97
+ return config;
98
+ };
99
+ }
100
+ var cachedTempoProjectRoot = null;
101
+ function tempoProjectRoot() {
102
+ if (cachedTempoProjectRoot !== null) return cachedTempoProjectRoot;
103
+ let dir = process.cwd();
104
+ while (true) {
105
+ if (existsSync(resolve(dir, "package.json"))) break;
106
+ const parent = dirname(dir);
107
+ if (parent === dir) break;
108
+ dir = parent;
109
+ }
110
+ let canonical = dir;
111
+ try {
112
+ canonical = realpathSync.native(dir);
113
+ } catch {
114
+ }
115
+ cachedTempoProjectRoot = canonical;
116
+ return canonical;
117
+ }
118
+ function _resetTempoProjectRoot() {
119
+ cachedTempoProjectRoot = null;
120
+ }
121
+ function tempoNextjsPlugin(pluginOptions = {}) {
122
+ return (inputConfigArg) => {
123
+ const inputConfig = inputConfigArg ?? {};
124
+ if (!process.env.TEMPO) return inputConfig;
125
+ const loaderPath = _internal.resolveLoaderPath();
126
+ const version = _internal.detectNextVersion();
127
+ const omitTurbopack = _internal.shouldOmitTurbopack(version);
128
+ const useExperimental = _internal.useExperimentalTurbo(version);
129
+ const newRule = buildTurbopackRule(loaderPath, pluginOptions);
130
+ const existingTurbo = useExperimental ? inputConfig.experimental?.turbo : inputConfig.turbopack;
131
+ const mergedTurbo = mergeTurbopackRules(existingTurbo, newRule);
132
+ const webpackHook = buildWebpackHook(
133
+ loaderPath,
134
+ pluginOptions,
135
+ inputConfig.webpack ?? null
136
+ );
137
+ const next = {
138
+ ...inputConfig,
139
+ webpack: webpackHook
140
+ };
141
+ if (!omitTurbopack) {
142
+ if (useExperimental) {
143
+ next.experimental = {
144
+ ...inputConfig.experimental,
145
+ turbo: mergedTurbo
146
+ };
147
+ } else {
148
+ next.turbopack = mergedTurbo;
149
+ }
150
+ }
151
+ return next;
152
+ };
153
+ }
154
+ var _internal = {
155
+ buildTurbopackRule,
156
+ mergeTurbopackRules,
157
+ buildWebpackHook,
158
+ detectNextVersion,
159
+ useExperimentalTurbo,
160
+ shouldOmitTurbopack,
161
+ resolveLoaderPath
162
+ };
163
+
164
+ export {
165
+ tempoProjectRoot,
166
+ _resetTempoProjectRoot,
167
+ tempoNextjsPlugin,
168
+ _internal
169
+ };
170
+ //# sourceMappingURL=chunk-UWWB27SE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../nextjs.ts"],"sourcesContent":["import { existsSync, realpathSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type { ElementInfo, PropValue } from \"@modules/annotation\";\n\nexport type { ElementInfo, PropValue } from \"@modules/annotation\";\n\nexport type ComputeAnnotatedProps = (\n info: ElementInfo,\n filepath: string,\n modifiedtsMs: number,\n) => Record<string, PropValue>;\n\nexport interface TempoNextjsOptions {\n computeAnnotatedPropsModule?: string;\n include?: string | RegExp | Array<string | RegExp>;\n exclude?: string | RegExp | Array<string | RegExp>;\n autoInjectRootMeta?: boolean;\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: {\n dev: boolean;\n [key: string]: unknown;\n },\n ) => unknown)\n | null;\n turbopack?: TurbopackConfig;\n experimental?: {\n turbo?: TurbopackConfig;\n [key: string]: unknown;\n };\n [key: string]: unknown;\n}\n\nconst TURBOPACK_RULE_KEY = \"*.{tsx,jsx}\";\n\nconst requireFromHere = createRequire(\n typeof __filename !== \"undefined\" ? __filename : import.meta.url,\n);\n\nfunction resolveLoaderPath(): string {\n for (const candidate of [\"./nextjs-loader.cjs\", \"./dist/nextjs-loader.cjs\"]) {\n try {\n return requireFromHere.resolve(candidate);\n } catch {\n // Try the next build/publish shape.\n }\n }\n throw new Error(\n \"tempo-sdk/nextjs: could not resolve nextjs-loader.cjs. 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 match = /^(\\d+)\\.(\\d+)/.exec(pkg.version ?? \"\");\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n } catch {\n return null;\n }\n}\n\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\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 const condition = options.productionBuild\n ? { not: \"foreign\" }\n : { all: [{ not: \"foreign\" }, \"development\"] };\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 const allowProduction = options.productionBuild === true;\n\n return (configIn, context) => {\n const config = configIn as {\n module?: {\n rules?: unknown[];\n };\n };\n if (context.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\nlet cachedTempoProjectRoot: string | null = null;\n\nexport function tempoProjectRoot(): string {\n if (cachedTempoProjectRoot !== null) return cachedTempoProjectRoot;\n let dir = process.cwd();\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 // Fall back to the resolved directory.\n }\n cachedTempoProjectRoot = canonical;\n return canonical;\n}\n\nexport function _resetTempoProjectRoot(): void {\n cachedTempoProjectRoot = null;\n}\n\nexport function tempoNextjsPlugin(\n pluginOptions: TempoNextjsOptions = {},\n): (inputConfig?: NextConfigLike) => NextConfigLike {\n return (inputConfigArg) => {\n const inputConfig = inputConfigArg ?? {};\n if (!process.env.TEMPO) return inputConfig;\n\n const loaderPath = _internal.resolveLoaderPath();\n const version = _internal.detectNextVersion();\n const omitTurbopack = _internal.shouldOmitTurbopack(version);\n const useExperimental = _internal.useExperimentalTurbo(version);\n const newRule = buildTurbopackRule(loaderPath, pluginOptions);\n const existingTurbo = useExperimental\n ? inputConfig.experimental?.turbo\n : inputConfig.turbopack;\n const mergedTurbo = mergeTurbopackRules(existingTurbo, newRule);\n const webpackHook = buildWebpackHook(\n loaderPath,\n pluginOptions,\n inputConfig.webpack ?? null,\n );\n const next: NextConfigLike = {\n ...inputConfig,\n webpack: webpackHook,\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 const _internal = {\n buildTurbopackRule,\n mergeTurbopackRules,\n buildWebpackHook,\n detectNextVersion,\n useExperimentalTurbo,\n shouldOmitTurbopack,\n resolveLoaderPath,\n};\n"],"mappings":";AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,eAAe;AAgDjC,IAAM,qBAAqB;AAE3B,IAAM,kBAAkB;AAAA,EACtB,OAAO,eAAe,cAAc,aAAa,YAAY;AAC/D;AAEA,SAAS,oBAA4B;AACnC,aAAW,aAAa,CAAC,uBAAuB,0BAA0B,GAAG;AAC3E,QAAI;AACF,aAAO,gBAAgB,QAAQ,SAAS;AAAA,IAC1C,QAAQ;AAAA,IAER;AAAA,EACF;AACA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AAOA,SAAS,oBA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C,GACa;AAClD,SAAO,CAAC,mBAAmB;AACzB,UAAM,cAAc,kBAAkB,CAAC;AACvC,QAAI,CAAC,QAAQ,IAAI,MAAO,QAAO;AAE/B,UAAM,aAAa,UAAU,kBAAkB;AAC/C,UAAM,UAAU,UAAU,kBAAkB;AAC5C,UAAM,gBAAgB,UAAU,oBAAoB,OAAO;AAC3D,UAAM,kBAAkB,UAAU,qBAAqB,OAAO;AAC9D,UAAM,UAAU,mBAAmB,YAAY,aAAa;AAC5D,UAAM,gBAAgB,kBAClB,YAAY,cAAc,QAC1B,YAAY;AAChB,UAAM,cAAc,oBAAoB,eAAe,OAAO;AAC9D,UAAM,cAAc;AAAA,MAClB;AAAA,MACA;AAAA,MACA,YAAY,WAAW;AAAA,IACzB;AACA,UAAM,OAAuB;AAAA,MAC3B,GAAG;AAAA,MACH,SAAS;AAAA,IACX;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;AAEO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
package/dist/index.d.ts CHANGED
@@ -42,15 +42,6 @@ interface StoryboardLayout {
42
42
  width: number;
43
43
  height: number;
44
44
  zIndex?: number;
45
- /** Opt the storyboard wrapper's runtime size out of the legacy
46
- * page-metadata path: when set, the wrapper sizes to whatever rect
47
- * the storyboard's root element renders at (tracked via
48
- * `useStoryboardRootSizeSync`) rather than to the cached `width`/
49
- * `height` above. The cached values still drive the cold-boot
50
- * render before the iframe captures and the layers panel size
51
- * fields. New frames drawn via the canvas-edit-pipeline land in
52
- * this mode by default. */
53
- intrinsicSizing?: "root-element";
54
45
  }
55
46
  interface TempoStoryboard {
56
47
  render: () => ReactElement;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // index.ts
2
- import { existsSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
- import { dirname, relative, resolve } from "path";
2
+ import { realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
+ import { relative } from "path";
4
4
 
5
5
  // ../../modules/annotation/annotate-file.ts
6
6
  import { parseSync as parseSync2 } from "oxc-parser";
@@ -111,17 +111,6 @@ function annotateFile(source, filename, computeAnnotatedProps) {
111
111
  return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
112
112
  }
113
113
 
114
- // ../../modules/annotation/has-expression-children.ts
115
- function hasJsxExpressionChild(element) {
116
- for (const child of element.children) {
117
- if (child.type !== "JSXExpressionContainer") continue;
118
- const expression = child.expression;
119
- if (!expression || expression.type === "JSXEmptyExpression") continue;
120
- return true;
121
- }
122
- return false;
123
- }
124
-
125
114
  // index.ts
126
115
  import { createFilter } from "@rollup/pluginutils";
127
116
 
@@ -692,47 +681,6 @@ function hasRootMetaTag(html) {
692
681
  function isIntrinsicElement(tagName) {
693
682
  return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
694
683
  }
695
- var IMPORT_RESOLUTION_EXTENSIONS = [
696
- "",
697
- ".tsx",
698
- ".ts",
699
- ".jsx",
700
- ".js",
701
- ".mjs",
702
- ".cjs",
703
- ".json"
704
- ];
705
- function hasJsxAttribute(info, attrName) {
706
- for (const attr of info.element.openingElement.attributes) {
707
- const name = attr.name;
708
- if (name?.name === attrName) return true;
709
- }
710
- return false;
711
- }
712
- function pathExistsWithCommonExtensions(basePath) {
713
- for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
714
- const candidate = `${basePath}${ext}`;
715
- if (existsSync(candidate)) return true;
716
- }
717
- for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
718
- const candidate = resolve(basePath, `index${ext}`);
719
- if (existsSync(candidate)) return true;
720
- }
721
- return false;
722
- }
723
- function findMissingRelativeImport(source, importerPath) {
724
- const importPattern = /(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?["'](\.{1,2}\/[^"']+)["']/g;
725
- let match;
726
- while (match = importPattern.exec(source)) {
727
- const specifier = match[1];
728
- if (!specifier) continue;
729
- const resolved = resolve(dirname(importerPath), specifier);
730
- if (!pathExistsWithCommonExtensions(resolved)) {
731
- return specifier;
732
- }
733
- }
734
- return null;
735
- }
736
684
  var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
737
685
  "area",
738
686
  "base",
@@ -804,10 +752,10 @@ function createErrorServer() {
804
752
  return server;
805
753
  }
806
754
  function readBody(req) {
807
- return new Promise((resolve2, reject) => {
755
+ return new Promise((resolve, reject) => {
808
756
  const chunks = [];
809
757
  req.on("data", (chunk) => chunks.push(chunk));
810
- req.on("end", () => resolve2(Buffer.concat(chunks).toString()));
758
+ req.on("end", () => resolve(Buffer.concat(chunks).toString()));
811
759
  req.on("error", reject);
812
760
  });
813
761
  }
@@ -858,29 +806,6 @@ function handleErrorMiddleware(errorServer, req, res, next) {
858
806
  }
859
807
  next();
860
808
  }
861
- function parseViteInternalServerError(message) {
862
- if (!message.includes("Internal server error:")) return null;
863
- const lines = message.split(/\r?\n/);
864
- const firstLine = lines.find(
865
- (line) => line.includes("Internal server error:")
866
- );
867
- if (!firstLine) return null;
868
- const fileLine = lines.find((line) => line.trim().startsWith("File:"));
869
- const pluginLine = lines.find((line) => line.trim().startsWith("Plugin:"));
870
- const locMatch = fileLine?.match(/File:\s*(.+?)(?::(\d+):(\d+))?\s*$/);
871
- return {
872
- type: "compile",
873
- message: firstLine.replace(/^.*Internal server error:\s*/, "").trim(),
874
- stack: message,
875
- file: locMatch?.[1]?.trim(),
876
- plugin: pluginLine?.replace(/^.*Plugin:\s*/, "").trim(),
877
- loc: locMatch?.[2] && locMatch?.[3] ? {
878
- file: locMatch[1]?.trim(),
879
- line: Number(locMatch[2]),
880
- column: Number(locMatch[3])
881
- } : void 0
882
- };
883
- }
884
809
  function tempoVitePlugin(options = {}) {
885
810
  const enabled = !!process.env.TEMPO;
886
811
  const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
@@ -940,18 +865,6 @@ function tempoVitePlugin(options = {}) {
940
865
  if (clientHot && clientHot !== server.ws) {
941
866
  interceptHmrSend(clientHot);
942
867
  }
943
- if (server.config?.logger?.error) {
944
- const originalLoggerError = server.config.logger.error.bind(
945
- server.config.logger
946
- );
947
- server.config.logger.error = ((message, options2) => {
948
- const error = parseViteInternalServerError(String(message));
949
- if (error) {
950
- errorServer.setError(error);
951
- }
952
- return originalLoggerError(message, options2);
953
- });
954
- }
955
868
  },
956
869
  transformIndexHtml(html) {
957
870
  if (!enabled || command !== "serve") {
@@ -984,43 +897,22 @@ function tempoVitePlugin(options = {}) {
984
897
  }
985
898
  try {
986
899
  const filepath = relative(canonicalRoot, cleanId);
987
- const missingImport = findMissingRelativeImport(source, cleanId);
988
- if (missingImport) {
989
- const message = `Failed to resolve import "${missingImport}" from "${filepath}". Does the file exist?`;
990
- errorServer.setError({
991
- type: "compile",
992
- message,
993
- file: cleanId,
994
- plugin: "vite:import-analysis"
995
- });
996
- } else {
997
- errorServer.clearErrorForModules([cleanId, filepath]);
998
- }
999
900
  const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
1000
901
  const typeInfo = typeAnalyzer?.analyzeFileTypes(cleanId, source);
1001
902
  const result = annotateFile(source, cleanId, (info) => {
1002
903
  const userProps = computeAnnotatedProps(info, filepath, modifiedtsMs);
1003
- const dynamicChildrenProp = hasJsxExpressionChild(info.element) ? { "data-tempo-dynamic-children": true } : {};
1004
904
  if (isIntrinsicElement(info.tagName)) {
1005
905
  return {
1006
906
  ...userProps,
1007
- ...dynamicChildrenProp,
1008
- "data-tempo-supports-children": hasJsxAttribute(
1009
- info,
1010
- "data-tempo-supports-children"
1011
- ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
907
+ "data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
1012
908
  };
1013
909
  }
1014
910
  const support = typeInfo?.get(info.element.openingElement.start);
1015
911
  return {
1016
912
  ...userProps,
1017
- ...dynamicChildrenProp,
1018
913
  "data-tempo-supports-style": support?.supportsStyle ?? false,
1019
914
  "data-tempo-supports-classname": support?.supportsClassName ?? false,
1020
- "data-tempo-supports-children": hasJsxAttribute(
1021
- info,
1022
- "data-tempo-supports-children"
1023
- ) ? void 0 : support?.supportsChildren ?? false
915
+ "data-tempo-supports-children": support?.supportsChildren ?? false
1024
916
  };
1025
917
  });
1026
918
  if (result.elementsAnnotated === 0) {