Skip to content

Commit 28b2f42

Browse files
authored
refactor: clean up dead code for env API (#14395)
* refactor: clean up dead code for env API * Add comment and fix import * Format * Remove extra export * Drop Node 18 in tests
1 parent aa355a0 commit 28b2f42

File tree

16 files changed

+57
-92
lines changed

16 files changed

+57
-92
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
strategy:
111111
matrix:
112112
OS: [ubuntu-latest, macos-14, windows-2025]
113-
NODE_VERSION: [18, 20, 22]
113+
NODE_VERSION: [20, 22, 24]
114114
TEST_SUITE:
115115
- { name: astro, script: 'pnpm run test:astro' }
116116
- { name: integrations, script: 'pnpm run test:integrations' }
@@ -119,11 +119,11 @@ jobs:
119119
# Windows and use one of the older Node versions.
120120
exclude:
121121
- os: macos-14
122-
NODE_VERSION: 18
122+
NODE_VERSION: 24
123123
- os: macos-14
124124
NODE_VERSION: 20
125125
- os: windows-2025
126-
NODE_VERSION: 18
126+
NODE_VERSION: 24
127127
- os: windows-2025
128128
NODE_VERSION: 20
129129
fail-fast: false

knip.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export default {
3030
'e2e/**/*.test.js',
3131
'test/units/teardown.js',
3232
],
33-
ignore: ['**/e2e/**/{fixtures,_temp-fixtures}/**', 'performance/**/*'],
33+
ignore: [
34+
'**/e2e/**/{fixtures,_temp-fixtures}/**',
35+
'performance/**/*',
36+
// This export is resolved dynamically in packages/astro/src/vite-plugin-app/index.ts
37+
'src/vite-plugin-app/createExports.ts',
38+
],
3439
// Those deps are used in tests but only referenced as strings
3540
ignoreDependencies: [
3641
'rehype-autolink-headings',

packages/astro/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"./container": "./dist/container/index.js",
5151
"./app": "./dist/core/app/index.js",
5252
"./app/node": "./dist/core/app/node.js",
53-
"./app/dev": "./dist/core/app/dev/index.js",
5453
"./client/*": "./dist/runtime/client/*",
5554
"./components": "./components/index.ts",
5655
"./components/*": "./components/*",

packages/astro/src/core/build/plugins/plugin-prerender.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Rollup, Plugin as VitePlugin } from 'vite';
2-
import { getPrerenderMetadata } from '../../../prerender/metadata.js';
32
import type { BuildInternals } from '../internal.js';
43
import type { AstroBuildPlugin } from '../plugin.js';
54
import type { StaticBuildOptions } from '../types.js';
@@ -17,9 +16,7 @@ function vitePluginPrerender(internals: BuildInternals): VitePlugin {
1716
if (!pageInfo) continue;
1817
const moduleInfo = this.getModuleInfo(id);
1918
if (!moduleInfo) continue;
20-
21-
const prerender = !!getPrerenderMetadata(moduleInfo);
22-
pageInfo.route.prerender = prerender;
19+
pageInfo.route.prerender = Boolean(moduleInfo?.meta?.astro?.pageOptions?.prerender);
2320
}
2421

2522
// Find all chunks used in the SSR runtime (that aren't used for prerendering only), then use

packages/astro/src/core/build/plugins/plugin-renderers.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { addRollupInput } from '../add-rollup-input.js';
66
import type { AstroBuildPlugin } from '../plugin.js';
77
import type { StaticBuildOptions } from '../types.js';
88

9-
// Keep the old export for backwards compatibility, but it now points to the new module ID
10-
export const RENDERERS_MODULE_ID = ASTRO_RENDERERS_MODULE_ID;
11-
export const RESOLVED_RENDERERS_MODULE_ID = `\0${RENDERERS_MODULE_ID}`;
12-
139
function vitePluginRenderersForBuild(opts: StaticBuildOptions): VitePlugin {
1410
const basePlugin = vitePluginRenderers({ settings: opts.settings });
1511

packages/astro/src/core/build/static-build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { appendForwardSlash, prependForwardSlash } from '../../core/path.js';
1111
import { runHookBuildSetup } from '../../integrations/hooks.js';
1212
import { getServerOutputDirectory } from '../../prerender/utils.js';
1313
import type { RouteData } from '../../types/public/internal.js';
14+
import { RESOLVED_ASTRO_RENDERERS_MODULE_ID } from '../../vite-plugin-renderers/index.js';
1415
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
1516
import { routeIsRedirect } from '../redirects/index.js';
1617
import { getOutDirWithinCwd } from './common.js';
@@ -21,7 +22,6 @@ import { type AstroBuildPluginContainer, createPluginContainer } from './plugin.
2122
import { registerAllPlugins } from './plugins/index.js';
2223
import { RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID } from './plugins/plugin-manifest.js';
2324
import { ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js';
24-
import { RESOLVED_RENDERERS_MODULE_ID } from './plugins/plugin-renderers.js';
2525
import { RESOLVED_SSR_VIRTUAL_MODULE_ID } from './plugins/plugin-ssr.js';
2626
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
2727
import type { StaticBuildOptions } from './types.js';
@@ -199,7 +199,7 @@ async function ssrBuild(
199199
);
200200
} else if (chunkInfo.facadeModuleId === RESOLVED_SSR_VIRTUAL_MODULE_ID) {
201201
return opts.settings.config.build.serverEntry;
202-
} else if (chunkInfo.facadeModuleId === RESOLVED_RENDERERS_MODULE_ID) {
202+
} else if (chunkInfo.facadeModuleId === RESOLVED_ASTRO_RENDERERS_MODULE_ID) {
203203
return 'renderers.mjs';
204204
} else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) {
205205
return 'manifest_[hash].mjs';

packages/astro/src/core/config/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export {
33
resolveConfigPath,
44
resolveRoot,
55
} from './config.js';
6-
export { createConsoleLogger, createNodeLogger } from './logging.js';
76
export { mergeConfig } from './merge.js';
87
export { createSettings } from './settings.js';
98
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { AstroInlineConfig } from '../../types/public/config.js';
2-
import { consoleLogDestination } from '../logger/console.js';
32
import { Logger } from '../logger/core.js';
43
import { nodeLogDestination } from '../logger/node.js';
54

@@ -11,10 +10,3 @@ export function createNodeLogger(inlineConfig: AstroInlineConfig): Logger {
1110
level: inlineConfig.logLevel ?? 'info',
1211
});
1312
}
14-
15-
export function createConsoleLogger(level: AstroInlineConfig['logLevel']): Logger {
16-
return new Logger({
17-
dest: consoleLogDestination,
18-
level: level ?? 'info',
19-
});
20-
}

