import fs from "node:fs"; import path from "node:path"; /** * Dependencies that _are not_ bundled along with wrangler */ export const EXTERNAL_DEPENDENCIES = [ // Wrangler depends on a pinned version of esbuild. "esbuild", // This blows up when bundled, and has WASM dependencies. Wrangler depends on a pinned version. "blake3-wasm", // Wrangler depends on a pinned version of Miniflare. "miniflare", // @cloudflare/workers-types is an optional peer dependency of wrangler, so users can // get the types by installing the package (to what version they prefer) themselves "@cloudflare/workers-types", // unenv must be external because it contains unenv/runtime code which needs to be resolved // and read when we are bundling the worker application "unenv", "@cloudflare/unenv-preset", // path-to-regexp must be external because it contains runtime code which needs to be resolved // and read when we are bundling the worker application. // See `templates/pages-template-workers` "path-to-regexp", // @cloudflare/kv-asset-handler must be external because it contains runtime code which needs to be resolved // and read when we are bundling the worker application // Pending deletion in v4... "@cloudflare/kv-asset-handler", // workerd contains a native binary, so must be external. Wrangler depends on a pinned version. "workerd", ]; /** * Bare-specifier imports that legitimately appear in wrangler's bundled * output but should NOT be treated as missing runtime dependencies. * * Each entry must be justified — typically the import is guarded * (try/catch, optional require) inside a bundled-in third-party library that * probes for the consumer's environment. */ export const IGNORED_DIST_IMPORTS = [ // @netlify/build-info (bundled devDependency) tries to require these // framework packages to detect what the user has installed. Each call // is guarded by try/catch and used only for framework detection. "@angular/ssr", "@cloudflare/vite-plugin", "isbot", "react-dom", "react-router", "waku", // @aws-sdk/client-s3 (bundled devDependency) optionally uses this native // crypto implementation if installed; falls back to a JS implementation // when missing. "@aws-sdk/signature-v4-crt", ]; const pathToPackageJson = path.resolve(__dirname, "..", "package.json"); const packageJson = fs.readFileSync(pathToPackageJson, { encoding: "utf-8" }); const { dependencies, devDependencies } = JSON.parse(packageJson); /** * Dependencies that _are_ bundled along with wrangler */ export const BUNDLED_DEPENDENCIES = Object.keys({ ...dependencies, ...devDependencies, }).filter((dep) => !EXTERNAL_DEPENDENCIES.includes(dep));