Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Oct 3, 2023
2 parents f2623ee + 240d8ff commit 65564de
Show file tree
Hide file tree
Showing 29 changed files with 170 additions and 24 deletions.
25 changes: 25 additions & 0 deletions .changeset/eleven-buttons-wash.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/red-masks-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix `tsconfig.json` update causing the server to crash
5 changes: 5 additions & 0 deletions .changeset/tricky-otters-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/partytown': patch
---

Expose types for TypeScript users
5 changes: 5 additions & 0 deletions .changeset/witty-fishes-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improve `astro info` copy to clipboard compatability
3 changes: 3 additions & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,8 @@
"engines": {
"node": ">=18.14.1",
"npm": ">=6.14.0"
},
"publishConfig": {
"provenance": true
}
}
22 changes: 17 additions & 5 deletions packages/astro/src/cli/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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(
Expand Down
12 changes: 9 additions & 3 deletions packages/astro/src/content/vite-plugin-content-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
51 changes: 38 additions & 13 deletions packages/astro/src/core/module-loader/vite.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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);
};
}
3 changes: 3 additions & 0 deletions packages/integrations/alpinejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
"devDependencies": {
"astro": "workspace:*",
"astro-scripts": "workspace:*"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@
"cheerio": "1.0.0-rc.12",
"mocha": "^10.2.0",
"wrangler": "^3.5.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
"peerDependencies": {
"@webcomponents/template-shadowroot": "^0.2.1",
"lit": "^2.7.0"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
"mocha": "^10.2.0",
"node-mocks-http": "^1.13.0",
"undici": "^5.23.0"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/partytown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"devDependencies": {
"astro": "workspace:*",
"astro-scripts": "workspace:*"
},
"publishConfig": {
"provenance": true
}
}
2 changes: 1 addition & 1 deletion packages/integrations/partytown/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/prefetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
},
"dependencies": {
"throttles": "^1.0.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
"chai": "^4.3.7",
"mocha": "^10.2.0",
"xml2js": "0.6.2"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
"peerDependencies": {
"astro": "workspace:^3.2.2",
"tailwindcss": "^3.0.24"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@
"chai-jest-snapshot": "^2.0.0",
"cheerio": "1.0.0-rc.12",
"mocha": "^10.2.0"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/integrations/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
5 changes: 4 additions & 1 deletion packages/internal-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"keywords": [
"astro",
"astro-component"
]
],
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/markdown/remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@
"chai": "^4.3.7",
"mdast-util-mdx-expression": "^1.3.2",
"mocha": "^10.2.0"
},
"publishConfig": {
"provenance": true
}
}
3 changes: 3 additions & 0 deletions packages/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
},
"engines": {
"node": ">=18.14.1"
},
"publishConfig": {
"provenance": true
}
}
5 changes: 4 additions & 1 deletion packages/underscore-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"keywords": [
"astro",
"astro-component"
]
],
"publishConfig": {
"provenance": true
}
}

0 comments on commit 65564de

Please sign in to comment.