@bytecodealliance/jco 0.12.3 → 0.13.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/jco",
3
- "version": "0.12.3",
3
+ "version": "0.13.1",
4
4
  "description": "JavaScript tooling for working with WebAssembly Components",
5
5
  "author": "Guy Bedford",
6
6
  "bin": {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "type": "module",
20
20
  "dependencies": {
21
- "@bytecodealliance/preview2-shim": "0.0.17",
21
+ "@bytecodealliance/preview2-shim": "0.0.20",
22
22
  "binaryen": "^111.0.0",
23
23
  "chalk-template": "^0.4.0",
24
24
  "commander": "^9.4.1",
@@ -27,7 +27,7 @@
27
27
  "terser": "^5.16.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@bytecodealliance/componentize-js": "^0.3.0",
30
+ "@bytecodealliance/componentize-js": "^0.4.0",
31
31
  "@types/node": "^18.11.17",
32
32
  "@typescript-eslint/eslint-plugin": "^5.41.0",
33
33
  "@typescript-eslint/parser": "^5.41.0",
@@ -52,7 +52,7 @@
52
52
  "homepage": "https://github.com/bytecodealliance/jco#readme",
53
53
  "scripts": {
54
54
  "build": "cargo xtask build workspace",
55
- "build:types:preview2-shim": "cargo xtask build shims",
55
+ "build:types:preview2-shim": "cargo xtask generate wasi-types",
56
56
  "lint": "eslint -c eslintrc.cjs lib/**/*.js packages/*/lib/**/*.js",
57
57
  "test": "mocha -u tdd test/test.js --timeout 120000"
58
58
  },
package/src/cmd/run.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { getTmpDir } from '../common.js';
2
2
  import { transpile } from './transpile.js';
3
- import { rm, stat, mkdir, writeFile, symlink, chmod } from 'node:fs/promises';
3
+ import { rm, stat, mkdir, writeFile, symlink } from 'node:fs/promises';
4
4
  import { basename, resolve, extname } from 'node:path';
5
- import { spawn } from 'node:child_process';
6
- import { argv0, exit } from 'node:process';
5
+ import { fork } from 'node:child_process';
6
+ import process from 'node:process';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import c from 'chalk-template';
9
9
 
10
10
  export async function run (componentPath, args) {
11
+ // Ensure that `args` is an array
12
+ args = [...args];
13
+
11
14
  const name = basename(componentPath.slice(0, -extname(componentPath).length || Infinity));
12
15
  const outDir = await getTmpDir();
13
- let cp;
14
16
  try {
15
17
  try {
16
18
  await transpile(componentPath, {
@@ -22,11 +24,9 @@ export async function run (componentPath, args) {
22
24
  });
23
25
  }
24
26
  catch (e) {
25
- console.error(c`{red ERR}: Unable to transpile command for execution`);
26
- throw e;
27
+ throw new Error('Unable to transpile command for execution', { cause: e });
27
28
  }
28
29
 
29
- await mkdir(resolve(outDir, 'node_modules', '@bytecodealliance'), { recursive: true });
30
30
  await writeFile(resolve(outDir, 'package.json'), JSON.stringify({ type: 'module' }));
31
31
 
32
32
  let preview2ShimPath = fileURLToPath(new URL('../../node_modules/@bytecodealliance/preview2-shim', import.meta.url));
@@ -38,14 +38,15 @@ export async function run (componentPath, args) {
38
38
  }
39
39
  catch {}
40
40
  let len = preview2ShimPath.length;
41
- preview2ShimPath = resolve(preview2ShimPath, '../../../node_modules/@bytecodealliance/preview2-shim');
41
+ preview2ShimPath = resolve(preview2ShimPath, '..', '..', '..', 'node_modules', '@bytecodealliance', 'preview2-shim');
42
42
  if (preview2ShimPath.length === len) {
43
- console.error(c`{red ERR}: Unable to locate the {bold @bytecodealliance/preview2-shim} package, make sure it is installed.`);
44
- return;
43
+ throw c`Unable to locate the {bold @bytecodealliance/preview2-shim} package, make sure it is installed.`;
45
44
  }
46
45
  }
47
46
 
48
- await symlink(preview2ShimPath, resolve(outDir, 'node_modules/@bytecodealliance/preview2-shim'), 'dir');
47
+ const modulesDir = resolve(outDir, 'node_modules', '@bytecodealliance');
48
+ await mkdir(modulesDir, { recursive: true });
49
+ await symlink(preview2ShimPath, resolve(modulesDir, 'preview2-shim'), 'dir');
49
50
 
50
51
  const runPath = resolve(outDir, '_run.js');
51
52
  await writeFile(runPath, `
@@ -71,24 +72,17 @@ export async function run (componentPath, args) {
71
72
  throw e;
72
73
  }
73
74
  `);
74
- await chmod(runPath, 0o777);
75
75
 
76
- cp = spawn(argv0, [runPath, ...args], { stdio: 'inherit' });
76
+ process.exitCode = await new Promise((resolve, reject) => {
77
+ const cp = fork(runPath, args, { stdio: 'inherit' });
78
+
79
+ cp.on('error', reject);
80
+ cp.on('exit', resolve);
81
+ });
77
82
  }
78
83
  finally {
79
- if (!cp) {
80
- try {
81
- await rm(outDir, { recursive: true });
82
- } catch {}
83
- }
84
+ try {
85
+ await rm(outDir, { recursive: true });
86
+ } catch {}
84
87
  }
85
-
86
- const exitCode = await new Promise((resolve, reject) => {
87
- cp.on('error', reject);
88
- cp.on('exit', resolve);
89
- });
90
- try {
91
- await rm(outDir, { recursive: true });
92
- } catch {}
93
- exit(exitCode);
94
88
  }
package/src/jco.js CHANGED
@@ -11,7 +11,7 @@ program
11
11
  .name('jco')
12
12
  .description(c`{bold jco - WebAssembly JS Component Tools}\n JS Component Transpilation Bindgen & Wasm Tools for JS`)
13
13
  .usage('<command> [options]')
14
- .version('0.12.3');
14
+ .version('0.13.1');
15
15
 
16
16
  function myParseInt(value) {
17
17
  return parseInt(value, 10);