@deveco-test/deveco-code 1.10.32 → 1.10.35

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/postinstall.mjs +60 -18
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.32",
9
+ "version": "1.10.35",
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-darwin-arm64": "1.10.32",
20
- "@deveco-test/deveco-code-darwin-x64": "1.10.32",
21
- "@deveco-test/deveco-code-windows-x64-baseline": "1.10.32",
22
- "@deveco-test/deveco-code-windows-x64": "1.10.32",
23
- "@deveco-test/deveco-code-hmos-arm64": "1.10.32"
19
+ "@deveco-test/deveco-code-darwin-x64": "1.10.35",
20
+ "@deveco-test/deveco-code-darwin-arm64": "1.10.35",
21
+ "@deveco-test/deveco-code-windows-x64-baseline": "1.10.35",
22
+ "@deveco-test/deveco-code-windows-x64": "1.10.35",
23
+ "@deveco-test/deveco-code-hmos-arm64": "1.10.35"
24
24
  },
25
25
  "dependencies": {
26
26
  "@deveco/deveco-cli": "1.3.2"
package/postinstall.mjs CHANGED
@@ -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,64 @@ 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
+ // The runtime derives installRoot from the hmos binary's own package
325
+ // dir (the shim spawns node_modules/.../bin/hmos), so the marker must
326
+ // exist there too — same as darwin/windows writing into packageDir.
327
+ try {
328
+ writeDevecoCliEntryMarker(__dirname)
329
+ writeDevecoCliEntryMarker(packageDir)
330
+ } catch {
331
+ const roots = [path.join(packageDir, "node_modules"), path.join(__dirname, "node_modules")]
332
+ writeVendorEntryMarker(__dirname, roots)
333
+ writeVendorEntryMarker(packageDir, roots)
334
+ }
335
+ } else writeDevecoCliEntryMarker(packageDir)
300
336
  if (verifyBinary()) return
301
337
  } catch {
302
338
  if (installPackage(name)) {
303
- if (isOhos()) writeVendorEntryMarker(__dirname)
339
+ if (isOhos()) {
340
+ try {
341
+ writeDevecoCliEntryMarker(__dirname)
342
+ } catch {
343
+ writeVendorEntryMarker(__dirname)
344
+ }
345
+ }
304
346
  if (verifyBinary()) return
305
347
  }
306
348
  }