@spyglassmc/core 0.1.2 → 0.2.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 (187) 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/TwoWayMap.js +4 -10
  5. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  6. package/lib/common/externals/BrowserExternals.js +191 -0
  7. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  8. package/lib/common/externals/NodeJsExternals.js +151 -0
  9. package/lib/common/externals/downloader.d.ts +31 -0
  10. package/lib/common/externals/downloader.js +32 -0
  11. package/lib/common/externals/index.d.ts +96 -0
  12. package/lib/common/externals/index.js +2 -0
  13. package/lib/common/index.d.ts +2 -1
  14. package/lib/common/index.js +2 -17
  15. package/lib/common/util.d.ts +15 -15
  16. package/lib/common/util.js +30 -77
  17. package/lib/index.d.ts +7 -7
  18. package/lib/index.js +7 -23
  19. package/lib/node/AstNode.d.ts +3 -3
  20. package/lib/node/AstNode.js +10 -16
  21. package/lib/node/BooleanNode.d.ts +2 -2
  22. package/lib/node/BooleanNode.js +4 -7
  23. package/lib/node/CommentNode.d.ts +1 -1
  24. package/lib/node/CommentNode.js +2 -5
  25. package/lib/node/ErrorNode.d.ts +1 -1
  26. package/lib/node/ErrorNode.js +2 -5
  27. package/lib/node/FileNode.d.ts +3 -3
  28. package/lib/node/FileNode.js +2 -5
  29. package/lib/node/FloatNode.d.ts +2 -2
  30. package/lib/node/FloatNode.js +4 -7
  31. package/lib/node/IntegerNode.d.ts +2 -2
  32. package/lib/node/IntegerNode.js +4 -7
  33. package/lib/node/ListNode.d.ts +2 -2
  34. package/lib/node/ListNode.js +2 -5
  35. package/lib/node/LiteralNode.d.ts +3 -3
  36. package/lib/node/LiteralNode.js +4 -7
  37. package/lib/node/LongNode.d.ts +2 -2
  38. package/lib/node/LongNode.js +4 -7
  39. package/lib/node/RecordNode.d.ts +2 -2
  40. package/lib/node/RecordNode.js +2 -5
  41. package/lib/node/ResourceLocationNode.d.ts +5 -5
  42. package/lib/node/ResourceLocationNode.js +9 -12
  43. package/lib/node/Sequence.d.ts +2 -2
  44. package/lib/node/Sequence.js +4 -7
  45. package/lib/node/StringNode.d.ts +4 -4
  46. package/lib/node/StringNode.js +9 -12
  47. package/lib/node/SymbolNode.d.ts +3 -3
  48. package/lib/node/SymbolNode.js +4 -7
  49. package/lib/node/index.d.ts +15 -15
  50. package/lib/node/index.js +15 -31
  51. package/lib/nodejs.d.ts +2 -0
  52. package/lib/nodejs.js +2 -0
  53. package/lib/parser/Parser.d.ts +3 -3
  54. package/lib/parser/Parser.js +1 -4
  55. package/lib/parser/boolean.d.ts +2 -2
  56. package/lib/parser/boolean.js +3 -6
  57. package/lib/parser/comment.d.ts +2 -2
  58. package/lib/parser/comment.js +5 -9
  59. package/lib/parser/empty.d.ts +1 -1
  60. package/lib/parser/empty.js +1 -5
  61. package/lib/parser/error.d.ts +2 -2
  62. package/lib/parser/error.js +5 -9
  63. package/lib/parser/file.d.ts +3 -3
  64. package/lib/parser/file.js +9 -13
  65. package/lib/parser/float.d.ts +4 -4
  66. package/lib/parser/float.js +12 -16
  67. package/lib/parser/index.d.ts +16 -16
  68. package/lib/parser/index.js +16 -38
  69. package/lib/parser/integer.d.ts +4 -4
  70. package/lib/parser/integer.js +10 -14
  71. package/lib/parser/list.d.ts +2 -2
  72. package/lib/parser/list.js +15 -19
  73. package/lib/parser/literal.d.ts +2 -2
  74. package/lib/parser/literal.js +5 -9
  75. package/lib/parser/long.d.ts +4 -4
  76. package/lib/parser/long.js +10 -14
  77. package/lib/parser/record.d.ts +3 -3
  78. package/lib/parser/record.js +20 -24
  79. package/lib/parser/resourceLocation.d.ts +2 -2
  80. package/lib/parser/resourceLocation.js +14 -18
  81. package/lib/parser/string.d.ts +5 -5
  82. package/lib/parser/string.js +36 -42
  83. package/lib/parser/symbol.d.ts +3 -3
  84. package/lib/parser/symbol.js +3 -7
  85. package/lib/parser/util.d.ts +5 -5
  86. package/lib/parser/util.js +38 -56
  87. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  88. package/lib/processor/ColorInfoProvider.js +6 -9
  89. package/lib/processor/InlayHintProvider.d.ts +2 -2
  90. package/lib/processor/InlayHintProvider.js +1 -2
  91. package/lib/processor/SignatureHelpProvider.d.ts +2 -2
  92. package/lib/processor/SignatureHelpProvider.js +1 -2
  93. package/lib/processor/checker/Checker.d.ts +2 -2
  94. package/lib/processor/checker/Checker.js +1 -5
  95. package/lib/processor/checker/builtin.d.ts +4 -4
  96. package/lib/processor/checker/builtin.js +19 -30
  97. package/lib/processor/checker/index.d.ts +2 -2
  98. package/lib/processor/checker/index.js +2 -31
  99. package/lib/processor/colorizer/Colorizer.d.ts +4 -4
  100. package/lib/processor/colorizer/Colorizer.js +8 -11
  101. package/lib/processor/colorizer/builtin.d.ts +3 -3
  102. package/lib/processor/colorizer/builtin.js +33 -46
  103. package/lib/processor/colorizer/index.d.ts +2 -2
  104. package/lib/processor/colorizer/index.js +2 -31
  105. package/lib/processor/completer/Completer.d.ts +4 -4
  106. package/lib/processor/completer/Completer.js +14 -33
  107. package/lib/processor/completer/builtin.d.ts +7 -7
  108. package/lib/processor/completer/builtin.js +46 -62
  109. package/lib/processor/completer/index.d.ts +2 -2
  110. package/lib/processor/completer/index.js +2 -31
  111. package/lib/processor/formatter/Formatter.d.ts +2 -2
  112. package/lib/processor/formatter/Formatter.js +2 -7
  113. package/lib/processor/formatter/builtin.d.ts +3 -3
  114. package/lib/processor/formatter/builtin.js +22 -36
  115. package/lib/processor/formatter/index.d.ts +2 -2
  116. package/lib/processor/formatter/index.js +2 -31
  117. package/lib/processor/index.d.ts +9 -9
  118. package/lib/processor/index.js +9 -25
  119. package/lib/processor/linter/Linter.d.ts +2 -2
  120. package/lib/processor/linter/Linter.js +1 -2
  121. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  122. package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
  123. package/lib/processor/linter/builtin.d.ts +3 -3
  124. package/lib/processor/linter/builtin.js +19 -26
  125. package/lib/processor/linter/index.d.ts +2 -2
  126. package/lib/processor/linter/index.js +2 -31
  127. package/lib/processor/util.d.ts +2 -2
  128. package/lib/processor/util.js +4 -9
  129. package/lib/service/CacheService.d.ts +6 -6
  130. package/lib/service/CacheService.js +32 -56
  131. package/lib/service/Config.d.ts +11 -12
  132. package/lib/service/Config.js +50 -45
  133. package/lib/service/Context.d.ts +13 -13
  134. package/lib/service/Context.js +29 -32
  135. package/lib/service/Dependency.js +2 -5
  136. package/lib/service/Downloader.d.ts +10 -40
  137. package/lib/service/Downloader.js +37 -110
  138. package/lib/service/ErrorReporter.d.ts +2 -2
  139. package/lib/service/ErrorReporter.js +10 -14
  140. package/lib/service/FileService.d.ts +16 -14
  141. package/lib/service/FileService.js +55 -92
  142. package/lib/service/Hover.d.ts +2 -2
  143. package/lib/service/Hover.js +4 -7
  144. package/lib/service/Logger.js +2 -5
  145. package/lib/service/MetaRegistry.d.ts +12 -12
  146. package/lib/service/MetaRegistry.js +62 -73
  147. package/lib/service/Operations.js +3 -9
  148. package/lib/service/Profiler.d.ts +1 -1
  149. package/lib/service/Profiler.js +25 -41
  150. package/lib/service/Project.d.ts +47 -51
  151. package/lib/service/Project.js +199 -239
  152. package/lib/service/Service.d.ts +17 -27
  153. package/lib/service/Service.js +37 -43
  154. package/lib/service/SymbolLocations.d.ts +3 -3
  155. package/lib/service/SymbolLocations.js +4 -7
  156. package/lib/service/SymbolRegistrar.d.ts +1 -1
  157. package/lib/service/SymbolRegistrar.js +1 -2
  158. package/lib/service/fileUtil.d.ts +15 -45
  159. package/lib/service/fileUtil.js +38 -143
  160. package/lib/service/index.d.ts +17 -17
  161. package/lib/service/index.js +17 -35
  162. package/lib/source/IndexMap.d.ts +1 -1
  163. package/lib/source/IndexMap.js +7 -10
  164. package/lib/source/LanguageError.d.ts +2 -2
  165. package/lib/source/LanguageError.js +2 -5
  166. package/lib/source/Location.d.ts +3 -3
  167. package/lib/source/Location.js +6 -9
  168. package/lib/source/Offset.d.ts +1 -1
  169. package/lib/source/Offset.js +4 -7
  170. package/lib/source/Position.js +2 -5
  171. package/lib/source/PositionRange.d.ts +2 -2
  172. package/lib/source/PositionRange.js +14 -17
  173. package/lib/source/Range.d.ts +1 -1
  174. package/lib/source/Range.js +7 -10
  175. package/lib/source/Source.d.ts +3 -3
  176. package/lib/source/Source.js +28 -29
  177. package/lib/source/index.d.ts +8 -8
  178. package/lib/source/index.js +8 -24
  179. package/lib/symbol/Symbol.d.ts +2 -2
  180. package/lib/symbol/Symbol.js +49 -65
  181. package/lib/symbol/SymbolUtil.d.ts +22 -25
  182. package/lib/symbol/SymbolUtil.js +150 -151
  183. package/lib/symbol/UriBinder.d.ts +1 -1
  184. package/lib/symbol/UriBinder.js +1 -2
  185. package/lib/symbol/index.d.ts +3 -3
  186. package/lib/symbol/index.js +3 -19
  187. package/package.json +7 -4
