this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Prepare for the npm package (#8)

Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>

authored by

Victor Berchet
Peter Bacon Darwin
and committed by
GitHub
b84cd5fd 0ec7c7c1

+114 -26
+25
LICENSE
··· 1 + Copyright (c) 2020 Cloudflare, Inc. 2 + 3 + Permission is hereby granted, free of charge, to any 4 + person obtaining a copy of this software and associated 5 + documentation files (the "Software"), to deal in the 6 + Software without restriction, including without 7 + limitation the rights to use, copy, modify, merge, 8 + publish, distribute, sublicense, and/or sell copies of 9 + the Software, and to permit persons to whom the Software 10 + is furnished to do so, subject to the following 11 + conditions: 12 + 13 + The above copyright notice and this permission notice 14 + shall be included in all copies or substantial portions 15 + of the Software. 16 + 17 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 + TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 + PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 + SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 + IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 + DEALINGS IN THE SOFTWARE.
+1
TODO.md
··· 14 14 ## Install 15 15 16 16 - `npx create-next-app@latest <app-name> --use-npm` (use npm to avoid symlinks) 17 + 17 18 - update next.config.mjs as follows 18 19 19 20 ```typescript
+46
builder/README.md
··· 1 + # Next.js builder for Cloudflare 2 + 3 + ## Build your app 4 + 5 + - update the `next.config.mjs` as follows 6 + 7 + ```typescript 8 + /** @type {import('next').NextConfig} */ 9 + const nextConfig = { 10 + output: "standalone", 11 + experimental: { 12 + serverMinification: false, 13 + }, 14 + }; 15 + 16 + export default nextConfig; 17 + ``` 18 + 19 + - add the following `devDependency` to the `package.json`: 20 + 21 + ```json 22 + "node-url": "npm:url@^0.11.4", 23 + "wrangler": "^3.77.0" 24 + ``` 25 + 26 + - Execute `npx @flarelabs-net/builder@latest` in your app folder 27 + 28 + ## Serve your app 29 + 30 + - add a `wrangler.toml` at the root of your project 31 + 32 + ```toml 33 + #:schema node_modules/wrangler/config-schema.json 34 + name = "<app-name>" 35 + main = ".worker-next/index.mjs" 36 + 37 + compatibility_date = "2024-08-29" 38 + compatibility_flags = ["nodejs_compat_v2"] 39 + workers_dev = true 40 + minify = false 41 + 42 + # Use the new Workers + Assets to host the static frontend files 43 + experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" } 44 + ``` 45 + 46 + - Use `wrangler dev`
+19 -1
builder/package.json
··· 1 1 { 2 - "name": "builder", 2 + "name": "@flarelabs-net/builder", 3 + "description": "Cloudflare builder for next apps", 4 + "version": "0.0.1", 3 5 "scripts": { 4 6 "build": "tsup", 5 7 "build:watch": "tsup --watch src" 6 8 }, 7 9 "bin": "dist/index.mjs", 8 10 "files": [ 11 + "README.md", 9 12 "dist" 10 13 ], 14 + "repository": { 15 + "type": "git", 16 + "url": "https://github.com/flarelabs-net/poc-next.git", 17 + "directory": "builder" 18 + }, 19 + "keywords": [ 20 + "cloudflare", 21 + "workers", 22 + "next.js" 23 + ], 24 + "license": "MIT", 25 + "bugs": { 26 + "url": "https://github.com/flarelabs-net/poc-next/issues" 27 + }, 28 + "homepage": "https://github.com/flarelabs-net/poc-next", 11 29 "devDependencies": { 12 30 "@types/node": "^22.2.0", 13 31 "esbuild": "^0.23.0",
+1 -1
builder/src/build/build-worker/index.ts builder/src/build/build-worker.ts
··· 1 - import { NextjsAppPaths } from "../../nextjs-paths"; 1 + import { NextjsAppPaths } from "../nextjs-paths"; 2 2 import { build, Plugin } from "esbuild"; 3 3 import { readdirSync, readFileSync, writeFileSync } from "node:fs"; 4 4 import { cp, readFile, writeFile } from "node:fs/promises";
+1 -1
builder/src/build/build-worker/patches/investigated/copy-templates.ts builder/src/build/patches/investigated/copy-templates.ts
··· 1 1 import path from "node:path"; 2 - import { NextjsAppPaths } from "../../../../nextjs-paths"; 2 + import { NextjsAppPaths } from "../../../nextjs-paths"; 3 3 import { cpSync } from "node:fs"; 4 4 5 5 /**
builder/src/build/build-worker/patches/investigated/patch-require.ts builder/src/build/patches/investigated/patch-require.ts
builder/src/build/build-worker/patches/investigated/patch-url.ts builder/src/build/patches/investigated/patch-url.ts
+1 -1
builder/src/build/build-worker/patches/to-investigate/inline-eval-manifest.ts builder/src/build/patches/to-investigate/inline-eval-manifest.ts
··· 1 1 import { globSync } from "glob"; 2 - import { NextjsAppPaths } from "../../../../nextjs-paths"; 2 + import { NextjsAppPaths } from "../../../nextjs-paths"; 3 3 4 4 /** 5 5 * `evalManifest` relies on readFileSync so we need to patch the function so that it instead returns the content of the manifest files
+1 -1
builder/src/build/build-worker/patches/to-investigate/inline-next-require.ts builder/src/build/patches/to-investigate/inline-next-require.ts
··· 1 1 import { readFileSync, existsSync } from "node:fs"; 2 - import { NextjsAppPaths } from "../../../../nextjs-paths"; 2 + import { NextjsAppPaths } from "../../../nextjs-paths"; 3 3 4 4 /** 5 5 * The following avoid various Next.js specific files `require`d at runtime since we can just read
+1 -1
builder/src/build/build-worker/patches/to-investigate/patch-find-dir.ts builder/src/build/patches/to-investigate/patch-find-dir.ts
··· 1 - import { NextjsAppPaths } from "../../../../nextjs-paths"; 1 + import { NextjsAppPaths } from "../../../nextjs-paths"; 2 2 import { existsSync } from "node:fs"; 3 3 4 4 /**
+1 -1
builder/src/build/build-worker/patches/to-investigate/patch-read-file.ts builder/src/build/patches/to-investigate/patch-read-file.ts
··· 1 1 import { readFileSync } from "node:fs"; 2 2 import { globSync } from "glob"; 3 - import { NextjsAppPaths } from "../../../../nextjs-paths"; 3 + import { NextjsAppPaths } from "../../../nextjs-paths"; 4 4 5 5 export function patchReadFile(code: string, nextjsAppPaths: NextjsAppPaths): string { 6 6 console.log("# patchReadFile");
+1 -1
builder/src/build/build-worker/patches/to-investigate/wrangler-deps.ts builder/src/build/patches/to-investigate/wrangler-deps.ts
··· 1 1 import path from "node:path"; 2 2 import fs, { writeFileSync } from "node:fs"; 3 - import { NextjsAppPaths } from "../../../../nextjs-paths"; 3 + import { NextjsAppPaths } from "../../../nextjs-paths"; 4 4 5 5 export function patchWranglerDeps(paths: NextjsAppPaths) { 6 6 console.log("# patchWranglerDeps");
builder/src/build/build-worker/templates/shims/empty.ts builder/src/templates/shims/empty.ts
builder/src/build/build-worker/templates/shims/env.ts builder/src/templates/shims/env.ts
builder/src/build/build-worker/templates/shims/node-fs.ts builder/src/templates/shims/node-fs.ts
builder/src/build/build-worker/templates/shims/throw.ts builder/src/templates/shims/throw.ts
builder/src/build/build-worker/templates/worker.ts builder/src/templates/worker.ts
-2
builder/src/build/index.ts builder/src/build/build.ts
··· 43 43 44 44 const templateDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "templates"); 45 45 46 - console.log({ outputDir, nextjsAppPaths, templateDir }); 47 - 48 46 await buildWorker(outputDir, nextjsAppPaths, templateDir); 49 47 } 50 48
+4 -4
builder/src/index.ts
··· 1 1 import { resolve } from "node:path"; 2 2 import { getArgs } from "./args"; 3 3 import { existsSync } from "node:fs"; 4 - import { build } from "./build"; 4 + import { build } from "./build/build"; 5 5 6 - const inputNextAppDir = resolve("."); 6 + const nextAppDir = resolve("."); 7 7 8 - console.log({ inputNextAppDir }); 8 + console.log(`Building the Next.js app in the current folder (${nextAppDir})`); 9 9 10 10 if (!["js", "cjs", "mjs", "ts"].some((ext) => existsSync(`./next.config.${ext}`))) { 11 11 // TODO: we can add more validation later ··· 14 14 15 15 const { skipBuild, outputDir } = getArgs(); 16 16 17 - await build(inputNextAppDir, { 17 + await build(nextAppDir, { 18 18 outputDir, 19 19 skipBuild: !!skipBuild, 20 20 });
+2 -2
builder/tsup.config.ts
··· 4 4 export default defineConfig({ 5 5 entry: ["src/index.ts"], 6 6 outDir: "dist", 7 - dts: true, 7 + dts: false, 8 8 format: ["esm"], 9 9 platform: "node", 10 10 external: ["esbuild"], 11 11 onSuccess: async () => { 12 - await cp(`${__dirname}/src/build/build-worker/templates`, `${__dirname}/dist/templates`, { 12 + await cp(`${__dirname}/src/templates`, `${__dirname}/dist/templates`, { 13 13 recursive: true, 14 14 }); 15 15 },
+2 -2
examples/api/package.json
··· 7 7 "build": "next build", 8 8 "start": "next start", 9 9 "lint": "next lint", 10 - "build:worker": "builder", 10 + "build:worker": "pnpm builder", 11 11 "dev:worker": "wrangler dev --port 8770", 12 12 "preview:worker": "pnpm build:worker && pnpm dev:worker", 13 13 "e2e": "playwright test" ··· 18 18 "react-dom": "^18" 19 19 }, 20 20 "devDependencies": { 21 - "builder": "workspace:*", 21 + "@flarelabs-net/builder": "workspace:*", 22 22 "@playwright/test": "1.47.0", 23 23 "@types/node": "^22.2.0", 24 24 "node-url": "npm:url@^0.11.4",
+2 -2
examples/create-next-app/package.json
··· 7 7 "build": "next build", 8 8 "start": "next start", 9 9 "lint": "next lint", 10 - "build:worker": "builder", 10 + "build:worker": "pnpm builder", 11 11 "dev:worker": "wrangler dev --port 8771", 12 12 "preview:worker": "pnpm build:worker && pnpm dev:worker", 13 13 "e2e": "playwright test -c e2e/playwright.config.ts" ··· 18 18 "next": "14.2.11" 19 19 }, 20 20 "devDependencies": { 21 - "builder": "workspace:*", 21 + "@flarelabs-net/builder": "workspace:*", 22 22 "@playwright/test": "1.47.0", 23 23 "@types/node": "^20", 24 24 "@types/react": "^18",
+6 -6
pnpm-lock.yaml
··· 48 48 specifier: ^18 49 49 version: 18.3.1(react@18.3.1) 50 50 devDependencies: 51 + '@flarelabs-net/builder': 52 + specifier: workspace:* 53 + version: link:../../builder 51 54 '@playwright/test': 52 55 specifier: 1.47.0 53 56 version: 1.47.0 54 57 '@types/node': 55 58 specifier: ^22.2.0 56 59 version: 22.2.0 57 - builder: 58 - specifier: workspace:* 59 - version: link:../../builder 60 60 node-url: 61 61 specifier: npm:url@^0.11.4 62 62 version: url@0.11.4 ··· 76 76 specifier: ^18 77 77 version: 18.3.1(react@18.3.1) 78 78 devDependencies: 79 + '@flarelabs-net/builder': 80 + specifier: workspace:* 81 + version: link:../../builder 79 82 '@playwright/test': 80 83 specifier: 1.47.0 81 84 version: 1.47.0 ··· 88 91 '@types/react-dom': 89 92 specifier: ^18 90 93 version: 18.3.0 91 - builder: 92 - specifier: workspace:* 93 - version: link:../../builder 94 94 eslint: 95 95 specifier: ^8 96 96 version: 8.57.0