Merged PR 2405: Representation Entry Policy discovery and wrapper

Related work items: #23754
This commit is contained in:
Robert Bond
2026-06-19 08:19:56 +00:00
parent 60a2ff4594
commit be68b987a1
4 changed files with 1054 additions and 116 deletions
@@ -47,6 +47,10 @@ module.exports = {
"getAvailableRepresentationTypes.js"
);
let domainSource = fs.readFileSync(domainFilePath, "utf8");
domainSource = domainSource.replace(
/import\s+\{\s*getAppealTypeFamily\s*\}\s+from\s+"\.\.\/appeal-type-policy";/,
'const { getAppealTypeFamily } = require("../appeal-type-policy");'
);
domainSource = domainSource.replace(
/export const\s+getAvailableRepresentationTypes\s*=/g,
"const getAvailableRepresentationTypes ="
@@ -57,7 +61,150 @@ module.exports = {
const domainContext = {
module: { exports: {} },
exports: {},
require,
require: (nestedModulePath) => {
if (nestedModulePath === "../appeal-type-policy") {
const appealTypePolicyPath = path.join(
rootDir,
"lib",
"domain",
"appeal-type-policy",
"index.js"
);
let appealTypePolicySource = fs.readFileSync(
appealTypePolicyPath,
"utf8"
);
appealTypePolicySource =
appealTypePolicySource.replace(
/export\s+\{\s*getAppealTypeFamily\s*\}\s+from\s+"\.\/getAppealTypeFamily";/,
'const { getAppealTypeFamily } = require("./getAppealTypeFamily");\nmodule.exports = { getAppealTypeFamily };'
);
const appealTypePolicyContext = {
module: { exports: {} },
exports: {},
require: (appealModulePath) => {
if (
appealModulePath ===
"./getAppealTypeFamily"
) {
const getAppealTypeFamilyPath =
path.join(
rootDir,
"lib",
"domain",
"appeal-type-policy",
"getAppealTypeFamily.js"
);
let getAppealTypeFamilySource =
fs.readFileSync(
getAppealTypeFamilyPath,
"utf8"
);
getAppealTypeFamilySource =
getAppealTypeFamilySource.replace(
/import\s+\{\s*mapAppealType\s*\}\s+from\s+"\.\.\/case-lifecycle\/mapAppealType";/,
'const { mapAppealType } = require("../case-lifecycle/mapAppealType");'
);
getAppealTypeFamilySource =
getAppealTypeFamilySource.replace(
/export function\s+getAppealTypeFamily\s*\(/,
"function getAppealTypeFamily("
);
getAppealTypeFamilySource +=
"\nmodule.exports = { getAppealTypeFamily };\n";
const getAppealTypeFamilyContext = {
module: { exports: {} },
exports: {},
require: (caseLifecyclePath) => {
if (
caseLifecyclePath ===
"../case-lifecycle/mapAppealType"
) {
const mapAppealTypePath =
path.join(
rootDir,
"lib",
"domain",
"case-lifecycle",
"mapAppealType.js"
);
let mapAppealTypeSource =
fs.readFileSync(
mapAppealTypePath,
"utf8"
);
mapAppealTypeSource =
mapAppealTypeSource.replace(
/export const\s+/g,
"const "
);
mapAppealTypeSource =
mapAppealTypeSource.replace(
/export function\s+mapAppealType\s*\(/,
"function mapAppealType("
);
mapAppealTypeSource +=
"\nmodule.exports = { caseTypeAliases, caseTypeKeyByAppealTypeId, normaliseCaseType, mapAppealType };\n";
const mapAppealTypeContext =
{
module: {
exports: {}
},
exports: {}
};
vm.runInNewContext(
mapAppealTypeSource,
mapAppealTypeContext,
{
filename:
mapAppealTypePath
}
);
return mapAppealTypeContext
.module.exports;
}
return require(
caseLifecyclePath
);
}
};
vm.runInNewContext(
getAppealTypeFamilySource,
getAppealTypeFamilyContext,
{
filename:
getAppealTypeFamilyPath
}
);
return getAppealTypeFamilyContext.module
.exports;
}
return require(appealModulePath);
}
};
vm.runInNewContext(
appealTypePolicySource,
appealTypePolicyContext,
{
filename: appealTypePolicyPath
}
);
return appealTypePolicyContext.module.exports;
}
return require(nestedModulePath);
},
Date
};