Skip to content

Commit

Permalink
Use wrap instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Aug 8, 2023
1 parent 50b58fb commit 92f0f0c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/astro/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './dist/@types/astro.js'
export * from './dist/core/index.js'
export type * from './dist/@types/astro.js';
export * from './dist/core/index.js';
11 changes: 5 additions & 6 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ export interface BuildOptions {
* Builds your site for deployment. By default, this will generate static files and place them in a dist/ directory.
* If SSR is enabled, this will generate the necessary server files to serve your site.
*/
export default async function build(inlineConfig: AstroInlineConfig): Promise<void> {
export default async function build(
inlineConfig: AstroInlineConfig,
options?: BuildOptions
): Promise<void> {
applyPolyfill();
const logging = createNodeLogging(inlineConfig);
const { userConfig, astroConfig } = await resolveConfig(inlineConfig, 'build');
telemetry.record(eventCliSession('build', userConfig));

const settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));

// Use this hack to prevent the build options being public API
// eslint-disable-next-line prefer-rest-params
const internalOptions = arguments[1] as BuildOptions | undefined;

const builder = new AstroBuilder(settings, {
...internalOptions,
...options,
logging,
mode: inlineConfig.mode,
});
Expand Down
20 changes: 18 additions & 2 deletions packages/astro/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// This is the main entrypoint when importing the `astro` package.

export { default as build } from './build/index.js';
import type { AstroInlineConfig } from '../@types/astro.js';
import { default as _build } from './build/index.js';
import { default as _sync } from './sync/index.js';

export { default as dev } from './dev/index.js';
export { default as preview } from './preview/index.js';
export { default as sync } from './sync/index.js';

/**
* Builds your site for deployment. By default, this will generate static files and place them in a dist/ directory.
* If SSR is enabled, this will generate the necessary server files to serve your site.
*/
// Wrap `_build` to prevent exposing the second internal options parameter
export const build = (inlineConfig: AstroInlineConfig) => _build(inlineConfig);

/**
* Generates TypeScript types for all Astro modules. This sets up a `src/env.d.ts` file for type inferencing,
* and defines the `astro:content` module for the Content Collections API.
*/
// Wrap `_sync` to prevent exposing the second internal options parameter
export const sync = (inlineConfig: AstroInlineConfig) => _sync(inlineConfig);
11 changes: 5 additions & 6 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export type SyncInternalOptions = SyncOptions & {
* Generates TypeScript types for all Astro modules. This sets up a `src/env.d.ts` file for type inferencing,
* and defines the `astro:content` module for the Content Collections API.
*/
export default async function sync(inlineConfig: AstroInlineConfig): Promise<ProcessExit> {
export default async function sync(
inlineConfig: AstroInlineConfig,
options?: SyncOptions
): Promise<ProcessExit> {
const logging = createNodeLogging(inlineConfig);
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, 'sync');
telemetry.record(eventCliSession('sync', userConfig));
Expand All @@ -48,11 +51,7 @@ export default async function sync(inlineConfig: AstroInlineConfig): Promise<Pro
command: 'build',
});

// Use this hack to prevent the sync options being public API
// eslint-disable-next-line prefer-rest-params
const internalOptions = arguments[1] as SyncOptions | undefined;

return await syncInternal(settings, { ...internalOptions, logging });
return await syncInternal(settings, { ...options, logging });
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
import stripAnsi from 'strip-ansi';
import { check } from '../dist/cli/check/index.js';
import { dev, build, preview, sync } from '../dist/core/index.js';
import { dev, preview } from '../dist/core/index.js';
import build from '../dist/core/build/index.js';
import sync from '../dist/core/sync/index.js';
import { RESOLVED_SPLIT_MODULE_ID } from '../dist/core/build/plugins/plugin-ssr.js';
import { getVirtualModulePageNameFromPath } from '../dist/core/build/plugins/util.js';
import { makeSplitEntryPointFileName } from '../dist/core/build/static-build.js';
Expand Down

0 comments on commit 92f0f0c

Please sign in to comment.