-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to CJS for index, and remove enabled
CJS allows us to add hooks from CJS files synchronously. "enabled" is just too hard to properly track when accounting for CJS.
- Loading branch information
Showing
11 changed files
with
64 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
const { addHook } = require('../index.js') | ||
const { strictEqual } = require('assert') | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
const orig = exports.default | ||
exports.default = function bar() { | ||
return orig() + 15 | ||
} | ||
} | ||
}) | ||
|
||
;(async () => { | ||
const { default: barMjs } = await import('./fixtures/something.mjs') | ||
const { default: barJs } = await import('./fixtures/something.js') | ||
|
||
strictEqual(barMjs(), 57) | ||
strictEqual(barJs(), 57) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
const { addHook } = require('../index.js') | ||
const { strictEqual } = require('assert') | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
exports.foo += 15 | ||
} | ||
if (name.match('os')) { | ||
exports.freemem = () => 47 | ||
} | ||
}) | ||
|
||
;(async () => { | ||
const { foo: fooMjs } = await import('./fixtures/something.mjs') | ||
const { foo: fooJs } = await import('./fixtures/something.js') | ||
const { freemem } = await import('os') | ||
|
||
strictEqual(fooMjs, 57) | ||
strictEqual(fooJs, 57) | ||
strictEqual(freemem(), 47) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters