Skip to content

Commit 4a1cabf

Browse files
authored
Cleanup dependencies (#5773)
1 parent 10137cd commit 4a1cabf

File tree

9 files changed

+20
-110
lines changed

9 files changed

+20
-110
lines changed

.changeset/six-carpets-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Cleanup dependencies

packages/astro/package.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
"@babel/traverse": "^7.18.2",
122122
"@babel/types": "^7.18.4",
123123
"@types/babel__core": "^7.1.19",
124-
"@types/html-escaper": "^3.0.0",
125124
"@types/yargs-parser": "^21.0.0",
126125
"acorn": "^8.8.1",
127126
"boxen": "^6.2.1",
@@ -138,22 +137,15 @@
138137
"fast-glob": "^3.2.11",
139138
"github-slugger": "^2.0.0",
140139
"gray-matter": "^4.0.3",
141-
"html-entities": "^2.3.3",
142140
"html-escaper": "^3.0.3",
143-
"import-meta-resolve": "^2.1.0",
144141
"kleur": "^4.1.4",
145142
"magic-string": "^0.27.0",
146143
"mime": "^3.0.0",
147144
"ora": "^6.1.0",
148-
"path-browserify": "^1.0.1",
149145
"path-to-regexp": "^6.2.1",
150-
"postcss": "^8.4.14",
151-
"postcss-load-config": "^3.1.4",
152146
"preferred-pm": "^3.0.3",
153147
"prompts": "^2.4.2",
154-
"recast": "^0.20.5",
155148
"rehype": "^12.0.1",
156-
"resolve": "^1.22.0",
157149
"semver": "^7.3.7",
158150
"server-destroy": "^1.0.1",
159151
"shiki": "^0.11.1",
@@ -182,10 +174,9 @@
182174
"@types/diff": "^5.0.2",
183175
"@types/estree": "^0.0.51",
184176
"@types/hast": "^2.3.4",
177+
"@types/html-escaper": "^3.0.0",
185178
"@types/mime": "^2.0.3",
186179
"@types/mocha": "^9.1.1",
187-
"@types/parse5": "^6.0.3",
188-
"@types/path-browserify": "^1.0.0",
189180
"@types/prettier": "^2.6.3",
190181
"@types/prompts": "^2.0.14",
191182
"@types/resolve": "^1.20.2",

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import type { RehypePlugin, RemarkPlugin, RemarkRehype } from '@astrojs/markdown-remark';
22
import { markdownConfigDefaults } from '@astrojs/markdown-remark';
3-
import type * as Postcss from 'postcss';
43
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
54
import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro';
65

76
import { OutgoingHttpHeaders } from 'http';
8-
import postcssrc from 'postcss-load-config';
97
import { BUNDLED_THEMES } from 'shiki';
10-
import { fileURLToPath } from 'url';
118
import { z } from 'zod';
129
import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js';
13-
import { isObject } from '../util.js';
1410

1511
const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
1612
root: '.',
@@ -183,35 +179,6 @@ export const AstroConfigSchema = z.object({
183179
legacy: z.object({}).optional().default({}),
184180
});
185181

186-
interface PostCSSConfigResult {
187-
options: Postcss.ProcessOptions;
188-
plugins: Postcss.Plugin[];
189-
}
190-
191-
async function resolvePostcssConfig(inlineOptions: any, root: URL): Promise<PostCSSConfigResult> {
192-
if (isObject(inlineOptions)) {
193-
const options = { ...inlineOptions };
194-
delete options.plugins;
195-
return {
196-
options,
197-
plugins: inlineOptions.plugins || [],
198-
};
199-
}
200-
const searchPath = typeof inlineOptions === 'string' ? inlineOptions : fileURLToPath(root);
201-
try {
202-
// @ts-ignore
203-
return await postcssrc({}, searchPath);
204-
} catch (err: any) {
205-
if (!/No PostCSS Config found/.test(err.message)) {
206-
throw err;
207-
}
208-
return {
209-
options: {},
210-
plugins: [],
211-
};
212-
}
213-
}
214-
215182
export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) {
216183
// We need to extend the global schema to add transforms that are relative to root.
217184
// This is type checked against the global schema to make sure we still match.

packages/astro/src/core/create-vite.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import markdownVitePlugin from '../vite-plugin-markdown/index.js';
2424
import astroScannerPlugin from '../vite-plugin-scanner/index.js';
2525
import astroScriptsPlugin from '../vite-plugin-scripts/index.js';
2626
import astroScriptsPageSSRPlugin from '../vite-plugin-scripts/page-ssr.js';
27-
import { resolveDependency } from './util.js';
2827

2928
interface CreateViteOptions {
3029
settings: AstroSettings;
@@ -33,7 +32,7 @@ interface CreateViteOptions {
3332
fs?: typeof nodeFs;
3433
}
3534

36-
const ALWAYS_NOEXTERNAL = new Set([
35+
const ALWAYS_NOEXTERNAL = [
3736
// This is only because Vite's native ESM doesn't resolve "exports" correctly.
3837
'astro',
3938
// Vite fails on nested `.astro` imports without bundling
@@ -43,21 +42,7 @@ const ALWAYS_NOEXTERNAL = new Set([
4342
'@nanostores/preact',
4443
// fontsource packages are CSS that need to be processed
4544
'@fontsource/*',
46-
]);
47-
48-
function getSsrNoExternalDeps(projectRoot: URL): string[] {
49-
let noExternalDeps = [];
50-
for (const dep of ALWAYS_NOEXTERNAL) {
51-
try {
52-
resolveDependency(dep, projectRoot);
53-
noExternalDeps.push(dep);
54-
} catch {
55-
// ignore dependency if *not* installed / present in your project
56-
// prevents hard error from Vite!
57-
}
58-
}
59-
return noExternalDeps;
60-
}
45+
];
6146

6247
/** Return a common starting point for all Vite actions */
6348
export async function createVite(
@@ -166,10 +151,7 @@ export async function createVite(
166151
dedupe: ['astro'],
167152
},
168153
ssr: {
169-
noExternal: [
170-
...getSsrNoExternalDeps(settings.config.root),
171-
...astroPkgsConfig.ssr.noExternal,
172-
],
154+
noExternal: [...ALWAYS_NOEXTERNAL, ...astroPkgsConfig.ssr.noExternal],
173155
// shiki is imported by Code.astro, which is no-externalized (processed by Vite).
174156
// However, shiki's deps are in CJS and trips up Vite's dev SSR transform, externalize
175157
// shiki to load it with node instead.

packages/astro/src/core/render/ssr-element.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import slashify from 'slash';
12
import type { SSRElement } from '../../@types/astro';
2-
3-
import npath from 'path-browserify';
4-
import { appendForwardSlash } from '../../core/path.js';
3+
import { appendForwardSlash, removeLeadingForwardSlash } from '../../core/path.js';
54

65
function getRootPath(base?: string): string {
76
return appendForwardSlash(new URL(base || '/', 'http://localhost/').pathname);
87
}
98

109
function joinToRoot(href: string, base?: string): string {
11-
return npath.posix.join(getRootPath(base), href);
10+
const rootPath = getRootPath(base);
11+
const normalizedHref = slashify(href);
12+
return appendForwardSlash(rootPath) + removeLeadingForwardSlash(normalizedHref);
1213
}
1314

1415
export function createLinkStylesheetElement(href: string, base?: string): SSRElement {

packages/astro/src/core/util.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import resolve from 'resolve';
43
import slash from 'slash';
5-
import { fileURLToPath, pathToFileURL } from 'url';
4+
import { fileURLToPath } from 'url';
65
import { normalizePath } from 'vite';
76
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
87
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js';
@@ -83,14 +82,6 @@ export function parseNpmName(
8382
};
8483
}
8584

86-
export function resolveDependency(dep: string, projectRoot: URL) {
87-
const resolved = resolve.sync(dep, {
88-
basedir: fileURLToPath(projectRoot),
89-
});
90-
// For Windows compat, we need a fully resolved `file://` URL string
91-
return pathToFileURL(resolved).toString();
92-
}
93-
9485
/**
9586
* Convert file URL to ID for viteServer.moduleGraph.idToModuleMap.get(:viteID)
9687
* Format:

packages/astro/src/template/4xx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { encode } from 'html-entities';
1+
import { escape } from 'html-escaper';
22
import { baseCSS } from './css.js';
33

44
interface ErrorTemplateOptions {
@@ -58,7 +58,7 @@ export default function template({
5858
${
5959
body ||
6060
`
61-
<pre>Path: ${encode(pathname)}</pre>
61+
<pre>Path: ${escape(pathname)}</pre>
6262
`
6363
}
6464
</main>

packages/astro/src/vite-plugin-jsx/tag.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { PluginObj } from '@babel/core';
22
import * as t from '@babel/types';
3-
import { resolve as importMetaResolve } from 'import-meta-resolve';
4-
import { fileURLToPath } from 'url';
53

64
/**
75
* This plugin handles every file that runs through our JSX plugin.
@@ -18,9 +16,6 @@ export default async function tagExportsWithRenderer({
1816
rendererName: string;
1917
root: URL;
2018
}): Promise<PluginObj> {
21-
const astroServerPath = fileURLToPath(
22-
await importMetaResolve('astro/server/index.js', root.toString())
23-
);
2419
return {
2520
visitor: {
2621
Program: {
@@ -36,7 +31,7 @@ export default async function tagExportsWithRenderer({
3631
t.identifier('__astro_tag_component__')
3732
),
3833
],
39-
t.stringLiteral(astroServerPath)
34+
t.stringLiteral('astro/server/index.js')
4035
)
4136
);
4237
},

pnpm-lock.yaml

Lines changed: 2 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)