@mikrojs/native 0.10.0-pr-134.gc6ec955 → 0.10.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/CMakeLists.txt +2 -2
- package/cmake/mikrojs_bytecode.cmake +1 -1
- package/package.json +5 -5
- package/prebuilds/darwin-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-x64/mikrojs.napi.node +0 -0
- package/runtime/ble/ble.ts +2 -2
- package/runtime/fs/fs.ts +1 -1
- package/runtime/http/helpers.ts +1 -1
- package/runtime/http/native.ts +2 -2
- package/runtime/internal.d.ts +16 -16
- package/runtime/kv/nvs.ts +1 -1
- package/runtime/kv/rtc.ts +1 -1
- package/runtime/kv/shared.ts +2 -2
- package/runtime/pwm/pwm.ts +1 -1
- package/runtime/reader/reader.ts +1 -1
- package/runtime/reader/types.ts +1 -1
- package/runtime/schema/schema.ts +1 -1
- package/runtime/sntp/sntp.ts +1 -1
- package/runtime/stream/stream.ts +1 -1
- package/runtime/stream/types.ts +1 -1
- package/runtime/sys/sys.ts +1 -1
- package/runtime/test/test.ts +1 -1
- package/runtime/uart/uart.ts +1 -1
- package/runtime/udp/udp.ts +1 -1
- package/runtime/wifi/wifi.ts +2 -2
- package/scripts/bundle-runtime.js +2 -2
- package/src/builtins.cpp +2 -2
- package/src/modules.cpp +7 -7
package/CMakeLists.txt
CHANGED
|
@@ -82,8 +82,8 @@ include(cmake/mikrojs_bytecode.cmake)
|
|
|
82
82
|
mikrojs_generate_bytecode(
|
|
83
83
|
RUNTIME_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
|
|
84
84
|
MODULES cbor env result schema fs http/helpers http/request i2c kv/nvs kv/rtc kv/shared module neopixel observable observable/lazy observable/operators pin pwm reader sleep spi sntp stdio stream sys test uart udp wifi
|
|
85
|
-
MODULE_PREFIX "
|
|
86
|
-
SYMBOL_PREFIX "
|
|
85
|
+
MODULE_PREFIX "mikro"
|
|
86
|
+
SYMBOL_PREFIX "mikro"
|
|
87
87
|
TARGET gen_bytecode
|
|
88
88
|
)
|
|
89
89
|
add_dependencies(mikrojs gen_bytecode)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# mikrojs_generate_bytecode(
|
|
8
8
|
# RUNTIME_DIR <path> # Directory containing <mod>/<mod>.ts files
|
|
9
9
|
# MODULES <mod1> <mod2> # Module names to compile
|
|
10
|
-
# MODULE_PREFIX <prefix> # Module name prefix (e.g. "
|
|
10
|
+
# MODULE_PREFIX <prefix> # Module name prefix (e.g. "mikro" -> "mikro/pin")
|
|
11
11
|
# SYMBOL_PREFIX <prefix> # C symbol prefix (e.g. "mikrojs" -> "mikrojs_pin_bytecode")
|
|
12
12
|
# TARGET <name> # Custom target name (default: gen_bytecode)
|
|
13
13
|
# WORKING_DIRECTORY <dir> # Working dir for esbuild (default: CMAKE_CURRENT_SOURCE_DIR)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikrojs/native",
|
|
3
|
-
"version": "0.10.0
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Mikro.js C++ runtime library and Node.js native addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp32",
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"quickjs",
|
|
10
10
|
"runtime"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://github.com/mikrojs/
|
|
12
|
+
"homepage": "https://github.com/mikrojs/mikro#readme",
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/mikrojs/
|
|
14
|
+
"url": "https://github.com/mikrojs/mikro/issues"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"author": "Bjørge Næss <bjoerge@gmail.com>",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/mikrojs/
|
|
20
|
+
"url": "git+https://github.com/mikrojs/mikro.git"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"cmake-js": "^8.0.0",
|
|
80
80
|
"node-addon-api": "^8.7.0",
|
|
81
81
|
"node-gyp-build": "^4.8.4",
|
|
82
|
-
"@mikrojs/quickjs": "0.10.0
|
|
82
|
+
"@mikrojs/quickjs": "0.10.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@swc/core": "^1.15.30",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/runtime/ble/ble.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {lazyEvent} from '
|
|
2
|
-
import {err, ok} from '
|
|
1
|
+
import {lazyEvent} from 'mikro/observable/lazy'
|
|
2
|
+
import {err, ok} from 'mikro/result'
|
|
3
3
|
import {Ble as NativeBle} from 'native:ble'
|
|
4
4
|
|
|
5
5
|
import type {Result} from '../result/types.js'
|
package/runtime/fs/fs.ts
CHANGED
package/runtime/http/helpers.ts
CHANGED
package/runtime/http/native.ts
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
type Request,
|
|
9
9
|
RequestError,
|
|
10
10
|
type RequestOptions,
|
|
11
|
-
} from '
|
|
12
|
-
import {err, ok} from '
|
|
11
|
+
} from 'mikro/http/helpers'
|
|
12
|
+
import {err, ok} from 'mikro/result'
|
|
13
13
|
|
|
14
14
|
import type {ErrResult, Result} from '../result/types.js'
|
|
15
15
|
|
package/runtime/internal.d.ts
CHANGED
|
@@ -4,20 +4,20 @@ type NR<T> = {ok: true; value: T} | {ok: false; error: {code: number; message: s
|
|
|
4
4
|
|
|
5
5
|
// Internal shared runtime modules. Registered as builtins so sibling bundles
|
|
6
6
|
// can reference them at runtime to dedupe shared code, but not exposed via
|
|
7
|
-
// the public `
|
|
7
|
+
// the public `mikro/*` subpath exports so user apps can't accidentally
|
|
8
8
|
// import them. Keep these in sync with the MODULES list in the firmware +
|
|
9
9
|
// @mikrojs/native CMakeLists.
|
|
10
|
-
declare module '
|
|
10
|
+
declare module 'mikro/kv/shared' {
|
|
11
11
|
export {KVError, makeCreateValue, type NativeKvFns} from './kv/shared.js'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
declare module '
|
|
14
|
+
declare module 'mikro/observable/lazy' {
|
|
15
15
|
export {lazyEvent} from './observable/lazy.js'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
declare module 'native:cbor' {
|
|
19
19
|
import type {CborError} from '@mikrojs/native/runtime/cbor/types'
|
|
20
|
-
import type {Result} from '
|
|
20
|
+
import type {Result} from 'mikro/result'
|
|
21
21
|
export function encode(value: unknown): Result<Uint8Array, CborError>
|
|
22
22
|
export function decode(data: Uint8Array): Result<unknown, CborError>
|
|
23
23
|
}
|
|
@@ -122,7 +122,7 @@ declare module 'native:stdio' {
|
|
|
122
122
|
|
|
123
123
|
declare module 'native:pin' {
|
|
124
124
|
import type {PinError} from '@mikrojs/native/runtime/pin/types'
|
|
125
|
-
import type {Result} from '
|
|
125
|
+
import type {Result} from 'mikro/result'
|
|
126
126
|
export type PinMode = 0x01 | 0x03 | 0x05
|
|
127
127
|
export function pinMode(pin: number, value: PinMode): Result<void, PinError>
|
|
128
128
|
export function digitalWrite(pin: number, value: 0 | 1): Result<void, PinError>
|
|
@@ -143,8 +143,8 @@ declare module 'native:sleep' {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
declare module 'native:http' {
|
|
146
|
-
import type {RequestError} from '
|
|
147
|
-
import type {Result} from '
|
|
146
|
+
import type {RequestError} from 'mikro/http/helpers'
|
|
147
|
+
import type {Result} from 'mikro/result'
|
|
148
148
|
|
|
149
149
|
import type {ErrResult} from './result/types.js'
|
|
150
150
|
type HeadersMsg = {status: number; headers: [string, string][]}
|
|
@@ -165,7 +165,7 @@ declare module 'native:http' {
|
|
|
165
165
|
}
|
|
166
166
|
declare module 'native:i2c' {
|
|
167
167
|
import type {I2cError} from '@mikrojs/native/runtime/i2c/types'
|
|
168
|
-
import type {Result} from '
|
|
168
|
+
import type {Result} from 'mikro/result'
|
|
169
169
|
|
|
170
170
|
export interface I2cBaseOptions {
|
|
171
171
|
freq?: number
|
|
@@ -197,7 +197,7 @@ declare module 'native:i2c' {
|
|
|
197
197
|
}
|
|
198
198
|
declare module 'native:spi' {
|
|
199
199
|
import type {SpiError} from '@mikrojs/native/runtime/spi/types'
|
|
200
|
-
import type {Result} from '
|
|
200
|
+
import type {Result} from 'mikro/result'
|
|
201
201
|
|
|
202
202
|
export interface SpiOptions {
|
|
203
203
|
clk: number
|
|
@@ -226,7 +226,7 @@ declare module 'native:spi' {
|
|
|
226
226
|
|
|
227
227
|
declare module 'native:sntp' {
|
|
228
228
|
import type {SntpError} from '@mikrojs/native/runtime/sntp/types'
|
|
229
|
-
import type {Result} from '
|
|
229
|
+
import type {Result} from 'mikro/result'
|
|
230
230
|
/**
|
|
231
231
|
* Native errors: the outer Result covers init/config failures (InitFailed);
|
|
232
232
|
* the inner Result on resolve covers post-start errors (Cancelled).
|
|
@@ -262,7 +262,7 @@ declare module 'native:nvs_kv' {
|
|
|
262
262
|
|
|
263
263
|
declare module 'native:pwm' {
|
|
264
264
|
import type {PwmError} from '@mikrojs/native/runtime/pwm/types'
|
|
265
|
-
import type {Result} from '
|
|
265
|
+
import type {Result} from 'mikro/result'
|
|
266
266
|
|
|
267
267
|
export declare const Pwm: {
|
|
268
268
|
prototype: Pwm
|
|
@@ -279,7 +279,7 @@ declare module 'native:pwm' {
|
|
|
279
279
|
|
|
280
280
|
declare module 'native:neopixel' {
|
|
281
281
|
import type {NeoPixelError} from '@mikrojs/native/runtime/neopixel/types'
|
|
282
|
-
import type {Result} from '
|
|
282
|
+
import type {Result} from 'mikro/result'
|
|
283
283
|
|
|
284
284
|
export declare const NeoPixel: {
|
|
285
285
|
prototype: NeoPixel
|
|
@@ -297,7 +297,7 @@ declare module 'native:neopixel' {
|
|
|
297
297
|
|
|
298
298
|
declare module 'native:uart' {
|
|
299
299
|
import type {UartError} from '@mikrojs/native/runtime/uart/types'
|
|
300
|
-
import type {Result} from '
|
|
300
|
+
import type {Result} from 'mikro/result'
|
|
301
301
|
|
|
302
302
|
export interface UartOptions {
|
|
303
303
|
tx?: number
|
|
@@ -329,7 +329,7 @@ declare module 'native:uart' {
|
|
|
329
329
|
|
|
330
330
|
declare module 'native:ble' {
|
|
331
331
|
import type {BleError} from '@mikrojs/native/runtime/ble/types'
|
|
332
|
-
import type {Result} from '
|
|
332
|
+
import type {Result} from 'mikro/result'
|
|
333
333
|
|
|
334
334
|
type R<T> = Result<T, BleError>
|
|
335
335
|
|
|
@@ -383,7 +383,7 @@ declare module 'native:ble' {
|
|
|
383
383
|
|
|
384
384
|
declare module 'native:wifi' {
|
|
385
385
|
import type {WifiError} from '@mikrojs/native/runtime/wifi/types'
|
|
386
|
-
import type {Result} from '
|
|
386
|
+
import type {Result} from 'mikro/result'
|
|
387
387
|
|
|
388
388
|
type R<T> = Result<T, WifiError>
|
|
389
389
|
|
|
@@ -469,7 +469,7 @@ declare module 'native:udp' {
|
|
|
469
469
|
UdpError,
|
|
470
470
|
UdpFamily,
|
|
471
471
|
} from '@mikrojs/native/runtime/udp/types'
|
|
472
|
-
import type {Result} from '
|
|
472
|
+
import type {Result} from 'mikro/result'
|
|
473
473
|
|
|
474
474
|
export interface NativeUdpSocket {
|
|
475
475
|
readonly port: number
|
package/runtime/kv/nvs.ts
CHANGED
package/runtime/kv/rtc.ts
CHANGED
package/runtime/kv/shared.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {err, ok} from '
|
|
1
|
+
import {err, ok} from 'mikro/result'
|
|
2
2
|
// Typed loosely to avoid deep type instantiation from Infer<S> in parse's generics.
|
|
3
3
|
// Type safety is provided by the storage interface overloads in types.ts.
|
|
4
|
-
import {parse as _parse} from '
|
|
4
|
+
import {parse as _parse} from 'mikro/schema'
|
|
5
5
|
|
|
6
6
|
import type {NativeError} from '../result/types.js'
|
|
7
7
|
|
package/runtime/pwm/pwm.ts
CHANGED
package/runtime/reader/reader.ts
CHANGED
package/runtime/reader/types.ts
CHANGED
package/runtime/schema/schema.ts
CHANGED
package/runtime/sntp/sntp.ts
CHANGED
package/runtime/stream/stream.ts
CHANGED
package/runtime/stream/types.ts
CHANGED
package/runtime/sys/sys.ts
CHANGED
package/runtime/test/test.ts
CHANGED
package/runtime/uart/uart.ts
CHANGED
package/runtime/udp/udp.ts
CHANGED
package/runtime/wifi/wifi.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {lazyEvent} from '
|
|
2
|
-
import {err, ok} from '
|
|
1
|
+
import {lazyEvent} from 'mikro/observable/lazy'
|
|
2
|
+
import {err, ok} from 'mikro/result'
|
|
3
3
|
import {Wifi as NativeWifi} from 'native:wifi'
|
|
4
4
|
|
|
5
5
|
import type {Result} from '../result/types.js'
|
|
@@ -104,7 +104,7 @@ for (const name of moduleNames) {
|
|
|
104
104
|
target: 'es2024',
|
|
105
105
|
platform: 'neutral',
|
|
106
106
|
format: 'esm',
|
|
107
|
-
external: ['
|
|
107
|
+
external: ['mikro', 'mikro/*', '@mikrojs/*', 'native:*'],
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
const output = result.outputFiles?.[0]
|
|
@@ -128,7 +128,7 @@ for (const name of moduleNames) {
|
|
|
128
128
|
// Extract external imports so CMake can pass them as -M flags to qjsc
|
|
129
129
|
const externals = []
|
|
130
130
|
for (const match of source.matchAll(
|
|
131
|
-
/(?:from|import)\s*["']((?:native:|
|
|
131
|
+
/(?:from|import)\s*["']((?:native:|mikro\/|@mikrojs\/)[^"']+)["']/g,
|
|
132
132
|
)) {
|
|
133
133
|
externals.push(match[1])
|
|
134
134
|
}
|
package/src/builtins.cpp
CHANGED
|
@@ -14,8 +14,8 @@ typedef struct {
|
|
|
14
14
|
|
|
15
15
|
/* Generated by mikrojs_generate_bytecode() in CMake — includes + lookup table.
|
|
16
16
|
* Adding a new module only requires updating the MODULES list in CMakeLists.txt. */
|
|
17
|
-
#include "gen/
|
|
18
|
-
#define builtins
|
|
17
|
+
#include "gen/mikro_builtins_table.h"
|
|
18
|
+
#define builtins mikro_builtins
|
|
19
19
|
|
|
20
20
|
/* External builtins registered by board/driver packages via MIK_REGISTER_BUILTIN() */
|
|
21
21
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
package/src/modules.cpp
CHANGED
|
@@ -200,7 +200,7 @@ static JSModuleDef* mik_module_load_from_fs(JSContext* ctx, const char* module_n
|
|
|
200
200
|
|
|
201
201
|
static JSModuleDef* mik_module_loader_inner(JSContext* ctx, const char* module_name,
|
|
202
202
|
void* opaque) {
|
|
203
|
-
static const char
|
|
203
|
+
static const char mikro_prefix[] = "mikro/";
|
|
204
204
|
|
|
205
205
|
/* Virtual modules take priority over builtins — allows host-side JS to
|
|
206
206
|
* override any native:* C module (e.g. mocking device modules for dev). */
|
|
@@ -239,7 +239,7 @@ static JSModuleDef* mik_module_loader_inner(JSContext* ctx, const char* module_n
|
|
|
239
239
|
return nullptr;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
if (strncmp(
|
|
242
|
+
if (strncmp(mikro_prefix, module_name, strlen(mikro_prefix)) == 0) {
|
|
243
243
|
JSModuleDef* builtin_m = mik__load_builtin(ctx, module_name);
|
|
244
244
|
if (builtin_m) return builtin_m;
|
|
245
245
|
/* mik__load_builtin returns NULL either because the module isn't in
|
|
@@ -655,11 +655,11 @@ static char* mik__resolve_node_modules(JSContext* ctx, const char* base_dir,
|
|
|
655
655
|
return NULL;
|
|
656
656
|
}
|
|
657
657
|
|
|
658
|
-
/* Anchored names (native:,
|
|
658
|
+
/* Anchored names (native:, mikro/, @mikrojs/) are never unloaded
|
|
659
659
|
* and don't contribute meaningfully to the import graph for orphan
|
|
660
660
|
* detection. We skip recording edges where the target is anchored. */
|
|
661
661
|
static bool mik__is_anchored_name(const char* name) {
|
|
662
|
-
return strncmp(name, "native:", 7) == 0 || strncmp(name, "
|
|
662
|
+
return strncmp(name, "native:", 7) == 0 || strncmp(name, "mikro/", 6) == 0 ||
|
|
663
663
|
strncmp(name, "@mikrojs/", 9) == 0;
|
|
664
664
|
}
|
|
665
665
|
|
|
@@ -683,8 +683,8 @@ static char* mik__module_normalizer_impl(JSContext* ctx, const char* base_name,
|
|
|
683
683
|
|
|
684
684
|
static const char internal_prefix[] = "native:";
|
|
685
685
|
if (strncmp(name, internal_prefix, strlen(internal_prefix)) == 0) {
|
|
686
|
-
// Only built-in modules (native:,
|
|
687
|
-
if (strncmp(base_name, "native:", 7) != 0 && strncmp(base_name, "
|
|
686
|
+
// Only built-in modules (native:, mikro/, @mikrojs/) may import native: internals
|
|
687
|
+
if (strncmp(base_name, "native:", 7) != 0 && strncmp(base_name, "mikro/", 6) != 0 &&
|
|
688
688
|
strncmp(base_name, "@mikrojs/", 9) != 0) {
|
|
689
689
|
JS_ThrowTypeError(ctx, "Failed to resolve module specifier '%s'", name);
|
|
690
690
|
return NULL;
|
|
@@ -693,7 +693,7 @@ static char* mik__module_normalizer_impl(JSContext* ctx, const char* base_name,
|
|
|
693
693
|
|
|
694
694
|
if (name[0] != '.' && name[0] != '/') {
|
|
695
695
|
/* Built-in modules pass through unchanged */
|
|
696
|
-
if (strncmp(name, "
|
|
696
|
+
if (strncmp(name, "mikro/", 6) == 0 || strncmp(name, "native:", 7) == 0) {
|
|
697
697
|
return js_strdup(ctx, name);
|
|
698
698
|
}
|
|
699
699
|
/* Check if this bare specifier matches an external builtin (board/driver
|