@designtools/next-plugin 0.1.7 → 0.1.8

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/index.js CHANGED
@@ -73,8 +73,8 @@ ${entry}
73
73
  } catch {
74
74
  }
75
75
  }
76
- function discoverComponentFiles(projectRoot) {
77
- const dirs = ["components/ui", "src/components/ui"];
76
+ function discoverComponentFiles(projectRoot, overrideDir) {
77
+ const dirs = overrideDir ? [overrideDir] : ["components/ui", "src/components/ui"];
78
78
  for (const dir of dirs) {
79
79
  const fullDir = import_path.default.join(projectRoot, dir);
80
80
  if (import_fs.default.existsSync(fullDir)) {
@@ -87,7 +87,13 @@ function discoverComponentFiles(projectRoot) {
87
87
 
88
88
  // src/index.ts
89
89
  function withDesigntools(nextConfig = {}) {
90
- return {
90
+ const projectRoot = process.cwd();
91
+ const appDir = import_path2.default.resolve(projectRoot, "app");
92
+ try {
93
+ generateComponentRegistry(appDir);
94
+ } catch {
95
+ }
96
+ const result = {
91
97
  ...nextConfig,
92
98
  webpack(config, context) {
93
99
  if (context.dev) {
@@ -115,11 +121,6 @@ function withDesigntools(nextConfig = {}) {
115
121
  }
116
122
  ]
117
123
  });
118
- const appDir = import_path2.default.resolve(context.dir, "app");
119
- try {
120
- generateComponentRegistry(appDir);
121
- } catch {
122
- }
123
124
  }
124
125
  if (typeof nextConfig.webpack === "function") {
125
126
  return nextConfig.webpack(config, context);
@@ -127,6 +128,54 @@ function withDesigntools(nextConfig = {}) {
127
128
  return config;
128
129
  }
129
130
  };
131
+ if (process.env.TURBOPACK) {
132
+ const sourceLoader = {
133
+ loader: import_path2.default.resolve(__dirname, "loader.js"),
134
+ options: {
135
+ // In webpack, context.dir provides this. In turbopack config time,
136
+ // process.cwd() is equivalent since next.config runs from the project root.
137
+ cwd: projectRoot
138
+ }
139
+ };
140
+ const mountLoader = {
141
+ loader: import_path2.default.resolve(__dirname, "codesurface-mount-loader.js")
142
+ };
143
+ const sourceRule = {
144
+ loaders: [sourceLoader],
145
+ as: "*.tsx",
146
+ condition: {
147
+ path: /\.(tsx|jsx)$/
148
+ }
149
+ };
150
+ const wildcardGlob = "{*,designtools-source}";
151
+ let wildcardRule = nextConfig.turbopack?.rules?.[wildcardGlob] ?? [];
152
+ wildcardRule = [
153
+ ...Array.isArray(wildcardRule) ? wildcardRule : [wildcardRule],
154
+ sourceRule
155
+ ];
156
+ const mountRule = {
157
+ loaders: [mountLoader],
158
+ as: "*.tsx",
159
+ condition: {
160
+ path: /layout\.(tsx|jsx)$/
161
+ }
162
+ };
163
+ const mountGlob = "{*,designtools-mount}";
164
+ let mountGlobRule = nextConfig.turbopack?.rules?.[mountGlob] ?? [];
165
+ mountGlobRule = [
166
+ ...Array.isArray(mountGlobRule) ? mountGlobRule : [mountGlobRule],
167
+ mountRule
168
+ ];
169
+ result.turbopack = {
170
+ ...nextConfig.turbopack,
171
+ rules: {
172
+ ...nextConfig.turbopack?.rules,
173
+ [wildcardGlob]: wildcardRule,
174
+ [mountGlob]: mountGlobRule
175
+ }
176
+ };
177
+ }
178
+ return result;
130
179
  }
131
180
  // Annotate the CommonJS export names for ESM import in node:
132
181
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -41,8 +41,8 @@ ${entry}
41
41
  } catch {
42
42
  }
43
43
  }
44
- function discoverComponentFiles(projectRoot) {
45
- const dirs = ["components/ui", "src/components/ui"];
44
+ function discoverComponentFiles(projectRoot, overrideDir) {
45
+ const dirs = overrideDir ? [overrideDir] : ["components/ui", "src/components/ui"];
46
46
  for (const dir of dirs) {
47
47
  const fullDir = path.join(projectRoot, dir);
48
48
  if (fs.existsSync(fullDir)) {
@@ -55,7 +55,13 @@ function discoverComponentFiles(projectRoot) {
55
55
 
56
56
  // src/index.ts
57
57
  function withDesigntools(nextConfig = {}) {
58
- return {
58
+ const projectRoot = process.cwd();
59
+ const appDir = path2.resolve(projectRoot, "app");
60
+ try {
61
+ generateComponentRegistry(appDir);
62
+ } catch {
63
+ }
64
+ const result = {
59
65
  ...nextConfig,
60
66
  webpack(config, context) {
61
67
  if (context.dev) {
@@ -83,11 +89,6 @@ function withDesigntools(nextConfig = {}) {
83
89
  }
84
90
  ]
85
91
  });
86
- const appDir = path2.resolve(context.dir, "app");
87
- try {
88
- generateComponentRegistry(appDir);
89
- } catch {
90
- }
91
92
  }
92
93
  if (typeof nextConfig.webpack === "function") {
93
94
  return nextConfig.webpack(config, context);
@@ -95,6 +96,54 @@ function withDesigntools(nextConfig = {}) {
95
96
  return config;
96
97
  }
97
98
  };
99
+ if (process.env.TURBOPACK) {
100
+ const sourceLoader = {
101
+ loader: path2.resolve(__dirname, "loader.js"),
102
+ options: {
103
+ // In webpack, context.dir provides this. In turbopack config time,
104
+ // process.cwd() is equivalent since next.config runs from the project root.
105
+ cwd: projectRoot
106
+ }
107
+ };
108
+ const mountLoader = {
109
+ loader: path2.resolve(__dirname, "codesurface-mount-loader.js")
110
+ };
111
+ const sourceRule = {
112
+ loaders: [sourceLoader],
113
+ as: "*.tsx",
114
+ condition: {
115
+ path: /\.(tsx|jsx)$/
116
+ }
117
+ };
118
+ const wildcardGlob = "{*,designtools-source}";
119
+ let wildcardRule = nextConfig.turbopack?.rules?.[wildcardGlob] ?? [];
120
+ wildcardRule = [
121
+ ...Array.isArray(wildcardRule) ? wildcardRule : [wildcardRule],
122
+ sourceRule
123
+ ];
124
+ const mountRule = {
125
+ loaders: [mountLoader],
126
+ as: "*.tsx",
127
+ condition: {
128
+ path: /layout\.(tsx|jsx)$/
129
+ }
130
+ };
131
+ const mountGlob = "{*,designtools-mount}";
132
+ let mountGlobRule = nextConfig.turbopack?.rules?.[mountGlob] ?? [];
133
+ mountGlobRule = [
134
+ ...Array.isArray(mountGlobRule) ? mountGlobRule : [mountGlobRule],
135
+ mountRule
136
+ ];
137
+ result.turbopack = {
138
+ ...nextConfig.turbopack,
139
+ rules: {
140
+ ...nextConfig.turbopack?.rules,
141
+ [wildcardGlob]: wildcardRule,
142
+ [mountGlob]: mountGlobRule
143
+ }
144
+ };
145
+ }
146
+ return result;
98
147
  }
99
148
  export {
100
149
  withDesigntools
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designtools/next-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": {
package/src/index.ts CHANGED
@@ -11,7 +11,17 @@ import path from "path";
11
11
  import { generateComponentRegistry } from "./preview-route.js";
12
12
 
13
13
  export function withDesigntools<T extends Record<string, any>>(nextConfig: T = {} as T): T {
14
- return {
14
+ // Generate the component registry unconditionally (filesystem operation, not loader-specific).
15
+ // Use process.cwd() since withDesigntools() is called at config time from the project root.
16
+ const projectRoot = process.cwd();
17
+ const appDir = path.resolve(projectRoot, "app");
18
+ try {
19
+ generateComponentRegistry(appDir);
20
+ } catch {
21
+ // Non-fatal — isolation feature just won't work
22
+ }
23
+
24
+ const result: any = {
15
25
  ...nextConfig,
16
26
  webpack(config: any, context: any) {
17
27
  // Only add the loader in development
@@ -42,14 +52,6 @@ export function withDesigntools<T extends Record<string, any>>(nextConfig: T = {
42
52
  },
43
53
  ],
44
54
  });
45
-
46
- // Generate the component registry for isolation overlay
47
- const appDir = path.resolve(context.dir, "app");
48
- try {
49
- generateComponentRegistry(appDir);
50
- } catch {
51
- // Non-fatal — isolation feature just won't work
52
- }
53
55
  }
54
56
 
55
57
  // Call the user's webpack config if provided
@@ -60,4 +62,64 @@ export function withDesigntools<T extends Record<string, any>>(nextConfig: T = {
60
62
  return config;
61
63
  },
62
64
  };
65
+
66
+ // Turbopack support — register the same loaders via turbopack.rules
67
+ // following the exact pattern used by @next/mdx.
68
+ if (process.env.TURBOPACK) {
69
+ const sourceLoader = {
70
+ loader: path.resolve(__dirname, "loader.js"),
71
+ options: {
72
+ // In webpack, context.dir provides this. In turbopack config time,
73
+ // process.cwd() is equivalent since next.config runs from the project root.
74
+ cwd: projectRoot,
75
+ },
76
+ };
77
+
78
+ const mountLoader = {
79
+ loader: path.resolve(__dirname, "codesurface-mount-loader.js"),
80
+ };
81
+
82
+ // Source annotation rule — uses a unique glob like @next/mdx does
83
+ const sourceRule = {
84
+ loaders: [sourceLoader],
85
+ as: "*.tsx",
86
+ condition: {
87
+ path: /\.(tsx|jsx)$/,
88
+ },
89
+ };
90
+
91
+ const wildcardGlob = "{*,designtools-source}";
92
+ let wildcardRule = (nextConfig as any).turbopack?.rules?.[wildcardGlob] ?? [];
93
+ wildcardRule = [
94
+ ...(Array.isArray(wildcardRule) ? wildcardRule : [wildcardRule]),
95
+ sourceRule,
96
+ ];
97
+
98
+ // Mount loader rule for root layout files
99
+ const mountRule = {
100
+ loaders: [mountLoader],
101
+ as: "*.tsx",
102
+ condition: {
103
+ path: /layout\.(tsx|jsx)$/,
104
+ },
105
+ };
106
+
107
+ const mountGlob = "{*,designtools-mount}";
108
+ let mountGlobRule = (nextConfig as any).turbopack?.rules?.[mountGlob] ?? [];
109
+ mountGlobRule = [
110
+ ...(Array.isArray(mountGlobRule) ? mountGlobRule : [mountGlobRule]),
111
+ mountRule,
112
+ ];
113
+
114
+ result.turbopack = {
115
+ ...(nextConfig as any).turbopack,
116
+ rules: {
117
+ ...(nextConfig as any).turbopack?.rules,
118
+ [wildcardGlob]: wildcardRule,
119
+ [mountGlob]: mountGlobRule,
120
+ },
121
+ };
122
+ }
123
+
124
+ return result as T;
63
125
  }
@@ -71,9 +71,10 @@ function ensureGitignore(projectRoot: string): void {
71
71
  /**
72
72
  * Scan the project for component .tsx files in known directories.
73
73
  * Returns paths like "components/ui/button" (no extension).
74
+ * Accepts an optional override directory to skip hardcoded candidates.
74
75
  */
75
- function discoverComponentFiles(projectRoot: string): string[] {
76
- const dirs = ["components/ui", "src/components/ui"];
76
+ function discoverComponentFiles(projectRoot: string, overrideDir?: string): string[] {
77
+ const dirs = overrideDir ? [overrideDir] : ["components/ui", "src/components/ui"];
77
78
  for (const dir of dirs) {
78
79
  const fullDir = path.join(projectRoot, dir);
79
80
  if (fs.existsSync(fullDir)) {