honkit 6.2.4 → 6.2.6

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.
@@ -135,4 +135,25 @@ describe("WebsiteGenerator", () => {
135
135
  expect(folder).toHaveFile("index.html");
136
136
  });
137
137
  });
138
+ longTest("should write a separate search index for each language", async () => {
139
+ const folder = await (0, generateMock_1.default)(website_1.default, {
140
+ "LANGS.md": "# Languages\n\n* [en](en)\n* [fr](fr)",
141
+ en: {
142
+ "README.md": "# Hello\n\nenglishonly"
143
+ },
144
+ fr: {
145
+ "README.md": "# Bonjour\n\nfrenchonly"
146
+ }
147
+ });
148
+ const readIndex = (language) => JSON.parse(fs_1.default.readFileSync(`${folder}/${language}/search_index.json`, "utf8"));
149
+ const en = readIndex("en");
150
+ const fr = readIndex("fr");
151
+ expect(Object.values(en.store).map((doc) => doc.body.trim())).toEqual(["Hello\nenglishonly"]);
152
+ expect(Object.values(fr.store).map((doc) => doc.body.trim())).toEqual(["Bonjour\nfrenchonly"]);
153
+ // The index itself, not only the store, must not contain words of the other language
154
+ expect(JSON.stringify(en.index)).toContain("englishon");
155
+ expect(JSON.stringify(en.index)).not.toContain("frenchon");
156
+ expect(JSON.stringify(fr.index)).toContain("frenchon");
157
+ expect(JSON.stringify(fr.index)).not.toContain("englishon");
158
+ });
138
159
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PluginResolver.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginResolver.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;GAYG;AAEH,qBAAa,cAAc;IACvB,aAAa,EAAE,MAAM,CAAC;gBAEV,MAAM,GAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAO;IAOnD;;;;OAIG;IACH,wBAAwB,CAAC,WAAW,KAAA;CAyBvC"}
1
+ {"version":3,"file":"PluginResolver.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginResolver.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;GAYG;AAEH,qBAAa,cAAc;IACvB,aAAa,EAAE,MAAM,CAAC;gBAEV,MAAM,GAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAO;IAOnD;;;;OAIG;IACH,wBAAwB,CAAC,WAAW,KAAA;CA2BvC"}
@@ -34,6 +34,7 @@ const path_2 = __importDefault(require("../utils/path"));
34
34
  const SPECIAL_PACKAGE_NAME = [
35
35
  "fontsettings", // → @honkit/honkit-plugin-fontsettings
36
36
  "highlight", // → @honkit/honkit-plugin-highlight
37
+ "lunr", // → @honkit/honkit-plugin-lunr
37
38
  "theme-default" // → @honkit/honkit-plugin-theme-default
38
39
  ];
