Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elm-pages v2.1.11 has some files in .elm-pages and elm-stuff created as read-only when node_modules is read-only #305

Open
jali-clarke opened this issue May 30, 2022 · 4 comments · May be fixed by #382

Comments

@jali-clarke
Copy link

Some application deployment methods freeze node_modules as read-only to prevent accidental modification at application runtime. When we bundle elm-pages @ v2.1.11 using this method, it copies these files into .elm-pages and elm-stuff while preserving their read-only permissions. This makes it impossible to e.g. run elm-pages dev twice without deleting .elm-pages and elm-stuff between invocations.

The following patch fixes this for v2.1.11:

diff --git a/generator/src/codegen.js b/generator/src/codegen.js
index a0ef8806e..fe00ac904 100644
--- a/generator/src/codegen.js
+++ b/generator/src/codegen.js
@@ -20,33 +20,33 @@ async function generate(basePath) {
 
   const uiFileContent = elmPagesUiFile();
   await Promise.all([
-    fs.promises.copyFile(
-      path.join(__dirname, `./Page.elm`),
-      `./.elm-pages/Page.elm`
+    fs.promises.writeFile(
+      `./.elm-pages/Page.elm`,
+      fs.readFileSync(path.join(__dirname, `./Page.elm`))
     ),
-    fs.promises.copyFile(
-      path.join(__dirname, `./elm-application.json`),
-      `./elm-stuff/elm-pages/elm-application.json`
+    fs.promises.writeFile(
+      `./elm-stuff/elm-pages/elm-application.json`,
+      fs.readFileSync(path.join(__dirname, `./elm-application.json`))
     ),
-    fs.promises.copyFile(
-      path.join(__dirname, `./Page.elm`),
-      `./elm-stuff/elm-pages/.elm-pages/Page.elm`
+    fs.promises.writeFile(
+      `./elm-stuff/elm-pages/.elm-pages/Page.elm`,
+      fs.readFileSync(path.join(__dirname, `./Page.elm`))
     ),
-    fs.promises.copyFile(
-      path.join(__dirname, `./SharedTemplate.elm`),
-      `./.elm-pages/SharedTemplate.elm`
+    fs.promises.writeFile(
+      `./.elm-pages/SharedTemplate.elm`,
+      fs.readFileSync(path.join(__dirname, `./SharedTemplate.elm`))
     ),
-    fs.promises.copyFile(
-      path.join(__dirname, `./SharedTemplate.elm`),
-      `./elm-stuff/elm-pages/.elm-pages/SharedTemplate.elm`
+    fs.promises.writeFile(
+      `./elm-stuff/elm-pages/.elm-pages/SharedTemplate.elm`,
+      fs.readFileSync(path.join(__dirname, `./SharedTemplate.elm`))
     ),
-    fs.promises.copyFile(
-      path.join(__dirname, `./SiteConfig.elm`),
-      `./.elm-pages/SiteConfig.elm`
+    fs.promises.writeFile(
+      `./.elm-pages/SiteConfig.elm`,
+      fs.readFileSync(path.join(__dirname, `./SiteConfig.elm`))
     ),
-    fs.promises.copyFile(
-      path.join(__dirname, `./SiteConfig.elm`),
-      `./elm-stuff/elm-pages/.elm-pages/SiteConfig.elm`
+    fs.promises.writeFile(
+      `./elm-stuff/elm-pages/.elm-pages/SiteConfig.elm`,
+      fs.readFileSync(path.join(__dirname, `./SiteConfig.elm`))
     ),
     fs.promises.writeFile("./.elm-pages/Pages.elm", uiFileContent),
     // write `Pages.elm` with cli interface

The code in master has changed since then, however.

jali-clarke added a commit to NoRedInk/nixpkgs that referenced this issue May 30, 2022
`node-packages.nix` was regenerated after having run `generate-node-packages.sh`
in order to pick up dependencies for `elm-pages`.  In addition, we add `elm`,
`elm-review`, and `elm-optimize-level-2` to the `PATH` for `elm-pages` since those
are needed at runtime.

A patch is also included to fix an issue where files are copied from the `nix-store`
as read-only (credit to @bcardiff for that fix).  An upstream issue
dillonkearns/elm-pages#305 has been opened to track this.
@kradalby
Copy link

I'm seeing this as well with elm-pages 3.0.

@qbit
Copy link

qbit commented Jun 20, 2023

I created NixOS/nixpkgs#235300 for a more comprehensive fix. I have been thinking about making a PR to include the walk function / fix in the elm-pages stuff.. Haven't had time though.

@qbit
Copy link

qbit commented Jun 20, 2023

oh, also it's not against 3.0 :P

@bcardiff bcardiff linked a pull request Jun 20, 2023 that will close this issue
@bcardiff
Copy link
Contributor

@kradalby I believe #382 should fix it for elm-pages 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants