@lincyaw/workspace 1.0.0-rc.29 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/workspace",
3
- "version": "1.0.0-rc.29",
3
+ "version": "1.0.0-rc.30",
4
4
  "description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -34,12 +34,12 @@
34
34
  "mime-types": "3.0.2",
35
35
  "playwright-chromium": "1.64.1",
36
36
  "yaml": "^2.9.1",
37
- "@lincyaw/compiler": "1.0.0-rc.29",
38
- "@lincyaw/kernel": "1.0.0-rc.29",
39
- "@lincyaw/server": "1.0.0-rc.29"
37
+ "@lincyaw/compiler": "1.0.0-rc.30",
38
+ "@lincyaw/kernel": "1.0.0-rc.30",
39
+ "@lincyaw/server": "1.0.0-rc.30"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/mime-types": "^3.0.1",
43
- "@lincyaw/mcp": "1.0.0-rc.29"
43
+ "@lincyaw/mcp": "1.0.0-rc.30"
44
44
  }
45
45
  }
package/src/node/build.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { cpSync, existsSync, readdirSync, rmSync } from 'node:fs'
2
2
  import { isAbsolute, join, resolve } from 'node:path'
3
- import { build, Compiler } from '@lincyaw/compiler'
3
+ import { build, Compiler, WORKSPACE_CONFIG } from '@lincyaw/compiler'
4
4
  import type { Compilation, RunStats } from '@lincyaw/compiler'
5
5
  import { APP_DIR, errorMessage, isRecord, SLIDES_DIR } from '@lincyaw/kernel'
6
6
  import type { Finding, IRDocument, SiteSpec } from '@lincyaw/kernel'
7
+ import { relativePath } from '../domain/paths.ts'
7
8
  import { listDocuments, readWorkspaceConfig } from './config.ts'
8
9
  import { siteContext, siteDocument, siteIR, siteSpec, siteTranslations, webRenderer } from './site.ts'
9
10
 
@@ -25,7 +26,7 @@ export async function buildWorkspace(root: string, options: { outDir?: string, b
25
26
  for (const document of found) {
26
27
  const compilation = await new Compiler(join(config.root, document.entry), { bundled: options.bundled, settings: config.settings }).compile({ pruneCache: true })
27
28
  compilations.push(compilation)
28
- const to = presentations(compilation, base, `${base}${urlPath(document.dir)}/`, siteLook(config.site, config.root))
29
+ const to = presentations(compilation, base, `${base}${urlPath(document.dir)}/`, siteLook(config.site, config.root, document.dir))
29
30
  if (to.length > 0) forms.push({ dir: document.dir, compilation, to })
30
31
  const translated = await siteTranslations(compilation)
31
32
  findings.push(...compilation.doc.diagnostics, ...translated.findings)
@@ -82,10 +83,14 @@ function pluginsByName(site: SiteSpec, compilations: readonly Compilation[]): Re
82
83
 
83
84
  const PRESENTATIONS = ['slides', 'lecture']
84
85
 
85
- /** The site's theme and its parameters, for its presentations to look like its pages; a theme directory made absolute. */
86
- function siteLook(site: Record<string, unknown>, root: string): Record<string, unknown> {
86
+ /**
87
+ * The site's theme and its parameters, for the presentations of the document in `dir` to look like its pages: a theme
88
+ * directory made absolute, and the parameters with the file they are written in (`siteFile`, relative to the document),
89
+ * for their paths (`logo`) to resolve against it.
90
+ */
91
+ function siteLook(site: Record<string, unknown>, root: string, dir: string): Record<string, unknown> {
87
92
  const theme = typeof site.theme === 'string' && (site.theme.startsWith('.') || isAbsolute(site.theme)) ? resolve(root, site.theme) : site.theme
88
- return { ...theme !== undefined ? { theme } : {}, ...isRecord(site.params) ? { params: site.params } : {} }
93
+ return { ...theme !== undefined ? { theme } : {}, ...isRecord(site.params) ? { params: site.params, siteFile: relativePath(dir, WORKSPACE_CONFIG) } : {} }
89
94
  }
90
95
 
91
96
  const urlPath = (dir: string) => dir.split('/').map(encodeURIComponent).join('/')
@@ -106,7 +111,12 @@ function presentations(compilation: Compilation, base: string, prefix: string, l
106
111
  const { renderers } = compilation.doc.config
107
112
  const to = PRESENTATIONS.filter(form => renderers[form] !== undefined)
108
113
  if (to.length === 0) return to
109
- if (to.includes('slides')) renderers.slides = { ...look, ...isRecord(renderers.slides) ? renderers.slides : {}, base: `${prefix}${SLIDES_DIR}/`, appBase: base }
114
+ if (to.includes('slides')) {
115
+ const own = isRecord(renderers.slides) ? renderers.slides : {}
116
+ // Parameters the document sets for its slides are written in its lecture.json, not in the workspace's file.
117
+ const { siteFile, ...shared } = look
118
+ renderers.slides = { ...shared, ...own.params === undefined && siteFile !== undefined ? { siteFile } : {}, ...own, base: `${prefix}${SLIDES_DIR}/`, appBase: base }
119
+ }
110
120
  const settings = compilation.doc.config.presmium ??= {}
111
121
  const web = isRecord(settings['presmium.web']) ? settings['presmium.web'] : {}
112
122
  settings['presmium.web'] = { ...web, webUrl: prefix, ...to.includes('slides') ? { slidesUrl: `${prefix}${SLIDES_DIR}/` } : {} }
@@ -2,6 +2,7 @@ import { existsSync, lstatSync, mkdtempSync, readdirSync, readFileSync, rmdirSyn
2
2
  import { tmpdir } from 'node:os'
3
3
  import { join, relative, resolve, sep } from 'node:path'
4
4
  import type { DocumentFileChange, HistoryRevision, Member, RevertResult, Revision, RevisionsAnswer, RevisionService, UncommittedFile } from '@lincyaw/kernel'
5
+ import { LOCAL_AUTHOR } from '@lincyaw/kernel'
5
6
  import { leavesRoot } from '../domain/paths.ts'
6
7
  import { commitMessage, memberAddress, originOf } from '../domain/commit-message.ts'
7
8
  import type { CommitOrigin } from '../domain/commit-message.ts'
@@ -208,14 +209,16 @@ export class Revisions implements RevisionService {
208
209
 
209
210
  /** Commits the paths; the caller holds the git lock (`Git.exclusive`). */
210
211
  async commitWhileLocked(commit: LockedCommit): Promise<Revision | undefined> {
211
- const { summary, body, origin } = commit
212
+ const { summary, body } = commit
212
213
  const unique = [...new Set(commit.paths.map(path => path.replace(/^\.?\/+|\/+$/g, '')).filter(path => path && !leavesRoot(path)))]
213
214
  if (unique.length === 0) return undefined
214
215
  await this.#git.output(['add', '-A', '--', ...unique], { GIT_LITERAL_PATHSPECS: '1' })
215
216
  const staged = (await this.#git.output(['diff', '--cached', '--name-only', '--', ...unique], { GIT_LITERAL_PATHSPECS: '1' })).trim()
216
217
  if (!staged) return undefined
218
+ const member = await this.#author(commit.origin.member)
219
+ const origin = { ...commit.origin, ...member ? { member } : {} }
217
220
  const message = withTrailers(commitMessage(summary, body, origin, commit.revert), commit.trailers ?? [])
218
- await this.#git.output([...await this.#identity(), 'commit', '-q', '--no-verify', '-m', message, ...this.#author(origin.member), '--', ...unique], { GIT_LITERAL_PATHSPECS: '1' })
221
+ await this.#git.output([...await this.#identity(), 'commit', '-q', '--no-verify', '-m', message, ...member ? [`--author=${memberAddress(member)}`] : [], '--', ...unique], { GIT_LITERAL_PATHSPECS: '1' })
219
222
  return this.#revision('HEAD')
220
223
  }
221
224
 
@@ -545,8 +548,15 @@ export class Revisions implements RevisionService {
545
548
  return entry && revision(entry)
546
549
  }
547
550
 
548
- #author(member: Member | undefined): string[] {
549
- return member ? [`--author=${memberAddress(member)}`] : []
551
+ /**
552
+ * The member a commit names as its author. The local author (the one person a local service serves) is the
553
+ * repository's configured git user when git has one, so that their saves are theirs; members of a shared service
554
+ * have their own name and email.
555
+ */
556
+ async #author(member: Member | undefined): Promise<Member | undefined> {
557
+ if (!member || member.email || member.id !== LOCAL_AUTHOR.id || member.name !== LOCAL_AUTHOR.name) return member
558
+ const [name, email] = await Promise.all([this.#git.tryOutput(['config', 'user.name']), this.#git.tryOutput(['config', 'user.email'])])
559
+ return name.ok && email.ok && name.output.trim() && email.output.trim() ? { ...member, name: name.output.trim(), email: email.output.trim() } : member
550
560
  }
551
561
 
552
562
  async #identity(): Promise<string[]> {