@@ -1,17 +1,17 @@
1
1
  import type { TextDocument } from 'vscode-languageserver-textdocument';
2
- import type { LinterErrorReporter } from '.';
3
- import type { Range } from '../source';
4
- import { ReadonlySource } from '../source';
5
- import type { SymbolTable, SymbolUtil } from '../symbol';
6
- import type { Config } from './Config';
7
- import { ErrorReporter } from './ErrorReporter';
8
- import type { FileService } from './FileService';
9
- import type { RootUriString } from './fileUtil';
10
- import type { Logger } from './Logger';
11
- import type { MetaRegistry } from './MetaRegistry';
12
- import { Operations } from './Operations';
13
- import type { ProfilerFactory } from './Profiler';
14
- import type { DocAndNode, ProjectData } from './Project';
2
+ import type { LinterErrorReporter } from './index.js';
3
+ import type { Range } from '../source/index.js';
4
+ import { ReadonlySource } from '../source/index.js';
5
+ import type { SymbolTable, SymbolUtil } from '../symbol/index.js';
6
+ import type { Config } from './Config.js';
7
+ import { ErrorReporter } from './ErrorReporter.js';
8
+ import type { FileService } from './FileService.js';
9
+ import type { RootUriString } from './fileUtil.js';
10
+ import type { Logger } from './Logger.js';
11
+ import type { MetaRegistry } from './MetaRegistry.js';
12
+ import { Operations } from './Operations.js';
13
+ import type { ProfilerFactory } from './Profiler.js';
14
+ import type { DocAndNode, ProjectData } from './Project.js';
15
15
  export interface ContextBase {
16
16
  fs: FileService;
17
17
  getDocAndNode: (uri: string) => DocAndNode | undefined;
@@ -1,12 +1,9 @@
1
- "use strict";
2
1
  /* istanbul ignore file */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.UriBinderContext = exports.SignatureHelpProviderContext = exports.CompleterContext = exports.ColorizerContext = exports.FormatterContext = exports.LinterContext = exports.CheckerContext = exports.ProcessorContext = exports.ParserContext = exports.ContextBase = void 0;
5
- const processor_1 = require("../processor");
6
- const source_1 = require("../source");
7
- const ErrorReporter_1 = require("./ErrorReporter");
8
- const Operations_1 = require("./Operations");
9
- var ContextBase;
2
+ import { formatterContextIndentation } from '../processor/index.js';
3
+ import { ReadonlySource } from '../source/index.js';
4
+ import { ErrorReporter } from './ErrorReporter.js';
5
+ import { Operations } from './Operations.js';
6
+ export var ContextBase;
10
7
  (function (ContextBase) {
11
8
  function create(project) {
12
9
  return {
@@ -21,33 +18,33 @@ var ContextBase;
21
18
  };
22
19
  }
23
20
  ContextBase.create = create;
24
- })(ContextBase = exports.ContextBase || (exports.ContextBase = {}));
25
- var ParserContext;
21
+ })(ContextBase || (ContextBase = {}));
22
+ export var ParserContext;
26
23
  (function (ParserContext) {
27
24
  function create(project, opts) {
28
25
  return {
29
26
  ...ContextBase.create(project),
30
27
  config: project.config,
31
28
  doc: opts.doc,
32
- err: opts.err ?? new ErrorReporter_1.ErrorReporter(),
29
+ err: opts.err ?? new ErrorReporter(),
33
30
  symbols: project.symbols,
34
31
  };
35
32
  }
36
33
  ParserContext.create = create;
37
- })(ParserContext = exports.ParserContext || (exports.ParserContext = {}));
38
- var ProcessorContext;
34
+ })(ParserContext || (ParserContext = {}));
35
+ export var ProcessorContext;
39
36
  (function (ProcessorContext) {
40
37
  function create(project, opts) {
41
38
  return {
42
39
  ...ContextBase.create(project),
43
40
  config: project.config,
44
41
  doc: opts.doc,
45
- src: opts.src ?? new source_1.ReadonlySource(opts.doc.getText()),
42
+ src: opts.src ?? new ReadonlySource(opts.doc.getText()),
46
43
  symbols: project.symbols,
47
44
  };
48
45
  }
49
46
  ProcessorContext.create = create;
50
- })(ProcessorContext = exports.ProcessorContext || (exports.ProcessorContext = {}));
47
+ })(ProcessorContext || (ProcessorContext = {}));
51
48
  var ProcessorWithRangeContext;
