@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
package/src/utils.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
|
|
3
|
-
export function isAstroFilePath(filePath: string) {
|
|
4
|
-
return filePath.endsWith('.astro');
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function isVirtualAstroFilePath(filePath: string) {
|
|
8
|
-
return filePath.endsWith('.astro.ts');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function toRealAstroFilePath(filePath: string) {
|
|
12
|
-
return filePath.slice(0, -'.ts'.length);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function ensureRealAstroFilePath(filePath: string) {
|
|
16
|
-
return isVirtualAstroFilePath(filePath) ? toRealAstroFilePath(filePath) : filePath;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isNotNullOrUndefined<T>(val: T | undefined | null): val is T {
|
|
20
|
-
return val !== undefined && val !== null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Replace all occurrences of a string within an object with another string,
|
|
25
|
-
*/
|
|
26
|
-
export function replaceDeep<T extends Record<string, any>>(
|
|
27
|
-
obj: T,
|
|
28
|
-
searchStr: string | RegExp,
|
|
29
|
-
replacementStr: string
|
|
30
|
-
): T {
|
|
31
|
-
return _replaceDeep(obj);
|
|
32
|
-
|
|
33
|
-
function _replaceDeep(_obj: any): any {
|
|
34
|
-
if (typeof _obj === 'string') {
|
|
35
|
-
return _obj.replace(searchStr, replacementStr);
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(_obj)) {
|
|
38
|
-
return _obj.map((entry) => _replaceDeep(entry));
|
|
39
|
-
}
|
|
40
|
-
if (typeof _obj === 'object') {
|
|
41
|
-
return Object.keys(_obj).reduce((_o, key) => {
|
|
42
|
-
_o[key] = _replaceDeep(_obj[key]);
|
|
43
|
-
return _o;
|
|
44
|
-
}, {} as any);
|
|
45
|
-
}
|
|
46
|
-
return _obj;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getConfigPathForProject(project: ts.server.Project) {
|
|
51
|
-
return (
|
|
52
|
-
(project as ts.server.ConfiguredProject).canonicalConfigFilePath ??
|
|
53
|
-
(project.getCompilerOptions() as any).configFilePath
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function readProjectAstroFilesFromFs(
|
|
58
|
-
ts: typeof import('typescript/lib/tsserverlibrary'),
|
|
59
|
-
project: ts.server.Project,
|
|
60
|
-
parsedCommandLine: ts.ParsedCommandLine
|
|
61
|
-
) {
|
|
62
|
-
const fileSpec: TsFilesSpec = parsedCommandLine.raw;
|
|
63
|
-
const { include, exclude } = fileSpec;
|
|
64
|
-
|
|
65
|
-
if (include?.length === 0) {
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return ts.sys
|
|
70
|
-
.readDirectory(project.getCurrentDirectory() || process.cwd(), ['.astro'], exclude, include)
|
|
71
|
-
.map(ts.server.toNormalizedPath);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface TsFilesSpec {
|
|
75
|
-
include?: readonly string[];
|
|
76
|
-
exclude?: readonly string[];
|
|
77
|
-
}
|
package/test/fixtures/script.ts
DELETED
package/test/runTest.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const { runTests } = require('@vscode/test-electron');
|
|
3
|
-
const { downloadDirToExecutablePath } = require('./utils');
|
|
4
|
-
const { existsSync, readdirSync } = require('fs');
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
try {
|
|
8
|
-
// The folder containing the Extension Manifest package.json
|
|
9
|
-
// Passed to `--extensionDevelopmentPath`
|
|
10
|
-
const extensionDevelopmentPath = path.resolve(__dirname, '../../vscode');
|
|
11
|
-
|
|
12
|
-
// The path to the extension test script
|
|
13
|
-
// Passed to --extensionTestsPath
|
|
14
|
-
const extensionTestsPath = path.resolve(__dirname, './suite/index.js');
|
|
15
|
-
|
|
16
|
-
// If there's already a downloaded version of VS Code, let's use it
|
|
17
|
-
const vscodeTestPath = path.resolve(__dirname, '../../vscode/.vscode-test');
|
|
18
|
-
let vsPath = undefined;
|
|
19
|
-
if (existsSync(vscodeTestPath)) {
|
|
20
|
-
const files = readdirSync(vscodeTestPath);
|
|
21
|
-
files.forEach((file) => {
|
|
22
|
-
if (file.startsWith('vscode-')) {
|
|
23
|
-
vsPath = downloadDirToExecutablePath(
|
|
24
|
-
path.resolve(__dirname, '../../vscode/.vscode-test/', file)
|
|
25
|
-
);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
await runTests({
|
|
32
|
-
extensionDevelopmentPath,
|
|
33
|
-
extensionTestsPath,
|
|
34
|
-
vscodeExecutablePath: vsPath,
|
|
35
|
-
launchArgs: ['./fixtures/fixtures.code-workspace'],
|
|
36
|
-
});
|
|
37
|
-
} catch (err) {
|
|
38
|
-
console.error('Failed to run tests');
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
main();
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const { expect } = require('chai');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const vscode = require('vscode');
|
|
5
|
-
|
|
6
|
-
suite('Extension Test Suite', () => {
|
|
7
|
-
vscode.window.showInformationMessage('Start all tests.');
|
|
8
|
-
|
|
9
|
-
// TypeScript takes a while to wake up and there's unfortunately no good way to wait for it
|
|
10
|
-
async function waitForTS(command, commandArgs, condition) {
|
|
11
|
-
for (let i = 0; i < 1000; i++) {
|
|
12
|
-
const commandResult = await vscode.commands.executeCommand(command, ...commandArgs);
|
|
13
|
-
if (condition(commandResult)) {
|
|
14
|
-
return commandResult;
|
|
15
|
-
}
|
|
16
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17
|
-
}
|
|
18
|
-
throw new Error(
|
|
19
|
-
`TypeScript plugin never started or condition never resolved for command ${command}`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
test('extension is enabled', async () => {
|
|
24
|
-
const ext = vscode.extensions.getExtension('astro-build.astro-vscode');
|
|
25
|
-
const activate = await ext?.activate();
|
|
26
|
-
|
|
27
|
-
assert.notStrictEqual(activate, undefined);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('can find references inside Astro files', async () => {
|
|
31
|
-
const doc = await vscode.workspace.openTextDocument(
|
|
32
|
-
vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts'))
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const references = await waitForTS(
|
|
36
|
-
'vscode.executeReferenceProvider',
|
|
37
|
-
[doc.uri, new vscode.Position(0, 18)],
|
|
38
|
-
(result) => result.length > 1
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const hasAstroRef = references.some((ref) => ref.uri.path.includes('MyAstroComponent.astro'));
|
|
42
|
-
expect(hasAstroRef).to.be.true;
|
|
43
|
-
}).timeout(22000);
|
|
44
|
-
|
|
45
|
-
test('can get completions for Astro components', async () => {
|
|
46
|
-
const doc = await vscode.workspace.openTextDocument(
|
|
47
|
-
vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts'))
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const completions = await waitForTS(
|
|
51
|
-
'vscode.executeCompletionItemProvider',
|
|
52
|
-
[doc.uri, new vscode.Position(4, 12)],
|
|
53
|
-
(result) => result.items.length > 0
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const hasAstroCompletion = completions.items.some((item) => {
|
|
57
|
-
return item.insertText === 'MyAstroComponent';
|
|
58
|
-
});
|
|
59
|
-
expect(hasAstroCompletion).to.be.true;
|
|
60
|
-
}).timeout(12000);
|
|
61
|
-
|
|
62
|
-
test('can get implementations inside Astro files', async () => {
|
|
63
|
-
const doc = await vscode.workspace.openTextDocument(
|
|
64
|
-
vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts'))
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const implementations = await waitForTS(
|
|
68
|
-
'vscode.executeImplementationProvider',
|
|
69
|
-
[doc.uri, new vscode.Position(6, 15)],
|
|
70
|
-
(result) => result.length > 1
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const hasAstroImplementation = implementations.some((impl) =>
|
|
74
|
-
impl.uri.path.includes('MyAstroComponent')
|
|
75
|
-
);
|
|
76
|
-
expect(hasAstroImplementation).to.be.true;
|
|
77
|
-
}).timeout(12000);
|
|
78
|
-
});
|
package/test/suite/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Mocha = require('mocha');
|
|
3
|
-
const glob = require('glob');
|
|
4
|
-
|
|
5
|
-
exports.run = function () {
|
|
6
|
-
// Create the mocha test
|
|
7
|
-
const mocha = new Mocha({
|
|
8
|
-
ui: 'tdd',
|
|
9
|
-
color: true,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const testsRoot = path.resolve(__dirname, '..');
|
|
13
|
-
|
|
14
|
-
return new Promise((c, e) => {
|
|
15
|
-
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
|
16
|
-
if (err) {
|
|
17
|
-
return e(err);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Add files to the test suite
|
|
21
|
-
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
// Run the mocha test
|
|
25
|
-
mocha.run((failures) => {
|
|
26
|
-
if (failures > 0) {
|
|
27
|
-
e(new Error(`${failures} tests failed.`));
|
|
28
|
-
} else {
|
|
29
|
-
c();
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
33
|
-
} catch (err) {
|
|
34
|
-
e(err);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
};
|
package/test/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "ES2020",
|
|
5
|
-
"target": "ES2020",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"checkJs": false,
|
|
9
|
-
"rootDir": ".",
|
|
10
|
-
"emitDeclarationOnly": false,
|
|
11
|
-
"noEmit": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["**/*.js"]
|
|
14
|
-
}
|
package/test/utils.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/* MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE */
|
|
22
|
-
|
|
23
|
-
// @vscode/test-electron doesn't export this, so copying it here
|
|
24
|
-
// https://github.com/microsoft/vscode-test/blob/c6092b087a9c795c6d2097e864ab13e89d825226/lib/util.ts
|
|
25
|
-
|
|
26
|
-
const path = require('path');
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @type {string}
|
|
30
|
-
*/
|
|
31
|
-
let systemDefaultPlatform;
|
|
32
|
-
const windowsPlatforms = new Set(['win32-archive', 'win32-x64-archive', 'win32-arm64-archive']);
|
|
33
|
-
const darwinPlatforms = new Set(['darwin-arm64', 'darwin']);
|
|
34
|
-
|
|
35
|
-
switch (process.platform) {
|
|
36
|
-
case 'darwin':
|
|
37
|
-
systemDefaultPlatform = process.arch === 'arm64' ? 'darwin-arm64' : 'darwin';
|
|
38
|
-
break;
|
|
39
|
-
case 'win32':
|
|
40
|
-
systemDefaultPlatform =
|
|
41
|
-
process.arch === 'arm64'
|
|
42
|
-
? 'win32-arm64-archive'
|
|
43
|
-
: process.arch === 'ia32'
|
|
44
|
-
? 'win32-archive'
|
|
45
|
-
: 'win32-x64-archive';
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
48
|
-
systemDefaultPlatform =
|
|
49
|
-
process.arch === 'arm64'
|
|
50
|
-
? 'linux-arm64'
|
|
51
|
-
: process.arch === 'arm'
|
|
52
|
-
? 'linux-armhf'
|
|
53
|
-
: 'linux-x64';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {string} dir
|
|
58
|
-
*/
|
|
59
|
-
function downloadDirToExecutablePath(dir) {
|
|
60
|
-
if (windowsPlatforms.has(systemDefaultPlatform)) {
|
|
61
|
-
return path.resolve(dir, 'Code.exe');
|
|
62
|
-
} else if (darwinPlatforms.has(systemDefaultPlatform)) {
|
|
63
|
-
return path.resolve(dir, 'Visual Studio Code.app/Contents/MacOS/Electron');
|
|
64
|
-
} else {
|
|
65
|
-
return path.resolve(dir, 'code');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
module.exports = { downloadDirToExecutablePath };
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dist",
|
|
5
|
-
"rootDir": "src",
|
|
6
|
-
"target": "ES2020",
|
|
7
|
-
"module": "CommonJS",
|
|
8
|
-
"ignoreDeprecations": "5.0",
|
|
9
|
-
"importsNotUsedAsValues": "error"
|
|
10
|
-
},
|
|
11
|
-
"include": ["src"],
|
|
12
|
-
"exclude": ["node_modules"]
|
|
13
|
-
}
|