-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.mjs
More file actions
52 lines (49 loc) · 2.43 KB
/
Copy pathbootstrap.mjs
File metadata and controls
52 lines (49 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Shared bootstrap for every example's run.mjs.
*
* Provides inkyExample(), a tiny helper that gives each example a clean
* output directory under dist/ — the same shape as the PHP suite's
* bootstrap.php / inky_example().
*
* Runtime note — this port's own "Task 1" (see SUITE.md "Porting notes for
* Stage C" #2, and "Runtime requirements" in the same file for the PHP
* original this mirrors):
*
* (a) Does the local path-dependency mechanism break the binding's lookup?
* This repo has no local path dependency at all — there is no
* `npm link`, no workspace, no package installed from a local path.
* lib/wasm.mjs and lib/cli.mjs instead resolve `../inky/bindings/node`
* and `../inky/target/release/inky` (or a `cargo run` fallback) via a
* plain relative `require`/path.resolve() from this repo's own file
* location, on the same "checked out as a sibling of inky/" assumption
* the PHP suite documents. There is no symlink in the path (unlike
* Composer's path-repo symlink, which PHP's __DIR__ resolution turned
* out to see through transparently) — a plain relative path needs no
* such verification. Confirmed empirically while building this port:
* `require()` of the prebuilt bindings/node/inky.js and its sibling
* inky_bg.wasm works unmodified from outside that directory.
* (b) Does npm's default dependency-resolution policy need an equivalent
* to Composer's `minimum-stability: dev` / `prefer-stable: true`? No —
* npm has no stability-channel concept to configure here; the only
* third-party dependency is `nunjucks` (a normal published, stable
* npm package, used only by example 10), and the Inky binding itself
* is not an npm dependency at all (no package.json entry), just a
* relative filesystem path to the sibling `inky` checkout. Nothing
* analogous to composer.json's minimum-stability fix was needed.
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
export const ROOT = path.dirname(fileURLToPath(import.meta.url));
/**
* Return the dist output directory for an example, creating it if needed.
*
* Every run.mjs starts with:
* import { inkyExample } from "../../bootstrap.mjs";
* const dist = inkyExample("01-quickstart");
*/
export function inkyExample(name) {
const dir = path.join(ROOT, "dist", name);
fs.mkdirSync(dir, { recursive: true });
return dir;
}