23 lines
684 B
TypeScript
23 lines
684 B
TypeScript
const Module = require('module');
|
|
const originalLoader = Module._load;
|
|
|
|
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
|
|
const mappings = JSON.parse(process.env.NX_MAPPINGS);
|
|
const keys = Object.keys(mappings);
|
|
const fileToRun = process.env.NX_FILE_TO_RUN;
|
|
|
|
Module._load = function (request, parent) {
|
|
if (!parent) return originalLoader.apply(this, arguments);
|
|
const match = keys.find((k) => request === k);
|
|
if (match) {
|
|
const newArguments = [...arguments];
|
|
newArguments[0] = mappings[match];
|
|
return originalLoader.apply(this, newArguments);
|
|
} else {
|
|
return originalLoader.apply(this, arguments);
|
|
}
|
|
};
|
|
|
|
dynamicImport(fileToRun);
|