UNPKG

1.71 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createConfig = createConfig;
7exports.addDevDependency = addDevDependency;
8exports.getInvalidations = getInvalidations;
9
10function createConfig({
11 isSource,
12 searchPath,
13 env,
14 resolvedPath,
15 result,
16 includedFiles,
17 watchGlob,
18 devDeps,
19 shouldRehydrate,
20 shouldReload,
21 shouldInvalidateOnStartup
22}) {
23 return {
24 isSource,
25 searchPath,
26 env,
27 resolvedPath,
28 result: result !== null && result !== void 0 ? result : null,
29 resultHash: null,
30 includedFiles: includedFiles !== null && includedFiles !== void 0 ? includedFiles : new Set(),
31 pkg: null,
32 watchGlob,
33 devDeps: devDeps !== null && devDeps !== void 0 ? devDeps : new Map(),
34 shouldRehydrate: shouldRehydrate !== null && shouldRehydrate !== void 0 ? shouldRehydrate : false,
35 shouldReload: shouldReload !== null && shouldReload !== void 0 ? shouldReload : false,
36 shouldInvalidateOnStartup: shouldInvalidateOnStartup !== null && shouldInvalidateOnStartup !== void 0 ? shouldInvalidateOnStartup : false
37 };
38}
39
40function addDevDependency(config, name, version) {
41 config.devDeps.set(name, version);
42} // TODO: start using edge types for more flexible invalidations
43
44
45function getInvalidations(config) {
46 let invalidations = [];
47
48 if (config.watchGlob != null) {
49 invalidations.push({
50 action: 'add',
51 pattern: config.watchGlob
52 });
53 }
54
55 for (let filePath of [config.resolvedPath, ...config.includedFiles]) {
56 invalidations.push({
57 action: 'change',
58 pattern: filePath
59 });
60 invalidations.push({
61 action: 'unlink',
62 pattern: filePath
63 });
64 }
65
66 return invalidations;
67}
\No newline at end of file