mikrojs 0.0.0 → 0.0.8
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 +21 -0
- package/README.md +76 -0
- package/bin/mikrojs.js +3 -0
- package/dist/_exports/ble.d.ts +3 -0
- package/dist/_exports/ble.d.ts.map +1 -0
- package/dist/_exports/ble.js +2 -0
- package/dist/_exports/ble.js.map +1 -0
- package/dist/_exports/cbor.d.ts +3 -0
- package/dist/_exports/cbor.d.ts.map +1 -0
- package/dist/_exports/cbor.js +2 -0
- package/dist/_exports/cbor.js.map +1 -0
- package/dist/_exports/console.d.ts +2 -0
- package/dist/_exports/console.d.ts.map +1 -0
- package/dist/_exports/console.js +2 -0
- package/dist/_exports/console.js.map +1 -0
- package/dist/_exports/env.d.ts +2 -0
- package/dist/_exports/env.d.ts.map +1 -0
- package/dist/_exports/env.js +2 -0
- package/dist/_exports/env.js.map +1 -0
- package/dist/_exports/format.d.ts +2 -0
- package/dist/_exports/format.d.ts.map +1 -0
- package/dist/_exports/format.js +2 -0
- package/dist/_exports/format.js.map +1 -0
- package/dist/_exports/fs.d.ts +2 -0
- package/dist/_exports/fs.d.ts.map +1 -0
- package/dist/_exports/fs.js +2 -0
- package/dist/_exports/fs.js.map +1 -0
- package/dist/_exports/http/helpers.d.ts +3 -0
- package/dist/_exports/http/helpers.d.ts.map +1 -0
- package/dist/_exports/http/helpers.js +5 -0
- package/dist/_exports/http/helpers.js.map +1 -0
- package/dist/_exports/http/request.d.ts +4 -0
- package/dist/_exports/http/request.d.ts.map +1 -0
- package/dist/_exports/http/request.js +10 -0
- package/dist/_exports/http/request.js.map +1 -0
- package/dist/_exports/i2c.d.ts +2 -0
- package/dist/_exports/i2c.d.ts.map +1 -0
- package/dist/_exports/i2c.js +2 -0
- package/dist/_exports/i2c.js.map +1 -0
- package/dist/_exports/index.d.ts +61 -0
- package/dist/_exports/index.d.ts.map +1 -0
- package/dist/_exports/index.js +4 -0
- package/dist/_exports/index.js.map +1 -0
- package/dist/_exports/inspect.d.ts +2 -0
- package/dist/_exports/inspect.d.ts.map +1 -0
- package/dist/_exports/inspect.js +2 -0
- package/dist/_exports/inspect.js.map +1 -0
- package/dist/_exports/kv/nvs.d.ts +3 -0
- package/dist/_exports/kv/nvs.d.ts.map +1 -0
- package/dist/_exports/kv/nvs.js +2 -0
- package/dist/_exports/kv/nvs.js.map +1 -0
- package/dist/_exports/kv/rtc.d.ts +3 -0
- package/dist/_exports/kv/rtc.d.ts.map +1 -0
- package/dist/_exports/kv/rtc.js +2 -0
- package/dist/_exports/kv/rtc.js.map +1 -0
- package/dist/_exports/neopixel.d.ts +2 -0
- package/dist/_exports/neopixel.d.ts.map +1 -0
- package/dist/_exports/neopixel.js +2 -0
- package/dist/_exports/neopixel.js.map +1 -0
- package/dist/_exports/pin.d.ts +2 -0
- package/dist/_exports/pin.d.ts.map +1 -0
- package/dist/_exports/pin.js +2 -0
- package/dist/_exports/pin.js.map +1 -0
- package/dist/_exports/pwm.d.ts +2 -0
- package/dist/_exports/pwm.d.ts.map +1 -0
- package/dist/_exports/pwm.js +2 -0
- package/dist/_exports/pwm.js.map +1 -0
- package/dist/_exports/reader.d.ts +2 -0
- package/dist/_exports/reader.d.ts.map +1 -0
- package/dist/_exports/reader.js +2 -0
- package/dist/_exports/reader.js.map +1 -0
- package/dist/_exports/result.d.ts +2 -0
- package/dist/_exports/result.d.ts.map +1 -0
- package/dist/_exports/result.js +2 -0
- package/dist/_exports/result.js.map +1 -0
- package/dist/_exports/schema.d.ts +2 -0
- package/dist/_exports/schema.d.ts.map +1 -0
- package/dist/_exports/schema.js +2 -0
- package/dist/_exports/schema.js.map +1 -0
- package/dist/_exports/sim.d.ts +199 -0
- package/dist/_exports/sim.d.ts.map +1 -0
- package/dist/_exports/sim.js +8 -0
- package/dist/_exports/sim.js.map +1 -0
- package/dist/_exports/sleep.d.ts +2 -0
- package/dist/_exports/sleep.d.ts.map +1 -0
- package/dist/_exports/sleep.js +2 -0
- package/dist/_exports/sleep.js.map +1 -0
- package/dist/_exports/sntp.d.ts +3 -0
- package/dist/_exports/sntp.d.ts.map +1 -0
- package/dist/_exports/sntp.js +2 -0
- package/dist/_exports/sntp.js.map +1 -0
- package/dist/_exports/spi.d.ts +2 -0
- package/dist/_exports/spi.d.ts.map +1 -0
- package/dist/_exports/spi.js +2 -0
- package/dist/_exports/spi.js.map +1 -0
- package/dist/_exports/stdio.d.ts +2 -0
- package/dist/_exports/stdio.d.ts.map +1 -0
- package/dist/_exports/stdio.js +2 -0
- package/dist/_exports/stdio.js.map +1 -0
- package/dist/_exports/stream.d.ts +2 -0
- package/dist/_exports/stream.d.ts.map +1 -0
- package/dist/_exports/stream.js +2 -0
- package/dist/_exports/stream.js.map +1 -0
- package/dist/_exports/sys.d.ts +2 -0
- package/dist/_exports/sys.d.ts.map +1 -0
- package/dist/_exports/sys.js +2 -0
- package/dist/_exports/sys.js.map +1 -0
- package/dist/_exports/test.d.ts +2 -0
- package/dist/_exports/test.d.ts.map +1 -0
- package/dist/_exports/test.js +2 -0
- package/dist/_exports/test.js.map +1 -0
- package/dist/_exports/uart.d.ts +2 -0
- package/dist/_exports/uart.d.ts.map +1 -0
- package/dist/_exports/uart.js +2 -0
- package/dist/_exports/uart.js.map +1 -0
- package/dist/_exports/wifi.d.ts +3 -0
- package/dist/_exports/wifi.d.ts.map +1 -0
- package/dist/_exports/wifi.js +2 -0
- package/dist/_exports/wifi.js.map +1 -0
- package/dist/cli/cli.d.ts +3 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +215 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/cliWrapper.d.ts +3 -0
- package/dist/cli/cliWrapper.d.ts.map +1 -0
- package/dist/cli/cliWrapper.js +40 -0
- package/dist/cli/cliWrapper.js.map +1 -0
- package/dist/cli/commands/build-runtime.d.ts +14 -0
- package/dist/cli/commands/build-runtime.d.ts.map +1 -0
- package/dist/cli/commands/build-runtime.js +122 -0
- package/dist/cli/commands/build-runtime.js.map +1 -0
- package/dist/cli/commands/build.d.ts +31 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +145 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/clean.d.ts +16 -0
- package/dist/cli/commands/clean.d.ts.map +1 -0
- package/dist/cli/commands/clean.js +148 -0
- package/dist/cli/commands/clean.js.map +1 -0
- package/dist/cli/commands/console.d.ts +19 -0
- package/dist/cli/commands/console.d.ts.map +1 -0
- package/dist/cli/commands/console.js +32 -0
- package/dist/cli/commands/console.js.map +1 -0
- package/dist/cli/commands/deploy.d.ts +63 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +242 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +41 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +170 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/docs.d.ts +7 -0
- package/dist/cli/commands/docs.d.ts.map +1 -0
- package/dist/cli/commands/docs.js +20 -0
- package/dist/cli/commands/docs.js.map +1 -0
- package/dist/cli/commands/env.d.ts +59 -0
- package/dist/cli/commands/env.d.ts.map +1 -0
- package/dist/cli/commands/env.js +257 -0
- package/dist/cli/commands/env.js.map +1 -0
- package/dist/cli/commands/erase.d.ts +18 -0
- package/dist/cli/commands/erase.d.ts.map +1 -0
- package/dist/cli/commands/erase.js +90 -0
- package/dist/cli/commands/erase.js.map +1 -0
- package/dist/cli/commands/flash.d.ts +30 -0
- package/dist/cli/commands/flash.d.ts.map +1 -0
- package/dist/cli/commands/flash.js +243 -0
- package/dist/cli/commands/flash.js.map +1 -0
- package/dist/cli/commands/home.d.ts +7 -0
- package/dist/cli/commands/home.d.ts.map +1 -0
- package/dist/cli/commands/home.js +20 -0
- package/dist/cli/commands/home.js.map +1 -0
- package/dist/cli/commands/ls.d.ts +17 -0
- package/dist/cli/commands/ls.d.ts.map +1 -0
- package/dist/cli/commands/ls.js +62 -0
- package/dist/cli/commands/ls.js.map +1 -0
- package/dist/cli/commands/sim/clean.d.ts +7 -0
- package/dist/cli/commands/sim/clean.d.ts.map +1 -0
- package/dist/cli/commands/sim/clean.js +34 -0
- package/dist/cli/commands/sim/clean.js.map +1 -0
- package/dist/cli/commands/sim/deploy.d.ts +46 -0
- package/dist/cli/commands/sim/deploy.d.ts.map +1 -0
- package/dist/cli/commands/sim/deploy.js +127 -0
- package/dist/cli/commands/sim/deploy.js.map +1 -0
- package/dist/cli/commands/sim/dev.d.ts +52 -0
- package/dist/cli/commands/sim/dev.d.ts.map +1 -0
- package/dist/cli/commands/sim/dev.js +380 -0
- package/dist/cli/commands/sim/dev.js.map +1 -0
- package/dist/cli/commands/sim/env.d.ts +56 -0
- package/dist/cli/commands/sim/env.d.ts.map +1 -0
- package/dist/cli/commands/sim/env.js +204 -0
- package/dist/cli/commands/sim/env.js.map +1 -0
- package/dist/cli/commands/sim/profile.d.ts +67 -0
- package/dist/cli/commands/sim/profile.d.ts.map +1 -0
- package/dist/cli/commands/sim/profile.js +356 -0
- package/dist/cli/commands/sim/profile.js.map +1 -0
- package/dist/cli/commands/sim/repl.d.ts +16 -0
- package/dist/cli/commands/sim/repl.d.ts.map +1 -0
- package/dist/cli/commands/sim/repl.js +119 -0
- package/dist/cli/commands/sim/repl.js.map +1 -0
- package/dist/cli/commands/sim/reset.d.ts +11 -0
- package/dist/cli/commands/sim/reset.d.ts.map +1 -0
- package/dist/cli/commands/sim/reset.js +59 -0
- package/dist/cli/commands/sim/reset.js.map +1 -0
- package/dist/cli/commands/sim/scaffold.d.ts +11 -0
- package/dist/cli/commands/sim/scaffold.d.ts.map +1 -0
- package/dist/cli/commands/sim/scaffold.js +41 -0
- package/dist/cli/commands/sim/scaffold.js.map +1 -0
- package/dist/cli/commands/sim/test.d.ts +49 -0
- package/dist/cli/commands/sim/test.d.ts.map +1 -0
- package/dist/cli/commands/sim/test.js +364 -0
- package/dist/cli/commands/sim/test.js.map +1 -0
- package/dist/cli/commands/sim.d.ts +228 -0
- package/dist/cli/commands/sim.d.ts.map +1 -0
- package/dist/cli/commands/sim.js +69 -0
- package/dist/cli/commands/sim.js.map +1 -0
- package/dist/cli/commands/tail.d.ts +14 -0
- package/dist/cli/commands/tail.d.ts.map +1 -0
- package/dist/cli/commands/tail.js +50 -0
- package/dist/cli/commands/tail.js.map +1 -0
- package/dist/cli/commands/test.d.ts +39 -0
- package/dist/cli/commands/test.d.ts.map +1 -0
- package/dist/cli/commands/test.js +432 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/components/DevicePicker.d.ts +9 -0
- package/dist/cli/components/DevicePicker.d.ts.map +1 -0
- package/dist/cli/components/DevicePicker.js +71 -0
- package/dist/cli/components/DevicePicker.js.map +1 -0
- package/dist/cli/components/EnvEditor.d.ts +12 -0
- package/dist/cli/components/EnvEditor.d.ts.map +1 -0
- package/dist/cli/components/EnvEditor.js +201 -0
- package/dist/cli/components/EnvEditor.js.map +1 -0
- package/dist/cli/components/TextInput.d.ts +28 -0
- package/dist/cli/components/TextInput.d.ts.map +1 -0
- package/dist/cli/components/TextInput.js +73 -0
- package/dist/cli/components/TextInput.js.map +1 -0
- package/dist/cli/components/TitledBox.d.ts +27 -0
- package/dist/cli/components/TitledBox.d.ts.map +1 -0
- package/dist/cli/components/TitledBox.js +111 -0
- package/dist/cli/components/TitledBox.js.map +1 -0
- package/dist/cli/hooks/useDevices.d.ts +23 -0
- package/dist/cli/hooks/useDevices.d.ts.map +1 -0
- package/dist/cli/hooks/useDevices.js +19 -0
- package/dist/cli/hooks/useDevices.js.map +1 -0
- package/dist/cli/lib/RenderAndExit.d.ts +6 -0
- package/dist/cli/lib/RenderAndExit.d.ts.map +1 -0
- package/dist/cli/lib/RenderAndExit.js +8 -0
- package/dist/cli/lib/RenderAndExit.js.map +1 -0
- package/dist/cli/lib/Spinner.d.ts +11 -0
- package/dist/cli/lib/Spinner.d.ts.map +1 -0
- package/dist/cli/lib/Spinner.js +22 -0
- package/dist/cli/lib/Spinner.js.map +1 -0
- package/dist/cli/lib/agent.d.ts +38 -0
- package/dist/cli/lib/agent.d.ts.map +1 -0
- package/dist/cli/lib/agent.js +87 -0
- package/dist/cli/lib/agent.js.map +1 -0
- package/dist/cli/lib/boards.d.ts +23 -0
- package/dist/cli/lib/boards.d.ts.map +1 -0
- package/dist/cli/lib/boards.js +67 -0
- package/dist/cli/lib/boards.js.map +1 -0
- package/dist/cli/lib/build.d.ts +47 -0
- package/dist/cli/lib/build.d.ts.map +1 -0
- package/dist/cli/lib/build.js +533 -0
- package/dist/cli/lib/build.js.map +1 -0
- package/dist/cli/lib/connectSim.d.ts +21 -0
- package/dist/cli/lib/connectSim.d.ts.map +1 -0
- package/dist/cli/lib/connectSim.js +20 -0
- package/dist/cli/lib/connectSim.js.map +1 -0
- package/dist/cli/lib/deploy.d.ts +42 -0
- package/dist/cli/lib/deploy.d.ts.map +1 -0
- package/dist/cli/lib/deploy.js +121 -0
- package/dist/cli/lib/deploy.js.map +1 -0
- package/dist/cli/lib/deployProgress.d.ts +8 -0
- package/dist/cli/lib/deployProgress.d.ts.map +1 -0
- package/dist/cli/lib/deployProgress.js +32 -0
- package/dist/cli/lib/deployProgress.js.map +1 -0
- package/dist/cli/lib/dotenv.d.ts +16 -0
- package/dist/cli/lib/dotenv.d.ts.map +1 -0
- package/dist/cli/lib/dotenv.js +33 -0
- package/dist/cli/lib/dotenv.js.map +1 -0
- package/dist/cli/lib/esbuild.d.ts +7 -0
- package/dist/cli/lib/esbuild.d.ts.map +1 -0
- package/dist/cli/lib/esbuild.js +15 -0
- package/dist/cli/lib/esbuild.js.map +1 -0
- package/dist/cli/lib/esptool.d.ts +41 -0
- package/dist/cli/lib/esptool.d.ts.map +1 -0
- package/dist/cli/lib/esptool.js +43 -0
- package/dist/cli/lib/esptool.js.map +1 -0
- package/dist/cli/lib/firmware.d.ts +24 -0
- package/dist/cli/lib/firmware.d.ts.map +1 -0
- package/dist/cli/lib/firmware.js +406 -0
- package/dist/cli/lib/firmware.js.map +1 -0
- package/dist/cli/lib/firmwareCompat.d.ts +19 -0
- package/dist/cli/lib/firmwareCompat.d.ts.map +1 -0
- package/dist/cli/lib/firmwareCompat.js +31 -0
- package/dist/cli/lib/firmwareCompat.js.map +1 -0
- package/dist/cli/lib/heapBaseline.d.ts +15 -0
- package/dist/cli/lib/heapBaseline.d.ts.map +1 -0
- package/dist/cli/lib/heapBaseline.js +39 -0
- package/dist/cli/lib/heapBaseline.js.map +1 -0
- package/dist/cli/lib/ink-table/index.d.ts +88 -0
- package/dist/cli/lib/ink-table/index.d.ts.map +1 -0
- package/dist/cli/lib/ink-table/index.js +217 -0
- package/dist/cli/lib/ink-table/index.js.map +1 -0
- package/dist/cli/lib/loadMikroConfig.d.ts +7 -0
- package/dist/cli/lib/loadMikroConfig.d.ts.map +1 -0
- package/dist/cli/lib/loadMikroConfig.js +26 -0
- package/dist/cli/lib/loadMikroConfig.js.map +1 -0
- package/dist/cli/lib/minify.d.ts +3 -0
- package/dist/cli/lib/minify.d.ts.map +1 -0
- package/dist/cli/lib/minify.js +89 -0
- package/dist/cli/lib/minify.js.map +1 -0
- package/dist/cli/lib/openSim.d.ts +29 -0
- package/dist/cli/lib/openSim.d.ts.map +1 -0
- package/dist/cli/lib/openSim.js +32 -0
- package/dist/cli/lib/openSim.js.map +1 -0
- package/dist/cli/lib/ospawn.d.ts +34 -0
- package/dist/cli/lib/ospawn.d.ts.map +1 -0
- package/dist/cli/lib/ospawn.js +90 -0
- package/dist/cli/lib/ospawn.js.map +1 -0
- package/dist/cli/lib/parseMinifier.d.ts +10 -0
- package/dist/cli/lib/parseMinifier.d.ts.map +1 -0
- package/dist/cli/lib/parseMinifier.js +49 -0
- package/dist/cli/lib/parseMinifier.js.map +1 -0
- package/dist/cli/lib/parseSize.d.ts +6 -0
- package/dist/cli/lib/parseSize.d.ts.map +1 -0
- package/dist/cli/lib/parseSize.js +25 -0
- package/dist/cli/lib/parseSize.js.map +1 -0
- package/dist/cli/lib/projectRoot.d.ts +11 -0
- package/dist/cli/lib/projectRoot.d.ts.map +1 -0
- package/dist/cli/lib/projectRoot.js +28 -0
- package/dist/cli/lib/projectRoot.js.map +1 -0
- package/dist/cli/lib/protocol.d.ts +144 -0
- package/dist/cli/lib/protocol.d.ts.map +1 -0
- package/dist/cli/lib/protocol.js +385 -0
- package/dist/cli/lib/protocol.js.map +1 -0
- package/dist/cli/lib/recover.d.ts +25 -0
- package/dist/cli/lib/recover.d.ts.map +1 -0
- package/dist/cli/lib/recover.js +144 -0
- package/dist/cli/lib/recover.js.map +1 -0
- package/dist/cli/lib/resolveEntry.d.ts +7 -0
- package/dist/cli/lib/resolveEntry.d.ts.map +1 -0
- package/dist/cli/lib/resolveEntry.js +30 -0
- package/dist/cli/lib/resolveEntry.js.map +1 -0
- package/dist/cli/lib/runHooks.d.ts +34 -0
- package/dist/cli/lib/runHooks.d.ts.map +1 -0
- package/dist/cli/lib/runHooks.js +90 -0
- package/dist/cli/lib/runHooks.js.map +1 -0
- package/dist/cli/lib/serial/InkReplConsole.d.ts +27 -0
- package/dist/cli/lib/serial/InkReplConsole.d.ts.map +1 -0
- package/dist/cli/lib/serial/InkReplConsole.js +24 -0
- package/dist/cli/lib/serial/InkReplConsole.js.map +1 -0
- package/dist/cli/lib/serial/InkReplMode.d.ts +38 -0
- package/dist/cli/lib/serial/InkReplMode.d.ts.map +1 -0
- package/dist/cli/lib/serial/InkReplMode.js +90 -0
- package/dist/cli/lib/serial/InkReplMode.js.map +1 -0
- package/dist/cli/lib/serial/ReplConsole.d.ts +21 -0
- package/dist/cli/lib/serial/ReplConsole.d.ts.map +1 -0
- package/dist/cli/lib/serial/ReplConsole.js +249 -0
- package/dist/cli/lib/serial/ReplConsole.js.map +1 -0
- package/dist/cli/lib/serial/devSession.d.ts +57 -0
- package/dist/cli/lib/serial/devSession.d.ts.map +1 -0
- package/dist/cli/lib/serial/devSession.js +160 -0
- package/dist/cli/lib/serial/devSession.js.map +1 -0
- package/dist/cli/lib/serial/dispatchReplCommand.d.ts +25 -0
- package/dist/cli/lib/serial/dispatchReplCommand.d.ts.map +1 -0
- package/dist/cli/lib/serial/dispatchReplCommand.js +27 -0
- package/dist/cli/lib/serial/dispatchReplCommand.js.map +1 -0
- package/dist/cli/lib/serial/openSession.d.ts +28 -0
- package/dist/cli/lib/serial/openSession.d.ts.map +1 -0
- package/dist/cli/lib/serial/openSession.js +48 -0
- package/dist/cli/lib/serial/openSession.js.map +1 -0
- package/dist/cli/lib/serial/replStateMachine.d.ts +169 -0
- package/dist/cli/lib/serial/replStateMachine.d.ts.map +1 -0
- package/dist/cli/lib/serial/replStateMachine.js +657 -0
- package/dist/cli/lib/serial/replStateMachine.js.map +1 -0
- package/dist/cli/lib/serial/runAgentRepl.d.ts +33 -0
- package/dist/cli/lib/serial/runAgentRepl.d.ts.map +1 -0
- package/dist/cli/lib/serial/runAgentRepl.js +80 -0
- package/dist/cli/lib/serial/runAgentRepl.js.map +1 -0
- package/dist/cli/lib/session.d.ts +163 -0
- package/dist/cli/lib/session.d.ts.map +1 -0
- package/dist/cli/lib/session.js +490 -0
- package/dist/cli/lib/session.js.map +1 -0
- package/dist/cli/lib/simConfig.d.ts +15 -0
- package/dist/cli/lib/simConfig.d.ts.map +1 -0
- package/dist/cli/lib/simConfig.js +25 -0
- package/dist/cli/lib/simConfig.js.map +1 -0
- package/dist/cli/lib/simPid.d.ts +30 -0
- package/dist/cli/lib/simPid.d.ts.map +1 -0
- package/dist/cli/lib/simPid.js +120 -0
- package/dist/cli/lib/simPid.js.map +1 -0
- package/dist/cli/lib/simTransport.d.ts +17 -0
- package/dist/cli/lib/simTransport.d.ts.map +1 -0
- package/dist/cli/lib/simTransport.js +80 -0
- package/dist/cli/lib/simTransport.js.map +1 -0
- package/dist/cli/lib/testRunner.d.ts +86 -0
- package/dist/cli/lib/testRunner.d.ts.map +1 -0
- package/dist/cli/lib/testRunner.js +469 -0
- package/dist/cli/lib/testRunner.js.map +1 -0
- package/dist/cli/lib/transport.d.ts +34 -0
- package/dist/cli/lib/transport.d.ts.map +1 -0
- package/dist/cli/lib/transport.js +117 -0
- package/dist/cli/lib/transport.js.map +1 -0
- package/dist/cli/lib/useObservable.d.ts +4 -0
- package/dist/cli/lib/useObservable.d.ts.map +1 -0
- package/dist/cli/lib/useObservable.js +22 -0
- package/dist/cli/lib/useObservable.js.map +1 -0
- package/dist/cli/lib/watcher.d.ts +10 -0
- package/dist/cli/lib/watcher.d.ts.map +1 -0
- package/dist/cli/lib/watcher.js +34 -0
- package/dist/cli/lib/watcher.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +27 -0
- package/dist/constants.js.map +1 -0
- package/dist/simulator/builtins/ble.d.ts +3 -0
- package/dist/simulator/builtins/ble.d.ts.map +1 -0
- package/dist/simulator/builtins/ble.js +46 -0
- package/dist/simulator/builtins/ble.js.map +1 -0
- package/dist/simulator/builtins/console.d.ts +8 -0
- package/dist/simulator/builtins/console.d.ts.map +1 -0
- package/dist/simulator/builtins/console.js +24 -0
- package/dist/simulator/builtins/console.js.map +1 -0
- package/dist/simulator/builtins/http.d.ts +3 -0
- package/dist/simulator/builtins/http.d.ts.map +1 -0
- package/dist/simulator/builtins/http.js +90 -0
- package/dist/simulator/builtins/http.js.map +1 -0
- package/dist/simulator/builtins/i2c.d.ts +3 -0
- package/dist/simulator/builtins/i2c.d.ts.map +1 -0
- package/dist/simulator/builtins/i2c.js +17 -0
- package/dist/simulator/builtins/i2c.js.map +1 -0
- package/dist/simulator/builtins/index.d.ts +7 -0
- package/dist/simulator/builtins/index.d.ts.map +1 -0
- package/dist/simulator/builtins/index.js +49 -0
- package/dist/simulator/builtins/index.js.map +1 -0
- package/dist/simulator/builtins/kv.d.ts +3 -0
- package/dist/simulator/builtins/kv.d.ts.map +1 -0
- package/dist/simulator/builtins/kv.js +39 -0
- package/dist/simulator/builtins/kv.js.map +1 -0
- package/dist/simulator/builtins/neopixel.d.ts +3 -0
- package/dist/simulator/builtins/neopixel.d.ts.map +1 -0
- package/dist/simulator/builtins/neopixel.js +15 -0
- package/dist/simulator/builtins/neopixel.js.map +1 -0
- package/dist/simulator/builtins/nvs-kv.d.ts +3 -0
- package/dist/simulator/builtins/nvs-kv.d.ts.map +1 -0
- package/dist/simulator/builtins/nvs-kv.js +69 -0
- package/dist/simulator/builtins/nvs-kv.js.map +1 -0
- package/dist/simulator/builtins/pin.d.ts +3 -0
- package/dist/simulator/builtins/pin.d.ts.map +1 -0
- package/dist/simulator/builtins/pin.js +32 -0
- package/dist/simulator/builtins/pin.js.map +1 -0
- package/dist/simulator/builtins/pwm.d.ts +3 -0
- package/dist/simulator/builtins/pwm.d.ts.map +1 -0
- package/dist/simulator/builtins/pwm.js +31 -0
- package/dist/simulator/builtins/pwm.js.map +1 -0
- package/dist/simulator/builtins/sleep.d.ts +3 -0
- package/dist/simulator/builtins/sleep.d.ts.map +1 -0
- package/dist/simulator/builtins/sleep.js +33 -0
- package/dist/simulator/builtins/sleep.js.map +1 -0
- package/dist/simulator/builtins/sntp.d.ts +3 -0
- package/dist/simulator/builtins/sntp.d.ts.map +1 -0
- package/dist/simulator/builtins/sntp.js +14 -0
- package/dist/simulator/builtins/sntp.js.map +1 -0
- package/dist/simulator/builtins/spi.d.ts +3 -0
- package/dist/simulator/builtins/spi.d.ts.map +1 -0
- package/dist/simulator/builtins/spi.js +16 -0
- package/dist/simulator/builtins/spi.js.map +1 -0
- package/dist/simulator/builtins/types.d.ts +24 -0
- package/dist/simulator/builtins/types.d.ts.map +1 -0
- package/dist/simulator/builtins/types.js +2 -0
- package/dist/simulator/builtins/types.js.map +1 -0
- package/dist/simulator/builtins/uart.d.ts +3 -0
- package/dist/simulator/builtins/uart.d.ts.map +1 -0
- package/dist/simulator/builtins/uart.js +22 -0
- package/dist/simulator/builtins/uart.js.map +1 -0
- package/dist/simulator/builtins/wifi.d.ts +3 -0
- package/dist/simulator/builtins/wifi.d.ts.map +1 -0
- package/dist/simulator/builtins/wifi.js +55 -0
- package/dist/simulator/builtins/wifi.js.map +1 -0
- package/dist/simulator/devRunner.d.ts +41 -0
- package/dist/simulator/devRunner.d.ts.map +1 -0
- package/dist/simulator/devRunner.js +201 -0
- package/dist/simulator/devRunner.js.map +1 -0
- package/dist/simulator/loadSimStubs.d.ts +15 -0
- package/dist/simulator/loadSimStubs.d.ts.map +1 -0
- package/dist/simulator/loadSimStubs.js +54 -0
- package/dist/simulator/loadSimStubs.js.map +1 -0
- package/dist/simulator/simProcess.d.ts +11 -0
- package/dist/simulator/simProcess.d.ts.map +1 -0
- package/dist/simulator/simProcess.js +957 -0
- package/dist/simulator/simProcess.js.map +1 -0
- package/dist/simulator/simTemplates.d.ts +6 -0
- package/dist/simulator/simTemplates.d.ts.map +1 -0
- package/dist/simulator/simTemplates.js +21 -0
- package/dist/simulator/simTemplates.js.map +1 -0
- package/package.json +123 -2
- package/runtime.d.ts +95 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { command, constant, message, optional } from '@optique/core';
|
|
3
|
+
import { object as objectConstruct, or as orConstruct } from '@optique/core/constructs';
|
|
4
|
+
import { argument, flag } from '@optique/core/primitives';
|
|
5
|
+
import { string } from '@optique/core/valueparser';
|
|
6
|
+
import { agentError, agentResult, isAgentMode } from '../../lib/agent.js';
|
|
7
|
+
import { openSim } from '../../lib/openSim.js';
|
|
8
|
+
import { SimAlreadyRunningError } from '../../lib/simPid.js';
|
|
9
|
+
const jsonFlag = optional(flag('--json', { description: message `Output as JSON` }));
|
|
10
|
+
const agentFlag = optional(flag('--agent', { description: message `Output as JSON (agent mode)` }));
|
|
11
|
+
const listArgs = command('list', objectConstruct({
|
|
12
|
+
envSubcommand: constant('list'),
|
|
13
|
+
json: jsonFlag,
|
|
14
|
+
agent: agentFlag,
|
|
15
|
+
}));
|
|
16
|
+
const getArgs = command('get', objectConstruct({
|
|
17
|
+
envSubcommand: constant('get'),
|
|
18
|
+
key: argument(string({ metavar: 'KEY' })),
|
|
19
|
+
json: jsonFlag,
|
|
20
|
+
agent: agentFlag,
|
|
21
|
+
}));
|
|
22
|
+
const setArgs = command('set', objectConstruct({
|
|
23
|
+
envSubcommand: constant('set'),
|
|
24
|
+
secret: optional(flag('--secret', {
|
|
25
|
+
description: message `Mark value as a secret (write-only, never displayed)`,
|
|
26
|
+
})),
|
|
27
|
+
key: argument(string({ metavar: 'KEY' })),
|
|
28
|
+
value: optional(argument(string({ metavar: 'VALUE' }))),
|
|
29
|
+
json: jsonFlag,
|
|
30
|
+
agent: agentFlag,
|
|
31
|
+
}));
|
|
32
|
+
const deleteArgs = command('delete', objectConstruct({
|
|
33
|
+
envSubcommand: constant('delete'),
|
|
34
|
+
key: argument(string({ metavar: 'KEY' })),
|
|
35
|
+
json: jsonFlag,
|
|
36
|
+
agent: agentFlag,
|
|
37
|
+
}));
|
|
38
|
+
export const args = command('env', objectConstruct({
|
|
39
|
+
subcommand: constant('env'),
|
|
40
|
+
envSub: orConstruct(listArgs, getArgs, setArgs, deleteArgs),
|
|
41
|
+
}), { description: message `Manage environment variables stored in the simulator` });
|
|
42
|
+
async function withSimSession(fn) {
|
|
43
|
+
const { session, transport } = await openSim();
|
|
44
|
+
try {
|
|
45
|
+
return await fn(session);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
session.close();
|
|
49
|
+
transport.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function run(config) {
|
|
53
|
+
const sub = config.envSub;
|
|
54
|
+
const jsonOutput = sub.json === true || isAgentMode(sub.agent);
|
|
55
|
+
try {
|
|
56
|
+
switch (sub.envSubcommand) {
|
|
57
|
+
case 'list': {
|
|
58
|
+
await withSimSession(async (session) => {
|
|
59
|
+
const entries = await session.config.list();
|
|
60
|
+
if (jsonOutput) {
|
|
61
|
+
agentResult('sim env list', entries.map((e) => ({
|
|
62
|
+
key: e.key,
|
|
63
|
+
value: e.secret ? undefined : e.value,
|
|
64
|
+
secret: e.secret,
|
|
65
|
+
})), [
|
|
66
|
+
{ command: 'mikro sim env set <KEY> <VALUE>', description: 'Set an env variable' },
|
|
67
|
+
{ command: 'mikro sim env delete <KEY>', description: 'Delete an env variable' },
|
|
68
|
+
]);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (entries.length === 0) {
|
|
72
|
+
console.log('No env variables configured');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const envEntries = entries.filter((e) => !e.secret);
|
|
76
|
+
const secretEntries = entries.filter((e) => e.secret);
|
|
77
|
+
if (envEntries.length > 0) {
|
|
78
|
+
const maxKeyLen = Math.max(...envEntries.map((e) => e.key.length));
|
|
79
|
+
for (const e of envEntries)
|
|
80
|
+
console.log(`${e.key.padEnd(maxKeyLen)} ${e.value}`);
|
|
81
|
+
}
|
|
82
|
+
for (const e of secretEntries)
|
|
83
|
+
console.log(`${e.key} ********`);
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'get': {
|
|
88
|
+
await withSimSession(async (session) => {
|
|
89
|
+
const entries = await session.config.list();
|
|
90
|
+
const entry = entries.find((e) => e.key === sub.key);
|
|
91
|
+
if (!entry) {
|
|
92
|
+
if (jsonOutput) {
|
|
93
|
+
agentError('sim env get', `Not found: ${sub.key}`, {
|
|
94
|
+
fix: 'Run mikro sim env list to see available keys',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.error(`Not found: ${sub.key}`);
|
|
99
|
+
}
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
if (jsonOutput) {
|
|
103
|
+
agentResult('sim env get', {
|
|
104
|
+
key: entry.key,
|
|
105
|
+
value: entry.secret ? undefined : entry.value,
|
|
106
|
+
secret: entry.secret,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else if (entry.secret) {
|
|
110
|
+
console.log('********');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.log(entry.value);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'set': {
|
|
119
|
+
const { key, secret: isSecret } = sub;
|
|
120
|
+
if (Buffer.byteLength(key, 'utf-8') > 15) {
|
|
121
|
+
if (jsonOutput) {
|
|
122
|
+
agentError('sim env set', `Key "${key}" exceeds NVS 15-char limit`, {
|
|
123
|
+
fix: 'Use a key with 15 or fewer characters',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.error(`Error: key "${key}" exceeds NVS 15-char limit`);
|
|
128
|
+
}
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
if (!sub.value) {
|
|
132
|
+
if (jsonOutput) {
|
|
133
|
+
agentError('sim env set', 'Missing VALUE', {
|
|
134
|
+
fix: 'Provide a value: mikro sim env set <KEY> <VALUE>',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.error('Error: missing VALUE');
|
|
139
|
+
}
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
await withSimSession(async (session) => {
|
|
143
|
+
await session.config.set(key, sub.value, isSecret === true);
|
|
144
|
+
if (jsonOutput) {
|
|
145
|
+
agentResult('sim env set', { key }, [
|
|
146
|
+
{ command: 'mikro sim env list', description: 'List all env variables' },
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
else if (isSecret) {
|
|
150
|
+
console.log(`Set secret ${key}`);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
console.log(`Set ${key}=${sub.value}`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'delete': {
|
|
159
|
+
const { key } = sub;
|
|
160
|
+
await withSimSession(async (session) => {
|
|
161
|
+
const entries = await session.config.list();
|
|
162
|
+
const entry = entries.find((e) => e.key === key);
|
|
163
|
+
if (!entry) {
|
|
164
|
+
if (jsonOutput) {
|
|
165
|
+
agentError('sim env delete', `Not found: ${key}`, {
|
|
166
|
+
fix: 'Run mikro sim env list to see available keys',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.error(`Not found: ${key}`);
|
|
171
|
+
}
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
await session.config.delete(key);
|
|
175
|
+
if (jsonOutput) {
|
|
176
|
+
agentResult('sim env delete', { key }, [
|
|
177
|
+
{ command: 'mikro sim env list', description: 'List all env variables' },
|
|
178
|
+
]);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
console.log(`Deleted ${key}`);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (err instanceof SimAlreadyRunningError) {
|
|
190
|
+
if (jsonOutput) {
|
|
191
|
+
agentError('sim env', err.message, {
|
|
192
|
+
fix: 'Stop the running sim (Ctrl-C in that terminal), then retry.',
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
console.error(`Error: ${err.message}`);
|
|
197
|
+
}
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
throw err;
|
|
201
|
+
}
|
|
202
|
+
process.exit(0);
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../../src/cli/commands/sim/env.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,eAAe,CAAA;AAClE,OAAO,EAAC,MAAM,IAAI,eAAe,EAAE,EAA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MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBAChC,IAAI,UAAU,EAAE,CAAC;wBACf,WAAW,CAAC,gBAAgB,EAAE,EAAC,GAAG,EAAC,EAAE;4BACnC,EAAC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,wBAAwB,EAAC;yBACvE,CAAC,CAAA;oBACJ,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,EAAE,CAAC,CAAA;oBAC/B,CAAC;gBACH,CAAC,CAAC,CAAA;gBACF,MAAK;YACP,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,sBAAsB,EAAE,CAAC;YAC1C,IAAI,UAAU,EAAE,CAAC;gBACf,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE;oBACjC,GAAG,EAAE,6DAA6D;iBACnE,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;YACxC,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export declare const args: import("@optique/core").Parser<"sync", {
|
|
2
|
+
readonly subcommand: "profile";
|
|
3
|
+
readonly entry: string | undefined;
|
|
4
|
+
readonly memLimit: string | undefined;
|
|
5
|
+
readonly memoryBudget: number | undefined;
|
|
6
|
+
readonly chip: string | undefined;
|
|
7
|
+
readonly top: number | undefined;
|
|
8
|
+
readonly sort: string | undefined;
|
|
9
|
+
readonly minBytes: number | undefined;
|
|
10
|
+
readonly includeNative: true | undefined;
|
|
11
|
+
readonly includeBuiltins: true | undefined;
|
|
12
|
+
readonly onlyNative: true | undefined;
|
|
13
|
+
readonly onlyBuiltins: true | undefined;
|
|
14
|
+
readonly bundle: true | undefined;
|
|
15
|
+
readonly noBundle: true | undefined;
|
|
16
|
+
readonly noMinify: true | undefined;
|
|
17
|
+
readonly minifier: string | undefined;
|
|
18
|
+
readonly minifyLevel: string | undefined;
|
|
19
|
+
readonly json: true | undefined;
|
|
20
|
+
readonly env: string | undefined;
|
|
21
|
+
readonly noEnvFile: true | undefined;
|
|
22
|
+
}, ["matched", string] | ["parsing", {
|
|
23
|
+
readonly subcommand: "profile";
|
|
24
|
+
readonly entry: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
25
|
+
readonly memLimit: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
26
|
+
readonly memoryBudget: [import("@optique/core").ValueParserResult<number> | undefined] | undefined;
|
|
27
|
+
readonly chip: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
28
|
+
readonly top: [import("@optique/core").ValueParserResult<number> | undefined] | undefined;
|
|
29
|
+
readonly sort: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
30
|
+
readonly minBytes: [import("@optique/core").ValueParserResult<number> | undefined] | undefined;
|
|
31
|
+
readonly includeNative: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
32
|
+
readonly includeBuiltins: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
33
|
+
readonly onlyNative: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
34
|
+
readonly onlyBuiltins: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
35
|
+
readonly bundle: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
36
|
+
readonly noBundle: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
37
|
+
readonly noMinify: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
38
|
+
readonly minifier: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
39
|
+
readonly minifyLevel: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
40
|
+
readonly json: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
41
|
+
readonly env: [import("@optique/core").ValueParserResult<string> | undefined] | undefined;
|
|
42
|
+
readonly noEnvFile: [import("@optique/core").ValueParserResult<true> | undefined] | undefined;
|
|
43
|
+
}] | undefined>;
|
|
44
|
+
interface RunConfig {
|
|
45
|
+
entry?: string;
|
|
46
|
+
memLimit?: string;
|
|
47
|
+
memoryBudget?: number;
|
|
48
|
+
chip?: string;
|
|
49
|
+
top?: number;
|
|
50
|
+
sort?: string;
|
|
51
|
+
minBytes?: number;
|
|
52
|
+
includeNative?: boolean;
|
|
53
|
+
includeBuiltins?: boolean;
|
|
54
|
+
onlyNative?: boolean;
|
|
55
|
+
onlyBuiltins?: boolean;
|
|
56
|
+
bundle?: boolean;
|
|
57
|
+
noBundle?: boolean;
|
|
58
|
+
noMinify?: boolean;
|
|
59
|
+
minifier?: string;
|
|
60
|
+
minifyLevel?: string;
|
|
61
|
+
json?: boolean;
|
|
62
|
+
env?: string;
|
|
63
|
+
noEnvFile?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export declare function run(config: RunConfig): Promise<void>;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/sim/profile.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAyFhB,CAAA;AAeD,UAAU,SAAS;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,wBAAsB,GAAG,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAY1D"}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import * as pathlib from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { command, constant, message, optional } from '@optique/core';
|
|
8
|
+
import { object } from '@optique/core/constructs';
|
|
9
|
+
import { argument, flag, option } from '@optique/core/primitives';
|
|
10
|
+
import { integer, string } from '@optique/core/valueparser';
|
|
11
|
+
import { path } from '@optique/run';
|
|
12
|
+
import { lastValueFrom } from 'rxjs';
|
|
13
|
+
import { build } from '../../lib/build.js';
|
|
14
|
+
import { connectSim } from '../../lib/connectSim.js';
|
|
15
|
+
import { collectFiles, loadEnvFiles } from '../../lib/deploy.js';
|
|
16
|
+
import { parseMinifier, parseMinifyLevel } from '../../lib/parseMinifier.js';
|
|
17
|
+
import { parseSize } from '../../lib/parseSize.js';
|
|
18
|
+
import { getMikroDir, resolveProjectRoot } from '../../lib/projectRoot.js';
|
|
19
|
+
import { resolveEntry } from '../../lib/resolveEntry.js';
|
|
20
|
+
import { loadSimConfig } from '../../lib/simConfig.js';
|
|
21
|
+
import { checkPid, SimAlreadyRunningError } from '../../lib/simPid.js';
|
|
22
|
+
// Profile mode measures, not enforces. Default to 32 MB so apps larger than
|
|
23
|
+
// the device-realistic ceiling can still be profiled. Override with --mem-limit.
|
|
24
|
+
const DEFAULT_PROFILE_MEM_LIMIT_BYTES = 32 * 1024 * 1024;
|
|
25
|
+
export const args = command('profile', object({
|
|
26
|
+
subcommand: constant('profile'),
|
|
27
|
+
entry: optional(argument(path({ metavar: 'ENTRY', mustExist: true, type: 'file' }))),
|
|
28
|
+
memLimit: optional(option('--mem-limit', string({ metavar: 'BYTES' }), {
|
|
29
|
+
description: message `QuickJS heap ceiling for the profile run (default: 32M). Supports K/M/G suffixes.`,
|
|
30
|
+
})),
|
|
31
|
+
memoryBudget: optional(option('--memory-budget', integer({ metavar: 'KB' }), {
|
|
32
|
+
description: message `Memory budget in KB for highlighting rows over budget`,
|
|
33
|
+
})),
|
|
34
|
+
chip: optional(option('--chip', string({ metavar: 'NAME' }), {
|
|
35
|
+
description: message `Chip preset for --memory-budget (e.g. esp32c6)`,
|
|
36
|
+
})),
|
|
37
|
+
top: optional(option('--top', integer({ metavar: 'N' }), {
|
|
38
|
+
description: message `Show only the N largest modules`,
|
|
39
|
+
})),
|
|
40
|
+
sort: optional(option('--sort', string({ metavar: 'KEY' }), {
|
|
41
|
+
description: message `Sort by "size" (default) or "order"`,
|
|
42
|
+
})),
|
|
43
|
+
minBytes: optional(option('--min-bytes', integer({ metavar: 'N' }), {
|
|
44
|
+
description: message `Hide modules smaller than N bytes`,
|
|
45
|
+
})),
|
|
46
|
+
includeNative: optional(flag('--include-native', {
|
|
47
|
+
description: message `Include native:* runtime modules in the output (excluded by default)`,
|
|
48
|
+
})),
|
|
49
|
+
includeBuiltins: optional(flag('--include-builtins', {
|
|
50
|
+
description: message `Include mikrojs/* built-in modules in the output (excluded by default)`,
|
|
51
|
+
})),
|
|
52
|
+
onlyNative: optional(flag('--only-native', {
|
|
53
|
+
description: message `Show only native:* modules (whitelist; overrides --include-*)`,
|
|
54
|
+
})),
|
|
55
|
+
onlyBuiltins: optional(flag('--only-builtins', {
|
|
56
|
+
description: message `Show only mikrojs/* built-ins (whitelist; overrides --include-*)`,
|
|
57
|
+
})),
|
|
58
|
+
bundle: optional(flag('--bundle', {
|
|
59
|
+
description: message `Enable bundling even if mikro.config.ts disables it`,
|
|
60
|
+
})),
|
|
61
|
+
noBundle: optional(flag('--no-bundle', {
|
|
62
|
+
description: message `Disable bundling even if mikro.config.ts enables it`,
|
|
63
|
+
})),
|
|
64
|
+
noMinify: optional(flag('--no-minify', { description: message `Skip minification` })),
|
|
65
|
+
minifier: optional(option('--minifier', string({ metavar: 'NAME' }), {
|
|
66
|
+
description: message `Minifier: esbuild, terser, or swc (default: esbuild)`,
|
|
67
|
+
})),
|
|
68
|
+
minifyLevel: optional(option('--minify-level', string({ metavar: 'LEVEL' }), {
|
|
69
|
+
description: message `Minify level: default or max`,
|
|
70
|
+
})),
|
|
71
|
+
json: optional(flag('--json', { description: message `Output as JSON` })),
|
|
72
|
+
env: optional(option('--env', string({ metavar: 'FILE' }), {
|
|
73
|
+
description: message `Path to .env file with environment variables`,
|
|
74
|
+
})),
|
|
75
|
+
noEnvFile: optional(flag('--no-env-file', {
|
|
76
|
+
description: message `Skip auto-loading of .env and .env.development from the project root`,
|
|
77
|
+
})),
|
|
78
|
+
}), { description: message `Profile per-module QuickJS heap usage in the simulator` });
|
|
79
|
+
const CHIP_BUDGETS_KB = {
|
|
80
|
+
esp32: 200,
|
|
81
|
+
esp32c3: 180,
|
|
82
|
+
esp32c6: 240,
|
|
83
|
+
esp32s3: 260,
|
|
84
|
+
};
|
|
85
|
+
export async function run(config) {
|
|
86
|
+
try {
|
|
87
|
+
await runImpl(config);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (err instanceof SimAlreadyRunningError) {
|
|
91
|
+
console.error(`Error: ${err.message}`);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
console.error(`mikro sim profile failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
95
|
+
if (err instanceof Error && err.stack)
|
|
96
|
+
console.error(err.stack);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function runImpl(config) {
|
|
101
|
+
const mikroDir = getMikroDir();
|
|
102
|
+
checkPid(mikroDir);
|
|
103
|
+
const entry = resolveEntry(config.entry);
|
|
104
|
+
const buildDir = pathlib.join(getMikroDir(), 'build');
|
|
105
|
+
const log = (msg) => console.error(msg);
|
|
106
|
+
const minify = !config.noMinify;
|
|
107
|
+
const minifier = parseMinifier(config.minifier);
|
|
108
|
+
const minifyLevel = parseMinifyLevel(config.minifyLevel);
|
|
109
|
+
log(`Building ${entry}…`);
|
|
110
|
+
const bundle = config.noBundle === true ? false : config.bundle === true ? true : undefined;
|
|
111
|
+
await lastValueFrom(build(entry, buildDir, { minify, bytecode: true, minifier, minifyLevel, bundle }), { defaultValue: undefined });
|
|
112
|
+
const files = await collectFiles(buildDir);
|
|
113
|
+
log(`Built ${files.length} file(s)`);
|
|
114
|
+
const envVars = [
|
|
115
|
+
{ key: 'MIKRO_ENV', value: 'development', secret: false },
|
|
116
|
+
...(await loadEnvFiles({
|
|
117
|
+
cwd: resolveProjectRoot(),
|
|
118
|
+
mode: 'development',
|
|
119
|
+
envFile: config.env,
|
|
120
|
+
noEnvFile: config.noEnvFile === true,
|
|
121
|
+
})),
|
|
122
|
+
];
|
|
123
|
+
const sim = await loadSimConfig(pathlib.dirname(entry));
|
|
124
|
+
// Wipe any previously-deployed app from sim-fs before connecting. The first
|
|
125
|
+
// simProcess spawned by connectSim calls bootRuntime() on startup, which
|
|
126
|
+
// evaluates whatever was previously staged in sim-fs/app. If the last run
|
|
127
|
+
// left a broken app there, that boot crashes and we never get to deploy the
|
|
128
|
+
// fresh build. Since profile is a one-shot transient operation, blowing
|
|
129
|
+
// away the prior state is always the right thing.
|
|
130
|
+
const appDir = pathlib.join(sim.fsRoot, 'app');
|
|
131
|
+
if (existsSync(appDir))
|
|
132
|
+
rmSync(appDir, { force: true, recursive: true });
|
|
133
|
+
const profileMemLimit = config.memLimit
|
|
134
|
+
? parseSize(config.memLimit)
|
|
135
|
+
: DEFAULT_PROFILE_MEM_LIMIT_BYTES;
|
|
136
|
+
log('Staging to simulator…');
|
|
137
|
+
const stage = connectSim(sim, { memLimitOverride: profileMemLimit });
|
|
138
|
+
try {
|
|
139
|
+
const last = await lastValueFrom(stage.session.deploy({ files, envVars, erase: true, restart: false }));
|
|
140
|
+
if (last.type !== 'complete')
|
|
141
|
+
throw new Error('Deploy did not complete');
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
stage.session.close();
|
|
145
|
+
stage.transport.close();
|
|
146
|
+
}
|
|
147
|
+
const tmpDir = tmpdir();
|
|
148
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
149
|
+
const profilePath = pathlib.join(tmpDir, `mikro-profile-${process.pid}.json`);
|
|
150
|
+
try {
|
|
151
|
+
log('Profiling…');
|
|
152
|
+
await runProfileSubprocess(sim.fsRoot, profileMemLimit, profilePath);
|
|
153
|
+
const { entries, baseline } = readProfile(profilePath);
|
|
154
|
+
if (entries.length === 0) {
|
|
155
|
+
log('Warning: profile is empty. No modules were loaded during boot.');
|
|
156
|
+
}
|
|
157
|
+
renderProfile(entries, {
|
|
158
|
+
baseline,
|
|
159
|
+
memoryBudgetKB: resolveBudget(config.memoryBudget, config.chip),
|
|
160
|
+
chipName: config.chip,
|
|
161
|
+
top: config.top,
|
|
162
|
+
sort: config.sort ?? 'size',
|
|
163
|
+
minBytes: config.minBytes ?? 0,
|
|
164
|
+
includeNative: config.includeNative === true,
|
|
165
|
+
includeBuiltins: config.includeBuiltins === true,
|
|
166
|
+
onlyNative: config.onlyNative === true,
|
|
167
|
+
onlyBuiltins: config.onlyBuiltins === true,
|
|
168
|
+
json: config.json === true,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
try {
|
|
173
|
+
rmSync(profilePath, { force: true });
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// best-effort cleanup
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function resolveBudget(explicit, chip) {
|
|
181
|
+
if (explicit !== undefined)
|
|
182
|
+
return explicit;
|
|
183
|
+
if (chip !== undefined) {
|
|
184
|
+
const preset = CHIP_BUDGETS_KB[chip];
|
|
185
|
+
if (preset === undefined) {
|
|
186
|
+
console.error(`Unknown chip '${chip}'. Known: ${Object.keys(CHIP_BUDGETS_KB).join(', ')}. ` +
|
|
187
|
+
`Use --memory-budget to set an explicit value.`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
return preset;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
function runProfileSubprocess(fsRoot, memLimitBytes, profilePath) {
|
|
195
|
+
return new Promise((resolve, reject) => {
|
|
196
|
+
const entryPath = fileURLToPath(new URL('../../../simulator/simProcess.js', import.meta.url));
|
|
197
|
+
const childArgs = [
|
|
198
|
+
entryPath,
|
|
199
|
+
'--fs-root',
|
|
200
|
+
fsRoot,
|
|
201
|
+
'--mem-limit',
|
|
202
|
+
String(memLimitBytes),
|
|
203
|
+
'--profile-output',
|
|
204
|
+
profilePath,
|
|
205
|
+
];
|
|
206
|
+
const stdoutChunks = [];
|
|
207
|
+
const child = spawn(process.execPath, childArgs, { stdio: ['ignore', 'pipe', 'inherit'] });
|
|
208
|
+
child.stdout?.on('data', (chunk) => stdoutChunks.push(chunk));
|
|
209
|
+
child.on('error', reject);
|
|
210
|
+
child.on('exit', (code, signal) => {
|
|
211
|
+
if (code === 0) {
|
|
212
|
+
resolve();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const stdoutPreview = Buffer.concat(stdoutChunks).toString('utf-8').slice(0, 500);
|
|
216
|
+
const tail = stdoutPreview ? `\nsimProcess stdout: ${stdoutPreview}` : '';
|
|
217
|
+
reject(new Error(`simProcess exited with code=${code} signal=${signal ?? 'none'}\n` +
|
|
218
|
+
` node ${childArgs.join(' ')}${tail}`));
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function readProfile(profilePath) {
|
|
223
|
+
if (!existsSync(profilePath)) {
|
|
224
|
+
throw new Error(`simProcess did not write profile to ${profilePath}. ` +
|
|
225
|
+
`This usually means bootRuntime failed or no app was deployed.`);
|
|
226
|
+
}
|
|
227
|
+
const raw = readFileSync(profilePath, 'utf-8');
|
|
228
|
+
const parsed = JSON.parse(raw);
|
|
229
|
+
return { entries: parsed.entries, baseline: parsed.baseline ?? 0 };
|
|
230
|
+
}
|
|
231
|
+
function classifyEntry(name) {
|
|
232
|
+
if (name.startsWith('native:'))
|
|
233
|
+
return 'native';
|
|
234
|
+
if (name.startsWith('mikrojs/'))
|
|
235
|
+
return 'builtin';
|
|
236
|
+
return 'user';
|
|
237
|
+
}
|
|
238
|
+
function renderProfile(entries, opts) {
|
|
239
|
+
// Whitelist mode: if any --only-* flag is set, only those kinds are shown
|
|
240
|
+
// and --include-* is ignored. Otherwise we hide runtime kinds by default
|
|
241
|
+
// and the user opts in via --include-*.
|
|
242
|
+
const whitelistMode = opts.onlyNative || opts.onlyBuiltins;
|
|
243
|
+
const showNative = whitelistMode ? opts.onlyNative : opts.includeNative;
|
|
244
|
+
const showBuiltins = whitelistMode ? opts.onlyBuiltins : opts.includeBuiltins;
|
|
245
|
+
const showUser = !whitelistMode;
|
|
246
|
+
const nativeEntries = entries.filter((e) => classifyEntry(e.name) === 'native');
|
|
247
|
+
const builtinEntries = entries.filter((e) => classifyEntry(e.name) === 'builtin');
|
|
248
|
+
const userEntries = entries.filter((e) => classifyEntry(e.name) === 'user');
|
|
249
|
+
const visibleEntries = entries.filter((e) => {
|
|
250
|
+
const kind = classifyEntry(e.name);
|
|
251
|
+
if (kind === 'native')
|
|
252
|
+
return showNative;
|
|
253
|
+
if (kind === 'builtin')
|
|
254
|
+
return showBuiltins;
|
|
255
|
+
return showUser;
|
|
256
|
+
});
|
|
257
|
+
const filtered = visibleEntries.filter((e) => e.deltaBytes >= opts.minBytes);
|
|
258
|
+
const sorted = opts.sort === 'order'
|
|
259
|
+
? [...filtered].sort((a, b) => a.order - b.order)
|
|
260
|
+
: [...filtered].sort((a, b) => b.deltaBytes - a.deltaBytes);
|
|
261
|
+
const displayed = opts.top !== undefined ? sorted.slice(0, opts.top) : sorted;
|
|
262
|
+
const visibleTotalBytes = visibleEntries.reduce((sum, e) => sum + e.deltaBytes, 0);
|
|
263
|
+
const nativeTotalBytes = nativeEntries.reduce((sum, e) => sum + e.deltaBytes, 0);
|
|
264
|
+
const builtinTotalBytes = builtinEntries.reduce((sum, e) => sum + e.deltaBytes, 0);
|
|
265
|
+
const userTotalBytes = userEntries.reduce((sum, e) => sum + e.deltaBytes, 0);
|
|
266
|
+
// In whitelist mode, users asked for a specific view — don't add noise
|
|
267
|
+
// about what's hidden. In default mode, surface runtime cost explicitly
|
|
268
|
+
// so it's clear why the number is lower than expected.
|
|
269
|
+
const hiddenNative = !whitelistMode && !showNative && nativeEntries.length > 0;
|
|
270
|
+
const hiddenBuiltins = !whitelistMode && !showBuiltins && builtinEntries.length > 0;
|
|
271
|
+
const hiddenUser = whitelistMode && userEntries.length > 0;
|
|
272
|
+
const baselineKB = opts.baseline / 1024;
|
|
273
|
+
const allModuleTotalBytes = entries.reduce((sum, e) => sum + e.deltaBytes, 0);
|
|
274
|
+
const grandTotalKB = (opts.baseline + allModuleTotalBytes) / 1024;
|
|
275
|
+
if (opts.json) {
|
|
276
|
+
console.log(JSON.stringify({
|
|
277
|
+
baseline: opts.baseline,
|
|
278
|
+
moduleCount: visibleEntries.length,
|
|
279
|
+
totalBytes: visibleTotalBytes,
|
|
280
|
+
grandTotalBytes: opts.baseline + allModuleTotalBytes,
|
|
281
|
+
budgetBytes: opts.memoryBudgetKB !== null ? opts.memoryBudgetKB * 1024 : null,
|
|
282
|
+
entries: displayed,
|
|
283
|
+
hidden: {
|
|
284
|
+
native: hiddenNative ? { count: nativeEntries.length, bytes: nativeTotalBytes } : null,
|
|
285
|
+
builtins: hiddenBuiltins
|
|
286
|
+
? { count: builtinEntries.length, bytes: builtinTotalBytes }
|
|
287
|
+
: null,
|
|
288
|
+
user: hiddenUser ? { count: userEntries.length, bytes: userTotalBytes } : null,
|
|
289
|
+
},
|
|
290
|
+
}, null, 2));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const totalKB = visibleTotalBytes / 1024;
|
|
294
|
+
const budgetBytes = opts.memoryBudgetKB !== null ? opts.memoryBudgetKB * 1024 : null;
|
|
295
|
+
console.log(`QuickJS baseline: ${baselineKB.toFixed(1)} KB (runtime + context + intrinsics)`);
|
|
296
|
+
const header = `Module profile — ${visibleEntries.length} modules, ${totalKB.toFixed(1)} KB load cost, ${grandTotalKB.toFixed(1)} KB total`;
|
|
297
|
+
console.log(header);
|
|
298
|
+
console.log(dim(` Load cost only; linking + evaluation overhead not included`));
|
|
299
|
+
if (hiddenNative) {
|
|
300
|
+
const kb = nativeTotalBytes / 1024;
|
|
301
|
+
console.log(dim(` ${nativeEntries.length} native:* module(s) hidden (${kb.toFixed(1)} KB). Pass --include-native to show.`));
|
|
302
|
+
}
|
|
303
|
+
if (hiddenBuiltins) {
|
|
304
|
+
const kb = builtinTotalBytes / 1024;
|
|
305
|
+
console.log(dim(` ${builtinEntries.length} mikrojs/* module(s) hidden (${kb.toFixed(1)} KB). Pass --include-builtins to show.`));
|
|
306
|
+
}
|
|
307
|
+
if (hiddenUser) {
|
|
308
|
+
const kb = userTotalBytes / 1024;
|
|
309
|
+
console.log(dim(` ${userEntries.length} user module(s) hidden (${kb.toFixed(1)} KB) by --only-*.`));
|
|
310
|
+
}
|
|
311
|
+
if (budgetBytes !== null) {
|
|
312
|
+
const pct = (visibleTotalBytes / budgetBytes) * 100;
|
|
313
|
+
const budgetLabel = opts.chipName
|
|
314
|
+
? `${opts.memoryBudgetKB} KB (${opts.chipName})`
|
|
315
|
+
: `${opts.memoryBudgetKB} KB`;
|
|
316
|
+
const footer = `Budget: ${budgetLabel}, used ${totalKB.toFixed(1)} KB (${pct.toFixed(0)}%)`;
|
|
317
|
+
console.log(pct > 100 ? red(footer) : pct >= 80 ? yellow(footer) : footer);
|
|
318
|
+
}
|
|
319
|
+
console.log('');
|
|
320
|
+
const nameWidth = Math.min(Math.max(10, ...displayed.map((e) => e.name.length)), 60);
|
|
321
|
+
const sizeHeader = 'Size';
|
|
322
|
+
const cumHeader = 'Cumulative';
|
|
323
|
+
console.log(` ${'Module'.padEnd(nameWidth)} ${sizeHeader.padStart(8)} ${cumHeader.padStart(12)}`);
|
|
324
|
+
let cumulative = 0;
|
|
325
|
+
for (const entry of displayed) {
|
|
326
|
+
cumulative += entry.deltaBytes;
|
|
327
|
+
const sizeCell = formatKB(entry.deltaBytes).padStart(8);
|
|
328
|
+
const cumCell = formatKB(cumulative).padStart(12);
|
|
329
|
+
const nameCell = truncate(entry.name, nameWidth).padEnd(nameWidth);
|
|
330
|
+
const row = ` ${nameCell} ${sizeCell} ${cumCell}`;
|
|
331
|
+
console.log(colorizeRow(row, entry.deltaBytes, cumulative, budgetBytes));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function formatKB(bytes) {
|
|
335
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
336
|
+
}
|
|
337
|
+
function truncate(s, max) {
|
|
338
|
+
if (s.length <= max)
|
|
339
|
+
return s;
|
|
340
|
+
return s.slice(0, max - 1) + '…';
|
|
341
|
+
}
|
|
342
|
+
function colorizeRow(row, deltaBytes, cumulative, budgetBytes) {
|
|
343
|
+
if (budgetBytes === null)
|
|
344
|
+
return row;
|
|
345
|
+
if (deltaBytes > budgetBytes * 0.25)
|
|
346
|
+
return red(row);
|
|
347
|
+
if (cumulative > budgetBytes)
|
|
348
|
+
return red(row);
|
|
349
|
+
if (deltaBytes > Math.min(budgetBytes * 0.1, 10 * 1024))
|
|
350
|
+
return yellow(row);
|
|
351
|
+
return row;
|
|
352
|
+
}
|
|
353
|
+
const red = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
354
|
+
const yellow = (s) => `\x1b[33m${s}\x1b[0m`;
|
|
355
|
+
const dim = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
356
|
+
//# sourceMappingURL=profile.js.map
|