dsh-office-kit 0.3.1 → 0.3.2

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/dist/index.js CHANGED
@@ -280,18 +280,13 @@ function statusOf(python) {
280
280
  remedy: runtimeRemedy()
281
281
  };
282
282
  }
283
- /** Inspect every candidate; return the first interpreter that proves it has all dependencies. */
284
- async function inspectRuntime(configFile = officePaths().configFile) {
285
- let compatible;
286
- let last;
287
- for (const candidate of [...candidates(configFile), ...await launcherInterpreters()]) for (const expanded of await expandLauncher(candidate)) {
288
- if (expanded !== candidate && !isFile(expanded)) continue;
289
- const inspection = await inspectPython(expanded);
290
- if (inspection.compatible && inspection.missing.length === 0) return statusOf(inspection);
291
- if (inspection.compatible && compatible == null) compatible = inspection;
292
- last = inspection;
293
- }
283
+ /** Pick the best interpreter: all dependencies first, then compatible-only, else none. */
284
+ function selectRuntime(inspections) {
285
+ const ready = inspections.find((inspection) => inspection.compatible && inspection.missing.length === 0);
286
+ if (ready != null) return statusOf(ready);
287
+ const compatible = inspections.find((inspection) => inspection.compatible);
294
288
  if (compatible != null) return statusOf(compatible);
289
+ const last = inspections[inspections.length - 1];
295
290
  return {
296
291
  state: "no-interpreter",
297
292
  packages: [],
@@ -300,6 +295,17 @@ async function inspectRuntime(configFile = officePaths().configFile) {
300
295
  ...last?.error == null ? {} : { error: last.error }
301
296
  };
302
297
  }
298
+ /** Inspect candidates in priority order; the first fully-provisioned interpreter wins. */
299
+ async function inspectRuntime(configFile = officePaths().configFile) {
300
+ const seen = [];
301
+ for (const candidate of [...candidates(configFile), ...await launcherInterpreters()]) for (const expanded of await expandLauncher(candidate)) {
302
+ if (expanded !== candidate && !isFile(expanded)) continue;
303
+ const inspection = await inspectPython(expanded);
304
+ seen.push(inspection);
305
+ if (inspection.compatible && inspection.missing.length === 0) return selectRuntime(seen);
306
+ }
307
+ return selectRuntime(seen);
308
+ }
303
309
  /** Run postinstall.mjs as a child process; resolve with an error summary or undefined. */
304
310
  function runPostinstall() {
305
311
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-office-kit",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "description": "Office documents, PDF, presentations, and spreadsheets for DeepSeek Harness",
6
6
  "author": "Hairy",
7
7
  "license": "MIT",
package/postinstall.mjs CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  import { spawnSync } from 'node:child_process'
19
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
19
+ import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
20
20
  import { homedir, tmpdir } from 'node:os'
21
21
  import { dirname, join } from 'node:path'
22
22
  import process from 'node:process'
@@ -25,15 +25,15 @@ import { fileURLToPath } from 'node:url'
25
25
  const PACKAGE_ROOT = dirname(fileURLToPath(import.meta.url))
26
26
  const IS_WINDOWS = process.platform === 'win32'
27
27
  const PYTHON_VERSION = '3.12.10'
28
- const RUNTIME_DIR = join(homedir(), '.dsh', 'office', 'runtime')
29
- const VENV_DIR = join(RUNTIME_DIR, 'venv')
28
+ export const RUNTIME_DIR = join(homedir(), '.dsh', 'office', 'runtime')
29
+ export const VENV_DIR = join(RUNTIME_DIR, 'venv')
30
30
  const VENV_PYTHON = join(VENV_DIR, IS_WINDOWS ? 'Scripts/python.exe' : 'bin/python')
31
31
  const LEGACY_DATA_DIR = IS_WINDOWS
32
32
  ? join(process.env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local'), 'dsh-office-kit')
33
33
  : process.platform === 'darwin'
34
34
  ? join(homedir(), 'Library', 'Application Support', 'dsh-office-kit')
35
35
  : join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), 'dsh-office-kit')
36
- const LEGACY_VENV_DIR = join(LEGACY_DATA_DIR, 'venv')
36
+ export const LEGACY_VENV_DIR = join(LEGACY_DATA_DIR, 'venv')
37
37
  const LEGACY_VENV_PYTHON = join(LEGACY_VENV_DIR, IS_WINDOWS ? 'Scripts/python.exe' : 'bin/python')
38
38
  const CONFIG_DIR = join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'dsh-office-kit')
39
39
  const CONFIG_FILE = join(CONFIG_DIR, 'config.json')
@@ -181,6 +181,24 @@ function verifySignature(file) {
181
181
  }
182
182
  }
