Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto set name and env on runtimeConfig #152

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions standalone/standalone/src/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface RunnerOptions {
*/
innerObjects?: Record<string, object>;
env?: string;
name?: string;
innerObjectHandlers?: Record<string, InnerObject[]>;
}

Expand All @@ -41,6 +42,7 @@ export class Runner {
readonly moduleReferences: readonly ModuleReference[];
readonly moduleConfigs: Record<string, ModuleConfigHolder>;
readonly env?: string;
readonly name?: string;
private loadUnitLoader: EggModuleLoader;
private runnerProto: EggPrototype;
private configSourceEggPrototypeHook: ConfigSourceLoadUnitHook;
Expand All @@ -59,6 +61,7 @@ export class Runner {
constructor(cwd: string, options?: RunnerOptions) {
this.cwd = cwd;
this.env = options?.env;
this.name = options?.name;
this.moduleReferences = ModuleConfigUtil.readModuleReference(this.cwd);
this.moduleConfigs = {};
this.innerObjects = {
Expand All @@ -70,6 +73,8 @@ export class Runner {

const runtimeConfig: Partial<RuntimeConfig> = {
baseDir: this.cwd,
name: this.name,
env: this.env,
};
// Inject runtimeConfig
this.innerObjects.runtimeConfig = [{
Expand Down
18 changes: 17 additions & 1 deletion standalone/standalone/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,23 @@ describe('test/index.test.ts', () => {
describe('runner with runtimeConfig', () => {
it('should work', async () => {
const msg = await main(path.join(__dirname, './fixtures/runtime-config'));
assert.deepEqual(msg, { baseDir: path.join(__dirname, './fixtures/runtime-config') });
assert.deepEqual(msg, {
baseDir: path.join(__dirname, './fixtures/runtime-config'),
env: undefined,
name: undefined,
});
});

it('should auto set name and env', async () => {
const msg = await main(path.join(__dirname, './fixtures/runtime-config'), {
name: 'foo',
env: 'unittest',
});
assert.deepEqual(msg, {
baseDir: path.join(__dirname, './fixtures/runtime-config'),
name: 'foo',
env: 'unittest',
});
});
});

Expand Down
Loading