Skip to content

Commit

Permalink
feat: disable env in cloudflare
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Oct 2, 2024
1 parent 1ddf94b commit 3424299
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ import {
// ...
```

> **Notice**
> [!NOTE]
>
> From `unplugin-info@0.6.0`, the original virtual module called `~build/info` will be renamed to `~build/git`, and the CI/CD related information will be moved to another virtual module called `~build/ci`.
Expand Down
8 changes: 5 additions & 3 deletions src/core/modules/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export class BuildEnvModule extends BuildInfoModule {
return options.env;
};

const cloudflare = options.cloudflare === true;
const meta = await get();
const body = Object.entries(meta).map(
([key, value]) =>
`export const ${key} = (import.meta.env.SSR ? process?.env?.['${key.replace(/'/g, '\\')}'] : undefined) ?? ${JSON.stringify(value, null, 2)};`
const body = Object.entries(meta).map(([key, value]) =>
!cloudflare
? `export const ${key} = (import.meta.env.SSR ? process?.env?.['${key.replace(/'/g, '\\')}'] : undefined) ?? ${JSON.stringify(value, null, 2)};`
: `export const ${key} = ${JSON.stringify(value, null, 2)};`
);

return body.length > 0 ? body.join('\n') : 'export {};';
Expand Down
8 changes: 8 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export interface Options {
*/
env?: Metadata | (() => Env | Promise<Env>);

/**
* Print help build information
*/
console?: {
/**
* Enable build info log under these NODE_ENV
Expand All @@ -80,4 +83,9 @@ export interface Options {
* @default '~build'
*/
prefix?: string;

/**
* Whether it is bundled for cloudflare worker runtime
*/
cloudflare?: boolean;
}

0 comments on commit 3424299

Please sign in to comment.