Cleanup dependencies (#5773)
This commit is contained in:
parent
10137cd9cc
commit
4a1cabfe6b
9 changed files with 20 additions and 110 deletions
5
.changeset/six-carpets-talk.md
Normal file
5
.changeset/six-carpets-talk.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Cleanup dependencies
|
|
@ -121,7 +121,6 @@
|
|||
"@babel/traverse": "^7.18.2",
|
||||
"@babel/types": "^7.18.4",
|
||||
"@types/babel__core": "^7.1.19",
|
||||
"@types/html-escaper": "^3.0.0",
|
||||
"@types/yargs-parser": "^21.0.0",
|
||||
"acorn": "^8.8.1",
|
||||
"boxen": "^6.2.1",
|
||||
|
@ -138,22 +137,15 @@
|
|||
"fast-glob": "^3.2.11",
|
||||
"github-slugger": "^2.0.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"html-entities": "^2.3.3",
|
||||
"html-escaper": "^3.0.3",
|
||||
"import-meta-resolve": "^2.1.0",
|
||||
"kleur": "^4.1.4",
|
||||
"magic-string": "^0.27.0",
|
||||
"mime": "^3.0.0",
|
||||
"ora": "^6.1.0",
|
||||
"path-browserify": "^1.0.1",
|
||||
"path-to-regexp": "^6.2.1",
|
||||
"postcss": "^8.4.14",
|
||||
"postcss-load-config": "^3.1.4",
|
||||
"preferred-pm": "^3.0.3",
|
||||
"prompts": "^2.4.2",
|
||||
"recast": "^0.20.5",
|
||||
"rehype": "^12.0.1",
|
||||
"resolve": "^1.22.0",
|
||||
"semver": "^7.3.7",
|
||||
"server-destroy": "^1.0.1",
|
||||
"shiki": "^0.11.1",
|
||||
|
@ -182,10 +174,9 @@
|
|||
"@types/diff": "^5.0.2",
|
||||
"@types/estree": "^0.0.51",
|
||||
"@types/hast": "^2.3.4",
|
||||
"@types/html-escaper": "^3.0.0",
|
||||
"@types/mime": "^2.0.3",
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/parse5": "^6.0.3",
|
||||
"@types/path-browserify": "^1.0.0",
|
||||
"@types/prettier": "^2.6.3",
|
||||
"@types/prompts": "^2.0.14",
|
||||
"@types/resolve": "^1.20.2",
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import type { RehypePlugin, RemarkPlugin, RemarkRehype } from '@astrojs/markdown-remark';
|
||||
import { markdownConfigDefaults } from '@astrojs/markdown-remark';
|
||||
import type * as Postcss from 'postcss';
|
||||
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
||||
import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro';
|
||||
|
||||
import { OutgoingHttpHeaders } from 'http';
|
||||
import postcssrc from 'postcss-load-config';
|
||||
import { BUNDLED_THEMES } from 'shiki';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { z } from 'zod';
|
||||
import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js';
|
||||
import { isObject } from '../util.js';
|
||||
|
||||
const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
|
||||
root: '.',
|
||||
|
@ -183,35 +179,6 @@ export const AstroConfigSchema = z.object({
|
|||
legacy: z.object({}).optional().default({}),
|
||||
});
|
||||
|
||||
interface PostCSSConfigResult {
|
||||
options: Postcss.ProcessOptions;
|
||||
plugins: Postcss.Plugin[];
|
||||
}
|
||||
|
||||
async function resolvePostcssConfig(inlineOptions: any, root: URL): Promise<PostCSSConfigResult> {
|
||||
if (isObject(inlineOptions)) {
|
||||
const options = { ...inlineOptions };
|
||||
delete options.plugins;
|
||||
return {
|
||||
options,
|
||||
plugins: inlineOptions.plugins || [],
|
||||
};
|
||||
}
|
||||
const searchPath = typeof inlineOptions === 'string' ? inlineOptions : fileURLToPath(root);
|
||||
try {
|
||||
// @ts-ignore
|
||||
return await postcssrc({}, searchPath);
|
||||
} catch (err: any) {
|
||||
if (!/No PostCSS Config found/.test(err.message)) {
|
||||
throw err;
|
||||
}
|
||||
return {
|
||||
options: {},
|
||||
plugins: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) {
|
||||
// We need to extend the global schema to add transforms that are relative to root.
|
||||
// This is type checked against the global schema to make sure we still match.
|
||||
|
|
|
@ -24,7 +24,6 @@ import markdownVitePlugin from '../vite-plugin-markdown/index.js';
|
|||
import astroScannerPlugin from '../vite-plugin-scanner/index.js';
|
||||
import astroScriptsPlugin from '../vite-plugin-scripts/index.js';
|
||||
import astroScriptsPageSSRPlugin from '../vite-plugin-scripts/page-ssr.js';
|
||||
import { resolveDependency } from './util.js';
|
||||
|
||||
interface CreateViteOptions {
|
||||
settings: AstroSettings;
|
||||
|
@ -33,7 +32,7 @@ interface CreateViteOptions {
|
|||
fs?: typeof nodeFs;
|
||||
}
|
||||
|
||||
const ALWAYS_NOEXTERNAL = new Set([
|
||||
const ALWAYS_NOEXTERNAL = [
|
||||
// This is only because Vite's native ESM doesn't resolve "exports" correctly.
|
||||
'astro',
|
||||
// Vite fails on nested `.astro` imports without bundling
|
||||
|
@ -43,21 +42,7 @@ const ALWAYS_NOEXTERNAL = new Set([
|
|||
'@nanostores/preact',
|
||||
// fontsource packages are CSS that need to be processed
|
||||
'@fontsource/*',
|
||||
]);
|
||||
|
||||
function getSsrNoExternalDeps(projectRoot: URL): string[] {
|
||||
let noExternalDeps = [];
|
||||
for (const dep of ALWAYS_NOEXTERNAL) {
|
||||
try {
|
||||
resolveDependency(dep, projectRoot);
|
||||
noExternalDeps.push(dep);
|
||||
} catch {
|
||||
// ignore dependency if *not* installed / present in your project
|
||||
// prevents hard error from Vite!
|
||||
}
|
||||
}
|
||||
return noExternalDeps;
|
||||
}
|
||||
];
|
||||
|
||||
/** Return a common starting point for all Vite actions */
|
||||
export async function createVite(
|
||||
|
@ -166,10 +151,7 @@ export async function createVite(
|
|||
dedupe: ['astro'],
|
||||
},
|
||||
ssr: {
|
||||
noExternal: [
|
||||
...getSsrNoExternalDeps(settings.config.root),
|
||||
...astroPkgsConfig.ssr.noExternal,
|
||||
],
|
||||
noExternal: [...ALWAYS_NOEXTERNAL, ...astroPkgsConfig.ssr.noExternal],
|
||||
// shiki is imported by Code.astro, which is no-externalized (processed by Vite).
|
||||
// However, shiki's deps are in CJS and trips up Vite's dev SSR transform, externalize
|
||||
// shiki to load it with node instead.
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import slashify from 'slash';
|
||||
import type { SSRElement } from '../../@types/astro';
|
||||
|
||||
import npath from 'path-browserify';
|
||||
import { appendForwardSlash } from '../../core/path.js';
|
||||
import { appendForwardSlash, removeLeadingForwardSlash } from '../../core/path.js';
|
||||
|
||||
function getRootPath(base?: string): string {
|
||||
return appendForwardSlash(new URL(base || '/', 'http://localhost/').pathname);
|
||||
}
|
||||
|
||||
function joinToRoot(href: string, base?: string): string {
|
||||
return npath.posix.join(getRootPath(base), href);
|
||||
const rootPath = getRootPath(base);
|
||||
const normalizedHref = slashify(href);
|
||||
return appendForwardSlash(rootPath) + removeLeadingForwardSlash(normalizedHref);
|
||||
}
|
||||
|
||||
export function createLinkStylesheetElement(href: string, base?: string): SSRElement {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import resolve from 'resolve';
|
||||
import slash from 'slash';
|
||||
import { fileURLToPath, pathToFileURL } from 'url';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { normalizePath } from 'vite';
|
||||
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
||||
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js';
|
||||
|
@ -83,14 +82,6 @@ export function parseNpmName(
|
|||
};
|
||||
}
|
||||
|
||||
export function resolveDependency(dep: string, projectRoot: URL) {
|
||||
const resolved = resolve.sync(dep, {
|
||||
basedir: fileURLToPath(projectRoot),
|
||||
});
|
||||
// For Windows compat, we need a fully resolved `file://` URL string
|
||||
return pathToFileURL(resolved).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert file URL to ID for viteServer.moduleGraph.idToModuleMap.get(:viteID)
|
||||
* Format:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { encode } from 'html-entities';
|
||||
import { escape } from 'html-escaper';
|
||||
import { baseCSS } from './css.js';
|
||||
|
||||
interface ErrorTemplateOptions {
|
||||
|
@ -58,7 +58,7 @@ export default function template({
|
|||
${
|
||||
body ||
|
||||
`
|
||||
<pre>Path: ${encode(pathname)}</pre>
|
||||
<pre>Path: ${escape(pathname)}</pre>
|
||||
`
|
||||
}
|
||||
</main>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import type { PluginObj } from '@babel/core';
|
||||
import * as t from '@babel/types';
|
||||
import { resolve as importMetaResolve } from 'import-meta-resolve';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
* This plugin handles every file that runs through our JSX plugin.
|
||||
|
@ -18,9 +16,6 @@ export default async function tagExportsWithRenderer({
|
|||
rendererName: string;
|
||||
root: URL;
|
||||
}): Promise<PluginObj> {
|
||||
const astroServerPath = fileURLToPath(
|
||||
await importMetaResolve('astro/server/index.js', root.toString())
|
||||
);
|
||||
return {
|
||||
visitor: {
|
||||
Program: {
|
||||
|
@ -36,7 +31,7 @@ export default async function tagExportsWithRenderer({
|
|||
t.identifier('__astro_tag_component__')
|
||||
),
|
||||
],
|
||||
t.stringLiteral(astroServerPath)
|
||||
t.stringLiteral('astro/server/index.js')
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -411,8 +411,6 @@ importers:
|
|||
'@types/html-escaper': ^3.0.0
|
||||
'@types/mime': ^2.0.3
|
||||
'@types/mocha': ^9.1.1
|
||||
'@types/parse5': ^6.0.3
|
||||
'@types/path-browserify': ^1.0.0
|
||||
'@types/prettier': ^2.6.3
|
||||
'@types/prompts': ^2.0.14
|
||||
'@types/resolve': ^1.20.2
|
||||
|
@ -440,9 +438,7 @@ importers:
|
|||
fast-glob: ^3.2.11
|
||||
github-slugger: ^2.0.0
|
||||
gray-matter: ^4.0.3
|
||||
html-entities: ^2.3.3
|
||||
html-escaper: ^3.0.3
|
||||
import-meta-resolve: ^2.1.0
|
||||
kleur: ^4.1.4
|
||||
magic-string: ^0.27.0
|
||||
memfs: ^3.4.7
|
||||
|
@ -450,19 +446,14 @@ importers:
|
|||
mocha: ^9.2.2
|
||||
node-mocks-http: ^1.11.0
|
||||
ora: ^6.1.0
|
||||
path-browserify: ^1.0.1
|
||||
path-to-regexp: ^6.2.1
|
||||
postcss: ^8.4.14
|
||||
postcss-load-config: ^3.1.4
|
||||
preferred-pm: ^3.0.3
|
||||
prompts: ^2.4.2
|
||||
recast: ^0.20.5
|
||||
rehype: ^12.0.1
|
||||
rehype-autolink-headings: ^6.1.1
|
||||
rehype-slug: ^5.0.1
|
||||
rehype-toc: ^3.0.2
|
||||
remark-code-titles: ^0.1.2
|
||||
resolve: ^1.22.0
|
||||
rollup: ^3.9.0
|
||||
sass: ^1.52.2
|
||||
semver: ^7.3.7
|
||||
|
@ -496,7 +487,6 @@ importers:
|
|||
'@babel/traverse': 7.20.12
|
||||
'@babel/types': 7.20.7
|
||||
'@types/babel__core': 7.1.20
|
||||
'@types/html-escaper': 3.0.0
|
||||
'@types/yargs-parser': 21.0.0
|
||||
acorn: 8.8.1
|
||||
boxen: 6.2.1
|
||||
|
@ -513,22 +503,15 @@ importers:
|
|||
fast-glob: 3.2.12
|
||||
github-slugger: 2.0.0
|
||||
gray-matter: 4.0.3
|
||||
html-entities: 2.3.3
|
||||
html-escaper: 3.0.3
|
||||
import-meta-resolve: 2.2.1
|
||||
kleur: 4.1.5
|
||||
magic-string: 0.27.0
|
||||
mime: 3.0.0
|
||||
ora: 6.1.2
|
||||
path-browserify: 1.0.1
|
||||
path-to-regexp: 6.2.1
|
||||
postcss: 8.4.21
|
||||
postcss-load-config: 3.1.4_postcss@8.4.21
|
||||
preferred-pm: 3.0.3
|
||||
prompts: 2.4.2
|
||||
recast: 0.20.5
|
||||
rehype: 12.0.1
|
||||
resolve: 1.22.1
|
||||
semver: 7.3.8
|
||||
server-destroy: 1.0.1
|
||||
shiki: 0.11.1
|
||||
|
@ -556,10 +539,9 @@ importers:
|
|||
'@types/diff': 5.0.2
|
||||
'@types/estree': 0.0.51
|
||||
'@types/hast': 2.3.4
|
||||
'@types/html-escaper': 3.0.0
|
||||
'@types/mime': 2.0.3
|
||||
'@types/mocha': 9.1.1
|
||||
'@types/parse5': 6.0.3
|
||||
'@types/path-browserify': 1.0.0
|
||||
'@types/prettier': 2.7.2
|
||||
'@types/prompts': 2.4.2
|
||||
'@types/resolve': 1.20.2
|
||||
|
@ -6985,7 +6967,6 @@ packages:
|
|||
|
||||
/@types/html-escaper/3.0.0:
|
||||
resolution: {integrity: sha512-OcJcvP3Yk8mjYwf/IdXZtTE1tb/u0WF0qa29ER07ZHCYUBZXSN29Z1mBS+/96+kNMGTFUAbSz9X+pHmHpZrTCw==}
|
||||
dev: false
|
||||
|
||||
/@types/http-cache-semantics/4.0.1:
|
||||
resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==}
|
||||
|
@ -7067,10 +7048,7 @@ packages:
|
|||
|
||||
/@types/parse5/6.0.3:
|
||||
resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==}
|
||||
|
||||
/@types/path-browserify/1.0.0:
|
||||
resolution: {integrity: sha512-XMCcyhSvxcch8b7rZAtFAaierBYdeHXVvg2iYnxOV0MCQHmPuRRmGZPFDRzPayxcGiiSL1Te9UIO+f3cuj0tfw==}
|
||||
dev: true
|
||||
dev: false
|
||||
|
||||
/@types/prettier/2.7.2:
|
||||
resolution: {integrity: sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==}
|
||||
|
|
Loading…
Reference in a new issue