@docusaurus/core 2.0.0-beta.13 → 2.0.0-beta.15

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.
Files changed (90) hide show
  1. package/bin/beforeCli.js +14 -15
  2. package/bin/docusaurus.js +7 -5
  3. package/lib/babel/preset.d.ts +1 -1
  4. package/lib/choosePort.js +8 -8
  5. package/lib/client/LinksCollector.d.ts +1 -1
  6. package/lib/client/PendingNavigation.d.ts +2 -2
  7. package/lib/client/exports/BrowserOnly.d.ts +1 -1
  8. package/lib/client/exports/BrowserOnly.js +7 -2
  9. package/lib/client/exports/ErrorBoundary.d.ts +1 -1
  10. package/lib/client/exports/ErrorBoundary.js +3 -1
  11. package/lib/client/exports/Interpolate.d.ts +1 -1
  12. package/lib/client/exports/Translate.d.ts +2 -2
  13. package/lib/client/exports/browserContext.d.ts +1 -1
  14. package/lib/client/exports/docusaurusContext.d.ts +2 -2
  15. package/lib/client/exports/useBaseUrl.js +2 -2
  16. package/lib/client/exports/useDocusaurusContext.d.ts +1 -1
  17. package/lib/client/nprogress.css +2 -2
  18. package/lib/client/preload.d.ts +1 -1
  19. package/lib/client/serverEntry.d.ts +10 -0
  20. package/lib/client/serverEntry.js +86 -126
  21. package/lib/commands/build.d.ts +1 -1
  22. package/lib/commands/build.js +17 -15
  23. package/lib/commands/clear.js +10 -11
  24. package/lib/commands/commandUtils.d.ts +1 -1
  25. package/lib/commands/deploy.d.ts +1 -1
  26. package/lib/commands/deploy.js +12 -14
  27. package/lib/commands/external.d.ts +1 -1
  28. package/lib/commands/external.js +1 -1
  29. package/lib/commands/serve.d.ts +1 -1
  30. package/lib/commands/serve.js +2 -8
  31. package/lib/commands/start.d.ts +1 -1
  32. package/lib/commands/start.js +23 -22
  33. package/lib/commands/swizzle.d.ts +1 -1
  34. package/lib/commands/swizzle.js +26 -35
  35. package/lib/commands/writeHeadingIds.d.ts +1 -1
  36. package/lib/commands/writeHeadingIds.js +4 -5
  37. package/lib/commands/writeTranslations.d.ts +2 -2
  38. package/lib/commands/writeTranslations.js +1 -1
  39. package/lib/server/brokenLinks.d.ts +1 -1
  40. package/lib/server/brokenLinks.js +1 -2
  41. package/lib/server/client-modules/index.d.ts +1 -1
  42. package/lib/server/config.d.ts +2 -2
  43. package/lib/server/config.js +5 -2
  44. package/lib/server/configValidation.d.ts +1 -1
  45. package/lib/server/configValidation.js +5 -4
  46. package/lib/server/duplicateRoutes.d.ts +1 -1
  47. package/lib/server/html-tags/index.d.ts +1 -1
  48. package/lib/server/i18n.d.ts +1 -1
  49. package/lib/server/i18n.js +6 -14
  50. package/lib/server/index.d.ts +1 -1
  51. package/lib/server/index.js +26 -15
  52. package/lib/server/loadSetup.d.ts +1 -1
  53. package/lib/server/moduleShorthand.js +11 -7
  54. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
  55. package/lib/server/plugins/index.d.ts +1 -1
  56. package/lib/server/plugins/index.js +3 -3
  57. package/lib/server/plugins/init.d.ts +2 -2
  58. package/lib/server/plugins/init.js +10 -9
  59. package/lib/server/plugins/pluginIds.d.ts +1 -1
  60. package/lib/server/presets/index.d.ts +1 -1
  61. package/lib/server/presets/index.js +1 -1
  62. package/lib/server/routes.d.ts +1 -1
  63. package/lib/server/routes.js +1 -2
  64. package/lib/server/themes/alias.d.ts +1 -1
  65. package/lib/server/themes/index.d.ts +1 -1
  66. package/lib/server/translations/translations.d.ts +1 -1
  67. package/lib/server/translations/translations.js +7 -12
  68. package/lib/server/translations/translationsExtractor.d.ts +2 -2
  69. package/lib/server/translations/translationsExtractor.js +123 -92
  70. package/lib/server/utils.d.ts +1 -1
  71. package/lib/server/versions/__tests/index.test.js +6 -5
  72. package/lib/server/versions/index.d.ts +1 -1
  73. package/lib/webpack/base.d.ts +2 -2
  74. package/lib/webpack/client.d.ts +2 -2
  75. package/lib/webpack/client.js +2 -2
  76. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +1 -1
  77. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +1 -1
  78. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  79. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  80. package/lib/webpack/server.d.ts +2 -2
  81. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  82. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  83. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  84. package/lib/webpack/utils.d.ts +4 -4
  85. package/lib/webpack/utils.js +19 -14
  86. package/package.json +22 -22
  87. package/lib/.tsbuildinfo +0 -1
  88. package/lib/client/.tsbuildinfo +0 -1
  89. package/tsconfig.client.json +0 -12
  90. package/tsconfig.json +0 -14
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
12
  const traverse_1 = (0, tslib_1.__importDefault)(require("@babel/traverse"));
