Skip to content

Commit d11f4ab

Browse files
authored
Merge pull request #381 from karthik2804/update_templates
Update templates
2 parents 875deae + 1de996e commit d11f4ab

File tree

17 files changed

+191
-84
lines changed

17 files changed

+191
-84
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist.js
88
dist/
99
build/
1010
docs/
11+
!templates/**/.vscode/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "starlingmonkey",
6+
"request": "launch",
7+
"name": "Debug StarlingMonkey component",
8+
"component": "${workspaceFolder}/dist/{{ project-name | kebab_case }}.wasm",
9+
"program": "${workspaceFolder}/src/index.js",
10+
"stopOnEntry": false,
11+
"trace": true
12+
}
13+
]
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"starlingmonkey": {
3+
"componentRuntime": {
4+
"executable": "spin",
5+
"options": [
6+
"up",
7+
"-f",
8+
"${workspaceFolder}",
9+
],
10+
}
11+
}
12+
}

templates/http-js/content/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ To use additional Spin interfaces, install the corresponding packages:
2929
| PostgreSQL | `@spinframework/spin-postgres` |
3030
| Redis | `@spinframework/spin-redis` |
3131
| SQLite | `@spinframework/spin-sqlite` |
32-
| Variables | `@spinframework/spin-variables` |
32+
| Variables | `@spinframework/spin-variables` |
33+
34+
## Using the StarlingMonkey Debugger for VS Code
35+
36+
1. First install the [StarlingMonkey Debugger](https://marketplace.visualstudio.com/items?itemName=BytecodeAlliance.starlingmonkey-debugger) extension.
37+
2. Build the component using the debug command `npm run build:debug`.
38+
3. Uncomment `tcp://127.0.0.1:*` in the `allowed_outbound_hosts` field in the `spin.toml`.
39+
4. Start the debugger in VS Code which should start Spin and attach the debugger. The debugger needs to be restarted for each http call.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// build.mjs
2+
import { build } from 'esbuild';
3+
import path from 'path';
4+
import { SpinEsbuildPlugin } from "@spinframework/build-tools/plugins/esbuild/index.js";
5+
import fs from 'fs';
6+
7+
const spinPlugin = await SpinEsbuildPlugin();
8+
9+
// plugin to handle vendor files in node_modules that may not be bundled.
10+
// Instead of generating a real source map for these files, it appends a minimal
11+
// inline source map pointing to an empty source. This avoids errors and ensures
12+
// source maps exist even for unbundled vendor code.
13+
let SourceMapPlugin = {
14+
name: 'excludeVendorFromSourceMap',
15+
setup(build) {
16+
build.onLoad({ filter: /node_modules/ }, args => {
17+
return {
18+
contents: fs.readFileSync(args.path, 'utf8')
19+
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
20+
loader: 'default',
21+
}
22+
})
23+
},
24+
}
25+
26+
await build({
27+
entryPoints: ['./src/index.js'],
28+
outfile: './build/bundle.js',
29+
bundle: true,
30+
format: 'esm',
31+
platform: 'node',
32+
sourcemap: true,
33+
minify: false,
34+
plugins: [spinPlugin, SourceMapPlugin],
35+
logLevel: 'error',
36+
loader: {
37+
'.ts': 'ts',
38+
'.tsx': 'tsx',
39+
},
40+
resolveExtensions: ['.ts', '.tsx', '.js'],
41+
sourceRoot: path.resolve(process.cwd(), 'src'),
42+
});

templates/http-js/content/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
"description": "{{project-description}}",
55
"main": "index.js",
66
"scripts": {
7-
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js --initLocation http://{{project-name | kebab_case}}.localhost -o dist/{{ project-name | kebab_case }}.wasm",
7+
"build": "node build.mjs && mkdirp dist && j2w -i build/bundle.js --initLocation http://{{project-name | kebab_case}}.localhost -o dist/{{ project-name | kebab_case }}.wasm",
8+
"build:debug": "node build.mjs && mkdirp dist && j2w -d -i build/bundle.js --initLocation http://{{project-name | kebab_case}}.localhost -o dist/{{ project-name | kebab_case }}.wasm",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"keywords": [],
1112
"author": "",
1213
"license": "ISC",
1314
"devDependencies": {
1415
"mkdirp": "^3.0.1",
15-
"webpack": "^5.74.0",
16-
"webpack-cli": "^4.10.0"
16+
"esbuild": "^0.25.8"
1717
},
1818
"dependencies": {
1919
{%- case http-router -%}

templates/http-js/content/spin.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ component = "{{project-name | kebab_case}}"
1313
[component.{{project-name | kebab_case}}]
1414
source = "dist/{{project-name | kebab_case}}.wasm"
1515
exclude_files = ["**/node_modules"]
16+
allowed_outbound_hosts = [
17+
# "tcp://127.0.0.1:*", # Uncomment this line to while using the StarlingMonkey Debugger
18+
]
1619
[component.{{project-name | kebab_case}}.build]
1720
command = ["npm install", "npm run build"]
1821
watch = ["src/**/*.js"]

templates/http-js/content/webpack.config.js

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "starlingmonkey",
6+
"request": "launch",
7+
"name": "Debug StarlingMonkey component",
8+
"component": "${workspaceFolder}/dist/{{ project-name | kebab_case }}.wasm",
9+
"program": "${workspaceFolder}/src/index.ts",
10+
"stopOnEntry": false,
11+
"trace": true
12+
}
13+
]
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"starlingmonkey": {
3+
"componentRuntime": {
4+
"executable": "spin",
5+
"options": [
6+
"up",
7+
"-f",
8+
"${workspaceFolder}",
9+
],
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)