Skip to content
Open
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
39 changes: 36 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* @import { DomStackOpts as DomStackOpts, Results, SiteData } from './lib/builder.js'
* @import { Stats } from 'node:fs'
* @import { FSWatcher } from 'chokidar'
* @import { AsyncLayoutFunction, LayoutFunction } from './lib/build-pages/page-data.js'
* @import { PageFunction, AsyncPageFunction } from './lib/build-pages/page-builders/page-writer.js'
* @import { AsyncLayoutFunction, LayoutFunction, LayoutFunctionParams } from './lib/build-pages/page-data.js'
* @import { PageFunction, AsyncPageFunction, PageFunctionParams } from './lib/build-pages/page-builders/page-writer.js'
* @import { TemplateFunction } from './lib/build-pages/page-builders/template-builder.js'
* @import { TemplateAsyncIterator } from './lib/build-pages/page-builders/template-builder.js'
* @import { TemplateOutputOverride } from './lib/build-pages/page-builders/template-builder.js'
* @import { GlobalDataFunction, AsyncGlobalDataFunction, WorkerBuildStepResult } from './lib/build-pages/index.js'
* @import { TemplateFunctionParams } from './lib/build-pages/page-builders/template-builder.js'
* @import { GlobalDataFunction, AsyncGlobalDataFunction, WorkerBuildStepResult, GlobalDataFunctionParams } from './lib/build-pages/index.js'
* @import { BuildOptions, BuildContext } from 'esbuild'
* @import { PageInfo, TemplateInfo } from './lib/identify-pages.js'
*/
Expand Down Expand Up @@ -49,6 +50,8 @@ import { resolveVars } from './lib/build-pages/resolve-vars.js'
import { ensureDest } from './lib/helpers/ensure-dest.js'
import { DomStackAggregateError } from './lib/helpers/domstack-aggregate-error.js'

export { PageData } from './lib/build-pages/page-data.js'

Comment thread
bcomnes marked this conversation as resolved.
/**
* @typedef {BuildOptions} BuildOptions
*/
Expand Down Expand Up @@ -103,6 +106,36 @@ import { DomStackAggregateError } from './lib/helpers/domstack-aggregate-error.j
* @typedef {TemplateOutputOverride} TemplateOutputOverride
*/

/**
* @typedef {PageInfo} PageInfo
*/

/**
* @typedef {TemplateInfo} TemplateInfo
*/

/**
* @template {Record<string, any>} T - The type of variables passed to the layout function
* @template [U=any] U - The return type of the page function
* @template [V=string] V - The return type of the layout function
* @typedef {LayoutFunctionParams<T, U, V>} LayoutFunctionParams
*/

/**
* @typedef {GlobalDataFunctionParams} GlobalDataFunctionParams
*/

/**
* @template {Record<string, any>} T - The type of variables passed to the page function
* @template [U=any] U - The return type of the page function
* @typedef {PageFunctionParams<T, U>} PageFunctionParams
*/
Comment thread
bcomnes marked this conversation as resolved.

/**
* @template {Record<string, any>} [T=Record<string, any>] - The type of variables for the template function
* @typedef {TemplateFunctionParams<T>} TemplateFunctionParams
*/

const DEFAULT_IGNORES = /** @type {const} */ ([
'.*',
'coverage',
Expand Down
17 changes: 11 additions & 6 deletions lib/build-pages/page-builders/template-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import { writeFile, mkdir } from 'fs/promises'
* content: string
* }} TemplateOutputOverride */

/**
* The parameters object passed to a {@link TemplateFunction} or {@link TemplateAsyncIterator}.
*
* @template {Record<string, any>} [T=Record<string, any>] - The type of variables for the template
* @typedef {object} TemplateFunctionParams
* @property {T} vars - All of the site globalVars.
* @property {TemplateInfo} template - Info about the current template.
* @property {PageData<T, any, string>[]} pages - An array of info about every page.
*/

/**
* Callback for rendering a template.
*
Expand All @@ -24,16 +34,11 @@ import { writeFile, mkdir } from 'fs/promises'
* } - The results of a template build
*/

/**
* @template {Record<string, any>} T - The type of variables for the template function parameters
* @typedef {Parameters<TemplateFunction<T>>} TemplateFunctionParams
*/

/**
* Callback for rendering a template with an async iterator.
* @template T - The type of variables for the template async iterator
* @callback TemplateAsyncIterator
* @param {TemplateFunctionParams<T>[0]} params - Parameters of the template function.
* @param {TemplateFunctionParams<T>} params - Parameters of the template function.
* @returns {AsyncIterable<TemplateOutputOverride>}
Comment thread
bcomnes marked this conversation as resolved.
*/

Expand Down
20 changes: 20 additions & 0 deletions test-cases/type-exports/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check
import { test } from 'node:test'
import assert from 'node:assert'
import { PageData } from '../../index.js'

/**
* Smoke test that all public types are importable from the package entry point.
* The type imports below are verified by TypeScript at compile time via `npm run test:tsc`.
*
* @typedef {import('../../index.js').PageInfo} PageInfo
* @typedef {import('../../index.js').TemplateInfo} TemplateInfo
* @typedef {import('../../index.js').LayoutFunctionParams<any>} LayoutFunctionParams
* @typedef {import('../../index.js').GlobalDataFunctionParams} GlobalDataFunctionParams
* @typedef {import('../../index.js').PageFunctionParams<any>} PageFunctionParams
* @typedef {import('../../index.js').TemplateFunctionParams} TemplateFunctionParams
*/

test('PageData is importable from the package entry point', () => {
assert.strictEqual(typeof PageData, 'function', 'PageData is a class')
})