diff --git a/packages/plugin-tools/package.json b/packages/plugin-tools/package.json index 1bc02c785..1566eb49d 100644 --- a/packages/plugin-tools/package.json +++ b/packages/plugin-tools/package.json @@ -1,6 +1,6 @@ { "name": "framer-plugin-tools", - "version": "1.2.0", + "version": "1.2.1", "description": "CLI Tools for Framer Plugins", "type": "module", "main": "dist/index.js", diff --git a/packages/plugin-tools/src/lib.test.ts b/packages/plugin-tools/src/lib.test.ts index 8caccb1ec..19d636742 100644 --- a/packages/plugin-tools/src/lib.test.ts +++ b/packages/plugin-tools/src/lib.test.ts @@ -3,7 +3,7 @@ import os from "node:os" import path from "node:path" import AdmZip from "adm-zip" import { afterEach, beforeEach, describe, expect, it } from "vitest" -import { detectPackageManager, zipPluginDistribution } from "./lib" +import { detectPackageManager, normalizeZipEntryPaths, zipPluginDistribution } from "./lib" describe("detectPackageManager", () => { let tmpDir: string @@ -203,6 +203,17 @@ describe("zipPluginDistribution", () => { expect(entries).toContain("assets/images/logo.png") }) + it("normalizes backslash entry names to use forward slashes", () => { + const zip = new AdmZip() + zip.addFile("nested\\dir\\file.txt", Buffer.from("content", "utf-8")) + + normalizeZipEntryPaths(zip) + + const entries = zip.getEntries().map(e => e.entryName) + expect(entries).toContain("nested/dir/file.txt") + expect(entries).not.toContain("nested\\dir\\file.txt") + }) + it("returns correct zipPath", () => { const distDir = path.join(tmpDir, "dist") fs.mkdirSync(distDir) diff --git a/packages/plugin-tools/src/lib.ts b/packages/plugin-tools/src/lib.ts index 80f0b6509..55be965bd 100644 --- a/packages/plugin-tools/src/lib.ts +++ b/packages/plugin-tools/src/lib.ts @@ -35,6 +35,15 @@ interface ZipPluginDistributionOptions { zipFileName: string } +// Normalize all entry paths to use forward slashes +export function normalizeZipEntryPaths(zip: AdmZip): void { + for (const entry of zip.getEntries()) { + if (entry.entryName.includes("\\")) { + entry.entryName = entry.entryName.replace(/\\/g, "/") + } + } +} + export function zipPluginDistribution(options: ZipPluginDistributionOptions): string { const distPath = path.isAbsolute(options.distPath) ? options.distPath : path.join(options.cwd, options.distPath) @@ -54,6 +63,7 @@ export function zipPluginDistribution(options: ZipPluginDistributionOptions): st zip.addLocalFolder(distPath) zip.deleteFile(markerFileName) zip.addFile(markerFileName, Buffer.from("true", "utf-8")) + normalizeZipEntryPaths(zip) zip.writeZip(zipFilePath) return zipFilePath