diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e6502266..51851885 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -43,14 +43,19 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] + package-manager: [npm, yarn] steps: - uses: actions/checkout@v3 - - name: Use Node.js 20 + - name: Use Node.js 22 uses: actions/setup-node@v3 with: - node-version: 20 + node-version: 22 + + - name: Install Yarn (if needed) + if: matrix.package-manager == 'yarn' + run: npm install -g yarn - name: Setup `spin` uses: fermyon/actions/spin/setup@v1 @@ -61,19 +66,17 @@ jobs: run: spin templates install --dir . - name: Create new project - run: spin new -t http-ts test-project -a + run: spin new -t http-ts test-project -v package-manager=${{ matrix.package-manager }} -a - name: Install dependencies of the test project run: | cd test-project - npm install - name: Add new component to project run: | cd test-project - spin add -t http-ts new-component -a + spin add -t http-ts new-component -v package-manager=${{ matrix.package-manager }} -a cd new-component - npm install - name: Build the application run: | diff --git a/templates/http-js/content/package.json b/templates/http-js/content/package.json index d17c3727..e421ba8e 100644 --- a/templates/http-js/content/package.json +++ b/templates/http-js/content/package.json @@ -1,23 +1,23 @@ { - "name": "{{project-name | kebab_case}}", - "version": "1.0.0", - "description": "{{project-description}}", - "main": "index.js", - "scripts": { - "build": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -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", - "@fermyon/knitwit": "0.3.0" - }, - "dependencies": { - "@fermyon/spin-sdk": "^3.0.0", - "itty-router": "^5.0.18" - } + "name": "{{project-name | kebab_case}}", + "version": "1.0.0", + "description": "{{project-description}}", + "main": "index.js", + "scripts": { + "build": "knitwit --out-dir build/wit/knitwit --out-world combined && webpack --mode=production && mkdirp dist && j2w -i build/bundle.js -d build/wit/knitwit -n combined -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", + "@fermyon/knitwit": "0.3.0" + }, + "dependencies": { + "@fermyon/spin-sdk": "^3.0.0", + "itty-router": "^5.0.18" + } } \ No newline at end of file diff --git a/templates/http-js/content/spin.toml b/templates/http-js/content/spin.toml index 038370f3..265b0870 100644 --- a/templates/http-js/content/spin.toml +++ b/templates/http-js/content/spin.toml @@ -13,6 +13,8 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "dist/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] +allowed_outbound_hosts = [] + [component.{{project-name | kebab_case}}.build] -command = ["npm install", "npm run build"] -watch = ["src/**/*.js"] \ No newline at end of file +command = ["{{package-manager}} install", "{{package-manager}} run build"] +watch = ["src/**/*.js"] diff --git a/templates/http-js/metadata/snippets/component.txt b/templates/http-js/metadata/snippets/component.txt index 1e5388ae..9ca20243 100644 --- a/templates/http-js/metadata/snippets/component.txt +++ b/templates/http-js/metadata/snippets/component.txt @@ -7,5 +7,5 @@ source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm install && npm run build" +command = ["{{package-manager}} install", "{{package-manager}} run build"] workdir = "{{ output-path }}" diff --git a/templates/http-js/metadata/spin-template.toml b/templates/http-js/metadata/spin-template.toml index a138db92..a85fe2f2 100644 --- a/templates/http-js/metadata/spin-template.toml +++ b/templates/http-js/metadata/spin-template.toml @@ -10,3 +10,4 @@ component = "component.txt" [parameters] project-description = { type = "string", prompt = "Description", default = "" } http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" } diff --git a/templates/http-ts/content/package.json b/templates/http-ts/content/package.json index 812ad4a8..5e4f50b3 100644 --- a/templates/http-ts/content/package.json +++ b/templates/http-ts/content/package.json @@ -4,7 +4,7 @@ "description": "{{project-description}}", "main": "index.js", "scripts": { - "build": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{ project-name | kebab_case }}.wasm", + "build": "knitwit --out-dir build/wit/knitwit --out-world combined && webpack --mode=production && mkdirp dist && j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{ project-name | kebab_case }}.wasm", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/templates/http-ts/content/spin.toml b/templates/http-ts/content/spin.toml index 82c26af2..4e26353f 100644 --- a/templates/http-ts/content/spin.toml +++ b/templates/http-ts/content/spin.toml @@ -13,6 +13,8 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "dist/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] +allowed_outbound_hosts = [] + [component.{{project-name | kebab_case}}.build] -command = ["npm install", "npm run build"] -watch = ["src/**/*.ts"] \ No newline at end of file +command = ["{{package-manager}} install", "{{package-manager}} run build"] +watch = ["src/**/*.ts"] diff --git a/templates/http-ts/metadata/snippets/component.txt b/templates/http-ts/metadata/snippets/component.txt index b8184acb..172577df 100644 --- a/templates/http-ts/metadata/snippets/component.txt +++ b/templates/http-ts/metadata/snippets/component.txt @@ -7,5 +7,5 @@ source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm install && npm run build" +command = ["{{package-manager}} install", "{{package-manager}} run build"] workdir = "{{ output-path }}" \ No newline at end of file diff --git a/templates/http-ts/metadata/spin-template.toml b/templates/http-ts/metadata/spin-template.toml index c468b052..2d036d8c 100644 --- a/templates/http-ts/metadata/spin-template.toml +++ b/templates/http-ts/metadata/spin-template.toml @@ -10,3 +10,4 @@ component = "component.txt" [parameters] project-description = { type = "string", prompt = "Description", default = "" } http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" } diff --git a/templates/redis-js/content/package.json b/templates/redis-js/content/package.json index 6a10fd51..2495b54d 100644 --- a/templates/redis-js/content/package.json +++ b/templates/redis-js/content/package.json @@ -4,9 +4,8 @@ "description": "{{project-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/{{project-name | kebab_case}}.wasm", - "test": "echo \"Error: no test specified\" && exit 1", - "postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined" + "build": "knitwit --out-dir build/wit/knitwit --out-world combined && webpack --mode=production && mkdirp dist && j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm", + "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", diff --git a/templates/redis-js/content/spin.toml b/templates/redis-js/content/spin.toml index 83514a3a..8ddfc6f3 100644 --- a/templates/redis-js/content/spin.toml +++ b/templates/redis-js/content/spin.toml @@ -16,6 +16,8 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "dist/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] +allowed_outbound_hosts = [] + [component.{{project-name | kebab_case}}.build] -command = "npm install && npm run build" +command = ["{{package-manager}} install", "{{package-manager}} run build"] watch = ["src/**/*.ts", "package.json"] diff --git a/templates/redis-js/metadata/snippets/component.txt b/templates/redis-js/metadata/snippets/component.txt index 7cfe976c..5e354e44 100644 --- a/templates/redis-js/metadata/snippets/component.txt +++ b/templates/redis-js/metadata/snippets/component.txt @@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}" source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm install && npm run build" +command = ["{{package-manager}} install", "{{package-manager}} run build"] workdir = "{{ output-path }}" \ No newline at end of file diff --git a/templates/redis-js/metadata/spin-template.toml b/templates/redis-js/metadata/spin-template.toml index 232ef7d0..ac061c73 100644 --- a/templates/redis-js/metadata/spin-template.toml +++ b/templates/redis-js/metadata/spin-template.toml @@ -17,3 +17,4 @@ skip_snippets = ["application_trigger"] project-description = { type = "string", prompt = "Description", default = "" } redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" } redis-channel = { type = "string", prompt = "Redis channel" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" } diff --git a/templates/redis-ts/content/package.json b/templates/redis-ts/content/package.json index 29dc8477..4a6c80ee 100644 --- a/templates/redis-ts/content/package.json +++ b/templates/redis-ts/content/package.json @@ -4,9 +4,8 @@ "description": "{{project-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/{{project-name | kebab_case}}.wasm", - "test": "echo \"Error: no test specified\" && exit 1", - "postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined" + "build": "knitwit --out-dir build/wit/knitwit --out-world combined && webpack --mode=production && mkdirp dist && j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm", + "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", diff --git a/templates/redis-ts/content/spin.toml b/templates/redis-ts/content/spin.toml index 83514a3a..8ddfc6f3 100644 --- a/templates/redis-ts/content/spin.toml +++ b/templates/redis-ts/content/spin.toml @@ -16,6 +16,8 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] source = "dist/{{project-name | kebab_case}}.wasm" exclude_files = ["**/node_modules"] +allowed_outbound_hosts = [] + [component.{{project-name | kebab_case}}.build] -command = "npm install && npm run build" +command = ["{{package-manager}} install", "{{package-manager}} run build"] watch = ["src/**/*.ts", "package.json"] diff --git a/templates/redis-ts/metadata/snippets/component.txt b/templates/redis-ts/metadata/snippets/component.txt index 7cfe976c..5e354e44 100644 --- a/templates/redis-ts/metadata/snippets/component.txt +++ b/templates/redis-ts/metadata/snippets/component.txt @@ -6,5 +6,5 @@ component = "{{project-name | kebab_case}}" source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm" allowed_outbound_hosts = [] [component.{{project-name | kebab_case}}.build] -command = "npm install && npm run build" +command = ["{{package-manager}} install", "{{package-manager}} run build"] workdir = "{{ output-path }}" \ No newline at end of file diff --git a/templates/redis-ts/metadata/spin-template.toml b/templates/redis-ts/metadata/spin-template.toml index 710c69e4..0774af86 100644 --- a/templates/redis-ts/metadata/spin-template.toml +++ b/templates/redis-ts/metadata/spin-template.toml @@ -17,3 +17,4 @@ skip_snippets = ["application_trigger"] project-description = { type = "string", prompt = "Description", default = "" } redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" } redis-channel = { type = "string", prompt = "Redis channel" } +package-manager = { type = "string", prompt = "Which package manager would you like to use (npm|yarn)", default = "npm", pattern = "^(npm|yarn)$" }