Skip to content

Commit 3b13790

Browse files
committed
fix: zip
1 parent d573c49 commit 3b13790

5 files changed

Lines changed: 50 additions & 24 deletions

File tree

.github/workflows/dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
run: |
8383
npx puppeteer browsers install
8484
php -S 0.0.0.0:8899 -t $GITHUB_WORKSPACE/tests/simple-server &
85-
sleep 5
85+
sleep 3
8686
npm run test:e2e
8787
- name: Publish snapshot
8888
env:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"axios": "^1.7.2",
5858
"cpr": "^3.0.1",
5959
"cross-env": "^7.0.3",
60-
"cross-zip": "^4.0.1",
6160
"crx": "^5.0.1",
6261
"fs-extra": "^11.1.1",
6362
"get-port": "^7.1.0",

pnpm-lock.yaml

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/pack.mjs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import crx from './pack-utils/crx.mjs';
2929
import cws from './pack-utils/cws.mjs';
3030
import edge from './pack-utils/edge.mjs';
3131
import xpi from './pack-utils/xpi.mjs';
32+
import { createZip } from './zip.mjs';
3233

3334
const packUtils = {
3435
amo,
@@ -59,19 +60,6 @@ function copyDir(source, target) {
5960
});
6061
}
6162

62-
function createZip(source, target) {
63-
return new Promise((resolve, reject) => {
64-
zip(source, target, err => {
65-
console.log(`zip ${source} -> ${target}`, err);
66-
if (err) {
67-
reject(err);
68-
} else {
69-
resolve();
70-
}
71-
});
72-
});
73-
}
74-
7563
async function packOnePlatform(name, browserConfig, itemConfig) {
7664
if (typeof packUtils[name] === 'undefined') {
7765
console.error(`pack-utils for ${name} not found`);
@@ -95,6 +83,7 @@ async function packOnePlatform(name, browserConfig, itemConfig) {
9583
}),
9684
);
9785
// 打包成zip
86+
console.log(`zip ${source} -> ${target}`);
9887
await createZip(thisPack, zipPath);
9988
// 执行上传等操作
10089
console.log(`running ${name} pack...`);

scripts/zip.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { execFile } from 'child_process';
2+
import fs from 'fs/promises';
3+
import os from 'os';
4+
import path from 'path';
5+
6+
function quotePath(p) {
7+
return '"' + p + '"';
8+
}
9+
10+
function exec(command, args, options) {
11+
return new Promise((resolve, reject) => {
12+
execFile(command, args, options, err => {
13+
if (err) {
14+
reject(err);
15+
} else {
16+
resolve();
17+
}
18+
});
19+
});
20+
}
21+
22+
export async function createZip(inPath, outPath) {
23+
if (process.platform === 'win32') {
24+
await fs.rm(outPath, { recursive: true, maxRetries: 3 });
25+
return exec(
26+
'powershell.exe',
27+
[
28+
'-nologo',
29+
'-noprofile',
30+
'-command',
31+
'& { param([String]$myInPath, [String]$myOutPath); Add-Type -A "System.IO.Compression.FileSystem"; [IO.Compression.ZipFile]::CreateFromDirectory($myInPath, $myOutPath); exit !$? }',
32+
'-myInPath',
33+
quotePath(inPath),
34+
'-myOutPath',
35+
quotePath(outPath),
36+
],
37+
{
38+
cwd: path.dirname(inPath),
39+
maxBuffer: Infinity,
40+
},
41+
);
42+
}
43+
return exec('zip', ['-r', '-y', outPath, '.'], {
44+
cwd: inPath,
45+
maxBuffer: Infinity,
46+
});
47+
}

0 commit comments

Comments
 (0)