@pubinfo/vite 2.1.7 → 2.1.9

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.
@@ -1,9 +1,9 @@
1
- import { UserConfig, UserConfigFnObject } from "rolldown-vite";
1
+ import { UserConfig, UserConfigFnObject } from "vite";
2
2
  import * as vite_plugin_vue_devtools0 from "vite-plugin-vue-devtools";
3
3
  import { VitePluginVueDevToolsOptions } from "vite-plugin-vue-devtools";
4
4
  import * as _pubinfo_unplugin_openapi0 from "@pubinfo/unplugin-openapi";
5
5
  import { Options } from "@pubinfo/unplugin-openapi";
6
- export * from "rolldown-vite";
6
+ export * from "vite";
7
7
  export * from "vite-plugin-fake-server/client";
8
8
 
9
9
  //#region src/plugins/built-in/inject-auto.d.ts
@@ -11,9 +11,6 @@ interface InjectAutoOptions {
11
11
  id: string;
12
12
  enabled?: boolean;
13
13
  }
14
- /**
15
- * 自动注入代码
16
- */
17
14
  //#endregion
18
15
  //#region src/plugins/built-in/lib-resolver.d.ts
19
16
  type GlobInput = string;
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { defineConfig, loadEnv, mergeConfig, normalizePath } from "rolldown-vite";
2
+ import { defineConfig, loadEnv, mergeConfig, normalizePath } from "vite";
3
3
  import process, { cwd } from "node:process";
4
4
  import { logger } from "@pubinfo/shared";
5
5
  import chalk from "chalk";
@@ -7,6 +7,10 @@ import path, { dirname, join, posix, relative, resolve } from "node:path";
7
7
  import vue from "@vitejs/plugin-vue";
8
8
  import vueJsx from "@vitejs/plugin-vue-jsx";
9
9
  import fs from "fs-extra";
10
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
11
+ import { proxyCreateProgram } from "@volar/typescript";
12
+ import { createParsedCommandLine, createVueLanguagePlugin, getDefaultCompilerOptions } from "@vue/language-core";
13
+ import ts from "typescript";
10
14
  import boxen from "boxen";
11
15
  import MagicString from "magic-string";
12
16
  import fg from "fast-glob";
@@ -16,7 +20,6 @@ import "micromatch";
16
20
  import { execSync } from "node:child_process";
17
21
  import dayjs from "dayjs";
18
22
  import { readPackageJSON } from "pkg-types";
19
- import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
20
23
  import { readFile } from "node:fs/promises";
21
24
  import { fileURLToPath } from "node:url";
22
25
  import { Buffer } from "node:buffer";
@@ -28,7 +31,6 @@ import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
28
31
  import components from "unplugin-vue-components/vite";
29
32
  import compression from "vite-plugin-compression";
30
33
  import { pubinfoDevtools } from "@pubinfo/devtools";
31
- import dts from "vite-plugin-dts";
32
34
  import Icons from "unplugin-icons/vite";
33
35
  import { libInjectCss } from "vite-plugin-lib-inject-css";
34
36
  import VueDevTools from "vite-plugin-vue-devtools";
@@ -37,21 +39,21 @@ import { vitePluginFakeServer } from "vite-plugin-fake-server";
37
39
  import OpenAPI from "@pubinfo/unplugin-openapi/vite";
38
40
  import Unocss from "unocss/vite";
39
41
 
40
- export * from "rolldown-vite"
42
+ export * from "vite"
41
43
 
42
44
  export * from "vite-plugin-fake-server/client"
43
45
 
44
46
  //#region src/helper/alias.ts
45
47
  function alias(root) {
46
48
  const resolvePath = (name) => join(root, name);
47
- const resolveDeps = (name, path$1) => join(createRequire(import.meta.url).resolve(name), path$1);
49
+ const resolveDeps = (name) => dirname(createRequire(import.meta.url).resolve(name));
48
50
  return {
49
51
  "@": resolvePath("src"),
50
52
  "#": resolvePath("types"),
51
- "vue": resolveDeps("vue", "../"),
52
- "vue-router": resolveDeps("vue-router", "../"),
53
- "pinia": resolveDeps("pinia", "../"),
54
- "unocss": resolveDeps("unocss", "../")
53
+ "vue": resolveDeps("vue"),
54
+ "vue-router": resolveDeps("vue-router"),
55
+ "pinia": resolveDeps("pinia"),
56
+ "unocss": resolveDeps("unocss")
55
57
  };
56
58
  }
57
59
 
@@ -104,6 +106,124 @@ function createCleanBuild() {
104
106
  };
105
107
  }
106
108
 
