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

publish es5-compatible version on npm #6

Open
fczuardi opened this issue Mar 9, 2017 · 2 comments
Open

publish es5-compatible version on npm #6

fczuardi opened this issue Mar 9, 2017 · 2 comments

Comments

@fczuardi
Copy link

fczuardi commented Mar 9, 2017

Hi, thanks for the package.

I am using it as a dependency on a code that gets compressed using uglify-js, and as it is it doesnt support es6 and the process fail because of the let keyword and because the use of string literals `:

Errors:

Parse error at dist/www/bundle.js:38333,6
  let milli = Math.abs(isNaN(+t2) ? t1 : t2 - t1);
      ^
SyntaxError: Unexpected token: name (milli)
    at JS_Parse_Error.Object.defineProperty.get (eval at <anonymous> (/Users/fabricio/20k/road/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:86:23)
    at /Users/fabricio/20k/road/node_modules/uglify-js/bin/uglifyjs:384:39
    at time_it (/Users/fabricio/20k/road/node_modules/uglify-js/bin/uglifyjs:620:15)
    at /Users/fabricio/20k/road/node_modules/uglify-js/bin/uglifyjs:345:9
    at tryToString (fs.js:449:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436:12)
Parse error at dist/www/bundle.js:38354,9
  return `${n + (mode === 'short' ? '' : ' ')}${unit}${mode === 'short' || n ===
         ^
SyntaxError: Unexpected character '`'
    at JS_Parse_Error.Object.defineProperty.get (eval at <anonymous> (/Users/fabricio/20k/road/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:86:23)
    at /Users/fabricio/20k/road/node_modules/uglify-js/bin/uglifyjs:384:39
    at time_it (/Users/fabricio/20k/road/node_modules/uglify-js/bin/uglifyjs:620:15)
    at /Users/fabricio/20k/road/node_modules/uglify-js/bin/uglifyjs:345:9
    at tryToString (fs.js:449:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436:12)

Maybe we can either just replace those two lines with var and regular strings, or add a npm script to run the lib through babel with es2020 preset before publishing to npm.

I can create a PR for either option if you want :)

@fczuardi
Copy link
Author

fczuardi commented Mar 9, 2017

one workaround for people creating bundles with browserify is to use viralify to inject your es6 transform(es2020, es2040, babelify) in the package, something like this should work:

`yarn bin`/viralify . -t es2040 -p tiny-human-time

@danasilver
Copy link
Owner

Hi @fczuardi! Glad you're using Tiny Human Time!

Thanks for bring this to my attention. Sorry it took me a while to respond. It seems like publishing ES5 code to npm is still the norm. Since converting a few declarations and strings is pretty easy, there are no dependencies, and it'll be compatible with the newer Node versions we already support, I think we should convert to both ES5 source and published code (I would like to keep those the same).

If you're still up for it, I'd be happy to review a PR!

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

2 participants