dillonkearns / elm-pages

Hybrid Elm framework with full-stack and static routes.
https://elm-pages.com
BSD 3-Clause "New" or "Revised" License
658 stars 98 forks source link

`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 2 years ago

jali-clarke commented 2 years ago

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.

kradalby commented 1 year ago

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

qbit commented 1 year ago

I created https://github.com/NixOS/nixpkgs/pull/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 commented 1 year ago

oh, also it's not against 3.0 :P

bcardiff commented 1 year ago

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