swc-plugin-source-tracker 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/index.d.ts +11 -0
  2. package/index.js +8 -4
  3. package/package.json +3 -1
package/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export function withSourceTracker(
2
+ pluginConfig?: { attr?: string },
3
+ options?: { version?: "v35" | "v54" },
4
+ ): [string, Record<string, unknown>];
5
+
6
+ export function getWasmPath(options?: {
7
+ version?: "v35" | "v54";
8
+ }): string;
9
+
10
+ export const VERSION_MAP: Record<string, string>;
11
+ export const NEXTJS_MAP: Record<number, string>;
package/index.js CHANGED
@@ -65,13 +65,17 @@ function getWasmPath(options = {}) {
65
65
  }
66
66
 
67
67
  /**
68
- * WASM 파일을 프로젝트 루트에 복사하고 상대 경로를 반환한다.
68
+ * WASM 파일을 프로젝트 루트에 복사하고 절대 경로를 반환한다.
69
69
  * Turbopack은 node_modules 안의 WASM을 resolve하지 못하므로
70
70
  * 프로젝트 루트에 복사해야 한다.
71
71
  *
72
+ * Next.js는 swcPlugins 경로에 require.resolve()를 호출하므로
73
+ * 상대 경로("./...")는 next/dist/build/swc/ 기준으로 resolve되어 실패한다.
74
+ * 절대 경로를 반환해야 모노레포 등 모든 환경에서 동작한다.
75
+ *
72
76
  * @param {string} srcWasmPath - 원본 WASM 절대 경로
73
77
  * @param {string} projectRoot - 프로젝트 루트 (process.cwd())
74
- * @returns {string} "./파일명.wasm" 형태의 상대 경로
78
+ * @returns {string} WASM 파일의 절대 경로
75
79
  */
76
80
  function ensureLocalWasm(srcWasmPath, projectRoot) {
77
81
  const filename = "swc_plugin_source_tracker.wasm";
@@ -82,12 +86,12 @@ function ensureLocalWasm(srcWasmPath, projectRoot) {
82
86
  const srcStat = fs.statSync(srcWasmPath);
83
87
  const destStat = fs.statSync(destPath);
84
88
  if (srcStat.size === destStat.size) {
85
- return "./" + filename;
89
+ return destPath;
86
90
  }
87
91
  }
88
92
 
89
93
  fs.copyFileSync(srcWasmPath, destPath);
90
- return "./" + filename;
94
+ return destPath;
91
95
  }
92
96
 
93
97
  /**
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "swc-plugin-source-tracker",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "SWC plugin that injects data-source attributes with file:line:col into JSX DOM elements. Replaces React 19's removed __debugSource. Works with Next.js 15/16 + Turbopack.",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "exports": {
7
8
  ".": "./index.js",
8
9
  "./wasm/v35": "./wasm/v35.wasm",
@@ -10,6 +11,7 @@
10
11
  },
11
12
  "files": [
12
13
  "index.js",
14
+ "index.d.ts",
13
15
  "wasm/*.wasm"
14
16
  ],
15
17
  "keywords": [