vite-plugin-blocklet 0.7.5 → 0.7.6

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 CHANGED
@@ -14,6 +14,7 @@ var YAML = require('yaml');
14
14
  var isMobile = require('ismobilejs');
15
15
  var getPort = require('get-port');
16
16
  var mri = require('mri');
17
+ var dotenv = require('dotenv');
17
18
 
18
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
20
 
@@ -25,6 +26,7 @@ var YAML__default = /*#__PURE__*/_interopDefaultLegacy(YAML);
25
26
  var isMobile__default = /*#__PURE__*/_interopDefaultLegacy(isMobile);
26
27
  var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
27
28
  var mri__default = /*#__PURE__*/_interopDefaultLegacy(mri);
29
+ var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
28
30
 
29
31
  const { types } = Mcrypto__default["default"];
30
32
 
@@ -418,25 +420,30 @@ async function setupClient(app, options = {}) {
418
420
  const { host = '127.0.0.1', protocol = 'ws', port: inputPort, configFile = '', appType = 'spa' } = options;
419
421
  let skipWritePort = true;
420
422
  let envAppendContent = '';
421
- const envFile = path__default["default"].join(process.cwd(), '.env.development.local');
423
+ let envObject = '';
424
+ const envFilePath = path__default["default"].join(process.cwd(), '.env.development.local');
422
425
  let port;
423
426
 
424
- if (!fs__default["default"].existsSync(envFile)) {
427
+ if (!fs__default["default"].existsSync(envFilePath)) {
425
428
  skipWritePort = false;
426
429
  port = await getPort__default["default"]({ port: inputPort });
427
- envAppendContent = `VITE_BLOCKLET_PORT=${port}`;
430
+ envAppendContent = `BLOCKLET_VITE_PORT=${port}`;
428
431
  } else {
429
432
  port = await getPort__default["default"]({ port: inputPort });
430
- const content = await fs__default["default"].promises.readFile(envFile, 'utf-8');
431
- if (!content.includes('VITE_BLOCKLET_PORT')) {
433
+ const envContent = await fs__default["default"].promises.readFile(envFilePath, 'utf-8');
434
+ envObject = dotenv__default["default"].parse(envContent);
435
+
436
+ if (!envObject.BLOCKLET_VITE_PORT) {
432
437
  skipWritePort = false;
433
- envAppendContent = `${content}\nVITE_BLOCKLET_PORT=${port}`;
438
+ envAppendContent = `${envContent}\nBLOCKLET_VITE_PORT=${port}`;
434
439
  } else {
435
- port = process.env.VITE_BLOCKLET_PORT;
440
+ port = process.env.BLOCKLET_VITE_PORT;
436
441
  }
437
442
  }
438
443
  if (!skipWritePort && envAppendContent) {
439
- await fs__default["default"].promises.writeFile(envFile, envAppendContent);
444
+ // TODO @zhanghan 常见的 env file 处理暂不支持保留 comment,所以不能通过解析后的对象来写入文件
445
+ // @see https://github.com/bevry/envfile/pull/213
446
+ await fs__default["default"].promises.writeFile(envFilePath, envAppendContent);
440
447
  }
441
448
  // 以中间件模式创建 Vite 服务器
442
449
  const vite$1 = await vite.createServer({
package/libs/client.js CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import getPort from 'get-port';
4
4
  import { createServer } from 'vite';
5
5
  import mri from 'mri';
6
+ import dotenv from 'dotenv';
6
7
 
7
8
  const argv = process.argv.slice(2);
8
9
  const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
@@ -29,25 +30,30 @@ export default async function setupClient(app, options = {}) {
29
30
  const { host = '127.0.0.1', protocol = 'ws', port: inputPort, configFile = '', appType = 'spa' } = options;
30
31
  let skipWritePort = true;
31
32
  let envAppendContent = '';
32
- const envFile = path.join(process.cwd(), '.env.development.local');
33
+ let envObject = '';
34
+ const envFilePath = path.join(process.cwd(), '.env.development.local');
33
35
  let port;
34
36
 
35
- if (!fs.existsSync(envFile)) {
37
+ if (!fs.existsSync(envFilePath)) {
36
38
  skipWritePort = false;
37
39
  port = await getPort({ port: inputPort });
38
- envAppendContent = `VITE_BLOCKLET_PORT=${port}`;
40
+ envAppendContent = `BLOCKLET_VITE_PORT=${port}`;
39
41
  } else {
40
42
  port = await getPort({ port: inputPort });
41
- const content = await fs.promises.readFile(envFile, 'utf-8');
42
- if (!content.includes('VITE_BLOCKLET_PORT')) {
43
+ const envContent = await fs.promises.readFile(envFilePath, 'utf-8');
44
+ envObject = dotenv.parse(envContent);
45
+
46
+ if (!envObject.BLOCKLET_VITE_PORT) {
43
47
  skipWritePort = false;
44
- envAppendContent = `${content}\nVITE_BLOCKLET_PORT=${port}`;
48
+ envAppendContent = `${envContent}\nBLOCKLET_VITE_PORT=${port}`;
45
49
  } else {
46
- port = process.env.VITE_BLOCKLET_PORT;
50
+ port = process.env.BLOCKLET_VITE_PORT;
47
51
  }
48
52
  }
49
53
  if (!skipWritePort && envAppendContent) {
50
- await fs.promises.writeFile(envFile, envAppendContent);
54
+ // TODO @zhanghan 常见的 env file 处理暂不支持保留 comment,所以不能通过解析后的对象来写入文件
55
+ // @see https://github.com/bevry/envfile/pull/213
56
+ await fs.promises.writeFile(envFilePath, envAppendContent);
51
57
  }
52
58
  // 以中间件模式创建 Vite 服务器
53
59
  const vite = await createServer({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-blocklet",
3
3
  "type": "module",
4
- "version": "0.7.5",
4
+ "version": "0.7.6",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -30,6 +30,7 @@
30
30
  "@arcblock/did": "^1.18.108",
31
31
  "@ocap/mcrypto": "^1.18.108",
32
32
  "@ocap/util": "^1.18.108",
33
+ "dotenv": "^16.4.5",
33
34
  "get-port": "^5.1.1",
34
35
  "ismobilejs": "^1.1.1",
35
36
  "mri": "^1.2.0",