@dxup/nuxt 0.0.1 → 0.0.2
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 +3 -2
- package/dist/ast-BfhxgPs7.cjs +34 -0
- package/dist/module.d.ts +11 -2
- package/dist/module.js +25 -47
- package/dist/typescript.cjs +136 -24
- package/dist/typescript.d.cts +6 -1
- package/dist/vue/nitro-routes.cjs +10 -13
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ This is a collection of TypeScript and Vue plugins that improves Nuxt DX.
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- Go to definition for nitro routes on data fetching methods
|
|
12
|
+
- Go to definition for runtime config
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
@@ -24,6 +25,6 @@ Add the following to your `nuxt.config.ts`:
|
|
|
24
25
|
export default defineNuxtConfig({
|
|
25
26
|
modules: [
|
|
26
27
|
"@dxup/nuxt",
|
|
27
|
-
]
|
|
28
|
-
})
|
|
28
|
+
],
|
|
29
|
+
});
|
|
29
30
|
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/ast.ts
|
|
3
|
+
function* forEachNode(node) {
|
|
4
|
+
yield node;
|
|
5
|
+
const children = [];
|
|
6
|
+
node.forEachChild((child) => {
|
|
7
|
+
children.push(child);
|
|
8
|
+
});
|
|
9
|
+
for (const child of children) yield* forEachNode(child);
|
|
10
|
+
}
|
|
11
|
+
function walkNodes(node, callback) {
|
|
12
|
+
function next() {
|
|
13
|
+
const children = [];
|
|
14
|
+
node.forEachChild((child) => {
|
|
15
|
+
children.push(child);
|
|
16
|
+
});
|
|
17
|
+
for (const child of children) walkNodes(child, callback);
|
|
18
|
+
}
|
|
19
|
+
callback(node, next);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, 'forEachNode', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return forEachNode;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, 'walkNodes', {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return walkNodes;
|
|
33
|
+
}
|
|
34
|
+
});
|
package/dist/module.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import * as _nuxt_schema0 from "@nuxt/schema";
|
|
2
2
|
|
|
3
|
+
//#region src/typescript/index.d.ts
|
|
4
|
+
interface Options {
|
|
5
|
+
nitroRoutes?: boolean;
|
|
6
|
+
runtimeConfig?: boolean;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
3
9
|
//#region src/module/index.d.ts
|
|
4
|
-
|
|
10
|
+
interface ModuleOptions extends Options {
|
|
11
|
+
unimport?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
5
14
|
//#endregion
|
|
6
|
-
export { _default as default };
|
|
15
|
+
export { ModuleOptions, _default as default };
|
package/dist/module.js
CHANGED
|
@@ -2,64 +2,42 @@ import { defineNuxtModule } from "@nuxt/kit";
|
|
|
2
2
|
|
|
3
3
|
//#region package.json
|
|
4
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
5
|
|
|
49
6
|
//#endregion
|
|
50
7
|
//#region src/module/index.ts
|
|
51
8
|
var module_default = defineNuxtModule({
|
|
52
9
|
meta: {
|
|
53
|
-
name
|
|
10
|
+
name,
|
|
54
11
|
configKey: "dxup"
|
|
55
12
|
},
|
|
13
|
+
defaults: {
|
|
14
|
+
nitroRoutes: true,
|
|
15
|
+
runtimeConfig: true,
|
|
16
|
+
unimport: true
|
|
17
|
+
},
|
|
56
18
|
async setup(options, nuxt) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
19
|
+
const pluginsTs = [];
|
|
20
|
+
const pluginsVue = [];
|
|
21
|
+
pluginsTs.push({
|
|
22
|
+
name: "@dxup/nuxt",
|
|
23
|
+
options: {
|
|
24
|
+
nitroRoutes: options.nitroRoutes,
|
|
25
|
+
runtimeConfig: options.runtimeConfig
|
|
26
|
+
}
|
|
60
27
|
});
|
|
28
|
+
if (options.nitroRoutes) pluginsVue.push("@dxup/nuxt/vue/nitro-routes");
|
|
29
|
+
if (options.unimport) pluginsTs.push({ name: "@dxup/unimport" });
|
|
30
|
+
append(pluginsTs, nuxt.options, "typescript", "tsConfig", "compilerOptions");
|
|
31
|
+
append(pluginsTs, nuxt.options.nitro, "typescript", "tsConfig", "compilerOptions");
|
|
32
|
+
append(pluginsTs, nuxt.options, "typescript", "sharedTsConfig", "compilerOptions");
|
|
33
|
+
append(pluginsTs, nuxt.options, "typescript", "nodeTsConfig", "compilerOptions");
|
|
34
|
+
append(pluginsVue, nuxt.options, "typescript", "tsConfig", "vueCompilerOptions");
|
|
61
35
|
}
|
|
62
36
|
});
|
|
37
|
+
function append(plugins, target, ...keys) {
|
|
38
|
+
for (const key of keys) target = target[key] ??= {};
|
|
39
|
+
(target.plugins ??= []).push(...plugins);
|
|
40
|
+
}
|
|
63
41
|
|
|
64
42
|
//#endregion
|
|
65
43
|
export { module_default as default };
|
package/dist/typescript.cjs
CHANGED
|
@@ -1,51 +1,163 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const require_ast = require('./ast-BfhxgPs7.cjs');
|
|
25
|
+
let node_path = require("node:path");
|
|
26
|
+
node_path = __toESM(node_path);
|
|
1
27
|
|
|
2
28
|
//#region src/typescript/index.ts
|
|
3
29
|
const plugin = (module$1) => {
|
|
4
30
|
const { typescript: ts } = module$1;
|
|
5
31
|
return { create(info) {
|
|
6
|
-
const
|
|
7
|
-
|
|
32
|
+
const options = {
|
|
33
|
+
nitroRoutes: true,
|
|
34
|
+
runtimeConfig: true,
|
|
35
|
+
...info.config.options
|
|
36
|
+
};
|
|
37
|
+
for (const [key, method] of [["getDefinitionAndBoundSpan", getDefinitionAndBoundSpan.bind(null, ts, info, options)]]) {
|
|
38
|
+
const original = info.languageService[key];
|
|
39
|
+
info.languageService[key] = method(original);
|
|
40
|
+
}
|
|
8
41
|
return info.languageService;
|
|
9
42
|
} };
|
|
10
43
|
};
|
|
11
44
|
var typescript_default = plugin;
|
|
12
|
-
function getDefinitionAndBoundSpan(ts,
|
|
45
|
+
function getDefinitionAndBoundSpan(ts, info, options, getDefinitionAndBoundSpan$1) {
|
|
13
46
|
return (fileName, position) => {
|
|
14
47
|
const result = getDefinitionAndBoundSpan$1(fileName, position);
|
|
15
48
|
if (!result?.definitions?.length) return result;
|
|
16
|
-
const program = languageService.getProgram();
|
|
49
|
+
const program = info.languageService.getProgram();
|
|
17
50
|
const definitions = new Set(result.definitions);
|
|
18
51
|
const skippedDefinitions = [];
|
|
19
52
|
for (const definition of result.definitions) {
|
|
20
|
-
if (!definition.fileName.endsWith("nitro-routes.d.ts")) continue;
|
|
21
53
|
const sourceFile = program.getSourceFile(definition.fileName);
|
|
22
|
-
if (sourceFile)
|
|
54
|
+
if (!sourceFile) continue;
|
|
55
|
+
let result$1 = [];
|
|
56
|
+
if (options.nitroRoutes && definition.fileName.endsWith("nitro-routes.d.ts")) result$1 = visitNitroRoutes(ts, sourceFile, definition, getDefinitionAndBoundSpan$1);
|
|
57
|
+
else if (options.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(ts, info, sourceFile, definition);
|
|
58
|
+
if (result$1?.length) {
|
|
59
|
+
for (const definition$1 of result$1) definitions.add(definition$1);
|
|
60
|
+
skippedDefinitions.push(definition);
|
|
61
|
+
}
|
|
23
62
|
}
|
|
24
63
|
for (const definition of skippedDefinitions) definitions.delete(definition);
|
|
25
64
|
return {
|
|
26
65
|
definitions: [...definitions],
|
|
27
66
|
textSpan: result.textSpan
|
|
28
67
|
};
|
|
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
68
|
};
|
|
48
69
|
}
|
|
70
|
+
function visitNitroRoutes(ts, sourceFile, definition, getDefinitionAndBoundSpan$1) {
|
|
71
|
+
const definitions = [];
|
|
72
|
+
for (const node of require_ast.forEachNode(sourceFile)) {
|
|
73
|
+
if (!ts.isPropertySignature(node) || !node.type || !ts.isTypeLiteralNode(node.type)) continue;
|
|
74
|
+
const { textSpan } = definition;
|
|
75
|
+
const start = node.name.getStart(sourceFile);
|
|
76
|
+
const end = node.name.getEnd();
|
|
77
|
+
if (start !== textSpan.start || end - start !== textSpan.length) continue;
|
|
78
|
+
for (const member of node.type.members) {
|
|
79
|
+
if (!ts.isPropertySignature(member)) continue;
|
|
80
|
+
const pos = (((((member.type?.typeArguments?.[0])?.typeArguments?.[0])?.typeArguments?.[0])?.typeArguments?.[0])?.qualifier)?.getStart(sourceFile);
|
|
81
|
+
if (pos !== void 0) {
|
|
82
|
+
const res = getDefinitionAndBoundSpan$1(definition.fileName, pos);
|
|
83
|
+
if (res?.definitions?.length) definitions.push(...res.definitions);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
return definitions;
|
|
89
|
+
}
|
|
90
|
+
function visitRuntimeConfig(ts, info, sourceFile, definition) {
|
|
91
|
+
let definitions = [];
|
|
92
|
+
const path = [];
|
|
93
|
+
require_ast.walkNodes(sourceFile, (node, next) => {
|
|
94
|
+
let key;
|
|
95
|
+
if (ts.isInterfaceDeclaration(node) && ts.isIdentifier(node.name)) key = node.name.text;
|
|
96
|
+
else if (ts.isPropertySignature(node) && ts.isIdentifier(node.name)) {
|
|
97
|
+
key = node.name.text;
|
|
98
|
+
const { textSpan } = definition;
|
|
99
|
+
const start = node.name.getStart(sourceFile);
|
|
100
|
+
const end = node.name.getEnd();
|
|
101
|
+
if (start === textSpan.start && end - start === textSpan.length) {
|
|
102
|
+
path.push(key);
|
|
103
|
+
definitions = [...proxyRuntimeConfig(ts, info, definition, path)];
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (key !== void 0) path.push(key);
|
|
108
|
+
next();
|
|
109
|
+
if (key !== void 0) path.pop();
|
|
110
|
+
});
|
|
111
|
+
return definitions;
|
|
112
|
+
}
|
|
113
|
+
function* proxyRuntimeConfig(ts, info, definition, path) {
|
|
114
|
+
switch (path[0]) {
|
|
115
|
+
case "SharedRuntimeConfig":
|
|
116
|
+
path.shift();
|
|
117
|
+
break;
|
|
118
|
+
case "SharedPublicRuntimeConfig":
|
|
119
|
+
path[0] = "public";
|
|
120
|
+
break;
|
|
121
|
+
default: return;
|
|
122
|
+
}
|
|
123
|
+
const configName = (0, node_path.join)((0, node_path.dirname)(info.project.getProjectName()), "tsconfig.node.json");
|
|
124
|
+
const nodeProject = info.project.projectService.findProject(configName);
|
|
125
|
+
if (!nodeProject) return;
|
|
126
|
+
const nodeProgram = nodeProject.getLanguageService().getProgram();
|
|
127
|
+
if (!nodeProgram) return;
|
|
128
|
+
const nuxtConfigName = nodeProgram.getRootFileNames().find((name) => name.endsWith("nuxt.config.ts"));
|
|
129
|
+
if (!nuxtConfigName) return;
|
|
130
|
+
const sourceFile = nodeProgram.getSourceFile(nuxtConfigName);
|
|
131
|
+
if (!sourceFile) return;
|
|
132
|
+
const checker = nodeProgram.getTypeChecker();
|
|
133
|
+
for (const node of sourceFile.statements) if (ts.isExportAssignment(node) && ts.isCallExpression(node.expression) && node.expression.arguments.length) {
|
|
134
|
+
const arg = node.expression.arguments[0];
|
|
135
|
+
let currentSymbol;
|
|
136
|
+
let currentType = checker.getTypeAtLocation(arg);
|
|
137
|
+
for (const key of ["runtimeConfig", ...path]) {
|
|
138
|
+
const symbol = currentType.getProperties().find((s) => s.name === key);
|
|
139
|
+
if (!symbol) return;
|
|
140
|
+
currentSymbol = symbol;
|
|
141
|
+
currentType = checker.getTypeOfSymbol(symbol);
|
|
142
|
+
}
|
|
143
|
+
for (const decl of currentSymbol.declarations ?? []) {
|
|
144
|
+
const sourceFile$1 = decl.getSourceFile();
|
|
145
|
+
const contextSpan = {
|
|
146
|
+
start: decl.getStart(sourceFile$1),
|
|
147
|
+
length: decl.getWidth(sourceFile$1)
|
|
148
|
+
};
|
|
149
|
+
yield {
|
|
150
|
+
...definition,
|
|
151
|
+
contextSpan,
|
|
152
|
+
fileName: sourceFile$1.fileName,
|
|
153
|
+
textSpan: ts.isPropertyAssignment(decl) ? {
|
|
154
|
+
start: decl.name.getStart(sourceFile$1),
|
|
155
|
+
length: decl.name.getWidth(sourceFile$1)
|
|
156
|
+
} : contextSpan
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
49
161
|
|
|
50
162
|
//#endregion
|
|
51
163
|
module.exports = typescript_default;
|
package/dist/typescript.d.cts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
//#region src/typescript/index.d.ts
|
|
4
|
+
interface Options {
|
|
5
|
+
nitroRoutes?: boolean;
|
|
6
|
+
runtimeConfig?: boolean;
|
|
7
|
+
}
|
|
4
8
|
declare const plugin: ts.server.PluginModuleFactory;
|
|
5
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Options, plugin as default };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_ast = require('../ast-BfhxgPs7.cjs');
|
|
1
2
|
|
|
2
3
|
//#region src/vue/nitro-routes.ts
|
|
3
4
|
const functionNames = new Set([
|
|
@@ -13,20 +14,16 @@ const plugin = ({ modules: { typescript: ts } }) => {
|
|
|
13
14
|
const { scriptSetup } = sfc;
|
|
14
15
|
if (!scriptSetup) return;
|
|
15
16
|
const codes = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
arg.getStart(scriptSetup.ast),
|
|
25
|
-
{ navigation: true }
|
|
26
|
-
], `]} */;\n`);
|
|
27
|
-
}
|
|
28
|
-
node.forEachChild(visit);
|
|
17
|
+
for (const node of require_ast.forEachNode(scriptSetup.ast)) if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && functionNames.has(node.expression.text) && node.arguments.length && ts.isStringLiteralLike(node.arguments[0])) {
|
|
18
|
+
const arg = node.arguments[0];
|
|
19
|
+
codes.push(`/** @type {__VLS_InternalApi[`, [
|
|
20
|
+
arg.getText(scriptSetup.ast),
|
|
21
|
+
sfc.scriptSetup.name,
|
|
22
|
+
arg.getStart(scriptSetup.ast),
|
|
23
|
+
{ navigation: true }
|
|
24
|
+
], `]} */;\n`);
|
|
29
25
|
}
|
|
26
|
+
if (codes.length) embeddedFile.content.push(`import type { InternalApi as __VLS_InternalApi } from 'nitropack/types';\n`, ...codes);
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
29
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxup/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "TypeScript and Vue plugins for Nuxt",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@nuxt/kit": "^4.1.2"
|
|
20
|
+
"@nuxt/kit": "^4.1.2",
|
|
21
|
+
"@dxup/unimport": "^0.0.1"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@vue/language-core": "^3.0.8",
|
|
24
|
-
"nuxt": "^4.1.2"
|
|
25
|
+
"nuxt": "^4.1.2",
|
|
26
|
+
"typescript": "^5.9.2"
|
|
25
27
|
},
|
|
26
28
|
"scripts": {
|
|
27
29
|
"build": "tsdown",
|