@code-inspector/vite 1.1.1 → 1.2.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/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var P=Object.defineProperty,x=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var v=(e,t,r)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t)=>{for(var r in t||(t={}))W.call(t,r)&&v(e,r,t[r]);if(d)for(var r of d(t))j.call(t,r)&&v(e,r,t[r]);return e},f=(e,t)=>x(e,C(t));var h=(e,t,r)=>new Promise((n,a)=>{var p=l=>{try{o(r.next(l))}catch(s){a(s)}},m=l=>{try{o(r.throw(l))}catch(s){a(s)}},o=l=>l.done?n(l.value):Promise.resolve(l.value).then(p,m);o((r=r.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@code-inspector/core"),T="@code-inspector/vite",b=["isJsx","isTsx","lang.jsx","lang.tsx"];function w(e){const t={port:0,entry:"",output:e.output,envDir:""};return f(g({name:T},e.enforcePre===!1?{}:{enforce:"pre"}),{apply(n,{command:a}){return!e.close&&i.isDev(e.dev,a==="serve")},configResolved(n){t.envDir=n.envDir||n.root},transform(n,a){return h(this,null,function*(){if(i.isExcludedFile(a,e))return n;n=yield i.getCodeWithWebComponent({options:e,file:a,code:n,record:t});const{escapeTags:p=[],mappings:m}=e,[o,l]=a.split("?",2);let s=i.normalizePath(o);s=i.getMappingFilePath(s,m);const c=new URLSearchParams(l);if(e.match&&!e.match.test(s))return n;let u="";return i.isJsTypeFile(s)||s.endsWith(".vue")&&(b.some(y=>c.get(y)!==null)||c.get("lang")==="tsx"||c.get("lang")==="jsx")?u="jsx":s.endsWith(".html")&&c.get("type")==="template"&&c.has("vue")||s.endsWith(".vue")&&c.get("type")!=="style"&&c.get("raw")===null?u="vue":s.endsWith(".svelte")&&(u="svelte"),u?i.transformCode({content:n,filePath:s,fileType:u,escapeTags:p,pathType:e.pathType}):n})},transformIndexHtml(n){return h(this,null,function*(){const a=yield i.getCodeWithWebComponent({options:f(g({},e),{importClient:"code"}),file:"main.js",code:"",record:t,inject:!0});return n.replace("<head>",'<head><script type="module">\n'.concat(a,"\n<\/script>"))})}})}exports.ViteCodeInspectorPlugin=w;
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 x = Object.defineProperty, P = Object.defineProperties;
2
- var j = Object.getOwnPropertyDescriptors;
3
- var g = Object.getOwnPropertySymbols;
4
- var T = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
5
- var v = (e, t, r) => t in e ? x(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, f = (e, t) => {
6
- for (var r in t || (t = {}))
7
- T.call(t, r) && v(e, r, t[r]);
8
- if (g)
9
- for (var r of g(t))
10
- W.call(t, r) && v(e, r, t[r]);
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
- }, h = (e, t) => P(e, j(t));
13
- var o = (e, t, r) => new Promise((s, a) => {
14
- var p = (l) => {
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
- u(r.next(l));
17
- } catch (n) {
18
- a(n);
16
+ p(i.next(c));
17
+ } catch (r) {
18
+ a(r);
19
19
  }
20
- }, m = (l) => {
20
+ }, o = (c) => {
21
21
  try {
22
- u(r.throw(l));
23
- } catch (n) {
24
- a(n);
22
+ p(i.throw(c));
23
+ } catch (r) {
24
+ a(r);
25
25
  }
26
- }, u = (l) => l.done ? s(l.value) : Promise.resolve(l.value).then(p, m);
27
- u((r = r.apply(e, t)).next());
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 C, isExcludedFile as w, getCodeWithWebComponent as d, normalizePath as D, getMappingFilePath as F, isJsTypeFile as I, transformCode as J } from "@code-inspector/core";
30
- const L = "@code-inspector/vite", R = ["isJsx", "isTsx", "lang.jsx", "lang.tsx"];
31
- function q(e) {
32
- const t = {
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 h(f({
39
- name: L
93
+ return f(u({
94
+ name: k
40
95
  }, e.enforcePre === !1 ? {} : { enforce: "pre" }), {
41
- apply(s, { command: a }) {
42
- return !e.close && C(e.dev, a === "serve");
96
+ apply(t, { command: a }) {
97
+ return !e.close && I(e.dev, a === "serve");
43
98
  },
44
- configResolved(s) {
45
- t.envDir = s.envDir || s.root;
99
+ configResolved(t) {
100
+ n.envDir = t.envDir || t.root;
46
101
  },
47
- transform(s, a) {
48
- return o(this, null, function* () {
49
- if (w(a, e))
50
- return s;
51
- s = yield d({
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: s,
55
- record: t
109
+ code: t,
110
+ record: n
56
111
  });
57
- const { escapeTags: p = [], mappings: m } = e, [u, l] = a.split("?", 2);
58
- let n = D(u);
59
- n = F(n, m);
60
- const i = new URLSearchParams(l);
61
- if (e.match && !e.match.test(n))
62
- return s;
63
- let c = "";
64
- return I(n) || n.endsWith(".vue") && (R.some((y) => i.get(y) !== null) || i.get("lang") === "tsx" || i.get("lang") === "jsx") ? c = "jsx" : n.endsWith(".html") && i.get("type") === "template" && i.has("vue") || n.endsWith(".vue") && i.get("type") !== "style" && i.get("raw") === null ? c = "vue" : n.endsWith(".svelte") && (c = "svelte"), c ? J({
65
- content: s,
66
- filePath: n,
67
- fileType: c,
68
- escapeTags: p,
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
- }) : s;
125
+ }) : t;
71
126
  });
72
127
  },
73
128
  // 追加到 html 中,适配 MPA 项目
74
- transformIndexHtml(s) {
75
- return o(this, null, function* () {
76
- const a = yield d({
77
- options: h(f({}, e), { importClient: "code" }),
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: t,
135
+ record: n,
81
136
  inject: !0
82
137
  });
83
- return s.replace(
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
- q as ViteCodeInspectorPlugin
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.1.1",
3
+ "version": "1.2.1",
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
- "@code-inspector/core": "1.1.1"
41
+ "chalk": "4.1.1",
42
+ "@code-inspector/core": "1.2.1"
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
  };