pybao-xc-sdk 1.5.279 → 1.5.280

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/lib/runtime-resolver.cjs +153 -140
  2. package/package.json +10 -9
@@ -1,140 +1,153 @@
1
- const fs = require('node:fs')
2
- const path = require('node:path')
3
- const { spawnSync } = require('node:child_process')
4
- const {
5
- detectRuntimePlatform,
6
- getRuntimeBinaryName,
7
- getRuntimePackageName,
8
- } = require('./platform.cjs')
9
-
10
- function findPackageRoot(startDir) {
11
- let dir = startDir
12
- for (let i = 0; i < 25; i += 1) {
13
- if (fs.existsSync(path.join(dir, 'package.json'))) return dir
14
- const parent = path.dirname(dir)
15
- if (parent === dir) break
16
- dir = parent
17
- }
18
- return startDir
19
- }
20
-
21
- function resolveRuntimeFromOptionalDependency(packageRoot, packageName) {
22
- try {
23
- const manifestPath = require.resolve(`${packageName}/manifest.json`, {
24
- paths: [packageRoot],
25
- })
26
- const manifestDir = path.dirname(manifestPath)
27
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
28
- const binary = manifest?.binary
29
- const resourcesRoot = manifest?.resourcesRoot
30
- if (typeof binary !== 'string' || !binary.trim()) {
31
- throw new Error(`invalid runtime manifest in ${packageName}: missing binary`)
32
- }
33
- return {
34
- runtimeRoot: manifestDir,
35
- binaryPath: path.resolve(manifestDir, binary),
36
- resourcesRoot:
37
- typeof resourcesRoot === 'string' && resourcesRoot.trim()
38
- ? path.resolve(manifestDir, resourcesRoot)
39
- : path.resolve(manifestDir, 'resources'),
40
- source: 'optionalDependency',
41
- }
42
- } catch {
43
- return null
44
- }
45
- }
46
-
47
- function resolveRuntimeFromPackageDir(runtimeRoot, source) {
48
- const manifestPath = path.join(runtimeRoot, 'manifest.json')
49
- if (!fs.existsSync(manifestPath)) return null
50
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
51
- const binary = manifest?.binary
52
- const resourcesRoot = manifest?.resourcesRoot
53
- if (typeof binary !== 'string' || !binary.trim()) {
54
- throw new Error(`invalid runtime manifest in ${runtimeRoot}: missing binary`)
55
- }
56
- return {
57
- runtimeRoot,
58
- binaryPath: path.resolve(runtimeRoot, binary),
59
- resourcesRoot:
60
- typeof resourcesRoot === 'string' && resourcesRoot.trim()
61
- ? path.resolve(runtimeRoot, resourcesRoot)
62
- : path.resolve(runtimeRoot, 'resources'),
63
- source,
64
- }
65
- }
66
-
67
- function resolveRuntimeFromLocalCache(packageRoot, platformSuffix) {
68
- return (
69
- resolveRuntimeFromPackageDir(
70
- path.join(packageRoot, 'native', 'runtime-packages', platformSuffix),
71
- 'localPackage',
72
- ) ||
73
- resolveRuntimeFromPackageDir(path.join(packageRoot, 'runtime', platformSuffix), 'localCache')
74
- )
75
- }
76
-
77
- function resolveRuntime(packageRoot) {
78
- const platformSuffix = detectRuntimePlatform()
79
- if (!platformSuffix) {
80
- throw new Error(`Unsupported platform: ${process.platform}-${process.arch}`)
81
- }
82
- const packageName = getRuntimePackageName(platformSuffix)
83
- const explicitRuntimeRoot = process.env.PYB_RUNTIME_PACKAGE_ROOT?.trim()
84
- if (explicitRuntimeRoot) {
85
- const explicitRuntime = resolveRuntimeFromPackageDir(
86
- path.resolve(explicitRuntimeRoot),
87
- 'explicitRuntimePackageRoot',
88
- )
89
- if (explicitRuntime) {
90
- return { ...explicitRuntime, platformSuffix, packageName }
91
- }
92
- }
93
- const dependencyRuntime =
94
- packageName && resolveRuntimeFromOptionalDependency(packageRoot, packageName)
95
- if (dependencyRuntime) {
96
- return { ...dependencyRuntime, platformSuffix, packageName }
97
- }
98
- const localRuntime = resolveRuntimeFromLocalCache(packageRoot, platformSuffix)
99
- if (localRuntime) {
100
- return { ...localRuntime, platformSuffix, packageName }
101
- }
102
- throw new Error(
103
- [
104
- `Runtime package for ${platformSuffix} is not installed.`,
105
- `Expected optional dependency: ${packageName}`,
106
- 'Reinstall or ensure the platform runtime package is available.',
107
- ].join('\n'),
108
- )
109
- }
110
-
111
- function runResolvedBinary(options = {}) {
112
- const packageRoot = options.packageRoot ?? findPackageRoot(__dirname)
113
- const passthroughArgs = Array.isArray(options.args) ? options.args : process.argv.slice(2)
114
- const prependArgs = Array.isArray(options.prependArgs) ? options.prependArgs : []
115
- const runtime = resolveRuntime(packageRoot)
116
- const runtimeNodeModules = path.join(runtime.runtimeRoot, 'node_modules')
117
- const pathDelimiter = process.platform === 'win32' ? ';' : ':'
118
- const nodePath = process.env.NODE_PATH?.trim()
119
- const env = {
120
- ...process.env,
121
- PYB_RUNTIME_ROOT: runtime.runtimeRoot,
122
- PYB_RUNTIME_EXECUTOR: runtime.source,
123
- PYB_PACKAGED: process.env.PYB_PACKAGED || '1',
124
- NODE_PATH: nodePath ? `${runtimeNodeModules}${pathDelimiter}${nodePath}` : runtimeNodeModules,
125
- }
126
- const result = spawnSync(runtime.binaryPath, [...prependArgs, ...passthroughArgs], {
127
- stdio: 'inherit',
128
- env,
129
- })
130
- if (result.error) {
131
- throw result.error
132
- }
133
- return typeof result.status === 'number' ? result.status : 1
134
- }
135
-
136
- module.exports = {
137
- findPackageRoot,
138
- resolveRuntime,
139
- runResolvedBinary,
140
- }
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { spawnSync } = require('node:child_process')
4
+ const {
5
+ detectRuntimePlatform,
6
+ getRuntimeBinaryName,
7
+ getRuntimePackageName,
8
+ } = require('./platform.cjs')
9
+
10
+ function findPackageRoot(startDir) {
11
+ let dir = startDir
12
+ for (let i = 0; i < 25; i += 1) {
13
+ if (fs.existsSync(path.join(dir, 'package.json'))) return dir
14
+ const parent = path.dirname(dir)
15
+ if (parent === dir) break
16
+ dir = parent
17
+ }
18
+ return startDir
19
+ }
20
+
21
+ function resolveRuntimeFromOptionalDependency(packageRoot, packageName) {
22
+ try {
23
+ const manifestPath = require.resolve(`${packageName}/manifest.json`, {
24
+ paths: [packageRoot],
25
+ })
26
+ const manifestDir = path.dirname(manifestPath)
27
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
28
+ const binary = manifest?.binary
29
+ const resourcesRoot = manifest?.resourcesRoot
30
+ if (typeof binary !== 'string' || !binary.trim()) {
31
+ throw new Error(`invalid runtime manifest in ${packageName}: missing binary`)
32
+ }
33
+ return {
34
+ runtimeRoot: manifestDir,
35
+ binaryPath: path.resolve(manifestDir, binary),
36
+ resourcesRoot:
37
+ typeof resourcesRoot === 'string' && resourcesRoot.trim()
38
+ ? path.resolve(manifestDir, resourcesRoot)
39
+ : path.resolve(manifestDir, 'resources'),
40
+ source: 'optionalDependency',
41
+ }
42
+ } catch {
43
+ return null
44
+ }
45
+ }
46
+
47
+ function resolveRuntimeFromPackageDir(runtimeRoot, source) {
48
+ const manifestPath = path.join(runtimeRoot, 'manifest.json')
49
+ if (!fs.existsSync(manifestPath)) return null
50
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
51
+ const binary = manifest?.binary
52
+ const resourcesRoot = manifest?.resourcesRoot
53
+ if (typeof binary !== 'string' || !binary.trim()) {
54
+ throw new Error(`invalid runtime manifest in ${runtimeRoot}: missing binary`)
55
+ }
56
+ return {
57
+ runtimeRoot,
58
+ binaryPath: path.resolve(runtimeRoot, binary),
59
+ resourcesRoot:
60
+ typeof resourcesRoot === 'string' && resourcesRoot.trim()
61
+ ? path.resolve(runtimeRoot, resourcesRoot)
62
+ : path.resolve(runtimeRoot, 'resources'),
63
+ source,
64
+ }
65
+ }
66
+
67
+ function resolveRuntimeFromLocalCache(packageRoot, platformSuffix) {
68
+ return (
69
+ resolveRuntimeFromPackageDir(
70
+ path.join(packageRoot, 'native', 'runtime-packages', platformSuffix),
71
+ 'localPackage',
72
+ ) ||
73
+ resolveRuntimeFromPackageDir(path.join(packageRoot, 'runtime', platformSuffix), 'localCache')
74
+ )
75
+ }
76
+
77
+ function resolveRuntime(packageRoot) {
78
+ const platformSuffix = detectRuntimePlatform()
79
+ if (!platformSuffix) {
80
+ throw new Error(`Unsupported platform: ${process.platform}-${process.arch}`)
81
+ }
82
+ const packageName = getRuntimePackageName(platformSuffix)
83
+ const explicitRuntimeRoot = process.env.PYB_RUNTIME_PACKAGE_ROOT?.trim()
84
+ if (explicitRuntimeRoot) {
85
+ const explicitRuntime = resolveRuntimeFromPackageDir(
86
+ path.resolve(explicitRuntimeRoot),
87
+ 'explicitRuntimePackageRoot',
88
+ )
89
+ if (explicitRuntime) {
90
+ return { ...explicitRuntime, platformSuffix, packageName }
91
+ }
92
+ }
93
+ const dependencyRuntime =
94
+ packageName && resolveRuntimeFromOptionalDependency(packageRoot, packageName)
95
+ if (dependencyRuntime) {
96
+ return { ...dependencyRuntime, platformSuffix, packageName }
97
+ }
98
+ const localRuntime = resolveRuntimeFromLocalCache(packageRoot, platformSuffix)
99
+ if (localRuntime) {
100
+ return { ...localRuntime, platformSuffix, packageName }
101
+ }
102
+ throw new Error(
103
+ [
104
+ `Runtime package for ${platformSuffix} is not installed.`,
105
+ `Expected optional dependency: ${packageName}`,
106
+ 'Reinstall or ensure the platform runtime package is available.',
107
+ ].join('\n'),
108
+ )
109
+ }
110
+
111
+ function runResolvedBinary(options = {}) {
112
+ const packageRoot = options.packageRoot ?? findPackageRoot(__dirname)
113
+ const passthroughArgs = Array.isArray(options.args) ? options.args : process.argv.slice(2)
114
+ const prependArgs = Array.isArray(options.prependArgs) ? options.prependArgs : []
115
+ const runtime = resolveRuntime(packageRoot)
116
+ const runtimeNodeModules = path.join(runtime.runtimeRoot, 'node_modules')
117
+ const pathDelimiter = process.platform === 'win32' ? ';' : ':'
118
+ const nodePath = process.env.NODE_PATH?.trim()
119
+ // Absolute-entry env channel (same pattern as PYB_NATIVE_LOCK_NODE_PATH):
120
+ // ESM dynamic import ignores NODE_PATH, so point straight at the embedded
121
+ // sharp entry file inside the runtime package resources (Node's import()
122
+ // does not resolve package directories, only files).
123
+ const embeddedSharpEntry = path.join(
124
+ runtime.resourcesRoot,
125
+ 'sharp-node',
126
+ 'node_modules',
127
+ 'sharp',
128
+ 'lib',
129
+ 'index.js',
130
+ )
131
+ const env = {
132
+ ...process.env,
133
+ PYB_RUNTIME_ROOT: runtime.runtimeRoot,
134
+ PYB_RUNTIME_EXECUTOR: runtime.source,
135
+ PYB_PACKAGED: process.env.PYB_PACKAGED || '1',
136
+ PYB_SHARP_ENTRY: fs.existsSync(embeddedSharpEntry) ? embeddedSharpEntry : '',
137
+ NODE_PATH: nodePath ? `${runtimeNodeModules}${pathDelimiter}${nodePath}` : runtimeNodeModules,
138
+ }
139
+ const result = spawnSync(runtime.binaryPath, [...prependArgs, ...passthroughArgs], {
140
+ stdio: 'inherit',
141
+ env,
142
+ })
143
+ if (result.error) {
144
+ throw result.error
145
+ }
146
+ return typeof result.status === 'number' ? result.status : 1
147
+ }
148
+
149
+ module.exports = {
150
+ findPackageRoot,
151
+ resolveRuntime,
152
+ runResolvedBinary,
153
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pybao-xc-sdk",
3
- "version": "1.5.279",
3
+ "version": "1.5.280",
4
4
  "bin": {
5
5
  "pyb": "bin/pyb.js",
6
6
  "pyb-acp": "bin/pyb-acp.js"
@@ -108,6 +108,7 @@
108
108
  "release:gate": "npm run generate:sdk && npm run check:sdk-generated && npm run generate:legacy-mapping && npm run check:legacy-usage && npm run report:legacy-usage-trend && npm run check:legacy-window && npm run check:docs-consistency && npm run check:major-cutover && npm run check:facade-closeout && npm run check:sdk-consistency && npm run check:sdk-contract-consistency && npm run check:sdk-legacy-semantics && npm run check:compat-window && npm run build:sdk && npm run test:server && npm run lint && npm run typecheck",
109
109
  "prepare": "bun run scripts/install-hooks.mjs",
110
110
  "sync:native-lock": "node scripts/sync-native-lock-versions.mjs",
111
+ "sync:sharp-resources": "node scripts/sync-sharp-resources.mjs",
111
112
  "sync:runtime-package-metadata": "bun scripts/sync-runtime-package-metadata.mjs",
112
113
  "publish:native-lock": "node scripts/publish-native-lock.mjs",
113
114
  "verify:native-lock": "node scripts/verify-native-lock.mjs",
@@ -235,14 +236,14 @@
235
236
  "@puyib-cli/lock-linux-x64-musl": "1.4.55",
236
237
  "@puyib-cli/lock-win32-arm64-msvc": "1.4.55",
237
238
  "@puyib-cli/lock-win32-x64-msvc": "1.4.55",
238
- "pyb-runtime-darwin-arm64": "1.5.279",
239
- "pyb-runtime-darwin-x64": "1.5.279",
240
- "pyb-runtime-linux-arm64-gnu": "1.5.279",
241
- "pyb-runtime-linux-armv7-gnueabihf": "1.5.279",
242
- "pyb-runtime-linux-x64-gnu": "1.5.279",
243
- "pyb-runtime-linux-x64-musl": "1.5.279",
244
- "pyb-runtime-win32-arm64-msvc": "1.5.279",
245
- "pyb-runtime-win32-x64-msvc": "1.5.279"
239
+ "pyb-runtime-darwin-arm64": "1.5.280",
240
+ "pyb-runtime-darwin-x64": "1.5.280",
241
+ "pyb-runtime-linux-arm64-gnu": "1.5.280",
242
+ "pyb-runtime-linux-armv7-gnueabihf": "1.5.280",
243
+ "pyb-runtime-linux-x64-gnu": "1.5.280",
244
+ "pyb-runtime-linux-x64-musl": "1.5.280",
245
+ "pyb-runtime-win32-arm64-msvc": "1.5.280",
246
+ "pyb-runtime-win32-x64-msvc": "1.5.280"
246
247
  },
247
248
  "pybRuntimePlatforms": [
248
249
  "win32-x64-msvc",