@spyglassmc/core 0.1.2 → 0.4.0

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 (205) hide show
  1. package/README.md +7 -0
  2. package/lib/browser.d.ts +2 -0
  3. package/lib/browser.js +2 -0
  4. package/lib/common/Dev.d.ts +11 -0
  5. package/lib/common/Dev.js +90 -0
  6. package/lib/{service → common}/Logger.d.ts +0 -0
  7. package/lib/{service → common}/Logger.js +2 -5
  8. package/lib/common/Operations.d.ts +12 -0
  9. package/lib/common/Operations.js +33 -0
  10. package/lib/common/ReadonlyProxy.d.ts +9 -0
  11. package/lib/common/ReadonlyProxy.js +23 -0
  12. package/lib/common/StateProxy.d.ts +35 -0
  13. package/lib/common/StateProxy.js +69 -0
  14. package/lib/common/TwoWayMap.js +4 -10
  15. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  16. package/lib/common/externals/BrowserExternals.js +191 -0
  17. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  18. package/lib/common/externals/NodeJsExternals.js +152 -0
  19. package/lib/common/externals/downloader.d.ts +31 -0
  20. package/lib/common/externals/downloader.js +32 -0
  21. package/lib/common/externals/index.d.ts +96 -0
  22. package/lib/common/externals/index.js +2 -0
  23. package/lib/common/index.d.ts +8 -1
  24. package/lib/common/index.js +8 -17
  25. package/lib/common/util.d.ts +48 -20
  26. package/lib/common/util.js +71 -86
  27. package/lib/index.d.ts +7 -7
  28. package/lib/index.js +7 -23
  29. package/lib/node/AstNode.d.ts +12 -11
  30. package/lib/node/AstNode.js +10 -16
  31. package/lib/node/BooleanNode.d.ts +2 -2
  32. package/lib/node/BooleanNode.js +4 -7
  33. package/lib/node/CommentNode.d.ts +6 -5
  34. package/lib/node/CommentNode.js +4 -9
  35. package/lib/node/ErrorNode.d.ts +1 -1
  36. package/lib/node/ErrorNode.js +2 -5
  37. package/lib/node/FileNode.d.ts +8 -4
  38. package/lib/node/FileNode.js +3 -6
  39. package/lib/node/FloatNode.d.ts +3 -3
  40. package/lib/node/FloatNode.js +4 -7
  41. package/lib/node/IntegerNode.d.ts +3 -3
  42. package/lib/node/IntegerNode.js +4 -7
  43. package/lib/node/ListNode.d.ts +2 -2
  44. package/lib/node/ListNode.js +2 -5
  45. package/lib/node/LiteralNode.d.ts +4 -4
  46. package/lib/node/LiteralNode.js +4 -7
  47. package/lib/node/LongNode.d.ts +3 -3
  48. package/lib/node/LongNode.js +4 -7
  49. package/lib/node/RecordNode.d.ts +2 -2
  50. package/lib/node/RecordNode.js +2 -5
  51. package/lib/node/ResourceLocationNode.d.ts +7 -7
  52. package/lib/node/ResourceLocationNode.js +9 -12
  53. package/lib/node/Sequence.d.ts +2 -2
  54. package/lib/node/Sequence.js +4 -7
  55. package/lib/node/StringNode.d.ts +5 -5
  56. package/lib/node/StringNode.js +9 -12
  57. package/lib/node/SymbolNode.d.ts +4 -4
  58. package/lib/node/SymbolNode.js +4 -7
  59. package/lib/node/index.d.ts +15 -15
  60. package/lib/node/index.js +15 -31
  61. package/lib/nodejs.d.ts +2 -0
  62. package/lib/nodejs.js +2 -0
  63. package/lib/parser/Parser.d.ts +3 -3
  64. package/lib/parser/Parser.js +1 -4
  65. package/lib/parser/boolean.d.ts +2 -2
  66. package/lib/parser/boolean.js +3 -6
  67. package/lib/parser/comment.d.ts +2 -2
  68. package/lib/parser/comment.js +5 -9
  69. package/lib/parser/empty.d.ts +1 -1
  70. package/lib/parser/empty.js +1 -5
  71. package/lib/parser/error.d.ts +2 -2
  72. package/lib/parser/error.js +5 -9
  73. package/lib/parser/file.d.ts +3 -3
  74. package/lib/parser/file.js +9 -13
  75. package/lib/parser/float.d.ts +4 -4
  76. package/lib/parser/float.js +12 -16
  77. package/lib/parser/index.d.ts +16 -16
  78. package/lib/parser/index.js +16 -38
  79. package/lib/parser/integer.d.ts +4 -4
  80. package/lib/parser/integer.js +10 -14
  81. package/lib/parser/list.d.ts +2 -2
  82. package/lib/parser/list.js +15 -19
  83. package/lib/parser/literal.d.ts +2 -2
  84. package/lib/parser/literal.js +5 -9
  85. package/lib/parser/long.d.ts +4 -4
  86. package/lib/parser/long.js +10 -14
  87. package/lib/parser/record.d.ts +3 -3
  88. package/lib/parser/record.js +20 -24
  89. package/lib/parser/resourceLocation.d.ts +2 -2
  90. package/lib/parser/resourceLocation.js +12 -24
  91. package/lib/parser/string.d.ts +7 -7
  92. package/lib/parser/string.js +36 -42
  93. package/lib/parser/symbol.d.ts +3 -3
  94. package/lib/parser/symbol.js +4 -14
  95. package/lib/parser/util.d.ts +6 -5
  96. package/lib/parser/util.js +40 -60
  97. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  98. package/lib/processor/ColorInfoProvider.js +6 -9
  99. package/lib/processor/InlayHintProvider.d.ts +4 -3
  100. package/lib/processor/InlayHintProvider.js +1 -2
  101. package/lib/processor/SignatureHelpProvider.d.ts +4 -3
  102. package/lib/processor/SignatureHelpProvider.js +1 -2
  103. package/lib/processor/binder/Binder.d.ts +26 -0
  104. package/lib/processor/binder/Binder.js +18 -0
  105. package/lib/processor/binder/builtin.d.ts +27 -0
  106. package/lib/processor/binder/builtin.js +116 -0
  107. package/lib/processor/binder/index.d.ts +3 -0
  108. package/lib/processor/binder/index.js +3 -0
  109. package/lib/processor/checker/Checker.d.ts +2 -2
  110. package/lib/processor/checker/Checker.js +1 -5
  111. package/lib/processor/checker/builtin.d.ts +4 -4
  112. package/lib/processor/checker/builtin.js +22 -33
  113. package/lib/processor/checker/index.d.ts +2 -2
  114. package/lib/processor/checker/index.js +2 -31
  115. package/lib/processor/colorizer/Colorizer.d.ts +6 -5
  116. package/lib/processor/colorizer/Colorizer.js +8 -11
  117. package/lib/processor/colorizer/builtin.d.ts +3 -3
  118. package/lib/processor/colorizer/builtin.js +34 -46
  119. package/lib/processor/colorizer/index.d.ts +2 -2
  120. package/lib/processor/colorizer/index.js +2 -31
  121. package/lib/processor/completer/Completer.d.ts +6 -5
  122. package/lib/processor/completer/Completer.js +14 -33
  123. package/lib/processor/completer/builtin.d.ts +10 -9
  124. package/lib/processor/completer/builtin.js +47 -63
  125. package/lib/processor/completer/index.d.ts +2 -2
  126. package/lib/processor/completer/index.js +2 -31
  127. package/lib/processor/formatter/Formatter.d.ts +4 -3
  128. package/lib/processor/formatter/Formatter.js +2 -7
  129. package/lib/processor/formatter/builtin.d.ts +3 -3
  130. package/lib/processor/formatter/builtin.js +22 -36
  131. package/lib/processor/formatter/index.d.ts +2 -2
  132. package/lib/processor/formatter/index.js +2 -31
  133. package/lib/processor/index.d.ts +10 -9
  134. package/lib/processor/index.js +10 -25
  135. package/lib/processor/linter/Linter.d.ts +4 -3
  136. package/lib/processor/linter/Linter.js +1 -2
  137. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  138. package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
  139. package/lib/processor/linter/builtin.d.ts +4 -3
  140. package/lib/processor/linter/builtin.js +19 -26
  141. package/lib/processor/linter/index.d.ts +2 -2
  142. package/lib/processor/linter/index.js +2 -31
  143. package/lib/processor/util.d.ts +4 -14
  144. package/lib/processor/util.js +1 -16
  145. package/lib/service/CacheService.d.ts +13 -8
  146. package/lib/service/CacheService.js +45 -57
  147. package/lib/service/Config.d.ts +11 -12
  148. package/lib/service/Config.js +50 -45
  149. package/lib/service/Context.d.ts +23 -20
  150. package/lib/service/Context.js +39 -36
  151. package/lib/service/Dependency.js +2 -5
  152. package/lib/service/Downloader.d.ts +9 -40
  153. package/lib/service/Downloader.js +37 -110
  154. package/lib/service/ErrorReporter.d.ts +2 -2
  155. package/lib/service/ErrorReporter.js +10 -14
  156. package/lib/service/FileService.d.ts +15 -14
  157. package/lib/service/FileService.js +55 -92
  158. package/lib/service/Hover.d.ts +2 -2
  159. package/lib/service/Hover.js +4 -7
  160. package/lib/service/MetaRegistry.d.ts +22 -12
  161. package/lib/service/MetaRegistry.js +81 -73
  162. package/lib/service/Profiler.d.ts +3 -2
  163. package/lib/service/Profiler.js +81 -45
  164. package/lib/service/Project.d.ts +105 -76
  165. package/lib/service/Project.js +449 -370
  166. package/lib/service/Service.d.ts +17 -27
  167. package/lib/service/Service.js +37 -43
  168. package/lib/service/SymbolLocations.d.ts +3 -3
  169. package/lib/service/SymbolLocations.js +4 -7
  170. package/lib/service/SymbolRegistrar.d.ts +1 -1
  171. package/lib/service/SymbolRegistrar.js +1 -2
  172. package/lib/service/UriProcessor.d.ts +5 -0
  173. package/lib/service/UriProcessor.js +2 -0
  174. package/lib/service/fileUtil.d.ts +15 -45
  175. package/lib/service/fileUtil.js +38 -143
  176. package/lib/service/index.d.ts +16 -17
  177. package/lib/service/index.js +16 -35
  178. package/lib/source/IndexMap.d.ts +1 -1
  179. package/lib/source/IndexMap.js +7 -10
  180. package/lib/source/LanguageError.d.ts +20 -6
  181. package/lib/source/LanguageError.js +16 -9
  182. package/lib/source/Location.d.ts +3 -3
  183. package/lib/source/Location.js +6 -9
  184. package/lib/source/Offset.d.ts +1 -1
  185. package/lib/source/Offset.js +4 -7
  186. package/lib/source/Position.js +2 -5
  187. package/lib/source/PositionRange.d.ts +3 -3
  188. package/lib/source/PositionRange.js +17 -20
  189. package/lib/source/Range.d.ts +1 -1
  190. package/lib/source/Range.js +7 -10
  191. package/lib/source/Source.d.ts +5 -3
  192. package/lib/source/Source.js +34 -29
  193. package/lib/source/index.d.ts +8 -8
  194. package/lib/source/index.js +8 -24
  195. package/lib/symbol/Symbol.d.ts +5 -4
  196. package/lib/symbol/Symbol.js +49 -65
  197. package/lib/symbol/SymbolUtil.d.ts +29 -31
  198. package/lib/symbol/SymbolUtil.js +178 -157
  199. package/lib/symbol/index.d.ts +2 -3
  200. package/lib/symbol/index.js +2 -19
  201. package/package.json +7 -4
  202. package/lib/service/Operations.d.ts +0 -8
  203. package/lib/service/Operations.js +0 -26
  204. package/lib/symbol/UriBinder.d.ts +0 -3
  205. package/lib/symbol/UriBinder.js +0 -3
@@ -1,68 +1,44 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- var _Downloader_memoryCache;
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LowLevelDownloader = exports.Downloader = exports.RemoteUriString = void 0;
13
- const follow_redirects_1 = require("follow-redirects");
14
- const fs_1 = require("fs");
15
- const path_1 = __importDefault(require("path"));
16
- const perf_hooks_1 = require("perf_hooks");
17
- const common_1 = require("../common");
18
- const fileUtil_1 = require("./fileUtil");
19
- var RemoteUriString;
20
- (function (RemoteUriString) {
21
- function is(value) {
22
- return value.startsWith('http:') || value.startsWith('https:');
23
- }
24
- RemoteUriString.is = is;
25
- function getProtocol(uri) {
26
- return uri.slice(0, uri.indexOf(':') + 1);
27
- }
28
- RemoteUriString.getProtocol = getProtocol;
29
- })(RemoteUriString = exports.RemoteUriString || (exports.RemoteUriString = {}));
30
- class Downloader {
31
- constructor(cacheRoot, logger, lld = LowLevelDownloader.create()) {
1
+ import { bufferToString, Uri } from '../common/index.js';
2
+ import { fileUtil } from './fileUtil.js';
3
+ export class Downloader {
4
+ cacheRoot;
5
+ externals;
6
+ logger;
7
+ #memoryCache = new Map();
8
+ constructor(cacheRoot, externals, logger) {
32
9
  this.cacheRoot = cacheRoot;
10
+ this.externals = externals;
33
11
  this.logger = logger;
34
- this.lld = lld;
35
- _Downloader_memoryCache.set(this, new Map());
36
12
  }
37
13
  async download(job, out = {}) {
38
14
  const { id, cache, uri, options, transformer, ttl } = job;
39
- if (ttl && __classPrivateFieldGet(this, _Downloader_memoryCache, "f").has(uri)) {
40
- const { buffer, time } = __classPrivateFieldGet(this, _Downloader_memoryCache, "f").get(uri);
41
- if (time <= perf_hooks_1.performance.now() + ttl) {
15
+ if (ttl && this.#memoryCache.has(uri)) {
16
+ const { buffer, time } = this.#memoryCache.get(uri);
17
+ if (time <= performance.now() + ttl) {
42
18
  this.logger.info(`[Downloader] [${id}] Skipped thanks to valid cache in memory`);
43
19
  return await transformer(buffer);
44
20
  }
45
21
  else {
46
- __classPrivateFieldGet(this, _Downloader_memoryCache, "f").delete(uri);
22
+ this.#memoryCache.delete(uri);
47
23
  }
48
24
  }
49
25
  let checksum;
50
- let cachePath;
51
- let cacheChecksumPath;
26
+ let cacheUri;
27
+ let cacheChecksumUri;
52
28
  if (cache) {
53
29
  const { checksumJob, checksumExtension } = cache;
54
- out.cachePath = cachePath = path_1.default.join(this.cacheRoot, 'downloader', id);
55
- cacheChecksumPath = path_1.default.join(this.cacheRoot, 'downloader', id + checksumExtension);
30
+ out.cacheUri = cacheUri = new Uri(`downloader/${id}`, this.cacheRoot).toString();
31
+ cacheChecksumUri = new Uri(`downloader/${id}${checksumExtension}`, this.cacheRoot).toString();
56
32
  try {
57
33
  out.checksum = checksum = await this.download({ ...checksumJob, id: id + checksumExtension });
58
34
  try {
59
- const cacheChecksum = (0, common_1.bufferToString)(await fileUtil_1.fileUtil.readFile(fileUtil_1.fileUtil.pathToFileUri(cacheChecksumPath)))
35
+ const cacheChecksum = bufferToString(await fileUtil.readFile(this.externals, cacheChecksumUri))
60
36
  .slice(0, -1); // Remove ending newline
61
37
  if (checksum === cacheChecksum) {
62
38
  try {
63
- const cachedBuffer = await fileUtil_1.fileUtil.readFile(fileUtil_1.fileUtil.pathToFileUri(cachePath));
39
+ const cachedBuffer = await fileUtil.readFile(this.externals, cacheUri);
64
40
  if (ttl) {
65
- __classPrivateFieldGet(this, _Downloader_memoryCache, "f").set(uri, { buffer: cachedBuffer, time: perf_hooks_1.performance.now() });
41
+ this.#memoryCache.set(uri, { buffer: cachedBuffer, time: performance.now() });
66
42
  }
67
43
  const deserializer = cache.deserializer ?? (b => b);
68
44
  const ans = await transformer(deserializer(cachedBuffer));
@@ -70,23 +46,23 @@ class Downloader {
70
46
  return ans;
71
47
  }
72
48
  catch (e) {
73
- this.logger.error(`[Downloader] [${id}] Loading cached file “${cachePath}”`, e);
74
- if ((0, common_1.isEnoent)(e)) {
49
+ this.logger.error(`[Downloader] [${id}] Loading cached file “${cacheUri}”`, e);
50
+ if (this.externals.error.isKind(e, 'ENOENT')) {
75
51
  // Cache checksum exists, but cached file doesn't.
76
52
  // Remove the invalid cache checksum.
77
53
  try {
78
- await fs_1.promises.unlink(cacheChecksumPath);
54
+ await this.externals.fs.unlink(cacheChecksumUri);
79
55
  }
80
56
  catch (e) {
81
- this.logger.error(`[Downloader] [${id}] Removing invalid cache checksum “${cacheChecksumPath}”`, e);
57
+ this.logger.error(`[Downloader] [${id}] Removing invalid cache checksum “${cacheChecksumUri}”`, e);
82
58
  }
83
59
  }
84
60
  }
85
61
  }
86
62
  }
87
63
  catch (e) {
88
- if (!(0, common_1.isEnoent)(e)) {
89
- this.logger.error(`[Downloader] [${id}] Loading cache checksum “${cacheChecksumPath}”`, e);
64
+ if (!this.externals.error.isKind(e, 'ENOENT')) {
65
+ this.logger.error(`[Downloader] [${id}] Loading cache checksum “${cacheChecksumUri}”`, e);
90
66
  }
91
67
  }
92
68
  }
@@ -95,25 +71,25 @@ class Downloader {
95
71
  }
96
72
  }
97
73
  try {
98
- const buffer = await this.lld.get(uri, options);
74
+ const buffer = await this.externals.downloader.get(uri, options);
99
75
  if (ttl) {
100
- __classPrivateFieldGet(this, _Downloader_memoryCache, "f").set(uri, { buffer, time: perf_hooks_1.performance.now() });
76
+ this.#memoryCache.set(uri, { buffer, time: performance.now() });
101
77
  }
102
- if (cache && cachePath && cacheChecksumPath) {
78
+ if (cache && cacheUri && cacheChecksumUri) {
103
79
  if (checksum) {
104
80
  try {
105
- await fileUtil_1.fileUtil.writeFile(fileUtil_1.fileUtil.pathToFileUri(cacheChecksumPath), `${checksum}\n`);
81
+ await fileUtil.writeFile(this.externals, cacheChecksumUri, `${checksum}\n`);
106
82
  }
107
83
  catch (e) {
108
- this.logger.error(`[Downloader] [${id}] Saving cache checksum “${cacheChecksumPath}”`, e);
84
+ this.logger.error(`[Downloader] [${id}] Saving cache checksum “${cacheChecksumUri}”`, e);
109
85
  }
110
86
  }
111
87
  try {
112
88
  const serializer = cache.serializer ?? (b => b);
113
- await fileUtil_1.fileUtil.writeFile(fileUtil_1.fileUtil.pathToFileUri(cachePath), serializer(buffer));
89
+ await fileUtil.writeFile(this.externals, cacheUri, serializer(buffer));
114
90
  }
115
91
  catch (e) {
116
- this.logger.error(`[Downloader] [${id}] Caching file “${cachePath}”`, e);
92
+ this.logger.error(`[Downloader] [${id}] Caching file “${cacheUri}”`, e);
117
93
  }
118
94
  }
119
95
  this.logger.info(`[Downloader] [${id}] Downloaded from “${uri}”`);
@@ -121,69 +97,20 @@ class Downloader {
121
97
  }
122
98
  catch (e) {
123
99
  this.logger.error(`[Downloader] [${id}] Downloading “${uri}”`, e);
124
- if (cache && cachePath) {
100
+ if (cache && cacheUri) {
125
101
  try {
126
- const cachedBuffer = await fileUtil_1.fileUtil.readFile(fileUtil_1.fileUtil.pathToFileUri(cachePath));
102
+ const cachedBuffer = await fileUtil.readFile(this.externals, cacheUri);
127
103
  const deserializer = cache.deserializer ?? (b => b);
128
104
  const ans = await transformer(deserializer(cachedBuffer));
129
- this.logger.warn(`[Downloader] [${id}] Fell back to cached file “${cachePath}”`);
105
+ this.logger.warn(`[Downloader] [${id}] Fell back to cached file “${cacheUri}”`);
130
106
  return ans;
131
107
  }
132
108
  catch (e) {
133
- this.logger.error(`[Downloader] [${id}] Fallback: loading cached file “${cachePath}”`, e);
109
+ this.logger.error(`[Downloader] [${id}] Fallback: loading cached file “${cacheUri}”`, e);
134
110
  }
135
111
  }
136
112
  }
137
113
  return undefined;
138
114
  }
139
115
  }
140
- exports.Downloader = Downloader;
141
- _Downloader_memoryCache = new WeakMap();
142
- var LowLevelDownloader;
143
- (function (LowLevelDownloader) {
144
- function create() {
145
- return new LowLevelDownloaderImpl();
146
- }
147
- LowLevelDownloader.create = create;
148
- function mock(options) {
149
- return new LowLevelDownloaderMock(options);
150
- }
151
- LowLevelDownloader.mock = mock;
152
- })(LowLevelDownloader = exports.LowLevelDownloader || (exports.LowLevelDownloader = {}));
153
- class LowLevelDownloaderImpl {
154
- get(uri, options = {}) {
155
- const protocol = RemoteUriString.getProtocol(uri);
156
- return new Promise((resolve, reject) => {
157
- const backend = protocol === 'http:' ? follow_redirects_1.http : follow_redirects_1.https;
158
- backend.get(uri, options, (res) => {
159
- if (res.statusCode !== 200) {
160
- reject(new Error(`Status code ${res.statusCode}: ${res.statusMessage}`));
161
- }
162
- else {
163
- resolve((0, common_1.promisifyAsyncIterable)(res, chunks => Buffer.concat(chunks)));
164
- }
165
- });
166
- });
167
- }
168
- }
169
- class LowLevelDownloaderMock {
170
- constructor(options) {
171
- this.options = options;
172
- }
173
- async get(uri) {
174
- if (!this.options.fixtures[uri]) {
175
- throw new Error(`404 not found: ${uri}`);
176
- }
177
- const fixture = this.options.fixtures[uri];
178
- if (Buffer.isBuffer(fixture)) {
179
- return fixture;
180
- }
181
- else if (typeof fixture === 'string') {
182
- return Buffer.from(fixture, 'utf-8');
183
- }
184
- else {
185
- return Buffer.from(JSON.stringify(fixture), 'utf-8');
186
- }
187
- }
188
- }
189
116
  //# sourceMappingURL=Downloader.js.map
@@ -1,5 +1,5 @@
1
- import type { LanguageErrorInfo, RangeLike } from '../source';
2
- import { ErrorSeverity, LanguageError } from '../source';
1
+ import type { LanguageErrorInfo, RangeLike } from '../source/index.js';
2
+ import { ErrorSeverity, LanguageError } from '../source/index.js';
3
3
  export declare class ErrorReporter {
4
4
  errors: LanguageError[];
5
5
  constructor();
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinterErrorReporter = exports.ErrorReporter = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- class ErrorReporter {
7
- constructor() {
8
- this.errors = [];
9
- }
1
+ import { localize } from '@spyglassmc/locales';
2
+ import { LanguageError, Range } from '../source/index.js';
3
+ export class ErrorReporter {
4
+ errors = [];
5
+ constructor() { }
10
6
  /**
11
7
  * Reports a new error.
12
8
  */
13
9
  report(message, range, severity = 3 /* ErrorSeverity.Error */, info) {
14
- this.errors.push(source_1.LanguageError.create(message, source_1.Range.get(range), severity, info));
10
+ this.errors.push(LanguageError.create(message, Range.get(range), severity, info));
15
11
  }
16
12
  /**
17
13
  * @returns All reported errors, and then clears the error stack.
@@ -29,15 +25,16 @@ class ErrorReporter {
29
25
  this.errors.push(...reporter.errors);
30
26
  }
31
27
  }
32
- exports.ErrorReporter = ErrorReporter;
33
- class LinterErrorReporter extends ErrorReporter {
28
+ export class LinterErrorReporter extends ErrorReporter {
29
+ ruleName;
30
+ ruleSeverity;
34
31
  constructor(ruleName, ruleSeverity) {
35
32
  super();
36
33
  this.ruleName = ruleName;
37
34
  this.ruleSeverity = ruleSeverity;
38
35
  }
39
36
  lint(message, range, info, severityOverride) {
40
- return this.report((0, locales_1.localize)('linter.diagnostic-message-wrapper', message, this.ruleName), range, severityOverride ?? this.ruleSeverity, info);
37
+ return this.report(localize('linter.diagnostic-message-wrapper', message, this.ruleName), range, severityOverride ?? this.ruleSeverity, info);
41
38
  }
42
39
  static fromErrorReporter(reporter, ruleName, ruleSeverity) {
43
40
  const ans = new LinterErrorReporter(ruleName, ruleSeverity);
@@ -45,5 +42,4 @@ class LinterErrorReporter extends ErrorReporter {
45
42
  return ans;
46
43
  }
47
44
  }
48
- exports.LinterErrorReporter = LinterErrorReporter;
49
45
  //# sourceMappingURL=ErrorReporter.js.map
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
- import type { Dependency } from './Dependency';
3
- import type { RootUriString } from './fileUtil';
4
- import type { Logger } from './Logger';
1
+ import type { Externals, Logger } from '../common/index.js';
2
+ import type { Dependency } from './Dependency.js';
3
+ import type { RootUriString } from './fileUtil.js';
5
4
  export interface UriProtocolSupporter {
6
5
  /**
7
6
  * @throws
@@ -16,7 +15,7 @@ export interface UriProtocolSupporter {
16
15
  * @returns The content of the file at `uri`.
17
16
  * @throws If the URI doesn't exist in the file system.
18
17
  */
19
- readFile(uri: string): Promise<Buffer>;
18
+ readFile(uri: string): Promise<Uint8Array>;
20
19
  listFiles(): Iterable<string>;
21
20
  /**
22
21
  * Each URI in this array must end with a slash (`/`).
@@ -49,16 +48,17 @@ export interface FileService extends UriProtocolSupporter {
49
48
  mapFromDisk(uri: string): string;
50
49
  }
51
50
  export declare namespace FileService {
52
- function create(cacheRoot: string): FileService;
51
+ function create(externals: Externals, cacheRoot: RootUriString): FileService;
53
52
  }
54
53
  export declare class FileServiceImpl implements FileService {
54
+ private readonly externals;
55
55
  private readonly virtualUrisRoot?;
56
56
  private readonly supporters;
57
57
  /**
58
58
  * A two-way map from mapped physical URIs to virtual URIs.
59
59
  */
60
60
  private readonly map;
61
- constructor(virtualUrisRoot?: `${string}/` | undefined);
61
+ constructor(externals: Externals, virtualUrisRoot?: `${string}/` | undefined);
62
62
  register(protocol: Protocol, supporter: UriProtocolSupporter, force?: boolean): void;
63
63
  unregister(protocol: Protocol): void;
64
64
  /**
@@ -74,36 +74,37 @@ export declare class FileServiceImpl implements FileService {
74
74
  /**
75
75
  * @throws
76
76
  */
77
- readFile(uri: string): Promise<Buffer>;
77
+ readFile(uri: string): Promise<Uint8Array>;
78
78
  listFiles(): Generator<string, void, undefined>;
79
79
  listRoots(): Generator<`${string}/`, void, undefined>;
80
80
  mapToDisk(virtualUri: string): Promise<string | undefined>;
81
81
  mapFromDisk(mappedUri: string): string;
82
82
  }
83
83
  export declare class FileUriSupporter implements UriProtocolSupporter {
84
+ private readonly externals;
84
85
  private readonly roots;
85
86
  private readonly files;
86
87
  readonly protocol = "file:";
87
88
  private constructor();
88
89
  hash(uri: string): Promise<string>;
89
- readFile(uri: string): Promise<Buffer>;
90
+ readFile(uri: string): Promise<Uint8Array>;
90
91
  listFiles(): Generator<string, void, undefined>;
91
92
  listRoots(): `${string}/`[];
92
93
  mapToDisk(uri: string): Promise<string | undefined>;
93
- private static rootUriToGlob;
94
- static create(dependencies: readonly Dependency[], logger: Logger): Promise<FileUriSupporter>;
94
+ static create(dependencies: readonly Dependency[], externals: Externals, logger: Logger): Promise<FileUriSupporter>;
95
95
  }
96
96
  export declare class ArchiveUriSupporter implements UriProtocolSupporter {
97
+ private readonly externals;
97
98
  private readonly entries;
98
- readonly protocol = "archive:";
99
99
  static readonly Protocol = "archive:";
100
100
  private static readonly SupportedArchiveExtnames;
101
+ readonly protocol = "archive:";
101
102
  /**
102
103
  * @param entries A map from archive URIs to unzipped entries.
103
104
  */
104
105
  private constructor();
105
106
  hash(uri: string): Promise<string>;
106
- readFile(uri: string): Promise<Buffer>;
107
+ readFile(uri: string): Promise<Uint8Array>;
107
108
  /**
108
109
  * @throws
109
110
  */
@@ -115,7 +116,7 @@ export declare class ArchiveUriSupporter implements UriProtocolSupporter {
115
116
  * @throws When `uri` has the wrong protocol or hostname.
116
117
  */
117
118
  private static decodeUri;
118
- static create(dependencies: readonly Dependency[], logger: Logger, checksums: Record<RootUriString, string>): Promise<ArchiveUriSupporter>;
119
+ static create(dependencies: readonly Dependency[], externals: Externals, logger: Logger, checksums: Record<RootUriString, string>): Promise<ArchiveUriSupporter>;
119
120
  }
120
121
  export {};
121
122
  //# sourceMappingURL=FileService.d.ts.map
@@ -1,58 +1,26 @@
1
- "use strict";
2
1
  /* istanbul ignore file */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.ArchiveUriSupporter = exports.FileUriSupporter = exports.FileServiceImpl = exports.FileService = void 0;
31
- const crypto_1 = __importDefault(require("crypto"));
32
- const decompress_1 = __importDefault(require("decompress"));
33
- const fs_1 = __importStar(require("fs"));
34
- const globby_1 = __importDefault(require("globby"));
35
- const path_1 = __importDefault(require("path"));
36
- const common_1 = require("../common");
37
- const TwoWayMap_1 = require("../common/TwoWayMap");
38
- const fileUtil_1 = require("./fileUtil");
39
- const HashAlgorithm = 'sha1';
40
- var FileService;
2
+ import { Uri } from '../common/index.js';
3
+ import { TwoWayMap } from '../common/TwoWayMap.js';
4
+ import { fileUtil } from './fileUtil.js';
5
+ export var FileService;
41
6
  (function (FileService) {
42
- function create(cacheRoot) {
43
- const virtualUrisRoot = fileUtil_1.fileUtil.ensureEndingSlash(fileUtil_1.fileUtil.pathToFileUri(path_1.default.join(cacheRoot, 'virtual-uris')));
44
- return new FileServiceImpl(virtualUrisRoot);
7
+ function create(externals, cacheRoot) {
8
+ const virtualUrisRoot = fileUtil.ensureEndingSlash(new Uri('virtual-uris/', cacheRoot).toString());
9
+ return new FileServiceImpl(externals, virtualUrisRoot);
45
10
  }
46
11
  FileService.create = create;
47
- })(FileService = exports.FileService || (exports.FileService = {}));
48
- class FileServiceImpl {
49
- constructor(virtualUrisRoot) {
12
+ })(FileService || (FileService = {}));
13
+ export class FileServiceImpl {
14
+ externals;
15
+ virtualUrisRoot;
16
+ supporters = new Map();
17
+ /**
18
+ * A two-way map from mapped physical URIs to virtual URIs.
19
+ */
20
+ map = new TwoWayMap();
21
+ constructor(externals, virtualUrisRoot) {
22
+ this.externals = externals;
50
23
  this.virtualUrisRoot = virtualUrisRoot;
51
- this.supporters = new Map();
52
- /**
53
- * A two-way map from mapped physical URIs to virtual URIs.
54
- */
55
- this.map = new TwoWayMap_1.TwoWayMap();
56
24
  }
57
25
  register(protocol, supporter, force = false) {
58
26
  if (!force && this.supporters.has(protocol)) {
@@ -69,7 +37,7 @@ class FileServiceImpl {
69
37
  * @returns The protocol if it's supported.
70
38
  */
71
39
  getSupportedProtocol(uri) {
72
- const protocol = new common_1.Uri(uri).protocol;
40
+ const protocol = new Uri(uri).protocol;
73
41
  if (!this.supporters.has(protocol)) {
74
42
  throw new Error(`The protocol “${protocol}” is unsupported.`);
75
43
  }
@@ -100,7 +68,7 @@ class FileServiceImpl {
100
68
  }
101
69
  }
102
70
  async mapToDisk(virtualUri) {
103
- if (fileUtil_1.fileUtil.isFileUri(virtualUri)) {
71
+ if (fileUtil.isFileUri(virtualUri)) {
104
72
  return virtualUri;
105
73
  }
106
74
  if (!this.virtualUrisRoot) {
@@ -109,9 +77,9 @@ class FileServiceImpl {
109
77
  try {
110
78
  let mappedUri = this.map.getKey(virtualUri);
111
79
  if (mappedUri === undefined) {
112
- mappedUri = `${this.virtualUrisRoot}${(0, common_1.getSha1)(virtualUri)}/${fileUtil_1.fileUtil.basename(virtualUri)}`;
80
+ mappedUri = `${this.virtualUrisRoot}${await this.externals.crypto.getSha1(virtualUri)}/${fileUtil.basename(virtualUri)}`;
113
81
  const buffer = await this.readFile(virtualUri);
114
- await fileUtil_1.fileUtil.writeFile(mappedUri, buffer, 0o444);
82
+ await fileUtil.writeFile(this.externals, mappedUri, buffer, 0o444);
115
83
  this.map.set(mappedUri, virtualUri);
116
84
  }
117
85
  return mappedUri;
@@ -128,18 +96,21 @@ class FileServiceImpl {
128
96
  return this.map.get(mappedUri) ?? mappedUri;
129
97
  }
130
98
  }
131
- exports.FileServiceImpl = FileServiceImpl;
132
- class FileUriSupporter {
133
- constructor(roots, files) {
99
+ export class FileUriSupporter {
100
+ externals;
101
+ roots;
102
+ files;
103
+ protocol = 'file:';
104
+ constructor(externals, roots, files) {
105
+ this.externals = externals;
134
106
  this.roots = roots;
135
107
  this.files = files;
136
- this.protocol = 'file:';
137
108
  }
138
109
  async hash(uri) {
139
- return hashFile(uri);
110
+ return hashFile(this.externals, uri);
140
111
  }
141
112
  readFile(uri) {
142
- return fs_1.promises.readFile(new common_1.Uri(uri));
113
+ return this.externals.fs.readFile(uri);
143
114
  }
144
115
  *listFiles() {
145
116
  for (const files of this.files.values()) {
@@ -152,54 +123,55 @@ class FileUriSupporter {
152
123
  async mapToDisk(uri) {
153
124
  return uri;
154
125
  }
155
- static rootUriToGlob(root) {
156
- return fileUtil_1.fileUtil.fileUriToPath(root) + '**/*';
157
- }
158
- static async create(dependencies, logger) {
126
+ static async create(dependencies, externals, logger) {
159
127
  const roots = [];
160
128
  const files = new Map();
161
129
  for (let { uri } of dependencies) {
162
130
  try {
163
- if (fileUtil_1.fileUtil.isFileUri(uri) && (await fs_1.promises.stat(new common_1.Uri(uri))).isDirectory()) {
164
- uri = fileUtil_1.fileUtil.ensureEndingSlash(uri);
131
+ if (fileUtil.isFileUri(uri) && (await externals.fs.stat(uri)).isDirectory()) {
132
+ uri = fileUtil.ensureEndingSlash(uri);
165
133
  roots.push(uri);
166
- files.set(uri, (await (0, globby_1.default)(this.rootUriToGlob(uri), { absolute: true, dot: true })).map(fileUtil_1.fileUtil.pathToFileUri));
134
+ files.set(uri, await externals.fs.getAllFiles(uri));
167
135
  }
168
136
  }
169
137
  catch (e) {
170
138
  logger.error(`[FileUriSupporter#create] Bad dependency “${uri}”`, e);
171
139
  }
172
140
  }
173
- return new FileUriSupporter(roots, files);
141
+ return new FileUriSupporter(externals, roots, files);
174
142
  }
175
143
  }
176
- exports.FileUriSupporter = FileUriSupporter;
177
144
  // namespace ArchiveUri {
178
145
  // export function is(uri: Uri): boolean {
179
146
  // return uri.protocol === Protocol && uri.hostname === Hostname
180
147
  // }
181
148
  // }
182
- class ArchiveUriSupporter {
149
+ export class ArchiveUriSupporter {
150
+ externals;
151
+ entries;
152
+ static Protocol = 'archive:';
153
+ static SupportedArchiveExtnames = ['.tar', '.tar.bz2', '.tar.gz', '.zip'];
154
+ protocol = ArchiveUriSupporter.Protocol;
183
155
  /**
184
156
  * @param entries A map from archive URIs to unzipped entries.
185
157
  */
186
- constructor(entries) {
158
+ constructor(externals, entries) {
159
+ this.externals = externals;
187
160
  this.entries = entries;
188
- this.protocol = ArchiveUriSupporter.Protocol;
189
161
  }
190
162
  async hash(uri) {
191
- const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new common_1.Uri(uri));
163
+ const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
192
164
  if (!pathInArchive) {
193
165
  // Hash the archive itself.
194
- return hashFile(archiveUri);
166
+ return hashFile(this.externals, archiveUri);
195
167
  }
196
168
  else {
197
169
  // Hash the corresponding file.
198
- return (0, common_1.getSha1)(this.getDataInArchive(archiveUri, pathInArchive));
170
+ return this.externals.crypto.getSha1(this.getDataInArchive(archiveUri, pathInArchive));
199
171
  }
200
172
  }
201
173
  async readFile(uri) {
202
- const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new common_1.Uri(uri));
174
+ const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
203
175
  return this.getDataInArchive(archiveUri, pathInArchive);
204
176
  }
205
177
  /**
@@ -246,22 +218,22 @@ class ArchiveUriSupporter {
246
218
  pathInArchive: uri.pathname.charAt(0) === '/' ? uri.pathname.slice(1) : uri.pathname,
247
219
  };
248
220
  }
249
- static async create(dependencies, logger, checksums) {
221
+ static async create(dependencies, externals, logger, checksums) {
250
222
  const entries = new Map();
251
223
  for (const { uri, info } of dependencies) {
252
224
  try {
253
- if (uri.startsWith('file:') && ArchiveUriSupporter.SupportedArchiveExtnames.some(ext => uri.endsWith(ext)) && (await fs_1.promises.stat(new common_1.Uri(uri))).isFile()) {
225
+ if (uri.startsWith('file:') && ArchiveUriSupporter.SupportedArchiveExtnames.some(ext => uri.endsWith(ext)) && (await externals.fs.stat(uri)).isFile()) {
254
226
  const rootUri = ArchiveUriSupporter.getUri(uri);
255
227
  const cachedChecksum = checksums[rootUri];
256
228
  if (cachedChecksum !== undefined) {
257
- const checksum = await hashFile(uri);
229
+ const checksum = await hashFile(externals, uri);
258
230
  if (cachedChecksum === checksum) {
259
231
  // The dependency has not changed since last cache.
260
232
  logger.info(`[SpyglassUriSupporter#create] Skipped decompressing “${uri}” thanks to cache ${checksum}`);
261
233
  continue;
262
234
  }
263
235
  }
264
- const files = await (0, decompress_1.default)(fileUtil_1.fileUtil.fileUriToPath(uri), { strip: typeof info?.startDepth === 'number' ? info.startDepth : 0 });
236
+ const files = await externals.archive.decompressBall(await externals.fs.readFile(uri), { stripLevel: typeof info?.startDepth === 'number' ? info.startDepth : 0 });
265
237
  entries.set(uri, new Map(files.map(f => [f.path.replace(/\\/g, '/'), f])));
266
238
  }
267
239
  }
@@ -269,19 +241,10 @@ class ArchiveUriSupporter {
269
241
  logger.error(`[SpyglassUriSupporter#create] Bad dependency “${uri}”`, e);
270
242
  }
271
243
  }
272
- return new ArchiveUriSupporter(entries);
244
+ return new ArchiveUriSupporter(externals, entries);
273
245
  }
274
246
  }
275
- exports.ArchiveUriSupporter = ArchiveUriSupporter;
276
- ArchiveUriSupporter.Protocol = 'archive:';
277
- ArchiveUriSupporter.SupportedArchiveExtnames = ['.tar', '.tar.bz2', '.tar.gz', '.zip'];
278
- async function hashFile(uri) {
279
- return new Promise((resolve, reject) => {
280
- const hash = crypto_1.default.createHash(HashAlgorithm);
281
- fs_1.default.createReadStream(new common_1.Uri(uri))
282
- .on('data', chunk => hash.update(chunk))
283
- .on('end', () => resolve(hash.digest('hex')))
284
- .on('error', reject);
285
- });
247
+ async function hashFile(externals, uri) {
248
+ return externals.crypto.getSha1(await externals.fs.readFile(uri));
286
249
  }
287
250
  //# sourceMappingURL=FileService.js.map
@@ -1,5 +1,5 @@
1
- import type { RangeLike } from '../source';
2
- import { Range } from '../source';
1
+ import type { RangeLike } from '../source/index.js';
2
+ import { Range } from '../source/index.js';
3
3
  export interface Hover {
4
4
  range: Range;
5
5
  markdown: string;