diff --git a/.changeset/eleven-buttons-wash.md b/.changeset/eleven-buttons-wash.md new file mode 100644 index 000000000000..0e3cd3713c1d --- /dev/null +++ b/.changeset/eleven-buttons-wash.md @@ -0,0 +1,25 @@ +--- +'@astrojs/cloudflare': patch +'@astrojs/partytown': patch +'@astrojs/alpinejs': patch +'@astrojs/prefetch': patch +'@astrojs/tailwind': patch +'@astrojs/markdoc': patch +'@astrojs/sitemap': patch +'@astrojs/underscore-redirects': patch +'@astrojs/preact': patch +'@astrojs/svelte': patch +'@astrojs/vercel': patch +'@astrojs/react': patch +'@astrojs/solid-js': patch +'@astrojs/node': patch +'@astrojs/lit': patch +'@astrojs/mdx': patch +'@astrojs/vue': patch +'@astrojs/internal-helpers': patch +'@astrojs/markdown-remark': patch +'@astrojs/telemetry': patch +'astro': patch +--- + +Add provenance statement when publishing the library from CI diff --git a/.changeset/red-masks-drop.md b/.changeset/red-masks-drop.md new file mode 100644 index 000000000000..3564fa9e8a53 --- /dev/null +++ b/.changeset/red-masks-drop.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix `tsconfig.json` update causing the server to crash diff --git a/.changeset/tricky-otters-cross.md b/.changeset/tricky-otters-cross.md new file mode 100644 index 000000000000..e104f78eb30c --- /dev/null +++ b/.changeset/tricky-otters-cross.md @@ -0,0 +1,5 @@ +--- +'@astrojs/partytown': patch +--- + +Expose types for TypeScript users diff --git a/.changeset/witty-fishes-heal.md b/.changeset/witty-fishes-heal.md new file mode 100644 index 000000000000..0fb1d79f726c --- /dev/null +++ b/.changeset/witty-fishes-heal.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improve `astro info` copy to clipboard compatability diff --git a/packages/astro/package.json b/packages/astro/package.json index 7b7ef218c6fb..aec2fb5e52a0 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -226,5 +226,8 @@ "engines": { "node": ">=18.14.1", "npm": ">=6.14.0" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index 2ee9ffd0d784..cfa9aca8f636 100644 --- a/packages/astro/src/cli/info/index.ts +++ b/packages/astro/src/cli/info/index.ts @@ -41,10 +41,22 @@ export async function printInfo({ flags }: InfoOptions) { await copyToClipboard(output.trim()); } -const SUPPORTED_SYSTEM = new Set(['darwin', 'win32']); async function copyToClipboard(text: string) { const system = platform(); - if (!SUPPORTED_SYSTEM.has(system)) return; + let command = ''; + if (system === 'darwin') { + command = 'pbcopy'; + } else if (system === 'win32') { + command = 'clip'; + } else { + // Unix: check if `xclip` is installed + const output = execSync('which xclip', { encoding: 'utf8' }); + if (output[0] !== '/') { + // Did not find a path for xclip, bail out! + return; + } + command = 'xclip -sel clipboard -l 1'; + } console.log(); const { shouldCopy } = await prompts({ @@ -54,11 +66,11 @@ async function copyToClipboard(text: string) { initial: true, }); if (!shouldCopy) return; - const command = system === 'darwin' ? 'pbcopy' : 'clip'; + try { - execSync(`echo ${JSON.stringify(text.trim())} | ${command}`, { + execSync(command, { + input: text.trim(), encoding: 'utf8', - stdio: 'ignore', }); } catch (e) { console.error( diff --git a/packages/astro/src/content/vite-plugin-content-imports.ts b/packages/astro/src/content/vite-plugin-content-imports.ts index 4643e0922872..15ca6d956b11 100644 --- a/packages/astro/src/content/vite-plugin-content-imports.ts +++ b/packages/astro/src/content/vite-plugin-content-imports.ts @@ -148,9 +148,15 @@ export const _internal = { hasContentFlag(modUrl, DATA_FLAG) || Boolean(getContentRendererByViteId(modUrl, settings)) ) { - const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl); - if (mod) { - viteServer.moduleGraph.invalidateModule(mod); + try { + const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl); + if (mod) { + viteServer.moduleGraph.invalidateModule(mod); + } + } catch (e: any) { + // The server may be closed due to a restart caused by this file change + if (e.code === 'ERR_CLOSED_SERVER') break; + throw e; } } } diff --git a/packages/astro/src/core/module-loader/vite.ts b/packages/astro/src/core/module-loader/vite.ts index f58b2e720c59..48ec230f078a 100644 --- a/packages/astro/src/core/module-loader/vite.ts +++ b/packages/astro/src/core/module-loader/vite.ts @@ -1,19 +1,52 @@ import { EventEmitter } from 'node:events'; +import path from 'node:path'; import type * as vite from 'vite'; import type { ModuleLoader, ModuleLoaderEventEmitter } from './loader.js'; export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader { const events = new EventEmitter() as ModuleLoaderEventEmitter; - viteServer.watcher.on('add', (...args) => events.emit('file-add', args)); - viteServer.watcher.on('unlink', (...args) => events.emit('file-unlink', args)); - viteServer.watcher.on('change', (...args) => events.emit('file-change', args)); + let isTsconfigUpdated = false; + function isTsconfigUpdate(filePath: string) { + const result = path.basename(filePath) === 'tsconfig.json'; + if (result) isTsconfigUpdated = true; + return result; + } - wrapMethod(viteServer.ws, 'send', (msg) => { + // Skip event emit on tsconfig change as Vite restarts the server, and we don't + // want to trigger unnecessary work that will be invalidated shortly. + viteServer.watcher.on('add', (...args) => { + if (!isTsconfigUpdate(args[0])) { + events.emit('file-add', args); + } + }); + viteServer.watcher.on('unlink', (...args) => { + if (!isTsconfigUpdate(args[0])) { + events.emit('file-unlink', args); + } + }); + viteServer.watcher.on('change', (...args) => { + if (!isTsconfigUpdate(args[0])) { + events.emit('file-change', args); + } + }); + + const _wsSend = viteServer.ws.send; + viteServer.ws.send = function (...args: any) { + // If the tsconfig changed, Vite will trigger a reload as it invalidates the module. + // However in Astro, the whole server is restarted when the tsconfig changes. If we + // do a restart and reload at the same time, the browser will refetch and the server + // is not ready yet, causing a blank page. Here we block that reload from happening. + if (isTsconfigUpdated) { + isTsconfigUpdated = false; + return; + } + const msg = args[0] as vite.HMRPayload; if (msg?.type === 'error') { events.emit('hmr-error', msg); } - }); + _wsSend.apply(this, args); + }; return { import(src) { @@ -56,11 +89,3 @@ export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader { events, }; } - -function wrapMethod(object: any, method: string, newFn: (...args: any[]) => void) { - const orig = object[method]; - object[method] = function (...args: any[]) { - newFn.apply(this, args); - return orig.apply(this, args); - }; -} diff --git a/packages/integrations/alpinejs/package.json b/packages/integrations/alpinejs/package.json index 8c927159baf6..9b9f0f0ee017 100644 --- a/packages/integrations/alpinejs/package.json +++ b/packages/integrations/alpinejs/package.json @@ -39,5 +39,8 @@ "devDependencies": { "astro": "workspace:*", "astro-scripts": "workspace:*" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/cloudflare/package.json b/packages/integrations/cloudflare/package.json index 0fc14b203df6..7d4d07356ad2 100644 --- a/packages/integrations/cloudflare/package.json +++ b/packages/integrations/cloudflare/package.json @@ -58,5 +58,8 @@ "cheerio": "1.0.0-rc.12", "mocha": "^10.2.0", "wrangler": "^3.5.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/lit/package.json b/packages/integrations/lit/package.json index 54498a070d57..28945b53ea63 100644 --- a/packages/integrations/lit/package.json +++ b/packages/integrations/lit/package.json @@ -59,5 +59,8 @@ "peerDependencies": { "@webcomponents/template-shadowroot": "^0.2.1", "lit": "^2.7.0" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/markdoc/package.json b/packages/integrations/markdoc/package.json index af1a1d2bc4e0..8cb356aaced3 100644 --- a/packages/integrations/markdoc/package.json +++ b/packages/integrations/markdoc/package.json @@ -94,5 +94,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/mdx/package.json b/packages/integrations/mdx/package.json index cd580afd51cb..8bd9c4c39268 100644 --- a/packages/integrations/mdx/package.json +++ b/packages/integrations/mdx/package.json @@ -79,5 +79,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/node/package.json b/packages/integrations/node/package.json index 337d1e65f514..20739cbd78da 100644 --- a/packages/integrations/node/package.json +++ b/packages/integrations/node/package.json @@ -51,5 +51,8 @@ "mocha": "^10.2.0", "node-mocks-http": "^1.13.0", "undici": "^5.23.0" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/partytown/package.json b/packages/integrations/partytown/package.json index 96c6795a4838..ed70b728032f 100644 --- a/packages/integrations/partytown/package.json +++ b/packages/integrations/partytown/package.json @@ -38,5 +38,8 @@ "devDependencies": { "astro": "workspace:*", "astro-scripts": "workspace:*" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index 13f7b1118e77..755026512399 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -9,7 +9,7 @@ import { fileURLToPath } from 'node:url'; import sirv from './sirv.js'; const resolve = createRequire(import.meta.url).resolve; -type PartytownOptions = { +export type PartytownOptions = { config?: PartytownConfig; }; diff --git a/packages/integrations/preact/package.json b/packages/integrations/preact/package.json index f1e5aa36258d..c2c24e096a63 100644 --- a/packages/integrations/preact/package.json +++ b/packages/integrations/preact/package.json @@ -52,5 +52,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/prefetch/package.json b/packages/integrations/prefetch/package.json index 4db207fd2e8e..52259fb18429 100644 --- a/packages/integrations/prefetch/package.json +++ b/packages/integrations/prefetch/package.json @@ -40,5 +40,8 @@ }, "dependencies": { "throttles": "^1.0.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/react/package.json b/packages/integrations/react/package.json index 8eabf545d458..1724f2d73178 100644 --- a/packages/integrations/react/package.json +++ b/packages/integrations/react/package.json @@ -67,5 +67,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/sitemap/package.json b/packages/integrations/sitemap/package.json index 16de7702ac64..fe285e7bf619 100644 --- a/packages/integrations/sitemap/package.json +++ b/packages/integrations/sitemap/package.json @@ -43,5 +43,8 @@ "chai": "^4.3.7", "mocha": "^10.2.0", "xml2js": "0.6.2" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/solid/package.json b/packages/integrations/solid/package.json index 5fd37d31d3d3..8dbccc9d968c 100644 --- a/packages/integrations/solid/package.json +++ b/packages/integrations/solid/package.json @@ -47,5 +47,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json index 77ee714b0cd4..a1b49b1eeed9 100644 --- a/packages/integrations/svelte/package.json +++ b/packages/integrations/svelte/package.json @@ -53,5 +53,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/tailwind/package.json b/packages/integrations/tailwind/package.json index 9a90b3c92d77..9e958b576f0f 100644 --- a/packages/integrations/tailwind/package.json +++ b/packages/integrations/tailwind/package.json @@ -45,5 +45,8 @@ "peerDependencies": { "astro": "workspace:^3.2.2", "tailwindcss": "^3.0.24" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json index 87881e0d11ac..2158289db959 100644 --- a/packages/integrations/vercel/package.json +++ b/packages/integrations/vercel/package.json @@ -72,5 +72,8 @@ "chai-jest-snapshot": "^2.0.0", "cheerio": "1.0.0-rc.12", "mocha": "^10.2.0" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json index ad2075613183..16a767e22fda 100644 --- a/packages/integrations/vue/package.json +++ b/packages/integrations/vue/package.json @@ -61,5 +61,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/internal-helpers/package.json b/packages/internal-helpers/package.json index 0ca757a03e0b..ae7f54f5340f 100644 --- a/packages/internal-helpers/package.json +++ b/packages/internal-helpers/package.json @@ -37,5 +37,8 @@ "keywords": [ "astro", "astro-component" - ] + ], + "publishConfig": { + "provenance": true + } } diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json index d5bd3efae7f3..61b3f4aaa16c 100644 --- a/packages/markdown/remark/package.json +++ b/packages/markdown/remark/package.json @@ -57,5 +57,8 @@ "chai": "^4.3.7", "mdast-util-mdx-expression": "^1.3.2", "mocha": "^10.2.0" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index d251c7fc9ea8..56564db453f2 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -49,5 +49,8 @@ }, "engines": { "node": ">=18.14.1" + }, + "publishConfig": { + "provenance": true } } diff --git a/packages/underscore-redirects/package.json b/packages/underscore-redirects/package.json index 2531a51c24ea..51d81860b96e 100644 --- a/packages/underscore-redirects/package.json +++ b/packages/underscore-redirects/package.json @@ -38,5 +38,8 @@ "keywords": [ "astro", "astro-component" - ] + ], + "publishConfig": { + "provenance": true + } }