mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-11-03 11:49:12 +08:00
None of the breaking changes listed in https://github.com/mochajs/mocha/releases/tag/v7.0.0 appear to be relevant for us. R=jacktfranklin@chromium.org DISABLE_THIRD_PARTY_CHECK=Update Mocha Bug: 1068145 Change-Id: I4aec1e775595a0cfcfaa307a8aad7fc9abad22ca Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2137392 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
32 lines
974 B
JavaScript
32 lines
974 B
JavaScript
const url = require('url');
|
|
const path = require('path');
|
|
|
|
const requireOrImport = async file => {
|
|
file = path.resolve(file);
|
|
|
|
if (path.extname(file) === '.mjs') {
|
|
return import(url.pathToFileURL(file));
|
|
}
|
|
// This is currently the only known way of figuring out whether a file is CJS or ESM.
|
|
// If Node.js or the community establish a better procedure for that, we can fix this code.
|
|
// Another option here would be to always use `import()`, as this also supports CJS, but I would be
|
|
// wary of using it for _all_ existing test files, till ESM is fully stable.
|
|
try {
|
|
return require(file);
|
|
} catch (err) {
|
|
if (err.code === 'ERR_REQUIRE_ESM') {
|
|
return import(url.pathToFileURL(file));
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
};
|
|
|
|
exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
|
|
for (const file of files) {
|
|
preLoadFunc(file);
|
|
const result = await requireOrImport(file);
|
|
postLoadFunc(file, result);
|
|
}
|
|
};
|