packages/astro/src/core/dev/restart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { eventCliSession, telemetry } from '../../events/index.js';
77
import { SETTINGS_FILE } from '../../preferences/constants.js';
88
import type { AstroSettings } from '../../types/astro.js';
99
import type { AstroInlineConfig } from '../../types/public/config.js';
10-
import { createNodeLogger, createSettings, resolveConfig } from '../config/index.js';
10+
import { createSettings, resolveConfig } from '../config/index.js';
11+
import { createNodeLogger } from '../config/logging.js';
1112
import { collectErrorMetadata } from '../errors/dev/utils.js';
1213
import { isAstroConfigZodError } from '../errors/errors.js';
1314
import { createSafeError } from '../errors/index.js';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { escape } from 'html-escaper';
2+
import { bold, underline } from 'kleur/colors';
3+
import { AstroErrorData, type ErrorWithMetadata } from '../index.js';
4+
5+
/**
6+
* The docs has kebab-case urls for errors, so we need to convert the error name
7+
* @param errorName
8+
*/
9+
function getKebabErrorName(errorName: string): string {
10+
return errorName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
11+
}
12+
export function getDocsForError(err: ErrorWithMetadata): string | undefined {
13+
if (err.name !== 'UnknownError' && err.name in AstroErrorData) {
14+
return `https://docs.astro.build/en/reference/errors/${getKebabErrorName(err.name)}/`;
15+
}
16+
return undefined;
17+
}
18+
19+
const linkRegex = /\[([^[]+)\]\((.*)\)/g;
20+
const boldRegex = /\*\*(.+)\*\*/g;
21+
const urlRegex = / ((?:https?|ftp):\/\/[-\w+&@#\\/%?=~|!:,.;]*[-\w+&@#\\/%=~|])/gi;
22+
const codeRegex = /`([^`]+)`/g;
23+
24+
/**
25+
* Render a subset of Markdown to HTML or a CLI output
26+
*/
27+
export function renderErrorMarkdown(markdown: string, target: 'html' | 'cli') {
28+
if (target === 'html') {
29+
return escape(markdown)
30+
.replace(linkRegex, `<a href="$2" target="_blank">$1</a>`)
31+
.replace(boldRegex, '<b>$1</b>')
32+
.replace(urlRegex, ' <a href="$1" target="_blank">$1</a>')
33+
.replace(codeRegex, '<code>$1</code>');
34+
} else {
35+
return markdown
36+
.replace(linkRegex, (_, m1, m2) => `${bold(m1)} ${underline(m2)}`)
37+
.replace(urlRegex, (fullMatch) => ` ${underline(fullMatch.trim())}`)
38+
.replace(boldRegex, (_, m1) => `${bold(m1)}`);
39+
}
40+
}

0 commit comments

Comments
 (0)