@dxup/nuxt 0.0.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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/module.d.ts +6 -0
- package/dist/module.js +65 -0
- package/dist/typescript.cjs +51 -0
- package/dist/typescript.d.cts +5 -0
- package/dist/vue/nitro-routes.cjs +36 -0
- package/dist/vue/nitro-routes.d.cts +5 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present KazariEX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @dxup/nuxt
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@dxup/nuxt)
|
|
4
|
+
[](https://www.npmjs.com/package/@dxup/nuxt)
|
|
5
|
+
[](/LICENSE)
|
|
6
|
+
|
|
7
|
+
This is a collection of TypeScript and Vue plugins that improves Nuxt DX.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Go to definition for nitro routes on data fetching methods
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm i -D @dxup/nuxt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Add the following to your `nuxt.config.ts`:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export default defineNuxtConfig({
|
|
25
|
+
modules: [
|
|
26
|
+
"@dxup/nuxt",
|
|
27
|
+
]
|
|
28
|
+
})
|
|
29
|
+
```
|
package/dist/module.d.ts
ADDED
package/dist/module.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
|
|
3
|
+
//#region package.json
|
|
4
|
+
var name = "@dxup/nuxt";
|
|
5
|
+
var type = "module";
|
|
6
|
+
var version = "0.0.1";
|
|
7
|
+
var packageManager = "pnpm@10.17.1";
|
|
8
|
+
var description = "TypeScript and Vue plugins for Nuxt";
|
|
9
|
+
var author = "KazariEX";
|
|
10
|
+
var license = "MIT";
|
|
11
|
+
var repository = "KazariEX/dxup";
|
|
12
|
+
var exports = {
|
|
13
|
+
".": "./dist/module.js",
|
|
14
|
+
"./vue/nitro-routes": "./dist/vue/nitro-routes.cjs",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
};
|
|
17
|
+
var main = "./dist/typescript.cjs";
|
|
18
|
+
var types = "./dist/typescript.d.cts";
|
|
19
|
+
var files = ["dist"];
|
|
20
|
+
var scripts = {
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"dev": "tsdown -w --sourcemap",
|
|
23
|
+
"prepack": "pnpm run build",
|
|
24
|
+
"release": "bumpp"
|
|
25
|
+
};
|
|
26
|
+
var dependencies = { "@nuxt/kit": "catalog:" };
|
|
27
|
+
var devDependencies = {
|
|
28
|
+
"@vue/language-core": "catalog:",
|
|
29
|
+
"nuxt": "catalog:"
|
|
30
|
+
};
|
|
31
|
+
var package_default = {
|
|
32
|
+
name,
|
|
33
|
+
type,
|
|
34
|
+
version,
|
|
35
|
+
packageManager,
|
|
36
|
+
description,
|
|
37
|
+
author,
|
|
38
|
+
license,
|
|
39
|
+
repository,
|
|
40
|
+
exports,
|
|
41
|
+
main,
|
|
42
|
+
types,
|
|
43
|
+
files,
|
|
44
|
+
scripts,
|
|
45
|
+
dependencies,
|
|
46
|
+
devDependencies
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/module/index.ts
|
|
51
|
+
var module_default = defineNuxtModule({
|
|
52
|
+
meta: {
|
|
53
|
+
name: package_default.name,
|
|
54
|
+
configKey: "dxup"
|
|
55
|
+
},
|
|
56
|
+
async setup(options, nuxt) {
|
|
57
|
+
nuxt.hook("prepare:types", (options$1) => {
|
|
58
|
+
((options$1.tsConfig.compilerOptions ??= {}).plugins ??= []).push({ name: "@dxup/nuxt" });
|
|
59
|
+
((options$1.tsConfig.vueCompilerOptions ??= {}).plugins ??= []).push("@dxup/nuxt/vue/nitro-routes");
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { module_default as default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/typescript/index.ts
|
|
3
|
+
const plugin = (module$1) => {
|
|
4
|
+
const { typescript: ts } = module$1;
|
|
5
|
+
return { create(info) {
|
|
6
|
+
const original = info.languageService.getDefinitionAndBoundSpan;
|
|
7
|
+
info.languageService.getDefinitionAndBoundSpan = getDefinitionAndBoundSpan(ts, info.languageService, original);
|
|
8
|
+
return info.languageService;
|
|
9
|
+
} };
|
|
10
|
+
};
|
|
11
|
+
var typescript_default = plugin;
|
|
12
|
+
function getDefinitionAndBoundSpan(ts, languageService, getDefinitionAndBoundSpan$1) {
|
|
13
|
+
return (fileName, position) => {
|
|
14
|
+
const result = getDefinitionAndBoundSpan$1(fileName, position);
|
|
15
|
+
if (!result?.definitions?.length) return result;
|
|
16
|
+
const program = languageService.getProgram();
|
|
17
|
+
const definitions = new Set(result.definitions);
|
|
18
|
+
const skippedDefinitions = [];
|
|
19
|
+
for (const definition of result.definitions) {
|
|
20
|
+
if (!definition.fileName.endsWith("nitro-routes.d.ts")) continue;
|
|
21
|
+
const sourceFile = program.getSourceFile(definition.fileName);
|
|
22
|
+
if (sourceFile) visit(sourceFile, definition, sourceFile);
|
|
23
|
+
}
|
|
24
|
+
for (const definition of skippedDefinitions) definitions.delete(definition);
|
|
25
|
+
return {
|
|
26
|
+
definitions: [...definitions],
|
|
27
|
+
textSpan: result.textSpan
|
|
28
|
+
};
|
|
29
|
+
function visit(node, definition, sourceFile) {
|
|
30
|
+
if (ts.isPropertySignature(node) && node.type && ts.isTypeLiteralNode(node.type)) {
|
|
31
|
+
const { textSpan } = definition;
|
|
32
|
+
const start = node.name.getStart(sourceFile);
|
|
33
|
+
const end = node.name.getEnd();
|
|
34
|
+
if (start === textSpan.start && end - start === textSpan.length) for (const member of node.type.members) {
|
|
35
|
+
if (!ts.isPropertySignature(member)) continue;
|
|
36
|
+
const pos = (((((member.type?.typeArguments?.[0])?.typeArguments?.[0])?.typeArguments?.[0])?.typeArguments?.[0])?.qualifier)?.getStart(sourceFile);
|
|
37
|
+
if (pos !== void 0) {
|
|
38
|
+
const res = getDefinitionAndBoundSpan$1(definition.fileName, pos);
|
|
39
|
+
if (res?.definitions?.length) {
|
|
40
|
+
for (const definition$1 of res.definitions) definitions.add(definition$1);
|
|
41
|
+
skippedDefinitions.push(definition);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else ts.forEachChild(node, (child) => visit(child, definition, sourceFile));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
module.exports = typescript_default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/vue/nitro-routes.ts
|
|
3
|
+
const functionNames = new Set([
|
|
4
|
+
"$fetch",
|
|
5
|
+
"useFetch",
|
|
6
|
+
"useLazyFetch"
|
|
7
|
+
]);
|
|
8
|
+
const plugin = ({ modules: { typescript: ts } }) => {
|
|
9
|
+
return {
|
|
10
|
+
version: 2.2,
|
|
11
|
+
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
12
|
+
if (!embeddedFile.id.startsWith("script_")) return;
|
|
13
|
+
const { scriptSetup } = sfc;
|
|
14
|
+
if (!scriptSetup) return;
|
|
15
|
+
const codes = [];
|
|
16
|
+
visit(scriptSetup.ast);
|
|
17
|
+
if (codes.length) embeddedFile.content.push(`import type { InternalApi as __VLS_InternalApi } from 'nitropack/types';\n`, ...codes);
|
|
18
|
+
function visit(node) {
|
|
19
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && functionNames.has(node.expression.text) && node.arguments.length && ts.isStringLiteralLike(node.arguments[0])) {
|
|
20
|
+
const arg = node.arguments[0];
|
|
21
|
+
codes.push(`/** @type {__VLS_InternalApi[`, [
|
|
22
|
+
arg.getText(scriptSetup.ast),
|
|
23
|
+
sfc.scriptSetup.name,
|
|
24
|
+
arg.getStart(scriptSetup.ast),
|
|
25
|
+
{ navigation: true }
|
|
26
|
+
], `]} */;\n`);
|
|
27
|
+
}
|
|
28
|
+
node.forEachChild(visit);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
var nitro_routes_default = plugin;
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
module.exports = nitro_routes_default;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxup/nuxt",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "TypeScript and Vue plugins for Nuxt",
|
|
6
|
+
"author": "KazariEX",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": "KazariEX/dxup",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/module.js",
|
|
11
|
+
"./vue/nitro-routes": "./dist/vue/nitro-routes.cjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/typescript.cjs",
|
|
15
|
+
"types": "./dist/typescript.d.cts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@nuxt/kit": "^4.1.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@vue/language-core": "^3.0.8",
|
|
24
|
+
"nuxt": "^4.1.2"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"dev": "tsdown -w --sourcemap",
|
|
29
|
+
"release": "bumpp"
|
|
30
|
+
}
|
|
31
|
+
}
|