Skip to content

npm package 0.2.33 was packed with CRLF line endings; enforce LF packaging #9

Closed

Description

@fadymondy

Problem

The npm tarball for @togo-framework/cli@0.2.33 has CRLF line endings in bin/togo.js and install.js. Earlier versions (0.2.29–0.2.31) were LF. The repository index is LF, so this is a packaging artifact, not a source change.

Reproduction

d=$(mktemp -d) && cd "$d"
for v in 0.2.31 0.2.33; do
  npm pack @togo-framework/cli@$v --silent >/dev/null
  mkdir $v && tar -xzf togo-framework-cli-$v.tgz -C $v
  for f in bin/togo.js install.js package.json; do
    printf '%s %-14s CR bytes: %s\n' $v $f "$(tr -cd '\r' < $v/package/$f | wc -c)"
  done
done
# 0.2.31: 0 / 0 / 0
# 0.2.33: bin/togo.js 13, install.js 65, package.json 0

(Count with tr -cd '\r' | wc -c. In Git Bash, grep -c $'\r' miscounts.)

Cause

0.2.33 was packed with npm pack/npm publish from a Windows checkout where Git's system config sets core.autocrlf=true (Git for Windows default, in C:/Program Files/Git/etc/gitconfig). The repo has no .gitattributes, so text files under npm/ were checked out as CRLF (git ls-files --eol npm/ shows i/lf w/crlf) and npm packed them as-is. package.json stayed LF because npm rewrites it. The release workflow builds only goreleaser assets; the npm publish is a manual step.

Why 0.2.33 still works

  • bin/togo.js: on install, npm (bin-links) rewrites a CRLF shebang to LF in the installed bin, so #!/usr/bin/env node\r never reaches the kernel. Verified: the installed file's first line ends in \n, and togo version runs after a clean npm i -g on Debian (node:24-bookworm-slim), Alpine (node:24-alpine) and Windows 11.
  • install.js runs as node install.js (the postinstall script), and Node accepts CRLF source.

It still needs fixing: the result depends on npm's shebang fix-up, npx/other package managers, or direct execution of the file from the tarball, may not apply it. Builds also differ from LF releases depending on who packs them.

Recommendation

  1. Enforce LF in the repo: add .gitattributes with * text=auto eol=lf (or at least npm/** text eol=lf), so every checkout of npm/ is LF whatever core.autocrlf says.
  2. Pack and publish from Linux: preferably publish npm in the tag-triggered release workflow after goreleaser (ubuntu-latest, provenance, version taken from the tag), instead of from a developer machine.
  3. Guard: a CI step that runs npm pack and fails if any packed file contains \r.

These are complementary: (1) fixes local checkouts, (2) removes the developer-machine dependency, and (3) catches regressions either way.

Acceptance criteria

  • A fresh checkout on Windows with core.autocrlf=true produces LF files under npm/ (git ls-files --eol npm/ shows w/lf).
  • npm pack from that checkout produces a tarball with 0 CR bytes in every file.
  • CI fails if the packed tarball contains CR bytes, and passes on LF (shown with a deliberately CRLF file).
  • The next npm release (0.2.34+) is verified with the reproduction above: 0 CR bytes.
  • If npm publishing moves to CI: the release docs/workflow describe the publish step, its token/provenance, and who approves it.
  • 0.2.33 is not republished (npm doesn't allow it). This issue only changes the next release.

Out of scope: #4, #5, #6.

Activity

  1. added
    bug
    on Oct 8, 2026
  2. fadymondy commented on Oct 14, 2026

    @fadymondy
    ContributorAuthor

    Fixed in #19, released in v0.2.37.

    • .gitattributes (* text=auto eol=lf) makes npm/ LF on every checkout regardless of core.autocrlf (item 1).
    • npm/pack.test.js packs the package, extracts the tarball and fails on any CR byte; it runs in the npm CI job on ubuntu and windows (item 3). Confirmed it fails with a CRLF bin/togo.js and passes with LF.

    Not done: moving npm publish into the tag workflow (item 2). It needs an npm token and a provenance/approval decision, so publishing remains a maintainer step. Nothing was published to npm from here, so @togo-framework/cli@0.2.37 still needs publishing (from a Linux or LF checkout). Once it is out, run the reproduction above against 0.2.37 to tick the last acceptance item; reopen this issue if any CR bytes show up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions