@lincyaw/addon-exec-local 1.0.0-rc.12 → 1.0.0-rc.120

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Running code in a local container built from the repository's devcontainer definition, and exporting the environment.
4
4
 
5
- Part of [Presmium](https://github.com/Lincyaw/presmium), which compiles canonical lecture.json teaching documents into web pages, slides, Jupyter notebooks and narrated playback.
5
+ Part of [Presmium](https://github.com/Lincyaw/presmium), which compiles canonical index.pmd teaching documents into web pages, slides, Jupyter notebooks and narrated playback.
6
6
 
7
7
  ## Install
8
8
 
@@ -10,7 +10,7 @@ Part of [Presmium](https://github.com/Lincyaw/presmium), which compiles canonica
10
10
  pnpm add -D @lincyaw/addon-exec-local
11
11
  ```
12
12
 
13
- Add this package to `metadata.plugins` in the document's `lecture.json`.
13
+ Add this package to `metadata.plugins` in the document's `index.pmd`.
14
14
 
15
15
  It is a Presmium plugin: its components work on the web page and in the slides. It needs `@lincyaw/cli` and the renderers in the same project, and declares the Presmium packages it shares with them as peer dependencies (Presmium 1.x).
16
16
 
@@ -23,7 +23,7 @@ It needs Docker on the machine that builds or presents.
23
23
 
24
24
  ## Documentation
25
25
 
26
- - [Author guide](https://github.com/Lincyaw/presmium/blob/main/site/guide/locales/en/lecture.json) (Chinese: `site/guide/lecture.json`)
26
+ - [Author guide](https://github.com/Lincyaw/presmium/blob/main/site/guide/locales/en/index.pmd) (Chinese: `site/guide/index.pmd`)
27
27
  - [Document contract](https://github.com/Lincyaw/presmium/blob/main/.agents/skills/presmium-author/references/document.md): normalized entities, parameters, states and shared validation
28
28
 
29
29
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/addon-exec-local",
3
- "version": "1.0.0-rc.12",
3
+ "version": "1.0.0-rc.120",
4
4
  "description": "Presmium plugin: run code in a local container from the repository's devcontainer definition, and export the environment",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,14 +37,14 @@
37
37
  },
38
38
  "peerDependencies": {
39
39
  "react": "^18.3.1",
40
- "@lincyaw/host": "^1.0.0-rc.12",
41
- "@lincyaw/kernel": "^1.0.0-rc.12"
40
+ "@lincyaw/host": "^1.0.0-rc.120",
41
+ "@lincyaw/kernel": "^1.0.0-rc.120"
42
42
  },
43
43
  "devDependencies": {
44
44
  "react": "18.3.1",
45
45
  "@types/react": "18.3.28",
46
- "@lincyaw/cli": "1.0.0-rc.12",
47
- "@lincyaw/host": "1.0.0-rc.12",
48
- "@lincyaw/kernel": "1.0.0-rc.12"
46
+ "@lincyaw/cli": "1.0.0-rc.120",
47
+ "@lincyaw/host": "1.0.0-rc.120",
48
+ "@lincyaw/kernel": "1.0.0-rc.120"
49
49
  }
50
50
  }
@@ -1,46 +1,13 @@
1
- import { dirname, relative, resolve, sep } from 'node:path'
1
+ import { relative, resolve, sep } from 'node:path'
2
2
  import { componentCode, docBlocks } from '@lincyaw/kernel'
3
- import type { CodeNode, ComponentNode, DirectiveSpec, Executor, IRBlock, IRPass } from '@lincyaw/kernel'
4
- import { EXEC_LOCAL_ID, execLocalConfig, workspacePath } from '../domain/index.ts'
3
+ import type { ComponentNode, Executor, IRBlock, IRPass } from '@lincyaw/kernel'
4
+ import { EXEC_LOCAL_ID, execLocalConfig } from '../domain/index.ts'
5
5
  import type { ContainerExecutor } from './container.ts'
6
6
  import { createContainerExecutor } from './container.ts'
7
7
  import { findDefinition } from './devcontainer.ts'
8
8
  import { inLanguage, text } from './messages.ts'
9
9
  import { replicateArchive } from './replicate.ts'
10
10
 
11
- /** The `:workspace:` each {local-env} names, resolved, for the workspace pass of the same compile. */
12
- const requestedWorkspaces = new WeakMap<ComponentNode, string>()
13
-
14
- export const localEnvDirective: DirectiveSpec = {
15
- name: 'local-env',
16
- arg: true,
17
- body: true,
18
- options: { file: 'string', workspace: 'string' },
19
- toIR(input, ctx) {
20
- const lang = input.arg?.trim() || 'python'
21
- let file: string
22
- try {
23
- file = workspacePath(String(input.options.file ?? ''))
24
- }
25
- catch {
26
- const message = '{local-env} needs :file:, the path of the snippet inside the workspace'
27
- ctx.report({ checkId: 'presmium.execLocal.syntax', severity: 'error', message })
28
- return { node: { type: 'markdown', mdast: ctx.parse(`> ${message}`) } }
29
- }
30
- const code: CodeNode = { type: 'code', lang, value: input.body.replace(/\n+$/, '') }
31
- const node: ComponentNode = {
32
- type: 'component',
33
- plugin: EXEC_LOCAL_ID,
34
- name: 'PmLocalEnv',
35
- props: { file, lang, code: code.value },
36
- children: [{ id: 'source', role: 'visual', at: 0, source: ctx.source, node: code }],
37
- fallback: { type: 'root', children: [{ type: 'code', lang, value: code.value }] },
38
- }
39
- if (typeof input.options.workspace === 'string') requestedWorkspaces.set(node, resolve(dirname(ctx.file), input.options.workspace))
40
- return { node }
41
- },
42
- }
43
-
44
11
  const deckContainers = new Map<string, ContainerExecutor>()
45
12
 
46
13
  /** Each deck runs in its own workspace: the deck's container executor takes the place of the plugin's in the executors of this compile. */
@@ -61,15 +28,12 @@ export function localEnvPass(pluginContainer: Executor): IRPass {
61
28
  const config = execLocalConfig(ctx.config)
62
29
  const workspace = config.workspace !== undefined
63
30
  ? resolve(ctx.deckDir, config.workspace)
64
- : envs.map(env => requestedWorkspaces.get(env.node)).find(dir => dir !== undefined) ?? ctx.workspaceRoot
31
+ : ctx.workspaceRoot
65
32
  bindDeckContainer(ctx.deckDir, ctx.executors, pluginContainer).bind(workspace, config)
66
33
  const shared = relative(ctx.deckDir, workspace).split(sep).join('/') || '.'
67
34
  doc.config.presmium = { ...doc.config.presmium, [EXEC_LOCAL_ID]: { ...ctx.config, workspace: shared } }
68
- const named = (dir: string) => relative(ctx.deckDir, dir).split(sep).join('/') || '.'
69
35
 
70
36
  for (const { node, source, stepStates } of envs) {
71
- const dir = requestedWorkspaces.get(node) ?? workspace
72
- const at = { file: source.file, line: source.line }
73
37
  const code = componentCode(node)
74
38
  if (!code || node.children?.filter(child => child.node.type === 'code').length !== 1) {
75
39
  ctx.report({ checkId: EXEC_LOCAL_ID, severity: 'error', message: inLanguage(ctx.lang, () => text().codeChild), source })
@@ -82,29 +46,20 @@ export function localEnvPass(pluginContainer: Executor): IRPass {
82
46
  for (const state of stepStates ?? []) if (state.parameters) {
83
47
  for (const key of ['code', 'lang', 'archive', 'devcontainer']) delete state.parameters[key]
84
48
  }
85
- if (dir !== workspace) {
86
- ctx.report({
87
- checkId: 'presmium.execLocal.workspace',
88
- severity: 'error',
89
- message: `{local-env} names the workspace ${named(dir)}, but the deck's workspace is ${named(workspace)}: the snippet would run in ${named(workspace)}`,
90
- hint: 'give every {local-env} of the deck the same :workspace:, or set presmium.execLocal.workspace',
91
- source: at,
92
- })
93
- }
94
- const definition = findDefinition(dir)
49
+ const definition = findDefinition(workspace)
95
50
  if (!definition) {
96
51
  ctx.report({
97
52
  checkId: 'presmium.execLocal.devcontainer',
98
53
  severity: 'warning',
99
- message: `no devcontainer definition in ${named(dir)}; the snippet cannot be run in a container or exported`,
100
- source: at,
54
+ message: `no devcontainer definition in ${shared}; the snippet cannot be run in a container or exported`,
55
+ source,
101
56
  })
102
57
  continue
103
58
  }
104
59
  const file = String(node.props.file)
105
60
  const request = { file, content: `${code.value}\n`, lang: String(node.props.lang) }
106
- const { zip } = inLanguage(ctx.lang, () => replicateArchive(dir, definition, request))
107
- node.props.devcontainer = relative(dir, definition).split(sep).join('/')
61
+ const { zip } = inLanguage(ctx.lang, () => replicateArchive(workspace, definition, request))
62
+ node.props.devcontainer = relative(workspace, definition).split(sep).join('/')
108
63
  node.props.archive = Buffer.from(zip).toString('base64')
109
64
  }
110
65
  },
@@ -6,7 +6,7 @@ import { DEVCONTAINER_KIND, EXEC_LOCAL_ID } from '../domain/index.ts'
6
6
  import { createContainerExecutor } from './container.ts'
7
7
  import { findDefinition } from './devcontainer.ts'
8
8
  import { dockerAvailable } from './docker.ts'
9
- import { localEnvDirective, localEnvPass } from './local-env.ts'
9
+ import { localEnvPass } from './local-env.ts'
10
10
  import { localEnvRoutes } from './server.ts'
11
11
 
12
12
  const { version } = createRequire(import.meta.url)('../../package.json') as { version: string }
@@ -33,7 +33,6 @@ const plugin: PresmiumNodePlugin = {
33
33
  id: EXEC_LOCAL_ID,
34
34
  version,
35
35
  kernel: '^1.0.0',
36
- directives: [localEnvDirective],
37
36
  passes: [localEnvPass(container)],
38
37
  executors: [container],
39
38
  environments: { [DEVCONTAINER_KIND]: devcontainer },