Skip to content

Commit 2ed6d49

Browse files
committed
some review comment fixes and fix test
Signed-off-by: karthik2804 <[email protected]>
1 parent 4f387af commit 2ed6d49

File tree

9 files changed

+14
-45
lines changed

9 files changed

+14
-45
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
with:
3232
node-version: 22
3333

34-
# - name: Install depencies
34+
# - name: Install dependencies
3535
# shell: bash
3636
# run: npm install --ws
3737

packages/build-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@types/mocha": "^10.0.10",
2121
"@types/node": "^22.13.1",
2222
"@types/sinon": "^17.0.3",
23+
"@types/yargs": "^17.0.33",
2324
"chai": "^5.2.0",
2425
"mocha": "^11.1.0",
2526
"prettier": "^3.5.0",
@@ -30,7 +31,6 @@
3031
"dependencies": {
3132
"@bytecodealliance/componentize-js": "^0.18.0",
3233
"@bytecodealliance/jco": "^1.10.2",
33-
"@types/yargs": "^17.0.33",
3434
"yargs": "^17.7.2"
3535
},
3636
"files": [

packages/build-tools/plugins/webpack/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import {
22
getPackagesWithWasiDeps,
33
processWasiDeps,
44
} from '../../dist/wasiDepsParser.js';
5+
6+
// The plugin is used to automatically add the wit imports to the webpack
7+
// externals. This is required because the bindings for wit imports are not
8+
// generated until we are componentizing and webpack needs to consider them
9+
// externals (available at runtime).
510
class SpinSdkPlugin {
611
constructor() {
712
this.externals = {};
@@ -11,11 +16,15 @@ class SpinSdkPlugin {
1116
const { getWitImports } = await import('../../lib/wit_tools.js');
1217
let plugin = new SpinSdkPlugin();
1318

19+
// Get the list of wit dependencies from other packages as defined in the package.json.
1420
let wasiDeps = getPackagesWithWasiDeps(process.cwd(), new Set(), true);
1521
let { witPaths, targetWorlds } = processWasiDeps(wasiDeps);
1622

23+
// Get the list of wit imports from the world
1724
let imports = getWitImports(witPaths, targetWorlds);
1825

26+
// Convert the imports into a format that can be used to define the webpack
27+
// externals that can be applied.
1928
imports.map(i => {
2029
plugin.externals[i] = i;
2130
});

packages/build-tools/src/cli.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import yargs from 'yargs';
22
import { hideBin } from 'yargs/helpers';
33

4-
// Defining the shape of the arguments using TypeScript
54
export interface CliArgs {
65
input: string;
76
output: string;
8-
triggerType: string;
97
witPath?: string;
108
aot?: boolean;
119
debug?: boolean;
@@ -27,11 +25,6 @@ export function getCliArgs(): CliArgs {
2725
describe: 'Path to the output file',
2826
default: 'component.wasm',
2927
})
30-
.option('trigger-type', {
31-
alias: '-t',
32-
describe: 'Spin trigger to target',
33-
demandOption: true,
34-
})
3528
.option('aot', {
3629
describe: 'Enable Ahead of Time compilation',
3730
type: 'boolean',

packages/build-tools/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { basename } from 'node:path';
77

88
import {
99
calculateChecksum,
10-
getPackageVersion,
1110
saveBuildData,
1211
} from './utils.js';
1312
import { getCliArgs } from './cli.js';

packages/build-tools/src/utils.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
11
import { readFile } from 'fs/promises';
2-
import { fileURLToPath } from 'url';
3-
import path from 'path';
42
import { createHash } from 'node:crypto';
53
import { access, writeFile } from 'node:fs/promises';
64

7-
export const getPackageVersion = async (packageName: string) => {
8-
try {
9-
const resolvedPath = await import.meta.resolve(`${packageName}`);
10-
11-
let packageJsonPath = resolvedPath;
12-
let parentDir = path.dirname(fileURLToPath(new URL(packageJsonPath)));
13-
14-
// Walk up the directory structure to find package.json
15-
while (parentDir !== path.dirname(parentDir)) {
16-
const potentialPackageJsonPath = path.join(parentDir, 'package.json');
17-
try {
18-
// Try reading the package.json file in this directory
19-
const packageJsonContents = await readFile(
20-
potentialPackageJsonPath,
21-
'utf-8',
22-
);
23-
const packageJson = JSON.parse(packageJsonContents);
24-
25-
return packageJson.version;
26-
} catch (error) {
27-
parentDir = path.dirname(parentDir);
28-
}
29-
}
30-
31-
console.error(`Error: Could not find package.json for '${packageName}'`);
32-
return null;
33-
} catch (error) {
34-
console.error(`Error: Could not find package '${packageName}'`, error);
35-
return null;
36-
}
37-
};
385

396
// Function to calculate file checksum
407
export async function calculateChecksum(filePath: string) {

packages/build-tools/wit/world.wit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package spinframework:wasi-cli-environment@0.2.3;
22

3+
# Needed because of https://github.com/bytecodealliance/ComponentizeJS/issues/194
34
world wasi-cli {
45
import wasi:cli/environment@0.2.3;
56
}

test/test-app/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"keywords": [],
88
"license": "Apache-2.0",
99
"scripts": {
10-
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -n combined -o dist/test-app.wasm",
10+
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -o dist/test-app.wasm",
1111
"test": "echo \"Error: no test specified\" && exit 1"
1212
},
1313
"devDependencies": {

0 commit comments

Comments
 (0)