From 7d5423cb0cd48ef04f7281e0cbfdebd32d21f28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Mon, 4 Nov 2024 12:25:39 +0100 Subject: [PATCH 1/3] resolve relative paths in sql front-matter table definitions closes #1796 --- src/resolvers.ts | 4 +- test/input/build/sql/index.md | 8 +++ test/input/build/sql/table.csv | 3 ++ .../v1.1.1/wasm_eh/json.duckdb_extension.wasm | 0 .../wasm_mvp/json.duckdb_extension.wasm | 0 .../wasm_eh/parquet.duckdb_extension.wasm | 0 .../wasm_mvp/parquet.duckdb_extension.wasm | 0 .../output/build/sql/_file/table.b9485148.csv | 3 ++ .../@duckdb/duckdb-wasm@1.29.0/cd372fb8.js | 0 .../dist/duckdb-browser-eh.worker.cd372fb8.js | 0 .../duckdb-browser-mvp.worker.cd372fb8.js | 0 .../duckdb-wasm@1.29.0/dist/duckdb-eh.wasm | 0 .../duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm | 0 .../build/sql/_npm/htl@0.3.1/cd372fb8.js | 0 .../sql/_npm/isoformat@0.2.1/cd372fb8.js | 0 .../sql/_observablehq/client.00000001.js | 0 .../sql/_observablehq/runtime.00000002.js | 0 .../sql/_observablehq/stdlib.00000003.js | 0 .../_observablehq/stdlib/duckdb.00000005.js | 0 .../_observablehq/stdlib/inputs.00000006.css | 0 .../_observablehq/stdlib/inputs.00000007.js | 0 .../theme-air,near-midnight.00000004.css | 0 test/output/build/sql/index.html | 53 +++++++++++++++++++ 23 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 test/input/build/sql/index.md create mode 100644 test/input/build/sql/table.csv create mode 100644 test/output/build/sql/_duckdb/json-e3b0c442/v1.1.1/wasm_eh/json.duckdb_extension.wasm create mode 100644 test/output/build/sql/_duckdb/json-e3b0c442/v1.1.1/wasm_mvp/json.duckdb_extension.wasm create mode 100644 test/output/build/sql/_duckdb/parquet-e3b0c442/v1.1.1/wasm_eh/parquet.duckdb_extension.wasm create mode 100644 test/output/build/sql/_duckdb/parquet-e3b0c442/v1.1.1/wasm_mvp/parquet.duckdb_extension.wasm create mode 100644 test/output/build/sql/_file/table.b9485148.csv create mode 100644 test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/cd372fb8.js create mode 100644 test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-eh.worker.cd372fb8.js create mode 100644 test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-mvp.worker.cd372fb8.js create mode 100644 test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-eh.wasm create mode 100644 test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm create mode 100644 test/output/build/sql/_npm/htl@0.3.1/cd372fb8.js create mode 100644 test/output/build/sql/_npm/isoformat@0.2.1/cd372fb8.js create mode 100644 test/output/build/sql/_observablehq/client.00000001.js create mode 100644 test/output/build/sql/_observablehq/runtime.00000002.js create mode 100644 test/output/build/sql/_observablehq/stdlib.00000003.js create mode 100644 test/output/build/sql/_observablehq/stdlib/duckdb.00000005.js create mode 100644 test/output/build/sql/_observablehq/stdlib/inputs.00000006.css create mode 100644 test/output/build/sql/_observablehq/stdlib/inputs.00000007.js create mode 100644 test/output/build/sql/_observablehq/theme-air,near-midnight.00000004.css create mode 100644 test/output/build/sql/index.html diff --git a/src/resolvers.ts b/src/resolvers.ts index 600dfb196..146768ec5 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -14,7 +14,7 @@ import type {LoaderResolver} from "./loader.js"; import type {MarkdownPage} from "./markdown.js"; import {extractNodeSpecifier, resolveNodeImport, resolveNodeImports} from "./node.js"; import {extractNpmSpecifier, populateNpmCache, resolveNpmImport, resolveNpmImports} from "./npm.js"; -import {isAssetPath, isPathImport, parseRelativeUrl, relativePath, resolveLocalPath, resolvePath} from "./path.js"; +import {isAssetPath, isPathImport, parseRelativeUrl, relativePath, resolveLocalPath, resolvePath, resolveRelativePath} from "./path.js"; export interface Resolvers { path: string; @@ -133,7 +133,7 @@ export async function getResolvers(page: MarkdownPage, config: ResolversConfig): for (const value of Object.values(page.data.sql)) { const source = String(value); if (isAssetPath(source)) { - files.add(source); + files.add(resolveRelativePath(path, source)); } } } diff --git a/test/input/build/sql/index.md b/test/input/build/sql/index.md new file mode 100644 index 000000000..6c233ce7f --- /dev/null +++ b/test/input/build/sql/index.md @@ -0,0 +1,8 @@ +--- +sql: + table: /table.csv +--- + +```sql echo +FROM table +``` diff --git a/test/input/build/sql/table.csv b/test/input/build/sql/table.csv new file mode 100644 index 000000000..0099ae937 --- /dev/null +++ b/test/input/build/sql/table.csv @@ -0,0 +1,3 @@ +a,b +1,2 +3,4 diff --git a/test/output/build/sql/_duckdb/json-e3b0c442/v1.1.1/wasm_eh/json.duckdb_extension.wasm b/test/output/build/sql/_duckdb/json-e3b0c442/v1.1.1/wasm_eh/json.duckdb_extension.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_duckdb/json-e3b0c442/v1.1.1/wasm_mvp/json.duckdb_extension.wasm b/test/output/build/sql/_duckdb/json-e3b0c442/v1.1.1/wasm_mvp/json.duckdb_extension.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_duckdb/parquet-e3b0c442/v1.1.1/wasm_eh/parquet.duckdb_extension.wasm b/test/output/build/sql/_duckdb/parquet-e3b0c442/v1.1.1/wasm_eh/parquet.duckdb_extension.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_duckdb/parquet-e3b0c442/v1.1.1/wasm_mvp/parquet.duckdb_extension.wasm b/test/output/build/sql/_duckdb/parquet-e3b0c442/v1.1.1/wasm_mvp/parquet.duckdb_extension.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_file/table.b9485148.csv b/test/output/build/sql/_file/table.b9485148.csv new file mode 100644 index 000000000..0099ae937 --- /dev/null +++ b/test/output/build/sql/_file/table.b9485148.csv @@ -0,0 +1,3 @@ +a,b +1,2 +3,4 diff --git a/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/cd372fb8.js b/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/cd372fb8.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-eh.worker.cd372fb8.js b/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-eh.worker.cd372fb8.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-mvp.worker.cd372fb8.js b/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-mvp.worker.cd372fb8.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-eh.wasm b/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-eh.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm b/test/output/build/sql/_npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_npm/htl@0.3.1/cd372fb8.js b/test/output/build/sql/_npm/htl@0.3.1/cd372fb8.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_npm/isoformat@0.2.1/cd372fb8.js b/test/output/build/sql/_npm/isoformat@0.2.1/cd372fb8.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/client.00000001.js b/test/output/build/sql/_observablehq/client.00000001.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/runtime.00000002.js b/test/output/build/sql/_observablehq/runtime.00000002.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/stdlib.00000003.js b/test/output/build/sql/_observablehq/stdlib.00000003.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/stdlib/duckdb.00000005.js b/test/output/build/sql/_observablehq/stdlib/duckdb.00000005.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/stdlib/inputs.00000006.css b/test/output/build/sql/_observablehq/stdlib/inputs.00000006.css new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/stdlib/inputs.00000007.js b/test/output/build/sql/_observablehq/stdlib/inputs.00000007.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/_observablehq/theme-air,near-midnight.00000004.css b/test/output/build/sql/_observablehq/theme-air,near-midnight.00000004.css new file mode 100644 index 000000000..e69de29bb diff --git a/test/output/build/sql/index.html b/test/output/build/sql/index.html new file mode 100644 index 000000000..b79c552cf --- /dev/null +++ b/test/output/build/sql/index.html @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
FROM table
+
+
+ +
+ + From 0de572fa4b4d925fbbe215d88ea8dda073b30930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Mon, 4 Nov 2024 12:31:34 +0100 Subject: [PATCH 2/3] prettier --- src/resolvers.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/resolvers.ts b/src/resolvers.ts index 146768ec5..5f58c48b5 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -14,7 +14,15 @@ import type {LoaderResolver} from "./loader.js"; import type {MarkdownPage} from "./markdown.js"; import {extractNodeSpecifier, resolveNodeImport, resolveNodeImports} from "./node.js"; import {extractNpmSpecifier, populateNpmCache, resolveNpmImport, resolveNpmImports} from "./npm.js"; -import {isAssetPath, isPathImport, parseRelativeUrl, relativePath, resolveLocalPath, resolvePath, resolveRelativePath} from "./path.js"; +import { + isAssetPath, + isPathImport, + parseRelativeUrl, + relativePath, + resolveLocalPath, + resolvePath, + resolveRelativePath +} from "./path.js"; export interface Resolvers { path: string; From 977dc3364c9aa8f4422ad8f4009a33e18b3bfe69 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Tue, 5 Nov 2024 21:53:00 -0800 Subject: [PATCH 3/3] prettier imports --- src/resolvers.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/resolvers.ts b/src/resolvers.ts index 5f58c48b5..7a9ecb8ce 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -14,15 +14,8 @@ import type {LoaderResolver} from "./loader.js"; import type {MarkdownPage} from "./markdown.js"; import {extractNodeSpecifier, resolveNodeImport, resolveNodeImports} from "./node.js"; import {extractNpmSpecifier, populateNpmCache, resolveNpmImport, resolveNpmImports} from "./npm.js"; -import { - isAssetPath, - isPathImport, - parseRelativeUrl, - relativePath, - resolveLocalPath, - resolvePath, - resolveRelativePath -} from "./path.js"; +import {isAssetPath, isPathImport, parseRelativeUrl} from "./path.js"; +import {relativePath, resolveLocalPath, resolvePath, resolveRelativePath} from "./path.js"; export interface Resolvers { path: string;