@docusaurus/core 2.0.0-beta.12faed89d → 2.0.0-beta.13

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 (111) hide show
  1. package/bin/beforeCli.js +33 -8
  2. package/bin/docusaurus.js +36 -40
  3. package/lib/.tsbuildinfo +1 -1
  4. package/lib/babel/preset.d.ts +6 -0
  5. package/lib/babel/preset.js +3 -3
  6. package/lib/choosePort.js +12 -13
  7. package/lib/client/.eslintrc.js +0 -1
  8. package/lib/client/.tsbuildinfo +1 -1
  9. package/lib/client/App.js +12 -22
  10. package/lib/client/LinksCollector.d.ts +2 -2
  11. package/lib/client/LinksCollector.js +4 -8
  12. package/lib/client/PendingNavigation.d.ts +24 -1
  13. package/lib/client/PendingNavigation.js +1 -1
  14. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +5 -0
  15. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -2
  16. package/lib/client/client-lifecycles-dispatcher.js +0 -2
  17. package/lib/client/docusaurus.d.ts +6 -0
  18. package/lib/client/docusaurus.js +11 -19
  19. package/lib/client/exports/BrowserOnly.js +5 -3
  20. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  21. package/lib/client/exports/ErrorBoundary.js +35 -0
  22. package/lib/client/exports/Interpolate.js +12 -15
  23. package/lib/client/exports/Link.js +9 -9
  24. package/lib/client/exports/Translate.d.ts +2 -2
  25. package/lib/client/exports/Translate.js +13 -9
  26. package/lib/client/exports/browserContext.d.ts +11 -0
  27. package/lib/client/exports/browserContext.js +21 -0
  28. package/lib/client/exports/constants.js +1 -11
  29. package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
  30. package/lib/client/exports/docusaurusContext.js +25 -0
  31. package/lib/client/exports/useBaseUrl.js +2 -4
  32. package/lib/client/exports/useDocusaurusContext.js +2 -7
  33. package/lib/client/exports/useGlobalData.js +1 -5
  34. package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
  35. package/lib/{webpack/sharedModuleAliases.d.ts → client/exports/useIsBrowser.js} +5 -4
  36. package/lib/client/flat.d.ts +2 -1
  37. package/lib/client/flat.js +7 -9
  38. package/lib/client/normalizeLocation.d.ts +1 -3
  39. package/lib/client/prefetch.js +0 -1
  40. package/lib/client/serverEntry.js +15 -31
  41. package/lib/client/theme-fallback/Error/index.js +47 -0
  42. package/lib/client/theme-fallback/Layout/index.js +1 -1
  43. package/lib/client/theme-fallback/Loading/index.js +2 -2
  44. package/lib/client/theme-fallback/Root/index.js +1 -3
  45. package/lib/commands/build.js +34 -37
  46. package/lib/commands/clear.d.ts +6 -0
  47. package/lib/commands/clear.js +9 -9
  48. package/lib/commands/commandUtils.d.ts +6 -0
  49. package/lib/commands/commandUtils.js +7 -7
  50. package/lib/commands/deploy.d.ts +3 -0
  51. package/lib/commands/deploy.js +90 -53
  52. package/lib/commands/external.js +4 -4
  53. package/lib/commands/serve.js +13 -13
  54. package/lib/commands/start.js +82 -72
  55. package/lib/commands/swizzle.js +34 -34
  56. package/lib/commands/writeHeadingIds.d.ts +9 -6
  57. package/lib/commands/writeHeadingIds.js +32 -32
  58. package/lib/commands/writeTranslations.js +31 -11
  59. package/lib/server/brokenLinks.js +13 -17
  60. package/lib/server/client-modules/index.js +1 -3
  61. package/lib/server/config.js +4 -4
  62. package/lib/server/configValidation.d.ts +1 -1
  63. package/lib/server/configValidation.js +11 -6
  64. package/lib/server/duplicateRoutes.js +8 -2
  65. package/lib/server/html-tags/htmlTags.js +5 -6
  66. package/lib/server/html-tags/index.js +2 -2
  67. package/lib/server/i18n.js +16 -13
  68. package/lib/server/index.js +128 -58
  69. package/lib/server/loadSetup.js +3 -3
  70. package/lib/server/moduleShorthand.d.ts +9 -0
  71. package/lib/server/moduleShorthand.js +42 -0
  72. package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
  73. package/lib/server/plugins/index.d.ts +1 -1
  74. package/lib/server/plugins/index.js +24 -20
  75. package/lib/server/plugins/init.js +9 -12
  76. package/lib/server/plugins/pluginIds.js +6 -4
  77. package/lib/server/presets/index.js +12 -12
  78. package/lib/server/routes.js +9 -11
  79. package/lib/server/themes/alias.d.ts +1 -0
  80. package/lib/server/themes/alias.js +21 -12
  81. package/lib/server/themes/index.d.ts +1 -1
  82. package/lib/server/themes/index.js +22 -23
  83. package/lib/server/translations/translations.d.ts +6 -0
  84. package/lib/server/translations/translations.js +15 -17
  85. package/lib/server/translations/translationsExtractor.d.ts +7 -1
  86. package/lib/server/translations/translationsExtractor.js +65 -56
  87. package/lib/server/utils.d.ts +8 -2
  88. package/lib/server/utils.js +8 -10
  89. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  90. package/lib/server/versions/__tests/index.test.js +5 -5
  91. package/lib/server/versions/index.js +6 -6
  92. package/lib/webpack/base.js +14 -16
  93. package/lib/webpack/client.js +8 -17
  94. package/lib/webpack/plugins/CleanWebpackPlugin.js +4 -11
  95. package/lib/webpack/plugins/LogPlugin.js +5 -6
  96. package/lib/webpack/plugins/WaitPlugin.js +4 -4
  97. package/lib/webpack/server.js +9 -9
  98. package/lib/webpack/utils.d.ts +0 -22
  99. package/lib/webpack/utils.js +26 -125
  100. package/package.json +55 -50
  101. package/tsconfig.client.json +1 -2
  102. package/tsconfig.json +5 -4
  103. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  104. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  105. package/lib/constants.d.ts +0 -18
  106. package/lib/constants.js +0 -23
  107. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  108. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  109. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  110. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  111. package/lib/webpack/sharedModuleAliases.js +0 -18
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "2.0.0-beta.12faed89d",
4
+ "version": "2.0.0-beta.13",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -30,98 +30,103 @@
30
30
  "bugs": {
31
31
  "url": "https://github.com/facebook/docusaurus/issues"
32
32
  },
