Skip to content

new-package command fails on "Adding preview folder" #326

Open
@pete-murphy

Description

@pete-murphy
~/Code/elm
❯  elm-review new-package
✔ Your GitHub username: … pete-murphy
✔ The package name (starting with "elm-review-"): … elm-review-elm-css-migration
✔ The license for your package: … MIT
✔ Name of the rule (ex: No.Doing.Foo): … ElmCssMigration
✔ Choose the type of rule you want to start with: › Project rule
✔ Adding elm.json
✔ Adding package.json
✔ Adding elm-tooling.json
✔ Adding README
✖ Adding preview folder
-- UNEXPECTED ERROR ------------------------------------------------------------

I ran into an unexpected error. Please open an issue at the following link:
  https://github.com/jfmengels/node-elm-review/issues/new

Please include this error message and as much detail as you can provide. If you
can, please provide a setup that makes it easy to reproduce the error. That will
make it much easier to fix the issue.

Below is the error that was encountered.
--------------------------------------------------------------------------------
Error: EACCES: permission denied, open '/Users/pete/Code/elm/elm-review-elm-css-migration/preview/src/ReviewConfig.elm'
    at Object.writeFileSync (node:fs:2367:20)
    at createProject (/nix/store/mb9n2clplvhm81mlrkyjc1yn7jxsfiyb-elm-review-2.12.0/lib/node_modules/elm-review/lib/new-package.js:203:6)
    at async Object.create (/nix/store/mb9n2clplvhm81mlrkyjc1yn7jxsfiyb-elm-review-2.12.0/lib/node_modules/elm-review/lib/new-package.js:78:3)

Version info:

❯ elm-review --version
2.12.0
❯ readlink $(which elm-review)
/nix/store/r0l047mhzz7lz3dsvh2851776j8fvl49-home-manager-path/bin/elm-review

This is likely specific to Nix-installed elm-review, because if I install the same version via NPM I'm able to run the elm-review new-package command successfully.

What I think is happening: I've noticed when running elm-review init (using the Nix-installed elm-review), that the generated ReviewConfig.elm is read-only. I'm guessing this has to do with these lines

node-elm-review/lib/init.js

Lines 197 to 202 in 18e38de

function createReviewConfig(directory, template) {
fs.copyFileSync(
path.join(__dirname, '../init-templates/', template),
path.join(directory, 'ReviewConfig.elm')
);
}
copying from the install directory. I think the install directory will be read-only when elm-review is installed via Nix, because all files in Nix store are read-only from what I understand, and the copied files will also copy the permissions.

See the permissions for the ReviewConfig created by Nix-installed elm-review

.r--r--r-- 443 pete  8 Dec 12:26 ReviewConfig.elm

compared to NPM-installed

.rw-r--r-- 435 pete  8 Dec 12:33 ReviewConfig.elm

The new-package script then tries to write to that file, in these lines

const previewReviewConfig = fs.readFileSync(previewReviewConfigPath, 'utf8');
fs.writeFileSync(
previewReviewConfigPath,
previewReviewConfig.replace(/RULENAME_TO_REPLACE/g, ruleName)
);
as reported by the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions