standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

Weird behavior around process.on('warning') and util.deprecate #775

Open isaacs opened 5 years ago

isaacs commented 5 years ago

Check this out, it's super weird!

'use strict';
const util = require('util');

const fn = () => {};

const deprecated1 = util.deprecate(fn, 'msg1');
const deprecated2 = util.deprecate(fn, 'msg2');

process.once('warning', msg => {
  console.error('first', msg)
  console.error('about to assign')
  process.once('warning', msg => console.error('second', msg))
  console.error('about to call')
  deprecated2()
})
console.error('about to call')
deprecated1()

Without esm:

$ node d.js
about to call
(node:33121) DeprecationWarning: msg1
first { DeprecationWarning: msg1
    at Object.<anonymous> (/Users/isaacs/dev/js/tap/d.js:17:1)
    at Module._compile (internal/modules/cjs/loader.js:799:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
    at Module.load (internal/modules/cjs/loader.js:666:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
    at Function.Module._load (internal/modules/cjs/loader.js:598:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:862:12)
    at internal/main/run_main_module.js:21:11 name: 'DeprecationWarning' }
about to assign
about to call
(node:33121) DeprecationWarning: msg2
second { DeprecationWarning: msg2
    at process.once.msg (/Users/isaacs/dev/js/tap/d.js:14:3)
    at Object.onceWrapper (events.js:285:13)
    at process.emit (events.js:202:15)
    at internal/process/warning.js:82:13
    at processTicksAndRejections (internal/process/next_tick.js:74:9)
    at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:51:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:865:11)
    at internal/main/run_main_module.js:21:11 name: 'DeprecationWarning' }

With esm:

$ node -r esm d.js
about to call
first { DeprecationWarning: msg1
    at Object.<anonymous> (/Users/isaacs/dev/js/tap/d.js:17:1)
    at Object.<anonymous> (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:249808)
    at /Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:243656
    at Generator.next (<anonymous>)
    at yl (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:244014)
    at Pl (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:246261)
    at Object.u (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:286670)
    at Object.o (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:286067)
    at Object.<anonymous> (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:283809)
    at Object.apply (/Users/isaacs/dev/js/tap/node_modules/esm/esm.js:1:195695) name: 'DeprecationWarning' }
about to assign
about to call

Not sure what's going on there, just looks like it falls off a cliff, or never emits the warning, or something. Using esm@3.2.22.

isaacs commented 5 years ago

https://github.com/tapjs/node-tap/issues/528

isaacs commented 5 years ago

Is there anything that I can do to help move this forward? I'm not really sure where to even begin, tbh, but I'd be more than willing to help get to the root cause and get this fixed. Can you provide any pointers?