macaly-tagger 1.0.0 → 1.1.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 CHANGED
@@ -26,6 +26,47 @@ The loader has the following dependencies that will be installed automatically:
26
26
 
27
27
  ### Next.js Setup
28
28
 
29
+ #### For Next.js 15.3.0+ with Turbopack
30
+
31
+ Configure your `next.config.js`:
32
+
33
+ ```js
34
+ /** @type {import('next').NextConfig} */
35
+ const nextConfig = {
36
+ turbopack: {
37
+ rules: {
38
+ "*.{jsx,tsx}": {
39
+ condition: {
40
+ all: [
41
+ { not: "foreign" }, // Exclude node_modules
42
+ "development", // Only in development mode
43
+ ],
44
+ },
45
+ loaders: [
46
+ {
47
+ loader: "macaly-tagger",
48
+ options: {
49
+ disableSourceMaps: true, // Required to avoid Turbopack crashes
50
+ },
51
+ },
52
+ ],
53
+ as: "*", // Preserve original file handling
54
+ },
55
+ },
56
+ },
57
+ };
58
+
59
+ module.exports = nextConfig;
60
+ ```
61
+
62
+ > **Important Notes for Turbopack:**
63
+ > - **`disableSourceMaps: true` is required** to prevent Turbopack crashes when processing source maps
64
+ > - **`as: "*"`** preserves the original file type handling (don't use `"*.js"`)
65
+ > - **Don't include `'browser'` condition** as it may exclude server components in Next.js
66
+ > - The simple `"*.{jsx,tsx}"` glob pattern works correctly with these settings
67
+
68
+ #### For Next.js with Webpack (legacy)
69
+
29
70
  Configure your `next.config.js`:
30
71
 
31
72
  ```js
@@ -144,6 +185,25 @@ The loader works out of the box with no configuration needed. It automatically:
144
185
  - Runs only in development mode (when configured properly)
145
186
  - Handles both regular JSX elements (`<div>`) and member expressions (`<MyLib.Button>`)
146
187
 
188
+ ### Options
189
+
190
+ You can pass options to the loader:
191
+
192
+ ```js
193
+ {
194
+ loader: 'macaly-tagger',
195
+ options: {
196
+ debug: true, // Enable debug logging
197
+ disableSourceMaps: true, // Disable source map generation (useful for Turbopack)
198
+ },
199
+ }
200
+ ```
201
+
202
+ | Option | Type | Default | Description |
203
+ |--------|------|---------|-------------|
204
+ | `debug` | `boolean` | `false` | Enable detailed console logging for debugging |
205
+ | `disableSourceMaps` | `boolean` | `false` | Disable source map generation (recommended for Turbopack to avoid crashes) |
206
+
147
207
  ## Attributes Added
148
208
 
149
209
  For each JSX element, the loader adds:
@@ -171,7 +231,7 @@ Once installed, you can:
171
231
  ### Build errors?
172
232
 
173
233
  1. **Install dependencies**: Ensure all peer dependencies are installed
174
- 2. **Check webpack version**: Requires webpack >= 4.0.0
234
+ 2. **Check webpack version**: Requires webpack >= 4.0.0 (for webpack setup)
175
235
  3. **Verify loader path**: Make sure the loader is correctly referenced
176
236
 
177
237
  ### Performance issues?
@@ -211,6 +271,12 @@ MIT License - see LICENSE file for details.
211
271
 
212
272
  ## Changelog
213
273
 
274
+ ### 1.1.0
275
+
276
+ - Added `disableSourceMaps` option to prevent Turbopack crashes
277
+ - Added comprehensive Turbopack configuration documentation
278
+ - Tested and verified Turbopack compatibility with Next.js 15.3.0+
279
+
214
280
  ### 1.0.0
215
281
 
216
282
  - Initial release
@@ -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;AAuFjB,QAAA,MAAM,kBAAkB,EAAE,kBAmIzB,CAAC;AAEF,eAAe,kBAAkB,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;AAgGjB,QAAA,MAAM,kBAAkB,EAAE,kBAqIzB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -57,7 +57,7 @@ function isElementAlreadyTagged(attributes) {
57
57
  attr.name?.type === 'JSXIdentifier' &&
58
58
  attr.name.name === 'data-macaly-loc') ?? false);
59
59
  }
60
- function getJSXElementInfo(node) {
60
+ function getJSXElementInfo(node, debug = false) {
61
61
  let tagName;
62
62
  let insertPosition;
63
63
  if (node.name?.type === 'JSXIdentifier') {
@@ -72,16 +72,25 @@ function getJSXElementInfo(node) {
72
72
  insertPosition = node.name.end ?? 0;
73
73
  }
74
74
  else {
75
- console.log('[macaly-tagger] Unsupported JSX element type:', node.name?.type);
75
+ if (debug) {
76
+ console.log('[macaly-tagger] Unsupported JSX element type:', node.name?.type);
77
+ }
76
78
  return null;
77
79
  }
78
80
  if (!tagName || insertPosition === 0) {
79
- console.log('[macaly-tagger] Missing tagName or insertPosition:', { tagName, insertPosition });
81
+ if (debug) {
82
+ console.log('[macaly-tagger] Missing tagName or insertPosition:', {
83
+ tagName,
84
+ insertPosition,
85
+ });
86
+ }
80
87
  return null;
81
88
  }
82
89
  const loc = node.loc?.start;
83
90
  if (!loc) {
84
- console.log('[macaly-tagger] No location info for element:', tagName);
91
+ if (debug) {
92
+ console.log('[macaly-tagger] No location info for element:', tagName);
93
+ }
85
94
  return null;
86
95
  }
87
96
  return {
@@ -91,9 +100,11 @@ function getJSXElementInfo(node) {
91
100
  };
92
101
  }
93
102
  const macalyTaggerLoader = function (code) {
94
- console.log('[macaly-tagger] Loader called with:', this.resourcePath);
95
103
  const callback = this.async();
96
104
  const options = this.getOptions() || {};
105
+ if (options.debug) {
106
+ console.log('[macaly-tagger] Loader called with:', this.resourcePath);
107
+ }
97
108
  if (!callback) {
98
109
  throw new Error('[macaly-tagger] Async callback not available');
99
110
  }
@@ -135,7 +146,7 @@ const macalyTaggerLoader = function (code) {
135
146
  }
136
147
  return;
137
148
  }
138
- const elementInfo = getJSXElementInfo(jsxNode);
149
+ const elementInfo = getJSXElementInfo(jsxNode, !!options.debug);
139
150
  if (!elementInfo)
140
151
  return;
141
152
  const { tagName, insertPosition, location } = elementInfo;
@@ -166,7 +177,7 @@ const macalyTaggerLoader = function (code) {
166
177
  }
167
178
  return {
168
179
  code: transformedCode,
169
- map: ms.generateMap({ hires: true }),
180
+ map: options.disableSourceMaps ? null : ms.generateMap({ hires: true }),
170
181
  };
171
182
  }
172
183
  catch (error) {
@@ -177,7 +188,7 @@ const macalyTaggerLoader = function (code) {
177
188
  transform()
178
189
  .then((result) => {
179
190
  if (result) {
180
- callback(null, result.code, result.map);
191
+ callback(null, result.code, result.map || undefined);
181
192
  }
182
193
  else {
183
194
  callback(null, code);
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LoaderDefinitionFunction } from 'webpack';
2
2
  export interface MacalyTaggerLoaderOptions {
3
3
  debug?: boolean;
4
+ disableSourceMaps?: boolean;
4
5
  }
5
6
  export interface SourceLocation {
6
7
  line: number;
@@ -13,7 +14,7 @@ export interface JSXElementInfo {
13
14
  }
14
15
  export interface TransformResult {
15
16
  code: string;
16
- map: any;
17
+ map: any | null;
17
18
  }
18
19
  export type MacalyTaggerLoader = LoaderDefinitionFunction<MacalyTaggerLoaderOptions>;
19
20
  //# sourceMappingURL=types.d.ts.map
@@ -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;CACjB;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,CAAC;CACV;AAED,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,yBAAyB,CAAC,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;CAC7B;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.0",
3
+ "version": "1.1.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",
@@ -13,22 +13,6 @@
13
13
  },
14
14
  "./package.json": "./package.json"
15
15
  },
16
- "scripts": {
17
- "build": "tsc -p tsconfig.build.json",
18
- "build:watch": "tsc -p tsconfig.build.json --watch",
19
- "clean": "rimraf dist",
20
- "dev": "tsc -p tsconfig.build.json --watch",
21
- "lint": "eslint src --ext .ts,.tsx",
22
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
23
- "format": "prettier --write \"src/**/*.{ts,tsx}\"",
24
- "format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
25
- "test": "vitest run",
26
- "test:watch": "vitest",
27
- "test:coverage": "vitest run --coverage",
28
- "type-check": "tsc --noEmit",
29
- "prepublishOnly": "npm run clean && npm run build && npm run test && npm run lint",
30
- "prepack": "npm run build"
31
- },
32
16
  "keywords": [
33
17
  "webpack",
34
18
  "loader",
@@ -84,5 +68,19 @@
84
68
  "bugs": {
85
69
  "url": "https://github.com/langtail/macaly-tagger/issues"
86
70
  },
87
- "homepage": "https://github.com/langtail/macaly-tagger#readme"
88
- }
71
+ "homepage": "https://github.com/langtail/macaly-tagger#readme",
72
+ "scripts": {
73
+ "build": "tsc -p tsconfig.build.json",
74
+ "build:watch": "tsc -p tsconfig.build.json --watch",
75
+ "clean": "rimraf dist",
76
+ "dev": "tsc -p tsconfig.build.json --watch",
77
+ "lint": "eslint src --ext .ts,.tsx",
78
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
79
+ "format": "prettier --write \"src/**/*.{ts,tsx}\"",
80
+ "format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
81
+ "test": "vitest run",
82
+ "test:watch": "vitest",
83
+ "test:coverage": "vitest run --coverage",
84
+ "type-check": "tsc --noEmit"
85
+ }
86
+ }