Skip to content
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

Improve support for modular javascript runtimes #429

Merged
merged 3 commits into from
Jun 14, 2020
Merged

Improve support for modular javascript runtimes #429

merged 3 commits into from
Jun 14, 2020

Conversation

Avaq
Copy link
Member

@Avaq Avaq commented Jun 6, 2020

Motivation

In particular, I'd like Fluture to be easy to use with Deno, but other runtimes, such as modern browsers, should also benefit from these changes.

Changes

I've added a pre-release build step to create a modular bundle alongside the already existing script bundle. I've also updated the documentation to draw more attention to the existence of these bundles, mention usage in Deno, and lower the emphasis on using the CommonJS version.

@Avaq Avaq self-assigned this Jun 6, 2020
@codecov

This comment has been minimized.

README.md Outdated Show resolved Hide resolved
@Avaq
Copy link
Member Author

Avaq commented Jun 6, 2020

After some fiddling with file names, link locations, and TypeScript, it should now be possible for you to test this yourself:

  1. Install Deno
  2. Create a test.ts file with:
    import * as fl from 'https://cdn.jsdelivr.net/gh/fluture-js/Fluture@dist2/dist/module.js'
    fl.value (console.log) (fl.alt (fl.resolve (42)) (fl.resolve ('hi')))
  3. Run deno run test.ts
  4. Enjoy the type error, fix it, add something new, try it out, fix the bugs, create a business, etc.

@Avaq
Copy link
Member Author

Avaq commented Jun 6, 2020

Aside from downloading it over jsdelivr, you can also download it directly from the deno.land proxy: https://deno.land/x/gh:fluture-js:Fluture@dist2/dist/module.js

README.md Show resolved Hide resolved
Avaq added 3 commits June 7, 2020 20:38
This file can be consumed by any runtime that can load EcmaScript
modules. Most prominently, web browsers, and Deno. As a bonus, Deno or
other runtimes that support TypeScript will also see a reference for
where to download the typings.
I believe this was added by mistake when the TypeScript types were
introduced. I think it was probably copy pasted over from Tushar's
personal TypeScript overrides for the 'fluture' module.

It never caused any problems, because users have always been able to
import Fluture from the 'fluture' module. However, this changes with
Deno's dependency model.

This commit removes the module declaration wrapper around the TypeScript
types, forcing TypeScript to make the association with the relevant
module in a different way. In particular, TypeScript should now make the
association based either on the location of the file (when imported
using Node's require algorithm), or based on a <reference> directive,
such as the one used in dist/module.js.
@Avaq Avaq merged commit 8817493 into master Jun 14, 2020
@Avaq Avaq deleted the avaq/bundles branch June 14, 2020 08:36
Comment on lines +103 to +107
const getPackageName = function (file) {
return Future.node (function (done) { fs.readFile (file, 'utf8', done) })
.pipe (Future.chain (Future.encase (JSON.parse)))
.pipe (Future.map (function (x) { return x.name }))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little strange to see const alongside function expressions. Is there a reason to avoid arrow functions here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. You're right. This example was meant to illustrate what Fluture usage looks like in older runtimes. I guess I missed the const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants