nextjs-ide-helper 1.1.3 → 1.3.1
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/README.md +175 -10
- package/lib/__tests__/loader.test.js +480 -0
- package/lib/index.ts +8 -0
- package/lib/loader.js +222 -33
- package/lib/plugin.js +26 -2
- package/lib/withIdeButton.tsx +97 -0
- package/package.json +9 -2
- package/src/__tests__/loader.test.js +480 -0
- package/src/loader.js +222 -33
- package/src/plugin.js +25 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ A Next.js plugin that automatically adds IDE buttons to React components in deve
|
|
|
12
12
|
- ⚡ **Hydration Safe**: No SSR/client hydration mismatches
|
|
13
13
|
- 📱 **TypeScript Support**: Full TypeScript definitions included
|
|
14
14
|
- 🔌 **Multi-IDE Support**: Supports Cursor, VS Code, WebStorm, and Atom
|
|
15
|
+
- 🎭 **Multiple Component Patterns**: Supports all React component export patterns
|
|
16
|
+
- 🔍 **AST-Based Processing**: Uses robust Abstract Syntax Tree parsing for accurate code transformation
|
|
15
17
|
|
|
16
18
|
## Installation
|
|
17
19
|
|
|
@@ -53,7 +55,7 @@ const nextConfig = {
|
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
module.exports = withIdeHelper({
|
|
56
|
-
componentPaths: ['src/components', 'components', 'src/ui'], // directories to scan
|
|
58
|
+
componentPaths: ['src/components', 'components', 'src/ui'], // directories to scan (supports glob patterns)
|
|
57
59
|
projectRoot: process.cwd(), // project root directory
|
|
58
60
|
importPath: 'nextjs-ide-plugin/withIdeButton', // import path for the HOC
|
|
59
61
|
enabled: process.env.NODE_ENV === 'development', // enable/disable
|
|
@@ -65,12 +67,34 @@ module.exports = withIdeHelper({
|
|
|
65
67
|
|
|
66
68
|
| Option | Type | Default | Description |
|
|
67
69
|
|--------|------|---------|-------------|
|
|
68
|
-
| `componentPaths` | `string[]` | `['src/components']` | Directories to scan for React components |
|
|
70
|
+
| `componentPaths` | `string[]` | `['src/components']` | Directories to scan for React components (supports glob patterns) |
|
|
69
71
|
| `projectRoot` | `string` | `process.cwd()` | Root directory of your project |
|
|
70
72
|
| `importPath` | `string` | `'nextjs-ide-plugin/withIdeButton'` | Import path for the withIdeButton HOC |
|
|
71
73
|
| `enabled` | `boolean` | `process.env.NODE_ENV === 'development'` | Enable/disable the plugin |
|
|
72
74
|
| `ideType` | `'cursor' \| 'vscode' \| 'webstorm' \| 'atom'` | `'cursor'` | IDE to open files in |
|
|
73
75
|
|
|
76
|
+
### Glob Pattern Support
|
|
77
|
+
|
|
78
|
+
The `componentPaths` option supports glob patterns for matching nested directory structures:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
module.exports = withIdeHelper({
|
|
82
|
+
componentPaths: [
|
|
83
|
+
'src/components/**', // matches all nested directories under src/components
|
|
84
|
+
'**/components/**', // matches components directories anywhere in the project
|
|
85
|
+
'app/**/ui/**', // matches ui directories nested anywhere under app
|
|
86
|
+
'modules/*/components/**' // matches components in any module subdirectory
|
|
87
|
+
]
|
|
88
|
+
})(nextConfig);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Glob Pattern Examples:**
|
|
92
|
+
- `*` - matches any characters within a single directory level
|
|
93
|
+
- `**` - matches any number of directories and subdirectories recursively
|
|
94
|
+
- `src/components/*` - matches `src/components/Button.tsx` but not `src/components/ui/Button.tsx`
|
|
95
|
+
- `src/components/**` - matches both `src/components/Button.tsx` and `src/components/ui/forms/Button.tsx`
|
|
96
|
+
- `**/components/**` - matches `app/components/Button.tsx`, `modules/feature/components/deep/Widget.tsx`, etc.
|
|
97
|
+
|
|
74
98
|
## Manual Usage
|
|
75
99
|
|
|
76
100
|
You can also manually wrap components:
|
|
@@ -91,16 +115,95 @@ export default withIdeButton(MyComponent, 'src/components/MyComponent.tsx', {
|
|
|
91
115
|
});
|
|
92
116
|
```
|
|
93
117
|
|
|
118
|
+
## Supported Component Patterns
|
|
119
|
+
|
|
120
|
+
The plugin automatically detects and wraps all types of React component export patterns:
|
|
121
|
+
|
|
122
|
+
### Named Components
|
|
123
|
+
```tsx
|
|
124
|
+
// Standard pattern
|
|
125
|
+
const MyComponent = () => <div>Hello</div>;
|
|
126
|
+
export default MyComponent;
|
|
127
|
+
|
|
128
|
+
// Variable declaration
|
|
129
|
+
const MyComponent = function() {
|
|
130
|
+
return <div>Hello</div>;
|
|
131
|
+
};
|
|
132
|
+
export default MyComponent;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Direct Export Function Components
|
|
136
|
+
```tsx
|
|
137
|
+
// Named function
|
|
138
|
+
export default function MyComponent() {
|
|
139
|
+
return <div>Hello</div>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Anonymous function
|
|
143
|
+
export default function() {
|
|
144
|
+
return <div>Hello</div>;
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Arrow Function Components
|
|
149
|
+
```tsx
|
|
150
|
+
// Anonymous arrow function
|
|
151
|
+
export default () => {
|
|
152
|
+
return <div>Hello</div>;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Arrow function with parameters
|
|
156
|
+
export default (props) => {
|
|
157
|
+
return <div>Hello {props.name}</div>;
|
|
158
|
+
};
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Class Components
|
|
162
|
+
```tsx
|
|
163
|
+
// Named class
|
|
164
|
+
export default class MyComponent extends React.Component {
|
|
165
|
+
render() {
|
|
166
|
+
return <div>Hello</div>;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// TypeScript class
|
|
171
|
+
export default class MyComponent extends Component<Props> {
|
|
172
|
+
render() {
|
|
173
|
+
return <div>Hello</div>;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### TypeScript Components
|
|
179
|
+
```tsx
|
|
180
|
+
// Function with TypeScript
|
|
181
|
+
interface Props {
|
|
182
|
+
title: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export default function MyComponent(props: Props) {
|
|
186
|
+
return <div>{props.title}</div>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Arrow function with TypeScript
|
|
190
|
+
export default (props: Props) => {
|
|
191
|
+
return <div>{props.title}</div>;
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
94
195
|
## How It Works
|
|
95
196
|
|
|
96
|
-
1. **
|
|
97
|
-
2. **
|
|
98
|
-
3. **
|
|
99
|
-
4. **
|
|
100
|
-
5. **
|
|
197
|
+
1. **AST-Based Processing**: Uses Babel's Abstract Syntax Tree parser for robust code analysis
|
|
198
|
+
2. **Webpack Loader**: The plugin uses a custom webpack loader to transform your React components at build time
|
|
199
|
+
3. **Automatic Detection**: It scans specified directories for `.tsx` and `.jsx` files
|
|
200
|
+
4. **Smart Wrapping**: Only wraps components that export a default React component (PascalCase names)
|
|
201
|
+
5. **Development Only**: The IDE buttons only appear in development mode
|
|
202
|
+
6. **Hydration Safe**: Uses client-side state to prevent SSR/hydration mismatches
|
|
101
203
|
|
|
102
|
-
##
|
|
204
|
+
## Examples
|
|
103
205
|
|
|
206
|
+
### Standard Component Pattern
|
|
104
207
|
Before (your original component):
|
|
105
208
|
```tsx
|
|
106
209
|
// src/components/Button.tsx
|
|
@@ -133,7 +236,53 @@ const Button = ({ children, onClick }) => {
|
|
|
133
236
|
|
|
134
237
|
export default withIdeButton(Button, 'src/components/Button.tsx', {
|
|
135
238
|
projectRoot: '/path/to/project',
|
|
136
|
-
ideType: 'cursor'
|
|
239
|
+
ideType: 'cursor'
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Direct Export Function Component
|
|
244
|
+
Before:
|
|
245
|
+
```tsx
|
|
246
|
+
// src/components/Header.tsx
|
|
247
|
+
export default function Header() {
|
|
248
|
+
return <header>My App Header</header>;
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
After (automatically transformed):
|
|
253
|
+
```tsx
|
|
254
|
+
// src/components/Header.tsx (transformed by the plugin)
|
|
255
|
+
import { withIdeButton } from 'nextjs-ide-plugin/withIdeButton';
|
|
256
|
+
|
|
257
|
+
function Header() {
|
|
258
|
+
return <header>My App Header</header>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export default withIdeButton(Header, 'src/components/Header.tsx', {
|
|
262
|
+
projectRoot: '/path/to/project',
|
|
263
|
+
ideType: 'cursor'
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Anonymous Component
|
|
268
|
+
Before:
|
|
269
|
+
```tsx
|
|
270
|
+
// src/components/Footer.tsx
|
|
271
|
+
export default () => {
|
|
272
|
+
return <footer>© 2025 My App</footer>;
|
|
273
|
+
};
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
After (automatically transformed):
|
|
277
|
+
```tsx
|
|
278
|
+
// src/components/Footer.tsx (transformed by the plugin)
|
|
279
|
+
import { withIdeButton } from 'nextjs-ide-plugin/withIdeButton';
|
|
280
|
+
|
|
281
|
+
export default withIdeButton(() => {
|
|
282
|
+
return <footer>© 2025 My App</footer>;
|
|
283
|
+
}, 'src/components/Footer.tsx', {
|
|
284
|
+
projectRoot: '/path/to/project',
|
|
285
|
+
ideType: 'cursor'
|
|
137
286
|
});
|
|
138
287
|
```
|
|
139
288
|
|
|
@@ -174,8 +323,24 @@ MIT
|
|
|
174
323
|
|
|
175
324
|
## Changelog
|
|
176
325
|
|
|
326
|
+
See [CHANGELOG.md](./CHANGELOG.md) for detailed release notes.
|
|
327
|
+
|
|
328
|
+
### Recent Releases
|
|
329
|
+
|
|
330
|
+
### 1.3.0 - Glob Pattern Support
|
|
331
|
+
- Added support for glob patterns in `componentPaths` configuration
|
|
332
|
+
- Support for nested directory matching with `**` patterns
|
|
333
|
+
- Enhanced file path matching for complex project structures
|
|
334
|
+
- Updated tests and documentation
|
|
335
|
+
|
|
336
|
+
### 1.2.0 - Enhanced Component Support
|
|
337
|
+
- Added support for all React component export patterns
|
|
338
|
+
- AST-based code transformation for better reliability
|
|
339
|
+
- Anonymous component support
|
|
340
|
+
- Enhanced TypeScript compatibility
|
|
341
|
+
|
|
177
342
|
### 1.1.3
|
|
178
|
-
|
|
343
|
+
- Updated readme
|
|
179
344
|
|
|
180
345
|
### 1.1.2
|
|
181
346
|
- Added support for multiple IDEs (Cursor, VS Code, WebStorm, Atom)
|