diff --git a/examples/dev-overlay/.codesandbox/Dockerfile b/examples/dev-overlay/.codesandbox/Dockerfile deleted file mode 100644 index c3b5c81a121d..000000000000 --- a/examples/dev-overlay/.codesandbox/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -FROM node:18-bullseye diff --git a/examples/dev-overlay/.gitignore b/examples/dev-overlay/.gitignore deleted file mode 100644 index 6240da8b10bf..000000000000 --- a/examples/dev-overlay/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -# build output -dist/ -# generated types -.astro/ - -# dependencies -node_modules/ - -# logs -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* - - -# environment variables -.env -.env.production - -# macOS-specific files -.DS_Store diff --git a/examples/dev-overlay/.vscode/extensions.json b/examples/dev-overlay/.vscode/extensions.json deleted file mode 100644 index 22a15055d638..000000000000 --- a/examples/dev-overlay/.vscode/extensions.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "recommendations": ["astro-build.astro-vscode"], - "unwantedRecommendations": [] -} diff --git a/examples/dev-overlay/.vscode/launch.json b/examples/dev-overlay/.vscode/launch.json deleted file mode 100644 index d6422097621f..000000000000 --- a/examples/dev-overlay/.vscode/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "command": "./node_modules/.bin/astro dev", - "name": "Development server", - "request": "launch", - "type": "node-terminal" - } - ] -} diff --git a/examples/dev-overlay/README.md b/examples/dev-overlay/README.md deleted file mode 100644 index 906665df0458..000000000000 --- a/examples/dev-overlay/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Astro Starter Kit: Dev Overlay Showcase - -```sh -npm create astro@latest -- --template dev-overlay -``` - -[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal) -[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal) -[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json) - -> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! - -## 🚀 Project Structure - -Inside of your Astro project, you'll see the following folders and files: - -```text -/ -├── public/ -├── src/ -│ └── pages/ -│ └── index.astro -└── package.json -``` - -Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. - -There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. - -Any static assets, like images, can be placed in the `public/` directory. - -## 🧞 Commands - -All commands are run from the root of the project, from a terminal: - -| Command | Action | -| :------------------------ | :----------------------------------------------- | -| `npm install` | Installs dependencies | -| `npm run dev` | Starts local dev server at `localhost:4321` | -| `npm run build` | Build your production site to `./dist/` | -| `npm run preview` | Preview your build locally, before deploying | -| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | -| `npm run astro -- --help` | Get help using the Astro CLI | - -## 👀 Want to learn more? - -Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). diff --git a/examples/dev-overlay/astro-devtools-plugin.js b/examples/dev-overlay/astro-devtools-plugin.js deleted file mode 100644 index 409d4d1f05ad..000000000000 --- a/examples/dev-overlay/astro-devtools-plugin.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - id: 'custom', - title: "I'm a plugin!", - icon: '', -}; diff --git a/examples/dev-overlay/astro.config.mjs b/examples/dev-overlay/astro.config.mjs deleted file mode 100644 index 8947c2b607b0..000000000000 --- a/examples/dev-overlay/astro.config.mjs +++ /dev/null @@ -1,11 +0,0 @@ -import { defineConfig } from 'astro/config'; - -import solidJs from "@astrojs/solid-js"; - -// https://astro.build/config -export default defineConfig({ - devTools: { - plugins: ['./astro-devtools-plugin.js'] - }, - integrations: [solidJs()] -}); \ No newline at end of file diff --git a/examples/dev-overlay/components/Component.tsx b/examples/dev-overlay/components/Component.tsx deleted file mode 100644 index a482e0c64268..000000000000 --- a/examples/dev-overlay/components/Component.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export function HelloWorld(props: { text: string }) { - return <>
{props.text}

