@lincyaw/compiler 1.0.0-rc.3 → 1.0.0-rc.30
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/package.json +2 -2
- package/src/compilation-actions.ts +3 -1
- package/src/compiler.ts +4 -2
- package/src/index.ts +1 -0
- package/src/plugins.ts +20 -1
- package/src/renderers.ts +19 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/compiler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.30",
|
|
4
4
|
"description": "Presmium's compiler: structured JSON documents to runtime IR, plugin loading, compile-time execution and its cache, checks and the renderers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"semver": "^7.8.5",
|
|
39
39
|
"send": "1.2.1",
|
|
40
40
|
"yaml": "^2.9.1",
|
|
41
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
41
|
+
"@lincyaw/kernel": "1.0.0-rc.30"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/content-disposition": "^0.5.9",
|
|
@@ -5,6 +5,7 @@ import type { CheckContext, Finding, RunResult } from '@lincyaw/kernel'
|
|
|
5
5
|
import { build } from './build.ts'
|
|
6
6
|
import type { BuildReport } from './build.ts'
|
|
7
7
|
import type { Compilation } from './compiler.ts'
|
|
8
|
+
import { rendererChecks } from './renderers.ts'
|
|
8
9
|
import { frontmatterLine } from './source-lines.ts'
|
|
9
10
|
|
|
10
11
|
export function checkContext(compilation: Compilation): CheckContext {
|
|
@@ -20,7 +21,7 @@ export function checkContext(compilation: Compilation): CheckContext {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
/** The plugins' checks
|
|
24
|
+
/** The plugins' checks, the publication checks and the renderers'; a crashed check or a duplicate check ID becomes a finding. */
|
|
24
25
|
export async function runAllChecks(compilation: Compilation, options: { externalLinks?: boolean } = {}): Promise<Finding[]> {
|
|
25
26
|
const { entry } = compilation
|
|
26
27
|
const text = await readFile(entry, 'utf8').catch(() => '')
|
|
@@ -42,6 +43,7 @@ export async function runAllChecks(compilation: Compilation, options: { external
|
|
|
42
43
|
findings.push(finding.source ? finding : { ...finding, source: places.get(finding.checkId) ?? { file: entry, line: 1 } })
|
|
43
44
|
}
|
|
44
45
|
findings.push(...await compilation.publishChecks({ externalLinks: options.externalLinks }))
|
|
46
|
+
findings.push(...await rendererChecks(compilation))
|
|
45
47
|
return findings
|
|
46
48
|
}
|
|
47
49
|
|
package/src/compiler.ts
CHANGED
|
@@ -278,9 +278,11 @@ export class Compiler {
|
|
|
278
278
|
const document = validated.document
|
|
279
279
|
const headmatter = withHeadmatter({ ...document.metadata }, this.options.headmatter)
|
|
280
280
|
const defaultVoice = document.production.defaults.voiceSource
|
|
281
|
-
const
|
|
281
|
+
const declared = isRecord((headmatter.renderers as Record<string, unknown> | undefined)?.lecture)
|
|
282
|
+
const lecture = declared ? (headmatter.renderers as Record<string, Record<string, unknown>>).lecture : {}
|
|
282
283
|
if (lecture && Object.hasOwn(lecture, 'script')) throw new Error('/metadata/renderers/lecture/script: External lecture scripts are not supported. Author narration in lecture.json narrations and bind it through each step narrationIds.')
|
|
283
|
-
|
|
284
|
+
// The production defaults configure the lecture form where the document builds it; they never add the form.
|
|
285
|
+
if (declared && (defaultVoice?.type === 'tts' || document.production.defaults.trailingPauseMs !== undefined || Object.keys(lecture ?? {}).length)) headmatter.renderers = { ...(isRecord(headmatter.renderers) ? headmatter.renderers : {}), lecture: { ...lecture, ...defaultVoice?.type === 'tts' ? { voice: defaultVoice.voice } : {}, ...document.production.defaults.trailingPauseMs !== undefined ? { gap: document.production.defaults.trailingPauseMs } : {} } }
|
|
284
286
|
const lang = typeof headmatter.lang === 'string' && headmatter.lang.trim() ? headmatter.lang.trim() : DEFAULT_LANG
|
|
285
287
|
const inputs = new CompileInputs(workspaceRoot, this.#committed)
|
|
286
288
|
const presmium = isRecord(headmatter.presmium) ? headmatter.presmium : {}
|
package/src/index.ts
CHANGED
|
@@ -26,5 +26,6 @@ export { frontmatterLine, lineContaining } from './source-lines.ts'
|
|
|
26
26
|
export { compileTranslations, documentDigest } from './translations.ts'
|
|
27
27
|
export type { CompiledTranslation } from './translations.ts'
|
|
28
28
|
export { viewFor } from './views.ts'
|
|
29
|
+
export { findWorkspaceRoot } from './workspace.ts'
|
|
29
30
|
export { operatorDir, WORKSPACE_CONFIG, workspaceSettings } from './workspace-settings.ts'
|
|
30
31
|
export type { OperatorSettings } from './workspace-settings.ts'
|
package/src/plugins.ts
CHANGED
|
@@ -35,11 +35,30 @@ const jiti = createJiti(import.meta.url)
|
|
|
35
35
|
|
|
36
36
|
export async function loadPlugin(name: string, deckDir: string, sources?: PluginSources): Promise<{ loaded?: LoadedPlugin, problem?: PluginProblem }> {
|
|
37
37
|
const problem = (severity: Severity, message: string): PluginProblem => ({ name, severity, message })
|
|
38
|
-
const
|
|
38
|
+
const own = findPackageDir(name, resolve(deckDir))
|
|
39
|
+
const bundled = bundledDir(name, sources)
|
|
40
|
+
// An official plugin is versioned with the Presmium that runs it (its host, viewer and kernel): use the
|
|
41
|
+
// installation's copy whenever the project has a separate copy, even when both happen to have the same version.
|
|
42
|
+
// Otherwise the plugin's browser bundle can carry a second host module and fail with "no host installed".
|
|
43
|
+
if (own && bundled && name.startsWith(PRESMIUM_SCOPE) && realpathSync(own) !== realpathSync(bundled)) {
|
|
44
|
+
const result = await loadFrom(name, bundled, problem)
|
|
45
|
+
if (result.problem || packageVersion(own) === packageVersion(bundled)) return result
|
|
46
|
+
return { ...result, problem: problem('warning', `plugin "${name}": the project's ${packageVersion(own)} is not used; this Presmium runs its own ${packageVersion(bundled)}. Update the project's @lincyaw packages (pnpm up "@lincyaw/*") or run the project's own presmium (pnpm exec presmium)`) }
|
|
47
|
+
}
|
|
48
|
+
const dir = own ?? bundled
|
|
39
49
|
if (!dir) return { problem: problem('error', `cannot load plugin "${name}": package not found from ${deckDir}`) }
|
|
40
50
|
return loadFrom(name, dir, problem)
|
|
41
51
|
}
|
|
42
52
|
|
|
53
|
+
function packageVersion(dir: string): string | undefined {
|
|
54
|
+
try {
|
|
55
|
+
const { version } = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { version?: unknown }
|
|
56
|
+
return typeof version === 'string' ? version : undefined
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
43
62
|
function bundledDir(name: string, sources?: PluginSources): string | undefined {
|
|
44
63
|
if (!sources?.bundled) return undefined
|
|
45
64
|
return BUNDLED.has(name) || dependsOn(sources.bundled, name) ? findPackageDir(name, sources.bundled) : undefined
|
package/src/renderers.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { errorMessage, findComponentRenderer, isRecord } from '@lincyaw/kernel'
|
|
|
4
4
|
import type { BoundRendererExtension, ComponentNode, ComponentRenderer, Exporter, Finding, IRBlock, IRDocument, NodeVitePlugin, RenderContext, RenderOutput, Renderer } from '@lincyaw/kernel'
|
|
5
5
|
import { documentLink, publishedAsset } from './assets.ts'
|
|
6
6
|
import type { Compilation, Compiler } from './compiler.ts'
|
|
7
|
-
import { portable } from './paths.ts'
|
|
7
|
+
import { portable, WORK_DIR } from './paths.ts'
|
|
8
8
|
import { loadPlugin, pluginId } from './plugins.ts'
|
|
9
9
|
import type { LoadedPlugin } from './plugins.ts'
|
|
10
10
|
import { compileTranslations } from './translations.ts'
|
|
@@ -172,6 +172,24 @@ export function nodeVitePlugins(compilation: Pick<Compilation, 'plugins' | 'doc'
|
|
|
172
172
|
})
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/** The checks of the document's renderers (`Renderer.check`), each given the whole document; a crashed check becomes a finding. */
|
|
176
|
+
export async function rendererChecks(compilation: Compilation): Promise<Finding[]> {
|
|
177
|
+
const { selected } = await selectRenderers(compilation)
|
|
178
|
+
const run = planRenderRun(compilation, selected, false)
|
|
179
|
+
const findings: Finding[] = []
|
|
180
|
+
for (const { renderer } of selected) {
|
|
181
|
+
if (!renderer.check) continue
|
|
182
|
+
const workDir = join(compilation.deckDir, WORK_DIR, renderer.id)
|
|
183
|
+
const ctx = renderContext(compilation, renderer.id, workDir, workDir, run, findings)
|
|
184
|
+
try {
|
|
185
|
+
for (const finding of await renderer.check(compilation.doc, ctx)) ctx.report(finding)
|
|
186
|
+
} catch (error) {
|
|
187
|
+
findings.push(renderFinding(compilation, 'error', `renderer ${renderer.id} could not check the document: ${errorMessage(error)}`))
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return findings
|
|
191
|
+
}
|
|
192
|
+
|
|
175
193
|
export function unsupportedBlocks(doc: IRDocument, renderer: Renderer, extensions: BoundRendererExtension[]): RenderOutput['skipped'] {
|
|
176
194
|
const skipped: RenderOutput['skipped'] = []
|
|
177
195
|
const visit = (section: string, blocks: IRBlock[]) => {
|