Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename build option to static #1144

Merged
merged 4 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function prepare(nitro: Nitro) {
if (!nitro.options.noPublicDir) {
await prepareDir(nitro.options.output.publicDir);
}
if (nitro.options.build) {
if (!nitro.options.static) {
await prepareDir(nitro.options.output.serverDir);
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ async function _build(nitro: Nitro, rollupConfig: RollupConfig) {
await writeTypes(nitro);
await _snapshot(nitro);

if (nitro.options.build) {
if (!nitro.options.static) {
nitro.logger.info(
`Building Nitro Server (preset: \`${nitro.options.preset}\`)`
);
Expand All @@ -281,7 +281,7 @@ async function _build(nitro: Nitro, rollupConfig: RollupConfig) {
};
await writeFile(nitroConfigPath, JSON.stringify(buildInfo, null, 2));

if (nitro.options.build) {
if (!nitro.options.static) {
nitro.logger.success("Nitro server built");
if (nitro.options.logLevel > 1) {
process.stdout.write(
Expand Down
5 changes: 2 additions & 3 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const NitroDefaults: NitroConfig = {
// General
debug: isDebug,
logLevel: isTest ? 1 : 3,
build: true,
runtimeConfig: { app: {}, nitro: {} },
appConfig: {},
appConfigFiles: [],
Expand Down Expand Up @@ -148,7 +147,7 @@ export async function loadOptions(
options.preset =
presetOverride ||
(layers.find((l) => l.config.preset)?.config.preset as string) ||
(detectTarget({ static: !options.build }) ?? "node-server");
(detectTarget({ static: options.static }) ?? "node-server");

options.rootDir = resolve(options.rootDir || ".");
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
Expand All @@ -169,7 +168,7 @@ export async function loadOptions(
};

// Resolve possibly template paths
if (options.build && !options.entry) {
if (!options.static && !options.entry) {
throw new Error(
`Nitro entry is missing! Is "${options.preset}" preset correct?`
);
Expand Down
4 changes: 2 additions & 2 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ async function writeRedirects(nitro: Nitro) {
)
? "/* /404.html 404"
: "";
let contents = nitro.options.build
let contents = !nitro.options.static
? "/* /.netlify/functions/server 200"
: staticFallback;

const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
);

if (nitro.options.build) {
if (!nitro.options.static) {
// Rewrite static ISR paths to builder functions
for (const [key, value] of rules.filter(
([_, value]) => value.isr !== undefined
Expand Down
2 changes: 1 addition & 1 deletion src/presets/static.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineNitroPreset } from "../preset";

export const _static = defineNitroPreset({
build: false,
static: true,
output: {
dir: "{{ rootDir }}/.output",
publicDir: "{{ output.dir }}/public",
Expand Down
4 changes: 2 additions & 2 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function generateBuildConfig(nitro: Nitro) {
],
});

// Early return if we are not building a serverless function
if (!nitro.options.build) {
// Early return if we are building a static site
if (nitro.options.static) {
return config;
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export interface NitroOptions extends PresetOptions {
debug: boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
preset: KebabCase<keyof typeof _PRESETS> | (string & {});
build: boolean;
static: boolean;
logLevel: LogLevel;
runtimeConfig: {
app: {
Expand Down