@dxup/nuxt 0.0.2 → 0.0.4
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 -1
- package/dist/module.d.ts +3 -6
- package/dist/module.js +78 -10
- package/dist/src-BfXMgjZD.cjs +31 -0
- package/dist/typescript.cjs +149 -46
- package/dist/typescript.d.cts +1 -6
- package/dist/vue/nitro-routes.cjs +2 -2
- package/package.json +7 -2
- package/dist/ast-BfhxgPs7.cjs +0 -34
package/README.md
CHANGED
|
@@ -8,8 +8,10 @@ This is a collection of TypeScript and Vue plugins that improves Nuxt DX.
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
-
|
|
11
|
+
- Update references when renaming auto imported component files
|
|
12
|
+
- Go to definition for nitro routes in data fetching methods within Vue files
|
|
12
13
|
- Go to definition for runtime config
|
|
14
|
+
- [@dxup/unimport](/packages/unimport)
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
package/dist/module.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import * as _nuxt_schema0 from "@nuxt/schema";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
4
|
-
interface
|
|
3
|
+
//#region src/module/index.d.ts
|
|
4
|
+
interface ModuleOptions {
|
|
5
|
+
components?: boolean;
|
|
5
6
|
nitroRoutes?: boolean;
|
|
6
7
|
runtimeConfig?: boolean;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/module/index.d.ts
|
|
10
|
-
interface ModuleOptions extends Options {
|
|
11
8
|
unimport?: boolean;
|
|
12
9
|
}
|
|
13
10
|
declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.js
CHANGED
|
@@ -1,8 +1,67 @@
|
|
|
1
|
-
import { defineNuxtModule } from "@nuxt/kit";
|
|
1
|
+
import { addTemplate, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
import EventEmitter from "node:events";
|
|
4
|
+
import { mkdir, open, readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import { watch } from "chokidar";
|
|
6
|
+
import { dirname, join } from "pathe";
|
|
2
7
|
|
|
3
8
|
//#region package.json
|
|
4
9
|
var name = "@dxup/nuxt";
|
|
5
10
|
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/event/client.ts
|
|
13
|
+
const responseRE = /^```json \{(?<key>.*)\}\n(?<value>[\s\S]*?)\n```$/;
|
|
14
|
+
async function createEventClient(nuxt) {
|
|
15
|
+
const path = join(nuxt.options.buildDir, "dxup/events.md");
|
|
16
|
+
await mkdir(dirname(path), { recursive: true });
|
|
17
|
+
await writeFile(path, "");
|
|
18
|
+
const fd = await open(path, "r");
|
|
19
|
+
const watcher = watch(path, { ignoreInitial: true });
|
|
20
|
+
nuxt.hook("close", async () => {
|
|
21
|
+
await fd.close();
|
|
22
|
+
await watcher.close();
|
|
23
|
+
});
|
|
24
|
+
const client = new EventEmitter();
|
|
25
|
+
let offset = 0;
|
|
26
|
+
watcher.on("change", async (path$1, stats) => {
|
|
27
|
+
if (!stats || stats.size <= offset) return;
|
|
28
|
+
const pos = offset;
|
|
29
|
+
offset = stats.size;
|
|
30
|
+
const buffer = Buffer.alloc(offset - pos);
|
|
31
|
+
await fd.read(buffer, 0, buffer.length, pos);
|
|
32
|
+
const match = buffer.toString("utf-8").trim().match(responseRE);
|
|
33
|
+
if (match) {
|
|
34
|
+
const { key, value } = match.groups;
|
|
35
|
+
client.emit(key, JSON.parse(value));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return client;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/module/events.ts
|
|
43
|
+
const uppercaseRE = /[A-Z]/;
|
|
44
|
+
async function onComponentsRename(nuxt, { fileName, references }) {
|
|
45
|
+
const component = Object.values(nuxt.apps).flatMap((app) => app.components).find((c) => c.filePath === fileName);
|
|
46
|
+
if (!component) return;
|
|
47
|
+
const tasks = Object.entries(references).map(async ([fileName$1, references$1]) => {
|
|
48
|
+
const code = await readFile(fileName$1, "utf-8");
|
|
49
|
+
const chunks = [];
|
|
50
|
+
let offset = 0;
|
|
51
|
+
for (const { textSpan, lazy } of references$1) {
|
|
52
|
+
const start = textSpan.start;
|
|
53
|
+
const end = start + textSpan.length;
|
|
54
|
+
const oldName = code.slice(start, end);
|
|
55
|
+
const newName = uppercaseRE.test(oldName) ? lazy ? "Lazy" + component.pascalName : component.pascalName : lazy ? "lazy-" + component.kebabName : component.kebabName;
|
|
56
|
+
chunks.push(code.slice(offset, start), newName);
|
|
57
|
+
offset = end;
|
|
58
|
+
}
|
|
59
|
+
chunks.push(code.slice(offset));
|
|
60
|
+
await writeFile(fileName$1, chunks.join(""));
|
|
61
|
+
});
|
|
62
|
+
await Promise.all(tasks);
|
|
63
|
+
}
|
|
64
|
+
|
|
6
65
|
//#endregion
|
|
7
66
|
//#region src/module/index.ts
|
|
8
67
|
var module_default = defineNuxtModule({
|
|
@@ -11,27 +70,36 @@ var module_default = defineNuxtModule({
|
|
|
11
70
|
configKey: "dxup"
|
|
12
71
|
},
|
|
13
72
|
defaults: {
|
|
73
|
+
components: true,
|
|
14
74
|
nitroRoutes: true,
|
|
15
75
|
runtimeConfig: true,
|
|
16
76
|
unimport: true
|
|
17
77
|
},
|
|
18
78
|
async setup(options, nuxt) {
|
|
19
|
-
const pluginsTs = [];
|
|
79
|
+
const pluginsTs = [{ name: "@dxup/nuxt" }];
|
|
20
80
|
const pluginsVue = [];
|
|
21
|
-
pluginsTs.push({
|
|
22
|
-
name: "@dxup/nuxt",
|
|
23
|
-
options: {
|
|
24
|
-
nitroRoutes: options.nitroRoutes,
|
|
25
|
-
runtimeConfig: options.runtimeConfig
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
81
|
if (options.nitroRoutes) pluginsVue.push("@dxup/nuxt/vue/nitro-routes");
|
|
29
|
-
if (options.unimport) pluginsTs.
|
|
82
|
+
if (options.unimport) pluginsTs.unshift({ name: "@dxup/unimport" });
|
|
30
83
|
append(pluginsTs, nuxt.options, "typescript", "tsConfig", "compilerOptions");
|
|
31
84
|
append(pluginsTs, nuxt.options.nitro, "typescript", "tsConfig", "compilerOptions");
|
|
32
85
|
append(pluginsTs, nuxt.options, "typescript", "sharedTsConfig", "compilerOptions");
|
|
33
86
|
append(pluginsTs, nuxt.options, "typescript", "nodeTsConfig", "compilerOptions");
|
|
34
87
|
append(pluginsVue, nuxt.options, "typescript", "tsConfig", "vueCompilerOptions");
|
|
88
|
+
addTemplate({
|
|
89
|
+
filename: "dxup/data.json",
|
|
90
|
+
write: true,
|
|
91
|
+
getContents() {
|
|
92
|
+
const data = {
|
|
93
|
+
buildDir: nuxt.options.buildDir,
|
|
94
|
+
configFiles: [...nuxt.options._nuxtConfigFiles, ...nuxt.options._layers.map((layer) => layer._configFile).filter(Boolean)],
|
|
95
|
+
components: options.components,
|
|
96
|
+
nitroRoutes: options.nitroRoutes,
|
|
97
|
+
runtimeConfig: options.runtimeConfig
|
|
98
|
+
};
|
|
99
|
+
return JSON.stringify(data, null, 2);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
(await createEventClient(nuxt)).on("components:rename", (data) => onComponentsRename(nuxt, data));
|
|
35
103
|
}
|
|
36
104
|
});
|
|
37
105
|
function append(plugins, target, ...keys) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
//#region ../shared/src/index.ts
|
|
3
|
+
function* forEachNode(ts, node) {
|
|
4
|
+
yield node;
|
|
5
|
+
const children = [];
|
|
6
|
+
ts.forEachChild(node, (child) => {
|
|
7
|
+
children.push(child);
|
|
8
|
+
});
|
|
9
|
+
for (const child of children) yield* forEachNode(ts, child);
|
|
10
|
+
}
|
|
11
|
+
function walkNodes(ts, node, callback) {
|
|
12
|
+
callback(node, () => {
|
|
13
|
+
ts.forEachChild(node, (child) => {
|
|
14
|
+
walkNodes(ts, child, callback);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
Object.defineProperty(exports, 'forEachNode', {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return forEachNode;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, 'walkNodes', {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return walkNodes;
|
|
30
|
+
}
|
|
31
|
+
});
|
package/dist/typescript.cjs
CHANGED
|
@@ -21,20 +21,51 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
-
const
|
|
25
|
-
let
|
|
26
|
-
|
|
24
|
+
const require_src = require('./src-BfXMgjZD.cjs');
|
|
25
|
+
let pathe = require("pathe");
|
|
26
|
+
pathe = __toESM(pathe);
|
|
27
|
+
let node_fs_promises = require("node:fs/promises");
|
|
28
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
27
29
|
|
|
30
|
+
//#region src/event/server.ts
|
|
31
|
+
function createEventServer(info) {
|
|
32
|
+
const path = (0, pathe.join)(info.project.getCurrentDirectory(), "dxup/events.md");
|
|
33
|
+
function write(key, data) {
|
|
34
|
+
return (0, node_fs_promises.appendFile)(path, `\`\`\`json {${key}}\n${JSON.stringify(data, null, 2)}\n\`\`\`\n`).catch();
|
|
35
|
+
}
|
|
36
|
+
return { write };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
28
40
|
//#region src/typescript/index.ts
|
|
29
41
|
const plugin = (module$1) => {
|
|
30
42
|
const { typescript: ts } = module$1;
|
|
31
43
|
return { create(info) {
|
|
32
|
-
const
|
|
44
|
+
const currentDirectory = info.languageServiceHost.getCurrentDirectory();
|
|
45
|
+
const path = (0, pathe.join)(currentDirectory, "dxup/data.json");
|
|
46
|
+
const data = {
|
|
47
|
+
buildDir: currentDirectory,
|
|
48
|
+
configFiles: [],
|
|
49
|
+
components: true,
|
|
33
50
|
nitroRoutes: true,
|
|
34
51
|
runtimeConfig: true,
|
|
35
|
-
...
|
|
52
|
+
...JSON.parse(ts.sys.readFile(path) ?? "{}")
|
|
53
|
+
};
|
|
54
|
+
const server = createEventServer(info);
|
|
55
|
+
const context = {
|
|
56
|
+
ts,
|
|
57
|
+
info,
|
|
58
|
+
data,
|
|
59
|
+
server
|
|
36
60
|
};
|
|
37
|
-
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
context.language = (info.project.__vue__ ?? info.project["program"]?.__vue__)?.language;
|
|
63
|
+
}, 500);
|
|
64
|
+
for (const [key, method] of [
|
|
65
|
+
["findRenameLocations", findRenameLocations.bind(null, context)],
|
|
66
|
+
["getDefinitionAndBoundSpan", getDefinitionAndBoundSpan.bind(null, context)],
|
|
67
|
+
["getEditsForFileRename", getEditsForFileRename.bind(null, context)]
|
|
68
|
+
]) {
|
|
38
69
|
const original = info.languageService[key];
|
|
39
70
|
info.languageService[key] = method(original);
|
|
40
71
|
}
|
|
@@ -42,9 +73,18 @@ const plugin = (module$1) => {
|
|
|
42
73
|
} };
|
|
43
74
|
};
|
|
44
75
|
var typescript_default = plugin;
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
76
|
+
function findRenameLocations(context, findRenameLocations$1) {
|
|
77
|
+
const { data } = context;
|
|
78
|
+
return (...args) => {
|
|
79
|
+
return findRenameLocations$1(...args)?.filter((edit) => {
|
|
80
|
+
return !edit.fileName.startsWith(data.buildDir);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function getDefinitionAndBoundSpan(context, getDefinitionAndBoundSpan$1) {
|
|
85
|
+
const { info, data } = context;
|
|
86
|
+
return (...args) => {
|
|
87
|
+
const result = getDefinitionAndBoundSpan$1(...args);
|
|
48
88
|
if (!result?.definitions?.length) return result;
|
|
49
89
|
const program = info.languageService.getProgram();
|
|
50
90
|
const definitions = new Set(result.definitions);
|
|
@@ -53,8 +93,8 @@ function getDefinitionAndBoundSpan(ts, info, options, getDefinitionAndBoundSpan$
|
|
|
53
93
|
const sourceFile = program.getSourceFile(definition.fileName);
|
|
54
94
|
if (!sourceFile) continue;
|
|
55
95
|
let result$1 = [];
|
|
56
|
-
if (
|
|
57
|
-
else if (
|
|
96
|
+
if (data.nitroRoutes && definition.fileName.endsWith("nitro-routes.d.ts")) result$1 = visitNitroRoutes(context, sourceFile, definition, getDefinitionAndBoundSpan$1);
|
|
97
|
+
else if (data.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(context, sourceFile, definition);
|
|
58
98
|
if (result$1?.length) {
|
|
59
99
|
for (const definition$1 of result$1) definitions.add(definition$1);
|
|
60
100
|
skippedDefinitions.push(definition);
|
|
@@ -67,9 +107,10 @@ function getDefinitionAndBoundSpan(ts, info, options, getDefinitionAndBoundSpan$
|
|
|
67
107
|
};
|
|
68
108
|
};
|
|
69
109
|
}
|
|
70
|
-
function visitNitroRoutes(
|
|
110
|
+
function visitNitroRoutes(context, sourceFile, definition, getDefinitionAndBoundSpan$1) {
|
|
111
|
+
const { ts } = context;
|
|
71
112
|
const definitions = [];
|
|
72
|
-
for (const node of
|
|
113
|
+
for (const node of require_src.forEachNode(ts, sourceFile)) {
|
|
73
114
|
if (!ts.isPropertySignature(node) || !node.type || !ts.isTypeLiteralNode(node.type)) continue;
|
|
74
115
|
const { textSpan } = definition;
|
|
75
116
|
const start = node.name.getStart(sourceFile);
|
|
@@ -87,10 +128,11 @@ function visitNitroRoutes(ts, sourceFile, definition, getDefinitionAndBoundSpan$
|
|
|
87
128
|
}
|
|
88
129
|
return definitions;
|
|
89
130
|
}
|
|
90
|
-
function visitRuntimeConfig(
|
|
131
|
+
function visitRuntimeConfig(context, sourceFile, definition) {
|
|
132
|
+
const { ts } = context;
|
|
91
133
|
let definitions = [];
|
|
92
134
|
const path = [];
|
|
93
|
-
|
|
135
|
+
require_src.walkNodes(ts, sourceFile, (node, next) => {
|
|
94
136
|
let key;
|
|
95
137
|
if (ts.isInterfaceDeclaration(node) && ts.isIdentifier(node.name)) key = node.name.text;
|
|
96
138
|
else if (ts.isPropertySignature(node) && ts.isIdentifier(node.name)) {
|
|
@@ -100,7 +142,7 @@ function visitRuntimeConfig(ts, info, sourceFile, definition) {
|
|
|
100
142
|
const end = node.name.getEnd();
|
|
101
143
|
if (start === textSpan.start && end - start === textSpan.length) {
|
|
102
144
|
path.push(key);
|
|
103
|
-
definitions = [...proxyRuntimeConfig(
|
|
145
|
+
definitions = [...proxyRuntimeConfig(context, definition, path)];
|
|
104
146
|
return;
|
|
105
147
|
}
|
|
106
148
|
}
|
|
@@ -110,7 +152,8 @@ function visitRuntimeConfig(ts, info, sourceFile, definition) {
|
|
|
110
152
|
});
|
|
111
153
|
return definitions;
|
|
112
154
|
}
|
|
113
|
-
function* proxyRuntimeConfig(
|
|
155
|
+
function* proxyRuntimeConfig(context, definition, path) {
|
|
156
|
+
const { ts, info, data } = context;
|
|
114
157
|
switch (path[0]) {
|
|
115
158
|
case "SharedRuntimeConfig":
|
|
116
159
|
path.shift();
|
|
@@ -120,44 +163,104 @@ function* proxyRuntimeConfig(ts, info, definition, path) {
|
|
|
120
163
|
break;
|
|
121
164
|
default: return;
|
|
122
165
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
166
|
+
const configFile = data.configFiles[0];
|
|
167
|
+
if (configFile === void 0) return;
|
|
168
|
+
const { configFileName } = info.project.projectService.openClientFile(configFile);
|
|
169
|
+
if (configFileName === void 0) return;
|
|
170
|
+
const nodeProject = info.project.projectService.findProject(configFileName);
|
|
125
171
|
if (!nodeProject) return;
|
|
126
172
|
const nodeProgram = nodeProject.getLanguageService().getProgram();
|
|
127
173
|
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
174
|
const checker = nodeProgram.getTypeChecker();
|
|
133
|
-
for (const
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
textSpan
|
|
175
|
+
for (const configFile$1 of data.configFiles) {
|
|
176
|
+
const sourceFile = nodeProgram.getSourceFile(configFile$1);
|
|
177
|
+
if (!sourceFile) continue;
|
|
178
|
+
outer: for (const node of sourceFile.statements) {
|
|
179
|
+
if (!ts.isExportAssignment(node) || !ts.isCallExpression(node.expression) || !node.expression.arguments.length) continue;
|
|
180
|
+
const arg = node.expression.arguments[0];
|
|
181
|
+
let currentSymbol;
|
|
182
|
+
let currentType = checker.getTypeAtLocation(arg);
|
|
183
|
+
for (const key of ["runtimeConfig", ...path]) {
|
|
184
|
+
const symbol = currentType.getProperties().find((s) => s.name === key);
|
|
185
|
+
if (!symbol) break outer;
|
|
186
|
+
currentSymbol = symbol;
|
|
187
|
+
currentType = checker.getTypeOfSymbol(symbol);
|
|
188
|
+
}
|
|
189
|
+
for (const decl of currentSymbol?.declarations ?? []) {
|
|
190
|
+
const sourceFile$1 = decl.getSourceFile();
|
|
191
|
+
const contextSpan = {
|
|
192
|
+
start: decl.getStart(sourceFile$1),
|
|
193
|
+
length: decl.getWidth(sourceFile$1)
|
|
194
|
+
};
|
|
195
|
+
let textSpan = contextSpan;
|
|
196
|
+
if (ts.isPropertyAssignment(decl) || ts.isPropertySignature(decl)) textSpan = {
|
|
154
197
|
start: decl.name.getStart(sourceFile$1),
|
|
155
198
|
length: decl.name.getWidth(sourceFile$1)
|
|
156
|
-
}
|
|
157
|
-
|
|
199
|
+
};
|
|
200
|
+
yield {
|
|
201
|
+
...definition,
|
|
202
|
+
fileName: sourceFile$1.fileName,
|
|
203
|
+
textSpan,
|
|
204
|
+
contextSpan
|
|
205
|
+
};
|
|
206
|
+
}
|
|
158
207
|
}
|
|
159
208
|
}
|
|
160
209
|
}
|
|
210
|
+
function getEditsForFileRename(context, getEditsForFileRename$1) {
|
|
211
|
+
const { ts, info, data, server } = context;
|
|
212
|
+
return (...args) => {
|
|
213
|
+
const result = getEditsForFileRename$1(...args);
|
|
214
|
+
if (!result?.length) return result;
|
|
215
|
+
const program = info.languageService.getProgram();
|
|
216
|
+
const changes = [];
|
|
217
|
+
const references = {};
|
|
218
|
+
for (const change of result) {
|
|
219
|
+
const { fileName, textChanges } = change;
|
|
220
|
+
if (data.components && fileName.endsWith("components.d.ts")) {
|
|
221
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
222
|
+
if (!sourceFile) continue;
|
|
223
|
+
const nodes = [];
|
|
224
|
+
if (fileName.endsWith("types/components.d.ts")) {
|
|
225
|
+
for (const node of require_src.forEachNode(ts, sourceFile)) if (ts.isPropertySignature(node)) nodes.push(node);
|
|
226
|
+
} else for (const node of require_src.forEachNode(ts, sourceFile)) if (ts.isVariableDeclaration(node)) nodes.push(node);
|
|
227
|
+
for (const node of nodes) {
|
|
228
|
+
const start = node.getStart(sourceFile);
|
|
229
|
+
const end = node.getEnd();
|
|
230
|
+
if (textChanges.every(({ span }) => span.start < start || span.start + span.length > end)) continue;
|
|
231
|
+
const symbols = info.languageService.findReferences(fileName, start);
|
|
232
|
+
const lazy = node.type && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "LazyComponent";
|
|
233
|
+
for (const reference of symbols?.flatMap(({ references: references$1 }) => references$1) ?? []) {
|
|
234
|
+
if (reference.isDefinition) continue;
|
|
235
|
+
const { fileName: fileName$1, textSpan } = reference;
|
|
236
|
+
(references[fileName$1] ??= []).push({
|
|
237
|
+
textSpan: toSourceSpan(context.language, fileName$1, textSpan) ?? textSpan,
|
|
238
|
+
lazy: lazy || void 0
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (!fileName.startsWith(data.buildDir)) changes.push(change);
|
|
244
|
+
}
|
|
245
|
+
if (Object.keys(references).length) server.write("components:rename", {
|
|
246
|
+
fileName: args[1],
|
|
247
|
+
references
|
|
248
|
+
});
|
|
249
|
+
return changes;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function toSourceSpan(language, fileName, textSpan) {
|
|
253
|
+
const sourceScript = language?.scripts.get(fileName);
|
|
254
|
+
if (!sourceScript?.generated) return;
|
|
255
|
+
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
256
|
+
if (!serviceScript) return;
|
|
257
|
+
const map = language.maps.get(serviceScript.code, sourceScript);
|
|
258
|
+
const leadingOffset = sourceScript.snapshot.getLength();
|
|
259
|
+
for (const [start, end] of map.toSourceRange(textSpan.start - leadingOffset, textSpan.start + textSpan.length - leadingOffset, false)) return {
|
|
260
|
+
start,
|
|
261
|
+
length: end - start
|
|
262
|
+
};
|
|
263
|
+
}
|
|
161
264
|
|
|
162
265
|
//#endregion
|
|
163
266
|
module.exports = typescript_default;
|
package/dist/typescript.d.cts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
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
|
-
}
|
|
8
4
|
declare const plugin: ts.server.PluginModuleFactory;
|
|
9
|
-
|
|
10
|
-
export { Options, plugin as default };
|
|
5
|
+
export = plugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_src = require('../src-BfXMgjZD.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/vue/nitro-routes.ts
|
|
4
4
|
const functionNames = new Set([
|
|
@@ -14,7 +14,7 @@ const plugin = ({ modules: { typescript: ts } }) => {
|
|
|
14
14
|
const { scriptSetup } = sfc;
|
|
15
15
|
if (!scriptSetup) return;
|
|
16
16
|
const codes = [];
|
|
17
|
-
for (const node of
|
|
17
|
+
for (const node of require_src.forEachNode(ts, scriptSetup.ast)) if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && functionNames.has(node.expression.text) && node.arguments.length && ts.isStringLiteralLike(node.arguments[0])) {
|
|
18
18
|
const arg = node.arguments[0];
|
|
19
19
|
codes.push(`/** @type {__VLS_InternalApi[`, [
|
|
20
20
|
arg.getText(scriptSetup.ast),
|
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.4",
|
|
5
5
|
"description": "TypeScript and Vue plugins for Nuxt",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,9 +18,14 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@nuxt/kit": "^4.1.2",
|
|
21
|
+
"chokidar": "^4.0.3",
|
|
22
|
+
"pathe": "2.0.3",
|
|
21
23
|
"@dxup/unimport": "^0.0.1"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
26
|
+
"@dxup/shared": "",
|
|
27
|
+
"@volar/language-core": "^2.4.23",
|
|
28
|
+
"@volar/typescript": "^2.4.23",
|
|
24
29
|
"@vue/language-core": "^3.0.8",
|
|
25
30
|
"nuxt": "^4.1.2",
|
|
26
31
|
"typescript": "^5.9.2"
|
|
@@ -28,6 +33,6 @@
|
|
|
28
33
|
"scripts": {
|
|
29
34
|
"build": "tsdown",
|
|
30
35
|
"dev": "tsdown -w --sourcemap",
|
|
31
|
-
"release": "
|
|
36
|
+
"release": "node ../../scripts/release.ts"
|
|
32
37
|
}
|
|
33
38
|
}
|
package/dist/ast-BfhxgPs7.cjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
});
|