@locuschain/lib 0.1.38 → 0.1.40
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/accounts/index.amd.js +306 -0
- package/dist/accounts/index.cjs.cjs +2 -2
- package/dist/accounts/index.esm.js +2 -2
- package/dist/autogen/index.amd.js +151 -0
- package/dist/autogen/index.cjs.cjs +2 -2
- package/dist/autogen/index.esm.js +2 -2
- package/dist/chunks/account-BSrvZ7S8.js +77 -0
- package/dist/chunks/address-class-Dp7aNQb2.js +18 -0
- package/dist/chunks/base-B_kRRfsf.js +27 -0
- package/dist/chunks/debugWalletActions-BDz-h2tl.js +993 -0
- package/dist/chunks/{keystore-BFVSylSw.js → keystore-B86UzV8A.js} +1 -1
- package/dist/chunks/{keystore-BbK5pVrh.cjs → keystore-BUskzeOs.cjs} +1 -1
- package/dist/chunks/keystore-y1JlFTKh.js +143 -0
- package/dist/chunks/lclib-Bv86gksL.js +3861 -0
- package/dist/chunks/{lclib-C2eG5HzD.js → lclib-j2x9RvDY.js} +55 -32
- package/dist/chunks/{lclib-DuoOR0-Q.cjs → lclib-rGyKpClJ.cjs} +64 -41
- package/dist/chunks/rpc-C4n7t9y0.js +25 -0
- package/dist/chunks/transport-BBAz1kmP.js +30 -0
- package/dist/chunks/tslib.es6-D29rxPkW.js +37 -0
- package/dist/chunks/tx-type-CS4wIUJ8.js +68 -0
- package/dist/chunks/{wasm-DTyHBxcY.cjs → wasm-BYOKRR31.cjs} +1 -1
- package/dist/chunks/{wasm-BtPcXTR4.js → wasm-CLXJDrJA.js} +1 -1
- package/dist/chunks/wasm-CkFW222S.js +213 -0
- package/dist/clients/index.amd.js +97 -0
- package/dist/clients/index.cjs.cjs +1 -1
- package/dist/clients/index.esm.js +1 -1
- package/dist/constant/index.amd.js +458 -0
- package/dist/contracts/index.amd.js +19640 -0
- package/dist/contracts/index.cjs.cjs +2 -2
- package/dist/contracts/index.esm.js +2 -2
- package/dist/errors/index.amd.js +17 -0
- package/dist/index.amd.js +43 -0
- package/dist/index.cjs.cjs +3 -3
- package/dist/index.esm.js +3 -3
- package/dist/transports/index.amd.js +98 -0
- package/dist/utils/index.amd.js +353 -0
- package/dist/utils/index.cjs.cjs +3 -3
- package/dist/utils/index.esm.js +4 -4
- package/dist/vite-plugin/index.amd.js +186 -0
- package/dist/vite-plugin/index.cjs.cjs +189 -0
- package/dist/vite-plugin/index.d.cts +46 -0
- package/dist/vite-plugin/index.d.mts +46 -0
- package/dist/vite-plugin/index.esm.js +183 -0
- package/dist/webpack-plugin/index.amd.js +101 -0
- package/dist/webpack-plugin/index.cjs.cjs +104 -0
- package/dist/webpack-plugin/index.d.cts +46 -0
- package/dist/webpack-plugin/index.d.mts +46 -0
- package/dist/webpack-plugin/index.esm.js +98 -0
- package/package.json +36 -6
- package/dist/index.umd.d.mts +0 -15
- package/dist/umd/index.umd.js +0 -26296
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
define(['module', 'exports', 'node:fs', 'node:path', 'node:url'], (function (module, exports, fs, path, node_url) { 'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @locuschain/lib/webpack-plugin
|
|
5
|
+
*
|
|
6
|
+
* Webpack 5 사용자가 lib 의 wasm 4 개를 자동으로 빌드 그래프에 포함시키도록 돕는 plugin.
|
|
7
|
+
*
|
|
8
|
+
* Webpack 5 는 기본적으로 `new URL(<literal>, import.meta.url)` 패턴을 인식해서
|
|
9
|
+
* asset/resource 모듈로 처리한다 — 따라서 대부분의 경우 lib 만 import 해도 wasm 이
|
|
10
|
+
* 자동으로 output 에 emit 된다.
|
|
11
|
+
*
|
|
12
|
+
* 다만 다음 환경에서 보장이 약해진다:
|
|
13
|
+
* - 사용처가 `module: { rules: [{ test: /\.wasm$/, type: 'javascript/auto' }] }` 같은
|
|
14
|
+
* override 를 두어 native asset 처리를 비활성화한 경우
|
|
15
|
+
* - import.meta.url 처리가 비활성화된 target (`target: 'web'` 외)
|
|
16
|
+
* - babel 등 다른 loader 가 패턴을 망가뜨리는 경우
|
|
17
|
+
*
|
|
18
|
+
* 이 plugin 은 다음을 보장한다:
|
|
19
|
+
* 1. lib 의 dist/autogen/wasm/*.wasm 4 개를 output 에 강제로 emit (asset 으로 등록)
|
|
20
|
+
* 2. lib 코드 안의 `new URL(<literal>, import.meta.url)` 패턴을 그대로 보존해서
|
|
21
|
+
* Webpack 의 URLDependency 처리가 정상 작동하도록
|
|
22
|
+
*
|
|
23
|
+
* 사용법:
|
|
24
|
+
* // webpack.config.js
|
|
25
|
+
* const { LocusWasmPlugin } = require('@locuschain/lib/webpack-plugin');
|
|
26
|
+
* module.exports = {
|
|
27
|
+
* plugins: [new LocusWasmPlugin()],
|
|
28
|
+
* // ... lib 의 ESM dist 를 Webpack 5 가 처리하도록
|
|
29
|
+
* experiments: { asyncWebAssembly: true, topLevelAwait: true }
|
|
30
|
+
* };
|
|
31
|
+
*
|
|
32
|
+
* 효과:
|
|
33
|
+
* - output 의 `<name>.<hash>.wasm` 으로 wasm 4 개가 emit 되고
|
|
34
|
+
* - 사용처는 `await loadLocusWasm()` (인자 없이) 호출만 하면 동작.
|
|
35
|
+
*/
|
|
36
|
+
const WASM_FILES = [
|
|
37
|
+
'lclib.wasm',
|
|
38
|
+
'crypto_aimer.wasm',
|
|
39
|
+
'crypto_smaugt.wasm',
|
|
40
|
+
'crypto_haetae.wasm'
|
|
41
|
+
];
|
|
42
|
+
// 이 모듈은 lib 패키지의 dist/webpack-plugin/index.{esm.js|cjs.cjs} 로 빌드된다.
|
|
43
|
+
const WASM_DIR = node_url.fileURLToPath(new URL('../autogen/wasm/', new URL(module.uri, document.baseURI).href));
|
|
44
|
+
class LocusWasmPlugin {
|
|
45
|
+
constructor(opts = {}) {
|
|
46
|
+
var _a;
|
|
47
|
+
this.outputDir = (_a = opts.outputDir) !== null && _a !== void 0 ? _a : 'assets';
|
|
48
|
+
}
|
|
49
|
+
apply(compiler) {
|
|
50
|
+
const pluginName = 'LocusWasmPlugin';
|
|
51
|
+
const { webpack } = compiler;
|
|
52
|
+
const { RawSource } = webpack.sources;
|
|
53
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
54
|
+
compilation.hooks.processAssets.tap({
|
|
55
|
+
name: pluginName,
|
|
56
|
+
// PROCESS_ASSETS_STAGE_ADDITIONAL: 기본 자산 emit 직후, optimization 전.
|
|
57
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
58
|
+
}, () => {
|
|
59
|
+
for (const filename of WASM_FILES) {
|
|
60
|
+
const filepath = path.join(WASM_DIR, filename);
|
|
61
|
+
if (!fs.existsSync(filepath)) {
|
|
62
|
+
compilation.errors.push(new webpack.WebpackError(`[LocusWasmPlugin] missing wasm asset: ${filepath}\n` +
|
|
63
|
+
`lib 가 정상적으로 빌드/설치되었는지 확인하세요.`));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const buf = fs.readFileSync(filepath);
|
|
67
|
+
const outPath = path.posix.join(this.outputDir, filename);
|
|
68
|
+
// 이미 같은 경로에 자산이 있다면 (Webpack 의 native URL processing 으로 등록됨)
|
|
69
|
+
// 중복 emit 을 피한다.
|
|
70
|
+
if (!compilation.getAsset(outPath)) {
|
|
71
|
+
compilation.emitAsset(outPath, new RawSource(buf));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// Webpack 의 native asset URL processing 이 lib 의 ESM dist 에 동작하도록 보조.
|
|
77
|
+
// 기본 module.parser.javascript.url 옵션을 명시적으로 활성화한다.
|
|
78
|
+
compiler.hooks.afterEnvironment.tap(pluginName, () => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const moduleConfig = compiler.options.module;
|
|
81
|
+
moduleConfig.parser = (_a = moduleConfig.parser) !== null && _a !== void 0 ? _a : {};
|
|
82
|
+
moduleConfig.parser.javascript = (_b = moduleConfig.parser.javascript) !== null && _b !== void 0 ? _b : {};
|
|
83
|
+
if (moduleConfig.parser.javascript.url === false) {
|
|
84
|
+
// 사용자가 명시적으로 끈 경우만 'relative' 로 강제 (lib 한정).
|
|
85
|
+
// 전역 활성화는 부작용이 클 수 있으니 false → relative 로만 완화.
|
|
86
|
+
moduleConfig.parser.javascript.url = 'relative';
|
|
87
|
+
}
|
|
88
|
+
else if (moduleConfig.parser.javascript.url === undefined) {
|
|
89
|
+
// 기본 활성화.
|
|
90
|
+
moduleConfig.parser.javascript.url = true;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
exports.LocusWasmPlugin = LocusWasmPlugin;
|
|
97
|
+
exports.default = LocusWasmPlugin;
|
|
98
|
+
|
|
99
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
100
|
+
|
|
101
|
+
}));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('node:fs');
|
|
6
|
+
var path = require('node:path');
|
|
7
|
+
var node_url = require('node:url');
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
/**
|
|
11
|
+
* @locuschain/lib/webpack-plugin
|
|
12
|
+
*
|
|
13
|
+
* Webpack 5 사용자가 lib 의 wasm 4 개를 자동으로 빌드 그래프에 포함시키도록 돕는 plugin.
|
|
14
|
+
*
|
|
15
|
+
* Webpack 5 는 기본적으로 `new URL(<literal>, import.meta.url)` 패턴을 인식해서
|
|
16
|
+
* asset/resource 모듈로 처리한다 — 따라서 대부분의 경우 lib 만 import 해도 wasm 이
|
|
17
|
+
* 자동으로 output 에 emit 된다.
|
|
18
|
+
*
|
|
19
|
+
* 다만 다음 환경에서 보장이 약해진다:
|
|
20
|
+
* - 사용처가 `module: { rules: [{ test: /\.wasm$/, type: 'javascript/auto' }] }` 같은
|
|
21
|
+
* override 를 두어 native asset 처리를 비활성화한 경우
|
|
22
|
+
* - import.meta.url 처리가 비활성화된 target (`target: 'web'` 외)
|
|
23
|
+
* - babel 등 다른 loader 가 패턴을 망가뜨리는 경우
|
|
24
|
+
*
|
|
25
|
+
* 이 plugin 은 다음을 보장한다:
|
|
26
|
+
* 1. lib 의 dist/autogen/wasm/*.wasm 4 개를 output 에 강제로 emit (asset 으로 등록)
|
|
27
|
+
* 2. lib 코드 안의 `new URL(<literal>, import.meta.url)` 패턴을 그대로 보존해서
|
|
28
|
+
* Webpack 의 URLDependency 처리가 정상 작동하도록
|
|
29
|
+
*
|
|
30
|
+
* 사용법:
|
|
31
|
+
* // webpack.config.js
|
|
32
|
+
* const { LocusWasmPlugin } = require('@locuschain/lib/webpack-plugin');
|
|
33
|
+
* module.exports = {
|
|
34
|
+
* plugins: [new LocusWasmPlugin()],
|
|
35
|
+
* // ... lib 의 ESM dist 를 Webpack 5 가 처리하도록
|
|
36
|
+
* experiments: { asyncWebAssembly: true, topLevelAwait: true }
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* 효과:
|
|
40
|
+
* - output 의 `<name>.<hash>.wasm` 으로 wasm 4 개가 emit 되고
|
|
41
|
+
* - 사용처는 `await loadLocusWasm()` (인자 없이) 호출만 하면 동작.
|
|
42
|
+
*/
|
|
43
|
+
const WASM_FILES = [
|
|
44
|
+
'lclib.wasm',
|
|
45
|
+
'crypto_aimer.wasm',
|
|
46
|
+
'crypto_smaugt.wasm',
|
|
47
|
+
'crypto_haetae.wasm'
|
|
48
|
+
];
|
|
49
|
+
// 이 모듈은 lib 패키지의 dist/webpack-plugin/index.{esm.js|cjs.cjs} 로 빌드된다.
|
|
50
|
+
const WASM_DIR = node_url.fileURLToPath(new URL('../autogen/wasm/', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('webpack-plugin/index.cjs.cjs', document.baseURI).href))));
|
|
51
|
+
class LocusWasmPlugin {
|
|
52
|
+
constructor(opts = {}) {
|
|
53
|
+
var _a;
|
|
54
|
+
this.outputDir = (_a = opts.outputDir) !== null && _a !== void 0 ? _a : 'assets';
|
|
55
|
+
}
|
|
56
|
+
apply(compiler) {
|
|
57
|
+
const pluginName = 'LocusWasmPlugin';
|
|
58
|
+
const { webpack } = compiler;
|
|
59
|
+
const { RawSource } = webpack.sources;
|
|
60
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
61
|
+
compilation.hooks.processAssets.tap({
|
|
62
|
+
name: pluginName,
|
|
63
|
+
// PROCESS_ASSETS_STAGE_ADDITIONAL: 기본 자산 emit 직후, optimization 전.
|
|
64
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
65
|
+
}, () => {
|
|
66
|
+
for (const filename of WASM_FILES) {
|
|
67
|
+
const filepath = path.join(WASM_DIR, filename);
|
|
68
|
+
if (!fs.existsSync(filepath)) {
|
|
69
|
+
compilation.errors.push(new webpack.WebpackError(`[LocusWasmPlugin] missing wasm asset: ${filepath}\n` +
|
|
70
|
+
`lib 가 정상적으로 빌드/설치되었는지 확인하세요.`));
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const buf = fs.readFileSync(filepath);
|
|
74
|
+
const outPath = path.posix.join(this.outputDir, filename);
|
|
75
|
+
// 이미 같은 경로에 자산이 있다면 (Webpack 의 native URL processing 으로 등록됨)
|
|
76
|
+
// 중복 emit 을 피한다.
|
|
77
|
+
if (!compilation.getAsset(outPath)) {
|
|
78
|
+
compilation.emitAsset(outPath, new RawSource(buf));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
// Webpack 의 native asset URL processing 이 lib 의 ESM dist 에 동작하도록 보조.
|
|
84
|
+
// 기본 module.parser.javascript.url 옵션을 명시적으로 활성화한다.
|
|
85
|
+
compiler.hooks.afterEnvironment.tap(pluginName, () => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
const moduleConfig = compiler.options.module;
|
|
88
|
+
moduleConfig.parser = (_a = moduleConfig.parser) !== null && _a !== void 0 ? _a : {};
|
|
89
|
+
moduleConfig.parser.javascript = (_b = moduleConfig.parser.javascript) !== null && _b !== void 0 ? _b : {};
|
|
90
|
+
if (moduleConfig.parser.javascript.url === false) {
|
|
91
|
+
// 사용자가 명시적으로 끈 경우만 'relative' 로 강제 (lib 한정).
|
|
92
|
+
// 전역 활성화는 부작용이 클 수 있으니 false → relative 로만 완화.
|
|
93
|
+
moduleConfig.parser.javascript.url = 'relative';
|
|
94
|
+
}
|
|
95
|
+
else if (moduleConfig.parser.javascript.url === undefined) {
|
|
96
|
+
// 기본 활성화.
|
|
97
|
+
moduleConfig.parser.javascript.url = true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.LocusWasmPlugin = LocusWasmPlugin;
|
|
104
|
+
exports.default = LocusWasmPlugin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @locuschain/lib/webpack-plugin
|
|
3
|
+
*
|
|
4
|
+
* Webpack 5 사용자가 lib 의 wasm 4 개를 자동으로 빌드 그래프에 포함시키도록 돕는 plugin.
|
|
5
|
+
*
|
|
6
|
+
* Webpack 5 는 기본적으로 `new URL(<literal>, import.meta.url)` 패턴을 인식해서
|
|
7
|
+
* asset/resource 모듈로 처리한다 — 따라서 대부분의 경우 lib 만 import 해도 wasm 이
|
|
8
|
+
* 자동으로 output 에 emit 된다.
|
|
9
|
+
*
|
|
10
|
+
* 다만 다음 환경에서 보장이 약해진다:
|
|
11
|
+
* - 사용처가 `module: { rules: [{ test: /\.wasm$/, type: 'javascript/auto' }] }` 같은
|
|
12
|
+
* override 를 두어 native asset 처리를 비활성화한 경우
|
|
13
|
+
* - import.meta.url 처리가 비활성화된 target (`target: 'web'` 외)
|
|
14
|
+
* - babel 등 다른 loader 가 패턴을 망가뜨리는 경우
|
|
15
|
+
*
|
|
16
|
+
* 이 plugin 은 다음을 보장한다:
|
|
17
|
+
* 1. lib 의 dist/autogen/wasm/*.wasm 4 개를 output 에 강제로 emit (asset 으로 등록)
|
|
18
|
+
* 2. lib 코드 안의 `new URL(<literal>, import.meta.url)` 패턴을 그대로 보존해서
|
|
19
|
+
* Webpack 의 URLDependency 처리가 정상 작동하도록
|
|
20
|
+
*
|
|
21
|
+
* 사용법:
|
|
22
|
+
* // webpack.config.js
|
|
23
|
+
* const { LocusWasmPlugin } = require('@locuschain/lib/webpack-plugin');
|
|
24
|
+
* module.exports = {
|
|
25
|
+
* plugins: [new LocusWasmPlugin()],
|
|
26
|
+
* // ... lib 의 ESM dist 를 Webpack 5 가 처리하도록
|
|
27
|
+
* experiments: { asyncWebAssembly: true, topLevelAwait: true }
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* 효과:
|
|
31
|
+
* - output 의 `<name>.<hash>.wasm` 으로 wasm 4 개가 emit 되고
|
|
32
|
+
* - 사용처는 `await loadLocusWasm()` (인자 없이) 호출만 하면 동작.
|
|
33
|
+
*/
|
|
34
|
+
import type { Compiler } from 'webpack';
|
|
35
|
+
export interface LocusWasmPluginOptions {
|
|
36
|
+
/**
|
|
37
|
+
* 출력 디렉토리 prefix. 기본은 `assets/`.
|
|
38
|
+
*/
|
|
39
|
+
outputDir?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class LocusWasmPlugin {
|
|
42
|
+
private readonly outputDir;
|
|
43
|
+
constructor(opts?: LocusWasmPluginOptions);
|
|
44
|
+
apply(compiler: Compiler): void;
|
|
45
|
+
}
|
|
46
|
+
export default LocusWasmPlugin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @locuschain/lib/webpack-plugin
|
|
3
|
+
*
|
|
4
|
+
* Webpack 5 사용자가 lib 의 wasm 4 개를 자동으로 빌드 그래프에 포함시키도록 돕는 plugin.
|
|
5
|
+
*
|
|
6
|
+
* Webpack 5 는 기본적으로 `new URL(<literal>, import.meta.url)` 패턴을 인식해서
|
|
7
|
+
* asset/resource 모듈로 처리한다 — 따라서 대부분의 경우 lib 만 import 해도 wasm 이
|
|
8
|
+
* 자동으로 output 에 emit 된다.
|
|
9
|
+
*
|
|
10
|
+
* 다만 다음 환경에서 보장이 약해진다:
|
|
11
|
+
* - 사용처가 `module: { rules: [{ test: /\.wasm$/, type: 'javascript/auto' }] }` 같은
|
|
12
|
+
* override 를 두어 native asset 처리를 비활성화한 경우
|
|
13
|
+
* - import.meta.url 처리가 비활성화된 target (`target: 'web'` 외)
|
|
14
|
+
* - babel 등 다른 loader 가 패턴을 망가뜨리는 경우
|
|
15
|
+
*
|
|
16
|
+
* 이 plugin 은 다음을 보장한다:
|
|
17
|
+
* 1. lib 의 dist/autogen/wasm/*.wasm 4 개를 output 에 강제로 emit (asset 으로 등록)
|
|
18
|
+
* 2. lib 코드 안의 `new URL(<literal>, import.meta.url)` 패턴을 그대로 보존해서
|
|
19
|
+
* Webpack 의 URLDependency 처리가 정상 작동하도록
|
|
20
|
+
*
|
|
21
|
+
* 사용법:
|
|
22
|
+
* // webpack.config.js
|
|
23
|
+
* const { LocusWasmPlugin } = require('@locuschain/lib/webpack-plugin');
|
|
24
|
+
* module.exports = {
|
|
25
|
+
* plugins: [new LocusWasmPlugin()],
|
|
26
|
+
* // ... lib 의 ESM dist 를 Webpack 5 가 처리하도록
|
|
27
|
+
* experiments: { asyncWebAssembly: true, topLevelAwait: true }
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* 효과:
|
|
31
|
+
* - output 의 `<name>.<hash>.wasm` 으로 wasm 4 개가 emit 되고
|
|
32
|
+
* - 사용처는 `await loadLocusWasm()` (인자 없이) 호출만 하면 동작.
|
|
33
|
+
*/
|
|
34
|
+
import type { Compiler } from 'webpack';
|
|
35
|
+
export interface LocusWasmPluginOptions {
|
|
36
|
+
/**
|
|
37
|
+
* 출력 디렉토리 prefix. 기본은 `assets/`.
|
|
38
|
+
*/
|
|
39
|
+
outputDir?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class LocusWasmPlugin {
|
|
42
|
+
private readonly outputDir;
|
|
43
|
+
constructor(opts?: LocusWasmPluginOptions);
|
|
44
|
+
apply(compiler: Compiler): void;
|
|
45
|
+
}
|
|
46
|
+
export default LocusWasmPlugin;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @locuschain/lib/webpack-plugin
|
|
7
|
+
*
|
|
8
|
+
* Webpack 5 사용자가 lib 의 wasm 4 개를 자동으로 빌드 그래프에 포함시키도록 돕는 plugin.
|
|
9
|
+
*
|
|
10
|
+
* Webpack 5 는 기본적으로 `new URL(<literal>, import.meta.url)` 패턴을 인식해서
|
|
11
|
+
* asset/resource 모듈로 처리한다 — 따라서 대부분의 경우 lib 만 import 해도 wasm 이
|
|
12
|
+
* 자동으로 output 에 emit 된다.
|
|
13
|
+
*
|
|
14
|
+
* 다만 다음 환경에서 보장이 약해진다:
|
|
15
|
+
* - 사용처가 `module: { rules: [{ test: /\.wasm$/, type: 'javascript/auto' }] }` 같은
|
|
16
|
+
* override 를 두어 native asset 처리를 비활성화한 경우
|
|
17
|
+
* - import.meta.url 처리가 비활성화된 target (`target: 'web'` 외)
|
|
18
|
+
* - babel 등 다른 loader 가 패턴을 망가뜨리는 경우
|
|
19
|
+
*
|
|
20
|
+
* 이 plugin 은 다음을 보장한다:
|
|
21
|
+
* 1. lib 의 dist/autogen/wasm/*.wasm 4 개를 output 에 강제로 emit (asset 으로 등록)
|
|
22
|
+
* 2. lib 코드 안의 `new URL(<literal>, import.meta.url)` 패턴을 그대로 보존해서
|
|
23
|
+
* Webpack 의 URLDependency 처리가 정상 작동하도록
|
|
24
|
+
*
|
|
25
|
+
* 사용법:
|
|
26
|
+
* // webpack.config.js
|
|
27
|
+
* const { LocusWasmPlugin } = require('@locuschain/lib/webpack-plugin');
|
|
28
|
+
* module.exports = {
|
|
29
|
+
* plugins: [new LocusWasmPlugin()],
|
|
30
|
+
* // ... lib 의 ESM dist 를 Webpack 5 가 처리하도록
|
|
31
|
+
* experiments: { asyncWebAssembly: true, topLevelAwait: true }
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* 효과:
|
|
35
|
+
* - output 의 `<name>.<hash>.wasm` 으로 wasm 4 개가 emit 되고
|
|
36
|
+
* - 사용처는 `await loadLocusWasm()` (인자 없이) 호출만 하면 동작.
|
|
37
|
+
*/
|
|
38
|
+
const WASM_FILES = [
|
|
39
|
+
'lclib.wasm',
|
|
40
|
+
'crypto_aimer.wasm',
|
|
41
|
+
'crypto_smaugt.wasm',
|
|
42
|
+
'crypto_haetae.wasm'
|
|
43
|
+
];
|
|
44
|
+
// 이 모듈은 lib 패키지의 dist/webpack-plugin/index.{esm.js|cjs.cjs} 로 빌드된다.
|
|
45
|
+
const WASM_DIR = fileURLToPath(new URL('../autogen/wasm/', import.meta.url));
|
|
46
|
+
class LocusWasmPlugin {
|
|
47
|
+
constructor(opts = {}) {
|
|
48
|
+
var _a;
|
|
49
|
+
this.outputDir = (_a = opts.outputDir) !== null && _a !== void 0 ? _a : 'assets';
|
|
50
|
+
}
|
|
51
|
+
apply(compiler) {
|
|
52
|
+
const pluginName = 'LocusWasmPlugin';
|
|
53
|
+
const { webpack } = compiler;
|
|
54
|
+
const { RawSource } = webpack.sources;
|
|
55
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
56
|
+
compilation.hooks.processAssets.tap({
|
|
57
|
+
name: pluginName,
|
|
58
|
+
// PROCESS_ASSETS_STAGE_ADDITIONAL: 기본 자산 emit 직후, optimization 전.
|
|
59
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
60
|
+
}, () => {
|
|
61
|
+
for (const filename of WASM_FILES) {
|
|
62
|
+
const filepath = path.join(WASM_DIR, filename);
|
|
63
|
+
if (!fs.existsSync(filepath)) {
|
|
64
|
+
compilation.errors.push(new webpack.WebpackError(`[LocusWasmPlugin] missing wasm asset: ${filepath}\n` +
|
|
65
|
+
`lib 가 정상적으로 빌드/설치되었는지 확인하세요.`));
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const buf = fs.readFileSync(filepath);
|
|
69
|
+
const outPath = path.posix.join(this.outputDir, filename);
|
|
70
|
+
// 이미 같은 경로에 자산이 있다면 (Webpack 의 native URL processing 으로 등록됨)
|
|
71
|
+
// 중복 emit 을 피한다.
|
|
72
|
+
if (!compilation.getAsset(outPath)) {
|
|
73
|
+
compilation.emitAsset(outPath, new RawSource(buf));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
// Webpack 의 native asset URL processing 이 lib 의 ESM dist 에 동작하도록 보조.
|
|
79
|
+
// 기본 module.parser.javascript.url 옵션을 명시적으로 활성화한다.
|
|
80
|
+
compiler.hooks.afterEnvironment.tap(pluginName, () => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const moduleConfig = compiler.options.module;
|
|
83
|
+
moduleConfig.parser = (_a = moduleConfig.parser) !== null && _a !== void 0 ? _a : {};
|
|
84
|
+
moduleConfig.parser.javascript = (_b = moduleConfig.parser.javascript) !== null && _b !== void 0 ? _b : {};
|
|
85
|
+
if (moduleConfig.parser.javascript.url === false) {
|
|
86
|
+
// 사용자가 명시적으로 끈 경우만 'relative' 로 강제 (lib 한정).
|
|
87
|
+
// 전역 활성화는 부작용이 클 수 있으니 false → relative 로만 완화.
|
|
88
|
+
moduleConfig.parser.javascript.url = 'relative';
|
|
89
|
+
}
|
|
90
|
+
else if (moduleConfig.parser.javascript.url === undefined) {
|
|
91
|
+
// 기본 활성화.
|
|
92
|
+
moduleConfig.parser.javascript.url = true;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { LocusWasmPlugin, LocusWasmPlugin as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@locuschain/lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "bloomtechnology",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
"node": "~22.19.0"
|
|
10
10
|
},
|
|
11
11
|
"main": "./dist/index.cjs.cjs",
|
|
12
|
-
"module": "./dist/index.
|
|
13
|
-
"unpkg": "./dist/umd/index.umd.js",
|
|
14
|
-
"jsdelivr": "./dist/umd/index.umd.js",
|
|
12
|
+
"module": "./dist/index.amd.js",
|
|
15
13
|
"types": "./dist/index.d.mts",
|
|
16
14
|
"exports": {
|
|
17
15
|
".": {
|
|
@@ -91,6 +89,22 @@
|
|
|
91
89
|
},
|
|
92
90
|
"import": "./dist/constant/index.esm.js",
|
|
93
91
|
"require": "./dist/constant/index.cjs.cjs"
|
|
92
|
+
},
|
|
93
|
+
"./vite-plugin": {
|
|
94
|
+
"types": {
|
|
95
|
+
"require": "./dist/vite-plugin/index.d.cjs",
|
|
96
|
+
"import": "./dist/vite-plugin/index.d.mjs"
|
|
97
|
+
},
|
|
98
|
+
"import": "./dist/vite-plugin/index.esm.js",
|
|
99
|
+
"require": "./dist/vite-plugin/index.cjs.cjs"
|
|
100
|
+
},
|
|
101
|
+
"./webpack-plugin": {
|
|
102
|
+
"types": {
|
|
103
|
+
"require": "./dist/webpack-plugin/index.d.cjs",
|
|
104
|
+
"import": "./dist/webpack-plugin/index.d.mjs"
|
|
105
|
+
},
|
|
106
|
+
"import": "./dist/webpack-plugin/index.esm.js",
|
|
107
|
+
"require": "./dist/webpack-plugin/index.cjs.cjs"
|
|
94
108
|
}
|
|
95
109
|
},
|
|
96
110
|
"files": [
|
|
@@ -101,18 +115,34 @@
|
|
|
101
115
|
"@rollup/plugin-json": "^6.1.0",
|
|
102
116
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
103
117
|
"@rollup/plugin-typescript": "^12.1.1",
|
|
118
|
+
"@types/node": "^22.15.0",
|
|
119
|
+
"@types/webpack": "^5.28.5",
|
|
104
120
|
"copyfiles": "^2.4.1",
|
|
105
121
|
"rollup": "^4.24.3",
|
|
106
122
|
"rollup-plugin-copy": "^3.5.0",
|
|
107
|
-
"tslib": "^2.8.1"
|
|
123
|
+
"tslib": "^2.8.1",
|
|
124
|
+
"vite": "^7.0.0",
|
|
125
|
+
"webpack": "^5.95.0"
|
|
108
126
|
},
|
|
109
127
|
"dependencies": {
|
|
110
128
|
"wasm-opt": "^1.4.0",
|
|
111
129
|
"@locuschain/errors": "1.1.0"
|
|
112
130
|
},
|
|
131
|
+
"peerDependencies": {
|
|
132
|
+
"vite": ">=5.0.0",
|
|
133
|
+
"webpack": ">=5.0.0"
|
|
134
|
+
},
|
|
135
|
+
"peerDependenciesMeta": {
|
|
136
|
+
"vite": {
|
|
137
|
+
"optional": true
|
|
138
|
+
},
|
|
139
|
+
"webpack": {
|
|
140
|
+
"optional": true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
113
143
|
"scripts": {
|
|
114
144
|
"generate-code": "./generate-code.sh",
|
|
115
|
-
"build": "rm -rf dist && rollup -c rollup.config.mjs && node -e \"const fs=require('fs'); const paths=['clients','transports','accounts','errors','contracts','types','utils','constant','autogen']; paths.forEach(p => { const base='./dist/'+p+'/index'; if(fs.existsSync(base+'.d.mts')){ fs.copyFileSync(base+'.d.mts', base+'.d.cts'); } })\"",
|
|
145
|
+
"build": "rm -rf dist && rollup -c rollup.config.mjs && node -e \"const fs=require('fs'); const paths=['clients','transports','accounts','errors','contracts','types','utils','constant','autogen','vite-plugin','webpack-plugin']; paths.forEach(p => { const base='./dist/'+p+'/index'; if(fs.existsSync(base+'.d.mts')){ fs.copyFileSync(base+'.d.mts', base+'.d.cts'); } })\"",
|
|
116
146
|
"gen-build-publish": "npm run generate-code && npm run build && npm publish --access public"
|
|
117
147
|
}
|
|
118
148
|
}
|
package/dist/index.umd.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './clients/index.mjs';
|
|
2
|
-
export * from './transports/index.mjs';
|
|
3
|
-
export * from './accounts/index.mjs';
|
|
4
|
-
export * from './errors/index.mjs';
|
|
5
|
-
export * from './contracts/index.mjs';
|
|
6
|
-
export * from './constant/index.mjs';
|
|
7
|
-
export * from './types/index.mjs';
|
|
8
|
-
export * from './utils/index.mjs';
|
|
9
|
-
export * from './autogen/rpc-api-spec.mjs';
|
|
10
|
-
export * from './autogen/locus-tx.mjs';
|
|
11
|
-
export * from './autogen/publicActions.mjs';
|
|
12
|
-
export * from './autogen/walletActions.mjs';
|
|
13
|
-
export * from './autogen/debugPublicActions.mjs';
|
|
14
|
-
export * from './autogen/debugWalletActions.mjs';
|
|
15
|
-
export * from './autogen/actions/index.mjs';
|