Skip to content

Commit

Permalink
fix(pluv): fix environment variables not replacing (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
pluvrt authored Dec 20, 2023
1 parent f64b0f0 commit 1158176
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-rivers-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pluv": patch
---

Fix environment variables not correctly applying when building with the pluv cli.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "leedavidcs",
"license": "MIT",
"type": "module",
"types": "./dist/cli",
"bin": {
"pluv": "./dist/cli.js"
},
Expand Down
32 changes: 25 additions & 7 deletions packages/cli/src/utils/buildApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,36 @@ export interface BuildAppOptions {
}

export const buildApp = async (options: BuildAppOptions) => {
const replaceEnv = Object.entries(options.env).reduce<
Record<string, string>
>(
(acc, [key, value]) => ({
...acc,
[`process.env.${key}`]: JSON.stringify(value),
}),
{},
);

const bundle = await rollup({
input: options.input,
output: { format: "esm" },
onLog: (level, log) => {
const { frame, loc, message } = log;

if (loc) {
console.warn(
`${loc.file} (${loc.line}:${loc.column}) ${message}`,
);
if (frame) console.warn(frame);
} else {
console.warn(log);
}
},
plugins: [
(replace as unknown as typeof replace.default)({
values: Object.entries(options).reduce<Record<string, string>>(
(acc, [key, value]) => ({
...acc,
[`process.env.${key}`]: JSON.stringify(value),
}),
{},
),
include: options.input,
preventAssignment: true,
values: replaceEnv,
}),
(typescript as unknown as typeof typescript.default)({
allowJs: true,
Expand Down

1 comment on commit 1158176

@vercel
Copy link

@vercel vercel bot commented on 1158176 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pluv – ./

pluv-git-master-pluv.vercel.app
pluv.vercel.app
pluv-pluv.vercel.app
pluv.io
www.pluv.io

Please sign in to comment.