@bytecodealliance/jco
Advanced tools
Comparing version 0.12.1 to 0.12.2
{ | ||
"name": "@bytecodealliance/jco", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"description": "JavaScript tooling for working with WebAssembly Components", | ||
@@ -21,3 +21,3 @@ "author": "Guy Bedford", | ||
"dependencies": { | ||
"@bytecodealliance/preview2-shim": "0.0.16", | ||
"@bytecodealliance/preview2-shim": "0.0.17", | ||
"binaryen": "^111.0.0", | ||
@@ -31,3 +31,3 @@ "chalk-template": "^0.4.0", | ||
"devDependencies": { | ||
"@bytecodealliance/componentize-js": "^0.2.0", | ||
"@bytecodealliance/componentize-js": "^0.3.0", | ||
"@types/node": "^18.11.17", | ||
@@ -56,6 +56,6 @@ "@typescript-eslint/eslint-plugin": "^5.41.0", | ||
"scripts": { | ||
"build": "cargo build --workspace --target wasm32-wasi --release && cargo run", | ||
"build:types:preview2-shim": "PREVIEW2_SHIM_TYPES=* cargo build -p jco", | ||
"build": "cargo xtask build workspace", | ||
"build:types:preview2-shim": "cargo xtask build shims", | ||
"lint": "eslint -c eslintrc.cjs lib/**/*.js packages/*/lib/**/*.js", | ||
"test": "rm -rf $(pwd)/node_modules/@bytecodealliance/jco/lib && ln -s $(pwd)/lib $(pwd)/node_modules/@bytecodealliance/jco/ && mocha -u tdd test/test.js --timeout 120000" | ||
"test": "mocha -u tdd test/test.js --timeout 120000" | ||
}, | ||
@@ -62,0 +62,0 @@ "files": [ |
@@ -40,3 +40,3 @@ <div align="center"> | ||
See the [example workflow](EXAMPLE.md) page for a full usage example. | ||
See the [example workflow](docs/src/example.md) page for a full usage example. | ||
@@ -180,8 +180,4 @@ ## CLI | ||
Development is based on a standard `npm install && npm run build && npm run test` workflow. | ||
See the [Contributing](docs/src/contributing.md) chapter of the jco book. | ||
Tests can be run without bundling via `npm run build:dev && npm run test:dev`. | ||
Specific tests can be run adding the mocha `--grep` flag, for example: `npm run test:dev -- --grep exports_only`. | ||
# License | ||
@@ -188,0 +184,0 @@ |
@@ -19,2 +19,3 @@ import { readFile, writeFile } from 'node:fs/promises'; | ||
enableStdout: opts.enableStdout, | ||
preview2Adapter: opts.preview2Adapter, | ||
}); | ||
@@ -21,0 +22,0 @@ await writeFile(opts.out, component); |
@@ -0,3 +1,3 @@ | ||
import { getTmpDir } from '../common.js'; | ||
import { transpile } from './transpile.js'; | ||
import { tmpdir } from 'node:os'; | ||
import { rm, stat, mkdir, writeFile, symlink, chmod } from 'node:fs/promises'; | ||
@@ -8,12 +8,7 @@ import { basename, resolve, extname } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import * as crypto from 'node:crypto'; | ||
import c from 'chalk-template'; | ||
function getTmpDir (name) { | ||
return resolve(tmpdir(), crypto.createHash('sha256').update(name).update(Math.random().toString()).digest('hex')); | ||
} | ||
export async function run (componentPath, args) { | ||
const name = basename(componentPath.slice(0, -extname(componentPath).length || Infinity)); | ||
const outDir = resolve(getTmpDir(name)); | ||
const outDir = await getTmpDir(); | ||
let cp; | ||
@@ -58,6 +53,2 @@ try { | ||
await writeFile(runPath, ` | ||
import { _setEnv, _setArgs, _setCwd } from '@bytecodealliance/preview2-shim/cli'; | ||
_setArgs(process.argv.slice(1)); | ||
_setEnv(process.env); | ||
_setCwd(process.cwd()); | ||
function logInvalidCommand () { | ||
@@ -64,0 +55,0 @@ console.error('Not a valid command component to execute, make sure it was built to a command adapter and with the same version.'); |
@@ -1,5 +0,4 @@ | ||
import crypto from 'node:crypto'; | ||
import { resolve } from 'node:path'; | ||
import { normalize, resolve, sep } from 'node:path'; | ||
import { tmpdir } from 'node:os'; | ||
import { readFile, writeFile, unlink } from 'node:fs/promises'; | ||
import { readFile, writeFile, rm, mkdtemp } from 'node:fs/promises'; | ||
import { spawn } from 'node:child_process'; | ||
@@ -59,4 +58,9 @@ import { argv0 } from 'node:process'; | ||
export function getTmpFile (source, ext) { | ||
return resolve(tmpdir(), crypto.createHash('sha256').update(source).update(Math.random().toString()).digest('hex') + ext); | ||
/** | ||
* Securely creates a temporary directory and returns its path. | ||
* | ||
* The new directory is created using `fsPromises.mkdtemp()`. | ||
*/ | ||
export async function getTmpDir () { | ||
return await mkdtemp(normalize(tmpdir() + sep)); | ||
} | ||
@@ -75,32 +79,31 @@ | ||
export async function spawnIOTmp (cmd, input, args) { | ||
const inFile = getTmpFile(input, '.wasm'); | ||
let outFile = getTmpFile(inFile, '.wasm'); | ||
const tmpDir = await getTmpDir(); | ||
try { | ||
const inFile = resolve(tmpDir, 'in.wasm'); | ||
let outFile = resolve(tmpDir, 'out.wasm'); | ||
await writeFile(inFile, input); | ||
await writeFile(inFile, input); | ||
const cp = spawn(argv0, [cmd, inFile, ...args, outFile], { stdio: 'pipe' }); | ||
const cp = spawn(argv0, [cmd, inFile, ...args, outFile], { stdio: 'pipe' }); | ||
let stderr = ''; | ||
const p = new Promise((resolve, reject) => { | ||
cp.stderr.on('data', data => stderr += data.toString()); | ||
cp.on('error', e => { | ||
reject(e); | ||
let stderr = ''; | ||
const p = new Promise((resolve, reject) => { | ||
cp.stderr.on('data', data => stderr += data.toString()); | ||
cp.on('error', e => { | ||
reject(e); | ||
}); | ||
cp.on('exit', code => { | ||
if (code === 0) | ||
resolve(); | ||
else | ||
reject(stderr); | ||
}); | ||
}); | ||
cp.on('exit', code => { | ||
if (code === 0) | ||
resolve(); | ||
else | ||
reject(stderr); | ||
}); | ||
}); | ||
try { | ||
await p; | ||
var output = await readFile(outFile); | ||
await Promise.all([unlink(inFile), unlink(outFile)]); | ||
return output; | ||
} catch (e) { | ||
await unlink(inFile); | ||
throw e; | ||
} finally { | ||
await rm(tmpDir, { recursive: true }); | ||
} | ||
} |
@@ -14,3 +14,3 @@ #!/usr/bin/env node | ||
.usage('<command> [options]') | ||
.version('0.12.1'); | ||
.version('0.12.2'); | ||
@@ -28,2 +28,3 @@ function myParseInt(value) { | ||
.option('--enable-stdout', 'Allow console.log to output to stdout') | ||
.option('--preview2-adapter <adapter>', 'provide a custom preview2 adapter path') | ||
.requiredOption('-o, --out <out>', 'output component file') | ||
@@ -30,0 +31,0 @@ .action(asyncAction(componentize)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
28606994
43
6410
191
+ Added@bytecodealliance/preview2-shim@0.0.17(transitive)
- Removed@bytecodealliance/preview2-shim@0.0.16(transitive)