From 5a83cd1540530679a08bac717e7daaeca8e56b49 Mon Sep 17 00:00:00 2001 From: Theodore Brockman Date: Wed, 18 Sep 2024 09:54:04 -0400 Subject: [PATCH] Set bundle config as internal env vars so they're also accessible by any other parcel plugins. --- cli/plasmo/src/features/env/env-config.ts | 6 ++++++ cli/plasmo/src/features/helpers/create-parcel-bundler.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/cli/plasmo/src/features/env/env-config.ts b/cli/plasmo/src/features/env/env-config.ts index 7b1296c95..760e1200e 100644 --- a/cli/plasmo/src/features/env/env-config.ts +++ b/cli/plasmo/src/features/env/env-config.ts @@ -89,6 +89,12 @@ function maybeParseJSON(value: string): any { return match ? JSON.parse(match[1]) : value } +export const setInternalEnv = (env: Record) => { + for (const [key, value] of Object.entries(env)) { + process.env[`${INTERNAL_ENV_PREFIX}${constantCase(key)}`] = value + } +} + export const getEnvFileNames = () => { const nodeEnv = process.env.NODE_ENV const flagMap = getFlagMap() diff --git a/cli/plasmo/src/features/helpers/create-parcel-bundler.ts b/cli/plasmo/src/features/helpers/create-parcel-bundler.ts index f7c03ee7b..786d84b55 100644 --- a/cli/plasmo/src/features/helpers/create-parcel-bundler.ts +++ b/cli/plasmo/src/features/helpers/create-parcel-bundler.ts @@ -11,6 +11,7 @@ import { Parcel, type ParcelOptions } from "@plasmohq/parcel-core" import type { PlasmoManifest } from "~features/manifest-factory/base" import { getPackageManager } from "./package-manager" +import { setInternalEnv } from "~features/env/env-config" const PackageInstallerMap = { npm: ParcelPM.Npm, @@ -104,6 +105,8 @@ export const createParcelBuilder = async ( : ["last 1 Chrome version"] } + setInternalEnv(bundleConfig) + const bundler = new Parcel({ inputFS, packageManager,