Skip to content

Commit

Permalink
Drop tsup in favor of tsc (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Dec 19, 2024
1 parent 4341c70 commit c51b8b3
Show file tree
Hide file tree
Showing 35 changed files with 141 additions and 330 deletions.
2 changes: 1 addition & 1 deletion examples/api/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:schema node_modules/wrangler/config-schema.json
name = "api"
main = ".open-next/worker.ts"
main = ".open-next/worker.js"
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]

Expand Down
2 changes: 1 addition & 1 deletion examples/create-next-app/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:schema node_modules/wrangler/config-schema.json
name = "create-next-app"
main = ".open-next/worker.ts"
main = ".open-next/worker.js"

compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]
Expand Down
2 changes: 1 addition & 1 deletion examples/middleware/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:schema node_modules/wrangler/config-schema.json
name = "middleware"
main = ".open-next/worker.ts"
main = ".open-next/worker.js"
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]

Expand Down
2 changes: 1 addition & 1 deletion examples/vercel-blog-starter/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:schema node_modules/wrangler/config-schema.json
name = "vercel-blog-starter-on-workers"
main = ".open-next/worker.ts"
main = ".open-next/worker.js"

compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]
Expand Down
2 changes: 1 addition & 1 deletion examples/vercel-commerce/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:schema node_modules/wrangler/config-schema.json
name = "vercel-commerce-on-workers"
main = ".open-next/worker.ts"
main = ".open-next/worker.js"

compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/
```toml
#:schema node_modules/wrangler/config-schema.json
name = "<your-app-name>"
main = ".open-next/worker.ts"
main = ".open-next/worker.js"

compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]
Expand Down
35 changes: 0 additions & 35 deletions packages/cloudflare/TODO.md

This file was deleted.

22 changes: 12 additions & 10 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
"name": "@opennextjs/cloudflare",
"description": "Cloudflare builder for next apps",
"version": "0.3.0",
"type": "module",
"scripts": {
"build": "tsup",
"build:watch": "tsup --watch src",
"clean": "rimraf dist",
"build": "pnpm clean && tsc",
"build:watch": "tsc -w",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"ts:check": "tsc --noEmit",
"test": "vitest --run",
"test:watch": "vitest"
},
"bin": {
"opennextjs-cloudflare": "dist/cli/index.mjs"
"opennextjs-cloudflare": "dist/cli/index.js"
},
"main": "./dist/api/index.mjs",
"types": "./dist/api/index.d.mts",
"main": "./dist/api/index.js",
"types": "./dist/api/index.d.ts",
"exports": {
".": {
"import": "./dist/api/index.mjs",
"types": "./dist/api/index.d.mts"
"import": "./dist/api/index.js",
"types": "./dist/api/index.d.ts"
}
},
"files": [
Expand Down Expand Up @@ -49,14 +51,13 @@
"@types/node": "catalog:",
"esbuild": "catalog:",
"eslint": "catalog:",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-import": "catalog:",
"eslint-plugin-simple-import-sort": "catalog:",
"eslint-plugin-unicorn": "catalog:",
"glob": "catalog:",
"globals": "catalog:",
"next": "catalog:",
"package-manager-detector": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:",
"typescript-eslint": "catalog:",
"vitest": "catalog:",
Expand All @@ -69,6 +70,7 @@
"@dotenvx/dotenvx": "catalog:"
},
"peerDependencies": {
"rimraf": "catalog:",
"wrangler": "catalog:"
}
}
2 changes: 1 addition & 1 deletion packages/cloudflare/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./get-cloudflare-context";
export * from "./get-cloudflare-context.js";
19 changes: 8 additions & 11 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { fileURLToPath } from "node:url";
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
import { build, Plugin } from "esbuild";

import { Config } from "../config";
import * as patches from "./patches";
import { copyPrerenderedRoutes } from "./utils";
import { Config } from "../config.js";
import * as patches from "./patches/index.js";
import { copyPrerenderedRoutes } from "./utils/index.js";

/** The dist directory of the Cloudflare adapter package */
const packageDistDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
const packageDistDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "../..");

/**
* Bundle the Open Next server.
Expand Down Expand Up @@ -51,15 +51,15 @@ export async function bundleServer(config: Config, openNextOptions: BuildOptions
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
// eval("require")("bufferutil");
// eval("require")("utf-8-validate");
"next/dist/compiled/ws": path.join(config.paths.internal.templates, "shims", "empty.ts"),
"next/dist/compiled/ws": path.join(config.paths.internal.templates, "shims", "empty.js"),
// Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
// eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
// which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
// QUESTION: Why did I encountered this but mhart didn't?
"next/dist/compiled/edge-runtime": path.join(config.paths.internal.templates, "shims", "empty.ts"),
"next/dist/compiled/edge-runtime": path.join(config.paths.internal.templates, "shims", "empty.js"),
// `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
// source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
"@next/env": path.join(config.paths.internal.templates, "shims", "env.ts"),
"@next/env": path.join(config.paths.internal.templates, "shims", "env.js"),
},
define: {
// config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139
Expand Down Expand Up @@ -188,10 +188,7 @@ function createFixRequiresESBuildPlugin(config: Config): Plugin {
setup(build) {
// Note: we (empty) shim require-hook modules as they generate problematic code that uses requires
build.onResolve({ filter: /^\.\/require-hook$/ }, () => ({
path: path.join(config.paths.internal.templates, "shims", "empty.ts"),
}));
build.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, () => ({
path: path.join(config.paths.internal.templates, "shims", "empty.ts"),
path: path.join(config.paths.internal.templates, "shims", "empty.js"),
}));
},
};
Expand Down
10 changes: 5 additions & 5 deletions packages/cloudflare/src/cli/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { printHeader, showWarningOnWindows } from "@opennextjs/aws/build/utils.j
import logger from "@opennextjs/aws/logger.js";
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";

import type { ProjectOptions } from "../config";
import { containsDotNextDir, getConfig } from "../config";
import { bundleServer } from "./bundle-server";
import { compileEnvFiles } from "./open-next/compile-env-files";
import { createServerBundle } from "./open-next/createServerBundle";
import type { ProjectOptions } from "../config.js";
import { containsDotNextDir, getConfig } from "../config.js";
import { bundleServer } from "./bundle-server.js";
import { compileEnvFiles } from "./open-next/compile-env-files.js";
import { createServerBundle } from "./open-next/createServerBundle.js";

/**
* Builds the application in a format that can be passed to workerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "node:path";

import { BuildOptions } from "@opennextjs/aws/build/helper.js";

import { extractProjectEnvVars } from "../utils";
import { extractProjectEnvVars } from "../utils/index.js";

/**
* Compiles the values extracted from the project's env files to the output directory for use in the worker.
Expand Down
4 changes: 2 additions & 2 deletions packages/cloudflare/src/cli/build/patches/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./investigated";
export * from "./to-investigate";
export * from "./investigated/index.js";
export * from "./to-investigate/index.js";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "node:path";

import type { BuildOptions } from "@opennextjs/aws/build/helper.js";

import { Config } from "../../../config";
import { Config } from "../../../config.js";

/**
* Copies the template files present in the cloudflare adapter package into the standalone node_modules folder
Expand All @@ -16,7 +16,7 @@ export function copyPackageCliFiles(packageDistDir: string, config: Config, open
fs.cpSync(sourceDir, destinationDir, { recursive: true });

fs.copyFileSync(
path.join(packageDistDir, "cli", "templates", "worker.ts"),
path.join(openNextConfig.outputDir, "worker.ts")
path.join(packageDistDir, "cli", "templates", "worker.js"),
path.join(openNextConfig.outputDir, "worker.js")
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./copy-package-cli-files";
export * from "./patch-cache";
export * from "./patch-require";
export * from "./update-webpack-chunks-file";
export * from "./copy-package-cli-files.js";
export * from "./patch-cache.js";
export * from "./patch-require.js";
export * from "./update-webpack-chunks-file/index.js";
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { readFile } from "node:fs/promises";

import { describe, expect, test } from "vitest";

import { tsParseFile } from "../../../utils";
import { getChunkInstallationIdentifiers } from "./get-chunk-installation-identifiers";
import { tsParseFile } from "../../../utils/index.js";
import { getChunkInstallationIdentifiers } from "./get-chunk-installation-identifiers.js";

describe("getChunkInstallationIdentifiers", () => {
test("gets chunk identifiers from unminified code", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";

import { describe, expect, test } from "vitest";

import { tsParseFile } from "../../../utils";
import { tsParseFile } from "../../../utils/index.js";
import { getFileContentWithUpdatedWebpackFRequireCode } from "./get-file-content-with-updated-webpack-f-require-code";

describe("getFileContentWithUpdatedWebpackFRequireCode", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";

import { describe, expect, test } from "vitest";

import { getUpdatedWebpackChunksFileContent } from "./get-updated-webpack-chunks-file-content";
import { getUpdatedWebpackChunksFileContent } from "./get-updated-webpack-chunks-file-content.js";

describe("getUpdatedWebpackChunksFileContent", () => {
test("returns the updated content of a webpack runtime chunks unminified file", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tsParseFile } from "../../../utils";
import { getChunkInstallationIdentifiers } from "./get-chunk-installation-identifiers";
import { getFileContentWithUpdatedWebpackFRequireCode } from "./get-file-content-with-updated-webpack-f-require-code";
import { tsParseFile } from "../../../utils/index.js";
import { getChunkInstallationIdentifiers } from "./get-chunk-installation-identifiers.js";
import { getFileContentWithUpdatedWebpackFRequireCode } from "./get-file-content-with-updated-webpack-f-require-code.js";

/**
* Updates the content of the webpack runtime file in a manner so that it doesn't perform runtime dynamic `require` calls which fail in our runtime.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";

import { Config } from "../../../../config";
import { getUpdatedWebpackChunksFileContent } from "./get-updated-webpack-chunks-file-content";
import { Config } from "../../../../config.js";
import { getUpdatedWebpackChunksFileContent } from "./get-updated-webpack-chunks-file-content.js";

/**
* Fixes the webpack-runtime.js file by removing its webpack dynamic requires.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from "./inline-eval-manifest";
export * from "./inline-middleware-manifest-require";
export * from "./inline-next-require";
export * from "./patch-exception-bubbling";
export * from "./patch-find-dir";
export * from "./patch-load-instrumentation-module";
export * from "./patch-read-file";
export * from "./wrangler-deps";
export * from "./inline-eval-manifest.js";
export * from "./inline-middleware-manifest-require.js";
export * from "./inline-next-require.js";
export * from "./patch-exception-bubbling.js";
export * from "./patch-find-dir.js";
export * from "./patch-load-instrumentation-module.js";
export * from "./patch-read-file.js";
export * from "./wrangler-deps.js";
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { join, posix } from "node:path";

import { globSync } from "glob";

import { Config } from "../../../config";
import { normalizePath } from "../../utils";
import { Config } from "../../../config.js";
import { normalizePath } from "../../utils/index.js";

/**
* `evalManifest` relies on readFileSync so we need to patch the function so that it instead returns the content of the manifest files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";

import { Config } from "../../../config";
import { Config } from "../../../config.js";

/**
* Inlines the middleware manifest from the build output to prevent a dynamic require statement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";

import { Config } from "../../../config";
import { Config } from "../../../config.js";

/**
* The following avoid various Next.js specific files `require`d at runtime since we can just read
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync } from "node:fs";
import { join } from "node:path";

import { Config } from "../../../config";
import { Config } from "../../../config.js";

/**
* Here we patch `findDir` so that the next server can detect whether the `app` or `pages` directory exists
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from "ts-morph";

import { tsParseFile } from "../../utils";
import { tsParseFile } from "../../utils/index.js";

/**
* The `loadInstrumentationModule` method (source: https://github.com/vercel/next.js/blob/5b7833e3/packages/next/src/server/next-server.ts#L301)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { join, posix } from "node:path";

import { globSync } from "glob";

import { Config } from "../../../config";
import { normalizePath } from "../../utils";
import { Config } from "../../../config.js";
import { normalizePath } from "../../utils/index.js";

export function patchBuildId(code: string, config: Config): string {
// The next-server code gets the buildId from the filesystem, resulting in a `[unenv] fs.readFileSync is not implemented yet!` error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync, statSync, writeFileSync } from "node:fs";
import { join } from "node:path";

import { Config } from "../../../config";
import { Config } from "../../../config.js";

export function patchWranglerDeps(config: Config) {
console.log("# patchWranglerDeps");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { dirname, join } from "node:path";

import type { PrerenderManifest } from "next/dist/build";

import { Config } from "../../config";
import { NEXT_META_SUFFIX, SEED_DATA_DIR } from "../../constants/incremental-cache";
import { readPathsRecursively } from "./read-paths-recursively";
import { Config } from "../../config.js";
import { NEXT_META_SUFFIX, SEED_DATA_DIR } from "../../constants/incremental-cache.js";
import { readPathsRecursively } from "./read-paths-recursively.js";

/**
* Copies all prerendered routes from the standalone output directory to the OpenNext static assets
Expand Down
Loading

0 comments on commit c51b8b3

Please sign in to comment.