52
49
  (function (ProcessorWithRangeContext) {
53
50
  function create(project, opts) {
@@ -68,19 +65,19 @@ var ProcessorWithOffsetContext;
68
65
  }
69
66
  ProcessorWithOffsetContext.create = create;
70
67
  })(ProcessorWithOffsetContext || (ProcessorWithOffsetContext = {}));
71
- var CheckerContext;
68
+ export var CheckerContext;
72
69
  (function (CheckerContext) {
73
70
  function create(project, opts) {
74
71
  return {
75
72
  ...ProcessorContext.create(project, opts),
76
- err: opts.err ?? new ErrorReporter_1.ErrorReporter(),
77
- ops: opts.ops ?? new Operations_1.Operations(),
73
+ err: opts.err ?? new ErrorReporter(),
74
+ ops: opts.ops ?? new Operations(),
78
75
  ensureChecked: project.ensureParsedAndChecked?.bind(project),
79
76
  };
80
77
  }
81
78
  CheckerContext.create = create;
82
- })(CheckerContext = exports.CheckerContext || (exports.CheckerContext = {}));
83
- var LinterContext;
79
+ })(CheckerContext || (CheckerContext = {}));
80
+ export var LinterContext;
84
81
  (function (LinterContext) {
85
82
  function create(project, opts) {
86
83
  return {
@@ -91,8 +88,8 @@ var LinterContext;
91
88
  };
92
89
  }
93
90
  LinterContext.create = create;
94
- })(LinterContext = exports.LinterContext || (exports.LinterContext = {}));
95
- var FormatterContext;
91
+ })(LinterContext || (LinterContext = {}));
92
+ export var FormatterContext;
96
93
  (function (FormatterContext) {
97
94
  function create(project, opts) {
98
95
  return {
@@ -100,20 +97,20 @@ var FormatterContext;
100
97
  ...opts,
101
98
  indentLevel: 0,
102
99
  indent(additionalLevels) {
103
- return (0, processor_1.formatterContextIndentation)(this, additionalLevels);
100
+ return formatterContextIndentation(this, additionalLevels);
104
101
  },
105
102
  };
106
103
  }
107
104
  FormatterContext.create = create;
108
- })(FormatterContext = exports.FormatterContext || (exports.FormatterContext = {}));
109
- var ColorizerContext;
105
+ })(FormatterContext || (FormatterContext = {}));
106
+ export var ColorizerContext;
110
107
  (function (ColorizerContext) {
111
108
  function create(project, opts) {
112
109
  return ProcessorWithRangeContext.create(project, opts);
113
110
  }
114
111
  ColorizerContext.create = create;
115
- })(ColorizerContext = exports.ColorizerContext || (exports.ColorizerContext = {}));
116
- var CompleterContext;
112
+ })(ColorizerContext || (ColorizerContext = {}));
113
+ export var CompleterContext;
117
114
  (function (CompleterContext) {
118
115
  function create(project, opts) {
119
116
  return {
@@ -123,15 +120,15 @@ var CompleterContext;
123
120
  };
124
121
  }
125
122
  CompleterContext.create = create;
126
- })(CompleterContext = exports.CompleterContext || (exports.CompleterContext = {}));
127
- var SignatureHelpProviderContext;
123
+ })(CompleterContext || (CompleterContext = {}));
124
+ export var SignatureHelpProviderContext;
128
125
  (function (SignatureHelpProviderContext) {
129
126
  function create(project, opts) {
130
127
  return ProcessorWithOffsetContext.create(project, opts);
131
128
  }
132
129
  SignatureHelpProviderContext.create = create;
133
- })(SignatureHelpProviderContext = exports.SignatureHelpProviderContext || (exports.SignatureHelpProviderContext = {}));
134
- var UriBinderContext;
130
+ })(SignatureHelpProviderContext || (SignatureHelpProviderContext = {}));
131
+ export var UriBinderContext;
135
132
  (function (UriBinderContext) {
136
133
  function create(project) {
137
134
  return {
@@ -140,5 +137,5 @@ var UriBinderContext;
140
137
  };
141
138
  }
142
139
  UriBinderContext.create = create;
143
- })(UriBinderContext = exports.UriBinderContext || (exports.UriBinderContext = {}));
140
+ })(UriBinderContext || (UriBinderContext = {}));
144
141
  //# sourceMappingURL=Context.js.map
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DependencyKey = void 0;
4
- var DependencyKey;
1
+ export var DependencyKey;
5
2
  (function (DependencyKey) {
6
3
  function is(value) {
7
4
  return value.startsWith('@');
8
5
  }
9
6
  DependencyKey.is = is;
10
- })(DependencyKey = exports.DependencyKey || (exports.DependencyKey = {}));
7
+ })(DependencyKey || (DependencyKey = {}));
11
8
  //# sourceMappingURL=Dependency.js.map
