@typed/content-hash
Version:
Content hash a directory of HTML/JS/CSS files and other static assets
27 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fsReadDependencies = void 0;
const Env_1 = require("@typed/fp/Env");
const FxEnv_1 = require("@typed/fp/FxEnv");
const fs_1 = require("fs");
const logging_1 = require("../application/services/logging");
const fsReadFile_1 = require("./fsReadFile");
const sourceMapExt = '.map';
const supportSourceMap = (path, registry) => {
const sourceMapPath = path + sourceMapExt;
return registry.has(sourceMapPath) || (0, fs_1.existsSync)(sourceMapPath);
};
const fsReadDependencies = (directory, document) => (0, FxEnv_1.Do)(function* (_) {
yield* _((0, logging_1.debug)(`Reading dependencies of ${document.filePath}...`));
const { documentRegistry } = yield* _((0, Env_1.ask)());
const dependenciesToLookFor = document.dependencies.filter((dep) => dep.filePath.startsWith(directory));
const dependencies = yield* _((0, Env_1.zip)(dependenciesToLookFor.map((d) => documentRegistry.has(d.filePath)
? (0, Env_1.of)(documentRegistry.get(d.filePath))
: (0, fsReadFile_1.fsReadFile)(d.filePath, {
isBase64Encoded: true,
supportsSourceMaps: supportSourceMap(d.filePath, documentRegistry),
}))));
return dependencies;
});
exports.fsReadDependencies = fsReadDependencies;
//# sourceMappingURL=fsReadDependencies.js.map