From 2bda8070f19c209b08b0c09b4b916c5fb4a30d09 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:20:21 +0100 Subject: [PATCH 1/2] Fix hot reload for dependencies of cursorless-org --- packages/cursorless-org/next.config.js | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/cursorless-org/next.config.js b/packages/cursorless-org/next.config.js index 0befbccd58..17be7cab20 100644 --- a/packages/cursorless-org/next.config.js +++ b/packages/cursorless-org/next.config.js @@ -1,10 +1,29 @@ import mdx from "@next/mdx"; +import { readFileSync } from "fs"; +import { join, dirname } from "path"; +import { fileURLToPath } from "url"; + const withMDX = mdx({ options: { providerImportSource: "@mdx-js/react", }, }); +const __dirname = dirname(fileURLToPath(import.meta.url)); + +/** + * The names of the packages that come from the same monorepo as this package. + * We want these to be transpiled by Next.js because we are directly importing + * the source typescript files from these packages. + */ +const references = JSON.parse( + readFileSync(join(__dirname, "tsconfig.json"), "utf-8"), +).references.map(({ path }) => { + return JSON.parse( + readFileSync(join(__dirname, path, "package.json"), "utf-8"), + ).name; +}); + /** @type {import('next').NextConfig} */ const nextConfig = { webpack(config) { @@ -14,11 +33,20 @@ const nextConfig = { use: ["@svgr/webpack"], }); + config.plugins.push({ + apply(compiler) { + compiler.hooks.afterEnvironment.tap("NextEntryPlugin", () => { + compiler.options.resolve.conditionNames.push("cursorless:bundler"); + }); + }, + }); + return config; }, experimental: { mdxRs: true, }, + transpilePackages: references, reactStrictMode: true, output: "export", }; From cdfe1504df94d2900931ac8a8f129e878c761a1d Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:25:43 +0100 Subject: [PATCH 2/2] Add comment --- packages/cursorless-org/next.config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/cursorless-org/next.config.js b/packages/cursorless-org/next.config.js index 17be7cab20..2be517d4f8 100644 --- a/packages/cursorless-org/next.config.js +++ b/packages/cursorless-org/next.config.js @@ -33,6 +33,10 @@ const nextConfig = { use: ["@svgr/webpack"], }); + // Set our custom condition for the bundler so that we directly use + // typescript from packages in our monorepo, which makes hot-reloading + // smoother. Based on + // https://github.com/vercel/next.js/discussions/33813#discussioncomment-7457277 config.plugins.push({ apply(compiler) { compiler.hooks.afterEnvironment.tap("NextEntryPlugin", () => {