@docusaurus/bundler 0.0.0-6102 → 0.0.0-6105
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/minifyHtml.d.ts +5 -1
- package/lib/minifyHtml.d.ts.map +1 -1
- package/lib/minifyHtml.js +10 -35
- package/lib/minifyHtml.js.map +1 -1
- package/package.json +7 -7
- package/src/minifyHtml.ts +19 -47
package/lib/minifyHtml.d.ts
CHANGED
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
+
export type HtmlMinifierResult = {
|
|
9
|
+
code: string;
|
|
10
|
+
warnings: string[];
|
|
11
|
+
};
|
|
8
12
|
export type HtmlMinifier = {
|
|
9
|
-
minify: (html: string) => Promise<
|
|
13
|
+
minify: (html: string) => Promise<HtmlMinifierResult>;
|
|
10
14
|
};
|
|
11
15
|
type SiteConfigSlice = {
|
|
12
16
|
future: {
|
package/lib/minifyHtml.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minifyHtml.d.ts","sourceRoot":"","sources":["../src/minifyHtml.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"minifyHtml.d.ts","sourceRoot":"","sources":["../src/minifyHtml.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAKxD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACvD,CAAC;AAMF,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE;QACN,mBAAmB,EAAE,IAAI,CACvB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EACjD,kBAAkB,CACnB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,wBAAsB,eAAe,CAAC,EACpC,UAAU,GACX,EAAE;IACD,UAAU,EAAE,eAAe,CAAC;CAC7B,GAAG,OAAO,CAAC,YAAY,CAAC,CASxB"}
|
package/lib/minifyHtml.js
CHANGED
|
@@ -7,14 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getHtmlMinifier = getHtmlMinifier;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
10
|
const html_minifier_terser_1 = require("html-minifier-terser");
|
|
13
11
|
const importFaster_1 = require("./importFaster");
|
|
14
12
|
// Historical env variable
|
|
15
13
|
const SkipHtmlMinification = process.env.SKIP_HTML_MINIFICATION === 'true';
|
|
16
14
|
const NoopMinifier = {
|
|
17
|
-
minify: async (html) => html,
|
|
15
|
+
minify: async (html) => ({ code: html, warnings: [] }),
|
|
18
16
|
};
|
|
19
17
|
async function getHtmlMinifier({ siteConfig, }) {
|
|
20
18
|
if (SkipHtmlMinification) {
|
|
@@ -32,7 +30,7 @@ async function getTerserMinifier() {
|
|
|
32
30
|
return {
|
|
33
31
|
minify: async function minifyHtmlWithTerser(html) {
|
|
34
32
|
try {
|
|
35
|
-
|
|
33
|
+
const code = await (0, html_minifier_terser_1.minify)(html, {
|
|
36
34
|
removeComments: false,
|
|
37
35
|
removeRedundantAttributes: true,
|
|
38
36
|
removeEmptyAttributes: true,
|
|
@@ -41,6 +39,7 @@ async function getTerserMinifier() {
|
|
|
41
39
|
useShortDoctype: true,
|
|
42
40
|
minifyJS: true,
|
|
43
41
|
});
|
|
42
|
+
return { code, warnings: [] };
|
|
44
43
|
}
|
|
45
44
|
catch (err) {
|
|
46
45
|
throw new Error(`HTML minification failed (Terser)`, {
|
|
@@ -74,37 +73,13 @@ async function getSwcMinifier() {
|
|
|
74
73
|
minifyJson: true,
|
|
75
74
|
minifyCss: true,
|
|
76
75
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// TODO Docusaurus seems to emit NULL chars, and minifier detects it
|
|
85
|
-
// see https://github.com/facebook/docusaurus/issues/9985
|
|
86
|
-
'Unexpected null character',
|
|
87
|
-
];
|
|
88
|
-
result.errors = result.errors.filter((diagnostic) => !ignoredErrors.includes(diagnostic.message));
|
|
89
|
-
if (result.errors.length) {
|
|
90
|
-
throw new Error(`HTML minification diagnostic errors:
|
|
91
|
-
- ${result.errors
|
|
92
|
-
.map((diagnostic) => `[${diagnostic.level}] ${diagnostic.message} - ${JSON.stringify(diagnostic.span)}`)
|
|
93
|
-
.join('\n- ')}
|
|
94
|
-
Note: please report the problem to the Docusaurus team
|
|
95
|
-
In the meantime, you can skip this error with ${logger_1.default.code('DOCUSAURUS_IGNORE_SWC_HTML_MINIFIER_ERRORS=true')}`);
|
|
96
|
-
}
|
|
97
|
-
/*
|
|
98
|
-
if (result.errors.length) {
|
|
99
|
-
throw new AggregateError(
|
|
100
|
-
result.errors.map(
|
|
101
|
-
(diagnostic) => new Error(JSON.stringify(diagnostic, null, 2)),
|
|
102
|
-
),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
*/
|
|
106
|
-
}
|
|
107
|
-
return result.code;
|
|
76
|
+
const warnings = (result.errors ?? []).map((diagnostic) => {
|
|
77
|
+
return `[HTML minifier diagnostic - ${diagnostic.level}] ${diagnostic.message} - ${JSON.stringify(diagnostic.span)}`;
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
code: result.code,
|
|
81
|
+
warnings,
|
|
82
|
+
};
|
|
108
83
|
}
|
|
109
84
|
catch (err) {
|
|
110
85
|
throw new Error(`HTML minification failed (SWC)`, {
|
package/lib/minifyHtml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minifyHtml.js","sourceRoot":"","sources":["../src/minifyHtml.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"minifyHtml.js","sourceRoot":"","sources":["../src/minifyHtml.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA+BH,0CAaC;AA1CD,+DAAkE;AAClE,iDAAqD;AAGrD,0BAA0B;AAC1B,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,MAAM,CAAC;AAW3E,MAAM,YAAY,GAAiB;IACjC,MAAM,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAC,CAAC;CAC7D,CAAC;AAWK,KAAK,UAAU,eAAe,CAAC,EACpC,UAAU,GAGX;IACC,IAAI,oBAAoB,EAAE,CAAC;QACzB,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,CAAC;QAC3D,OAAO,cAAc,EAAE,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,OAAO,iBAAiB,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,qEAAqE;AACrE,KAAK,UAAU,iBAAiB;IAC9B,OAAO;QACL,MAAM,EAAE,KAAK,UAAU,oBAAoB,CAAC,IAAI;YAC9C,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAA,6BAAkB,EAAC,IAAI,EAAE;oBAC1C,cAAc,EAAE,KAAK;oBACrB,yBAAyB,EAAE,IAAI;oBAC/B,qBAAqB,EAAE,IAAI;oBAC3B,0BAA0B,EAAE,IAAI;oBAChC,6BAA6B,EAAE,IAAI;oBACnC,eAAe,EAAE,IAAI;oBACrB,Q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Q;iBACT,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,gCAAgC,EAAE;oBAChD,KAAK,EAAE,GAAY;iBACpB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/bundler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-6105",
|
|
4
4
|
"description": "Docusaurus util package to abstract the current bundler.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/core": "^7.23.3",
|
|
22
|
-
"@docusaurus/babel": "0.0.0-
|
|
23
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
24
|
-
"@docusaurus/logger": "0.0.0-
|
|
25
|
-
"@docusaurus/types": "0.0.0-
|
|
26
|
-
"@docusaurus/utils": "0.0.0-
|
|
22
|
+
"@docusaurus/babel": "0.0.0-6105",
|
|
23
|
+
"@docusaurus/cssnano-preset": "0.0.0-6105",
|
|
24
|
+
"@docusaurus/logger": "0.0.0-6105",
|
|
25
|
+
"@docusaurus/types": "0.0.0-6105",
|
|
26
|
+
"@docusaurus/utils": "0.0.0-6105",
|
|
27
27
|
"autoprefixer": "^10.4.14",
|
|
28
28
|
"babel-loader": "^9.1.3",
|
|
29
29
|
"clean-css": "^5.3.2",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=18.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "b46becffec32979bc2fcdb4d1be8e77100c06a21"
|
|
62
62
|
}
|
package/src/minifyHtml.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import logger from '@docusaurus/logger';
|
|
9
8
|
import {minify as terserHtmlMinifier} from 'html-minifier-terser';
|
|
10
9
|
import {importSwcHtmlMinifier} from './importFaster';
|
|
11
10
|
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
@@ -13,12 +12,17 @@ import type {DocusaurusConfig} from '@docusaurus/types';
|
|
|
13
12
|
// Historical env variable
|
|
14
13
|
const SkipHtmlMinification = process.env.SKIP_HTML_MINIFICATION === 'true';
|
|
15
14
|
|
|
15
|
+
export type HtmlMinifierResult = {
|
|
16
|
+
code: string;
|
|
17
|
+
warnings: string[];
|
|
18
|
+
};
|
|
19
|
+
|
|
16
20
|
export type HtmlMinifier = {
|
|
17
|
-
minify: (html: string) => Promise<
|
|
21
|
+
minify: (html: string) => Promise<HtmlMinifierResult>;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
const NoopMinifier: HtmlMinifier = {
|
|
21
|
-
minify: async (html: string) => html,
|
|
25
|
+
minify: async (html: string) => ({code: html, warnings: []}),
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
type SiteConfigSlice = {
|
|
@@ -50,7 +54,7 @@ async function getTerserMinifier(): Promise<HtmlMinifier> {
|
|
|
50
54
|
return {
|
|
51
55
|
minify: async function minifyHtmlWithTerser(html) {
|
|
52
56
|
try {
|
|
53
|
-
|
|
57
|
+
const code = await terserHtmlMinifier(html, {
|
|
54
58
|
removeComments: false,
|
|
55
59
|
removeRedundantAttributes: true,
|
|
56
60
|
removeEmptyAttributes: true,
|
|
@@ -59,6 +63,7 @@ async function getTerserMinifier(): Promise<HtmlMinifier> {
|
|
|
59
63
|
useShortDoctype: true,
|
|
60
64
|
minifyJS: true,
|
|
61
65
|
});
|
|
66
|
+
return {code, warnings: []};
|
|
62
67
|
} catch (err) {
|
|
63
68
|
throw new Error(`HTML minification failed (Terser)`, {
|
|
64
69
|
cause: err as Error,
|
|
@@ -95,49 +100,16 @@ async function getSwcMinifier(): Promise<HtmlMinifier> {
|
|
|
95
100
|
minifyCss: true,
|
|
96
101
|
});
|
|
97
102
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'Unexpected null character',
|
|
109
|
-
];
|
|
110
|
-
result.errors = result.errors.filter(
|
|
111
|
-
(diagnostic) => !ignoredErrors.includes(diagnostic.message),
|
|
112
|
-
);
|
|
113
|
-
if (result.errors.length) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
`HTML minification diagnostic errors:
|
|
116
|
-
- ${result.errors
|
|
117
|
-
.map(
|
|
118
|
-
(diagnostic) =>
|
|
119
|
-
`[${diagnostic.level}] ${
|
|
120
|
-
diagnostic.message
|
|
121
|
-
} - ${JSON.stringify(diagnostic.span)}`,
|
|
122
|
-
)
|
|
123
|
-
.join('\n- ')}
|
|
124
|
-
Note: please report the problem to the Docusaurus team
|
|
125
|
-
In the meantime, you can skip this error with ${logger.code(
|
|
126
|
-
'DOCUSAURUS_IGNORE_SWC_HTML_MINIFIER_ERRORS=true',
|
|
127
|
-
)}`,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
/*
|
|
131
|
-
if (result.errors.length) {
|
|
132
|
-
throw new AggregateError(
|
|
133
|
-
result.errors.map(
|
|
134
|
-
(diagnostic) => new Error(JSON.stringify(diagnostic, null, 2)),
|
|
135
|
-
),
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
*/
|
|
139
|
-
}
|
|
140
|
-
return result.code;
|
|
103
|
+
const warnings = (result.errors ?? []).map((diagnostic) => {
|
|
104
|
+
return `[HTML minifier diagnostic - ${diagnostic.level}] ${
|
|
105
|
+
diagnostic.message
|
|
106
|
+
} - ${JSON.stringify(diagnostic.span)}`;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
code: result.code,
|
|
111
|
+
warnings,
|
|
112
|
+
};
|
|
141
113
|
} catch (err) {
|
|
142
114
|
throw new Error(`HTML minification failed (SWC)`, {
|
|
143
115
|
cause: err as Error,
|