@codapult/cli 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/setup.d.ts +2 -2
- package/dist/commands/setup.js +3 -3
- package/dist/mcp/tools/db.js +7 -4
- package/dist/mcp/tools/db.test.js +15 -0
- package/dist/mcp/tools/env.js +20 -5
- package/dist/mcp/tools/env.test.js +24 -2
- package/dist/mcp/tools/plugins.js +8 -5
- package/dist/mcp/tools/project.js +12 -9
- package/dist/mcp/tools/project.test.js +31 -1
- package/dist/mcp/tools/schemas.d.ts +5 -0
- package/dist/mcp/tools/schemas.js +5 -0
- package/dist/utils/project-env.d.ts +2 -1
- package/dist/utils/project-env.js +4 -1
- package/dist/utils/project-env.test.js +9 -4
- package/package.json +1 -1
package/dist/commands/setup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProjectEnvOptions } from '../utils/project-env.js';
|
|
2
|
+
interface SetupOptions extends Pick<ProjectEnvOptions, 'envFile'> {
|
|
2
3
|
preset?: string;
|
|
3
|
-
noEnvFile?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare function setupCommand(options: SetupOptions): Promise<void>;
|
|
6
6
|
export {};
|
package/dist/commands/setup.js
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node
|
|
|
2
2
|
import { resolve, relative, join } from 'node:path';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
import { findProjectRoot } from '../utils/project.js';
|
|
5
|
-
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from '../utils/project-env.js';
|
|
5
|
+
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, } from '../utils/project-env.js';
|
|
6
6
|
import { heading, success, fail, info, dim } from '../utils/ui.js';
|
|
7
7
|
const rl = () => createInterface({ input: process.stdin, output: process.stdout });
|
|
8
8
|
function ask(iface, question, defaultValue) {
|
|
@@ -609,7 +609,7 @@ export async function setupCommand(options) {
|
|
|
609
609
|
config = await interactiveSetup();
|
|
610
610
|
}
|
|
611
611
|
heading('Generating configuration');
|
|
612
|
-
if (options.
|
|
612
|
+
if (options.envFile === false) {
|
|
613
613
|
dim(`Skipped ${ENV_FILE_NAME} generation`);
|
|
614
614
|
}
|
|
615
615
|
else {
|
|
@@ -624,7 +624,7 @@ export async function setupCommand(options) {
|
|
|
624
624
|
info('Preset applied. Proceeding to build.');
|
|
625
625
|
}
|
|
626
626
|
else {
|
|
627
|
-
if (options.
|
|
627
|
+
if (options.envFile === false) {
|
|
628
628
|
printProcessEnvNextSteps();
|
|
629
629
|
}
|
|
630
630
|
else {
|
package/dist/mcp/tools/db.js
CHANGED
|
@@ -2,7 +2,8 @@ import { existsSync, readdirSync } from 'node:fs';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { findProjectRoot, readProjectFile } from '../../utils/project.js';
|
|
5
|
-
import { loadProjectEnv } from '../../utils/project-env.js';
|
|
5
|
+
import { getProjectEnvOptions, loadProjectEnv } from '../../utils/project-env.js';
|
|
6
|
+
import { envSourceSchema } from './schemas.js';
|
|
6
7
|
function getRoot() {
|
|
7
8
|
const root = findProjectRoot();
|
|
8
9
|
if (!root)
|
|
@@ -102,10 +103,12 @@ export function registerDbTools(server) {
|
|
|
102
103
|
server.registerTool('codapult_db_status', {
|
|
103
104
|
title: 'Database Status',
|
|
104
105
|
description: 'Get database provider, table count, and migration count',
|
|
105
|
-
inputSchema: {
|
|
106
|
-
|
|
106
|
+
inputSchema: {
|
|
107
|
+
env_source: envSourceSchema.optional(),
|
|
108
|
+
},
|
|
109
|
+
}, ({ env_source }) => {
|
|
107
110
|
const root = getRoot();
|
|
108
|
-
const envContent = loadProjectEnv(root).content;
|
|
111
|
+
const envContent = loadProjectEnv(root, getProjectEnvOptions(env_source)).content;
|
|
109
112
|
const providerMatch = /^DB_PROVIDER\s*=\s*"?(\w+)"?/m.exec(envContent);
|
|
110
113
|
const provider = providerMatch?.[1] ?? 'turso';
|
|
111
114
|
const schemaContent = readProjectFile(root, 'src/lib/db/schema.ts') ?? '';
|
|
@@ -150,5 +150,20 @@ export const user = sqliteTable('user', {
|
|
|
150
150
|
const parsed = JSON.parse(result.content[0].text);
|
|
151
151
|
expect(parsed.provider).toBe('turso');
|
|
152
152
|
});
|
|
153
|
+
it('can read provider from process env', () => {
|
|
154
|
+
const server = createMockServer();
|
|
155
|
+
registerDbTools(server);
|
|
156
|
+
vi.stubEnv('DB_PROVIDER', 'postgres');
|
|
157
|
+
mockedReadProject.mockImplementation((_root, path) => {
|
|
158
|
+
if (path === 'src/lib/db/schema.ts')
|
|
159
|
+
return '';
|
|
160
|
+
return null;
|
|
161
|
+
});
|
|
162
|
+
mockedExists.mockReturnValue(false);
|
|
163
|
+
const handler = server.tools.find((t) => t.name === 'codapult_db_status').handler;
|
|
164
|
+
const result = handler({ env_source: 'process' });
|
|
165
|
+
const parsed = JSON.parse(result.content[0].text);
|
|
166
|
+
expect(parsed.provider).toBe('postgres');
|
|
167
|
+
});
|
|
153
168
|
});
|
|
154
169
|
});
|
package/dist/mcp/tools/env.js
CHANGED
|
@@ -2,7 +2,8 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { findProjectRoot, readProjectFile } from '../../utils/project.js';
|
|
5
|
-
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from '../../utils/project-env.js';
|
|
5
|
+
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME, getProjectEnvOptions, loadProjectEnv, } from '../../utils/project-env.js';
|
|
6
|
+
import { envSourceSchema } from './schemas.js';
|
|
6
7
|
function getRoot() {
|
|
7
8
|
const root = findProjectRoot();
|
|
8
9
|
if (!root)
|
|
@@ -68,11 +69,13 @@ export function registerEnvTools(server) {
|
|
|
68
69
|
.boolean()
|
|
69
70
|
.default(false)
|
|
70
71
|
.describe('When true, show full values for sensitive keys (use with caution)'),
|
|
72
|
+
env_source: envSourceSchema.optional(),
|
|
71
73
|
},
|
|
72
|
-
}, ({ show_secrets }) => {
|
|
74
|
+
}, ({ show_secrets, env_source }) => {
|
|
73
75
|
const root = getRoot();
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
+
const env = loadProjectEnv(root, getProjectEnvOptions(env_source));
|
|
77
|
+
const localContent = env.content;
|
|
78
|
+
if (!localContent && env.source === 'file')
|
|
76
79
|
return {
|
|
77
80
|
content: [{ type: 'text', text: `${ENV_FILE_NAME} not found` }],
|
|
78
81
|
isError: true,
|
|
@@ -107,8 +110,9 @@ export function registerEnvTools(server) {
|
|
|
107
110
|
inputSchema: {
|
|
108
111
|
key: z.string().describe('Variable name (e.g. "STRIPE_SECRET_KEY")'),
|
|
109
112
|
value: z.string().describe('Variable value'),
|
|
113
|
+
env_source: envSourceSchema.optional(),
|
|
110
114
|
},
|
|
111
|
-
}, ({ key, value }) => {
|
|
115
|
+
}, ({ key, value, env_source }) => {
|
|
112
116
|
if (!ENV_KEY_REGEX.test(key)) {
|
|
113
117
|
return {
|
|
114
118
|
content: [
|
|
@@ -121,6 +125,17 @@ export function registerEnvTools(server) {
|
|
|
121
125
|
};
|
|
122
126
|
}
|
|
123
127
|
const root = getRoot();
|
|
128
|
+
if (env_source === 'process') {
|
|
129
|
+
return {
|
|
130
|
+
content: [
|
|
131
|
+
{
|
|
132
|
+
type: 'text',
|
|
133
|
+
text: 'Updating process.env via MCP is not supported; use env_source="file"',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
isError: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
124
139
|
const envPath = resolve(root, ENV_FILE_NAME);
|
|
125
140
|
if (!existsSync(envPath)) {
|
|
126
141
|
return {
|
|
@@ -75,9 +75,9 @@ DATABASE_URL=sqlite://local.db
|
|
|
75
75
|
registerEnvTools(server);
|
|
76
76
|
const envLocal = `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=your-key-here\n`;
|
|
77
77
|
const envExample = `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=\nDATABASE_URL=\n`;
|
|
78
|
+
mockedExists.mockReturnValue(true);
|
|
79
|
+
mockedRead.mockReturnValue(envLocal);
|
|
78
80
|
mockedReadProject.mockImplementation((_root, path) => {
|
|
79
|
-
if (path === ENV_FILE_NAME)
|
|
80
|
-
return envLocal;
|
|
81
81
|
if (path === ENV_EXAMPLE_FILE_NAME)
|
|
82
82
|
return envExample;
|
|
83
83
|
return null;
|
|
@@ -88,6 +88,21 @@ DATABASE_URL=sqlite://local.db
|
|
|
88
88
|
expect(parsed.missing).toContain('DATABASE_URL');
|
|
89
89
|
expect(parsed.unconfigured).toContain('STRIPE_SECRET_KEY');
|
|
90
90
|
});
|
|
91
|
+
it('can read from process env', () => {
|
|
92
|
+
const server = createMockServer();
|
|
93
|
+
registerEnvTools(server);
|
|
94
|
+
vi.stubEnv('AUTH_PROVIDER', 'better-auth');
|
|
95
|
+
vi.stubEnv('STRIPE_SECRET_KEY', 'sk_live_123');
|
|
96
|
+
mockedReadProject.mockImplementation((_root, path) => {
|
|
97
|
+
if (path === ENV_EXAMPLE_FILE_NAME)
|
|
98
|
+
return `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=\nDATABASE_URL=\n`;
|
|
99
|
+
return null;
|
|
100
|
+
});
|
|
101
|
+
const handler = server.tools.find((t) => t.name === 'codapult_env_read').handler;
|
|
102
|
+
const result = handler({ env_source: 'process' });
|
|
103
|
+
const parsed = JSON.parse(result.content[0].text);
|
|
104
|
+
expect(parsed.variables.some((v) => v.key === 'AUTH_PROVIDER')).toBe(true);
|
|
105
|
+
});
|
|
91
106
|
it(`returns error when ${ENV_FILE_NAME} not found`, () => {
|
|
92
107
|
const server = createMockServer();
|
|
93
108
|
registerEnvTools(server);
|
|
@@ -128,5 +143,12 @@ DATABASE_URL=sqlite://local.db
|
|
|
128
143
|
const result = handler({ key: 'X', value: 'Y' });
|
|
129
144
|
expect(result.isError).toBe(true);
|
|
130
145
|
});
|
|
146
|
+
it('returns error for process env updates', () => {
|
|
147
|
+
const server = createMockServer();
|
|
148
|
+
registerEnvTools(server);
|
|
149
|
+
const handler = server.tools.find((t) => t.name === 'codapult_env_update').handler;
|
|
150
|
+
const result = handler({ key: 'X', value: 'Y', env_source: 'process' });
|
|
151
|
+
expect(result.isError).toBe(true);
|
|
152
|
+
});
|
|
131
153
|
});
|
|
132
154
|
});
|
|
@@ -2,9 +2,10 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { findProjectRoot } from '../../utils/project.js';
|
|
5
|
-
import { ENV_FILE_NAME
|
|
5
|
+
import { ENV_FILE_NAME } from '../../utils/project-env.js';
|
|
6
6
|
import { resolveManifest } from '../../utils/manifest.js';
|
|
7
7
|
import { patchSchemaImports, patchSchemaTables, patchDbReExports, patchNextConfig, createPluginRegistration, patchPages, findPageConflicts, patchEnvFile, patchPackageJson, } from '../../utils/patchers.js';
|
|
8
|
+
import { envSourceSchema } from './schemas.js';
|
|
8
9
|
function getRoot() {
|
|
9
10
|
const root = findProjectRoot();
|
|
10
11
|
if (!root)
|
|
@@ -43,8 +44,9 @@ export function registerPluginTools(server) {
|
|
|
43
44
|
description: 'Install a Codapult plugin by name. Patches schema, config, pages, and env automatically.',
|
|
44
45
|
inputSchema: {
|
|
45
46
|
name: z.string().describe('Plugin name (e.g. "ai-kit", "video-player")'),
|
|
47
|
+
env_source: envSourceSchema.optional(),
|
|
46
48
|
},
|
|
47
|
-
}, ({ name }) => {
|
|
49
|
+
}, ({ name, env_source }) => {
|
|
48
50
|
const root = getRoot();
|
|
49
51
|
const result = resolveManifest(root, name);
|
|
50
52
|
if (!result) {
|
|
@@ -89,7 +91,7 @@ export function registerPluginTools(server) {
|
|
|
89
91
|
createPluginRegistration(root, manifest.name, manifest.package, 'add');
|
|
90
92
|
steps.push('Plugin registered');
|
|
91
93
|
if (manifest.install.env && Object.keys(manifest.install.env).length > 0) {
|
|
92
|
-
if (
|
|
94
|
+
if (env_source === 'process') {
|
|
93
95
|
steps.push('Project uses process.env; add plugin env vars outside the CLI');
|
|
94
96
|
}
|
|
95
97
|
else {
|
|
@@ -115,8 +117,9 @@ export function registerPluginTools(server) {
|
|
|
115
117
|
description: 'Uninstall a Codapult plugin by name. Reverts all patches.',
|
|
116
118
|
inputSchema: {
|
|
117
119
|
name: z.string().describe('Plugin name to remove'),
|
|
120
|
+
env_source: envSourceSchema.optional(),
|
|
118
121
|
},
|
|
119
|
-
}, ({ name }) => {
|
|
122
|
+
}, ({ name, env_source }) => {
|
|
120
123
|
const root = getRoot();
|
|
121
124
|
const result = resolveManifest(root, name);
|
|
122
125
|
const manifest = result?.manifest ?? {
|
|
@@ -152,7 +155,7 @@ export function registerPluginTools(server) {
|
|
|
152
155
|
steps.push('next.config.ts reverted');
|
|
153
156
|
}
|
|
154
157
|
if (manifest.install.env && Object.keys(manifest.install.env).length > 0) {
|
|
155
|
-
if (
|
|
158
|
+
if (env_source === 'process') {
|
|
156
159
|
steps.push(`Project uses process.env; no ${ENV_FILE_NAME} env vars were removed`);
|
|
157
160
|
}
|
|
158
161
|
else {
|
|
@@ -3,8 +3,9 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { findProjectRoot, readProjectFile } from '../../utils/project.js';
|
|
6
|
-
import { ENV_FILE_NAME,
|
|
6
|
+
import { ENV_FILE_NAME, getProjectEnvOptions, loadProjectEnv } from '../../utils/project-env.js';
|
|
7
7
|
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, } from '../../utils/env-config.js';
|
|
8
|
+
import { envSourceSchema } from './schemas.js';
|
|
8
9
|
function getRoot() {
|
|
9
10
|
const root = findProjectRoot();
|
|
10
11
|
if (!root)
|
|
@@ -15,11 +16,13 @@ export function registerProjectTools(server) {
|
|
|
15
16
|
server.registerTool('codapult_project_status', {
|
|
16
17
|
title: 'Project Status',
|
|
17
18
|
description: 'Get Codapult project status: variant, adapters, installed plugins, enabled features, git status',
|
|
18
|
-
inputSchema: {
|
|
19
|
-
|
|
19
|
+
inputSchema: {
|
|
20
|
+
env_source: envSourceSchema.optional(),
|
|
21
|
+
},
|
|
22
|
+
}, ({ env_source }) => {
|
|
20
23
|
const root = getRoot();
|
|
21
24
|
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
|
|
22
|
-
const envContent = loadProjectEnv(root).content;
|
|
25
|
+
const envContent = loadProjectEnv(root, getProjectEnvOptions(env_source)).content;
|
|
23
26
|
const pluginsDir = resolve(root, 'src/plugins');
|
|
24
27
|
const plugins = existsSync(pluginsDir)
|
|
25
28
|
? readdirSync(pluginsDir)
|
|
@@ -59,7 +62,6 @@ export function registerProjectTools(server) {
|
|
|
59
62
|
server.registerTool('codapult_project_config', {
|
|
60
63
|
title: 'Project Config',
|
|
61
64
|
description: 'Read the app configuration from src/config/app.ts (brand, auth, features)',
|
|
62
|
-
inputSchema: {},
|
|
63
65
|
}, () => {
|
|
64
66
|
const root = getRoot();
|
|
65
67
|
const content = readProjectFile(root, 'src/config/app.ts') ?? 'Config file not found';
|
|
@@ -103,8 +105,10 @@ export function registerProjectTools(server) {
|
|
|
103
105
|
server.registerTool('codapult_doctor', {
|
|
104
106
|
title: 'Doctor',
|
|
105
107
|
description: 'Run project health checks: file structure, env vars, dependencies, TypeScript, git',
|
|
106
|
-
inputSchema: {
|
|
107
|
-
|
|
108
|
+
inputSchema: {
|
|
109
|
+
env_source: envSourceSchema.optional(),
|
|
110
|
+
},
|
|
111
|
+
}, ({ env_source }) => {
|
|
108
112
|
const root = getRoot();
|
|
109
113
|
const checks = [];
|
|
110
114
|
const requiredFiles = [
|
|
@@ -122,8 +126,7 @@ export function registerProjectTools(server) {
|
|
|
122
126
|
detail: existsSync(resolve(root, f)) ? 'exists' : 'missing',
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
|
-
|
|
126
|
-
if (envSource === 'process') {
|
|
129
|
+
if (env_source === 'process') {
|
|
127
130
|
checks.push({
|
|
128
131
|
name: 'Environment source',
|
|
129
132
|
status: 'ok',
|
|
@@ -8,7 +8,8 @@ vi.mock('../../utils/project.js', () => ({
|
|
|
8
8
|
}));
|
|
9
9
|
vi.mock('../../utils/project-env.js', () => ({
|
|
10
10
|
ENV_FILE_NAME: '.env.local',
|
|
11
|
-
|
|
11
|
+
getProjectEnvOptions: vi.fn((envSource) => ({ envFile: envSource !== 'process' })),
|
|
12
|
+
getProjectEnvSource: vi.fn((options) => options?.envFile === false ? 'process' : 'file'),
|
|
12
13
|
loadProjectEnv: vi.fn(),
|
|
13
14
|
}));
|
|
14
15
|
const { existsSync, readFileSync, readdirSync } = await import('node:fs');
|
|
@@ -96,6 +97,24 @@ describe('registerProjectTools', () => {
|
|
|
96
97
|
expect(parsed.git.branch).toBe('main');
|
|
97
98
|
expect(parsed.git.dirty).toBe(false);
|
|
98
99
|
});
|
|
100
|
+
it('uses process env when requested', () => {
|
|
101
|
+
const server = createMockServer();
|
|
102
|
+
registerProjectTools(server);
|
|
103
|
+
mockedRead.mockReturnValue(JSON.stringify({ name: 'codapult', version: '1.0.0' }));
|
|
104
|
+
mockedLoadProjectEnv.mockReturnValue({
|
|
105
|
+
source: 'process',
|
|
106
|
+
filePath: `/project/${ENV_FILE_NAME}`,
|
|
107
|
+
fileExists: false,
|
|
108
|
+
content: 'AUTH_PROVIDER=none\nENABLE_BLOG=false',
|
|
109
|
+
});
|
|
110
|
+
mockedExists.mockReturnValue(true);
|
|
111
|
+
mockedReaddir.mockReturnValue([]);
|
|
112
|
+
const handler = server.tools.find((t) => t.name === 'codapult_project_status').handler;
|
|
113
|
+
const result = handler({ env_source: 'process' });
|
|
114
|
+
const parsed = JSON.parse(result.content[0].text);
|
|
115
|
+
expect(parsed.adapters.auth).toBe('none');
|
|
116
|
+
expect(mockedLoadProjectEnv).toHaveBeenCalledWith('/project', { envFile: false });
|
|
117
|
+
});
|
|
99
118
|
});
|
|
100
119
|
describe('codapult_project_config', () => {
|
|
101
120
|
it('returns app.ts content', () => {
|
|
@@ -142,5 +161,16 @@ describe('registerProjectTools', () => {
|
|
|
142
161
|
const failedChecks = parsed.filter((c) => c.status === 'fail');
|
|
143
162
|
expect(failedChecks.length).toBeGreaterThan(0);
|
|
144
163
|
});
|
|
164
|
+
it('reports process env source when requested', () => {
|
|
165
|
+
const server = createMockServer();
|
|
166
|
+
registerProjectTools(server);
|
|
167
|
+
mockedExists.mockReturnValue(true);
|
|
168
|
+
mockedExec.mockReturnValue(Buffer.from(''));
|
|
169
|
+
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
170
|
+
const result = handler({ env_source: 'process' });
|
|
171
|
+
const parsed = JSON.parse(result.content[0].text);
|
|
172
|
+
const envCheck = parsed.find((c) => c.name === 'Environment source');
|
|
173
|
+
expect(envCheck?.detail).toBe('process.env');
|
|
174
|
+
});
|
|
145
175
|
});
|
|
146
176
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ProjectEnvSource = 'file' | 'process';
|
|
2
2
|
export interface ProjectEnvOptions {
|
|
3
|
-
|
|
3
|
+
envFile?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export interface LoadedProjectEnv {
|
|
6
6
|
source: ProjectEnvSource;
|
|
@@ -12,4 +12,5 @@ export declare const ENV_EXAMPLE_FILE_NAME = ".env.example";
|
|
|
12
12
|
export declare const ENV_FILE_NAME = ".env.local";
|
|
13
13
|
export declare function getProjectEnvFilePath(projectRoot: string): string;
|
|
14
14
|
export declare function getProjectEnvSource(options?: ProjectEnvOptions): ProjectEnvSource;
|
|
15
|
+
export declare function getProjectEnvOptions(envSource?: ProjectEnvSource): ProjectEnvOptions;
|
|
15
16
|
export declare function loadProjectEnv(projectRoot: string, options?: ProjectEnvOptions): LoadedProjectEnv;
|
|
@@ -6,7 +6,10 @@ export function getProjectEnvFilePath(projectRoot) {
|
|
|
6
6
|
return resolve(projectRoot, ENV_FILE_NAME);
|
|
7
7
|
}
|
|
8
8
|
export function getProjectEnvSource(options) {
|
|
9
|
-
return options?.
|
|
9
|
+
return options?.envFile === false ? 'process' : 'file';
|
|
10
|
+
}
|
|
11
|
+
export function getProjectEnvOptions(envSource) {
|
|
12
|
+
return envSource === 'process' ? { envFile: false } : { envFile: true };
|
|
10
13
|
}
|
|
11
14
|
function serializeProcessEnv(env) {
|
|
12
15
|
return Object.entries(env)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { ENV_FILE_NAME, getProjectEnvFilePath, getProjectEnvSource, loadProjectEnv, } from './project-env.js';
|
|
2
|
+
import { ENV_FILE_NAME, getProjectEnvFilePath, getProjectEnvOptions, getProjectEnvSource, loadProjectEnv, } from './project-env.js';
|
|
3
3
|
vi.mock('node:fs');
|
|
4
4
|
const { existsSync, readFileSync } = await import('node:fs');
|
|
5
5
|
const mockedExists = vi.mocked(existsSync);
|
|
@@ -12,8 +12,13 @@ describe('project-env', () => {
|
|
|
12
12
|
it('defaults to file env source', () => {
|
|
13
13
|
expect(getProjectEnvSource()).toBe('file');
|
|
14
14
|
});
|
|
15
|
-
it('uses process env source when
|
|
16
|
-
expect(getProjectEnvSource({
|
|
15
|
+
it('uses process env source when envFile is disabled', () => {
|
|
16
|
+
expect(getProjectEnvSource({ envFile: false })).toBe('process');
|
|
17
|
+
});
|
|
18
|
+
it('maps env source to options', () => {
|
|
19
|
+
expect(getProjectEnvOptions('process')).toEqual({ envFile: false });
|
|
20
|
+
expect(getProjectEnvOptions('file')).toEqual({ envFile: true });
|
|
21
|
+
expect(getProjectEnvOptions()).toEqual({ envFile: true });
|
|
17
22
|
});
|
|
18
23
|
it(`loads env content from ${ENV_FILE_NAME} in file mode`, () => {
|
|
19
24
|
mockedExists.mockImplementation((path) => path === `/project/${ENV_FILE_NAME}`);
|
|
@@ -29,7 +34,7 @@ describe('project-env', () => {
|
|
|
29
34
|
mockedExists.mockReturnValue(false);
|
|
30
35
|
vi.stubEnv('AUTH_PROVIDER', 'better-auth');
|
|
31
36
|
vi.stubEnv('DB_PROVIDER', 'postgres');
|
|
32
|
-
const env = loadProjectEnv('/project', {
|
|
37
|
+
const env = loadProjectEnv('/project', { envFile: false });
|
|
33
38
|
expect(env.source).toBe('process');
|
|
34
39
|
expect(env.filePath).toBe(`/project/${ENV_FILE_NAME}`);
|
|
35
40
|
expect(env.fileExists).toBe(false);
|