vite-plugin-blocklet 0.7.9 → 0.8.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 +16 -30
- package/libs/hmr.js +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var vitePluginNodePolyfills = require('vite-plugin-node-polyfills');
|
|
6
4
|
var vite = require('vite');
|
|
7
5
|
var semver = require('semver');
|
|
@@ -16,19 +14,7 @@ var getPort = require('get-port');
|
|
|
16
14
|
var mri = require('mri');
|
|
17
15
|
var dotenv = require('dotenv');
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
|
|
22
|
-
var Mcrypto__default = /*#__PURE__*/_interopDefaultLegacy(Mcrypto);
|
|
23
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
24
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
25
|
-
var YAML__default = /*#__PURE__*/_interopDefaultLegacy(YAML);
|
|
26
|
-
var isMobile__default = /*#__PURE__*/_interopDefaultLegacy(isMobile);
|
|
27
|
-
var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
|
|
28
|
-
var mri__default = /*#__PURE__*/_interopDefaultLegacy(mri);
|
|
29
|
-
var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
|
|
30
|
-
|
|
31
|
-
const { types } = Mcrypto__default["default"];
|
|
17
|
+
const { types } = Mcrypto;
|
|
32
18
|
|
|
33
19
|
function toBlockletDid(name) {
|
|
34
20
|
if (did.isValid(name)) {
|
|
@@ -55,13 +41,13 @@ function createHmrPlugin(options = {}) {
|
|
|
55
41
|
apply: 'serve',
|
|
56
42
|
async transform(code, id) {
|
|
57
43
|
if (isInBlocklet && id.endsWith('/vite/dist/client/client.mjs')) {
|
|
58
|
-
const pureVersion =
|
|
44
|
+
const pureVersion = semver.major(version);
|
|
59
45
|
let replacedCode = code;
|
|
60
46
|
if (pureVersion === 2) {
|
|
61
47
|
replacedCode = replacedCode.replace("const base = __BASE__ || '/';\n", '');
|
|
62
48
|
replacedCode = replacedCode.replace(
|
|
63
49
|
'const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`;',
|
|
64
|
-
"const base = __BASE__ || '/';\nlet tmpPort = __HMR_PORT__;\nif (window.blocklet) {\ntmpPort = new URL(window.location.href).port + base;\n}\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}${tmpPort ? `:${tmpPort}` : ''}`;"
|
|
50
|
+
"const base = __BASE__ || '/';\nlet tmpPort = __HMR_PORT__;\nif (window.blocklet) {\ntmpPort = new URL(window.location.href).port + base;\n}\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}${tmpPort ? `:${tmpPort}` : ''}`;",
|
|
65
51
|
);
|
|
66
52
|
return replacedCode;
|
|
67
53
|
}
|
|
@@ -79,7 +65,7 @@ function createConfigPlugin$1() {
|
|
|
79
65
|
const prefix = req.headers['x-path-prefix'] || '/';
|
|
80
66
|
// blocklet server 会把设置的 base 从请求 url 中移除,所以需要再加回 base
|
|
81
67
|
if (!req.url.startsWith(prefix)) {
|
|
82
|
-
req.url =
|
|
68
|
+
req.url = path.join(prefix || '/', req.url);
|
|
83
69
|
}
|
|
84
70
|
return next();
|
|
85
71
|
});
|
|
@@ -114,7 +100,7 @@ function createConfigPlugin$1() {
|
|
|
114
100
|
if (!config.base) {
|
|
115
101
|
try {
|
|
116
102
|
const blockletYamlPath = './blocklet.yml';
|
|
117
|
-
const blockletYaml =
|
|
103
|
+
const blockletYaml = YAML.parse(fs.readFileSync(blockletYamlPath, 'utf8'));
|
|
118
104
|
let { name, did } = blockletYaml;
|
|
119
105
|
if (!did && name) {
|
|
120
106
|
did = toBlockletDid(name);
|
|
@@ -156,7 +142,7 @@ function createMetaPlugin() {
|
|
|
156
142
|
// 如果 index.html 中没有设置 title,则自动注入 blocklet.yml 中的 title
|
|
157
143
|
if (!/<title>(.*?)<\/title>/.test(html)) {
|
|
158
144
|
const blockletYamlPath = './blocklet.yml';
|
|
159
|
-
const blockletYaml =
|
|
145
|
+
const blockletYaml = YAML.parse(fs.readFileSync(blockletYamlPath, 'utf8'));
|
|
160
146
|
const { title } = blockletYaml;
|
|
161
147
|
|
|
162
148
|
tags.push({
|
|
@@ -343,7 +329,7 @@ function createConfigPlugin(options) {
|
|
|
343
329
|
if (debugPlatform.includes('all')) {
|
|
344
330
|
enabled = true;
|
|
345
331
|
}
|
|
346
|
-
const isMobileFn =
|
|
332
|
+
const isMobileFn = isMobile.default ? isMobile.default : isMobile;
|
|
347
333
|
if (isMobileFn(req.headers['user-agent']).any) {
|
|
348
334
|
if (debugPlatform.includes('mobile')) {
|
|
349
335
|
enabled = true;
|
|
@@ -412,7 +398,7 @@ const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NO
|
|
|
412
398
|
*/
|
|
413
399
|
async function setupClient(app, options = {}) {
|
|
414
400
|
if (!isProduction) {
|
|
415
|
-
const params =
|
|
401
|
+
const params = mri(argv, {
|
|
416
402
|
alias: {
|
|
417
403
|
config: 'c',
|
|
418
404
|
},
|
|
@@ -421,17 +407,17 @@ async function setupClient(app, options = {}) {
|
|
|
421
407
|
let skipWritePort = true;
|
|
422
408
|
let envAppendContent = '';
|
|
423
409
|
let envObject = '';
|
|
424
|
-
const envFilePath =
|
|
410
|
+
const envFilePath = path.join(process.cwd(), '.env.development.local');
|
|
425
411
|
let port;
|
|
426
412
|
|
|
427
|
-
if (!
|
|
413
|
+
if (!fs.existsSync(envFilePath)) {
|
|
428
414
|
skipWritePort = false;
|
|
429
|
-
port = await
|
|
415
|
+
port = await getPort({ port: inputPort });
|
|
430
416
|
envAppendContent = `BLOCKLET_VITE_PORT=${port}`;
|
|
431
417
|
} else {
|
|
432
|
-
port = await
|
|
433
|
-
const envContent = await
|
|
434
|
-
envObject =
|
|
418
|
+
port = await getPort({ port: inputPort });
|
|
419
|
+
const envContent = await fs.promises.readFile(envFilePath, 'utf-8');
|
|
420
|
+
envObject = dotenv.parse(envContent);
|
|
435
421
|
|
|
436
422
|
if (!envObject.BLOCKLET_VITE_PORT) {
|
|
437
423
|
skipWritePort = false;
|
|
@@ -443,7 +429,7 @@ async function setupClient(app, options = {}) {
|
|
|
443
429
|
if (!skipWritePort && envAppendContent) {
|
|
444
430
|
// TODO @zhanghan 常见的 env file 处理暂不支持保留 comment,所以不能通过解析后的对象来写入文件
|
|
445
431
|
// @see https://github.com/bevry/envfile/pull/213
|
|
446
|
-
await
|
|
432
|
+
await fs.promises.writeFile(envFilePath, envAppendContent);
|
|
447
433
|
}
|
|
448
434
|
// 以中间件模式创建 Vite 服务器
|
|
449
435
|
const vite$1 = await vite.createServer({
|
|
@@ -526,7 +512,7 @@ function createBlockletPlugin(options = {}) {
|
|
|
526
512
|
return plugins;
|
|
527
513
|
}
|
|
528
514
|
|
|
529
|
-
Object.defineProperty(exports,
|
|
515
|
+
Object.defineProperty(exports, "nodePolyfills", {
|
|
530
516
|
enumerable: true,
|
|
531
517
|
get: function () { return vitePluginNodePolyfills.nodePolyfills; }
|
|
532
518
|
});
|
package/libs/hmr.js
CHANGED
|
@@ -22,7 +22,7 @@ export default function createHmrPlugin(options = {}) {
|
|
|
22
22
|
replacedCode = replacedCode.replace("const base = __BASE__ || '/';\n", '');
|
|
23
23
|
replacedCode = replacedCode.replace(
|
|
24
24
|
'const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`;',
|
|
25
|
-
"const base = __BASE__ || '/';\nlet tmpPort = __HMR_PORT__;\nif (window.blocklet) {\ntmpPort = new URL(window.location.href).port + base;\n}\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}${tmpPort ? `:${tmpPort}` : ''}`;"
|
|
25
|
+
"const base = __BASE__ || '/';\nlet tmpPort = __HMR_PORT__;\nif (window.blocklet) {\ntmpPort = new URL(window.location.href).port + base;\n}\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}${tmpPort ? `:${tmpPort}` : ''}`;",
|
|
26
26
|
);
|
|
27
27
|
return replacedCode;
|
|
28
28
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-blocklet",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"author": "",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"rollup": "^
|
|
27
|
+
"rollup": "^4.18.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@arcblock/did": "^1.18.
|
|
31
|
-
"@ocap/mcrypto": "^1.18.
|
|
32
|
-
"@ocap/util": "^1.18.
|
|
30
|
+
"@arcblock/did": "^1.18.124",
|
|
31
|
+
"@ocap/mcrypto": "^1.18.124",
|
|
32
|
+
"@ocap/util": "^1.18.124",
|
|
33
33
|
"dotenv": "^16.4.5",
|
|
34
34
|
"get-port": "^5.1.1",
|
|
35
35
|
"ismobilejs": "^1.1.1",
|
|
36
36
|
"mri": "^1.2.0",
|
|
37
|
-
"semver": "^7.
|
|
38
|
-
"vite-plugin-node-polyfills": "^0.
|
|
39
|
-
"yaml": "^2.
|
|
37
|
+
"semver": "^7.6.2",
|
|
38
|
+
"vite-plugin-node-polyfills": "^0.22.0",
|
|
39
|
+
"yaml": "^2.4.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": ">=5"
|