Skip to content

Commit

Permalink
Remove more unused code (#11598)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Aug 2, 2024
1 parent c2d6c1f commit 69d54b4
Show file tree
Hide file tree
Showing 32 changed files with 41 additions and 403 deletions.
10 changes: 1 addition & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { builtinModules } from 'node:module';

import { FlatCompat } from '@eslint/eslintrc';
import tseslint from 'typescript-eslint';

// plugins
Expand All @@ -16,12 +15,6 @@ const typescriptParser = tseslint.parser;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// ref: https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
// mimic CommonJS variables -- not needed if using CommonJS
const compat = new FlatCompat({
baseDirectory: __dirname,
});

export default [
// If ignores is used without any other keys in the configuration object, then the patterns act as global ignores.
// ref: https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
Expand All @@ -43,8 +36,7 @@ export default [

...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
// mimic ESLintRC-style extends
...compat.extends('plugin:regexp/recommended'),
regexpEslint.configs['flat/recommended'],
{
languageOptions: {
parser: typescriptParser,
Expand Down
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,15 @@
"@biomejs/biome": "1.8.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"@eslint/eslintrc": "^3.1.0",
"@types/node": "^18.17.8",
"esbuild": "^0.21.5",
"eslint": "^9.8.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-regexp": "^2.6.0",
"globby": "^14.0.2",
"only-allow": "^1.2.1",
"organize-imports-cli": "^0.10.0",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1",
"tiny-glob": "^0.2.9",
"turbo": "^1.13.4",
"typescript": "~5.5.4",
"typescript-eslint": "^7.18.0"
Expand All @@ -89,10 +86,6 @@
}
}
},
"overrides": {
"organize-imports-cli>ts-morph": "^19.0.0",
"tsconfig-resolver>type-fest": "3.0.0"
},
"peerDependencyRules": {
"ignoreMissing": [
"rollup",
Expand Down
6 changes: 0 additions & 6 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
"aria-query": "^5.3.0",
"axobject-query": "^4.1.0",
"boxen": "7.1.1",
"chokidar": "^3.6.0",
"ci-info": "^4.0.0",
"clsx": "^2.1.1",
"common-ancestor-path": "^1.0.1",
Expand Down Expand Up @@ -198,7 +197,6 @@
"@types/babel__generator": "^7.6.8",
"@types/babel__traverse": "^7.20.6",
"@types/common-ancestor-path": "^1.0.2",
"@types/connect": "^3.4.38",
"@types/cssesc": "^3.0.2",
"@types/debug": "^4.1.12",
"@types/diff": "^5.2.1",
Expand All @@ -208,11 +206,8 @@
"@types/html-escaper": "^3.0.2",
"@types/http-cache-semantics": "^4.0.4",
"@types/js-yaml": "^4.0.9",
"@types/probe-image-size": "^7.2.5",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.5.8",
"@types/send": "^0.17.4",
"@types/unist": "^3.0.2",
"@types/yargs-parser": "^21.0.3",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0-rc.12",
Expand All @@ -229,7 +224,6 @@
"remark-code-titles": "^0.1.2",
"rollup": "^4.19.1",
"sass": "^1.77.8",
"srcset-parse": "^1.1.0",
"undici": "^6.19.5",
"unified": "^11.0.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ async function tryToInstallIntegrations({
}
}

export async function validateIntegrations(integrations: string[]): Promise<IntegrationInfo[]> {
async function validateIntegrations(integrations: string[]): Promise<IntegrationInfo[]> {
const spinner = ora('Resolving packages...').start();
try {
const integrationEntries = await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/install-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export async function fetchPackageVersions(packageName: string): Promise<string[
//
// A copy of this function also exists in the create-astro package
let _registry: string;
export async function getRegistry(): Promise<string> {
async function getRegistry(): Promise<string> {
if (_registry) return _registry;
const fallback = 'https://registry.npmjs.org';
const packageManager = (await preferredPM(process.cwd()))?.name || 'npm';
Expand Down
13 changes: 4 additions & 9 deletions packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type ContentLookupMap = {
[collectionName: string]: { type: 'content' | 'data'; entries: { [lookupId: string]: string } };
};

export const collectionConfigParser = z.union([
const collectionConfigParser = z.union([
z.object({
type: z.literal('content').optional().default('content'),
schema: z.any().optional(),
Expand All @@ -37,7 +37,7 @@ export const collectionConfigParser = z.union([
}),
]);

export const contentConfigParser = z.object({
const contentConfigParser = z.object({
collections: z.record(collectionConfigParser),
});

Expand All @@ -46,11 +46,6 @@ export type ContentConfig = z.infer<typeof contentConfigParser>;

type EntryInternal = { rawData: string | undefined; filePath: string };

export const msg = {
collectionConfigMissing: (collection: string) =>
`${collection} does not have a config. We suggest adding one for type safety!`,
};

export function parseEntrySlug({
id,
collection,
Expand Down Expand Up @@ -313,7 +308,7 @@ export function getEntryType(
}
}

export function hasUnderscoreBelowContentDirectoryPath(
function hasUnderscoreBelowContentDirectoryPath(
fileUrl: URL,
contentDir: ContentPaths['contentDir']
): boolean {
Expand Down Expand Up @@ -388,7 +383,7 @@ export function hasContentFlag(viteId: string, flag: (typeof CONTENT_FLAGS)[numb
return flags.has(flag);
}

export async function loadContentConfig({
async function loadContentConfig({
fs,
settings,
viteServer,
Expand Down
28 changes: 0 additions & 28 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import fs from 'node:fs';
import os from 'node:os';
import { fileURLToPath } from 'node:url';
import { bgGreen, black, blue, bold, dim, green, magenta, red } from 'kleur/colors';
import PQueue from 'p-queue';
import type { OutputAsset, OutputChunk } from 'rollup';
import type {
AstroConfig,
AstroSettings,
Expand All @@ -25,7 +23,6 @@ import { type BuildInternals, hasPrerenderedPages } from '../../core/build/inter
import {
isRelativePath,
joinPaths,
prependForwardSlash,
removeLeadingForwardSlash,
removeTrailingForwardSlash,
} from '../../core/path.js';
Expand Down Expand Up @@ -57,31 +54,6 @@ function createEntryURL(filePath: string, outFolder: URL) {
return new URL('./' + filePath + `?time=${Date.now()}`, outFolder);
}

// Gives back a facadeId that is relative to the root.
// ie, src/pages/index.astro instead of /Users/name..../src/pages/index.astro
export function rootRelativeFacadeId(facadeId: string, settings: AstroSettings): string {
return facadeId.slice(fileURLToPath(settings.config.root).length);
}

// Determines of a Rollup chunk is an entrypoint page.
export function chunkIsPage(
settings: AstroSettings,
output: OutputAsset | OutputChunk,
internals: BuildInternals
) {
if (output.type !== 'chunk') {
return false;
}
const chunk = output;
if (chunk.facadeModuleId) {
const facadeToEntryId = prependForwardSlash(
rootRelativeFacadeId(chunk.facadeModuleId, settings)
);
return internals.entrySpecifierToBundleMap.has(facadeToEntryId);
}
return false;
}

export async function generatePages(options: StaticBuildOptions, internals: BuildInternals) {
const generatePagesTimer = performance.now();
const ssr = isServerLikeOutput(options.settings.config);
Expand Down
18 changes: 1 addition & 17 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,6 @@ export function trackScriptPageDatas(
}
}

export function* getPageDatasByChunk(
internals: BuildInternals,
chunk: Rollup.RenderedChunk
): Generator<PageBuildData, void, unknown> {
const pagesByViteID = internals.pagesByViteID;
for (const [modulePath] of Object.entries(chunk.modules)) {
if (pagesByViteID.has(modulePath)) {
yield pagesByViteID.get(modulePath)!;
}
}
}

export function* getPageDatasByClientOnlyID(
internals: BuildInternals,
viteid: ViteID
Expand Down Expand Up @@ -264,7 +252,7 @@ export function getPageData(
* @param internals Build Internals with all the pages
* @param component path to the component, used to identify related pages
*/
export function getPagesDatasByComponent(
function getPagesDatasByComponent(
internals: BuildInternals,
component: string
): PageBuildData[] {
Expand Down Expand Up @@ -326,10 +314,6 @@ export function getPageDataByViteID(
return undefined;
}

export function hasPageDataByViteID(internals: BuildInternals, viteid: ViteID): boolean {
return internals.pagesByViteID.has(viteid);
}

export function hasPrerenderedPages(internals: BuildInternals) {
for (const pageData of internals.pagesByKeys.values()) {
if (pageData.route.prerender) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { BuildOptions, Plugin as VitePlugin } from 'vite';
import type { BuildOptions, Plugin as VitePlugin, Rollup } from 'vite';
import type { AstroSettings } from '../../../@types/astro.js';
import { viteID } from '../../util.js';
import type { BuildInternals } from '../internal.js';
import { getPageDataByViteID } from '../internal.js';
import type { AstroBuildPlugin } from '../plugin.js';
import type { OutputChunk, StaticBuildOptions } from '../types.js';
import type { StaticBuildOptions } from '../types.js';
import { shouldInlineAsset } from './util.js';

function virtualHoistedEntry(id: string) {
Expand Down Expand Up @@ -49,7 +49,7 @@ export function vitePluginHoistedScripts(
},

async generateBundle(_options, bundle) {
const considerInlining = new Map<string, OutputChunk>();
const considerInlining = new Map<string, Rollup.OutputChunk>();
const importedByOtherScripts = new Set<string>();

// Find all page entry points and create a map of the entry point to the hashed hoisted script.
Expand Down
7 changes: 2 additions & 5 deletions packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function pluginManifest(
};
}

export async function createManifest(
async function createManifest(
buildOpts: StaticBuildOptions,
internals: BuildInternals
): Promise<SerializedSSRManifest> {
Expand All @@ -137,11 +137,8 @@ export async function createManifest(

/**
* It injects the manifest in the given output rollup chunk. It returns the new emitted code
* @param buildOpts
* @param internals
* @param chunk
*/
export function injectManifest(manifest: SerializedSSRManifest, chunk: Readonly<OutputChunk>) {
function injectManifest(manifest: SerializedSSRManifest, chunk: Readonly<OutputChunk>) {
const code = chunk.code;

return code.replace(replaceExp, () => {
Expand Down
7 changes: 0 additions & 7 deletions packages/astro/src/core/build/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type * as vite from 'vite';
import type { InlineConfig } from 'vite';
import type {
AstroConfig,
AstroSettings,
ComponentInstance,
ManifestData,
Expand All @@ -14,7 +13,6 @@ import type { Logger } from '../logger/core.js';

export type ComponentPath = string;
export type ViteID = string;
export type PageOutput = AstroConfig['output'];

export type StylesheetAsset =
| { type: 'inline'; content: string }
Expand Down Expand Up @@ -58,8 +56,3 @@ export interface SinglePageBuiltModule {
}

export type ViteBuildReturn = Awaited<ReturnType<typeof vite.build>>;
export type RollupOutput = Extract<
Extract<ViteBuildReturn, Exclude<ViteBuildReturn, Array<any>>>,
{ output: any }
>;
export type OutputChunk = Extract<RollupOutput['output'][number], { type: 'chunk' }>;
1 change: 0 additions & 1 deletion packages/astro/src/core/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { compile } from './compile.js';
export type { CompileProps, CompileResult } from './compile.js';
export type { TransformStyle } from './types.js';
13 changes: 0 additions & 13 deletions packages/astro/src/core/compile/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import type { SourceMap } from 'rollup';

export type TransformStyleResult = null | {
code: string;
map: SourceMap | null;
deps: Set<string>;
};

export type TransformStyle = (
source: string,
lang: string
) => TransformStyleResult | Promise<TransformStyleResult>;

export interface CompileCssResult {
code: string;
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function createRestartedContainer(
const configRE = /.*astro.config.(?:mjs|cjs|js|ts)$/;
const preferencesRE = /.*\.astro\/settings.json$/;

export function shouldRestartContainer(
function shouldRestartContainer(
{ settings, inlineConfig, restartInFlight }: Container,
changedFile: string
): boolean {
Expand Down Expand Up @@ -66,7 +66,7 @@ export function shouldRestartContainer(
return shouldRestart;
}

export async function restartContainer(container: Container): Promise<Container | Error> {
async function restartContainer(container: Container): Promise<Container | Error> {
const { logger, close, settings: existingSettings } = container;
container.restartInFlight = true;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/errors/dev/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): Promise<Astro
* FROM: https://github.com/shikijs/shiki/blob/4a58472070a9a359a4deafec23bb576a73e24c6a/packages/transformers/src/transformers/compact-line-options.ts
* LICENSE: https://github.com/shikijs/shiki/blob/4a58472070a9a359a4deafec23bb576a73e24c6a/LICENSE
*/
export function transformerCompactLineOptions(
function transformerCompactLineOptions(
lineOptions: {
/**
* 1-based line number.
Expand Down
6 changes: 0 additions & 6 deletions packages/astro/src/core/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { appendForwardSlash } from '../path.js';

const isWindows = process.platform === 'win32';

/** An fs utility, similar to `rimraf` or `rm -rf` */
export function removeDir(_dir: URL): void {
const dir = fileURLToPath(_dir);
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 3 });
}

export function removeEmptyDirs(root: URL): void {
const dir = fileURLToPath(root);
if (!fs.statSync(dir).isDirectory()) return;
Expand Down
Loading

0 comments on commit 69d54b4

Please sign in to comment.