Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Snapshotting CJS exports #36

Closed
bmeck opened this issue Aug 14, 2017 · 4 comments
Closed

Snapshotting CJS exports #36

bmeck opened this issue Aug 14, 2017 · 4 comments

Comments

@bmeck
Copy link

bmeck commented Aug 14, 2017

Dunno if this one has a sane solution without punching require('module').Module.prototype.load pretty hard...

https://github.com/nodejs/node-eps/blob/master/002-es-modules.md#491-es-will-not-honor-reassigning-moduleexports-after-evaluation

// entry.js

require('@std/esm');
require('./mutates');
global.incr();
require('./a')
// a.mjs
import assert from 'assert';
import v from './mutates';
assert.strictEqual(v, 1);
// mutates.js
global.incr = () => module.exports++;
module.exports = 1;
@jdalton
Copy link
Member

jdalton commented Aug 14, 2017

Thanks @bmeck!

We'll need to add a test for this for sure.

@jdalton
Copy link
Member

jdalton commented Aug 15, 2017

Ok checking back, we seem to snapshot appropriately when running within the hook. The example presented above is running in the bridge file which is before rules can be imposed. I'll be adding a round of unit tests over the next couple of days to solidify support.

@jdalton jdalton closed this as completed Aug 15, 2017
@bmeck
Copy link
Author

bmeck commented Aug 16, 2017

Different example not using the bridge file:

// a.mjs
import b from './b';
console.log('a', b); // prints 1
import('./c');
// b.js
module.exports = 1;
process.nextTick(()=>module.exports++);
// c.mjs
import b from './b';
console.log('c', b); // prints 2

@jdalton
Copy link
Member

jdalton commented Aug 16, 2017

Thanks! That's super interesting!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants