Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Feature: Runtime loaders, transpilation at import time #96

Closed
GeoffreyBooth opened this issue May 19, 2018 · 6 comments
Closed

Feature: Runtime loaders, transpilation at import time #96

GeoffreyBooth opened this issue May 19, 2018 · 6 comments
Labels

Comments

@GeoffreyBooth
Copy link
Member

Just as we can do:

# app.coffee
require 'coffeescript/register'
{ slice } = require './pizza.coffee'

or

// app.js
require('babel/register');
const { slice } = require('./pizza.js');

we should be able to achieve the equivalent in ESM, e.g. import a CoffeeScript file or import a JavaScript file that requires transpilation. References: CoffeeScript register, babel-register.

Use case 4. Related to #82.

@ljharb
Copy link
Member

ljharb commented May 19, 2018

I’m not sure the first example works - you have to require the register module before you’re able to require or run coffeescript.

@GeoffreyBooth
Copy link
Member Author

@ljharb I didn’t flesh it out, but the first example works if run via coffee, as in coffee app.coffee. But it turns out that using that method means you don’t need register, so I guess you’re right in that sense. If the file were transpiled into app.js and then run via node app.js, you would need the register:

// app.js, transpiled from app.coffee above
var slice;

require('coffeescript/register');

({slice} = require('./pizza.coffee'));

@bmeck
Copy link
Member

bmeck commented May 23, 2018

@GeoffreyBooth to clarify, does this request require you to mutate the loader pipeline at runtime? If the loader needs to be declared somewhere outside of evaluation that does seem to fit this use case on a glance, but differs in workflow from your example (easier to analyze though).

@benjamingr
Copy link
Member

@bmeck from what I recall - loaders (declared via the CLI flag or package.json) are entirely sufficient in order to implement the feature requested here.

I'm not saying they are the solution we should adopt necessarily. Just that importing CoffeeScript or TypeScript could work this way.

@Janpot
Copy link

Janpot commented May 23, 2018

Also, if such loaders (as declared via the CLI flag or package.json) existed, wouldn't that mean you could write a loader that allows mutating the loader pipeline at runtime?

@GeoffreyBooth
Copy link
Member Author

does this request require you to mutate the loader pipeline at runtime?

@bmeck I don’t think that necessarily needs to happen at runtime, if the advent of loaders creates a new phase of code to be executed before app code and dependencies are evaluated. I guess ideally we would support either scenario? But I’m not sure it makes a difference.

It also depends on how loaders are defined and configured to be loaded. Currently, require('coffeescript/register') registers a file extension handler on CommonJS whenever that require line happens, and so any require lines for .coffee files need to happen afterward. That’s fine. I’m not sure how loaders would be configured or how Node would be told to load them; package.json and/or CLI flags? I don’t think it matters so much as the effect would be the same.

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

No branches or pull requests

5 participants