39
40
  /**
@@ -71,11 +72,13 @@ class PluginResolver {
71
72
  // e.g.) load theme-default as @honkit/honkit-plugins-theme-default
72
73
  const honkitScopePackageName = `@honkit/${honkitFullPackageName}`;
73
74
  // In sometimes, HonKit package has not main field - so search package.json
75
+ // The scoped package is tried before the bare name: a bare name such as "lunr" is
76
+ // also a regular library (a dependency of the plugin) and is not a HonKit plugin.
74
77
  const pkgPath = path_2.default.tryResolve(path_1.default.join(baseDir, honkitFullPackageName, "/package.json")) ||
75
78
  path_2.default.tryResolve(path_1.default.join(baseDir, gitbookFullPackageName, "/package.json")) ||
76
- path_2.default.tryResolve(path_1.default.join(baseDir, packageName, "/package.json")) ||
77
79
  (SPECIAL_PACKAGE_NAME.includes(packageName) &&
78
- path_2.default.tryResolve(path_1.default.join(baseDir, honkitScopePackageName, "/package.json")));
80
+ path_2.default.tryResolve(path_1.default.join(baseDir, honkitScopePackageName, "/package.json"))) ||
81
+ path_2.default.tryResolve(path_1.default.join(baseDir, packageName, "/package.json"));
79
82
  if (!pkgPath) {
80
83
  throw new ReferenceError(`Failed to load HonKit's plugin module: "${packageName}" is not found.
81
84
 
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PluginResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginResolver.d.ts","sourceRoot":"","sources":["../../../src/plugins/__tests__/PluginResolver.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const PluginResolver_1 = require("../PluginResolver");
10
+ describe("PluginResolver", () => {
11
+ let baseDirectory;
12
+ // Create a fake package in baseDirectory, as if it was installed in node_modules
13
+ const installPackage = (name) => {
14
+ const packageDir = path_1.default.join(baseDirectory, name);
15
+ fs_1.default.mkdirSync(packageDir, { recursive: true });
16
+ fs_1.default.writeFileSync(path_1.default.join(packageDir, "package.json"), JSON.stringify({ name }));
17
+ return packageDir;
18
+ };
19
+ beforeEach(() => {
20
+ // require.resolve returns the real path: the temporary directory is a symlink on macOS
21
+ // and a short (8.3) path on Windows, which only the native realpath expands
22
+ baseDirectory = fs_1.default.realpathSync.native(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "honkit-plugin-resolver-")));
23
+ });
24
+ afterEach(() => {
25
+ fs_1.default.rmSync(baseDirectory, { recursive: true, force: true });
26
+ });
27
+ const resolve = (name) => new PluginResolver_1.PluginResolver({ baseDirectory }).resolvePluginPackageName(name);
28
+ it("should resolve honkit-plugin-* before gitbook-plugin-*", () => {
29
+ const honkitPlugin = installPackage("honkit-plugin-example");
30
+ installPackage("gitbook-plugin-example");
31
+ expect(resolve("example")).toBe(honkitPlugin);
32
+ });
33
+ it("should resolve gitbook-plugin-*", () => {
34
+ const gitbookPlugin = installPackage("gitbook-plugin-example");
35
+ expect(resolve("example")).toBe(gitbookPlugin);
36
+ });
37
+ it("should resolve a package by its full name", () => {
38
+ const plugin = installPackage("honkit-plugin-example");
39
+ expect(resolve("honkit-plugin-example")).toBe(plugin);
40
+ });
41
+ it("should resolve a default plugin to the @honkit/ package before a library of the same name", () => {
42
+ // npm hoists the "lunr" library, a dependency of @honkit/honkit-plugin-lunr, next to the plugin
43
+ installPackage("lunr");
44
+ const scopedPlugin = installPackage("@honkit/honkit-plugin-lunr");
45
+ expect(resolve("lunr")).toBe(scopedPlugin);
46
+ });
47
+ it("should prefer a user-installed gitbook-plugin-* over the @honkit/ package", () => {
48
+ installPackage("@honkit/honkit-plugin-lunr");
49
+ const gitbookPlugin = installPackage("gitbook-plugin-lunr");
50
+ expect(resolve("lunr")).toBe(gitbookPlugin);
51
+ });
52
+ it("should not resolve a non-default plugin to the @honkit/ package", () => {
53
+ installPackage("@honkit/honkit-plugin-example");
54
+ expect(() => resolve("example")).toThrow(ReferenceError);
55
+ });
56
+ it("should fall back to the bare package name", () => {
57
+ const plugin = installPackage("example");
58
+ expect(resolve("example")).toBe(plugin);
59
+ });
60
+ it("should throw when the plugin is not found", () => {
61
+ expect(() => resolve("not-found")).toThrow(/"not-found" is not found/);
62
+ });
63
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honkit",
3
- "version": "6.2.4",
3
+ "version": "6.2.6",
4
4
  "description": "HonKit is building beautiful books using Markdown.",
5
5
  "keywords": [
6
6
  "git",
@@ -48,7 +48,6 @@
48
48
  "flat-cache": "^4.0.1",
49
49
  "front-matter": "^2.3.0",
50
50
  "gitbook-plugin-livereload": "^0.0.1",
51
- "gitbook-plugin-lunr": "^1.2.0",
52
51
  "gitbook-plugin-search": "^2.2.1",
53
52
  "github-slugid": "^1.0.1",
54
53
  "i18n-t": "^1.0.1",
@@ -70,12 +69,13 @@
70
69
  "semver": "^7.6.3",
71
70
  "send": "^0.19.2",
72
71
  "tiny-lr": "^1.1.1",
73
- "@honkit/asciidoc": "6.2.4",
74
- "@honkit/honkit-plugin-fontsettings": "6.2.4",
75
- "@honkit/honkit-plugin-theme-default": "6.2.4",
76
- "@honkit/html": "6.2.4",
77
- "@honkit/honkit-plugin-highlight": "6.2.4",
78
- "@honkit/markdown-legacy": "6.2.4"
72
+ "@honkit/honkit-plugin-highlight": "6.2.6",
73
+ "@honkit/asciidoc": "6.2.6",
74
+ "@honkit/honkit-plugin-fontsettings": "6.2.6",
75
+ "@honkit/honkit-plugin-lunr": "6.2.6",
76
+ "@honkit/html": "6.2.6",
77
+ "@honkit/markdown-legacy": "6.2.6",
78
+ "@honkit/honkit-plugin-theme-default": "6.2.6"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@relmify/jest-serializer-strip-ansi": "^1.0.2",
@@ -87,7 +87,7 @@
87
87
  "object-path": "^0.11.8",
88
88
  "rimraf": "^6.0.1",
89
89
  "typescript": "^5.6.2",
90
- "@honkit/internal-test-utils": "6.2.4"
90
+ "@honkit/internal-test-utils": "6.2.6"
91
91
  },
92
92
  "scripts": {
93
93
  "build": "tsc -p .",