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
2 changes: 1 addition & 1 deletion files/site/conference/src/trokky/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function site(core: TrokkyCore): Promise<Site> {
...s,
day: dayOf(s.day),
track: tracksById.get(refId(s.track) ?? '') ?? null,
speakers: (s.speakers ?? []).map((v: unknown) => speakersById.get(refId(v) ?? '')).filter((sp): sp is Doc => Boolean(sp)),
speakers: ((s.speakers ?? []) as unknown[]).map(v => speakersById.get(refId(v) ?? '')).filter((sp): sp is Doc => Boolean(sp)),
})

const sessions = sessionRows
Expand Down
2 changes: 1 addition & 1 deletion files/site/magazine/src/trokky/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function site(core: TrokkyCore): Promise<Site> {
categoryBySlug: (slug) => one('category', { slug }),
categories: () => list('category'),
articlesBy: async (field, id) => (await list('article', { [field]: id })).sort(byDateDesc),
articlesIn: async (ids) => (await Promise.all(ids.map(id => core.getDocument('article', id)))).filter((d): d is Doc => !!d && d._status === 'published'),
articlesIn: async (ids) => (await Promise.all(ids.map(id => core.getDocument('article', id) as Promise<Doc | null>))).filter((d): d is Doc => !!d && d._status === 'published'),
documents: async () => (await list('document')).sort(byDateDesc),
page: (slug) => one('page', { slug }),
}
Expand Down
20 changes: 19 additions & 1 deletion scripts/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ async function smoke(testCase) {
run('npm', ['run', 'build'], dir)
notes.push('built')

// A Workers build is wrangler's bundler, which never typechecks. Without this, a project that
// opens in the editor full of type errors passes. (Node API and Studio builds run tsc; Node
// full-site builds run astro build, which does not typecheck either: Trokky/generator#12.)
if (workers) {
try {
run('npx', ['tsc', '--noEmit', '-p', 'tsconfig.json'], dir)
} catch (error) {
// The reporter prints the first line of the message and `stderr`: tsc writes its
// diagnostics to stdout, so carry them across or the failure says nothing.
throw Object.assign(new Error('the generated project does not typecheck'), {
stderr: `${error.stdout ?? ''}${error.stderr ?? ''}`,
})
}
notes.push('typechecked')
}

if (testCase.skipBoot) return `${notes.join(', ')}, boot skipped (${testCase.skipBoot})`

const port = workers ? 8876 : 8877
Expand All @@ -160,7 +176,9 @@ async function smoke(testCase) {
// tail so the failure says what happened.
const child = workers
? spawn('npx', ['wrangler', 'dev', '--port', String(port), '--ip', '127.0.0.1'], { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'] })
: spawn('npx', ['tsx', 'src/server.ts'], { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, PORT: String(port) } })
// `npm start`, as the README says to run it in production: a wrong start path used to ship
// with this matrix green, because it booted src/server.ts through tsx instead.
: spawn('npm', ['start'], { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, PORT: String(port), NODE_ENV: 'production' } })

let tail = ''
const keepTail = chunk => { tail = (tail + chunk).slice(-4000) }
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function withDefaults(input: PartialConfig): ProjectConfig {
parts: pick('parts') as ProjectConfig['parts'],
content: pick('content') as ProjectConfig['content'],
// 3.6: TrokkyCore takes `env`, which the Workers entry passes
trokkyVersion: input.trokkyVersion ?? '^3.6.0',
trokkyVersion: input.trokkyVersion ?? '^3.6.2',
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ${hasStudio(config) ? `
return studio(request)
}
` : ''}${hasFrontend(config) ? `
return handle(request, env as unknown as Env, ctx)` : `
return handle(request, env as unknown as Parameters<typeof handle>[1], ctx)` : `
return new Response('Not Found', { status: 404 })`}
},
} satisfies ExportedHandler<TrokkyEnv>
Expand Down Expand Up @@ -557,7 +557,8 @@ export function tsconfig(config: ProjectConfig): string {
extends: hasFrontend(config) ? 'astro/tsconfigs/strict' : undefined,
compilerOptions: {
target: 'ES2022', module: 'ESNext', moduleResolution: 'bundler',
types: ['@cloudflare/workers-types/2023-07-01'],
// The bare package: workers-types 5 dropped the dated entry points (2023-07-01, …).
types: ['@cloudflare/workers-types'],
strict: true, skipLibCheck: true, noEmit: true,
},
include: ['src/**/*', 'scripts/**/*'],
Expand Down
5 changes: 3 additions & 2 deletions test/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ describe('the full edge site', () => {
// Not in the example: the deploy button would offer it for the deployed Worker
expect(text(tree, '.dev.vars.example')).not.toMatch(/^TROKKY_ENV=/m)
expect(text(tree, 'README.md')).toContain('echo TROKKY_ENV=development >> .dev.vars')
// 3.6 is the first release whose TrokkyCore takes env
expect(JSON.parse(text(tree, 'package.json')).dependencies['@trokky/trokky']).toBe('^3.6.0')
// 3.6 is the first release whose TrokkyCore takes env; 3.6.2 the first whose R2 adapter
// accepts env.MEDIA as the globals type it
expect(JSON.parse(text(tree, 'package.json')).dependencies['@trokky/trokky']).toBe('^3.6.2')
})

it('never makes deploy rebuild, because Workers Builds already built', () => {
Expand Down
Loading