Skip to content

Commit

Permalink
Merge branch 'main' into cleanup-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jan 10, 2023
2 parents 63d2f29 + 10137cd commit f74260e
Show file tree
Hide file tree
Showing 49 changed files with 331 additions and 665 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-rivers-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/lit': patch
---

Only shim fetch if not already present
16 changes: 16 additions & 0 deletions .changeset/curvy-beds-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'astro': major
'@astrojs/prism': major
'create-astro': major
'@astrojs/mdx': minor
'@astrojs/node': major
'@astrojs/preact': major
'@astrojs/react': major
'@astrojs/solid-js': major
'@astrojs/svelte': major
'@astrojs/vercel': major
'@astrojs/vue': major
'@astrojs/telemetry': major
---

Remove support for Node 14. Minimum supported Node version is now >=16.12.0
5 changes: 5 additions & 0 deletions .changeset/lemon-bobcats-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': major
---

Default preview host to `localhost` instead of `127.0.0.1`. This allows the static server and integration preview servers to serve under ipv6.
7 changes: 7 additions & 0 deletions .changeset/stupid-wolves-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astrojs/webapi': major
---

Replace node-fetch's polyfill with undici.

Since `undici` does not support it, this change also removes custom support for the `file:` protocol
2 changes: 1 addition & 1 deletion packages/astro-prism/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"@types/prismjs": "1.26.0"
},
"engines": {
"node": "^14.18.0 || >=16.12.0"
"node": ">=16.12.0"
}
}
2 changes: 1 addition & 1 deletion packages/astro/astro.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function main() {
// it's okay to hard-code the valid Node versions here since they will not change over time.
if (typeof require === 'undefined') {
console.error(`\nNode.js v${version} is not supported by Astro!
Please upgrade to a version of Node.js with complete ESM support: "^14.18.0 || >=16.12.0"\n`);
Please upgrade to a supported version of Node.js: ">=16.12.0"\n`);
}

// Not supported: Report the most helpful error message possible.
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
"prompts": "^2.4.2",
"rehype": "^12.0.1",
"semver": "^7.3.7",
"server-destroy": "^1.0.1",
"shiki": "^0.11.1",
"sirv": "^2.0.2",
"slash": "^4.0.0",
"string-width": "^5.1.2",
"strip-ansi": "^7.0.1",
Expand All @@ -163,7 +163,7 @@
"zod": "^3.17.3"
},
"devDependencies": {
"@playwright/test": "^1.22.2",
"@playwright/test": "^1.29.2",
"@types/babel__generator": "^7.6.4",
"@types/babel__traverse": "^7.17.1",
"@types/chai": "^4.3.1",
Expand All @@ -182,14 +182,14 @@
"@types/resolve": "^1.20.2",
"@types/rimraf": "^3.0.2",
"@types/send": "^0.17.1",
"@types/server-destroy": "^1.0.1",
"@types/unist": "^2.0.6",
"astro-scripts": "workspace:*",
"chai": "^4.3.6",
"cheerio": "^1.0.0-rc.11",
"eol": "^0.9.1",
"memfs": "^3.4.7",
"mocha": "^9.2.2",
"node-fetch": "^3.2.5",
"node-mocks-http": "^1.11.0",
"rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.0.1",
Expand All @@ -198,11 +198,11 @@
"rollup": "^3.9.0",
"sass": "^1.52.2",
"srcset-parse": "^1.1.0",
"typescript": "*",
"undici": "^5.14.0",
"unified": "^10.1.2"
},
"engines": {
"node": "^14.18.0 || >=16.12.0",
"node": ">=16.12.0",
"npm": ">=6.14.0"
}
}
5 changes: 1 addition & 4 deletions packages/astro/src/core/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,14 @@ export default async function dev(
// Start listening to the port
const devServerAddressInfo = await startContainer(restart.container);

const site = settings.config.site
? new URL(settings.config.base, settings.config.site)
: undefined;
info(
options.logging,
null,
msg.serverStart({
startupTime: performance.now() - devStart,
resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
host: settings.config.server.host,
site,
base: settings.config.base,
isRestart: options.isRestart,
})
);
Expand Down
67 changes: 5 additions & 62 deletions packages/astro/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import {
underline,
yellow,
} from 'kleur/colors';
import type { AddressInfo } from 'net';
import os from 'os';
import { ResolvedServerUrls } from 'vite';
import { ZodError } from 'zod';
import { renderErrorMarkdown } from './errors/dev/utils.js';
import { AstroError, CompilerError, ErrorWithMetadata } from './errors/index.js';
import { removeTrailingForwardSlash } from './path.js';
import { emoji, getLocalAddress, padMultilineString } from './util.js';
import { emoji, padMultilineString } from './util.js';

const PREFIX_PADDING = 6;

Expand Down Expand Up @@ -58,31 +55,26 @@ export function serverStart({
startupTime,
resolvedUrls,
host,
site,
base,
isRestart = false,
}: {
startupTime: number;
resolvedUrls: ResolvedServerUrls;
host: string | boolean;
site: URL | undefined;
base: string;
isRestart?: boolean;
}): string {
// PACKAGE_VERSION is injected at build-time
const version = process.env.PACKAGE_VERSION ?? '0.0.0';
const rootPath = site ? site.pathname : '/';
const localPrefix = `${dim('┃')} Local `;
const networkPrefix = `${dim('┃')} Network `;
const emptyPrefix = ' '.repeat(11);

const localUrlMessages = resolvedUrls.local.map((url, i) => {
return `${i === 0 ? localPrefix : emptyPrefix}${bold(
cyan(removeTrailingForwardSlash(url) + rootPath)
)}`;
return `${i === 0 ? localPrefix : emptyPrefix}${bold(cyan(new URL(url).origin + base))}`;
});
const networkUrlMessages = resolvedUrls.network.map((url, i) => {
return `${i === 0 ? networkPrefix : emptyPrefix}${bold(
cyan(removeTrailingForwardSlash(url) + rootPath)
)}`;
return `${i === 0 ? networkPrefix : emptyPrefix}${bold(cyan(new URL(url).origin + base))}`;
});

if (networkUrlMessages.length === 0) {
Expand All @@ -109,50 +101,6 @@ export function serverStart({
.join('\n');
}

export function resolveServerUrls({
address,
host,
https,
}: {
address: AddressInfo;
host: string | boolean;
https: boolean;
}): ResolvedServerUrls {
const { address: networkAddress, port } = address;
const localAddress = getLocalAddress(networkAddress, host);
const networkLogging = getNetworkLogging(host);
const toDisplayUrl = (hostname: string) => `${https ? 'https' : 'http'}://${hostname}:${port}`;

let local = toDisplayUrl(localAddress);
let network: string | null = null;

if (networkLogging === 'visible') {
const ipv4Networks = Object.values(os.networkInterfaces())
.flatMap((networkInterface) => networkInterface ?? [])
.filter(
(networkInterface) =>
networkInterface?.address &&
// Node < v18
((typeof networkInterface.family === 'string' && networkInterface.family === 'IPv4') ||
// Node >= v18
(typeof networkInterface.family === 'number' && (networkInterface as any).family === 4))
);
for (let { address: ipv4Address } of ipv4Networks) {
if (ipv4Address.includes('127.0.0.1')) {
const displayAddress = ipv4Address.replace('127.0.0.1', localAddress);
local = toDisplayUrl(displayAddress);
} else {
network = toDisplayUrl(ipv4Address);
}
}
}

return {
local: [local],
network: network ? [network] : [],
};
}

export function telemetryNotice() {
const headline = yellow(`Astro now collects ${bold('anonymous')} usage data.`);
const why = `This ${bold('optional program')} will help shape our roadmap.`;
Expand Down Expand Up @@ -228,11 +176,6 @@ export function cancelled(message: string, tip?: string) {
.join('\n');
}

/** Display port in use */
export function portInUse({ port }: { port: number }): string {
return `Port ${port} in use. Trying a new one…`;
}

const LOCAL_IP_HOSTS = new Set(['localhost', '127.0.0.1']);

export function getNetworkLogging(host: string | boolean): 'none' | 'host-to-expose' | 'visible' {
Expand Down
8 changes: 3 additions & 5 deletions packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export default async function preview(
logging: logging,
});
await runHookConfigDone({ settings: settings, logging: logging });
const host = getResolvedHostForHttpServer(settings.config.server.host);
const { port, headers } = settings.config.server;

if (settings.config.output === 'static') {
const server = await createStaticPreviewServer(settings, { logging, host, port, headers });
const server = await createStaticPreviewServer(settings, logging);
return server;
}
if (!settings.adapter) {
Expand Down Expand Up @@ -55,8 +53,8 @@ export default async function preview(
outDir: settings.config.outDir,
client: settings.config.build.client,
serverEntrypoint: new URL(settings.config.build.serverEntry, settings.config.build.server),
host,
port,
host: getResolvedHostForHttpServer(settings.config.server.host),
port: settings.config.server.port,
base: settings.config.base,
});

Expand Down
Loading

0 comments on commit f74260e

Please sign in to comment.