@deveco-test/deveco-code 0.2.0-Test → 0.2.1-5

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/CHANGELOG.md CHANGED
File without changes
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -241,7 +241,6 @@ DevEco Code 集成了常用 HarmonyOS 开发工具能力:
241
241
  | `hdc_log` | 收集/清理设备日志/查看连接模拟器 |
242
242
  | `verify_ui` | 执行 UI 操作验证功能是否正确 |
243
243
  | `arkts_check` | ArkTS 静态语法检查 |
244
- | `arkts_knowledge_search` | HarmonyOS 知识搜索 |
245
244
  | `switch_cwd` | 切换构建项目路径 |
246
245
 
247
246
  常见场景包括:从零到一创建 HarmonyOS 工程、增量开发页面、修复编译报错、真机调试。
package/bin/deveco.exe ADDED
@@ -0,0 +1,10 @@
1
+ echo "Error: deveco-ai's postinstall script was not run." >&2
2
+ echo "" >&2
3
+ echo "This occurs when using --ignore-scripts during installation, or when using a" >&2
4
+ echo "package manager like pnpm that does not run postinstall scripts by default." >&2
5
+ echo "" >&2
6
+ echo "To fix this, run the postinstall script manually:" >&2
7
+ echo " cd node_modules/deveco-ai && node postinstall.mjs" >&2
8
+ echo "" >&2
9
+ echo "Or reinstall deveco-ai without the --ignore-scripts flag." >&2
10
+ exit 1
package/package.json CHANGED
@@ -1,13 +1,22 @@
1
1
  {
2
2
  "name": "@deveco-test/deveco-code",
3
3
  "bin": {
4
- "deveco": "./bin/deveco"
4
+ "deveco": "./bin/deveco.exe"
5
5
  },
6
6
  "scripts": {
7
- "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
7
+ "postinstall": "node ./postinstall.mjs"
8
8
  },
9
- "version": "0.2.0-Test",
9
+ "version": "0.2.1-5",
10
10
  "license": "MIT",
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "arm64",
18
+ "x64"
19
+ ],
11
20
  "files": [
12
21
  "bin/**/*",
13
22
  "postinstall.mjs",
@@ -16,9 +25,12 @@
16
25
  "CHANGELOG.md"
17
26
  ],
18
27
  "optionalDependencies": {
19
- "@deveco-test/deveco-code-windows-x64": "0.2.0-Test",
20
- "@deveco-test/deveco-code-darwin-x64": "0.2.0-Test",
21
- "@deveco-test/deveco-code-darwin-arm64": "0.2.0-Test",
22
- "@deveco-test/deveco-code-windows-x64-baseline": "0.2.0-Test"
28
+ "@deveco-test/deveco-code-darwin-x64": "0.2.1-5",
29
+ "@deveco-test/deveco-code-darwin-arm64": "0.2.1-5",
30
+ "@deveco-test/deveco-code-windows-x64-baseline": "0.2.1-5",
31
+ "@deveco-test/deveco-code-windows-x64": "0.2.1-5"
32
+ },
33
+ "dependencies": {
34
+ "@deveco/deveco-cli": "1.3.0-stable"
23
35
  }
24
36
  }
package/postinstall.mjs CHANGED
@@ -24,9 +24,24 @@ const archMap = {
24
24
 
25
25
  const platform = platformMap[os.platform()] ?? os.platform()
26
26
  const arch = archMap[os.arch()] ?? os.arch()
27
- const base = `@deveco-test/deveco-code-${platform}-${arch}`
27
+ const scope = packageJson.name && packageJson.name.includes("/") ? packageJson.name.split("/")[0] : "@deveco"
28
+ const base = `${scope}/deveco-code-${platform}-${arch}`
28
29
  const sourceBinary = platform === "windows" ? "deveco.exe" : "deveco"
29
30
  const targetBinary = path.join(__dirname, "bin", "deveco.exe")
31
+ const devecoCliEntryMarker = path.join(__dirname, "vendor", ".deveco-cli-entry")
32
+ const devecoCliPackageName = "@deveco/deveco-cli"
33
+
34
+ function resolveLocalDevecoCliEntry() {
35
+ const packageJsonPath = require.resolve(`${devecoCliPackageName}/package.json`)
36
+ const entry = path.join(path.dirname(packageJsonPath), "dist", "cli.js")
37
+ if (fs.existsSync(entry)) return entry
38
+ throw new Error(`Local dependency "${devecoCliPackageName}" has no CLI entry at ${entry}.`)
39
+ }
40
+
41
+ function writeDevecoCliEntryMarker() {
42
+ fs.mkdirSync(path.dirname(devecoCliEntryMarker), { recursive: true })
43
+ fs.writeFileSync(devecoCliEntryMarker, `${resolveLocalDevecoCliEntry()}\n`, "utf8")
44
+ }
30
45
 
31
46
  function supportsAvx2() {
32
47
  if (arch !== "x64") return false
@@ -148,24 +163,42 @@ function copyVendor(packageDir) {
148
163
  const vendorDst = path.join(__dirname, "vendor")
149
164
  if (fs.existsSync(vendorSrc)) {
150
165
  copyDir(vendorSrc, vendorDst)
151
- restoreDevecoCliDeps(path.join(vendorDst, "deveco-cli"))
152
- restoreDevecoCliDeps(path.join(packageDir, "vendor", "deveco-cli"))
166
+ // Windows packs often drop Unix +x; force it back on macOS/Linux install.
167
+ ensureVendorExecutables(vendorDst)
168
+ ensureVendorExecutables(path.join(packageDir, "vendor"))
153
169
  }
154
170
  }
155
171
 
156
- function restoreDevecoCliDeps(cliDir) {
157
- const tarPath = path.join(cliDir, "deps.tar.gz")
158
- if (!fs.existsSync(tarPath)) return
159
- const result = childProcess.spawnSync("tar", ["-xzf", tarPath, "-C", cliDir], {
160
- stdio: "inherit",
161
- windowsHide: true,
162
- shell: true,
163
- })
164
- if (result.status !== 0) {
165
- console.warn("Warning: failed to restore deveco-cli dependencies")
166
- return
172
+ /** Restore execute bits lost when packages are built/published from Windows. */
173
+ function ensureVendorExecutables(vendorRoot) {
174
+ if (process.platform === "win32" || !fs.existsSync(vendorRoot)) return
175
+
176
+ const stack = [vendorRoot]
177
+ while (stack.length > 0) {
178
+ const dir = stack.pop()
179
+ let entries
180
+ try {
181
+ entries = fs.readdirSync(dir, { withFileTypes: true })
182
+ } catch {
183
+ continue
184
+ }
185
+ for (const entry of entries) {
186
+ const full = path.join(dir, entry.name)
187
+ if (entry.isDirectory()) {
188
+ stack.push(full)
189
+ continue
190
+ }
191
+ if (!entry.isFile()) continue
192
+ // Top-level vendor/ripgrep/rg and nested @vscode/ripgrep*/**/rg
193
+ if (entry.name === "rg") {
194
+ try {
195
+ fs.chmodSync(full, 0o755)
196
+ } catch {
197
+ // Best-effort; ignore files we cannot chmod.
198
+ }
199
+ }
200
+ }
167
201
  }
168
- fs.unlinkSync(tarPath)
169
202
  }
170
203
 
171
204
  function installPackage(name) {
@@ -211,6 +244,8 @@ function verifyBinary() {
211
244
  }
212
245
 
213
246
  function main() {
247
+ writeDevecoCliEntryMarker()
248
+
214
249
  for (const name of packageNames()) {
215
250
  try {
216
251
  copyBinary(resolveBinary(name), targetBinary)
package/bin/deveco DELETED
@@ -1,199 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const childProcess = require("child_process")
4
- const fs = require("fs")
5
- const path = require("path")
6
- const os = require("os")
7
-
8
- const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"]
9
-
10
- function run(target) {
11
- const child = childProcess.spawn(target, process.argv.slice(2), {
12
- stdio: "inherit",
13
- })
14
-
15
- child.on("error", (error) => {
16
- console.error(error.message)
17
- process.exit(1)
18
- })
19
-
20
- const forwarders = {}
21
- for (const signal of forwardedSignals) {
22
- forwarders[signal] = () => {
23
- try {
24
- child.kill(signal)
25
- } catch {
26
- // The child may have already exited.
27
- }
28
- }
29
- process.on(signal, forwarders[signal])
30
- }
31
-
32
- child.on("exit", (code, signal) => {
33
- for (const forwardedSignal of forwardedSignals) {
34
- process.removeListener(forwardedSignal, forwarders[forwardedSignal])
35
- }
36
-
37
- if (signal) {
38
- process.kill(process.pid, signal)
39
- return
40
- }
41
-
42
- process.exit(typeof code === "number" ? code : 0)
43
- })
44
- }
45
-
46
- const envPath = process.env.DEVECO_BIN_PATH
47
-
48
- const scriptPath = fs.realpathSync(__filename)
49
- const scriptDir = path.dirname(scriptPath)
50
-
51
- //
52
- const cached = path.join(scriptDir, ".deveco")
53
-
54
- const platformMap = {
55
- darwin: "darwin",
56
- linux: "linux",
57
- win32: "windows",
58
- }
59
- const archMap = {
60
- x64: "x64",
61
- arm64: "arm64",
62
- arm: "arm",
63
- }
64
-
65
- let platform = platformMap[os.platform()]
66
- if (!platform) {
67
- platform = os.platform()
68
- }
69
- let arch = archMap[os.arch()]
70
- if (!arch) {
71
- arch = os.arch()
72
- }
73
- const base = "@deveco-test/deveco-code-" + platform + "-" + arch
74
- const binary = platform === "windows" ? "deveco.exe" : "deveco"
75
-
76
- function supportsAvx2() {
77
- if (arch !== "x64") return false
78
-
79
- if (platform === "linux") {
80
- try {
81
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
82
- } catch {
83
- return false
84
- }
85
- }
86
-
87
- if (platform === "darwin") {
88
- try {
89
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
90
- encoding: "utf8",
91
- timeout: 1500,
92
- })
93
- if (result.status !== 0) return false
94
- return (result.stdout || "").trim() === "1"
95
- } catch {
96
- return false
97
- }
98
- }
99
-
100
- if (platform === "windows") {
101
- const cmd =
102
- '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
103
-
104
- for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
105
- try {
106
- const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
107
- encoding: "utf8",
108
- timeout: 3000,
109
- windowsHide: true,
110
- })
111
- if (result.status !== 0) continue
112
- const out = (result.stdout || "").trim().toLowerCase()
113
- if (out === "true" || out === "1") return true
114
- if (out === "false" || out === "0") return false
115
- } catch {
116
- continue
117
- }
118
- }
119
-
120
- return false
121
- }
122
-
123
- return false
124
- }
125
-
126
- const names = (() => {
127
- const avx2 = supportsAvx2()
128
- const baseline = arch === "x64" && !avx2
129
-
130
- if (platform === "linux") {
131
- const musl = (() => {
132
- try {
133
- if (fs.existsSync("/etc/alpine-release")) return true
134
- } catch {
135
- // ignore
136
- }
137
-
138
- try {
139
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
140
- const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
141
- if (text.includes("musl")) return true
142
- } catch {
143
- // ignore
144
- }
145
-
146
- return false
147
- })()
148
-
149
- if (musl) {
150
- if (arch === "x64") {
151
- if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
152
- return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
153
- }
154
- return [`${base}-musl`, base]
155
- }
156
-
157
- if (arch === "x64") {
158
- if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
159
- return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
160
- }
161
- return [base, `${base}-musl`]
162
- }
163
-
164
- if (arch === "x64") {
165
- if (baseline) return [`${base}-baseline`, base]
166
- return [base, `${base}-baseline`]
167
- }
168
- return [base]
169
- })()
170
-
171
- function findBinary(startDir) {
172
- let current = startDir
173
- for (;;) {
174
- const modules = path.join(current, "node_modules")
175
- if (fs.existsSync(modules)) {
176
- for (const name of names) {
177
- const candidate = path.join(modules, name, "bin", binary)
178
- if (fs.existsSync(candidate)) return candidate
179
- }
180
- }
181
- const parent = path.dirname(current)
182
- if (parent === current) {
183
- return
184
- }
185
- current = parent
186
- }
187
- }
188
-
189
- const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
190
- if (!resolved) {
191
- console.error(
192
- "It seems that your package manager failed to install the right version of the deveco CLI for your platform. You can try manually installing " +
193
- names.map((n) => `\"${n}\"`).join(" or ") +
194
- " package",
195
- )
196
- process.exit(1)
197
- }
198
-
199
- run(resolved)