Innovenergy_trunk/frontend/node_modules/testcafe/lib/compiler/esm-loader.js

38 lines
5.0 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.load = void 0;
const api_based_1 = __importDefault(require("./test-file/api-based"));
const url_1 = __importDefault(require("url"));
const index_1 = __importDefault(require("./index"));
const setup_sourcemap_support_1 = require("../utils/setup-sourcemap-support");
function getFilenameFromURL(url) {
try {
return url_1.default.fileURLToPath(url);
}
catch (_) {
return null;
}
}
async function load(url, context, defaultLoad) {
const isNodeModulesDep = api_based_1.default._isNodeModulesDep(url);
const isTestcafeLibDep = api_based_1.default._isTestCafeLibDep(url);
const filename = getFilenameFromURL(url);
if (isNodeModulesDep || isTestcafeLibDep || !filename)
return defaultLoad(url, context, defaultLoad);
const testFilesInfo = await index_1.default.createTestFileInfo(filename);
if (testFilesInfo === null || testFilesInfo === void 0 ? void 0 : testFilesInfo.compiler) {
const [compiledCode] = await testFilesInfo.compiler.precompile([testFilesInfo]);
setup_sourcemap_support_1.fileContentsCache[url] = compiledCode;
return {
format: context.format || 'module',
source: compiledCode,
shortCircuit: true,
};
}
return defaultLoad(url, context, defaultLoad);
}
exports.load = load;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXNtLWxvYWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21waWxlci9lc20tbG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLHNFQUFpRTtBQUNqRSw4Q0FBMkI7QUFDM0Isb0RBQStCO0FBQy9CLDhFQUFxRTtBQWNyRSxTQUFTLGtCQUFrQixDQUFFLEdBQVc7SUFDcEMsSUFBSTtRQUNBLE9BQU8sYUFBUSxDQUFDLGFBQWEsQ0FBQyxHQUFHLEN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