Skip to content

update to componentizeJS 0.17 #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2025
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/j2w.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ const args = yargs(hideBin(process.argv))
describe: "Spin trigger to target",
demandOption: true
})
.option('debug-build', {
describe: "Use debug build of the runtime",
type: 'boolean',
})
.option('aot', {
describe: "Enable Ahead of Time compilation",
type: 'boolean',
})
.check((argv) => {
if (argv['debug-build'] && argv['runtime-path']) {
throw new Error("The --runtime-path option cannot be used when --debug-build is enabled.");
}
return true;
})
.argv;

const src = args.input;
Expand Down Expand Up @@ -123,6 +133,7 @@ async function saveBuildData(buildDataPath, checksum, version) {
worldName: args.triggerType,
disableFeatures: [],
enableFeatures: ["http"],
debugBuild: args.debugBuild ?? false,
enableAot: args.aot
});

Expand Down
1 change: 1 addition & 0 deletions bin/wit/deps/[email protected]/spin.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fermyon:[email protected];

world spin-imports {
import wasi:cli/[email protected];
import wasi:http/[email protected];
import llm;
import redis;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fermyon/spin-sdk",
"version": "3.1.0",
"version": "3.2.0",
"description": "",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -26,7 +26,7 @@
"typescript": "^5.4.3"
},
"dependencies": {
"@bytecodealliance/componentize-js": "^0.16.0",
"@bytecodealliance/componentize-js": "^0.17.0",
"@fermyon/knitwit": "^0.3.0",
"acorn-walk": "^8.3.4",
"acron": "^1.0.5",
Expand All @@ -45,4 +45,4 @@
"world": "spin-imports"
}
}
}
}
34 changes: 16 additions & 18 deletions plugins/webpack/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
class SpinSdkPlugin {
constructor() {
this.externals = {
"wasi:http/[email protected]": "wasi:http/[email protected]",
"wasi:cli/[email protected]": "wasi:cli/[email protected]",
"wasi:filesystem/[email protected]": "wasi:filesystem/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"fermyon:spin/[email protected]": "fermyon:spin/[email protected]",
"wasi:config/[email protected]": "wasi:config/[email protected]",
"spin:postgres/[email protected]": "spin:postgres/[email protected]",
};
this.externals = [
/^wasi:.*/,
/^fermyon:.*/,
/^spin:.*/,
];
}

apply(compiler) {
// If externals are already defined, merge them with new externals
if (compiler.options.externals && typeof compiler.options.externals === 'object') {
this.externals = Object.assign({}, compiler.options.externals, this.externals);
const userExternals = compiler.options.externals;

if (Array.isArray(userExternals)) {
// Append to the existing array
compiler.options.externals = [...userExternals, ...this.externals];
} else if (typeof userExternals === 'object') {
// Wrap in an array and add the object as-is
compiler.options.externals = [userExternals, ...this.externals];
} else {
// Default: Just use our externals
compiler.options.externals = [...this.externals];
}
compiler.options.externals = this.externals;
}
}

Expand Down
15 changes: 9 additions & 6 deletions test/test-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions test/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/test-app.wasm --aot",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit --out-dir build/wit/knitwit"
"build": "knitwit --out-dir build/wit/knitwit && npx webpack --mode=production && npx mkdirp dist && npx j2w --debug-build -i build/bundle.js -d build/wit/knitwit -n combined -o dist/test-app.wasm --aot",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
Expand All @@ -22,4 +21,4 @@
"@fermyon/spin-sdk": "file:../../",
"itty-router": "^5.0.18"
}
}
}