@deveco-test/deveco-cli 1.3.0-Test.100-tmp → 1.3.0-Test.11

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.
@@ -1,102 +0,0 @@
1
- /*
2
- * Copyright (c) 2026 Huawei Device Co., Ltd.
3
- * SPDX-License-Identifier: MIT
4
- */
5
-
6
- import { dirname, join } from 'path';
7
- import { existsSync } from 'fs';
8
- import { spawnSync } from 'child_process';
9
- import { fileURLToPath } from 'url';
10
- import { packageRoot } from './better-sqlite3-vendor.mjs';
11
-
12
- const JIEBA_WASM_VERSION = '2.0.1';
13
-
14
- function resolveNpmCliPath() {
15
- const nodeDir = dirname(process.execPath);
16
- const candidates = [
17
- join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
18
- join(nodeDir, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'),
19
- ];
20
- return candidates.find((candidate) => existsSync(candidate)) ?? null;
21
- }
22
-
23
- function quoteWindowsCmdArg(arg) {
24
- return /\s/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
25
- }
26
-
27
- function spawnDetail(result) {
28
- return [result.stderr, result.stdout, result.error?.message]
29
- .filter(Boolean)
30
- .join('\n')
31
- .trim();
32
- }
33
-
34
- function runNpmInstallJiebaWasm(targetVersion) {
35
- const args = [
36
- 'install',
37
- `@node-rs/jieba-wasm32-wasi@${targetVersion}`,
38
- '--no-save',
39
- '--cpu=wasm32',
40
- ];
41
- const npmCli = resolveNpmCliPath();
42
- if (npmCli) {
43
- return spawnSync(process.execPath, [npmCli, ...args], {
44
- cwd: packageRoot,
45
- stdio: 'pipe',
46
- encoding: 'utf-8',
47
- });
48
- }
49
- if (process.platform === 'win32') {
50
- const command = ['npm', ...args].map(quoteWindowsCmdArg).join(' ');
51
- return spawnSync(command, {
52
- cwd: packageRoot,
53
- stdio: 'pipe',
54
- encoding: 'utf-8',
55
- shell: true,
56
- });
57
- }
58
- return spawnSync('npm', args, {
59
- cwd: packageRoot,
60
- stdio: 'pipe',
61
- encoding: 'utf-8',
62
- });
63
- }
64
-
65
- export async function installJiebaWasmViaNpm(targetVersion = JIEBA_WASM_VERSION) {
66
- try {
67
- await import('@node-rs/jieba-wasm32-wasi');
68
- return { ok: true, skipped: true, reason: 'already-installed' };
69
- } catch {
70
- // continue — try native or install wasm
71
- }
72
-
73
- try {
74
- await import('@node-rs/jieba');
75
- return { ok: true, skipped: true, reason: 'native-available' };
76
- } catch {
77
- // continue — install wasm fallback
78
- }
79
-
80
- const result = runNpmInstallJiebaWasm(targetVersion);
81
- if (result.status !== 0) {
82
- return {
83
- ok: false,
84
- reason: 'npm-install-failed',
85
- version: targetVersion,
86
- error: spawnDetail(result) || `exit ${result.status ?? 'null'}`,
87
- };
88
- }
89
-
90
- try {
91
- await import('@node-rs/jieba-wasm32-wasi');
92
- } catch {
93
- return {
94
- ok: false,
95
- reason: 'load-failed',
96
- version: targetVersion,
97
- error:
98
- 'npm install finished but @node-rs/jieba-wasm32-wasi still cannot be imported',
99
- };
100
- }
101
- return { ok: true, version: targetVersion, method: 'npm' };
102
- }