Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

import { createHook } from './hook.js'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const { createHook } = require('./hook.js')

const { initialize, load, resolve, getFormat, getSource } = createHook(import.meta)

Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/double-loader.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { readFile } from 'fs/promises'

export async function load (url, context, nextLoad) {
const result = await nextLoad(url, context)
if (!result.source && url.startsWith('file:')) {
result.source = await readFile(new URL(url))
}
return result
}
15 changes: 15 additions & 0 deletions test/other/double-loading.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

import { execSync } from 'child_process'
import { doesNotThrow } from 'assert'

const env = {
...process.env,
NODE_OPTIONS: '--no-warnings --experimental-loader ./test/fixtures/double-loader.mjs --experimental-loader ./hook.mjs'
}

doesNotThrow(() => {
execSync('node -p 0', { env })
})