typescript-svelte-plugin 0.3.29 → 0.3.31

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.
package/dist/src/index.js CHANGED
@@ -127,9 +127,20 @@ function init(modules) {
127
127
  const svelteTsPath = (0, path_1.dirname)(require.resolve('svelte2tsx'));
128
128
  const sveltePath = require.resolve('svelte/compiler', configFilePath ? { paths: [configFilePath] } : undefined);
129
129
  const VERSION = require(sveltePath).VERSION;
130
- const svelteTsxFiles = (VERSION.split('.')[0] === '3'
130
+ const isSvelte3 = VERSION.split('.')[0] === '3';
131
+ const svelteHtmlDeclaration = isSvelte3
132
+ ? undefined
133
+ : (0, path_1.join)((0, path_1.dirname)(sveltePath), 'svelte-html.d.ts');
134
+ const svelteHtmlFallbackIfNotExist = svelteHtmlDeclaration && modules.typescript.sys.fileExists(svelteHtmlDeclaration)
135
+ ? svelteHtmlDeclaration
136
+ : './svelte-jsx-v4.d.ts';
137
+ const svelteTsxFiles = (isSvelte3
131
138
  ? ['./svelte-shims.d.ts', './svelte-jsx.d.ts', './svelte-native-jsx.d.ts']
132
- : ['./svelte-shims-v4.d.ts', './svelte-jsx-v4.d.ts', './svelte-native-jsx.d.ts']).map((f) => modules.typescript.sys.resolvePath((0, path_1.resolve)(svelteTsPath, f)));
139
+ : [
140
+ './svelte-shims-v4.d.ts',
141
+ svelteHtmlFallbackIfNotExist,
142
+ './svelte-native-jsx.d.ts'
143
+ ]).map((f) => modules.typescript.sys.resolvePath((0, path_1.resolve)(svelteTsPath, f)));
133
144
  resolvedSvelteTsxFiles = svelteTsxFiles;
134
145
  return svelteTsxFiles;
135
146
  }
@@ -32,6 +32,7 @@ export declare class ProjectSvelteFilesManager {
32
32
  private readProjectSvelteFilesFromFs;
33
33
  private onConfigChanged;
34
34
  private removeFileFromProject;
35
- private disposeWatchersAndFiles;
35
+ private disposeWatchers;
36
+ private clearProjectFile;
36
37
  dispose(): void;
37
38
  }
@@ -27,7 +27,8 @@ class ProjectSvelteFilesManager {
27
27
  if (!parsedCommandLine) {
28
28
  return;
29
29
  }
30
- this.disposeWatchersAndFiles();
30
+ this.disposeWatchers();
31
+ this.clearProjectFile();
31
32
  this.parsedCommandLine = parsedCommandLine;
32
33
  this.setupWatchers();
33
34
  this.updateProjectSvelteFiles();
@@ -109,7 +110,8 @@ class ProjectSvelteFilesManager {
109
110
  .map(this.typescript.server.toNormalizedPath);
110
111
  }
111
112
  onConfigChanged(config) {
112
- this.disposeWatchersAndFiles();
113
+ this.disposeWatchers();
114
+ this.clearProjectFile();
113
115
  if (config.enable) {
114
116
  this.setupWatchers();
115
117
  this.updateProjectSvelteFiles();
@@ -121,14 +123,20 @@ class ProjectSvelteFilesManager {
121
123
  this.project.removeFile(info, exists, true);
122
124
  }
123
125
  }
124
- disposeWatchersAndFiles() {
126
+ disposeWatchers() {
125
127
  this.directoryWatchers.forEach((watcher) => watcher.close());
126
128
  this.directoryWatchers.clear();
129
+ }
130
+ clearProjectFile() {
127
131
  this.projectFileToOriginalCasing.forEach((file) => this.removeFileFromProject(file));
128
132
  this.projectFileToOriginalCasing.clear();
129
133
  }
130
134
  dispose() {
131
- this.disposeWatchersAndFiles();
135
+ this.disposeWatchers();
136
+ // Don't remove files from the project here
137
+ // because TypeScript already does that when the project is closed
138
+ // - and because the project is closed, `project.removeFile` will result in an error
139
+ this.projectFileToOriginalCasing.clear();
132
140
  ProjectSvelteFilesManager.instances.delete(this.project.getProjectName());
133
141
  }
134
142
  }
@@ -14,6 +14,12 @@ function createSvelteSys(ts, logger) {
14
14
  readDirectory(path, extensions, exclude, include, depth) {
15
15
  const extensionsWithSvelte = (extensions ?? []).concat('.svelte');
16
16
  return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
17
+ },
18
+ readFile(path, encoding) {
19
+ // imba typescript plugin patch this with Object.defineProperty
20
+ // and copying the property descriptor from a class that extends the original ts.sys
21
+ // so we explicitly define it here
22
+ return ts.sys.readFile(path, encoding);
17
23
  }
18
24
  };
19
25
  if (ts.sys.realpath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.29",
3
+ "version": "0.3.31",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "keywords": [