gutterpress 0.11.21 → 0.11.22-alpha.1

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.
Files changed (51) hide show
  1. package/README.md +11 -0
  2. package/dist/api/index.d.ts +5 -1
  3. package/dist/api/index.js +67 -46
  4. package/dist/{build-0neyk5h6.js → build-se85j9ec.js} +16 -10
  5. package/dist/cli-5553w972.js +75 -0
  6. package/dist/{cli-b57adna7.js → cli-8hccw62p.js} +9 -201
  7. package/dist/cli-9vy4b6ec.js +2089 -0
  8. package/dist/{cli-sqkccnm7.js → cli-d8xjns66.js} +1 -102
  9. package/dist/{cli-j0drzb6f.js → cli-fbwqv7p4.js} +720 -5428
  10. package/dist/cli-gc9av5hs.js +103 -0
  11. package/dist/cli-gmm3bdeq.js +196 -0
  12. package/dist/cli-h3phdstf.js +200 -0
  13. package/dist/{index-qf7y4d85.js → cli-habkc5ng.js} +12 -258
  14. package/dist/cli-pfrg1r9x.js +3073 -0
  15. package/dist/{cli-j79451n6.js → cli-yejbb9f8.js} +5 -76
  16. package/dist/cli.js +15 -13
  17. package/dist/{doctor-fptq8tvn.js → doctor-bv2t82zd.js} +7 -4
  18. package/dist/{engine-x07q927h.js → engine-h4ehmrvf.js} +4 -3
  19. package/dist/{engine-0b8bt05n.js → engine-qwkyhrej.js} +3 -2
  20. package/dist/{ext-gp624t5c.js → ext-a8ndp142.js} +21 -14
  21. package/dist/extension-restore-926mv2qk.js +16 -0
  22. package/dist/extension-restore-q1f7njec.js +20 -0
  23. package/dist/index-38e18a7j.js +3244 -0
  24. package/dist/{index-mr72vt8n.js → index-5h9a38jn.js} +1 -213
  25. package/dist/{cli-5qr3z0qa.js → index-93pqkvty.js} +63 -207
  26. package/dist/index-dhknsvfz.js +213 -0
  27. package/dist/index-dm7hx46j.js +2208 -0
  28. package/dist/{index-t7r8g75c.js → index-gmfh6n05.js} +4 -2
  29. package/dist/index-r7jcsk6h.js +200 -0
  30. package/dist/{index-mr7zs8mv.js → index-tkjvs1gf.js} +4774 -9354
  31. package/dist/index.js +70 -49
  32. package/dist/lib/extension-manifest.d.ts +22 -1
  33. package/dist/lib/markdown/plugins.d.ts +20 -0
  34. package/dist/lib/markdown/two-versions.d.ts +32 -0
  35. package/dist/lib/publish/plugin-provider.d.ts +16 -0
  36. package/dist/lib/publish/run-publish.d.ts +13 -5
  37. package/dist/lib/publish/types.d.ts +34 -2
  38. package/dist/lib/text-diff.d.ts +43 -0
  39. package/dist/lib/two-versions-markers.d.ts +26 -0
  40. package/dist/lib/version-changes.d.ts +87 -0
  41. package/dist/{new-dre6aw05.js → new-nadp2hvb.js} +23 -16
  42. package/dist/plugins-gy4q9vaa.js +26 -0
  43. package/dist/plugins-yeh4shd7.js +24 -0
  44. package/dist/{preflight-1k1zkg1p.js → preflight-c6q25xqa.js} +18 -11
  45. package/dist/{preview-dtrksvxf.js → preview-y8chv4cb.js} +19 -13
  46. package/dist/{publish-g1ytnrmr.js → publish-3qwvxsxa.js} +40 -23
  47. package/dist/render.js +120 -0
  48. package/dist/{source-provider-pzmz0br9.js → source-provider-2r74a7wp.js} +2 -1
  49. package/dist/{source-provider-qbthnmqw.js → source-provider-qbfknhyy.js} +2 -1
  50. package/dist/{validate-yrrq8639.js → validate-w108kk87.js} +16 -10
  51. package/package.json +1 -1
