honkit 3.7.1 → 3.7.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.
@@ -12,9 +12,8 @@ const pkg = require("../../package.json");
12
12
  * @return {PluginDependency}
13
13
  */
14
14
  function createFromDependency(pluginName) {
15
- const npmID = pluginDependency_1.default.nameToNpmID(pluginName);
15
+ const npmID = "gitbook-plugin-" + pluginName;
16
16
  const version = pkg.dependencies[npmID];
17
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'create' does not exist on type 'Class'.
18
17
  return pluginDependency_1.default.create(pluginName, version);
19
18
  }
20
19
  exports.default = immutable_1.default.List(["highlight", "search", "lunr", "fontsettings", "theme-default"]).map(createFromDependency);
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const plugin_1 = __importDefault(require("../plugin"));
7
+ const immutable_1 = __importDefault(require("immutable"));
7
8
  describe("Plugin", () => {
8
9
  describe("createFromString", () => {
9
10
  test("must parse name", () => {
@@ -17,6 +18,29 @@ describe("Plugin", () => {
17
18
  expect(plugin.getVersion()).toBe("1.0.0");
18
19
  });
19
20
  });
21
+ describe("getNpmId", () => {
22
+ it("should return package's name", () => {
23
+ const plugin = new plugin_1.default({
24
+ name: "testplugin",
25
+ version: "*",
26
+ path: "test.js",
27
+ package: immutable_1.default.fromJS({
28
+ name: "testplugin-name"
29
+ }),
30
+ content: immutable_1.default.fromJS({
31
+ hooks: {
32
+ "page:before": function (page) {
33
+ return page;
34
+ },
35
+ page: function (page) {
36
+ return page;
37
+ }
38
+ }
39
+ })
40
+ });
41
+ expect(plugin.getNpmID()).toBe("testplugin-name");
42
+ });
43
+ });
20
44
  describe("isLoaded", () => {
21
45
  test("must return false for empty plugin", () => {
22
46
  const plugin = plugin_1.default.createFromString("hello");
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const immutable_1 = __importDefault(require("immutable"));
7
7
  const templateBlock_1 = __importDefault(require("./templateBlock"));
8
- const pluginDependency_1 = __importDefault(require("./pluginDependency"));
9
8
  const themePrefix_1 = __importDefault(require("../constants/themePrefix"));
10
9
  const DEFAULT_VERSION = "*";
11
10
  class Plugin extends immutable_1.default.Record({
@@ -46,10 +45,15 @@ class Plugin extends immutable_1.default.Record({
46
45
  }
47
46
  /**
48
47
  * Return the ID on NPM for this plugin
48
+ * return package.json's name
49
49
  * @return {string}
50
50
  */
51
51
  getNpmID() {
52
- return pluginDependency_1.default.nameToNpmID(this.getName());
52
+ const pkg = this.getPackage().toJS();
53
+ if ("name" in pkg) {
54
+ return pkg["name"];
55
+ }
56
+ throw new Error(`${this.getName()} plugin's package.json does not have "name" fields.`);
53
57
  }
54
58
  /**
55
59
  * Check if a plugin is loaded
@@ -112,8 +116,8 @@ class Plugin extends immutable_1.default.Record({
112
116
  }
113
117
  /**
114
118
  * Create a plugin from a string
115
- * @param {string}
116
119
  * @return {Plugin}
120
+ * @param s
117
121
  */
118
122
  static createFromString(s) {
119
123
  const parts = s.split("@");
@@ -135,5 +139,4 @@ class Plugin extends immutable_1.default.Record({
135
139
  });
136
140
  }
137
141
  }
138
- Plugin.nameToNpmID = pluginDependency_1.default.nameToNpmID;
139
142
  exports.default = Plugin;
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const is_1 = __importDefault(require("is"));
7
7
  const semver_1 = __importDefault(require("semver"));
8
8
  const immutable_1 = __importDefault(require("immutable"));
9
- const pluginPrefix_1 = __importDefault(require("../constants/pluginPrefix"));
10
9
  const DEFAULT_VERSION = "*";
11
10
  /*
12
- * PluginDependency represents the informations about a plugin
11
+ * PluginDependency represents the information about a plugin
13
12
  * stored in config.plugins
14
13
  */
15
14
  class PluginDependency extends immutable_1.default.Record({
@@ -43,13 +42,6 @@ class PluginDependency extends immutable_1.default.Record({
43
42
  }
44
43
  return this.set("enabled", state);
45
44
  }
46
- /**
47
- * Return NPM ID for the dependency
48
- * @return {string}
49
- */
50
- getNpmID() {
51
- return PluginDependency.nameToNpmID(this.getName());
52
- }
53
45
  /**
54
46
  * Is the plugin using a git dependency
55
47
  * @return {boolean}
@@ -59,7 +51,6 @@ class PluginDependency extends immutable_1.default.Record({
59
51
  }
60
52
  /**
61
53
  * Create a plugin with a name and a plugin
62
- * @param {string}
63
54
  * @return {Plugin|undefined}
64
55
  */
65
56
  static create(name, version, enabled) {
@@ -180,13 +171,5 @@ class PluginDependency extends immutable_1.default.Record({
180
171
  })
181
172
  .toJS();
182
173
  }
183
- /**
184
- * Return NPM id for a plugin name
185
- * @param {string}
186
- * @return {string}
187
- */
188
- static nameToNpmID(s) {
189
- return pluginPrefix_1.default + s;
190
- }
191
174
  }
192
175
  exports.default = PluginDependency;
@@ -19,7 +19,6 @@ function addPlugin(config, pluginName, version) {
19
19
  return (0, togglePlugin_1.default)(config, pluginName, true);
20
20
  }
21
21
  let deps = config.getPluginDependencies();
22
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'create' does not exist on type 'Class'.
23
22
  const dep = pluginDependency_1.default.create(pluginName, version);
24
23
  deps = deps.push(dep);
25
24
  return config.setPluginDependencies(deps);
@@ -59,8 +59,6 @@ function copyAssets(output, plugin) {
59
59
  }
60
60
  /**
61
61
  Copy resources from a plugin
62
-
63
- @param {Plugin}
64
62
  @return {Promise}
65
63
  */
66
64
  function copyResources(output, plugin) {
@@ -37,7 +37,6 @@ function templateFolder(dir) {
37
37
  function createTemplateEngine(output, currentFile) {
38
38
  const book = output.getBook();
39
39
  const state = output.getState();
40
- // @ts-expect-error: state type
41
40
  const i18n = state.getI18n();
42
41
  const config = book.getConfig();
43
42
  const summary = book.getSummary();
@@ -9,9 +9,6 @@ const location_1 = __importDefault(require("../utils/location"));
9
9
  const pluginResources_1 = __importDefault(require("../constants/pluginResources"));
10
10
  /**
11
11
  List all resources from a list of plugins
12
-
13
- @param {OrderedMap<String:Plugin>}
14
- @param {string} type
15
12
  @return {Map<String:List<{url, path}>}
16
13
  */
17
14
  function listResources(plugins, resources) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honkit",
3
- "version": "3.7.1",
3
+ "version": "3.7.2",
4
4
  "description": "HonKit is building beautiful books using Markdown.",
5
5
  "keywords": [
6
6
  "git",
@@ -109,5 +109,5 @@
109
109
  "rimraf": "^3.0.2",
110
110
  "typescript": "^4.1.3"
111
111
  },
112
- "gitHead": "35d95d4d0b9f28dce4a4ac8cd3feb39c12ec1d1b"
112
+ "gitHead": "89e4ff9d86596d7c650c5e83e2d768435d6eef20"
113
113
  }
@@ -1,25 +0,0 @@
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 path_1 = __importDefault(require("path"));
7
- const immutable_1 = __importDefault(require("immutable"));
8
- const findInstalled_1 = __importDefault(require("../findInstalled"));
9
- describe("findInstalled", () => {
10
- test.skip("must list default plugins for gitbook directory", () => {
11
- // Read gitbook-plugins from package.json
12
- const pkg = require(path_1.default.resolve(__dirname, "../../../package.json"));
13
- const gitbookPlugins = immutable_1.default.Seq(pkg.dependencies)
14
- .filter((v, k) => {
15
- return k.indexOf("gitbook-plugin") === 0;
16
- })
17
- // @ts-expect-error
18
- .cacheResult();
19
- return (0, findInstalled_1.default)(path_1.default.resolve(__dirname, "../../../")).then((plugins) => {
20
- expect(plugins.size >= gitbookPlugins.size).toBeTruthy();
21
- expect(plugins.has("fontsettings")).toBe(true);
22
- expect(plugins.has("search")).toBe(true);
23
- });
24
- });
25
- });
@@ -1,87 +0,0 @@
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 read_installed_1 = __importDefault(require("read-installed"));
7
- const immutable_1 = __importDefault(require("immutable"));
8
- const path_1 = __importDefault(require("path"));
9
- const promise_1 = __importDefault(require("../utils/promise"));
10
- const fs_1 = __importDefault(require("../utils/fs"));
11
- const plugin_1 = __importDefault(require("../models/plugin"));
12
- const pluginPrefix_1 = __importDefault(require("../constants/pluginPrefix"));
13
- /**
14
- * Validate if a package name is a GitBook/HonKit plugin
15
- *
16
- * @return {boolean}
17
- */
18
- function validateId(name) {
19
- return name && name.indexOf(pluginPrefix_1.default) === 0;
20
- }
21
- /**
22
- * List all packages installed inside a folder
23
- *
24
- * @param {string} folder
25
- * @return {OrderedMap<String:Plugin>}
26
- */
27
- function findInstalled(folder) {
28
- const options = {
29
- dev: false,
30
- log: function () { },
31
- depth: 4,
32
- };
33
- let results = immutable_1.default.OrderedMap();
34
- function onPackage(pkg, parent) {
35
- if (!pkg.name)
36
- return;
37
- const name = pkg.name;
38
- const version = pkg.version;
39
- const pkgPath = pkg.realPath;
40
- const depth = pkg.depth;
41
- const dependencies = pkg.dependencies;
42
- const pluginName = name.slice(pluginPrefix_1.default.length);
43
- if (!validateId(name)) {
44
- if (parent)
45
- return;
46
- }
47
- else {
48
- results = results.set(pluginName, new plugin_1.default({
49
- name: pluginName,
50
- version: version,
51
- path: pkgPath,
52
- depth: depth,
53
- parent: parent,
54
- }));
55
- }
56
- immutable_1.default.Map(dependencies).forEach((dep) => {
57
- onPackage(dep, pluginName);
58
- });
59
- }
60
- // Search for gitbook-plugins in node_modules folder
61
- const node_modules = path_1.default.join(folder, "node_modules");
62
- // List all folders in node_modules
63
- return fs_1.default
64
- .readdir(node_modules)
65
- .fail(() => {
66
- return (0, promise_1.default)([]);
67
- })
68
- .then((modules) => {
69
- return promise_1.default.serie(modules, (module) => {
70
- // Not a gitbook-plugin
71
- if (!validateId(module)) {
72
- return (0, promise_1.default)();
73
- }
74
- // Read gitbook-plugin package details
75
- const module_folder = path_1.default.join(node_modules, module);
76
- return promise_1.default.nfcall(read_installed_1.default, module_folder, options).then((data) => {
77
- // @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
78
- onPackage(data);
79
- });
80
- });
81
- })
82
- .then(() => {
83
- // Return installed plugins
84
- return results;
85
- });
86
- }
87
- exports.default = findInstalled;