code-inspector-plugin 0.14.2 → 0.15.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 +39 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +227 -155
- package/package.json +5 -4
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,8 @@ The following are which compilers, web frameworks and editors we supported now:
|
|
|
40
40
|
✅ webpack<br />
|
|
41
41
|
✅ vite<br />
|
|
42
42
|
✅ rspack / rsbuild<br />
|
|
43
|
+
✅ farm<br />
|
|
44
|
+
✅ esbuild<br />
|
|
43
45
|
✅ nextjs / nuxt / umijs eg.<br />
|
|
44
46
|
- The following Web frameworks are currently supported:<br />
|
|
45
47
|
✅ vue2<br />
|
|
@@ -149,6 +151,43 @@ Please check here for more usage information: [code-inspector-plugin configurati
|
|
|
149
151
|
|
|
150
152
|
</details>
|
|
151
153
|
|
|
154
|
+
<details>
|
|
155
|
+
<summary>Click to expand configuration about: <b>esbuild</b></summary>
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
// esbuild.config.js
|
|
159
|
+
const esbuild = require('esbuild');
|
|
160
|
+
const { codeInspectorPlugin } = require('code-inspector-plugin');
|
|
161
|
+
|
|
162
|
+
esbuild.build({
|
|
163
|
+
// other configs...
|
|
164
|
+
// [注意] esbuild 中使用时,dev 函数的返回值需自己根据环境判断,本地开发的环境返回 true,线上打包返回 false
|
|
165
|
+
plugins: [codeInspectorPlugin({ bundler: 'esbuild', dev: () => true })],
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
</details>
|
|
170
|
+
|
|
171
|
+
<details>
|
|
172
|
+
<summary>Click to expand configuration about: <b>farm</b></summary>
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
// farm.config.js
|
|
176
|
+
import { defineConfig } from '@farmfe/core';
|
|
177
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
178
|
+
|
|
179
|
+
export default defineConfig({
|
|
180
|
+
vitePlugins: [
|
|
181
|
+
codeInspectorPlugin({
|
|
182
|
+
bundler: 'vite',
|
|
183
|
+
}),
|
|
184
|
+
// ...other code
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
</details>
|
|
190
|
+
|
|
152
191
|
<details>
|
|
153
192
|
<summary>Click to expand configuration about: <b>vue-cli</b></summary>
|
|
154
193
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var P=Object.defineProperty,k=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var b=(e,t,n)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,w=(e,t)=>{for(var n in t||(t={}))x.call(t,n)&&b(e,n,t[n]);if(_)for(var n of _(t))R.call(t,n)&&b(e,n,t[n]);return e},D=(e,t)=>k(e,C(t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("vite-code-inspector-plugin"),L=require("webpack-code-inspector-plugin"),f=require("code-inspector-core"),g=require("fs"),v=require("path"),F=require("chalk");var K=(e,t,n)=>new Promise((s,c)=>{var r=a=>{try{i(n.next(a))}catch(u){c(u)}},o=a=>{try{i(n.throw(a))}catch(u){c(u)}},i=a=>a.done?s(a.value):Promise.resolve(a.value).then(r,o);i((n=n.apply(e,t)).next())});const A="esbuild-code-inspector-plugin";function Y(e){let t;return typeof e=="function"?t=e():t=e,!!t}function M(e){return{name:A,setup(t){if(e.close||!Y(e.dev))return;const n={port:0,entry:"",output:e.output},{escapeTags:s=[]}=e,c=new Map;t.onLoad({filter:e.match||/\.(jsx|tsx|js|ts|mjs|mts)?$/},r=>K(this,null,function*(){const o=r.path;let i=yield g.promises.readFile(o,"utf8"),a=c.get(o);if(!a||a.originCode!==i){let u=yield f.getCodeWithWebComponent(e,o,i,n),d="";if(f.isJsTypeFile(o)?d="jsx":o.endsWith(".svelte")&&(d="svelte"),d)u=f.transformCode({content:u,filePath:o,fileType:d,escapeTags:s});else if(o.endsWith(".vue")){d="vue";const{descriptor:E}=f.parseSFC(u,{sourceMap:!1}),V=f.transformCode({content:E.template.content,filePath:o,fileType:d,escapeTags:s});u=u.replace(E.template.content,V)}const $=v.extname(o).replace(".","");a={originCode:i,output:{contents:u,loader:$}},c.set(o,a)}return a.output}))}}}function U(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var n=function s(){if(this instanceof s){var c=[null];c.push.apply(c,arguments);var r=Function.bind.apply(t,c);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(s){var c=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(n,s,c.get?c:{enumerable:!0,get:function(){return e[s]}})}),n}var p={},q={get exports(){return p},set exports(e){p=e}};const B={},W=Object.freeze(Object.defineProperty({__proto__:null,default:B},Symbol.toStringTag,{value:"Module"})),I=U(W),J="dotenv",G="16.3.1",Q="Loads environment variables from .env file",z="lib/main.js",H="lib/main.d.ts",X={".":{types:"./lib/main.d.ts",require:"./lib/main.js",default:"./lib/main.js"},"./config":"./config.js","./config.js":"./config.js","./lib/env-options":"./lib/env-options.js","./lib/env-options.js":"./lib/env-options.js","./lib/cli-options":"./lib/cli-options.js","./lib/cli-options.js":"./lib/cli-options.js","./package.json":"./package.json"},Z={"dts-check":"tsc --project tests/types/tsconfig.json",lint:"standard","lint-readme":"standard-markdown",pretest:"npm run lint && npm run dts-check",test:"tap tests/*.js --100 -Rspec",prerelease:"npm test",release:"standard-version"},ee={type:"git",url:"git://github.com/motdotla/dotenv.git"},te="https://github.com/motdotla/dotenv?sponsor=1",ne=["dotenv","env",".env","environment","variables","config","settings"],re="README.md",oe="BSD-2-Clause",se={"@definitelytyped/dtslint":"^0.0.133","@types/node":"^18.11.3",decache:"^4.6.1",sinon:"^14.0.1",standard:"^17.0.0","standard-markdown":"^7.1.0","standard-version":"^9.5.0",tap:"^16.3.0",tar:"^6.1.11",typescript:"^4.8.4"},ce={node:">=12"},ie={fs:!1},ae={name:J,version:G,description:Q,main:z,types:H,exports:X,scripts:Z,repository:ee,funding:te,keywords:ne,readmeFilename:re,license:oe,devDependencies:se,engines:ce,browser:ie},O=g,h=v,le=I,ue=I,de=ae,y=de.version,pe=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function fe(e){const t={};let n=e.toString();n=n.replace(/\r\n?/mg,"\n");let s;for(;(s=pe.exec(n))!=null;){const c=s[1];let r=s[2]||"";r=r.trim();const o=r[0];r=r.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),o==='"'&&(r=r.replace(/\\n/g,"\n"),r=r.replace(/\\r/g,"\r")),t[c]=r}return t}function ve(e){const t=j(e),n=l.configDotenv({path:t});if(!n.parsed)throw new Error("MISSING_DATA: Cannot parse ".concat(t," for an unknown reason"));const s=T(e).split(","),c=s.length;let r;for(let o=0;o<c;o++)try{const i=s[o].trim(),a=he(n,i);r=l.decrypt(a.ciphertext,a.key);break}catch(i){if(o+1>=c)throw i}return l.parse(r)}function ge(e){console.log("[dotenv@".concat(y,"][INFO] ").concat(e))}function me(e){console.log("[dotenv@".concat(y,"][WARN] ").concat(e))}function m(e){console.log("[dotenv@".concat(y,"][DEBUG] ").concat(e))}function T(e){return e&&e.DOTENV_KEY&&e.DOTENV_KEY.length>0?e.DOTENV_KEY:process.env.DOTENV_KEY&&process.env.DOTENV_KEY.length>0?process.env.DOTENV_KEY:""}function he(e,t){let n;try{n=new URL(t)}catch(i){throw i.code==="ERR_INVALID_URL"?new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development"):i}const s=n.password;if(!s)throw new Error("INVALID_DOTENV_KEY: Missing key part");const c=n.searchParams.get("environment");if(!c)throw new Error("INVALID_DOTENV_KEY: Missing environment part");const r="DOTENV_VAULT_".concat(c.toUpperCase()),o=e.parsed[r];if(!o)throw new Error("NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ".concat(r," in your .env.vault file."));return{ciphertext:o,key:s}}function j(e){let t=h.resolve(process.cwd(),".env");return e&&e.path&&e.path.length>0&&(t=e.path),t.endsWith(".vault")?t:"".concat(t,".vault")}function ye(e){return e[0]==="~"?h.join(le.homedir(),e.slice(1)):e}function Ee(e){ge("Loading env from encrypted .env.vault");const t=l._parseVault(e);let n=process.env;return e&&e.processEnv!=null&&(n=e.processEnv),l.populate(n,t,e),{parsed:t}}function _e(e){let t=h.resolve(process.cwd(),".env"),n="utf8";const s=!!(e&&e.debug);e&&(e.path!=null&&(t=ye(e.path)),e.encoding!=null&&(n=e.encoding));try{const c=l.parse(O.readFileSync(t,{encoding:n}));let r=process.env;return e&&e.processEnv!=null&&(r=e.processEnv),l.populate(r,c,e),{parsed:c}}catch(c){return s&&m("Failed to load ".concat(t," ").concat(c.message)),{error:c}}}function be(e){const t=j(e);return T(e).length===0?l.configDotenv(e):O.existsSync(t)?l._configVault(e):(me("You set DOTENV_KEY but you are missing a .env.vault file at ".concat(t,". Did you forget to build it?")),l.configDotenv(e))}function we(e,t){const n=Buffer.from(t.slice(-64),"hex");let s=Buffer.from(e,"base64");const c=s.slice(0,12),r=s.slice(-16);s=s.slice(12,-16);try{const o=ue.createDecipheriv("aes-256-gcm",n,c);return o.setAuthTag(r),"".concat(o.update(s)).concat(o.final())}catch(o){const i=o instanceof RangeError,a=o.message==="Invalid key length",u=o.message==="Unsupported state or unable to authenticate data";if(i||a){const d="INVALID_DOTENV_KEY: It must be 64 characters long (or more)";throw new Error(d)}else if(u){const d="DECRYPTION_FAILED: Please check your DOTENV_KEY";throw new Error(d)}else throw console.error("Error: ",o.code),console.error("Error: ",o.message),o}}function De(e,t,n={}){const s=!!(n&&n.debug),c=!!(n&&n.override);if(typeof t!="object")throw new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");for(const r of Object.keys(t))Object.prototype.hasOwnProperty.call(e,r)?(c===!0&&(e[r]=t[r]),s&&m(c===!0?'"'.concat(r,'" is already defined and WAS overwritten'):'"'.concat(r,'" is already defined and was NOT overwritten'))):e[r]=t[r]}const l={configDotenv:_e,_configVault:Ee,_parseVault:ve,config:be,decrypt:we,parse:fe,populate:De};p.configDotenv=l.configDotenv;p._configVault=l._configVault;p._parseVault=l._parseVault;p.config=l.config;p.decrypt=l.decrypt;p.parse=l.parse;p.populate=l.populate;q.exports=l;function N(e){if(!(e!=null&&e.bundler)){console.log(F.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 r=v.resolve(process.cwd(),".env.local");if(g.existsSync(r)){const o=g.readFileSync(r,"utf-8"),i=p.parse(o||"");(i==null?void 0:i.CODE_INSPECTOR)==="true"&&(t=!1)}}let n="";typeof __dirname!="undefined"?n=__dirname:n=v.dirname(f.fileURLToPath(typeof document=="undefined"?require("url").pathToFileURL(__filename).href:document.currentScript&&document.currentScript.src||new URL("index.js",document.baseURI).href));const s=D(w({},e),{close:t,output:v.resolve(n,"./")});return e.bundler==="webpack"||e.bundler==="rspack"?new L(s):e.bundler==="esbuild"?M(s):S.ViteCodeInspectorPlugin(s)}const Ie=N;exports.CodeInspectorPlugin=N;exports.codeInspectorPlugin=Ie;
|
package/dist/index.mjs
CHANGED
|
@@ -1,31 +1,103 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var V = Object.defineProperty, k = Object.defineProperties;
|
|
2
|
+
var P = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var E = Object.getOwnPropertySymbols;
|
|
4
|
+
var x = Object.prototype.hasOwnProperty, C = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var _ = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, b = (e, t) => {
|
|
6
6
|
for (var n in t || (t = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var n of
|
|
10
|
-
|
|
7
|
+
x.call(t, n) && _(e, n, t[n]);
|
|
8
|
+
if (E)
|
|
9
|
+
for (var n of E(t))
|
|
10
|
+
C.call(t, n) && _(e, n, t[n]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
import { ViteCodeInspectorPlugin as
|
|
14
|
-
import
|
|
15
|
-
import { fileURLToPath as
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
12
|
+
}, w = (e, t) => k(e, P(t));
|
|
13
|
+
import { ViteCodeInspectorPlugin as R } from "vite-code-inspector-plugin";
|
|
14
|
+
import K from "webpack-code-inspector-plugin";
|
|
15
|
+
import { getCodeWithWebComponent as L, isJsTypeFile as S, parseSFC as A, transformCode as D, fileURLToPath as F } from "code-inspector-core";
|
|
16
|
+
import f from "fs";
|
|
17
|
+
import v, { dirname as Y } from "path";
|
|
18
|
+
import M from "chalk";
|
|
19
|
+
var B = (e, t, n) => new Promise((s, c) => {
|
|
20
|
+
var r = (a) => {
|
|
21
|
+
try {
|
|
22
|
+
i(n.next(a));
|
|
23
|
+
} catch (u) {
|
|
24
|
+
c(u);
|
|
25
|
+
}
|
|
26
|
+
}, o = (a) => {
|
|
27
|
+
try {
|
|
28
|
+
i(n.throw(a));
|
|
29
|
+
} catch (u) {
|
|
30
|
+
c(u);
|
|
31
|
+
}
|
|
32
|
+
}, i = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(r, o);
|
|
33
|
+
i((n = n.apply(e, t)).next());
|
|
34
|
+
});
|
|
35
|
+
const W = "esbuild-code-inspector-plugin";
|
|
36
|
+
function U(e) {
|
|
37
|
+
let t;
|
|
38
|
+
return typeof e == "function" ? t = e() : t = e, !!t;
|
|
39
|
+
}
|
|
40
|
+
function q(e) {
|
|
41
|
+
return {
|
|
42
|
+
name: W,
|
|
43
|
+
setup(t) {
|
|
44
|
+
if (e.close || !U(e.dev))
|
|
45
|
+
return;
|
|
46
|
+
const n = {
|
|
47
|
+
port: 0,
|
|
48
|
+
entry: "",
|
|
49
|
+
output: e.output
|
|
50
|
+
}, { escapeTags: s = [] } = e, c = /* @__PURE__ */ new Map();
|
|
51
|
+
t.onLoad(
|
|
52
|
+
{ filter: e.match || /\.(jsx|tsx|js|ts|mjs|mts)?$/ },
|
|
53
|
+
(r) => B(this, null, function* () {
|
|
54
|
+
const o = r.path;
|
|
55
|
+
let i = yield f.promises.readFile(o, "utf8"), a = c.get(o);
|
|
56
|
+
if (!a || a.originCode !== i) {
|
|
57
|
+
let u = yield L(
|
|
58
|
+
e,
|
|
59
|
+
o,
|
|
60
|
+
i,
|
|
61
|
+
n
|
|
62
|
+
), p = "";
|
|
63
|
+
if (S(o) ? p = "jsx" : o.endsWith(".svelte") && (p = "svelte"), p)
|
|
64
|
+
u = D({
|
|
65
|
+
content: u,
|
|
66
|
+
filePath: o,
|
|
67
|
+
fileType: p,
|
|
68
|
+
escapeTags: s
|
|
69
|
+
});
|
|
70
|
+
else if (o.endsWith(".vue")) {
|
|
71
|
+
p = "vue";
|
|
72
|
+
const { descriptor: y } = A(u, {
|
|
73
|
+
sourceMap: !1
|
|
74
|
+
}), $ = D({
|
|
75
|
+
content: y.template.content,
|
|
76
|
+
filePath: o,
|
|
77
|
+
fileType: p,
|
|
78
|
+
escapeTags: s
|
|
79
|
+
});
|
|
80
|
+
u = u.replace(y.template.content, $);
|
|
81
|
+
}
|
|
82
|
+
const I = v.extname(o).replace(".", "");
|
|
83
|
+
a = { originCode: i, output: { contents: u, loader: I } }, c.set(o, a);
|
|
84
|
+
}
|
|
85
|
+
return a.output;
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function J(e) {
|
|
20
92
|
if (e.__esModule)
|
|
21
93
|
return e;
|
|
22
94
|
var t = e.default;
|
|
23
95
|
if (typeof t == "function") {
|
|
24
|
-
var n = function
|
|
25
|
-
if (this instanceof
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
var r = Function.bind.apply(t,
|
|
96
|
+
var n = function s() {
|
|
97
|
+
if (this instanceof s) {
|
|
98
|
+
var c = [null];
|
|
99
|
+
c.push.apply(c, arguments);
|
|
100
|
+
var r = Function.bind.apply(t, c);
|
|
29
101
|
return new r();
|
|
30
102
|
}
|
|
31
103
|
return t.apply(this, arguments);
|
|
@@ -33,28 +105,28 @@ function K(e) {
|
|
|
33
105
|
n.prototype = t.prototype;
|
|
34
106
|
} else
|
|
35
107
|
n = {};
|
|
36
|
-
return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(e).forEach(function(
|
|
37
|
-
var
|
|
38
|
-
Object.defineProperty(n,
|
|
108
|
+
return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(e).forEach(function(s) {
|
|
109
|
+
var c = Object.getOwnPropertyDescriptor(e, s);
|
|
110
|
+
Object.defineProperty(n, s, c.get ? c : {
|
|
39
111
|
enumerable: !0,
|
|
40
112
|
get: function() {
|
|
41
|
-
return e[
|
|
113
|
+
return e[s];
|
|
42
114
|
}
|
|
43
115
|
});
|
|
44
116
|
}), n;
|
|
45
117
|
}
|
|
46
|
-
var
|
|
118
|
+
var d = {}, G = {
|
|
47
119
|
get exports() {
|
|
48
|
-
return
|
|
120
|
+
return d;
|
|
49
121
|
},
|
|
50
122
|
set exports(e) {
|
|
51
|
-
|
|
123
|
+
d = e;
|
|
52
124
|
}
|
|
53
125
|
};
|
|
54
|
-
const
|
|
126
|
+
const Q = {}, z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
55
127
|
__proto__: null,
|
|
56
|
-
default:
|
|
57
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
128
|
+
default: Q
|
|
129
|
+
}, Symbol.toStringTag, { value: "Module" })), O = /* @__PURE__ */ J(z), H = "dotenv", X = "16.3.1", Z = "Loads environment variables from .env file", ee = "lib/main.js", te = "lib/main.d.ts", ne = {
|
|
58
130
|
".": {
|
|
59
131
|
types: "./lib/main.d.ts",
|
|
60
132
|
require: "./lib/main.js",
|
|
@@ -67,7 +139,7 @@ const L = {}, S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
|
|
|
67
139
|
"./lib/cli-options": "./lib/cli-options.js",
|
|
68
140
|
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
69
141
|
"./package.json": "./package.json"
|
|
70
|
-
},
|
|
142
|
+
}, re = {
|
|
71
143
|
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
72
144
|
lint: "standard",
|
|
73
145
|
"lint-readme": "standard-markdown",
|
|
@@ -75,10 +147,10 @@ const L = {}, S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
|
|
|
75
147
|
test: "tap tests/*.js --100 -Rspec",
|
|
76
148
|
prerelease: "npm test",
|
|
77
149
|
release: "standard-version"
|
|
78
|
-
},
|
|
150
|
+
}, oe = {
|
|
79
151
|
type: "git",
|
|
80
152
|
url: "git://github.com/motdotla/dotenv.git"
|
|
81
|
-
},
|
|
153
|
+
}, se = "https://github.com/motdotla/dotenv?sponsor=1", ce = [
|
|
82
154
|
"dotenv",
|
|
83
155
|
"env",
|
|
84
156
|
".env",
|
|
@@ -86,7 +158,7 @@ const L = {}, S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
|
|
|
86
158
|
"variables",
|
|
87
159
|
"config",
|
|
88
160
|
"settings"
|
|
89
|
-
],
|
|
161
|
+
], ie = "README.md", ae = "BSD-2-Clause", le = {
|
|
90
162
|
"@definitelytyped/dtslint": "^0.0.133",
|
|
91
163
|
"@types/node": "^18.11.3",
|
|
92
164
|
decache: "^4.6.1",
|
|
@@ -97,165 +169,165 @@ const L = {}, S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
|
|
|
97
169
|
tap: "^16.3.0",
|
|
98
170
|
tar: "^6.1.11",
|
|
99
171
|
typescript: "^4.8.4"
|
|
100
|
-
},
|
|
172
|
+
}, ue = {
|
|
101
173
|
node: ">=12"
|
|
102
|
-
},
|
|
174
|
+
}, pe = {
|
|
103
175
|
fs: !1
|
|
104
|
-
},
|
|
105
|
-
name:
|
|
106
|
-
version:
|
|
107
|
-
description:
|
|
108
|
-
main:
|
|
109
|
-
types:
|
|
110
|
-
exports:
|
|
111
|
-
scripts:
|
|
112
|
-
repository:
|
|
113
|
-
funding:
|
|
114
|
-
keywords:
|
|
115
|
-
readmeFilename:
|
|
116
|
-
license:
|
|
117
|
-
devDependencies:
|
|
118
|
-
engines:
|
|
119
|
-
browser:
|
|
120
|
-
},
|
|
121
|
-
function
|
|
176
|
+
}, de = {
|
|
177
|
+
name: H,
|
|
178
|
+
version: X,
|
|
179
|
+
description: Z,
|
|
180
|
+
main: ee,
|
|
181
|
+
types: te,
|
|
182
|
+
exports: ne,
|
|
183
|
+
scripts: re,
|
|
184
|
+
repository: oe,
|
|
185
|
+
funding: se,
|
|
186
|
+
keywords: ce,
|
|
187
|
+
readmeFilename: ie,
|
|
188
|
+
license: ae,
|
|
189
|
+
devDependencies: le,
|
|
190
|
+
engines: ue,
|
|
191
|
+
browser: pe
|
|
192
|
+
}, T = f, m = v, fe = O, ve = O, ge = de, h = ge.version, me = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
193
|
+
function he(e) {
|
|
122
194
|
const t = {};
|
|
123
195
|
let n = e.toString();
|
|
124
196
|
n = n.replace(/\r\n?/mg, "\n");
|
|
125
|
-
let
|
|
126
|
-
for (; (
|
|
127
|
-
const
|
|
128
|
-
let r =
|
|
197
|
+
let s;
|
|
198
|
+
for (; (s = me.exec(n)) != null; ) {
|
|
199
|
+
const c = s[1];
|
|
200
|
+
let r = s[2] || "";
|
|
129
201
|
r = r.trim();
|
|
130
|
-
const
|
|
131
|
-
r = r.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"),
|
|
202
|
+
const o = r[0];
|
|
203
|
+
r = r.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"), o === '"' && (r = r.replace(/\\n/g, "\n"), r = r.replace(/\\r/g, "\r")), t[c] = r;
|
|
132
204
|
}
|
|
133
205
|
return t;
|
|
134
206
|
}
|
|
135
|
-
function
|
|
136
|
-
const t =
|
|
207
|
+
function ye(e) {
|
|
208
|
+
const t = j(e), n = l.configDotenv({ path: t });
|
|
137
209
|
if (!n.parsed)
|
|
138
210
|
throw new Error("MISSING_DATA: Cannot parse ".concat(t, " for an unknown reason"));
|
|
139
|
-
const
|
|
211
|
+
const s = N(e).split(","), c = s.length;
|
|
140
212
|
let r;
|
|
141
|
-
for (let
|
|
213
|
+
for (let o = 0; o < c; o++)
|
|
142
214
|
try {
|
|
143
|
-
const
|
|
144
|
-
r =
|
|
215
|
+
const i = s[o].trim(), a = be(n, i);
|
|
216
|
+
r = l.decrypt(a.ciphertext, a.key);
|
|
145
217
|
break;
|
|
146
|
-
} catch (
|
|
147
|
-
if (
|
|
148
|
-
throw
|
|
218
|
+
} catch (i) {
|
|
219
|
+
if (o + 1 >= c)
|
|
220
|
+
throw i;
|
|
149
221
|
}
|
|
150
|
-
return
|
|
222
|
+
return l.parse(r);
|
|
151
223
|
}
|
|
152
|
-
function
|
|
153
|
-
console.log("[dotenv@".concat(
|
|
224
|
+
function Ee(e) {
|
|
225
|
+
console.log("[dotenv@".concat(h, "][INFO] ").concat(e));
|
|
154
226
|
}
|
|
155
|
-
function
|
|
156
|
-
console.log("[dotenv@".concat(
|
|
227
|
+
function _e(e) {
|
|
228
|
+
console.log("[dotenv@".concat(h, "][WARN] ").concat(e));
|
|
157
229
|
}
|
|
158
|
-
function
|
|
159
|
-
console.log("[dotenv@".concat(
|
|
230
|
+
function g(e) {
|
|
231
|
+
console.log("[dotenv@".concat(h, "][DEBUG] ").concat(e));
|
|
160
232
|
}
|
|
161
|
-
function
|
|
233
|
+
function N(e) {
|
|
162
234
|
return e && e.DOTENV_KEY && e.DOTENV_KEY.length > 0 ? e.DOTENV_KEY : process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0 ? process.env.DOTENV_KEY : "";
|
|
163
235
|
}
|
|
164
|
-
function
|
|
236
|
+
function be(e, t) {
|
|
165
237
|
let n;
|
|
166
238
|
try {
|
|
167
239
|
n = new URL(t);
|
|
168
|
-
} catch (
|
|
169
|
-
throw
|
|
240
|
+
} catch (i) {
|
|
241
|
+
throw i.code === "ERR_INVALID_URL" ? new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development") : i;
|
|
170
242
|
}
|
|
171
|
-
const
|
|
172
|
-
if (!o)
|
|
173
|
-
throw new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
174
|
-
const s = n.searchParams.get("environment");
|
|
243
|
+
const s = n.password;
|
|
175
244
|
if (!s)
|
|
176
|
-
throw new Error("INVALID_DOTENV_KEY: Missing
|
|
177
|
-
const
|
|
245
|
+
throw new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
246
|
+
const c = n.searchParams.get("environment");
|
|
178
247
|
if (!c)
|
|
248
|
+
throw new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
249
|
+
const r = "DOTENV_VAULT_".concat(c.toUpperCase()), o = e.parsed[r];
|
|
250
|
+
if (!o)
|
|
179
251
|
throw new Error("NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ".concat(r, " in your .env.vault file."));
|
|
180
|
-
return { ciphertext:
|
|
252
|
+
return { ciphertext: o, key: s };
|
|
181
253
|
}
|
|
182
|
-
function
|
|
183
|
-
let t =
|
|
254
|
+
function j(e) {
|
|
255
|
+
let t = m.resolve(process.cwd(), ".env");
|
|
184
256
|
return e && e.path && e.path.length > 0 && (t = e.path), t.endsWith(".vault") ? t : "".concat(t, ".vault");
|
|
185
257
|
}
|
|
186
|
-
function
|
|
187
|
-
return e[0] === "~" ?
|
|
258
|
+
function we(e) {
|
|
259
|
+
return e[0] === "~" ? m.join(fe.homedir(), e.slice(1)) : e;
|
|
188
260
|
}
|
|
189
|
-
function
|
|
190
|
-
|
|
191
|
-
const t =
|
|
261
|
+
function De(e) {
|
|
262
|
+
Ee("Loading env from encrypted .env.vault");
|
|
263
|
+
const t = l._parseVault(e);
|
|
192
264
|
let n = process.env;
|
|
193
|
-
return e && e.processEnv != null && (n = e.processEnv),
|
|
265
|
+
return e && e.processEnv != null && (n = e.processEnv), l.populate(n, t, e), { parsed: t };
|
|
194
266
|
}
|
|
195
|
-
function
|
|
196
|
-
let t =
|
|
197
|
-
const
|
|
198
|
-
e && (e.path != null && (t =
|
|
267
|
+
function Oe(e) {
|
|
268
|
+
let t = m.resolve(process.cwd(), ".env"), n = "utf8";
|
|
269
|
+
const s = !!(e && e.debug);
|
|
270
|
+
e && (e.path != null && (t = we(e.path)), e.encoding != null && (n = e.encoding));
|
|
199
271
|
try {
|
|
200
|
-
const
|
|
272
|
+
const c = l.parse(T.readFileSync(t, { encoding: n }));
|
|
201
273
|
let r = process.env;
|
|
202
|
-
return e && e.processEnv != null && (r = e.processEnv),
|
|
203
|
-
} catch (
|
|
204
|
-
return
|
|
274
|
+
return e && e.processEnv != null && (r = e.processEnv), l.populate(r, c, e), { parsed: c };
|
|
275
|
+
} catch (c) {
|
|
276
|
+
return s && g("Failed to load ".concat(t, " ").concat(c.message)), { error: c };
|
|
205
277
|
}
|
|
206
278
|
}
|
|
207
|
-
function
|
|
208
|
-
const t =
|
|
209
|
-
return
|
|
279
|
+
function Te(e) {
|
|
280
|
+
const t = j(e);
|
|
281
|
+
return N(e).length === 0 ? l.configDotenv(e) : T.existsSync(t) ? l._configVault(e) : (_e("You set DOTENV_KEY but you are missing a .env.vault file at ".concat(t, ". Did you forget to build it?")), l.configDotenv(e));
|
|
210
282
|
}
|
|
211
|
-
function
|
|
283
|
+
function Ne(e, t) {
|
|
212
284
|
const n = Buffer.from(t.slice(-64), "hex");
|
|
213
|
-
let
|
|
214
|
-
const
|
|
215
|
-
|
|
285
|
+
let s = Buffer.from(e, "base64");
|
|
286
|
+
const c = s.slice(0, 12), r = s.slice(-16);
|
|
287
|
+
s = s.slice(12, -16);
|
|
216
288
|
try {
|
|
217
|
-
const
|
|
218
|
-
return
|
|
219
|
-
} catch (
|
|
220
|
-
const
|
|
221
|
-
if (
|
|
222
|
-
const
|
|
223
|
-
throw new Error(
|
|
224
|
-
} else if (
|
|
225
|
-
const
|
|
226
|
-
throw new Error(
|
|
289
|
+
const o = ve.createDecipheriv("aes-256-gcm", n, c);
|
|
290
|
+
return o.setAuthTag(r), "".concat(o.update(s)).concat(o.final());
|
|
291
|
+
} catch (o) {
|
|
292
|
+
const i = o instanceof RangeError, a = o.message === "Invalid key length", u = o.message === "Unsupported state or unable to authenticate data";
|
|
293
|
+
if (i || a) {
|
|
294
|
+
const p = "INVALID_DOTENV_KEY: It must be 64 characters long (or more)";
|
|
295
|
+
throw new Error(p);
|
|
296
|
+
} else if (u) {
|
|
297
|
+
const p = "DECRYPTION_FAILED: Please check your DOTENV_KEY";
|
|
298
|
+
throw new Error(p);
|
|
227
299
|
} else
|
|
228
|
-
throw console.error("Error: ",
|
|
300
|
+
throw console.error("Error: ", o.code), console.error("Error: ", o.message), o;
|
|
229
301
|
}
|
|
230
302
|
}
|
|
231
|
-
function
|
|
232
|
-
const
|
|
303
|
+
function je(e, t, n = {}) {
|
|
304
|
+
const s = !!(n && n.debug), c = !!(n && n.override);
|
|
233
305
|
if (typeof t != "object")
|
|
234
306
|
throw new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
235
307
|
for (const r of Object.keys(t))
|
|
236
|
-
Object.prototype.hasOwnProperty.call(e, r) ? (
|
|
308
|
+
Object.prototype.hasOwnProperty.call(e, r) ? (c === !0 && (e[r] = t[r]), s && g(c === !0 ? '"'.concat(r, '" is already defined and WAS overwritten') : '"'.concat(r, '" is already defined and was NOT overwritten'))) : e[r] = t[r];
|
|
237
309
|
}
|
|
238
|
-
const
|
|
239
|
-
configDotenv:
|
|
240
|
-
_configVault:
|
|
241
|
-
_parseVault:
|
|
242
|
-
config:
|
|
243
|
-
decrypt:
|
|
244
|
-
parse:
|
|
245
|
-
populate:
|
|
310
|
+
const l = {
|
|
311
|
+
configDotenv: Oe,
|
|
312
|
+
_configVault: De,
|
|
313
|
+
_parseVault: ye,
|
|
314
|
+
config: Te,
|
|
315
|
+
decrypt: Ne,
|
|
316
|
+
parse: he,
|
|
317
|
+
populate: je
|
|
246
318
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
function
|
|
319
|
+
d.configDotenv = l.configDotenv;
|
|
320
|
+
d._configVault = l._configVault;
|
|
321
|
+
d._parseVault = l._parseVault;
|
|
322
|
+
d.config = l.config;
|
|
323
|
+
d.decrypt = l.decrypt;
|
|
324
|
+
d.parse = l.parse;
|
|
325
|
+
d.populate = l.populate;
|
|
326
|
+
G.exports = l;
|
|
327
|
+
function Ie(e) {
|
|
256
328
|
if (!(e != null && e.bundler)) {
|
|
257
329
|
console.log(
|
|
258
|
-
|
|
330
|
+
M.red(
|
|
259
331
|
"Please specify the bundler in the options of code-inspector-plugin."
|
|
260
332
|
)
|
|
261
333
|
);
|
|
@@ -266,22 +338,22 @@ function he(e) {
|
|
|
266
338
|
if (t = !0, process.env.CODE_INSPECTOR === "true")
|
|
267
339
|
t = !1;
|
|
268
340
|
else {
|
|
269
|
-
const r =
|
|
270
|
-
if (
|
|
271
|
-
const
|
|
272
|
-
(
|
|
341
|
+
const r = v.resolve(process.cwd(), ".env.local");
|
|
342
|
+
if (f.existsSync(r)) {
|
|
343
|
+
const o = f.readFileSync(r, "utf-8"), i = d.parse(o || "");
|
|
344
|
+
(i == null ? void 0 : i.CODE_INSPECTOR) === "true" && (t = !1);
|
|
273
345
|
}
|
|
274
346
|
}
|
|
275
347
|
let n = "";
|
|
276
|
-
typeof __dirname != "undefined" ? n = __dirname : n =
|
|
277
|
-
const
|
|
348
|
+
typeof __dirname != "undefined" ? n = __dirname : n = Y(F(import.meta.url));
|
|
349
|
+
const s = w(b({}, e), {
|
|
278
350
|
close: t,
|
|
279
|
-
output:
|
|
351
|
+
output: v.resolve(n, "./")
|
|
280
352
|
});
|
|
281
|
-
return e.bundler === "webpack" || e.bundler === "rspack" ? new
|
|
353
|
+
return e.bundler === "webpack" || e.bundler === "rspack" ? new K(s) : e.bundler === "esbuild" ? q(s) : R(s);
|
|
282
354
|
}
|
|
283
|
-
const
|
|
355
|
+
const Ke = Ie;
|
|
284
356
|
export {
|
|
285
|
-
|
|
286
|
-
|
|
357
|
+
Ie as CodeInspectorPlugin,
|
|
358
|
+
Ke as codeInspectorPlugin
|
|
287
359
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-inspector-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"chalk": "4.1.1",
|
|
50
|
-
"code-inspector-core": "0.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
50
|
+
"code-inspector-core": "0.15.0",
|
|
51
|
+
"vite-code-inspector-plugin": "0.15.0",
|
|
52
|
+
"webpack-code-inspector-plugin": "0.15.0",
|
|
53
|
+
"esbuild-code-inspector-plugin": "0.15.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@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';
|
|
7
|
+
bundler: 'vite' | 'webpack' | 'rspack' | 'esbuild';
|
|
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
|