Skip to content

Commit 13e9463

Browse files
authored
Merge pull request #177 from voxpelli/voxpelli/misc-suggestions
A couple of suggestions and fixes
2 parents 4858bed + f442824 commit 13e9463

File tree

24 files changed

+86
-125
lines changed

24 files changed

+86
-125
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ The default `root.layout.js` is featured below, and is implemented with [`uhtml`
397397
import { html, render } from 'uhtml-isomorphic'
398398

399399
/**
400-
* @template T extends object
400+
* @template {Record<string, any>} T
401401
* @typedef {import('top-bun').LayoutFunction<T>} LayoutFunction
402402
*/
403403

@@ -460,7 +460,7 @@ import defaultRootLayout from './root.layout.js'
460460
import { html } from 'uhtml-isomorphic'
461461

462462
/**
463-
* @template T extends object
463+
* @template {Record<string, any>} T
464464
* @typedef {import('top-bun').LayoutFunction<T>} LayoutFunction
465465
*/
466466

examples/css-modules/src/layouts/root.layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { html } from 'htm/preact'
33
import { render } from 'preact-render-to-string'
44

55
/**
6-
* @template T extends object
6+
* @template {Record<string, any>} T
77
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
88
*/
99

examples/preact/src/layouts/root.layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { html } from 'htm/preact'
33
import { render } from 'preact-render-to-string'
44

55
/**
6-
* @template T extends object
6+
* @template {Record<string, any>} T
77
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
88
*/
99

examples/tailwind/src/layouts/root.layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { html } from 'htm/preact'
33
import { render } from 'preact-render-to-string'
44

55
/**
6-
* @template T extends object
6+
* @template {Record<string, any>} T
77
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
88
*/
99

index.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,51 @@ import { TopBunAggregateError } from './lib/helpers/top-bun-aggregate-error.js'
2020
*/
2121

2222
/**
23-
* @template T extends Object.<string, any>
23+
* @template {Record<string, any>} T
2424
* @typedef {import('./lib/build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
2525
*/
2626

2727
/**
28-
* @template T extends Object.<string, any>
28+
* @template {Record<string, any>} T
2929
* @typedef {import('./lib/build-pages/resolve-vars.js').PostVarsFunction<T>} PostVarsFunction
3030
*/
3131

3232
/**
33-
* @template T extends Object.<string, any>
33+
* @template {Record<string, any>} T
3434
* @typedef {import('./lib/build-pages/page-builders/page-writer.js').PageFunction<T>} PageFunction
3535
*/
3636

3737
/**
38-
* @template T extends Object.<string, any>
38+
* @template {Record<string, any>} T
3939
* @typedef {import('./lib/build-pages/page-builders/template-builder.js').TemplateFunction<T>} TemplateFunction
4040
*/
4141

4242
/**
43-
* @template T extends Object.<string, any>
43+
* @template {Record<string, any>} T
4444
* @typedef {import('./lib/build-pages/page-builders/template-builder.js').TemplateAsyncIterator<T>} TemplateAsyncIterator
4545
*/
4646

4747
/**
4848
* @typedef {import('./lib/build-pages/page-builders/template-builder.js').TemplateOutputOverride} TemplateOutputOverride
4949
*/
5050

51+
const DEFAULT_IGNORES = /** @type {const} */ ([
52+
'.*',
53+
'coverage',
54+
'node_modules',
55+
'package.json',
56+
'package-lock.json',
57+
'pnpm-lock.yaml',
58+
'yarn.lock',
59+
])
60+
61+
/**
62+
* @template {TopBunOpts} [CurrentOpts=TopBunOpts]
63+
*/
5164
export class TopBun {
5265
/** @type {string} */ #src = ''
5366
/** @type {string} */ #dest = ''
54-
/** @type {TopBunOpts} */ opts = {}
67+
/** @type {Readonly<CurrentOpts & { ignore: string[] }>} */ opts
5568
/** @type {FSWatcher?} */ #watcher = null
5669
/** @type {any?} */ #cpxWatcher = null
5770
/** @type {browserSync.BrowserSyncInstance?} */ #browserSyncServer = null
@@ -60,20 +73,24 @@ export class TopBun {
6073
*
6174
* @param {string} src - The src path of the page build
6275
* @param {string} dest - The dest path of the page build
63-
* @param {TopBunOpts} [opts] - The options for the site build
76+
* @param {CurrentOpts} [opts] - The options for the site build
6477
*/
65-
constructor (src, dest, opts = {}) {
66-
assert(src, 'src is a required argument')
67-
assert(dest, 'dest is a required argument')
68-
69-
const defaultIgnore = ['.*', 'node_modules', basename(dest), 'package.json', 'pacakge-lock.json']
70-
71-
opts.ignore = defaultIgnore.concat(makeArray(opts.ignore))
78+
constructor (src, dest, opts = /** @type {CurrentOpts} */ ({})) {
79+
if (!src || typeof src !== 'string') throw new TypeError('src should be a (non-empty) string')
80+
if (!dest || typeof dest !== 'string') throw new TypeError('dest should be a (non-empty) string')
81+
if (!opts || typeof opts !== 'object') throw new TypeError('opts should be an object')
7282

7383
this.#src = src
7484
this.#dest = dest
7585

76-
this.opts = opts
86+
this.opts = {
87+
...opts,
88+
ignore: [
89+
...DEFAULT_IGNORES,
90+
basename(dest),
91+
...makeArray(opts.ignore),
92+
],
93+
}
7794
}
7895

7996
get watching () {

lib/build-pages/page-builders/html/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import assert from 'node:assert'
22
import { readFile } from 'fs/promises'
33
import Handlebars from 'handlebars'
44

5-
/**
6-
* @template T
7-
* @typedef {import('../page-writer.js').PageBuilderType<T>} PageBuilderType
8-
*/
9-
105
/**
116
* Build all of the bundles using esbuild.
12-
* @template T
13-
* @type {PageBuilderType<T>}
7+
* @template {Record<string, any>} T
8+
* @type {import('../page-writer.js').PageBuilderType<T>}
149
*/
1510
export async function htmlBuilder ({ pageInfo }) {
1611
assert(pageInfo.type === 'html', 'html builder requires a "html" page type')

lib/build-pages/page-builders/js/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import assert from 'node:assert'
22

3-
/**
4-
* @template T
5-
* @typedef {import('../page-writer.js').PageBuilderType<T>} PageBuilderType
6-
*/
7-
83
/**
94
* Build all of the bundles using esbuild.
10-
* @template T
11-
* @type {PageBuilderType<T>}
5+
* @template {Record<string, any>} T
6+
* @type {import('../page-writer.js').PageBuilderType<T>}
127
*/
138
export async function jsBuilder ({ pageInfo }) {
149
assert(pageInfo.type === 'js', 'js page builder requries "js" page type')

lib/build-pages/page-builders/md/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@ import { getMd, renderMd } from './get-md.js'
77

88
const md = getMd()
99

10-
/**
11-
* @template T
12-
* @typedef {import('../page-writer.js').PageBuilderType<T>} PageBuilderType
13-
*/
14-
1510
/**
1611
* Build all of the bundles using esbuild.
17-
* @template T
18-
* @type {PageBuilderType<T>}
12+
* @template {Record<string, any>} T
13+
* @type {import('../page-writer.js').PageBuilderType<T>}
1914
*/
2015
export async function mdBuilder ({ pageInfo }) {
2116
assert(pageInfo.type === 'md', 'md builder requires an "md" page type')

lib/build-pages/page-builders/page-writer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { writeFile, mkdir } from 'fs/promises'
66
*/
77

88
/**
9-
* @template T extends Object.<string, any>
9+
* @template {Record<string, any>} T
1010
* @typedef {import('../page-data.js').PageData<T>} PageData
1111
*/
1212

1313
/**
1414
* pageLayout functions Can be used to type a name.layout.js file
1515
*
1616
* @async
17-
* @template T extends Object.<string, any>
17+
* @template {Record<string, any>} T
1818
* @callback PageFunction
1919
* @param {object} params - The parameters for the pageLayout.
2020
* @param {T} params.vars - All default, global, layout, page, and builder vars shallow merged.
@@ -26,14 +26,14 @@ import { writeFile, mkdir } from 'fs/promises'
2626
*/
2727

2828
/**
29-
* @template T extends Object.<string, any>
29+
* @template {Record<string, any>} T
3030
* @typedef PageBuilderResult
3131
* @property {object} vars - Any variables resolved by the builder
3232
* @property {PageFunction<T>} pageLayout - The function that returns the rendered page
3333
*/
3434

3535
/**
36-
* @template T extends Object.<string, any>
36+
* @template {Record<string, any>} T
3737
* @callback PageBuilderType
3838
*
3939
* @param {object} params
@@ -43,7 +43,7 @@ import { writeFile, mkdir } from 'fs/promises'
4343

4444
/**
4545
* Handles rendering and writing a page to disk
46-
* @template T extends object
46+
* @template {Record<string, any>} T
4747
* @param {object} params
4848
* @param {string} params.src - The src folder.
4949
* @param {string} params.dest - The dest folder.

lib/build-pages/page-builders/template-builder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { writeFile, mkdir } from 'fs/promises'
66
*/
77

88
/**
9-
* @template T extends object
9+
* @template {Record<string, any>} T
1010
* @typedef {import('../page-data.js').PageData<T>} PageData
1111
*/
1212

@@ -18,7 +18,7 @@ import { writeFile, mkdir } from 'fs/promises'
1818
/**
1919
* Callback for rendering a template.
2020
*
21-
* @template T extends Object.<string, any>,
21+
* @template {Record<string, any>} T
2222
* @callback TemplateFunction
2323
* @param {object} params - The parameters for the template.
2424
* @param {T} params.vars - All of the site globalVars.
@@ -29,7 +29,7 @@ import { writeFile, mkdir } from 'fs/promises'
2929
*/
3030

3131
/**
32-
* @template T
32+
* @template {Record<string, any>} T
3333
* @typedef {Parameters<TemplateFunction<T>>} TemplateFunctionParams
3434
*/
3535

@@ -51,7 +51,7 @@ import { writeFile, mkdir } from 'fs/promises'
5151

5252
/**
5353
* The template builder renders templates agains the globalVars variables
54-
* @template T extends Object.<string, any>
54+
* @template {Record<string, any>} T
5555
* @param {object} params
5656
* @param {string} params.src - The src path of the site build.
5757
* @param {string} params.dest - The dest path of the site build.

0 commit comments

Comments
 (0)