Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/cli/pack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { confirm } from "@inquirer/prompts";
import { createHash } from "crypto";
import type { Zippable } from "fflate";
import { zipSync } from "fflate";
import {
existsSync,
Expand Down Expand Up @@ -140,8 +141,9 @@ export async function packExtension({
>();
const shallowFiles: Array<{ path: string; size: number }> = [];

for (const [filePath, content] of fileEntries) {
for (const [filePath, fileData] of fileEntries) {
const relPath = relative(resolvedPath, filePath);
const content = fileData.data;
const size =
typeof content === "string"
? Buffer.byteLength(content, "utf8")
Expand Down Expand Up @@ -184,8 +186,26 @@ export async function packExtension({
}
}

// Create zip
const zipData = zipSync(files, {
// Create zip with preserved file permissions
const zipFiles: Zippable = {};

const isUnix = process.platform !== "win32";

for (const [filePath, fileData] of Object.entries(files)) {
if (isUnix) {
// Set external file attributes to preserve Unix permissions
// The mode needs to be shifted to the upper 16 bits for ZIP format
zipFiles[filePath] = [
fileData.data,
{ os: 3, attrs: (fileData.mode & 0o777) << 16 },
];
} else {
// On Windows, use default ZIP attributes (no Unix permissions)
zipFiles[filePath] = fileData.data;
}
}

const zipData = zipSync(zipFiles, {
level: 9, // Maximum compression
mtime: new Date(),
});
Expand Down
13 changes: 10 additions & 3 deletions src/node/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,19 @@ export function getAllFiles(
return fileList;
}

interface FileWithPermissions {
data: Uint8Array;
mode: number;
}
export interface GetAllFilesResult {
files: Record<string, Uint8Array>;
files: Record<string, FileWithPermissions>;
ignoredCount: number;
}

export function getAllFilesWithCount(
dirPath: string,
baseDir: string = dirPath,
fileList: Record<string, Uint8Array> = {},
fileList: Record<string, FileWithPermissions> = {},
additionalPatterns: string[] = [],
ignoredCount = 0,
): GetAllFilesResult {
Expand Down Expand Up @@ -183,7 +187,10 @@ export function getAllFilesWithCount(
} else {
// Use forward slashes in zip file paths
const zipPath = relativePath.split(sep).join("/");
fileList[zipPath] = readFileSync(filePath);
fileList[zipPath] = {
data: readFileSync(filePath),
mode: stat.mode,
};
}
}

Expand Down