@react-spectrum/ts-plugin 3.0.0-nightly-a45e2a5ec-241011
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/package.json +17 -0
- package/src/index.js +49 -0
package/package.json
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"name": "@react-spectrum/ts-plugin",
|
3
|
+
"version": "3.0.0-nightly-a45e2a5ec-241011",
|
4
|
+
"main": "./src/index.js",
|
5
|
+
"license": "Apache-2.0",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "https://github.com/adobe/react-spectrum"
|
9
|
+
},
|
10
|
+
"publishConfig": {
|
11
|
+
"access": "public"
|
12
|
+
},
|
13
|
+
"rsp": {
|
14
|
+
"type": "cli"
|
15
|
+
},
|
16
|
+
"stableVersion": "0.1.0"
|
17
|
+
}
|
package/src/index.js
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
*
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
10
|
+
* governing permissions and limitations under the License.
|
11
|
+
*/
|
12
|
+
|
13
|
+
module.exports = function () {
|
14
|
+
/** @param info {import('typescript').server.PluginCreateInfo} */
|
15
|
+
function create(info) {
|
16
|
+
const proxy = Object.create(null);
|
17
|
+
for (let k of Object.keys(info.languageService)) {
|
18
|
+
const x = info.languageService[k];
|
19
|
+
proxy[k] = (...args) => x.apply(info.languageService, args);
|
20
|
+
}
|
21
|
+
|
22
|
+
proxy.getCompletionEntryDetails = (...args) => {
|
23
|
+
let result = info.languageService.getCompletionEntryDetails(...args);
|
24
|
+
if (!result.codeActions) {
|
25
|
+
return result;
|
26
|
+
}
|
27
|
+
|
28
|
+
// Override auto import of style macro to add `with {type: 'macro'}` automatically.
|
29
|
+
for (let action of result.codeActions) {
|
30
|
+
for (let change of action.changes) {
|
31
|
+
for (let textChange of change.textChanges) {
|
32
|
+
if (change.fileName.includes('@react-spectrum/s2')) {
|
33
|
+
// For files inside S2 itself, import specifier will be '../style', not '@react-spectrum/s2/style'.
|
34
|
+
textChange.newText = textChange.newText.replace(/(import\s*\{.*?\}\s*from\s*['"]\.\.\/style['"]);/g, '$1 with {type: \'macro\'};');
|
35
|
+
} else {
|
36
|
+
textChange.newText = textChange.newText.replace(/(import\s*\{.*?\}\s*from\s*['"]@react-spectrum\/s2\/style['"]);/g, '$1 with {type: \'macro\'};');
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
return result;
|
43
|
+
};
|
44
|
+
|
45
|
+
return proxy;
|
46
|
+
}
|
47
|
+
|
48
|
+
return {create};
|
49
|
+
};
|