@designtools/next-plugin 0.1.7 → 0.1.9

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
+ condition: {
146
+ not: "foreign"
147
+ }
148
+ };
149
+ const mountRule = {
150
+ loaders: [mountLoader],
151
+ condition: {
152
+ all: [
153
+ { not: "foreign" },
154
+ { path: /layout\.(tsx|jsx)$/ }
155
+ ]
156
+ }
157
+ };
158
+ const existingRules = nextConfig.turbopack?.rules ?? {};
159
+ const tsxRule = existingRules["*.tsx"] ?? [];
160
+ const jsxRule = existingRules["*.jsx"] ?? [];
161
+ result.turbopack = {
162
+ ...nextConfig.turbopack,
163
+ rules: {
164
+ ...existingRules,
165
+ "*.tsx": [
166
+ ...Array.isArray(tsxRule) ? tsxRule : [tsxRule],
167
+ sourceRule,
168
+ mountRule
169
+ ],
170
+ "*.jsx": [
171
+ ...Array.isArray(jsxRule) ? jsxRule : [jsxRule],
172
+ sourceRule,
173
+ mountRule
174
+ ]
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
+ condition: {
114
+ not: "foreign"
115
+ }
116
+ };
117
+ const mountRule = {
118
+ loaders: [mountLoader],
119
+ condition: {
120
+ all: [
121
+ { not: "foreign" },
122
+ { path: /layout\.(tsx|jsx)$/ }
123
+ ]
124
+ }
125
+ };
126
+ const existingRules = nextConfig.turbopack?.rules ?? {};
127
+ const tsxRule = existingRules["*.tsx"] ?? [];
128
+ const jsxRule = existingRules["*.jsx"] ?? [];
129
+ result.turbopack = {
130
+ ...nextConfig.turbopack,
131
+ rules: {
132
+ ...existingRules,
133
+ "*.tsx": [
134
+ ...Array.isArray(tsxRule) ? tsxRule : [tsxRule],
135
+ sourceRule,
136
+ mountRule
137
+ ],
138
+ "*.jsx": [
139
+ ...Array.isArray(jsxRule) ? jsxRule : [jsxRule],
140
+ sourceRule,
141
+ mountRule
142
+ ]
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.9",
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,69 @@ 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
+ // Unlike @next/mdx (which converts .mdx → .tsx and needs `as: '*.tsx'`),
68
+ // our loaders transform .tsx → .tsx (same extension), so we must NOT use `as`
69
+ // — that would cause Turbopack to re-append the extension (.tsx.tsx).
70
+ // Instead, use glob patterns that match the file extensions directly.
71
+ if (process.env.TURBOPACK) {
72
+ const sourceLoader = {
73
+ loader: path.resolve(__dirname, "loader.js"),
74
+ options: {
75
+ // In webpack, context.dir provides this. In turbopack config time,
76
+ // process.cwd() is equivalent since next.config runs from the project root.
77
+ cwd: projectRoot,
78
+ },
79
+ };
80
+
81
+ const mountLoader = {
82
+ loader: path.resolve(__dirname, "codesurface-mount-loader.js"),
83
+ };
84
+
85
+ // Source annotation loader for all .tsx/.jsx files (excluding node_modules)
86
+ const sourceRule = {
87
+ loaders: [sourceLoader],
88
+ condition: {
89
+ not: "foreign",
90
+ },
91
+ };
92
+
93
+ // Mount loader for layout files (the loader itself checks for <html to skip nested layouts)
94
+ const mountRule = {
95
+ loaders: [mountLoader],
96
+ condition: {
97
+ all: [
98
+ { not: "foreign" },
99
+ { path: /layout\.(tsx|jsx)$/ },
100
+ ],
101
+ },
102
+ };
103
+
104
+ // Use glob patterns that match tsx/jsx files.
105
+ // The source loader uses separate globs for .tsx and .jsx.
106
+ const existingRules = (nextConfig as any).turbopack?.rules ?? {};
107
+
108
+ const tsxRule = existingRules["*.tsx"] ?? [];
109
+ const jsxRule = existingRules["*.jsx"] ?? [];
110
+
111
+ result.turbopack = {
112
+ ...(nextConfig as any).turbopack,
113
+ rules: {
114
+ ...existingRules,
115
+ "*.tsx": [
116
+ ...(Array.isArray(tsxRule) ? tsxRule : [tsxRule]),
117
+ sourceRule,
118
+ mountRule,
119
+ ],
120
+ "*.jsx": [
121
+ ...(Array.isArray(jsxRule) ? jsxRule : [jsxRule]),
122
+ sourceRule,
123
+ mountRule,
124
+ ],
125
+ },
126
+ };
127
+ }
128
+
129
+ return result as T;
63
130
  }
@@ -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)) {