@@ -0,0 +1,103 @@
1
+ // package.json
2
+ var package_default = {
3
+ name: "gutterpress",
4
+ version: "0.11.22-alpha.1",
5
+ description: "Markdown-to-PDF converter for professional print layout using a native Chromium print engine and Ghostscript.",
6
+ author: "itlackey",
7
+ license: "MPL-2.0",
8
+ keywords: [
9
+ "markdown",
10
+ "pdf",
11
+ "print",
12
+ "ghostscript",
13
+ "book",
14
+ "publishing",
15
+ "zine"
16
+ ],
17
+ repository: {
18
+ type: "git",
19
+ url: "https://github.com/dimm-city/gutterpress.git"
20
+ },
21
+ homepage: "https://github.com/dimm-city/gutterpress#readme",
22
+ bugs: {
23
+ url: "https://github.com/dimm-city/gutterpress/issues"
24
+ },
25
+ type: "module",
26
+ main: "./dist/index.js",
27
+ types: "./dist/index.d.ts",
28
+ bin: {
29
+ gutterpress: "./dist/cli.js"
30
+ },
31
+ exports: {
32
+ ".": {
33
+ types: "./dist/index.d.ts",
34
+ default: "./dist/index.js"
35
+ },
36
+ "./api": {
37
+ types: "./dist/api/index.d.ts",
38
+ default: "./dist/api/index.js"
39
+ },
40
+ "./render": {
41
+ types: "./dist/render.d.ts",
42
+ default: "./dist/render.js"
43
+ }
44
+ },
45
+ files: [
46
+ "dist/",
47
+ "README.md",
48
+ "LICENSE"
49
+ ],
50
+ scripts: {
51
+ "build:library": "bun scripts/build-engine-bundles.mjs && rimraf dist && bun build src/index.ts src/api/index.ts --target=node --packages=external --splitting --outdir=dist && bun build src/render.ts --target=node --packages=external --outdir=dist && node scripts/check-render-pure.mjs && tsc -p tsconfig.build.json",
52
+ build: "bun run build:library && bun build src/cli.ts --target=node --packages=external --splitting --outdir=dist",
53
+ prepublishOnly: "bun run build",
54
+ test: "bun test",
55
+ typecheck: "tsc --noEmit",
56
+ "typecheck:engine-browser": "tsc --noEmit -p src/engine/browser.tsconfig.json",
57
+ "parity:gate": "bun scripts/native-parity-gate.ts"
58
+ },
59
+ engines: {
60
+ bun: ">=1.0.0",
61
+ node: ">=22.0.0"
62
+ },
63
+ dependencies: {
64
+ chokidar: "^5.0.0",
65
+ citty: "^0.2.0",
66
+ diff3: "0.0.3",
67
+ fflate: "0.8.3",
68
+ glob: "^13.0.0",
69
+ htmlhint: "^1.9.2",
70
+ ignore: "^5.3.2",
71
+ "isomorphic-git": "^1.38.4",
72
+ "markdown-it": "^14.3.2",
73
+ "markdown-it-abbr": "^2.0.0",
74
+ "markdown-it-attrs": "^4.3.0",
75
+ "markdown-it-deflist": "^3.0.1",
76
+ "markdown-it-footnote": "^4.0.0",
77
+ "markdown-it-mark": "^4.0.0",
78
+ "markdown-it-source-map": "^0.1.1",
79
+ "markdown-it-sub": "^2.0.0",
80
+ "markdown-it-sup": "^2.0.0",
81
+ markdownlint: "^0.40.0",
82
+ "pdf-lib": "^1.17.1",
83
+ postcss: "^8.5.18",
84
+ "resolve.exports": "2.0.3",
85
+ semver: "7.8.0",
86
+ tar: "7.5.22",
87
+ unpdf: "^1.6.2",
88
+ ws: "^8.21.0",
89
+ yaml: "^2.8.2"
90
+ },
91
+ devDependencies: {
92
+ "@types/bun": "1.3.14",
93
+ "@types/markdown-it": "^14.1.2",
94
+ "@types/node": "^22.0.0",
95
+ "@types/semver": "^7.7.1",
96
+ "@types/ws": "^8.5.13",
97
+ playwright: "^1.60.0",
98
+ rimraf: "^6.0.0",
99
+ typescript: "^5"
100
+ }
101
+ };
102
+
103
+ export { package_default };
@@ -0,0 +1,196 @@
1
+ // src/lib/embedded-assets.ts
2
+ import { existsSync } from "node:fs";
3
+ import { mkdtemp, mkdir, writeFile, readFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ // src/assets/favicon.ico
9
+ var favicon_default = "./favicon-272ga6y0.ico";
10
+
11
+ // src/assets/manifest.schema.json
12
+ var manifest_schema_default = "./manifest.schema-n292sb77.json";
13
+
14
+ // src/assets/preview/scripts/preview-interface.js
15
+ var preview_interface_default = "./preview-interface-nnmrxyqm.js";
16
+
17
+ // src/assets/preview/scripts/preview-bridge.js
18
+ var preview_bridge_default = "./preview-bridge-8wjcjec3.js";
19
+
20
+ // src/assets/preview/scripts/preview-shell.js
21
+ var preview_shell_default = "./preview-shell-wk9k3gcd.js";
22
+
23
+ // profiles/CGATS21_CRPC1.icc
24
+ var CGATS21_CRPC1_default = "./CGATS21_CRPC1-g0e3k7kr.icc";
25
+
26
+ // src/assets/engine/gutterpress-viewer.js
27
+ var gutterpress_viewer_default = "./gutterpress-viewer-w7njnkj7.js";
28
+
29
+ // src/assets/engine/gutterpress-agent.js
30
+ var gutterpress_agent_default = "./gutterpress-agent-d29ry3ak.js";
31
+
32
+ // src/assets/templates/book/manifest.yaml
33
+ var manifest_default = "./manifest-n1gh3qw5.yaml";
34
+
35
+ // src/assets/templates/book/chapter-01.md
36
+ var chapter_01_default = "./chapter-01-rkpyvjna.md";
37
+
38
+ // src/assets/templates/zine/manifest.yaml
39
+ var manifest_default2 = "./manifest-n1gh3qw5.yaml";
40
+
41
+ // src/assets/templates/zine/chapter-01.md
42
+ var chapter_01_default2 = "./chapter-01-7jwqg1ct.md";
43
+
44
+ // src/assets/templates/technical/manifest.yaml
45
+ var manifest_default3 = "./manifest-n1gh3qw5.yaml";
46
+
47
+ // src/assets/templates/technical/chapter-01.md
48
+ var chapter_01_default3 = "./chapter-01-6fn9pvd0.md";
49
+
50
+ // src/assets/extension-templates/plugin/package.json
51
+ var package_default = "./package-9rv69pxm.json";
52
+
53
+ // src/assets/extension-templates/plugin/README.md
54
+ var README_default = "./README-vsnsc1b3.md";
55
+
56
+ // src/assets/extension-templates/plugin/plugin.js.tpl
57
+ var plugin_js_default = "./plugin.js-cswq7wvd.tpl";
58
+
59
+ // src/assets/extension-templates/plugin/styles/plugin.css
60
+ var plugin_default = "./plugin-spbcem4j.css";
61
+
62
+ // src/assets/extension-templates/plugin/snippets/term-box.md
63
+ var term_box_default = "./term-box-4y0w7y32.md";
64
+
65
+ // src/assets/extension-templates/plugin/test/fixture.md
66
+ var fixture_default = "./fixture-2qnyqgb5.md";
67
+
68
+ // src/assets/extension-templates/plugin/test/expected.html
69
+ var expected_default = "./expected-ycmacem8.html";
70
+
71
+ // src/assets/extension-templates/plugin/test/plugin.test.js.tpl
72
+ var plugin_test_js_default = "./plugin.test.js-xgxrd8hf.tpl";
73
+
74
+ // src/assets/extension-templates/theme/package.json
75
+ var package_default2 = "./package-aenwjew3.json";
76
+
77
+ // src/assets/extension-templates/theme/README.md
78
+ var README_default2 = "./README-3nj919rm.md";
79
+
80
+ // src/assets/extension-templates/theme/components.yaml
81
+ var components_default = "./components-zzqdpt3m.yaml";
82
+
83
+ // src/assets/extension-templates/theme/snippets/callout.md
84
+ var callout_default = "./callout-hv56m16h.md";
85
+
86
+ // src/assets/extension-templates/theme/styles/tokens.css
87
+ var tokens_default = "./tokens-7984461t.css";
88
+
89
+ // src/assets/extension-templates/theme/styles/base.css
90
+ var base_default = "./base-ypqh9n7f.css";
91
+
92
+ // src/assets/extension-templates/theme/styles/components.css
93
+ var components_default2 = "./components-aam0fe2z.css";
94
+
95
+ // src/assets/extension-templates/theme/styles/page-templates.css
96
+ var page_templates_default = "./page-templates-tx9ryt19.css";
97
+
98
+ // src/assets/extension-templates/theme/styles/page-rules.css
99
+ var page_rules_default = "./page-rules-nsj3aw42.css";
100
+
101
+ // src/assets/extension-templates/theme/styles/book.css
102
+ var book_default = "./book-ted3tzrp.css";
103
+
104
+ // src/assets/themes/clean-book/theme.css
105
+ var theme_default = "./theme-j2bagrfx.css";
106
+
107
+ // src/assets/themes/clean-book/package.json
108
+ var package_default3 = "./package-97gm31sg.json";
109
+
110
+ // src/assets/themes/zine/theme.css
111
+ var theme_default2 = "./theme-h5recz6c.css";
112
+
113
+ // src/assets/themes/zine/package.json
114
+ var package_default4 = "./package-gag6ykwn.json";
115
+
116
+ // src/assets/themes/technical-doc/theme.css
117
+ var theme_default3 = "./theme-nn6d53zy.css";
118
+
119
+ // src/assets/themes/technical-doc/package.json
120
+ var package_default5 = "./package-nrhkwf2m.json";
121
+
122
+ // src/lib/embedded-assets.ts
123
+ var __libdir = dirname(fileURLToPath(import.meta.url));
124
+ var abs = (p) => resolve(__libdir, p);
125
+ var filePath = (v) => v;
126
+ var EMBEDDED_ASSETS = {
127
+ "favicon.ico": abs(favicon_default),
128
+ "manifest.schema.json": abs(filePath(manifest_schema_default)),
129
+ "preview/scripts/preview-interface.js": abs(filePath(preview_interface_default)),
130
+ "preview/scripts/preview-bridge.js": abs(filePath(preview_bridge_default)),
131
+ "preview/scripts/preview-shell.js": abs(filePath(preview_shell_default)),
132
+ "profiles/CGATS21_CRPC1.icc": abs(filePath(CGATS21_CRPC1_default)),
133
+ "engine/gutterpress-viewer.js": abs(filePath(gutterpress_viewer_default)),
134
+ "engine/gutterpress-agent.js": abs(filePath(gutterpress_agent_default)),
135
+ "templates/book/manifest.yaml": abs(filePath(manifest_default)),
136
+ "templates/book/chapter-01.md": abs(filePath(chapter_01_default)),
137
+ "templates/zine/manifest.yaml": abs(filePath(manifest_default2)),
138
+ "templates/zine/chapter-01.md": abs(filePath(chapter_01_default2)),
139
+ "templates/technical/manifest.yaml": abs(filePath(manifest_default3)),
140
+ "templates/technical/chapter-01.md": abs(filePath(chapter_01_default3)),
141
+ "extension-templates/plugin/package.json": abs(filePath(package_default)),
142
+ "extension-templates/plugin/README.md": abs(filePath(README_default)),
143
+ "extension-templates/plugin/plugin.js.tpl": abs(filePath(plugin_js_default)),
144
+ "extension-templates/plugin/styles/plugin.css": abs(filePath(plugin_default)),
145
+ "extension-templates/plugin/snippets/term-box.md": abs(filePath(term_box_default)),
146
+ "extension-templates/plugin/test/fixture.md": abs(filePath(fixture_default)),
147
+ "extension-templates/plugin/test/expected.html": abs(filePath(expected_default)),
148
+ "extension-templates/plugin/test/plugin.test.js.tpl": abs(filePath(plugin_test_js_default)),
149
+ "extension-templates/theme/package.json": abs(filePath(package_default2)),
150
+ "extension-templates/theme/README.md": abs(filePath(README_default2)),
151
+ "extension-templates/theme/components.yaml": abs(filePath(components_default)),
152
+ "extension-templates/theme/snippets/callout.md": abs(filePath(callout_default)),
153
+ "extension-templates/theme/styles/tokens.css": abs(filePath(tokens_default)),
154
+ "extension-templates/theme/styles/base.css": abs(filePath(base_default)),
155
+ "extension-templates/theme/styles/components.css": abs(filePath(components_default2)),
156
+ "extension-templates/theme/styles/page-templates.css": abs(filePath(page_templates_default)),
157
+ "extension-templates/theme/styles/page-rules.css": abs(filePath(page_rules_default)),
158
+ "extension-templates/theme/styles/book.css": abs(filePath(book_default)),
159
+ "themes/clean-book/theme.css": abs(filePath(theme_default)),
160
+ "themes/clean-book/package.json": abs(filePath(package_default3)),
161
+ "themes/zine/theme.css": abs(filePath(theme_default2)),
162
+ "themes/zine/package.json": abs(filePath(package_default4)),
163
+ "themes/technical-doc/theme.css": abs(filePath(theme_default3)),
164
+ "themes/technical-doc/package.json": abs(filePath(package_default5))
165
+ };
166
+ var extractPromise = null;
167
+ async function extractAssets() {
168
+ const root = await mkdtemp(join(tmpdir(), "gutterpress-assets-"));
169
+ for (const [relPath, srcPath] of Object.entries(EMBEDDED_ASSETS)) {
170
+ const dest = join(root, relPath);
171
+ await mkdir(dirname(dest), { recursive: true });
172
+ const bytes = await readFile(srcPath);
173
+ await writeFile(dest, bytes);
174
+ }
175
+ return root;
176
+ }
177
+ var SENTINEL_ASSET = "engine/gutterpress-viewer.js";
178
+ async function getAssetsDir() {
179
+ if (extractPromise) {
180
+ try {
181
+ const root = await extractPromise;
182
+ if (existsSync(join(root, SENTINEL_ASSET))) {
183
+ return root;
184
+ }
185
+ } catch {}
186
+ extractPromise = null;
187
+ }
188
+ extractPromise = extractAssets();
189
+ return extractPromise;
190
+ }
191
+ async function getAssetPath(relPath) {
192
+ const root = await getAssetsDir();
193
+ return join(root, relPath);
194
+ }
195
+
196
+ export { getAssetsDir, getAssetPath };
@@ -0,0 +1,200 @@
1
+ // src/lib/plugin-vendor.ts
2
+ import { lstat, readFile, realpath } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { exports as resolveExports } from "resolve.exports";
5
+ var PLUGINS_DIR = "plugins";
6
+ var VENDORED_NPM_DIR = "npm";
7
+ var NPM_SEGMENT = /^[a-z0-9][a-z0-9._~-]*$/;
8
+ var EXACT_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
9
+ var WINDOWS_RESERVED = /^(con|prn|aux|nul|clock\$|conin\$|conout\$|com[1-9¹²³]|lpt[1-9¹²³])(?:\..*)?$/i;
10
+ function isValidNpmPackageName(name) {
11
+ if (!name || name.length > 214 || name !== name.toLowerCase())
12
+ return false;
13
+ if (name.startsWith("@")) {
14
+ const parts = name.slice(1).split("/");
15
+ return parts.length === 2 && parts.every((part) => NPM_SEGMENT.test(part));
16
+ }
17
+ return !name.includes("/") && NPM_SEGMENT.test(name);
18
+ }
19
+ function parseNpmPluginSpec(input) {
20
+ const spec = input.trim();
21
+ if (!spec)
22
+ throw new Error("An npm package name is required.");
23
+ let name = spec;
24
+ let selector;
25
+ if (spec.startsWith("@")) {
26
+ const slash = spec.indexOf("/");
27
+ const versionAt = spec.lastIndexOf("@");
28
+ if (slash > 1 && versionAt > slash) {
29
+ name = spec.slice(0, versionAt);
30
+ selector = spec.slice(versionAt + 1);
31
+ }
32
+ } else {
33
+ const versionAt = spec.lastIndexOf("@");
34
+ if (versionAt > 0) {
35
+ name = spec.slice(0, versionAt);
36
+ selector = spec.slice(versionAt + 1);
37
+ }
38
+ }
39
+ if (!isValidNpmPackageName(name)) {
40
+ throw new Error(`"${name}" is not a valid npm package name. Use a name like ` + "markdown-it-highlightjs or @scope/markdown-it-plugin.");
41
+ }
42
+ if (selector !== undefined && !selector) {
43
+ throw new Error(`The package spec "${spec}" is missing a selector after @.`);
44
+ }
45
+ return selector === undefined ? { name } : { name, selector };
46
+ }
47
+ function isExactNpmVersion(version) {
48
+ return EXACT_VERSION.test(version);
49
+ }
50
+ function encodePathPart(value) {
51
+ return encodeURIComponent(value).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
52
+ }
53
+ function vendoredNpmPluginRoot(projectDir, name, version) {
54
+ return path.join(projectDir, PLUGINS_DIR, VENDORED_NPM_DIR, encodePathPart(name), encodePathPart(version));
55
+ }
56
+ function vendoredNpmPluginPackageDir(installRoot, name) {
57
+ return path.join(installRoot, "node_modules", ...name.split("/"));
58
+ }
59
+ function toPosixPath(value) {
60
+ return value.split(path.sep).join("/");
61
+ }
62
+ function assertWindowsSafeRelativePath(relative) {
63
+ if (!relative || relative.includes("\\") || relative.startsWith("/") || /^[a-zA-Z]:/.test(relative)) {
64
+ throw new Error(`Unsafe package path: ${relative || "(empty)"}`);
65
+ }
66
+ const normalized = relative.normalize("NFKC");
67
+ const parts = normalized.split("/");
68
+ if (parts.some((part) => !part || part === "." || part === "..")) {
69
+ throw new Error(`Unsafe package path: ${relative}`);
70
+ }
71
+ for (const part of parts) {
72
+ if (part.length > 255 || /[\u0000-\u001f<>:"|?*]/.test(part) || part.endsWith(".") || part.endsWith(" ") || WINDOWS_RESERVED.test(part)) {
73
+ throw new Error(`Package path is invalid on Windows: ${relative}`);
74
+ }
75
+ }
76
+ }
77
+ function windowsPathKey(relative) {
78
+ return relative.normalize("NFKC").toLowerCase();
79
+ }
80
+ function isContained(root, candidate) {
81
+ const relative = path.relative(root, candidate);
82
+ return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
83
+ }
84
+ function object(value) {
85
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
86
+ }
87
+ async function readPackageJson(packageDir) {
88
+ const packageJsonPath = path.join(packageDir, "package.json");
89
+ const info = await lstat(packageJsonPath);
90
+ if (!info.isFile() || info.isSymbolicLink()) {
91
+ throw new Error(`Package metadata is not a regular file: ${packageJsonPath}`);
92
+ }
93
+ const parsed = object(JSON.parse(await readFile(packageJsonPath, "utf8")));
94
+ if (!parsed)
95
+ throw new Error(`Package metadata is not an object: ${packageJsonPath}`);
96
+ return parsed;
97
+ }
98
+ function packageResolutionTargets(manifest, subpath, condition) {
99
+ if (manifest.exports !== undefined) {
100
+ try {
101
+ const targets2 = resolveExports(manifest, subpath ? `./${subpath}` : ".", { require: condition === "require" }) ?? [];
102
+ return targets2.map((target) => ({ target, exact: true }));
103
+ } catch {
104
+ return [];
105
+ }
106
+ }
107
+ if (subpath)
108
+ return [{ target: subpath, exact: false }];
109
+ const targets = [
110
+ ...condition === "import" && typeof manifest.module === "string" ? [manifest.module] : [],
111
+ ...typeof manifest.main === "string" ? [manifest.main] : [],
112
+ "index.mjs",
113
+ "index.js",
114
+ "index.cjs"
115
+ ];
116
+ return [...new Set(targets)].map((target) => ({ target, exact: false }));
117
+ }
118
+ function safePackageTarget(target) {
119
+ if (!target || target.includes("\\") || target.includes("*") || target.includes("?") || target.includes("#")) {
120
+ return null;
121
+ }
122
+ const relative = target.startsWith("./") ? target.slice(2) : target;
123
+ if (!relative || path.isAbsolute(relative))
124
+ return null;
125
+ assertWindowsSafeRelativePath(relative);
126
+ if (relative.normalize("NFKC").split("/").some((part) => part.toLowerCase() === "node_modules")) {
127
+ return null;
128
+ }
129
+ return relative;
130
+ }
131
+ async function resolveEntryCandidate(packageDir, resolution) {
132
+ const relative = safePackageTarget(resolution.target);
133
+ if (!relative)
134
+ return null;
135
+ const base = path.resolve(packageDir, ...relative.split("/"));
136
+ if (!isContained(packageDir, base))
137
+ return null;
138
+ const candidates = resolution.exact ? [base] : [
139
+ base,
140
+ `${base}.mjs`,
141
+ `${base}.js`,
142
+ `${base}.cjs`,
143
+ `${base}.json`,
144
+ path.join(base, "index.mjs"),
145
+ path.join(base, "index.js"),
146
+ path.join(base, "index.cjs"),
147
+ path.join(base, "index.json")
148
+ ];
149
+ for (const candidate of candidates) {
150
+ try {
151
+ const info = await lstat(candidate);
152
+ if (!info.isFile() || info.isSymbolicLink())
153
+ continue;
154
+ const extension = path.extname(candidate);
155
+ if (extension && ![".js", ".mjs", ".cjs", ".json"].includes(extension))
156
+ continue;
157
+ const [realRoot, realCandidate] = await Promise.all([realpath(packageDir), realpath(candidate)]);
158
+ if (!isContained(realRoot, realCandidate))
159
+ continue;
160
+ return toPosixPath(path.relative(packageDir, realCandidate));
161
+ } catch {}
162
+ }
163
+ return null;
164
+ }
165
+ async function resolvePackageEntry(packageDir, packageJson) {
166
+ const manifest = packageJson ?? await readPackageJson(packageDir);
167
+ for (const condition of ["import", "require"]) {
168
+ for (const target of packageResolutionTargets(manifest, "", condition)) {
169
+ const resolved = await resolveEntryCandidate(packageDir, target);
170
+ if (resolved)
171
+ return resolved;
172
+ }
173
+ }
174
+ throw new Error("Package has no contained JavaScript entry point.");
175
+ }
176
+ async function resolveVendoredPluginInstallRoot(projectDir, expectedName, expectedVersion) {
177
+ const requestedProjectRoot = path.resolve(projectDir);
178
+ const requestedInstallRoot = vendoredNpmPluginRoot(requestedProjectRoot, expectedName, expectedVersion);
179
+ let installInfo;
180
+ try {
181
+ installInfo = await lstat(requestedInstallRoot);
182
+ } catch (error) {
183
+ if (error.code === "ENOENT")
184
+ return null;
185
+ throw error;
186
+ }
187
+ if (!installInfo.isDirectory() || installInfo.isSymbolicLink()) {
188
+ throw new Error("Vendor install root is not a normal directory.");
189
+ }
190
+ const [realProjectRoot, installRoot] = await Promise.all([
191
+ realpath(requestedProjectRoot),
192
+ realpath(requestedInstallRoot)
193
+ ]);
194
+ if (!isContained(realProjectRoot, installRoot)) {
195
+ throw new Error("Vendor install root resolves outside the book folder.");
196
+ }
197
+ return installRoot;
198
+ }
199
+
200
+ export { PLUGINS_DIR, VENDORED_NPM_DIR, isValidNpmPackageName, parseNpmPluginSpec, isExactNpmVersion, vendoredNpmPluginRoot, vendoredNpmPluginPackageDir, assertWindowsSafeRelativePath, windowsPathKey, packageResolutionTargets, safePackageTarget, resolvePackageEntry, resolveVendoredPluginInstallRoot };