Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"detect-port": "^1.5.1",
"escape-html": "^1.0.3",
"eta": "^2.2.0",
"eval": "^0.1.8",
"execa": "^5.1.1",
"fs-extra": "^11.1.1",
"html-tags": "^3.3.1",
Expand Down
46 changes: 22 additions & 24 deletions packages/docusaurus/src/ssg/ssgRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import fs from 'fs-extra';
import path from 'path';
// TODO eval is archived / unmaintained: https://github.com/pierrec/node-eval
// We should internalize/modernize it
import evaluate from 'eval';
import {compileFunction} from 'vm';
import pMap from 'p-map';
import logger, {PerfLogger} from '@docusaurus/logger';
import {getHtmlMinifier} from '@docusaurus/bundler';
Expand Down Expand Up @@ -55,35 +53,35 @@ async function loadAppRenderer({
serverBundlePath: string;
}): Promise<AppRenderer> {
const source = await PerfLogger.async(`Load server bundle`, () =>
fs.readFile(serverBundlePath),
fs.readFile(serverBundlePath, 'utf8'),
);

const filename = path.basename(serverBundlePath);

const ssgRequire = createSSGRequire(serverBundlePath);

const globals = {
// When using "new URL('file.js', import.meta.url)", Webpack will emit
// __filename, and this plugin will throw. not sure the __filename value
// has any importance for this plugin, just using an empty string to
// avoid the error. See https://github.com/facebook/docusaurus/issues/4922
__filename: '',
const serverEntry = await PerfLogger.async(`Evaluate server bundle`, () => {
const fn = compileFunction(
source,
['exports', 'require', 'module', '__filename', '__dirname'],
{filename},
);

// This uses module.createRequire() instead of very old "require-like" lib
// See also: https://github.com/pierrec/node-eval/issues/33
require: ssgRequire.require,
};
const module = {
exports: {},
};

const serverEntry = await PerfLogger.async(
`Evaluate server bundle`,
() =>
evaluate(
source,
/* filename: */ filename,
/* scope: */ globals,
/* includeGlobals: */ true,
) as {default?: AppRenderer},
);
fn(
module.exports,
ssgRequire.require,
module,
// See https://github.com/facebook/docusaurus/issues/4922
'',
path.dirname(serverBundlePath),
);

return module.exports as {default?: AppRenderer};
});

if (!serverEntry?.default || typeof serverEntry.default !== 'function') {
throw new Error(
Expand Down
13 changes: 0 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8740,14 +8740,6 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==

eval@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/eval/-/eval-0.1.8.tgz#2b903473b8cc1d1989b83a1e7923f883eb357f85"
integrity sha512-EzV94NYKoO09GLXGjXj9JIlXijVck4ONSr5wiCWDvhsvj5jxSrzTmRU/9C1DyB6uToszLs8aifA6NQ7lEQdvFw==
dependencies:
"@types/node" "*"
require-like ">= 0.1.1"

event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
Expand Down Expand Up @@ -16187,11 +16179,6 @@ require-from-string@^2.0.2:
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==

"require-like@>= 0.1.1":
version "0.1.2"
resolved "https://registry.yarnpkg.com/require-like/-/require-like-0.1.2.tgz#ad6f30c13becd797010c468afa775c0c0a6b47fa"
integrity sha512-oyrU88skkMtDdauHDuKVrgR+zuItqr6/c//FXzvmxRGMexSDc6hNvJInGW3LL46n+8b50RykrvwSUIIQH2LQ5A==

requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
Expand Down
Loading