Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist.js
dist/
build/
docs/
!templates/**/.vscode/
14 changes: 14 additions & 0 deletions templates/http-js/content/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "starlingmonkey",
"request": "launch",
"name": "Debug StarlingMonkey component",
"component": "${workspaceFolder}/dist/{{ project-name | kebab_case }}.wasm",
"program": "${workspaceFolder}/src/index.js",
"stopOnEntry": false,
"trace": true
}
]
}
12 changes: 12 additions & 0 deletions templates/http-js/content/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"starlingmonkey": {
"componentRuntime": {
"executable": "spin",
"options": [
"up",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing to consider here is to change this to watch. That'd probably require/enable other changes to the lifecycle, as the process wouldn't need to be restarted when content changes.

"-f",
"${workspaceFolder}",
],
}
}
}
9 changes: 8 additions & 1 deletion templates/http-js/content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ To use additional Spin interfaces, install the corresponding packages:
| PostgreSQL | `@spinframework/spin-postgres` |
| Redis | `@spinframework/spin-redis` |
| SQLite | `@spinframework/spin-sqlite` |
| Variables | `@spinframework/spin-variables` |
| Variables | `@spinframework/spin-variables` |

## Using the StarlingMonkey Debugger for VS Code

1. First install the [StarlingMonkey Debugger](https://marketplace.visualstudio.com/items?itemName=BytecodeAlliance.starlingmonkey-debugger) extension.
2. Build the component using the debug command `npm run build:debug`.
3. Uncomment `tcp://127.0.0.1:*` in the `allowed_outbound_hosts` field in the `spin.toml`.
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.
42 changes: 42 additions & 0 deletions templates/http-js/content/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// build.mjs
import { build } from 'esbuild';
import path from 'path';
import { SpinEsbuildPlugin } from "@spinframework/build-tools/plugins/esbuild/index.js";
import fs from 'fs';

const spinPlugin = await SpinEsbuildPlugin();

// plugin to handle vendor files in node_modules that may not be bundled.
// Instead of generating a real source map for these files, it appends a minimal
// inline source map pointing to an empty source. This avoids errors and ensures
// source maps exist even for unbundled vendor code.
let SourceMapPlugin = {
name: 'excludeVendorFromSourceMap',
setup(build) {
build.onLoad({ filter: /node_modules/ }, args => {
return {
contents: fs.readFileSync(args.path, 'utf8')
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
loader: 'default',
}
})
},
}

await build({
entryPoints: ['./src/index.js'],
outfile: './build/bundle.js',
bundle: true,
format: 'esm',
platform: 'node',
sourcemap: true,
minify: false,
plugins: [spinPlugin, SourceMapPlugin],
logLevel: 'error',
loader: {
'.ts': 'ts',
'.tsx': 'tsx',
},
resolveExtensions: ['.ts', '.tsx', '.js'],
sourceRoot: path.resolve(process.cwd(), 'src'),
});
6 changes: 3 additions & 3 deletions templates/http-js/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js --initLocation http://{{project-name | kebab_case}}.localhost -o dist/{{ project-name | kebab_case }}.wasm",
"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",
"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",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"esbuild": "^0.25.8"
},
"dependencies": {
{%- case http-router -%}
Expand Down
3 changes: 3 additions & 0 deletions templates/http-js/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ component = "{{project-name | kebab_case}}"
[component.{{project-name | kebab_case}}]
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
allowed_outbound_hosts = [
# "tcp://127.0.0.1:*", # Uncomment this line to while using the StarlingMonkey Debugger
]
[component.{{project-name | kebab_case}}.build]
command = ["npm install", "npm run build"]
watch = ["src/**/*.js"]
32 changes: 0 additions & 32 deletions templates/http-js/content/webpack.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions templates/http-ts/content/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "starlingmonkey",
"request": "launch",
"name": "Debug StarlingMonkey component",
"component": "${workspaceFolder}/dist/{{ project-name | kebab_case }}.wasm",
"program": "${workspaceFolder}/src/index.ts",
"stopOnEntry": false,
"trace": true
}
]
}
12 changes: 12 additions & 0 deletions templates/http-ts/content/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"starlingmonkey": {
"componentRuntime": {
"executable": "spin",
"options": [
"up",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for the http-js template

"-f",
"${workspaceFolder}",
],
}
}
}
9 changes: 8 additions & 1 deletion templates/http-ts/content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ To use additional Spin interfaces, install the corresponding packages:
| PostgreSQL | `@spinframework/spin-postgres` |
| Redis | `@spinframework/spin-redis` |
| SQLite | `@spinframework/spin-sqlite` |
| Variables | `@spinframework/spin-variables` |
| Variables | `@spinframework/spin-variables` |

