test(508-1b 옛 헬퍼 공용 불러오기 7/7): 헬퍼 8 곳 loadTs 베낌 걷고 makeLoader 로

- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침
- 확인: 이 묶음 헬퍼를 쓰는 시험 70 개 전 70 통과 → 후 70 통과 (시험별 junit 대조 · 어긋남 0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 17:30:35 +09:00
co-authored by Claude Sonnet 5.5
parent fdd93cdb2d
commit c05a4ba798
8 changed files with 51 additions and 106 deletions
@@ -4,7 +4,7 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const B07 = path.join(__dirname, "..", "..", "B07_DesignDetail");
const calls = [];
@@ -36,14 +36,13 @@ global.localStorage = {
global.location = { reload: () => calls.push(["reload"]) };
global.document = { querySelectorAll: () => [] };
function loadTs(file) {
const js = ts.transpileModule(fs.readFileSync(file, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
new Function("exports", "module", "require", js)(box.exports, box, (r) => STUBS[r] ?? {});
return box.exports;
}
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
cache: false,
requireFor: (full) => {
return (r) => STUBS[r] ?? {};
},
});
const Save = loadTs(path.join(B07, "B07_DesignDetail_UI_Save.ts"));
@@ -3,27 +3,18 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const B05 = path.join(__dirname, "..", "..", "B05_Profile");
const STUBS = { "./B05_Profile_UI_RouteEdit_Input": { pickHover: () => null } };
const cache = new Map();
function loadTs(full) {
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) => {
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
requireFor: (full) => (request) => {
if (STUBS[request]) return STUBS[request];
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
},
});
/** 그린 것만 적는 가짜 캔버스 — 선 = moveTo/lineTo 점 · 점 = arc 가운데 · 획 색. */
function fakeContext() {
@@ -5,7 +5,7 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const B05 = path.join(__dirname, "..", "..", "B05_Profile");
const out = {};
@@ -94,25 +94,16 @@ const STUBS = {
],
},
};
const cache = new Map();
function loadTs(full) {
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) => {
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
requireFor: (full) => (request) => {
if (STUBS[request]) return STUBS[request];
if (request.startsWith("@ui/"))
return loadTs(path.join(B05, "..", "ui_template", `${request.slice(4)}.ts`));
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
},
});
/** 그린 것만 적는 가짜 캔버스 — 획 = 색 · 굵기 · 그때 옮긴 자리(translate) · 선 점. */
function fakeContext(canvas) {
+7 -11
View File
@@ -1,26 +1,22 @@
/* 403 곡선 창 하단 글 헬퍼 — `_Label.curveInfoText` 를 트랜스파일해 경우별 글을 JSON 으로 낸다. */
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const B05 = path.join(__dirname, "..", "..", "B05_Profile");
const STUBS = {
"@ui/ui_template_elements": { createButton: () => null },
"./B05_Profile_UI_Panel_Fields": { numberField: () => null, toggleButton: () => null },
};
function loadTs(full) {
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
const localRequire = (request) => {
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
cache: false,
requireFor: (full) => (request) => {
if (STUBS[request]) return STUBS[request];
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
return box.exports;
}
},
});
const { curveInfoText } = loadTs(path.join(B05, "B05_Profile_UI_RouteEdit_Label.ts"));
process.stdout.write(
@@ -5,7 +5,7 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const B05 = path.join(__dirname, "..", "..", "B05_Profile");
const out = {};
@@ -84,23 +84,14 @@ const STUBS = {
routeCrossSource: () => null,
},
};
const cache = new Map();
function loadTs(full) {
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) => {
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
requireFor: (full) => (request) => {
if (STUBS[request]) return STUBS[request];
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
},
});
const cross = loadTs(path.join(B05, "B05_Profile_UI_RouteEdit_Cross.ts"));
const station = (key, chainageM, kind, id = null) => ({ key, chainageM, kind, id });
+4 -17
View File
@@ -4,24 +4,11 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const cache = new Map();
function loadTs(file) {
const full = path.resolve(file);
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) => {
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
return box.exports;
}
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
});
const ground = loadTs(
path.join(__dirname, "..", "..", "B05_Profile", "logic", "B05_Profile_Grade_Ground.ts"),
+6 -15
View File
@@ -3,24 +3,15 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const cache = new Map();
function loadTs(file) {
const full = path.resolve(file);
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) =>
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
requireFor: (full) => (request) =>
request.startsWith(".")
? loadTs(path.join(path.dirname(full), `${request}.ts`))
: require(request);
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
return box.exports;
}
: require(request),
});
const align = loadTs(
path.join(__dirname, "..", "..", "B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.ts"),
+8 -9
View File
@@ -3,7 +3,7 @@
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const B07 = path.join(__dirname, "..", "..", "B07_DesignDetail");
const calls = [];
@@ -39,14 +39,13 @@ global.localStorage = { removeItem: (key) => calls.push(["drop", key]) };
global.location = { reload: () => calls.push(["reload"]) };
global.document = { querySelectorAll: () => [] };
function loadTs(file) {
const js = ts.transpileModule(fs.readFileSync(file, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
new Function("exports", "module", "require", js)(box.exports, box, (r) => STUBS[r] ?? {});
return box.exports;
}
const { loadTs } = makeLoader({
root: path.join(__dirname, "..", ".."),
cache: false,
requireFor: (full) => {
return (r) => STUBS[r] ?? {};
},
});
Save = loadTs(path.join(B07, "B07_DesignDetail_UI_Save.ts"));