1212import { execSync } from "node:child_process" ;
1313import fs from "node:fs" ;
1414import path from "node:path" ;
15- import { createReadStream , createWriteStream } from "node:fs" ;
16- import { pipeline } from "node:stream/promises" ;
1715
1816const __dirname = path . dirname ( new URL ( import . meta. url ) . pathname . replace ( / ^ \/ ( [ A - Z a - z ] : ) / , "$1" ) ) ;
1917const root = path . resolve ( __dirname , ".." ) ;
@@ -37,26 +35,50 @@ const zipPath = path.join(outDir, zipName);
3735/* ── remove stale zip ─────────────────────────────────────── */
3836if ( fs . existsSync ( zipPath ) ) fs . rmSync ( zipPath ) ;
3937
38+ /* ── directories to exclude from the extension package ───── */
39+ const EXCLUDE_DIRS = new Set ( [ ".vite" ] ) ;
40+
41+ /* ── recursive copy, skipping excluded dirs ───────────────── */
42+ function copyRecursive ( src , dest ) {
43+ fs . mkdirSync ( dest , { recursive : true } ) ;
44+ for ( const entry of fs . readdirSync ( src , { withFileTypes : true } ) ) {
45+ if ( EXCLUDE_DIRS . has ( entry . name ) ) continue ;
46+ const srcPath = path . join ( src , entry . name ) ;
47+ const destPath = path . join ( dest , entry . name ) ;
48+ if ( entry . isDirectory ( ) ) {
49+ copyRecursive ( srcPath , destPath ) ;
50+ } else {
51+ fs . copyFileSync ( srcPath , destPath ) ;
52+ }
53+ }
54+ }
55+
4056/* ── zip using platform tools ─────────────────────────────── */
4157const isWindows = process . platform === "win32" ;
58+ // Stage into a temp dir so we can exclude .vite without platform-specific
59+ // exclude flags (PowerShell Compress-Archive has no --exclude option).
60+ const stageDir = path . join ( root , ".tmp-zip-stage" ) ;
61+ if ( fs . existsSync ( stageDir ) ) fs . rmSync ( stageDir , { recursive : true } ) ;
4262
4363try {
64+ copyRecursive ( distDir , stageDir ) ;
65+
4466 if ( isWindows ) {
45- // PowerShell 5+ Compress-Archive (available on all modern Windows)
46- const distEscaped = distDir . replace ( / ' / g, "''" ) ;
67+ const stageEscaped = stageDir . replace ( / ' / g, "''" ) ;
4768 const zipEscaped = zipPath . replace ( / ' / g, "''" ) ;
4869 execSync (
49- `powershell -NoProfile -Command "Compress-Archive -Path '${ distEscaped } \\*' -DestinationPath '${ zipEscaped } ' -Force"` ,
70+ `powershell -NoProfile -Command "Compress-Archive -Path '${ stageEscaped } \\*' -DestinationPath '${ zipEscaped } ' -Force"` ,
5071 { stdio : "inherit" }
5172 ) ;
5273 } else {
53- // Unix: zip -r
54- execSync ( `zip -r "${ zipPath } " .` , { cwd : distDir , stdio : "inherit" } ) ;
74+ execSync ( `zip -r "${ zipPath } " .` , { cwd : stageDir , stdio : "inherit" } ) ;
5575 }
5676
5777 console . log ( `\nPackaged: dist-zip/${ zipName } ` ) ;
58- console . log ( `Upload this file at: https://chrome.google .com/webstore/developer/dashboard \n` ) ;
78+ console . log ( `Upload at: https://partner.microsoft .com/dashboard/microsoftedge/public/login?ref=dd \n` ) ;
5979} catch ( err ) {
6080 console . error ( "Packaging failed:" , err . message ) ;
6181 process . exit ( 1 ) ;
82+ } finally {
83+ if ( fs . existsSync ( stageDir ) ) fs . rmSync ( stageDir , { recursive : true } ) ;
6284}
0 commit comments