0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

[ci] format

This commit is contained in:
Matthew Phillips 2024-04-18 15:24:04 +00:00 committed by astrobot-houston
parent 6313277137
commit 6561af9def
6 changed files with 80 additions and 46 deletions

View file

@ -3,7 +3,6 @@ import fsMod from 'node:fs';
import { fileURLToPath } from 'node:url';
import pLimit from 'p-limit';
import { type Plugin as VitePlugin, normalizePath } from 'vite';
import { configPaths } from '../../config/index.js';
import { CONTENT_RENDER_FLAG, PROPAGATED_ASSET_FLAG } from '../../../content/consts.js';
import { type ContentLookupMap, hasContentFlag } from '../../../content/utils.js';
import {
@ -11,16 +10,22 @@ import {
generateLookupMap,
} from '../../../content/vite-plugin-content-virtual-mod.js';
import { isServerLikeOutput } from '../../../prerender/utils.js';
import { joinPaths, removeFileExtension, removeLeadingForwardSlash, appendForwardSlash } from '../../path.js';
import { configPaths } from '../../config/index.js';
import { emptyDir } from '../../fs/index.js';
import {
appendForwardSlash,
joinPaths,
removeFileExtension,
removeLeadingForwardSlash,
} from '../../path.js';
import { addRollupInput } from '../add-rollup-input.js';
import { CHUNKS_PATH } from '../consts.js';
import { type BuildInternals } from '../internal.js';
import type { AstroBuildPlugin } from '../plugin.js';
import { copyFiles } from '../static-build.js';
import type { StaticBuildOptions } from '../types.js';
import { encodeName } from '../util.js';
import { extendManualChunks } from './util.js';
import { emptyDir } from '../../fs/index.js';
import { CHUNKS_PATH } from '../consts.js';
const CONTENT_CACHE_DIR = './content/';
const CONTENT_MANIFEST_FILE = './manifest.json';
@ -54,14 +59,21 @@ const resolvedVirtualEmptyModuleId = `\0${virtualEmptyModuleId}`;
const NO_MANIFEST_VERSION = -1 as const;
function createContentManifest(): ContentManifest {
return { version: NO_MANIFEST_VERSION, entries: [], serverEntries: [], clientEntries: [], lockfiles: "", configs: "" };
return {
version: NO_MANIFEST_VERSION,
entries: [],
serverEntries: [],
clientEntries: [],
lockfiles: '',
configs: '',
};
}
function vitePluginContent(
opts: StaticBuildOptions,
lookupMap: ContentLookupMap,
internals: BuildInternals,
cachedBuildOutput: Array<{ cached: URL; dist: URL; }>
cachedBuildOutput: Array<{ cached: URL; dist: URL }>
): VitePlugin {
const { config } = opts.settings;
const { cacheDir } = config;
@ -310,7 +322,13 @@ function getEntriesFromManifests(
return entries;
}
type ManifestState = 'valid' | 'no-manifest' | 'version-mismatch' | 'no-entries' | 'lockfile-mismatch' | 'config-mismatch';
type ManifestState =
| 'valid'
| 'no-manifest'
| 'version-mismatch'
| 'no-entries'
| 'lockfile-mismatch'
| 'config-mismatch';
function manifestState(oldManifest: ContentManifest, newManifest: ContentManifest): ManifestState {
// There isn't an existing manifest.
@ -325,7 +343,7 @@ function manifestState(oldManifest: ContentManifest, newManifest: ContentManifes
return 'no-entries';
}
// Lockfiles have changed or there is no lockfile at all.
if((oldManifest.lockfiles !== newManifest.lockfiles) || newManifest.lockfiles === '') {
if (oldManifest.lockfiles !== newManifest.lockfiles || newManifest.lockfiles === '') {
return 'lockfile-mismatch';
}
// Config has changed.
@ -359,7 +377,7 @@ async function generateContentManifest(
const [lockfiles, configs] = await Promise.all([
lockfilesHash(opts.settings.config.root),
configHash(opts.settings.config.root)
configHash(opts.settings.config.root),
]);
manifest.lockfiles = lockfiles;
@ -411,7 +429,7 @@ async function configHash(root: URL) {
function checksum(...datas: string[] | Uint8Array[]): string {
const hash = createHash('sha1');
datas.forEach(data => hash.update(data));
datas.forEach((data) => hash.update(data));
return hash.digest('base64');
}

View file

@ -23,6 +23,7 @@ import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import { routeIsRedirect } from '../redirects/index.js';
import { getOutDirWithinCwd } from './common.js';
import { CHUNKS_PATH } from './consts.js';
import { generatePages } from './generate.js';
import { trackPageData } from './internal.js';
import { type AstroBuildPluginContainer, createPluginContainer } from './plugin.js';
@ -34,7 +35,6 @@ import { RESOLVED_SPLIT_MODULE_ID, RESOLVED_SSR_VIRTUAL_MODULE_ID } from './plug
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
import type { StaticBuildOptions } from './types.js';
import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from './util.js';
import { CHUNKS_PATH } from './consts.js';
export async function viteBuild(opts: StaticBuildOptions) {
const { allPages, settings } = opts;

View file

@ -1,4 +1,10 @@
export { configPaths, resolveConfig, resolveConfigPath, resolveFlags, resolveRoot } from './config.js';
export {
configPaths,
resolveConfig,
resolveConfigPath,
resolveFlags,
resolveRoot,
} from './config.js';
export { createNodeLogger } from './logging.js';
export { mergeConfig } from './merge.js';
export type { AstroConfigType } from './schema.js';

View file

@ -480,7 +480,13 @@ type RunHookBuildDone = {
cacheManifest: boolean;
};
export async function runHookBuildDone({ config, pages, routes, logging, cacheManifest }: RunHookBuildDone) {
export async function runHookBuildDone({
config,
pages,
routes,
logging,
cacheManifest,
}: RunHookBuildDone) {
const dir = isServerLikeOutput(config) ? config.build.client : config.outDir;
await fs.promises.mkdir(dir, { recursive: true });

View file

@ -1,8 +1,8 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';
import fs from 'node:fs';
import { after, before, describe, it } from 'node:test';
import { copyFiles } from '../dist/core/build/static-build.js';
import { loadFixture } from './test-utils.js';
describe('Experimental Content Collections cache - invalidation', () => {
class CacheBackup {
@ -32,14 +32,15 @@ describe('Experimental Content Collections cache - invalidation', () => {
hooks: {
'astro:build:done': ({ cacheManifest }) => {
this.used = cacheManifest;
}
}
}
},
},
};
}
}
describe('manifest version', () => {
let fixture, backup,
let fixture,
backup,
/** @type {ManifestTestPlugin} */
testPlugin;
before(async () => {
@ -48,11 +49,12 @@ describe('Experimental Content Collections cache - invalidation', () => {
root: './fixtures/content-collections-cache-invalidation/',
cacheDir: './cache/version-mismatch/',
experimental: { contentCollectionCache: true },
integrations: [
testPlugin.plugin()
]
integrations: [testPlugin.plugin()],
});
backup = new CacheBackup('./fixtures/content-collections-cache-invalidation/', './cache/version-mismatch/');
backup = new CacheBackup(
'./fixtures/content-collections-cache-invalidation/',
'./cache/version-mismatch/'
);
backup.backup();
await fixture.build();
});
@ -68,7 +70,8 @@ describe('Experimental Content Collections cache - invalidation', () => {
});
describe('lockfiles', () => {
let fixture, backup,
let fixture,
backup,
/** @type {ManifestTestPlugin} */
testPlugin;
before(async () => {
@ -77,11 +80,12 @@ describe('Experimental Content Collections cache - invalidation', () => {
root: './fixtures/content-collections-cache-invalidation/',
cacheDir: './cache/lockfile-mismatch/',
experimental: { contentCollectionCache: true },
integrations: [
testPlugin.plugin()
]
integrations: [testPlugin.plugin()],
});
backup = new CacheBackup('./fixtures/content-collections-cache-invalidation/', './cache/lockfile-mismatch/');
backup = new CacheBackup(
'./fixtures/content-collections-cache-invalidation/',
'./cache/lockfile-mismatch/'
);
backup.backup();
await fixture.build();
});