@dxup/nuxt 0.2.0 → 0.2.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 +44 -8
- package/dist/module.js +3 -5
- package/dist/typescript.cjs +25 -16
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -6,14 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
This is a TypeScript plugin that improves Nuxt DX.
|
|
8
8
|
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- Update references when renaming auto imported component files
|
|
12
|
-
- Go to definition for dynamic imports with glob patterns
|
|
13
|
-
- Go to definition for nitro routes in data fetching methods
|
|
14
|
-
- Go to definition for runtime config
|
|
15
|
-
- [@dxup/unimport](/packages/unimport)
|
|
16
|
-
|
|
17
9
|
## Installation
|
|
18
10
|
|
|
19
11
|
```bash
|
|
@@ -31,3 +23,47 @@ export default defineNuxtConfig({
|
|
|
31
23
|
],
|
|
32
24
|
});
|
|
33
25
|
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
### components
|
|
30
|
+
|
|
31
|
+
Update references when renaming auto imported component files.
|
|
32
|
+
|
|
33
|
+
### importGlob
|
|
34
|
+
|
|
35
|
+
Go to definition for dynamic imports with glob patterns.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import(`~/assets/${name}.webp`);
|
|
39
|
+
// ^^^^^^^^^^^^^^^^^^^^^^^
|
|
40
|
+
import.meta.glob("~/assets/*.webp");
|
|
41
|
+
// ^^^^^^^^^^^^^^^^^
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### nitroRoutes
|
|
45
|
+
|
|
46
|
+
Go to definition for nitro routes in data fetching methods.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
useFetch("/api/foo");
|
|
50
|
+
// ^^^^^^^^^^
|
|
51
|
+
// Also `$fetch` and `useLazyFetch`.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
It will fallback to resolve the URL from your `public` directory when no nitro routes match.
|
|
55
|
+
|
|
56
|
+
### runtimeConfig
|
|
57
|
+
|
|
58
|
+
Go to definition for runtime config.
|
|
59
|
+
|
|
60
|
+
```vue
|
|
61
|
+
<template>
|
|
62
|
+
{{ $config.public.domain }}
|
|
63
|
+
<!-- ^^^^^^ -->
|
|
64
|
+
</template>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### unimport
|
|
68
|
+
|
|
69
|
+
Please refer to the [@dxup/unimport](/packages/unimport) package for more details.
|
package/dist/module.js
CHANGED
|
@@ -88,14 +88,12 @@ var module_default = defineNuxtModule({
|
|
|
88
88
|
write: true,
|
|
89
89
|
getContents({ nuxt: nuxt$1 }) {
|
|
90
90
|
const nitro = useNitro();
|
|
91
|
-
const nitroRoutes = options.features?.nitroRoutes && Object.fromEntries(nitro.scannedHandlers.filter((item) => item.route).map((item) => [`${item.route}+${item.method ?? "get"}`, item.handler]));
|
|
92
91
|
const data = {
|
|
93
92
|
buildDir: nuxt$1.options.buildDir,
|
|
93
|
+
publicDir: nuxt$1.options.dir.public,
|
|
94
94
|
configFiles: [...nuxt$1.options._nuxtConfigFiles, ...nuxt$1.options._layers.map((layer) => layer._configFile).filter(Boolean)],
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
nitroRoutes,
|
|
98
|
-
runtimeConfig: options.features?.runtimeConfig
|
|
95
|
+
nitroRoutes: Object.fromEntries(nitro.scannedHandlers.filter((item) => item.route).map((item) => [`${item.route}+${item.method ?? "get"}`, item.handler])),
|
|
96
|
+
features: options.features
|
|
99
97
|
};
|
|
100
98
|
return JSON.stringify(data, null, 2);
|
|
101
99
|
}
|
package/dist/typescript.cjs
CHANGED
|
@@ -74,8 +74,8 @@ function* binaryVisit(ts, sourceFile, node, position) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
return textSpan.start + textSpan.length
|
|
77
|
+
function isTextSpanWithin(node, textSpan, sourceFile) {
|
|
78
|
+
return textSpan.start + textSpan.length <= node.getEnd() && textSpan.start >= node.getStart(sourceFile);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
//#endregion
|
|
@@ -96,8 +96,8 @@ function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
|
96
96
|
const checker = program$1.getTypeChecker();
|
|
97
97
|
let res;
|
|
98
98
|
for (const node of forEachTouchingNode(ts, sourceFile, args[1])) {
|
|
99
|
-
if (data.importGlob) res ??= visitImportGlob(ts, info, sourceFile, node, args[1]);
|
|
100
|
-
if (data.nitroRoutes) res ??= visitNitroRoutes(ts, checker, sourceFile, node, args[1]
|
|
99
|
+
if (data.features.importGlob) res ??= visitImportGlob(ts, info, sourceFile, node, args[1]);
|
|
100
|
+
if (data.features.nitroRoutes) res ??= visitNitroRoutes(ts, data, checker, sourceFile, node, args[1]);
|
|
101
101
|
}
|
|
102
102
|
if (res) return res;
|
|
103
103
|
}
|
|
@@ -108,7 +108,7 @@ function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
|
108
108
|
const sourceFile = program.getSourceFile(definition.fileName);
|
|
109
109
|
if (!sourceFile) continue;
|
|
110
110
|
let result$1 = [];
|
|
111
|
-
if (data.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(context, sourceFile, definition);
|
|
111
|
+
if (data.features.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(context, sourceFile, definition);
|
|
112
112
|
if (result$1?.length) {
|
|
113
113
|
for (const definition$1 of result$1) definitions.add(definition$1);
|
|
114
114
|
definitions.delete(definition);
|
|
@@ -159,8 +159,8 @@ function visitImportGlob(ts, info, sourceFile, node, position) {
|
|
|
159
159
|
}))
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
-
function visitNitroRoutes(ts, checker, sourceFile, node, position
|
|
163
|
-
if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression) || !fetchFunctions.has(node.expression.text) || !node.arguments.length) return;
|
|
162
|
+
function visitNitroRoutes(ts, data, checker, sourceFile, node, position) {
|
|
163
|
+
if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression) || !fetchFunctions.has(node.expression.text) || !node.arguments.length || !ts.isStringLiteralLike(node.arguments[0])) return;
|
|
164
164
|
const firstArg = node.arguments[0];
|
|
165
165
|
const start = firstArg.getStart(sourceFile);
|
|
166
166
|
const end = firstArg.getEnd();
|
|
@@ -178,11 +178,16 @@ function visitNitroRoutes(ts, checker, sourceFile, node, position, nitroRoutes)
|
|
|
178
178
|
routeType = typeArguments?.[2];
|
|
179
179
|
methodType = typeArguments?.[3];
|
|
180
180
|
}
|
|
181
|
-
if (!routeType?.isStringLiteral()) return;
|
|
182
181
|
const paths = [];
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
182
|
+
if (routeType?.isStringLiteral()) {
|
|
183
|
+
for (const type of methodType?.isUnion() ? methodType.types : [methodType]) if (type?.isStringLiteral()) {
|
|
184
|
+
const path = data.nitroRoutes[`${routeType.value}+${type.value}`];
|
|
185
|
+
if (path !== void 0) paths.push(path);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (!paths.length && firstArg.text.startsWith("/")) {
|
|
189
|
+
const fallback = (0, pathe.join)(data.publicDir, firstArg.text);
|
|
190
|
+
if (ts.sys.fileExists(fallback)) paths.push(fallback);
|
|
186
191
|
}
|
|
187
192
|
return {
|
|
188
193
|
textSpan: {
|
|
@@ -211,7 +216,7 @@ function visitRuntimeConfig(context, sourceFile, definition) {
|
|
|
211
216
|
if (ts.isInterfaceDeclaration(node) && ts.isIdentifier(node.name)) key = node.name.text;
|
|
212
217
|
else if (ts.isPropertySignature(node) && ts.isIdentifier(node.name)) {
|
|
213
218
|
key = node.name.text;
|
|
214
|
-
if (
|
|
219
|
+
if (isTextSpanWithin(node.name, definition.textSpan, sourceFile)) {
|
|
215
220
|
path.push(key);
|
|
216
221
|
definitions = [...forwardRuntimeConfig(context, definition, path)];
|
|
217
222
|
break;
|
|
@@ -303,7 +308,7 @@ function getEditsForFileRename(context, getEditsForFileRename$1) {
|
|
|
303
308
|
const references = {};
|
|
304
309
|
for (const change of result) {
|
|
305
310
|
const { fileName, textChanges } = change;
|
|
306
|
-
if (data.components && fileName.endsWith("components.d.ts")) {
|
|
311
|
+
if (data.features.components && fileName.endsWith("components.d.ts")) {
|
|
307
312
|
const sourceFile = program.getSourceFile(fileName);
|
|
308
313
|
if (!sourceFile) continue;
|
|
309
314
|
for (const { span } of textChanges) for (const node of forEachTouchingNode(ts, sourceFile, span.start)) {
|
|
@@ -358,11 +363,15 @@ var typescript_default = plugin;
|
|
|
358
363
|
function createData(ts, info) {
|
|
359
364
|
const initialValue = {
|
|
360
365
|
buildDir: "",
|
|
366
|
+
publicDir: "",
|
|
361
367
|
configFiles: [],
|
|
362
|
-
components: true,
|
|
363
|
-
importGlob: true,
|
|
364
368
|
nitroRoutes: {},
|
|
365
|
-
|
|
369
|
+
features: {
|
|
370
|
+
components: true,
|
|
371
|
+
importGlob: true,
|
|
372
|
+
nitroRoutes: true,
|
|
373
|
+
runtimeConfig: true
|
|
374
|
+
}
|
|
366
375
|
};
|
|
367
376
|
const path = (0, pathe.join)(info.languageServiceHost.getCurrentDirectory(), "dxup/data.json");
|
|
368
377
|
const data = {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxup/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "TypeScript plugin for Nuxt",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@nuxt/kit": "^4.
|
|
19
|
+
"@nuxt/kit": "^4.2.0",
|
|
20
20
|
"chokidar": "^4.0.3",
|
|
21
|
-
"pathe": "2.0.3",
|
|
21
|
+
"pathe": "^2.0.3",
|
|
22
22
|
"tinyglobby": "^0.2.15",
|
|
23
|
-
"@dxup/unimport": "^0.1.
|
|
23
|
+
"@dxup/unimport": "^0.1.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@dxup/shared": "",
|
|
27
27
|
"@volar/language-core": "^2.4.23",
|
|
28
28
|
"@volar/typescript": "^2.4.23",
|
|
29
|
-
"@vue/language-core": "^3.1.
|
|
30
|
-
"nuxt": "^4.
|
|
29
|
+
"@vue/language-core": "^3.1.3",
|
|
30
|
+
"nuxt": "^4.2.0",
|
|
31
31
|
"typescript": "^5.9.3"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|