typescript-plugin-scoped-imports 0.1.2 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3 - 2026-02-15
4
+
5
+ - Completions hardening: private directory validation by `typedPath` now applies only to exact `__private__` directory entries.
6
+ - Completions hardening: candidate import path is built from the evaluated directory entry name (no hardcoded private folder suffix in helper).
7
+ - Tests: added unit coverage for similarly named private-like directories (for example `__private__backup`) and candidate path construction.
8
+
3
9
  ## 0.1.2 - 2026-02-15
4
10
 
5
11
  - Refactor: split plugin internals into `utils/` modules and keep `src/index.ts` focused on tsserver interceptor orchestration.
@@ -6,6 +6,7 @@ export type GetImportPathAtPositionParams = {
6
6
  };
7
7
  export type IsPathPrefixValidForPrivateParams = {
8
8
  pathPrefix: string;
9
+ directoryName: string;
9
10
  currentFile: string;
10
11
  isPrivateImportAllowed: (importPath: string, currentFile: string) => boolean;
11
12
  };
@@ -31,9 +31,9 @@ function getImportPathAtPosition(params) {
31
31
  }
32
32
  }
33
33
  function isPathPrefixValidForPrivate(params) {
34
- const { pathPrefix, currentFile, isPrivateImportAllowed } = params;
34
+ const { pathPrefix, directoryName, currentFile, isPrivateImportAllowed } = params;
35
35
  const normalizedPath = (0, path_1.normalizePath)(pathPrefix);
36
- if (!normalizedPath) {
36
+ if (!normalizedPath || !directoryName) {
37
37
  return false;
38
38
  }
39
39
  let basePath = normalizedPath;
@@ -46,27 +46,29 @@ function isPathPrefixValidForPrivate(params) {
46
46
  if (!basePath.endsWith("/")) {
47
47
  basePath += "/";
48
48
  }
49
- const candidateImportPath = `${basePath}${constants_1.PRIVATE_FOLDER}`;
49
+ const candidateImportPath = `${basePath}${directoryName}`;
50
50
  return isPrivateImportAllowed(candidateImportPath, currentFile);
51
51
  }
52
52
  function shouldAllowCompletionEntry({ entry, typedPath, fileName, blockedNames, isPrivateImportAllowed, logInfo, }) {
53
- if (entry.name?.toLowerCase().includes(constants_1.PRIVATE_FOLDER)) {
54
- if (entry.source) {
55
- return isPrivateImportAllowed(entry.source, fileName);
56
- }
57
- if (entry.kind === "directory") {
58
- if (typedPath !== null &&
59
- isPathPrefixValidForPrivate({
60
- pathPrefix: typedPath,
61
- currentFile: fileName,
62
- isPrivateImportAllowed,
63
- })) {
64
- logInfo(`typescript-plugin-scoped-imports: ALLOWING ${constants_1.PRIVATE_FOLDER} directory (valid path: "${typedPath}")`);
65
- return true;
66
- }
67
- logInfo(`typescript-plugin-scoped-imports: BLOCKING ${constants_1.PRIVATE_FOLDER} directory (invalid path: "${typedPath}")`);
68
- return false;
53
+ const isPrivateDirectoryEntry = entry.kind === "directory" && entry.name === constants_1.PRIVATE_FOLDER;
54
+ if (isPrivateDirectoryEntry) {
55
+ if (typedPath !== null &&
56
+ isPathPrefixValidForPrivate({
57
+ pathPrefix: typedPath,
58
+ directoryName: entry.name,
59
+ currentFile: fileName,
60
+ isPrivateImportAllowed,
61
+ })) {
62
+ logInfo(`typescript-plugin-scoped-imports: ALLOWING ${constants_1.PRIVATE_FOLDER} directory (valid path: "${typedPath}")`);
63
+ return true;
69
64
  }
65
+ logInfo(`typescript-plugin-scoped-imports: BLOCKING ${constants_1.PRIVATE_FOLDER} directory (invalid path: "${typedPath}")`);
66
+ return false;
67
+ }
68
+ if (entry.source?.includes(constants_1.PRIVATE_FOLDER)) {
69
+ return isPrivateImportAllowed(entry.source, fileName);
70
+ }
71
+ if (entry.name?.toLowerCase().includes(constants_1.PRIVATE_FOLDER)) {
70
72
  logInfo(`typescript-plugin-scoped-imports: BLOCKING entry by name (no source): ${entry.name}`);
71
73
  return false;
72
74
  }
@@ -89,8 +91,5 @@ function shouldAllowCompletionEntry({ entry, typedPath, fileName, blockedNames,
89
91
  }
90
92
  return true;
91
93
  }
92
- if (entry.source.includes(constants_1.PRIVATE_FOLDER)) {
93
- return isPrivateImportAllowed(entry.source, fileName);
94
- }
95
94
  return true;
96
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-plugin-scoped-imports",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript Language Server plugin para controlar auto-imports basado en scope",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",