@deveco-test/deveco-code 1.10.31 → 1.10.33

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/bin/deveco CHANGED
@@ -76,9 +76,34 @@ try {
76
76
  } catch {
77
77
  // dev mode or missing package.json
78
78
  }
79
+ // Mirrors script/postinstall.mjs isOhos(): OHOS PCs report linux/arm64 (or
80
+ // openharmony) but need the cross-built hmos artifact.
81
+ function isOhos() {
82
+ if (os.platform() === "openharmony") return true
83
+ if (os.platform() !== "linux") return false
84
+ let filePara = false
85
+ let fileRelease = false
86
+ try {
87
+ filePara = fs.existsSync("/system/etc/ohos.para")
88
+ fileRelease = fs.existsSync("/etc/ohos-release")
89
+ } catch {
90
+ // Ignore filesystem probes that are blocked by the host.
91
+ }
92
+ const rel = os.release().toLowerCase()
93
+ return (
94
+ Boolean(process.env.HOS_VERSION) ||
95
+ Boolean(process.env.OHOS_API_VERSION) ||
96
+ rel.includes("ohos") ||
97
+ rel.includes("hongmeng") ||
98
+ filePara ||
99
+ fileRelease
100
+ )
101
+ }
102
+
103
+ const ohos = isOhos()
79
104
  const scope = mainPkg.name && mainPkg.name.includes("/") ? mainPkg.name.split("/")[0] : "@deveco"
80
- const base = scope + "/deveco-code-" + platform + "-" + arch
81
- const binary = platform === "windows" ? "deveco.exe" : "deveco"
105
+ const base = scope + "/deveco-code-" + (ohos ? "hmos" : platform) + "-" + arch
106
+ const binary = ohos ? "hmos" : platform === "windows" ? "deveco.exe" : "deveco"
82
107
 
83
108
  function supportsAvx2() {
84
109
  if (arch !== "x64") return false
@@ -131,6 +156,7 @@ function supportsAvx2() {
131
156
  }
132
157
 
133
158
  const names = (() => {
159
+ if (ohos) return [base]
134
160
  const avx2 = supportsAvx2()
135
161
  const baseline = arch === "x64" && !avx2
136
162
 
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "scripts": {
7
7
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
8
  },
9
- "version": "1.10.31",
9
+ "version": "1.10.33",
10
10
  "license": "MIT",
11
11
  "files": [
12
12
  "bin/**/*",
@@ -16,11 +16,11 @@
16
16
  "CHANGELOG.md"
17
17
  ],
18
18
  "optionalDependencies": {
19
- "@deveco-test/deveco-code-windows-x64": "1.10.31",
20
- "@deveco-test/deveco-code-windows-x64-baseline": "1.10.31",
21
- "@deveco-test/deveco-code-darwin-x64": "1.10.31",
22
- "@deveco-test/deveco-code-darwin-arm64": "1.10.31",
23
- "@deveco-test/deveco-code-hmos-arm64": "1.10.31"
19
+ "@deveco-test/deveco-code-windows-x64": "1.10.33",
20
+ "@deveco-test/deveco-code-windows-x64-baseline": "1.10.33",
21
+ "@deveco-test/deveco-code-darwin-arm64": "1.10.33",
22
+ "@deveco-test/deveco-code-darwin-x64": "1.10.33",
23
+ "@deveco-test/deveco-code-hmos-arm64": "1.10.33"
24
24
  },
25
25
  "dependencies": {
26
26
  "@deveco/deveco-cli": "1.3.2"
package/postinstall.mjs CHANGED
@@ -30,8 +30,8 @@ const sourceBinary = platform === "windows" ? "deveco.exe" : "deveco"
30
30
  const targetBinary = path.join(__dirname, "bin", "deveco.exe")
31
31
  const devecoCliPackageName = "@deveco/deveco-cli"
32
32
 
33
- // Mirrors packages/tui isOhos(): OHOS PCs report linux/arm64 to npm but need
34
- // the cross-built hmos artifact instead of a generic linux platform package.
33
+ // Mirrors packages/tui isOhos(): OHOS PCs report openharmony (or linux) to
34
+ // npm but need the cross-built hmos artifact instead of a linux package.
35
35
  function isOhos() {
36
36
  if (os.platform() === "openharmony") return true
37
37
  if (os.platform() !== "linux") return false
@@ -58,17 +58,21 @@ function binaryName(name) {
58
58
  return name.includes("-hmos-") ? "hmos" : sourceBinary
59
59
  }
60
60
 
61
- function resolveLocalDevecoCliEntry() {
62
- const packageJsonPath = require.resolve(`${devecoCliPackageName}/package.json`)
61
+ function resolveLocalDevecoCliEntry(packageName = devecoCliPackageName) {
62
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
63
63
  const entry = path.join(path.dirname(packageJsonPath), "dist", "cli.js")
64
64
  if (fs.existsSync(entry)) return entry
65
- throw new Error(`Local dependency "${devecoCliPackageName}" has no CLI entry at ${entry}.`)
65
+ throw new Error(`Local dependency "${packageName}" has no CLI entry at ${entry}.`)
66
66
  }
67
67
 
68
68
  function writeDevecoCliEntryMarker(installRoot) {
69
+ // OHOS follows the darwin/windows dependency-marker mechanism; only the
70
+ // package name differs (hmos cli arrives as a dependency of the hmos
71
+ // platform package and is hoisted into the main package's node_modules).
72
+ const packageName = isOhos() ? "@deveco-test/hmos-deveco-cli" : devecoCliPackageName
69
73
  const marker = path.join(installRoot, "vendor", ".deveco-cli-entry")
70
74
  fs.mkdirSync(path.dirname(marker), { recursive: true })
71
- fs.writeFileSync(marker, `${resolveLocalDevecoCliEntry()}\n`, "utf8")
75
+ fs.writeFileSync(marker, `${resolveLocalDevecoCliEntry(packageName)}\n`, "utf8")
72
76
  }
73
77
 
74
78
  function supportsAvx2() {
@@ -246,6 +250,14 @@ function installPackage(name) {
246
250
  const packageDir = path.join(temp, "node_modules", name)
247
251
  copyBinary(path.join(packageDir, "bin", binaryName(name)), targetBinary)
248
252
  copyVendor(packageDir)
253
+ // The temp prefix is deleted below; persist the cli into the vendor tree
254
+ // so the marker written by main() points at a stable path.
255
+ const entry = resolveCliEntry([path.join(packageDir, "node_modules"), path.join(temp, "node_modules")])
256
+ if (entry) {
257
+ const cliDir = entry.slice(0, -"/dist/cli.js".length)
258
+ const rel = path.relative(path.join(temp, "node_modules"), cliDir)
259
+ copyDir(cliDir, path.join(__dirname, "vendor", "deveco-cli", "node_modules", rel))
260
+ }
249
261
  return true
250
262
  } finally {
251
263
  fs.rmSync(temp, { recursive: true, force: true })
@@ -273,34 +285,61 @@ function verifyBinary() {
273
285
  return result.status === 0
274
286
  }
275
287
 
276
- function writeVendorEntryMarker(installRoot) {
277
- const vendorRoot = path.join(installRoot, "vendor", "deveco-cli")
288
+ function resolveCliEntry(roots) {
278
289
  const names = ["@deveco-test/hmos-deveco-cli", "@deveco/deveco-cli", "@deveco-test/deveco-cli"]
279
- for (const name of names) {
280
- const entry = path.join(vendorRoot, "node_modules", ...name.split("/"), "dist", "cli.js")
281
- if (!fs.existsSync(entry)) continue
282
- fs.mkdirSync(path.join(installRoot, "vendor"), { recursive: true })
283
- fs.writeFileSync(path.join(installRoot, "vendor", ".deveco-cli-entry"), `${entry}\n`, "utf8")
284
- return
290
+ for (const root of roots) {
291
+ for (const name of names) {
292
+ const entry = path.join(root, ...name.split("/"), "dist", "cli.js")
293
+ if (fs.existsSync(entry)) return entry
294
+ }
285
295
  }
286
296
  }
287
297
 
298
+ function writeVendorEntryMarker(installRoot, extraRoots = []) {
299
+ // npm pack strips nested node_modules, so the tarball's vendor tree is an
300
+ // empty shell; the cli actually arrives as a dependency of the hmos package
301
+ // (hoisted or nested), hence the extra roots.
302
+ const entry = resolveCliEntry([path.join(installRoot, "vendor", "deveco-cli", "node_modules"), ...extraRoots])
303
+ if (!entry) return
304
+ fs.mkdirSync(path.join(installRoot, "vendor"), { recursive: true })
305
+ fs.writeFileSync(path.join(installRoot, "vendor", ".deveco-cli-entry"), `${entry}\n`, "utf8")
306
+ }
307
+
288
308
  function main() {
289
- // On OHOS the npm dependency cli must not win over the vendored hmos cli, so
290
- // the dependency marker is skipped and the vendor marker is written instead.
291
- if (!isOhos()) writeDevecoCliEntryMarker(__dirname)
309
+ // Same dependency-marker mechanism on every platform; on OHOS the cli may
310
+ // still be missing here (platform package not hoisted yet), in which case
311
+ // the loop below resolves or materializes it.
312
+ try {
313
+ writeDevecoCliEntryMarker(__dirname)
314
+ } catch {
315
+ // resolved later
316
+ }
292
317
 
293
318
  for (const name of packageNames()) {
294
319
  try {
295
320
  const packageDir = resolvePackageDir(name)
296
321
  copyBinary(resolveBinary(name), targetBinary)
297
322
  copyVendor(packageDir)
298
- if (isOhos()) writeVendorEntryMarker(__dirname)
299
- else writeDevecoCliEntryMarker(packageDir)
323
+ if (isOhos()) {
324
+ try {
325
+ writeDevecoCliEntryMarker(__dirname)
326
+ } catch {
327
+ writeVendorEntryMarker(__dirname, [
328
+ path.join(packageDir, "node_modules"),
329
+ path.join(__dirname, "node_modules"),
330
+ ])
331
+ }
332
+ } else writeDevecoCliEntryMarker(packageDir)
300
333
  if (verifyBinary()) return
301
334
  } catch {
302
335
  if (installPackage(name)) {
303
- if (isOhos()) writeVendorEntryMarker(__dirname)
336
+ if (isOhos()) {
337
+ try {
338
+ writeDevecoCliEntryMarker(__dirname)
339
+ } catch {
340
+ writeVendorEntryMarker(__dirname)
341
+ }
342
+ }
304
343
  if (verifyBinary()) return
305
344
  }
306
345
  }