@stylable/core
Version:
CSS for Components
56 lines • 2.38 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createInfrastructure = void 0;
const path_1 = __importDefault(require("path"));
const cached_process_file_1 = require("./cached-process-file");
const parser_1 = require("./parser");
const stylable_processor_1 = require("./stylable-processor");
const timed_cache_1 = require("./timed-cache");
const module_resolver_1 = require("./module-resolver");
const diagnostics_1 = require("./diagnostics");
function createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions = {}, resolveNamespace, timedCacheOptions, resolveModule = module_resolver_1.createDefaultResolver(fileSystem, resolveOptions), diagnostics = new diagnostics_1.Diagnostics()) {
let resolvePath = (context = projectRoot, moduleId) => {
if (!path_1.default.isAbsolute(moduleId) && !moduleId.startsWith('.')) {
moduleId = resolveModule(context, moduleId);
}
return moduleId;
};
if (timedCacheOptions) {
const cacheManager = timed_cache_1.timedCache(resolvePath, {
createKey: (args) => args.join(';'),
...timedCacheOptions,
});
resolvePath = cacheManager.get;
}
const fileProcessor = cached_process_file_1.cachedProcessFile((from, content) => {
return stylable_processor_1.process(parser_1.safeParse(content, { from: resolvePath(projectRoot, from) }), diagnostics, resolveNamespace);
}, {
readFileSync(resolvedPath) {
return fileSystem.readFileSync(resolvedPath, 'utf8');
},
statSync(resolvedPath) {
const stat = fileSystem.statSync(resolvedPath);
if (!stat.mtime) {
return {
mtime: new Date(0),
};
}
return stat;
},
readlinkSync() {
throw new Error(`not implemented`);
},
}, (path, context) => resolvePath(context || projectRoot, path));
if (onProcess) {
fileProcessor.postProcessors.push(onProcess);
}
return {
resolvePath,
fileProcessor,
};
}
exports.createInfrastructure = createInfrastructure;
//# sourceMappingURL=create-infra-structure.js.map
;