@deveco-test/deveco-code 0.0.0-test → 0.0.0-test-harness.1

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 (6) hide show
  1. package/CHANGELOG.md +394 -178
  2. package/LICENSE +21 -21
  3. package/README.md +333 -328
  4. package/bin/deveco +206 -206
  5. package/package.json +6 -5
  6. package/postinstall.mjs +325 -217
package/bin/deveco CHANGED
@@ -1,206 +1,206 @@
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
- let mainPkg = {}
74
- try {
75
- mainPkg = JSON.parse(fs.readFileSync(path.join(scriptDir, "..", "package.json"), "utf8"))
76
- } catch {
77
- // dev mode or missing package.json
78
- }
79
- 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"
82
-
83
- function supportsAvx2() {
84
- if (arch !== "x64") return false
85
-
86
- if (platform === "linux") {
87
- try {
88
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
89
- } catch {
90
- return false
91
- }
92
- }
93
-
94
- if (platform === "darwin") {
95
- try {
96
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
97
- encoding: "utf8",
98
- timeout: 1500,
99
- })
100
- if (result.status !== 0) return false
101
- return (result.stdout || "").trim() === "1"
102
- } catch {
103
- return false
104
- }
105
- }
106
-
107
- if (platform === "windows") {
108
- const cmd =
109
- '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
110
-
111
- for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
112
- try {
113
- const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
114
- encoding: "utf8",
115
- timeout: 3000,
116
- windowsHide: true,
117
- })
118
- if (result.status !== 0) continue
119
- const out = (result.stdout || "").trim().toLowerCase()
120
- if (out === "true" || out === "1") return true
121
- if (out === "false" || out === "0") return false
122
- } catch {
123
- continue
124
- }
125
- }
126
-
127
- return false
128
- }
129
-
130
- return false
131
- }
132
-
133
- const names = (() => {
134
- const avx2 = supportsAvx2()
135
- const baseline = arch === "x64" && !avx2
136
-
137
- if (platform === "linux") {
138
- const musl = (() => {
139
- try {
140
- if (fs.existsSync("/etc/alpine-release")) return true
141
- } catch {
142
- // ignore
143
- }
144
-
145
- try {
146
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
147
- const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
148
- if (text.includes("musl")) return true
149
- } catch {
150
- // ignore
151
- }
152
-
153
- return false
154
- })()
155
-
156
- if (musl) {
157
- if (arch === "x64") {
158
- if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
159
- return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
160
- }
161
- return [`${base}-musl`, base]
162
- }
163
-
164
- if (arch === "x64") {
165
- if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
166
- return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
167
- }
168
- return [base, `${base}-musl`]
169
- }
170
-
171
- if (arch === "x64") {
172
- if (baseline) return [`${base}-baseline`, base]
173
- return [base, `${base}-baseline`]
174
- }
175
- return [base]
176
- })()
177
-
178
- function findBinary(startDir) {
179
- let current = startDir
180
- for (;;) {
181
- const modules = path.join(current, "node_modules")
182
- if (fs.existsSync(modules)) {
183
- for (const name of names) {
184
- const candidate = path.join(modules, name, "bin", binary)
185
- if (fs.existsSync(candidate)) return candidate
186
- }
187
- }
188
- const parent = path.dirname(current)
189
- if (parent === current) {
190
- return
191
- }
192
- current = parent
193
- }
194
- }
195
-
196
- const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
197
- if (!resolved) {
198
- console.error(
199
- "It seems that your package manager failed to install the right version of the deveco CLI for your platform. You can try manually installing " +
200
- names.map((n) => `\"${n}\"`).join(" or ") +
201
- " package",
202
- )
203
- process.exit(1)
204
- }
205
-
206
- run(resolved)
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
+ let mainPkg = {}
74
+ try {
75
+ mainPkg = JSON.parse(fs.readFileSync(path.join(scriptDir, "..", "package.json"), "utf8"))
76
+ } catch {
77
+ // dev mode or missing package.json
78
+ }
79
+ const scope = mainPkg.name && mainPkg.name.includes("/") ? mainPkg.name.split("/")[0] : "@deveco-test"
80
+ const base = scope + "/deveco-code-" + platform + "-" + arch
81
+ const binary = platform === "windows" ? "deveco.exe" : "deveco"
82
+
83
+ function supportsAvx2() {
84
+ if (arch !== "x64") return false
85
+
86
+ if (platform === "linux") {
87
+ try {
88
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
89
+ } catch {
90
+ return false
91
+ }
92
+ }
93
+
94
+ if (platform === "darwin") {
95
+ try {
96
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
97
+ encoding: "utf8",
98
+ timeout: 1500,
99
+ })
100
+ if (result.status !== 0) return false
101
+ return (result.stdout || "").trim() === "1"
102
+ } catch {
103
+ return false
104
+ }
105
+ }
106
+
107
+ if (platform === "windows") {
108
+ const cmd =
109
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
110
+
111
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
112
+ try {
113
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
114
+ encoding: "utf8",
115
+ timeout: 3000,
116
+ windowsHide: true,
117
+ })
118
+ if (result.status !== 0) continue
119
+ const out = (result.stdout || "").trim().toLowerCase()
120
+ if (out === "true" || out === "1") return true
121
+ if (out === "false" || out === "0") return false
122
+ } catch {
123
+ continue
124
+ }
125
+ }
126
+
127
+ return false
128
+ }
129
+
130
+ return false
131
+ }
132
+
133
+ const names = (() => {
134
+ const avx2 = supportsAvx2()
135
+ const baseline = arch === "x64" && !avx2
136
+
137
+ if (platform === "linux") {
138
+ const musl = (() => {
139
+ try {
140
+ if (fs.existsSync("/etc/alpine-release")) return true
141
+ } catch {
142
+ // ignore
143
+ }
144
+
145
+ try {
146
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
147
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
148
+ if (text.includes("musl")) return true
149
+ } catch {
150
+ // ignore
151
+ }
152
+
153
+ return false
154
+ })()
155
+
156
+ if (musl) {
157
+ if (arch === "x64") {
158
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
159
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
160
+ }
161
+ return [`${base}-musl`, base]
162
+ }
163
+
164
+ if (arch === "x64") {
165
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
166
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
167
+ }
168
+ return [base, `${base}-musl`]
169
+ }
170
+
171
+ if (arch === "x64") {
172
+ if (baseline) return [`${base}-baseline`, base]
173
+ return [base, `${base}-baseline`]
174
+ }
175
+ return [base]
176
+ })()
177
+
178
+ function findBinary(startDir) {
179
+ let current = startDir
180
+ for (;;) {
181
+ const modules = path.join(current, "node_modules")
182
+ if (fs.existsSync(modules)) {
183
+ for (const name of names) {
184
+ const candidate = path.join(modules, name, "bin", binary)
185
+ if (fs.existsSync(candidate)) return candidate
186
+ }
187
+ }
188
+ const parent = path.dirname(current)
189
+ if (parent === current) {
190
+ return
191
+ }
192
+ current = parent
193
+ }
194
+ }
195
+
196
+ const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
197
+ if (!resolved) {
198
+ console.error(
199
+ "It seems that your package manager failed to install the right version of the deveco CLI for your platform. You can try manually installing " +
200
+ names.map((n) => `\"${n}\"`).join(" or ") +
201
+ " package",
202
+ )
203
+ process.exit(1)
204
+ }
205
+
206
+ run(resolved)
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "scripts": {
7
7
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
8
  },
9
- "version": "0.0.0-test",
9
+ "version": "0.0.0-test-harness.1",
10
10
  "license": "MIT",
11
11
  "files": [
12
12
  "bin/**/*",
@@ -16,9 +16,10 @@
16
16
  "CHANGELOG.md"
17
17
  ],
18
18
  "optionalDependencies": {
19
- "@deveco-test/deveco-code-windows-x64": "0.0.0-test",
20
- "@deveco-test/deveco-code-windows-x64-baseline": "0.0.0-test",
21
- "@deveco-test/deveco-code-darwin-x64": "0.0.0-test",
22
- "@deveco-test/deveco-code-darwin-arm64": "0.0.0-test"
19
+ "@deveco-test/deveco-code-windows-x64": "0.0.0-test-harness.1"
20
+ },
21
+ "dependencies": {
22
+ "@deveco-test/deveco-harness": "0.2.0-test.0",
23
+ "homegraph": "latest"
23
24
  }
24
25
  }