33
- "devDependencies": {
34
- "@docusaurus/module-type-aliases": "2.0.0-beta.12faed89d",
35
- "@types/detect-port": "^1.3.0",
36
- "@types/nprogress": "^0.2.0",
37
- "tmp-promise": "^3.0.2"
38
- },
39
33
  "dependencies": {
40
- "@babel/core": "^7.12.16",
41
- "@babel/generator": "^7.12.15",
34
+ "@babel/core": "^7.16.0",
35
+ "@babel/generator": "^7.16.0",
42
36
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
43
- "@babel/plugin-transform-runtime": "^7.12.15",
44
- "@babel/preset-env": "^7.12.16",
45
- "@babel/preset-react": "^7.12.13",
46
- "@babel/preset-typescript": "^7.12.16",
47
- "@babel/runtime": "^7.12.5",
48
- "@babel/runtime-corejs3": "^7.12.13",
49
- "@babel/traverse": "^7.12.13",
50
- "@docusaurus/cssnano-preset": "2.0.0-beta.12faed89d",
51
- "@docusaurus/react-loadable": "5.5.0",
52
- "@docusaurus/types": "2.0.0-beta.12faed89d",
53
- "@docusaurus/utils": "2.0.0-beta.12faed89d",
54
- "@docusaurus/utils-common": "2.0.0-beta.12faed89d",
55
- "@docusaurus/utils-validation": "2.0.0-beta.12faed89d",
37
+ "@babel/plugin-transform-runtime": "^7.16.0",
38
+ "@babel/preset-env": "^7.16.4",
39
+ "@babel/preset-react": "^7.16.0",
40
+ "@babel/preset-typescript": "^7.16.0",
41
+ "@babel/runtime": "^7.16.3",
42
+ "@babel/runtime-corejs3": "^7.16.3",
43
+ "@babel/traverse": "^7.16.3",
44
+ "@docusaurus/cssnano-preset": "2.0.0-beta.13",
45
+ "@docusaurus/mdx-loader": "2.0.0-beta.13",
46
+ "@docusaurus/react-loadable": "5.5.2",
47
+ "@docusaurus/utils": "2.0.0-beta.13",
48
+ "@docusaurus/utils-common": "2.0.0-beta.13",
49
+ "@docusaurus/utils-validation": "2.0.0-beta.13",
56
50
  "@slorber/static-site-generator-webpack-plugin": "^4.0.0",
57
- "@svgr/webpack": "^5.5.0",
58
- "autoprefixer": "^10.2.5",
51
+ "@svgr/webpack": "^6.0.0",
52
+ "autoprefixer": "^10.3.5",
59
53
  "babel-loader": "^8.2.2",
60
54
  "babel-plugin-dynamic-import-node": "2.3.0",
61
55
  "boxen": "^5.0.1",
62
- "chalk": "^4.1.1",
63
- "chokidar": "^3.5.1",
64
- "clean-css": "^5.1.2",
56
+ "chalk": "^4.1.2",
57
+ "chokidar": "^3.5.2",
58
+ "clean-css": "^5.1.5",
65
59
  "commander": "^5.1.0",
66
- "copy-webpack-plugin": "^9.0.0",
67
- "core-js": "^3.9.1",
60
+ "copy-webpack-plugin": "^9.0.1",
61
+ "core-js": "^3.18.0",
68
62
  "css-loader": "^5.1.1",
69
- "css-minimizer-webpack-plugin": "^3.0.1",
70
- "cssnano": "^5.0.4",
63
+ "css-minimizer-webpack-plugin": "^3.0.2",
64
+ "cssnano": "^5.0.8",
71
65
  "del": "^6.0.0",
72
66
  "detect-port": "^1.3.0",
73
67
  "escape-html": "^1.0.3",
74
- "eta": "^1.12.1",
75
- "express": "^4.17.1",
68
+ "eta": "^1.12.3",
76
69
  "file-loader": "^6.2.0",
77
70
  "fs-extra": "^10.0.0",
78
- "github-slugger": "^1.3.0",
79
71
  "globby": "^11.0.2",
80
- "html-minifier-terser": "^5.1.1",
72
+ "html-minifier-terser": "^6.0.2",
81
73
  "html-tags": "^3.1.0",
82
- "html-webpack-plugin": "^5.3.2",
74
+ "html-webpack-plugin": "^5.4.0",
83
75
  "import-fresh": "^3.3.0",
84
76
  "is-root": "^2.1.0",
85
77
  "leven": "^3.1.0",
86
78
  "lodash": "^4.17.20",
87
79
  "mini-css-extract-plugin": "^1.6.0",
88
- "module-alias": "^2.2.2",
89
80
  "nprogress": "^0.2.0",
90
- "postcss": "^8.2.15",
91
- "postcss-loader": "^5.3.0",
81
+ "postcss": "^8.3.7",
82
+ "postcss-loader": "^6.1.1",
92
83
  "prompts": "^2.4.1",
93
- "react-dev-utils": "^11.0.1",
84
+ "react-dev-utils": "12.0.0-next.47",
94
85
  "react-error-overlay": "^6.0.9",
95
86
  "react-helmet": "^6.1.0",
96
- "react-loadable": "^5.5.0",
87
+ "react-loadable": "npm:@docusaurus/react-loadable@5.5.2",
97
88
  "react-loadable-ssr-addon-v5-slorber": "^1.0.1",
98
89
  "react-router": "^5.2.0",
99
90
  "react-router-config": "^5.1.1",
100
91
  "react-router-dom": "^5.2.0",
92
+ "remark-admonitions": "^1.2.1",
101
93
  "resolve-pathname": "^3.0.0",
102
- "rtl-detect": "^1.0.3",
94
+ "rtl-detect": "^1.0.4",
103
95
  "semver": "^7.3.4",
104
96
  "serve-handler": "^6.1.3",
105
97
  "shelljs": "^0.8.4",
106
- "std-env": "^2.2.1",
107
98
  "strip-ansi": "^6.0.0",
108
- "terser-webpack-plugin": "^5.1.3",
109
- "tslib": "^2.2.0",
99
+ "terser-webpack-plugin": "^5.2.4",
100
+ "tslib": "^2.3.1",
110
101
  "update-notifier": "^5.1.0",
111
102
  "url-loader": "^4.1.1",
112
- "wait-on": "^5.3.0",
113
- "webpack": "^5.40.0",
103
+ "wait-on": "^6.0.0",
104
+ "webpack": "^5.61.0",
114
105
  "webpack-bundle-analyzer": "^4.4.2",
115
- "webpack-dev-server": "^3.11.2",
106
+ "webpack-dev-server": "^4.5.0",
116
107
  "webpack-merge": "^5.8.0",
117
108
  "webpackbar": "^5.0.0-3"
118
109
  },
