tempo-sdk 0.0.5 → 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,108 @@
1
+ import { ElementInfo, PropValue } from '@modules/annotation';
2
+ export { ElementInfo, PropValue } from '@modules/annotation';
3
+
4
+ /**
5
+ * Next.js plugin that registers the tempo-annotate loader for Webpack and
6
+ * Turbopack. Mirrors the user-facing pattern of `@next/mdx`: a higher-order
7
+ * function that takes plugin options, returns a function that takes the user's
8
+ * `next.config`, and returns a new config with the plugin's loader rules
9
+ * merged in.
10
+ *
11
+ * See SPEC_NEXTJS.md (in this directory) for the full design rationale.
12
+ *
13
+ * @example
14
+ * ```js
15
+ * // next.config.js
16
+ * const tempoNextjsPlugin = require("tempo-sdk/nextjs");
17
+ * module.exports = tempoNextjsPlugin()({ reactStrictMode: true });
18
+ * ```
19
+ */
20
+
21
+ type ComputeAnnotatedProps = (info: ElementInfo, filepath: string, modifiedtsMs: number) => Record<string, PropValue>;
22
+ interface TempoNextjsOptions {
23
+ /** Path to a JS/TS module that default-exports a `ComputeAnnotatedProps`
24
+ * function. Resolved relative to the project root (CWD where the user
25
+ * invokes `next dev` / `next build`). Turbopack does not allow function-
26
+ * valued loader options, so this must be a path. */
27
+ computeAnnotatedPropsModule?: string;
28
+ /** File patterns to include. Default: `["**\/*.tsx", "**\/*.jsx"]`. */
29
+ include?: string | RegExp | Array<string | RegExp>;
30
+ /** File patterns to exclude. Default: `["**\/node_modules\/**"]`. */
31
+ exclude?: string | RegExp | Array<string | RegExp>;
32
+ /** Auto-inject `<meta name="tempo-project-root">` into JSX `<head>`.
33
+ * Default: `true`. */
34
+ autoInjectRootMeta?: boolean;
35
+ /** Run the loader during production builds too. Default: `false`. */
36
+ productionBuild?: boolean;
37
+ }
38
+ interface TurbopackRule {
39
+ condition?: unknown;
40
+ loaders?: Array<{
41
+ loader: string;
42
+ options?: unknown;
43
+ } | string>;
44
+ }
45
+ interface TurbopackConfig {
46
+ rules?: Record<string, TurbopackRule | TurbopackRule[]>;
47
+ [key: string]: unknown;
48
+ }
49
+ interface NextConfigLike {
50
+ webpack?: ((config: unknown, context: {
51
+ dev: boolean;
52
+ [k: string]: unknown;
53
+ }) => unknown) | null;
54
+ turbopack?: TurbopackConfig;
55
+ experimental?: {
56
+ turbo?: TurbopackConfig;
57
+ [k: string]: unknown;
58
+ };
59
+ [key: string]: unknown;
60
+ }
61
+ declare function resolveLoaderPath(): string;
62
+ interface NextVersionInfo {
63
+ major: number;
64
+ minor: number;
65
+ }
66
+ declare function detectNextVersion(): NextVersionInfo | null;
67
+ /** Should the wrapper write to `experimental.turbo` instead of `turbopack`? */
68
+ declare function useExperimentalTurbo(version: NextVersionInfo | null): boolean;
69
+ /** Should the wrapper omit Turbopack registration entirely? Some pre-13 versions
70
+ * error on unknown config keys. */
71
+ declare function shouldOmitTurbopack(version: NextVersionInfo | null): boolean;
72
+ declare function buildTurbopackRule(loaderPath: string, options: TempoNextjsOptions): TurbopackRule;
73
+ declare function mergeTurbopackRules(existing: TurbopackConfig | undefined, newRule: TurbopackRule): TurbopackConfig;
74
+ declare function buildWebpackHook(loaderPath: string, options: TempoNextjsOptions, userWebpack: NextConfigLike["webpack"]): NonNullable<NextConfigLike["webpack"]>;
75
+ /**
76
+ * Returns the canonical project root that the Tempo loader uses to compute
77
+ * `data-tempo-filepath` values. Use this in `pages/_document.tsx` to set the
78
+ * content of `<meta name="tempo-project-root">`, ensuring the manual meta tag
79
+ * value matches what the loader produces.
80
+ */
81
+ declare function tempoProjectRoot(): string;
82
+ /** Reset the cached project root. For tests only. */
83
+ declare function _resetTempoProjectRoot(): void;
84
+ /**
85
+ * Higher-order function that wraps a Next.js config to register the
86
+ * tempo-annotate loader with both Webpack and Turbopack. No-op when
87
+ * `process.env.TEMPO` is not set.
88
+ *
89
+ * @example
90
+ * ```js
91
+ * // next.config.js
92
+ * const tempoNextjsPlugin = require("tempo-sdk/nextjs");
93
+ * module.exports = tempoNextjsPlugin()({ reactStrictMode: true });
94
+ * ```
95
+ */
96
+ declare function tempoNextjsPlugin(pluginOptions?: TempoNextjsOptions): (inputConfig?: NextConfigLike) => NextConfigLike;
97
+
98
+ declare const _internal: {
99
+ buildTurbopackRule: typeof buildTurbopackRule;
100
+ mergeTurbopackRules: typeof mergeTurbopackRules;
101
+ buildWebpackHook: typeof buildWebpackHook;
102
+ detectNextVersion: typeof detectNextVersion;
103
+ useExperimentalTurbo: typeof useExperimentalTurbo;
104
+ shouldOmitTurbopack: typeof shouldOmitTurbopack;
105
+ resolveLoaderPath: typeof resolveLoaderPath;
106
+ };
107
+
108
+ export { type ComputeAnnotatedProps, type TempoNextjsOptions, _internal, _resetTempoProjectRoot, tempoNextjsPlugin as default, tempoNextjsPlugin, tempoProjectRoot };
@@ -0,0 +1,108 @@
1
+ import { ElementInfo, PropValue } from '@modules/annotation';
2
+ export { ElementInfo, PropValue } from '@modules/annotation';
3
+
4
+ /**
5
+ * Next.js plugin that registers the tempo-annotate loader for Webpack and
6
+ * Turbopack. Mirrors the user-facing pattern of `@next/mdx`: a higher-order
7
+ * function that takes plugin options, returns a function that takes the user's
8
+ * `next.config`, and returns a new config with the plugin's loader rules
9
+ * merged in.
10
+ *
11
+ * See SPEC_NEXTJS.md (in this directory) for the full design rationale.
12
+ *
13
+ * @example
14
+ * ```js
15
+ * // next.config.js
16
+ * const tempoNextjsPlugin = require("tempo-sdk/nextjs");
17
+ * module.exports = tempoNextjsPlugin()({ reactStrictMode: true });
18
+ * ```
19
+ */
20
+
21
+ type ComputeAnnotatedProps = (info: ElementInfo, filepath: string, modifiedtsMs: number) => Record<string, PropValue>;
22
+ interface TempoNextjsOptions {
23
+ /** Path to a JS/TS module that default-exports a `ComputeAnnotatedProps`
24
+ * function. Resolved relative to the project root (CWD where the user
25
+ * invokes `next dev` / `next build`). Turbopack does not allow function-
26
+ * valued loader options, so this must be a path. */
27
+ computeAnnotatedPropsModule?: string;
28
+ /** File patterns to include. Default: `["**\/*.tsx", "**\/*.jsx"]`. */
29
+ include?: string | RegExp | Array<string | RegExp>;
30
+ /** File patterns to exclude. Default: `["**\/node_modules\/**"]`. */
31
+ exclude?: string | RegExp | Array<string | RegExp>;
32
+ /** Auto-inject `<meta name="tempo-project-root">` into JSX `<head>`.
33
+ * Default: `true`. */
34
+ autoInjectRootMeta?: boolean;
35
+ /** Run the loader during production builds too. Default: `false`. */
36
+ productionBuild?: boolean;
37
+ }
38
+ interface TurbopackRule {
39
+ condition?: unknown;
40
+ loaders?: Array<{
41
+ loader: string;
42
+ options?: unknown;
43
+ } | string>;
44
+ }
45
+ interface TurbopackConfig {
46
+ rules?: Record<string, TurbopackRule | TurbopackRule[]>;
47
+ [key: string]: unknown;
48
+ }
49
+ interface NextConfigLike {
50
+ webpack?: ((config: unknown, context: {
51
+ dev: boolean;
52
+ [k: string]: unknown;
53
+ }) => unknown) | null;
54
+ turbopack?: TurbopackConfig;
55
+ experimental?: {
56
+ turbo?: TurbopackConfig;
57
+ [k: string]: unknown;
58
+ };
59
+ [key: string]: unknown;
60
+ }
61
+ declare function resolveLoaderPath(): string;
62
+ interface NextVersionInfo {
63
+ major: number;
64
+ minor: number;
65
+ }
66
+ declare function detectNextVersion(): NextVersionInfo | null;
67
+ /** Should the wrapper write to `experimental.turbo` instead of `turbopack`? */
68
+ declare function useExperimentalTurbo(version: NextVersionInfo | null): boolean;
69
+ /** Should the wrapper omit Turbopack registration entirely? Some pre-13 versions
70
+ * error on unknown config keys. */
71
+ declare function shouldOmitTurbopack(version: NextVersionInfo | null): boolean;
72
+ declare function buildTurbopackRule(loaderPath: string, options: TempoNextjsOptions): TurbopackRule;
73
+ declare function mergeTurbopackRules(existing: TurbopackConfig | undefined, newRule: TurbopackRule): TurbopackConfig;
74
+ declare function buildWebpackHook(loaderPath: string, options: TempoNextjsOptions, userWebpack: NextConfigLike["webpack"]): NonNullable<NextConfigLike["webpack"]>;
75
+ /**
76
+ * Returns the canonical project root that the Tempo loader uses to compute
77
+ * `data-tempo-filepath` values. Use this in `pages/_document.tsx` to set the
78
+ * content of `<meta name="tempo-project-root">`, ensuring the manual meta tag
79
+ * value matches what the loader produces.
80
+ */
81
+ declare function tempoProjectRoot(): string;
82
+ /** Reset the cached project root. For tests only. */
83
+ declare function _resetTempoProjectRoot(): void;
84
+ /**
85
+ * Higher-order function that wraps a Next.js config to register the
86
+ * tempo-annotate loader with both Webpack and Turbopack. No-op when
87
+ * `process.env.TEMPO` is not set.
88
+ *
89
+ * @example
90
+ * ```js
91
+ * // next.config.js
92
+ * const tempoNextjsPlugin = require("tempo-sdk/nextjs");
93
+ * module.exports = tempoNextjsPlugin()({ reactStrictMode: true });
94
+ * ```
95
+ */
96
+ declare function tempoNextjsPlugin(pluginOptions?: TempoNextjsOptions): (inputConfig?: NextConfigLike) => NextConfigLike;
97
+
98
+ declare const _internal: {
99
+ buildTurbopackRule: typeof buildTurbopackRule;
100
+ mergeTurbopackRules: typeof mergeTurbopackRules;
101
+ buildWebpackHook: typeof buildWebpackHook;
102
+ detectNextVersion: typeof detectNextVersion;
103
+ useExperimentalTurbo: typeof useExperimentalTurbo;
104
+ shouldOmitTurbopack: typeof shouldOmitTurbopack;
105
+ resolveLoaderPath: typeof resolveLoaderPath;
106
+ };
107
+
108
+ export { type ComputeAnnotatedProps, type TempoNextjsOptions, _internal, _resetTempoProjectRoot, tempoNextjsPlugin as default, tempoNextjsPlugin, tempoProjectRoot };
package/dist/nextjs.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ _internal,
3
+ _resetTempoProjectRoot,
4
+ nextjs_default,
5
+ tempoNextjsPlugin,
6
+ tempoProjectRoot
7
+ } from "./chunk-BRNAFXET.js";
8
+ export {
9
+ _internal,
10
+ _resetTempoProjectRoot,
11
+ nextjs_default as default,
12
+ tempoNextjsPlugin,
13
+ tempoProjectRoot
14
+ };
15
+ //# sourceMappingURL=nextjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "name": "tempo-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
- "description": "Tempo SDK — Vite plugin for JSX annotation and shared page/storyboard types",
5
+ "description": "Tempo SDK — Vite + Next.js plugins for JSX annotation and shared page/storyboard types",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/index.js",
9
- "types": "./dist/index.d.ts"
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ },
11
+ "./nextjs": {
12
+ "types": "./dist/nextjs.d.ts",
13
+ "import": "./dist/nextjs.js",
14
+ "require": "./dist/nextjs.cjs"
15
+ },
16
+ "./nextjs/plugin": {
17
+ "types": "./dist/nextjs/plugin.d.ts",
18
+ "import": "./dist/nextjs/plugin.js"
10
19
  }
