Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Install Rust
run: rustup update stable --no-self-update && rustup default stable
- name: Install wasm32-unknown-unknown target
Expand Down
3 changes: 1 addition & 2 deletions packages/preview2-shim/lib/io/worker-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import {
STDOUT,
reverseMap,
} from "./calls.js";
import { exit, stderr, stdout, env } from "node:process";
import nodeProcess, { exit, stderr, stdout, env } from "node:process";

import * as nodeProcess from "node:process";
const _rawDebug = nodeProcess._rawDebug || console.error.bind(console);

const workerPath = fileURLToPath(
Expand Down
2 changes: 1 addition & 1 deletion packages/preview2-shim/lib/nodejs/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argv, env, cwd } from "node:process";
import process, { argv, env, cwd } from "node:process";
import {
ioCall,
streams,
Expand Down
3 changes: 1 addition & 2 deletions packages/preview2-shim/lib/nodejs/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "../io/worker-io.js";
import { INPUT_STREAM_CREATE, OUTPUT_STREAM_CREATE } from "../io/calls.js";
import { FILE } from "../io/calls.js";
import {
import nodeFs, {
closeSync,
constants,
fdatasyncSync,
Expand All @@ -32,7 +32,6 @@ import {
} from "node:fs";
import { platform } from "node:process";

import * as nodeFs from 'node:fs';
const lutimesSync = nodeFs.lutimesSync;

const symbolDispose = Symbol.dispose || Symbol.for("dispose");
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getTmpDir } from '../common.js';
import { transpile } from './transpile.js';
import { rm, stat, mkdir, writeFile, symlink } from 'node:fs/promises';
import { basename, resolve, extname } from 'node:path';
import { fork } from 'node:child_process';
import { spawn } from 'node:child_process';
import process from 'node:process';
import { fileURLToPath, pathToFileURL } from 'node:url';
import c from 'chalk-template';
Expand Down Expand Up @@ -112,15 +112,18 @@ async function runComponent (componentPath, args, opts, executor) {
const runPath = resolve(outDir, '_run.js');
await writeFile(runPath, `
${jcoImport ? `import ${JSON.stringify(pathToFileURL(jcoImport))}` : ''}
import process from 'node:process';
try {
process.argv[1] = "${name}";
} catch {}
const mod = await import('./${name}.js');
${executor}
`);

const nodePath = process.env.JCO_RUN_PATH || process.argv[0];

process.exitCode = await new Promise((resolve, reject) => {
const cp = fork(runPath, args, { stdio: 'inherit' });
const cp = spawn(nodePath, [...process.env.JCO_RUN_ARGS ? process.env.JCO_RUN_ARGS.split(' ') : [], runPath, ...args], { stdio: 'inherit' });

cp.on('error', reject);
cp.on('exit', resolve);
Expand Down
Binary file modified tests/gen/api_proxy.component.wasm
Binary file not shown.
Binary file modified tests/gen/api_proxy_streaming.component.wasm
Binary file not shown.
Binary file modified tests/gen/api_reactor.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/api_reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn api_reactor() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/api_reactor");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/api_read_only.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/api_read_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn api_read_only() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/api_read_only");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/api_time.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/api_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn api_time() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/api_time");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_args.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_args() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_args");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_default_clocks.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_default_clocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_default_clocks() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_default_clocks");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_directory_list.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_directory_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_directory_list() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_directory_list");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_env.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_env() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_env");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_exit_default.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_exit_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_exit_default() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_exit_default");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_exit_failure.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_exit_failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_exit_failure() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_exit_failure");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_exit_panic.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_exit_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_exit_panic() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_exit_panic");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_exit_success.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_exit_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_exit_success() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_exit_success");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_export_cabi_realloc.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_export_cabi_realloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_export_cabi_realloc() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_export_cabi_realloc");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_file_append.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_file_append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_file_append() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_file_append");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_file_dir_sync.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_file_dir_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_file_dir_sync() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_file_dir_sync");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_file_read.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_file_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_file_read() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_file_read");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_hello_stdout.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_hello_stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_hello_stdout() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_hello_stdout");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_no_ip_name_lookup.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_no_ip_name_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_no_ip_name_lookup() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_no_ip_name_lookup");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_no_tcp.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_no_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_no_tcp() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_no_tcp");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_no_udp.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_no_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_no_udp() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_no_udp");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_splice_stdin.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_splice_stdin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_splice_stdin() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_splice_stdin");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_stdin.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_stdin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn cli_stdin() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_stdin");
cmd1.arg("--jco-import");
Expand Down
Binary file modified tests/gen/cli_stdio_write_flushes.component.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion tests/gen/cli_stdio_write_flushes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn cli_stdio_write_flushes() -> anyhow::Result<()> {
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");

cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/cli_stdio_write_flushes");
cmd1.arg("--jco-import");
Expand Down
29 changes: 29 additions & 0 deletions tests/gen/deno_api_reactor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use std::fs;
use std::process::{Command, Stdio};

#[test]
fn api_reactor() -> anyhow::Result<()> {
{
let wasi_file = "./tests/gen/api_reactor.component.wasm";
let _ = fs::remove_dir_all("./tests/rundir/deno_api_reactor");
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");
cmd1.env("JCO_RUN_PATH", "deno")
.env("JCO_RUN_ARGS", "run --importmap ./tests/importmap.json -A");
cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/deno_api_reactor");
cmd1.arg("--jco-import");
cmd1.arg("./tests/virtualenvs/base.js");
cmd1.arg(wasi_file);
cmd1.args(&["hello", "this", "", "is an argument", "with 🚩 emoji"]);
cmd1.stdin(Stdio::null());
let mut cmd1_child = cmd1.spawn().expect("failed to spawn test program");
let status = cmd1_child.wait().expect("failed to wait on child");
assert!(status.success(), "test execution failed");
}
Ok(())
}
29 changes: 29 additions & 0 deletions tests/gen/deno_api_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use std::fs;
use std::process::{Command, Stdio};

#[test]
fn api_time() -> anyhow::Result<()> {
{
let wasi_file = "./tests/gen/api_time.component.wasm";
let _ = fs::remove_dir_all("./tests/rundir/deno_api_time");
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");
cmd1.env("JCO_RUN_PATH", "deno")
.env("JCO_RUN_ARGS", "run --importmap ./tests/importmap.json -A");
cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/deno_api_time");
cmd1.arg("--jco-import");
cmd1.arg("./tests/virtualenvs/fakeclocks.js");
cmd1.arg(wasi_file);
cmd1.args(&["hello", "this", "", "is an argument", "with 🚩 emoji"]);
cmd1.stdin(Stdio::null());
let mut cmd1_child = cmd1.spawn().expect("failed to spawn test program");
let status = cmd1_child.wait().expect("failed to wait on child");
assert!(status.success(), "test execution failed");
}
Ok(())
}
29 changes: 29 additions & 0 deletions tests/gen/deno_cli_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use std::fs;
use std::process::{Command, Stdio};

#[test]
fn cli_args() -> anyhow::Result<()> {
{
let wasi_file = "./tests/gen/cli_args.component.wasm";
let _ = fs::remove_dir_all("./tests/rundir/deno_cli_args");
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");
cmd1.env("JCO_RUN_PATH", "deno")
.env("JCO_RUN_ARGS", "run --importmap ./tests/importmap.json -A");
cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/deno_cli_args");
cmd1.arg("--jco-import");
cmd1.arg("./tests/virtualenvs/base.js");
cmd1.arg(wasi_file);
cmd1.args(&["hello", "this", "", "is an argument", "with 🚩 emoji"]);
cmd1.stdin(Stdio::null());
let mut cmd1_child = cmd1.spawn().expect("failed to spawn test program");
let status = cmd1_child.wait().expect("failed to wait on child");
assert!(status.success(), "test execution failed");
}
Ok(())
}
29 changes: 29 additions & 0 deletions tests/gen/deno_cli_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use std::fs;
use std::process::{Command, Stdio};

#[test]
fn cli_env() -> anyhow::Result<()> {
{
let wasi_file = "./tests/gen/cli_env.component.wasm";
let _ = fs::remove_dir_all("./tests/rundir/deno_cli_env");
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");
cmd1.env("JCO_RUN_PATH", "deno")
.env("JCO_RUN_ARGS", "run --importmap ./tests/importmap.json -A");
cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/deno_cli_env");
cmd1.arg("--jco-import");
cmd1.arg("./tests/virtualenvs/envtest.js");
cmd1.arg(wasi_file);
cmd1.args(&["hello", "this", "", "is an argument", "with 🚩 emoji"]);
cmd1.stdin(Stdio::null());
let mut cmd1_child = cmd1.spawn().expect("failed to spawn test program");
let status = cmd1_child.wait().expect("failed to wait on child");
assert!(status.success(), "test execution failed");
}
Ok(())
}
29 changes: 29 additions & 0 deletions tests/gen/deno_cli_exit_default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use std::fs;
use std::process::{Command, Stdio};

#[test]
fn cli_exit_default() -> anyhow::Result<()> {
{
let wasi_file = "./tests/gen/cli_exit_default.component.wasm";
let _ = fs::remove_dir_all("./tests/rundir/deno_cli_exit_default");
let mut cmd1 = Command::new("node");
cmd1.arg("./src/jco.js");
cmd1.arg("run");
cmd1.env("JCO_RUN_PATH", "deno")
.env("JCO_RUN_ARGS", "run --importmap ./tests/importmap.json -A");
cmd1.arg("--jco-dir");
cmd1.arg("./tests/rundir/deno_cli_exit_default");
cmd1.arg("--jco-import");
cmd1.arg("./tests/virtualenvs/base.js");
cmd1.arg(wasi_file);
cmd1.args(&["hello", "this", "", "is an argument", "with 🚩 emoji"]);
cmd1.stdin(Stdio::null());
let mut cmd1_child = cmd1.spawn().expect("failed to spawn test program");
let status = cmd1_child.wait().expect("failed to wait on child");
assert!(status.success(), "test execution failed");
}
Ok(())
}
Loading