vite-plugin-zip-file 4.0.0 → 4.1.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/README.md CHANGED
@@ -20,6 +20,12 @@ or
20
20
  npm install vite-plugin-zip-file --save-dev
21
21
  ```
22
22
 
23
+ or
24
+
25
+ ```
26
+ pnpm add vite-plugin-zip-file -D
27
+ ```
28
+
23
29
  # Options
24
30
 
25
31
 
@@ -34,7 +40,7 @@ npm install vite-plugin-zip-file --save-dev
34
40
 
35
41
  <br />
36
42
 
37
- # Options(中文)
43
+ # 选项
38
44
 
39
45
  <table>
40
46
  <thead>
@@ -110,7 +116,7 @@ export default defineConfig({
110
116
  viteZip({
111
117
  folderPath: path.resolve(__dirname, 'dist'),
112
118
  outPath: path.resolve(__dirname),
113
- zipName: 'Test.zip',
119
+ zipName: 'dist.zip',
114
120
  enabled: env.NODE_ENV === 'production'? true: false
115
121
  })
116
122
  ]
package/lib/index.cjs CHANGED
@@ -1 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("path"),n=require("fs"),z=require("node:module");var f=typeof document<"u"?document.currentScript:null;const E=z.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:f&&f.tagName.toUpperCase()==="SCRIPT"&&f.src||new URL("index.cjs",document.baseURI).href),o=i.sep,{cwd:v}=process,R={enabled:!0,folderPath:i.join(v(),"/dist"),outPath:i.resolve(v()),zipName:"",deleteFolder:!1,withoutMainFolder:!1},C=g=>{let F={...R,...g},{enabled:u,folderPath:s,outPath:d,zipName:r,deleteFolder:w,withoutMainFolder:b}=F;if(u=!!u,!s||!d)throw new Error("config.folderPath and config.outPath is required.");s=i.resolve(s),d=i.resolve(d),r=r||s.split(o).pop()+".zip";const j=()=>{const q=E("jszip"),p=new q,y=function(e,t,c="",l=0){const Z=n.readdirSync(t);b?l!==0&&(c+=t.split(o).pop()+o):c+=t.split(o).pop()+o,Z.forEach(h=>{const a=i.join(t,o,h);n.statSync(a).isDirectory()?y(e,a,c,l+1):e.file(c+h,n.readFileSync(a))})},m=(e=r)=>{const t=i.join(d,o+e);n.existsSync(t)&&n.unlinkSync(t)},S=e=>{n.readdirSync(e).forEach(c=>{const l=e+o+c;n.statSync(l).isDirectory()?S(l):n.unlinkSync(l)}),n.rmdirSync(e)},P=function(){y(p,s,"",0),p.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(e=>{m(r),n.writeFileSync(i.join(d,o,r),e),w&&S(s)})};m(r),P()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){u&&j()}}};exports.viteZip=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("path"),n=require("fs"),Z=require("node:module");var y=typeof document<"u"?document.currentScript:null;const E=Z.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:y&&y.tagName.toUpperCase()==="SCRIPT"&&y.src||new URL("index.cjs",document.baseURI).href),r=c.sep,{cwd:w}=process,C={enabled:!0,folderPath:c.join(w(),"/dist"),outPath:c.resolve(w()),zipName:"",deleteFolder:!1,withoutMainFolder:!1};let a={};const N=z=>{let F={...C,...z},{enabled:d,folderPath:l,outPath:p,zipName:s,deleteFolder:P,withoutMainFolder:b}=F;if(d=!!d,!l||!p)throw new Error("config.folderPath and config.outPath is required.");l=c.resolve(l),p=c.resolve(p),s=s||l.split(r).pop()+".zip";const j=()=>{const i=E("jszip"),m=new i,g=function(e,o,t="",f=0){const R=n.readdirSync(o);b?f!==0&&(t+=o.split(r).pop()+r):t+=o.split(r).pop()+r,R.forEach(v=>{const u=c.join(o,r,v);n.statSync(u).isDirectory()?g(e,u,t,f+1):e.file(t+v,n.readFileSync(u))})},S=(e=s)=>{const o=c.join(p,r+e);n.existsSync(o)&&n.unlinkSync(o)},h=e=>{n.readdirSync(e).forEach(t=>{const f=e+r+t;n.statSync(f).isDirectory()?h(f):n.unlinkSync(f)}),n.rmdirSync(e)},q=async()=>new Promise((e,o)=>{g(m,l,"",0),m.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(t=>{S(s),n.writeFileSync(c.join(p,r,s),t),P&&h(l),e(s)}).catch(t=>{o(t)})});return S(s),q()};return{name:"vite-plugin-zip-file",apply:"build",enforce:"post",configResolved(i){a=i.logger},async closeBundle(){try{if(!d)return;const i=await j();a.info(`
2
+ ✨ [vite-plugin-zip-file] - zip floder successfully: ${i}
3
+ `)}catch(i){a.error(typeof i=="string"?i:JSON.stringify(i)),a.error(`
4
+ ❌ [vite-plugin-zip-file] - zip floder failed.
5
+ `)}}}};exports.viteZip=N;
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { PluginOption } from 'vite';
2
+ interface ViteZipConfig {
3
+ enabled?: boolean;
4
+ folderPath: string;
5
+ outPath: string;
6
+ zipName?: string;
7
+ deleteFolder?: boolean;
8
+ withoutMainFolder?: boolean;
9
+ }
10
+ export declare const viteZip: (customConfig: ViteZipConfig) => PluginOption;
11
+ export {};
package/lib/index.mjs CHANGED
@@ -1,38 +1,40 @@
1
- import i from "path";
2
- import o from "fs";
3
- import { createRequire as Z } from "node:module";
4
- const b = Z(import.meta.url), t = i.sep, { cwd: h } = process, k = {
1
+ import l from "path";
2
+ import t from "fs";
3
+ import { createRequire as b } from "node:module";
4
+ const k = b(import.meta.url), r = l.sep, { cwd: v } = process, q = {
5
5
  enabled: !0,
6
- folderPath: i.join(h(), "/dist"),
7
- outPath: i.resolve(h()),
6
+ folderPath: l.join(v(), "/dist"),
7
+ outPath: l.resolve(v()),
8
8
  zipName: "",
9
9
  deleteFolder: !1,
10
10
  withoutMainFolder: !1
11
- }, M = (v) => {
12
- let F = {
13
- ...k,
14
- ...v
15
- }, { enabled: f, folderPath: r, outPath: p, zipName: s, deleteFolder: w, withoutMainFolder: g } = F;
16
- if (f = !!f, !r || !p)
11
+ };
12
+ let a = {};
13
+ const J = (z) => {
14
+ let w = {
15
+ ...q,
16
+ ...z
17
+ }, { enabled: d, folderPath: c, outPath: p, zipName: s, deleteFolder: F, withoutMainFolder: P } = w;
18
+ if (d = !!d, !c || !p)
17
19
  throw new Error("config.folderPath and config.outPath is required.");
18
- r = i.resolve(r), p = i.resolve(p), s = s || r.split(t).pop() + ".zip";
20
+ c = l.resolve(c), p = l.resolve(p), s = s || c.split(r).pop() + ".zip";
19
21
  const j = () => {
20
- const z = b("jszip"), d = new z(), u = function(e, n, c = "", l = 0) {
21
- const P = o.readdirSync(n);
22
- g ? l !== 0 && (c += n.split(t).pop() + t) : c += n.split(t).pop() + t, P.forEach((S) => {
23
- const a = i.join(n, t, S);
24
- o.statSync(a).isDirectory() ? u(e, a, c, l + 1) : e.file(c + S, o.readFileSync(a));
22
+ const n = k("jszip"), y = new n(), m = function(e, o, i = "", f = 0) {
23
+ const Z = t.readdirSync(o);
24
+ P ? f !== 0 && (i += o.split(r).pop() + r) : i += o.split(r).pop() + r, Z.forEach((h) => {
25
+ const u = l.join(o, r, h);
26
+ t.statSync(u).isDirectory() ? m(e, u, i, f + 1) : e.file(i + h, t.readFileSync(u));
25
27
  });
26
- }, m = (e = s) => {
27
- const n = i.join(p, t + e);
28
- o.existsSync(n) && o.unlinkSync(n);
29
- }, y = (e) => {
30
- o.readdirSync(e).forEach((c) => {
31
- const l = e + t + c;
32
- o.statSync(l).isDirectory() ? y(l) : o.unlinkSync(l);
33
- }), o.rmdirSync(e);
34
- }, E = function() {
35
- u(d, r, "", 0), d.generateAsync({
28
+ }, g = (e = s) => {
29
+ const o = l.join(p, r + e);
30
+ t.existsSync(o) && t.unlinkSync(o);
31
+ }, S = (e) => {
32
+ t.readdirSync(e).forEach((i) => {
33
+ const f = e + r + i;
34
+ t.statSync(f).isDirectory() ? S(f) : t.unlinkSync(f);
35
+ }), t.rmdirSync(e);
36
+ }, E = async () => new Promise((e, o) => {
37
+ m(y, c, "", 0), y.generateAsync({
36
38
  type: "nodebuffer",
37
39
  // 压缩类型
38
40
  compression: "DEFLATE",
@@ -41,20 +43,37 @@ const b = Z(import.meta.url), t = i.sep, { cwd: h } = process, k = {
41
43
  // 压缩级别
42
44
  level: 9
43
45
  }
44
- }).then((e) => {
45
- m(s), o.writeFileSync(i.join(p, t, s), e), w && y(r);
46
+ }).then((i) => {
47
+ g(s), t.writeFileSync(l.join(p, r, s), i), F && S(c), e(s);
48
+ }).catch((i) => {
49
+ o(i);
46
50
  });
47
- };
48
- m(s), E();
51
+ });
52
+ return g(s), E();
49
53
  };
50
54
  return {
51
55
  name: "vite-plugin-zip-file",
52
56
  apply: "build",
53
- closeBundle() {
54
- f && j();
57
+ enforce: "post",
58
+ configResolved(n) {
59
+ a = n.logger;
60
+ },
61
+ async closeBundle() {
62
+ try {
63
+ if (!d)
64
+ return;
65
+ const n = await j();
66
+ a.info(`
67
+ ✨ [vite-plugin-zip-file] - zip floder successfully: ${n}
68
+ `);
69
+ } catch (n) {
70
+ a.error(typeof n == "string" ? n : JSON.stringify(n)), a.error(`
71
+ ❌ [vite-plugin-zip-file] - zip floder failed.
72
+ `);
73
+ }
55
74
  }
56
75
  };
57
76
  };
58
77
  export {
59
- M as viteZip
78
+ J as viteZip
60
79
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-zip-file",
3
- "version": "4.0.0",
4
- "description": "zip files at build time.",
3
+ "version": "4.1.1",
4
+ "description": "Zip files at build time.",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "files": [
@@ -11,11 +11,20 @@
11
11
  "README.md"
12
12
  ],
13
13
  "module": "lib/index.mjs",
14
+ "types": "lib/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/index.d.ts",
18
+ "import": "./lib/index.mjs",
19
+ "require": "./lib/index.cjs"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
14
23
  "scripts": {
15
24
  "dev": "vite",
16
25
  "build": "vite build",
17
26
  "build-d": "node --inspect-brk=9229 ./node_modules/vite/dist/node/cli.js build",
18
- "build-plugin": "vite --config plugin.config.js build"
27
+ "build-plugin": "vite --config plugin.config.ts build && tsc"
19
28
  },
20
29
  "repository": {
21
30
  "type": "git",
@@ -33,11 +42,13 @@
33
42
  },
34
43
  "homepage": "https://github.com/Ssis53/vite-plugin-zip#readme",
35
44
  "dependencies": {
36
- "jszip": "^3.10.1"
45
+ "jszip": "3.10.1"
37
46
  },
38
47
  "devDependencies": {
39
- "vite": "^6.2.0",
40
- "@rollup/plugin-node-resolve": "^15.2.0"
48
+ "@rollup/plugin-node-resolve": "^15.2.0",
49
+ "@types/node": "^22.13.15",
50
+ "typescript": "^5.8.2",
51
+ "vite": "^6.2.0"
41
52
  },
42
53
  "peerDependencies": {
43
54
  "vite": ">=2.0.0"