11
20
  },
12
21
  "files": [
@@ -19,7 +28,16 @@
19
28
  "peerDependencies": {
20
29
  "react": "^18 || ^19",
21
30
  "typescript": "^5.0.0",
22
- "vite": "^5 || ^6 || ^7"
31
+ "vite": "^5 || ^6 || ^7",
32
+ "next": "^13 || ^14 || ^15 || ^16"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "vite": {
36
+ "optional": true
37
+ },
38
+ "next": {
39
+ "optional": true
40
+ }
23
41
  },
24
42
  "devDependencies": {
25
43
  "@types/node": "^25.0.8",
@@ -30,13 +48,19 @@
30
48
  "typescript": "^5.9.3",
31
49
  "vite": "^7.3.1",
32
50
  "vitest": "^4.0.18",
51
+ "@modules/file-parser": "0.0.1",
33
52
  "@modules/annotation": "0.0.1",
34
53
  "@modules/typescript": "0.0.1"
35
54
  },
36
55
  "scripts": {
37
56
  "build": "tsup",
38
57
  "demo": "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
58
+ "demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
39
59
  "test": "vitest run",
40
- "test:watch": "vitest"
60
+ "test:watch": "vitest",
61
+ "test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
62
+ "test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
63
+ "test:nextjs:production": "vitest run nextjs-production.test.ts",
64
+ "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"
41
65
  }
42
66
  }