macaly-tagger 1.0.1 → 1.2.0
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 +130 -2
- package/dist/dom-elements.d.ts +4 -0
- package/dist/dom-elements.d.ts.map +1 -0
- package/dist/dom-elements.js +191 -0
- package/dist/import-collector.d.ts +8 -0
- package/dist/import-collector.d.ts.map +1 -0
- package/dist/import-collector.js +56 -0
- package/dist/macaly-tagger-loader.d.ts.map +1 -1
- package/dist/macaly-tagger-loader.js +25 -2
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ A webpack loader that adds location metadata to JSX elements for development deb
|
|
|
8
8
|
- 🚀 **Zero runtime overhead**: Only runs in development mode
|
|
9
9
|
- 🔧 **Easy integration**: Simple webpack configuration
|
|
10
10
|
- 📦 **TypeScript support**: Works with both `.jsx` and `.tsx` files
|
|
11
|
-
- 🚫 **Smart filtering**: Automatically excludes `node_modules
|
|
11
|
+
- 🚫 **Smart filtering**: Automatically excludes `node_modules`, React Fragments, and non-DOM elements
|
|
12
|
+
- 🎮 **Custom renderer support**: Compatible with React Three Fiber and other custom renderers via `ignorePackages` option
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
@@ -26,6 +27,47 @@ The loader has the following dependencies that will be installed automatically:
|
|
|
26
27
|
|
|
27
28
|
### Next.js Setup
|
|
28
29
|
|
|
30
|
+
#### For Next.js 15.3.0+ with Turbopack
|
|
31
|
+
|
|
32
|
+
Configure your `next.config.js`:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
/** @type {import('next').NextConfig} */
|
|
36
|
+
const nextConfig = {
|
|
37
|
+
turbopack: {
|
|
38
|
+
rules: {
|
|
39
|
+
"*.{jsx,tsx}": {
|
|
40
|
+
condition: {
|
|
41
|
+
all: [
|
|
42
|
+
{ not: "foreign" }, // Exclude node_modules
|
|
43
|
+
"development", // Only in development mode
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
loaders: [
|
|
47
|
+
{
|
|
48
|
+
loader: "macaly-tagger",
|
|
49
|
+
options: {
|
|
50
|
+
disableSourceMaps: true, // Required to avoid Turbopack crashes
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
as: "*", // Preserve original file handling
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports = nextConfig;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **Important Notes for Turbopack:**
|
|
64
|
+
> - **`disableSourceMaps: true` is required** to prevent Turbopack crashes when processing source maps
|
|
65
|
+
> - **`as: "*"`** preserves the original file type handling (don't use `"*.js"`)
|
|
66
|
+
> - **Don't include `'browser'` condition** as it may exclude server components in Next.js
|
|
67
|
+
> - The simple `"*.{jsx,tsx}"` glob pattern works correctly with these settings
|
|
68
|
+
|
|
69
|
+
#### For Next.js with Webpack (legacy)
|
|
70
|
+
|
|
29
71
|
Configure your `next.config.js`:
|
|
30
72
|
|
|
31
73
|
```js
|
|
@@ -144,6 +186,79 @@ The loader works out of the box with no configuration needed. It automatically:
|
|
|
144
186
|
- Runs only in development mode (when configured properly)
|
|
145
187
|
- Handles both regular JSX elements (`<div>`) and member expressions (`<MyLib.Button>`)
|
|
146
188
|
|
|
189
|
+
### Options
|
|
190
|
+
|
|
191
|
+
You can pass options to the loader:
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
{
|
|
195
|
+
loader: 'macaly-tagger',
|
|
196
|
+
options: {
|
|
197
|
+
debug: true, // Enable debug logging
|
|
198
|
+
disableSourceMaps: true, // Disable source map generation (useful for Turbopack)
|
|
199
|
+
ignorePackages: [ // Skip components imported from these packages
|
|
200
|
+
'@react-three/fiber',
|
|
201
|
+
'@react-three/drei',
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
| Option | Type | Default | Description |
|
|
208
|
+
|--------|------|---------|-------------|
|
|
209
|
+
| `debug` | `boolean` | `false` | Enable detailed console logging for debugging |
|
|
210
|
+
| `disableSourceMaps` | `boolean` | `false` | Disable source map generation (recommended for Turbopack to avoid crashes) |
|
|
211
|
+
| `ignorePackages` | `string[]` | `[]` | List of package names whose imports should not be tagged |
|
|
212
|
+
|
|
213
|
+
### Custom Renderers (React Three Fiber, etc.)
|
|
214
|
+
|
|
215
|
+
If you're using custom React renderers like [React Three Fiber](https://github.com/pmndrs/react-three-fiber), you may encounter errors because these renderers use components that don't support DOM attributes.
|
|
216
|
+
|
|
217
|
+
Use the `ignorePackages` option to skip tagging components imported from these packages:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
{
|
|
221
|
+
loader: 'macaly-tagger',
|
|
222
|
+
options: {
|
|
223
|
+
ignorePackages: [
|
|
224
|
+
'@react-three/fiber',
|
|
225
|
+
'@react-three/drei',
|
|
226
|
+
'@react-three/postprocessing',
|
|
227
|
+
'three',
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
This will automatically skip tagging any component imported from these packages:
|
|
234
|
+
|
|
235
|
+
```jsx
|
|
236
|
+
import { Canvas } from '@react-three/fiber'; // Canvas will NOT be tagged
|
|
237
|
+
import { OrbitControls, Html } from '@react-three/drei'; // OrbitControls, Html will NOT be tagged
|
|
238
|
+
import * as Fiber from '@react-three/fiber'; // Fiber.* will NOT be tagged
|
|
239
|
+
|
|
240
|
+
function Scene() {
|
|
241
|
+
return (
|
|
242
|
+
<div> {/* ✓ Tagged (HTML element) */}
|
|
243
|
+
<Canvas> {/* ✗ Skipped (imported from @react-three/fiber) */}
|
|
244
|
+
<OrbitControls /> {/* ✗ Skipped (imported from @react-three/drei) */}
|
|
245
|
+
<Html> {/* ✗ Skipped (imported from @react-three/drei) */}
|
|
246
|
+
<span>Label</span> {/* ✓ Tagged (HTML element) */}
|
|
247
|
+
</Html>
|
|
248
|
+
<mesh> {/* ✗ Skipped (lowercase non-HTML element) */}
|
|
249
|
+
<boxGeometry /> {/* ✗ Skipped (lowercase non-HTML element) */}
|
|
250
|
+
</mesh>
|
|
251
|
+
</Canvas>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The loader handles all import styles:
|
|
258
|
+
- **Named imports**: `import { Canvas } from '...'`
|
|
259
|
+
- **Default imports**: `import Drei from '...'` (skips `Drei.Something`)
|
|
260
|
+
- **Namespace imports**: `import * as Fiber from '...'` (skips `Fiber.Something`)
|
|
261
|
+
|
|
147
262
|
## Attributes Added
|
|
148
263
|
|
|
149
264
|
For each JSX element, the loader adds:
|
|
@@ -171,7 +286,7 @@ Once installed, you can:
|
|
|
171
286
|
### Build errors?
|
|
172
287
|
|
|
173
288
|
1. **Install dependencies**: Ensure all peer dependencies are installed
|
|
174
|
-
2. **Check webpack version**: Requires webpack >= 4.0.0
|
|
289
|
+
2. **Check webpack version**: Requires webpack >= 4.0.0 (for webpack setup)
|
|
175
290
|
3. **Verify loader path**: Make sure the loader is correctly referenced
|
|
176
291
|
|
|
177
292
|
### Performance issues?
|
|
@@ -211,6 +326,19 @@ MIT License - see LICENSE file for details.
|
|
|
211
326
|
|
|
212
327
|
## Changelog
|
|
213
328
|
|
|
329
|
+
### 1.2.0
|
|
330
|
+
|
|
331
|
+
- Added `ignorePackages` option to skip tagging components imported from specified packages
|
|
332
|
+
- Added automatic filtering for React Fragments (`<Fragment>`, `<React.Fragment>`)
|
|
333
|
+
- Added smart element filtering: only tags HTML/SVG elements and React components, skips unknown lowercase elements (custom renderer elements like R3F's `<mesh>`, `<boxGeometry>`, etc.)
|
|
334
|
+
- Improved compatibility with React Three Fiber and other custom renderers
|
|
335
|
+
|
|
336
|
+
### 1.1.0
|
|
337
|
+
|
|
338
|
+
- Added `disableSourceMaps` option to prevent Turbopack crashes
|
|
339
|
+
- Added comprehensive Turbopack configuration documentation
|
|
340
|
+
- Tested and verified Turbopack compatibility with Next.js 15.3.0+
|
|
341
|
+
|
|
214
342
|
### 1.0.0
|
|
215
343
|
|
|
216
344
|
- Initial release
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-elements.d.ts","sourceRoot":"","sources":["../src/dom-elements.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,aAiHxB,CAAC;AAKH,eAAO,MAAM,YAAY,aA8DvB,CAAC;AAiBH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAgBzD"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SVG_ELEMENTS = exports.HTML_ELEMENTS = void 0;
|
|
4
|
+
exports.shouldTagElement = shouldTagElement;
|
|
5
|
+
exports.HTML_ELEMENTS = new Set([
|
|
6
|
+
'a',
|
|
7
|
+
'abbr',
|
|
8
|
+
'address',
|
|
9
|
+
'area',
|
|
10
|
+
'article',
|
|
11
|
+
'aside',
|
|
12
|
+
'audio',
|
|
13
|
+
'b',
|
|
14
|
+
'base',
|
|
15
|
+
'bdi',
|
|
16
|
+
'bdo',
|
|
17
|
+
'blockquote',
|
|
18
|
+
'body',
|
|
19
|
+
'br',
|
|
20
|
+
'button',
|
|
21
|
+
'canvas',
|
|
22
|
+
'caption',
|
|
23
|
+
'cite',
|
|
24
|
+
'code',
|
|
25
|
+
'col',
|
|
26
|
+
'colgroup',
|
|
27
|
+
'data',
|
|
28
|
+
'datalist',
|
|
29
|
+
'dd',
|
|
30
|
+
'del',
|
|
31
|
+
'details',
|
|
32
|
+
'dfn',
|
|
33
|
+
'dialog',
|
|
34
|
+
'div',
|
|
35
|
+
'dl',
|
|
36
|
+
'dt',
|
|
37
|
+
'em',
|
|
38
|
+
'embed',
|
|
39
|
+
'fieldset',
|
|
40
|
+
'figcaption',
|
|
41
|
+
'figure',
|
|
42
|
+
'footer',
|
|
43
|
+
'form',
|
|
44
|
+
'h1',
|
|
45
|
+
'h2',
|
|
46
|
+
'h3',
|
|
47
|
+
'h4',
|
|
48
|
+
'h5',
|
|
49
|
+
'h6',
|
|
50
|
+
'head',
|
|
51
|
+
'header',
|
|
52
|
+
'hgroup',
|
|
53
|
+
'hr',
|
|
54
|
+
'html',
|
|
55
|
+
'i',
|
|
56
|
+
'iframe',
|
|
57
|
+
'img',
|
|
58
|
+
'input',
|
|
59
|
+
'ins',
|
|
60
|
+
'kbd',
|
|
61
|
+
'label',
|
|
62
|
+
'legend',
|
|
63
|
+
'li',
|
|
64
|
+
'link',
|
|
65
|
+
'main',
|
|
66
|
+
'map',
|
|
67
|
+
'mark',
|
|
68
|
+
'menu',
|
|
69
|
+
'meta',
|
|
70
|
+
'meter',
|
|
71
|
+
'nav',
|
|
72
|
+
'noscript',
|
|
73
|
+
'object',
|
|
74
|
+
'ol',
|
|
75
|
+
'optgroup',
|
|
76
|
+
'option',
|
|
77
|
+
'output',
|
|
78
|
+
'p',
|
|
79
|
+
'picture',
|
|
80
|
+
'pre',
|
|
81
|
+
'progress',
|
|
82
|
+
'q',
|
|
83
|
+
'rp',
|
|
84
|
+
'rt',
|
|
85
|
+
'ruby',
|
|
86
|
+
's',
|
|
87
|
+
'samp',
|
|
88
|
+
'script',
|
|
89
|
+
'search',
|
|
90
|
+
'section',
|
|
91
|
+
'select',
|
|
92
|
+
'slot',
|
|
93
|
+
'small',
|
|
94
|
+
'source',
|
|
95
|
+
'span',
|
|
96
|
+
'strong',
|
|
97
|
+
'style',
|
|
98
|
+
'sub',
|
|
99
|
+
'summary',
|
|
100
|
+
'sup',
|
|
101
|
+
'table',
|
|
102
|
+
'tbody',
|
|
103
|
+
'td',
|
|
104
|
+
'template',
|
|
105
|
+
'textarea',
|
|
106
|
+
'tfoot',
|
|
107
|
+
'th',
|
|
108
|
+
'thead',
|
|
109
|
+
'time',
|
|
110
|
+
'title',
|
|
111
|
+
'tr',
|
|
112
|
+
'track',
|
|
113
|
+
'u',
|
|
114
|
+
'ul',
|
|
115
|
+
'var',
|
|
116
|
+
'video',
|
|
117
|
+
'wbr',
|
|
118
|
+
]);
|
|
119
|
+
exports.SVG_ELEMENTS = new Set([
|
|
120
|
+
'svg',
|
|
121
|
+
'a',
|
|
122
|
+
'animate',
|
|
123
|
+
'animateMotion',
|
|
124
|
+
'animateTransform',
|
|
125
|
+
'circle',
|
|
126
|
+
'clipPath',
|
|
127
|
+
'defs',
|
|
128
|
+
'desc',
|
|
129
|
+
'ellipse',
|
|
130
|
+
'feBlend',
|
|
131
|
+
'feColorMatrix',
|
|
132
|
+
'feComponentTransfer',
|
|
133
|
+
'feComposite',
|
|
134
|
+
'feConvolveMatrix',
|
|
135
|
+
'feDiffuseLighting',
|
|
136
|
+
'feDisplacementMap',
|
|
137
|
+
'feDistantLight',
|
|
138
|
+
'feDropShadow',
|
|
139
|
+
'feFlood',
|
|
140
|
+
'feFuncA',
|
|
141
|
+
'feFuncB',
|
|
142
|
+
'feFuncG',
|
|
143
|
+
'feFuncR',
|
|
144
|
+
'feGaussianBlur',
|
|
145
|
+
'feImage',
|
|
146
|
+
'feMerge',
|
|
147
|
+
'feMergeNode',
|
|
148
|
+
'feMorphology',
|
|
149
|
+
'feOffset',
|
|
150
|
+
'fePointLight',
|
|
151
|
+
'feSpecularLighting',
|
|
152
|
+
'feSpotLight',
|
|
153
|
+
'feTile',
|
|
154
|
+
'feTurbulence',
|
|
155
|
+
'filter',
|
|
156
|
+
'foreignObject',
|
|
157
|
+
'g',
|
|
158
|
+
'image',
|
|
159
|
+
'line',
|
|
160
|
+
'linearGradient',
|
|
161
|
+
'marker',
|
|
162
|
+
'mask',
|
|
163
|
+
'metadata',
|
|
164
|
+
'mpath',
|
|
165
|
+
'path',
|
|
166
|
+
'pattern',
|
|
167
|
+
'polygon',
|
|
168
|
+
'polyline',
|
|
169
|
+
'radialGradient',
|
|
170
|
+
'rect',
|
|
171
|
+
'set',
|
|
172
|
+
'stop',
|
|
173
|
+
'switch',
|
|
174
|
+
'symbol',
|
|
175
|
+
'text',
|
|
176
|
+
'textPath',
|
|
177
|
+
'title',
|
|
178
|
+
'tspan',
|
|
179
|
+
'use',
|
|
180
|
+
'view',
|
|
181
|
+
]);
|
|
182
|
+
function shouldTagElement(tagName) {
|
|
183
|
+
if (tagName === 'Fragment' || tagName.endsWith('.Fragment')) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
const firstChar = tagName[0];
|
|
187
|
+
if (firstChar && firstChar !== firstChar.toLowerCase()) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return exports.HTML_ELEMENTS.has(tagName) || exports.SVG_ELEMENTS.has(tagName);
|
|
191
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface IgnoredImports {
|
|
2
|
+
namedImports: Set<string>;
|
|
3
|
+
namespaceImports: Set<string>;
|
|
4
|
+
}
|
|
5
|
+
export declare function createEmptyIgnoredImports(): IgnoredImports;
|
|
6
|
+
export declare function collectIgnoredImports(ast: any, ignorePackages: string[]): IgnoredImports;
|
|
7
|
+
export declare function isIgnoredImport(tagName: string, ignoredImports: IgnoredImports): boolean;
|
|
8
|
+
//# sourceMappingURL=import-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-collector.d.ts","sourceRoot":"","sources":["../src/import-collector.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAK7B,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAO1B,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC/B;AAKD,wBAAgB,yBAAyB,IAAI,cAAc,CAK1D;AAcD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,cAAc,CA+CxF;AASD,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAexF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmptyIgnoredImports = createEmptyIgnoredImports;
|
|
4
|
+
exports.collectIgnoredImports = collectIgnoredImports;
|
|
5
|
+
exports.isIgnoredImport = isIgnoredImport;
|
|
6
|
+
const estree_walker_1 = require("estree-walker");
|
|
7
|
+
function createEmptyIgnoredImports() {
|
|
8
|
+
return {
|
|
9
|
+
namedImports: new Set(),
|
|
10
|
+
namespaceImports: new Set(),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function collectIgnoredImports(ast, ignorePackages) {
|
|
14
|
+
const result = createEmptyIgnoredImports();
|
|
15
|
+
if (!ignorePackages || ignorePackages.length === 0) {
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
const packagesSet = new Set(ignorePackages);
|
|
19
|
+
(0, estree_walker_1.walk)(ast, {
|
|
20
|
+
enter: (node) => {
|
|
21
|
+
if (node.type !== 'ImportDeclaration')
|
|
22
|
+
return;
|
|
23
|
+
const importNode = node;
|
|
24
|
+
const source = importNode.source.value;
|
|
25
|
+
if (typeof source !== 'string' || !packagesSet.has(source)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (const specifier of importNode.specifiers || []) {
|
|
29
|
+
switch (specifier.type) {
|
|
30
|
+
case 'ImportSpecifier':
|
|
31
|
+
result.namedImports.add(specifier.local.name);
|
|
32
|
+
break;
|
|
33
|
+
case 'ImportDefaultSpecifier':
|
|
34
|
+
result.namespaceImports.add(specifier.local.name);
|
|
35
|
+
break;
|
|
36
|
+
case 'ImportNamespaceSpecifier':
|
|
37
|
+
result.namespaceImports.add(specifier.local.name);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function isIgnoredImport(tagName, ignoredImports) {
|
|
46
|
+
if (ignoredImports.namedImports.has(tagName)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (tagName.includes('.')) {
|
|
50
|
+
const prefix = tagName.split('.')[0];
|
|
51
|
+
if (prefix && ignoredImports.namespaceImports.has(prefix)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macaly-tagger-loader.d.ts","sourceRoot":"","sources":["../src/macaly-tagger-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"macaly-tagger-loader.d.ts","sourceRoot":"","sources":["../src/macaly-tagger-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,SAAS,CAAC;AAuGjB,QAAA,MAAM,kBAAkB,EAAE,kBAiKzB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -40,6 +40,8 @@ const parser_1 = require("@babel/parser");
|
|
|
40
40
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const estree_walker_1 = require("estree-walker");
|
|
43
|
+
const dom_elements_1 = require("./dom-elements");
|
|
44
|
+
const import_collector_1 = require("./import-collector");
|
|
43
45
|
const VALID_EXTENSIONS = new Set(['.jsx', '.tsx']);
|
|
44
46
|
function getMemberExpressionName(memberExpression) {
|
|
45
47
|
if (memberExpression.type === 'JSXIdentifier') {
|
|
@@ -128,8 +130,17 @@ const macalyTaggerLoader = function (code) {
|
|
|
128
130
|
const ms = new magic_string_1.default(code);
|
|
129
131
|
const fileRelative = path.relative(this.rootContext || process.cwd(), this.resourcePath);
|
|
130
132
|
let transformCount = 0;
|
|
133
|
+
const ignoredImports = options.ignorePackages?.length
|
|
134
|
+
? (0, import_collector_1.collectIgnoredImports)(ast, options.ignorePackages)
|
|
135
|
+
: (0, import_collector_1.createEmptyIgnoredImports)();
|
|
131
136
|
if (options.debug) {
|
|
132
137
|
console.log('[macaly-tagger] File relative path:', fileRelative);
|
|
138
|
+
if (ignoredImports.namedImports.size > 0 || ignoredImports.namespaceImports.size > 0) {
|
|
139
|
+
console.log('[macaly-tagger] Ignored imports:', {
|
|
140
|
+
named: Array.from(ignoredImports.namedImports),
|
|
141
|
+
namespaces: Array.from(ignoredImports.namespaceImports),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
133
144
|
}
|
|
134
145
|
(0, estree_walker_1.walk)(ast, {
|
|
135
146
|
enter: (node) => {
|
|
@@ -150,6 +161,18 @@ const macalyTaggerLoader = function (code) {
|
|
|
150
161
|
if (!elementInfo)
|
|
151
162
|
return;
|
|
152
163
|
const { tagName, insertPosition, location } = elementInfo;
|
|
164
|
+
if ((0, import_collector_1.isIgnoredImport)(tagName, ignoredImports)) {
|
|
165
|
+
if (options.debug) {
|
|
166
|
+
console.log('[macaly-tagger] Skipping ignored import:', tagName);
|
|
167
|
+
}
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!(0, dom_elements_1.shouldTagElement)(tagName)) {
|
|
171
|
+
if (options.debug) {
|
|
172
|
+
console.log('[macaly-tagger] Skipping element:', tagName);
|
|
173
|
+
}
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
153
176
|
const macalyLoc = `${fileRelative}:${location.line}:${location.column}`;
|
|
154
177
|
if (options.debug) {
|
|
155
178
|
console.log('[macaly-tagger] Adding attributes to:', tagName, 'at', macalyLoc);
|
|
@@ -177,7 +200,7 @@ const macalyTaggerLoader = function (code) {
|
|
|
177
200
|
}
|
|
178
201
|
return {
|
|
179
202
|
code: transformedCode,
|
|
180
|
-
map: ms.generateMap({ hires: true }),
|
|
203
|
+
map: options.disableSourceMaps ? null : ms.generateMap({ hires: true }),
|
|
181
204
|
};
|
|
182
205
|
}
|
|
183
206
|
catch (error) {
|
|
@@ -188,7 +211,7 @@ const macalyTaggerLoader = function (code) {
|
|
|
188
211
|
transform()
|
|
189
212
|
.then((result) => {
|
|
190
213
|
if (result) {
|
|
191
|
-
callback(null, result.code, result.map);
|
|
214
|
+
callback(null, result.code, result.map || undefined);
|
|
192
215
|
}
|
|
193
216
|
else {
|
|
194
217
|
callback(null, code);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { LoaderDefinitionFunction } from 'webpack';
|
|
2
2
|
export interface MacalyTaggerLoaderOptions {
|
|
3
3
|
debug?: boolean;
|
|
4
|
+
disableSourceMaps?: boolean;
|
|
5
|
+
ignorePackages?: string[];
|
|
4
6
|
}
|
|
5
7
|
export interface SourceLocation {
|
|
6
8
|
line: number;
|
|
@@ -13,7 +15,7 @@ export interface JSXElementInfo {
|
|
|
13
15
|
}
|
|
14
16
|
export interface TransformResult {
|
|
15
17
|
code: string;
|
|
16
|
-
map: any;
|
|
18
|
+
map: any | null;
|
|
17
19
|
}
|
|
18
20
|
export type MacalyTaggerLoader = LoaderDefinitionFunction<MacalyTaggerLoaderOptions>;
|
|
19
21
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAS5B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,yBAAyB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "macaly-tagger",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A webpack loader that adds location metadata to JSX elements for development debugging",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@babel/parser": "^7.24.0",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
52
|
+
"estree-walker": "^2.0.2",
|
|
53
|
+
"magic-string": "^0.30.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@babel/types": "^7.24.0",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"eslint": "^8.57.0",
|
|
62
62
|
"eslint-config-prettier": "^9.1.0",
|
|
63
63
|
"eslint-plugin-prettier": "^5.1.3",
|
|
64
|
-
"vitest": "^1.4.0",
|
|
65
64
|
"prettier": "^3.2.5",
|
|
66
65
|
"rimraf": "^5.0.5",
|
|
67
|
-
"typescript": "^5.4.2"
|
|
66
|
+
"typescript": "^5.4.2",
|
|
67
|
+
"vitest": "^4.0.17"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"webpack": ">=4.0.0"
|
|
@@ -84,5 +84,6 @@
|
|
|
84
84
|
"bugs": {
|
|
85
85
|
"url": "https://github.com/langtail/macaly-tagger/issues"
|
|
86
86
|
},
|
|
87
|
-
"homepage": "https://github.com/langtail/macaly-tagger#readme"
|
|
87
|
+
"homepage": "https://github.com/langtail/macaly-tagger#readme",
|
|
88
|
+
"packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531"
|
|
88
89
|
}
|