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

Strict ES module semantics require using Object.defineProperty instead of Object.assign for module objects #26

Open
jgonggrijp opened this issue Sep 5, 2022 · 0 comments

Comments

@jgonggrijp
Copy link

Thanks for making power-assert possible!

I'm working on a project that uses power-assert together with karma, mocha, rollup and coffeescript. To make it all work together, I needed to make rollup the only preprocessor to karma, use the coffeescript plugin for rollup, and add power-assert support through the babel preset, which in turn I enabled through the babel plugin for rollup. Since everything needs to run in the browser, I'm also using rollup-plugin-node-polyfills, which ends up providing its own version of the Node.js standard assert module.

A consequence of this setup is that assert.ok et al end up being defined as getters of the assert module object. This means that these properties cannot simply be reassigned, even if you try to do this on an intermediate object that inherits the module through the prototype chain. Unfortunately, this is exactly what empower-core/index.js is trying to do on line 50. Fortunately, there is a straightforward alternative: use core-js's define helper instead, which was already imported in the module, anyway.

Using patch-package, I generated the following diff that solved my problem:

diff --git a/node_modules/empower-core/index.js b/node_modules/empower-core/index.js
index e9118c7..8074a81 100644
--- a/node_modules/empower-core/index.js
+++ b/node_modules/empower-core/index.js
@@ -47,7 +47,8 @@ function empowerAssertObject (assertObject, options) {
     var config = assign(defaultOptions(), options);
     var target = config.destructive ? assertObject : create(assertObject);
     var decorator = new Decorator(target, config);
-    return assign(target, decorator.enhancement());
+    define(target, decorator.enhancement());
+    return target;
 }
 
 function empowerAssertFunction (assertFunction, options) {

This issue body was partially generated by patch-package.

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