code-inspector-plugin 0.20.17 → 1.0.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 +37 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +101 -67
- package/package.json +6 -5
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ The following are which compilers, web frameworks and editors we supported now:
|
|
|
42
42
|
✅ rspack / rsbuild<br />
|
|
43
43
|
✅ farm<br />
|
|
44
44
|
✅ esbuild<br />
|
|
45
|
+
✅ turbopack (next.js v15+)<br />
|
|
45
46
|
✅ nextjs / nuxt / umijs eg.<br />
|
|
46
47
|
- The following Web frameworks are currently supported:<br />
|
|
47
48
|
✅ vue2<br />
|
|
@@ -247,6 +248,7 @@ Please check here for more usage information: [code-inspector-plugin configurati
|
|
|
247
248
|
<details>
|
|
248
249
|
<summary>Click to expand configuration about: <b>next.js</b></summary>
|
|
249
250
|
|
|
251
|
+
For next.js(<= 14.x):
|
|
250
252
|
```js
|
|
251
253
|
// next.config.js
|
|
252
254
|
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
@@ -261,6 +263,41 @@ Please check here for more usage information: [code-inspector-plugin configurati
|
|
|
261
263
|
module.exports = nextConfig;
|
|
262
264
|
```
|
|
263
265
|
|
|
266
|
+
For next.js(15.0.x ~ 15.2.x):
|
|
267
|
+
```js
|
|
268
|
+
import type { NextConfig } from 'next';
|
|
269
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
270
|
+
|
|
271
|
+
const nextConfig: NextConfig = {
|
|
272
|
+
experimental: {
|
|
273
|
+
turbo: {
|
|
274
|
+
rules: codeInspectorPlugin({
|
|
275
|
+
bundler: 'turbopack',
|
|
276
|
+
}),
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export default nextConfig;
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
For next.js(>= 15.3.x):
|
|
285
|
+
```js
|
|
286
|
+
// next.config.js
|
|
287
|
+
import type { NextConfig } from 'next';
|
|
288
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
289
|
+
|
|
290
|
+
const nextConfig: NextConfig = {
|
|
291
|
+
turbopack: {
|
|
292
|
+
rules: codeInspectorPlugin({
|
|
293
|
+
bundler: 'turbopack',
|
|
294
|
+
}),
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export default nextConfig;
|
|
299
|
+
```
|
|
300
|
+
|
|
264
301
|
</details>
|
|
265
302
|
|
|
266
303
|
<details>
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=Object.defineProperty,q=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var E=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var h=(e,t,r)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t)=>{for(var r in t||(t={}))E.call(t,r)&&h(e,r,t[r]);if(b)for(var r of b(t))k.call(t,r)&&h(e,r,t[r]);return e},P=(e,t)=>q(e,D(t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("vite-code-inspector-plugin"),R=require("webpack-code-inspector-plugin"),i=require("code-inspector-core"),v=require("fs"),f=require("path"),W=require("chalk"),L=require("dotenv");var M=(e,t,r)=>new Promise((l,u)=>{var p=o=>{try{c(r.next(o))}catch(s){u(s)}},n=o=>{try{c(r.throw(o))}catch(s){u(s)}},c=o=>o.done?l(o.value):Promise.resolve(o.value).then(p,n);c((r=r.apply(e,t)).next())});const N="esbuild-code-inspector-plugin";function U(e){return{name:N,setup(t){if(e.close||!i.isDev(e.dev,!1))return;const r={port:0,entry:"",output:e.output},{escapeTags:l=[]}=e,u=new Map;t.onLoad({filter:e.match||/\.(jsx|tsx|js|ts|mjs|mts)?$/},p=>M(this,null,function*(){let n=p.path;n=i.getMappingFilePath(n,e.mappings);let c=yield v.promises.readFile(n,"utf8"),o=u.get(n);if(!o||o.originCode!==c){let s=c,d=e.exclude||[];Array.isArray(d)||(d=[d]);const T=i.matchCondition([...d,/\/node_modules\//],n),w=i.matchCondition(e.include||[],n);if(T&&!w)return s;s=yield i.getCodeWithWebComponent({options:e,file:n,code:s,record:r});let a="";if(i.isJsTypeFile(n)?a="jsx":n.endsWith(".svelte")&&(a="svelte"),a)s=i.transformCode({content:s,filePath:n,fileType:a,escapeTags:l,pathType:e.pathType});else if(n.endsWith(".vue")){a="vue";const{descriptor:y}=i.parseSFC(s,{sourceMap:!1}),S=i.transformCode({content:y.template.content,filePath:n,fileType:a,escapeTags:l,pathType:e.pathType});s=s.replace(y.template.content,S)}const x=f.extname(n).replace(".","");o={originCode:c,output:{contents:s,loader:x}},u.set(n,o)}return o.output}))}}}var A=Object.defineProperty,V=Object.defineProperties,J=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable,j=(e,t,r)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,m=(e,t)=>{for(var r in t||(t={}))$.call(t,r)&&j(e,r,t[r]);if(C)for(var r of C(t))z.call(t,r)&&j(e,r,t[r]);return e},I=(e,t)=>V(e,J(t));function B(e){const t={port:0,entry:"",output:e.output};return e.close||!i.isDev(e.dev,process.env.NODE_ENV==="development")?{}:{"**/*.{jsx,tsx,js,ts,mjs,mts}":{loaders:[m({loader:"webpack-code-inspector-plugin/dist/loader.js",options:I(m({},e),{record:t})},e.enforcePre===!1?{}:{enforce:"pre"}),{loader:"webpack-code-inspector-plugin/dist/inject-loader.js",options:I(m({},e),{record:t}),enforce:"pre"}]}}}function O(e){if(!(e!=null&&e.bundler)){console.log(W.red("Please specify the bundler in the options of code-inspector-plugin."));return}let t=!1;if(e.needEnvInspector)if(t=!0,process.env.CODE_INSPECTOR==="true")t=!1;else{const p=f.resolve(process.cwd(),".env.local");if(v.existsSync(p)){const n=v.readFileSync(p,"utf-8"),c=L.parse(n||"");(c==null?void 0:c.CODE_INSPECTOR)==="true"&&(t=!1)}}let r="";typeof __dirname!="undefined"?r=__dirname:r=f.dirname(i.fileURLToPath(typeof document=="undefined"?require("url").pathToFileURL(__filename).href:document.currentScript&&document.currentScript.src||new URL("index.js",document.baseURI).href));const l=P(g({},e),{close:t,output:f.resolve(r,"./")});return e.bundler==="webpack"||e.bundler==="rspack"?new R(l):e.bundler==="esbuild"?U(l):e.bundler==="turbopack"?B(l):F.ViteCodeInspectorPlugin(l)}const G=O;exports.CodeInspectorPlugin=O;exports.codeInspectorPlugin=G;
|
package/dist/index.mjs
CHANGED
|
@@ -1,106 +1,140 @@
|
|
|
1
|
-
var
|
|
1
|
+
var k = Object.defineProperty, D = Object.defineProperties;
|
|
2
2
|
var F = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var y = Object.getOwnPropertySymbols;
|
|
4
|
+
var S = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var b = (e, t, r) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, h = (e, t) => {
|
|
6
6
|
for (var r in t || (t = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var r of
|
|
10
|
-
|
|
7
|
+
S.call(t, r) && b(e, r, t[r]);
|
|
8
|
+
if (y)
|
|
9
|
+
for (var r of y(t))
|
|
10
|
+
W.call(t, r) && b(e, r, t[r]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
import { ViteCodeInspectorPlugin as
|
|
14
|
-
import
|
|
15
|
-
import { isDev as
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
var
|
|
21
|
-
var
|
|
12
|
+
}, g = (e, t) => D(e, F(t));
|
|
13
|
+
import { ViteCodeInspectorPlugin as N } from "vite-code-inspector-plugin";
|
|
14
|
+
import M from "webpack-code-inspector-plugin";
|
|
15
|
+
import { isDev as T, getMappingFilePath as R, matchCondition as P, getCodeWithWebComponent as A, isJsTypeFile as L, parseSFC as V, transformCode as C, fileURLToPath as J } from "code-inspector-core";
|
|
16
|
+
import f from "fs";
|
|
17
|
+
import m, { dirname as U } from "path";
|
|
18
|
+
import $ from "chalk";
|
|
19
|
+
import q from "dotenv";
|
|
20
|
+
var z = (e, t, r) => new Promise((l, p) => {
|
|
21
|
+
var i = (n) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
c(r.next(n));
|
|
24
24
|
} catch (s) {
|
|
25
|
-
|
|
25
|
+
p(s);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
27
|
+
}, o = (n) => {
|
|
28
28
|
try {
|
|
29
|
-
|
|
29
|
+
c(r.throw(n));
|
|
30
30
|
} catch (s) {
|
|
31
|
-
|
|
31
|
+
p(s);
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
|
|
33
|
+
}, c = (n) => n.done ? l(n.value) : Promise.resolve(n.value).then(i, o);
|
|
34
|
+
c((r = r.apply(e, t)).next());
|
|
35
35
|
});
|
|
36
|
-
const
|
|
37
|
-
function
|
|
36
|
+
const B = "esbuild-code-inspector-plugin";
|
|
37
|
+
function G(e) {
|
|
38
38
|
return {
|
|
39
|
-
name:
|
|
39
|
+
name: B,
|
|
40
40
|
setup(t) {
|
|
41
|
-
if (e.close || !
|
|
41
|
+
if (e.close || !T(e.dev, !1))
|
|
42
42
|
return;
|
|
43
43
|
const r = {
|
|
44
44
|
port: 0,
|
|
45
45
|
entry: "",
|
|
46
46
|
output: e.output
|
|
47
|
-
}, { escapeTags: l = [] } = e,
|
|
47
|
+
}, { escapeTags: l = [] } = e, p = /* @__PURE__ */ new Map();
|
|
48
48
|
t.onLoad(
|
|
49
49
|
{ filter: e.match || /\.(jsx|tsx|js|ts|mjs|mts)?$/ },
|
|
50
|
-
(
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
let
|
|
54
|
-
if (!
|
|
55
|
-
let s =
|
|
50
|
+
(i) => z(this, null, function* () {
|
|
51
|
+
let o = i.path;
|
|
52
|
+
o = R(o, e.mappings);
|
|
53
|
+
let c = yield f.promises.readFile(o, "utf8"), n = p.get(o);
|
|
54
|
+
if (!n || n.originCode !== c) {
|
|
55
|
+
let s = c, u = e.exclude || [];
|
|
56
56
|
Array.isArray(u) || (u = [u]);
|
|
57
|
-
const
|
|
57
|
+
const x = P(
|
|
58
58
|
[...u, /\/node_modules\//],
|
|
59
|
-
|
|
60
|
-
),
|
|
61
|
-
if (
|
|
59
|
+
o
|
|
60
|
+
), I = P(e.include || [], o);
|
|
61
|
+
if (x && !I)
|
|
62
62
|
return s;
|
|
63
|
-
s = yield
|
|
63
|
+
s = yield A({
|
|
64
64
|
options: e,
|
|
65
|
-
file:
|
|
65
|
+
file: o,
|
|
66
66
|
code: s,
|
|
67
67
|
record: r
|
|
68
68
|
});
|
|
69
69
|
let a = "";
|
|
70
|
-
if (
|
|
71
|
-
s =
|
|
70
|
+
if (L(o) ? a = "jsx" : o.endsWith(".svelte") && (a = "svelte"), a)
|
|
71
|
+
s = C({
|
|
72
72
|
content: s,
|
|
73
|
-
filePath:
|
|
73
|
+
filePath: o,
|
|
74
74
|
fileType: a,
|
|
75
75
|
escapeTags: l,
|
|
76
76
|
pathType: e.pathType
|
|
77
77
|
});
|
|
78
|
-
else if (
|
|
78
|
+
else if (o.endsWith(".vue")) {
|
|
79
79
|
a = "vue";
|
|
80
|
-
const { descriptor:
|
|
80
|
+
const { descriptor: v } = V(s, {
|
|
81
81
|
sourceMap: !1
|
|
82
|
-
}),
|
|
83
|
-
content:
|
|
84
|
-
filePath:
|
|
82
|
+
}), _ = C({
|
|
83
|
+
content: v.template.content,
|
|
84
|
+
filePath: o,
|
|
85
85
|
fileType: a,
|
|
86
86
|
escapeTags: l,
|
|
87
87
|
pathType: e.pathType
|
|
88
88
|
});
|
|
89
|
-
s = s.replace(
|
|
89
|
+
s = s.replace(v.template.content, _);
|
|
90
90
|
}
|
|
91
|
-
const
|
|
92
|
-
|
|
91
|
+
const E = m.extname(o).replace(".", "");
|
|
92
|
+
n = { originCode: c, output: { contents: s, loader: E } }, p.set(o, n);
|
|
93
93
|
}
|
|
94
|
-
return
|
|
94
|
+
return n.output;
|
|
95
95
|
})
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
var H = Object.defineProperty, K = Object.defineProperties, Q = Object.getOwnPropertyDescriptors, j = Object.getOwnPropertySymbols, X = Object.prototype.hasOwnProperty, Y = Object.prototype.propertyIsEnumerable, O = (e, t, r) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, d = (e, t) => {
|
|
101
|
+
for (var r in t || (t = {}))
|
|
102
|
+
X.call(t, r) && O(e, r, t[r]);
|
|
103
|
+
if (j)
|
|
104
|
+
for (var r of j(t))
|
|
105
|
+
Y.call(t, r) && O(e, r, t[r]);
|
|
106
|
+
return e;
|
|
107
|
+
}, w = (e, t) => K(e, Q(t));
|
|
108
|
+
function Z(e) {
|
|
109
|
+
const t = {
|
|
110
|
+
port: 0,
|
|
111
|
+
entry: "",
|
|
112
|
+
output: e.output
|
|
113
|
+
};
|
|
114
|
+
return e.close || !T(e.dev, process.env.NODE_ENV === "development") ? {} : {
|
|
115
|
+
"**/*.{jsx,tsx,js,ts,mjs,mts}": {
|
|
116
|
+
loaders: [
|
|
117
|
+
d({
|
|
118
|
+
loader: "webpack-code-inspector-plugin/dist/loader.js",
|
|
119
|
+
options: w(d({}, e), {
|
|
120
|
+
record: t
|
|
121
|
+
})
|
|
122
|
+
}, e.enforcePre === !1 ? {} : { enforce: "pre" }),
|
|
123
|
+
{
|
|
124
|
+
loader: "webpack-code-inspector-plugin/dist/inject-loader.js",
|
|
125
|
+
options: w(d({}, e), {
|
|
126
|
+
record: t
|
|
127
|
+
}),
|
|
128
|
+
enforce: "pre"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function ee(e) {
|
|
101
135
|
if (!(e != null && e.bundler)) {
|
|
102
136
|
console.log(
|
|
103
|
-
|
|
137
|
+
$.red(
|
|
104
138
|
"Please specify the bundler in the options of code-inspector-plugin."
|
|
105
139
|
)
|
|
106
140
|
);
|
|
@@ -111,22 +145,22 @@ function q(e) {
|
|
|
111
145
|
if (t = !0, process.env.CODE_INSPECTOR === "true")
|
|
112
146
|
t = !1;
|
|
113
147
|
else {
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
(
|
|
148
|
+
const i = m.resolve(process.cwd(), ".env.local");
|
|
149
|
+
if (f.existsSync(i)) {
|
|
150
|
+
const o = f.readFileSync(i, "utf-8"), c = q.parse(o || "");
|
|
151
|
+
(c == null ? void 0 : c.CODE_INSPECTOR) === "true" && (t = !1);
|
|
118
152
|
}
|
|
119
153
|
}
|
|
120
154
|
let r = "";
|
|
121
|
-
typeof __dirname != "undefined" ? r = __dirname : r =
|
|
122
|
-
const l =
|
|
155
|
+
typeof __dirname != "undefined" ? r = __dirname : r = U(J(import.meta.url));
|
|
156
|
+
const l = g(h({}, e), {
|
|
123
157
|
close: t,
|
|
124
|
-
output:
|
|
158
|
+
output: m.resolve(r, "./")
|
|
125
159
|
});
|
|
126
|
-
return e.bundler === "webpack" || e.bundler === "rspack" ? new
|
|
160
|
+
return e.bundler === "webpack" || e.bundler === "rspack" ? new M(l) : e.bundler === "esbuild" ? G(l) : e.bundler === "turbopack" ? Z(l) : N(l);
|
|
127
161
|
}
|
|
128
|
-
const
|
|
162
|
+
const ie = ee;
|
|
129
163
|
export {
|
|
130
|
-
|
|
131
|
-
|
|
164
|
+
ee as CodeInspectorPlugin,
|
|
165
|
+
ie as codeInspectorPlugin
|
|
132
166
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-inspector-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -48,10 +48,11 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"chalk": "4.1.1",
|
|
50
50
|
"dotenv": "^16.3.1",
|
|
51
|
-
"code-inspector-core": "0.
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
51
|
+
"code-inspector-core": "1.0.1",
|
|
52
|
+
"esbuild-code-inspector-plugin": "1.0.1",
|
|
53
|
+
"webpack-code-inspector-plugin": "1.0.1",
|
|
54
|
+
"turbopack-code-inspector-plugin": "1.0.1",
|
|
55
|
+
"vite-code-inspector-plugin": "1.0.1"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@types/node": "^16.0.1",
|
package/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface CodeInspectorPluginOptions extends CodeOptions {
|
|
|
4
4
|
* @zh 指定项目的打包器
|
|
5
5
|
* @en specify the bundler of the project
|
|
6
6
|
*/
|
|
7
|
-
bundler: 'vite' | 'webpack' | 'rspack' | 'esbuild';
|
|
7
|
+
bundler: 'vite' | 'webpack' | 'rspack' | 'esbuild' | 'turbopack';
|
|
8
8
|
/**
|
|
9
9
|
* @zh 设置为 true 时,仅当 .env.local 文件存在且其包含 CODE_INSPECTOR=true 时插件生效;默认值为 false
|
|
10
10
|
* @en When set the value to true, only if the .env.local file exists and it contains CODE_INSPECTOR=true, the plugin takes effect; The default value is false
|