Skip to content

Commit 16b0362

Browse files
Merge pull request #1 from functionalscript/update
Update functionalscript to v0.24.0 and add CI workflow
2 parents 223dca4 + 405d787 commit 16b0362

10 files changed

Lines changed: 784 additions & 64 deletions

File tree

.github/workflows/ci.yml

Lines changed: 542 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/node.js.yml

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

all.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'functionalscript/fs/emergent_testing/all.test.js'

bun.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno.lock

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 74 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
"main": "server.f.ts",
1717
"scripts": {
1818
"test": "tsc && fjs t",
19-
"start": "fjs r ./server.f.ts"
19+
"start": "fjs r ./server.f.ts",
20+
"update": "npx npm-check-updates -u && npm install && deno install && bun install && fjs i",
21+
"cov": "node --test --experimental-test-coverage --test-coverage-include=**/*.f.ts"
2022
},
2123
"dependencies": {
22-
"functionalscript": "^0.11.10"
24+
"functionalscript": "0.29.0"
2325
},
2426
"devDependencies": {
25-
"typescript": "^5.9.3"
27+
"@playwright/test": "1.60.0",
28+
"typescript": "6.0.3"
2629
}
2730
}

proof.f.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { assert, assertEq } from 'functionalscript/fs/asserts/module.f.js'
2+
import { utf8, utf8ToString } from 'functionalscript/fs/text/module.f.js'
3+
import { vec8 } from 'functionalscript/fs/types/bit_vec/module.f.js'
4+
import type { IncomingMessage } from 'functionalscript/fs/effects/node/module.f.js'
5+
import { virtual, emptyState } from 'functionalscript/fs/effects/node/virtual/module.f.js'
6+
import { listener } from './server.f.ts'
7+
8+
const request = (url: string): IncomingMessage => ({
9+
method: 'GET',
10+
url,
11+
headers: {},
12+
body: vec8(0n),
13+
})
14+
15+
const runRequest = (url: string, root = emptyState.root) =>
16+
virtual({ ...emptyState, root })(listener(request(url)))
17+
18+
const bodyText = (url: string, root = emptyState.root) => {
19+
const [state, response] = runRequest(url, root)
20+
return [state, response, utf8ToString(response.body)] as const
21+
}
22+
23+
const includes = (s: string) => (part: string) => {
24+
assert(s.includes(part), [part, s])
25+
}
26+
27+
export const proof = {
28+
servesFiles: () => {
29+
const file = utf8('body { color: green; }\n')
30+
const [state, response] = runRequest('/main.css', { 'main.css': file })
31+
32+
assertEq(response.status, 200)
33+
assertEq(utf8ToString(response.body), 'body { color: green; }\n')
34+
includes(state.stdout)('reading ./main.css\n')
35+
includes(state.stdout)('served: 23 bytes\n')
36+
},
37+
ignoresQueryString: () => {
38+
const file = utf8('ok')
39+
const [_, response] = runRequest('/main.css?cache=bust', { 'main.css': file })
40+
41+
assertEq(response.status, 200)
42+
assertEq(utf8ToString(response.body), 'ok')
43+
},
44+
rendersDirectoryListing: () => {
45+
const [state, response, body] = bodyText('/docs', {
46+
docs: {
47+
'a.txt': utf8('A'),
48+
nested: {},
49+
},
50+
})
51+
52+
assertEq(response.status, 200)
53+
includes(body)('<link rel="stylesheet" href="/main.css">')
54+
includes(body)('<pre><a href="/docs/a.txt">a.txt</a>\n<a href="/docs/nested">nested/</a>\n</pre>')
55+
includes(state.stdout)('reading ./docs\n')
56+
includes(state.stdout)('served: ')
57+
},
58+
missingPaths404: () => {
59+
const [state, response] = runRequest('/missing')
60+
61+
assertEq(response.status, 404)
62+
assertEq(utf8ToString(response.body), '404 not found')
63+
assertEq(state.stdout, 'reading ./missing\nserved: 13 bytes\n')
64+
},
65+
}

server.f.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { utf8 } from 'functionalscript/text/module.f.js'
2-
import { length, type Vec } from 'functionalscript/types/bit_vec/module.f.js'
3-
import { pure } from 'functionalscript/types/effects/module.f.js'
1+
import { utf8 } from 'functionalscript/fs/text/module.f.js'
2+
import { empty, length, type Vec } from 'functionalscript/fs/types/bit_vec/module.f.js'
3+
import { pure } from 'functionalscript/fs/effects/module.f.js'
44
import {
55
createServer,
66
listen,
@@ -12,11 +12,11 @@ import {
1212
readdir,
1313
type IoResult,
1414
type Dirent,
15-
} from 'functionalscript/types/effects/node/module.f.js'
16-
import { htmlToString } from 'functionalscript/html/module.f.js'
17-
import { concat } from 'functionalscript/path/module.f.js'
15+
} from 'functionalscript/fs/effects/node/module.f.js'
16+
import { htmlUtf8 } from 'functionalscript/fs/html/module.f.js'
17+
import { concat } from 'functionalscript/fs/path/module.f.js'
1818

19-
const listener = ({ url }: IncomingMessage) => {
19+
export const listener = ({ url }: IncomingMessage) => {
2020
const path = url.split('?')[0] ?? ''
2121
const file = '.' + path
2222

@@ -25,22 +25,14 @@ const listener = ({ url }: IncomingMessage) => {
2525
return [['a', { href }, name + (isFile ? '' : '/')], '\n'] as const
2626
}
2727

28-
const dirPage = (v: readonly Dirent[]) => htmlToString(
29-
['html',
30-
['head',
31-
['link', { rel: 'stylesheet', href: '/main.css' }]
32-
],
33-
['body',
34-
['pre',
35-
...v.flatMap(dirLink)
36-
]
37-
]
38-
])
28+
const dirPage = (v: readonly Dirent[]) => htmlUtf8
29+
(['link', { rel: 'stylesheet', href: '/main.css' }])
30+
(['pre', ...v.flatMap(dirLink)])
3931

4032
const orReadDir = (r: IoResult<Vec>) => r[0] === 'ok'
4133
? pure(r)
4234
: readdir(file, {})
43-
.step(([s, v]) => pure([s, utf8(s === 'ok' ? dirPage(v) : '')] as const))
35+
.step(([s, v]) => pure([s, s === 'ok' ? dirPage(v) : empty] as const))
4436

4537
return log(`reading ${file}`)
4638
.step(() => readFile(file))

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
// Recommended Options
3636
"strict": true,
3737
"jsx": "react-jsx",
38-
"verbatimModuleSyntax": true,
39-
"isolatedModules": true,
38+
"verbatimModuleSyntax": true,
39+
"allowImportingTsExtensions": true,
40+
"isolatedModules": true,
4041
"noUncheckedSideEffectImports": true,
4142
"moduleDetection": "force",
4243
"skipLibCheck": true,

0 commit comments

Comments
 (0)