typescript-svelte-plugin 0.3.9 → 0.3.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.
@@ -26,9 +26,10 @@ function decorateCompletions(ls, logger) {
26
26
  const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
27
27
  const relativeFileName = (_b = fileName.split(routesFolder)[1]) === null || _b === void 0 ? void 0 : _b.slice(1);
28
28
  if (relativeFileName) {
29
+ const relativePath = (0, path_1.dirname)(relativeFileName) === '.' ? '' : `${(0, path_1.dirname)(relativeFileName)}/`;
29
30
  const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
30
31
  // note the missing .d.ts at the end - TS wants it that way for some reason
31
- `.svelte-kit/types/${routesFolder}/${(0, path_1.dirname)(relativeFileName)}/$types`;
32
+ `.svelte-kit/types/${routesFolder}/${relativePath}$types`;
32
33
  completions.entries.push({
33
34
  ...$typeImport,
34
35
  // Ensure it's sorted above the other imports
@@ -1,20 +1,33 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.decorateUpdateImports = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const utils_1 = require("../utils");
5
9
  function decorateUpdateImports(ls, snapshotManager, logger) {
6
10
  const getEditsForFileRename = ls.getEditsForFileRename;
7
11
  ls.getEditsForFileRename = (oldFilePath, newFilePath, formatOptions, preferences) => {
8
12
  const renameLocations = getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences);
9
- // If a file move/rename of a TS/JS file results a Svelte file change,
10
- // the Svelte extension will notice that, too, and adjusts the same imports.
11
- // This results in duplicate adjustments or race conditions with conflicting text spans
12
- // which can break imports in some cases.
13
- // Therefore don't do any updates of Svelte files and and also no updates of mixed TS files
14
- // and let the Svelte extension handle that.
15
13
  return renameLocations === null || renameLocations === void 0 ? void 0 : renameLocations.filter((renameLocation) => {
14
+ // If a file move/rename of a TS/JS file results a Svelte file change,
15
+ // the Svelte extension will notice that, too, and adjusts the same imports.
16
+ // This results in duplicate adjustments or race conditions with conflicting text spans
17
+ // which can break imports in some cases.
18
+ // Therefore don't do any updates of Svelte files and and also no updates of mixed TS files
19
+ // and let the Svelte extension handle that.
16
20
  return (!(0, utils_1.isSvelteFilePath)(renameLocation.fileName) &&
17
21
  !renameLocation.textChanges.some((change) => change.newText.endsWith('.svelte')));
22
+ }).map((renameLocation) => {
23
+ if (path_1.default.basename(renameLocation.fileName).startsWith('+')) {
24
+ // Filter out changes to './$type' imports for Kit route files,
25
+ // you'll likely want these to stay as-is
26
+ renameLocation.textChanges = renameLocation.textChanges.filter((change) => {
27
+ return !change.newText.includes('.svelte-kit/types/');
28
+ });
29
+ }
30
+ return renameLocation;
18
31
  });
19
32
  };
20
33
  }
@@ -7,7 +7,8 @@ const utils_1 = require("./utils");
7
7
  * Caches resolved modules.
8
8
  */
9
9
  class ModuleResolutionCache {
10
- constructor() {
10
+ constructor(projectService) {
11
+ this.projectService = projectService;
11
12
  this.cache = new Map();
12
13
  }
13
14
  /**
@@ -30,8 +31,9 @@ class ModuleResolutionCache {
30
31
  * @param resolvedModuleName full path of the module
31
32
  */
32
33
  delete(resolvedModuleName) {
34
+ resolvedModuleName = this.projectService.toCanonicalFileName(resolvedModuleName);
33
35
  this.cache.forEach((val, key) => {
34
- if (val.resolvedFileName === resolvedModuleName) {
36
+ if (this.projectService.toCanonicalFileName(val.resolvedFileName) === resolvedModuleName) {
35
37
  this.cache.delete(key);
36
38
  }
37
39
  });
@@ -40,7 +42,9 @@ class ModuleResolutionCache {
40
42
  this.cache.clear();
41
43
  }
42
44
  getKey(moduleName, containingFile) {
43
- return containingFile + ':::' + (0, utils_1.ensureRealSvelteFilePath)(moduleName);
45
+ return (this.projectService.toCanonicalFileName(containingFile) +
46
+ ':::' +
47
+ this.projectService.toCanonicalFileName((0, utils_1.ensureRealSvelteFilePath)(moduleName)));
44
48
  }
45
49
  }
46
50
  /**
@@ -55,7 +59,7 @@ class ModuleResolutionCache {
55
59
  function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project, configManager) {
56
60
  var _a;
57
61
  const svelteSys = (0, svelte_sys_1.createSvelteSys)(logger);
58
- const moduleCache = new ModuleResolutionCache();
62
+ const moduleCache = new ModuleResolutionCache(project.projectService);
59
63
  const origResolveModuleNames = (_a = lsHost.resolveModuleNames) === null || _a === void 0 ? void 0 : _a.bind(lsHost);
60
64
  lsHost.resolveModuleNames = resolveModuleNames;
61
65
  const origRemoveFile = project.removeFile.bind(project);
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProjectSvelteFilesManager = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  class ProjectSvelteFilesManager {
6
+ static getInstance(projectName) {
7
+ return this.instances.get(projectName);
8
+ }
6
9
  constructor(typescript, project, serverHost, snapshotManager, parsedCommandLine, configManager) {
7
10
  this.typescript = typescript;
8
11
  this.project = project;
@@ -18,9 +21,6 @@ class ProjectSvelteFilesManager {
18
21
  configManager.onConfigurationChanged(this.onConfigChanged.bind(this));
19
22
  ProjectSvelteFilesManager.instances.set(project.getProjectName(), this);
20
23
  }
21
- static getInstance(projectName) {
22
- return this.instances.get(projectName);
23
- }
24
24
  updateProjectConfig(serviceHost) {
25
25
  var _a;
26
26
  const parsedCommandLine = (_a = serviceHost.getParsedCommandLine) === null || _a === void 0 ? void 0 : _a.call(serviceHost, (0, utils_1.getConfigPathForProject)(this.project));
@@ -1,8 +1,8 @@
1
1
  import type ts from 'typescript/lib/tsserverlibrary';
2
- declare type LineChar = ts.LineAndCharacter;
3
- declare type FileMapping = LineMapping[];
4
- declare type LineMapping = CharacterMapping[];
5
- declare type CharacterMapping = [
2
+ type LineChar = ts.LineAndCharacter;
3
+ type FileMapping = LineMapping[];
4
+ type LineMapping = CharacterMapping[];
5
+ type CharacterMapping = [
6
6
  number,
7
7
  number,
8
8
  number,
@@ -199,11 +199,12 @@ class SvelteSnapshotManager {
199
199
  this.patchProjectServiceReadFile();
200
200
  }
201
201
  get(fileName) {
202
- return this.snapshots.get(fileName);
202
+ return this.snapshots.get(this.projectService.toCanonicalFileName(fileName));
203
203
  }
204
204
  create(fileName) {
205
- if (this.snapshots.has(fileName)) {
206
- return this.snapshots.get(fileName);
205
+ const canonicalFilePath = this.projectService.toCanonicalFileName(fileName);
206
+ if (this.snapshots.has(canonicalFilePath)) {
207
+ return this.snapshots.get(canonicalFilePath);
207
208
  }
208
209
  // This will trigger projectService.host.readFile which is patched below
209
210
  const scriptInfo = this.projectService.getOrCreateScriptInfoForNormalizedPath(this.typescript.server.toNormalizedPath(fileName), false);
@@ -217,13 +218,13 @@ class SvelteSnapshotManager {
217
218
  catch (e) {
218
219
  this.logger.log('Loading Snapshot failed', fileName);
219
220
  }
220
- const snapshot = this.snapshots.get(fileName);
221
+ const snapshot = this.snapshots.get(this.projectService.toCanonicalFileName(fileName));
221
222
  if (!snapshot) {
222
223
  this.logger.log('Svelte snapshot was not found after trying to load script snapshot for', fileName);
223
224
  return; // should never get here
224
225
  }
225
226
  snapshot.setAndPatchScriptInfo(scriptInfo);
226
- this.snapshots.set(fileName, snapshot);
227
+ this.snapshots.set(canonicalFilePath, snapshot);
227
228
  return snapshot;
228
229
  }
229
230
  patchProjectServiceReadFile() {
@@ -263,12 +264,13 @@ class SvelteSnapshotManager {
263
264
  mode: 'ts',
264
265
  typingsNamespace: this.svelteOptions.namespace
265
266
  });
266
- const existingSnapshot = this.snapshots.get(path);
267
+ const canonicalFilePath = this.projectService.toCanonicalFileName(path);
268
+ const existingSnapshot = this.snapshots.get(canonicalFilePath);
267
269
  if (existingSnapshot) {
268
270
  existingSnapshot.update(svelteCode, new source_mapper_1.SourceMapper(result.map.mappings));
269
271
  }
270
272
  else {
271
- this.snapshots.set(path, new SvelteSnapshot(this.typescript, path, svelteCode, new source_mapper_1.SourceMapper(result.map.mappings), this.logger, isTsFile));
273
+ this.snapshots.set(canonicalFilePath, new SvelteSnapshot(this.typescript, path, svelteCode, new source_mapper_1.SourceMapper(result.map.mappings), this.logger, isTsFile));
272
274
  }
273
275
  this.logger.log('Successfully read Svelte file contents of', path);
274
276
  return result.code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {