File tree Expand file tree Collapse file tree 9 files changed +14
-45
lines changed Expand file tree Collapse file tree 9 files changed +14
-45
lines changed Original file line number Diff line number Diff line change 3131 with :
3232 node-version : 22
3333
34- # - name: Install depencies
34+ # - name: Install dependencies
3535 # shell: bash
3636 # run: npm install --ws
3737
Original file line number Diff line number Diff line change 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" ,
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" : [
Original file line number Diff line number Diff 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).
510class 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 } ) ;
Original file line number Diff line number Diff line change 11import yargs from 'yargs' ;
22import { hideBin } from 'yargs/helpers' ;
33
4- // Defining the shape of the arguments using TypeScript
54export 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' ,
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import { basename } from 'node:path';
77
88import {
99 calculateChecksum ,
10- getPackageVersion ,
1110 saveBuildData ,
1211} from './utils.js' ;
1312import { getCliArgs } from './cli.js' ;
Original file line number Diff line number Diff line change 11import { readFile } from 'fs/promises' ;
2- import { fileURLToPath } from 'url' ;
3- import path from 'path' ;
42import { createHash } from 'node:crypto' ;
53import { 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
407export async function calculateChecksum ( filePath : string ) {
Original file line number Diff line number Diff line change 11package spinframework : wasi-cli-environment @ 0.2.3;
22
3+ # Needed because of https://github.com/bytecodealliance/ComponentizeJS/issues/194
34world wasi-cli {
45 import wasi :cli /environment @ 0.2.3 ;
56}
Original file line number Diff line number Diff line change 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" : {
You can’t perform that action at this time.
0 commit comments