honkit 6.2.1 → 6.2.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.
@@ -3,17 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const tmp_1 = __importDefault(require("tmp"));
6
+ const tmpdir_1 = require("../fs/tmpdir");
7
7
  const init_1 = __importDefault(require("../init"));
8
8
  describe("initBook", () => {
9
9
  let dir;
10
10
  beforeEach(() => {
11
- dir = tmp_1.default.dirSync();
11
+ dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-init-test-");
12
12
  });
13
13
  test("should create a README and SUMMARY for empty book", () => {
14
- return (0, init_1.default)(dir.name).then(() => {
15
- expect(dir.name).toHaveFile("README.md");
16
- expect(dir.name).toHaveFile("SUMMARY.md");
14
+ return (0, init_1.default)(dir).then(() => {
15
+ expect(dir).toHaveFile("README.md");
16
+ expect(dir).toHaveFile("SUMMARY.md");
17
17
  });
18
18
  });
19
19
  });
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const os_1 = __importDefault(require("os"));
9
8
  const bin_1 = require("../../bin");
10
9
  const internal_test_utils_1 = require("@honkit/internal-test-utils");
10
+ const tmpdir_1 = require("../../fs/tmpdir");
11
11
  /**
12
12
  * Integration tests for honkit build output
13
13
  *
@@ -23,7 +23,7 @@ describe("build integration", () => {
23
23
  let tempDir;
24
24
  let outputDir;
25
25
  beforeEach(() => {
26
- tempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "honkit-build-test-"));
26
+ tempDir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-build-test-");
27
27
  outputDir = path_1.default.join(tempDir, "_book");
28
28
  });
29
29
  afterEach(() => {
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const os_1 = __importDefault(require("os"));
9
8
  const child_process_1 = require("child_process");
9
+ const tmpdir_1 = require("../../fs/tmpdir");
10
10
  /**
11
11
  * Integration tests for honkit serve rebuild behavior
12
12
  *
@@ -22,7 +22,7 @@ describe("serve integration", () => {
22
22
  let outputDir;
23
23
  let serveProcess = null;
24
24
  beforeEach(() => {
25
- tempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "honkit-serve-test-"));
25
+ tempDir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-serve-test-");
26
26
  outputDir = path_1.default.join(tempDir, "_book");
27
27
  });
28
28
  afterEach(async () => {
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const os_1 = __importDefault(require("os"));
9
8
  const watch_1 = __importDefault(require("../watch"));
9
+ const tmpdir_1 = require("../../fs/tmpdir");
10
10
  /**
11
11
  * Normalize path separators to forward slashes for cross-platform comparison
12
12
  */
@@ -19,7 +19,7 @@ describe("watch", () => {
19
19
  let tempDir;
20
20
  let watchers = [];
21
21
  beforeEach(() => {
22
- tempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "honkit-watch-test-"));
22
+ tempDir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-watch-test-");
23
23
  });
24
24
  afterEach(async () => {
25
25
  // Close all watchers
@@ -1 +1 @@
1
- {"version":3,"file":"tmpdir.d.ts","sourceRoot":"","sources":["../../src/fs/tmpdir.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,YAAY,MAAM,WAGtD,CAAC"}
1
+ {"version":3,"file":"tmpdir.d.ts","sourceRoot":"","sources":["../../src/fs/tmpdir.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,YAAY,MAAM,WAGtD,CAAC"}
package/lib/fs/tmpdir.js CHANGED
@@ -7,6 +7,14 @@ exports.createTmpDirWithRealPath = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
+ const getRealTmpRoot = () => {
11
+ try {
12
+ return fs_1.default.realpathSync.native(os_1.default.tmpdir());
13
+ }
14
+ catch {
15
+ return os_1.default.tmpdir();
16
+ }
17
+ };
10
18
  /**
11
19
  * Create a temporary directory with a real path
12
20
  * ebook-convert requires a real path to work
@@ -14,7 +22,7 @@ const fs_1 = __importDefault(require("fs"));
14
22
  * @param prefix "honkit-"
15
23
  */
16
24
  const createTmpDirWithRealPath = (prefix = "honkit-") => {
17
- const tmpDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), prefix));
18
- return fs_1.default.realpathSync(tmpDir);
25
+ const tmpDir = fs_1.default.mkdtempSync(path_1.default.join(getRealTmpRoot(), prefix));
26
+ return fs_1.default.realpathSync.native(tmpDir);
19
27
  };
20
28
  exports.createTmpDirWithRealPath = createTmpDirWithRealPath;
@@ -27,8 +27,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const html_1 = require("@honkit/html");
30
- const tmp_1 = __importDefault(require("tmp"));
31
30
  const path_1 = __importDefault(require("path"));
31
+ const tmpdir_1 = require("../../../fs/tmpdir");
32
32
  const fetchRemoteImages_1 = __importDefault(require("../fetchRemoteImages"));
33
33
  const promises_1 = __importDefault(require("fs/promises"));
34
34
  const assert_1 = __importDefault(require("assert"));
@@ -39,29 +39,29 @@ jest.retryTimes(3);
39
39
  describe("fetchRemoteImages", () => {
40
40
  let dir;
41
41
  beforeEach(() => {
42
- dir = tmp_1.default.dirSync();
43
- return promises_1.default.rm(dir.name, { recursive: true, force: true });
42
+ dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-fetch-remote-images-test-");
43
+ return promises_1.default.rm(dir, { recursive: true, force: true });
44
44
  });
45
45
  afterEach(() => {
46
- // remove tmp `dir`
47
- return promises_1.default.rm(dir.name, { recursive: true, force: true });
46
+ // remove temporary directory
47
+ return promises_1.default.rm(dir, { recursive: true, force: true });
48
48
  });
49
49
  it("should download image file", async () => {
50
50
  const $ = (0, html_1.loadHtml)(`<img src="${URL}" />`);
51
- await (0, fetchRemoteImages_1.default)(dir.name, "index.html", $);
51
+ await (0, fetchRemoteImages_1.default)(dir, "index.html", $);
52
52
  const $img = $("img");
53
53
  const src = $img.attr("src");
54
- const expected = path_1.default.join(dir.name, src);
54
+ const expected = path_1.default.join(dir, src);
55
55
  await assert_1.default.doesNotReject(() => {
56
56
  return promises_1.default.access(expected, constants.F_OK);
57
57
  });
58
58
  }, 15 * 1000);
59
59
  it("should download image file and replace with relative path", async () => {
60
60
  const $ = (0, html_1.loadHtml)(`<img src="${URL}" />`);
61
- await (0, fetchRemoteImages_1.default)(dir.name, "test/index.html", $);
61
+ await (0, fetchRemoteImages_1.default)(dir, "test/index.html", $);
62
62
  const $img = $("img");
63
63
  const src = $img.attr("src");
64
- const expected = path_1.default.join(dir.name, "test/" + src);
64
+ const expected = path_1.default.join(dir, "test/" + src);
65
65
  await assert_1.default.doesNotReject(() => {
66
66
  return promises_1.default.access(expected, constants.F_OK);
67
67
  });
@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const html_1 = require("@honkit/html");
7
- const tmp_1 = __importDefault(require("tmp"));
7
+ const tmpdir_1 = require("../../../fs/tmpdir");
8
8
  const inlinePng_1 = __importDefault(require("../inlinePng"));
9
9
  describe("inlinePng", () => {
10
10
  let dir;
11
11
  beforeEach(() => {
12
- dir = tmp_1.default.dirSync();
12
+ dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-inline-png-test-");
13
13
  });
14
14
  test("should write an inline PNG using data URI as a file", () => {
15
15
  const $ = (0, html_1.loadHtml)("<img alt=\"HonKit Logo 20x20\" src=\"data:image/png;base64,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\"/>");
16
- return (0, inlinePng_1.default)(dir.name, "index.html", $).then(() => {
16
+ return (0, inlinePng_1.default)(dir, "index.html", $).then(() => {
17
17
  const $img = $("img");
18
18
  const src = $img.attr("src");
19
- expect(dir.name).toHaveFile(src);
19
+ expect(dir).toHaveFile(src);
20
20
  });
21
21
  });
22
22
  });
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const html_1 = require("@honkit/html");
7
- const tmp_1 = __importDefault(require("tmp"));
8
7
  const path_1 = __importDefault(require("path"));
9
8
  const fs_1 = __importDefault(require("fs"));
9
+ const tmpdir_1 = require("../../../fs/tmpdir");
10
10
  const inlineSvg_1 = __importDefault(require("../inlineSvg"));
11
11
  describe("inlineSvg", () => {
12
12
  let dir;
13
13
  let svgPath;
14
14
  beforeEach(() => {
15
- dir = tmp_1.default.dirSync();
16
- svgPath = path_1.default.join(dir.name, "test.svg");
15
+ dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-inline-svg-test-");
16
+ svgPath = path_1.default.join(dir, "test.svg");
17
17
  });
18
18
  test("should inline svg icons", () => {
19
19
  const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke-width="6"/></svg>';
@@ -21,7 +21,7 @@ describe("inlineSvg", () => {
21
21
  return fs_1.default.promises
22
22
  .writeFile(svgPath, svg)
23
23
  .then(() => {
24
- return (0, inlineSvg_1.default)(dir.name, "index.html", $);
24
+ return (0, inlineSvg_1.default)(dir, "index.html", $);
25
25
  })
26
26
  .then(() => {
27
27
  expect($("svg").attr("fill")).toBe("currentColor");
@@ -33,7 +33,7 @@ describe("inlineSvg", () => {
33
33
  return fs_1.default.promises
34
34
  .writeFile(svgPath, svg)
35
35
  .then(() => {
36
- return (0, inlineSvg_1.default)(dir.name, "index.html", $);
36
+ return (0, inlineSvg_1.default)(dir, "index.html", $);
37
37
  })
38
38
  .then(() => {
39
39
  expect($("svg").length).toBe(0);
@@ -4,24 +4,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const html_1 = require("@honkit/html");
7
- const tmp_1 = __importDefault(require("tmp"));
7
+ const tmpdir_1 = require("../../../fs/tmpdir");
8
8
  const svgToImg_1 = __importDefault(require("../svgToImg"));
9
9
  describe("svgToImg", () => {
10
10
  let dir;
11
11
  beforeEach(() => {
12
- dir = tmp_1.default.dirSync();
12
+ dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-svg-to-img-test-");
13
13
  });
14
14
  test("should write svg as a file", () => {
15
15
  const $ = (0, html_1.loadHtml)('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>');
16
- return (0, svgToImg_1.default)(dir.name, "index.html", $).then(() => {
16
+ return (0, svgToImg_1.default)(dir, "index.html", $).then(() => {
17
17
  const $img = $("img");
18
18
  const src = $img.attr("src");
19
- expect(dir.name).toHaveFile(src);
19
+ expect(dir).toHaveFile(src);
20
20
  });
21
21
  });
22
22
  it("should not write icon svg as a file", () => {
23
23
  const $ = (0, html_1.loadHtml)('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1" fill="currentColor"><rect width="200" height="100" stroke-width="6"/></svg>');
24
- return (0, svgToImg_1.default)(dir.name, "index.html", $).then(() => {
24
+ return (0, svgToImg_1.default)(dir, "index.html", $).then(() => {
25
25
  // @ts-expect-error
26
26
  expect($.contains("img")).toBe(false);
27
27
  });
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateMockBook = generateMockBook;
7
7
  const mock_1 = __importDefault(require("../../fs/mock"));
8
- const tmp_1 = __importDefault(require("tmp"));
8
+ const tmpdir_1 = require("../../fs/tmpdir");
9
9
  const book_1 = __importDefault(require("../../models/book"));
10
10
  const parseBook_1 = __importDefault(require("../../parse/parseBook"));
11
11
  const generateBook_1 = require("../generateBook");
@@ -22,19 +22,19 @@ const generateBook_1 = require("../generateBook");
22
22
  function generateMockBook(Generator, files) {
23
23
  const fs = (0, mock_1.default)(files);
24
24
  let book = book_1.default.createForFS(fs);
25
- const dir = tmp_1.default.dirSync();
25
+ const dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-generate-test-");
26
26
  book = book.setLogLevel("disabled");
27
27
  return (0, parseBook_1.default)(book)
28
28
  .then((resultBook) => {
29
29
  return (0, generateBook_1.generateBook)(Generator, resultBook, {
30
- root: dir.name
30
+ root: dir
31
31
  });
32
32
  })
33
33
  .then((output) => {
34
34
  return {
35
35
  book,
36
36
  output,
37
- dir: dir.name
37
+ dir
38
38
  };
39
39
  });
40
40
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/utils/__tests__/fs.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
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 promises_1 = __importDefault(require("fs/promises"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_2 = __importDefault(require("../fs"));
11
+ describe("fs", () => {
12
+ const createdPaths = [];
13
+ let tmpDir;
14
+ beforeAll(() => {
15
+ try {
16
+ tmpDir = fs_1.default.realpathSync.native(os_1.default.tmpdir());
17
+ }
18
+ catch {
19
+ tmpDir = os_1.default.tmpdir();
20
+ }
21
+ });
22
+ afterEach(async () => {
23
+ await Promise.all(createdPaths.splice(0).map((createdPath) => promises_1.default.rm(createdPath, { recursive: true, force: true })));
24
+ });
25
+ test("tmpDir creates a temporary directory", async () => {
26
+ const dir = await fs_2.default.tmpDir();
27
+ createdPaths.push(dir);
28
+ expect(path_1.default.dirname(dir)).toBe(tmpDir);
29
+ expect(path_1.default.basename(dir).startsWith("honkit-")).toBe(true);
30
+ await expect(promises_1.default.stat(dir)).resolves.toMatchObject({ isDirectory: expect.any(Function) });
31
+ });
32
+ test("tmpFile creates a temporary file", async () => {
33
+ const file = await fs_2.default.tmpFile();
34
+ createdPaths.push(file);
35
+ expect(path_1.default.dirname(file)).toBe(tmpDir);
36
+ expect(path_1.default.basename(file).startsWith("honkit-")).toBe(true);
37
+ await expect(promises_1.default.stat(file)).resolves.toMatchObject({ isFile: expect.any(Function) });
38
+ });
39
+ });
package/lib/utils/fs.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import fs from "fs";
2
2
  declare function writeStream(filename: any, st: any): any;
3
3
  declare function fileExists(filename: any): any;
4
- declare function genTmpFile(opts: any): any;
4
+ declare function genTmpFile(): any;
5
5
  /**
6
6
  * Generate temporary dir
7
7
  * @deprecated use tmpdir.ts
8
- * @param opts
9
8
  */
10
- declare function genTmpDir(opts: any): any;
9
+ declare function genTmpDir(): any;
11
10
  declare function download(uri: string, destFilePath: string): Promise<any>;
12
11
  declare function uniqueFilename(base: any, filename: any): any;
13
12
  declare function ensureFile(filename: any): any;
@@ -1 +1 @@
1
- {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAYpB,iBAAS,WAAW,CAAC,QAAQ,KAAA,EAAE,EAAE,KAAA,OA0BhC;AAGD,iBAAS,UAAU,CAAC,QAAQ,KAAA,OAY3B;AAGD,iBAAS,UAAU,CAAC,IAAI,KAAA,OAEvB;AAED;;;;GAIG;AACH,iBAAS,SAAS,CAAC,IAAI,KAAA,OAEtB;AA0BD,iBAAe,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAaxD;AAGD,iBAAS,cAAc,CAAC,IAAI,KAAA,EAAE,QAAQ,KAAA,OAcrC;AAGD,iBAAS,UAAU,CAAC,QAAQ,KAAA,OAI3B;AAGD,iBAAS,KAAK,CAAC,IAAI,KAAA,OAIlB;AAED;;;;;;GAMG;AACH,iBAAS,UAAU,CAAC,QAAQ,KAAA,EAAE,SAAS,KAAA,OAMtC;AAED;;;;;;GAMG;AACH,iBAAS,QAAQ,CAAC,UAAU,KAAA,EAAE,QAAQ,KAAA,UAOrC;AAED;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,UAAU,KAAA,OAQ/B;;;;;;;;;;;;;;;;;IAiCG;;OAEG;;;;;;;;AAjCP,wBAwCE"}
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAapB,iBAAS,WAAW,CAAC,QAAQ,KAAA,EAAE,EAAE,KAAA,OA0BhC;AAGD,iBAAS,UAAU,CAAC,QAAQ,KAAA,OAY3B;AAWD,iBAAS,UAAU,QA4BlB;AAED;;;GAGG;AACH,iBAAS,SAAS,QAEjB;AA0BD,iBAAe,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAaxD;AAGD,iBAAS,cAAc,CAAC,IAAI,KAAA,EAAE,QAAQ,KAAA,OAcrC;AAGD,iBAAS,UAAU,CAAC,QAAQ,KAAA,OAI3B;AAGD,iBAAS,KAAK,CAAC,IAAI,KAAA,OAIlB;AAED;;;;;;GAMG;AACH,iBAAS,UAAU,CAAC,QAAQ,KAAA,EAAE,SAAS,KAAA,OAMtC;AAED;;;;;;GAMG;AACH,iBAAS,QAAQ,CAAC,UAAU,KAAA,EAAE,QAAQ,KAAA,UAOrC;AAED;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,UAAU,KAAA,OAQ/B;;;;;;;;;;;;;;;;;IAiCG;;OAEG;;;;;;;;AAjCP,wBAwCE"}
package/lib/utils/fs.js CHANGED
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
7
  const mkdirp_1 = __importDefault(require("mkdirp"));
8
8
  const destroy_1 = __importDefault(require("destroy"));
9
- const tmp_1 = __importDefault(require("tmp"));
10
9
  const path_1 = __importDefault(require("path"));
10
+ const os_1 = __importDefault(require("os"));
11
+ const crypto_1 = __importDefault(require("crypto"));
11
12
  const cp_1 = __importDefault(require("cp"));
12
13
  const cpr_1 = __importDefault(require("cpr"));
13
14
  const promise_1 = __importDefault(require("./promise"));
@@ -49,17 +50,44 @@ function fileExists(filename) {
49
50
  });
50
51
  return d.promise;
51
52
  }
53
+ function getTmpDir() {
54
+ try {
55
+ return fs_1.default.realpathSync.native(os_1.default.tmpdir());
56
+ }
57
+ catch {
58
+ return os_1.default.tmpdir();
59
+ }
60
+ }
52
61
  // Generate temporary file
53
- function genTmpFile(opts) {
54
- return promise_1.default.nfcall(tmp_1.default.file, opts).get(0);
62
+ function genTmpFile() {
63
+ return (0, promise_1.default)((async () => {
64
+ const tmpDir = getTmpDir();
65
+ for (let i = 0; i < 10; i++) {
66
+ const name = `honkit-${process.pid}-${Date.now()}-${crypto_1.default.randomBytes(6).toString("hex")}`;
67
+ const filePath = path_1.default.join(tmpDir, name);
68
+ let handle;
69
+ try {
70
+ handle = await fs_1.default.promises.open(filePath, fs_1.default.constants.O_CREAT | fs_1.default.constants.O_EXCL | fs_1.default.constants.O_RDWR, 0o600);
71
+ return filePath;
72
+ }
73
+ catch (error) {
74
+ if (error.code !== "EEXIST") {
75
+ throw error;
76
+ }
77
+ }
78
+ finally {
79
+ await handle?.close();
80
+ }
81
+ }
82
+ throw new Error("Could not create a unique temporary file");
83
+ })());
55
84
  }
56
85
  /**
57
86
  * Generate temporary dir
58
87
  * @deprecated use tmpdir.ts
59
- * @param opts
60
88
  */
61
- function genTmpDir(opts) {
62
- return promise_1.default.nfcall(tmp_1.default.dir, opts).get(0);
89
+ function genTmpDir() {
90
+ return (0, promise_1.default)(fs_1.default.promises.mkdtemp(path_1.default.join(getTmpDir(), "honkit-")));
63
91
  }
64
92
  // https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries
65
93
  const downloadStream = (url, dest, cb) => {
@@ -1 +1 @@
1
- {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAUA,iBAAS,GAAG,SAGX;kBAHQ,GAAG;;;;;;;;AAkIZ,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAUA,iBAAS,GAAG,SAGX;kBAHQ,GAAG;;;;;;;;AAiIZ,eAAe,GAAG,CAAC"}
package/lib/utils/git.js CHANGED
@@ -24,7 +24,6 @@ Git.prototype.allocateDir = function () {
24
24
  const that = this;
25
25
  if (this.tmpDir)
26
26
  return (0, promise_1.default)();
27
- // @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0.
28
27
  return fs_1.default.tmpDir().then((dir) => {
29
28
  that.tmpDir = dir;
30
29
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honkit",
3
- "version": "6.2.1",
3
+ "version": "6.2.2",
4
4
  "description": "HonKit is building beautiful books using Markdown.",
5
5
  "keywords": [
6
6
  "git",
@@ -70,13 +70,12 @@
70
70
  "semver": "^7.6.3",
71
71
  "send": "^0.19.2",
72
72
  "tiny-lr": "^1.1.1",
73
- "tmp": "0.2.4",
74
- "@honkit/asciidoc": "6.2.1",
75
- "@honkit/honkit-plugin-fontsettings": "6.2.1",
76
- "@honkit/honkit-plugin-highlight": "6.2.1",
77
- "@honkit/honkit-plugin-theme-default": "6.2.1",
78
- "@honkit/html": "6.2.1",
79
- "@honkit/markdown-legacy": "6.2.1"
73
+ "@honkit/honkit-plugin-fontsettings": "6.2.2",
74
+ "@honkit/honkit-plugin-highlight": "6.2.2",
75
+ "@honkit/asciidoc": "6.2.2",
76
+ "@honkit/honkit-plugin-theme-default": "6.2.2",
77
+ "@honkit/html": "6.2.2",
78
+ "@honkit/markdown-legacy": "6.2.2"
80
79
  },
81
80
  "devDependencies": {
82
81
  "@relmify/jest-serializer-strip-ansi": "^1.0.2",
@@ -88,7 +87,7 @@
88
87
  "object-path": "^0.11.8",
89
88
  "rimraf": "^6.0.1",
90
89
  "typescript": "^5.6.2",
91
- "@honkit/internal-test-utils": "6.2.1"
90
+ "@honkit/internal-test-utils": "6.2.2"
92
91
  },
93
92
  "scripts": {
94
93
  "build": "tsc -p .",