mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-25 17:22:50 +00:00
fix(mdx-loader): fix url.parse deprecation warning on Node 24+ (#11530)
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (24) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (25.1) (push) Waiting to run
E2E Tests / E2E — Yarn v1 Windows (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (24) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (25.1) (push) Waiting to run
E2E Tests / E2E — Yarn v1 Windows (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
366b4a1b26
commit
bbec801e3f
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import path from 'path';
|
||||
import url from 'url';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
toMessageRelativeFilePath,
|
||||
|
|
@ -15,6 +14,7 @@ import {
|
|||
findAsyncSequential,
|
||||
getFileLoaderUtils,
|
||||
parseURLOrPath,
|
||||
parseLocalURLPath,
|
||||
} from '@docusaurus/utils';
|
||||
import escapeHtml from 'escape-html';
|
||||
import {imageSizeFromFile} from 'image-size/fromFile';
|
||||
|
|
@ -207,11 +207,11 @@ async function processImageNode(target: Target, context: Context) {
|
|||
return;
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(node.url);
|
||||
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
||||
// pathname:// is an escape hatch, in case user does not want her images to
|
||||
const localUrlPath = parseLocalURLPath(node.url);
|
||||
if (!localUrlPath) {
|
||||
// pathname:// is an escape hatch, in case the user does not want images to
|
||||
// be converted to require calls going through webpack loader
|
||||
if (parsedUrl.protocol === 'pathname:') {
|
||||
if (parseURLOrPath(node.url).protocol === 'pathname:') {
|
||||
node.url = node.url.replace('pathname://', '');
|
||||
}
|
||||
return;
|
||||
|
|
@ -220,7 +220,7 @@ async function processImageNode(target: Target, context: Context) {
|
|||
// We decode it first because Node Url.pathname is always encoded
|
||||
// while the image file-system path are not.
|
||||
// See https://github.com/facebook/docusaurus/discussions/10720
|
||||
const decodedPathname = decodeURIComponent(parsedUrl.pathname);
|
||||
const decodedPathname = decodeURIComponent(localUrlPath.pathname);
|
||||
|
||||
// We try to convert image urls without protocol to images with require calls
|
||||
// going through webpack ensures that image assets exist at build time
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import path from 'path';
|
||||
import url from 'url';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
toMessageRelativeFilePath,
|
||||
|
|
@ -15,6 +14,7 @@ import {
|
|||
findAsyncSequential,
|
||||
getFileLoaderUtils,
|
||||
parseURLOrPath,
|
||||
parseLocalURLPath,
|
||||
} from '@docusaurus/utils';
|
||||
import escapeHtml from 'escape-html';
|
||||
import logger from '@docusaurus/logger';
|
||||
|
|
@ -209,21 +209,22 @@ async function processLinkNode(target: Target, context: Context) {
|
|||
return;
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(node.url);
|
||||
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
||||
const localUrlPath = parseLocalURLPath(node.url);
|
||||
if (!localUrlPath) {
|
||||
// Don't process pathname:// here, it's used by the <Link> component
|
||||
return;
|
||||
}
|
||||
const hasSiteAlias = parsedUrl.pathname.startsWith('@site/');
|
||||
|
||||
const hasSiteAlias = localUrlPath.pathname.startsWith('@site/');
|
||||
const hasAssetLikeExtension =
|
||||
path.extname(parsedUrl.pathname) &&
|
||||
!parsedUrl.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
|
||||
path.extname(localUrlPath.pathname) &&
|
||||
!localUrlPath.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
|
||||
if (!hasSiteAlias && !hasAssetLikeExtension) {
|
||||
return;
|
||||
}
|
||||
|
||||
const localFilePath = await getLocalFileAbsolutePath(
|
||||
decodeURIComponent(parsedUrl.pathname),
|
||||
decodeURIComponent(localUrlPath.pathname),
|
||||
context,
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue