Skip to content

Commit d9d137a

Browse files
committed
Add @std/dotenv if have env
1 parent dada3ee commit d9d137a

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

packages/init/src/action/deps.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ type Deps = Record<string, string>;
2626
* @returns A record of dependencies with their versions
2727
*/
2828
export const getDependencies = (
29-
{ initializer, kv, mq, testMode, packageManager }: Pick<
29+
{ initializer, kv, mq, env, testMode, packageManager }: Pick<
3030
InitCommandData,
31-
"initializer" | "kv" | "mq" | "packageManager" | "testMode"
31+
"initializer" | "kv" | "mq" | "env" | "packageManager" | "testMode"
3232
>,
3333
): Deps =>
3434
pipe(
3535
{
3636
"@fedify/fedify": PACKAGE_VERSION,
3737
"@fedify/vocab": PACKAGE_VERSION,
3838
"@logtape/logtape": deps["@logtape/logtape"],
39+
...(packageManager === "deno" && Object.keys(env).length > 0 &&
40+
{ "@std/dotenv": deps["@std/dotenv"] }),
3941
},
4042
merge(initializer.dependencies),
4143
merge(kv.dependencies),

packages/init/src/action/templates.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { entries, join, map, pipe } from "@fxts/core";
22
import { toMerged } from "es-toolkit";
3-
import { replace } from "../utils.ts";
43
import { readTemplate } from "../lib.ts";
54
import type { InitCommandData, PackageManager } from "../types.ts";
5+
import { replace } from "../utils.ts";
66

77
/**
88
* Loads the federation configuration file content from template.
@@ -48,7 +48,7 @@ export const loadLogging = async ({ projectName }: InitCommandData) =>
4848
* @param param0 - Destructured object containing kv and mq configurations
4949
* @returns A multi-line string containing all necessary import statements
5050
*/
51-
export const getImports = ({ kv, mq }: InitCommandData) =>
51+
export const getImports = ({ kv, mq, packageManager, env }: InitCommandData) =>
5252
pipe(
5353
toMerged(kv.imports, mq.imports),
5454
entries,
@@ -62,6 +62,10 @@ export const getImports = ({ kv, mq }: InitCommandData) =>
6262
} from ${JSON.stringify(module)};`
6363
),
6464
join("\n"),
65+
(imports) =>
66+
packageManager === "deno" && Object.keys(env).length > 0
67+
? `import "@std/dotenv/load";\n${imports}`
68+
: imports,
6569
);
6670

6771
/**

packages/init/src/templates/bare-bones/main/deno.ts.tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import "@std/dotenv/load";
21
import { behindProxy } from "@hongminhee/x-forwarded-fetch";
32
import federation from "./federation.ts";
43
import "./logging.ts";

packages/init/src/templates/hono/index/deno.ts.tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { behindProxy } from "@hongminhee/x-forwarded-fetch";
2-
import "@std/dotenv/load";
32
import app from "./app.tsx";
43
import "./logging.ts";
54

packages/init/src/webframeworks/hono.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const honoDescription: WebFrameworkDescription = {
1515
dependencies: pm === "deno"
1616
? {
1717
...defaultDenoDependencies,
18-
"@std/dotenv": deps["@std/dotenv"],
1918
"@hono/hono": deps["@hono/hono"],
2019
"@hongminhee/x-forwarded-fetch": deps["@hongminhee/x-forwarded-fetch"],
2120
"@fedify/hono": PACKAGE_VERSION,

0 commit comments

Comments
 (0)