13
13
  const generator_1 = (0, tslib_1.__importDefault)(require("@babel/generator"));
14
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
14
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
15
15
  const core_1 = require("@babel/core");
16
16
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
17
17
  const utils_1 = require("@docusaurus/utils");
@@ -23,7 +23,7 @@ const TranslatableSourceCodeExtension = new Set([
23
23
  '.ts',
24
24
  '.tsx',
25
25
  // TODO support md/mdx too? (may be overkill)
26
- // need to compile the MDX to JSX first and remove frontmatter
26
+ // need to compile the MDX to JSX first and remove front matter
27
27
  // '.md',
28
28
  // '.mdx',
29
29
  ]);
@@ -78,7 +78,7 @@ exports.extractSiteSourceCodeTranslations = extractSiteSourceCodeTranslations;
78
78
  function logSourceCodeFileTranslationsWarnings(sourceCodeFilesTranslations) {
79
79
  sourceCodeFilesTranslations.forEach(({ sourceCodeFilePath, warnings }) => {
80
80
  if (warnings.length > 0) {
81
- console.warn(`Translation extraction warnings for file path=${sourceCodeFilePath}:\n- ${chalk_1.default.yellow(warnings.join('\n\n- '))}`);
81
+ logger_1.default.warn `Translation extraction warnings for file path=${sourceCodeFilePath}: ${warnings}`;
82
82
  }
83
83
  });
84
84
  }
