@pubinfo-pr/vite 0.189.2 → 0.203.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.
@@ -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;
@@ -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-pr/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";
@@ -70,7 +72,7 @@ function getServerProxy(env, isProxy) {
70
72
  else serverProxy[pk] = {
71
73
  target: url,
72
74
  changeOrigin: true,
73
- rewrite: (path$1) => path$1.replace(pk, ""),
75
+ rewrite: (path) => path.replace(pk, ""),
74
76
  secure: false
75
77
  };
76
78
  }
@@ -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-pr: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-pr: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-pr:dts] Could not find tsconfig.json");
150
+ return;
151
+ }
152
+ const configFile = ts.readConfigFile(configPath, (path) => readFileSync(path, "utf-8"));
153
+ if (configFile.error) {
154
+ console.error("[pubinfo-pr: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-pr:dts] Type diagnostics:\n", ts.formatDiagnosticsWithColorAndContext(diagnostics, {
217
+ getCanonicalFileName: (path) => path,
218
+ getCurrentDirectory: () => root,
219
+ getNewLine: () => "\n"
220
+ }));
221
+ const elapsed = Date.now() - startTime;
222
+ console.warn(`[pubinfo-pr: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 {
@@ -198,8 +318,8 @@ function getPatternBase(pattern) {
198
318
  }
199
319
  return baseParts.join("/");
200
320
  }
201
- function normalizePath$1(path$1) {
202
- return posix.normalize(path$1.replace(/\\/g, "/"));
321
+ function normalizePath$1(path) {
322
+ return posix.normalize(path.replace(/\\/g, "/"));
203
323
  }
204
324
  function libResolverPlugin(options) {
205
325
  const virtualModuleId = "virtual:pubinfo-resolver";
@@ -532,12 +652,12 @@ function createCompression(env) {
532
652
  const plugin = [];
533
653
  if (compressList.includes("gzip")) plugin.push(compression({
534
654
  ext: ".gz",
535
- deleteOriginFile: false
655
+ deleteOriginFile: true
536
656
  }));
537
657
  if (compressList.includes("brotli")) plugin.push(compression({
538
658
  ext: ".br",
539
659
  algorithm: "brotliCompress",
540
- deleteOriginFile: false
660
+ deleteOriginFile: true
541
661
  }));
542
662
  return plugin;
543
663
  }
@@ -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() {
@@ -623,12 +734,12 @@ function createVitePlugins(viteEnv, isBuild = false, config, type) {
623
734
  createUnocss(),
624
735
  createIcons(),
625
736
  createMock(viteEnv, isBuild),
626
- createInspector(config.devtools),
627
- createPubinfoDevtoolsPlugin(),
737
+ !isBuild && createInspector(config.devtools),
738
+ !isBuild && createPubinfoDevtoolsPlugin(),
628
739
  createOpenAPI(config.openapi),
629
740
  createLibResolver(config.resolver),
630
741
  createAppInfo(),
631
- createVirtualInspector({ enabled: true }),
742
+ !isBuild && createVirtualInspector({ enabled: true }),
632
743
  createSystemInfo()
633
744
  ];
634
745
  if (type === "module") {
@@ -654,8 +765,8 @@ function createDefaultAppConfig(config) {
654
765
  const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
655
766
  return {
656
767
  base: "./",
768
+ envDir: root,
657
769
  server: {
658
- open: true,
659
770
  host: true,
660
771
  proxy: getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true"),
661
772
  warmup: { clientFiles: ["./index.html"] }
@@ -675,7 +786,8 @@ function createDefaultAppConfig(config) {
675
786
  entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
676
787
  advancedChunks: { groups: [{
677
788
  name: "pubinfo-pr",
678
- test: "pubinfo-pr"
789
+ test: "pubinfo-pr",
790
+ priority: 10
679
791
  }] }
680
792
  } }
681
793
  },
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@pubinfo-pr/vite",
3
3
  "type": "module",
4
- "version": "0.189.2",
4
+ "version": "0.203.2",
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,51 +18,54 @@
18
18
  "node": "^20.19.0 || >=22.12.0"
19
19
  },
20
20
  "peerDependencies": {
21
- "pinia": "^3.0.3",
22
- "vue": "^3.5.17",
23
- "vue-router": "^4.5.1"
21
+ "pinia": "^3.0.4",
22
+ "typescript": "^5.9.3",
23
+ "vue": "^3.5.28",
24
+ "vue-router": "^5.0.2",
25
+ "vue-tsc": "^3.2.4"
24
26
  },
25
27
  "dependencies": {
26
- "@pubinfo-pr/devtools": "0.189.2",
27
- "@pubinfo-pr/shared": "0.189.2",
28
+ "@pubinfo-pr/devtools": "0.203.2",
29
+ "@pubinfo-pr/shared": "0.203.2",
28
30
  "@pubinfo/unplugin-openapi": "^0.9.1",
29
31
  "@vitejs/plugin-legacy": "^7.2.1",
30
- "@vitejs/plugin-vue": "^6.0.0",
31
- "@vitejs/plugin-vue-jsx": "^5.0.1",
32
+ "@vitejs/plugin-vue": "^6.0.4",
33
+ "@vitejs/plugin-vue-jsx": "^5.1.4",
34
+ "@volar/typescript": "^2.4.28",
35
+ "@vue/language-core": "^3.2.4",
32
36
  "abort-controller": "^3.0.0",
33
37
  "boxen": "^8.0.1",
34
- "chalk": "^5.4.1",
35
- "dayjs": "^1.11.13",
38
+ "chalk": "^5.6.2",
39
+ "dayjs": "^1.11.19",
36
40
  "fast-glob": "^3.3.3",
37
- "fs-extra": "^11.3.0",
41
+ "fs-extra": "^11.3.3",
38
42
  "jszip": "^3.10.1",
39
- "lodash-es": "^4.17.21",
40
- "magic-string": "^0.30.19",
43
+ "lodash-es": "^4.17.23",
44
+ "magic-string": "^0.30.21",
41
45
  "micromatch": "^4.0.8",
42
46
  "picomatch": "^4.0.3",
43
47
  "pkg-types": "^2.3.0",
44
- "terser": "^5.43.1",
45
- "unocss": "^66.4.2",
46
- "unplugin-auto-import": "^20.0.0",
47
- "unplugin-icons": "^22.2.0",
48
- "unplugin-vue-components": "^29.0.0",
49
- "vite": "^8.0.0-beta.0",
48
+ "terser": "^5.46.0",
49
+ "unocss": "^66.6.0",
50
+ "unplugin-auto-import": "^21.0.0",
51
+ "unplugin-icons": "^23.0.1",
52
+ "unplugin-vue-components": "^31.0.0",
53
+ "vite": "^8.0.0-beta.13",
50
54
  "vite-plugin-compression": "^0.5.1",
51
- "vite-plugin-dts": "^4.5.4",
52
- "vite-plugin-env-runtime": "^0.3.6",
53
- "vite-plugin-fake-server": "^2.2.0",
55
+ "vite-plugin-env-runtime": "^0.3.7",
56
+ "vite-plugin-fake-server": "^2.2.2",
54
57
  "vite-plugin-lib-inject-css": "^2.2.2",
55
- "vite-plugin-vue-devtools": "^8.0.0"
58
+ "vite-plugin-vue-devtools": "^8.0.6"
56
59
  },
57
60
  "devDependencies": {
58
61
  "@types/fs-extra": "^11.0.4",
59
62
  "@types/lodash-es": "^4.17.12",
60
- "@types/micromatch": "^4.0.9",
61
- "@types/node": "^24.0.10",
63
+ "@types/micromatch": "^4.0.10",
64
+ "@types/node": "^25.2.2",
62
65
  "@types/picomatch": "^4.0.2",
63
- "pinia": "^3.0.3",
64
- "vue": "^3.5.17",
65
- "vue-router": "^4.5.1"
66
+ "pinia": "^3.0.4",
67
+ "vue": "^3.5.28",
68
+ "vue-router": "^5.0.2"
66
69
  },
67
70
  "scripts": {
68
71
  "dev": "tsdown --watch",