UNPKG

webpack-mock-server

Version:

Mocks api requests for webpack-dev-server with hot-replacement

39 lines (38 loc) 1.33 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); class CompilerOutRootFiles { constructor() { this.files = []; } update(rootNames, inDir, outDir) { let isChanged = false; if (!rootNames || !rootNames.length) { if (this.files.length) { isChanged = true; } this.files = []; } else { this.files.forEach((v, i) => { if (!rootNames.includes(v.rootName)) { isChanged = true; this.files.splice(i, 1); } }); rootNames.forEach((rootName) => { const ePath = rootName.replace(/([^.][^d])(\.ts)$/, "$1.js"); const outPath = path_1.default.join(outDir, path_1.default.relative(inDir, ePath)); if (!this.files.find((f) => f.path === outPath)) { isChanged = true; this.files.push({ path: outPath, rootName }); } }); } return isChanged; } } exports.default = CompilerOutRootFiles;