110
+ "devDependencies": {
111
+ "@docusaurus/module-type-aliases": "2.0.0-beta.13",
112
+ "@docusaurus/types": "2.0.0-beta.13",
113
+ "@types/copy-webpack-plugin": "^8.0.1",
114
+ "@types/css-minimizer-webpack-plugin": "^3.0.2",
115
+ "@types/detect-port": "^1.3.0",
116
+ "@types/mini-css-extract-plugin": "^1.4.3",
117
+ "@types/nprogress": "^0.2.0",
118
+ "@types/react-dom": "^17.0.9",
119
+ "@types/rtl-detect": "^1.0.0",
120
+ "@types/serve-handler": "^6.1.1",
121
+ "@types/webpack-bundle-analyzer": "^4.4.1",
122
+ "tmp-promise": "^3.0.2"
123
+ },
119
124
  "peerDependencies": {
120
125
  "react": "^16.8.4 || ^17.0.0",
121
126
  "react-dom": "^16.8.4 || ^17.0.0"
122
127
  },
123
128
  "engines": {
124
- "node": ">=12.13.0"
129
+ "node": ">=14"
125
130
  },
126
- "gitHead": "1430dbacfbe9da59a17ce395ed29bdbddaf90049"
131
+ "gitHead": "b6ca12aedf10a10c2375f4f8b7e7380cfd7c7202"
127
132
  }
