Skip to content

Migrate to ES Modules #17

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

Merged
merged 5 commits into from
Jul 30, 2018
Merged

Migrate to ES Modules #17

merged 5 commits into from
Jul 30, 2018

Conversation

59naga
Copy link
Contributor

@59naga 59naga commented Jul 30, 2018

Since I want to use your library from .mjs or babel, I use the one that adjusted the environment and released it as named-package @59naga/assert-diff.

yarn add -D eastern @59naga/assert-diff
node --experimental-modules test/index.mjs
#  ✓  strict diff deep equal (3 ms)
#
#  Eastern: 1 passing (21 ms)

This can be used as follows for .mjs or babel.

// test/index.mjs
import spec from 'eastern'
import { deepEqual } from '@59naga/assert-diff'

spec('strict diff deep equal', () => {
  deepEqual({a: 1}, {a: 1}, 'this should not fail')
})

.default is required as a disadvantage for commonjs.

var assert = require('@59naga/assert-diff').default
assert.deepEqual({a: 1}, {a: 1}, 'this should not fail')

@pihvi pihvi merged commit 885ac14 into pihvi:master Jul 30, 2018
@pihvi
Copy link
Owner

pihvi commented Jul 30, 2018

Thank you!

I released this as new major version 2.0.0. Can you confirm this is now working for you?

-Antti

@59naga
Copy link
Contributor Author

59naga commented Jul 30, 2018

Oh sorry, You need to run npm build before npm publish to generate code index.js for babel and commonjs 💯.

yarn add -D eastern assert-diff

# work!
node --experimental-modules test/index.mjs

# doesn't work...
node test/index.js
var assert = require('assert-diff').default // Error: Cannot find module 'assert-diff'
assert.deepEqual({a: 1}, {a: 1}, 'this should not fail')

@pihvi
Copy link
Owner

pihvi commented Jul 30, 2018

Right, thanks!

I have no idea of these new module exports or babel builds, so I'm very grateful for the help :)

I got the tests working now with mocha which is familiar to me. I have to look at that eastern module a bit more to understand it. But now the build is published in v. 2.0.1. Is this working for you?

@pihvi
Copy link
Owner

pihvi commented Jul 30, 2018

I restored the old index.js on the side of the index.mjs as the new code broke the old behavior promised by this library i.e. it is a drop-in replacement for package 'assert'. So by default it should work the same as 'assert'. Now it won't work for e.g. assert(true), but you must use assert.default(true) etc. so it's not a drop-in replacement anymore. Do you have an idea how the module exports could work in the new system as before so assert(true) could work without having to use require('assert-diff').default ?

@59naga
Copy link
Contributor Author

59naga commented Jul 30, 2018

Awesome, that works! 👍
If you continue to use mocha please see @std/esm

@59naga 59naga mentioned this pull request Jul 30, 2018
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

Successfully merging this pull request may close these issues.

2 participants