@dxup/nuxt 0.4.0 → 0.4.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/module.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as _nuxt_schema0 from "@nuxt/schema";
1
+ import * as _$_nuxt_schema0 from "@nuxt/schema";
2
2
 
3
3
  //#region src/module/index.d.ts
4
4
  interface ModuleOptions {
@@ -46,7 +46,7 @@ interface ModuleOptions {
46
46
  unofficial?: boolean;
47
47
  };
48
48
  }
49
- declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, {
49
+ declare const _default: _$_nuxt_schema0.NuxtModule<ModuleOptions, {
50
50
  features: {
51
51
  components: true;
52
52
  importGlob: true;
package/dist/module.mjs CHANGED
@@ -1,13 +1,11 @@
1
1
  import { addTemplate, defineNuxtModule, useNitro } from "@nuxt/kit";
2
2
  import { Buffer } from "node:buffer";
3
- import EventEmitter from "node:events";
3
+ import { EventEmitter } from "node:events";
4
4
  import { mkdir, open, readFile, writeFile } from "node:fs/promises";
5
5
  import { watch } from "chokidar";
6
6
  import { dirname, join } from "pathe";
7
-
8
7
  //#region package.json
9
8
  var name = "@dxup/nuxt";
10
-
11
9
  //#endregion
12
10
  //#region src/event/client.ts
13
11
  const responseRE = /^```json \{(?<key>.*)\}\n(?<value>[\s\S]*?)\n```$/;
@@ -23,7 +21,7 @@ async function createEventClient(nuxt) {
23
21
  });
24
22
  const client = new EventEmitter();
25
23
  let offset = 0;
26
- watcher.on("change", async (path$1, stats) => {
24
+ watcher.on("change", async (path, stats) => {
27
25
  if (!stats || stats.size <= offset) return;
28
26
  const pos = offset;
29
27
  offset = stats.size;
@@ -37,18 +35,17 @@ async function createEventClient(nuxt) {
37
35
  });
38
36
  return client;
39
37
  }
40
-
41
38
  //#endregion
42
39
  //#region src/module/events.ts
43
40
  const uppercaseRE = /[A-Z]/;
44
41
  async function onComponentsRename(nuxt, { fileName, references }) {
45
42
  const component = Object.values(nuxt.apps).flatMap((app) => app.components).find((c) => c.filePath === fileName);
46
43
  if (!component) return;
47
- const tasks = Object.entries(references).map(async ([fileName$1, references$1]) => {
48
- const code = await readFile(fileName$1, "utf-8");
44
+ const tasks = Object.entries(references).map(async ([fileName, references]) => {
45
+ const code = await readFile(fileName, "utf-8");
49
46
  const chunks = [];
50
47
  let offset = 0;
51
- for (const { textSpan, lazy } of references$1) {
48
+ for (const { textSpan, lazy } of references) {
52
49
  const start = textSpan.start;
53
50
  const end = start + textSpan.length;
54
51
  const oldName = code.slice(start, end);
@@ -57,11 +54,10 @@ async function onComponentsRename(nuxt, { fileName, references }) {
57
54
  offset = end;
58
55
  }
59
56
  chunks.push(code.slice(offset));
60
- await writeFile(fileName$1, chunks.join(""));
57
+ await writeFile(fileName, chunks.join(""));
61
58
  });
62
59
  await Promise.all(tasks);
63
60
  }
64
-
65
61
  //#endregion
66
62
  //#region src/module/index.ts
67
63
  var module_default = defineNuxtModule().with({
@@ -89,7 +85,7 @@ var module_default = defineNuxtModule().with({
89
85
  addTemplate({
90
86
  filename: "dxup/data.json",
91
87
  write: true,
92
- getContents({ nuxt: nuxt$1, app }) {
88
+ getContents({ nuxt, app }) {
93
89
  const layouts = Object.fromEntries(Object.values(app.layouts).map((item) => [item.name, item.file]));
94
90
  const middleware = app.middleware.reduce((acc, item) => {
95
91
  if (!item.global) acc[item.name] = item.path;
@@ -105,9 +101,9 @@ var module_default = defineNuxtModule().with({
105
101
  return acc;
106
102
  }, {});
107
103
  const data = {
108
- buildDir: nuxt$1.options.buildDir,
109
- publicDir: nuxt$1.options.dir.public,
110
- configFiles: [...nuxt$1.options._nuxtConfigFiles, ...nuxt$1.options._layers.map((layer) => layer._configFile).filter(Boolean)],
104
+ buildDir: nuxt.options.buildDir,
105
+ publicDir: nuxt.options.dir.public,
106
+ configFiles: [...nuxt.options._nuxtConfigFiles, ...nuxt.options._layers.map((layer) => layer._configFile).filter(Boolean)],
111
107
  layouts,
112
108
  middleware,
113
109
  nitroRoutes,
@@ -124,6 +120,5 @@ function append(plugins, target, ...keys) {
124
120
  for (const key of keys) target = target[key] ??= {};
125
121
  (target.plugins ??= []).push(...plugins);
126
122
  }
127
-
128
123
  //#endregion
129
- export { module_default as default };
124
+ export { module_default as default };
@@ -1,24 +1,18 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __defProp = Object.defineProperty;
3
- var __export = (all, symbols) => {
3
+ var __exportAll = (all, no_symbols) => {
4
4
  let target = {};
5
- for (var name in all) {
6
- __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- }
11
- if (symbols) {
12
- __defProp(target, Symbol.toStringTag, { value: "Module" });
13
- }
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
14
10
  return target;
15
11
  };
16
-
17
12
  //#endregion
18
13
  let node_fs_promises = require("node:fs/promises");
19
14
  let pathe = require("pathe");
20
15
  let tinyglobby = require("tinyglobby");
21
-
22
16
  //#region src/event/server.ts
23
17
  function createEventServer(info) {
24
18
  const path = (0, pathe.join)(info.project.getCurrentDirectory(), "dxup/events.md");
@@ -29,7 +23,6 @@ function createEventServer(info) {
29
23
  }
30
24
  return { write };
31
25
  }
32
-
33
26
  //#endregion
34
27
  //#region src/typescript/data.ts
35
28
  const initialValue = {
@@ -55,20 +48,19 @@ function createData(ts, info) {
55
48
  const path = (0, pathe.join)(info.languageServiceHost.getCurrentDirectory(), "dxup/data.json");
56
49
  const data = {};
57
50
  const updates = callbacks[path] ??= (ts.sys.watchFile?.(path, () => {
58
- const text$1 = ts.sys.readFile(path);
59
- for (const update of updates) update(text$1);
51
+ const text = ts.sys.readFile(path);
52
+ for (const update of updates) update(text);
60
53
  }), []);
61
- updates.push((text$1) => {
54
+ updates.push((text) => {
62
55
  Object.assign(data, {
63
56
  ...initialValue,
64
- ...text$1 ? JSON.parse(text$1) : {}
57
+ ...text ? JSON.parse(text) : {}
65
58
  });
66
59
  });
67
60
  const text = ts.sys.readFile(path);
68
61
  updates.at(-1)(text);
69
62
  return data;
70
63
  }
71
-
72
64
  //#endregion
73
65
  //#region src/typescript/utils.ts
74
66
  function createModuleDefinition(ts, path) {
@@ -115,10 +107,9 @@ function withVirtualOffset(language, sourceScript, position, method) {
115
107
  map.toGeneratedLocation = original;
116
108
  }
117
109
  }
118
-
119
110
  //#endregion
120
111
  //#region src/typescript/features/findReferences.ts
121
- var findReferences_exports = /* @__PURE__ */ __export({ postprocess: () => postprocess$1 });
112
+ var findReferences_exports = /* @__PURE__ */ __exportAll({ postprocess: () => postprocess$1 });
122
113
  function postprocess$1(context, language, findReferences) {
123
114
  const { ts, info } = context;
124
115
  return (...args) => {
@@ -137,10 +128,9 @@ function postprocess$1(context, language, findReferences) {
137
128
  return result;
138
129
  };
139
130
  }
140
-
141
131
  //#endregion
142
132
  //#region src/typescript/features/findRenameLocations.ts
143
- var findRenameLocations_exports = /* @__PURE__ */ __export({ preprocess: () => preprocess$2 });
133
+ var findRenameLocations_exports = /* @__PURE__ */ __exportAll({ preprocess: () => preprocess$2 });
144
134
  function preprocess$2(context, findRenameLocations) {
145
135
  const { data } = context;
146
136
  return (...args) => {
@@ -149,7 +139,6 @@ function preprocess$2(context, findRenameLocations) {
149
139
  });
150
140
  };
151
141
  }
152
-
153
142
  //#endregion
154
143
  //#region ../shared/src/index.ts
155
144
  function* forEachTouchingNode(ts, sourceFile, position) {
@@ -164,12 +153,12 @@ function* binaryVisit(ts, sourceFile, node, position) {
164
153
  let right = nodes.length - 1;
165
154
  while (left <= right) {
166
155
  const mid = Math.floor((left + right) / 2);
167
- const node$1 = nodes[mid];
168
- if (position > node$1.getEnd()) left = mid + 1;
169
- else if (position < node$1.getStart(sourceFile)) right = mid - 1;
156
+ const node = nodes[mid];
157
+ if (position > node.getEnd()) left = mid + 1;
158
+ else if (position < node.getStart(sourceFile)) right = mid - 1;
170
159
  else {
171
- yield node$1;
172
- yield* binaryVisit(ts, sourceFile, node$1, position);
160
+ yield node;
161
+ yield* binaryVisit(ts, sourceFile, node, position);
173
162
  return;
174
163
  }
175
164
  }
@@ -177,10 +166,9 @@ function* binaryVisit(ts, sourceFile, node, position) {
177
166
  function isTextSpanWithin(node, textSpan, sourceFile) {
178
167
  return textSpan.start + textSpan.length <= node.getEnd() && textSpan.start >= node.getStart(sourceFile);
179
168
  }
180
-
181
169
  //#endregion
182
170
  //#region src/typescript/features/getDefinitionAndBoundSpan.ts
183
- var getDefinitionAndBoundSpan_exports = /* @__PURE__ */ __export({
171
+ var getDefinitionAndBoundSpan_exports = /* @__PURE__ */ __exportAll({
184
172
  postprocess: () => postprocess,
185
173
  preprocess: () => preprocess$1
186
174
  });
@@ -222,18 +210,18 @@ function preprocess$1(context, getDefinitionAndBoundSpan) {
222
210
  return (...args) => {
223
211
  const result = getDefinitionAndBoundSpan(...args);
224
212
  if (!result) {
225
- const program$1 = info.languageService.getProgram();
226
- const sourceFile = program$1.getSourceFile(args[0]);
213
+ const program = info.languageService.getProgram();
214
+ const sourceFile = program.getSourceFile(args[0]);
227
215
  if (!sourceFile) return;
228
- const checker = program$1.getTypeChecker();
229
- let result$1;
216
+ const checker = program.getTypeChecker();
217
+ let result;
230
218
  for (const node of forEachTouchingNode(ts, sourceFile, args[1])) {
231
- if (data.features.importGlob) result$1 ??= visitImportGlob(ts, info, sourceFile, node, args[1]);
232
- if (data.features.nitroRoutes) result$1 ??= visitNitroRoutes(ts, data, checker, sourceFile, node, args[1]);
233
- if (data.features.pageMeta) result$1 ??= visitPageMeta(ts, data, sourceFile, node, args[1]);
234
- if (data.features.typedPages) result$1 ??= visitTypedPages(ts, data, checker, sourceFile, node, args[1]);
219
+ if (data.features.importGlob) result ??= visitImportGlob(ts, info, sourceFile, node, args[1]);
220
+ if (data.features.nitroRoutes) result ??= visitNitroRoutes(ts, data, checker, sourceFile, node, args[1]);
221
+ if (data.features.pageMeta) result ??= visitPageMeta(ts, data, sourceFile, node, args[1]);
222
+ if (data.features.typedPages) result ??= visitTypedPages(ts, data, checker, sourceFile, node, args[1]);
235
223
  }
236
- if (result$1) return result$1;
224
+ if (result) return result;
237
225
  }
238
226
  if (!result?.definitions?.length) return result;
239
227
  const program = info.languageService.getProgram();
@@ -241,10 +229,10 @@ function preprocess$1(context, getDefinitionAndBoundSpan) {
241
229
  for (const definition of result.definitions) {
242
230
  const sourceFile = program.getSourceFile(definition.fileName);
243
231
  if (!sourceFile) continue;
244
- let result$1;
245
- if (data.features.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result$1 = visitRuntimeConfig(context, sourceFile, definition);
246
- if (result$1?.length) {
247
- for (const definition$1 of result$1) definitions.add(definition$1);
232
+ let result;
233
+ if (data.features.runtimeConfig && definition.fileName.endsWith("runtime-config.d.ts")) result = visitRuntimeConfig(context, sourceFile, definition);
234
+ if (result?.length) {
235
+ for (const definition of result) definitions.add(definition);
248
236
  definitions.delete(definition);
249
237
  }
250
238
  }
@@ -328,11 +316,19 @@ function visitPageMeta(ts, data, sourceFile, node, position) {
328
316
  if (!ts.isPropertyAssignment(node) || !ts.isIdentifier(node.name) || !pageMetaKeys.has(node.name.text) || !ts.isCallExpression(node.parent.parent) || !ts.isIdentifier(node.parent.parent.expression) || node.parent.parent.expression.text !== "definePageMeta") return;
329
317
  switch (node.name.text) {
330
318
  case "layout": {
331
- if (!ts.isStringLiteralLike(node.initializer)) return;
332
- const start = node.initializer.getStart(sourceFile);
333
- const end = node.initializer.getEnd();
319
+ let literal;
320
+ if (ts.isStringLiteralLike(node.initializer)) literal = node.initializer;
321
+ else if (ts.isObjectLiteralExpression(node.initializer)) {
322
+ for (const prop of node.initializer.properties) if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === "name" && ts.isStringLiteralLike(prop.initializer)) {
323
+ literal = prop.initializer;
324
+ break;
325
+ }
326
+ }
327
+ if (!literal) return;
328
+ const start = literal.getStart(sourceFile);
329
+ const end = literal.getEnd();
334
330
  if (position < start || position > end) return;
335
- const path = data.layouts[node.initializer.text];
331
+ const path = data.layouts[literal.text];
336
332
  if (path === void 0) return;
337
333
  return {
338
334
  textSpan: {
@@ -418,8 +414,8 @@ function* forwardRuntimeConfig(context, definition, path) {
418
414
  const nodeProgram = nodeProject.getLanguageService().getProgram();
419
415
  if (!nodeProgram) return;
420
416
  const checker = nodeProgram.getTypeChecker();
421
- for (const configFile$1 of data.configFiles) {
422
- const sourceFile = nodeProgram.getSourceFile(configFile$1);
417
+ for (const configFile of data.configFiles) {
418
+ const sourceFile = nodeProgram.getSourceFile(configFile);
423
419
  if (!sourceFile) continue;
424
420
  outer: for (const node of sourceFile.statements) {
425
421
  if (!ts.isExportAssignment(node) || !ts.isCallExpression(node.expression) || !node.expression.arguments.length) continue;
@@ -433,19 +429,19 @@ function* forwardRuntimeConfig(context, definition, path) {
433
429
  currentType = checker.getTypeOfSymbol(symbol);
434
430
  }
435
431
  for (const decl of currentSymbol?.declarations ?? []) {
436
- const sourceFile$1 = decl.getSourceFile();
432
+ const sourceFile = decl.getSourceFile();
437
433
  const contextSpan = {
438
- start: decl.getStart(sourceFile$1),
439
- length: decl.getWidth(sourceFile$1)
434
+ start: decl.getStart(sourceFile),
435
+ length: decl.getWidth(sourceFile)
440
436
  };
441
437
  let textSpan = contextSpan;
442
438
  if (ts.isPropertyAssignment(decl) || ts.isPropertySignature(decl)) textSpan = {
443
- start: decl.name.getStart(sourceFile$1),
444
- length: decl.name.getWidth(sourceFile$1)
439
+ start: decl.name.getStart(sourceFile),
440
+ length: decl.name.getWidth(sourceFile)
445
441
  };
446
442
  yield {
447
443
  ...definition,
448
- fileName: sourceFile$1.fileName,
444
+ fileName: sourceFile.fileName,
449
445
  textSpan,
450
446
  contextSpan
451
447
  };
@@ -453,10 +449,9 @@ function* forwardRuntimeConfig(context, definition, path) {
453
449
  }
454
450
  }
455
451
  }
456
-
457
452
  //#endregion
458
453
  //#region src/typescript/features/getEditsForFileRename.ts
459
- var getEditsForFileRename_exports = /* @__PURE__ */ __export({ preprocess: () => preprocess });
454
+ var getEditsForFileRename_exports = /* @__PURE__ */ __exportAll({ preprocess: () => preprocess });
460
455
  function preprocess(context, getEditsForFileRename) {
461
456
  const { ts, info, data, server } = context;
462
457
  return (...args) => {
@@ -475,7 +470,7 @@ function preprocess(context, getEditsForFileRename) {
475
470
  const position = node.name.getStart(sourceFile);
476
471
  const res = languageService.getReferencesAtPosition(fileName, position)?.filter((entry) => !entry.fileName.startsWith(data.buildDir))?.sort((a, b) => a.textSpan.start - b.textSpan.start);
477
472
  const lazy = node.type && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "LazyComponent";
478
- for (const { fileName: fileName$1, textSpan } of res ?? []) (references[fileName$1] ??= []).push({
473
+ for (const { fileName, textSpan } of res ?? []) (references[fileName] ??= []).push({
479
474
  textSpan,
480
475
  lazy: lazy || void 0
481
476
  });
@@ -492,11 +487,10 @@ function preprocess(context, getEditsForFileRename) {
492
487
  });
493
488
  };
494
489
  }
495
-
496
490
  //#endregion
497
491
  //#region src/typescript/index.ts
498
- const plugin = (module$1) => {
499
- const { typescript: ts } = module$1;
492
+ const plugin = (module) => {
493
+ const { typescript: ts } = module;
500
494
  return { create(info) {
501
495
  const data = createData(ts, info);
502
496
  const context = {
@@ -514,14 +508,9 @@ const plugin = (module$1) => {
514
508
  const original = languageService[key];
515
509
  methods[key] = method.postprocess(context, context.language, original);
516
510
  }
517
- info.project["languageService"] = new Proxy(languageService, {
518
- get(target, p, receiver) {
519
- return methods[p] ?? Reflect.get(target, p, receiver);
520
- },
521
- set(...args) {
522
- return Reflect.set(...args);
523
- }
524
- });
511
+ info.project["languageService"] = new Proxy(languageService, { get(target, p, receiver) {
512
+ return methods[p] ?? Reflect.get(target, p, receiver);
513
+ } });
525
514
  });
526
515
  for (const [key, method] of [
527
516
  ["findRenameLocations", findRenameLocations_exports],
@@ -534,7 +523,5 @@ const plugin = (module$1) => {
534
523
  return info.languageService;
535
524
  } };
536
525
  };
537
- var typescript_default = plugin;
538
-
539
526
  //#endregion
540
- module.exports = typescript_default;
527
+ module.exports = plugin;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dxup/nuxt",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "description": "TypeScript plugin for Nuxt",
6
6
  "author": "KazariEX",
7
7
  "license": "MIT",
@@ -18,20 +18,25 @@
18
18
  "peerDependencies": {
19
19
  "typescript": "*"
20
20
  },
21
+ "peerDependenciesMeta": {
22
+ "typescript": {
23
+ "optional": true
24
+ }
25
+ },
21
26
  "dependencies": {
22
- "@nuxt/kit": "^4.2.2",
27
+ "@nuxt/kit": "^4.4.2",
23
28
  "chokidar": "^5.0.0",
24
29
  "pathe": "^2.0.3",
25
- "tinyglobby": "^0.2.15",
30
+ "tinyglobby": "^0.2.16",
26
31
  "@dxup/unimport": "^0.1.2"
27
32
  },
28
33
  "devDependencies": {
29
- "@dxup/shared": "",
30
- "@volar/language-core": "^2.4.27",
31
- "@volar/typescript": "^2.4.27",
32
- "@vue/language-core": "^3.2.1",
33
- "nuxt": "^4.2.2",
34
- "typescript": "^5.9.3"
34
+ "@volar/language-core": "^2.4.28",
35
+ "@volar/typescript": "^2.4.28",
36
+ "@vue/language-core": "^3.2.7",
37
+ "nuxt": "^4.4.2",
38
+ "typescript": "^6.0.3",
39
+ "@dxup/shared": "0.0.0"
35
40
  },
36
41
  "scripts": {
37
42
  "build": "tsdown",