; -} diff --git a/examples/dev-overlay/package.json b/examples/dev-overlay/package.json deleted file mode 100644 index 7c1ba8e5927c..000000000000 --- a/examples/dev-overlay/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "@example/dev-overlay", - "type": "module", - "version": "0.0.1", - "private": true, - "scripts": { - "dev": "astro dev", - "start": "astro dev", - "build": "astro build", - "preview": "astro preview", - "astro": "astro" - }, - "dependencies": { - "astro": "^3.2.3", - "@astrojs/solid-js": "^3.0.1", - "solid-js": "^1.7.11" - } -} diff --git a/examples/dev-overlay/public/astro-logo.png b/examples/dev-overlay/public/astro-logo.png deleted file mode 100644 index 300e7633a71e..000000000000 Binary files a/examples/dev-overlay/public/astro-logo.png and /dev/null differ diff --git a/examples/dev-overlay/public/favicon.svg b/examples/dev-overlay/public/favicon.svg deleted file mode 100644 index f157bd1c5e28..000000000000 --- a/examples/dev-overlay/public/favicon.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - diff --git a/examples/dev-overlay/src/pages/index.astro b/examples/dev-overlay/src/pages/index.astro deleted file mode 100644 index 03fbe7218904..000000000000 --- a/examples/dev-overlay/src/pages/index.astro +++ /dev/null @@ -1,27 +0,0 @@ ---- -import { HelloWorld } from '../../components/Component'; ---- - - - - - - - - Astro - - -

Astro

- - - -

Components