@@ -1,21 +1,16 @@
1
- /// <reference types="node" />
2
- import type { Logger } from './Logger';
3
- declare type RemoteProtocol = 'http:' | 'https:';
4
- export declare type RemoteUriString = `${RemoteProtocol}${string}`;
5
- export declare namespace RemoteUriString {
6
- function is(value: string): value is RemoteUriString;
7
- function getProtocol(uri: RemoteUriString): RemoteProtocol;
8
- }
1
+ import type { ExternalDownloaderOptions, Externals, RemoteUriString } from '../common/index.js';
2
+ import type { RootUriString } from './fileUtil.js';
3
+ import type { Logger } from './Logger.js';
9
4
  export interface DownloaderDownloadOut {
10
- cachePath?: string;
5
+ cacheUri?: string;
11
6
  checksum?: string;
12
7
  }
13
8
  export declare class Downloader {
14
9
  #private;
15
10
  private readonly cacheRoot;
11
+ private readonly externals;
16
12
  private readonly logger;
17
- private readonly lld;
18
- constructor(cacheRoot: string, logger: Logger, lld?: LowLevelDownloader);
13
+ constructor(cacheRoot: RootUriString, externals: Externals, logger: Logger);
19
14
  download<R>(job: Job<R>, out?: DownloaderDownloadOut): Promise<R | undefined>;
20
15
  }
