-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
70 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import {isPathImport} from "../path.js"; | ||
|
||
const annotate = process.env["OBSERVABLE_ANNOTATE_FILES"]; | ||
if (annotate && annotate !== "true") throw new Error(`unsupported OBSERVABLE_ANNOTATE_FILES: ${annotate}`); | ||
|
||
/** Annotate a path to a local import or file so it can be reworked server-side. */ | ||
export const annotatePath = annotate | ||
? (uri: string) => `${JSON.stringify(uri)}${isPathImport(uri) ? "/* observablehq-file */" : ""}` | ||
: JSON.stringify; | ||
export function annotatePath(uri: string) { | ||
return `${JSON.stringify(uri)}${isPathImport(uri) ? "/* observablehq-file */" : ""}`; | ||
} |
2 changes: 0 additions & 2 deletions
2
test/javascript/annotate.ts → test/javascript/annotate-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]/_esm.js";'); | ||
assert.strictEqual(output, 'import "../_npm/[email protected]/_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/[email protected]/index.js";'); | ||
assert.strictEqual(output, 'import "../_node/[email protected]/index.js"/* observablehq-file */;'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]/dist/d3-array.js";\n', (v) => resolve("/_npm/[email protected]/dist/d3.js", v)), 'export * from "../../[email protected]/dist/d3-array.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('export * from "/npm/[email protected]/dist/d3-array.js";\n', (v) => resolve("/_npm/[email protected]/dist/d3.js", v)), 'export * from "../../[email protected]/dist/d3-array.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites /npm/…+esm imports to _esm.js", () => { | ||
assert.strictEqual(rewriteNpmImports('export * from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'export * from "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('export * from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'export * from "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites /npm/ imports to a relative path", () => { | ||
assert.strictEqual(rewriteNpmImports('import "/npm/[email protected]/dist/d3-array.js";\n', (v) => resolve("/_npm/[email protected]/dist/d3.js", v)), 'import "../../[email protected]/dist/d3-array.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('import "/npm/[email protected]/dist/d3-array.js";\n', (v) => resolve("/_npm/[email protected]/d3.js", v)), 'import "../[email protected]/dist/d3-array.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('import "/npm/[email protected]/dist/d3-array.js";\n', (v) => resolve("/_npm/[email protected]/dist/d3.js", v)), 'import "../../[email protected]/dist/d3-array.js"/* observablehq-file */;\n'); | ||
assert.strictEqual(rewriteNpmImports('import "/npm/[email protected]/dist/d3-array.js";\n', (v) => resolve("/_npm/[email protected]/d3.js", v)), 'import "../[email protected]/dist/d3-array.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites named imports", () => { | ||
assert.strictEqual(rewriteNpmImports('import {sort} from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import {sort} from "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('import {sort} from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import {sort} from "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites empty imports", () => { | ||
assert.strictEqual(rewriteNpmImports('import "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('import "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites default imports", () => { | ||
assert.strictEqual(rewriteNpmImports('import d3 from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import d3 from "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('import d3 from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import d3 from "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites namespace imports", () => { | ||
assert.strictEqual(rewriteNpmImports('import * as d3 from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import * as d3 from "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('import * as d3 from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import * as d3 from "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites named exports", () => { | ||
assert.strictEqual(rewriteNpmImports('export {sort} from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'export {sort} from "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('export {sort} from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'export {sort} from "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites namespace exports", () => { | ||
assert.strictEqual(rewriteNpmImports('export * from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'export * from "../[email protected]/_esm.js";\n'); | ||
assert.strictEqual(rewriteNpmImports('export * from "/npm/[email protected]/+esm";\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'export * from "../[email protected]/_esm.js"/* observablehq-file */;\n'); | ||
}); | ||
it("rewrites dynamic imports with static module specifiers", () => { | ||
assert.strictEqual(rewriteNpmImports('import("/npm/[email protected]/+esm");\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js");\n'); | ||
assert.strictEqual(rewriteNpmImports("import(`/npm/[email protected]/+esm`);\n", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js");\n'); | ||
assert.strictEqual(rewriteNpmImports("import('/npm/[email protected]/+esm');\n", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js");\n'); | ||
assert.strictEqual(rewriteNpmImports('import("/npm/[email protected]/+esm");\n', (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js"/* observablehq-file */);\n'); | ||
assert.strictEqual(rewriteNpmImports("import(`/npm/[email protected]/+esm`);\n", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js"/* observablehq-file */);\n'); | ||
assert.strictEqual(rewriteNpmImports("import('/npm/[email protected]/+esm');\n", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_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/[email protected]/_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/[email protected]/_esm.js", v)), "import(`/npm/d3-array@${version}/+esm`);\n"); | ||
}); | ||
it("strips the sourceMappingURL declaration", () => { | ||
assert.strictEqual(rewriteNpmImports("import(`/npm/[email protected]/+esm`);\n//# sourceMappingURL=index.js.map", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js");\n'); | ||
assert.strictEqual(rewriteNpmImports("import(`/npm/[email protected]/+esm`);\n//# sourceMappingURL=index.js.map\n", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js");\n'); | ||
assert.strictEqual(rewriteNpmImports("import(`/npm/[email protected]/+esm`);\n//# sourceMappingURL=index.js.map", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js"/* observablehq-file */);\n'); | ||
assert.strictEqual(rewriteNpmImports("import(`/npm/[email protected]/+esm`);\n//# sourceMappingURL=index.js.map\n", (v) => resolve("/_npm/[email protected]/_esm.js", v)), 'import("../[email protected]/_esm.js"/* observablehq-file */);\n'); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export {test} from "./test.86a60bc6.js"; | ||
export {test} from "./test.86a60bc6.js"/* observablehq-file */; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import {FileAttachment} from "../_observablehq/stdlib.00000003.js"; | ||
import * as Plot from "../_npm/@observablehq/[email protected]/cd372fb8.js"; | ||
import {FileAttachment} from "../_observablehq/stdlib.00000003.js"/* observablehq-file */; | ||
import * as Plot from "../_npm/@observablehq/[email protected]/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"}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import "./_observablehq/stdlib.00000003.js"; | ||
import "./_npm/@observablehq/[email protected]/cd372fb8.js"; | ||
import "./_npm/[email protected]/cd372fb8.js"; | ||
export * from "./_import/chart.2ce91e05.js"; | ||
import "./_observablehq/stdlib.00000003.js"/* observablehq-file */; | ||
import "./_npm/@observablehq/[email protected]/cd372fb8.js"/* observablehq-file */; | ||
import "./_npm/[email protected]/cd372fb8.js"/* observablehq-file */; | ||
export * from "./_import/chart.2ce91e05.js"/* observablehq-file */; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export {bar} from "./baz.2add1dd0.js"; | ||
export {bar} from "./baz.2add1dd0.js"/* observablehq-file */; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import "../../_npm/[email protected]/cd372fb8.js"; | ||
import "../../_npm/@example/[email protected]/1dd108c5.js"; | ||
import {bar} from "../bar/bar.4460ccc2.js"; | ||
export {top} from "../top.160847a6.js"; | ||
import "../../_npm/[email protected]/cd372fb8.js"/* observablehq-file */; | ||
import "../../_npm/@example/[email protected]/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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]/cd372fb8.js"), import("../_import/bar/bar.4460ccc2.js"), import("../_import/top.160847a6.js")]); | ||
const [d3, {bar}, {top}] = await Promise.all([import("../_npm/[email protected]/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}; | ||
}}); | ||
|
2 changes: 1 addition & 1 deletion
2
test/output/build/jsr/_jsr/@std/[email protected]/integer_between.4528767d.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/output/build/jsr/_jsr/@std/[email protected]/sample.6e7cf133.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.