@beltype/cli 0.1.8 → 0.1.9

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
@@ -77,6 +77,8 @@ npx playwright-core@1.63.0 install chromium-headless-shell
77
77
 
78
78
  The companions come from npm, pinned exactly: `@beltype/cicero` 0.1.10, `@beltype/caster` 0.2.5 and `@beltype/common` 0.1.2.
79
79
 
80
+ The package is a binary, not a module: it has no `exports` map and ships no typings, so `import '@beltype/cli'` is not a supported road until a consumer asks for one.
81
+
80
82
  ## Working on it
81
83
 
82
84
  ```bash
package/dist/src/main.js CHANGED
@@ -78,7 +78,7 @@ async function main(argv) {
78
78
  const output = values.output ?? input.replace(/\.html?$/i, '') + '.pdf';
79
79
  const created = createdFromEnv();
80
80
  const result = await print(input, output, { given, sandbox: !values['no-sandbox'], ...(values.trace !== undefined ? { trace: values.trace } : {}), ...(created ? { created } : {}) });
81
- console.log(`${result.output}: ${result.pages} pages, ${result.words} words, ${(result.ms / 1000).toFixed(1)} s`);
81
+ console.log(`${result.output}: ${result.pages} pages, ${result.words} words, ${(result.ms / 1000).toFixed(1)} s${result.standard ? `, ${result.standard}` : ''}`);
82
82
  if (result.check) {
83
83
  for (const line of checkLines(result.check))
84
84
  console.log(line);
package/dist/src/print.js CHANGED
@@ -15,7 +15,7 @@ import { chromium } from 'playwright-core';
15
15
  import { ciceroFlags } from '@beltype/cicero/flags';
16
16
  import { cliFlags, tableOf } from './flags.js';
17
17
  import { checkPages, requireMupdf } from './check.js';
18
- import { ARGS, VIEWPORT, documentAssets, servedHtml, routeCompanions, routeDocument, printOnPage, refusal, deferralLine } from './run.js';
18
+ import { ARGS, VIEWPORT, documentAssets, servedHtml, routeCompanions, routeDocument, printOnPage, refusal, deferralLine, standardOf } from './run.js';
19
19
  export { spliceHead } from './run.js';
20
20
  const round = (ms) => Math.round(ms * 10) / 10;
21
21
  /**
@@ -41,6 +41,8 @@ export async function print(input, output, options = {}) {
41
41
  let step = 'launch';
42
42
  let chromiumVersion = 'unknown';
43
43
  try {
44
+ // A run that refuses writes no file, so an earlier print at this path must not stand for it.
45
+ fs.rmSync(output, { force: true });
44
46
  if (flags.beltype.check)
45
47
  await requireMupdf();
46
48
  const html = fs.readFileSync(input, 'utf8');
@@ -77,7 +79,7 @@ export async function print(input, output, options = {}) {
77
79
  }
78
80
  else
79
81
  lap('print');
80
- const { bytes, pages, words, screens, confessions } = printed;
82
+ const { bytes, pages, words, screens, confessions, conformance } = printed;
81
83
  step = 'close';
82
84
  await browser.close();
83
85
  lap('close');
@@ -93,7 +95,7 @@ export async function print(input, output, options = {}) {
93
95
  check = await checkPages(screens, bytes, path.resolve(output).replace(/\.pdf$/i, '') + '.check', flags.beltype.printer, confessions);
94
96
  lap('check');
95
97
  }
96
- return { output, pages, words, deferred: printed.deferred.length, ms: performance.now() - started, ...(check ? { check } : {}) };
98
+ return { output, pages, words, deferred: printed.deferred.length, standard: standardOf(conformance), ms: performance.now() - started, ...(check ? { check } : {}) };
97
99
  }
98
100
  finally {
99
101
  await browser.close();
package/dist/src/run.js CHANGED
@@ -169,6 +169,12 @@ function fromAssets(assets, assetPath) {
169
169
  function within(dir, rel) {
170
170
  const file = path.resolve(dir, rel);
171
171
  const inside = path.relative(dir, file);
172
- return !inside.startsWith('..') && !path.isAbsolute(inside) && isFile(file) ? file : null;
172
+ if (inside.startsWith('..') || path.isAbsolute(inside) || !isFile(file))
173
+ return null;
174
+ // A link is followed to where it lands, and only a landing inside the folder is served.
175
+ const landed = path.relative(fs.realpathSync(dir), fs.realpathSync(file));
176
+ return !landed.startsWith('..') && !path.isAbsolute(landed) ? file : null;
173
177
  }
178
+ /** What a print's file claims, as Caster's report says it: `pdf-2.0; pdf-ua-2`, or `pdf-2.0` alone where the claim was not asked for or was withdrawn; `null` where Caster never saw the file (`--printer chromium`). */
179
+ export const standardOf = (conformance) => conformance === null ? null : conformance === 'pdfua2' ? 'pdf-2.0; pdf-ua-2' : 'pdf-2.0';
174
180
  const isFile = (file) => fs.existsSync(file) && fs.statSync(file).isFile();
package/dist/src/serve.js CHANGED
@@ -22,7 +22,7 @@ import { chromium } from 'playwright-core';
22
22
  import { ciceroFlags } from '@beltype/cicero/flags';
23
23
  import { BuildError, ValidationError, FlagError } from '@beltype/common/errors';
24
24
  import { cliFlags, createdFromEnv, parseFlagArgs } from './flags.js';
25
- import { ARGS, ORIGIN, VIEWPORT, documentAssets, servedHtml, routeCompanions, routeDocument, printOnPage, cutAndPrint, refusal, deferralLine } from './run.js';
25
+ import { ARGS, ORIGIN, VIEWPORT, documentAssets, servedHtml, routeCompanions, routeDocument, printOnPage, cutAndPrint, refusal, deferralLine, standardOf } from './run.js';
26
26
  import { keepMergeInPage, reseatInPage, seatMergeInPage } from './in-page.js';
27
27
  const HOLDER_PATH = '/_beltype/holder.html';
28
28
  const HOLDER = `<!doctype html><html><head><meta charset="utf-8"><title>holder</title></head><body><script type="module">
@@ -507,4 +507,7 @@ function instant(value) {
507
507
  return date.toISOString();
508
508
  }
509
509
  /** What the file claims, as Caster's report says it: `x-beltype-standard: pdf-2.0; pdf-ua-2`, or `pdf-2.0` alone where the claim was not asked for or was withdrawn. A print under `beltype.printer=chromium` is Chromium's own file, which Caster never saw, and carries no header. */
510
- export const standardHeader = (conformance) => conformance === null ? {} : { 'x-beltype-standard': conformance === 'pdfua2' ? 'pdf-2.0; pdf-ua-2' : 'pdf-2.0' };
510
+ export const standardHeader = (conformance) => {
511
+ const standard = standardOf(conformance);
512
+ return standard === null ? {} : { 'x-beltype-standard': standard };
513
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beltype/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "beltype, the command line: a finished HTML document printed to PDF by Cicero and Caster in Chromium's headless shell.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@beltype/caster": "0.2.5",
38
- "@beltype/cicero": "0.1.10",
38
+ "@beltype/cicero": "0.1.11",
39
39
  "@beltype/common": "0.1.2",
40
40
  "playwright-core": "1.63.0"
41
41
  },