Skip to content

Commit 6791dcf

Browse files
committed
fix: broaden DuckDB WASM package preloading
1 parent e45a3cf commit 6791dcf

2 files changed

Lines changed: 7 additions & 27 deletions

File tree

frontend/src/core/wasm/__tests__/utils.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ describe("shouldLoadDuckDBPackages", () => {
88
expect(shouldLoadDuckDBPackages('df = mo.sql("SELECT 1")')).toBe(true);
99
});
1010

11-
it("loads for detected duckdb imports and usage", () => {
11+
it("loads for duckdb text", () => {
1212
expect(shouldLoadDuckDBPackages("import duckdb")).toBe(true);
1313
expect(shouldLoadDuckDBPackages("from duckdb import sql")).toBe(true);
14+
expect(shouldLoadDuckDBPackages("import pandas, duckdb")).toBe(true);
1415
expect(shouldLoadDuckDBPackages("rows = duckdb.sql('SELECT 1')")).toBe(
1516
true,
1617
);
18+
expect(shouldLoadDuckDBPackages("name = 'duckdb'")).toBe(true);
1719
});
1820

1921
it("loads when package discovery found duckdb", () => {
@@ -22,13 +24,7 @@ describe("shouldLoadDuckDBPackages", () => {
2224
).toBe(true);
2325
});
2426

25-
it("ignores incidental duckdb text", () => {
26-
expect(shouldLoadDuckDBPackages("# duckdb is mentioned here")).toBe(false);
27-
expect(shouldLoadDuckDBPackages("# duckdb.sql is mentioned here")).toBe(
28-
false,
29-
);
30-
expect(shouldLoadDuckDBPackages("name = 'duckdb'")).toBe(false);
31-
expect(shouldLoadDuckDBPackages("name = 'duckdb.sql'")).toBe(false);
32-
expect(shouldLoadDuckDBPackages('name = "duckdb.sql"')).toBe(false);
27+
it("does not load without mo.sql, duckdb text, or discovery", () => {
28+
expect(shouldLoadDuckDBPackages("print('hello')")).toBe(false);
3329
});
3430
});

frontend/src/core/wasm/utils.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,13 @@ export function isWasm(): boolean {
1111
);
1212
}
1313

14-
const DUCKDB_IMPORT = /^(import\s+duckdb\b|from\s+duckdb\s+import\b)/;
15-
const DUCKDB_USAGE = /(^|[^"'#])\bduckdb\s*\./;
16-
17-
function hasDuckDBImportOrUsage(code: string): boolean {
18-
return code.split("\n").some((line) => {
19-
const trimmed = line.trimStart();
20-
if (trimmed.startsWith("#")) {
21-
return false;
22-
}
23-
if (DUCKDB_IMPORT.test(trimmed)) {
24-
return true;
25-
}
26-
return DUCKDB_USAGE.test(line.split("#")[0]);
27-
});
28-
}
29-
3014
export function shouldLoadDuckDBPackages(
3115
code: string,
3216
foundPackages?: ReadonlySet<string>,
3317
): boolean {
3418
return (
3519
code.includes("mo.sql") ||
36-
foundPackages?.has("duckdb") === true ||
37-
hasDuckDBImportOrUsage(code)
20+
code.includes("duckdb") ||
21+
foundPackages?.has("duckdb") === true
3822
);
3923
}

0 commit comments

Comments
 (0)