@ripast/vue 0.0.0 → 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/dist/index.mjs +33 -39
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { existsSync, readFileSync, statSync } from "node:fs";
|
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
3
|
import { extractTemplateExpressions, posToLineCol, rewriteTemplateReferences } from "@ripast/core/adapter";
|
|
4
4
|
import { URI } from "vscode-uri";
|
|
5
|
-
import { spawnSync } from "node:child_process";
|
|
6
5
|
import process from "node:process";
|
|
7
6
|
import { FileType, createLanguage, createLanguageService, createUriMap } from "@volar/language-service";
|
|
8
7
|
import { createLanguageServiceHost, resolveFileLanguageId } from "@volar/typescript";
|
|
@@ -11,6 +10,7 @@ import { createVueLanguageServicePlugins } from "@vue/language-service";
|
|
|
11
10
|
import ts from "typescript";
|
|
12
11
|
import { create } from "volar-service-typescript";
|
|
13
12
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
14
|
function createVueService(tsconfigPath, cwd) {
|
|
15
15
|
const commandLine = createParsedCommandLine(ts, ts.sys, tsconfigPath);
|
|
16
16
|
const vueExts = getAllExtensions(commandLine.vueOptions).map((ext) => {
|
|
@@ -119,7 +119,7 @@ function workspaceEditToChanges(edit, vue, cwd, filter) {
|
|
|
119
119
|
if (after === before) return;
|
|
120
120
|
out.push({
|
|
121
121
|
path: fileName,
|
|
122
|
-
rel:
|
|
122
|
+
rel: workspaceRelativePath(fileName, cwd),
|
|
123
123
|
before,
|
|
124
124
|
after
|
|
125
125
|
});
|
|
@@ -130,23 +130,37 @@ function workspaceEditToChanges(edit, vue, cwd, filter) {
|
|
|
130
130
|
}
|
|
131
131
|
return out;
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function workspaceRelativePath(fileName, cwd) {
|
|
134
134
|
return fileName.startsWith(cwd) ? fileName.slice(cwd.length).replace(/^[/\\]/, "") : fileName;
|
|
135
135
|
}
|
|
136
|
-
function hasVueFilesContaining(cwd, pattern) {
|
|
137
|
-
return
|
|
136
|
+
function hasVueFilesContaining$1(cwd, pattern) {
|
|
137
|
+
return listVueFilesContaining(cwd, pattern).length > 0;
|
|
138
|
+
}
|
|
139
|
+
function listVueFiles(cwd) {
|
|
140
|
+
return rgVueFiles(cwd, ["--files"]);
|
|
141
|
+
}
|
|
142
|
+
function listVueFilesContaining(cwd, pattern) {
|
|
143
|
+
return rgVueFiles(cwd, [
|
|
138
144
|
"--files-with-matches",
|
|
145
|
+
"--fixed-strings",
|
|
146
|
+
pattern
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
function rgVueFiles(cwd, args) {
|
|
150
|
+
return spawnSync("rg", [
|
|
151
|
+
...args,
|
|
139
152
|
"--hidden",
|
|
140
153
|
"--no-messages",
|
|
141
|
-
"--fixed-strings",
|
|
142
154
|
"-g",
|
|
143
155
|
"*.vue",
|
|
144
|
-
pattern,
|
|
145
156
|
"."
|
|
146
157
|
], {
|
|
147
158
|
cwd,
|
|
148
159
|
encoding: "utf8"
|
|
149
|
-
}).stdout.
|
|
160
|
+
}).stdout.split("\n").filter(Boolean).map((path) => resolve(cwd, path));
|
|
161
|
+
}
|
|
162
|
+
function hasVueFilesContaining(cwd, pattern) {
|
|
163
|
+
return hasVueFilesContaining$1(cwd, pattern);
|
|
150
164
|
}
|
|
151
165
|
async function applyVueRename(tsconfigPath, cwd, from, to, sites) {
|
|
152
166
|
const vue = createVueService(tsconfigPath, cwd);
|
|
@@ -173,11 +187,12 @@ async function applyVueRename(tsconfigPath, cwd, from, to, sites) {
|
|
|
173
187
|
const before = existing?.before ?? safeReadFile(path);
|
|
174
188
|
if (before === void 0) continue;
|
|
175
189
|
const baseAfter = existing?.after ?? before;
|
|
190
|
+
if (hasLocalScriptBinding(baseAfter, from)) continue;
|
|
176
191
|
const rewritten = rewriteTemplateReferences(baseAfter, from, to);
|
|
177
192
|
if (rewritten === baseAfter) continue;
|
|
178
193
|
byPath.set(path, {
|
|
179
194
|
path,
|
|
180
|
-
rel: existing?.rel ??
|
|
195
|
+
rel: existing?.rel ?? workspaceRelativePath(path, cwd),
|
|
181
196
|
before,
|
|
182
197
|
after: rewritten
|
|
183
198
|
});
|
|
@@ -187,20 +202,15 @@ async function applyVueRename(tsconfigPath, cwd, from, to, sites) {
|
|
|
187
202
|
vue.dispose();
|
|
188
203
|
}
|
|
189
204
|
}
|
|
190
|
-
function
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
"."
|
|
200
|
-
], {
|
|
201
|
-
cwd,
|
|
202
|
-
encoding: "utf8"
|
|
203
|
-
}).stdout.split("\n").filter(Boolean).map((p) => resolve(cwd, p));
|
|
205
|
+
function hasLocalScriptBinding(source, name) {
|
|
206
|
+
const script = extractScript(source);
|
|
207
|
+
if (!script?.includes(name)) return false;
|
|
208
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
209
|
+
const withoutImports = script.replace(/^\s*import [^;\n]*;?$/gm, "");
|
|
210
|
+
return new RegExp(`\\b(?:const|let|var|function|class|interface|type|enum)\\s+${escaped}\\b`).test(withoutImports);
|
|
211
|
+
}
|
|
212
|
+
function extractScript(source) {
|
|
213
|
+
return /<script(?:\s[^>]*)?>([\s\S]*?)<\/script>/i.exec(source)?.[1] ?? null;
|
|
204
214
|
}
|
|
205
215
|
function safeReadFile(path) {
|
|
206
216
|
try {
|
|
@@ -209,9 +219,6 @@ function safeReadFile(path) {
|
|
|
209
219
|
return;
|
|
210
220
|
}
|
|
211
221
|
}
|
|
212
|
-
function relPath(fileName, cwd) {
|
|
213
|
-
return fileName.startsWith(cwd) ? fileName.slice(cwd.length).replace(/^[/\\]/, "") : fileName;
|
|
214
|
-
}
|
|
215
222
|
async function applyVueImportRewrite(tsconfigPath, cwd, fromAbs, toAbs) {
|
|
216
223
|
const vue = createVueService(tsconfigPath, cwd);
|
|
217
224
|
try {
|
|
@@ -266,19 +273,6 @@ async function getDiags(vue, fileName) {
|
|
|
266
273
|
function diagKey(d) {
|
|
267
274
|
return `${d.range.start.line}:${d.range.start.character}:${d.code ?? ""}:${d.message}`;
|
|
268
275
|
}
|
|
269
|
-
function listVueFiles(cwd) {
|
|
270
|
-
return spawnSync("rg", [
|
|
271
|
-
"--files",
|
|
272
|
-
"--hidden",
|
|
273
|
-
"--no-messages",
|
|
274
|
-
"-g",
|
|
275
|
-
"*.vue",
|
|
276
|
-
"."
|
|
277
|
-
], {
|
|
278
|
-
cwd,
|
|
279
|
-
encoding: "utf8"
|
|
280
|
-
}).stdout.split("\n").filter(Boolean).map((p) => resolve(cwd, p));
|
|
281
|
-
}
|
|
282
276
|
const adapter = {
|
|
283
277
|
name: "vue",
|
|
284
278
|
hasFilesContaining: hasVueFilesContaining,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ripast/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.1",
|
|
5
5
|
"description": "Vue (and Nuxt) framework adapter for ripast. Provides Volar/Vue Language Service-backed rename, move, and template rewriting for .vue SFCs.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"typescript": ">=5.4",
|
|
45
|
-
"@ripast/core": "0.0.
|
|
45
|
+
"@ripast/core": "0.0.1"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@volar/language-service": "^2.4.28",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"vscode-uri": "^3.1.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@ripast/core": "0.0.
|
|
58
|
+
"@ripast/core": "0.0.1"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "obuild",
|