-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
annotate local paths #1731
annotate local paths #1731
Conversation
src/javascript/transpile.ts
Outdated
* Annotate a path to a local import or file so it can be reworked server-side. | ||
*/ | ||
function annotatePath(uri: string): string { | ||
return !uri.startsWith(".") || /(?:[.][/]|(?:[.][.][/])+)(_jsr|_node|_npm|_observablehq)[/]/.test(uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be isAssetPath
or whatever that’s ['./', '../', '/']
. Don’t want to match against .foo
.
Sorry for the delay. I plan to review this tomorrow. |
test/javascript/transpile-test.ts
Outdated
@@ -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 */;'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this link is tagged as observable-file
, then we should also rewrite it to tag Observable files in it. If we don't rewrite it, I don't think we should tag it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was initially doing that (see line 307 in 6cfb74d#diff-a479e6903ca67c840829983998e33849155911842cf08fa118b42b2d88fe3c9b), then I think we decided to tag everything and let the server decide what it should do with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that this is a reference to an _npm
file that is tagged, but references to _npm
files from other _npm
files are not tagged. As a concrete example, in the docs build there is this chain:
dist/chart.js
tags its import to the_import
file:docs/.observablehq/dist/_import/chart.95e875cf.js
tags its import of an_npm
file:docs/.observablehq/dist/_npm/@observablehq/[email protected]/e828d8c8.js
does not tag its import of the_npm
file:../../[email protected]/c68fbd73.js
It would be helpful if the tagging was done based on the taget of the URL, not the place the URL occurs. As it stands, the server can't really make the decision fully, because links to _npm
files aren't consistent tagged/not tagged, so it has to special case them as not needing extra authentication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work. Thanks!
@Fil is there anything more you want to do on this PR before merging it? It would be nice to have this in Framework's main branch for further development. |
Not on my side; I just wanted to give Mike a chance to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this to be always on, or do we only want to turn it on when building for Cloud? I’d slightly prefer the latter and believe that was what we proposed (via environment variable)?
Annotations are now conditioned on the |
We should probably make that |
Sure, or |
I'd prefer if all environment variables that need to be set in Cloud Builds begin with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting a few things I plan on fixing.
"test:mocha:serial": "yarn test:build && rimraf --glob test/.observablehq/cache test/input/build/*/.observablehq/cache && cross-env OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles mocha --timeout 30000 \"test/build/test/**/*-test.js\"", | ||
"test:mocha": "yarn test:build && rimraf --glob test/.observablehq/cache test/input/build/*/.observablehq/cache && cross-env OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles mocha --timeout 30000 -p \"test/build/test/**/*-test.js\" && yarn test:annotate", | ||
"test:mocha:serial": "yarn test:build && rimraf --glob test/.observablehq/cache test/input/build/*/.observablehq/cache && cross-env OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles mocha --timeout 30000 \"test/build/test/**/*-test.js\" && yarn test:annotate", | ||
"test:annotate": "yarn test:build && cross-env OBSERVABLE_ANNOTATE_FILES=true TZ=America/Los_Angeles mocha --timeout 30000 \"test/build/test/**/annotate.js\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern breaks yarn test:mocha:serial
with it.only
or describe.only
because it always runs the test:annotate
in addition to your only’d tests.
const annotate = process.env["OBSERVABLE_ANNOTATE_FILES"]; | ||
if (typeof annotate === "string" && annotate !== "true") | ||
throw new Error(`unsupported OBSERVABLE_ANNOTATE_FILES value: ${annotate}`); | ||
export default annotate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don’t use default exports (because there’s no real reason to, and it encourages more inconsistency in how people name an imported symbol). This should be called annotatePath
or something.
paths to local files in transpiled JavaScript modules are postfixed with a comment
For example, when building the documentation, we now have in docs/.observablehq/dist/_import/chart.95e875cf.js
in lieu of
The annotate.js scripts lists a few cases that can be annotated.