code-inspector-plugin 0.20.16 → 1.0.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
@@ -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 S=Object.defineProperty,_=Object.defineProperties;var q=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var C=(e,t,n)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,g=(e,t)=>{for(var n in t||(t={}))w.call(t,n)&&C(e,n,t[n]);if(y)for(var n of y(t))F.call(t,n)&&C(e,n,t[n]);return e},v=(e,t)=>_(e,q(t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("vite-code-inspector-plugin"),R=require("webpack-code-inspector-plugin"),i=require("code-inspector-core"),m=require("fs"),f=require("path"),D=require("chalk"),E=require("dotenv");var O=(e,t,n)=>new Promise((l,u)=>{var a=o=>{try{c(n.next(o))}catch(s){u(s)}},r=o=>{try{c(n.throw(o))}catch(s){u(s)}},c=o=>o.done?l(o.value):Promise.resolve(o.value).then(a,r);c((n=n.apply(e,t)).next())});const W="esbuild-code-inspector-plugin";function k(e){return{name:W,setup(t){if(e.close||!i.isDev(e.dev,!1))return;const n={port:0,entry:"",output:e.output},{escapeTags:l=[]}=e,u=new Map;t.onLoad({filter:e.match||/\.(jsx|tsx|js|ts|mjs|mts)?$/},a=>O(this,null,function*(){let r=a.path;r=i.getMappingFilePath(r,e.mappings);let c=yield m.promises.readFile(r,"utf8"),o=u.get(r);if(!o||o.originCode!==c){let s=c,p=e.exclude||[];Array.isArray(p)||(p=[p]);const I=i.matchCondition([...p,/\/node_modules\//],r),T=i.matchCondition(e.include||[],r);if(I&&!T)return s;s=yield i.getCodeWithWebComponent({options:e,file:r,code:s,record:n});let d="";if(i.isJsTypeFile(r)?d="jsx":r.endsWith(".svelte")&&(d="svelte"),d)s=i.transformCode({content:s,filePath:r,fileType:d,escapeTags:l,pathType:e.pathType});else if(r.endsWith(".vue")){d="vue";const{descriptor:h}=i.parseSFC(s,{sourceMap:!1}),x=i.transformCode({content:h.template.content,filePath:r,fileType:d,escapeTags:l,pathType:e.pathType});s=s.replace(h.template.content,x)}const b=f.extname(r).replace(".","");o={originCode:c,output:{contents:s,loader:b}},u.set(r,o)}return o.output}))}}}function P(e){if(!(e!=null&&e.bundler)){console.log(D.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 a=f.resolve(process.cwd(),".env.local");if(m.existsSync(a)){const r=m.readFileSync(a,"utf-8"),c=E.parse(r||"");(c==null?void 0:c.CODE_INSPECTOR)==="true"&&(t=!1)}}let n="";typeof __dirname!="undefined"?n=__dirname:n=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=v(g({},e),{close:t,output:f.resolve(n,"./")});return e.bundler==="webpack"||e.bundler==="rspack"?new R(l):e.bundler==="esbuild"?k(l):j.ViteCodeInspectorPlugin(l)}const L=P;exports.CodeInspectorPlugin=P;exports.codeInspectorPlugin=L;
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 w = Object.defineProperty, _ = Object.defineProperties;
1
+ var k = Object.defineProperty, D = Object.defineProperties;
2
2
  var F = Object.getOwnPropertyDescriptors;
3
- var h = Object.getOwnPropertySymbols;
4
- var D = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
5
- var y = (e, t, r) => t in e ? w(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, v = (e, t) => {
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
- D.call(t, r) && y(e, r, t[r]);
8
- if (h)
9
- for (var r of h(t))
10
- E.call(t, r) && y(e, r, t[r]);
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
- }, C = (e, t) => _(e, F(t));
13
- import { ViteCodeInspectorPlugin as S } from "vite-code-inspector-plugin";
14
- import W from "webpack-code-inspector-plugin";
15
- import { isDev as j, getMappingFilePath as k, matchCondition as g, getCodeWithWebComponent as O, isJsTypeFile as M, parseSFC as R, transformCode as P, fileURLToPath as A } from "code-inspector-core";
16
- import d from "fs";
17
- import f, { dirname as L } from "path";
18
- import N from "chalk";
19
- import J from "dotenv";
20
- var U = (e, t, r) => new Promise((l, c) => {
21
- var p = (o) => {
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
- i(r.next(o));
23
+ c(r.next(n));
24
24
  } catch (s) {
25
- c(s);
25
+ p(s);
26
26
  }
27
- }, n = (o) => {
27
+ }, o = (n) => {
28
28
  try {
29
- i(r.throw(o));
29
+ c(r.throw(n));
30
30
  } catch (s) {
31
- c(s);
31
+ p(s);
32
32
  }
33
- }, i = (o) => o.done ? l(o.value) : Promise.resolve(o.value).then(p, n);
34
- i((r = r.apply(e, t)).next());
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 V = "esbuild-code-inspector-plugin";
37
- function $(e) {
36
+ const B = "esbuild-code-inspector-plugin";
37
+ function G(e) {
38
38
  return {
39
- name: V,
39
+ name: B,
40
40
  setup(t) {
41
- if (e.close || !j(e.dev, !1))
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, c = /* @__PURE__ */ new Map();
47
+ }, { escapeTags: l = [] } = e, p = /* @__PURE__ */ new Map();
48
48
  t.onLoad(
49
49
  { filter: e.match || /\.(jsx|tsx|js|ts|mjs|mts)?$/ },
50
- (p) => U(this, null, function* () {
51
- let n = p.path;
52
- n = k(n, e.mappings);
53
- let i = yield d.promises.readFile(n, "utf8"), o = c.get(n);
54
- if (!o || o.originCode !== i) {
55
- let s = i, u = e.exclude || [];
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 T = g(
57
+ const x = P(
58
58
  [...u, /\/node_modules\//],
59
- n
60
- ), b = g(e.include || [], n);
61
- if (T && !b)
59
+ o
60
+ ), I = P(e.include || [], o);
61
+ if (x && !I)
62
62
  return s;
63
- s = yield O({
63
+ s = yield A({
64
64
  options: e,
65
- file: n,
65
+ file: o,
66
66
  code: s,
67
67
  record: r
68
68
  });
69
69
  let a = "";
70
- if (M(n) ? a = "jsx" : n.endsWith(".svelte") && (a = "svelte"), a)
71
- s = P({
70
+ if (L(o) ? a = "jsx" : o.endsWith(".svelte") && (a = "svelte"), a)
71
+ s = C({
72
72
  content: s,
73
- filePath: n,
73
+ filePath: o,
74
74
  fileType: a,
75
75
  escapeTags: l,
76
76
  pathType: e.pathType
77
77
  });
78
- else if (n.endsWith(".vue")) {
78
+ else if (o.endsWith(".vue")) {
79
79
  a = "vue";
80
- const { descriptor: m } = R(s, {
80
+ const { descriptor: v } = V(s, {
81
81
  sourceMap: !1
82
- }), x = P({
83
- content: m.template.content,
84
- filePath: n,
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(m.template.content, x);
89
+ s = s.replace(v.template.content, _);
90
90
  }
91
- const I = f.extname(n).replace(".", "");
92
- o = { originCode: i, output: { contents: s, loader: I } }, c.set(n, o);
91
+ const E = m.extname(o).replace(".", "");
92
+ n = { originCode: c, output: { contents: s, loader: E } }, p.set(o, n);
93
93
  }
94
- return o.output;
94
+ return n.output;
95
95
  })
96
96
  );
97
97
  }
98
98
  };
99
99
  }
100
- function q(e) {
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
- N.red(
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 p = f.resolve(process.cwd(), ".env.local");
115
- if (d.existsSync(p)) {
116
- const n = d.readFileSync(p, "utf-8"), i = J.parse(n || "");
117
- (i == null ? void 0 : i.CODE_INSPECTOR) === "true" && (t = !1);
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 = L(A(import.meta.url));
122
- const l = C(v({}, e), {
155
+ typeof __dirname != "undefined" ? r = __dirname : r = U(J(import.meta.url));
156
+ const l = g(h({}, e), {
123
157
  close: t,
124
- output: f.resolve(r, "./")
158
+ output: m.resolve(r, "./")
125
159
  });
126
- return e.bundler === "webpack" || e.bundler === "rspack" ? new W(l) : e.bundler === "esbuild" ? $(l) : S(l);
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 Z = q;
162
+ const ie = ee;
129
163
  export {
130
- q as CodeInspectorPlugin,
131
- Z as codeInspectorPlugin
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.20.16",
3
+ "version": "1.0.0",
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
- "esbuild-code-inspector-plugin": "0.20.16",
52
- "code-inspector-core": "0.20.16",
53
- "vite-code-inspector-plugin": "0.20.16",
54
- "webpack-code-inspector-plugin": "0.20.16"
51
+ "code-inspector-core": "1.0.0",
52
+ "esbuild-code-inspector-plugin": "1.0.0",
53
+ "vite-code-inspector-plugin": "1.0.0",
54
+ "webpack-code-inspector-plugin": "1.0.0",
55
+ "turbopack-code-inspector-plugin": "1.0.0"
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