@dxup/nuxt 0.3.0 → 0.3.1
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 +14 -1
- package/dist/module.d.mts +6 -0
- package/dist/module.mjs +3 -1
- package/dist/typescript.cjs +44 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,20 @@ Go to definition for runtime config.
|
|
|
73
73
|
</template>
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
### 5.
|
|
76
|
+
### 5. typedPages
|
|
77
|
+
|
|
78
|
+
Go to definition for typed pages.
|
|
79
|
+
|
|
80
|
+
```vue
|
|
81
|
+
<template>
|
|
82
|
+
<nuxt-link :to="{ name: `about` }"/>
|
|
83
|
+
<!-- ^^^^^^^ -->
|
|
84
|
+
</template>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
It can be triggered on the `name` property of an object literal constrained by the `RouteLocationRaw` type.
|
|
88
|
+
|
|
89
|
+
### 6. unimport
|
|
77
90
|
|
|
78
91
|
Find references for SFC on `<template>`.
|
|
79
92
|
|
package/dist/module.d.mts
CHANGED
|
@@ -23,6 +23,11 @@ interface ModuleOptions {
|
|
|
23
23
|
* @default true
|
|
24
24
|
*/
|
|
25
25
|
runtimeConfig?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to enable Go to Definition for typed pages.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
typedPages?: boolean;
|
|
26
31
|
/**
|
|
27
32
|
* Whether to enable enhanced navigation for auto imported APIs.
|
|
28
33
|
* @default true
|
|
@@ -41,6 +46,7 @@ declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, {
|
|
|
41
46
|
importGlob: true;
|
|
42
47
|
nitroRoutes: true;
|
|
43
48
|
runtimeConfig: true;
|
|
49
|
+
typedPages: true;
|
|
44
50
|
unimport: true;
|
|
45
51
|
};
|
|
46
52
|
}, true>;
|
package/dist/module.mjs
CHANGED
|
@@ -74,6 +74,7 @@ var module_default = defineNuxtModule().with({
|
|
|
74
74
|
importGlob: true,
|
|
75
75
|
nitroRoutes: true,
|
|
76
76
|
runtimeConfig: true,
|
|
77
|
+
typedPages: true,
|
|
77
78
|
unimport: true
|
|
78
79
|
} },
|
|
79
80
|
async setup(options, nuxt) {
|
|
@@ -86,7 +87,7 @@ var module_default = defineNuxtModule().with({
|
|
|
86
87
|
addTemplate({
|
|
87
88
|
filename: "dxup/data.json",
|
|
88
89
|
write: true,
|
|
89
|
-
getContents({ nuxt: nuxt$1 }) {
|
|
90
|
+
getContents({ nuxt: nuxt$1, app }) {
|
|
90
91
|
const nitroRoutes = useNitro().scannedHandlers.reduce((acc, item) => {
|
|
91
92
|
if (item.route && item.method) (acc[item.route] ??= {})[item.method] = item.handler;
|
|
92
93
|
return acc;
|
|
@@ -96,6 +97,7 @@ var module_default = defineNuxtModule().with({
|
|
|
96
97
|
publicDir: nuxt$1.options.dir.public,
|
|
97
98
|
configFiles: [...nuxt$1.options._nuxtConfigFiles, ...nuxt$1.options._layers.map((layer) => layer._configFile).filter(Boolean)],
|
|
98
99
|
nitroRoutes,
|
|
100
|
+
typedPages: Object.fromEntries(app.pages?.map((page) => [page.name, page.file]) ?? []),
|
|
99
101
|
features: {
|
|
100
102
|
...options.features,
|
|
101
103
|
unimport: { componentReferences: typeof options.features.unimport === "object" ? options.features.unimport.componentReferences : options.features.unimport }
|
package/dist/typescript.cjs
CHANGED
|
@@ -37,11 +37,13 @@ const initialValue = {
|
|
|
37
37
|
publicDir: "",
|
|
38
38
|
configFiles: [],
|
|
39
39
|
nitroRoutes: {},
|
|
40
|
+
typedPages: {},
|
|
40
41
|
features: {
|
|
41
42
|
components: true,
|
|
42
43
|
importGlob: true,
|
|
43
44
|
nitroRoutes: true,
|
|
44
45
|
runtimeConfig: true,
|
|
46
|
+
typedPages: true,
|
|
45
47
|
unimport: { componentReferences: true }
|
|
46
48
|
}
|
|
47
49
|
};
|
|
@@ -66,6 +68,19 @@ function createData(ts, info) {
|
|
|
66
68
|
|
|
67
69
|
//#endregion
|
|
68
70
|
//#region src/typescript/utils.ts
|
|
71
|
+
function createModuleDefinition(ts, path) {
|
|
72
|
+
return {
|
|
73
|
+
fileName: path,
|
|
74
|
+
textSpan: {
|
|
75
|
+
start: 0,
|
|
76
|
+
length: 0
|
|
77
|
+
},
|
|
78
|
+
kind: ts.ScriptElementKind.moduleElement,
|
|
79
|
+
name: `"${path}"`,
|
|
80
|
+
containerKind: ts.ScriptElementKind.unknown,
|
|
81
|
+
containerName: ""
|
|
82
|
+
};
|
|
83
|
+
}
|
|
69
84
|
function isVueVirtualCode(code) {
|
|
70
85
|
return code?.languageId === "vue";
|
|
71
86
|
}
|
|
@@ -199,10 +214,10 @@ function postprocess(context, language, getDefinitionAndBoundSpan) {
|
|
|
199
214
|
definitions: [{
|
|
200
215
|
fileName: args[0],
|
|
201
216
|
textSpan,
|
|
202
|
-
kind: ts.ScriptElementKind.
|
|
203
|
-
name:
|
|
217
|
+
kind: ts.ScriptElementKind.memberVariableElement,
|
|
218
|
+
name: "default",
|
|
204
219
|
containerKind: ts.ScriptElementKind.unknown,
|
|
205
|
-
containerName:
|
|
220
|
+
containerName: args[0]
|
|
206
221
|
}]
|
|
207
222
|
};
|
|
208
223
|
return result;
|
|
@@ -219,12 +234,13 @@ function preprocess$1(context, getDefinitionAndBoundSpan) {
|
|
|
219
234
|
const sourceFile = program$1.getSourceFile(args[0]);
|
|
220
235
|
if (!sourceFile) return;
|
|
221
236
|
const checker = program$1.getTypeChecker();
|
|
222
|
-
let
|
|
237
|
+
let result$1;
|
|
223
238
|
for (const node of forEachTouchingNode(ts, sourceFile, args[1])) {
|
|
224
|
-
if (data.features.importGlob)
|
|
225
|
-
if (data.features.nitroRoutes)
|
|
239
|
+
if (data.features.importGlob) result$1 ??= visitImportGlob(ts, info, sourceFile, node, args[1]);
|
|
240
|
+
if (data.features.nitroRoutes) result$1 ??= visitNitroRoutes(ts, data, checker, sourceFile, node, args[1]);
|
|
241
|
+
if (data.features.typedPages) result$1 ??= visitTypedPages(ts, data, checker, sourceFile, node, args[1]);
|
|
226
242
|
}
|
|
227
|
-
if (
|
|
243
|
+
if (result$1) return result$1;
|
|
228
244
|
}
|
|
229
245
|
if (!result?.definitions?.length) return result;
|
|
230
246
|
const program = info.languageService.getProgram();
|
|
@@ -232,7 +248,7 @@ function preprocess$1(context, getDefinitionAndBoundSpan) {
|
|
|
232
248
|
for (const definition of result.definitions) {
|
|
233
249
|
const sourceFile = program.getSourceFile(definition.fileName);
|
|
234
250
|
if (!sourceFile) continue;
|
|
235
|
-
let result$1
|
|
251
|
+
let result$1;
|
|
236
252
|
if (data.features.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(context, sourceFile, definition);
|
|
237
253
|
if (result$1?.length) {
|
|
238
254
|
for (const definition$1 of result$1) definitions.add(definition$1);
|
|
@@ -271,17 +287,7 @@ function visitImportGlob(ts, info, sourceFile, node, position) {
|
|
|
271
287
|
start,
|
|
272
288
|
length: end - start
|
|
273
289
|
},
|
|
274
|
-
definitions: fileNames.map((fileName) => (
|
|
275
|
-
fileName,
|
|
276
|
-
textSpan: {
|
|
277
|
-
start: 0,
|
|
278
|
-
length: 0
|
|
279
|
-
},
|
|
280
|
-
kind: ts.ScriptElementKind.unknown,
|
|
281
|
-
name: fileName,
|
|
282
|
-
containerKind: ts.ScriptElementKind.unknown,
|
|
283
|
-
containerName: ""
|
|
284
|
-
}))
|
|
290
|
+
definitions: fileNames.map((fileName) => createModuleDefinition(ts, fileName))
|
|
285
291
|
};
|
|
286
292
|
}
|
|
287
293
|
function visitNitroRoutes(ts, data, checker, sourceFile, node, position) {
|
|
@@ -322,17 +328,23 @@ function visitNitroRoutes(ts, data, checker, sourceFile, node, position) {
|
|
|
322
328
|
start,
|
|
323
329
|
length: end - start
|
|
324
330
|
},
|
|
325
|
-
definitions: paths.map((path) => (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
definitions: paths.map((path) => createModuleDefinition(ts, path))
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function visitTypedPages(ts, data, checker, sourceFile, node, position) {
|
|
335
|
+
if (!ts.isPropertyAssignment(node) || !ts.isIdentifier(node.name) || node.name.text !== "name" || !ts.isStringLiteralLike(node.initializer)) return;
|
|
336
|
+
const start = node.initializer.getStart(sourceFile);
|
|
337
|
+
const end = node.initializer.getEnd();
|
|
338
|
+
if (position < start || position > end) return;
|
|
339
|
+
if (checker.getContextualType(node.parent)?.getNonNullableType().aliasSymbol?.name !== "RouteLocationRaw") return;
|
|
340
|
+
const path = data.typedPages[node.initializer.text];
|
|
341
|
+
if (path === void 0) return;
|
|
342
|
+
return {
|
|
343
|
+
textSpan: {
|
|
344
|
+
start,
|
|
345
|
+
length: end - start
|
|
346
|
+
},
|
|
347
|
+
definitions: [createModuleDefinition(ts, path)]
|
|
336
348
|
};
|
|
337
349
|
}
|
|
338
350
|
function visitRuntimeConfig(context, sourceFile, definition) {
|
|
@@ -460,7 +472,7 @@ const plugin = (module$1) => {
|
|
|
460
472
|
data,
|
|
461
473
|
server: createEventServer(info)
|
|
462
474
|
};
|
|
463
|
-
|
|
475
|
+
queueMicrotask(() => {
|
|
464
476
|
context.language = info.project.__vue__?.language;
|
|
465
477
|
if (!context.language || !data.features.unimport.componentReferences) return;
|
|
466
478
|
const languageService = info.project.getLanguageService();
|
|
@@ -477,7 +489,7 @@ const plugin = (module$1) => {
|
|
|
477
489
|
return Reflect.set(...args);
|
|
478
490
|
}
|
|
479
491
|
});
|
|
480
|
-
}
|
|
492
|
+
});
|
|
481
493
|
for (const [key, method] of [
|
|
482
494
|
["findRenameLocations", findRenameLocations_exports],
|
|
483
495
|
["getDefinitionAndBoundSpan", getDefinitionAndBoundSpan_exports],
|