/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { existsSync } from "node:fs"; import { realpath } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { exit, stdout } from "node:process"; import { ensureCompiled } from "./ensure-compiled.js"; import { executeNode } from "./execute.js"; /** * Execute a script in a package that conforms to matter.js conventions. This is primarily useful within a matter.js * development environment but should also work when installed via NPM. * * First we translate source filenames to the transpiled *.js equivalent. * * If the target script is in a package not installed via NPM we build the package. If the package is an NPM workspace * under a top-level package we also build dependencies. * * We then run the script in a child process so we can enable source maps using node --source-maps. You can disable * this by setting the environment variable MATTER_DIRECT_EXEC. */ export async function main(argv = process.argv) { let directExec = !!process.env.MATTER_DIRECT_EXEC; // Drop node and matter-run argv = argv.slice(2); const nodeArgv = Array(); // Process arguments to matter-run itself (very simple as of yet so just processing manually) while (argv[0][0] === "-") { const option = argv.shift()!; switch (option) { case "--clear": console.clear(); break; case "--direct": directExec = true; break; case "--help": stdout.write( "Usage: matter-run [--clear] [--direct] [-]...