diff --git a/src/javascript/transpile.ts b/src/javascript/transpile.ts index eee3d2947..d58ce94f1 100644 --- a/src/javascript/transpile.ts +++ b/src/javascript/transpile.ts @@ -101,7 +101,7 @@ export async function transpileModule( async function rewriteImportSource(source: StringLiteral) { const specifier = getStringLiteralValue(source); - output.replaceLeft(source.start, source.end, JSON.stringify(await resolveImport(specifier))); + output.replaceLeft(source.start, source.end, annotatePath(await resolveImport(specifier))); } for (const {name, node} of findFiles(body, path, input)) { @@ -111,17 +111,15 @@ export async function transpileModule( output.replaceLeft( source.start, source.end, - `${JSON.stringify( + `${ info - ? { - name: p, - mimeType: mime.getType(name) ?? undefined, - path: relativePath(servePath, resolveFile(name)), - lastModified: info.mtimeMs, - size: info.size - } - : p - )}, import.meta.url` + ? `{"name":${JSON.stringify(p)},"mimeType":${JSON.stringify( + mime.getType(name) ?? undefined + )},"path":${annotatePath(relativePath(servePath, resolveFile(name)))},"lastModified":${JSON.stringify( + info.mtimeMs + )},"size":${JSON.stringify(info.size)}}` + : JSON.stringify(p) + }, import.meta.url` ); } @@ -137,7 +135,7 @@ export async function transpileModule( if (isImportMetaResolve(node) && isStringLiteral(source)) { const value = getStringLiteralValue(source); const resolution = isPathImport(value) && !isJavaScript(value) ? resolveFile(value) : await resolveImport(value); - output.replaceLeft(source.start, source.end, JSON.stringify(resolution)); + output.replaceLeft(source.start, source.end, annotatePath(resolution)); } } @@ -205,7 +203,7 @@ function rewriteImportDeclarations( for (const node of declarations) { output.delete(node.start, node.end + +(output.input[node.end] === "\n")); specifiers.push(rewriteImportSpecifiers(node)); - imports.push(`import(${JSON.stringify(resolve(getStringLiteralValue(node.source as StringLiteral)))})`); + imports.push(`import(${annotatePath(resolve(getStringLiteralValue(node.source as StringLiteral)))})`); } if (declarations.length > 1) { output.insertLeft(0, `const [${specifiers.join(", ")}] = await Promise.all([${imports.join(", ")}]);\n`); @@ -259,3 +257,10 @@ export function rewriteParams(output: Sourcemap, body: Node, params: Params, inp output.replaceLeft(node.start, node.end, JSON.stringify(params[name])); } } + +/** + * Annotate a path to a local import or file so it can be reworked server-side. + */ +export function annotatePath(uri: string): string { + return `${JSON.stringify(uri)}${isPathImport(uri) ? "/* observablehq-file */" : ""}`; +} diff --git a/src/node.ts b/src/node.ts index 298a21cdf..b85591d3e 100644 --- a/src/node.ts +++ b/src/node.ts @@ -15,6 +15,7 @@ import esbuild from "rollup-plugin-esbuild"; import {prepareOutput, toOsPath} from "./files.js"; import type {ImportReference} from "./javascript/imports.js"; import {isJavaScript, parseImports} from "./javascript/imports.js"; +import {annotatePath} from "./javascript/transpile.js"; import {parseNpmSpecifier, rewriteNpmImports} from "./npm.js"; import {isPathImport, relativePath} from "./path.js"; import {faint} from "./tty.js"; @@ -86,7 +87,7 @@ function isBadCommonJs(specifier: string): boolean { } function shimCommonJs(specifier: string, require: NodeRequire): string { - return `export {${Object.keys(require(specifier))}} from ${JSON.stringify(specifier)};\n`; + return `export {${Object.keys(require(specifier))}} from ${annotatePath(specifier)};\n`; } async function bundle( diff --git a/src/npm.ts b/src/npm.ts index df2084df8..464b9915c 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -10,6 +10,7 @@ import {isImportMetaResolve, parseImports} from "./javascript/imports.js"; import {parseProgram} from "./javascript/parse.js"; import type {StringLiteral} from "./javascript/source.js"; import {getStringLiteralValue, isStringLiteral} from "./javascript/source.js"; +import {annotatePath} from "./javascript/transpile.js"; import {relativePath} from "./path.js"; import {Sourcemap} from "./sourcemap.js"; import {faint, yellow} from "./tty.js"; @@ -64,7 +65,7 @@ export function rewriteNpmImports(input: string, resolve: (s: string) => string const value = getStringLiteralValue(source); const resolved = resolve(value); if (resolved === undefined || value === resolved) return; - output.replaceLeft(source.start, source.end, JSON.stringify(resolved)); + output.replaceLeft(source.start, source.end, annotatePath(resolved)); } // TODO Preserve the source map, but download it too. diff --git a/src/rollup.ts b/src/rollup.ts index d380630a0..04d48fff1 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -8,6 +8,7 @@ import esbuild from "rollup-plugin-esbuild"; import {getClientPath, getStylePath} from "./files.js"; import type {StringLiteral} from "./javascript/source.js"; import {getStringLiteralValue, isStringLiteral} from "./javascript/source.js"; +import {annotatePath} from "./javascript/transpile.js"; import {resolveNpmImport} from "./npm.js"; import {getObservableUiOrigin} from "./observableApiClient.js"; import {isAssetPath, isPathImport, relativePath} from "./path.js"; @@ -177,7 +178,7 @@ function importMetaResolve(path: string, resolveImport: ImportResolver): Plugin for (const source of resolves) { const specifier = getStringLiteralValue(source); const resolution = await resolveImport(specifier); - if (resolution) output.replaceLeft(source.start, source.end, JSON.stringify(relativePath(path, resolution))); + if (resolution) output.replaceLeft(source.start, source.end, annotatePath(relativePath(path, resolution))); } return {code: String(output)}; diff --git a/test/javascript/transpile-test.ts b/test/javascript/transpile-test.ts index 4f3a9d3bd..b7de3a89a 100644 --- a/test/javascript/transpile-test.ts +++ b/test/javascript/transpile-test.ts @@ -210,11 +210,11 @@ describe("transpileModule(input, root, path)", () => { it("rewrites npm imports", async () => { const input = 'import "npm:d3-array";'; const output = (await transpileModule(input, options)).split("\n").pop()!; - assert.strictEqual(output, 'import "../_npm/d3-array@3.2.4/_esm.js";'); + assert.strictEqual(output, 'import "../_npm/d3-array@3.2.4/_esm.js"/* observablehq-file */;'); }); it("rewrites node imports", async () => { const input = 'import "d3-array";'; const output = (await transpileModule(input, options)).split("\n").pop()!; - assert.strictEqual(output, 'import "../_node/d3-array@3.2.4/index.js";'); + assert.strictEqual(output, 'import "../_node/d3-array@3.2.4/index.js"/* observablehq-file */;'); }); }); diff --git a/test/npm-test.ts b/test/npm-test.ts index ff7414e4a..dbb3e3073 100644 --- a/test/npm-test.ts +++ b/test/npm-test.ts @@ -103,37 +103,37 @@ describe("fromJsDelivrPath(path)", () => { // prettier-ignore describe("rewriteNpmImports(input, resolve)", () => { it("rewrites /npm/ imports to /_npm/", () => { - assert.strictEqual(rewriteNpmImports('export * from "/npm/d3-array@3.2.4/dist/d3-array.js";\n', (v) => resolve("/_npm/d3@7.8.5/dist/d3.js", v)), 'export * from "../../d3-array@3.2.4/dist/d3-array.js";\n'); + assert.strictEqual(rewriteNpmImports('export * from "/npm/d3-array@3.2.4/dist/d3-array.js";\n', (v) => resolve("/_npm/d3@7.8.5/dist/d3.js", v)), 'export * from "../../d3-array@3.2.4/dist/d3-array.js"/* observablehq-file */;\n'); }); it("rewrites /npm/…+esm imports to _esm.js", () => { - assert.strictEqual(rewriteNpmImports('export * from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'export * from "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('export * from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'export * from "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites /npm/ imports to a relative path", () => { - assert.strictEqual(rewriteNpmImports('import "/npm/d3-array@3.2.4/dist/d3-array.js";\n', (v) => resolve("/_npm/d3@7.8.5/dist/d3.js", v)), 'import "../../d3-array@3.2.4/dist/d3-array.js";\n'); - assert.strictEqual(rewriteNpmImports('import "/npm/d3-array@3.2.4/dist/d3-array.js";\n', (v) => resolve("/_npm/d3@7.8.5/d3.js", v)), 'import "../d3-array@3.2.4/dist/d3-array.js";\n'); + assert.strictEqual(rewriteNpmImports('import "/npm/d3-array@3.2.4/dist/d3-array.js";\n', (v) => resolve("/_npm/d3@7.8.5/dist/d3.js", v)), 'import "../../d3-array@3.2.4/dist/d3-array.js"/* observablehq-file */;\n'); + assert.strictEqual(rewriteNpmImports('import "/npm/d3-array@3.2.4/dist/d3-array.js";\n', (v) => resolve("/_npm/d3@7.8.5/d3.js", v)), 'import "../d3-array@3.2.4/dist/d3-array.js"/* observablehq-file */;\n'); }); it("rewrites named imports", () => { - assert.strictEqual(rewriteNpmImports('import {sort} from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import {sort} from "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('import {sort} from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import {sort} from "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites empty imports", () => { - assert.strictEqual(rewriteNpmImports('import "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('import "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites default imports", () => { - assert.strictEqual(rewriteNpmImports('import d3 from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import d3 from "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('import d3 from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import d3 from "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites namespace imports", () => { - assert.strictEqual(rewriteNpmImports('import * as d3 from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import * as d3 from "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('import * as d3 from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import * as d3 from "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites named exports", () => { - assert.strictEqual(rewriteNpmImports('export {sort} from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'export {sort} from "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('export {sort} from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'export {sort} from "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites namespace exports", () => { - assert.strictEqual(rewriteNpmImports('export * from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'export * from "../d3-array@3.2.4/_esm.js";\n'); + assert.strictEqual(rewriteNpmImports('export * from "/npm/d3-array@3.2.4/+esm";\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'export * from "../d3-array@3.2.4/_esm.js"/* observablehq-file */;\n'); }); it("rewrites dynamic imports with static module specifiers", () => { - assert.strictEqual(rewriteNpmImports('import("/npm/d3-array@3.2.4/+esm");\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js");\n'); - assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@3.2.4/+esm`);\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js");\n'); - assert.strictEqual(rewriteNpmImports("import('/npm/d3-array@3.2.4/+esm');\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js");\n'); + assert.strictEqual(rewriteNpmImports('import("/npm/d3-array@3.2.4/+esm");\n', (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js"/* observablehq-file */);\n'); + assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@3.2.4/+esm`);\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js"/* observablehq-file */);\n'); + assert.strictEqual(rewriteNpmImports("import('/npm/d3-array@3.2.4/+esm');\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js"/* observablehq-file */);\n'); }); it("ignores dynamic imports with dynamic module specifiers", () => { assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@${version}/+esm`);\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), "import(`/npm/d3-array@${version}/+esm`);\n"); @@ -142,8 +142,8 @@ describe("rewriteNpmImports(input, resolve)", () => { assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@${version}/+esm`);\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), "import(`/npm/d3-array@${version}/+esm`);\n"); }); it("strips the sourceMappingURL declaration", () => { - assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@3.2.4/+esm`);\n//# sourceMappingURL=index.js.map", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js");\n'); - assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@3.2.4/+esm`);\n//# sourceMappingURL=index.js.map\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js");\n'); + assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@3.2.4/+esm`);\n//# sourceMappingURL=index.js.map", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js"/* observablehq-file */);\n'); + assert.strictEqual(rewriteNpmImports("import(`/npm/d3-array@3.2.4/+esm`);\n//# sourceMappingURL=index.js.map\n", (v) => resolve("/_npm/d3@7.8.5/_esm.js", v)), 'import("../d3-array@3.2.4/_esm.js"/* observablehq-file */);\n'); }); }); diff --git a/test/output/build/data-loaders/_import/import-test.e7269c4e.js b/test/output/build/data-loaders/_import/import-test.e7269c4e.js index 10a131aa4..e46e0955e 100644 --- a/test/output/build/data-loaders/_import/import-test.e7269c4e.js +++ b/test/output/build/data-loaders/_import/import-test.e7269c4e.js @@ -1 +1 @@ -export {test} from "./test.86a60bc6.js"; +export {test} from "./test.86a60bc6.js"/* observablehq-file */; diff --git a/test/output/build/data-loaders/_import/test.86a60bc6.js b/test/output/build/data-loaders/_import/test.86a60bc6.js index 5a72a67ac..fd1781900 100644 --- a/test/output/build/data-loaders/_import/test.86a60bc6.js +++ b/test/output/build/data-loaders/_import/test.86a60bc6.js @@ -1,3 +1,3 @@ -import {FileAttachment} from "../_observablehq/stdlib.00000003.js"; +import {FileAttachment} from "../_observablehq/stdlib.00000003.js"/* observablehq-file */; -export const test = FileAttachment({"name":"../test.txt","mimeType":"text/plain","path":"../_file/test.f2ca1bb6.txt","lastModified":/* ts */1706742000000,"size":5}, import.meta.url).text(); +export const test = FileAttachment({"name":"../test.txt","mimeType":"text/plain","path":"../_file/test.f2ca1bb6.txt"/* observablehq-file */,"lastModified":/* ts */1706742000000,"size":5}, import.meta.url).text(); diff --git a/test/output/build/data-loaders/index.html b/test/output/build/data-loaders/index.html index 1770cbaf9..794fd7a3c 100644 --- a/test/output/build/data-loaders/index.html +++ b/test/output/build/data-loaders/index.html @@ -23,7 +23,7 @@ registerFile("./test.txt", {"name":"./test.txt","mimeType":"text/plain","path":"./_file/test.f2ca1bb6.txt","lastModified":/* ts */1706742000000,"size":5}); define({id: "05e74070", inputs: ["display"], outputs: ["test"], body: async (display) => { -const {test} = await import("./_import/import-test.e7269c4e.js"); +const {test} = await import("./_import/import-test.e7269c4e.js"/* observablehq-file */); display(await test); return {test}; diff --git a/test/output/build/embed/_import/chart.2ce91e05.js b/test/output/build/embed/_import/chart.2ce91e05.js index fb6db0292..8d6193a29 100644 --- a/test/output/build/embed/_import/chart.2ce91e05.js +++ b/test/output/build/embed/_import/chart.2ce91e05.js @@ -1,8 +1,8 @@ -import {FileAttachment} from "../_observablehq/stdlib.00000003.js"; -import * as Plot from "../_npm/@observablehq/plot@0.6.11/cd372fb8.js"; +import {FileAttachment} from "../_observablehq/stdlib.00000003.js"/* observablehq-file */; +import * as Plot from "../_npm/@observablehq/plot@0.6.11/cd372fb8.js"/* observablehq-file */; export async function Chart() { - const gistemp = await FileAttachment({"name":"../lib/gistemp.csv","mimeType":"text/csv","path":"../_file/lib/gistemp.1cf298b1.csv","lastModified":/* ts */1706742000000,"size":97}, import.meta.url).csv({typed: true}); + const gistemp = await FileAttachment({"name":"../lib/gistemp.csv","mimeType":"text/csv","path":"../_file/lib/gistemp.1cf298b1.csv"/* observablehq-file */,"lastModified":/* ts */1706742000000,"size":97}, import.meta.url).csv({typed: true}); return Plot.plot({ y: {grid: true}, color: {scheme: "burd"}, diff --git a/test/output/build/embed/chart.js b/test/output/build/embed/chart.js index b66c6335a..41471c2da 100644 --- a/test/output/build/embed/chart.js +++ b/test/output/build/embed/chart.js @@ -1,4 +1,4 @@ -import "./_observablehq/stdlib.00000003.js"; -import "./_npm/@observablehq/plot@0.6.11/cd372fb8.js"; -import "./_npm/d3-dsv@3.0.1/cd372fb8.js"; -export * from "./_import/chart.2ce91e05.js"; +import "./_observablehq/stdlib.00000003.js"/* observablehq-file */; +import "./_npm/@observablehq/plot@0.6.11/cd372fb8.js"/* observablehq-file */; +import "./_npm/d3-dsv@3.0.1/cd372fb8.js"/* observablehq-file */; +export * from "./_import/chart.2ce91e05.js"/* observablehq-file */; diff --git a/test/output/build/fetches/_import/foo/foo.666599bc.js b/test/output/build/fetches/_import/foo/foo.666599bc.js index d8ffe82c0..795b7c63f 100644 --- a/test/output/build/fetches/_import/foo/foo.666599bc.js +++ b/test/output/build/fetches/_import/foo/foo.666599bc.js @@ -1,3 +1,3 @@ -import {FileAttachment} from "../../_observablehq/stdlib.00000003.js"; -export const fooJsonData = await FileAttachment({"name":"../../foo/foo-data.json","mimeType":"application/json","path":"../../_file/foo/foo-data.67358ed8.json","lastModified":/* ts */1706742000000,"size":10}, import.meta.url).json(); -export const fooCsvData = await FileAttachment({"name":"../../foo/foo-data.csv","mimeType":"text/csv","path":"../../_file/foo/foo-data.24ef4634.csv","lastModified":/* ts */1706742000000,"size":72}, import.meta.url).text(); +import {FileAttachment} from "../../_observablehq/stdlib.00000003.js"/* observablehq-file */; +export const fooJsonData = await FileAttachment({"name":"../../foo/foo-data.json","mimeType":"application/json","path":"../../_file/foo/foo-data.67358ed8.json"/* observablehq-file */,"lastModified":/* ts */1706742000000,"size":10}, import.meta.url).json(); +export const fooCsvData = await FileAttachment({"name":"../../foo/foo-data.csv","mimeType":"text/csv","path":"../../_file/foo/foo-data.24ef4634.csv"/* observablehq-file */,"lastModified":/* ts */1706742000000,"size":72}, import.meta.url).text(); diff --git a/test/output/build/fetches/_import/top.c85e149a.js b/test/output/build/fetches/_import/top.c85e149a.js index 92ded23ba..65d9f3ed3 100644 --- a/test/output/build/fetches/_import/top.c85e149a.js +++ b/test/output/build/fetches/_import/top.c85e149a.js @@ -1,4 +1,4 @@ -import {FileAttachment} from "../_observablehq/stdlib.00000003.js"; -export {fooCsvData, fooJsonData} from "./foo/foo.666599bc.js"; -export const topJsonData = await FileAttachment({"name":"../top-data.json","mimeType":"application/json","path":"../_file/top-data.67358ed8.json","lastModified":/* ts */1706742000000,"size":10}, import.meta.url).json(); -export const topCsvData = await FileAttachment({"name":"../top-data.csv","mimeType":"text/csv","path":"../_file/top-data.24ef4634.csv","lastModified":/* ts */1706742000000,"size":72}, import.meta.url).text(); +import {FileAttachment} from "../_observablehq/stdlib.00000003.js"/* observablehq-file */; +export {fooCsvData, fooJsonData} from "./foo/foo.666599bc.js"/* observablehq-file */; +export const topJsonData = await FileAttachment({"name":"../top-data.json","mimeType":"application/json","path":"../_file/top-data.67358ed8.json"/* observablehq-file */,"lastModified":/* ts */1706742000000,"size":10}, import.meta.url).json(); +export const topCsvData = await FileAttachment({"name":"../top-data.csv","mimeType":"text/csv","path":"../_file/top-data.24ef4634.csv"/* observablehq-file */,"lastModified":/* ts */1706742000000,"size":72}, import.meta.url).text(); diff --git a/test/output/build/fetches/foo.html b/test/output/build/fetches/foo.html index e4fcd38f2..af83a0347 100644 --- a/test/output/build/fetches/foo.html +++ b/test/output/build/fetches/foo.html @@ -23,7 +23,7 @@ registerFile("./foo/foo-data.json", {"name":"./foo/foo-data.json","mimeType":"application/json","path":"./_file/foo/foo-data.67358ed8.json","lastModified":/* ts */1706742000000,"size":10}); define({id: "47a695da", inputs: ["display"], outputs: ["fooJsonData","fooCsvData"], body: async (display) => { -const {fooJsonData, fooCsvData} = await import("./_import/foo/foo.666599bc.js"); +const {fooJsonData, fooCsvData} = await import("./_import/foo/foo.666599bc.js"/* observablehq-file */); display(fooJsonData); display(fooCsvData); diff --git a/test/output/build/fetches/top.html b/test/output/build/fetches/top.html index 9f8a0d89a..0b678f412 100644 --- a/test/output/build/fetches/top.html +++ b/test/output/build/fetches/top.html @@ -26,7 +26,7 @@ registerFile("./top-data.json", {"name":"./top-data.json","mimeType":"application/json","path":"./_file/top-data.67358ed8.json","lastModified":/* ts */1706742000000,"size":10}); define({id: "cb908c08", inputs: ["display"], outputs: ["fooCsvData","fooJsonData","topCsvData","topJsonData"], body: async (display) => { -const {fooCsvData, fooJsonData, topCsvData, topJsonData} = await import("./_import/top.c85e149a.js"); +const {fooCsvData, fooJsonData, topCsvData, topJsonData} = await import("./_import/top.c85e149a.js"/* observablehq-file */); display(fooJsonData); display(fooCsvData); diff --git a/test/output/build/imports/_import/bar/bar.4460ccc2.js b/test/output/build/imports/_import/bar/bar.4460ccc2.js index e1fd9bbee..efa40dafc 100644 --- a/test/output/build/imports/_import/bar/bar.4460ccc2.js +++ b/test/output/build/imports/_import/bar/bar.4460ccc2.js @@ -1 +1 @@ -export {bar} from "./baz.2add1dd0.js"; +export {bar} from "./baz.2add1dd0.js"/* observablehq-file */; diff --git a/test/output/build/imports/_import/bar/baz.2add1dd0.js b/test/output/build/imports/_import/bar/baz.2add1dd0.js index 1e2c35f80..b96bdc3ef 100644 --- a/test/output/build/imports/_import/bar/baz.2add1dd0.js +++ b/test/output/build/imports/_import/bar/baz.2add1dd0.js @@ -1,4 +1,4 @@ -import {foo} from "../foo/foo.bcd720b2.js"; +import {foo} from "../foo/foo.bcd720b2.js"/* observablehq-file */; export const bar = "bar"; export const foobar = foo + "bar"; diff --git a/test/output/build/imports/_import/foo/foo.bcd720b2.js b/test/output/build/imports/_import/foo/foo.bcd720b2.js index 1eb0af22a..2ac4e810a 100644 --- a/test/output/build/imports/_import/foo/foo.bcd720b2.js +++ b/test/output/build/imports/_import/foo/foo.bcd720b2.js @@ -1,7 +1,7 @@ -import "../../_npm/d3@7.8.5/cd372fb8.js"; -import "../../_npm/@example/url-import@1.0.0/1dd108c5.js"; -import {bar} from "../bar/bar.4460ccc2.js"; -export {top} from "../top.160847a6.js"; +import "../../_npm/d3@7.8.5/cd372fb8.js"/* observablehq-file */; +import "../../_npm/@example/url-import@1.0.0/1dd108c5.js"/* observablehq-file */; +import {bar} from "../bar/bar.4460ccc2.js"/* observablehq-file */; +export {top} from "../top.160847a6.js"/* observablehq-file */; export const foo = "foo"; export const foobar = "foo" + bar; diff --git a/test/output/build/imports/foo/foo.html b/test/output/build/imports/foo/foo.html index 2cae2575d..e32e2aa49 100644 --- a/test/output/build/imports/foo/foo.html +++ b/test/output/build/imports/foo/foo.html @@ -29,7 +29,7 @@ registerFile("./hello.txt", {"name":"./hello.txt","mimeType":"text/plain","path":"../_file/foo/hello.5891b5b5.txt","lastModified":/* ts */1706742000000,"size":6}); define({id: "261e010e", inputs: ["display","FileAttachment"], outputs: ["d3","bar","top"], body: async (display,FileAttachment) => { -const [d3, {bar}, {top}] = await Promise.all([import("../_npm/d3@7.8.5/cd372fb8.js"), import("../_import/bar/bar.4460ccc2.js"), import("../_import/top.160847a6.js")]); +const [d3, {bar}, {top}] = await Promise.all([import("../_npm/d3@7.8.5/cd372fb8.js"/* observablehq-file */), import("../_import/bar/bar.4460ccc2.js"/* observablehq-file */), import("../_import/top.160847a6.js"/* observablehq-file */)]); display(bar); display(top); @@ -38,7 +38,7 @@ }}); define({id: "ec24b17a", inputs: ["display"], outputs: ["foobar"], body: async (display) => { -const {foobar} = await import("./foo%20bar.js"); +const {foobar} = await import("./foo%20bar.js"/* observablehq-file */); display(foobar); return {foobar}; }}); diff --git a/test/output/build/jsr/_jsr/@std/random@0.1.0/integer_between.4528767d.js b/test/output/build/jsr/_jsr/@std/random@0.1.0/integer_between.4528767d.js index 3f00f1eb9..9ee5c2c70 100644 --- a/test/output/build/jsr/_jsr/@std/random@0.1.0/integer_between.4528767d.js +++ b/test/output/build/jsr/_jsr/@std/random@0.1.0/integer_between.4528767d.js @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { randomBetween } from "./between.2ce008c6.js"; +import { randomBetween } from "./between.2ce008c6.js"/* observablehq-file */; /** * Generates a random integer between the provided minimum and maximum values. * diff --git a/test/output/build/jsr/_jsr/@std/random@0.1.0/mod.e50195f4.js b/test/output/build/jsr/_jsr/@std/random@0.1.0/mod.e50195f4.js index a36b4b4b1..f03047af1 100644 --- a/test/output/build/jsr/_jsr/@std/random@0.1.0/mod.e50195f4.js +++ b/test/output/build/jsr/_jsr/@std/random@0.1.0/mod.e50195f4.js @@ -16,8 +16,8 @@ * @experimental **UNSTABLE**: New API, yet to be vetted. * * @module - */ export * from "./between.2ce008c6.js"; -export * from "./integer_between.4528767d.js"; -export * from "./sample.6e7cf133.js"; -export * from "./seeded.4e59f274.js"; -export * from "./shuffle.0ef8dd95.js"; + */ export * from "./between.2ce008c6.js"/* observablehq-file */; +export * from "./integer_between.4528767d.js"/* observablehq-file */; +export * from "./sample.6e7cf133.js"/* observablehq-file */; +export * from "./seeded.4e59f274.js"/* observablehq-file */; +export * from "./shuffle.0ef8dd95.js"/* observablehq-file */; diff --git a/test/output/build/jsr/_jsr/@std/random@0.1.0/sample.6e7cf133.js b/test/output/build/jsr/_jsr/@std/random@0.1.0/sample.6e7cf133.js index c0e30e7d1..537642129 100644 --- a/test/output/build/jsr/_jsr/@std/random@0.1.0/sample.6e7cf133.js +++ b/test/output/build/jsr/_jsr/@std/random@0.1.0/sample.6e7cf133.js @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { randomIntegerBetween } from "./integer_between.4528767d.js"; +import { randomIntegerBetween } from "./integer_between.4528767d.js"/* observablehq-file */; /** * Returns a random element from the given array. * diff --git a/test/output/build/jsr/_jsr/@std/random@0.1.0/seeded.4e59f274.js b/test/output/build/jsr/_jsr/@std/random@0.1.0/seeded.4e59f274.js index 68112d183..b2b137ea9 100644 --- a/test/output/build/jsr/_jsr/@std/random@0.1.0/seeded.4e59f274.js +++ b/test/output/build/jsr/_jsr/@std/random@0.1.0/seeded.4e59f274.js @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { fromSeed, nextU32, seedFromU64 } from "./_pcg32.b2f4838f.js"; +import { fromSeed, nextU32, seedFromU64 } from "./_pcg32.b2f4838f.js"/* observablehq-file */; /** * Creates a pseudo-random number generator that generates random numbers in * the range `[0, 1)`, based on the given seed. The algorithm used for diff --git a/test/output/build/jsr/_jsr/@std/random@0.1.0/shuffle.0ef8dd95.js b/test/output/build/jsr/_jsr/@std/random@0.1.0/shuffle.0ef8dd95.js index 07667ead1..ab581ace4 100644 --- a/test/output/build/jsr/_jsr/@std/random@0.1.0/shuffle.0ef8dd95.js +++ b/test/output/build/jsr/_jsr/@std/random@0.1.0/shuffle.0ef8dd95.js @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { randomIntegerBetween } from "./integer_between.4528767d.js"; +import { randomIntegerBetween } from "./integer_between.4528767d.js"/* observablehq-file */; /** * Shuffles the provided array, returning a copy and without modifying the original array. * diff --git a/test/output/build/jsr/index.html b/test/output/build/jsr/index.html index 3d6e5617b..641b4ab8b 100644 --- a/test/output/build/jsr/index.html +++ b/test/output/build/jsr/index.html @@ -25,7 +25,7 @@ import {define} from "./_observablehq/client.00000001.js"; define({id: "0e3025ad", inputs: ["display"], outputs: ["randomIntegerBetween","randomSeeded","prng"], body: async (display) => { -const {randomIntegerBetween, randomSeeded} = await import("./_jsr/@std/random@0.1.0/mod.e50195f4.js"); +const {randomIntegerBetween, randomSeeded} = await import("./_jsr/@std/random@0.1.0/mod.e50195f4.js"/* observablehq-file */); const prng = randomSeeded(1n); diff --git a/test/output/build/npm/_import/index.4bdc071f.js b/test/output/build/npm/_import/index.4bdc071f.js index 108b15a25..ef6c282e3 100644 --- a/test/output/build/npm/_import/index.4bdc071f.js +++ b/test/output/build/npm/_import/index.4bdc071f.js @@ -1 +1 @@ -import "../_observablehq/stdlib/inputs.00000005.js"; +import "../_observablehq/stdlib/inputs.00000005.js"/* observablehq-file */; diff --git a/test/output/build/npm/index.html b/test/output/build/npm/index.html index 64771f980..627cdd1a2 100644 --- a/test/output/build/npm/index.html +++ b/test/output/build/npm/index.html @@ -23,7 +23,7 @@ import {define} from "./_observablehq/client.00000001.js"; define({id: "0e31b7ef", body: async () => { -const {} = await import("./_import/index.4bdc071f.js"); +const {} = await import("./_import/index.4bdc071f.js"/* observablehq-file */); }}); diff --git a/test/output/build/typescript/index.html b/test/output/build/typescript/index.html index 6365f5ee7..001bf84a9 100644 --- a/test/output/build/typescript/index.html +++ b/test/output/build/typescript/index.html @@ -35,7 +35,7 @@ }}); define({id: "5a5e524f", outputs: ["sum"], body: async () => { -const {sum} = await import("./_import/sum.fd55756b.js"); +const {sum} = await import("./_import/sum.fd55756b.js"/* observablehq-file */); return {sum}; }}); diff --git a/test/output/imports/alias-import.js b/test/output/imports/alias-import.js index 825af323d..5c07e249f 100644 --- a/test/output/imports/alias-import.js +++ b/test/output/imports/alias-import.js @@ -1,5 +1,5 @@ define({id: "0", inputs: ["display"], outputs: ["bar"], body: async (display) => { -const {foo: bar} = await import("./_import/bar.js"); +const {foo: bar} = await import("./_import/bar.js"/* observablehq-file */); display(bar); return {bar}; diff --git a/test/output/imports/empty-import.js b/test/output/imports/empty-import.js index fd48a299d..e51b01ce0 100644 --- a/test/output/imports/empty-import.js +++ b/test/output/imports/empty-import.js @@ -1,4 +1,4 @@ define({id: "0", body: async () => { -const {} = await import("./_import/bar.js"); +const {} = await import("./_import/bar.js"/* observablehq-file */); }}); diff --git a/test/output/imports/local-fetch-from-import.js b/test/output/imports/local-fetch-from-import.js index 96b63d240..8aaeaef8e 100644 --- a/test/output/imports/local-fetch-from-import.js +++ b/test/output/imports/local-fetch-from-import.js @@ -1,5 +1,5 @@ define({id: "0", inputs: ["display"], outputs: ["data"], body: async (display) => { -const {data} = await import("./_import/baz.js"); +const {data} = await import("./_import/baz.js"/* observablehq-file */); display(data); return {data}; diff --git a/test/output/imports/namespace-import.js b/test/output/imports/namespace-import.js index 9e746eac6..fdb50ac1d 100644 --- a/test/output/imports/namespace-import.js +++ b/test/output/imports/namespace-import.js @@ -1,5 +1,5 @@ define({id: "0", inputs: ["display"], outputs: ["bar"], body: async (display) => { -const bar = await import("./_import/bar.js"); +const bar = await import("./_import/bar.js"/* observablehq-file */); display(bar); return {bar}; diff --git a/test/output/imports/static-all-import.js b/test/output/imports/static-all-import.js index 54b21ac24..f846fedab 100644 --- a/test/output/imports/static-all-import.js +++ b/test/output/imports/static-all-import.js @@ -1,5 +1,5 @@ define({id: "0", outputs: ["foo","bar"], body: async () => { -const [{foo}, {bar}] = await Promise.all([import("./_import/foo.js"), import("./_import/bar.js")]); +const [{foo}, {bar}] = await Promise.all([import("./_import/foo.js"/* observablehq-file */), import("./_import/bar.js"/* observablehq-file */)]); foo() + bar(); return {foo,bar}; diff --git a/test/output/imports/static-import.js b/test/output/imports/static-import.js index aded43886..cd8bf6bd1 100644 --- a/test/output/imports/static-import.js +++ b/test/output/imports/static-import.js @@ -1,5 +1,5 @@ define({id: "0", inputs: ["display"], outputs: ["foo"], body: async (display) => { -const {foo} = await import("./_import/bar.js"); +const {foo} = await import("./_import/bar.js"/* observablehq-file */); display(foo); return {foo}; diff --git a/test/output/imports/transitive-static-import.js b/test/output/imports/transitive-static-import.js index 43f8c7cf3..c4f9e2f9b 100644 --- a/test/output/imports/transitive-static-import.js +++ b/test/output/imports/transitive-static-import.js @@ -1,5 +1,5 @@ define({id: "0", outputs: ["foo"], body: async () => { -const {foo} = await import("./_import/other/foo.js"); +const {foo} = await import("./_import/other/foo.js"/* observablehq-file */); return {foo}; }}); diff --git a/test/output/static-import-noent.js b/test/output/static-import-noent.js index 88878f0e3..4a6942d0e 100644 --- a/test/output/static-import-noent.js +++ b/test/output/static-import-noent.js @@ -1,5 +1,5 @@ define({id: "0", inputs: ["display"], outputs: ["foo"], body: async (display) => { -const {foo} = await import("./_import/noent.js"); +const {foo} = await import("./_import/noent.js"/* observablehq-file */); display(foo); return {foo};