@typed/content-hash
Version:
Content hash a directory of HTML/JS/CSS files and other static assets
24 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rewriteSourceMapUrls = void 0;
const Env_1 = require("@typed/fp/Env");
const FxEnv_1 = require("@typed/fp/FxEnv");
const function_1 = require("fp-ts/function");
const Option_1 = require("fp-ts/Option");
const logging_1 = require("../application/services/logging");
const getHashedPath_1 = require("./hashes/getHashedPath");
const rewriteDocumentContents_1 = require("./rewriteDocumentContents");
const rewriteSourceMapUrl_1 = require("./rewriteSourceMapUrl");
const rewriteSourceMapUrls = (hashLength, sourceMaps) => (0, FxEnv_1.Do)(function* (_) {
yield* _((0, logging_1.debug)(`Rewriting source-map URLs...`));
const env = yield* _((0, Env_1.ask)());
let documentRegistry = env.documentRegistry;
for (const document of documentRegistry.values()) {
if ((0, Option_1.isSome)(document.sourceMap)) {
documentRegistry = yield* _((0, function_1.pipe)((0, rewriteDocumentContents_1.rewriteDocumentContents)(document, (ms) => (0, rewriteSourceMapUrl_1.rewriteSourceMapUrl)(ms, (0, getHashedPath_1.getHashedPath)(document, documentRegistry, hashLength)), sourceMaps, true), (0, Env_1.useSome)({ documentRegistry })));
}
}
return documentRegistry;
});
exports.rewriteSourceMapUrls = rewriteSourceMapUrls;
//# sourceMappingURL=rewriteSourceMapUrls.js.map