21
16
  interface Job<R> {
@@ -32,37 +27,12 @@ interface Job<R> {
32
27
  */
33
28
  checksumJob: Omit<Job<string>, 'cache' | 'id'>;
34
29
  checksumExtension: `.${string}`;
35
- serializer?: (data: Buffer) => Buffer;
36
- deserializer?: (cache: Buffer) => Buffer;
30
+ serializer?: (data: Uint8Array) => Uint8Array;
31
+ deserializer?: (cache: Uint8Array) => Uint8Array;
37
32
  };
38
- transformer: (data: Buffer) => PromiseLike<R> | R;
39
- options?: LowLevelDownloadOptions;
33
+ transformer: (data: Uint8Array) => PromiseLike<R> | R;
34
+ options?: ExternalDownloaderOptions;
40
35
  ttl?: number;
41
36
  }
42
- interface LowLevelDownloadOptions {
43
- /**
44
- * Use an string array to set multiple values to the header.
45
- */
46
- headers?: Record<string, string | string[]>;
47
- timeout?: number;
48
- }
49
- export interface LowLevelDownloader {
50
- /**
51
- * @throws
52
- */
53
- get(uri: RemoteUriString, options?: LowLevelDownloadOptions): Promise<Buffer>;
54
- }
55
- export declare namespace LowLevelDownloader {
56
- function create(): LowLevelDownloader;
57
- function mock(options: LowLevelDownloaderMockOptions): LowLevelDownloader;
58
- }
59
- interface LowLevelDownloaderMockOptions {
60
- /**
61
- * A record from URIs to fixture data. The {@link LowLevelDownloader.get} only returns a {@link Buffer},
62
- * therefore `string` fixtures will be turned into a `Buffer` and `object` fixtures will be transformed
63
- * into JSON and then turned into a `Buffer`.
64
- */
65
- fixtures: Record<RemoteUriString, string | Buffer | object>;
66
- }
67
37
  export {};
