vite-userscript-plugin 1.9.1 → 1.10.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.cjs +4 -4
- package/dist/index.d.cts +187 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +4 -4
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}};var
|
|
3
|
-
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(
|
|
1
|
+
"use strict";var re=Object.create;var v=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var r in t)v(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ne(t))!ie.call(e,n)&&n!==r&&v(e,n,{get:()=>t[n],enumerable:!(s=se(t,n))||s.enumerable});return e};var j=(e,t,r)=>(r=e!=null?re(oe(e)):{},E(t||!e||!e.__esModule?v(r,"default",{value:e,enumerable:!0}):r,e)),le=e=>E(v({},"__esModule",{value:!0}),e);var ue={};ae(ue,{default:()=>K});module.exports=le(ue);var c=require("fs"),V=require("http"),p=require("path"),H=j(require("get-port"),1),W=j(require("open"),1),M=j(require("picocolors"),1),q=j(require("serve-handler"),1),z=require("vite"),B=require("websocket");var g=class{constructor(t){this.config=t;this.addHomepageMeta(),this.maxKeyLength=Math.max(...Object.keys(this.config).map(r=>r.length))+1}header=[];maxKeyLength;addHomepageMeta(){let t=this.config.homepage??this.config.homepageURL;t&&(this.config.updateURL=new URL(`${this.config.name}.meta.js`,t).href,this.config.downloadURL=new URL(`${this.config.name}.user.js`,t).href)}addSpaces(t){return" ".repeat(this.maxKeyLength-t.length)}addMetadata(t,r){r=Array.isArray(r)?r.join(" "):r===!0?"":r,this.header.push(`// @${t}${this.addSpaces(t)}${r}`)}generate(){for(let[t,r]of Object.entries(this.config))if(Array.isArray(r))r.forEach(s=>this.addMetadata(t,s));else{if(r===void 0)continue;this.addMetadata(t,r)}return["// ==UserScript==",...this.header,"// ==/UserScript=="].join(`
|
|
2
|
+
`)}};var _=require("path"),D=require("url"),me={},L=(0,_.dirname)((0,D.fileURLToPath)(me.url)),$="vite-userscript-plugin",R='console.warn("__STYLE__")',N=new RegExp(/\.(t|j)sx?$/),C=new RegExp(/\.(s[ac]|c|le)ss$/),ce=["setValue","getValue","deleteValue","listValues","setClipboard","addStyle","addElement","addValueChangeListener","removeValueChangeListener","registerMenuCommand","unregisterMenuCommand","download","getTab","getTabs","saveTab","openInTab","notification","getResourceURL","getResourceText","xmlhttpRequest","log","info"],pe=["unsafeWindow","window.onurlchange","window.focus","window.close"],h=ce.map(e=>[`GM_${e}`,`GM.${e}`]).flat();h.push(...pe);var k=require("vite");function O(e){return[...new Set(Array.isArray(e)?e:e?[e]:[])]}async function y({minify:e,file:t,name:r,loader:s},n){let{code:d}=await(0,k.transformWithEsbuild)(t,r,{minify:e,loader:s,sourcemap:!1,legalComments:"none",...n});return d}function A(e){let t=[];for(let r of h)e.indexOf(r)!==-1&&t.push(r);return t}var U=class{styles=new Map;async add(t,r,s){let n=await y({name:t,file:r,minify:s,loader:"css"});return this.styles.set(t,n.replace(`
|
|
3
|
+
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(t){let r=[];for(let s of t){let n=this.styles.get(s);n&&r.push([s,n])}this.styles.clear(),r.forEach(s=>this.styles.set(...s))}},S=new U;function K(e){try{let t,r,s=null,n=e.fileName??e.header.name,d=(0,z.createLogger)("info",{prefix:`[${$}]`,allowClearScreen:!0}),w=(0,V.createServer)((o,i)=>(0,q.default)(o,i,{public:t.build.outDir})),I=B.server;return new I({httpServer:w}).on("request",o=>{s=o.accept(null,o.origin)}),{name:$,apply:"build",config(){return{build:{target:"esnext",minify:!1,lib:{name:n,entry:e.entry,formats:["iife"],fileName:()=>`${n}.js`},rollupOptions:{output:{extend:!0}}}}},async configResolved(o){t=o,r=o.build.watch??!1,e.entry=(0,p.resolve)(o.root,e.entry),Array.from(["match","require","include","exclude","resource","connect"]).forEach(i=>{let a=e.header[i];e.header[i]=O(a)}),e.server={port:await(0,H.default)(),open:!1,...e.server}},async transform(o,i){let a=o;return C.test(i)&&(a=await S.add(i,a,!r)),i.includes(e.entry)&&(a=o+R),{code:a,map:null}},generateBundle(o,i){for(let a of Object.values(i)){if(a.type==="asset")continue;let m=Object.keys(a.modules).filter(u=>C.test(u));m.length&&S.merge(m)}},async writeBundle(o,i){let{open:a,port:m}=e.server,u=o.sanitizeFileName(n),J=`${u}.user.js`,G=`${u}.proxy.user.js`,Y=`${u}.meta.js`;for(let[f]of Object.entries(i))if(N.test(f)){let x=t.root,b=t.build.outDir,P=(0,p.resolve)(x,b,f),Q=(0,p.resolve)(x,b,J),X=(0,p.resolve)(x,b,G),Z=(0,p.resolve)(x,b,Y),T=(0,p.resolve)(L,`ws-${u}.js`);try{let l=(0,c.readFileSync)(P,"utf8");if(l=l.replace(R,`${S.inject()}`),l=await y({minify:!r,file:l,name:f,loader:"js"},e.esbuildTransformOptions),e.header.grant=O(r?h:[...A(l),...e.header.grant??[]]),r){let ee=(0,c.readFileSync)((0,p.resolve)(L,"ws.js"),"utf8"),te=await y({minify:!r,file:ee.replace("__WS__",`ws://localhost:${m}`),name:T,loader:"js"},e.esbuildTransformOptions);(0,c.writeFileSync)(T,te),(0,c.writeFileSync)(X,new g({...e.header,require:[...e.header.require??[],"file://"+T,"file://"+P]}).generate())}let F=new g(e.header).generate();(0,c.writeFileSync)(P,l),(0,c.writeFileSync)(Z,F),(0,c.writeFileSync)(Q,`${F}
|
|
4
4
|
|
|
5
|
-
${l}`)}catch(l){console.log(l)}}if(
|
|
5
|
+
${l}`)}catch(l){console.log(l)}}if(r&&!w.listening){let f=`http://localhost:${m}`;w.listen(m,()=>{d.clearScreen("info"),d.info(M.default.bold(`${M.default.cyan(">>> [vite-userscript-plugin]")} ${M.default.gray(f)}`))}),a&&await(0,W.default)(`${f}/${G}`)}else r||(w.close(),process.exit(0))},buildEnd(){r&&(d.clearScreen("info"),s&&s.sendUTF(JSON.stringify({message:"reload"})))}}}catch(t){return console.error(t),{name:$}}}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { EsbuildTransformOptions, PluginOption } from 'vite';
|
|
2
|
+
|
|
3
|
+
declare const GM: readonly ["setValue", "getValue", "deleteValue", "listValues", "setClipboard", "addStyle", "addElement", "addValueChangeListener", "removeValueChangeListener", "registerMenuCommand", "unregisterMenuCommand", "download", "getTab", "getTabs", "saveTab", "openInTab", "notification", "getResourceURL", "getResourceText", "xmlhttpRequest", "log", "info"];
|
|
4
|
+
declare const GMwindow: readonly ["unsafeWindow", "window.onurlchange", "window.focus", "window.close"];
|
|
5
|
+
|
|
6
|
+
type RunAt = 'document-start' | 'document-body' | 'document-end' | 'document-idle' | 'context-menu';
|
|
7
|
+
type GMLiterals<T extends string> = [`GM_${T}` | `GM.${T}`];
|
|
8
|
+
type GMWindow = typeof GMwindow[number];
|
|
9
|
+
type Grants = GMWindow | GMLiterals<typeof GM[number]>[number];
|
|
10
|
+
type HeaderConfig = {
|
|
11
|
+
[property: string]: any;
|
|
12
|
+
/**
|
|
13
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:name
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:namespace
|
|
18
|
+
*/
|
|
19
|
+
namespace?: string;
|
|
20
|
+
/**
|
|
21
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:copyright
|
|
22
|
+
*/
|
|
23
|
+
copyright?: string;
|
|
24
|
+
/**
|
|
25
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:version
|
|
26
|
+
*/
|
|
27
|
+
version: string;
|
|
28
|
+
/**
|
|
29
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:description
|
|
30
|
+
*/
|
|
31
|
+
description?: string;
|
|
32
|
+
/**
|
|
33
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
|
34
|
+
*/
|
|
35
|
+
icon?: string;
|
|
36
|
+
/**
|
|
37
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
|
38
|
+
*/
|
|
39
|
+
iconURL?: string;
|
|
40
|
+
/**
|
|
41
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
|
42
|
+
*/
|
|
43
|
+
defaulticon?: string;
|
|
44
|
+
/**
|
|
45
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon64
|
|
46
|
+
*/
|
|
47
|
+
icon64?: string;
|
|
48
|
+
/**
|
|
49
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon64
|
|
50
|
+
*/
|
|
51
|
+
icon64URL?: string;
|
|
52
|
+
/**
|
|
53
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:grant
|
|
54
|
+
*/
|
|
55
|
+
grant?: Grants[];
|
|
56
|
+
/**
|
|
57
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:author
|
|
58
|
+
*/
|
|
59
|
+
author?: string;
|
|
60
|
+
/**
|
|
61
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
62
|
+
*/
|
|
63
|
+
homepage?: string;
|
|
64
|
+
/**
|
|
65
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
66
|
+
*/
|
|
67
|
+
homepageURL?: string;
|
|
68
|
+
/**
|
|
69
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
70
|
+
*/
|
|
71
|
+
website?: string;
|
|
72
|
+
/**
|
|
73
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
74
|
+
*/
|
|
75
|
+
source?: string;
|
|
76
|
+
/**
|
|
77
|
+
* @see https://www.tampermonkey.net/documentation.phpmeta:antifeature
|
|
78
|
+
*/
|
|
79
|
+
antifeature?: [type: string, description: string][];
|
|
80
|
+
/**
|
|
81
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:require
|
|
82
|
+
*/
|
|
83
|
+
require?: string[] | string;
|
|
84
|
+
/**
|
|
85
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:resource
|
|
86
|
+
*/
|
|
87
|
+
resource?: [key: string, value: string][];
|
|
88
|
+
/**
|
|
89
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:include
|
|
90
|
+
*/
|
|
91
|
+
include?: string[] | string;
|
|
92
|
+
/**
|
|
93
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:match
|
|
94
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
|
|
95
|
+
*/
|
|
96
|
+
match: string[] | string;
|
|
97
|
+
/**
|
|
98
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
|
|
99
|
+
*/
|
|
100
|
+
'exclude-match'?: string[] | string;
|
|
101
|
+
/**
|
|
102
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:exclude
|
|
103
|
+
*/
|
|
104
|
+
exclude?: string[] | string;
|
|
105
|
+
/**
|
|
106
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:run_at
|
|
107
|
+
*/
|
|
108
|
+
'run-at'?: RunAt;
|
|
109
|
+
/**
|
|
110
|
+
* @see https://www.tampermonkey.net/documentation.phpmeta:sandbox
|
|
111
|
+
*/
|
|
112
|
+
sandbox?: string;
|
|
113
|
+
/**
|
|
114
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:connect
|
|
115
|
+
*/
|
|
116
|
+
connect?: string[] | string;
|
|
117
|
+
/**
|
|
118
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:noframes
|
|
119
|
+
*/
|
|
120
|
+
noframes?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:updateURL
|
|
123
|
+
*/
|
|
124
|
+
updateURL?: string;
|
|
125
|
+
/**
|
|
126
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:downloadURL
|
|
127
|
+
*/
|
|
128
|
+
downloadURL?: string;
|
|
129
|
+
/**
|
|
130
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:supportURL
|
|
131
|
+
*/
|
|
132
|
+
supportURL?: string;
|
|
133
|
+
/**
|
|
134
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:webRequest
|
|
135
|
+
*/
|
|
136
|
+
webRequest?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:unwrap
|
|
139
|
+
*/
|
|
140
|
+
unwrap?: boolean;
|
|
141
|
+
};
|
|
142
|
+
interface ServerConfig {
|
|
143
|
+
/**
|
|
144
|
+
* {@link https://github.com/sindresorhus/get-port}
|
|
145
|
+
*/
|
|
146
|
+
port?: number;
|
|
147
|
+
/**
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
open?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface UserscriptPluginConfig {
|
|
153
|
+
/**
|
|
154
|
+
* Path of userscript entry.
|
|
155
|
+
*/
|
|
156
|
+
entry: string;
|
|
157
|
+
/**
|
|
158
|
+
* Userscript file name.
|
|
159
|
+
*/
|
|
160
|
+
fileName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Userscript header config.
|
|
163
|
+
*
|
|
164
|
+
* @see https://www.tampermonkey.net/documentation.php
|
|
165
|
+
*/
|
|
166
|
+
header: HeaderConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Server config.
|
|
169
|
+
*/
|
|
170
|
+
server?: ServerConfig;
|
|
171
|
+
/**
|
|
172
|
+
* Override default esbuild transform options.
|
|
173
|
+
*
|
|
174
|
+
* @default
|
|
175
|
+
* ```json
|
|
176
|
+
* {
|
|
177
|
+
* "minify": true,
|
|
178
|
+
* "legalComments": "none"
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
esbuildTransformOptions?: Omit<EsbuildTransformOptions, 'format' | 'target' | 'loader' | 'sourcemap'>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare function UserscriptPlugin(config: UserscriptPluginConfig): PluginOption;
|
|
186
|
+
|
|
187
|
+
export { UserscriptPluginConfig, UserscriptPlugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginOption } from 'vite';
|
|
1
|
+
import { EsbuildTransformOptions, PluginOption } from 'vite';
|
|
2
2
|
|
|
3
3
|
declare const GM: readonly ["setValue", "getValue", "deleteValue", "listValues", "setClipboard", "addStyle", "addElement", "addValueChangeListener", "removeValueChangeListener", "registerMenuCommand", "unregisterMenuCommand", "download", "getTab", "getTabs", "saveTab", "openInTab", "notification", "getResourceURL", "getResourceText", "xmlhttpRequest", "log", "info"];
|
|
4
4
|
declare const GMwindow: readonly ["unsafeWindow", "window.onurlchange", "window.focus", "window.close"];
|
|
@@ -154,6 +154,10 @@ interface UserscriptPluginConfig {
|
|
|
154
154
|
* Path of userscript entry.
|
|
155
155
|
*/
|
|
156
156
|
entry: string;
|
|
157
|
+
/**
|
|
158
|
+
* Userscript file name.
|
|
159
|
+
*/
|
|
160
|
+
fileName?: string;
|
|
157
161
|
/**
|
|
158
162
|
* Userscript header config.
|
|
159
163
|
*
|
|
@@ -164,6 +168,18 @@ interface UserscriptPluginConfig {
|
|
|
164
168
|
* Server config.
|
|
165
169
|
*/
|
|
166
170
|
server?: ServerConfig;
|
|
171
|
+
/**
|
|
172
|
+
* Override default esbuild transform options.
|
|
173
|
+
*
|
|
174
|
+
* @default
|
|
175
|
+
* ```json
|
|
176
|
+
* {
|
|
177
|
+
* "minify": true,
|
|
178
|
+
* "legalComments": "none"
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
esbuildTransformOptions?: Omit<EsbuildTransformOptions, 'format' | 'target' | 'loader' | 'sourcemap'>;
|
|
167
183
|
}
|
|
168
184
|
|
|
169
185
|
declare function UserscriptPlugin(config: UserscriptPluginConfig): PluginOption;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{readFileSync as
|
|
2
|
-
`)}};import{dirname as
|
|
3
|
-
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(r){let e=[];for(let
|
|
1
|
+
import{readFileSync as E,writeFileSync as y}from"fs";import{createServer as J}from"http";import{resolve as c}from"path";import Y from"get-port";import Q from"open";import C from"picocolors";import X from"serve-handler";import{createLogger as Z}from"vite";import{server as ee}from"websocket";var d=class{constructor(r){this.config=r;this.addHomepageMeta(),this.maxKeyLength=Math.max(...Object.keys(this.config).map(e=>e.length))+1}header=[];maxKeyLength;addHomepageMeta(){let r=this.config.homepage??this.config.homepageURL;r&&(this.config.updateURL=new URL(`${this.config.name}.meta.js`,r).href,this.config.downloadURL=new URL(`${this.config.name}.user.js`,r).href)}addSpaces(r){return" ".repeat(this.maxKeyLength-r.length)}addMetadata(r,e){e=Array.isArray(e)?e.join(" "):e===!0?"":e,this.header.push(`// @${r}${this.addSpaces(r)}${e}`)}generate(){for(let[r,e]of Object.entries(this.config))if(Array.isArray(e))e.forEach(s=>this.addMetadata(r,s));else{if(e===void 0)continue;this.addMetadata(r,e)}return["// ==UserScript==",...this.header,"// ==/UserScript=="].join(`
|
|
2
|
+
`)}};import{dirname as q}from"path";import{fileURLToPath as z}from"url";var M=q(z(import.meta.url)),v="vite-userscript-plugin",P='console.warn("__STYLE__")',G=new RegExp(/\.(t|j)sx?$/),T=new RegExp(/\.(s[ac]|c|le)ss$/),B=["setValue","getValue","deleteValue","listValues","setClipboard","addStyle","addElement","addValueChangeListener","removeValueChangeListener","registerMenuCommand","unregisterMenuCommand","download","getTab","getTabs","saveTab","openInTab","notification","getResourceURL","getResourceText","xmlhttpRequest","log","info"],K=["unsafeWindow","window.onurlchange","window.focus","window.close"],g=B.map(t=>[`GM_${t}`,`GM.${t}`]).flat();g.push(...K);import{transformWithEsbuild as I}from"vite";function L(t){return[...new Set(Array.isArray(t)?t:t?[t]:[])]}async function h({minify:t,file:r,name:e,loader:s},a){let{code:f}=await I(r,e,{minify:t,loader:s,sourcemap:!1,legalComments:"none",...a});return f}function F(t){let r=[];for(let e of g)t.indexOf(e)!==-1&&r.push(e);return r}var R=class{styles=new Map;async add(r,e,s){let a=await h({name:r,file:e,minify:s,loader:"css"});return this.styles.set(r,a.replace(`
|
|
3
|
+
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(r){let e=[];for(let s of r){let a=this.styles.get(s);a&&e.push([s,a])}this.styles.clear(),e.forEach(s=>this.styles.set(...s))}},j=new R;function te(t){try{let r,e,s=null,a=t.fileName??t.header.name,f=Z("info",{prefix:`[${v}]`,allowClearScreen:!0}),w=J((n,o)=>X(n,o,{public:r.build.outDir})),_=ee;return new _({httpServer:w}).on("request",n=>{s=n.accept(null,n.origin)}),{name:v,apply:"build",config(){return{build:{target:"esnext",minify:!1,lib:{name:a,entry:t.entry,formats:["iife"],fileName:()=>`${a}.js`},rollupOptions:{output:{extend:!0}}}}},async configResolved(n){r=n,e=n.build.watch??!1,t.entry=c(n.root,t.entry),Array.from(["match","require","include","exclude","resource","connect"]).forEach(o=>{let i=t.header[o];t.header[o]=L(i)}),t.server={port:await Y(),open:!1,...t.server}},async transform(n,o){let i=n;return T.test(o)&&(i=await j.add(o,i,!e)),o.includes(t.entry)&&(i=n+P),{code:i,map:null}},generateBundle(n,o){for(let i of Object.values(o)){if(i.type==="asset")continue;let p=Object.keys(i.modules).filter(m=>T.test(m));p.length&&j.merge(p)}},async writeBundle(n,o){let{open:i,port:p}=t.server,m=n.sanitizeFileName(a),D=`${m}.user.js`,O=`${m}.proxy.user.js`,N=`${m}.meta.js`;for(let[u]of Object.entries(o))if(G.test(u)){let x=r.root,b=r.build.outDir,$=c(x,b,u),k=c(x,b,D),A=c(x,b,O),V=c(x,b,N),S=c(M,`ws-${m}.js`);try{let l=E($,"utf8");if(l=l.replace(P,`${j.inject()}`),l=await h({minify:!e,file:l,name:u,loader:"js"},t.esbuildTransformOptions),t.header.grant=L(e?g:[...F(l),...t.header.grant??[]]),e){let H=E(c(M,"ws.js"),"utf8"),W=await h({minify:!e,file:H.replace("__WS__",`ws://localhost:${p}`),name:S,loader:"js"},t.esbuildTransformOptions);y(S,W),y(A,new d({...t.header,require:[...t.header.require??[],"file://"+S,"file://"+$]}).generate())}let U=new d(t.header).generate();y($,l),y(V,U),y(k,`${U}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${l}`)}catch(l){console.log(l)}}if(e&&!w.listening){let u=`http://localhost:${p}`;w.listen(p,()=>{f.clearScreen("info"),f.info(C.bold(`${C.cyan(">>> [vite-userscript-plugin]")} ${C.gray(u)}`))}),i&&await Q(`${u}/${O}`)}else e||(w.close(),process.exit(0))},buildEnd(){e&&(f.clearScreen("info"),s&&s.sendUTF(JSON.stringify({message:"reload"})))}}}catch(r){return console.error(r),{name:v}}}export{te as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-userscript-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"@types/node": "18.15.3",
|
|
58
58
|
"@types/serve-handler": "6.1.1",
|
|
59
59
|
"@types/websocket": "1.0.5",
|
|
60
|
-
"@vitest/ui": "0.
|
|
61
|
-
"tsup": "7.
|
|
62
|
-
"turbo": "1.10.
|
|
63
|
-
"typescript": "5.1.
|
|
64
|
-
"vite": "4.
|
|
65
|
-
"vite-plugin-dts": "
|
|
66
|
-
"vitest": "0.
|
|
60
|
+
"@vitest/ui": "0.33.0",
|
|
61
|
+
"tsup": "7.1.0",
|
|
62
|
+
"turbo": "1.10.7",
|
|
63
|
+
"typescript": "5.1.6",
|
|
64
|
+
"vite": "4.4.2",
|
|
65
|
+
"vite-plugin-dts": "3.1.1",
|
|
66
|
+
"vitest": "0.33.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"vite": ">=3.0.0"
|