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
5 changes: 5 additions & 0 deletions .changeset/fix-dev-preserves-pre-marker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zile": patch
---

Fixed `zile dev` stripping pre-marker keys (scripts, devDependencies, etc.) from `package.json`
5 changes: 5 additions & 0 deletions .changeset/fix-publish-prepare-strip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zile": patch
---

Fixed `publish:prepare` to strip pre-marker keys from package.json
13 changes: 11 additions & 2 deletions src/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,19 @@ export async function writePackageJson(cwd: string, pkgJson: PackageJson) {
const indent = content ? detectIndent(content) : ' '
const hasTrailingNewline = content ? content.endsWith('\n') : true

// Merge decorated fields back into original package.json to preserve all fields
// Merge decorated fields back into original package.json to preserve all fields.
// Keep pre-marker keys (scripts, devDependencies, etc.) intact — they are only
// stripped when *reading* for build purposes, not when writing back.
const merged = (() => {
if (!content) return pkgJson
return { ...stripPreMarkerKeys(JSON.parse(content)), ...pkgJson }
const original = JSON.parse(content)
const keys = Object.keys(original)
const markerIndex = keys.indexOf('[!start-pkg]')
if (markerIndex === -1) return { ...original, ...pkgJson }
// Preserve everything up to and including the marker, then overlay decorated fields
const preMarker: Record<string, unknown> = {}
for (const key of keys.slice(0, markerIndex + 1)) preMarker[key] = original[key]
return { ...preMarker, ...pkgJson }
})()

let output = JSON.stringify(merged, null, indent)
Expand Down
7 changes: 7 additions & 0 deletions src/internal/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export async function preparePublish(command: Command) {
// Build the package (readPackageJson strips pre-marker keys automatically)
await Package.build({ cwd })

// Strip pre-marker keys from the written package.json so the published
// package only contains the publishable fields.
const builtContent = fs.readFileSync(packageJsonPath, 'utf-8')
const builtPkg = JSON.parse(builtContent)
const stripped = Package.stripPreMarkerKeys(builtPkg)
fs.writeFileSync(packageJsonPath, `${JSON.stringify(stripped, null, 2)}\n`, 'utf-8')

console.log(`✔︎ Package at ${cwd} prepared successfully`)
})
}
Expand Down
Loading