@astrojs/ts-plugin 1.0.9 → 1.0.10
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/astro-snapshots.js +234 -0
- package/dist/astro-sys.js +30 -0
- package/dist/astro2tsx.js +26 -0
- package/dist/index.js +50 -0
- package/dist/language-service/completions.js +45 -0
- package/dist/language-service/definition.js +38 -0
- package/dist/language-service/diagnostics.js +62 -0
- package/dist/language-service/file-references.js +30 -0
- package/dist/language-service/find-references.js +66 -0
- package/dist/language-service/implementation.js +30 -0
- package/dist/language-service/index.js +44 -0
- package/dist/language-service/line-column-offset.js +21 -0
- package/dist/language-service/rename.js +34 -0
- package/dist/logger.js +40 -0
- package/dist/module-loader.js +146 -0
- package/dist/project-astro-files.js +102 -0
- package/dist/utils.js +61 -0
- package/package.json +5 -1
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -113
- package/src/astro-snapshots.ts +0 -285
- package/src/astro-sys.ts +0 -35
- package/src/astro2tsx.ts +0 -26
- package/src/index.ts +0 -84
- package/src/language-service/completions.ts +0 -73
- package/src/language-service/definition.ts +0 -42
- package/src/language-service/diagnostics.ts +0 -73
- package/src/language-service/file-references.ts +0 -34
- package/src/language-service/find-references.ts +0 -90
- package/src/language-service/implementation.ts +0 -34
- package/src/language-service/index.ts +0 -56
- package/src/language-service/line-column-offset.ts +0 -24
- package/src/language-service/rename.ts +0 -46
- package/src/logger.ts +0 -41
- package/src/module-loader.ts +0 -219
- package/src/project-astro-files.ts +0 -138
- package/src/utils.ts +0 -77
- package/test/fixtures/MyAstroComponent.astro +0 -5
- package/test/fixtures/script.ts +0 -9
- package/test/fixtures/tsconfig.json +0 -3
- package/test/runTest.js +0 -43
- package/test/suite/extension.test.js +0 -78
- package/test/suite/index.js +0 -38
- package/test/tsconfig.json +0 -14
- package/test/utils.js +0 -69
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateLineColumnOffset = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
function decorateLineColumnOffset(ls, snapshotManager) {
|
|
6
|
+
if (!ls.toLineColumnOffset) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
// We need to patch this because (according to source, only) getDefinition uses this
|
|
10
|
+
const toLineColumnOffset = ls.toLineColumnOffset;
|
|
11
|
+
ls.toLineColumnOffset = (fileName, position) => {
|
|
12
|
+
if ((0, utils_1.isAstroFilePath)(fileName)) {
|
|
13
|
+
const snapshot = snapshotManager.get(fileName);
|
|
14
|
+
if (snapshot) {
|
|
15
|
+
return snapshot.positionAt(position);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return toLineColumnOffset(fileName, position);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.decorateLineColumnOffset = decorateLineColumnOffset;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateRename = void 0;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
function decorateRename(ls, snapshotManager, logger) {
|
|
6
|
+
const findRenameLocations = ls.findRenameLocations;
|
|
7
|
+
ls.findRenameLocations = (fileName, position, findInStrings, findInComments, preferences) => {
|
|
8
|
+
const renameLocations = findRenameLocations(fileName, position, findInStrings, findInComments, preferences);
|
|
9
|
+
return renameLocations
|
|
10
|
+
?.map((renameLocation) => {
|
|
11
|
+
const snapshot = snapshotManager.get(renameLocation.fileName);
|
|
12
|
+
if (!(0, utils_js_1.isAstroFilePath)(renameLocation.fileName) || !snapshot) {
|
|
13
|
+
return renameLocation;
|
|
14
|
+
}
|
|
15
|
+
// TODO more needed to filter invalid locations, see RenameProvider
|
|
16
|
+
const textSpan = snapshot.getOriginalTextSpan(renameLocation.textSpan);
|
|
17
|
+
if (!textSpan) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const converted = {
|
|
21
|
+
...renameLocation,
|
|
22
|
+
textSpan,
|
|
23
|
+
};
|
|
24
|
+
if (converted.contextSpan) {
|
|
25
|
+
// Not important, spare the work
|
|
26
|
+
converted.contextSpan = undefined;
|
|
27
|
+
}
|
|
28
|
+
logger.debug('Converted rename location ', converted);
|
|
29
|
+
return converted;
|
|
30
|
+
})
|
|
31
|
+
.filter(utils_js_1.isNotNullOrUndefined);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.decorateRename = decorateRename;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
constructor(tsLogService, suppressNonAstroLogs = false, logDebug = false) {
|
|
6
|
+
this.tsLogService = tsLogService;
|
|
7
|
+
this.logDebug = logDebug;
|
|
8
|
+
if (suppressNonAstroLogs) {
|
|
9
|
+
const log = this.tsLogService.info.bind(this.tsLogService);
|
|
10
|
+
this.tsLogService.info = (s) => {
|
|
11
|
+
if (s.startsWith('-Astro Plugin-')) {
|
|
12
|
+
log(s);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
log(...args) {
|
|
18
|
+
const str = args
|
|
19
|
+
.map((arg) => {
|
|
20
|
+
if (typeof arg === 'object') {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(arg);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return '[object that cannot by stringified]';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return arg;
|
|
29
|
+
})
|
|
30
|
+
.join(' ');
|
|
31
|
+
this.tsLogService.info('-Astro Plugin- ' + str);
|
|
32
|
+
}
|
|
33
|
+
debug(...args) {
|
|
34
|
+
if (!this.logDebug) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.log(...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchModuleLoader = void 0;
|
|
4
|
+
const astro_sys_js_1 = require("./astro-sys.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
/**
|
|
7
|
+
* Caches resolved modules.
|
|
8
|
+
*/
|
|
9
|
+
class ModuleResolutionCache {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.cache = new Map();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Tries to get a cached module.
|
|
15
|
+
*/
|
|
16
|
+
get(moduleName, containingFile) {
|
|
17
|
+
return this.cache.get(this.getKey(moduleName, containingFile));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Caches resolved module, if it is not undefined.
|
|
21
|
+
*/
|
|
22
|
+
set(moduleName, containingFile, resolvedModule) {
|
|
23
|
+
if (!resolvedModule) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.cache.set(this.getKey(moduleName, containingFile), resolvedModule);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Deletes module from cache. Call this if a file was deleted.
|
|
30
|
+
* @param resolvedModuleName full path of the module
|
|
31
|
+
*/
|
|
32
|
+
delete(resolvedModuleName) {
|
|
33
|
+
this.cache.forEach((val, key) => {
|
|
34
|
+
if (val.resolvedFileName === resolvedModuleName) {
|
|
35
|
+
this.cache.delete(key);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getKey(moduleName, containingFile) {
|
|
40
|
+
return containingFile + ':::' + (0, utils_js_1.ensureRealAstroFilePath)(moduleName);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a module loader than can also resolve `.astro` files.
|
|
45
|
+
*
|
|
46
|
+
* The typescript language service tries to look up other files that are referenced in the currently open astro file.
|
|
47
|
+
* For `.ts`/`.js` files this works, for `.astro` files it does not by default.
|
|
48
|
+
* Reason: The typescript language service does not know about the `.astro` file ending,
|
|
49
|
+
* so it assumes it's a normal typescript file and searches for files like `../Component.astro.ts`, which is wrong.
|
|
50
|
+
* In order to fix this, we need to wrap typescript's module resolution and reroute all `.astro.ts` file lookups to .astro.
|
|
51
|
+
*/
|
|
52
|
+
function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project) {
|
|
53
|
+
const astroSys = (0, astro_sys_js_1.createAstroSys)(logger, typescript);
|
|
54
|
+
const moduleCache = new ModuleResolutionCache();
|
|
55
|
+
const origResolveModuleNames = lsHost.resolveModuleNames?.bind(lsHost);
|
|
56
|
+
const origResolveModuleNamLiterals = lsHost.resolveModuleNameLiterals?.bind(lsHost);
|
|
57
|
+
if (lsHost.resolveModuleNameLiterals) {
|
|
58
|
+
lsHost.resolveModuleNameLiterals = resolveModuleNameLiterals;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
lsHost.resolveModuleNames = resolveModuleNames;
|
|
62
|
+
}
|
|
63
|
+
const origRemoveFile = project.removeFile.bind(project);
|
|
64
|
+
project.removeFile = (info, fileExists, detachFromProject) => {
|
|
65
|
+
logger.log('File is being removed. Delete from cache: ', info.fileName);
|
|
66
|
+
moduleCache.delete(info.fileName);
|
|
67
|
+
return origRemoveFile(info, fileExists, detachFromProject);
|
|
68
|
+
};
|
|
69
|
+
// Patch readDirectory so we get completions for .astro files
|
|
70
|
+
const origReadDirectory = project.readDirectory.bind(project);
|
|
71
|
+
project.readDirectory = (path, extensions, exclude, include, depth) => {
|
|
72
|
+
const extensionsWithAstro = (extensions ?? []).concat('.astro', '.md', '.mdx');
|
|
73
|
+
return origReadDirectory(path, extensionsWithAstro, exclude, include, depth);
|
|
74
|
+
};
|
|
75
|
+
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions) {
|
|
76
|
+
// logger.log('Resolving modules names for ' + containingFile);
|
|
77
|
+
// Try resolving all module names with the original method first.
|
|
78
|
+
// The ones that are undefined will be re-checked if they are a
|
|
79
|
+
// astro file and if so, are resolved, too. This way we can defer
|
|
80
|
+
// all module resolving logic except for astro files to TypeScript.
|
|
81
|
+
const resolved = origResolveModuleNames?.(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions) || Array.from(Array(moduleNames.length));
|
|
82
|
+
return resolved.map((moduleName, idx) => {
|
|
83
|
+
const fileName = moduleNames[idx];
|
|
84
|
+
if (moduleName || !(0, utils_js_1.ensureRealAstroFilePath)(fileName).endsWith('.astro')) {
|
|
85
|
+
return moduleName;
|
|
86
|
+
}
|
|
87
|
+
const cachedModule = moduleCache.get(fileName, containingFile);
|
|
88
|
+
if (cachedModule) {
|
|
89
|
+
return cachedModule;
|
|
90
|
+
}
|
|
91
|
+
const resolvedModule = resolveModuleName(fileName, containingFile, compilerOptions);
|
|
92
|
+
moduleCache.set(fileName, containingFile, resolvedModule);
|
|
93
|
+
return resolvedModule;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function resolveModuleName(name, containingFile, compilerOptions) {
|
|
97
|
+
const astroResolvedModule = typescript.resolveModuleName(name, containingFile, compilerOptions, astroSys).resolvedModule;
|
|
98
|
+
if (!astroResolvedModule || !(0, utils_js_1.isVirtualAstroFilePath)(astroResolvedModule.resolvedFileName)) {
|
|
99
|
+
return astroResolvedModule;
|
|
100
|
+
}
|
|
101
|
+
const resolvedFileName = (0, utils_js_1.ensureRealAstroFilePath)(astroResolvedModule.resolvedFileName);
|
|
102
|
+
logger.log('Resolved', name, 'to astro file', resolvedFileName);
|
|
103
|
+
const snapshot = snapshotManager.create(resolvedFileName);
|
|
104
|
+
if (!snapshot) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
const resolvedAstroModule = {
|
|
108
|
+
extension: typescript.Extension.Tsx,
|
|
109
|
+
resolvedFileName,
|
|
110
|
+
};
|
|
111
|
+
return resolvedAstroModule;
|
|
112
|
+
}
|
|
113
|
+
function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
|
|
114
|
+
logger.log('Resolving modules names for ' + containingFile);
|
|
115
|
+
// Try resolving all module names with the original method first.
|
|
116
|
+
// The ones that are undefined will be re-checked if they are a
|
|
117
|
+
// Astro file and if so, are resolved, too. This way we can defer
|
|
118
|
+
// all module resolving logic except for Astro files to TypeScript.
|
|
119
|
+
const resolved = origResolveModuleNamLiterals?.(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) ??
|
|
120
|
+
moduleLiterals.map(() => ({
|
|
121
|
+
resolvedModule: undefined,
|
|
122
|
+
}));
|
|
123
|
+
return resolved.map((tsResolvedModule, idx) => {
|
|
124
|
+
const moduleName = moduleLiterals[idx].text;
|
|
125
|
+
if (tsResolvedModule.resolvedModule ||
|
|
126
|
+
!(0, utils_js_1.ensureRealAstroFilePath)(moduleName).endsWith('.astro')) {
|
|
127
|
+
return tsResolvedModule;
|
|
128
|
+
}
|
|
129
|
+
return resolveAstroModuleNameFromCache(moduleName, containingFile, options);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function resolveAstroModuleNameFromCache(moduleName, containingFile, options) {
|
|
133
|
+
const cachedModule = moduleCache.get(moduleName, containingFile);
|
|
134
|
+
if (cachedModule) {
|
|
135
|
+
return {
|
|
136
|
+
resolvedModule: cachedModule,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const resolvedModule = resolveModuleName(moduleName, containingFile, options);
|
|
140
|
+
moduleCache.set(moduleName, containingFile, resolvedModule);
|
|
141
|
+
return {
|
|
142
|
+
resolvedModule: resolvedModule,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.patchModuleLoader = patchModuleLoader;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProjectAstroFilesManager = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class ProjectAstroFilesManager {
|
|
6
|
+
static getInstance(projectName) {
|
|
7
|
+
return this.instances.get(projectName);
|
|
8
|
+
}
|
|
9
|
+
constructor(typescript, project, serverHost, snapshotManager, parsedCommandLine) {
|
|
10
|
+
this.typescript = typescript;
|
|
11
|
+
this.project = project;
|
|
12
|
+
this.serverHost = serverHost;
|
|
13
|
+
this.snapshotManager = snapshotManager;
|
|
14
|
+
this.parsedCommandLine = parsedCommandLine;
|
|
15
|
+
this.files = new Set();
|
|
16
|
+
this.directoryWatchers = new Set();
|
|
17
|
+
this.setupWatchers();
|
|
18
|
+
this.updateProjectAstroFiles();
|
|
19
|
+
ProjectAstroFilesManager.instances.set(project.getProjectName(), this);
|
|
20
|
+
}
|
|
21
|
+
updateProjectConfig(serviceHost) {
|
|
22
|
+
const parsedCommandLine = serviceHost.getParsedCommandLine?.((0, utils_1.getConfigPathForProject)(this.project));
|
|
23
|
+
if (!parsedCommandLine) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.disposeWatchersAndFiles();
|
|
27
|
+
this.parsedCommandLine = parsedCommandLine;
|
|
28
|
+
this.setupWatchers();
|
|
29
|
+
this.updateProjectAstroFiles();
|
|
30
|
+
}
|
|
31
|
+
getFiles() {
|
|
32
|
+
return Array.from(this.files);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create directory watcher for include and exclude
|
|
36
|
+
* The watcher in tsserver doesn't support astro file
|
|
37
|
+
* It won't add new created astro file to root
|
|
38
|
+
*/
|
|
39
|
+
setupWatchers() {
|
|
40
|
+
for (const directory in this.parsedCommandLine.wildcardDirectories) {
|
|
41
|
+
if (!Object.prototype.hasOwnProperty.call(this.parsedCommandLine.wildcardDirectories, directory)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const watchDirectoryFlags = this.parsedCommandLine.wildcardDirectories[directory];
|
|
45
|
+
const watcher = this.serverHost.watchDirectory(directory, this.watcherCallback.bind(this), watchDirectoryFlags === this.typescript.WatchDirectoryFlags.Recursive, this.parsedCommandLine.watchOptions);
|
|
46
|
+
this.directoryWatchers.add(watcher);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
watcherCallback(fileName) {
|
|
50
|
+
if (!(0, utils_1.isAstroFilePath)(fileName)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// We can't just add the file to the project directly, because
|
|
54
|
+
// - the casing of fileName is different
|
|
55
|
+
// - we don't know whether the file was added or deleted
|
|
56
|
+
this.updateProjectAstroFiles();
|
|
57
|
+
}
|
|
58
|
+
updateProjectAstroFiles() {
|
|
59
|
+
const fileNamesAfter = (0, utils_1.readProjectAstroFilesFromFs)(this.typescript, this.project, this.parsedCommandLine);
|
|
60
|
+
const removedFiles = new Set(...this.files);
|
|
61
|
+
const newFiles = fileNamesAfter.filter((fileName) => {
|
|
62
|
+
const has = this.files.has(fileName);
|
|
63
|
+
if (has) {
|
|
64
|
+
removedFiles.delete(fileName);
|
|
65
|
+
}
|
|
66
|
+
return !has;
|
|
67
|
+
});
|
|
68
|
+
for (const newFile of newFiles) {
|
|
69
|
+
this.addFileToProject(newFile);
|
|
70
|
+
this.files.add(newFile);
|
|
71
|
+
}
|
|
72
|
+
for (const removedFile of removedFiles) {
|
|
73
|
+
this.removeFileFromProject(removedFile, false);
|
|
74
|
+
this.files.delete(removedFile);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
addFileToProject(newFile) {
|
|
78
|
+
this.snapshotManager.create(newFile);
|
|
79
|
+
const snapshot = this.project.projectService.getScriptInfo(newFile);
|
|
80
|
+
if (snapshot) {
|
|
81
|
+
this.project.addRoot(snapshot);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
removeFileFromProject(file, exists = true) {
|
|
85
|
+
const info = this.project.getScriptInfo(file);
|
|
86
|
+
if (info) {
|
|
87
|
+
this.project.removeFile(info, exists, true);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
disposeWatchersAndFiles() {
|
|
91
|
+
this.directoryWatchers.forEach((watcher) => watcher.close());
|
|
92
|
+
this.directoryWatchers.clear();
|
|
93
|
+
this.files.forEach((file) => this.removeFileFromProject(file));
|
|
94
|
+
this.files.clear();
|
|
95
|
+
}
|
|
96
|
+
dispose() {
|
|
97
|
+
this.disposeWatchersAndFiles();
|
|
98
|
+
ProjectAstroFilesManager.instances.delete(this.project.getProjectName());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ProjectAstroFilesManager = ProjectAstroFilesManager;
|
|
102
|
+
ProjectAstroFilesManager.instances = new Map();
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readProjectAstroFilesFromFs = exports.getConfigPathForProject = exports.replaceDeep = exports.isNotNullOrUndefined = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.isVirtualAstroFilePath = exports.isAstroFilePath = void 0;
|
|
4
|
+
function isAstroFilePath(filePath) {
|
|
5
|
+
return filePath.endsWith('.astro');
|
|
6
|
+
}
|
|
7
|
+
exports.isAstroFilePath = isAstroFilePath;
|
|
8
|
+
function isVirtualAstroFilePath(filePath) {
|
|
9
|
+
return filePath.endsWith('.astro.ts');
|
|
10
|
+
}
|
|
11
|
+
exports.isVirtualAstroFilePath = isVirtualAstroFilePath;
|
|
12
|
+
function toRealAstroFilePath(filePath) {
|
|
13
|
+
return filePath.slice(0, -'.ts'.length);
|
|
14
|
+
}
|
|
15
|
+
exports.toRealAstroFilePath = toRealAstroFilePath;
|
|
16
|
+
function ensureRealAstroFilePath(filePath) {
|
|
17
|
+
return isVirtualAstroFilePath(filePath) ? toRealAstroFilePath(filePath) : filePath;
|
|
18
|
+
}
|
|
19
|
+
exports.ensureRealAstroFilePath = ensureRealAstroFilePath;
|
|
20
|
+
function isNotNullOrUndefined(val) {
|
|
21
|
+
return val !== undefined && val !== null;
|
|
22
|
+
}
|
|
23
|
+
exports.isNotNullOrUndefined = isNotNullOrUndefined;
|
|
24
|
+
/**
|
|
25
|
+
* Replace all occurrences of a string within an object with another string,
|
|
26
|
+
*/
|
|
27
|
+
function replaceDeep(obj, searchStr, replacementStr) {
|
|
28
|
+
return _replaceDeep(obj);
|
|
29
|
+
function _replaceDeep(_obj) {
|
|
30
|
+
if (typeof _obj === 'string') {
|
|
31
|
+
return _obj.replace(searchStr, replacementStr);
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(_obj)) {
|
|
34
|
+
return _obj.map((entry) => _replaceDeep(entry));
|
|
35
|
+
}
|
|
36
|
+
if (typeof _obj === 'object') {
|
|
37
|
+
return Object.keys(_obj).reduce((_o, key) => {
|
|
38
|
+
_o[key] = _replaceDeep(_obj[key]);
|
|
39
|
+
return _o;
|
|
40
|
+
}, {});
|
|
41
|
+
}
|
|
42
|
+
return _obj;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.replaceDeep = replaceDeep;
|
|
46
|
+
function getConfigPathForProject(project) {
|
|
47
|
+
return (project.canonicalConfigFilePath ??
|
|
48
|
+
project.getCompilerOptions().configFilePath);
|
|
49
|
+
}
|
|
50
|
+
exports.getConfigPathForProject = getConfigPathForProject;
|
|
51
|
+
function readProjectAstroFilesFromFs(ts, project, parsedCommandLine) {
|
|
52
|
+
const fileSpec = parsedCommandLine.raw;
|
|
53
|
+
const { include, exclude } = fileSpec;
|
|
54
|
+
if (include?.length === 0) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return ts.sys
|
|
58
|
+
.readDirectory(project.getCurrentDirectory() || process.cwd(), ['.astro'], exclude, include)
|
|
59
|
+
.map(ts.server.toNormalizedPath);
|
|
60
|
+
}
|
|
61
|
+
exports.readProjectAstroFilesFromFs = readProjectAstroFilesFromFs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/ts-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A TypeScript Plugin providing Astro intellisense",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"javascript",
|
|
16
16
|
"plugin"
|
|
17
17
|
],
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*.js",
|
|
20
|
+
"dist/**/*.d.ts"
|
|
21
|
+
],
|
|
18
22
|
"author": "withastro",
|
|
19
23
|
"license": "MIT",
|
|
20
24
|
"dependencies": {
|
package/.turbo/turbo-build.log
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
# @astrojs/ts-plugin
|
|
2
|
-
|
|
3
|
-
## 1.0.9
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- b6a98e0: Better handle when the Astro compiler fails to parse a file
|
|
8
|
-
|
|
9
|
-
## 1.0.8
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- 170a193: Update dependencies
|
|
14
|
-
|
|
15
|
-
## 1.0.7
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- c6cf1d7: Update Prettier plugin version
|
|
20
|
-
|
|
21
|
-
## 1.0.6
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- 3fcbc1a: Fix TypeScript plugin crashing at start in certain circumstances
|
|
26
|
-
|
|
27
|
-
## 1.0.5
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- ae15420: Fix importing `.astro` files in `.ts` files not working with TypeScript 5.0+
|
|
32
|
-
|
|
33
|
-
## 1.0.4
|
|
34
|
-
|
|
35
|
-
### Patch Changes
|
|
36
|
-
|
|
37
|
-
- eaefe96: Fix packaging error
|
|
38
|
-
|
|
39
|
-
## 1.0.3
|
|
40
|
-
|
|
41
|
-
### Patch Changes
|
|
42
|
-
|
|
43
|
-
- 685513b: Improve stability related to converting files to TSX
|
|
44
|
-
|
|
45
|
-
## 1.0.0
|
|
46
|
-
|
|
47
|
-
### Major Changes
|
|
48
|
-
|
|
49
|
-
- 39a7669: 1.0! This release includes no new changes by itself, but symbolize the official release of what was previously the pre-release version of the extension. For changelogs, please refer to the changelog from `0.29.0` to now.
|
|
50
|
-
|
|
51
|
-
## 0.4.5
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- 8ff8bdf: Update compiler version to fix Windows mapping issue
|
|
56
|
-
|
|
57
|
-
## 0.4.4
|
|
58
|
-
|
|
59
|
-
### Patch Changes
|
|
60
|
-
|
|
61
|
-
- c04adf3: Upgrade compiler version to 1.1.1
|
|
62
|
-
|
|
63
|
-
## 0.4.3
|
|
64
|
-
|
|
65
|
-
### Patch Changes
|
|
66
|
-
|
|
67
|
-
- 6b81412: Added an explanation on how to generate types for content collections to the error message for the `astro:content` import
|
|
68
|
-
|
|
69
|
-
## 0.4.2
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- 94a9b61: Add proper support for renaming symbols inside Astro (.astro) files
|
|
74
|
-
|
|
75
|
-
## 0.4.1
|
|
76
|
-
|
|
77
|
-
### Patch Changes
|
|
78
|
-
|
|
79
|
-
- 985515d: Update `@astrojs/compiler`, fixing a few bugs
|
|
80
|
-
|
|
81
|
-
## 0.4.0
|
|
82
|
-
|
|
83
|
-
### Minor Changes
|
|
84
|
-
|
|
85
|
-
- c8cdef9: Improved support for `.astro` imports inside JavaScript/TypeScript files:
|
|
86
|
-
- Added support for finding file references inside Astro files
|
|
87
|
-
- Added support for path completions for .astro, .md and .mdx files
|
|
88
|
-
- Fixed cases where our TypeScript plugin would fail to load under certain circumstance
|
|
89
|
-
- Fixed certain cases where Go to definition / implementation would fail
|
|
90
|
-
|
|
91
|
-
## 0.3.0
|
|
92
|
-
|
|
93
|
-
### Minor Changes
|
|
94
|
-
|
|
95
|
-
- b66ae70: Update the VS Code extension to use a bundled version of the language server for better performance and compatibility with running the extension in the web
|
|
96
|
-
|
|
97
|
-
## 0.2.1
|
|
98
|
-
|
|
99
|
-
### Patch Changes
|
|
100
|
-
|
|
101
|
-
- d056cd5: Fixes production bugs in extension
|
|
102
|
-
|
|
103
|
-
## 0.2.0
|
|
104
|
-
|
|
105
|
-
### Minor Changes
|
|
106
|
-
|
|
107
|
-
- 6b6b47a: Remove internal astro.d.ts files, instead prefer the one provided by Astro itself
|
|
108
|
-
|
|
109
|
-
## 0.1.1
|
|
110
|
-
|
|
111
|
-
### Patch Changes
|
|
112
|
-
|
|
113
|
-
- f1f3091: Fix commenting, namespaced elements, and Fragment typings
|