@code-inspector/vite 1.1.1-beta.1 → 1.2.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/dist/index.js +1 -1
- package/dist/index.mjs +120 -59
- package/package.json +3 -2
- package/types/index.d.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.defineProperty,w=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var y=(e,n,i)=>n in e?j(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,f=(e,n)=>{for(var i in n||(n={}))W.call(n,i)&&y(e,i,n[i]);if(h)for(var i of h(n))q.call(n,i)&&y(e,i,n[i]);return e},m=(e,n)=>w(e,P(n));var v=(e,n,i)=>new Promise((t,a)=>{var g=c=>{try{u(i.next(c))}catch(r){a(r)}},p=c=>{try{u(i.throw(c))}catch(r){a(r)}},u=c=>c.done?t(c.value):Promise.resolve(c.value).then(g,p);u((i=i.apply(e,n)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@code-inspector/core"),d=require("chalk"),k="@code-inspector/vite",C=[{name:"vite:react-babel",package:"@vitejs/plugin-react"},{name:"vite:react-swc",package:"@vitejs/plugin-react-swc"},{name:"vite:react-oxc:config",package:"@vitejs/plugin-react-oxc"},{name:"solid",package:"vite-plugin-solid"},{name:"vite-plugin-qwik",package:"qwikVite"},{name:"vite-plugin-qwik-city",package:"qwikCity"},{name:"vite-plugin-qwik-react",package:"qwikReact"},{name:"vite:preact-jsx",package:"@preact/preset-vite"},{name:"vite-plugin-svelte",package:"@sveltejs/vite-plugin-svelte"}],I=["isJsx","isTsx","lang.jsx","lang.tsx"];function b(e=[]){const n=e.findIndex(i=>i.name===k);C.forEach(i=>{const t=e.findIndex(a=>a.name===i.name);if(t!==-1&&t<n){const a=[d.yellow("[WARNING]"),"You need to put",d.green("code-inspector-plugin"),"before",d.green(i.package),"in the vite config file."];console.log(a.join(" "))}})}function T(e){const n={port:0,entry:"",output:e.output,envDir:""};return m(f({name:k},e.enforcePre===!1?{}:{enforce:"pre"}),{apply(t,{command:a}){return!e.close&&l.isDev(e.dev,a==="serve")},configResolved(t){n.envDir=t.envDir||t.root},transform(t,a){return v(this,null,function*(){if(l.isExcludedFile(a,e))return t;t=yield l.getCodeWithWebComponent({options:e,file:a,code:t,record:n});const{escapeTags:g=[],mappings:p}=e,[u,c]=a.split("?",2);let r=l.normalizePath(u);r=l.getMappingFilePath(r,p);const s=new URLSearchParams(c);if(e.match&&!e.match.test(r))return t;let o="";return l.isJsTypeFile(r)||r.endsWith(".vue")&&(I.some(x=>s.get(x)!==null)||s.get("lang")==="tsx"||s.get("lang")==="jsx")?o="jsx":r.endsWith(".html")&&s.get("type")==="template"&&s.has("vue")||r.endsWith(".vue")&&s.get("type")!=="style"&&s.get("raw")===null?o="vue":r.endsWith(".svelte")&&(o="svelte"),o?l.transformCode({content:t,filePath:r,fileType:o,escapeTags:g,pathType:e.pathType}):t})},transformIndexHtml(t){return v(this,null,function*(){const a=yield l.getCodeWithWebComponent({options:m(f({},e),{importClient:"code"}),file:"main.js",code:"",record:n,inject:!0});return t.replace("<head>",'<head><script type="module">\n'.concat(a,"\n<\/script>"))})},configureServer(t){const a=t.config.logger.info;t.config.logger.info=function(g,p){a.call(this,g,p),b(t.config.plugins),t.config.logger.info=a}}})}exports.ViteCodeInspectorPlugin=T;
|
package/dist/index.mjs
CHANGED
|
@@ -1,93 +1,154 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
1
|
+
var w = Object.defineProperty, j = Object.defineProperties;
|
|
2
|
+
var P = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var d = Object.getOwnPropertySymbols;
|
|
4
|
+
var W = Object.prototype.hasOwnProperty, q = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var h = (e, n, i) => n in e ? w(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i, u = (e, n) => {
|
|
6
|
+
for (var i in n || (n = {}))
|
|
7
|
+
W.call(n, i) && h(e, i, n[i]);
|
|
8
|
+
if (d)
|
|
9
|
+
for (var i of d(n))
|
|
10
|
+
q.call(n, i) && h(e, i, n[i]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
12
|
+
}, f = (e, n) => j(e, P(n));
|
|
13
|
+
var m = (e, n, i) => new Promise((t, a) => {
|
|
14
|
+
var g = (c) => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
a(
|
|
16
|
+
p(i.next(c));
|
|
17
|
+
} catch (r) {
|
|
18
|
+
a(r);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, o = (c) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
a(
|
|
22
|
+
p(i.throw(c));
|
|
23
|
+
} catch (r) {
|
|
24
|
+
a(r);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
26
|
+
}, p = (c) => c.done ? t(c.value) : Promise.resolve(c.value).then(g, o);
|
|
27
|
+
p((i = i.apply(e, n)).next());
|
|
28
28
|
});
|
|
29
|
-
import { isDev as
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
import { isDev as I, isExcludedFile as C, getCodeWithWebComponent as x, normalizePath as T, getMappingFilePath as b, isJsTypeFile as D, transformCode as R } from "@code-inspector/core";
|
|
30
|
+
import v from "chalk";
|
|
31
|
+
const k = "@code-inspector/vite", F = [
|
|
32
|
+
{
|
|
33
|
+
name: "vite:react-babel",
|
|
34
|
+
package: "@vitejs/plugin-react"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "vite:react-swc",
|
|
38
|
+
package: "@vitejs/plugin-react-swc"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "vite:react-oxc:config",
|
|
42
|
+
package: "@vitejs/plugin-react-oxc"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "solid",
|
|
46
|
+
package: "vite-plugin-solid"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "vite-plugin-qwik",
|
|
50
|
+
package: "qwikVite"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "vite-plugin-qwik-city",
|
|
54
|
+
package: "qwikCity"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "vite-plugin-qwik-react",
|
|
58
|
+
package: "qwikReact"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "vite:preact-jsx",
|
|
62
|
+
package: "@preact/preset-vite"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "vite-plugin-svelte",
|
|
66
|
+
package: "@sveltejs/vite-plugin-svelte"
|
|
67
|
+
}
|
|
68
|
+
], L = ["isJsx", "isTsx", "lang.jsx", "lang.tsx"];
|
|
69
|
+
function N(e = []) {
|
|
70
|
+
const n = e.findIndex((i) => i.name === k);
|
|
71
|
+
F.forEach((i) => {
|
|
72
|
+
const t = e.findIndex((a) => a.name === i.name);
|
|
73
|
+
if (t !== -1 && t < n) {
|
|
74
|
+
const a = [
|
|
75
|
+
v.yellow("[WARNING]"),
|
|
76
|
+
"You need to put",
|
|
77
|
+
v.green("code-inspector-plugin"),
|
|
78
|
+
"before",
|
|
79
|
+
v.green(i.package),
|
|
80
|
+
"in the vite config file."
|
|
81
|
+
];
|
|
82
|
+
console.log(a.join(" "));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function O(e) {
|
|
87
|
+
const n = {
|
|
33
88
|
port: 0,
|
|
34
89
|
entry: "",
|
|
35
90
|
output: e.output,
|
|
36
91
|
envDir: ""
|
|
37
92
|
};
|
|
38
|
-
return
|
|
39
|
-
name:
|
|
93
|
+
return f(u({
|
|
94
|
+
name: k
|
|
40
95
|
}, e.enforcePre === !1 ? {} : { enforce: "pre" }), {
|
|
41
|
-
apply(
|
|
42
|
-
return !e.close &&
|
|
96
|
+
apply(t, { command: a }) {
|
|
97
|
+
return !e.close && I(e.dev, a === "serve");
|
|
43
98
|
},
|
|
44
|
-
configResolved(
|
|
45
|
-
|
|
99
|
+
configResolved(t) {
|
|
100
|
+
n.envDir = t.envDir || t.root;
|
|
46
101
|
},
|
|
47
|
-
transform(
|
|
48
|
-
return
|
|
49
|
-
if (
|
|
50
|
-
return
|
|
51
|
-
|
|
102
|
+
transform(t, a) {
|
|
103
|
+
return m(this, null, function* () {
|
|
104
|
+
if (C(a, e))
|
|
105
|
+
return t;
|
|
106
|
+
t = yield x({
|
|
52
107
|
options: e,
|
|
53
108
|
file: a,
|
|
54
|
-
code:
|
|
55
|
-
record:
|
|
109
|
+
code: t,
|
|
110
|
+
record: n
|
|
56
111
|
});
|
|
57
|
-
const { escapeTags:
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (e.match && !e.match.test(
|
|
62
|
-
return
|
|
63
|
-
let
|
|
64
|
-
return
|
|
65
|
-
content:
|
|
66
|
-
filePath:
|
|
67
|
-
fileType:
|
|
68
|
-
escapeTags:
|
|
112
|
+
const { escapeTags: g = [], mappings: o } = e, [p, c] = a.split("?", 2);
|
|
113
|
+
let r = T(p);
|
|
114
|
+
r = b(r, o);
|
|
115
|
+
const l = new URLSearchParams(c);
|
|
116
|
+
if (e.match && !e.match.test(r))
|
|
117
|
+
return t;
|
|
118
|
+
let s = "";
|
|
119
|
+
return D(r) || r.endsWith(".vue") && (L.some((y) => l.get(y) !== null) || l.get("lang") === "tsx" || l.get("lang") === "jsx") ? s = "jsx" : r.endsWith(".html") && l.get("type") === "template" && l.has("vue") || r.endsWith(".vue") && l.get("type") !== "style" && l.get("raw") === null ? s = "vue" : r.endsWith(".svelte") && (s = "svelte"), s ? R({
|
|
120
|
+
content: t,
|
|
121
|
+
filePath: r,
|
|
122
|
+
fileType: s,
|
|
123
|
+
escapeTags: g,
|
|
69
124
|
pathType: e.pathType
|
|
70
|
-
}) :
|
|
125
|
+
}) : t;
|
|
71
126
|
});
|
|
72
127
|
},
|
|
73
128
|
// 追加到 html 中,适配 MPA 项目
|
|
74
|
-
transformIndexHtml(
|
|
75
|
-
return
|
|
76
|
-
const a = yield
|
|
77
|
-
options:
|
|
129
|
+
transformIndexHtml(t) {
|
|
130
|
+
return m(this, null, function* () {
|
|
131
|
+
const a = yield x({
|
|
132
|
+
options: f(u({}, e), { importClient: "code" }),
|
|
78
133
|
file: "main.js",
|
|
79
134
|
code: "",
|
|
80
|
-
record:
|
|
135
|
+
record: n,
|
|
81
136
|
inject: !0
|
|
82
137
|
});
|
|
83
|
-
return
|
|
138
|
+
return t.replace(
|
|
84
139
|
"<head>",
|
|
85
140
|
'<head><script type="module">\n'.concat(a, "\n<\/script>")
|
|
86
141
|
);
|
|
87
142
|
});
|
|
143
|
+
},
|
|
144
|
+
configureServer(t) {
|
|
145
|
+
const a = t.config.logger.info;
|
|
146
|
+
t.config.logger.info = function(g, o) {
|
|
147
|
+
a.call(this, g, o), N(t.config.plugins), t.config.logger.info = a;
|
|
148
|
+
};
|
|
88
149
|
}
|
|
89
150
|
});
|
|
90
151
|
}
|
|
91
152
|
export {
|
|
92
|
-
|
|
153
|
+
O as ViteCodeInspectorPlugin
|
|
93
154
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-inspector/vite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"url": "https://github.com/zh-lx/code-inspector/issues"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
41
|
+
"chalk": "4.1.1",
|
|
42
|
+
"@code-inspector/core": "1.2.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/node": "^16.0.1",
|
package/types/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function ViteCodeInspectorPlugin(options: Options): {
|
|
|
10
10
|
configResolved(config: any): void;
|
|
11
11
|
transform(code: string, id: string): Promise<string>;
|
|
12
12
|
transformIndexHtml(html: any): Promise<any>;
|
|
13
|
+
configureServer(server: any): void;
|
|
13
14
|
enforce?: "pre";
|
|
14
15
|
name: string;
|
|
15
16
|
};
|