mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
[ci] format
This commit is contained in:
parent
6313277137
commit
6561af9def
6 changed files with 80 additions and 46 deletions
|
@ -3,7 +3,6 @@ import fsMod from 'node:fs';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import pLimit from 'p-limit';
|
import pLimit from 'p-limit';
|
||||||
import { type Plugin as VitePlugin, normalizePath } from 'vite';
|
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 { CONTENT_RENDER_FLAG, PROPAGATED_ASSET_FLAG } from '../../../content/consts.js';
|
||||||
import { type ContentLookupMap, hasContentFlag } from '../../../content/utils.js';
|
import { type ContentLookupMap, hasContentFlag } from '../../../content/utils.js';
|
||||||
import {
|
import {
|
||||||
|
@ -11,16 +10,22 @@ import {
|
||||||
generateLookupMap,
|
generateLookupMap,
|
||||||
} from '../../../content/vite-plugin-content-virtual-mod.js';
|
} from '../../../content/vite-plugin-content-virtual-mod.js';
|
||||||
import { isServerLikeOutput } from '../../../prerender/utils.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 { addRollupInput } from '../add-rollup-input.js';
|
||||||
|
import { CHUNKS_PATH } from '../consts.js';
|
||||||
import { type BuildInternals } from '../internal.js';
|
import { type BuildInternals } from '../internal.js';
|
||||||
import type { AstroBuildPlugin } from '../plugin.js';
|
import type { AstroBuildPlugin } from '../plugin.js';
|
||||||
import { copyFiles } from '../static-build.js';
|
import { copyFiles } from '../static-build.js';
|
||||||
import type { StaticBuildOptions } from '../types.js';
|
import type { StaticBuildOptions } from '../types.js';
|
||||||
import { encodeName } from '../util.js';
|
import { encodeName } from '../util.js';
|
||||||
import { extendManualChunks } 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_CACHE_DIR = './content/';
|
||||||
const CONTENT_MANIFEST_FILE = './manifest.json';
|
const CONTENT_MANIFEST_FILE = './manifest.json';
|
||||||
|
@ -54,14 +59,21 @@ const resolvedVirtualEmptyModuleId = `\0${virtualEmptyModuleId}`;
|
||||||
const NO_MANIFEST_VERSION = -1 as const;
|
const NO_MANIFEST_VERSION = -1 as const;
|
||||||
|
|
||||||
function createContentManifest(): ContentManifest {
|
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(
|
function vitePluginContent(
|
||||||
opts: StaticBuildOptions,
|
opts: StaticBuildOptions,
|
||||||
lookupMap: ContentLookupMap,
|
lookupMap: ContentLookupMap,
|
||||||
internals: BuildInternals,
|
internals: BuildInternals,
|
||||||
cachedBuildOutput: Array<{ cached: URL; dist: URL; }>
|
cachedBuildOutput: Array<{ cached: URL; dist: URL }>
|
||||||
): VitePlugin {
|
): VitePlugin {
|
||||||
const { config } = opts.settings;
|
const { config } = opts.settings;
|
||||||
const { cacheDir } = config;
|
const { cacheDir } = config;
|
||||||
|
@ -310,7 +322,13 @@ function getEntriesFromManifests(
|
||||||
return entries;
|
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 {
|
function manifestState(oldManifest: ContentManifest, newManifest: ContentManifest): ManifestState {
|
||||||
// There isn't an existing manifest.
|
// There isn't an existing manifest.
|
||||||
|
@ -325,7 +343,7 @@ function manifestState(oldManifest: ContentManifest, newManifest: ContentManifes
|
||||||
return 'no-entries';
|
return 'no-entries';
|
||||||
}
|
}
|
||||||
// Lockfiles have changed or there is no lockfile at all.
|
// 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';
|
return 'lockfile-mismatch';
|
||||||
}
|
}
|
||||||
// Config has changed.
|
// Config has changed.
|
||||||
|
@ -359,7 +377,7 @@ async function generateContentManifest(
|
||||||
|
|
||||||
const [lockfiles, configs] = await Promise.all([
|
const [lockfiles, configs] = await Promise.all([
|
||||||
lockfilesHash(opts.settings.config.root),
|
lockfilesHash(opts.settings.config.root),
|
||||||
configHash(opts.settings.config.root)
|
configHash(opts.settings.config.root),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
manifest.lockfiles = lockfiles;
|
manifest.lockfiles = lockfiles;
|
||||||
|
@ -411,7 +429,7 @@ async function configHash(root: URL) {
|
||||||
|
|
||||||
function checksum(...datas: string[] | Uint8Array[]): string {
|
function checksum(...datas: string[] | Uint8Array[]): string {
|
||||||
const hash = createHash('sha1');
|
const hash = createHash('sha1');
|
||||||
datas.forEach(data => hash.update(data));
|
datas.forEach((data) => hash.update(data));
|
||||||
return hash.digest('base64');
|
return hash.digest('base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||||
import { routeIsRedirect } from '../redirects/index.js';
|
import { routeIsRedirect } from '../redirects/index.js';
|
||||||
import { getOutDirWithinCwd } from './common.js';
|
import { getOutDirWithinCwd } from './common.js';
|
||||||
|
import { CHUNKS_PATH } from './consts.js';
|
||||||
import { generatePages } from './generate.js';
|
import { generatePages } from './generate.js';
|
||||||
import { trackPageData } from './internal.js';
|
import { trackPageData } from './internal.js';
|
||||||
import { type AstroBuildPluginContainer, createPluginContainer } from './plugin.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 { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
|
||||||
import type { StaticBuildOptions } from './types.js';
|
import type { StaticBuildOptions } from './types.js';
|
||||||
import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from './util.js';
|
import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from './util.js';
|
||||||
import { CHUNKS_PATH } from './consts.js';
|
|
||||||
|
|
||||||
export async function viteBuild(opts: StaticBuildOptions) {
|
export async function viteBuild(opts: StaticBuildOptions) {
|
||||||
const { allPages, settings } = opts;
|
const { allPages, settings } = opts;
|
||||||
|
|
|
@ -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 { createNodeLogger } from './logging.js';
|
||||||
export { mergeConfig } from './merge.js';
|
export { mergeConfig } from './merge.js';
|
||||||
export type { AstroConfigType } from './schema.js';
|
export type { AstroConfigType } from './schema.js';
|
||||||
|
|
|
@ -480,7 +480,13 @@ type RunHookBuildDone = {
|
||||||
cacheManifest: boolean;
|
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;
|
const dir = isServerLikeOutput(config) ? config.build.client : config.outDir;
|
||||||
await fs.promises.mkdir(dir, { recursive: true });
|
await fs.promises.mkdir(dir, { recursive: true });
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import assert from 'node:assert/strict';
|
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 fs from 'node:fs';
|
||||||
|
import { after, before, describe, it } from 'node:test';
|
||||||
import { copyFiles } from '../dist/core/build/static-build.js';
|
import { copyFiles } from '../dist/core/build/static-build.js';
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
|
||||||
describe('Experimental Content Collections cache - invalidation', () => {
|
describe('Experimental Content Collections cache - invalidation', () => {
|
||||||
class CacheBackup {
|
class CacheBackup {
|
||||||
|
@ -32,14 +32,15 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:build:done': ({ cacheManifest }) => {
|
'astro:build:done': ({ cacheManifest }) => {
|
||||||
this.used = cacheManifest;
|
this.used = cacheManifest;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('manifest version', () => {
|
describe('manifest version', () => {
|
||||||
let fixture, backup,
|
let fixture,
|
||||||
|
backup,
|
||||||
/** @type {ManifestTestPlugin} */
|
/** @type {ManifestTestPlugin} */
|
||||||
testPlugin;
|
testPlugin;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -48,11 +49,12 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
||||||
root: './fixtures/content-collections-cache-invalidation/',
|
root: './fixtures/content-collections-cache-invalidation/',
|
||||||
cacheDir: './cache/version-mismatch/',
|
cacheDir: './cache/version-mismatch/',
|
||||||
experimental: { contentCollectionCache: true },
|
experimental: { contentCollectionCache: true },
|
||||||
integrations: [
|
integrations: [testPlugin.plugin()],
|
||||||
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();
|
backup.backup();
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
@ -68,7 +70,8 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('lockfiles', () => {
|
describe('lockfiles', () => {
|
||||||
let fixture, backup,
|
let fixture,
|
||||||
|
backup,
|
||||||
/** @type {ManifestTestPlugin} */
|
/** @type {ManifestTestPlugin} */
|
||||||
testPlugin;
|
testPlugin;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -77,11 +80,12 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
||||||
root: './fixtures/content-collections-cache-invalidation/',
|
root: './fixtures/content-collections-cache-invalidation/',
|
||||||
cacheDir: './cache/lockfile-mismatch/',
|
cacheDir: './cache/lockfile-mismatch/',
|
||||||
experimental: { contentCollectionCache: true },
|
experimental: { contentCollectionCache: true },
|
||||||
integrations: [
|
integrations: [testPlugin.plugin()],
|
||||||
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();
|
backup.backup();
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue