Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devcontainer upgrade and implement workaround for #10769 #10770

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
44 changes: 24 additions & 20 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
"settings": {
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
"customizations": {
"vscode": {
"settings": {
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
},
"extensions": [
"dbaeumer.vscode-eslint",
"orta.vscode-jest",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker"
]
}
},
"extensions": [
"dbaeumer.vscode-eslint",
"orta.vscode-jest",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker"
],
"forwardPorts": [3000],
"containerUser": "vscode",
"postCreateCommand": "yarn install",
"waitFor": "postCreateCommand", // otherwise automated jest tests fail
"features": {
"node": {
"version": "18"
"version": "22"
},
"github-cli": "latest"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {applyTrailingSlash} from '@docusaurus/utils-common';
import {loadSiteConfig} from '../server/config';
import {build} from './build/build';
import {getHostPort, type HostPortOptions} from '../server/getHostPort';
import {forceV4OnRemoteContainers} from '../server/remoteContainersHook';
import type {LoadContextParams} from '../server/site';

function redirect(res: http.ServerResponse, location: string) {
Expand All @@ -41,6 +42,8 @@ export async function serve(
const buildDir = cliOptions.dir ?? DEFAULT_BUILD_DIR_NAME;
const outDir = path.resolve(siteDir, buildDir);

forceV4OnRemoteContainers(cliOptions);

if (cliOptions.build) {
await build(siteDir, {
config: cliOptions.config,
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus/src/commands/start/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import openBrowser from 'react-dev-utils/openBrowser';
import {setupSiteFileWatchers} from './watcher';
import {createWebpackDevServer} from './webpack';
import {createReloadableSite} from './utils';
import {forceV4OnRemoteContainers} from '../../server/remoteContainersHook';
import type {LoadContextParams} from '../../server/site';
import type {HostPortOptions} from '../../server/getHostPort';

Expand All @@ -31,6 +32,8 @@ export async function start(
// See https://github.com/facebook/docusaurus/issues/4542
process.env.DOCUSAURUS_CURRENT_LOCALE = cliOptions.locale;

forceV4OnRemoteContainers(cliOptions);

const reloadableSite = await createReloadableSite({siteDirParam, cliOptions});

setupSiteFileWatchers(
Expand Down
27 changes: 27 additions & 0 deletions packages/docusaurus/src/server/remoteContainersHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import logger from '@docusaurus/logger';

export function forceV4OnRemoteContainers(
userCLIConfig: OptionallyProvidedHost,
): void {
if (process.env.REMOTE_CONTAINERS === 'true') {
if (!userCLIConfig.host) {
userCLIConfig.host = '127.0.0.1';
logger.info(
'Will default to binding to IPv4 local address to better support VSCode Remote port forwarding',
);
} else {
logger.warn('VSCode Remote may not support IPv6');
}
}
}

export type OptionallyProvidedHost = {
host?: string;
};
Comment on lines +1 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to add Devcontainer specific things into Docusaurus core.

At best I can propose to implement docusaurus start --host 127.0.0, it's already supported for docusaurus serve. Devcontainer hacks should be added "from the outside"

Loading