Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Feb 6, 2023
1 parent 2189170 commit 91dc0f4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
4 changes: 1 addition & 3 deletions packages/astro/src/content/index.ts
Original file line number Diff line number Diff line change
@@ -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';
46 changes: 23 additions & 23 deletions packages/astro/src/content/vite-plugin-content-assets.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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://');
Expand Down Expand Up @@ -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',
Expand All @@ -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' &&
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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: '',
}))
Expand All @@ -164,7 +164,7 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B
mutate(chunk, 'server', newCode);
}
}
}
},
},
};
}
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/build/plugins/plugin-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ export function pluginAnalyzer(internals: BuildInternals): AstroBuildPlugin {
return {
vitePlugin: vitePluginAnalyzer(internals),
};
}
},
},
};
}
9 changes: 6 additions & 3 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/test/content-collections-render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 91dc0f4

Please sign in to comment.