kallal-compiler 0.0.0-stage → 0.1.0
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/LICENSE +48 -0
- package/index.d.ts +61 -0
- package/index.js +722 -0
- package/package.json +41 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Sandiford
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
--------------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
The native binary includes oxc (https://github.com/oxc-project/oxc), under this license:
|
|
26
|
+
|
|
27
|
+
MIT License
|
|
28
|
+
|
|
29
|
+
Copyright (c) 2024-present VoidZero Inc. & Contributors
|
|
30
|
+
Copyright (c) 2023 Boshen
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
in the Software without restriction, including without limitation the rights
|
|
35
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
furnished to do so, subject to the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be included in all
|
|
40
|
+
copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
SOFTWARE.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Which binding artifact the generated loader actually loaded: `'native'` for
|
|
6
|
+
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
|
|
7
|
+
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
|
|
8
|
+
* can point the loader at a WASI artifact this package does not build itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TightScript: compile one module for the browser. Kallal's passes run if asked, types are
|
|
14
|
+
* removed and JSX is compiled to the automatic runtime; nothing is lowered.
|
|
15
|
+
*/
|
|
16
|
+
export declare function compileSync(filename: string, sourceText: string, options?: TightScriptCompileOptions | undefined | null): TightScriptCompileResult
|
|
17
|
+
|
|
18
|
+
export interface TightScriptCompileOptions {
|
|
19
|
+
/** The module JSX compiles to imports from, `<source>/jsx-runtime`. Default: `react`. */
|
|
20
|
+
jsxImportSource?: string
|
|
21
|
+
/** Default: `false`. */
|
|
22
|
+
sourceMap?: boolean
|
|
23
|
+
/** Options for kallal's passes as JSON; the shapes are documented in the `kallal_passes` crate. */
|
|
24
|
+
kallal?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TightScriptCompileResult {
|
|
28
|
+
code: string
|
|
29
|
+
/** The source map as JSON. */
|
|
30
|
+
map?: string
|
|
31
|
+
errors: Array<OxcError>
|
|
32
|
+
/** What kallal's passes collected, as JSON, when `kallal` options were given. */
|
|
33
|
+
kallal?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Comment {
|
|
37
|
+
type: 'Line' | 'Block'
|
|
38
|
+
value: string
|
|
39
|
+
start: number
|
|
40
|
+
end: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ErrorLabel {
|
|
44
|
+
message: string | null
|
|
45
|
+
start: number
|
|
46
|
+
end: number
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface OxcError {
|
|
50
|
+
severity: Severity
|
|
51
|
+
message: string
|
|
52
|
+
labels: Array<ErrorLabel>
|
|
53
|
+
helpMessage: string | null
|
|
54
|
+
codeframe: string | null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare const enum Severity {
|
|
58
|
+
Error = 'Error',
|
|
59
|
+
Warning = 'Warning',
|
|
60
|
+
Advice = 'Advice',
|
|
61
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* auto-generated by NAPI-RS */
|
|
4
|
+
|
|
5
|
+
import { createRequire } from 'module'
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
7
|
+
|
|
8
|
+
const { readFileSync } = require('fs')
|
|
9
|
+
let nativeBinding = null
|
|
10
|
+
// Which artifact actually loaded. The WASI fallback chain overwrites it with
|
|
11
|
+
// the flavor it resolved; the late native retry below leaves it alone because
|
|
12
|
+
// it only runs while no WASI candidate has been loaded.
|
|
13
|
+
let __napiLoadedBindingTarget = 'native'
|
|
14
|
+
const loadErrors = []
|
|
15
|
+
|
|
16
|
+
const isMusl = () => {
|
|
17
|
+
let musl = false
|
|
18
|
+
if (process.platform === 'linux') {
|
|
19
|
+
musl = isMuslFromFilesystem()
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromReport()
|
|
22
|
+
}
|
|
23
|
+
if (musl === null) {
|
|
24
|
+
musl = isMuslFromChildProcess()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return musl
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
31
|
+
|
|
32
|
+
const isMuslFromFilesystem = () => {
|
|
33
|
+
try {
|
|
34
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isMuslFromReport = () => {
|
|
41
|
+
let report = null
|
|
42
|
+
if (process.report && typeof process.report.getReport === 'function') {
|
|
43
|
+
process.report.excludeNetwork = true
|
|
44
|
+
report = process.report.getReport()
|
|
45
|
+
}
|
|
46
|
+
if (!report) {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
53
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const isMuslFromChildProcess = () => {
|
|
61
|
+
try {
|
|
62
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
63
|
+
} catch (e) {
|
|
64
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function requireNative() {
|
|
70
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
71
|
+
try {
|
|
72
|
+
const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
|
|
73
|
+
// The override may be a generated WASI loader, which already reports its
|
|
74
|
+
// own flavor. Adopt it: `module.exports` aliases this object, so claiming
|
|
75
|
+
// 'native' would both misreport the artifact and overwrite the loader's
|
|
76
|
+
// marker through the alias.
|
|
77
|
+
__napiLoadedBindingTarget =
|
|
78
|
+
overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
|
|
79
|
+
? overrideBinding.__napiBindingTarget
|
|
80
|
+
: 'native'
|
|
81
|
+
return overrideBinding
|
|
82
|
+
} catch (err) {
|
|
83
|
+
loadErrors.push(err)
|
|
84
|
+
}
|
|
85
|
+
} else if (process.platform === 'android') {
|
|
86
|
+
if (process.arch === 'arm64') {
|
|
87
|
+
try {
|
|
88
|
+
return require('./kallal-compiler.android-arm64.node')
|
|
89
|
+
} catch (e) {
|
|
90
|
+
loadErrors.push(e)
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const binding = require('kallal-compiler-android-arm64')
|
|
94
|
+
const bindingPackageVersion = require('kallal-compiler-android-arm64/package.json').version
|
|
95
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
96
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
97
|
+
}
|
|
98
|
+
return binding
|
|
99
|
+
} catch (e) {
|
|
100
|
+
loadErrors.push(e)
|
|
101
|
+
}
|
|
102
|
+
} else if (process.arch === 'arm') {
|
|
103
|
+
try {
|
|
104
|
+
return require('./kallal-compiler.android-arm-eabi.node')
|
|
105
|
+
} catch (e) {
|
|
106
|
+
loadErrors.push(e)
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const binding = require('kallal-compiler-android-arm-eabi')
|
|
110
|
+
const bindingPackageVersion = require('kallal-compiler-android-arm-eabi/package.json').version
|
|
111
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
112
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
113
|
+
}
|
|
114
|
+
return binding
|
|
115
|
+
} catch (e) {
|
|
116
|
+
loadErrors.push(e)
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
120
|
+
}
|
|
121
|
+
} else if (process.platform === 'win32') {
|
|
122
|
+
if (process.arch === 'x64') {
|
|
123
|
+
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
124
|
+
try {
|
|
125
|
+
return require('./kallal-compiler.win32-x64-gnu.node')
|
|
126
|
+
} catch (e) {
|
|
127
|
+
loadErrors.push(e)
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const binding = require('kallal-compiler-win32-x64-gnu')
|
|
131
|
+
const bindingPackageVersion = require('kallal-compiler-win32-x64-gnu/package.json').version
|
|
132
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
133
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
134
|
+
}
|
|
135
|
+
return binding
|
|
136
|
+
} catch (e) {
|
|
137
|
+
loadErrors.push(e)
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
try {
|
|
141
|
+
return require('./kallal-compiler.win32-x64-msvc.node')
|
|
142
|
+
} catch (e) {
|
|
143
|
+
loadErrors.push(e)
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const binding = require('kallal-compiler-win32-x64-msvc')
|
|
147
|
+
const bindingPackageVersion = require('kallal-compiler-win32-x64-msvc/package.json').version
|
|
148
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
149
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
150
|
+
}
|
|
151
|
+
return binding
|
|
152
|
+
} catch (e) {
|
|
153
|
+
loadErrors.push(e)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} else if (process.arch === 'ia32') {
|
|
157
|
+
try {
|
|
158
|
+
return require('./kallal-compiler.win32-ia32-msvc.node')
|
|
159
|
+
} catch (e) {
|
|
160
|
+
loadErrors.push(e)
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const binding = require('kallal-compiler-win32-ia32-msvc')
|
|
164
|
+
const bindingPackageVersion = require('kallal-compiler-win32-ia32-msvc/package.json').version
|
|
165
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
166
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
167
|
+
}
|
|
168
|
+
return binding
|
|
169
|
+
} catch (e) {
|
|
170
|
+
loadErrors.push(e)
|
|
171
|
+
}
|
|
172
|
+
} else if (process.arch === 'arm64') {
|
|
173
|
+
try {
|
|
174
|
+
return require('./kallal-compiler.win32-arm64-msvc.node')
|
|
175
|
+
} catch (e) {
|
|
176
|
+
loadErrors.push(e)
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
const binding = require('kallal-compiler-win32-arm64-msvc')
|
|
180
|
+
const bindingPackageVersion = require('kallal-compiler-win32-arm64-msvc/package.json').version
|
|
181
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
182
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
183
|
+
}
|
|
184
|
+
return binding
|
|
185
|
+
} catch (e) {
|
|
186
|
+
loadErrors.push(e)
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
190
|
+
}
|
|
191
|
+
} else if (process.platform === 'darwin') {
|
|
192
|
+
try {
|
|
193
|
+
return require('./kallal-compiler.darwin-universal.node')
|
|
194
|
+
} catch (e) {
|
|
195
|
+
loadErrors.push(e)
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const binding = require('kallal-compiler-darwin-universal')
|
|
199
|
+
const bindingPackageVersion = require('kallal-compiler-darwin-universal/package.json').version
|
|
200
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
201
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
202
|
+
}
|
|
203
|
+
return binding
|
|
204
|
+
} catch (e) {
|
|
205
|
+
loadErrors.push(e)
|
|
206
|
+
}
|
|
207
|
+
if (process.arch === 'x64') {
|
|
208
|
+
try {
|
|
209
|
+
return require('./kallal-compiler.darwin-x64.node')
|
|
210
|
+
} catch (e) {
|
|
211
|
+
loadErrors.push(e)
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const binding = require('kallal-compiler-darwin-x64')
|
|
215
|
+
const bindingPackageVersion = require('kallal-compiler-darwin-x64/package.json').version
|
|
216
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
217
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
218
|
+
}
|
|
219
|
+
return binding
|
|
220
|
+
} catch (e) {
|
|
221
|
+
loadErrors.push(e)
|
|
222
|
+
}
|
|
223
|
+
} else if (process.arch === 'arm64') {
|
|
224
|
+
try {
|
|
225
|
+
return require('./kallal-compiler.darwin-arm64.node')
|
|
226
|
+
} catch (e) {
|
|
227
|
+
loadErrors.push(e)
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const binding = require('kallal-compiler-darwin-arm64')
|
|
231
|
+
const bindingPackageVersion = require('kallal-compiler-darwin-arm64/package.json').version
|
|
232
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
233
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
234
|
+
}
|
|
235
|
+
return binding
|
|
236
|
+
} catch (e) {
|
|
237
|
+
loadErrors.push(e)
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
241
|
+
}
|
|
242
|
+
} else if (process.platform === 'freebsd') {
|
|
243
|
+
if (process.arch === 'x64') {
|
|
244
|
+
try {
|
|
245
|
+
return require('./kallal-compiler.freebsd-x64.node')
|
|
246
|
+
} catch (e) {
|
|
247
|
+
loadErrors.push(e)
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const binding = require('kallal-compiler-freebsd-x64')
|
|
251
|
+
const bindingPackageVersion = require('kallal-compiler-freebsd-x64/package.json').version
|
|
252
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
253
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
254
|
+
}
|
|
255
|
+
return binding
|
|
256
|
+
} catch (e) {
|
|
257
|
+
loadErrors.push(e)
|
|
258
|
+
}
|
|
259
|
+
} else if (process.arch === 'arm64') {
|
|
260
|
+
try {
|
|
261
|
+
return require('./kallal-compiler.freebsd-arm64.node')
|
|
262
|
+
} catch (e) {
|
|
263
|
+
loadErrors.push(e)
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const binding = require('kallal-compiler-freebsd-arm64')
|
|
267
|
+
const bindingPackageVersion = require('kallal-compiler-freebsd-arm64/package.json').version
|
|
268
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
269
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
270
|
+
}
|
|
271
|
+
return binding
|
|
272
|
+
} catch (e) {
|
|
273
|
+
loadErrors.push(e)
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
277
|
+
}
|
|
278
|
+
} else if (process.platform === 'linux') {
|
|
279
|
+
if (process.arch === 'x64') {
|
|
280
|
+
if (isMusl()) {
|
|
281
|
+
try {
|
|
282
|
+
return require('./kallal-compiler.linux-x64-musl.node')
|
|
283
|
+
} catch (e) {
|
|
284
|
+
loadErrors.push(e)
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
const binding = require('kallal-compiler-linux-x64-musl')
|
|
288
|
+
const bindingPackageVersion = require('kallal-compiler-linux-x64-musl/package.json').version
|
|
289
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
290
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
291
|
+
}
|
|
292
|
+
return binding
|
|
293
|
+
} catch (e) {
|
|
294
|
+
loadErrors.push(e)
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
try {
|
|
298
|
+
return require('./kallal-compiler.linux-x64-gnu.node')
|
|
299
|
+
} catch (e) {
|
|
300
|
+
loadErrors.push(e)
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const binding = require('kallal-compiler-linux-x64-gnu')
|
|
304
|
+
const bindingPackageVersion = require('kallal-compiler-linux-x64-gnu/package.json').version
|
|
305
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
306
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
307
|
+
}
|
|
308
|
+
return binding
|
|
309
|
+
} catch (e) {
|
|
310
|
+
loadErrors.push(e)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} else if (process.arch === 'arm64') {
|
|
314
|
+
if (isMusl()) {
|
|
315
|
+
try {
|
|
316
|
+
return require('./kallal-compiler.linux-arm64-musl.node')
|
|
317
|
+
} catch (e) {
|
|
318
|
+
loadErrors.push(e)
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const binding = require('kallal-compiler-linux-arm64-musl')
|
|
322
|
+
const bindingPackageVersion = require('kallal-compiler-linux-arm64-musl/package.json').version
|
|
323
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
324
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
325
|
+
}
|
|
326
|
+
return binding
|
|
327
|
+
} catch (e) {
|
|
328
|
+
loadErrors.push(e)
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
try {
|
|
332
|
+
return require('./kallal-compiler.linux-arm64-gnu.node')
|
|
333
|
+
} catch (e) {
|
|
334
|
+
loadErrors.push(e)
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
const binding = require('kallal-compiler-linux-arm64-gnu')
|
|
338
|
+
const bindingPackageVersion = require('kallal-compiler-linux-arm64-gnu/package.json').version
|
|
339
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
340
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
341
|
+
}
|
|
342
|
+
return binding
|
|
343
|
+
} catch (e) {
|
|
344
|
+
loadErrors.push(e)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
} else if (process.arch === 'arm') {
|
|
348
|
+
if (isMusl()) {
|
|
349
|
+
try {
|
|
350
|
+
return require('./kallal-compiler.linux-arm-musleabihf.node')
|
|
351
|
+
} catch (e) {
|
|
352
|
+
loadErrors.push(e)
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const binding = require('kallal-compiler-linux-arm-musleabihf')
|
|
356
|
+
const bindingPackageVersion = require('kallal-compiler-linux-arm-musleabihf/package.json').version
|
|
357
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
358
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
359
|
+
}
|
|
360
|
+
return binding
|
|
361
|
+
} catch (e) {
|
|
362
|
+
loadErrors.push(e)
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
try {
|
|
366
|
+
return require('./kallal-compiler.linux-arm-gnueabihf.node')
|
|
367
|
+
} catch (e) {
|
|
368
|
+
loadErrors.push(e)
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
const binding = require('kallal-compiler-linux-arm-gnueabihf')
|
|
372
|
+
const bindingPackageVersion = require('kallal-compiler-linux-arm-gnueabihf/package.json').version
|
|
373
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
374
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
375
|
+
}
|
|
376
|
+
return binding
|
|
377
|
+
} catch (e) {
|
|
378
|
+
loadErrors.push(e)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
} else if (process.arch === 'loong64') {
|
|
382
|
+
if (isMusl()) {
|
|
383
|
+
try {
|
|
384
|
+
return require('./kallal-compiler.linux-loong64-musl.node')
|
|
385
|
+
} catch (e) {
|
|
386
|
+
loadErrors.push(e)
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const binding = require('kallal-compiler-linux-loong64-musl')
|
|
390
|
+
const bindingPackageVersion = require('kallal-compiler-linux-loong64-musl/package.json').version
|
|
391
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
392
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
393
|
+
}
|
|
394
|
+
return binding
|
|
395
|
+
} catch (e) {
|
|
396
|
+
loadErrors.push(e)
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
try {
|
|
400
|
+
return require('./kallal-compiler.linux-loong64-gnu.node')
|
|
401
|
+
} catch (e) {
|
|
402
|
+
loadErrors.push(e)
|
|
403
|
+
}
|
|
404
|
+
try {
|
|
405
|
+
const binding = require('kallal-compiler-linux-loong64-gnu')
|
|
406
|
+
const bindingPackageVersion = require('kallal-compiler-linux-loong64-gnu/package.json').version
|
|
407
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
408
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
409
|
+
}
|
|
410
|
+
return binding
|
|
411
|
+
} catch (e) {
|
|
412
|
+
loadErrors.push(e)
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
} else if (process.arch === 'riscv64') {
|
|
416
|
+
if (isMusl()) {
|
|
417
|
+
try {
|
|
418
|
+
return require('./kallal-compiler.linux-riscv64-musl.node')
|
|
419
|
+
} catch (e) {
|
|
420
|
+
loadErrors.push(e)
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const binding = require('kallal-compiler-linux-riscv64-musl')
|
|
424
|
+
const bindingPackageVersion = require('kallal-compiler-linux-riscv64-musl/package.json').version
|
|
425
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
426
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
427
|
+
}
|
|
428
|
+
return binding
|
|
429
|
+
} catch (e) {
|
|
430
|
+
loadErrors.push(e)
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
try {
|
|
434
|
+
return require('./kallal-compiler.linux-riscv64-gnu.node')
|
|
435
|
+
} catch (e) {
|
|
436
|
+
loadErrors.push(e)
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
const binding = require('kallal-compiler-linux-riscv64-gnu')
|
|
440
|
+
const bindingPackageVersion = require('kallal-compiler-linux-riscv64-gnu/package.json').version
|
|
441
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
442
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
443
|
+
}
|
|
444
|
+
return binding
|
|
445
|
+
} catch (e) {
|
|
446
|
+
loadErrors.push(e)
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
} else if (process.arch === 'ppc64') {
|
|
450
|
+
try {
|
|
451
|
+
return require('./kallal-compiler.linux-ppc64-gnu.node')
|
|
452
|
+
} catch (e) {
|
|
453
|
+
loadErrors.push(e)
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
const binding = require('kallal-compiler-linux-ppc64-gnu')
|
|
457
|
+
const bindingPackageVersion = require('kallal-compiler-linux-ppc64-gnu/package.json').version
|
|
458
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
459
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
460
|
+
}
|
|
461
|
+
return binding
|
|
462
|
+
} catch (e) {
|
|
463
|
+
loadErrors.push(e)
|
|
464
|
+
}
|
|
465
|
+
} else if (process.arch === 's390x') {
|
|
466
|
+
try {
|
|
467
|
+
return require('./kallal-compiler.linux-s390x-gnu.node')
|
|
468
|
+
} catch (e) {
|
|
469
|
+
loadErrors.push(e)
|
|
470
|
+
}
|
|
471
|
+
try {
|
|
472
|
+
const binding = require('kallal-compiler-linux-s390x-gnu')
|
|
473
|
+
const bindingPackageVersion = require('kallal-compiler-linux-s390x-gnu/package.json').version
|
|
474
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
475
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
476
|
+
}
|
|
477
|
+
return binding
|
|
478
|
+
} catch (e) {
|
|
479
|
+
loadErrors.push(e)
|
|
480
|
+
}
|
|
481
|
+
} else {
|
|
482
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
483
|
+
}
|
|
484
|
+
} else if (process.platform === 'openharmony') {
|
|
485
|
+
if (process.arch === 'arm64') {
|
|
486
|
+
try {
|
|
487
|
+
return require('./kallal-compiler.openharmony-arm64.node')
|
|
488
|
+
} catch (e) {
|
|
489
|
+
loadErrors.push(e)
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const binding = require('kallal-compiler-openharmony-arm64')
|
|
493
|
+
const bindingPackageVersion = require('kallal-compiler-openharmony-arm64/package.json').version
|
|
494
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
495
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
496
|
+
}
|
|
497
|
+
return binding
|
|
498
|
+
} catch (e) {
|
|
499
|
+
loadErrors.push(e)
|
|
500
|
+
}
|
|
501
|
+
} else if (process.arch === 'x64') {
|
|
502
|
+
try {
|
|
503
|
+
return require('./kallal-compiler.openharmony-x64.node')
|
|
504
|
+
} catch (e) {
|
|
505
|
+
loadErrors.push(e)
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
const binding = require('kallal-compiler-openharmony-x64')
|
|
509
|
+
const bindingPackageVersion = require('kallal-compiler-openharmony-x64/package.json').version
|
|
510
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
511
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
512
|
+
}
|
|
513
|
+
return binding
|
|
514
|
+
} catch (e) {
|
|
515
|
+
loadErrors.push(e)
|
|
516
|
+
}
|
|
517
|
+
} else if (process.arch === 'arm') {
|
|
518
|
+
try {
|
|
519
|
+
return require('./kallal-compiler.openharmony-arm.node')
|
|
520
|
+
} catch (e) {
|
|
521
|
+
loadErrors.push(e)
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
const binding = require('kallal-compiler-openharmony-arm')
|
|
525
|
+
const bindingPackageVersion = require('kallal-compiler-openharmony-arm/package.json').version
|
|
526
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
527
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
528
|
+
}
|
|
529
|
+
return binding
|
|
530
|
+
} catch (e) {
|
|
531
|
+
loadErrors.push(e)
|
|
532
|
+
}
|
|
533
|
+
} else {
|
|
534
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
535
|
+
}
|
|
536
|
+
} else {
|
|
537
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function createLoadErrorChain(errors) {
|
|
542
|
+
return errors.reduce((previous, current) => {
|
|
543
|
+
let message
|
|
544
|
+
try {
|
|
545
|
+
message =
|
|
546
|
+
current && typeof current.message === 'string'
|
|
547
|
+
? current.message
|
|
548
|
+
: String(current)
|
|
549
|
+
} catch {
|
|
550
|
+
message = 'Unknown error'
|
|
551
|
+
}
|
|
552
|
+
const error = new Error(message)
|
|
553
|
+
error.cause = previous
|
|
554
|
+
return error
|
|
555
|
+
}, null)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
559
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
560
|
+
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
561
|
+
// 'error' → require WASI without initializing a native fallback
|
|
562
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
563
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
564
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
565
|
+
//
|
|
566
|
+
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
567
|
+
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
568
|
+
const __napiWasiFlavors = ['wasm32-wasi']
|
|
569
|
+
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
570
|
+
const __napiWasiFlavorRequested =
|
|
571
|
+
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
572
|
+
if (
|
|
573
|
+
__napiWasiFlavorRequested &&
|
|
574
|
+
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
575
|
+
) {
|
|
576
|
+
throw new Error(
|
|
577
|
+
'Unsupported WASI flavor "' +
|
|
578
|
+
__napiWasiFlavor +
|
|
579
|
+
'". Available flavors: ' +
|
|
580
|
+
__napiWasiFlavors.join(', '),
|
|
581
|
+
)
|
|
582
|
+
}
|
|
583
|
+
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
584
|
+
const forceWasi =
|
|
585
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
586
|
+
forceWasiError ||
|
|
587
|
+
__napiWasiFlavorRequested
|
|
588
|
+
|
|
589
|
+
if (!forceWasi) {
|
|
590
|
+
nativeBinding = requireNative()
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (!nativeBinding || forceWasi) {
|
|
594
|
+
let wasiBinding = null
|
|
595
|
+
let wasiBindingLoaded = false
|
|
596
|
+
const wasiBindingErrors = []
|
|
597
|
+
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
598
|
+
try {
|
|
599
|
+
require.resolve(specifier)
|
|
600
|
+
} catch (resolveError) {
|
|
601
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
602
|
+
throw resolveError
|
|
603
|
+
}
|
|
604
|
+
if (isPackage) {
|
|
605
|
+
try {
|
|
606
|
+
require.resolve(specifier + '/package.json')
|
|
607
|
+
} catch (packageError) {
|
|
608
|
+
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
609
|
+
return resolveError
|
|
610
|
+
}
|
|
611
|
+
// An exports restriction proves the package exists even when its
|
|
612
|
+
// package.json is not public. Preserve the root resolution failure.
|
|
613
|
+
throw resolveError
|
|
614
|
+
}
|
|
615
|
+
// The package exists but its main/export target is broken.
|
|
616
|
+
throw resolveError
|
|
617
|
+
}
|
|
618
|
+
return resolveError
|
|
619
|
+
}
|
|
620
|
+
if (localArtifacts) {
|
|
621
|
+
let artifactError = null
|
|
622
|
+
for (let i = 0; i < localArtifacts.length; i++) {
|
|
623
|
+
try {
|
|
624
|
+
require.resolve(localArtifacts[i])
|
|
625
|
+
return null
|
|
626
|
+
} catch (resolveError) {
|
|
627
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
628
|
+
throw resolveError
|
|
629
|
+
}
|
|
630
|
+
artifactError = resolveError
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return artifactError
|
|
634
|
+
}
|
|
635
|
+
return null
|
|
636
|
+
}
|
|
637
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
638
|
+
let candidateError = null
|
|
639
|
+
let candidateFailed = false
|
|
640
|
+
try {
|
|
641
|
+
candidateError = __napiWasiResolveCandidate('./kallal-compiler.wasi.cjs', false, ['./kallal-compiler.wasm32-wasi.debug.wasm', './kallal-compiler.wasm32-wasi.wasm'])
|
|
642
|
+
candidateFailed = candidateError !== null
|
|
643
|
+
if (!candidateFailed) {
|
|
644
|
+
wasiBinding = require('./kallal-compiler.wasi.cjs')
|
|
645
|
+
nativeBinding = wasiBinding
|
|
646
|
+
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
647
|
+
wasiBindingLoaded = true
|
|
648
|
+
}
|
|
649
|
+
} catch (err) {
|
|
650
|
+
candidateError = err
|
|
651
|
+
candidateFailed = true
|
|
652
|
+
}
|
|
653
|
+
if (candidateFailed) {
|
|
654
|
+
wasiBindingErrors.push(candidateError)
|
|
655
|
+
loadErrors.push(candidateError)
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
659
|
+
let candidateError = null
|
|
660
|
+
let candidateFailed = false
|
|
661
|
+
try {
|
|
662
|
+
candidateError = __napiWasiResolveCandidate('kallal-compiler-wasm32-wasi', true, undefined)
|
|
663
|
+
candidateFailed = candidateError !== null
|
|
664
|
+
if (!candidateFailed) {
|
|
665
|
+
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
666
|
+
const bindingPackageVersion = require('kallal-compiler-wasm32-wasi/package.json').version
|
|
667
|
+
if (bindingPackageVersion !== '0.1.0') {
|
|
668
|
+
throw new Error(`WASI binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
wasiBinding = require('kallal-compiler-wasm32-wasi')
|
|
672
|
+
nativeBinding = wasiBinding
|
|
673
|
+
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
674
|
+
wasiBindingLoaded = true
|
|
675
|
+
}
|
|
676
|
+
} catch (err) {
|
|
677
|
+
candidateError = err
|
|
678
|
+
candidateFailed = true
|
|
679
|
+
}
|
|
680
|
+
if (candidateFailed) {
|
|
681
|
+
wasiBindingErrors.push(candidateError)
|
|
682
|
+
loadErrors.push(candidateError)
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (
|
|
686
|
+
!wasiBindingLoaded &&
|
|
687
|
+
forceWasi &&
|
|
688
|
+
!forceWasiError &&
|
|
689
|
+
!__napiWasiFlavorRequested
|
|
690
|
+
) {
|
|
691
|
+
nativeBinding = requireNative()
|
|
692
|
+
}
|
|
693
|
+
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
694
|
+
const error = new Error(
|
|
695
|
+
__napiWasiFlavorRequested
|
|
696
|
+
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
697
|
+
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
698
|
+
)
|
|
699
|
+
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
700
|
+
throw error
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (!nativeBinding) {
|
|
705
|
+
if (loadErrors.length > 0) {
|
|
706
|
+
const error = new Error(
|
|
707
|
+
`Cannot find native binding. ` +
|
|
708
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
709
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
710
|
+
)
|
|
711
|
+
// assign instead of the `new Error(message, { cause })` options form,
|
|
712
|
+
// which Node < 16.9 silently ignores
|
|
713
|
+
error.cause = createLoadErrorChain(loadErrors)
|
|
714
|
+
throw error
|
|
715
|
+
}
|
|
716
|
+
throw new Error(`Failed to load native binding`)
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const { compileSync, Severity } = nativeBinding
|
|
720
|
+
export { compileSync }
|
|
721
|
+
export { Severity }
|
|
722
|
+
export const __napiBindingTarget = __napiLoadedBindingTarget
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kallal-compiler",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Kallal's dev compiler: types, JSX and kallal's dev passes in one native call per file",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=24"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"kallal-compiler-win32-x64-msvc": "0.1.0",
|
|
25
|
+
"kallal-compiler-linux-x64-gnu": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@napi-rs/cli": "3.10.8",
|
|
29
|
+
"@types/node": "24.1.0",
|
|
30
|
+
"vitest": "5.0.3"
|
|
31
|
+
},
|
|
32
|
+
"napi": {
|
|
33
|
+
"binaryName": "kallal-compiler",
|
|
34
|
+
"targets": [
|
|
35
|
+
"x86_64-pc-windows-msvc",
|
|
36
|
+
"x86_64-unknown-linux-gnu"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build-dev": "napi build --esm --platform",
|
|
41
|
+
"build": "napi build --esm --platform --features allocator --release",
|
|
42
|
+
"test": "vitest run --dir ./test"
|
|
43
|
+
}
|
|
6
44
|
}
|
package/README.md
DELETED