vite-userscript-plugin 2.3.0 → 2.3.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/README.md +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/index.js +10 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ See [examples/sourcemap](./examples/sourcemap).
|
|
|
133
133
|
| Option | Default | Description |
|
|
134
134
|
| --- | --- | --- |
|
|
135
135
|
| `entry` | — | Userscript entry. Required. |
|
|
136
|
-
| `header` | — | Metablock. Required: `name`, `version`, `match`. Relative `icon` / `require` / `resource` / `supportURL` / `updateURL` / `downloadURL` join `homepage` (`homepageURL` / `website` / `source`). Absolute `http(s):` URLs stay as-is. |
|
|
136
|
+
| `header` | — | Metablock. Required: `name`, `version`, `match`. Relative `icon` / `require` / `resource` / `supportURL` / `updateURL` / `downloadURL` join `homepage` (`homepageURL` / `website` / `source`). Absolute `http(s):` URLs stay as-is. `updateURL` / `downloadURL` of `none` disable updates and are not joined. |
|
|
137
137
|
| `fileName` | sanitized `header.name` | Output base name (`{fileName}.user.js`). |
|
|
138
138
|
| `server.open` | `false` | Open the install target when Vite starts (`true`, `'user'`, `'proxy'`). HMR: `.dev.user.js`. `file`: `.user.js` or `.proxy.user.js`. Vite opens one URL. |
|
|
139
139
|
| `server.prefix` | `'server:'` | Prefix for `@name` in serve mode. `false` disables it. |
|
package/dist/index.d.ts
CHANGED
|
@@ -63,18 +63,33 @@ type HeaderConfig = {
|
|
|
63
63
|
*/
|
|
64
64
|
'author'?: string;
|
|
65
65
|
/**
|
|
66
|
+
* Script homepage. Also the base for relative `icon`, `iconURL`,
|
|
67
|
+
* `defaulticon`, `icon64`, `icon64URL`, `require`, `resource`, `supportURL`,
|
|
68
|
+
* `updateURL`, and `downloadURL`. Absolute `http(s):` URLs stay as-is.
|
|
69
|
+
* `updateURL` / `downloadURL` of `none` are not joined.
|
|
70
|
+
*
|
|
71
|
+
* Fallback order: `homepage`, `homepageURL`, `website`, `source`.
|
|
72
|
+
*
|
|
66
73
|
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
67
74
|
*/
|
|
68
75
|
'homepage'?: string;
|
|
69
76
|
/**
|
|
77
|
+
* Alias of `homepage`. Used as the relative-URL base when `homepage` is empty.
|
|
78
|
+
*
|
|
70
79
|
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
71
80
|
*/
|
|
72
81
|
'homepageURL'?: string;
|
|
73
82
|
/**
|
|
83
|
+
* Alias of `homepage`. Used as the relative-URL base when `homepage` and
|
|
84
|
+
* `homepageURL` are empty.
|
|
85
|
+
*
|
|
74
86
|
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
75
87
|
*/
|
|
76
88
|
'website'?: string;
|
|
77
89
|
/**
|
|
90
|
+
* Alias of `homepage`. Used as the relative-URL base when `homepage`,
|
|
91
|
+
* `homepageURL`, and `website` are empty.
|
|
92
|
+
*
|
|
78
93
|
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
79
94
|
*/
|
|
80
95
|
'source'?: string;
|
|
@@ -124,13 +139,17 @@ type HeaderConfig = {
|
|
|
124
139
|
*/
|
|
125
140
|
'noframes'?: boolean;
|
|
126
141
|
/**
|
|
142
|
+
* `none` disables update checks. It is not joined with homepage.
|
|
143
|
+
*
|
|
127
144
|
* @see https://www.tampermonkey.net/documentation.php#meta:updateURL
|
|
128
145
|
*/
|
|
129
|
-
'updateURL'?: string;
|
|
146
|
+
'updateURL'?: 'none' | (string & {});
|
|
130
147
|
/**
|
|
148
|
+
* `none` disables update checks (pinned / non-latest installs). It is not joined with homepage.
|
|
149
|
+
*
|
|
131
150
|
* @see https://www.tampermonkey.net/documentation.php#meta:downloadURL
|
|
132
151
|
*/
|
|
133
|
-
'downloadURL'?: string;
|
|
152
|
+
'downloadURL'?: 'none' | (string & {});
|
|
134
153
|
/**
|
|
135
154
|
* @see https://www.tampermonkey.net/documentation.php#meta:supportURL
|
|
136
155
|
*/
|
package/dist/index.js
CHANGED
|
@@ -118,16 +118,17 @@ function resolveHomePage(header) {
|
|
|
118
118
|
const trimmed = homePage.trim();
|
|
119
119
|
return trimmed === "" ? void 0 : trimmed;
|
|
120
120
|
}
|
|
121
|
-
function isResolvableHeaderPath(value) {
|
|
121
|
+
function isResolvableHeaderPath(value, field) {
|
|
122
122
|
const trimmed = value.trim();
|
|
123
123
|
if (!trimmed) return false;
|
|
124
|
+
if ((field === "updateURL" || field === "downloadURL") && trimmed.toLowerCase() === "none") return false;
|
|
124
125
|
if (ABSOLUTE_URL_RE.test(trimmed) || trimmed.startsWith("//") || trimmed.startsWith("/")) return false;
|
|
125
126
|
return true;
|
|
126
127
|
}
|
|
127
|
-
function containsResolvableHeaderPath(value) {
|
|
128
|
-
if (typeof value === "string") return isResolvableHeaderPath(value);
|
|
128
|
+
function containsResolvableHeaderPath(value, field) {
|
|
129
|
+
if (typeof value === "string") return isResolvableHeaderPath(value, field);
|
|
129
130
|
if (!Array.isArray(value)) return false;
|
|
130
|
-
return value.some((item) => typeof item === "string" && isResolvableHeaderPath(item));
|
|
131
|
+
return value.some((item) => typeof item === "string" && isResolvableHeaderPath(item, field));
|
|
131
132
|
}
|
|
132
133
|
function containsResolvableResourcePath(resource) {
|
|
133
134
|
if (!Array.isArray(resource)) return false;
|
|
@@ -137,7 +138,7 @@ function containsResolvableResourcePath(resource) {
|
|
|
137
138
|
}
|
|
138
139
|
function listHomepageRelativeFields(header) {
|
|
139
140
|
const fields = [];
|
|
140
|
-
for (const key of HOMEPAGE_RELATIVE_FIELDS) if (containsResolvableHeaderPath(header[key])) fields.push(key);
|
|
141
|
+
for (const key of HOMEPAGE_RELATIVE_FIELDS) if (containsResolvableHeaderPath(header[key], key)) fields.push(key);
|
|
141
142
|
if (containsResolvableResourcePath(header.resource)) fields.push("resource");
|
|
142
143
|
return fields;
|
|
143
144
|
}
|
|
@@ -148,12 +149,12 @@ function resolvePublicFileUrl(header, fileName) {
|
|
|
148
149
|
return new URL(fileName, ensureTrailingSlash(homePage)).href;
|
|
149
150
|
} catch {}
|
|
150
151
|
}
|
|
151
|
-
function resolveHeaderUrlValue(header, value) {
|
|
152
|
+
function resolveHeaderUrlValue(header, value, field) {
|
|
152
153
|
if (typeof value === "string") {
|
|
153
|
-
if (!isResolvableHeaderPath(value)) return value;
|
|
154
|
+
if (!isResolvableHeaderPath(value, field)) return value;
|
|
154
155
|
return resolvePublicFileUrl(header, value.trim()) ?? value;
|
|
155
156
|
}
|
|
156
|
-
if (Array.isArray(value)) return value.map((item) => typeof item === "string" ? resolveHeaderUrlValue(header, item) : item);
|
|
157
|
+
if (Array.isArray(value)) return value.map((item) => typeof item === "string" ? resolveHeaderUrlValue(header, item, field) : item);
|
|
157
158
|
return value;
|
|
158
159
|
}
|
|
159
160
|
function resolveResourceUrls(header, resource) {
|
|
@@ -169,7 +170,7 @@ function resolveResourceUrls(header, resource) {
|
|
|
169
170
|
function applyHomepageRelativeUrls(header) {
|
|
170
171
|
if (!resolveHomePage(header)) return header;
|
|
171
172
|
const next = { ...header };
|
|
172
|
-
for (const key of HOMEPAGE_RELATIVE_FIELDS) if (next[key] != null) Object.assign(next, { [key]: resolveHeaderUrlValue(next, next[key]) });
|
|
173
|
+
for (const key of HOMEPAGE_RELATIVE_FIELDS) if (next[key] != null) Object.assign(next, { [key]: resolveHeaderUrlValue(next, next[key], key) });
|
|
173
174
|
if (next.resource != null) next.resource = resolveResourceUrls(next, next.resource);
|
|
174
175
|
return next;
|
|
175
176
|
}
|