Skip to content

Commit ebbce70

Browse files
authored
Allow extensions to populate project config without workflow_settings. (#2095)
Some extensions might use different configuration files, this will allow them to proceed when workflow_settings.yaml is missing.
1 parent 5334037 commit ebbce70

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

core/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export function main(coreExecutionRequest: Uint8Array | string): Uint8Array | st
3838
}
3939
const compileRequest = request.compile;
4040

41+
// Allow extensions to populate settings by themselves.
42+
const failIfMissing = !compileRequest?.compileConfig?.extension?.compilationMode;
4143
// Read the workflow settings from the root of the project.
42-
let projectConfig = readWorkflowSettings();
44+
let projectConfig = readWorkflowSettings(failIfMissing);
4345

4446
// Merge in project config overrides.
4547
const projectConfigOverride = compileRequest.compileConfig.projectConfigOverride ?? {};

core/main_test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,44 @@ publish("name", {type: "${fromType}", schema: "schemaOverride"}).type("${toType}
19631963
expect(result.compile.compiledGraph.targets?.map(t => t.name)).deep.equals(["sample-action"]);
19641964
});
19651965

1966+
test("works in application mode without workflow settings", () => {
1967+
const projectDir = tmpDirFixture.createNewTmpDir();
1968+
fs.mkdirSync(path.join(projectDir, "definitions"));
1969+
fs.writeFileSync(path.join(projectDir, "definitions/e.sqlx"), `config {type: "view"}`);
1970+
fs.writeFileSync(path.join(projectDir, "definitions/file.sqlx"), "${resolve('e')}");
1971+
1972+
const request = coreExecutionRequestFromPath(projectDir);
1973+
request.compile.compileConfig.extension = {
1974+
name: "@dataform/sample-extension",
1975+
compilationMode: dataform.ExtensionCompilationMode.APPLICATION_CODE
1976+
};
1977+
1978+
const result = runMainInVm(request);
1979+
1980+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
1981+
expect(result.compile.compiledGraph.targets?.map(t => t.name)).deep.equals([
1982+
"sample-action"
1983+
]);
1984+
});
1985+
1986+
test("works in prologue mode without workflow settings", () => {
1987+
const projectDir = tmpDirFixture.createNewTmpDir();
1988+
fs.mkdirSync(path.join(projectDir, "definitions"));
1989+
fs.writeFileSync(path.join(projectDir, "definitions/e.sqlx"), `config {type: "view"}`);
1990+
fs.writeFileSync(path.join(projectDir, "definitions/file.sqlx"), "${resolve('e')}");
1991+
1992+
const request = coreExecutionRequestFromPath(projectDir);
1993+
request.compile.compileConfig.extension = {
1994+
name: "@dataform/sample-extension",
1995+
compilationMode: dataform.ExtensionCompilationMode.PROLOGUE,
1996+
};
1997+
1998+
const result = runMainInVm(request);
1999+
2000+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
2001+
expect(result.compile.compiledGraph.targets?.map(t => t.name)).deep.equals(["sample-action", "e", "file"]);
2002+
});
2003+
19662004
test("catches extension import exceptions", () => {
19672005
const projectDir = setUpProjectWithExtension();
19682006
const request = coreExecutionRequestFromPath(projectDir);

core/workflow_settings.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare var __webpack_require__: any;
99
declare var __non_webpack_require__: any;
1010
const nativeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
1111

12-
export function readWorkflowSettings(): dataform.ProjectConfig {
12+
export function readWorkflowSettings(failIfMissing: boolean = true): dataform.ProjectConfig {
1313
const workflowSettingsYaml = maybeRequire("workflow_settings.yaml");
1414
// `dataform.json` is deprecated; new versions of Dataform Core prefer `workflow_settings.yaml`.
1515
const dataformJson = maybeRequire("dataform.json");
@@ -42,7 +42,10 @@ export function readWorkflowSettings(): dataform.ProjectConfig {
4242
}
4343
}
4444

45-
throw Error("Failed to resolve workflow_settings.yaml");
45+
if (failIfMissing) {
46+
throw Error("Failed to resolve workflow_settings.yaml");
47+
}
48+
return dataform.ProjectConfig.create();
4649
}
4750

4851
function verifyWorkflowSettingsAsJson(workflowSettingsAsJson: object): dataform.WorkflowSettings {

0 commit comments

Comments
 (0)