Skip to content

Commit

Permalink
fix(page): stop inlining minissg types
Browse files Browse the repository at this point in the history
  • Loading branch information
uenoB committed Jan 4, 2025
1 parent 2372599 commit 9430cb5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion packages/page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"debug": "^4.4.0"
},
"devDependencies": {
"@types/debug": "^4.1.12"
"@types/debug": "^4.1.12",
"vite-plugin-minissg": "^4.1.3"
}
}
4 changes: 2 additions & 2 deletions packages/page/src/minissg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Main } from 'vite-plugin-minissg'

Check failure on line 1 in packages/page/src/minissg.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.

Check failure on line 1 in packages/page/src/minissg.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.
import type { Awaitable } from '../../vite-plugin-minissg/src/util'
import type * as minissg from '../../vite-plugin-minissg/src/module'

export type MainModule = Readonly<{ main: minissg.Main }>
export type MainModule = Readonly<{ main: Main }>
export type Loaded<Impl> = Awaitable<Impl | MainModule>

export const hasMinissgMain = (x: object): x is MainModule =>
Expand Down
4 changes: 2 additions & 2 deletions packages/page/src/page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Delay } from '@minissg/async'
import type { Content } from 'vite-plugin-minissg'

Check failure on line 2 in packages/page/src/page.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.

Check failure on line 2 in packages/page/src/page.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.
import type { Awaitable, Null } from '../../vite-plugin-minissg/src/util'
import type * as minissg from '../../vite-plugin-minissg/src/module'
import { type Pairs, type List, iteratePairs, listItems } from './items'
import type { RelPath as RelPathTy } from './filename'
import { PathSteps, emptyRelPath, copyRelPath } from './filename'
Expand Down Expand Up @@ -33,7 +33,7 @@ interface CommonArg<Load, This> {
url?: Readonly<URL> | string | Null
parsePath?: ((this: This, path: string) => Awaitable<ParsePath>) | Null
paginatePath?: ((this: This, index: number) => Awaitable<RelPath>) | Null
render?: ((this: This, loaded: Load) => Awaitable<minissg.Content>) | Null
render?: ((this: This, loaded: Load) => Awaitable<Content>) | Null
}

type Loaded<Load> = Awaitable<Load | MainModule>
Expand Down
8 changes: 4 additions & 4 deletions packages/page/src/page_base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Delay } from '@minissg/async'
import type * as minissg from '../../vite-plugin-minissg/src/module'
import type { Content, Context, Module } from 'vite-plugin-minissg'

Check failure on line 2 in packages/page/src/page_base.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.

Check failure on line 2 in packages/page/src/page_base.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.
import type { Awaitable } from '../../vite-plugin-minissg/src/util'
import type { RelPath } from './filename'
import type { Asset } from './asset'
Expand Down Expand Up @@ -92,18 +92,18 @@ export abstract class PageBase<Base, This extends Base = Base, Load = unknown> {
return this.stem.wrap(s => this.#tree?.findByStem('/' + s) ?? new Set())
}

main(context: Readonly<minissg.Context>): Awaitable<minissg.Module> {
main(context: Readonly<Context>): Awaitable<Module> {
if (this.#tree == null) throw Error('main is unavailable')
return this.#tree.main(context)
}

render(module: Load): Awaitable<minissg.Content> {
render(module: Load): Awaitable<Content> {
const mod: unknown = module
if (mod == null) return mod
if (typeof mod === 'string') return mod
if (mod instanceof Uint8Array) return mod
if (typeof mod !== 'object') return `[${typeof mod}]`
if ('default' in mod) return mod.default as minissg.Content
if ('default' in mod) return mod.default as Content
// eslint-disable-next-line @typescript-eslint/unbound-method
return Reflect.apply(Object.prototype.toString, mod, [])
}
Expand Down
15 changes: 8 additions & 7 deletions packages/page/src/tree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Delay, Ivar, Memo } from '@minissg/async'
import type * as minissg from '../../vite-plugin-minissg/src/module'
import type { Context, Module } from 'vite-plugin-minissg'

Check failure on line 2 in packages/page/src/tree.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.

Check failure on line 2 in packages/page/src/tree.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.
import type { ModuleName } from '../../vite-plugin-minissg/src/module'
import { type Awaitable, raise } from '../../vite-plugin-minissg/src/util'
import type { FileName, RelPath } from './filename'
import { PathSteps, concatName, concatFileName, emptyRelPath } from './filename'
Expand All @@ -15,9 +16,9 @@ type Laziable<X> = X | (() => X)

interface Instance<Base> {
readonly self: PublicTree<Base>
readonly moduleName: minissg.ModuleName
readonly stem: minissg.ModuleName
readonly variant: minissg.ModuleName
readonly moduleName: ModuleName
readonly stem: ModuleName
readonly variant: ModuleName
readonly fileName: FileName
readonly parent: Instance<Base> | undefined // undefined means root
readonly root: Instance<Base> | undefined // undefined means self
Expand Down Expand Up @@ -90,7 +91,7 @@ export class Tree<Base, This extends Base = Base, Load = unknown> {
})
}

toContext(): Delay<minissg.Context> {
toContext(): Delay<Context> {
return this.instance.get().wrap(inst => {
const parentContext = inst.parent?.self.toContext()
return (parentContext ?? Delay.resolve(undefined)).wrap(parent => {
Expand Down Expand Up @@ -249,7 +250,7 @@ export class Tree<Base, This extends Base = Base, Load = unknown> {
}

private findParent(
context: Readonly<minissg.Context> | undefined
context: Readonly<Context> | undefined
): Delay<Instance<Base> | undefined> {
for (let c = context; c != null; c = c.parent) {
const tree = this.context.getTree(c.module)
Expand All @@ -258,7 +259,7 @@ export class Tree<Base, This extends Base = Base, Load = unknown> {
return Delay.resolve(undefined)
}

async main(context: Readonly<minissg.Context>): Promise<minissg.Module> {
async main(context: Readonly<Context>): Promise<Module> {
const inst = await this.instantiate(() => this.findParent(context.parent))
if (context.moduleName.path !== inst.moduleName.path) {
throw Error(`module name mismatch: ${context.moduleName.path}`)
Expand Down
5 changes: 2 additions & 3 deletions packages/page/src/tree_context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AsyncLocalStorage } from 'node:async_hooks'
import { Memo } from '@minissg/async'
import type * as minissg from '../../vite-plugin-minissg/src/module'
import type { Context } from 'vite-plugin-minissg'

Check failure on line 3 in packages/page/src/tree_context.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.

Check failure on line 3 in packages/page/src/tree_context.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'vite-plugin-minissg' or its corresponding type declarations.
import type { Awaitable } from '../../vite-plugin-minissg/src/util'
//import { FileName } from './filename'
import type { PageBase } from './page_base'
import type { PublicTree } from './tree'

Expand All @@ -29,7 +28,7 @@ export class TreeContext<Base, This extends Base = Base, Load = unknown> {

private static readonly loadedStorage = new AsyncLocalStorage<Set<string>>()

static run<X>(context: minissg.Context, func: () => X): X {
static run<X>(context: Context, func: () => X): X {
return Memo.inContext(context, () => {
return context.loaded != null
? this.loadedStorage.run(context.loaded, func)
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9430cb5

Please sign in to comment.