183
183
 
184
+ /**
185
+ * Installer switches. PATH is appended by the installer itself (`AppendPath=1`),
186
+ * the install location stays the per-user default (no `TargetDir`), and the
187
+ * `py` launcher is kept so `py -3.12` works.
188
+ */
189
+ export function installerArguments() {
190
+ return [
191
+ '/quiet',
192
+ 'InstallAllUsers=0',
193
+ 'AppendPath=1',
194
+ 'CompileAll=0',
195
+ 'Include_test=0',
196
+ 'Include_doc=0',
197
+ 'Include_pip=1',
198
+ 'SimpleInstall=1',
199
+ ]
200
+ }
201
+
184
202
  function installPython() {
185
203
  if (!IS_WINDOWS) {
186
204
  return false
@@ -191,17 +209,7 @@ function installPython() {
191
209
  download(url, installer)
192
210
  verifySignature(installer)
193
211
  log(`installing Python ${PYTHON_VERSION} into the installer default per-user location`)
194
- const args = [
195
- '/quiet',
196
- 'InstallAllUsers=0',
197
- 'AppendPath=1',
198
- 'CompileAll=0',
199
- 'Include_test=0',
200
- 'Include_doc=0',
201
- 'Include_pip=1',
202
- 'SimpleInstall=1',
203
- ]
204
- const result = spawnSync(installer, args, { stdio: 'inherit', timeout: 15 * 60 * 1000 })
212
+ const result = spawnSync(installer, installerArguments(), { stdio: 'inherit', timeout: 15 * 60 * 1000 })
205
213
  rmSync(installer, { force: true })
206
214
  if (result.status !== 0) {
207
215
  throw new Error(`Python installer exited with status ${result.status}`)
@@ -368,6 +376,21 @@ function readPackageVersion() {
368
376
  }
369
377
  }
370
378
 
371
- const started = Date.now()
372
- main()
373
- log(`finished in ${((Date.now() - started) / 1000).toFixed(1)}s`)
379
+ function startedFromCli() {
380
+ const entry = process.argv[1]
381
+ if (entry == null) {
382
+ return false
383
+ }
384
+ try {
385
+ return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url))
386
+ }
387
+ catch {
388
+ return false
389
+ }
390
+ }
391
+
392
+ if (startedFromCli()) {
393
+ const started = Date.now()
394
+ main()
395
+ log(`finished in ${((Date.now() - started) / 1000).toFixed(1)}s`)
396
+ }
@@ -594,6 +594,9 @@ def _pdf_font() -> str:
594
594
  r"C:\Windows\Fonts\simsun.ttc",
595
595
  "/System/Library/Fonts/PingFang.ttc",
596
596
  "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
597
+ "/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
598
+ "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",
599
+ "/usr/share/fonts/truetype/arphic/uming.ttc",
597
600
  "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
598
601
  ]
599
602
  for candidate in candidates:
@@ -603,7 +606,13 @@ def _pdf_font() -> str:
603
606
  return "OfficeCJK"
604
607
  except Exception:
605
608
  continue
606
- return "Helvetica"
609
+ try:
610
+ from reportlab.pdfbase.cidfonts import UnicodeCIDFont
611
+
612
+ pdfmetrics.registerFont(UnicodeCIDFont("STSong-Light"))
613
+ return "STSong-Light"
614
+ except Exception:
615
+ return "Helvetica"
607
616
 
608
617
 
609
618
  def _pdf_flowables(blocks: Iterable[dict[str, Any]], font: str, counters: dict[str, int]):