From 5d71bfbba214e88cf59ed335a786806c947a2109 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 18 Oct 2023 17:54:22 +0200 Subject: [PATCH] fix: copy `vendor` over for local dev --- packages/runtime/package.json | 2 +- packages/runtime/patch-import-map.mjs | 13 +++++++++++++ packages/runtime/src/helpers/edge.ts | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 packages/runtime/patch-import-map.mjs diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 27b7bdfb1a..eb0dc81752 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -55,7 +55,7 @@ "publish:test": "cd .. && npm ci && npm test", "clean": "rimraf lib dist-types", "build": "run-s build:*", - "build:vendor": "rimraf src/templates/vendor && deno vendor src/templates/vendor.ts --output=src/templates/vendor && patch src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts html_rewriter.patch", + "build:vendor": "rimraf src/templates/vendor && deno vendor src/templates/vendor.ts --output=src/templates/vendor && node patch-import-map.mjs && patch src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts html_rewriter.patch", "build:tsc": "tsc", "watch": "tsc --watch", "prepare": "npm run build" diff --git a/packages/runtime/patch-import-map.mjs b/packages/runtime/patch-import-map.mjs new file mode 100644 index 0000000000..26c1a487c0 --- /dev/null +++ b/packages/runtime/patch-import-map.mjs @@ -0,0 +1,13 @@ +import { readFile, writeFile } from "fs/promises" + +const importMapPath = new URL("src/templates/vendor/import_map.json", import.meta.url) +const importMap = JSON.parse(await readFile(importMapPath, "utf8")) + +const newMap = { + scopes: { + "../": importMap.imports, + ...importMap.scopes + } +} + +await writeFile(importMapPath, JSON.stringify(newMap, null, 2)) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index 4187d6cded..9551b48a29 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -260,10 +260,12 @@ export const writeDevEdgeFunction = async ({ }, ], version: 1, + import_map: 'vendor/import_map.json', } const edgeFunctionRoot = resolve(INTERNAL_EDGE_FUNCTIONS_SRC) await emptyDir(edgeFunctionRoot) await writeJson(join(edgeFunctionRoot, 'manifest.json'), manifest) + await copy(getEdgeTemplatePath('../vendor'), join(edgeFunctionRoot, 'vendor')) await copy(getEdgeTemplatePath('../edge-shared'), join(edgeFunctionRoot, 'edge-shared')) const edgeFunctionDir = join(edgeFunctionRoot, 'next-dev')