[ci] format
This commit is contained in:
parent
2189170be5
commit
91dc0f4015
6 changed files with 35 additions and 36 deletions
|
@ -1,8 +1,6 @@
|
|||
export { attachContentServerListeners } from './server-listeners.js';
|
||||
export { createContentTypesGenerator } from './types-generator.js';
|
||||
export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js';
|
||||
export {
|
||||
astroContentAssetPropagationPlugin,
|
||||
} from './vite-plugin-content-assets.js';
|
||||
export { astroContentAssetPropagationPlugin } from './vite-plugin-content-assets.js';
|
||||
export { astroContentImportPlugin } from './vite-plugin-content-imports.js';
|
||||
export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { pathToFileURL } from 'url';
|
||||
import npath from 'node:path';
|
||||
import { pathToFileURL } from 'url';
|
||||
import type { Plugin } from 'vite';
|
||||
import { moduleIsTopLevelPage, walkParentInfos } from '../core/build/graph.js';
|
||||
import { BuildInternals, getPageDataByViteID } from '../core/build/internal.js';
|
||||
import { AstroBuildPlugin } from '../core/build/plugin.js';
|
||||
import type { StaticBuildOptions } from '../core/build/types';
|
||||
import type { ModuleLoader } from '../core/module-loader/loader.js';
|
||||
import { createViteLoader } from '../core/module-loader/vite.js';
|
||||
import { prependForwardSlash } from '../core/path.js';
|
||||
import { getStylesForURL } from '../core/render/dev/css.js';
|
||||
import { getScriptsForURL } from '../core/render/dev/scripts.js';
|
||||
import {
|
||||
|
@ -15,8 +17,6 @@ import {
|
|||
SCRIPTS_PLACEHOLDER,
|
||||
STYLES_PLACEHOLDER,
|
||||
} from './consts.js';
|
||||
import type { RollupOutput, OutputChunk, StaticBuildOptions } from '../core/build/types';
|
||||
import { prependForwardSlash } from '../core/path.js';
|
||||
|
||||
function isPropagatedAsset(viteId: string): boolean {
|
||||
const url = new URL(viteId, 'file://');
|
||||
|
@ -76,7 +76,10 @@ export function astroContentAssetPropagationPlugin({ mode }: { mode: string }):
|
|||
};
|
||||
}
|
||||
|
||||
export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin {
|
||||
export function astroConfigBuildPlugin(
|
||||
options: StaticBuildOptions,
|
||||
internals: BuildInternals
|
||||
): AstroBuildPlugin {
|
||||
let ssrPluginContext: any = undefined;
|
||||
return {
|
||||
build: 'ssr',
|
||||
|
@ -86,15 +89,15 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B
|
|||
vitePlugin: {
|
||||
name: 'astro:content-build-plugin',
|
||||
generateBundle() {
|
||||
if(build === 'ssr') {
|
||||
if (build === 'ssr') {
|
||||
ssrPluginContext = this;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
'build:post': ({ ssrOutputs, clientOutputs, mutate }) => {
|
||||
const outputs = ssrOutputs.flatMap(o => o.output);
|
||||
const outputs = ssrOutputs.flatMap((o) => o.output);
|
||||
for (const chunk of outputs) {
|
||||
if (
|
||||
chunk.type === 'chunk' &&
|
||||
|
@ -109,16 +112,16 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B
|
|||
const pageViteID = pageInfo.id;
|
||||
const pageData = getPageDataByViteID(internals, pageViteID);
|
||||
if (!pageData) continue;
|
||||
|
||||
|
||||
const _entryCss = pageData.propagatedStyles?.get(id);
|
||||
const _entryScripts = pageData.propagatedScripts?.get(id);
|
||||
if(_entryCss) {
|
||||
for(const value of _entryCss) {
|
||||
if (_entryCss) {
|
||||
for (const value of _entryCss) {
|
||||
entryCSS.add(value);
|
||||
}
|
||||
}
|
||||
if(_entryScripts) {
|
||||
for(const value of _entryScripts) {
|
||||
if (_entryScripts) {
|
||||
for (const value of _entryScripts) {
|
||||
entryScripts.add(value);
|
||||
}
|
||||
}
|
||||
|
@ -135,11 +138,11 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B
|
|||
}
|
||||
if (entryScripts.size) {
|
||||
const entryFileNames = new Set<string>();
|
||||
for(const output of clientOutputs) {
|
||||
for(const clientChunk of output.output) {
|
||||
if(clientChunk.type !== 'chunk') continue;
|
||||
for(const [id] of Object.entries(clientChunk.modules)) {
|
||||
if(entryScripts.has(id)) {
|
||||
for (const output of clientOutputs) {
|
||||
for (const clientChunk of output.output) {
|
||||
if (clientChunk.type !== 'chunk') continue;
|
||||
for (const [id] of Object.entries(clientChunk.modules)) {
|
||||
if (entryScripts.has(id)) {
|
||||
entryFileNames.add(clientChunk.fileName);
|
||||
}
|
||||
}
|
||||
|
@ -150,11 +153,8 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B
|
|||
JSON.stringify(
|
||||
[...entryFileNames].map((src) => ({
|
||||
props: {
|
||||
src: prependForwardSlash(npath.posix.join(
|
||||
options.settings.config.base,
|
||||
src
|
||||
)),
|
||||
type: 'module'
|
||||
src: prependForwardSlash(npath.posix.join(options.settings.config.base, src)),
|
||||
type: 'module',
|
||||
},
|
||||
children: '',
|
||||
}))
|
||||
|
@ -164,7 +164,7 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B
|
|||
mutate(chunk, 'server', newCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ export function moduleIsTopLevelPage(info: ModuleInfo): boolean {
|
|||
// This could be a .astro page, a .markdown or a .md (or really any file extension for markdown files) page.
|
||||
export function* getTopLevelPages(
|
||||
id: string,
|
||||
ctx: { getModuleInfo: GetModuleInfo },
|
||||
ctx: { getModuleInfo: GetModuleInfo }
|
||||
): Generator<[ModuleInfo, number, number], void, unknown> {
|
||||
for (const res of walkParentInfos(id, ctx)) {
|
||||
if (moduleIsTopLevelPage(res[0])) {
|
||||
|
|
|
@ -4,14 +4,14 @@ import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin
|
|||
import type { BuildInternals } from '../internal.js';
|
||||
import type { AstroBuildPlugin } from '../plugin.js';
|
||||
|
||||
import { PROPAGATED_ASSET_FLAG } from '../../../content/consts.js';
|
||||
import { prependForwardSlash } from '../../../core/path.js';
|
||||
import { getTopLevelPages, moduleIsTopLevelPage, walkParentInfos } from '../graph.js';
|
||||
import { getPageDataByViteID, trackClientOnlyPageDatas } from '../internal.js';
|
||||
import { PROPAGATED_ASSET_FLAG } from '../../../content/consts.js';
|
||||
|
||||
function isPropagatedAsset(id: string) {
|
||||
try {
|
||||
return new URL('file://' + id).searchParams.has(PROPAGATED_ASSET_FLAG)
|
||||
return new URL('file://' + id).searchParams.has(PROPAGATED_ASSET_FLAG);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ export function pluginAnalyzer(internals: BuildInternals): AstroBuildPlugin {
|
|||
return {
|
||||
vitePlugin: vitePluginAnalyzer(internals),
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -248,9 +248,12 @@ async function runPostBuildHooks(
|
|||
const config = container.options.settings.config;
|
||||
const buildConfig = container.options.settings.config.build;
|
||||
for (const [fileName, mutation] of mutations) {
|
||||
const root = config.output === 'server' ?
|
||||
mutation.build === 'server' ? buildConfig.server : buildConfig.client :
|
||||
config.outDir;
|
||||
const root =
|
||||
config.output === 'server'
|
||||
? mutation.build === 'server'
|
||||
? buildConfig.server
|
||||
: buildConfig.client
|
||||
: config.outDir;
|
||||
const fileURL = new URL(fileName, root);
|
||||
await fs.promises.mkdir(new URL('./', fileURL), { recursive: true });
|
||||
await fs.promises.writeFile(fileURL, mutation.code, 'utf-8');
|
||||
|
|
|
@ -45,9 +45,7 @@ describe('Content Collections - render()', () => {
|
|||
|
||||
// Includes hoisted script
|
||||
expect(
|
||||
[...allScripts].find((script) =>
|
||||
$(script).attr('src')?.includes('WithScripts')
|
||||
),
|
||||
[...allScripts].find((script) => $(script).attr('src')?.includes('WithScripts')),
|
||||
'`WithScripts.astro` hoisted script missing from head.'
|
||||
).to.not.be.undefined;
|
||||
|
||||
|
|
Loading…
Reference in a new issue