elm-pages 3.0.0-beta.30 → 3.0.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  2. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +4 -104
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +7125 -6415
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  11. package/generator/dead-code-review/elm.json +4 -4
  12. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  13. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  14. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  15. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  16. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  17. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  20. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +4 -104
  21. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +16847 -16037
  22. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  23. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  24. package/generator/review/elm.json +5 -5
  25. package/generator/src/build.js +2 -1
  26. package/generator/src/cli.js +99 -93
  27. package/generator/src/compatibility-key.js +1 -1
  28. package/generator/src/compile-elm.js +18 -1
  29. package/generator/src/render.js +0 -2
  30. package/generator/src/resolve-elm-module.js +63 -0
  31. package/generator/src/rewrite-client-elm-json.js +1 -0
  32. package/generator/src/rewrite-elm-json-help.js +56 -0
  33. package/generator/src/rewrite-elm-json.js +13 -3
  34. package/generator/template/elm.json +1 -2
  35. package/package.json +17 -16
  36. package/src/Pages/Internal/Platform/Cli.elm +91 -0
  37. package/src/Pages/Internal/Platform.elm +1 -0
  38. package/src/Scaffold/Form.elm +187 -111
  39. package/src/Scaffold/Route.elm +261 -249
  40. package/src/Server/Session.elm +29 -9
  41. package/src/Server/SetCookie.elm +11 -3
@@ -75,7 +75,7 @@ console.elmlog = (str) => logs.push(str + "\n");
75
75
  const { Elm } = require("./Runner.elm.js");
76
76
 
77
77
  // Start the Elm app
78
- const flags = { initialSeed: 776409072, fuzzRuns: 100, filter: null };
78
+ const flags = { initialSeed: 3355512856, fuzzRuns: 100, filter: null };
79
79
  const app = Elm.Runner.init({ flags: flags });
80
80
 
81
81
  // Record the timing at which we received the last "runTest" message
@@ -82,7 +82,7 @@ const verbosity = 0;
82
82
  // Create a long lived reporter worker
83
83
  const { Elm } = require("./Reporter.elm.js");
84
84
  const flags = {
85
- initialSeed: 776409072,
85
+ initialSeed: 3355512856,
86
86
  fuzzRuns: 100,
87
87
  mode: "consoleColor",
88
88
  verbosity: verbosity,
@@ -11,8 +11,8 @@
11
11
  "elm/html": "1.0.0",
12
12
  "elm/json": "1.1.3",
13
13
  "elm/regex": "1.0.0",
14
- "jfmengels/elm-review": "2.10.0",
15
- "mdgriffith/elm-codegen": "2.0.0",
14
+ "jfmengels/elm-review": "2.12.2",
15
+ "mdgriffith/elm-codegen": "3.0.0",
16
16
  "stil4m/elm-syntax": "7.2.9",
17
17
  "the-sett/elm-syntax-dsl": "6.0.2"
18
18
  },
@@ -27,8 +27,8 @@
27
27
  "elm-community/basics-extra": "4.1.0",
28
28
  "elm-community/list-extra": "8.7.0",
29
29
  "elm-community/maybe-extra": "5.3.0",
30
- "elm-explorations/test": "2.1.0",
31
- "miniBill/elm-unicode": "1.0.2",
30
+ "elm-explorations/test": "2.1.1",
31
+ "miniBill/elm-unicode": "1.0.3",
32
32
  "rtfeldman/elm-hex": "1.0.0",
33
33
  "stil4m/structured-writer": "1.0.3",
34
34
  "the-sett/elm-pretty-printer": "3.0.0"
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "test-dependencies": {
38
38
  "direct": {
39
- "elm-explorations/test": "2.1.0"
39
+ "elm-explorations/test": "2.1.1"
40
40
  },
41
41
  "indirect": {}
42
42
  }
@@ -446,8 +446,9 @@ function modeToOptions(mode) {
446
446
  */
447
447
  function runElmMake(mode, options, elmEntrypointPath, outputPath, cwd) {
448
448
  return new Promise(async (resolve, reject) => {
449
+ const executableName = options.executableName || "lamdera";
449
450
  const subprocess = spawnCallback(
450
- `lamdera`,
451
+ executableName,
451
452
  [
452
453
  "make",
453
454
  elmEntrypointPath,
@@ -14,10 +14,11 @@ import * as esbuild from "esbuild";
14
14
  import { rewriteElmJson } from "./rewrite-elm-json.js";
15
15
  import { ensureDirSync } from "./file-helpers.js";
16
16
  import * as url from "url";
17
-
17
+ import { default as which } from "which";
18
18
  import * as commander from "commander";
19
19
  import { runElmCodegenInstall } from "./elm-codegen.js";
20
20
  import { packageVersion } from "./compatibility-key.js";
21
+ import { resolveInputPathOrModuleName } from "./resolve-elm-module.js";
21
22
 
22
23
  const Argument = commander.Argument;
23
24
  const Option = commander.Option;
@@ -85,52 +86,29 @@ async function main() {
85
86
  });
86
87
 
87
88
  program
88
- .command("run <moduleName>")
89
+ .command("run <elmModulePath>")
89
90
  .description("run an elm-pages script")
90
91
  .allowUnknownOption()
91
92
  .allowExcessArguments()
92
- .action(async (moduleName, options, options2) => {
93
+ .action(async (elmModulePath, options, options2) => {
93
94
  const unprocessedCliOptions = options2.args.splice(
94
95
  options2.processedArgs.length,
95
96
  options2.args.length
96
97
  );
97
- if (!/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(moduleName)) {
98
- throw `Invalid module name "${moduleName}", must be in the format of an Elm module`;
99
- }
100
- const splitModuleName = moduleName.split(".");
101
- const expectedFilePath = path.join(
102
- process.cwd(),
103
- "script/src/",
104
- `${splitModuleName.join("/")}.elm`
105
- );
106
- if (!fs.existsSync(expectedFilePath)) {
107
- throw `I couldn't find a module named ${expectedFilePath}`;
108
- }
109
98
  try {
110
- // await codegen.generate("");
111
- ensureDirSync(
112
- path.join(process.cwd(), ".elm-pages", "http-response-cache")
113
- );
114
- if (fs.existsSync("./codegen/")) {
115
- await runElmCodegenInstall();
116
- }
99
+ await compileElmForScript(elmModulePath);
117
100
 
118
- ensureDirSync("./script/elm-stuff");
119
- ensureDirSync("./script/elm-stuff/elm-pages/.elm-pages");
120
- await fs.promises.writeFile(
121
- path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
122
- generatorWrapperFile(moduleName)
123
- );
124
- await rewriteElmJson(
125
- "./script/elm.json",
126
- "./script/elm-stuff/elm-pages/elm.json"
127
- );
101
+ const { moduleName, projectDirectory, sourceDirectory } =
102
+ resolveInputPathOrModuleName(elmModulePath);
128
103
 
129
104
  const portBackendTaskCompiled = esbuild
130
105
  .build({
131
- entryPoints: ["./custom-backend-task"],
106
+ entryPoints: [path.join(projectDirectory, "./custom-backend-task")],
132
107
  platform: "node",
133
- outfile: ".elm-pages/compiled-ports/custom-backend-task.mjs",
108
+ outfile: path.join(
109
+ projectDirectory,
110
+ ".elm-pages/compiled-ports/custom-backend-task.mjs"
111
+ ),
134
112
  assetNames: "[name]-[hash]",
135
113
  chunkNames: "chunks/[name]-[hash]",
136
114
  metafile: true,
@@ -160,20 +138,23 @@ async function main() {
160
138
  });
161
139
  const portsPath = await portBackendTaskCompiled;
162
140
 
163
- process.chdir("./script");
141
+ const cwd = process.cwd();
142
+ process.chdir(projectDirectory);
164
143
  // TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
165
- await build.compileCliApp({ debug: "debug" });
166
- process.chdir("../");
144
+
145
+ let executableName = await lamderaOrElmFallback();
146
+ await build.compileCliApp({ debug: "debug", executableName });
167
147
  fs.renameSync(
168
- "./script/elm-stuff/elm-pages/elm.js",
169
- "./script/elm-stuff/elm-pages/elm.cjs"
148
+ `${projectDirectory}/elm-stuff/elm-pages/elm.js`,
149
+ `${projectDirectory}/elm-stuff/elm-pages/elm.cjs`
170
150
  );
151
+ process.chdir(cwd);
171
152
  await renderer.runGenerator(
172
153
  unprocessedCliOptions,
173
154
  portsPath
174
155
  ? await import(url.pathToFileURL(path.resolve(portsPath)).href)
175
156
  : null,
176
- await requireElm("./script/elm-stuff/elm-pages/elm.cjs"),
157
+ await requireElm(`${projectDirectory}/elm-stuff/elm-pages/elm.cjs`),
177
158
  moduleName
178
159
  );
179
160
  } catch (error) {
@@ -200,65 +181,44 @@ async function main() {
200
181
  collect,
201
182
  []
202
183
  )
203
- .action(async (moduleName, options, options2) => {
204
- if (!/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(moduleName)) {
205
- throw `Invalid module name "${moduleName}", must be in the format of an Elm module`;
206
- }
207
- const splitModuleName = moduleName.split(".");
208
- const expectedFilePath = path.join(
209
- process.cwd(),
210
- "script/src/",
211
- `${splitModuleName.join("/")}.elm`
184
+ .action(async (elmModulePath, options, options2) => {
185
+ const { moduleName, projectDirectory, sourceDirectory } =
186
+ resolveInputPathOrModuleName(elmModulePath);
187
+ await compileElmForScript(elmModulePath);
188
+
189
+ const cwd = process.cwd();
190
+ process.chdir(projectDirectory);
191
+ // TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
192
+
193
+ let executableName = await lamderaOrElmFallback();
194
+ await build.compileCliApp({ debug: options.debug, executableName });
195
+ fs.renameSync(
196
+ `${projectDirectory}/elm-stuff/elm-pages/elm.js`,
197
+ `${projectDirectory}/elm-stuff/elm-pages/elm.cjs`
212
198
  );
213
- if (!fs.existsSync(expectedFilePath)) {
214
- throw `I couldn't find a module named ${expectedFilePath}`;
215
- }
216
- try {
217
- if (fs.existsSync("./codegen/")) {
218
- await runElmCodegenInstall();
219
- }
199
+ process.chdir(cwd);
220
200
 
221
- ensureDirSync("./script/elm-stuff");
222
- ensureDirSync("./script/elm-stuff/elm-pages/.elm-pages");
223
- await fs.promises.writeFile(
224
- path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
225
- generatorWrapperFile(moduleName)
226
- );
227
- await rewriteElmJson(
228
- "./script/elm.json",
229
- "./script/elm-stuff/elm-pages/elm.json"
230
- );
201
+ try {
202
+ const { moduleName, projectDirectory, sourceDirectory } =
203
+ resolveInputPathOrModuleName(elmModulePath);
231
204
 
232
- process.chdir("./script");
233
- // TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
234
- console.log("Compiling...");
235
- await build.compileCliApp({ debug: options.debug });
236
- process.chdir("../");
237
- if (!options.debug) {
238
- console.log("Running elm-optimize-level-2...");
239
- await build.elmOptimizeLevel2(
240
- "./script/elm-stuff/elm-pages/elm.js",
241
- process.cwd()
242
- );
243
- }
244
- fs.renameSync(
245
- "./script/elm-stuff/elm-pages/elm.js",
246
- "./script/elm-stuff/elm-pages/elm.cjs"
247
- );
248
- // TODO allow no custom-backend-task
249
205
  const portBackendTaskFileFound =
250
- globby.globbySync("./custom-backend-task.*").length > 0;
206
+ globby.globbySync(
207
+ path.join(projectDirectory, "custom-backend-task.*")
208
+ ).length > 0;
251
209
 
252
210
  const scriptRunner = `${
253
211
  portBackendTaskFileFound
254
- ? `import * as customBackendTask from "${path.resolve(
212
+ ? `import * as customBackendTask from "${path.join(
213
+ projectDirectory,
255
214
  "./custom-backend-task"
256
215
  )}";`
257
216
  : "const customBackendTask = {};"
258
217
  }
259
218
  import * as renderer from "./render.js";
260
- import { default as Elm } from "${path.resolve(
261
- "./script/elm-stuff/elm-pages/elm.cjs"
219
+ import { default as Elm } from "${path.join(
220
+ projectDirectory,
221
+ "elm-stuff/elm-pages/elm.cjs"
262
222
  )}";
263
223
 
264
224
  await renderer.runGenerator(
@@ -278,9 +238,12 @@ await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await impo
278
238
  platform: "node",
279
239
  stdin: { contents: scriptRunner, resolveDir: __dirname },
280
240
  bundle: true,
281
- outfile: options.output,
241
+ // TODO do I need to make the outfile joined with the current working directory?
242
+
243
+ outfile: path.resolve(cwd, options.output),
282
244
  external: ["node:*", ...options.external],
283
245
  minify: true,
246
+ absWorkingDir: projectDirectory,
284
247
  banner: { js: `#!/usr/bin/env node\n\n${ESM_REQUIRE_SHIM}` },
285
248
  });
286
249
  } catch (error) {
@@ -361,7 +324,6 @@ async function requireElm(compiledElmPath) {
361
324
  function generatorWrapperFile(moduleName) {
362
325
  return `port module Main exposing (main)
363
326
 
364
- import Bytes
365
327
  import BackendTask exposing (BackendTask)
366
328
  import FatalError
367
329
  import Cli.Program as Program
@@ -378,7 +340,7 @@ main =
378
340
  , toJsPort = toJsPort
379
341
  , fromJsPort = fromJsPort identity
380
342
  , gotBatchSub = gotBatchSub identity
381
- , sendPageData = sendPageData
343
+ , sendPageData = \\_ -> Cmd.none
382
344
  }
383
345
 
384
346
 
@@ -389,13 +351,57 @@ port fromJsPort : (Decode.Value -> msg) -> Sub msg
389
351
 
390
352
 
391
353
  port gotBatchSub : (Decode.Value -> msg) -> Sub msg
392
-
393
-
394
- port sendPageData : { oldThing : Encode.Value, binaryPageData : Bytes.Bytes } -> Cmd msg
395
354
  `;
396
355
  }
397
356
  function collect(value, previous) {
398
357
  return previous.concat([value]);
399
358
  }
400
359
 
360
+ async function compileElmForScript(elmModulePath) {
361
+ const { moduleName, projectDirectory, sourceDirectory } =
362
+ resolveInputPathOrModuleName(elmModulePath);
363
+ const splitModuleName = moduleName.split(".");
364
+ const expectedFilePath = path.join(
365
+ sourceDirectory,
366
+ `${splitModuleName.join("/")}.elm`
367
+ );
368
+ if (!fs.existsSync(expectedFilePath)) {
369
+ throw `I couldn't find a module named ${expectedFilePath}`;
370
+ }
371
+ // await codegen.generate("");
372
+ ensureDirSync(path.join(process.cwd(), ".elm-pages", "http-response-cache"));
373
+ if (fs.existsSync("./codegen/")) {
374
+ await runElmCodegenInstall();
375
+ }
376
+
377
+ ensureDirSync(`${projectDirectory}/elm-stuff`);
378
+ ensureDirSync(`${projectDirectory}/elm-stuff/elm-pages/.elm-pages`);
379
+ await fs.promises.writeFile(
380
+ path.join(`${projectDirectory}/elm-stuff/elm-pages/.elm-pages/Main.elm`),
381
+ generatorWrapperFile(moduleName)
382
+ );
383
+ let executableName = await lamderaOrElmFallback();
384
+ try {
385
+ await which("lamdera");
386
+ } catch (error) {
387
+ await which("elm");
388
+ executableName = "elm";
389
+ }
390
+ await rewriteElmJson(
391
+ `${projectDirectory}/elm.json`,
392
+ `${projectDirectory}/elm-stuff/elm-pages/elm.json`,
393
+ { executableName }
394
+ );
395
+ }
396
+
397
+ async function lamderaOrElmFallback() {
398
+ try {
399
+ await which("lamdera");
400
+ return "lamdera";
401
+ } catch (error) {
402
+ await which("elm");
403
+ return "elm";
404
+ }
405
+ }
406
+
401
407
  main();
@@ -1,3 +1,3 @@
1
1
  export const compatibilityKey = 12;
2
2
 
3
- export const packageVersion = "3.0.0-beta.29";
3
+ export const packageVersion = "3.0.0-beta.31";
@@ -6,6 +6,8 @@ import * as path from "path";
6
6
  import * as kleur from "kleur/colors";
7
7
  import { inject } from "elm-hot";
8
8
  import { fileURLToPath } from "url";
9
+ import { rewriteElmJson } from "./rewrite-elm-json-help.js";
10
+ import { ensureDirSync } from "./file-helpers.js";
9
11
  const __filename = fileURLToPath(import.meta.url);
10
12
  const __dirname = path.dirname(__filename);
11
13
 
@@ -16,7 +18,22 @@ export async function compileElmForBrowser(options) {
16
18
  "elm-stuff/elm-pages/",
17
19
  "browser-elm.js"
18
20
  );
19
- await runElm(options, "./.elm-pages/Main.elm", pathToClientElm);
21
+ const secretDir = path.join(process.cwd(), "elm-stuff/elm-pages/browser-elm");
22
+ await fsHelpers.tryMkdir(secretDir);
23
+ rewriteElmJson(process.cwd(), secretDir, function (elmJson) {
24
+ elmJson["source-directories"] = elmJson["source-directories"].map(
25
+ (item) => {
26
+ return "../../../" + item;
27
+ }
28
+ );
29
+ return elmJson;
30
+ });
31
+ await runElm(
32
+ options,
33
+ "../../../.elm-pages/Main.elm",
34
+ pathToClientElm,
35
+ secretDir
36
+ );
20
37
  return fs.promises.writeFile(
21
38
  "./.elm-pages/cache/elm.js",
22
39
  inject(await fs.promises.readFile(pathToClientElm, "utf-8")).replace(
@@ -133,7 +133,6 @@ function runGeneratorAppHelp(
133
133
 
134
134
  killApp = () => {
135
135
  app.ports.toJsPort.unsubscribe(portHandler);
136
- app.ports.sendPageData.unsubscribe(portHandler);
137
136
  app.die();
138
137
  app = null;
139
138
  // delete require.cache[require.resolve(compiledElmPath)];
@@ -209,7 +208,6 @@ function runGeneratorAppHelp(
209
208
  }
210
209
  }
211
210
  app.ports.toJsPort.subscribe(portHandler);
212
- app.ports.sendPageData.subscribe(portHandler);
213
211
  }).finally(() => {
214
212
  try {
215
213
  killApp();
@@ -0,0 +1,63 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+
4
+ function findNearestElmJson(filePath) {
5
+ function searchForElmJson(directory) {
6
+ if (directory === "/") {
7
+ return null;
8
+ }
9
+
10
+ const elmJsonPath = path.join(directory, "elm.json");
11
+ return fs.existsSync(elmJsonPath)
12
+ ? elmJsonPath
13
+ : searchForElmJson(path.dirname(directory));
14
+ }
15
+
16
+ return searchForElmJson(path.dirname(filePath));
17
+ }
18
+
19
+ function getElmModuleName(inputPath) {
20
+ const filePath = path.normalize(
21
+ path.isAbsolute(inputPath) ? inputPath : path.resolve(inputPath)
22
+ );
23
+ const elmJsonPath = findNearestElmJson(filePath);
24
+
25
+ if (!elmJsonPath) {
26
+ throw new Error("No elm.json found");
27
+ }
28
+
29
+ const elmJson = JSON.parse(fs.readFileSync(elmJsonPath, "utf8"));
30
+ const sourceDirectories = elmJson["source-directories"];
31
+ const projectDirectory = path.dirname(elmJsonPath);
32
+
33
+ const matchingSourceDir = sourceDirectories
34
+ .map((sourceDir) => path.join(projectDirectory, sourceDir))
35
+ .find((absoluteSourceDir) => filePath.startsWith(absoluteSourceDir));
36
+
37
+ if (!matchingSourceDir) {
38
+ throw new Error(
39
+ "File is not in any source-directories specified in elm.json"
40
+ );
41
+ }
42
+
43
+ const relativePath = path.relative(matchingSourceDir, filePath);
44
+ const moduleName = relativePath
45
+ .replace(path.extname(relativePath), "")
46
+ .replace("/", ".");
47
+
48
+ return { projectDirectory, moduleName, sourceDirectory: matchingSourceDir };
49
+ }
50
+
51
+ export function resolveInputPathOrModuleName(inputPathOrModuleName) {
52
+ if (
53
+ /^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(inputPathOrModuleName)
54
+ ) {
55
+ return {
56
+ moduleName: inputPathOrModuleName,
57
+ projectDirectory: "./script",
58
+ sourceDirectory: "./script/src",
59
+ };
60
+ } else {
61
+ return getElmModuleName(inputPathOrModuleName);
62
+ }
63
+ }
@@ -27,6 +27,7 @@ function rewriteClientElmJsonHelp(elmJson) {
27
27
  elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
28
28
  return "../../../" + item;
29
29
  });
30
+ elmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
30
31
  // 3. add our own secret My.elm module 😈
31
32
  elmJson["source-directories"].push(".elm-pages");
32
33
  elmJson["source-directories"].push("app");
@@ -0,0 +1,56 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+
4
+ /**
5
+ * @param {string} sourceElmJsonPath
6
+ * @param {string} targetElmJsonPath
7
+ * @param {( (arg0: JSON) => JSON )?} modifyElmJson
8
+ */
9
+ export async function rewriteElmJson(
10
+ sourceElmJsonPath,
11
+ targetElmJsonPath,
12
+ modifyElmJson
13
+ ) {
14
+ if (!modifyElmJson) {
15
+ modifyElmJson = function (json) {
16
+ return json;
17
+ };
18
+ }
19
+ var elmJson = JSON.parse(
20
+ (
21
+ await fs.promises.readFile(path.join(sourceElmJsonPath, "elm.json"))
22
+ ).toString()
23
+ );
24
+
25
+ let modifiedElmJson = modifyElmJson(elmJson);
26
+ // always add `lamdera/codecs` dependency
27
+ modifiedElmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
28
+
29
+ // write new elm.json
30
+ await writeFileIfChanged(
31
+ path.join(targetElmJsonPath, "elm.json"),
32
+ JSON.stringify(modifiedElmJson)
33
+ );
34
+ }
35
+
36
+ /**
37
+ * @param {fs.PathLike | fs.promises.FileHandle} filePath
38
+ * @param {string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream").Stream} content
39
+ */
40
+ async function writeFileIfChanged(filePath, content) {
41
+ if (
42
+ !(await fileExists(filePath)) ||
43
+ (await fs.promises.readFile(filePath, "utf8")) !== content
44
+ ) {
45
+ await fs.promises.writeFile(filePath, content);
46
+ }
47
+ }
48
+ /**
49
+ * @param {fs.PathLike} file
50
+ */
51
+ function fileExists(file) {
52
+ return fs.promises
53
+ .access(file, fs.constants.F_OK)
54
+ .then(() => true)
55
+ .catch(() => false);
56
+ }
@@ -1,6 +1,10 @@
1
1
  import * as fs from "node:fs";
2
2
 
3
- export async function rewriteElmJson(sourceElmJsonPath, targetElmJsonPath) {
3
+ export async function rewriteElmJson(
4
+ sourceElmJsonPath,
5
+ targetElmJsonPath,
6
+ options
7
+ ) {
4
8
  var elmJson = JSON.parse(
5
9
  (await fs.promises.readFile(sourceElmJsonPath)).toString()
6
10
  );
@@ -9,11 +13,11 @@ export async function rewriteElmJson(sourceElmJsonPath, targetElmJsonPath) {
9
13
 
10
14
  await writeFileIfChanged(
11
15
  targetElmJsonPath,
12
- JSON.stringify(rewriteElmJsonHelp(elmJson))
16
+ JSON.stringify(rewriteElmJsonHelp(elmJson, options))
13
17
  );
14
18
  }
15
19
 
16
- function rewriteElmJsonHelp(elmJson) {
20
+ function rewriteElmJsonHelp(elmJson, options) {
17
21
  // The internal generated file will be at:
18
22
  // ./elm-stuff/elm-pages/
19
23
  // So, we need to take the existing elmJson and
@@ -27,6 +31,12 @@ function rewriteElmJsonHelp(elmJson) {
27
31
  elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
28
32
  return "../../" + item;
29
33
  });
34
+ if (options && options.executableName === "elm") {
35
+ // elm, don't add lamdera/codecs
36
+ } else {
37
+ // lamdera, add codecs dependency
38
+ elmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
39
+ }
30
40
  // 3. add our own secret My.elm module 😈
31
41
  elmJson["source-directories"].push(".elm-pages");
32
42
  return elmJson;
@@ -30,7 +30,6 @@
30
30
  "elm-community/result-extra": "2.4.0",
31
31
  "jluckyiv/elm-utc-date-strings": "1.0.0",
32
32
  "justinmimbs/date": "4.0.1",
33
- "lamdera/codecs": "1.0.0",
34
33
  "mdgriffith/elm-codegen": "2.0.0",
35
34
  "miniBill/elm-codec": "2.0.0",
36
35
  "noahzgordon/elm-color-extra": "1.0.2",
@@ -62,4 +61,4 @@
62
61
  "direct": {},
63
62
  "indirect": {}
64
63
  }
65
- }
64
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elm-pages",
3
3
  "type": "module",
4
- "version": "3.0.0-beta.30",
4
+ "version": "3.0.0-beta.31",
5
5
  "homepage": "https://elm-pages.com",
6
6
  "moduleResolution": "node",
7
7
  "description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
@@ -25,27 +25,27 @@
25
25
  "author": "Dillon Kearns",
26
26
  "license": "BSD-3-Clause",
27
27
  "dependencies": {
28
- "busboy": "^1.0.0",
28
+ "busboy": "^1.6.0",
29
29
  "chokidar": "^3.5.3",
30
30
  "commander": "^10.0.0",
31
31
  "connect": "^3.7.0",
32
- "cookie-signature": "^1.1.0",
32
+ "cookie-signature": "^1.2.1",
33
33
  "cross-spawn": "7.0.3",
34
34
  "devcert": "^1.2.2",
35
35
  "elm-doc-preview": "^5.0.5",
36
36
  "elm-hot": "^1.1.6",
37
- "esbuild": "0.17.10",
38
- "fs-extra": "^11.1.0",
37
+ "esbuild": "^0.17.12",
38
+ "fs-extra": "^11.1.1",
39
39
  "globby": "13.1.3",
40
40
  "gray-matter": "^4.0.3",
41
41
  "jsesc": "^3.0.2",
42
42
  "kleur": "^4.1.5",
43
43
  "make-fetch-happen": "^11.0.3",
44
- "memfs": "^3.4.7",
44
+ "memfs": "^3.4.13",
45
45
  "micromatch": "^4.0.5",
46
46
  "serve-static": "^1.15.0",
47
- "terser": "^5.16.3",
48
- "vite": "^4.1.1",
47
+ "vite": "^4.2.1",
48
+ "terser": "^5.16.8",
49
49
  "which": "^3.0.0"
50
50
  },
51
51
  "devDependencies": {
@@ -53,18 +53,19 @@
53
53
  "@types/fs-extra": "^11.0.1",
54
54
  "@types/make-fetch-happen": "^10.0.1",
55
55
  "@types/micromatch": "^4.0.2",
56
- "@types/node": "^18.11.9",
57
- "@types/serve-static": "^1.15.0",
58
- "cypress": "^12.5.1",
56
+ "@types/node": "^18.15.7",
57
+ "@types/serve-static": "^1.15.1",
58
+ "cypress": "^12.8.1",
59
59
  "elm-codegen": "^0.3.0",
60
60
  "elm-optimize-level-2": "^0.3.5",
61
- "elm-review": "^2.8.2",
61
+ "elm-review": "^2.9.2",
62
62
  "elm-test": "^0.19.1-revision11",
63
- "elm-tooling": "^1.12.0",
63
+ "elm-tooling": "^1.13.1",
64
64
  "elm-verify-examples": "^5.2.0",
65
- "elmi-to-json": "^1.2.0",
66
- "typescript": "^4.9.5",
67
- "vitest": "^0.28.5"
65
+ "elmi-to-json": "^1.4.3",
66
+ "typescript": "^5.0.2",
67
+ "vite": "^4.2.1",
68
+ "vitest": "^0.29.7"
68
69
  },
69
70
  "files": [
70
71
  "generator/src/",