@spyglassmc/core 0.4.9 → 0.4.11

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.
@@ -105,8 +105,8 @@ export const NodeJsExternals = {
105
105
  unlink(location) {
106
106
  return fsp.unlink(toFsPathLike(location));
107
107
  },
108
- watch(locations) {
109
- return new ChokidarWatcherWrapper(chokidar.watch(locations.map(toPath)));
108
+ watch(locations, { usePolling = false } = {}) {
109
+ return new ChokidarWatcherWrapper(chokidar.watch(locations.map(toPath), { usePolling }));
110
110
  },
111
111
  writeFile(location, data, options) {
112
112
  return fsp.writeFile(toFsPathLike(location), data, options);
@@ -72,7 +72,9 @@ export interface ExternalFileSystem {
72
72
  isFile(): boolean;
73
73
  }>;
74
74
  unlink(location: FsLocation): Promise<void>;
75
- watch(locations: FsLocation[]): FsWatcher;
75
+ watch(locations: FsLocation[], options: {
76
+ usePolling?: boolean;
77
+ }): FsWatcher;
76
78
  /**
77
79
  * @param options `mode` - File mode bit mask (e.g. `0o775`).
78
80
  */
@@ -5,7 +5,7 @@ import { Range, Source } from '../source/index.js';
5
5
  import { Failure } from './Parser.js';
6
6
  export function attempt(parser, src, ctx) {
7
7
  const tmpSrc = src.clone();
8
- const tmpCtx = { ...ctx, err: new ErrorReporter() };
8
+ const tmpCtx = { ...ctx, err: new ErrorReporter(ctx.err.source) };
9
9
  const result = parser(tmpSrc, tmpCtx);
10
10
  return {
11
11
  result,
@@ -5,7 +5,11 @@ import { ErrorReporter } from '../../service/index.js';
5
5
  import { traversePreOrder } from '../util.js';
6
6
  import { AsyncBinder, SyncBinder } from './Binder.js';
7
7
  export function attempt(binder, node, ctx) {
8
- const tempCtx = { ...ctx, err: new ErrorReporter(), symbols: ctx.symbols.clone() };
8
+ const tempCtx = {
9
+ ...ctx,
10
+ err: new ErrorReporter(ctx.err.source),
11
+ symbols: ctx.symbols.clone(),
12
+ };
9
13
  const processAfterBinder = () => {
10
14
  StateProxy.undoChanges(node);
11
15
  const totalErrorSpan = tempCtx.err.errors.map((e) => e.range.end - e.range.start).reduce((a, b) => a + b, 0);
@@ -4,7 +4,7 @@ import { traversePreOrder } from '../util.js';
4
4
  export function attempt(checker, node, ctx) {
5
5
  const tempCtx = {
6
6
  ...ctx,
7
- err: new ErrorReporter(),
7
+ err: new ErrorReporter(ctx.err.source),
8
8
  symbols: ctx.symbols.clone(),
9
9
  };
10
10
  // FIXME: await
@@ -7,7 +7,7 @@ import type { Project } from './Project.js';
7
7
  * The format version of the cache. Should be increased when any changes that
8
8
  * could invalidate the cache are introduced to the Spyglass codebase.
9
9
  */
10
- export declare const LatestCacheVersion = 4;
10
+ export declare const LatestCacheVersion = 5;
11
11
  /**
12
12
  * Checksums of cached files or roots.
13
13
  */
@@ -5,7 +5,7 @@ import { fileUtil } from './fileUtil.js';
5
5
  * The format version of the cache. Should be increased when any changes that
6
6
  * could invalidate the cache are introduced to the Spyglass codebase.
7
7
  */
8
- export const LatestCacheVersion = 4;
8
+ export const LatestCacheVersion = 5;
9
9
  var Checksums;
10
10
  (function (Checksums) {
11
11
  function create() {
@@ -112,6 +112,16 @@ export interface EnvConfig {
112
112
  }>>;
113
113
  permissionLevel: 1 | 2 | 3 | 4;
114
114
  plugins: string[];
115
+ /**
116
+ * Makes the file-watcher use polling to watch for file changes.
117
+ * Comes at a performance cost for very large datapacks.
118
+ *
119
+ * On Windows, enabling this can fix file-lock issues when Spyglass is running.
120
+ * See: https://github.com/SpyglassMC/Spyglass/issues/1414
121
+ *
122
+ * **You should only consider enabling this for Windows machines.**
123
+ */
124
+ useFilePolling: boolean;
115
125
  }
116
126
  export type LinterSeverity = 'hint' | 'information' | 'warning' | 'error';
117
127
  export declare namespace LinterSeverity {
@@ -1,5 +1,5 @@
1
1
  import rfdc from 'rfdc';
2
- import { Arrayable, bufferToString, TypePredicates } from '../common/index.js';
2
+ import { Arrayable, bufferToString, merge, TypePredicates } from '../common/index.js';
3
3
  import { FileCategories, RegistryCategories } from '../symbol/index.js';
4
4
  export var LinterSeverity;
5
5
  (function (LinterSeverity) {
@@ -139,6 +139,7 @@ export const VanillaConfig = {
139
139
  permissionLevel: 2,
140
140
  plugins: [],
141
141
  mcmetaSummaryOverrides: {},
142
+ useFilePolling: false,
142
143
  },
143
144
  format: {
144
145
  blockStateBracketSpacing: { inside: 0 },
@@ -260,14 +261,7 @@ export class ConfigService {
260
261
  return ConfigService.ConfigFileNames.some((n) => uri.endsWith(`/${n}`));
261
262
  }
262
263
  static merge(base, ...overrides) {
263
- // FIXME
264
- const ans = rfdc()(base);
265
- for (const override of overrides) {
266
- for (const key of ['env', 'format', 'lint', 'snippet']) {
267
- ans[key] = { ...ans[key], ...override[key] };
268
- }
269
- }
270
- return ans;
264
+ return overrides.reduce(merge, rfdc()(base));
271
265
  }
272
266
  }
273
267
  //# sourceMappingURL=Config.js.map
@@ -24,7 +24,7 @@ export var ParserContext;
24
24
  ...ContextBase.create(project),
25
25
  config: project.config,
26
26
  doc: opts.doc,
27
- err: opts.err ?? new ErrorReporter(),
27
+ err: opts.err ?? new ErrorReporter(project.ctx['errorSource']),
28
28
  };
29
29
  }
30
30
  ParserContext.create = create;
@@ -61,7 +61,7 @@ export var BinderContext;
61
61
  function create(project, opts) {
62
62
  return {
63
63
  ...ProcessorContext.create(project, opts),
64
- err: opts.err ?? new ErrorReporter(),
64
+ err: opts.err ?? new ErrorReporter(project.ctx['errorSource']),
65
65
  ensureBindingStarted: project.ensureBindingStarted?.bind(project),
66
66
  };
67
67
  }
@@ -72,7 +72,7 @@ export var CheckerContext;
72
72
  function create(project, opts) {
73
73
  return {
74
74
  ...ProcessorContext.create(project, opts),
75
- err: opts.err ?? new ErrorReporter(),
75
+ err: opts.err ?? new ErrorReporter(project.ctx['errorSource']),
76
76
  ensureBindingStarted: project.ensureBindingStarted?.bind(project),
77
77
  };
78
78
  }
@@ -1,8 +1,9 @@
1
1
  import type { LanguageErrorInfo, RangeLike } from '../source/index.js';
2
2
  import { ErrorSeverity, LanguageError } from '../source/index.js';
3
3
  export declare class ErrorReporter {
4
+ readonly source?: string | undefined;
4
5
  errors: LanguageError[];
5
- constructor();
6
+ constructor(source?: string | undefined);
6
7
  /**
7
8
  * Reports a new error.
8
9
  */
@@ -20,7 +21,7 @@ export declare class ErrorReporter {
20
21
  export declare class LinterErrorReporter extends ErrorReporter {
21
22
  ruleName: string;
22
23
  ruleSeverity: ErrorSeverity;
23
- constructor(ruleName: string, ruleSeverity: ErrorSeverity);
24
+ constructor(ruleName: string, ruleSeverity: ErrorSeverity, source?: string);
24
25
  lint(message: string, range: RangeLike, info?: LanguageErrorInfo, severityOverride?: ErrorSeverity): void;
25
26
  static fromErrorReporter(reporter: ErrorReporter, ruleName: string, ruleSeverity: ErrorSeverity): LinterErrorReporter;
26
27
  }
@@ -1,8 +1,11 @@
1
1
  import { localize } from '@spyglassmc/locales';
2
2
  import { LanguageError, Range } from '../source/index.js';
3
3
  export class ErrorReporter {
4
+ source;
4
5
  errors = [];
5
- constructor() { }
6
+ constructor(source) {
7
+ this.source = source;
8
+ }
6
9
  /**
7
10
  * Reports a new error.
8
11
  */
@@ -10,7 +13,7 @@ export class ErrorReporter {
10
13
  if (message.trim() === '') {
11
14
  throw new Error('Tried to report an error with no message');
12
15
  }
13
- this.errors.push(LanguageError.create(message, Range.get(range), severity, info));
16
+ this.errors.push(LanguageError.create(message, Range.get(range), severity, info, this.source));
14
17
  }
15
18
  /**
16
19
  * @returns All reported errors, and then clears the error stack.
@@ -31,8 +34,8 @@ export class ErrorReporter {
31
34
  export class LinterErrorReporter extends ErrorReporter {
32
35
  ruleName;
33
36
  ruleSeverity;
34
- constructor(ruleName, ruleSeverity) {
35
- super();
37
+ constructor(ruleName, ruleSeverity, source) {
38
+ super(source);
36
39
  this.ruleName = ruleName;
37
40
  this.ruleSeverity = ruleSeverity;
38
41
  }
@@ -40,7 +43,7 @@ export class LinterErrorReporter extends ErrorReporter {
40
43
  return this.report(localize('linter.diagnostic-message-wrapper', message, this.ruleName), range, severityOverride ?? this.ruleSeverity, info);
41
44
  }
42
45
  static fromErrorReporter(reporter, ruleName, ruleSeverity) {
43
- const ans = new LinterErrorReporter(ruleName, ruleSeverity);
46
+ const ans = new LinterErrorReporter(ruleName, ruleSeverity, reporter.source);
44
47
  ans.errors = reporter.errors;
45
48
  return ans;
46
49
  }
@@ -215,12 +215,12 @@ export class Project {
215
215
  this.tryClearingCache(uri);
216
216
  }).on('ready', () => {
217
217
  this.#isReady = true;
218
- // // Recheck client managed files after the READY process, as they may have incomplete results and are user-facing.
219
- // const promises: Promise<unknown>[] = []
220
- // for (const { doc, node } of this.#clientManagedDocAndNodes.values()) {
221
- // promises.push(this.check(doc, node))
222
- // }
223
- // Promise.all(promises).catch(e => this.logger.error('[Project#ready] Error occurred when rechecking client managed files after READY', e))
218
+ // Recheck client managed files after the READY process, as they may have incomplete results and are user-facing.
219
+ const promises = [];
220
+ for (const { doc, node } of this.#clientManagedDocAndNodes.values()) {
221
+ promises.push(this.check(doc, node));
222
+ }
223
+ Promise.all(promises).catch(e => this.logger.error('[Project#ready] Error occurred when rechecking client managed files after READY', e));
224
224
  });
225
225
  }
226
226
  setInitPromise() {
@@ -330,7 +330,9 @@ export class Project {
330
330
  }
331
331
  this.#watchedFiles.clear();
332
332
  this.#watcherReady = false;
333
- this.#watcher = this.externals.fs.watch(this.projectRoots).once('ready', () => {
333
+ this.#watcher = this.externals.fs.watch(this.projectRoots, {
334
+ usePolling: this.config.env.useFilePolling,
335
+ }).once('ready', () => {
334
336
  this.#watcherReady = true;
335
337
  resolve();
336
338
  }).on('add', (uri) => {
@@ -603,7 +605,7 @@ export class Project {
603
605
  }
604
606
  const ctx = LinterContext.create(this, {
605
607
  doc,
606
- err: new LinterErrorReporter(ruleName, ruleSeverity),
608
+ err: new LinterErrorReporter(ruleName, ruleSeverity, this.ctx['errorSource']),
607
609
  ruleName,
608
610
  ruleValue,
609
611
  });
@@ -6,6 +6,7 @@ export interface LanguageErrorData {
6
6
  message: string;
7
7
  severity: ErrorSeverity;
8
8
  info?: LanguageErrorInfo;
9
+ source?: string;
9
10
  }
10
11
  export interface LanguageError extends LanguageErrorData {
11
12
  range: Range;
@@ -17,7 +18,7 @@ export interface PosRangeLanguageError extends LanguageErrorData {
17
18
  posRange: PositionRange;
18
19
  }
19
20
  export declare namespace LanguageError {
20
- function create(message: string, range: Range, severity?: ErrorSeverity, info?: LanguageErrorInfo): LanguageError;
21
+ function create(message: string, range: Range, severity?: ErrorSeverity, info?: LanguageErrorInfo, source?: string): LanguageError;
21
22
  /**
22
23
  * @returns A {@link PosRangeLanguageError}.
23
24
  */
@@ -1,11 +1,14 @@
1
1
  import { PositionRange } from './PositionRange.js';
2
2
  export var LanguageError;
3
3
  (function (LanguageError) {
4
- function create(message, range, severity = 3 /* ErrorSeverity.Error */, info) {
4
+ function create(message, range, severity = 3 /* ErrorSeverity.Error */, info, source) {
5
5
  const ans = { range, message, severity };
6
6
  if (info) {
7
7
  ans.info = info;
8
8
  }
9
+ if (source) {
10
+ ans.source = source;
11
+ }
9
12
  return ans;
10
13
  }
11
14
  LanguageError.create = create;
@@ -18,6 +21,7 @@ export var LanguageError;
18
21
  message: error.message,
19
22
  severity: error.severity,
20
23
  ...(error.info && { info: error.info }),
24
+ ...(error.source && { source: error.source }),
21
25
  };
22
26
  }
23
27
  LanguageError.withPosRange = withPosRange;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/core",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",