@dxup/nuxt 0.0.5 → 0.1.0
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/README.md +1 -1
- package/dist/typescript.cjs +22 -27
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@dxup/nuxt)
|
|
5
5
|
[](/LICENSE)
|
|
6
6
|
|
|
7
|
-
This is a
|
|
7
|
+
This is a TypeScript plugin that improves Nuxt DX.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
package/dist/typescript.cjs
CHANGED
|
@@ -50,7 +50,7 @@ function findRenameLocations(context, findRenameLocations$1) {
|
|
|
50
50
|
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region ../shared/src/index.ts
|
|
53
|
-
function*
|
|
53
|
+
function* forEachTouchingNode(ts, sourceFile, position) {
|
|
54
54
|
yield* binaryVisit(ts, sourceFile, sourceFile, position);
|
|
55
55
|
}
|
|
56
56
|
function* binaryVisit(ts, sourceFile, node, position) {
|
|
@@ -92,7 +92,7 @@ function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
|
92
92
|
const sourceFile = program$1.getSourceFile(args[0]);
|
|
93
93
|
if (!sourceFile) return;
|
|
94
94
|
const checker = program$1.getTypeChecker();
|
|
95
|
-
for (const node of
|
|
95
|
+
for (const node of forEachTouchingNode(ts, sourceFile, args[1])) {
|
|
96
96
|
if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression) || !fetchFunctions.has(node.expression.text) || !node.arguments.length) continue;
|
|
97
97
|
const firstArg = node.arguments[0];
|
|
98
98
|
const start = firstArg.getStart(sourceFile);
|
|
@@ -101,11 +101,10 @@ function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
|
101
101
|
const resolvedSignature = checker.getResolvedSignature(node);
|
|
102
102
|
if (!resolvedSignature) break;
|
|
103
103
|
const typeArguments = checker.getTypeArgumentsForResolvedSignature(resolvedSignature);
|
|
104
|
-
const routeType = typeArguments?.[2];
|
|
105
|
-
|
|
106
|
-
if (!routeType?.isStringLiteral() || !methodtype?.isStringLiteral()) break;
|
|
104
|
+
const [routeType, methodType] = (node.expression.text === "$fetch" ? typeArguments?.[2] && checker.getTypeArguments(typeArguments?.[2]) : typeArguments?.slice(2)) ?? [];
|
|
105
|
+
if (!routeType?.isStringLiteral() || !methodType?.isStringLiteral()) break;
|
|
107
106
|
const route = routeType.value.replace(nonApiRE, "/routes");
|
|
108
|
-
const method =
|
|
107
|
+
const method = methodType.value;
|
|
109
108
|
const path = (0, pathe.join)(data.serverDir, `${route}.${method}.ts`);
|
|
110
109
|
return {
|
|
111
110
|
textSpan: {
|
|
@@ -130,7 +129,6 @@ function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
|
130
129
|
if (!result?.definitions?.length) return result;
|
|
131
130
|
const program = info.languageService.getProgram();
|
|
132
131
|
const definitions = new Set(result.definitions);
|
|
133
|
-
const skippedDefinitions = [];
|
|
134
132
|
for (const definition of result.definitions) {
|
|
135
133
|
const sourceFile = program.getSourceFile(definition.fileName);
|
|
136
134
|
if (!sourceFile) continue;
|
|
@@ -138,10 +136,9 @@ function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
|
138
136
|
if (data.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(context, sourceFile, definition);
|
|
139
137
|
if (result$1?.length) {
|
|
140
138
|
for (const definition$1 of result$1) definitions.add(definition$1);
|
|
141
|
-
|
|
139
|
+
definitions.delete(definition);
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
|
-
for (const definition of skippedDefinitions) definitions.delete(definition);
|
|
145
142
|
return {
|
|
146
143
|
definitions: [...definitions],
|
|
147
144
|
textSpan: result.textSpan
|
|
@@ -152,7 +149,7 @@ function visitRuntimeConfig(context, sourceFile, definition) {
|
|
|
152
149
|
const { ts } = context;
|
|
153
150
|
let definitions = [];
|
|
154
151
|
const path = [];
|
|
155
|
-
for (const node of
|
|
152
|
+
for (const node of forEachTouchingNode(ts, sourceFile, definition.textSpan.start)) {
|
|
156
153
|
let key;
|
|
157
154
|
if (ts.isInterfaceDeclaration(node) && ts.isIdentifier(node.name)) key = node.name.text;
|
|
158
155
|
else if (ts.isPropertySignature(node) && ts.isIdentifier(node.name)) {
|
|
@@ -162,7 +159,7 @@ function visitRuntimeConfig(context, sourceFile, definition) {
|
|
|
162
159
|
const end = node.name.getEnd();
|
|
163
160
|
if (start === textSpan.start && end - start === textSpan.length) {
|
|
164
161
|
path.push(key);
|
|
165
|
-
definitions = [...
|
|
162
|
+
definitions = [...forwardRuntimeConfig(context, definition, path)];
|
|
166
163
|
break;
|
|
167
164
|
}
|
|
168
165
|
}
|
|
@@ -170,7 +167,7 @@ function visitRuntimeConfig(context, sourceFile, definition) {
|
|
|
170
167
|
}
|
|
171
168
|
return definitions;
|
|
172
169
|
}
|
|
173
|
-
function*
|
|
170
|
+
function* forwardRuntimeConfig(context, definition, path) {
|
|
174
171
|
const { ts, info, data } = context;
|
|
175
172
|
switch (path[0]) {
|
|
176
173
|
case "SharedRuntimeConfig":
|
|
@@ -249,14 +246,13 @@ function getEditsForFileRename(context, getEditsForFileRename$1) {
|
|
|
249
246
|
const result = getEditsForFileRename$1(...args);
|
|
250
247
|
if (!result?.length) return result;
|
|
251
248
|
const program = info.languageService.getProgram();
|
|
252
|
-
const changes = [];
|
|
253
249
|
const references = {};
|
|
254
250
|
for (const change of result) {
|
|
255
251
|
const { fileName, textChanges } = change;
|
|
256
252
|
if (data.components && fileName.endsWith("components.d.ts")) {
|
|
257
253
|
const sourceFile = program.getSourceFile(fileName);
|
|
258
254
|
if (!sourceFile) continue;
|
|
259
|
-
for (const { span } of textChanges) for (const node of
|
|
255
|
+
for (const { span } of textChanges) for (const node of forEachTouchingNode(ts, sourceFile, span.start)) {
|
|
260
256
|
if (!ts.isPropertySignature(node) && !ts.isVariableDeclaration(node)) continue;
|
|
261
257
|
const position = node.name.getStart(sourceFile);
|
|
262
258
|
const res = info.languageService.getReferencesAtPosition(fileName, position)?.filter((entry) => !entry.fileName.startsWith(data.buildDir));
|
|
@@ -268,13 +264,14 @@ function getEditsForFileRename(context, getEditsForFileRename$1) {
|
|
|
268
264
|
break;
|
|
269
265
|
}
|
|
270
266
|
}
|
|
271
|
-
if (!fileName.startsWith(data.buildDir)) changes.push(change);
|
|
272
267
|
}
|
|
273
268
|
if (Object.keys(references).length) server.write("components:rename", {
|
|
274
269
|
fileName: args[1],
|
|
275
270
|
references
|
|
276
271
|
});
|
|
277
|
-
return
|
|
272
|
+
return result.filter((change) => {
|
|
273
|
+
return !change.fileName.startsWith(data.buildDir);
|
|
274
|
+
});
|
|
278
275
|
};
|
|
279
276
|
}
|
|
280
277
|
|
|
@@ -285,20 +282,18 @@ const plugin = (module$1) => {
|
|
|
285
282
|
return { create(info) {
|
|
286
283
|
const currentDirectory = info.languageServiceHost.getCurrentDirectory();
|
|
287
284
|
const path = (0, pathe.join)(currentDirectory, "dxup/data.json");
|
|
288
|
-
const data = {
|
|
289
|
-
buildDir: currentDirectory,
|
|
290
|
-
configFiles: [],
|
|
291
|
-
components: true,
|
|
292
|
-
nitroRoutes: true,
|
|
293
|
-
runtimeConfig: true,
|
|
294
|
-
...JSON.parse(ts.sys.readFile(path) ?? "{}")
|
|
295
|
-
};
|
|
296
|
-
const server = createEventServer(info);
|
|
297
285
|
const context = {
|
|
298
286
|
ts,
|
|
299
287
|
info,
|
|
300
|
-
data
|
|
301
|
-
|
|
288
|
+
data: {
|
|
289
|
+
buildDir: currentDirectory,
|
|
290
|
+
configFiles: [],
|
|
291
|
+
components: true,
|
|
292
|
+
nitroRoutes: true,
|
|
293
|
+
runtimeConfig: true,
|
|
294
|
+
...JSON.parse(ts.sys.readFile(path) ?? "{}")
|
|
295
|
+
},
|
|
296
|
+
server: createEventServer(info)
|
|
302
297
|
};
|
|
303
298
|
setTimeout(() => {
|
|
304
299
|
context.language = (info.project.__vue__ ?? info.project["program"]?.__vue__)?.language;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxup/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"description": "TypeScript
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "TypeScript plugin for Nuxt",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": "KazariEX/dxup",
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@nuxt/kit": "^4.1.
|
|
19
|
+
"@nuxt/kit": "^4.1.3",
|
|
20
20
|
"chokidar": "^4.0.3",
|
|
21
21
|
"pathe": "2.0.3",
|
|
22
|
-
"@dxup/unimport": "^0.0
|
|
22
|
+
"@dxup/unimport": "^0.1.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@dxup/shared": "",
|
|
26
26
|
"@volar/language-core": "^2.4.23",
|
|
27
27
|
"@volar/typescript": "^2.4.23",
|
|
28
|
-
"@vue/language-core": "^3.
|
|
29
|
-
"nuxt": "^4.1.
|
|
30
|
-
"typescript": "^5.9.
|
|
28
|
+
"@vue/language-core": "^3.1.1",
|
|
29
|
+
"nuxt": "^4.1.3",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsdown",
|