From c9ce7501dbe3cd809ad6647dfcae767171218806 Mon Sep 17 00:00:00 2001 From: Artur Piotr Izaak Laskowski Date: Wed, 11 Feb 2026 20:17:29 +0100 Subject: [PATCH 1/4] Support both 'yaml' and 'yml' file extensions We can support both formats in Dataform. Native configurations are stored in YAML format, but other configurations eg. from extensions might use YML too. --- core/compilers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/compilers.ts b/core/compilers.ts index 69c8f7704..a760153ff 100644 --- a/core/compilers.ts +++ b/core/compilers.ts @@ -28,7 +28,7 @@ export function compile(code: string, path: string): string { if (Path.fileExtension(path) === "sqlx") { return compileSqlx(SyntaxTreeNode.create(code), path); } - if (Path.fileExtension(path) === "yaml") { + if (Path.fileExtension(path) === "yaml" || Path.fileExtension(path) === "yml") { try { const yamlAsJson = loadYaml(code); return `exports.asJson = ${JSON.stringify(yamlAsJson)}`; From 7ad296a707a4881008dc8810e4de7b98f4d5c041 Mon Sep 17 00:00:00 2001 From: Artur Piotr Izaak Laskowski Date: Wed, 11 Feb 2026 20:17:29 +0100 Subject: [PATCH 2/4] Support both 'yaml' and 'yml' file extensions We can support both formats in Dataform. Native configurations are stored in YAML format, but other configurations eg. from extensions might use YML too. --- core/BUILD | 1 + core/compilers_test.ts | 95 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 core/compilers_test.ts diff --git a/core/BUILD b/core/BUILD index 3655099e1..b46881a57 100644 --- a/core/BUILD +++ b/core/BUILD @@ -65,6 +65,7 @@ ts_test_suite( srcs = [ "main_test.ts", "utils_test.ts", + "compilers_test.ts", "actions/assertion_test.ts", "actions/data_preparation_test.ts", "actions/declaration_test.ts", diff --git a/core/compilers_test.ts b/core/compilers_test.ts new file mode 100644 index 000000000..dcb2e0584 --- /dev/null +++ b/core/compilers_test.ts @@ -0,0 +1,95 @@ +import { expect } from "chai"; +import { suite, test } from "df/testing"; +import { compile } from "df/core/compilers"; + +suite("core/compilers", () => { + suite("compile", () => { + test("compiles sqlx to js", () => { + const code = `config { type: "table" } select 1`; + const path = "definitions/foo.sqlx"; + const result = compile(code, path); + expect(result).to.include("dataform.sqlxAction"); + expect(result).to.include("name: \"foo\""); + expect(result).to.include("{ type: \"table\" }"); + // The sqlx compiler will format the query. + expect(result).to.include("select 1"); + }); + + test("compiles yml to js", () => { + const code = "foo: bar"; + const path = "definitions/foo.yml"; + const result = compile(code, path); + expect(result).to.equal(`exports.asJson = {"foo":"bar"}`); + }); + + test("compiles yaml to js", () => { + const code = ` +- item1 +- item2`; + const path = "definitions/foo.yaml"; + const result = compile(code, path); + expect(result).to.equal(`exports.asJson = ["item1","item2"]`); + }); + + test("throws error for invalid yaml", () => { + const code = "foo: : bar"; + const path = "definitions/foo.yaml"; + expect(() => compile(code, path)).to.throw(`${path} is not a valid YAML file: YAMLException: bad indentation of a mapping entry (1:6)`); + }); + + test("compiles ipynb to js", () => { + const code = '{"cells": []}'; + const path = "definitions/foo.ipynb"; + const result = compile(code, path); + expect(result).to.equal('exports.asJson = {"cells":[]}'); + }); + + test("throws error for invalid ipynb json", () => { + const code = '{"cells": [}'; + const path = "definitions/foo.ipynb"; + expect(() => compile(code, path)).to.throw(`Error parsing ${path} as JSON:`); + }); + + test("compiles sql to js", () => { + const code = "select 1"; + const path = "definitions/foo.sql"; + const result = compile(code, path); + expect(result).to.equal("exports.query = `select 1`;"); + }); + + test("escapes backticks in sql", () => { + const code = "select `a` from `b`"; + const path = "definitions/foo.sql"; + const result = compile(code, path); + expect(result).to.equal("exports.query = `select \\`a\\` from \\`b\\``;"); + }); + + test("escapes backslashes in sql", () => { + const code = "select ''"; + const path = "definitions/foo.sql"; + const result = compile(code, path); + expect(result).to.equal("exports.query = `select ''`;"); + }); + + test("escapes template literals in sql", () => { + const code = "select ${foo}"; + const path = "definitions/foo.sql"; + const result = compile(code, path); + expect(result).to.equal("exports.query = `select \\${foo}`;"); + }); + + test("returns raw code for other file types", () => { + const code = "const a = 1;"; + const path = "definitions/foo.js"; + const result = compile(code, path); + expect(result).to.equal(code); + }); + + test("returns raw code for files with no extension", () => { + const code = "const a = 1;"; + const path = "definitions/foo"; + const result = compile(code, path); + expect(result).to.equal(code); + }); + }); +}); \ No newline at end of file From 46705e4087c1c56319f8dc2ccbd6bb8513dcf819 Mon Sep 17 00:00:00 2001 From: Artur Piotr Izaak Laskowski Date: Wed, 11 Feb 2026 20:17:29 +0100 Subject: [PATCH 3/4] Support both 'yaml' and 'yml' file extensions We can support both formats in Dataform. Native configurations are stored in YAML format, but other configurations eg. from extensions might use YML too. --- cli/vm/compile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/vm/compile.ts b/cli/vm/compile.ts index e42a83aaa..f5e8cfc1e 100644 --- a/cli/vm/compile.ts +++ b/cli/vm/compile.ts @@ -48,7 +48,7 @@ export function compile(compileConfig: dataform.ICompileConfig) { resolve: (moduleName, parentDirName) => path.join(parentDirName, path.relative(parentDirName, compileConfig.projectDir), moduleName) }, - sourceExtensions: ["js", "sql", "sqlx", "yaml"], + sourceExtensions: ["js", "sql", "sqlx", "yaml", "yml"], compiler }); From 53b22b8588ad86f5f3e7c6ab31d7edbba3fd5c15 Mon Sep 17 00:00:00 2001 From: Artur Piotr Izaak Laskowski Date: Fri, 13 Feb 2026 01:17:50 +0100 Subject: [PATCH 4/4] Reorganize imports in compilers_test.ts --- core/compilers_test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/compilers_test.ts b/core/compilers_test.ts index dcb2e0584..f5410e557 100644 --- a/core/compilers_test.ts +++ b/core/compilers_test.ts @@ -1,6 +1,7 @@ import { expect } from "chai"; -import { suite, test } from "df/testing"; + import { compile } from "df/core/compilers"; +import { suite, test } from "df/testing"; suite("core/compilers", () => { suite("compile", () => { @@ -92,4 +93,4 @@ suite("core/compilers", () => { expect(result).to.equal(code); }); }); -}); \ No newline at end of file +});