@impakers/debug 1.4.18 → 1.4.21

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
@@ -1,92 +1 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ImpakersDebug: () => ImpakersDebug
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
-
27
- // src/core/auth.ts
28
- var STORAGE_KEY = "impakers-debug-token";
29
- var TOKEN_DATA_KEY = "impakers-debug-token-data";
30
- function loadToken() {
31
- if (typeof window === "undefined") return null;
32
- try {
33
- const data = localStorage.getItem(TOKEN_DATA_KEY);
34
- if (!data) return null;
35
- const parsed = JSON.parse(data);
36
- if (new Date(parsed.expiresAt) < /* @__PURE__ */ new Date()) {
37
- clearToken();
38
- return null;
39
- }
40
- return parsed.token;
41
- } catch {
42
- return null;
43
- }
44
- }
45
- function isAuthenticated() {
46
- return loadToken() !== null;
47
- }
48
- function clearToken() {
49
- if (typeof window === "undefined") return;
50
- try {
51
- localStorage.removeItem(TOKEN_DATA_KEY);
52
- localStorage.removeItem(STORAGE_KEY);
53
- } catch {
54
- }
55
- }
56
-
57
- // src/index.ts
58
- var _ImpakersDebug = class _ImpakersDebug {
59
- /** 인증 프롬프트 띄우기 */
60
- static showAuth() {
61
- _ImpakersDebug._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:show-auth"));
62
- }
63
- /** 인증 상태 확인 */
64
- static isActive() {
65
- return isAuthenticated();
66
- }
67
- /** 로그아웃 (토큰 삭제 + UI 숨김) */
68
- static deactivate() {
69
- clearToken();
70
- _ImpakersDebug._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:deactivate"));
71
- }
72
- /** 피드백 폼 열기 (인증된 상태에서) */
73
- static open() {
74
- if (!isAuthenticated()) {
75
- _ImpakersDebug.showAuth();
76
- return;
77
- }
78
- _ImpakersDebug._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:open"));
79
- }
80
- /** 내부 이벤트 리스너 등록 (React Provider에서 사용) */
81
- static _on(event, handler) {
82
- _ImpakersDebug._eventTarget?.addEventListener(event, handler);
83
- return () => _ImpakersDebug._eventTarget?.removeEventListener(event, handler);
84
- }
85
- };
86
- _ImpakersDebug._eventTarget = typeof EventTarget !== "undefined" ? new EventTarget() : null;
87
- var ImpakersDebug = _ImpakersDebug;
88
- // Annotate the CommonJS export names for ESM import in node:
89
- 0 && (module.exports = {
90
- ImpakersDebug
91
- });
92
- //# sourceMappingURL=index.js.map
1
+ "use strict";var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},f=(t,e,o,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!v.call(t,r)&&r!==o&&a(t,r,{get:()=>e[r],enumerable:!(u=p(e,r))||u.enumerable});return t};var m=t=>f(a({},"__esModule",{value:!0}),t);var k={};g(k,{ImpakersDebug:()=>c});module.exports=m(k);var h="impakers-debug-token",d="impakers-debug-token-data";function w(){if(typeof window>"u")return null;try{let t=localStorage.getItem(d);if(!t)return null;let e=JSON.parse(t);return new Date(e.expiresAt)<new Date?(s(),null):e.token}catch{return null}}function i(){return w()!==null}function s(){if(!(typeof window>"u"))try{localStorage.removeItem(d),localStorage.removeItem(h)}catch{}}var n=class n{static showAuth(){n._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:show-auth"))}static isActive(){return i()}static deactivate(){s(),n._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:deactivate"))}static open(){if(!i()){n.showAuth();return}n._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:open"))}static _on(e,o){return n._eventTarget?.addEventListener(e,o),()=>n._eventTarget?.removeEventListener(e,o)}};n._eventTarget=typeof EventTarget<"u"?new EventTarget:null;var c=n;0&&(module.exports={ImpakersDebug});
package/dist/index.mjs CHANGED
@@ -1,65 +1 @@
1
- // src/core/auth.ts
2
- var STORAGE_KEY = "impakers-debug-token";
3
- var TOKEN_DATA_KEY = "impakers-debug-token-data";
4
- function loadToken() {
5
- if (typeof window === "undefined") return null;
6
- try {
7
- const data = localStorage.getItem(TOKEN_DATA_KEY);
8
- if (!data) return null;
9
- const parsed = JSON.parse(data);
10
- if (new Date(parsed.expiresAt) < /* @__PURE__ */ new Date()) {
11
- clearToken();
12
- return null;
13
- }
14
- return parsed.token;
15
- } catch {
16
- return null;
17
- }
18
- }
19
- function isAuthenticated() {
20
- return loadToken() !== null;
21
- }
22
- function clearToken() {
23
- if (typeof window === "undefined") return;
24
- try {
25
- localStorage.removeItem(TOKEN_DATA_KEY);
26
- localStorage.removeItem(STORAGE_KEY);
27
- } catch {
28
- }
29
- }
30
-
31
- // src/index.ts
32
- var _ImpakersDebug = class _ImpakersDebug {
33
- /** 인증 프롬프트 띄우기 */
34
- static showAuth() {
35
- _ImpakersDebug._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:show-auth"));
36
- }
37
- /** 인증 상태 확인 */
38
- static isActive() {
39
- return isAuthenticated();
40
- }
41
- /** 로그아웃 (토큰 삭제 + UI 숨김) */
42
- static deactivate() {
43
- clearToken();
44
- _ImpakersDebug._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:deactivate"));
45
- }
46
- /** 피드백 폼 열기 (인증된 상태에서) */
47
- static open() {
48
- if (!isAuthenticated()) {
49
- _ImpakersDebug.showAuth();
50
- return;
51
- }
52
- _ImpakersDebug._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:open"));
53
- }
54
- /** 내부 이벤트 리스너 등록 (React Provider에서 사용) */
55
- static _on(event, handler) {
56
- _ImpakersDebug._eventTarget?.addEventListener(event, handler);
57
- return () => _ImpakersDebug._eventTarget?.removeEventListener(event, handler);
58
- }
59
- };
60
- _ImpakersDebug._eventTarget = typeof EventTarget !== "undefined" ? new EventTarget() : null;
61
- var ImpakersDebug = _ImpakersDebug;
62
- export {
63
- ImpakersDebug
64
- };
65
- //# sourceMappingURL=index.mjs.map
1
+ var c="impakers-debug-token",i="impakers-debug-token-data";function u(){if(typeof window>"u")return null;try{let r=localStorage.getItem(i);if(!r)return null;let t=JSON.parse(r);return new Date(t.expiresAt)<new Date?(o(),null):t.token}catch{return null}}function n(){return u()!==null}function o(){if(!(typeof window>"u"))try{localStorage.removeItem(i),localStorage.removeItem(c)}catch{}}var e=class e{static showAuth(){e._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:show-auth"))}static isActive(){return n()}static deactivate(){o(),e._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:deactivate"))}static open(){if(!n()){e.showAuth();return}e._eventTarget?.dispatchEvent(new CustomEvent("impakers-debug:open"))}static _on(t,a){return e._eventTarget?.addEventListener(t,a),()=>e._eventTarget?.removeEventListener(t,a)}};e._eventTarget=typeof EventTarget<"u"?new EventTarget:null;var s=e;export{s as ImpakersDebug};
package/dist/next.js CHANGED
@@ -1,237 +1 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/next.ts
21
- var next_exports = {};
22
- __export(next_exports, {
23
- withImpakersDebug: () => withImpakersDebug
24
- });
25
- module.exports = __toCommonJS(next_exports);
26
- var StripSourceContentPlugin = class {
27
- apply(compiler) {
28
- compiler.hooks.afterEmit.tapAsync(
29
- "ImpakersDebugStripSourceContent",
30
- (compilation, callback) => {
31
- const fs = require("fs");
32
- const path = require("path");
33
- const outputPath = compilation.outputOptions?.path;
34
- if (!outputPath) {
35
- callback();
36
- return;
37
- }
38
- const staticDir = path.resolve(outputPath, "../static");
39
- if (!fs.existsSync(staticDir)) {
40
- callback();
41
- return;
42
- }
43
- const findMaps = (dir) => {
44
- const results = [];
45
- try {
46
- for (const entry of fs.readdirSync(dir, {
47
- withFileTypes: true
48
- })) {
49
- const full = path.join(dir, entry.name);
50
- if (entry.isDirectory()) results.push(...findMaps(full));
51
- else if (entry.name.endsWith(".js.map")) results.push(full);
52
- }
53
- } catch {
54
- }
55
- return results;
56
- };
57
- let stripped = 0;
58
- for (const file of findMaps(staticDir)) {
59
- try {
60
- const raw = fs.readFileSync(file, "utf-8");
61
- const map = JSON.parse(raw);
62
- let changed = false;
63
- if (map.sourcesContent) {
64
- delete map.sourcesContent;
65
- changed = true;
66
- }
67
- if (map.sections) {
68
- for (const section of map.sections) {
69
- if (section.map?.sourcesContent) {
70
- delete section.map.sourcesContent;
71
- changed = true;
72
- }
73
- }
74
- }
75
- if (changed) {
76
- fs.writeFileSync(file, JSON.stringify(map));
77
- stripped++;
78
- }
79
- } catch {
80
- }
81
- }
82
- if (stripped > 0) {
83
- console.log(
84
- `[@impakers/debug] Stripped sourcesContent from ${stripped} sourcemap files`
85
- );
86
- }
87
- callback();
88
- }
89
- );
90
- }
91
- };
92
- var RouteManifestPlugin = class {
93
- constructor(projectDir) {
94
- this.projectDir = projectDir;
95
- }
96
- apply(compiler) {
97
- compiler.hooks.afterEmit.tapAsync(
98
- "ImpakersDebugRouteManifest",
99
- (compilation, callback) => {
100
- const fs = require("fs");
101
- const path = require("path");
102
- const outputPath = compilation.outputOptions?.path;
103
- if (!outputPath) {
104
- callback();
105
- return;
106
- }
107
- const appDir = findAppDirectory(fs, path, this.projectDir);
108
- if (!appDir) {
109
- callback();
110
- return;
111
- }
112
- const entries = scanRouteManifestEntries(fs, path, this.projectDir, appDir);
113
- if (entries.length === 0) {
114
- callback();
115
- return;
116
- }
117
- const manifestPath = path.resolve(
118
- outputPath,
119
- "../static/chunks/impakers-debug-route-manifest.json"
120
- );
121
- try {
122
- fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
123
- fs.writeFileSync(
124
- manifestPath,
125
- JSON.stringify({ version: 1, entries }, null, 2),
126
- "utf-8"
127
- );
128
- console.log(
129
- `[@impakers/debug] Emitted route manifest with ${entries.length} route entries`
130
- );
131
- } catch {
132
- }
133
- callback();
134
- }
135
- );
136
- }
137
- };
138
- function findAppDirectory(fs, path, projectDir) {
139
- const candidates = [
140
- path.join(projectDir, "src", "app"),
141
- path.join(projectDir, "app")
142
- ];
143
- for (const candidate of candidates) {
144
- if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
145
- return candidate;
146
- }
147
- }
148
- return null;
149
- }
150
- function toPosixPath(path) {
151
- return path.replace(/\\/g, "/");
152
- }
153
- function findRouteFile(fs, path, dir, baseName) {
154
- const extensions = [".tsx", ".ts", ".jsx", ".js"];
155
- for (const ext of extensions) {
156
- const file = path.join(dir, `${baseName}${ext}`);
157
- if (fs.existsSync(file) && fs.statSync(file).isFile()) {
158
- return file;
159
- }
160
- }
161
- return null;
162
- }
163
- function getUrlSegment(segmentName) {
164
- if (!segmentName) return null;
165
- if (segmentName.startsWith("(") && segmentName.endsWith(")")) return null;
166
- return segmentName;
167
- }
168
- function routeFromSegments(segments) {
169
- if (segments.length === 0) return "/";
170
- return `/${segments.join("/")}`;
171
- }
172
- function scanRouteManifestEntries(fs, path, projectDir, appDir) {
173
- const entries = [];
174
- const walk = (currentDir, routeSegments, layoutChain) => {
175
- const currentLayout = findRouteFile(fs, path, currentDir, "layout");
176
- const nextLayoutChain = currentLayout ? [
177
- ...layoutChain,
178
- {
179
- kind: "layout",
180
- file: toPosixPath(path.relative(projectDir, currentLayout))
181
- }
182
- ] : layoutChain;
183
- const currentPage = findRouteFile(fs, path, currentDir, "page");
184
- if (currentPage) {
185
- entries.push({
186
- route: routeFromSegments(routeSegments),
187
- segments: [...routeSegments],
188
- files: [
189
- {
190
- kind: "page",
191
- file: toPosixPath(path.relative(projectDir, currentPage))
192
- },
193
- ...nextLayoutChain
194
- ]
195
- });
196
- }
197
- const children = fs.readdirSync(currentDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name));
198
- for (const child of children) {
199
- if (child.name.startsWith("@")) continue;
200
- const nextSegment = getUrlSegment(child.name);
201
- walk(
202
- path.join(currentDir, child.name),
203
- nextSegment ? [...routeSegments, nextSegment] : routeSegments,
204
- nextLayoutChain
205
- );
206
- }
207
- };
208
- walk(appDir, [], []);
209
- return entries;
210
- }
211
- function withImpakersDebug(nextConfig, options = {}) {
212
- const { stripSourceContent = true, emitRouteManifest = true } = options;
213
- return {
214
- ...nextConfig,
215
- // 소스맵 생성 활성화
216
- productionBrowserSourceMaps: true,
217
- webpack(config, context) {
218
- if (typeof nextConfig.webpack === "function") {
219
- config = nextConfig.webpack(config, context);
220
- }
221
- if (!context.isServer) {
222
- config.plugins = config.plugins || [];
223
- if (stripSourceContent) {
224
- config.plugins.push(new StripSourceContentPlugin());
225
- }
226
- if (emitRouteManifest && context.dir) {
227
- config.plugins.push(new RouteManifestPlugin(context.dir));
228
- }
229
- }
230
- return config;
231
- }
232
- };
233
- }
234
- // Annotate the CommonJS export names for ESM import in node:
235
- 0 && (module.exports = {
236
- withImpakersDebug
237
- });
1
+ "use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var i in e)d(t,i,{get:e[i],enumerable:!0})},b=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of j(e))!F.call(t,n)&&n!==i&&d(t,n,{get:()=>e[n],enumerable:!(r=w(e,n))||r.enumerable});return t};var v=t=>b(d({},"__esModule",{value:!0}),t);var O={};R(O,{withImpakersDebug:()=>E});module.exports=v(O);var h=class{apply(e){e.hooks.afterEmit.tapAsync("ImpakersDebugStripSourceContent",(i,r)=>{let n=require("fs"),s=require("path"),o=i.outputOptions?.path;if(!o){r();return}let c=s.resolve(o,"../static");if(!n.existsSync(c)){r();return}let f=l=>{let y=[];try{for(let a of n.readdirSync(l,{withFileTypes:!0})){let u=s.join(l,a.name);a.isDirectory()?y.push(...f(u)):a.name.endsWith(".js.map")&&y.push(u)}}catch{}return y},p=0;for(let l of f(c))try{let y=n.readFileSync(l,"utf-8"),a=JSON.parse(y),u=!1;if(a.sourcesContent&&(delete a.sourcesContent,u=!0),a.sections)for(let g of a.sections)g.map?.sourcesContent&&(delete g.map.sourcesContent,u=!0);u&&(n.writeFileSync(l,JSON.stringify(a)),p++)}catch{}p>0&&console.log(`[@impakers/debug] Stripped sourcesContent from ${p} sourcemap files`),r()})}},m=class{constructor(e){this.projectDir=e}apply(e){e.hooks.afterEmit.tapAsync("ImpakersDebugRouteManifest",(i,r)=>{let n=require("fs"),s=require("path"),o=i.outputOptions?.path;if(!o){r();return}let c=x(n,s,this.projectDir);if(!c){r();return}let f=D(n,s,this.projectDir,c);if(f.length===0){r();return}let p=s.resolve(o,"../static/chunks/impakers-debug-route-manifest.json");try{n.mkdirSync(s.dirname(p),{recursive:!0}),n.writeFileSync(p,JSON.stringify({version:1,entries:f},null,2),"utf-8"),console.log(`[@impakers/debug] Emitted route manifest with ${f.length} route entries`)}catch{}r()})}};function x(t,e,i){let r=[e.join(i,"src","app"),e.join(i,"app")];for(let n of r)if(t.existsSync(n)&&t.statSync(n).isDirectory())return n;return null}function S(t){return t.replace(/\\/g,"/")}function k(t,e,i,r){let n=[".tsx",".ts",".jsx",".js"];for(let s of n){let o=e.join(i,`${r}${s}`);if(t.existsSync(o)&&t.statSync(o).isFile())return o}return null}function M(t){return!t||t.startsWith("(")&&t.endsWith(")")?null:t}function C(t){return t.length===0?"/":`/${t.join("/")}`}function D(t,e,i,r){let n=[],s=(o,c,f)=>{let p=k(t,e,o,"layout"),l=p?[...f,{kind:"layout",file:S(e.relative(i,p))}]:f,y=k(t,e,o,"page");y&&n.push({route:C(c),segments:[...c],files:[{kind:"page",file:S(e.relative(i,y))},...l]});let a=t.readdirSync(o,{withFileTypes:!0}).filter(u=>u.isDirectory()).sort((u,g)=>u.name.localeCompare(g.name));for(let u of a){if(u.name.startsWith("@"))continue;let g=M(u.name);s(e.join(o,u.name),g?[...c,g]:c,l)}};return s(r,[],[]),n}function E(t,e={}){let{stripSourceContent:i=!0,emitRouteManifest:r=!0}=e;return{...t,productionBrowserSourceMaps:!0,webpack(n,s){return typeof t.webpack=="function"&&(n=t.webpack(n,s)),s.isServer||(n.plugins=n.plugins||[],i&&n.plugins.push(new h),r&&s.dir&&n.plugins.push(new m(s.dir))),n}}}0&&(module.exports={withImpakersDebug});
package/dist/next.mjs CHANGED
@@ -1,219 +1 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/next.ts
9
- var StripSourceContentPlugin = class {
10
- apply(compiler) {
11
- compiler.hooks.afterEmit.tapAsync(
12
- "ImpakersDebugStripSourceContent",
13
- (compilation, callback) => {
14
- const fs = __require("fs");
15
- const path = __require("path");
16
- const outputPath = compilation.outputOptions?.path;
17
- if (!outputPath) {
18
- callback();
19
- return;
20
- }
21
- const staticDir = path.resolve(outputPath, "../static");
22
- if (!fs.existsSync(staticDir)) {
23
- callback();
24
- return;
25
- }
26
- const findMaps = (dir) => {
27
- const results = [];
28
- try {
29
- for (const entry of fs.readdirSync(dir, {
30
- withFileTypes: true
31
- })) {
32
- const full = path.join(dir, entry.name);
33
- if (entry.isDirectory()) results.push(...findMaps(full));
34
- else if (entry.name.endsWith(".js.map")) results.push(full);
35
- }
36
- } catch {
37
- }
38
- return results;
39
- };
40
- let stripped = 0;
41
- for (const file of findMaps(staticDir)) {
42
- try {
43
- const raw = fs.readFileSync(file, "utf-8");
44
- const map = JSON.parse(raw);
45
- let changed = false;
46
- if (map.sourcesContent) {
47
- delete map.sourcesContent;
48
- changed = true;
49
- }
50
- if (map.sections) {
51
- for (const section of map.sections) {
52
- if (section.map?.sourcesContent) {
53
- delete section.map.sourcesContent;
54
- changed = true;
55
- }
56
- }
57
- }
58
- if (changed) {
59
- fs.writeFileSync(file, JSON.stringify(map));
60
- stripped++;
61
- }
62
- } catch {
63
- }
64
- }
65
- if (stripped > 0) {
66
- console.log(
67
- `[@impakers/debug] Stripped sourcesContent from ${stripped} sourcemap files`
68
- );
69
- }
70
- callback();
71
- }
72
- );
73
- }
74
- };
75
- var RouteManifestPlugin = class {
76
- constructor(projectDir) {
77
- this.projectDir = projectDir;
78
- }
79
- apply(compiler) {
80
- compiler.hooks.afterEmit.tapAsync(
81
- "ImpakersDebugRouteManifest",
82
- (compilation, callback) => {
83
- const fs = __require("fs");
84
- const path = __require("path");
85
- const outputPath = compilation.outputOptions?.path;
86
- if (!outputPath) {
87
- callback();
88
- return;
89
- }
90
- const appDir = findAppDirectory(fs, path, this.projectDir);
91
- if (!appDir) {
92
- callback();
93
- return;
94
- }
95
- const entries = scanRouteManifestEntries(fs, path, this.projectDir, appDir);
96
- if (entries.length === 0) {
97
- callback();
98
- return;
99
- }
100
- const manifestPath = path.resolve(
101
- outputPath,
102
- "../static/chunks/impakers-debug-route-manifest.json"
103
- );
104
- try {
105
- fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
106
- fs.writeFileSync(
107
- manifestPath,
108
- JSON.stringify({ version: 1, entries }, null, 2),
109
- "utf-8"
110
- );
111
- console.log(
112
- `[@impakers/debug] Emitted route manifest with ${entries.length} route entries`
113
- );
114
- } catch {
115
- }
116
- callback();
117
- }
118
- );
119
- }
120
- };
121
- function findAppDirectory(fs, path, projectDir) {
122
- const candidates = [
123
- path.join(projectDir, "src", "app"),
124
- path.join(projectDir, "app")
125
- ];
126
- for (const candidate of candidates) {
127
- if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
128
- return candidate;
129
- }
130
- }
131
- return null;
132
- }
133
- function toPosixPath(path) {
134
- return path.replace(/\\/g, "/");
135
- }
136
- function findRouteFile(fs, path, dir, baseName) {
137
- const extensions = [".tsx", ".ts", ".jsx", ".js"];
138
- for (const ext of extensions) {
139
- const file = path.join(dir, `${baseName}${ext}`);
140
- if (fs.existsSync(file) && fs.statSync(file).isFile()) {
141
- return file;
142
- }
143
- }
144
- return null;
145
- }
146
- function getUrlSegment(segmentName) {
147
- if (!segmentName) return null;
148
- if (segmentName.startsWith("(") && segmentName.endsWith(")")) return null;
149
- return segmentName;
150
- }
151
- function routeFromSegments(segments) {
152
- if (segments.length === 0) return "/";
153
- return `/${segments.join("/")}`;
154
- }
155
- function scanRouteManifestEntries(fs, path, projectDir, appDir) {
156
- const entries = [];
157
- const walk = (currentDir, routeSegments, layoutChain) => {
158
- const currentLayout = findRouteFile(fs, path, currentDir, "layout");
159
- const nextLayoutChain = currentLayout ? [
160
- ...layoutChain,
161
- {
162
- kind: "layout",
163
- file: toPosixPath(path.relative(projectDir, currentLayout))
164
- }
165
- ] : layoutChain;
166
- const currentPage = findRouteFile(fs, path, currentDir, "page");
167
- if (currentPage) {
168
- entries.push({
169
- route: routeFromSegments(routeSegments),
170
- segments: [...routeSegments],
171
- files: [
172
- {
173
- kind: "page",
174
- file: toPosixPath(path.relative(projectDir, currentPage))
175
- },
176
- ...nextLayoutChain
177
- ]
178
- });
179
- }
180
- const children = fs.readdirSync(currentDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name));
181
- for (const child of children) {
182
- if (child.name.startsWith("@")) continue;
183
- const nextSegment = getUrlSegment(child.name);
184
- walk(
185
- path.join(currentDir, child.name),
186
- nextSegment ? [...routeSegments, nextSegment] : routeSegments,
187
- nextLayoutChain
188
- );
189
- }
190
- };
191
- walk(appDir, [], []);
192
- return entries;
193
- }
194
- function withImpakersDebug(nextConfig, options = {}) {
195
- const { stripSourceContent = true, emitRouteManifest = true } = options;
196
- return {
197
- ...nextConfig,
198
- // 소스맵 생성 활성화
199
- productionBrowserSourceMaps: true,
200
- webpack(config, context) {
201
- if (typeof nextConfig.webpack === "function") {
202
- config = nextConfig.webpack(config, context);
203
- }
204
- if (!context.isServer) {
205
- config.plugins = config.plugins || [];
206
- if (stripSourceContent) {
207
- config.plugins.push(new StripSourceContentPlugin());
208
- }
209
- if (emitRouteManifest && context.dir) {
210
- config.plugins.push(new RouteManifestPlugin(context.dir));
211
- }
212
- }
213
- return config;
214
- }
215
- };
216
- }
217
- export {
218
- withImpakersDebug
219
- };
1
+ var d=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,s)=>(typeof require<"u"?require:e)[s]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var h=class{apply(e){e.hooks.afterEmit.tapAsync("ImpakersDebugStripSourceContent",(s,i)=>{let n=d("fs"),r=d("path"),o=s.outputOptions?.path;if(!o){i();return}let c=r.resolve(o,"../static");if(!n.existsSync(c)){i();return}let f=l=>{let y=[];try{for(let a of n.readdirSync(l,{withFileTypes:!0})){let u=r.join(l,a.name);a.isDirectory()?y.push(...f(u)):a.name.endsWith(".js.map")&&y.push(u)}}catch{}return y},p=0;for(let l of f(c))try{let y=n.readFileSync(l,"utf-8"),a=JSON.parse(y),u=!1;if(a.sourcesContent&&(delete a.sourcesContent,u=!0),a.sections)for(let g of a.sections)g.map?.sourcesContent&&(delete g.map.sourcesContent,u=!0);u&&(n.writeFileSync(l,JSON.stringify(a)),p++)}catch{}p>0&&console.log(`[@impakers/debug] Stripped sourcesContent from ${p} sourcemap files`),i()})}},m=class{constructor(e){this.projectDir=e}apply(e){e.hooks.afterEmit.tapAsync("ImpakersDebugRouteManifest",(s,i)=>{let n=d("fs"),r=d("path"),o=s.outputOptions?.path;if(!o){i();return}let c=w(n,r,this.projectDir);if(!c){i();return}let f=R(n,r,this.projectDir,c);if(f.length===0){i();return}let p=r.resolve(o,"../static/chunks/impakers-debug-route-manifest.json");try{n.mkdirSync(r.dirname(p),{recursive:!0}),n.writeFileSync(p,JSON.stringify({version:1,entries:f},null,2),"utf-8"),console.log(`[@impakers/debug] Emitted route manifest with ${f.length} route entries`)}catch{}i()})}};function w(t,e,s){let i=[e.join(s,"src","app"),e.join(s,"app")];for(let n of i)if(t.existsSync(n)&&t.statSync(n).isDirectory())return n;return null}function S(t){return t.replace(/\\/g,"/")}function k(t,e,s,i){let n=[".tsx",".ts",".jsx",".js"];for(let r of n){let o=e.join(s,`${i}${r}`);if(t.existsSync(o)&&t.statSync(o).isFile())return o}return null}function j(t){return!t||t.startsWith("(")&&t.endsWith(")")?null:t}function F(t){return t.length===0?"/":`/${t.join("/")}`}function R(t,e,s,i){let n=[],r=(o,c,f)=>{let p=k(t,e,o,"layout"),l=p?[...f,{kind:"layout",file:S(e.relative(s,p))}]:f,y=k(t,e,o,"page");y&&n.push({route:F(c),segments:[...c],files:[{kind:"page",file:S(e.relative(s,y))},...l]});let a=t.readdirSync(o,{withFileTypes:!0}).filter(u=>u.isDirectory()).sort((u,g)=>u.name.localeCompare(g.name));for(let u of a){if(u.name.startsWith("@"))continue;let g=j(u.name);r(e.join(o,u.name),g?[...c,g]:c,l)}};return r(i,[],[]),n}function v(t,e={}){let{stripSourceContent:s=!0,emitRouteManifest:i=!0}=e;return{...t,productionBrowserSourceMaps:!0,webpack(n,r){return typeof t.webpack=="function"&&(n=t.webpack(n,r)),r.isServer||(n.plugins=n.plugins||[],s&&n.plugins.push(new h),i&&r.dir&&n.plugins.push(new m(r.dir))),n}}}export{v as withImpakersDebug};