@@ -2,11 +2,10 @@
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "incremental": true,
5
- "lib": ["DOM"],
5
+ "lib": ["DOM", "ES2019"],
6
6
  "module": "esnext",
7
7
  "tsBuildInfoFile": "./lib/client/.tsbuildinfo",
8
8
  "outDir": "lib/client",
9
- "noImplicitAny": false,
10
9
  "jsx": "react"
11
10
  },
12
11
  "include": ["src/client"]
package/tsconfig.json CHANGED
@@ -2,12 +2,13 @@
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "incremental": true,
5
- "lib": ["DOM"],
5
+ "lib": ["DOM", "ES2019"],
6
6
  "tsBuildInfoFile": "./lib/.tsbuildinfo",
7
7
  "rootDir": "src",
8
8
  "outDir": "lib",
9
- "noImplicitAny": false,
10
- "jsx": "react"
9
+ "jsx": "react",
10
+ "allowJs": true
11
11
  },
12
- "exclude": ["node_modules", "**/__tests__/**/*", "**/lib/**/*", "src/client"]
12
+ "include": ["src"],
13
+ "exclude": ["**/__tests__/**/*", "src/client"]
13
14
  }
@@ -1,7 +0,0 @@
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
- export declare function buildUrl(githubHost: string, githubPort: string | undefined, gitCredentials: string | undefined, organizationName: string, projectName: string, useSSH: boolean | undefined): string;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.buildUrl = void 0;
10
- function buildUrl(githubHost, githubPort, gitCredentials, organizationName, projectName, useSSH) {
11
- return useSSH
12
- ? buildSshUrl(githubHost, organizationName, projectName, githubPort)
13
- : buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort);
14
- }
15
- exports.buildUrl = buildUrl;
16
- function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
17
- if (githubPort) {
18
- return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
19
- }
20
- return `git@${githubHost}:${organizationName}/${projectName}.git`;
21
- }
22
- function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
23
- if (githubPort) {
24
- return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
25
- }
26
- return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
27
- }
@@ -1,18 +0,0 @@
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
- export declare const NODE_MAJOR_VERSION: number;
8
- export declare const NODE_MINOR_VERSION: number;
9
- export declare const DEFAULT_BUILD_DIR_NAME = "build";
10
- export declare const DEFAULT_CONFIG_FILE_NAME = "docusaurus.config.js";
11
- export declare const BABEL_CONFIG_FILE_NAME: string;
12
- export declare const GENERATED_FILES_DIR_NAME: string;
13
- export declare const SRC_DIR_NAME = "src";
14
- export declare const STATIC_DIR_NAME = "static";
15
- export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
16
- export declare const THEME_PATH: string;
17
- export declare const DEFAULT_PORT = 3000;
18
- export declare const DEFAULT_PLUGIN_ID = "default";
package/lib/constants.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
- exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
11
- exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
12
- // Can be overridden with cli option --out-dir
13
- exports.DEFAULT_BUILD_DIR_NAME = 'build';
14
- // Can be overridden with cli option --config
15
- exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
16
- exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
17
- exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
18
- exports.SRC_DIR_NAME = 'src';
19
- exports.STATIC_DIR_NAME = 'static';
20
- exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
21
- exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
22
- exports.DEFAULT_PORT = 3000;
23
- exports.DEFAULT_PLUGIN_ID = 'default';
@@ -1,11 +0,0 @@
1
- This is a temporary copy of
2
-
3
- CRA / react-dev-utils does not support Webpack 5 yet
4
-
5
- https://github.com/facebook/create-react-app/issues/9994
6
-
7
- This folder is a temporary copy of some react-dev-utils code to which we made some changes to support Webpack 5 without warnings
8
-
9
- TODO remove this folder once Webpack 5 is supported (https://github.com/facebook/create-react-app/issues/9994)
10
-
11
- The comment `// modified for Docusaurus` is added near the modified elements
@@ -1,57 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
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
- /* eslint-disable */
8
- /*
9
- * THIS FILE IS MODIFIED FOR DOCUSAURUS
10
- * the above copyright header must be preserved for license compliance.
11
- */
12
-
13
- /*
14
- Implementation based on comment: https://github.com/facebook/create-react-app/issues/9994#issuecomment-811289191
15
- */
16
-
17
- function base64SourceMap(source) {
18
- const base64 = Buffer.from(JSON.stringify(source.map()), 'utf8').toString(
19
- 'base64',
20
- );
21
- return `data:application/json;charset=utf-8;base64,${base64}`;
22
- }
23
-
24
- // modified for Docusaurus => remove webpack 5 deprecation warnings
25
- // See https://github.com/facebook/create-react-app/issues/9994#issuecomment-811289191
26
- function getSourceById(server, id) {
27
- const module = Array.from(server._stats.compilation.modules).find(
28
- (m) => server._stats.compilation.chunkGraph.getModuleId(m) == id,
29
- );
30
- return module.originalSource();
31
- }
32
-
33
- /*
34
- * Middleware responsible for retrieving a generated source
35
- * Receives a webpack internal url: "webpack-internal:///<module-id>"
36
- * Returns a generated source: "<source-text><sourceMappingURL><sourceURL>"
37
- *
38
- * Based on EvalSourceMapDevToolModuleTemplatePlugin.js
39
- */
40
- module.exports = function createEvalSourceMapMiddleware(server) {
41
- return function handleWebpackInternalMiddleware(req, res, next) {
42
- if (req.url.startsWith('/__get-internal-source')) {
43
- const fileName = req.query.fileName;
44
- const id = fileName.match(/webpack-internal:\/\/\/(.+)/)[1];
45
- if (!id || !server._stats) {
46
- next();
47
- }
48
-
49
- const source = getSourceById(server, id);
50
- const sourceMapURL = `//# sourceMappingURL=${base64SourceMap(source)}`;
51
- const sourceURL = `//# sourceURL=webpack-internal:///${module.id}`;
52
- res.end(`${source.source()}\n${sourceMapURL}\n${sourceURL}`);
53
- } else {
54
- next();
55
- }
56
- };
57
- };
@@ -1,138 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
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
- /* eslint-disable */
8
- /*
9
- * THIS FILE IS MODIFIED FOR DOCUSAURUS
10
- * the above copyright header must be preserved for license compliance.
11
- */
12
-
13
- /*
14
- Implementation has been copied from https://github.com/facebook/create-react-app/pull/10656
15
- */
16
-
17
- const friendlySyntaxErrorLabel = 'Syntax error:';
18
-
19
- function isLikelyASyntaxError(message) {
20
- return message.indexOf(friendlySyntaxErrorLabel) !== -1;
21
- }
22
-
23
- // Cleans up webpack error messages.
24
- function formatMessage(message) {
25
- let lines = [];
26
-
27
- // modified for Docusaurus => see https://github.com/facebook/create-react-app/pull/10656
28
- if (typeof message === 'string') {
29
- lines = message.split('\n');
30
- } else if ('message' in message) {
31
- lines = message['message'].split('\n');
32
- } else if (Array.isArray(message)) {
33
- message.forEach((message) => {
34
- if ('message' in message) {
35
- lines = message['message'].split('\n');
36
- }
37
- });
38
- }
39
-
40
- // Strip webpack-added headers off errors/warnings
41
- // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
42
- lines = lines.filter((line) => !/Module [A-z ]+\(from/.test(line));
43
-
44
- // Transform parsing error into syntax error
45
- // TODO: move this to our ESLint formatter?
46
- lines = lines.map((line) => {
47
- const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
48
- line,
49
- );
50
- if (!parsingError) {
51
- return line;
52
- }
53
- const [, errorLine, errorColumn, errorMessage] = parsingError;
54
- return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
55
- });
56
-
57
- message = lines.join('\n');
58
- // Smoosh syntax errors (commonly found in CSS)
59
- message = message.replace(
60
- /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
61
- `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`,
62
- );
63
- // Clean up export errors
64
- message = message.replace(
65
- /^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
66
- `Attempted import error: '$1' is not exported from '$2'.`,
67
- );
68
- message = message.replace(
69
- /^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
70
- `Attempted import error: '$2' does not contain a default export (imported as '$1').`,
71
- );
72
- message = message.replace(
73
- /^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
74
- `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`,
75
- );
76
- lines = message.split('\n');
77
-
78
- // Remove leading newline
79
- if (lines.length > 2 && lines[1].trim() === '') {
80
- lines.splice(1, 1);
81
- }
82
- // Clean up file name
83
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
84
-
85
- // Cleans up verbose "module not found" messages for files and packages.
86
- if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
87
- lines = [
88
- lines[0],
89
- lines[1]
90
- .replace('Error: ', '')
91
- .replace('Module not found: Cannot find file:', 'Cannot find file:'),
92
- ];
93
- }
94
-
95
- // Add helpful message for users trying to use Sass for the first time
96
- if (lines[1] && lines[1].match(/Cannot find module.+node-sass/)) {
97
- lines[1] = 'To import Sass files, you first need to install node-sass.\n';
98
- lines[1] +=
99
- 'Run `npm install node-sass` or `yarn add node-sass` inside your workspace.';
100
- }
101
-
102
- message = lines.join('\n');
103
- // Internal stacks are generally useless so we strip them... with the
104
- // exception of stacks containing `webpack:` because they're normally
105
- // from user code generated by webpack. For more information see
106
- // https://github.com/facebook/create-react-app/pull/1050
107
- message = message.replace(
108
- /^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
109
- '',
110
- ); // at ... ...:x:y
111
- message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
112
- lines = message.split('\n');
113
-
114
- // Remove duplicated newlines
115
- lines = lines.filter(
116
- (line, index, arr) =>
117
- index === 0 ||
118
- line.trim() !== '' ||
119
- line.trim() !== arr[index - 1].trim(),
120
- );
121
-
122
- // Reassemble the message
123
- message = lines.join('\n');
124
- return message.trim();
125
- }
126
-
127
- function formatWebpackMessages(json) {
128
- const formattedErrors = json.errors.map(formatMessage);
129
- const formattedWarnings = json.warnings.map(formatMessage);
130
- const result = {errors: formattedErrors, warnings: formattedWarnings};
131
- if (result.errors.some(isLikelyASyntaxError)) {
132
- // If there are any syntax errors, show just them.
133
- result.errors = result.errors.filter(isLikelyASyntaxError);
134
- }
135
- return result;
136
- }
137
-
138
- module.exports = formatWebpackMessages;