Skip to content

Commit 103ec60

Browse files
authored
fix(task): consider config sys in task runner (#3518)
this commit updates the generation of a `ValidatedConfig` entity to take a `sys` property on a user provided `Config` in the context of `runTask`. when generating the validated configuration, the `sys` entity takes precedence over all other configurations, with the belief that in the event argument was provided, it is the intent of the user to use it. in the event `sys` is not expressly provided, use the one on the provided configuration entity. this is useful in the case that a user used stencil's external facing apis in a flow that: 1. loads a configuration 2. validates that configuration 3. uses that configuration when calling `runTask` directly this commit fixes a bug introduced making `sys` a required field on `ValidatedConfig`, where `config.sys` was not properly accounted for. the bug was initially introduced in a6a9171 (#3491)
1 parent 8d2cbea commit 103ec60

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cli/run.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const runTask = async (
133133
flags: createConfigFlags(config.flags ?? { task }),
134134
logger,
135135
outputTargets: config.outputTargets ?? [],
136-
sys: sys ?? coreCompiler.createSystem({ logger }),
136+
sys: sys ?? config.sys ?? coreCompiler.createSystem({ logger }),
137137
testing: config.testing ?? {},
138138
};
139139

src/cli/test/run.spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,38 @@ describe('run', () => {
177177
taskTestSpy.mockRestore();
178178
});
179179

180+
describe('default configuration', () => {
181+
describe('sys property', () => {
182+
it('uses the sys argument if one is provided', async () => {
183+
// remove the `CompilerSystem` on the config, just to be sure we don't accidentally use it
184+
unvalidatedConfig.sys = undefined;
185+
186+
validatedConfig = mockValidatedConfig({ sys });
187+
188+
await runTask(coreCompiler, unvalidatedConfig, 'build', sys);
189+
190+
// first validate there was one call, and that call had two arguments
191+
expect(taskBuildSpy).toHaveBeenCalledTimes(1);
192+
expect(taskBuildSpy).toHaveBeenCalledWith(coreCompiler, validatedConfig);
193+
194+
const compilerSystemUsed: d.CompilerSystem = taskBuildSpy.mock.calls[0][1].sys;
195+
expect(compilerSystemUsed).toBe(sys);
196+
});
197+
198+
it('uses the sys field on the config if no sys argument is provided', async () => {
199+
// if the optional `sys` argument isn't provided, attempt to default to the one on the config
200+
await runTask(coreCompiler, unvalidatedConfig, 'build');
201+
202+
// first validate there was one call, and that call had two arguments
203+
expect(taskBuildSpy).toHaveBeenCalledTimes(1);
204+
expect(taskBuildSpy).toHaveBeenCalledWith(coreCompiler, validatedConfig);
205+
206+
const compilerSystemUsed: d.CompilerSystem = taskBuildSpy.mock.calls[0][1].sys;
207+
expect(compilerSystemUsed).toBe(unvalidatedConfig.sys);
208+
});
209+
});
210+
});
211+
180212
it('calls the build task', async () => {
181213
await runTask(coreCompiler, unvalidatedConfig, 'build', sys);
182214

0 commit comments

Comments
 (0)