Skip to content

Commit

Permalink
refactor!: use nitro as canonical name
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 13, 2024
1 parent 23c715a commit 9bdce70
Show file tree
Hide file tree
Showing 157 changed files with 263 additions and 300 deletions.
13 changes: 6 additions & 7 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ export default defineBuildConfig({
{ input: "src/types/index.ts" },
],
alias: {
nitropack: "nitropack",
"nitropack/meta": resolve(srcDir, "../meta.ts"),
"nitropack/runtime/meta": resolve(srcDir, "../runtime-meta.mjs"),
"nitro/meta": resolve(srcDir, "../meta.ts"),
"nitro/runtime/meta": resolve(srcDir, "../runtime-meta.mjs"),
...Object.fromEntries(
subpaths.map((subpath) => [
`nitropack/${subpath}`,
`nitro/${subpath}`,
resolve(srcDir, `${subpath}/index.ts`),
])
),
Expand All @@ -63,9 +62,9 @@ export default defineBuildConfig({
},
},
externals: [
"nitropack",
"nitropack/runtime/meta",
...subpaths.map((subpath) => `nitropack/${subpath}`),
"nitro",
"nitro/runtime/meta",
...subpaths.map((subpath) => `nitro/${subpath}`),
"firebase-functions",
"@scalar/api-reference",
],
Expand Down
2 changes: 1 addition & 1 deletion examples/graceful-shutdown/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "nitropack/config";
import { defineNitroConfig } from "nitro/config";

export default defineNitroConfig({});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nitropack",
"version": "2.9.6",
"name": "nitro",
"version": "3.0.0",
"description": "Build and Deploy Universal JavaScript Servers",
"repository": "unjs/nitro",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion playground/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNitroConfig } from "nitropack/config";
import { defineNitroConfig } from "nitro/config";

export default defineNitroConfig({
compatibilityDate: "2024-06-12",
Expand Down
6 changes: 3 additions & 3 deletions scripts/gen-presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { kebabCase, camelCase, pascalCase, snakeCase } from "scule";
import { readdirSync, existsSync, writeFileSync, readFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import type { NitroPreset, NitroPresetMeta } from "nitropack/types";
import type { NitroPreset, NitroPresetMeta } from "nitro/types";
import { findTypeExports } from "mlly";
import { subpaths } from "../build.config";

Expand All @@ -25,10 +25,10 @@ const jitiRequire = createJITI(presetsDir, {
esmResolve: true,
interopDefault: true,
alias: {
nitropack: fileURLToPath(new URL("../src/core/index.ts", import.meta.url)),
nitro: fileURLToPath(new URL("../src/core/index.ts", import.meta.url)),
...Object.fromEntries(
subpaths.map((pkg) => [
`nitropack/${pkg}`,
`nitro/${pkg}`,
fileURLToPath(new URL(`../src/${pkg}/index.ts`, import.meta.url)),
])
),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
build,
prepare,
copyPublicAssets,
} from "nitropack/core";
} from "nitro/core";
import { commonArgs } from "../common";
import type { DateString } from "compatx";

Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { defineCommand } from "citty";
import { resolve } from "pathe";
import { consola } from "consola";
import { getArgs, parseArgs } from "listhen/cli";
import { createNitro, build, prepare, createDevServer } from "nitropack/core";
import { createNitro, build, prepare, createDevServer } from "nitro/core";
import { commonArgs } from "../common";
import type { Nitro } from "nitropack/types";
import type { Nitro } from "nitro/types";

const hmrKeyRe = /^runtimeConfig\.|routeRules\./;

Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from "citty";
import { resolve } from "pathe";
import { createNitro, writeTypes } from "nitropack/core";
import { createNitro, writeTypes } from "nitro/core";
import { commonArgs } from "../common";

export default defineCommand({
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/task/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import { resolve } from "pathe";
import { consola } from "consola";
import { listTasks } from "nitropack/core";
import { listTasks } from "nitro/core";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/task/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineCommand } from "citty";
import { resolve } from "pathe";
import destr from "destr";
import { consola } from "consola";
import { runTask } from "nitropack/core";
import { runTask } from "nitro/core";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { defineCommand, runMain } from "citty";
import { version as nitroVersion } from "nitropack/meta";
import { version as nitroVersion } from "nitro/meta";

const main = defineCommand({
meta: {
Expand Down
4 changes: 2 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NitroConfig } from "nitropack/types";
import type { NitroConfig } from "nitro/types";

export type { NitroConfig } from "nitropack/types";
export type { NitroConfig } from "nitro/types";

export function defineNitroConfig(config: NitroConfig): NitroConfig {
return config;
Expand Down
4 changes: 2 additions & 2 deletions src/core/build/assets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { existsSync, promises as fsp } from "node:fs";
import { relative, resolve, join } from "pathe";
import { globby } from "globby";
import { prettyPath, isDirectory } from "nitropack/kit";
import type { Nitro } from "nitropack/types";
import { prettyPath, isDirectory } from "nitro/kit";
import type { Nitro } from "nitro/types";
import { compressPublicAssets } from "../utils/compress";

const NEGATION_RE = /^(!?)(.*)$/;
Expand Down
4 changes: 2 additions & 2 deletions src/core/build/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getRollupConfig } from "nitropack/rollup";
import type { Nitro } from "nitropack/types";
import { getRollupConfig } from "nitro/rollup";
import type { Nitro } from "nitro/types";
import { watchDev } from "./dev";
import { buildProduction } from "./prod";

Expand Down
2 changes: 1 addition & 1 deletion src/core/build/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as rollup from "rollup";
import { watch } from "chokidar";
import { debounce } from "perfect-debounce";
import { GLOB_SCAN_PATTERN, scanHandlers } from "../scan";
import type { Nitro, RollupConfig } from "nitropack/types";
import type { Nitro, RollupConfig } from "nitro/types";
import { writeTypes } from "./types";
import defu from "defu";
import { formatRollupError } from "./error";
Expand Down
2 changes: 1 addition & 1 deletion src/core/build/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fsp from "node:fs/promises";
import fse from "fs-extra";
import type { Nitro } from "nitropack";
import type { Nitro } from "nitro/types";

export async function prepare(nitro: Nitro) {
await prepareDir(nitro.options.output.dir);
Expand Down
6 changes: 3 additions & 3 deletions src/core/build/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { promises as fsp } from "node:fs";
import { relative, resolve, join, dirname } from "pathe";
import * as rollup from "rollup";
import { generateFSTree } from "../utils/fs-tree";
import { writeFile } from "nitropack/kit";
import { writeFile } from "nitro/kit";
import { scanHandlers } from "../scan";
import type { Nitro, NitroBuildInfo, RollupConfig } from "nitropack/types";
import { version as nitroVersion } from "nitropack/meta";
import type { Nitro, NitroBuildInfo, RollupConfig } from "nitro/types";
import { version as nitroVersion } from "nitro/meta";
import { snapshotStorage } from "../utils/storage";
import { formatRollupError } from "./error";
import { writeTypes } from "./types";
Expand Down
18 changes: 9 additions & 9 deletions src/core/build/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
resolvePath,
} from "mlly";
import { JSValue, generateTypes, resolveSchema } from "untyped";
import { writeFile, isDirectory, resolveNitroPath } from "nitropack/kit";
import type { Nitro, NitroTypes } from "nitropack/types";
import { runtimeDir } from "nitropack/runtime/meta";
import { writeFile, isDirectory, resolveNitroPath } from "nitro/kit";
import type { Nitro, NitroTypes } from "nitro/types";
import { runtimeDir } from "nitro/runtime/meta";
import { relative } from "pathe";

export async function writeTypes(nitro: Nitro) {
Expand Down Expand Up @@ -103,8 +103,8 @@ export async function writeTypes(nitro: Nitro) {

const routes = [
"// Generated by nitro",
'import type { Serialize, Simplify } from "nitropack/types";',
'declare module "nitropack/types" {',
'import type { Serialize, Simplify } from "nitro/types";',
'declare module "nitro/types" {',
" type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T",
" interface InternalApi {",
...Object.entries(types.routes).map(([path, methods]) =>
Expand Down Expand Up @@ -140,7 +140,7 @@ type UserAppConfig = Defu<{}, [${nitro.options.appConfigFiles
.map((_, index: number) => `typeof appConfig${index}`)
.join(", ")}]>
declare module "nitropack/types" {
declare module "nitro/types" {
interface AppConfig extends UserAppConfig {}`,
nitro.options.typescript.generateRuntimeConfigTypes
? generateTypes(
Expand All @@ -166,7 +166,7 @@ declare module "nitropack/types" {
];

const declarations = [
// local nitropack augmentations
// local nitro augmentations
'/// <reference path="./nitro-routes.d.ts" />',
'/// <reference path="./nitro-config.d.ts" />',
// global server auto-imports
Expand Down Expand Up @@ -250,13 +250,13 @@ declare module "nitropack/types" {
],
...(nitro.options.typescript.internalPaths
? {
"nitropack/runtime": [
"nitro/runtime": [
relativeWithDot(tsconfigDir, join(runtimeDir, "index")),
],
"#internal/nitro": [
relativeWithDot(tsconfigDir, join(runtimeDir, "index")),
],
"nitropack/runtime/*": [
"nitro/runtime/*": [
relativeWithDot(tsconfigDir, join(runtimeDir, "*")),
],
"#internal/nitro/*": [
Expand Down
8 changes: 4 additions & 4 deletions src/core/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isTest, isDebug } from "std-env";
import type { NitroConfig } from "nitropack/types";
import type { NitroConfig } from "nitro/types";
import { resolve } from "pathe";
import { runtimeDir } from "nitropack/runtime/meta";
import { runtimeDir } from "nitro/runtime/meta";

export const NitroDefaults: NitroConfig = {
// General
Expand Down Expand Up @@ -58,8 +58,8 @@ export const NitroDefaults: NitroConfig = {
baseURL: process.env.NITRO_APP_BASE_URL || "/",
handlers: [],
devHandlers: [],
// errorHandler: "nitropack/runtime/internal/error",
errorHandler: "#internal/nitro/error",
// errorHandler: "nitro/runtime/internal/error",
errorHandler: "#internal/nitro/internal/error",
routeRules: {},
prerender: {
autoSubfolderIndex: true,
Expand Down
12 changes: 6 additions & 6 deletions src/core/config/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
NitroConfig,
NitroOptions,
NitroPresetMeta,
} from "nitropack/types";
import type { PresetName } from "nitropack/presets";
} from "nitro/types";
import type { PresetName } from "nitro/presets";

import { NitroDefaults } from "./defaults";

Expand Down Expand Up @@ -81,8 +81,8 @@ async function _loadUserConfig(

// Preset resolver
const { resolvePreset } = (await import(
"nitropack/" + "presets"
)) as typeof import("nitropack/presets");
"nitro/" + "presets"
)) as typeof import("nitro/presets");

const loadedConfig = await (opts.watch
? watchConfig<NitroConfig & { _meta?: NitroPresetMeta }>
Expand Down Expand Up @@ -114,8 +114,8 @@ async function _loadUserConfig(
defaults: NitroDefaults,
jitiOptions: {
alias: {
nitropack: "nitropack/config",
"nitropack/config": "nitropack/config",
nitropack: "nitro/config",
"nitro/config": "nitro/config",
},
},
async resolve(id: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/resolvers/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from "pathe";
import { existsSync } from "node:fs";
import { withLeadingSlash, withoutTrailingSlash } from "ufo";
import { defu } from "defu";
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";

export async function resolveAssetsOptions(options: NitroOptions) {
// Public Assets
Expand Down
4 changes: 2 additions & 2 deletions src/core/config/resolvers/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "compatx";
import _consola from "consola";
import { colorize } from "consola/utils";
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";
import { relative } from "pathe";

// Nitro v2.9.6 release
Expand Down Expand Up @@ -104,7 +104,7 @@ async function _resolveDefault(options: NitroOptions): Promise<DateString> {

function _getDefaultNitroConfig() {
return /* js */ `
import { defineNitroConfig } from 'nitropack/config'
import { defineNitroConfig } from 'nitro/config'
export default defineNitroConfig({})
`;
Expand Down
4 changes: 2 additions & 2 deletions src/core/config/resolvers/database.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";

export async function resolveDatabaseOptions(options: NitroOptions) {
if (options.experimental.database && options.imports) {
options.imports.presets.push({
from: "nitropack/runtime",
from: "nitro/runtime",
imports: ["useDatabase"],
});
if (options.dev && !options.database && !options.devDatabase) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/resolvers/export-conditions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";

export async function resolveExportConditionsOptions(options: NitroOptions) {
options.exportConditions = _resolveExportConditions(
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/resolvers/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import consola from "consola";
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";
import { nodeMajorVersion, provider } from "std-env";

export async function resolveFetchOptions(options: NitroOptions) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/config/resolvers/imports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";
import escapeRE from "escape-string-regexp";
import { resolveModuleExportNames } from "mlly";
import { join } from "pathe";
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function resolveImportsOptions(options: NitroOptions) {
function getNitroImportsPreset(): Preset[] {
return [
{
from: "nitropack/runtime",
from: "nitro/runtime",
imports: [
"defineCachedFunction",
"defineCachedEventHandler",
Expand Down
8 changes: 4 additions & 4 deletions src/core/config/resolvers/open-api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { NitroOptions } from "nitropack/types";
import type { NitroOptions } from "nitro/types";

export async function resolveOpenAPIOptions(options: NitroOptions) {
if (options.dev && options.experimental.openAPI) {
options.handlers.push({
route: "/_nitro/openapi.json",
handler: "nitropack/runtime/internal/routes/openapi",
handler: "nitro/runtime/internal/routes/openapi",
});
options.handlers.push({
route: "/_nitro/scalar",
handler: "nitropack/runtime/internal/routes/scalar",
handler: "nitro/runtime/internal/routes/scalar",
});
options.handlers.push({
route: "/_nitro/swagger",
handler: "nitropack/runtime/internal/routes/swagger",
handler: "nitro/runtime/internal/routes/swagger",
});
}
}
6 changes: 3 additions & 3 deletions src/core/config/resolvers/paths.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { findWorkspaceDir } from "pkg-types";
import { resolveNitroPath } from "nitropack/kit";
import type { NitroOptions } from "nitropack/types";
import { resolveNitroPath } from "nitro/kit";
import type { NitroOptions } from "nitro/types";
import { resolve, join } from "pathe";
import { NitroDefaults } from "../defaults";
import { pkgDir } from "nitropack/runtime/meta";
import { pkgDir } from "nitro/runtime/meta";
import { existsSync } from "node:fs";

export async function resolvePathOptions(options: NitroOptions) {
Expand Down
Loading

0 comments on commit 9bdce70

Please sign in to comment.