@lincyaw/kernel 1.0.0-rc.33 → 1.0.0-rc.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ Plugins declare it as a peer dependency, so they share the application's copy:
14
14
 
15
15
  ## Entries
16
16
 
17
- - `@lincyaw/kernel`: the contracts (`PresmiumNodePlugin`, `PluginDefinition`, `DirectiveSpec`, `IRPass`, `Renderer`, `RenderContext`, `Check`, the service tokens), the canonical authoring types (`TeachingDocument`, `DocumentEditOperation`), `DOCUMENT_ENTRY`, `DOCUMENT_SCHEMA_VERSION`, `DOCUMENT_JSON_SCHEMA`, `validateDocument`, the derived IR types (`IRDocument` and its nodes), `KERNEL_VERSION`, `IR_VERSION`, and plain helpers such as `docBlocks`, `withProp`, `deckLocale`, `jsonResponse` and `problemResponse`.
17
+ - `@lincyaw/kernel`: the contracts (`PresmiumNodePlugin`, `PluginDefinition`, `IRPass`, `Renderer`, `RenderContext`, `Check`, the service tokens), the canonical authoring types (`TeachingDocument`, `DocumentEditOperation`), `DOCUMENT_ENTRY`, `DOCUMENT_SCHEMA_VERSION`, `DOCUMENT_JSON_SCHEMA`, `validateDocument`, the derived IR types (`IRDocument` and its nodes), `KERNEL_VERSION`, `IR_VERSION`, and plain helpers such as `docBlocks`, `withProp`, `deckLocale`, `jsonResponse` and `problemResponse`.
18
18
  - `@lincyaw/kernel/contracts`, `@lincyaw/kernel/ir`: the contracts (types, service tokens and the preview protocol's parsers) or the IR types alone; the helpers are only in `@lincyaw/kernel`.
19
19
  - `@lincyaw/kernel/reading`: plain functions that read a compiled document, the IR (`chapters`, `blockText`, `narrationAt`, `tokenize`); they do no I/O.
20
20
  - `@lincyaw/kernel/node`: helpers for Node code: `copyPublished` and `isInside` (its other exports are internal).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/kernel",
3
- "version": "1.0.0-rc.33",
3
+ "version": "1.0.0-rc.35",
4
4
  "description": "Presmium's shared kernel: the IR and plugin contracts, the service registry, anchors and checks",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -40,6 +40,7 @@
40
40
  "json-schema-library": "11.6.16",
41
41
  "parse5": "7.3.0",
42
42
  "semver": "^7.8.5",
43
- "proper-lockfile": "4.1.2"
43
+ "proper-lockfile": "4.1.2",
44
+ "resolve.exports": "2.0.4"
44
45
  }
45
46
  }
@@ -1,4 +1,4 @@
1
- import type { CanonicalSource, DirectiveSpec, IRDocument, IRPass, Renderer, RendererContribution, RoleSpec } from '../ir.ts'
1
+ import type { CanonicalSource, IRDocument, IRPass, Renderer, RendererContribution } from '../ir.ts'
2
2
  import type { AgentTool } from './agent.ts'
3
3
  import type { AnchorResolver, AnchorString } from './anchors.ts'
4
4
  import type { Check, CheckContext } from './checks.ts'