68
38
  //# sourceMappingURL=Downloader.d.ts.map
@@ -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,7 @@
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 } from '../common/index.js';
2
+ import type { Dependency } from './Dependency.js';
3
+ import type { RootUriString } from './fileUtil.js';
4
+ import type { Logger } from './Logger.js';
5
5
  export interface UriProtocolSupporter {
6
6
  /**
7
7
  * @throws
@@ -16,7 +16,7 @@ export interface UriProtocolSupporter {
16
16
  * @returns The content of the file at `uri`.
17
17
  * @throws If the URI doesn't exist in the file system.
18
18
  */
19
- readFile(uri: string): Promise<Buffer>;
19
+ readFile(uri: string): Promise<Uint8Array>;
20
20
  listFiles(): Iterable<string>;
21
21
  /**
22
22
  * Each URI in this array must end with a slash (`/`).
@@ -49,16 +49,17 @@ export interface FileService extends UriProtocolSupporter {
49
49
  mapFromDisk(uri: string): string;
50
50
  }
51
51
  export declare namespace FileService {
52
- function create(cacheRoot: string): FileService;
52
+ function create(externals: Externals, cacheRoot: RootUriString): FileService;
53
53
  }
54
54
  export declare class FileServiceImpl implements FileService {
55
+ private readonly externals;
55
56
  private readonly virtualUrisRoot?;
56
57
  private readonly supporters;
57
58
  /**
58
59
  * A two-way map from mapped physical URIs to virtual URIs.
59
60
  */
60
61
  private readonly map;
61
- constructor(virtualUrisRoot?: `${string}/` | undefined);
62
+ constructor(externals: Externals, virtualUrisRoot?: `${string}/` | undefined);
62
63
  register(protocol: Protocol, supporter: UriProtocolSupporter, force?: boolean): void;
63
64
  unregister(protocol: Protocol): void;
64
65
  /**
@@ -74,36 +75,37 @@ export declare class FileServiceImpl implements FileService {
74
75
  /**
75
76
  * @throws
76
77
  */
77
- readFile(uri: string): Promise<Buffer>;
78
+ readFile(uri: string): Promise<Uint8Array>;
78
79
  listFiles(): Generator<string, void, undefined>;
79
80
  listRoots(): Generator<`${string}/`, void, undefined>;
80
81
  mapToDisk(virtualUri: string): Promise<string | undefined>;
81
82
  mapFromDisk(mappedUri: string): string;
82
83
  }