- - - -
- - - - - diff --git a/examples/dev-overlay/tsconfig.json b/examples/dev-overlay/tsconfig.json deleted file mode 100644 index d8a3e745da90..000000000000 --- a/examples/dev-overlay/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "astro/tsconfigs/base", - "compilerOptions": { - "jsx": "preserve", - "jsxImportSource": "solid-js" - } -} \ No newline at end of file diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index c6580dd9e458..47f53440e055 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1084,10 +1084,6 @@ export interface AstroUserConfig { remotePatterns?: Partial[]; }; - devOverlay?: { - plugins: string[]; - }; - /** * @docs * @kind heading @@ -1526,6 +1522,7 @@ export interface AstroSettings { * Map of directive name (e.g. `load`) to the directive script code */ clientDirectives: Map; + devOverlayPlugins: string[]; tsConfig: TSConfig | undefined; tsConfigPath: string | undefined; watchFiles: string[]; @@ -2051,6 +2048,7 @@ export interface AstroIntegration { injectScript: (stage: InjectedScriptStage, content: string) => void; injectRoute: (injectRoute: InjectedRoute) => void; addClientDirective: (directive: ClientDirectiveConfig) => void; + addDevOverlayPlugin: (entrypoint: string) => void; logger: AstroIntegrationLogger; // TODO: Add support for `injectElement()` for full HTML element injection, not just scripts. // This may require some refactoring of `scripts`, `styles`, and `links` into something diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index d811c420c662..ee470abc8fee 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -39,9 +39,6 @@ const ASTRO_CONFIG_DEFAULTS = { image: { service: { entrypoint: 'astro/assets/services/sharp', config: {} }, }, - devOverlay: { - plugins: [], - }, compressHTML: true, server: { host: false, @@ -231,9 +228,6 @@ export const AstroConfigSchema = z.object({ .default([]), }) .default(ASTRO_CONFIG_DEFAULTS.image), - devOverlay: z - .object({ plugins: z.array(z.string()).default([]) }) - .default(ASTRO_CONFIG_DEFAULTS.devOverlay), markdown: z .object({ drafts: z.boolean().default(false), diff --git a/packages/astro/src/core/config/settings.ts b/packages/astro/src/core/config/settings.ts index 07f22a33c080..cf4db7598e44 100644 --- a/packages/astro/src/core/config/settings.ts +++ b/packages/astro/src/core/config/settings.ts @@ -98,6 +98,7 @@ export function createBaseSettings(config: AstroConfig): AstroSettings { scripts: [], clientDirectives: getDefaultClientDirectives(), watchFiles: [], + devOverlayPlugins: [], timer: new AstroTimer(), }; } diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 3f75eb5b0e85..7aba9c602eac 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -16,7 +16,7 @@ import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.j import { vitePluginAstroServer } from '../vite-plugin-astro-server/index.js'; import astroVitePlugin from '../vite-plugin-astro/index.js'; import configAliasVitePlugin from '../vite-plugin-config-alias/index.js'; -import astroDevTools from '../vite-plugin-dev-tools/vite-plugin-dev-tools.js'; +import astroDevOverlay from '../vite-plugin-dev-tools/vite-plugin-dev-overlay.js'; import envVitePlugin from '../vite-plugin-env/index.js'; import astroHeadPlugin from '../vite-plugin-head/index.js'; import htmlVitePlugin from '../vite-plugin-html/index.js'; @@ -133,7 +133,7 @@ export async function createVite( vitePluginSSRManifest(), astroAssetsPlugin({ settings, logger, mode }), astroTransitions(), - astroDevTools({ settings, logger }), + astroDevOverlay({ settings, logger }), ], publicDir: fileURLToPath(settings.config.publicDir), root: fileURLToPath(settings.config.root), diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 5485794c5769..268721025fbf 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -125,6 +125,9 @@ export async function runHookConfigSetup({ addWatchFile: (path) => { updatedSettings.watchFiles.push(path instanceof URL ? fileURLToPath(path) : path); }, + addDevOverlayPlugin: (entrypoint) => { + updatedSettings.devOverlayPlugins.push(entrypoint); + }, addClientDirective: ({ name, entrypoint }) => { if (updatedSettings.clientDirectives.has(name) || addedClientDirectives.has(name)) { throw new Error( diff --git a/packages/astro/src/runtime/client/dev-overlay/overlay.ts b/packages/astro/src/runtime/client/dev-overlay/overlay.ts index 69a2bebd4fb9..200b8aeedd7e 100644 --- a/packages/astro/src/runtime/client/dev-overlay/overlay.ts +++ b/packages/astro/src/runtime/client/dev-overlay/overlay.ts @@ -1,12 +1,13 @@ /* eslint-disable no-console */ // @ts-expect-error -import { loadDevToolsPlugins } from 'astro:dev-tools'; +import { loadDevOverlayPlugins } from 'astro:dev-overlay'; import type { DevOverlayItem as DevOverlayItemDefinition } from '../../../@types/astro.js'; import astroDevToolPlugin from './plugins/astro.js'; import astroAuditPlugin from './plugins/audit.js'; import astroXrayPlugin from './plugins/xray.js'; import { DevOverlayCard } from './ui-library/card.js'; import { DevOverlayHighlight } from './ui-library/highlight.js'; +import { getIconElement } from './ui-library/icons.js'; import { DevOverlayTooltip } from './ui-library/tooltip.js'; import { DevOverlayWindow } from './ui-library/window.js'; @@ -29,7 +30,7 @@ document.addEventListener('DOMContentLoaded', async () => { status: 'loading', eventTarget: new EventTarget(), })); - const customPluginsImports = (await loadDevToolsPlugins()) as DevOverlayItemDefinition[]; + const customPluginsImports = (await loadDevOverlayPlugins()) as DevOverlayItemDefinition[]; const customPlugins: DevOverlayItem[] = []; customPlugins.push( ...customPluginsImports.map((plugin) => ({ @@ -67,12 +68,18 @@ document.addEventListener('DOMContentLoaded', async () => { async connectedCallback() { this.shadowRoot.innerHTML = ` -
-
- ${builtinPlugins.map((plugin) => this.getPluginTemplate(plugin)).join('')} -
- ${customPlugins.map((plugin) => this.getPluginTemplate(plugin)).join('')} +
+
+
+ ${builtinPlugins.map((plugin) => this.getPluginTemplate(plugin)).join('')} +
+ ${customPlugins.map((plugin) => this.getPluginTemplate(plugin)).join('')} +
+
${getIconElement('arrow-down')?.outerHTML}
`; this.attachClickEvents(); @@ -211,7 +235,7 @@ document.addEventListener('DOMContentLoaded', async () => { plugin.status = 'ready'; if (import.meta.hot) { - import.meta.hot.send(`${WS_EVENT_NAME}:${plugin.id}:init`, { msg: 'Hey!' }); + import.meta.hot.send(`${WS_EVENT_NAME}:${plugin.id}:init`); } } catch (e) { console.error(`Failed to init plugin ${plugin.id}, error: ${e}`); @@ -253,6 +277,8 @@ document.addEventListener('DOMContentLoaded', async () => { import.meta.hot.send(`${WS_EVENT_NAME}:${plugin.id}:toggle`, { state: plugin.active }); } } + + showMinimizeButton() {} } class DevOverlayCanvas extends HTMLElement { diff --git a/packages/astro/src/runtime/client/dev-overlay/ui-library/icons.ts b/packages/astro/src/runtime/client/dev-overlay/ui-library/icons.ts index 7efe9ec1df78..9281a1571923 100644 --- a/packages/astro/src/runtime/client/dev-overlay/ui-library/icons.ts +++ b/packages/astro/src/runtime/client/dev-overlay/ui-library/icons.ts @@ -1,8 +1,3 @@ -const icons = { - 'astro:logo': ``, - warning: ``, -} as const; - export type DefinedIcon = keyof typeof icons; export type Icon = DefinedIcon | (string & NonNullable); @@ -24,3 +19,10 @@ export function getIconElement( return svgFragment.firstElementChild as SVGElement; } + +const icons = { + 'astro:logo': ``, + warning: ``, + 'arrow-down': + '', +} as const; diff --git a/packages/astro/src/vite-plugin-dev-tools/vite-plugin-dev-overlay.ts b/packages/astro/src/vite-plugin-dev-tools/vite-plugin-dev-overlay.ts new file mode 100644 index 000000000000..e92952b003cf --- /dev/null +++ b/packages/astro/src/vite-plugin-dev-tools/vite-plugin-dev-overlay.ts @@ -0,0 +1,27 @@ +import type * as vite from 'vite'; +import type { AstroPluginOptions } from '../@types/astro.js'; + +const VIRTUAL_MODULE_ID = 'astro:dev-overlay'; +const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID; + +export default function astroDevOverlay({ settings }: AstroPluginOptions): vite.Plugin { + return { + name: 'astro:dev-overlay', + resolveId(id) { + if (id === VIRTUAL_MODULE_ID) { + return resolvedVirtualModuleId; + } + }, + load(id) { + if (id === resolvedVirtualModuleId) { + return ` + export const loadDevOverlayPlugins = async () => { + return [${settings.devOverlayPlugins + .map((plugin) => `(await import('${plugin}')).default`) + .join(',')}]; + }; + `; + } + }, + }; +} diff --git a/packages/astro/src/vite-plugin-dev-tools/vite-plugin-dev-tools.ts b/packages/astro/src/vite-plugin-dev-tools/vite-plugin-dev-tools.ts deleted file mode 100644 index d766062e77ff..000000000000 --- a/packages/astro/src/vite-plugin-dev-tools/vite-plugin-dev-tools.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type * as vite from 'vite'; -import type { AstroPluginOptions } from '../@types/astro.js'; - -const VIRTUAL_MODULE_ID = 'astro:dev-tools'; -const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID; - -export default function astroDevTools({ settings }: AstroPluginOptions): vite.Plugin { - return { - name: 'astro:dev-tools', - resolveId(id) { - if (id === VIRTUAL_MODULE_ID) { - return resolvedVirtualModuleId; - } - }, - load(id) { - if (id === resolvedVirtualModuleId) { - return ` - export const loadDevToolsPlugins = async () => { - return [${settings.config.devTools.plugins.map((p) => `(await import('${p}')).default`).join(',')}]; - }; - `; - } - }, - configureServer(server) { - // Example: wait for a client to connect before sending a message - server.ws.on('connection', () => { - server.ws.send('astro-dev-tools', { msg: 'hello' }); - }); - }, - }; -}