## Using the StarlingMonkey Debugger for VS Code

1. First install the [StarlingMonkey Debugger](https://marketplace.visualstudio.com/items?itemName=BytecodeAlliance.starlingmonkey-debugger) extension.
2. Build the component using the debug command `npm run build:debug`.
3. Uncomment `tcp://127.0.0.1:*` in the `allowed_outbound_hosts` field in the `spin.toml`.
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.
42 changes: 42 additions & 0 deletions templates/http-ts/content/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// build.mjs
import { build } from 'esbuild';
import path from 'path';
import { SpinEsbuildPlugin } from "@spinframework/build-tools/plugins/esbuild/index.js";
import fs from 'fs';

const spinPlugin = await SpinEsbuildPlugin();

// plugin to handle vendor files in node_modules that may not be bundled.
// Instead of generating a real source map for these files, it appends a minimal
// inline source map pointing to an empty source. This avoids errors and ensures
// source maps exist even for unbundled vendor code.
let SourceMapPlugin = {
name: 'excludeVendorFromSourceMap',
setup(build) {
build.onLoad({ filter: /node_modules/ }, args => {
return {
contents: fs.readFileSync(args.path, 'utf8')
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
loader: 'default',
}
})
},
}

await build({
entryPoints: ['./src/index.ts'],
outfile: './build/bundle.js',
bundle: true,
format: 'esm',
platform: 'node',
sourcemap: true,
minify: false,
plugins: [spinPlugin, SourceMapPlugin],
logLevel: 'error',
loader: {
'.ts': 'ts',
'.tsx': 'tsx',
},
resolveExtensions: ['.ts', '.tsx', '.js'],
sourceRoot: path.resolve(process.cwd(), 'src'),
});
6 changes: 3 additions & 3 deletions templates/http-ts/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js --initLocation http://{{project-name | kebab_case}}.localhost -o dist/{{ project-name | kebab_case }}.wasm",
"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",
"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",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand All @@ -14,8 +15,7 @@
"mkdirp": "^3.0.1",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"esbuild": "^0.25.8"
},
"dependencies": {
{%- case http-router -%}
Expand Down
3 changes: 3 additions & 0 deletions templates/http-ts/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ component = "{{project-name | kebab_case}}"
[component.{{project-name | kebab_case}}]
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
allowed_outbound_hosts = [
# "tcp://127.0.0.1:*", # Uncomment this line to while using the StarlingMonkey Debugger
]
[component.{{project-name | kebab_case}}.build]
command = ["npm install", "npm run build"]
watch = ["src/**/*.ts"]
44 changes: 0 additions & 44 deletions templates/http-ts/content/webpack.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions test/test-app/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "starlingmonkey",
"request": "launch",
"name": "Debug StarlingMonkey component",
"component": "${workspaceFolder}/dist/test-app.wasm",
"program": "${workspaceFolder}/src/index.ts",
"stopOnEntry": false,
"trace": true
}
]
}
12 changes: 12 additions & 0 deletions test/test-app/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"starlingmonkey": {
"componentRuntime": {
"executable": "spin",
"options": [
"up",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and same here

"-f",
"${workspaceFolder}",
],
}
}
}