83
84
  export declare class FileUriSupporter implements UriProtocolSupporter {
85
+ private readonly externals;
84
86
  private readonly roots;
85
87
  private readonly files;
86
88
  readonly protocol = "file:";
87
89
  private constructor();
88
90
  hash(uri: string): Promise<string>;
89
- readFile(uri: string): Promise<Buffer>;
91
+ readFile(uri: string): Promise<Uint8Array>;
90
92
  listFiles(): Generator<string, void, undefined>;
91
93
  listRoots(): `${string}/`[];
92
94
  mapToDisk(uri: string): Promise<string | undefined>;
93
- private static rootUriToGlob;
94
- static create(dependencies: readonly Dependency[], logger: Logger): Promise<FileUriSupporter>;
95
+ static create(dependencies: readonly Dependency[], externals: Externals, logger: Logger): Promise<FileUriSupporter>;
95
96
  }
96
97
  export declare class ArchiveUriSupporter implements UriProtocolSupporter {
98
+ private readonly externals;
97
99
  private readonly entries;
98
- readonly protocol = "archive:";
99
100
  static readonly Protocol = "archive:";
100
101
  private static readonly SupportedArchiveExtnames;
102
+ readonly protocol = "archive:";
101
103
  /**
102
104
  * @param entries A map from archive URIs to unzipped entries.
103
105
  */
104
106
  private constructor();
105
107
  hash(uri: string): Promise<string>;
106
- readFile(uri: string): Promise<Buffer>;
108
+ readFile(uri: string): Promise<Uint8Array>;
107
109
  /**
108
110
  * @throws
109
111
  */
@@ -115,7 +117,7 @@ export declare class ArchiveUriSupporter implements UriProtocolSupporter {
115
117
  * @throws When `uri` has the wrong protocol or hostname.
116
118
  */
117
119
  private static decodeUri;
118
- static create(dependencies: readonly Dependency[], logger: Logger, checksums: Record<RootUriString, string>): Promise<ArchiveUriSupporter>;
120
+ static create(dependencies: readonly Dependency[], externals: Externals, logger: Logger, checksums: Record<RootUriString, string>): Promise<ArchiveUriSupporter>;
119
121
  }
120
122
  export {};
121
123
  //# sourceMappingURL=FileService.d.ts.map