Skip to content

Commit 81b914b

Browse files
authored
Merge pull request #573 from framer/always-use-forward-slash
Replace \ with / in file names when packing
2 parents f122cf2 + 15b265c commit 81b914b

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

packages/plugin-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "framer-plugin-tools",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "CLI Tools for Framer Plugins",
55
"type": "module",
66
"main": "dist/index.js",

packages/plugin-tools/src/lib.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os from "node:os"
33
import path from "node:path"
44
import AdmZip from "adm-zip"
55
import { afterEach, beforeEach, describe, expect, it } from "vitest"
6-
import { detectPackageManager, zipPluginDistribution } from "./lib"
6+
import { detectPackageManager, normalizeZipEntryPaths, zipPluginDistribution } from "./lib"
77

88
describe("detectPackageManager", () => {
99
let tmpDir: string
@@ -203,6 +203,17 @@ describe("zipPluginDistribution", () => {
203203
expect(entries).toContain("assets/images/logo.png")
204204
})
205205

206+
it("normalizes backslash entry names to use forward slashes", () => {
207+
const zip = new AdmZip()
208+
zip.addFile("nested\\dir\\file.txt", Buffer.from("content", "utf-8"))
209+
210+
normalizeZipEntryPaths(zip)
211+
212+
const entries = zip.getEntries().map(e => e.entryName)
213+
expect(entries).toContain("nested/dir/file.txt")
214+
expect(entries).not.toContain("nested\\dir\\file.txt")
215+
})
216+
206217
it("returns correct zipPath", () => {
207218
const distDir = path.join(tmpDir, "dist")
208219
fs.mkdirSync(distDir)

packages/plugin-tools/src/lib.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ interface ZipPluginDistributionOptions {
3535
zipFileName: string
3636
}
3737

38+
// Normalize all entry paths to use forward slashes
39+
export function normalizeZipEntryPaths(zip: AdmZip): void {
40+
for (const entry of zip.getEntries()) {
41+
if (entry.entryName.includes("\\")) {
42+
entry.entryName = entry.entryName.replace(/\\/g, "/")
43+
}
44+
}
45+
}
46+
3847
export function zipPluginDistribution(options: ZipPluginDistributionOptions): string {
3948
const distPath = path.isAbsolute(options.distPath) ? options.distPath : path.join(options.cwd, options.distPath)
4049

@@ -54,6 +63,7 @@ export function zipPluginDistribution(options: ZipPluginDistributionOptions): st
5463
zip.addLocalFolder(distPath)
5564
zip.deleteFile(markerFileName)
5665
zip.addFile(markerFileName, Buffer.from("true", "utf-8"))
66+
normalizeZipEntryPaths(zip)
5767
zip.writeZip(zipFilePath)
5868

5969
return zipFilePath

0 commit comments

Comments
 (0)