@electron-forge/plugin-vite 7.4.0 → 7.6.0
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 +2 -0
- package/dist/Config.d.ts +7 -2
- package/dist/Config.d.ts.map +1 -1
- package/dist/ViteConfig.d.ts +4 -6
- package/dist/ViteConfig.d.ts.map +1 -1
- package/dist/ViteConfig.js +26 -13
- package/dist/VitePlugin.d.ts +1 -2
- package/dist/VitePlugin.d.ts.map +1 -1
- package/dist/VitePlugin.js +34 -43
- package/dist/config/vite.base.config.d.ts +11 -0
- package/dist/config/vite.base.config.d.ts.map +1 -0
- package/dist/config/vite.base.config.js +90 -0
- package/dist/config/vite.main.config.d.ts +3 -0
- package/dist/config/vite.main.config.d.ts.map +1 -0
- package/dist/config/vite.main.config.js +34 -0
- package/dist/config/vite.preload.config.d.ts +3 -0
- package/dist/config/vite.preload.config.d.ts.map +1 -0
- package/dist/config/vite.preload.config.js +30 -0
- package/dist/config/vite.renderer.config.d.ts +3 -0
- package/dist/config/vite.renderer.config.d.ts.map +1 -0
- package/dist/config/vite.renderer.config.js +26 -0
- package/dist/util/plugins.d.ts.map +1 -1
- package/dist/util/plugins.js +1 -1
- package/forge-vite-env.d.ts +23 -0
- package/package.json +9 -8
- package/src/Config.ts +7 -3
- package/src/ViteConfig.ts +28 -13
- package/src/VitePlugin.ts +36 -46
- package/src/config/vite.base.config.ts +97 -0
- package/src/config/vite.main.config.ts +33 -0
- package/src/config/vite.preload.config.ts +28 -0
- package/src/config/vite.renderer.config.ts +25 -0
- package/src/util/plugins.ts +0 -1
- package/dist/util/package.d.ts +0 -14
- package/dist/util/package.d.ts.map +0 -1
- package/dist/util/package.js +0 -93
- package/src/util/package.ts +0 -108
package/src/util/package.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
|
|
5
|
-
export interface Dependency {
|
|
6
|
-
name: string;
|
|
7
|
-
path: SourceAndDestination;
|
|
8
|
-
dependencies: Dependency[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface SourceAndDestination {
|
|
12
|
-
src: string;
|
|
13
|
-
dest: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function isRootPath(dir: string) {
|
|
17
|
-
// *unix or Windows root path
|
|
18
|
-
return dir === '/' || /^[a-zA-Z]:\\$/i.test(dir);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function isDirectory(p: string): Promise<boolean> {
|
|
22
|
-
try {
|
|
23
|
-
const stat = await fs.promises.stat(p);
|
|
24
|
-
return stat.isDirectory();
|
|
25
|
-
} catch {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function lookupNodeModulesPaths(root: string, paths: string[] = []): Promise<string[]> {
|
|
31
|
-
if (!root) return paths;
|
|
32
|
-
if (!path.isAbsolute(root)) return paths;
|
|
33
|
-
|
|
34
|
-
const p = path.join(root, 'node_modules');
|
|
35
|
-
|
|
36
|
-
if (await isDirectory(p)) {
|
|
37
|
-
paths = paths.concat(p);
|
|
38
|
-
}
|
|
39
|
-
root = path.join(root, '..');
|
|
40
|
-
|
|
41
|
-
return isRootPath(root) ? paths : await lookupNodeModulesPaths(root, paths);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function resolveDependencies(root: string) {
|
|
45
|
-
const rootDependencies = Object.keys((await fs.readJson(path.join(root, 'package.json'))).dependencies || {});
|
|
46
|
-
const resolve = async (prePath: string, dependencies: string[], collected: Map<string, Dependency> = new Map()) =>
|
|
47
|
-
await Promise.all(
|
|
48
|
-
dependencies.map(async (name) => {
|
|
49
|
-
let curPath = prePath,
|
|
50
|
-
depPath = null,
|
|
51
|
-
packageJson = null;
|
|
52
|
-
while (!packageJson && !isRootPath(curPath)) {
|
|
53
|
-
const allNodeModules = await lookupNodeModulesPaths(curPath);
|
|
54
|
-
|
|
55
|
-
for (const nodeModules of allNodeModules) {
|
|
56
|
-
depPath = path.join(nodeModules, name);
|
|
57
|
-
if (await fs.pathExists(depPath)) break;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (depPath) {
|
|
61
|
-
try {
|
|
62
|
-
packageJson = await fs.readJson(path.join(depPath, 'package.json'));
|
|
63
|
-
} catch (err) {
|
|
64
|
-
// lookup node_modules
|
|
65
|
-
curPath = path.join(curPath, '..');
|
|
66
|
-
if (curPath.length < root.length) {
|
|
67
|
-
console.error(`not found 'node_modules' in root path: ${root}`);
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!depPath || !packageJson) {
|
|
75
|
-
throw new Error(`find dependencies error in: ${curPath}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const result: Dependency = {
|
|
79
|
-
name,
|
|
80
|
-
path: {
|
|
81
|
-
src: depPath,
|
|
82
|
-
dest: path.relative(root, depPath),
|
|
83
|
-
},
|
|
84
|
-
dependencies: [],
|
|
85
|
-
};
|
|
86
|
-
const shouldResolveDeps = !collected.has(depPath);
|
|
87
|
-
collected.set(depPath, result);
|
|
88
|
-
if (shouldResolveDeps) {
|
|
89
|
-
result.dependencies = await resolve(depPath, Object.keys(packageJson.dependencies || {}), collected);
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
return resolve(root, rootDependencies);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export async function getFlatDependencies(root = process.cwd()) {
|
|
98
|
-
const depsTree = await resolveDependencies(root);
|
|
99
|
-
const depsFlat = new Map<string, SourceAndDestination>();
|
|
100
|
-
|
|
101
|
-
const flatten = (dep: Dependency) => {
|
|
102
|
-
depsFlat.set(dep.path.src, dep.path); // dedup
|
|
103
|
-
dep.dependencies.forEach(flatten);
|
|
104
|
-
};
|
|
105
|
-
depsTree.forEach(flatten);
|
|
106
|
-
|
|
107
|
-
return [...depsFlat.values()];
|
|
108
|
-
}
|