Coder Social home page Coder Social logo

cjs-es's People

Contributors

eight04 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jeremy-coleman

cjs-es's Issues

require(APP_ROOT + '/foo')

hey @eight04 ,

I guess there's no built-in way to require from a path relative to some pre-defined global app root in Node. There sure are a lot of userland npm modules for this. It might be nice to add support for something basic. My current thought is to just configure a pre-defined global [1]. This would allow cjs modules to work normally in node but also properly convert to es imports/exports.

Maybe there's nothing cjs-es can do here, i dunno.

For now, I can probably work around this by setting a global in Node and using a rollup/regex-replace plugin to swap APP_ROOT before passing it on to cjs-es.

[1] https://gist.github.com/branneman/8048520#3-the-global

Optimize nested module

function test() {
  module.exports();
}
module.exports = () => {};

to

function test() {
  _export_default_();
}
const _export_default_ = () => {};
export default _export_default_;

better hoist?

(module.exports = () => "foo").bar = true;

to

let _export_default_;
export default _export_default_;
(_export_default_ = () => "foo").bar = true;

Multiline var definition

Transform

var a = require("a"),
  b = require("b")

to

import * as a from "a";
import * as b from "b";
  • It only works if nested: true? or can we analyze the entire VariableDeclaration?

Idea: Add a way to invoke from cli

Hey there, have you thought about adding a cli entry point? Or is there already another package doing that?

Context: On the journey of making a library written in commonjs format also available in es module format, it would make sense to generate all the es modules from the commonjs modules (after every change).

I do not have a lot of experience on the topic, but I think using rollup for that would generate a single file, not multiple files, which is not what I would prefer.

Document nested option

code: a.js

require('./c');

if (true) {
  require('./a');
} else {
  require('./b');
}

function A () {
  console.log('hhhh');
}

module.exports = A;

and I use the below code to transform

const fs = require('fs');
const {parse} = require("acorn");
const {transform} = require("cjs-es");
const code = fs.readFileSync('./a.js', 'utf-8');
transform({code, parse})
  .then(result => {
    console.log(result.code);
  });

the result show that not working in if-else block
image

acorn: 8.0.4
cjs-es: 0.8.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.