1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.createInfrastructure = void 0;
|
7 | const path_1 = __importDefault(require("path"));
|
8 | const cached_process_file_1 = require("./cached-process-file");
|
9 | const parser_1 = require("./parser");
|
10 | const stylable_processor_1 = require("./stylable-processor");
|
11 | const timed_cache_1 = require("./timed-cache");
|
12 | const module_resolver_1 = require("./module-resolver");
|
13 | function createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions = {}, resolveNamespace, timedCacheOptions, resolveModule = module_resolver_1.createDefaultResolver(fileSystem, resolveOptions), createDiagnostics) {
|
14 | let resolvePath = (context = projectRoot, moduleId) => {
|
15 | if (!path_1.default.isAbsolute(moduleId) && !moduleId.startsWith('.')) {
|
16 | moduleId = resolveModule(context, moduleId);
|
17 | }
|
18 | return moduleId;
|
19 | };
|
20 | if (timedCacheOptions) {
|
21 | const cacheManager = timed_cache_1.timedCache(resolvePath, {
|
22 | createKey: (args) => args.join(';'),
|
23 | ...timedCacheOptions,
|
24 | });
|
25 | resolvePath = cacheManager.get;
|
26 | }
|
27 | const fileProcessor = cached_process_file_1.cachedProcessFile((from, content) => {
|
28 | const resolvedFrom = resolvePath(projectRoot, from);
|
29 | return stylable_processor_1.process(parser_1.safeParse(content, { from: resolvedFrom }), createDiagnostics === null || createDiagnostics === void 0 ? void 0 : createDiagnostics(resolvedFrom), resolveNamespace);
|
30 | }, {
|
31 | readFileSync(resolvedPath) {
|
32 | return fileSystem.readFileSync(resolvedPath, 'utf8');
|
33 | },
|
34 | statSync(resolvedPath) {
|
35 | const stat = fileSystem.statSync(resolvedPath);
|
36 | if (!stat.mtime) {
|
37 | return {
|
38 | mtime: new Date(0),
|
39 | };
|
40 | }
|
41 | return stat;
|
42 | },
|
43 | readlinkSync() {
|
44 | throw new Error(`not implemented`);
|
45 | },
|
46 | }, (path, context) => resolvePath(context || projectRoot, path));
|
47 | if (onProcess) {
|
48 | fileProcessor.postProcessors.push(onProcess);
|
49 | }
|
50 | return {
|
51 | resolvePath,
|
52 | fileProcessor,
|
53 | };
|
54 | }
|
55 | exports.createInfrastructure = createInfrastructure;
|
56 |
|
\ | No newline at end of file |