mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-08 20:58:24 +08:00
Breaking changes here https://github.com/mochajs/mocha/releases/tag/v8.0.0 seem fine. DISABLE_THIRD_PARTY_CHECK=Update Mocha Bug: chromium:1101784 Change-Id: Idc75c94f9a923e2b0ca13d1d1331540cb1c5d3a3 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2279830 Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Peter Marshall <petermarshall@chromium.org>
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const path = require('path');
|
|
const url = require('url');
|
|
|
|
const formattedImport = async file => {
|
|
if (path.isAbsolute(file)) {
|
|
return import(url.pathToFileURL(file));
|
|
}
|
|
return import(file);
|
|
};
|
|
|
|
exports.requireOrImport = async file => {
|
|
if (path.extname(file) === '.mjs') {
|
|
return formattedImport(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 formattedImport(file);
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
};
|
|
|
|
exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
|
|
for (const file of files) {
|
|
preLoadFunc(file);
|
|
const result = await exports.requireOrImport(path.resolve(file));
|
|
postLoadFunc(file, result);
|
|
}
|
|
};
|