From 484a9e7a64c90fbabc69acdfac8ca594e23e4c16 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Tue, 17 Sep 2024 19:46:47 -0700 Subject: [PATCH 1/3] observablehq:stdlib --- docs/chart.js | 2 +- docs/embeds.md | 2 +- docs/files.md | 2 +- docs/imports.md | 8 ++--- docs/lib/generators.md | 2 +- docs/reactivity.md | 2 +- src/client/preview.js | 2 +- src/client/stdlib/inputs.js | 2 +- src/client/stdlib/zip.js | 2 +- src/javascript/files.ts | 2 +- src/resolvers.ts | 4 +-- test/input/build/data-loaders/test.js | 2 +- test/input/build/fetches/foo/foo.js | 2 +- test/input/build/fetches/top.js | 2 +- test/input/imports/baz.js | 2 +- test/javascript/files-test.ts | 14 ++++---- test/javascript/module-test.ts | 12 +++---- test/javascript/transpile-test.ts | 36 +++++++++---------- .../_import/import-test.7d216225.js | 1 - .../_import/import-test.e7269c4e.js | 1 + .../{test.513ced9f.js => test.17d808d0.js} | 0 test/output/build/data-loaders/index.html | 6 ++-- .../foo/{foo.6fd063d5.js => foo.3bb4a170.js} | 0 .../{top.d8f5cc36.js => top.6c858de5.js} | 2 +- test/output/build/fetches/foo.html | 4 +-- test/output/build/fetches/top.html | 6 ++-- test/resolvers-test.ts | 4 +-- 27 files changed, 63 insertions(+), 61 deletions(-) delete mode 100644 test/output/build/data-loaders/_import/import-test.7d216225.js create mode 100644 test/output/build/data-loaders/_import/import-test.e7269c4e.js rename test/output/build/data-loaders/_import/{test.513ced9f.js => test.17d808d0.js} (100%) rename test/output/build/fetches/_import/foo/{foo.6fd063d5.js => foo.3bb4a170.js} (100%) rename test/output/build/fetches/_import/{top.d8f5cc36.js => top.6c858de5.js} (88%) diff --git a/docs/chart.js b/docs/chart.js index 510ce4a0e..fd48baaeb 100644 --- a/docs/chart.js +++ b/docs/chart.js @@ -1,5 +1,5 @@ -import {FileAttachment} from "npm:@observablehq/stdlib"; import * as Plot from "npm:@observablehq/plot"; +import {FileAttachment} from "observablehq:stdlib"; export async function Chart() { const gistemp = await FileAttachment("./lib/gistemp.csv").csv({typed: true}); diff --git a/docs/embeds.md b/docs/embeds.md index 2b297185d..bd8ef7b49 100644 --- a/docs/embeds.md +++ b/docs/embeds.md @@ -7,8 +7,8 @@ Embedded modules are vanilla JavaScript, and behave identically when embedded in Embedded modules are often written as component functions that return DOM elements. These functions can take options (or “props”), and typically load their own data. For example, below is a simple `chart.js` module that exports a `Chart` function that renders a scatterplot of global surface temperature data. ```js run=false -import {FileAttachment} from "npm:@observablehq/stdlib"; import * as Plot from "npm:@observablehq/plot"; +import {FileAttachment} from "observablehq:stdlib"; export async function Chart() { const gistemp = await FileAttachment("./lib/gistemp.csv").csv({typed: true}); diff --git a/docs/files.md b/docs/files.md index af67e31fc..ea1ece12d 100644 --- a/docs/files.md +++ b/docs/files.md @@ -7,7 +7,7 @@ keywords: file, fileattachment, attachment Load files — whether static or generated dynamically by a [data loader](./data-loaders) — using the built-in `FileAttachment` function. This is available by default in Markdown, but you can import it explicitly like so: ```js echo -import {FileAttachment} from "npm:@observablehq/stdlib"; +import {FileAttachment} from "observablehq:stdlib"; ``` The `FileAttachment` function takes a path and returns a file handle. This handle exposes: diff --git a/docs/imports.md b/docs/imports.md index 31bfa8a05..0cbcf2d6f 100644 --- a/docs/imports.md +++ b/docs/imports.md @@ -130,7 +130,7 @@ import {foo} from "./foo.js"; Within a local module, you can import other local modules, as well as `npm:`, Node, and remote imports. You can also reference local files within a local module by importing [`FileAttachment`](./files) from the Observable standard library like so: ```js run=false -import {FileAttachment} from "npm:@observablehq/stdlib"; +import {FileAttachment} from "observablehq:stdlib"; export const sales = await FileAttachment("sales.csv").csv({typed: true}); ``` @@ -212,9 +212,9 @@ For convenience, Framework provides recommended libraries by default in Markdown Click on any of the imported symbols below to learn more. -
import {FileAttachment} from "npm:@observablehq/stdlib";
-
import {Generators} from "npm:@observablehq/stdlib";
-
import {Mutable} from "npm:@observablehq/stdlib";
+
import {FileAttachment} from "observablehq:stdlib";
+
import {Generators} from "observablehq:stdlib";
+
import {Mutable} from "observablehq:stdlib";
import dot from "npm:@observablehq/dot";
import * as duckdb from "npm:@duckdb/duckdb-wasm";
import {DuckDBClient} from "npm:@observablehq/duckdb";
diff --git a/docs/lib/generators.md b/docs/lib/generators.md index 1beb3c579..7eee039d5 100644 --- a/docs/lib/generators.md +++ b/docs/lib/generators.md @@ -7,7 +7,7 @@ keywords: [dark, width] The Observable standard library includes several generator utilities. These are available by default in Markdown as `Generators`, but you can import them explicitly: ```js echo -import {Generators} from "npm:@observablehq/stdlib"; +import {Generators} from "observablehq:stdlib"; ``` ## input(*element*) diff --git a/docs/reactivity.md b/docs/reactivity.md index 7a3d820ee..6ec030b6c 100644 --- a/docs/reactivity.md +++ b/docs/reactivity.md @@ -326,7 +326,7 @@ Normally, only the code block that declares a top-level variable can define it o `Mutable` is available by default in Markdown but you can import it explicitly like so: ```js echo -import {Mutable} from "npm:@observablehq/stdlib"; +import {Mutable} from "observablehq:stdlib"; ``` Then to use it: diff --git a/src/client/preview.js b/src/client/preview.js index 215d9f914..e8c4683e9 100644 --- a/src/client/preview.js +++ b/src/client/preview.js @@ -1,4 +1,4 @@ -import {FileAttachment, registerFile} from "npm:@observablehq/stdlib"; +import {FileAttachment, registerFile} from "observablehq:stdlib"; import {main, runtime, undefine} from "./main.js"; import {findLoading, findRoots, registerRoot} from "./main.js"; import {enableCopyButtons} from "./pre.js"; diff --git a/src/client/stdlib/inputs.js b/src/client/stdlib/inputs.js index 21de73dba..a0370b6c3 100644 --- a/src/client/stdlib/inputs.js +++ b/src/client/stdlib/inputs.js @@ -1,5 +1,5 @@ import {file as _file} from "@observablehq/inputs"; -import {AbstractFile} from "npm:@observablehq/stdlib"; +import {AbstractFile} from "observablehq:stdlib"; export { button, diff --git a/src/client/stdlib/zip.js b/src/client/stdlib/zip.js index 81bc773b9..ea44e56ca 100644 --- a/src/client/stdlib/zip.js +++ b/src/client/stdlib/zip.js @@ -1,5 +1,5 @@ -import {AbstractFile} from "npm:@observablehq/stdlib"; import JSZip from "npm:jszip"; +import {AbstractFile} from "observablehq:stdlib"; export class ZipArchive { constructor(archive) { diff --git a/src/javascript/files.ts b/src/javascript/files.ts index e3ba16f29..ec4c5bca5 100644 --- a/src/javascript/files.ts +++ b/src/javascript/files.ts @@ -51,7 +51,7 @@ export function findFiles( // Support namespace imports? Error if stdlib is expressed with a version? simple(body, { ImportDeclaration(node) { - if (node.source.value === "npm:@observablehq/stdlib") { + if (node.source.value === "observablehq:stdlib" || node.source.value === "npm:@observablehq/stdlib") { for (const specifier of node.specifiers) { if ( specifier.type === "ImportSpecifier" && diff --git a/src/resolvers.ts b/src/resolvers.ts index 553440c6f..084c2c879 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -39,8 +39,8 @@ export interface ResolversConfig { const defaultImports = [ "observablehq:client", // Framework client - "npm:@observablehq/runtime", // Runtime - "npm:@observablehq/stdlib" // Standard library + "observablehq:runtime", // Runtime + "observablehq:stdlib" // Standard library ]; export const builtins = new Map([ diff --git a/test/input/build/data-loaders/test.js b/test/input/build/data-loaders/test.js index 555f3da69..91b1cbe8e 100644 --- a/test/input/build/data-loaders/test.js +++ b/test/input/build/data-loaders/test.js @@ -1,3 +1,3 @@ -import {FileAttachment} from "npm:@observablehq/stdlib"; +import {FileAttachment} from "observablehq:stdlib"; export const test = FileAttachment("./test.txt").text(); diff --git a/test/input/build/fetches/foo/foo.js b/test/input/build/fetches/foo/foo.js index 78a1dd0ba..9e626660c 100644 --- a/test/input/build/fetches/foo/foo.js +++ b/test/input/build/fetches/foo/foo.js @@ -1,3 +1,3 @@ -import {FileAttachment} from "npm:@observablehq/stdlib"; +import {FileAttachment} from "observablehq:stdlib"; export const fooJsonData = await FileAttachment("foo-data.json").json(); export const fooCsvData = await FileAttachment("foo-data.csv").text(); diff --git a/test/input/build/fetches/top.js b/test/input/build/fetches/top.js index 4702eb3ae..1ddb95151 100644 --- a/test/input/build/fetches/top.js +++ b/test/input/build/fetches/top.js @@ -1,4 +1,4 @@ -import {FileAttachment} from "npm:@observablehq/stdlib"; +import {FileAttachment} from "observablehq:stdlib"; export {fooCsvData, fooJsonData} from "./foo/foo.js"; export const topJsonData = await FileAttachment("top-data.json").json(); export const topCsvData = await FileAttachment("top-data.csv").text(); diff --git a/test/input/imports/baz.js b/test/input/imports/baz.js index f9a426bff..ed12b4ebe 100644 --- a/test/input/imports/baz.js +++ b/test/input/imports/baz.js @@ -1,3 +1,3 @@ -import {FileAttachment} from "npm:@observablehq/stdlib"; +import {FileAttachment} from "observablehq:stdlib"; export const data = FileAttachment("./fetch-local-data.json").json(); diff --git a/test/javascript/files-test.ts b/test/javascript/files-test.ts index 3c623c858..4e1ff187c 100644 --- a/test/javascript/files-test.ts +++ b/test/javascript/files-test.ts @@ -9,6 +9,8 @@ describe("findFiles(node, input)", () => { assert.deepStrictEqual(files('FileAttachment("foo.json")'), [{name: "./foo.json", method: "json"}]); }); it("finds imported FileAttachment", () => { + assert.deepStrictEqual(files('import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("foo.json")'), [{name: "./foo.json", method: "json"}]); + assert.deepStrictEqual(files('import {FileAttachment as F} from "observablehq:stdlib";\nF("foo.json")'), [{name: "./foo.json", method: "json"}]); assert.deepStrictEqual(files('import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("foo.json")'), [{name: "./foo.json", method: "json"}]); assert.deepStrictEqual(files('import {FileAttachment as F} from "npm:@observablehq/stdlib";\nF("foo.json")'), [{name: "./foo.json", method: "json"}]); }); @@ -103,25 +105,25 @@ describe("findFiles(node, input)", () => { assert.deepStrictEqual(files('File("foo.txt").csv', {aliases: ["File"]}), [{name: "./foo.txt", method: "csv"}]); }); it("finds the import declaration", () => { - assert.deepStrictEqual(files('import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("foo.txt").csv', {aliases: []}), [{name: "./foo.txt", method: "csv"}]); + assert.deepStrictEqual(files('import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("foo.txt").csv', {aliases: []}), [{name: "./foo.txt", method: "csv"}]); }); it("finds the import declaration if aliased", () => { - assert.deepStrictEqual(files('import {FileAttachment as F} from "npm:@observablehq/stdlib";\nF("foo.txt").csv', {aliases: []}), [{name: "./foo.txt", method: "csv"}]); + assert.deepStrictEqual(files('import {FileAttachment as F} from "observablehq:stdlib";\nF("foo.txt").csv', {aliases: []}), [{name: "./foo.txt", method: "csv"}]); }); it("finds the import declaration if aliased and masking a global", () => { - assert.deepStrictEqual(files('import {FileAttachment as File} from "npm:@observablehq/stdlib";\nFile("foo.txt").csv', {aliases: []}), [{name: "./foo.txt", method: "csv"}]); + assert.deepStrictEqual(files('import {FileAttachment as File} from "observablehq:stdlib";\nFile("foo.txt").csv', {aliases: []}), [{name: "./foo.txt", method: "csv"}]); }); it("finds the import declaration if multiple aliases", () => { - assert.deepStrictEqual(files('import {FileAttachment as F, FileAttachment as G} from "npm:@observablehq/stdlib";\nF("file1.txt");\nG("file2.txt");', {aliases: []}), [{name: "./file1.txt", method: "text"}, {name: "./file2.txt", method: "text"}]); + assert.deepStrictEqual(files('import {FileAttachment as F, FileAttachment as G} from "observablehq:stdlib";\nF("file1.txt");\nG("file2.txt");', {aliases: []}), [{name: "./file1.txt", method: "text"}, {name: "./file2.txt", method: "text"}]); }); it("ignores import declarations from another module", () => { assert.deepStrictEqual(files('import {FileAttachment as F} from "npm:@observablehq/not-stdlib";\nFileAttachment("file1.txt");', {aliases: []}), []); }); it.skip("supports namespace imports", () => { - assert.deepStrictEqual(files('import * as O from "npm:@observablehq/stdlib";\nO.FileAttachment("foo.txt");', {aliases: []}), [{name: "./foo.txt", method: "text"}]); + assert.deepStrictEqual(files('import * as O from "observablehq:stdlib";\nO.FileAttachment("foo.txt");', {aliases: []}), [{name: "./foo.txt", method: "text"}]); }); it("ignores masked references", () => { - assert.deepStrictEqual(files('import {FileAttachment} from "npm:@observablehq/stdlib";\n((FileAttachment) => FileAttachment("file.txt"))(String);', {aliases: []}), []); + assert.deepStrictEqual(files('import {FileAttachment} from "observablehq:stdlib";\n((FileAttachment) => FileAttachment("file.txt"))(String);', {aliases: []}), []); }); }); diff --git a/test/javascript/module-test.ts b/test/javascript/module-test.ts index 57da4f402..e1b83ea14 100644 --- a/test/javascript/module-test.ts +++ b/test/javascript/module-test.ts @@ -11,8 +11,8 @@ describe("getModuleHash(root, path)", () => { assert.strictEqual(getModuleHash("test/input/build/imports", "foo/foo.js"), "32f934a52fa34ba1b06aa6089fe5922dc442c9bf2dcddef864bc649a39d9eace"); // prettier-ignore assert.strictEqual(getModuleHash("test/input/build/imports", "bar/bar.js"), "7fe009c8bb0049d9b84d53a00b29fb172bbf07d8232d2ace5f7c6f220b23eb16"); // prettier-ignore assert.strictEqual(getModuleHash("test/input/build/imports", "top.js"), "160847a6b4890d59f8e8862911bfbe3b8066955d31f2708cafbe51945c3c57b6"); // prettier-ignore - assert.strictEqual(getModuleHash("test/input/build/fetches", "foo/foo.js"), "6fd063d5f14f3bb844cfdb599bf3bdd643c4d0f89841591f769960fd58104e6c"); // prettier-ignore - assert.strictEqual(getModuleHash("test/input/build/fetches", "top.js"), "d8f5cc36a8b359974a3aa89013db8d6c1dbb43b091bed4ea683a7c8c994b2a3d"); // prettier-ignore + assert.strictEqual(getModuleHash("test/input/build/fetches", "foo/foo.js"), "3bb4a170d2f3539934168741572d4aa3cd11da649d4ca88b408edefb5c287360"); // prettier-ignore + assert.strictEqual(getModuleHash("test/input/build/fetches", "top.js"), "6c858de52de6ff26b19508e95448288da02fac62251b7ca2710a308a0ebfd7ba"); // prettier-ignore }); it("returns the empty hash if the specified module does not exist", () => { assert.strictEqual(getModuleHash("test/input/build/imports", "does-not-exist.js"), emptyHash); @@ -63,8 +63,8 @@ describe("getModuleInfo(root, path)", () => { assert.deepStrictEqual(redactModuleInfo("test/input/build/fetches", "foo/foo.js"), { fileMethods: new Set(["json", "text"]), files: new Set(["./foo-data.csv", "./foo-data.json"]), - hash: "13349148aade73f9c04f331956a8f48535958a7c7e640b025eebfb52156067fa", - globalStaticImports: new Set(["npm:@observablehq/stdlib"]), + hash: "2b1e6b6f73a700231a3c60915d358d5ac10b1665e65a1647d91bf597d48f874e", + globalStaticImports: new Set(["observablehq:stdlib"]), globalDynamicImports: new Set(), localDynamicImports: new Set(), localStaticImports: new Set() @@ -72,8 +72,8 @@ describe("getModuleInfo(root, path)", () => { assert.deepStrictEqual(redactModuleInfo("test/input/build/fetches", "top.js"), { fileMethods: new Set(["json", "text"]), files: new Set(["./top-data.csv", "./top-data.json"]), - hash: "d755832694c7db24d3606bdef5ecfdfbd820b09576d5790feb310854f48b2228", - globalStaticImports: new Set(["npm:@observablehq/stdlib"]), + hash: "2a35a381b4975e007db01eef32f3dadd74645b61a6cf0fe3746bcb4ae8c8b3cf", + globalStaticImports: new Set(["observablehq:stdlib"]), globalDynamicImports: new Set(), localDynamicImports: new Set(), localStaticImports: new Set(["./foo/foo.js"]) diff --git a/test/javascript/transpile-test.ts b/test/javascript/transpile-test.ts index 382a1fe5d..2c2e3ff71 100644 --- a/test/javascript/transpile-test.ts +++ b/test/javascript/transpile-test.ts @@ -82,7 +82,7 @@ describe("transpileJavaScript(input, options)", () => { }); async function testFile(target: string, path: string): Promise { - const input = `import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment(${JSON.stringify(target)})`; + const input = `import {FileAttachment} from "observablehq:stdlib";\nFileAttachment(${JSON.stringify(target)})`; const output = await transpileModule(input, {root: "src", path}); return output.split("\n").pop()!; } @@ -126,68 +126,68 @@ describe("transpileModule(input, root, path)", () => { assert.strictEqual(await testFile("/test.txt", "sub/test.js"), 'FileAttachment("../../test.txt", import.meta.url)'); // prettier-ignore }); it("ignores FileAttachment if masked by a reference", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/stdlib";\n((FileAttachment) => FileAttachment("./test.txt"))(eval)'; // prettier-ignore + const input = 'import {FileAttachment} from "observablehq:stdlib";\n((FileAttachment) => FileAttachment("./test.txt"))(eval)'; // prettier-ignore const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, '((FileAttachment) => FileAttachment("./test.txt"))(eval)'); }); it("ignores FileAttachment if not imported", async () => { - const input = 'import {Generators} from "npm:@observablehq/stdlib";\nFileAttachment("./test.txt")'; + const input = 'import {Generators} from "observablehq:stdlib";\nFileAttachment("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'FileAttachment("./test.txt")'); }); it("ignores FileAttachment if a comma expression", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/stdlib";\n(1, FileAttachment)("./test.txt")'; + const input = 'import {FileAttachment} from "observablehq:stdlib";\n(1, FileAttachment)("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, '(1, FileAttachment)("./test.txt")'); }); - it("ignores FileAttachment if not imported from @observablehq/stdlib", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/inputs";\nFileAttachment("./test.txt")'; + it("ignores FileAttachment if not imported from observablehq:stdlib", async () => { + const input = 'import {FileAttachment} from "observablehq:inputs";\nFileAttachment("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'FileAttachment("./test.txt")'); }); it("rewrites FileAttachment when aliased", async () => { - const input = 'import {FileAttachment as F} from "npm:@observablehq/stdlib";\nF("./test.txt")'; + const input = 'import {FileAttachment as F} from "observablehq:stdlib";\nF("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'F("../test.txt", import.meta.url)'); }); it("rewrites FileAttachment when aliased to a global", async () => { - const input = 'import {FileAttachment as File} from "npm:@observablehq/stdlib";\nFile("./test.txt")'; + const input = 'import {FileAttachment as File} from "observablehq:stdlib";\nFile("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'File("../test.txt", import.meta.url)'); }); it.skip("rewrites FileAttachment when imported as a namespace", async () => { - const input = 'import * as O from "npm:@observablehq/stdlib";\nO.FileAttachment("./test.txt")'; + const input = 'import * as O from "observablehq:stdlib";\nO.FileAttachment("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'O.FileAttachment("../test.txt", import.meta.url)'); }); it("ignores non-FileAttachment calls", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFile("./test.txt")'; + const input = 'import {FileAttachment} from "observablehq:stdlib";\nFile("./test.txt")'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'File("./test.txt")'); }); it("rewrites single-quoted literals", async () => { - const input = "import {FileAttachment} from \"npm:@observablehq/stdlib\";\nFileAttachment('./test.txt')"; + const input = "import {FileAttachment} from \"observablehq:stdlib\";\nFileAttachment('./test.txt')"; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'FileAttachment("../test.txt", import.meta.url)'); }); it("rewrites template-quoted literals", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment(`./test.txt`)'; + const input = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment(`./test.txt`)'; const output = (await transpileModule(input, options)).split("\n").pop()!; assert.strictEqual(output, 'FileAttachment("../test.txt", import.meta.url)'); }); it("throws a syntax error with non-literal calls", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment(`./${test}.txt`)'; + const input = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment(`./${test}.txt`)'; await assert.rejects(() => transpileModule(input, options), /FileAttachment requires a single literal string/); // prettier-ignore }); it("throws a syntax error with URL fetches", async () => { - const input = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("https://example.com")'; + const input = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("https://example.com")'; await assert.rejects(() => transpileModule(input, options), /non-local file path/); // prettier-ignore }); it("ignores non-local path fetches", async () => { - const input1 = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("../test.txt")'; - const input2 = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("./../test.txt")'; - const input3 = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("../../test.txt")'; - const input4 = 'import {FileAttachment} from "npm:@observablehq/stdlib";\nFileAttachment("./../../test.txt")'; + const input1 = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("../test.txt")'; + const input2 = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("./../test.txt")'; + const input3 = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("../../test.txt")'; + const input4 = 'import {FileAttachment} from "observablehq:stdlib";\nFileAttachment("./../../test.txt")'; await assert.rejects(() => transpileModule(input1, options), /non-local file path/); // prettier-ignore await assert.rejects(() => transpileModule(input2, options), /non-local file path/); // prettier-ignore await assert.rejects(() => transpileModule(input3, {...options, path: "sub/test.js"}), /non-local file path/); // prettier-ignore diff --git a/test/output/build/data-loaders/_import/import-test.7d216225.js b/test/output/build/data-loaders/_import/import-test.7d216225.js deleted file mode 100644 index b92bea2ed..000000000 --- a/test/output/build/data-loaders/_import/import-test.7d216225.js +++ /dev/null @@ -1 +0,0 @@ -export {test} from "./test.513ced9f.js"; diff --git a/test/output/build/data-loaders/_import/import-test.e7269c4e.js b/test/output/build/data-loaders/_import/import-test.e7269c4e.js new file mode 100644 index 000000000..902282f3d --- /dev/null +++ b/test/output/build/data-loaders/_import/import-test.e7269c4e.js @@ -0,0 +1 @@ +export {test} from "./test.17d808d0.js"; diff --git a/test/output/build/data-loaders/_import/test.513ced9f.js b/test/output/build/data-loaders/_import/test.17d808d0.js similarity index 100% rename from test/output/build/data-loaders/_import/test.513ced9f.js rename to test/output/build/data-loaders/_import/test.17d808d0.js diff --git a/test/output/build/data-loaders/index.html b/test/output/build/data-loaders/index.html index f68246c29..cbca6b8ce 100644 --- a/test/output/build/data-loaders/index.html +++ b/test/output/build/data-loaders/index.html @@ -11,8 +11,8 @@ - - + +