vite-plugin-blocklet 0.14.0 → 0.14.2

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
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var vitePluginNodePolyfills = require('vite-plugin-node-polyfills');
4
+ var defu = require('defu');
4
5
  var vite = require('vite');
5
6
  var semver = require('semver');
6
7
  var node_fs = require('node:fs');
7
8
  var YAML = require('yaml');
8
- var Mcrypto = require('@ocap/mcrypto');
9
+ var mcrypto = require('@ocap/mcrypto');
9
10
  var util = require('@ocap/util');
10
11
  var did = require('@arcblock/did');
11
12
  var fs = require('fs');
@@ -20,15 +21,13 @@ var getPort = require('get-port');
20
21
  var mri = require('mri');
21
22
  var httpProxyMiddleware = require('http-proxy-middleware');
22
23
 
23
- const { types } = Mcrypto;
24
-
25
24
  function toBlockletDid(name) {
26
25
  if (did.isValid(name)) {
27
26
  return name;
28
27
  }
29
28
 
30
29
  const pk = util.toHex(Buffer.from(typeof name === 'string' ? name.trim() : name));
31
- return did.fromPublicKey(pk, { role: types.RoleType.ROLE_ANY });
30
+ return did.fromPublicKey(pk, { role: mcrypto.types.RoleType.ROLE_ANY });
32
31
  }
33
32
 
34
33
  async function getBlockletYAML() {
@@ -1004,6 +1003,14 @@ async function setupClient(app, options = {}) {
1004
1003
  * @property {number} [chunkSizeLimit=2000] - The chunk size limit in KB.
1005
1004
  */
1006
1005
 
1006
+ const defuReplaceArray = defu.createDefu((obj, key, value) => {
1007
+ // 如果当前值或默认值是数组,直接使用新值(实现替换)
1008
+ if (Array.isArray(obj[key]) || Array.isArray(value)) {
1009
+ obj[key] = value;
1010
+ return true // 返回 true 表示我们已经处理了这个 key,defu 不需要再做默认处理
1011
+ }
1012
+ });
1013
+
1007
1014
  /**
1008
1015
  * Create blocklet plugins.
1009
1016
  *
@@ -1039,7 +1046,15 @@ function createBlockletPlugin(options = {}) {
1039
1046
  plugins.push(createHmrPlugin(restOptions));
1040
1047
  }
1041
1048
  if (!disableNodePolyfills) {
1042
- plugins.push(vitePluginNodePolyfills.nodePolyfills(nodePolyfillsOptions));
1049
+ const mergedOptions = defuReplaceArray(nodePolyfillsOptions, {
1050
+ include: ['buffer'],
1051
+ globals: {
1052
+ buffer: true,
1053
+ global: false,
1054
+ process: false,
1055
+ }
1056
+ });
1057
+ plugins.push(vitePluginNodePolyfills.nodePolyfills(mergedOptions));
1043
1058
  }
1044
1059
  if (!disableLoading) {
1045
1060
  plugins.push(createLoadingPlugin(restOptions));
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { nodePolyfills } from 'vite-plugin-node-polyfills';
2
+ import { createDefu } from 'defu';
3
+
2
4
  import createHmrPlugin from './libs/hmr.js';
3
5
  import createConfigPlugin from './libs/config.js';
4
6
  import createMetaPlugin from './libs/meta.js';
@@ -44,6 +46,14 @@ import setupClient from './libs/client.js';
44
46
  * @property {number} [chunkSizeLimit=2000] - The chunk size limit in KB.
45
47
  */
46
48
 
49
+ const defuReplaceArray = createDefu((obj, key, value) => {
50
+ // 如果当前值或默认值是数组,直接使用新值(实现替换)
51
+ if (Array.isArray(obj[key]) || Array.isArray(value)) {
52
+ obj[key] = value
53
+ return true // 返回 true 表示我们已经处理了这个 key,defu 不需要再做默认处理
54
+ }
55
+ })
56
+
47
57
  /**
48
58
  * Create blocklet plugins.
49
59
  *
@@ -79,7 +89,15 @@ export function createBlockletPlugin(options = {}) {
79
89
  plugins.push(createHmrPlugin(restOptions));
80
90
  }
81
91
  if (!disableNodePolyfills) {
82
- plugins.push(nodePolyfills(nodePolyfillsOptions));
92
+ const mergedOptions = defuReplaceArray(nodePolyfillsOptions, {
93
+ include: ['buffer'],
94
+ globals: {
95
+ buffer: true,
96
+ global: false,
97
+ process: false,
98
+ }
99
+ });
100
+ plugins.push(nodePolyfills(mergedOptions));
83
101
  }
84
102
  if (!disableLoading) {
85
103
  plugins.push(createLoadingPlugin(restOptions));
package/libs/utils.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import YAML from 'yaml';
3
- import Mcrypto from '@ocap/mcrypto';
3
+ import { types } from '@ocap/mcrypto';
4
4
  import { toHex } from '@ocap/util';
5
5
  import { fromPublicKey, isValid } from '@arcblock/did';
6
6
 
7
- const { types } = Mcrypto;
8
-
9
7
  export function toBlockletDid(name) {
10
8
  if (isValid(name)) {
11
9
  return name;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-blocklet",
3
3
  "type": "module",
4
- "version": "0.14.0",
4
+ "version": "0.14.2",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -30,9 +30,10 @@
30
30
  "rollup": "^4.34.8"
31
31
  },
32
32
  "dependencies": {
33
- "@arcblock/did": "^1.27.15",
34
- "@ocap/mcrypto": "^1.27.15",
35
- "@ocap/util": "^1.27.15",
33
+ "@arcblock/did": "^1.28.0",
34
+ "@ocap/mcrypto": "^1.28.0",
35
+ "@ocap/util": "^1.28.0",
36
+ "defu": "^6.1.4",
36
37
  "get-port": "^5.1.1",
37
38
  "http-proxy-middleware": "^3.0.3",
38
39
  "ismobilejs": "^1.1.1",