@honkit/internal-test-utils 7.0.4 → 7.1.0
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.
- package/lib/index.d.ts +3 -0
- package/lib/index.js +9 -1
- package/lib/index.js.map +1 -1
- package/lib/normalizeOutput.d.ts +10 -0
- package/lib/normalizeOutput.js +82 -0
- package/lib/normalizeOutput.js.map +1 -0
- package/lib/outputSnapshot.d.ts +73 -0
- package/lib/outputSnapshot.js +105 -0
- package/lib/outputSnapshot.js.map +1 -0
- package/package.json +1 -9
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
1
|
export { directorySnapshotFile, iterateDirectoryContents } from "./directorySnapshot";
|
|
2
|
+
export { FILE_LIST_NAME, readOutputDirectory, compareWithSnapshotDirectory, hasMismatch } from "./outputSnapshot";
|
|
3
|
+
export type { SnapshotUpdateMode, OutputSnapshot, ReadOutputDirectoryOptions, SnapshotMismatch, CompareResult } from "./outputSnapshot";
|
|
4
|
+
export { normalizeHtml, normalizeJson } from "./normalizeOutput";
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.iterateDirectoryContents = void 0;
|
|
3
|
+
exports.normalizeJson = exports.normalizeHtml = exports.hasMismatch = exports.compareWithSnapshotDirectory = exports.readOutputDirectory = exports.FILE_LIST_NAME = exports.iterateDirectoryContents = void 0;
|
|
4
4
|
var directorySnapshot_1 = require("./directorySnapshot");
|
|
5
5
|
Object.defineProperty(exports, "iterateDirectoryContents", { enumerable: true, get: function () { return directorySnapshot_1.iterateDirectoryContents; } });
|
|
6
|
+
var outputSnapshot_1 = require("./outputSnapshot");
|
|
7
|
+
Object.defineProperty(exports, "FILE_LIST_NAME", { enumerable: true, get: function () { return outputSnapshot_1.FILE_LIST_NAME; } });
|
|
8
|
+
Object.defineProperty(exports, "readOutputDirectory", { enumerable: true, get: function () { return outputSnapshot_1.readOutputDirectory; } });
|
|
9
|
+
Object.defineProperty(exports, "compareWithSnapshotDirectory", { enumerable: true, get: function () { return outputSnapshot_1.compareWithSnapshotDirectory; } });
|
|
10
|
+
Object.defineProperty(exports, "hasMismatch", { enumerable: true, get: function () { return outputSnapshot_1.hasMismatch; } });
|
|
11
|
+
var normalizeOutput_1 = require("./normalizeOutput");
|
|
12
|
+
Object.defineProperty(exports, "normalizeHtml", { enumerable: true, get: function () { return normalizeOutput_1.normalizeHtml; } });
|
|
13
|
+
Object.defineProperty(exports, "normalizeJson", { enumerable: true, get: function () { return normalizeOutput_1.normalizeJson; } });
|
|
6
14
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAsF;AAAtD,6HAAA,wBAAwB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAsF;AAAtD,6HAAA,wBAAwB,OAAA;AACxD,mDAAkH;AAAzG,gHAAA,cAAc,OAAA;AAAE,qHAAA,mBAAmB,OAAA;AAAE,8HAAA,4BAA4B,OAAA;AAAE,6GAAA,WAAW,OAAA;AAQvF,qDAAiE;AAAxD,gHAAA,aAAa,OAAA;AAAE,gHAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizers for the files that `honkit build` writes.
|
|
3
|
+
* They replace only the values that differ between builds:
|
|
4
|
+
* the HonKit version, the build time and the modified time of the source file.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeHtml(content: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Print as indented JSON with sorted keys to make the diff readable
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeJson(content: string): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizers for the files that `honkit build` writes.
|
|
4
|
+
* They replace only the values that differ between builds:
|
|
5
|
+
* the HonKit version, the build time and the modified time of the source file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.normalizeHtml = normalizeHtml;
|
|
9
|
+
exports.normalizeJson = normalizeJson;
|
|
10
|
+
const PAGE_CONTEXT_PATTERN = /(<script type="application\/json" id="honkit-page-context">)([\s\S]*?)(<\/script>)/;
|
|
11
|
+
/**
|
|
12
|
+
* The page context is the state that the theme and the plugins read in a browser.
|
|
13
|
+
* It is written as one line of JSON, so print it as indented JSON to make the diff readable.
|
|
14
|
+
*/
|
|
15
|
+
function normalizePageContext(json) {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const context = JSON.parse(json);
|
|
18
|
+
if (((_a = context.file) === null || _a === void 0 ? void 0 : _a.mtime) !== undefined) {
|
|
19
|
+
context.file.mtime = "<MTIME>";
|
|
20
|
+
}
|
|
21
|
+
if (((_b = context.gitbook) === null || _b === void 0 ? void 0 : _b.version) !== undefined) {
|
|
22
|
+
context.gitbook.version = "<VERSION>";
|
|
23
|
+
}
|
|
24
|
+
if (((_c = context.gitbook) === null || _c === void 0 ? void 0 : _c.time) !== undefined) {
|
|
25
|
+
context.gitbook.time = "<TIME>";
|
|
26
|
+
}
|
|
27
|
+
return `\n${JSON.stringify(context, null, 2)}\n`;
|
|
28
|
+
}
|
|
29
|
+
function normalizeHtml(content) {
|
|
30
|
+
return content
|
|
31
|
+
.replace(/(<meta name="generator" content="HonKit )[^"]*(">)/g, "$1<VERSION>$2")
|
|
32
|
+
.replace(PAGE_CONTEXT_PATTERN, (_all, open, json, close) => {
|
|
33
|
+
return `${open}${normalizePageContext(json)}${close}`;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The keys of the objects that hold the HonKit version and the build time.
|
|
38
|
+
* The json format writes both `gitbook` and `honkit` for compatibility with GitBook.
|
|
39
|
+
*/
|
|
40
|
+
const VERSION_OBJECT_KEYS = new Set(["gitbook", "honkit"]);
|
|
41
|
+
/**
|
|
42
|
+
* Replace the values that differ between builds in a JSON value of the json format.
|
|
43
|
+
* - `mtime` of every file (SUMMARY.md, README.md, the page)
|
|
44
|
+
* - `version` and `time` of `gitbook` and `honkit`
|
|
45
|
+
* The other values, such as the `version` of the json format itself, are kept.
|
|
46
|
+
*
|
|
47
|
+
* The keys of every object are sorted. The order of arrays is kept.
|
|
48
|
+
* The pages are rendered in parallel, so the key order of `search_index.json` changes between builds.
|
|
49
|
+
* The key order of a JSON object has no meaning, so it is not a part of the snapshot.
|
|
50
|
+
*/
|
|
51
|
+
function normalizeJsonValue(value, parentKey) {
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map((item) => normalizeJsonValue(item));
|
|
54
|
+
}
|
|
55
|
+
if (value === null || typeof value !== "object") {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
const result = {};
|
|
59
|
+
for (const key of Object.keys(value).sort()) {
|
|
60
|
+
const child = value[key];
|
|
61
|
+
if (key === "mtime" && typeof child === "string") {
|
|
62
|
+
result[key] = "<MTIME>";
|
|
63
|
+
}
|
|
64
|
+
else if (parentKey !== undefined && VERSION_OBJECT_KEYS.has(parentKey) && key === "version") {
|
|
65
|
+
result[key] = "<VERSION>";
|
|
66
|
+
}
|
|
67
|
+
else if (parentKey !== undefined && VERSION_OBJECT_KEYS.has(parentKey) && key === "time") {
|
|
68
|
+
result[key] = "<TIME>";
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
result[key] = normalizeJsonValue(child, key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Print as indented JSON with sorted keys to make the diff readable
|
|
78
|
+
*/
|
|
79
|
+
function normalizeJson(content) {
|
|
80
|
+
return `${JSON.stringify(normalizeJsonValue(JSON.parse(content)), null, 2)}\n`;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=normalizeOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeOutput.js","sourceRoot":"","sources":["../src/normalizeOutput.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA2BH,sCAMC;AA4CD,sCAEC;AA7ED,MAAM,oBAAoB,GAAG,oFAAoF,CAAC;AAOlH;;;GAGG;AACH,SAAS,oBAAoB,CAAC,IAAY;;IACtC,MAAM,OAAO,GAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAA,MAAA,OAAO,CAAC,IAAI,0CAAE,KAAK,MAAK,SAAS,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACnC,CAAC;IACD,IAAI,CAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,OAAO,MAAK,SAAS,EAAE,CAAC;QACzC,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG,WAAW,CAAC;IAC1C,CAAC;IACD,IAAI,CAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,IAAI,MAAK,SAAS,EAAE,CAAC;QACtC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC;IACpC,CAAC;IACD,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED,SAAgB,aAAa,CAAC,OAAe;IACzC,OAAO,OAAO;SACT,OAAO,CAAC,qDAAqD,EAAE,eAAe,CAAC;SAC/E,OAAO,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,IAAY,EAAE,IAAY,EAAE,KAAa,EAAE,EAAE;QAC/E,OAAO,GAAG,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC;IA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E,GAAG,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,OAAe;IACzC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name of the snapshot file that lists every file of the output directory.
|
|
3
|
+
* It makes a test fail when a build starts or stops writing a file,
|
|
4
|
+
* including the files whose content is not compared.
|
|
5
|
+
*/
|
|
6
|
+
export declare const FILE_LIST_NAME = "__files__.txt";
|
|
7
|
+
/**
|
|
8
|
+
* - "all": write the snapshot directory from the actual output (`vitest -u`)
|
|
9
|
+
* - "new": write it only when the snapshot directory does not exist yet
|
|
10
|
+
* - "none": never write (CI)
|
|
11
|
+
*/
|
|
12
|
+
export type SnapshotUpdateMode = "all" | "new" | "none";
|
|
13
|
+
export type OutputSnapshot = Map<string, string>;
|
|
14
|
+
export type ReadOutputDirectoryOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Directory that the build wrote to
|
|
17
|
+
*/
|
|
18
|
+
outputDir: string;
|
|
19
|
+
/**
|
|
20
|
+
* Return true to compare the content of the file.
|
|
21
|
+
* A file that returns false is only recorded in the file list.
|
|
22
|
+
* `filePath` is relative to `outputDir` and uses "/" on every OS.
|
|
23
|
+
*/
|
|
24
|
+
includeContent: (filePath: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Replace the parts that differ between builds, such as the build time
|
|
27
|
+
*/
|
|
28
|
+
normalize?: (filePath: string, content: string) => string;
|
|
29
|
+
};
|
|
30
|
+
export type SnapshotMismatch = {
|
|
31
|
+
/**
|
|
32
|
+
* Files that the build wrote but the snapshot does not have
|
|
33
|
+
*/
|
|
34
|
+
added: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Files that the snapshot has but the build did not write
|
|
37
|
+
*/
|
|
38
|
+
removed: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Files whose content differs
|
|
41
|
+
*/
|
|
42
|
+
changed: {
|
|
43
|
+
filePath: string;
|
|
44
|
+
expected: string;
|
|
45
|
+
actual: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
export type CompareResult = {
|
|
49
|
+
/**
|
|
50
|
+
* true when the snapshot directory was written during this call
|
|
51
|
+
*/
|
|
52
|
+
written: boolean;
|
|
53
|
+
mismatch: SnapshotMismatch;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Read an output directory as a snapshot.
|
|
57
|
+
*
|
|
58
|
+
* The snapshot has one entry per compared file, and a file list (`__files__.txt`)
|
|
59
|
+
* that has every file of the directory.
|
|
60
|
+
*/
|
|
61
|
+
export declare function readOutputDirectory({ outputDir, includeContent, normalize }: ReadOutputDirectoryOptions): OutputSnapshot;
|
|
62
|
+
/**
|
|
63
|
+
* Compare a snapshot with the files of the snapshot directory.
|
|
64
|
+
*
|
|
65
|
+
* A snapshot directory has the same structure as the output directory,
|
|
66
|
+
* so a change of the output is reviewed as a diff of each file.
|
|
67
|
+
*/
|
|
68
|
+
export declare function compareWithSnapshotDirectory({ actual, snapshotDir, update }: {
|
|
69
|
+
actual: OutputSnapshot;
|
|
70
|
+
snapshotDir: string;
|
|
71
|
+
update: SnapshotUpdateMode;
|
|
72
|
+
}): CompareResult;
|
|
73
|
+
export declare function hasMismatch(mismatch: SnapshotMismatch): boolean;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
exports.FILE_LIST_NAME = void 0;
|
|
7
|
+
exports.readOutputDirectory = readOutputDirectory;
|
|
8
|
+
exports.compareWithSnapshotDirectory = compareWithSnapshotDirectory;
|
|
9
|
+
exports.hasMismatch = hasMismatch;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
/**
|
|
13
|
+
* Name of the snapshot file that lists every file of the output directory.
|
|
14
|
+
* It makes a test fail when a build starts or stops writing a file,
|
|
15
|
+
* including the files whose content is not compared.
|
|
16
|
+
*/
|
|
17
|
+
exports.FILE_LIST_NAME = "__files__.txt";
|
|
18
|
+
const toPosixPath = (filePath) => filePath.split(path_1.default.sep).join("/");
|
|
19
|
+
// Sort by code unit, not by locale, so that the order is the same on every OS
|
|
20
|
+
const compareString = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
21
|
+
// Git on Windows may check out text files with CRLF
|
|
22
|
+
const normalizeNewline = (content) => content.replace(/\r\n/g, "\n");
|
|
23
|
+
function listFiles(baseDir) {
|
|
24
|
+
const results = [];
|
|
25
|
+
const walk = (dir) => {
|
|
26
|
+
for (const dirent of fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
27
|
+
const filePath = path_1.default.join(dir, dirent.name);
|
|
28
|
+
if (dirent.isDirectory()) {
|
|
29
|
+
walk(filePath);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
results.push(toPosixPath(path_1.default.relative(baseDir, filePath)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (fs_1.default.existsSync(baseDir)) {
|
|
37
|
+
walk(baseDir);
|
|
38
|
+
}
|
|
39
|
+
return results.sort(compareString);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read an output directory as a snapshot.
|
|
43
|
+
*
|
|
44
|
+
* The snapshot has one entry per compared file, and a file list (`__files__.txt`)
|
|
45
|
+
* that has every file of the directory.
|
|
46
|
+
*/
|
|
47
|
+
function readOutputDirectory({ outputDir, includeContent, normalize = (_filePath, content) => content }) {
|
|
48
|
+
const snapshot = new Map();
|
|
49
|
+
const filePaths = listFiles(outputDir);
|
|
50
|
+
if (filePaths.includes(exports.FILE_LIST_NAME)) {
|
|
51
|
+
throw new Error(`The output directory has "${exports.FILE_LIST_NAME}". It conflicts with the file list.`);
|
|
52
|
+
}
|
|
53
|
+
snapshot.set(exports.FILE_LIST_NAME, `${filePaths.join("\n")}\n`);
|
|
54
|
+
for (const filePath of filePaths) {
|
|
55
|
+
if (!includeContent(filePath)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const content = fs_1.default.readFileSync(path_1.default.join(outputDir, filePath), "utf-8");
|
|
59
|
+
snapshot.set(filePath, normalizeNewline(normalize(filePath, normalizeNewline(content))));
|
|
60
|
+
}
|
|
61
|
+
return snapshot;
|
|
62
|
+
}
|
|
63
|
+
function writeSnapshotDirectory(snapshotDir, actual) {
|
|
64
|
+
// Remove the snapshot files that the build does not write anymore
|
|
65
|
+
fs_1.default.rmSync(snapshotDir, { recursive: true, force: true });
|
|
66
|
+
for (const [filePath, content] of actual) {
|
|
67
|
+
const snapshotFilePath = path_1.default.join(snapshotDir, filePath);
|
|
68
|
+
fs_1.default.mkdirSync(path_1.default.dirname(snapshotFilePath), { recursive: true });
|
|
69
|
+
fs_1.default.writeFileSync(snapshotFilePath, content);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Compare a snapshot with the files of the snapshot directory.
|
|
74
|
+
*
|
|
75
|
+
* A snapshot directory has the same structure as the output directory,
|
|
76
|
+
* so a change of the output is reviewed as a diff of each file.
|
|
77
|
+
*/
|
|
78
|
+
function compareWithSnapshotDirectory({ actual, snapshotDir, update }) {
|
|
79
|
+
const noMismatch = { added: [], removed: [], changed: [] };
|
|
80
|
+
if (update === "all" || (update === "new" && !fs_1.default.existsSync(snapshotDir))) {
|
|
81
|
+
writeSnapshotDirectory(snapshotDir, actual);
|
|
82
|
+
return { written: true, mismatch: noMismatch };
|
|
83
|
+
}
|
|
84
|
+
const expectedFilePaths = listFiles(snapshotDir);
|
|
85
|
+
const mismatch = {
|
|
86
|
+
added: [...actual.keys()].filter((filePath) => !expectedFilePaths.includes(filePath)).sort(compareString),
|
|
87
|
+
removed: expectedFilePaths.filter((filePath) => !actual.has(filePath)),
|
|
88
|
+
changed: []
|
|
89
|
+
};
|
|
90
|
+
for (const filePath of expectedFilePaths) {
|
|
91
|
+
const actualContent = actual.get(filePath);
|
|
92
|
+
if (actualContent === undefined) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const expectedContent = normalizeNewline(fs_1.default.readFileSync(path_1.default.join(snapshotDir, filePath), "utf-8"));
|
|
96
|
+
if (expectedContent !== actualContent) {
|
|
97
|
+
mismatch.changed.push({ filePath, expected: expectedContent, actual: actualContent });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { written: false, mismatch };
|
|
101
|
+
}
|
|
102
|
+
function hasMismatch(mismatch) {
|
|
103
|
+
return mismatch.added.length > 0 || mismatch.removed.length > 0 || mismatch.changed.length > 0;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=outputSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputSnapshot.js","sourceRoot":"","sources":["../src/outputSnapshot.ts"],"names":[],"mappings":";;;;;;AA2FA,kDAmBC;AAkBD,oEA+BC;AAED,kCAEC;AAnKD,4CAAoB;AACpB,gDAAwB;AAExB;;;;GAIG;AACU,QAAA,cAAc,GAAG,eAAe,CAAC;AAmD9C,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE7E,8EAA8E;AAC9E,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC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;YACpC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QAC1F,CAAC;IACL,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC;AAED,SAAgB,WAAW,CAAC,QAA0B;IAClD,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AACnG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@honkit/internal-test-utils",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Internal utility for testing.",
|
|
5
5
|
"homepage": "https://github.com/honkit/honkit/tree/master/packages/@honkit/internal-test-utils/",
|
|
6
6
|
"bugs": {
|
|
@@ -22,15 +22,8 @@
|
|
|
22
22
|
"bin/",
|
|
23
23
|
"lib/"
|
|
24
24
|
],
|
|
25
|
-
"prettier": {
|
|
26
|
-
"singleQuote": false,
|
|
27
|
-
"printWidth": 120,
|
|
28
|
-
"tabWidth": 4,
|
|
29
|
-
"trailingComma": "none"
|
|
30
|
-
},
|
|
31
25
|
"devDependencies": {
|
|
32
26
|
"@types/node": "^22.7.4",
|
|
33
|
-
"prettier": "^3.3.3",
|
|
34
27
|
"rimraf": "^6.0.1",
|
|
35
28
|
"typescript": "^5.6.2"
|
|
36
29
|
},
|
|
@@ -40,7 +33,6 @@
|
|
|
40
33
|
"scripts": {
|
|
41
34
|
"build": "tsc -p .",
|
|
42
35
|
"clean": "rimraf lib/",
|
|
43
|
-
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
|
|
44
36
|
"prepublish": "npm run --if-present build",
|
|
45
37
|
"watch": "tsc -p . --watch"
|
|
46
38
|
}
|