Skip to content

Commit 3d60085

Browse files
Convert CLI code to TypeScript (#1247)
Co-authored-by: Sy Brand <[email protected]>
1 parent da4c169 commit 3d60085

35 files changed

+955
-396
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
steps:
1212
- uses: actions/[email protected]
1313
with:
14-
allow-licenses: Apache-2.0, MIT, BSD-3-Clause, ISC, BSD-2-Clause, MIT OR (CC0-1.0 AND MIT), CC0-1.0 OR MIT OR (CC0-1.0 AND MIT), CC-BY-3.0, CC0-1.0, MIT OR Apache-2.0, MIT AND Apache-2.0, MIT OR WTFPL, BSD-2-Clause OR (MIT OR Apache-2.0), Python-2.0, ISC AND MIT, Apache-2.0 AND MIT, MIT/Apache-2.0, Apache-2.0 OR MIT, (Apache-2.0 OR MIT) AND BSD-3-Clause, Zlib OR Apache-2.0 OR MIT, MIT OR Apache-2.0 OR Zlib, MIT OR (Apache-2.0 OR Zlib), (Apache-2.0 WITH LLVM-exception), 0BSD, CC-BY-4.0, Unlicense, MPL-1.1
14+
allow-licenses: Apache-2.0, MIT, BSD-3-Clause, ISC, BSD-2-Clause, MIT OR (CC0-1.0 AND MIT), CC0-1.0 OR MIT OR (CC0-1.0 AND MIT), CC-BY-3.0, CC0-1.0, MIT OR Apache-2.0, MIT AND Apache-2.0, MIT OR WTFPL, BSD-2-Clause OR (MIT OR Apache-2.0), Python-2.0, ISC AND MIT, Apache-2.0 AND MIT, MIT/Apache-2.0, Apache-2.0 OR MIT, (Apache-2.0 OR MIT) AND BSD-3-Clause, Zlib OR Apache-2.0 OR MIT, MIT OR Apache-2.0 OR Zlib, MIT OR (Apache-2.0 OR Zlib), (Apache-2.0 WITH LLVM-exception), 0BSD, CC-BY-4.0, Unlicense, MPL-1.1, LicenseRef-scancode-unicode AND MIT
1515
fail-on-scopes: runtime

.github/workflows/main.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ jobs:
154154
with:
155155
name: fastly-weval-ic-cache
156156
- run: npm install
157+
- name: Build CLI
158+
run: npm run build:cli
157159
- run: npm test
158160

159161
build-debug:
@@ -164,6 +166,11 @@ jobs:
164166
- uses: actions/checkout@v4
165167
with:
166168
submodules: true
169+
- name: Set up Node LTS
170+
uses: actions/setup-node@v3
171+
with:
172+
node-version: 'lts/*'
173+
- run: npm ci
167174
- name: Install Rust 1.81.0
168175
run: |
169176
rustup toolchain install 1.81.0
@@ -174,6 +181,8 @@ jobs:
174181
with:
175182
path: "/home/runner/.cargo/bin/wasm-tools"
176183
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
184+
- name: Build CLI
185+
run: npm run build:cli
177186
- name: Build with full debug info
178187
run: npm run build:debug:info
179188
- uses: actions/upload-artifact@v4
@@ -193,6 +202,11 @@ jobs:
193202
- uses: actions/checkout@v4
194203
with:
195204
submodules: true
205+
- name: Set up Node LTS
206+
uses: actions/setup-node@v3
207+
with:
208+
node-version: 'lts/*'
209+
- run: npm ci
196210
- name: Install Rust 1.81.0
197211
run: |
198212
rustup toolchain install 1.81.0
@@ -203,6 +217,8 @@ jobs:
203217
with:
204218
path: "/home/runner/.cargo/bin/wasm-tools"
205219
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
220+
- name: Build CLI
221+
run: npm run build:cli
206222
- name: Build
207223
if: matrix.profile == 'release'
208224
run: npm run build:release
@@ -229,9 +245,11 @@ jobs:
229245
- uses: actions/checkout@v4
230246
with:
231247
submodules: true
232-
- uses: actions/setup-node@v3
248+
- name: Set up Node LTS
249+
uses: actions/setup-node@v3
233250
with:
234251
node-version: 'lts/*'
252+
- run: npm ci
235253

236254
- name: Download Engine
237255
uses: actions/download-artifact@v4
@@ -250,8 +268,9 @@ jobs:
250268
with:
251269
path: "/home/runner/.cargo/bin/wasm-tools"
252270
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
253-
254-
- run: npm install
271+
272+
- name: Build CLI
273+
run: npm run build:cli
255274

256275
- name: Build WPT runtime
257276
run: tests/wpt-harness/build-wpt-runtime.sh --debug-build
@@ -277,9 +296,11 @@ jobs:
277296
- uses: actions/checkout@v4
278297
with:
279298
submodules: true
280-
- uses: actions/setup-node@v3
299+
- name: Set up Node LTS
300+
uses: actions/setup-node@v3
281301
with:
282302
node-version: 'lts/*'
303+
- run: npm ci
283304

284305
- name: Download Engine
285306
uses: actions/download-artifact@v4
@@ -305,7 +326,8 @@ jobs:
305326
path: "/home/runner/.cargo/bin/wasm-tools"
306327
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
307328

308-
- run: npm install
329+
- name: Build CLI
330+
run: npm run build:cli
309331

310332
- name: Build WPT runtime
311333
run: tests/wpt-harness/build-wpt-runtime.sh ${{matrix.profile == 'weval' && '--enable-experimental-aot' || matrix.profile == 'debug' && '--debug-build' || ''}}
@@ -378,6 +400,9 @@ jobs:
378400
- name: Npm install
379401
run: npm install && cd ./integration-tests/js-compute && npm install
380402

403+
- name: Build CLI
404+
run: npm run build:cli
405+
381406
- name: Run Tests
382407
run: SUFFIX_STRING=${{matrix.profile}} node integration-tests/js-compute/test.js --ci --skip-teardown${{ matrix.platform == 'viceroy' && ' --local' || '' }}${{ matrix.profile == 'weval' && ' --aot' || '' }}${{ matrix.features == 'http-cache' && ' --http-cache' || '' }}
383408
env:
@@ -445,6 +470,9 @@ jobs:
445470
- name: Npm install
446471
run: npm install && cd ./integration-tests/js-compute && npm install
447472

473+
- name: Build CLI
474+
run: npm run build:cli
475+
448476
- name: Run Tests
449477
run: SUFFIX_STRING=debug node integration-tests/js-compute/test.js --ci --skip-teardown --debug-build${{ matrix.platform == 'viceroy' && ' --local' || '' }}${{ matrix.features == 'http-cache' && ' --http-cache' || '' }}
450478
env:

.github/workflows/release-please.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ jobs:
8989
- uses: actions/checkout@v3
9090
with:
9191
submodules: true
92+
- name: Set up Node LTS
93+
uses: actions/setup-node@v3
94+
with:
95+
node-version: 'lts/*'
96+
- run: npm ci
9297
- name: Install Rust 1.81.0
9398
run: |
9499
rustup toolchain install 1.81.0
@@ -99,6 +104,8 @@ jobs:
99104
with:
100105
path: "/home/runner/.cargo/bin/wasm-tools"
101106
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
107+
- name: Build CLI
108+
run: npm run build:cli
102109
- name: Build
103110
if: ${{ matrix.profile == 'release' }}
104111
run: npm run build:release

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# TypeScript build output
2+
dist/
3+
14
# Integration Tests build output
25
/integration-tests/**/fixtures/**/*.tar.gz
36
/integration-tests/**/fixtures/**/fastly.toml

DEVELOPMENT.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ To build from source, you need to have the following tools installed to successf
3333
```sh
3434
sudo apt install binaryen
3535
```
36-
- rust target wasm32-wasi
36+
- rust target wasm32-wasip1
3737
```sh
38-
rustup target add wasm32-wasi
38+
rustup target add wasm32-wasip1
3939
```
4040
- [cbindgen](https://github.com/eqrion/cbindgen#quick-start)
4141
```sh
@@ -87,9 +87,9 @@ npm run build
8787
# then, restart shell or run:
8888
source $HOME/.cargo/env
8989
```
90-
- rust target wasm32-wasi
90+
- rust target wasm32-wasip1
9191
```sh
92-
rustup target add wasm32-wasi
92+
rustup target add wasm32-wasip1
9393
```
9494
- [cbindgen](https://github.com/eqrion/cbindgen#quick-start)
9595
```sh
@@ -180,10 +180,10 @@ In addition the following flags can be added after the command (passed via `npm
180180
A typical development test command is therefore something like:
181181

182182
```
183-
npm run build:debug && npm run test:integration -- --debug-build --debug-log --local --bail /crypto
183+
npm run build:cli && npm run build:debug && npm run test:integration -- --debug-build --debug-log --local --bail /crypto
184184
```
185185

186-
Which would run a debug build, enable debugging logging, and then that build against all the crypto tests locally on Viceroy, throwing an error as soon as one is found.
186+
Which would build the CLI TypeScript to JavaScript, run a debug build, enable debugging logging, and then that build against all the crypto tests locally on Viceroy, throwing an error as soon as one is found.
187187

188188
Some tests can only be run on Compute and not Viceroy and will be automatically skipped. A green tick is always shown for a test that ran successfully - if it is missing that means it did not run.
189189

eslint.config.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import { defineConfig } from 'eslint/config';
5+
import tseslint from 'typescript-eslint';
6+
7+
export default defineConfig([
8+
{
9+
files: ['src/**/*.{ts,tsx,js}'],
10+
languageOptions: {
11+
parserOptions: {
12+
projectService: true,
13+
},
14+
},
15+
extends: [
16+
eslint.configs.recommended,
17+
...tseslint.configs.recommendedTypeChecked,
18+
...tseslint.configs.stylisticTypeChecked,
19+
],
20+
rules: {
21+
'no-fallthrough': 'off',
22+
'@typescript-eslint/require-await': 'off',
23+
'@typescript-eslint/consistent-type-definitions': 'off',
24+
},
25+
},
26+
{
27+
ignores: [
28+
'ci/*',
29+
'dist/*',
30+
'documentation/*',
31+
'integration-tests/*',
32+
'runtime/*',
33+
'tests/*',
34+
'test-d/*',
35+
]
36+
},
37+
]);

integration-tests/cli/env.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'brittle';
2-
import { EnvParser } from '../../src/env.js';
2+
import { EnvParser } from '../../dist/env.js';
33

44
test('EnvParser should parse single key-value pair', function (t) {
55
const parser = new EnvParser();

integration-tests/cli/output-path-is-not-a-file.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test('should return non-zero exit code', async function (t) {
1818
ok(
1919
stderr
2020
.toString()
21-
.startsWith('Error: The `output` path does not point to a file:'),
21+
.startsWith('Error: The `output` path points to a directory:'),
2222
);
2323
ok(stderr.toString().endsWith('main.wasm'));
2424
t.is(code, 1);

integration-tests/js-compute/fixtures/app/fastly.toml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "js-test-app"
99
service_id = ""
1010

1111
[scripts]
12-
build = "node ../../../../js-compute-runtime-cli.js --env FASTLY_DEBUG_LOGGING,ACL_NAME,CONFIG_STORE_NAME,DICTIONARY_NAME,KV_STORE_NAME,SECRET_STORE_NAME,LOCAL_TEST,TEST=\"foo\" --enable-experimental-high-resolution-time-methods src/index.js"
12+
build = "node ../../../../dist/cli/js-compute-runtime-cli.js --env FASTLY_DEBUG_LOGGING,ACL_NAME,CONFIG_STORE_NAME,DICTIONARY_NAME,KV_STORE_NAME,SECRET_STORE_NAME,LOCAL_TEST,TEST=\"foo\" --enable-experimental-high-resolution-time-methods src/index.js"
1313

1414
[local_server]
1515

0 commit comments

Comments
 (0)