@tsrx/typescript-plugin 0.3.32 → 0.3.34
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/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/language-CK5RucYm.js +4 -0
- package/dist/language-CK5RucYm.js.map +1 -0
- package/dist/package.json +1 -0
- package/dist/tsc.js +3 -0
- package/dist/tsc.js.map +1 -0
- package/package.json +11 -5
- package/CHANGELOG.md +0 -411
- package/src/index.js +0 -10
- package/src/language.js +0 -926
- package/src/utils.js +0 -57
- package/tests/compiler-resolution.test.js +0 -205
- package/tests/fixtures/workspaces/both/package.json +0 -9
- package/tests/fixtures/workspaces/both-react/package.json +0 -8
- package/tests/fixtures/workspaces/react-only/package.json +0 -8
- package/tests/fixtures/workspaces/ripple-only/package.json +0 -9
- package/tests/plugin-integration.test.js +0 -120
- package/tests/workspace-fixtures.js +0 -244
- package/tsconfig.json +0 -17
- package/tsconfig.typecheck.json +0 -8
- package/tsdown.config.js +0 -30
package/src/utils.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export const DEBUG = process.env.RIPPLE_DEBUG === 'true';
|
|
2
|
-
// Matches valid JS/CSS identifier characters: word chars, dashes (CSS), $, and # (Ripple shorthands)
|
|
3
|
-
export const charAllowedWordRegex = /[\w\-$#]/;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a logging utility with a specific label
|
|
7
|
-
* @param {string} label
|
|
8
|
-
* @returns {{
|
|
9
|
-
* log: (...args: unknown[]) => void,
|
|
10
|
-
* logError: (...args: unknown[]) => void,
|
|
11
|
-
* logWarning: (...args: unknown[]) => void,
|
|
12
|
-
* }}
|
|
13
|
-
*/
|
|
14
|
-
export function createLogging(label) {
|
|
15
|
-
return {
|
|
16
|
-
log(...args) {
|
|
17
|
-
if (DEBUG) {
|
|
18
|
-
console.log(label, ...args);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
logError(...args) {
|
|
22
|
-
if (DEBUG) {
|
|
23
|
-
console.error(label, ...args);
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
logWarning(...args) {
|
|
27
|
-
if (DEBUG) {
|
|
28
|
-
console.warn(label, ...args);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get the word at a specific position in the text
|
|
36
|
-
* @param {string} text
|
|
37
|
-
* @param {number} start
|
|
38
|
-
* @returns {{word: string, start: number, end: number}}
|
|
39
|
-
*/
|
|
40
|
-
export function getWordFromPosition(text, start) {
|
|
41
|
-
let wordStart = start;
|
|
42
|
-
let wordEnd = start;
|
|
43
|
-
while (wordStart > 0 && charAllowedWordRegex.test(text[wordStart - 1])) {
|
|
44
|
-
wordStart--;
|
|
45
|
-
}
|
|
46
|
-
while (wordEnd < text.length && charAllowedWordRegex.test(text[wordEnd])) {
|
|
47
|
-
wordEnd++;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const word = text.substring(wordStart, wordEnd);
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
word,
|
|
54
|
-
start: wordStart,
|
|
55
|
-
end: wordEnd,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
import { cleanup_fixture_workspaces, create_fixture_workspace } from './workspace-fixtures.js';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
|
|
6
|
-
/** @import { WORKSPACE_CONFIGS } from './workspace-fixtures.js'; */
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
is_ripple_file,
|
|
10
|
-
find_workspace_compiler_entry_for_file,
|
|
11
|
-
COMPILER_CANDIDATES,
|
|
12
|
-
RIPPLE_EXTENSIONS,
|
|
13
|
-
_reset_for_test,
|
|
14
|
-
} = require('../src/language.js');
|
|
15
|
-
|
|
16
|
-
describe('typescript-plugin compiler resolution', () => {
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
_reset_for_test();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
cleanup_fixture_workspaces();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('extension metadata', () => {
|
|
26
|
-
it('recognizes .tsrx as the only supported extension', () => {
|
|
27
|
-
expect(RIPPLE_EXTENSIONS).toEqual(['.tsrx']);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('maps all compiler candidates to .tsrx', () => {
|
|
31
|
-
const ripple_candidate = COMPILER_CANDIDATES.find(
|
|
32
|
-
([package_name]) => package_name === '@tsrx/ripple',
|
|
33
|
-
);
|
|
34
|
-
const react_candidate = COMPILER_CANDIDATES.find(
|
|
35
|
-
([package_name]) => package_name === '@tsrx/react',
|
|
36
|
-
);
|
|
37
|
-
const solid_candidate = COMPILER_CANDIDATES.find(
|
|
38
|
-
([package_name]) => package_name === '@tsrx/solid',
|
|
39
|
-
);
|
|
40
|
-
const preact_candidate = COMPILER_CANDIDATES.find(
|
|
41
|
-
([package_name]) => package_name === '@tsrx/preact',
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (!ripple_candidate || !react_candidate || !solid_candidate || !preact_candidate) {
|
|
45
|
-
throw new Error('Missing compiler candidates');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
expect(ripple_candidate[2]).toEqual(['.tsrx']);
|
|
49
|
-
expect(react_candidate[2]).toEqual(['.tsrx']);
|
|
50
|
-
expect(solid_candidate[2]).toEqual(['.tsrx']);
|
|
51
|
-
expect(preact_candidate[2]).toEqual(['.tsrx']);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('is_ripple_file', () => {
|
|
56
|
-
it.each([
|
|
57
|
-
['Component.tsrx', true],
|
|
58
|
-
['/path/to/Component.tsrx', true],
|
|
59
|
-
['Component.ripple', false],
|
|
60
|
-
['Component.rsrx', false],
|
|
61
|
-
['Component.ts', false],
|
|
62
|
-
['Component.tsx', false],
|
|
63
|
-
['Component.js', false],
|
|
64
|
-
['Component.jsx', false],
|
|
65
|
-
['', false],
|
|
66
|
-
])('returns %j for %j', (file_name, expected) => {
|
|
67
|
-
expect(is_ripple_file(file_name)).toBe(expected);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('workspace resolution', () => {
|
|
72
|
-
it('selects the ripple compiler in a ripple-only project', () => {
|
|
73
|
-
const workspace = create_fixture_workspace('ripple-only');
|
|
74
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
75
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'ripple', 'src', 'index.js');
|
|
76
|
-
|
|
77
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
78
|
-
expected,
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('selects the react compiler in a react-only project', () => {
|
|
83
|
-
const workspace = create_fixture_workspace('react-only');
|
|
84
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
85
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'react', 'src', 'index.js');
|
|
86
|
-
|
|
87
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
88
|
-
expected,
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('selects the preact compiler in a preact-only project', () => {
|
|
93
|
-
const workspace = create_fixture_workspace('preact-only');
|
|
94
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
95
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'preact', 'src', 'index.js');
|
|
96
|
-
|
|
97
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
98
|
-
expected,
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('prefers the ripple compiler when both compilers exist in a ripple project', () => {
|
|
103
|
-
const workspace = create_fixture_workspace('both');
|
|
104
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
105
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'ripple', 'src', 'index.js');
|
|
106
|
-
|
|
107
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
108
|
-
expected,
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('prefers the react compiler when both compilers exist in a react project', () => {
|
|
113
|
-
const workspace = create_fixture_workspace('both-react');
|
|
114
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
115
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'react', 'src', 'index.js');
|
|
116
|
-
|
|
117
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
118
|
-
expected,
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('prefers the preact compiler when multiple compilers exist in a preact project', () => {
|
|
123
|
-
const workspace = create_fixture_workspace('both-preact');
|
|
124
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
125
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'preact', 'src', 'index.js');
|
|
126
|
-
|
|
127
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
128
|
-
expected,
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('walks up nested directories to find the nearest compiler', () => {
|
|
133
|
-
const workspace = create_fixture_workspace('ripple-only');
|
|
134
|
-
const file_name = path.join(workspace, 'src', 'nested', 'components', 'App.tsrx');
|
|
135
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'ripple', 'src', 'index.js');
|
|
136
|
-
|
|
137
|
-
expect(find_workspace_compiler_entry_for_file(file_name, fs.existsSync, new Map())).toBe(
|
|
138
|
-
expected,
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('returns undefined when no compiler exists', () => {
|
|
143
|
-
expect(
|
|
144
|
-
find_workspace_compiler_entry_for_file('/workspace/src/App.tsrx', () => false, new Map()),
|
|
145
|
-
).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('cache behavior', () => {
|
|
150
|
-
it('reuses the cached result for repeated lookups in the same directory', () => {
|
|
151
|
-
const workspace = create_fixture_workspace('ripple-only');
|
|
152
|
-
const compiler_path_map = new Map();
|
|
153
|
-
const expected = path.join(workspace, 'node_modules', '@tsrx', 'ripple', 'src', 'index.js');
|
|
154
|
-
let exists_sync_calls = 0;
|
|
155
|
-
|
|
156
|
-
/** @param {import('fs').PathLike} file_path */
|
|
157
|
-
const exists_sync = (file_path) => {
|
|
158
|
-
exists_sync_calls += 1;
|
|
159
|
-
return fs.existsSync(file_path);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
expect(
|
|
163
|
-
find_workspace_compiler_entry_for_file(
|
|
164
|
-
path.join(workspace, 'src', 'A.tsrx'),
|
|
165
|
-
exists_sync,
|
|
166
|
-
compiler_path_map,
|
|
167
|
-
),
|
|
168
|
-
).toBe(expected);
|
|
169
|
-
expect(
|
|
170
|
-
find_workspace_compiler_entry_for_file(
|
|
171
|
-
path.join(workspace, 'src', 'B.tsrx'),
|
|
172
|
-
exists_sync,
|
|
173
|
-
compiler_path_map,
|
|
174
|
-
),
|
|
175
|
-
).toBe(expected);
|
|
176
|
-
expect(exists_sync_calls).toBeGreaterThan(0);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe('project permutation matrix', () => {
|
|
181
|
-
/** @type {{ name: keyof typeof WORKSPACE_CONFIGS, expected: string[] }[]} */
|
|
182
|
-
const cases = [
|
|
183
|
-
{ name: 'ripple-only', expected: ['@tsrx', 'ripple'] },
|
|
184
|
-
{ name: 'react-only', expected: ['@tsrx', 'react'] },
|
|
185
|
-
{ name: 'solid-only', expected: ['@tsrx', 'solid'] },
|
|
186
|
-
{ name: 'preact-only', expected: ['@tsrx', 'preact'] },
|
|
187
|
-
{ name: 'both', expected: ['@tsrx', 'ripple'] },
|
|
188
|
-
{ name: 'both-react', expected: ['@tsrx', 'react'] },
|
|
189
|
-
{ name: 'both-preact', expected: ['@tsrx', 'preact'] },
|
|
190
|
-
];
|
|
191
|
-
|
|
192
|
-
for (const test_case of cases) {
|
|
193
|
-
it(`${test_case.name} resolves App.tsrx to the expected compiler`, () => {
|
|
194
|
-
const workspace = create_fixture_workspace(test_case.name);
|
|
195
|
-
const compiler_path = find_workspace_compiler_entry_for_file(
|
|
196
|
-
path.join(workspace, 'src', 'App.tsrx'),
|
|
197
|
-
fs.existsSync,
|
|
198
|
-
new Map(),
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
expect(compiler_path).toContain(path.join(...test_case.expected));
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
import { cleanup_fixture_workspaces, create_fixture_workspace } from './workspace-fixtures.js';
|
|
4
|
-
import * as ts from 'typescript';
|
|
5
|
-
import { getRippleLanguagePlugin, TSRXVirtualCode, _reset_for_test } from '../src/language.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {string} source
|
|
9
|
-
* @returns {import('typescript').IScriptSnapshot}
|
|
10
|
-
*/
|
|
11
|
-
function create_snapshot(source) {
|
|
12
|
-
return ts.ScriptSnapshot.fromString(source);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @returns {ReturnType<typeof getRippleLanguagePlugin>}
|
|
17
|
-
*/
|
|
18
|
-
function create_plugin() {
|
|
19
|
-
return getRippleLanguagePlugin();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @param {ReturnType<typeof getRippleLanguagePlugin>} plugin
|
|
24
|
-
* @param {string} file_name
|
|
25
|
-
* @param {string} source
|
|
26
|
-
* @returns {TSRXVirtualCode}
|
|
27
|
-
*/
|
|
28
|
-
function create_virtual_code(plugin, file_name, source) {
|
|
29
|
-
const create_virtual_code_fn = plugin.createVirtualCode;
|
|
30
|
-
if (typeof create_virtual_code_fn !== 'function') {
|
|
31
|
-
throw new Error('Language plugin does not expose createVirtualCode');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** @type {import('@volar/language-core').CodegenContext<string>} */
|
|
35
|
-
const ctx = { getAssociatedScript: () => undefined };
|
|
36
|
-
|
|
37
|
-
return /** @type {TSRXVirtualCode} */ (
|
|
38
|
-
create_virtual_code_fn(file_name, 'ripple', create_snapshot(source), ctx)
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('typescript-plugin language plugin integration', () => {
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
_reset_for_test();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
cleanup_fixture_workspaces();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('recognizes only .tsrx through the language plugin', () => {
|
|
52
|
-
const plugin = create_plugin();
|
|
53
|
-
|
|
54
|
-
expect(plugin.getLanguageId('/tmp/App.tsrx')).toBe('ripple');
|
|
55
|
-
expect(plugin.getLanguageId('/tmp/App.ripple')).toBeUndefined();
|
|
56
|
-
expect(plugin.getLanguageId('/tmp/App.rsrx')).toBeUndefined();
|
|
57
|
-
expect(plugin.getLanguageId('/tmp/App.ts')).toBeUndefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('creates virtual code with the ripple compiler in a ripple project', () => {
|
|
61
|
-
const plugin = create_plugin();
|
|
62
|
-
const workspace = create_fixture_workspace('both');
|
|
63
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
64
|
-
const virtual_code = create_virtual_code(plugin, file_name, '<div>Hello Ripple</div>');
|
|
65
|
-
|
|
66
|
-
expect(virtual_code).toBeInstanceOf(TSRXVirtualCode);
|
|
67
|
-
expect(virtual_code.generatedCode).toContain('compiler:ripple');
|
|
68
|
-
expect(virtual_code.generatedCode).toContain(file_name);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('creates virtual code with the react compiler in a react project when both compilers exist', () => {
|
|
72
|
-
const plugin = create_plugin();
|
|
73
|
-
const workspace = create_fixture_workspace('both-react');
|
|
74
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
75
|
-
const virtual_code = create_virtual_code(
|
|
76
|
-
plugin,
|
|
77
|
-
file_name,
|
|
78
|
-
'export default function App() { return <div>Hello TSRX</div>; }',
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(virtual_code).toBeInstanceOf(TSRXVirtualCode);
|
|
82
|
-
expect(virtual_code.generatedCode).toContain('compiler:react');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('creates virtual code with the react compiler in a react-only project', () => {
|
|
86
|
-
const plugin = create_plugin();
|
|
87
|
-
const workspace = create_fixture_workspace('react-only');
|
|
88
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
89
|
-
const virtual_code = create_virtual_code(plugin, file_name, 'export default <div>Hello</div>;');
|
|
90
|
-
|
|
91
|
-
expect(virtual_code).toBeInstanceOf(TSRXVirtualCode);
|
|
92
|
-
expect(virtual_code.generatedCode).toContain('compiler:react');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('creates virtual code with the ripple compiler in a ripple-only project', () => {
|
|
96
|
-
const plugin = create_plugin();
|
|
97
|
-
const workspace = create_fixture_workspace('ripple-only');
|
|
98
|
-
const file_name = path.join(workspace, 'src', 'App.tsrx');
|
|
99
|
-
const virtual_code = create_virtual_code(plugin, file_name, '<div>Hello</div>');
|
|
100
|
-
|
|
101
|
-
expect(virtual_code).toBeInstanceOf(TSRXVirtualCode);
|
|
102
|
-
expect(virtual_code.generatedCode).toContain('compiler:ripple');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('returns undefined for non-tsrx files before compiler resolution', () => {
|
|
106
|
-
const plugin = create_plugin();
|
|
107
|
-
const create_virtual_code_fn = /** @type {any} */ (plugin.createVirtualCode);
|
|
108
|
-
if (typeof create_virtual_code_fn !== 'function') {
|
|
109
|
-
throw new Error('Language plugin does not expose createVirtualCode');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
expect(
|
|
113
|
-
create_virtual_code_fn(
|
|
114
|
-
path.join(create_fixture_workspace('both'), 'src', 'App.ripple'),
|
|
115
|
-
'ripple',
|
|
116
|
-
create_snapshot('<div>Hello</div>'),
|
|
117
|
-
),
|
|
118
|
-
).toBeUndefined();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
const COMPILER_STUBS = {
|
|
6
|
-
ripple: `module.exports = {
|
|
7
|
-
compile_to_volar_mappings(source, filename) {
|
|
8
|
-
const code = \`/* compiler:ripple */\\nexport const filename = \${JSON.stringify(filename)};\\nexport default \${JSON.stringify(source)};\`;
|
|
9
|
-
return {
|
|
10
|
-
code,
|
|
11
|
-
mappings: [
|
|
12
|
-
{
|
|
13
|
-
sourceOffsets: [0],
|
|
14
|
-
generatedOffsets: [0],
|
|
15
|
-
lengths: [source.length],
|
|
16
|
-
generatedLengths: [source.length],
|
|
17
|
-
data: {
|
|
18
|
-
verification: false,
|
|
19
|
-
completion: true,
|
|
20
|
-
semantic: true,
|
|
21
|
-
navigation: true,
|
|
22
|
-
structure: true,
|
|
23
|
-
format: true,
|
|
24
|
-
customData: {},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
cssMappings: [],
|
|
29
|
-
errors: [],
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
`,
|
|
34
|
-
react: `module.exports = {
|
|
35
|
-
compile_to_volar_mappings(source, filename) {
|
|
36
|
-
const code = \`/* compiler:react */\\nexport const filename = \${JSON.stringify(filename)};\\nexport default \${JSON.stringify(source)};\`;
|
|
37
|
-
return {
|
|
38
|
-
code,
|
|
39
|
-
mappings: [
|
|
40
|
-
{
|
|
41
|
-
sourceOffsets: [0],
|
|
42
|
-
generatedOffsets: [0],
|
|
43
|
-
lengths: [source.length],
|
|
44
|
-
generatedLengths: [source.length],
|
|
45
|
-
data: {
|
|
46
|
-
verification: false,
|
|
47
|
-
completion: true,
|
|
48
|
-
semantic: true,
|
|
49
|
-
navigation: true,
|
|
50
|
-
structure: true,
|
|
51
|
-
format: true,
|
|
52
|
-
customData: {},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
cssMappings: [],
|
|
57
|
-
errors: [],
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
`,
|
|
62
|
-
solid: `module.exports = {
|
|
63
|
-
compile_to_volar_mappings(source, filename) {
|
|
64
|
-
const code = \`/* compiler:solid */\\nexport const filename = \${JSON.stringify(filename)};\\nexport default \${JSON.stringify(source)};\`;
|
|
65
|
-
return {
|
|
66
|
-
code,
|
|
67
|
-
mappings: [
|
|
68
|
-
{
|
|
69
|
-
sourceOffsets: [0],
|
|
70
|
-
generatedOffsets: [0],
|
|
71
|
-
lengths: [source.length],
|
|
72
|
-
generatedLengths: [source.length],
|
|
73
|
-
data: {
|
|
74
|
-
verification: false,
|
|
75
|
-
completion: true,
|
|
76
|
-
semantic: true,
|
|
77
|
-
navigation: true,
|
|
78
|
-
structure: true,
|
|
79
|
-
format: true,
|
|
80
|
-
customData: {},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
cssMappings: [],
|
|
85
|
-
errors: [],
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
`,
|
|
90
|
-
preact: `module.exports = {
|
|
91
|
-
compile_to_volar_mappings(source, filename) {
|
|
92
|
-
const code = \`/* compiler:preact */\\nexport const filename = \${JSON.stringify(filename)};\\nexport default \${JSON.stringify(source)};\`;
|
|
93
|
-
return {
|
|
94
|
-
code,
|
|
95
|
-
mappings: [
|
|
96
|
-
{
|
|
97
|
-
sourceOffsets: [0],
|
|
98
|
-
generatedOffsets: [0],
|
|
99
|
-
lengths: [source.length],
|
|
100
|
-
generatedLengths: [source.length],
|
|
101
|
-
data: {
|
|
102
|
-
verification: false,
|
|
103
|
-
completion: true,
|
|
104
|
-
semantic: true,
|
|
105
|
-
navigation: true,
|
|
106
|
-
structure: true,
|
|
107
|
-
format: true,
|
|
108
|
-
customData: {},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
cssMappings: [],
|
|
113
|
-
errors: [],
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
`,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export const WORKSPACE_CONFIGS = {
|
|
121
|
-
'ripple-only': {
|
|
122
|
-
package_json: {
|
|
123
|
-
name: '@ripple-ts/fixture-ripple-only-project',
|
|
124
|
-
private: true,
|
|
125
|
-
devDependencies: {
|
|
126
|
-
'@tsrx/ripple': 'workspace:*',
|
|
127
|
-
'@ripple-ts/vite-plugin': 'workspace:*',
|
|
128
|
-
ripple: 'workspace:*',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
compilers: ['ripple'],
|
|
132
|
-
},
|
|
133
|
-
'react-only': {
|
|
134
|
-
package_json: {
|
|
135
|
-
name: '@tsrx/fixture-react-only-project',
|
|
136
|
-
private: true,
|
|
137
|
-
devDependencies: {
|
|
138
|
-
'@tsrx/react': 'workspace:*',
|
|
139
|
-
'@tsrx/vite-plugin-react': 'workspace:*',
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
compilers: ['react'],
|
|
143
|
-
},
|
|
144
|
-
'solid-only': {
|
|
145
|
-
package_json: {
|
|
146
|
-
name: '@tsrx/fixture-solid-only-project',
|
|
147
|
-
private: true,
|
|
148
|
-
devDependencies: {
|
|
149
|
-
'@tsrx/solid': 'workspace:*',
|
|
150
|
-
'@tsrx/vite-plugin-solid': 'workspace:*',
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
compilers: ['solid'],
|
|
154
|
-
},
|
|
155
|
-
'preact-only': {
|
|
156
|
-
package_json: {
|
|
157
|
-
name: '@tsrx/fixture-preact-only-project',
|
|
158
|
-
private: true,
|
|
159
|
-
devDependencies: {
|
|
160
|
-
'@tsrx/preact': 'workspace:*',
|
|
161
|
-
'@tsrx/vite-plugin-preact': 'workspace:*',
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
compilers: ['preact'],
|
|
165
|
-
},
|
|
166
|
-
both: {
|
|
167
|
-
package_json: {
|
|
168
|
-
name: '@ripple-ts/fixture-ripple-project',
|
|
169
|
-
private: true,
|
|
170
|
-
devDependencies: {
|
|
171
|
-
'@tsrx/ripple': 'workspace:*',
|
|
172
|
-
'@ripple-ts/vite-plugin': 'workspace:*',
|
|
173
|
-
ripple: 'workspace:*',
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
compilers: ['ripple', 'react'],
|
|
177
|
-
},
|
|
178
|
-
'both-react': {
|
|
179
|
-
package_json: {
|
|
180
|
-
name: '@tsrx/fixture-react-project',
|
|
181
|
-
private: true,
|
|
182
|
-
devDependencies: {
|
|
183
|
-
'@tsrx/react': 'workspace:*',
|
|
184
|
-
'@tsrx/vite-plugin-react': 'workspace:*',
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
compilers: ['ripple', 'react'],
|
|
188
|
-
},
|
|
189
|
-
'both-preact': {
|
|
190
|
-
package_json: {
|
|
191
|
-
name: '@tsrx/fixture-preact-project',
|
|
192
|
-
private: true,
|
|
193
|
-
devDependencies: {
|
|
194
|
-
'@tsrx/preact': 'workspace:*',
|
|
195
|
-
'@tsrx/vite-plugin-preact': 'workspace:*',
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
compilers: ['ripple', 'react', 'solid', 'preact'],
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/** @type {string[]} */
|
|
203
|
-
const created_workspaces = [];
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* @param {string} workspace_dir
|
|
207
|
-
* @param {keyof typeof COMPILER_STUBS} compiler_name
|
|
208
|
-
*/
|
|
209
|
-
function write_compiler_stub(workspace_dir, compiler_name) {
|
|
210
|
-
const compiler_dir = path.join(workspace_dir, 'node_modules', '@tsrx', compiler_name, 'src');
|
|
211
|
-
fs.mkdirSync(compiler_dir, { recursive: true });
|
|
212
|
-
fs.writeFileSync(path.join(compiler_dir, 'index.js'), COMPILER_STUBS[compiler_name]);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* @param {keyof typeof WORKSPACE_CONFIGS} name
|
|
217
|
-
*/
|
|
218
|
-
export function create_fixture_workspace(name) {
|
|
219
|
-
const config = WORKSPACE_CONFIGS[name];
|
|
220
|
-
if (!config) {
|
|
221
|
-
throw new Error(`Unknown fixture workspace: ${name}`);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const workspace_dir = fs.mkdtempSync(path.join(os.tmpdir(), `ts-plugin-${name}-`));
|
|
225
|
-
created_workspaces.push(workspace_dir);
|
|
226
|
-
|
|
227
|
-
fs.mkdirSync(path.join(workspace_dir, 'src', 'nested', 'components'), { recursive: true });
|
|
228
|
-
fs.writeFileSync(
|
|
229
|
-
path.join(workspace_dir, 'package.json'),
|
|
230
|
-
JSON.stringify(config.package_json, null, 2) + '\n',
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
for (const compiler_name of config.compilers) {
|
|
234
|
-
write_compiler_stub(workspace_dir, /** @type {keyof typeof COMPILER_STUBS} */ (compiler_name));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return workspace_dir;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export function cleanup_fixture_workspaces() {
|
|
241
|
-
while (created_workspaces.length > 0) {
|
|
242
|
-
fs.rmSync(/** @type {string} */ (created_workspaces.pop()), { recursive: true, force: true });
|
|
243
|
-
}
|
|
244
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "esnext",
|
|
4
|
-
"moduleResolution": "bundler",
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"lib": ["esnext"],
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"checkJs": true,
|
|
9
|
-
"noEmit": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"types": ["node"]
|
|
14
|
-
},
|
|
15
|
-
"include": ["./src/**/*", "./tests/**/*"],
|
|
16
|
-
"exclude": ["dist", "node_modules"]
|
|
17
|
-
}
|