@@ -118,111 +118,142 @@ https://github.com/pugjs/babel-walk
118
118
  function extractSourceCodeAstTranslations(ast, sourceCodeFilePath) {
119
119
  function sourceWarningPart(node) {
120
120
  var _a;
121
- return `File: ${sourceCodeFilePath} at ${(_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line} line\nFull code: ${(0, generator_1.default)(node).code}`;
121
+ return `File: ${sourceCodeFilePath} at line ${(_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line}
122
+ Full code: ${(0, generator_1.default)(node).code}`;
122
123
  }
123
124
  const translations = {};
124
125
  const warnings = [];
125
- // TODO we should check the presence of the correct @docusaurus imports here!
126
+ let translateComponentName;
127
+ let translateFunctionName;
128
+ // First pass: find import declarations of Translate / translate.
129
+ // If not found, don't process the rest to avoid false positives
126
130
  (0, traverse_1.default)(ast, {
127
- JSXElement(path) {
128
- if (!path
129
- .get('openingElement')
130
- .get('name')
131
- .isJSXIdentifier({ name: 'Translate' })) {
131
+ ImportDeclaration(path) {
132
+ if (path.node.importKind === 'type' ||
133
+ path.get('source').node.value !== '@docusaurus/Translate') {
132
134
  return;
133
135
  }
134
- function evaluateJSXProp(propName) {
135
- const attributePath = path
136
- .get('openingElement.attributes')
137
- .find((attr) => attr.isJSXAttribute() &&
138
- attr
139
- .get('name')
140
- .isJSXIdentifier({ name: propName }));
141
- if (attributePath) {
142
- const attributeValue = attributePath.get('value');
143
- const attributeValueEvaluated = attributeValue.isJSXExpressionContainer()
144
- ? attributeValue.get('expression').evaluate()
145
- : attributeValue.evaluate();
146
- if (attributeValueEvaluated.confident &&
147
- typeof attributeValueEvaluated.value === 'string') {
148
- return attributeValueEvaluated.value;
136
+ const importSpecifiers = path.get('specifiers');
137
+ const defaultImport = importSpecifiers.find((specifier) => specifier.node.type === 'ImportDefaultSpecifier');
138
+ const callbackImport = importSpecifiers.find((specifier) => specifier.node.type === 'ImportSpecifier' &&
139
+ (specifier.get('imported')
140
+ .node.name === 'translate' ||
141
+ specifier.get('imported')
142
+ .node.value === 'translate'));
143
+ translateComponentName = defaultImport === null || defaultImport === void 0 ? void 0 : defaultImport.get('local').node.name;
144
+ translateFunctionName = callbackImport === null || callbackImport === void 0 ? void 0 : callbackImport.get('local').node.name;
145
+ },
146
+ });
147
+ (0, traverse_1.default)(ast, {
148
+ ...(translateComponentName && {
149
+ JSXElement(path) {
150
+ if (!path
151
+ .get('openingElement')
152
+ .get('name')
153
+ .isJSXIdentifier({ name: translateComponentName })) {
154
+ return;
155
+ }
156
+ function evaluateJSXProp(propName) {
157
+ const attributePath = path
158
+ .get('openingElement.attributes')
159
+ .find((attr) => attr.isJSXAttribute() &&
160
+ attr
161
+ .get('name')
162
+ .isJSXIdentifier({ name: propName }));
163
+ if (attributePath) {
164
+ const attributeValue = attributePath.get('value');
165
+ const attributeValueEvaluated = attributeValue.isJSXExpressionContainer()
166
+ ? attributeValue.get('expression').evaluate()
167
+ : attributeValue.evaluate();
168
+ if (attributeValueEvaluated.confident &&
169
+ typeof attributeValueEvaluated.value === 'string') {
170
+ return attributeValueEvaluated.value;
171
+ }
172
+ else {
173
+ warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.
174
+ Example: <Translate id="optional id" description="optional description">Message</Translate>
175
+ Dynamically constructed values are not allowed, because they prevent translations to be extracted.
176
+ ${sourceWarningPart(path.node)}`);
177
+ }
178
+ }
179
+ return undefined;
180
+ }
181
+ const id = evaluateJSXProp('id');
182
+ const description = evaluateJSXProp('description');
183
+ let message;
184
+ const childrenPath = path.get('children');
185
+ // Handle empty content
186
+ if (!childrenPath.length) {
187
+ if (!id) {
188
+ warnings.push(`<Translate> without children must have id prop.
189
+ Example: <Translate id="my-id" />
190
+ ${sourceWarningPart(path.node)}`);
149
191
  }
150
192
  else {
151
- warnings.push(`<Translate> prop=${propName} should be a statically evaluable object.\nExample: <Translate id="optional.id" description="optional description">Message</Translate>\nDynamically constructed values are not allowed, because they prevent translations to be extracted.\n${sourceWarningPart(path.node)}`);
193
+ translations[id] = {
194
+ message: message !== null && message !== void 0 ? message : id,
195
+ ...(description && { description }),
196
+ };
152
197
  }
198
+ return;
153
199
  }
154
- return undefined;
155
- }
156
- const id = evaluateJSXProp('id');
157
- const description = evaluateJSXProp('description');
158
- let message;
159
- const childrenPath = path.get('children');
160
- // Handle empty content
161
- if (!childrenPath.length) {
162
- if (!id) {
163
- warnings.push(`
164
- <Translate> without children must have id prop.\nExample: <Translate id="my-id" />\n${sourceWarningPart(path.node)}
165
- `);
166
- }
167
- else {
168
- translations[id] = {
169
- message: message !== null && message !== void 0 ? message : id,
170
- ...(description && { description }),
171
- };
172
- }
173
- return;
174
- }
175
- // Handle single non-empty content
176
- const singleChildren = childrenPath
177
- // Remove empty/useless text nodes that might be around our translation!
178
- // Makes the translation system more reliable to JSX formatting issues
179
- .filter((children) => !(children.isJSXText() &&
180
- children.node.value.replace('\n', '').trim() === ''))
181
- .pop();
182
- const isJSXText = singleChildren && singleChildren.isJSXText();
183
- const isJSXExpressionContainer = singleChildren &&
184
- singleChildren.isJSXExpressionContainer() &&
185
- singleChildren.get('expression').evaluate().confident;
186
- if (isJSXText || isJSXExpressionContainer) {
187
- message = isJSXText
188
- ? singleChildren.node.value.trim().replace(/\s+/g, ' ')
189
- : singleChildren.get('expression').evaluate().value;
190
- translations[id !== null && id !== void 0 ? id : message] = {
191
- message,
192
- ...(description && { description }),
193
- };
194
- }
195
- else {
196
- warnings.push(`Translate content could not be extracted. It has to be a static string and use optional but static props, like <Translate id="my-id" description="my-description">text</Translate>.\n${sourceWarningPart(path.node)}`);
197
- }
198
- },
199
- CallExpression(path) {
200
- if (!path.get('callee').isIdentifier({ name: 'translate' })) {
201
- return;
202
- }
203
- // console.log('CallExpression', path.node);
204
- const args = path.get('arguments');
205
- if (args.length === 1 || args.length === 2) {
206
- const firstArgPath = args[0];
207
- // evaluation allows translate("x" + "y"); to be considered as translate("xy");
208
- const firstArgEvaluated = firstArgPath.evaluate();
209
- // console.log('firstArgEvaluated', firstArgEvaluated);
210
- if (firstArgEvaluated.confident &&
211
- typeof firstArgEvaluated.value === 'object') {
212
- const { message, id, description } = firstArgEvaluated.value;
200
+ // Handle single non-empty content
201
+ const singleChildren = childrenPath
202
+ // Remove empty/useless text nodes that might be around our translation!
203
+ // Makes the translation system more reliable to JSX formatting issues
204
+ .filter((children) => !(children.isJSXText() &&
205
+ children.node.value.replace('\n', '').trim() === ''))
206
+ .pop();
207
+ const isJSXText = singleChildren && singleChildren.isJSXText();
208
+ const isJSXExpressionContainer = singleChildren &&
209
+ singleChildren.isJSXExpressionContainer() &&
210
+ singleChildren.get('expression').evaluate().confident;
211
+ if (isJSXText || isJSXExpressionContainer) {
212
+ message = isJSXText
213
+ ? singleChildren.node.value.trim().replace(/\s+/g, ' ')
214
+ : singleChildren.get('expression').evaluate().value;
213
215
  translations[id !== null && id !== void 0 ? id : message] = {
214
- message: message !== null && message !== void 0 ? message : id,
216
+ message,
215
217
  ...(description && { description }),
216
218
  };
217
219
  }
218
220
  else {
219
- warnings.push(`translate() first arg should be a statically evaluable object.\nExample: translate({message: "text",id: "optional.id",description: "optional description"}\nDynamically constructed values are not allowed, because they prevent translations to be extracted.\n${sourceWarningPart(path.node)}`);
221
+ warnings.push(`Translate content could not be extracted. It has to be a static string and use optional but static props, like <Translate id="my-id" description="my-description">text</Translate>.
222
+ ${sourceWarningPart(path.node)}`);
220
223
  }
221
- }
222
- else {
223
- warnings.push(`translate() function only takes 1 or 2 args\n${sourceWarningPart(path.node)}`);
224
- }
225
- },
224
+ },
225
+ }),
226
+ ...(translateFunctionName && {
227
+ CallExpression(path) {
228
+ if (!path.get('callee').isIdentifier({ name: translateFunctionName })) {
229
+ return;
230
+ }
231
+ const args = path.get('arguments');
232
+ if (args.length === 1 || args.length === 2) {
233
+ const firstArgPath = args[0];
234
+ // evaluation allows translate("x" + "y"); to be considered as translate("xy");
235
+ const firstArgEvaluated = firstArgPath.evaluate();
236
+ if (firstArgEvaluated.confident &&
237
+ typeof firstArgEvaluated.value === 'object') {
238
+ const { message, id, description } = firstArgEvaluated.value;
239
+ translations[id !== null && id !== void 0 ? id : message] = {
240
+ message: message !== null && message !== void 0 ? message : id,
241
+ ...(description && { description }),
242
+ };
243
+ }
244
+ else {
245
+ warnings.push(`translate() first arg should be a statically evaluable object.
246
+ Example: translate({message: "text",id: "optional.id",description: "optional description"}
247
+ Dynamically constructed values are not allowed, because they prevent translations to be extracted.
248
+ ${sourceWarningPart(path.node)}`);
249
+ }
250
+ }
251
+ else {
252
+ warnings.push(`translate() function only takes 1 or 2 args
253
+ ${sourceWarningPart(path.node)}`);
254
+ }
255
+ },
256
+ }),
226
257
  });
227
258
  return { sourceCodeFilePath, translations, warnings };
228
259
  }
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { RouteConfig } from '@docusaurus/types';
7
+ import type { RouteConfig } from '@docusaurus/types';
8
8
  import { Globby } from '@docusaurus/utils';
9
9
  export declare function getAllFinalRoutes(routeConfig: RouteConfig[]): RouteConfig[];
10
10
  export declare function safeGlobby(patterns: string[], options?: Globby.GlobbyOptions): Promise<string[]>;
@@ -6,18 +6,19 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ const tslib_1 = require("tslib");
9
10
  const __1 = require("..");
10
- const path_1 = require("path");
11
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
11
12
  describe('getPluginVersion', () => {
12
13
  it('Can detect external packages plugins versions of correctly.', () => {
13
- expect((0, __1.getPluginVersion)((0, path_1.join)(__dirname, '..', '__fixtures__', 'dummy-plugin.js'),
14
+ expect((0, __1.getPluginVersion)(path_1.default.join(__dirname, '..', '__fixtures__', 'dummy-plugin.js'),
14
15
  // Make the plugin appear external.
15
- (0, path_1.join)(__dirname, '..', '..', '..', '..', '..', '..', 'website'))).toEqual({ type: 'package', version: 'random-version' });
16
+ path_1.default.join(__dirname, '..', '..', '..', '..', '..', '..', 'website'))).toEqual({ type: 'package', version: 'random-version' });
16
17
  });
17
18
  it('Can detect project plugins versions correctly.', () => {
18
- expect((0, __1.getPluginVersion)((0, path_1.join)(__dirname, '..', '__fixtures__', 'dummy-plugin.js'),
19
+ expect((0, __1.getPluginVersion)(path_1.default.join(__dirname, '..', '__fixtures__', 'dummy-plugin.js'),
19
20
  // Make the plugin appear project local.
20
- (0, path_1.join)(__dirname, '..', '__fixtures__'))).toEqual({ type: 'project' });
21
+ path_1.default.join(__dirname, '..', '__fixtures__'))).toEqual({ type: 'project' });
21
22
  });
22
23
  it('Can detect local packages versions correctly.', () => {
23
24
  expect((0, __1.getPluginVersion)('/', '/')).toEqual({ type: 'local' });
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { DocusaurusPluginVersionInformation } from '@docusaurus/types';
7
+ import type { DocusaurusPluginVersionInformation } from '@docusaurus/types';
8
8
  export declare function getPackageJsonVersion(packageJsonPath: string): string | undefined;
9
9
  export declare function getPackageJsonName(packageJsonPath: string): string | undefined;
10
10
  export declare function getPluginVersion(pluginPath: string, siteDir: string): DocusaurusPluginVersionInformation;
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Configuration } from 'webpack';
8
- import { Props } from '@docusaurus/types';
7
+ import type { Configuration } from 'webpack';
8
+ import type { Props } from '@docusaurus/types';
9
9
  export declare const clientDir: string;
10
10
  export declare function excludeJS(modulePath: string): boolean;
11
11
  export declare function getDocusaurusAliases(): Record<string, string>;
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Configuration } from 'webpack';
8
- import { Props } from '@docusaurus/types';
7
+ import type { Configuration } from 'webpack';
8
+ import type { Props } from '@docusaurus/types';
9
9
  export default function createClientConfig(props: Props, minify?: boolean): Configuration;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
10
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
11
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
13
13
  const base_1 = require("./base");
@@ -39,7 +39,7 @@ function createClientConfig(props, minify = true) {
39
39
  apply: (compiler) => {
40
40
  compiler.hooks.done.tap('client:done', (stats) => {
41
41
  if (stats.hasErrors()) {
42
- console.log(chalk_1.default.red('Client bundle compiled with errors therefore further build is impossible.'));
42
+ logger_1.default.error('Client bundle compiled with errors therefore further build is impossible.');
43
43
  process.exit(1);
44
44
  }
45
45
  });
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Compiler } from 'webpack';
7
+ import { type Compiler } from 'webpack';
8
8
  declare class ChunkAssetPlugin {
9
9
  apply(compiler: Compiler): void;
10
10
  }
@@ -23,7 +23,7 @@
23
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
24
  * SOFTWARE.
25
25
  */
26
- import { Compiler, Stats } from 'webpack';
26
+ import type { Compiler, Stats } from 'webpack';
27
27
  export interface Options {
28
28
  /**
29
29
  * Write Logs to Console
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import WebpackBar from 'webpackbar';
8
- import { Compiler } from 'webpack';
8
+ import type { Compiler } from 'webpack';
9
9
  export default class LogPlugin extends WebpackBar {
10
10
  apply(compiler: Compiler): void;
11
11
  }
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Compiler } from 'webpack';
7
+ import type { Compiler } from 'webpack';
8
8
  interface WaitPluginOptions {
9
9
  filepath: string;
10
10
  }
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Configuration } from 'webpack';
8
- import { Props } from '@docusaurus/types';
7
+ import type { Configuration } from 'webpack';
8
+ import type { Props } from '@docusaurus/types';
9
9
  export default function createServerConfig({ props, onLinksCollected, }: {
10
10
  props: Props;
11
11
  onLinksCollected?: (staticPagePath: string, links: string[]) => void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ declare const _default: "\n<!DOCTYPE html>\n<html <%~ it.htmlAttributes %>>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"generator\" content=\"Docusaurus v<%= it.version %>\">\n <% if (it.noIndex) { %>\n <meta name=\"robots\" content=\"noindex, nofollow\" />\n <% } %>\n <%~ it.headTags %>\n <% it.metaAttributes.forEach((metaAttribute) => { %>\n <%~ metaAttribute %>\n <% }); %>\n <% it.stylesheets.forEach((stylesheet) => { %>\n <link rel=\"stylesheet\" href=\"<%= it.baseUrl %><%= stylesheet %>\" />\n <% }); %>\n <% it.scripts.forEach((script) => { %>\n <link rel=\"preload\" href=\"<%= it.baseUrl %><%= script %>\" as=\"script\">\n <% }); %>\n </head>\n <body <%~ it.bodyAttributes %>>\n <%~ it.preBodyTags %>\n <div id=\"__docusaurus\">\n <%~ it.appHtml %>\n </div>\n <% it.scripts.forEach((script) => { %>\n <script src=\"<%= it.baseUrl %><%= script %>\"></script>\n <% }); %>\n <%~ it.postBodyTags %>\n </body>\n</html>\n";
8
+ export default _default;
@@ -1,11 +1,12 @@
1
+ "use strict";
1
2
  /**
2
3
  * Copyright (c) Facebook, Inc. and its affiliates.
3
4
  *
4
5
  * This source code is licensed under the MIT license found in the
5
6
  * LICENSE file in the root directory of this source tree.
6
7
  */
7
-
8
- module.exports = `
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = `
9
10
  <!DOCTYPE html>
10
11
  <html <%~ it.htmlAttributes %>>
11
12
  <head>
@@ -5,10 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="node" />
8
- import { Configuration, RuleSetRule, WebpackPluginInstance } from 'webpack';
9
- import { TransformOptions } from '@babel/core';
10
- import { ConfigureWebpackFn, ConfigurePostCssFn } from '@docusaurus/types';
11
- export declare function getStyleLoaders(isServer: boolean, cssOptions?: {
8
+ import { type Configuration, type RuleSetRule, type WebpackPluginInstance } from 'webpack';
9
+ import type { TransformOptions } from '@babel/core';
10
+ import type { ConfigureWebpackFn, ConfigurePostCssFn } from '@docusaurus/types';
11
+ export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
12
12
  [key: string]: unknown;
13
13
  }): RuleSetRule[];
14
14
  export declare function getCustomBabelConfigFilePath(siteDir: string): string | undefined;
@@ -16,11 +16,16 @@ const terser_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("terser-web
16
16
  const css_minimizer_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("css-minimizer-webpack-plugin"));
17
17
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
18
18
  const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
19
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
19
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
20
20
  const utils_1 = require("@docusaurus/utils");
21
21
  const lodash_1 = require("lodash");
22
22
  // Utility method to get style loaders
23
- function getStyleLoaders(isServer, cssOptions = {}) {
23
+ function getStyleLoaders(isServer, cssOptionsArg = {}) {
24
+ const cssOptions = {
25
+ // TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
26
+ esModule: false,
27
+ ...cssOptionsArg,
28
+ };
24
29
  if (isServer) {
25
30
  return cssOptions.modules
26
31
  ? [
@@ -113,7 +118,7 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
113
118
  exports.getCustomizableJSLoader = getCustomizableJSLoader;
114
119
  // TODO remove this before end of 2021?
115
120
  const warnBabelLoaderOnce = (0, lodash_1.memoize)(() => {
116
- console.warn(chalk_1.default.yellow('Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): "getBabelLoader(isServer)" is now deprecated in favor of "getJSLoader({isServer})".'));
121
+ logger_1.default.warn `Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): code=${'getBabelLoader(isServer)'} is now deprecated in favor of code=${'getJSLoader(isServer)'}.`;
117
122
  });
118
123
  const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, babelOptions) {
119
124
  warnBabelLoaderOnce();
@@ -121,7 +126,7 @@ const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, bab
121
126
  };
122
127
  // TODO remove this before end of 2021 ?
123
128
  const warnCacheLoaderOnce = (0, lodash_1.memoize)(() => {
124
- console.warn(chalk_1.default.yellow('Docusaurus uses Webpack 5 and getCacheLoader() usage is now deprecated.'));
129
+ logger_1.default.warn `Docusaurus uses Webpack 5 and code=${'getCacheLoader()'} usage is now deprecated.`;
125
130
  });
126
131
  function getCacheLoaderDeprecated() {
127
132
  warnCacheLoaderOnce();
@@ -159,7 +164,7 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
159
164
  exports.applyConfigureWebpack = applyConfigureWebpack;
160
165
  function applyConfigurePostCss(configurePostCss, config) {
161
166
  var _a, _b;
162
- // TODO not ideal heuristic but good enough for our usecase?
167
+ // not ideal heuristic but good enough for our use-case?
163
168
  function isPostCssLoader(loader) {
164
169
  var _a, _b;
165
170
  return !!((_b = (_a = loader) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.postcssOptions);
@@ -188,11 +193,11 @@ function compile(config) {
188
193
  compiler.run((err, stats) => {
189
194
  var _a;
190
195
  if (err) {
191
- console.error(err.stack || err);
196
+ logger_1.default.error(err.stack || err);
192
197
  // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
193
198
  if (err.details) {
194
199
  // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
195
- console.error(err.details);
200
+ logger_1.default.error(err.details);
196
201
  }
197
202
  reject(err);
198
203
  }
@@ -203,14 +208,14 @@ function compile(config) {
203
208
  }
204
209
  if (errorsWarnings && (stats === null || stats === void 0 ? void 0 : stats.hasWarnings())) {
205
210
  (_a = errorsWarnings.warnings) === null || _a === void 0 ? void 0 : _a.forEach((warning) => {
206
- console.warn(warning);
211
+ logger_1.default.warn(warning);
207
212
  });
208
213
  }
209
214
  // Webpack 5 requires calling close() so that persistent caching works
210
215
  // See https://github.com/webpack/webpack.js.org/pull/4775
211
216
  compiler.close((errClose) => {
212
217
  if (errClose) {
213
- console.error(chalk_1.default.red('Error while closing Webpack compiler:', errClose));
218
+ logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
214
219
  reject(errClose);
215
220
  }
216
221
  else {
@@ -230,20 +235,22 @@ function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
230
235
  encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
231
236
  }
232
237
  catch (err) {
233
- throw new Error(`The certificate "${chalk_1.default.yellow(crtFile)}" is invalid.\n${err.message}`);
238
+ throw new Error(`The certificate ${crtFile} is invalid.
239
+ ${err}`);
234
240
  }
235
241
  try {
236
242
  // privateDecrypt will throw an error with an invalid key
237
243
  crypto_1.default.privateDecrypt(key, encrypted);
238
244
  }
239
245
  catch (err) {
240
- throw new Error(`The certificate key "${chalk_1.default.yellow(keyFile)}" is invalid.\n${err.message}`);
246
+ throw new Error(`The certificate key ${keyFile} is invalid.
247
+ ${err}`);
241
248
  }
242
249
  }
243
250
  // Read file and throw an error if it doesn't exist
244
251
  function readEnvFile(file, type) {
245
252
  if (!fs_extra_1.default.existsSync(file)) {
246
- throw new Error(`You specified ${chalk_1.default.cyan(type)} in your env, but the file "${chalk_1.default.yellow(file)}" can't be found.`);
253
+ throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
247
254
  }
248
255
  return fs_extra_1.default.readFileSync(file);
249
256
  }
@@ -293,7 +300,6 @@ function getMinimizer(useSimpleCssMinifier = false) {
293
300
  },
294
301
  compress: {
295
302
  ecma: 5,
296
- // @ts-expect-error: API change in new version?
297
303
  warnings: false,
298
304
  },
299
305
  mangle: {
@@ -324,7 +330,6 @@ function getMinimizer(useSimpleCssMinifier = false) {
324
330
  },
325
331
  // CleanCss options
326
332
  {
327
- // @ts-expect-error: API change in new version?
328
333
  inline: false,
329
334
  level: {
330
335
  1: {