Code Monkey home page Code Monkey logo

esm-middleware's People

Contributors

dependabot[bot] avatar fpipita avatar laggingreflex avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

laggingreflex

esm-middleware's Issues

Unresolved modules are removed

I have modules that I revolve dynamically, i.e. no file exists on disk for them to be loaded.

E.g.:

app.js:

import core from '/core'

While there's no file as "core" or "core.js", I resolve it dynamically:

server.js:

...
app.use(esm())
app.get('/core', (req, res) => {
   const core = getCore(...)
   res.send(core)
})

The problem is esm-middleware removes the entire line import core from '/core' from my app.js

I think it should give the user the choice not to remove any unresolved imports, like with an option: removeUnresolved: false

Windows error

Getting error on Windows:

SyntaxError: Invalid regular expression: /\/: \ at end of pattern
    at new RegExp (<anonymous>)
    at Object.<anonymous> (C:\...\node_modules\esm-middleware\src\babel-plugin-esm-resolver.js:11:33)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (C:\...\node_modules\esm-middleware\src\esm-middleware.js:5:27)

Looking at the source I believe the fix could be:

-const PATH_SEPARATOR_REPLACER = new RegExp(path.sep, "g");
+const IS_WIN = process.platform === "win32"
+const PATH_SEPARATOR_REPLACER = new RegExp(IS_WIN ? "\\\\" : path.sep, "g");

Also, is this open source? Never mind, I thought the source code wasn't available on github for some reason (got linked to Readme from npm and thought the repo was empty).

Great lib BTW!

docs: add TypeScript declarations

This would help consumers of this module to get started as typings would enable code completion and other nice development aids from their IDEs.

Allow loading static path ("client") without using a prefix ("/client")

I want to serve up my "client" folder (from the example) as the root, instead of "/client" prefix.

-app.use("/client", express.static(path.resolve("client")));
+app.use(express.static(path.resolve("client")));

This is a pretty standard practice, it's also used by express-generator

This currently doesn't seem to be possible.

Repro: https://github.com/laggingreflex/esm-middleware-clientdir

I think it should take an input for what might be the root for resolving req.url paths... (just like it does nodeModulesRoot)

feat: provide opt-in debugging tools

At the moment, all the code processed by the middleware is transformed and the original formatting is lost.

Although the produced code is decently formatted and readable, it would be nice to have an opt-in behavior which allowed to map the served code 1:1 with the original source code.

One solution could be to produce and serve source maps along with the transformed source files.

feat: improve support for cjs named exports

Given the npm package "bar" whose main entry is the module:

my-app/node_modules/bar/index.js

module.exports.foo = 'foo';

accessing the foo named export from our source code is only possible through the default export:

/my-app/src/app.js

import bar from "bar";
console.log(bar.foo) // prints "foo"

because only the default export is made available to consumers by the middleware when requesting pure cjs modules.

It would be nice if it was possible to access bar via an esm named import indeed:

/my-app/src/app.js

import { foo } from "bar";
console.log(foo) // prints "foo"

Loading modules without ".js" extension doesn't work

Sorry if I misread something or am using it wrong, but in the examples it says that I could do

import _ from "lodash";

But this doesn't seem to work.

In the sourcecode I see why:

    const mimeType = mime.lookup(req.originalUrl);

For "lodash" mimeType is always false.

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.