109
+ //#endregion
110
+ //#region src/plugins/built-in/dts.ts
111
+ function createDTS(options = {}) {
112
+ const { exclude = [
113
+ "tests/**/*",
114
+ "pubinfo.config.ts",
115
+ ".pubinfo/vite.config.ts",
116
+ ".pubinfo/vite.config.d.ts",
117
+ ".pubinfo/tsconfig.app.json"
118
+ ], excludeFromOutput = [".pubinfo/**/*"], clearPureImport = false } = options;
119
+ let root;
120
+ let outDir;
121
+ let libEntry;
122
+ const createVueProgram = proxyCreateProgram(ts, ts.createProgram, (tsInstance, programOptions) => {
123
+ const { configFilePath } = programOptions.options;
124
+ const vueOptions = typeof configFilePath === "string" ? createParsedCommandLine(tsInstance, tsInstance.sys, configFilePath.replace(/\\/g, "/")).vueOptions : getDefaultCompilerOptions();
125
+ return [createVueLanguagePlugin(tsInstance, programOptions.options, vueOptions, (id) => id)];
126
+ });
127
+ return {
128
+ name: "pubinfo:dts",
129
+ apply: "build",
130
+ enforce: "post",
131
+ configResolved(config) {
132
+ root = config.root;
133
+ outDir = resolve(root, config.build.outDir);
134
+ if (config.build.lib) {
135
+ const entry = config.build.lib.entry;
136
+ if (typeof entry === "string") libEntry = resolve(root, entry);
137
+ else if (Array.isArray(entry)) libEntry = resolve(root, entry[0]);
138
+ else if (entry && typeof entry === "object") {
139
+ const firstKey = Object.keys(entry)[0];
140
+ if (firstKey) libEntry = resolve(root, entry[firstKey]);
141
+ }
142
+ }
143
+ },
144
+ async closeBundle() {
145
+ console.warn("\n[pubinfo:dts] Start generating declaration files...");
146
+ const startTime = Date.now();
147
+ const configPath = ts.findConfigFile(root, ts.sys.fileExists);
148
+ if (!configPath) {
149
+ console.error("[pubinfo:dts] Could not find tsconfig.json");
150
+ return;
151
+ }
152
+ const configFile = ts.readConfigFile(configPath, (path$1) => readFileSync(path$1, "utf-8"));
153
+ if (configFile.error) {
154
+ console.error("[pubinfo:dts] Error reading tsconfig.json");
155
+ return;
156
+ }
157
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(configPath));
158
+ const compilerOptions = {
159
+ ...parsedConfig.options,
160
+ noEmit: false,
161
+ declaration: true,
162
+ emitDeclarationOnly: true,
163
+ declarationDir: outDir,
164
+ outDir,
165
+ skipLibCheck: true,
166
+ noEmitOnError: false
167
+ };
168
+ let entryRoot;
169
+ if (libEntry) entryRoot = dirname(libEntry);
170
+ else {
171
+ const srcDir = resolve(root, "src");
172
+ entryRoot = existsSync(srcDir) ? srcDir : root;
173
+ }
174
+ compilerOptions.rootDir = entryRoot;
175
+ const matchesPattern = (relativePath, patterns) => {
176
+ for (const pattern of patterns) if (pattern.includes("**")) {
177
+ const basePattern = pattern.replace("/**/*", "").replace("/**", "");
178
+ if (relativePath.startsWith(basePattern)) return true;
179
+ } else if (relativePath === pattern || relativePath.startsWith(`${pattern}/`)) return true;
180
+ return false;
181
+ };
182
+ const shouldIncludeForTypeCheck = (fileName) => {
183
+ return !matchesPattern(relative(root, fileName), exclude);
184
+ };
185
+ const shouldIncludeForOutput = (fileName) => {
186
+ return !matchesPattern(relative(root, fileName), [...exclude, ...excludeFromOutput]);
187
+ };
188
+ const rootNames = parsedConfig.fileNames.filter(shouldIncludeForTypeCheck);
189
+ const program = createVueProgram({
190
+ host: ts.createCompilerHost(compilerOptions),
191
+ rootNames,
192
+ options: {
193
+ ...compilerOptions,
194
+ configFilePath: configPath
195
+ }
196
+ });
197
+ let emittedCount = 0;
198
+ program.emit(void 0, (fileName, content) => {
199
+ const relativeToOutDir = relative(outDir, fileName);
200
+ if (!shouldIncludeForOutput(resolve(entryRoot, relativeToOutDir.replace(/\.d\.ts$/, ".ts").replace(/\.d\.tsx$/, ".tsx")))) return;
201
+ const outputDirPath = dirname(fileName);
202
+ if (!existsSync(outputDirPath)) mkdirSync(outputDirPath, { recursive: true });
203
+ let processedContent = content;
204
+ if (clearPureImport) processedContent = content.replace(/^import\s+['"][^'"]+['"];\s*$/gm, "");
205
+ writeFileSync(fileName, processedContent, "utf-8");
206
+ emittedCount++;
207
+ }, void 0, true);
208
+ const diagnostics = [
209
+ ...program.getDeclarationDiagnostics(),
210
+ ...program.getSemanticDiagnostics(),
211
+ ...program.getSyntacticDiagnostics()
212
+ ].filter((d) => {
213
+ if (d.file) return shouldIncludeForTypeCheck(d.file.fileName);
214
+ return true;
215
+ });
216
+ if (diagnostics.length > 0) console.warn("[pubinfo:dts] Type diagnostics:\n", ts.formatDiagnosticsWithColorAndContext(diagnostics, {
217
+ getCanonicalFileName: (path$1) => path$1,
218
+ getCurrentDirectory: () => root,
219
+ getNewLine: () => "\n"
220
+ }));
221
+ const elapsed = Date.now() - startTime;
222
+ console.warn(`[pubinfo:dts] Generated ${emittedCount} declaration files in ${elapsed}ms\n`);
223
+ }
224
+ };
225
+ }
226
+
107
227
  //#endregion