@@ -159,7 +159,6 @@ export interface PresmiumNodePlugin {
159
159
  resolvers?: AnchorResolver[]
160
160
  checks?: Check[]
161
161
  anchors?(ctx: CheckContext): AnchorString[] | Promise<AnchorString[]>
162
- directives?: DirectiveSpec[]
163
162
  passes?: IRPass[]
164
163
  executors?: Executor[]
165
164
  renderer?: Renderer
@@ -177,7 +176,6 @@ export interface PresmiumNodePlugin {
177
176
  services?(ctx: NodeServiceContext): [ServiceToken<unknown>, unknown][]
178
177
  environments?: Record<string, EnvironmentProvider>
179
178
  server?(ctx: ServerContext): ServerContribution | Promise<ServerContribution>
180
- roles?: RoleSpec[]
181
179
  tools?: AgentTool[]
182
180
  operator?: boolean
183
181
  }
package/src/ir.ts CHANGED
@@ -168,46 +168,7 @@ export interface ComponentNode {
168
168
  layer?: 'overlay'
169
169
  durations?: number[]
170
170
  /** The authored code that defines this component instance, when supplied by its plugin. */
171
- definition?: { file: string, language: string, exportName?: string }
172
- }
173
-
174
- export type DirectiveOptionType = 'string' | 'number' | 'boolean' | 'list'
175
-
176
- export interface DirectiveInput {
177
- name: string
178
- arg?: string
179
- options: Record<string, unknown>
180
- body: string
181
- }
182
-
183
- export interface DirectiveContext {
184
- file: string
185
- deckDir: string
186
- workspaceRoot: string
187
- lang?: string
188
- config: Record<string, unknown>
189
- source: SourcePos
190
- parse(markdown: string): MdastNode
191
- report(finding: Finding): void
192
- watch(...files: string[]): void
193
- }
194
-
195
- export interface DirectiveResult {
196
- node: IRNode
197
- role?: BlockRole
198
- span?: number
199
- }
200
-
201
- export interface RoleInput {
202
- name: string
203
- value: string
204
- options: Record<string, unknown>
205
- }
206
-
207
- export interface RoleSpec {
208
- name: string
209
- options?: Record<string, DirectiveOptionType>
210
- children?(input: RoleInput, ctx: DirectiveContext): MdastNode[]
171
+ definition?: { file: string, language: string, exportName?: string, kind?: string }
211
172
  }
212
173
 
213
174
  export interface PresmiumRoleNode extends MdastNode {
@@ -218,14 +179,6 @@ export interface PresmiumRoleNode extends MdastNode {
218
179
  children: MdastNode[]
219
180
  }
220
181
 
221
- export interface DirectiveSpec {
222
- name: string
223
- arg?: boolean | 'anchor'
224
- body?: boolean
225
- options?: Record<string, DirectiveOptionType>
226
- toIR(input: DirectiveInput, ctx: DirectiveContext): DirectiveResult | Promise<DirectiveResult>
227
- }
228
-
229
182
  export interface RunCache {
230
183
  get(key: string): RecordedRun | undefined
231
184
  set(key: string, run: RecordedRun): void
package/src/node/index.ts CHANGED
@@ -10,7 +10,7 @@ export { createVoiceoverOwner, VoiceoverOperationError, validateVoiceoverStart,
10
10
  export { createVoiceoverRoutes } from './voiceover-routes.ts'
11
11
  export { validateTranscriptionAdoptionDraft, validateTranscriptionAdoptionApply } from './transcription-adoption.ts'
12
12
  export { FONT_LICENSE, fontLicense } from './fonts.ts'
13
- export { findPackageBin, importSpecifier, literalGlob, packageOf, playwrightChromium, TYPESCRIPT_IMPORT } from './packages.ts'
13
+ export { findPackageBin, importSpecifier, literalGlob, packageExport, packageOf, playwrightChromium, TYPESCRIPT_IMPORT } from './packages.ts'
14
14
  export { ffmpegInstallCommand, findFfmpeg } from './ffmpeg.ts'
15
15
  export type { Ffmpeg } from './ffmpeg.ts'
16
16
  export { bracketIPv6, lanAddresses } from './network.ts'
@@ -2,6 +2,31 @@ import { existsSync, readFileSync } from 'node:fs'
2
2
  import { createRequire, findPackageJSON } from 'node:module'
3
3
  import { dirname, isAbsolute, join, relative, sep } from 'node:path'
4
4
  import { pathToFileURL } from 'node:url'
5
+ import { exports as resolveExports } from 'resolve.exports'
6
+
7
+ /** Resolve a public package export with Node or browser conditions, retaining package-relative target validation. */
8
+ export function packageExport(pkg: { name?: unknown, exports?: unknown }, dir: string, subpath: string, options: { browser?: boolean } = {}): string | undefined {
9
+ let targets: string[] | void
10
+ try {
11
+ targets = resolveExports(pkg as Parameters<typeof resolveExports>[0], subpath, options)
12
+ } catch {
13
+ return undefined
14
+ }
15
+ if (!targets?.length) return undefined
16
+ const base = pathToFileURL(`${dir}/`)
17
+ for (const target of targets) {
18
+ const path = target.split(/[?#]/, 1)[0]!
19
+ if (!path.startsWith('./') || /%2f|%5c/i.test(path)) continue
20
+ try {
21
+ const segments = path.slice(2).split(/[\\/]/).map(decodeURIComponent)
22
+ if (segments.some(segment => /^(?:\.{1,2}|node_modules)$/i.test(segment))) continue
23
+ if (new URL(target, base).href.startsWith(base.href)) return target
24
+ } catch {
25
+ // An export array may contain another valid package-relative target.
26
+ }
27
+ }
28
+ throw new Error(`${subpath} has no valid package-relative target`)
29
+ }
5
30
 
6
31
  export const TYPESCRIPT_IMPORT: readonly string[] = ['--import', new URL('./strip-types.mjs', import.meta.url).href]
7
32