ts-checker-rspack-plugin 1.1.7 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +69 -22
  2. package/lib/getDependenciesWorker.js +652 -0
  3. package/lib/getIssuesWorker.js +1095 -0
  4. package/lib/index.js +972 -4
  5. package/lib/issue/issue-config.d.ts +2 -0
  6. package/lib/issue/issue-options.d.ts +2 -0
  7. package/lib/issue/issue-severity.d.ts +4 -4
  8. package/lib/plugin-state.d.ts +0 -1
  9. package/lib/plugin.d.ts +1 -1
  10. package/lib/rpc/rpc-worker.d.ts +0 -1
  11. package/lib/rpc/wrap-rpc.d.ts +0 -1
  12. package/lib/typescript/worker/get-issues-worker.d.ts +2 -2
  13. package/lib/typescript/worker/lib/config.d.ts +2 -2
  14. package/lib/typescript/worker/lib/diagnostics.d.ts +3 -3
  15. package/lib/typescript/worker/lib/file-system/file-system.d.ts +0 -1
  16. package/lib/utils/async/abort-error.d.ts +0 -1
  17. package/lib/utils/async/pool.d.ts +0 -1
  18. package/lib/watch/watch-file-system.d.ts +0 -1
  19. package/package.json +12 -11
  20. package/lib/files-change.js +0 -57
  21. package/lib/files-match.js +0 -2
  22. package/lib/formatter/basic-formatter.js +0 -13
  23. package/lib/formatter/code-frame-formatter.js +0 -32
  24. package/lib/formatter/formatter-config.js +0 -36
  25. package/lib/formatter/formatter-options.js +0 -2
  26. package/lib/formatter/formatter.js +0 -2
  27. package/lib/formatter/index.js +0 -22
  28. package/lib/formatter/stats-formatter.js +0 -30
  29. package/lib/formatter/types/babel__code-frame.js +0 -7
  30. package/lib/formatter/webpack-formatter.js +0 -32
  31. package/lib/hooks/intercept-done-to-get-dev-server-tap.js +0 -18
  32. package/lib/hooks/tap-after-compile-to-add-dependencies.js +0 -59
  33. package/lib/hooks/tap-after-compile-to-get-issues.js +0 -43
  34. package/lib/hooks/tap-after-environment-to-patch-watching.js +0 -22
  35. package/lib/hooks/tap-done-to-async-get-issues.js +0 -74
  36. package/lib/hooks/tap-error-to-log-message.js +0 -32
  37. package/lib/hooks/tap-start-to-run-workers.js +0 -122
  38. package/lib/hooks/tap-stop-to-terminate-workers.js +0 -26
  39. package/lib/infrastructure-logger.js +0 -14
  40. package/lib/issue/index.js +0 -19
  41. package/lib/issue/issue-config.js +0 -29
  42. package/lib/issue/issue-location.js +0 -22
  43. package/lib/issue/issue-match.js +0 -20
  44. package/lib/issue/issue-options.js +0 -2
  45. package/lib/issue/issue-position.js +0 -16
  46. package/lib/issue/issue-predicate.js +0 -11
  47. package/lib/issue/issue-severity.js +0 -12
  48. package/lib/issue/issue-webpack-error.js +0 -31
  49. package/lib/issue/issue.js +0 -41
  50. package/lib/logger.js +0 -2
  51. package/lib/plugin-config.js +0 -26
  52. package/lib/plugin-hooks.js +0 -45
  53. package/lib/plugin-options.js +0 -2
  54. package/lib/plugin-pools.js +0 -32
  55. package/lib/plugin-state.js +0 -17
  56. package/lib/plugin.js +0 -74
  57. package/lib/rpc/expose-rpc.js +0 -69
  58. package/lib/rpc/index.js +0 -12
  59. package/lib/rpc/rpc-error.js +0 -12
  60. package/lib/rpc/rpc-worker.js +0 -86
  61. package/lib/rpc/types.js +0 -2
  62. package/lib/rpc/wrap-rpc.js +0 -70
  63. package/lib/typescript/type-script-config-overwrite.js +0 -2
  64. package/lib/typescript/type-script-diagnostics-options.js +0 -2
  65. package/lib/typescript/type-script-support.js +0 -31
  66. package/lib/typescript/type-script-worker-config.js +0 -36
  67. package/lib/typescript/type-script-worker-options.js +0 -2
  68. package/lib/typescript/worker/get-dependencies-worker.js +0 -15
  69. package/lib/typescript/worker/get-issues-worker.js +0 -70
  70. package/lib/typescript/worker/lib/artifacts.js +0 -94
  71. package/lib/typescript/worker/lib/config.js +0 -162
  72. package/lib/typescript/worker/lib/dependencies.js +0 -84
  73. package/lib/typescript/worker/lib/diagnostics.js +0 -112
  74. package/lib/typescript/worker/lib/emit.js +0 -13
  75. package/lib/typescript/worker/lib/file-system/file-system.js +0 -2
  76. package/lib/typescript/worker/lib/file-system/mem-file-system.js +0 -81
  77. package/lib/typescript/worker/lib/file-system/passive-file-system.js +0 -68
  78. package/lib/typescript/worker/lib/file-system/real-file-system.js +0 -171
  79. package/lib/typescript/worker/lib/host/compiler-host.js +0 -17
  80. package/lib/typescript/worker/lib/host/watch-compiler-host.js +0 -32
  81. package/lib/typescript/worker/lib/host/watch-solution-builder-host.js +0 -53
  82. package/lib/typescript/worker/lib/performance.js +0 -29
  83. package/lib/typescript/worker/lib/program/program.js +0 -37
  84. package/lib/typescript/worker/lib/program/solution-builder.js +0 -39
  85. package/lib/typescript/worker/lib/program/watch-program.js +0 -51
  86. package/lib/typescript/worker/lib/system.js +0 -229
  87. package/lib/typescript/worker/lib/tracing.js +0 -27
  88. package/lib/typescript/worker/lib/tsbuildinfo.js +0 -96
  89. package/lib/typescript/worker/lib/typescript.js +0 -6
  90. package/lib/typescript/worker/lib/worker-config.js +0 -5
  91. package/lib/utils/async/abort-error.js +0 -15
  92. package/lib/utils/async/controlled-promise.js +0 -17
  93. package/lib/utils/async/is-pending.js +0 -10
  94. package/lib/utils/async/pool.js +0 -36
  95. package/lib/utils/async/wait.js +0 -7
  96. package/lib/utils/path/forward-slash.js +0 -15
  97. package/lib/utils/path/is-inside-another-path.js +0 -22
  98. package/lib/utils/path/relative-to-context.js +0 -16
  99. package/lib/watch/inclusive-node-watch-file-system.js +0 -183
  100. package/lib/watch/watch-file-system.js +0 -2
@@ -1,162 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.didRootFilesChanged = exports.didDependenciesProbablyChanged = exports.didConfigFileChanged = exports.getConfigFilePathFromBuilderProgram = exports.getConfigFilePathFromProgram = exports.getConfigFilePathFromCompilerOptions = exports.invalidateConfig = exports.parseNextConfig = exports.getParsedConfig = exports.getParseConfigIssues = exports.parseConfig = void 0;
27
- const path = __importStar(require("path"));
28
- const forward_slash_1 = require("../../../utils/path/forward-slash");
29
- const diagnostics_1 = require("./diagnostics");
30
- const system_1 = require("./system");
31
- const typescript_1 = require("./typescript");
32
- const worker_config_1 = require("./worker-config");
33
- let parsedConfig;
34
- let parseConfigDiagnostics = [];
35
- // initialize ParseConfigFileHost
36
- const parseConfigFileHost = {
37
- ...system_1.system,
38
- onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
39
- parseConfigDiagnostics.push(diagnostic);
40
- },
41
- };
42
- function getUserProvidedConfigOverwrite() {
43
- return worker_config_1.config.configOverwrite || {};
44
- }
45
- function getImplicitConfigOverwrite() {
46
- const baseCompilerOptionsOverwrite = {
47
- skipLibCheck: true,
48
- sourceMap: false,
49
- inlineSourceMap: false,
50
- };
51
- switch (worker_config_1.config.mode) {
52
- case 'write-dts':
53
- return {
54
- compilerOptions: {
55
- ...baseCompilerOptionsOverwrite,
56
- declaration: true,
57
- emitDeclarationOnly: true,
58
- noEmit: false,
59
- },
60
- };
61
- case 'write-tsbuildinfo':
62
- case 'write-references':
63
- return {
64
- compilerOptions: {
65
- ...baseCompilerOptionsOverwrite,
66
- declaration: true,
67
- emitDeclarationOnly: false,
68
- noEmit: false,
69
- },
70
- };
71
- }
72
- return {
73
- compilerOptions: baseCompilerOptionsOverwrite,
74
- };
75
- }
76
- function applyConfigOverwrite(baseConfig, ...overwriteConfigs) {
77
- let config = baseConfig;
78
- for (const overwriteConfig of overwriteConfigs) {
79
- config = {
80
- ...(config || {}),
81
- ...(overwriteConfig || {}),
82
- compilerOptions: {
83
- ...(config?.compilerOptions || {}),
84
- ...(overwriteConfig?.compilerOptions || {}),
85
- },
86
- };
87
- }
88
- return config;
89
- }
90
- function parseConfig(configFileName, configFileContext) {
91
- const configFilePath = (0, forward_slash_1.forwardSlash)(configFileName);
92
- const { config: baseConfig, error: readConfigError } = typescript_1.typescript.readConfigFile(configFilePath, parseConfigFileHost.readFile);
93
- const overwrittenConfig = applyConfigOverwrite(baseConfig || {}, getImplicitConfigOverwrite(), getUserProvidedConfigOverwrite());
94
- const parsedConfigFile = typescript_1.typescript.parseJsonConfigFileContent(overwrittenConfig, parseConfigFileHost, configFileContext);
95
- return {
96
- ...parsedConfigFile,
97
- options: {
98
- ...parsedConfigFile.options,
99
- configFilePath: configFilePath,
100
- },
101
- errors: readConfigError ? [readConfigError] : parsedConfigFile.errors,
102
- };
103
- }
104
- exports.parseConfig = parseConfig;
105
- function getParseConfigIssues() {
106
- const issues = (0, diagnostics_1.createIssuesFromDiagnostics)(parseConfigDiagnostics);
107
- issues.forEach((issue) => {
108
- if (!issue.file) {
109
- issue.file = worker_config_1.config.configFile;
110
- }
111
- });
112
- return issues;
113
- }
114
- exports.getParseConfigIssues = getParseConfigIssues;
115
- function getParsedConfig(force = false) {
116
- if (!parsedConfig || force) {
117
- parsedConfig = parseConfig(worker_config_1.config.configFile, worker_config_1.config.context);
118
- parseConfigDiagnostics = parsedConfig.errors || [];
119
- }
120
- return parsedConfig;
121
- }
122
- exports.getParsedConfig = getParsedConfig;
123
- function parseNextConfig() {
124
- const prevParsedConfig = parsedConfig;
125
- const nextParsedConfig = getParsedConfig(true);
126
- return [prevParsedConfig, nextParsedConfig];
127
- }
128
- exports.parseNextConfig = parseNextConfig;
129
- function invalidateConfig() {
130
- parsedConfig = undefined;
131
- parseConfigDiagnostics = [];
132
- }
133
- exports.invalidateConfig = invalidateConfig;
134
- function getConfigFilePathFromCompilerOptions(compilerOptions) {
135
- return compilerOptions.configFilePath;
136
- }
137
- exports.getConfigFilePathFromCompilerOptions = getConfigFilePathFromCompilerOptions;
138
- function getConfigFilePathFromProgram(program) {
139
- return getConfigFilePathFromCompilerOptions(program.getCompilerOptions());
140
- }
141
- exports.getConfigFilePathFromProgram = getConfigFilePathFromProgram;
142
- function getConfigFilePathFromBuilderProgram(builderProgram) {
143
- return getConfigFilePathFromCompilerOptions(builderProgram.getProgram().getCompilerOptions());
144
- }
145
- exports.getConfigFilePathFromBuilderProgram = getConfigFilePathFromBuilderProgram;
146
- function didConfigFileChanged({ changedFiles = [], deletedFiles = [] }) {
147
- return [...changedFiles, ...deletedFiles]
148
- .map((file) => path.normalize(file))
149
- .includes(path.normalize(worker_config_1.config.configFile));
150
- }
151
- exports.didConfigFileChanged = didConfigFileChanged;
152
- function didDependenciesProbablyChanged(dependencies, { changedFiles = [], deletedFiles = [] }) {
153
- const didSomeDependencyHasBeenAdded = changedFiles.some((changeFile) => !dependencies.files.includes(changeFile));
154
- const didSomeDependencyHasBeenDeleted = deletedFiles.some((deletedFile) => dependencies.files.includes(deletedFile));
155
- return didSomeDependencyHasBeenAdded || didSomeDependencyHasBeenDeleted;
156
- }
157
- exports.didDependenciesProbablyChanged = didDependenciesProbablyChanged;
158
- function didRootFilesChanged() {
159
- const [prevConfig, nextConfig] = parseNextConfig();
160
- return (prevConfig && JSON.stringify(prevConfig.fileNames) !== JSON.stringify(nextConfig.fileNames));
161
- }
162
- exports.didRootFilesChanged = didRootFilesChanged;
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.invalidateDependencies = exports.getDependencies = void 0;
27
- const path = __importStar(require("path"));
28
- const config_1 = require("./config");
29
- const typescript_1 = require("./typescript");
30
- const worker_config_1 = require("./worker-config");
31
- let dependencies;
32
- function getDependencies(force = false) {
33
- if (!dependencies || force) {
34
- const parsedConfig = (0, config_1.getParsedConfig)();
35
- dependencies = getDependenciesWorker(parsedConfig, worker_config_1.config.context);
36
- }
37
- return dependencies;
38
- }
39
- exports.getDependencies = getDependencies;
40
- function invalidateDependencies() {
41
- dependencies = undefined;
42
- }
43
- exports.invalidateDependencies = invalidateDependencies;
44
- function getDependenciesWorker(parsedConfig, configFileContext, processedConfigFiles = []) {
45
- const files = new Set(parsedConfig.fileNames);
46
- const configFilePath = parsedConfig.options.configFilePath;
47
- if (typeof configFilePath === 'string') {
48
- files.add(configFilePath);
49
- }
50
- const dirs = new Set(Object.keys(parsedConfig.wildcardDirectories || {}));
51
- const excluded = new Set((parsedConfig.raw?.exclude || []).map((filePath) => path.resolve(configFileContext, filePath)));
52
- for (const projectReference of parsedConfig.projectReferences || []) {
53
- const childConfigFilePath = typescript_1.typescript.resolveProjectReferencePath(projectReference);
54
- const childConfigContext = path.dirname(childConfigFilePath);
55
- if (processedConfigFiles.includes(childConfigFilePath)) {
56
- // handle circular dependencies
57
- continue;
58
- }
59
- const childParsedConfig = (0, config_1.parseConfig)(childConfigFilePath, childConfigContext);
60
- const childDependencies = getDependenciesWorker(childParsedConfig, childConfigContext, [
61
- ...processedConfigFiles,
62
- childConfigFilePath,
63
- ]);
64
- childDependencies.files.forEach((file) => {
65
- files.add(file);
66
- });
67
- childDependencies.dirs.forEach((dir) => {
68
- dirs.add(dir);
69
- });
70
- }
71
- const extensions = [
72
- typescript_1.typescript.Extension.Ts,
73
- typescript_1.typescript.Extension.Tsx,
74
- typescript_1.typescript.Extension.Js,
75
- typescript_1.typescript.Extension.Jsx,
76
- typescript_1.typescript.Extension.TsBuildInfo,
77
- ];
78
- return {
79
- files: Array.from(files).map((file) => path.normalize(file)),
80
- dirs: Array.from(dirs).map((dir) => path.normalize(dir)),
81
- excluded: Array.from(excluded).map((aPath) => path.normalize(aPath)),
82
- extensions: extensions,
83
- };
84
- }
@@ -1,112 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.createIssuesFromDiagnostics = exports.getDiagnosticsOfProgram = exports.invalidateDiagnostics = exports.getIssues = exports.updateDiagnostics = void 0;
27
- const os = __importStar(require("os"));
28
- const issue_1 = require("../../../issue");
29
- const typescript_1 = require("./typescript");
30
- const worker_config_1 = require("./worker-config");
31
- const diagnosticsPerConfigFile = new Map();
32
- function updateDiagnostics(configFile, diagnostics) {
33
- diagnosticsPerConfigFile.set(configFile, diagnostics);
34
- }
35
- exports.updateDiagnostics = updateDiagnostics;
36
- function getIssues() {
37
- const allDiagnostics = [];
38
- diagnosticsPerConfigFile.forEach((diagnostics) => {
39
- allDiagnostics.push(...diagnostics);
40
- });
41
- return createIssuesFromDiagnostics(allDiagnostics);
42
- }
43
- exports.getIssues = getIssues;
44
- function invalidateDiagnostics() {
45
- diagnosticsPerConfigFile.clear();
46
- }
47
- exports.invalidateDiagnostics = invalidateDiagnostics;
48
- function getDiagnosticsOfProgram(program) {
49
- const programDiagnostics = [];
50
- try {
51
- if (worker_config_1.config.diagnosticOptions.syntactic) {
52
- programDiagnostics.push(...program.getSyntacticDiagnostics());
53
- }
54
- if (worker_config_1.config.diagnosticOptions.global) {
55
- programDiagnostics.push(...program.getGlobalDiagnostics());
56
- }
57
- if (worker_config_1.config.diagnosticOptions.semantic) {
58
- programDiagnostics.push(...program.getSemanticDiagnostics());
59
- }
60
- if (worker_config_1.config.diagnosticOptions.declaration) {
61
- programDiagnostics.push(...program.getDeclarationDiagnostics());
62
- }
63
- }
64
- catch (e) {
65
- if (e instanceof Error) {
66
- programDiagnostics.push({
67
- code: 1,
68
- category: 1,
69
- messageText: `TSC compiler crashed: ${e.message}
70
- ${e.stack}`,
71
- file: undefined,
72
- start: undefined,
73
- length: undefined,
74
- });
75
- }
76
- }
77
- return programDiagnostics;
78
- }
79
- exports.getDiagnosticsOfProgram = getDiagnosticsOfProgram;
80
- function createIssueFromDiagnostic(diagnostic) {
81
- let file;
82
- let location;
83
- if (diagnostic.file) {
84
- file = diagnostic.file.fileName;
85
- if (diagnostic.start && diagnostic.length) {
86
- const { line: startLine, character: startCharacter } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
87
- const { line: endLine, character: endCharacter } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length);
88
- location = {
89
- start: {
90
- line: startLine + 1,
91
- column: startCharacter + 1,
92
- },
93
- end: {
94
- line: endLine + 1,
95
- column: endCharacter + 1,
96
- },
97
- };
98
- }
99
- }
100
- return {
101
- code: 'TS' + String(diagnostic.code),
102
- // we don't handle Suggestion and Message diagnostics
103
- severity: diagnostic.category === 0 ? 'warning' : 'error',
104
- message: typescript_1.typescript.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL),
105
- file,
106
- location,
107
- };
108
- }
109
- function createIssuesFromDiagnostics(diagnostics) {
110
- return (0, issue_1.deduplicateAndSortIssues)(diagnostics.map((diagnostic) => createIssueFromDiagnostic(diagnostic)));
111
- }
112
- exports.createIssuesFromDiagnostics = createIssuesFromDiagnostics;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emitDtsIfNeeded = void 0;
4
- const config_1 = require("./config");
5
- const worker_config_1 = require("./worker-config");
6
- function emitDtsIfNeeded(program) {
7
- const parsedConfig = (0, config_1.getParsedConfig)();
8
- if (worker_config_1.config.mode === 'write-dts' && parsedConfig.options.declaration) {
9
- // emit .d.ts files only
10
- program.emit(undefined, undefined, undefined, true);
11
- }
12
- }
13
- exports.emitDtsIfNeeded = emitDtsIfNeeded;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.memFileSystem = void 0;
4
- const path_1 = require("path");
5
- const memfs_1 = require("memfs");
6
- const real_file_system_1 = require("./real-file-system");
7
- /**
8
- * It's an implementation of FileSystem interface which reads and writes to the in-memory file system.
9
- */
10
- exports.memFileSystem = {
11
- ...real_file_system_1.realFileSystem,
12
- exists(path) {
13
- return exists(real_file_system_1.realFileSystem.realPath(path));
14
- },
15
- readFile(path, encoding) {
16
- return readFile(real_file_system_1.realFileSystem.realPath(path), encoding);
17
- },
18
- readDir(path) {
19
- return readDir(real_file_system_1.realFileSystem.realPath(path));
20
- },
21
- readStats(path) {
22
- return readStats(real_file_system_1.realFileSystem.realPath(path));
23
- },
24
- writeFile(path, data) {
25
- writeFile(real_file_system_1.realFileSystem.realPath(path), data);
26
- },
27
- deleteFile(path) {
28
- deleteFile(real_file_system_1.realFileSystem.realPath(path));
29
- },
30
- createDir(path) {
31
- createDir(real_file_system_1.realFileSystem.realPath(path));
32
- },
33
- updateTimes(path, atime, mtime) {
34
- updateTimes(real_file_system_1.realFileSystem.realPath(path), atime, mtime);
35
- },
36
- clearCache() {
37
- real_file_system_1.realFileSystem.clearCache();
38
- },
39
- };
40
- function exists(path) {
41
- return memfs_1.fs.existsSync(real_file_system_1.realFileSystem.normalizePath(path));
42
- }
43
- function readStats(path) {
44
- return exists(path) ? memfs_1.fs.statSync(real_file_system_1.realFileSystem.normalizePath(path)) : undefined;
45
- }
46
- function readFile(path, encoding) {
47
- const stats = readStats(path);
48
- if (stats && stats.isFile()) {
49
- return memfs_1.fs
50
- .readFileSync(real_file_system_1.realFileSystem.normalizePath(path), { encoding: encoding })
51
- .toString();
52
- }
53
- }
54
- function readDir(path) {
55
- const stats = readStats(path);
56
- if (stats && stats.isDirectory()) {
57
- return memfs_1.fs.readdirSync(real_file_system_1.realFileSystem.normalizePath(path), {
58
- withFileTypes: true,
59
- });
60
- }
61
- return [];
62
- }
63
- function createDir(path) {
64
- memfs_1.fs.mkdirSync(real_file_system_1.realFileSystem.normalizePath(path), { recursive: true });
65
- }
66
- function writeFile(path, data) {
67
- if (!exists((0, path_1.dirname)(path))) {
68
- createDir((0, path_1.dirname)(path));
69
- }
70
- memfs_1.fs.writeFileSync(real_file_system_1.realFileSystem.normalizePath(path), data);
71
- }
72
- function deleteFile(path) {
73
- if (exists(path)) {
74
- memfs_1.fs.unlinkSync(real_file_system_1.realFileSystem.normalizePath(path));
75
- }
76
- }
77
- function updateTimes(path, atime, mtime) {
78
- if (exists(path)) {
79
- memfs_1.fs.utimesSync(real_file_system_1.realFileSystem.normalizePath(path), atime, mtime);
80
- }
81
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.passiveFileSystem = void 0;
4
- const mem_file_system_1 = require("./mem-file-system");
5
- const real_file_system_1 = require("./real-file-system");
6
- /**
7
- * It's an implementation of FileSystem interface which reads from the real file system, but write to the in-memory file system.
8
- */
9
- exports.passiveFileSystem = {
10
- ...mem_file_system_1.memFileSystem,
11
- exists(path) {
12
- return exists(real_file_system_1.realFileSystem.realPath(path));
13
- },
14
- readFile(path, encoding) {
15
- return readFile(real_file_system_1.realFileSystem.realPath(path), encoding);
16
- },
17
- readDir(path) {
18
- return readDir(real_file_system_1.realFileSystem.realPath(path));
19
- },
20
- readStats(path) {
21
- return readStats(real_file_system_1.realFileSystem.realPath(path));
22
- },
23
- realPath(path) {
24
- return real_file_system_1.realFileSystem.realPath(path);
25
- },
26
- clearCache() {
27
- real_file_system_1.realFileSystem.clearCache();
28
- },
29
- };
30
- function exists(path) {
31
- return real_file_system_1.realFileSystem.exists(path) || mem_file_system_1.memFileSystem.exists(path);
32
- }
33
- function readFile(path, encoding) {
34
- const fsStats = real_file_system_1.realFileSystem.readStats(path);
35
- const memStats = mem_file_system_1.memFileSystem.readStats(path);
36
- if (fsStats && memStats) {
37
- return fsStats.mtimeMs > memStats.mtimeMs
38
- ? real_file_system_1.realFileSystem.readFile(path, encoding)
39
- : mem_file_system_1.memFileSystem.readFile(path, encoding);
40
- }
41
- else if (fsStats) {
42
- return real_file_system_1.realFileSystem.readFile(path, encoding);
43
- }
44
- else if (memStats) {
45
- return mem_file_system_1.memFileSystem.readFile(path, encoding);
46
- }
47
- }
48
- function readDir(path) {
49
- const fsDirents = real_file_system_1.realFileSystem.readDir(path);
50
- const memDirents = mem_file_system_1.memFileSystem.readDir(path);
51
- // merge list of dirents from fs and mem
52
- return fsDirents
53
- .filter((fsDirent) => !memDirents.some((memDirent) => memDirent.name === fsDirent.name))
54
- .concat(memDirents);
55
- }
56
- function readStats(path) {
57
- const fsStats = real_file_system_1.realFileSystem.readStats(path);
58
- const memStats = mem_file_system_1.memFileSystem.readStats(path);
59
- if (fsStats && memStats) {
60
- return fsStats.mtimeMs > memStats.mtimeMs ? fsStats : memStats;
61
- }
62
- else if (fsStats) {
63
- return fsStats;
64
- }
65
- else if (memStats) {
66
- return memStats;
67
- }
68
- }