108
228
  //#region src/plugins/built-in/info.ts
109
229
  var Ctx$1 = class {
@@ -548,15 +668,6 @@ function createPubinfoDevtoolsPlugin() {
548
668
  return pubinfoDevtools();
549
669
  }
550
670
 
551
- //#endregion
552
- //#region src/plugins/intergrations/dts.ts
553
- function createDTS() {
554
- return dts({
555
- clearPureImport: false,
556
- exclude: ["tests/**/*", ".pubinfo/**/*"]
557
- });
558
- }
559
-
560
671
  //#endregion
561
672
  //#region src/plugins/intergrations/icon.ts
562
673
  function createIcons() {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@pubinfo/vite",
3
3
  "type": "module",
4
- "version": "2.1.7",
4
+ "version": "2.1.9",
5
5
  "exports": {
6
6
  ".": {
7
- "types": "./dist/index.d.ts",
8
- "default": "./dist/index.js"
7
+ "types": "./dist/index.d.mts",
8
+ "default": "./dist/index.mjs"
9
9
  }
10
10
  },
11
- "main": "./dist/index.js",
12
- "module": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
11
+ "main": "./dist/index.mjs",
12
+ "module": "./dist/index.mjs",
13
+ "types": "./dist/index.d.mts",
14
14
  "files": [
15
15
  "dist"
16
16
  ],
@@ -18,17 +18,23 @@
18
18
  "node": "^20.19.0 || >=22.12.0"
19
19
  },
20
20
  "peerDependencies": {
21
- "vue": "^3.5.17"
21
+ "pinia": "^3.0.4",
22
+ "typescript": "^5.8.3",
23
+ "vue": "^3.5.26",
24
+ "vue-router": "^4.6.4",
25
+ "vue-tsc": "^3.1.8"
22
26
  },
23
27
  "dependencies": {
24
28
  "@pubinfo/unplugin-openapi": "^0.9.1",
25
29
  "@vitejs/plugin-legacy": "^7.2.1",
26
- "@vitejs/plugin-vue": "^6.0.0",
27
- "@vitejs/plugin-vue-jsx": "^5.0.1",
30
+ "@vitejs/plugin-vue": "^6.0.3",
31
+ "@vitejs/plugin-vue-jsx": "^5.1.2",
32
+ "@volar/typescript": "^2.4.11",
33
+ "@vue/language-core": "^3.1.8",
28
34
  "abort-controller": "^3.0.0",
29
35
  "boxen": "^8.0.1",
30
36
  "chalk": "^5.4.1",
31
- "dayjs": "^1.11.13",
37
+ "dayjs": "^1.11.19",
32
38
  "fast-glob": "^3.3.3",
33
39
  "fs-extra": "^11.3.0",
34
40
  "jszip": "^3.10.1",
@@ -37,20 +43,19 @@
37
43
  "micromatch": "^4.0.8",
38
44
  "picomatch": "^4.0.3",
39
45
  "pkg-types": "^2.3.0",
40
- "rolldown-vite": "^7.1.2",
41
46
  "terser": "^5.43.1",
42
47
  "unocss": "^66.4.2",
43
48
  "unplugin-auto-import": "^20.0.0",
44
49
  "unplugin-icons": "^22.2.0",
45
50
  "unplugin-vue-components": "^29.0.0",
51
+ "vite": "^8.0.0-beta.3",
46
52
  "vite-plugin-compression": "^0.5.1",
47
- "vite-plugin-dts": "^4.5.4",
48
53
  "vite-plugin-env-runtime": "^0.3.6",
49
54
  "vite-plugin-fake-server": "^2.2.0",
50
55
  "vite-plugin-lib-inject-css": "^2.2.2",
51
56
  "vite-plugin-vue-devtools": "^8.0.0",
52
- "@pubinfo/devtools": "2.1.7",
53
- "@pubinfo/shared": "2.1.7"
57
+ "@pubinfo/devtools": "2.1.9",
58
+ "@pubinfo/shared": "2.1.9"
54
59
  },
55
60
  "devDependencies": {
56
61
  "@types/fs-extra": "^11.0.4",
@@ -58,7 +63,9 @@
58
63
  "@types/micromatch": "^4.0.9",
59
64
  "@types/node": "^24.0.10",
60
65
  "@types/picomatch": "^4.0.2",
61
- "vue": "^3.5.17"
66
+ "pinia": "^3.0.4",
67
+ "vue": "^3.5.26",
68
+ "vue-router": "^4.6.4"
62
69
  },
63
70
  "scripts": {
64
71
  "dev": "tsdown --watch",