From 4e37e82b4f4623e99bd58ebd70b5da0879d1713b Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 6 Jan 2023 15:39:46 +0800 Subject: [PATCH] Cleanup dependencies --- .changeset/six-carpets-talk.md | 5 ++ packages/astro/package.json | 13 +--- packages/astro/src/core/config/schema.ts | 33 ---------- packages/astro/src/core/create-vite.ts | 24 +------ packages/astro/src/core/render/ssr-element.ts | 9 +-- packages/astro/src/core/util.ts | 11 +--- packages/astro/src/template/4xx.ts | 4 +- packages/astro/src/vite-plugin-jsx/tag.ts | 7 +- pnpm-lock.yaml | 64 +------------------ 9 files changed, 22 insertions(+), 148 deletions(-) create mode 100644 .changeset/six-carpets-talk.md diff --git a/.changeset/six-carpets-talk.md b/.changeset/six-carpets-talk.md new file mode 100644 index 000000000000..8d0ab63735e5 --- /dev/null +++ b/.changeset/six-carpets-talk.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Cleanup dependencies diff --git a/packages/astro/package.json b/packages/astro/package.json index 8f30610828e0..ba10f10d363e 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -123,7 +123,6 @@ "@proload/core": "^0.3.3", "@proload/plugin-tsm": "^0.2.1", "@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", @@ -140,22 +139,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", "shiki": "^0.11.1", "sirv": "^2.0.2", @@ -164,7 +156,6 @@ "strip-ansi": "^7.0.1", "supports-esm": "^1.0.0", "tsconfig-resolver": "^3.0.1", - "typescript": "*", "unist-util-visit": "^4.1.0", "vfile": "^5.3.2", "vite": "^4.0.3", @@ -184,10 +175,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", @@ -209,6 +199,7 @@ "rollup": "^3.9.0", "sass": "^1.52.2", "srcset-parse": "^1.1.0", + "typescript": "*", "unified": "^10.1.2" }, "engines": { diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index a4dccb9940ae..3336c0a73b6d 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -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: '.', @@ -180,35 +176,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 { - 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. diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 351ea631815f..cccda8545d9f 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -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. diff --git a/packages/astro/src/core/render/ssr-element.ts b/packages/astro/src/core/render/ssr-element.ts index 63c02ff3ebc7..36fbca9e8572 100644 --- a/packages/astro/src/core/render/ssr-element.ts +++ b/packages/astro/src/core/render/ssr-element.ts @@ -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 { diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index d6f95062a958..f443bc6854c1 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -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: diff --git a/packages/astro/src/template/4xx.ts b/packages/astro/src/template/4xx.ts index e498d7e304c0..7c57c058f91e 100644 --- a/packages/astro/src/template/4xx.ts +++ b/packages/astro/src/template/4xx.ts @@ -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 || ` -
Path: ${encode(pathname)}
+
Path: ${escape(pathname)}
` } diff --git a/packages/astro/src/vite-plugin-jsx/tag.ts b/packages/astro/src/vite-plugin-jsx/tag.ts index adf7334190b7..eab920f63720 100644 --- a/packages/astro/src/vite-plugin-jsx/tag.ts +++ b/packages/astro/src/vite-plugin-jsx/tag.ts @@ -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 { - 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') ) ); }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75610958d666..0630d458f43e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -413,8 +413,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 @@ -427,7 +425,6 @@ importers: boxen: ^6.2.1 chai: ^4.3.6 cheerio: ^1.0.0-rc.11 - ci-info: ^3.3.1 common-ancestor-path: ^1.0.1 cookie: ^0.5.0 debug: ^4.3.4 @@ -441,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 @@ -452,19 +447,14 @@ importers: node-fetch: ^3.2.5 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 @@ -499,11 +489,9 @@ importers: '@proload/core': 0.3.3 '@proload/plugin-tsm': 0.2.1_@proload+core@0.3.3 '@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 - ci-info: 3.7.1 common-ancestor-path: 1.0.1 cookie: 0.5.0 debug: 4.3.4 @@ -516,22 +504,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.0 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.20 - postcss-load-config: 3.1.4_postcss@8.4.20 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 shiki: 0.11.1 sirv: 2.0.2 @@ -540,7 +521,6 @@ importers: strip-ansi: 7.0.1 supports-esm: 1.0.0 tsconfig-resolver: 3.0.1 - typescript: 4.9.4 unist-util-visit: 4.1.1 vfile: 5.3.6 vite: 4.0.4_sass@1.57.1 @@ -559,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 @@ -584,6 +563,7 @@ importers: rollup: 3.9.1 sass: 1.57.1 srcset-parse: 1.1.0 + typescript: 4.9.4 unified: 10.1.2 packages/astro-prism: @@ -1398,12 +1378,6 @@ importers: '@astrojs/svelte': link:../../../../integrations/svelte astro: link:../../.. - packages/astro/test/fixtures/astro-markdown-css: - specifiers: - astro: workspace:* - dependencies: - astro: link:../../.. - packages/astro/test/fixtures/astro-markdown-drafts: specifiers: astro: workspace:* @@ -1948,30 +1922,6 @@ importers: dependencies: astro: link:../../.. - packages/astro/test/fixtures/legacy-astro-flavored-markdown: - specifiers: - '@astrojs/preact': workspace:* - '@astrojs/svelte': workspace:* - astro: workspace:* - preact: ^10.11.0 - svelte: ^3.48.0 - dependencies: - '@astrojs/preact': link:../../../../integrations/preact - '@astrojs/svelte': link:../../../../integrations/svelte - astro: link:../../.. - preact: 10.11.3 - svelte: 3.55.0 - - packages/astro/test/fixtures/legacy-build: - specifiers: - '@astrojs/vue': workspace:* - astro: workspace:* - preact: ~10.6.6 - dependencies: - '@astrojs/vue': link:../../../../integrations/vue - astro: link:../../.. - preact: 10.6.6 - packages/astro/test/fixtures/lit-element: specifiers: '@astrojs/lit': workspace:* @@ -7027,7 +6977,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==} @@ -7115,10 +7064,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==} @@ -13248,10 +13194,6 @@ packages: /preact/10.11.3: resolution: {integrity: sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==} - /preact/10.6.6: - resolution: {integrity: sha512-dgxpTFV2vs4vizwKohYKkk7g7rmp1wOOcfd4Tz3IB3Wi+ivZzsn/SpeKJhRENSE+n8sUfsAl4S3HiCVT923ABw==} - dev: false - /prebuild-install/7.1.1: resolution: {integrity: sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==} engines: {node: '>=10'}