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

Package published to npm (v1.1.1) does not attempt to optimise *any* files #2

Open
richardscarrott opened this issue Jun 28, 2020 · 0 comments

Comments

@richardscarrott
Copy link

TBH I can't find the exact code for [email protected] published to npm as there are no tags in this repo and it doesn't look like it's in the history, but whatever is published to npm does not optimise any files because it expects a file to be both .js and .mjs which obviously isn't possible:

function unsupported (filename) {
  const ext = extname(filename)
  return ext !== '.js' || ext !== '.mjs'
}

I expect it should be:

function unsupported (filename) {
  const ext = extname(filename)
  return ext !== '.js' && ext !== '.mjs'
}

With this in mind, what is the status of esx, are you using it in production via some other means (babel plugin)? Also, is there any plan to support the legacy context API by any chance?

Really interesting project BTW!

Full npm module here:

'use strict'
const convert = require('to-esx')
const Module = require('module')
const { extname } = require('path')
const { _compile } = Module.prototype
require('esx') //load esx into the cache
const esx = require.resolve('esx')

const preloaded = require.main === undefined

function unsupported (filename) {
  const ext = extname(filename)
  return ext !== '.js' || ext !== '.mjs'
}

function install (opts = {}) {
  const { exclude = () => false } = opts
  Module.prototype._compile = function (content, filename) {
    if (filename === esx || exclude(filename) || unsupported(filename)) {
      return _compile.call(this, content, filename)
    }
    try { 
      const converted = convert(content)
      return _compile.call(this, converted, filename)
    } catch (e) {
      console.log(e, filename, content)
    }
    return content
  }
  return module.exports
}

function restore () {
  Module.prototype._compile = _compile
  return module.exports
}

if (preloaded) install()

module.exports = { install, restore }
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

No branches or pull requests

1 participant