-
Notifications
You must be signed in to change notification settings - Fork 75
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
Deno support #113
Comments
FWIW, this does work in deno: import {createElement} from 'https://unpkg.com/@bikeshaving/crank@0.1.4/esm/index.js'
import {renderer} from 'https://unpkg.com/@bikeshaving/crank@0.1.4/esm/html.js';
console.log(renderer.render(createElement('h1', {id: 'foo'}, 'Hello world'))); … but I believe it's not consuming the types (or even the sourcemaps) that way. |
You're going to love this: the best practice I can find is to write TSC-compatible TS ( Leadership!!! |
Yeah, I think the path forward is to do like above and use something like unpkg and import the esm js artifacts. (Note that you should be importing the files in the root for maximum compatibility in 0.2.0. In case you’re interested, I’m the author of the following issue asking for guidance (denoland/deno#3196) but there doesn’t seem to be much movement on that front. The problem is that typescript forces you to not specify file extensions, while deno forces you to, and it seems like they’re at an impasse about this. I personally would prefer to have explicit file extensions and never understood the TS team’s rationale behind not allowing it, but whatever. Something like this should work: /// <reference types="https://unpkg.com/@bikeshaving/crank@0.1.4/index.d.ts" />
import {createElement} from 'https://unpkg.com/@bikeshaving/crank@0.1.4/index.js'
/// <reference types="https://unpkg.com/@bikeshaving/crank@0.1.4/html.d.ts" />
import {renderer} from 'https://unpkg.com/@bikeshaving/crank@0.1.4/html.js'; I’m not sure if they changed the API for the 1.0 release though. Searching the deno docs/github for “triple slash directive” should give you the latest information. Thanks for looking into this stuff! Very curious about your thoughts on deno. I also think that the greenfield landscape of deno offers a huge opportunity in terms of evangelism, like if we can convince the deno community that Crank, and specifically its focus on async/generator functions is a perfect match for Deno’s API, which uses async iterators everywhere, we could jumpstart adoption. |
This page seems to have more information. It looks like triple slash references are what we are supposed to do on our end as library authors, while the deno-types comments are what library consumers do. |
I'm feeling pretty "meh" on deno 1.0.
|
haha this is nightmare fuel. I agree with all these points, but top-level await and a modern standard lib is kinda tempting. |
Funny you should mention it. Top-level await doesn't work in deno's REPL. denoland/deno#3700 TLA's just not ready yet. The V8 team is actively working on it. https://bugs.chromium.org/p/v8/issues/detail?id=9344 When they ship it, Node will use it, too. nodejs/node#31410 TLA is yet another area where deno's reach exceeded its grasp. What I feel like we learned from Node is that CLI JS has to stay one step behind the browsers. It's frustrating, because the browsers move so slowly, but getting out on the bleeding edge is just asking for incompatibility later down the road. IMO, the only safe way to get ahead of the browsers is transpilation. Everything else has to wait. As for modernizing the stdlib, I expect we'll see Node modernize its stdlib over time, e.g. |
The following almost works.
/** @jsx createElement */
// @deno-types="https://unpkg.com/@bikeshaving/crank@0.3.0/index.d.ts"
import {createElement} from "https://unpkg.com/@bikeshaving/crank@0.3.0/index.js";
// @deno-types="https://unpkg.com/@bikeshaving/crank@0.3.0/html.d.ts"
import {renderer} from "https://unpkg.com/@bikeshaving/crank@0.3.0/html.js";
console.log(renderer.render(<div>Hello world</div>, document.body));
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext", "dom"]
}
} command deno run -c tsconfig.json server.tsx I think the deno-types comment is kinda annoying and will see if we can get triple-slash reference comments in the d.ts files directly. The code throws the following error from the HTML module. [ERROR]: Invalid module name in augmentation. Module './index' resolves to an untyped module at 'https://unpkg.com/@bikeshaving/crank@0.3.0/index.js', which cannot be augmented.
declare module "./index" { There is this module augmentation issue in Deno (denoland/deno#6839), but I don’t think declaring modules based on relative/absolute path is robust in any sense. I think the best thing to do is to declare a Crank global module and use that (similar to the way TypeScript uses the JSX module). |
Crank officially supports deno as of 0.3.1. You can import it as follows via unpkg. /** @jsx createElement */
import {createElement} from "https://unpkg.com/@bikeshaving/crank@0.3.1/crank.js";
import {renderer} from "https://unpkg.com/@bikeshaving/crank@0.3.1/html.js";
console.log(renderer.render(<div>This is pretty cool</div>)); You need to make sure you add |
To repro:
Actual:
The text was updated successfully, but these errors were encountered: