elm-pages 3.0.25 → 3.0.26

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.
@@ -1,3 +1,3 @@
1
1
  export const compatibilityKey = 22;
2
2
 
3
- export const packageVersion = "3.0.25";
3
+ export const packageVersion = "3.0.26";
@@ -133,6 +133,12 @@ async function compileElm(options, elmEntrypointPath, outputPath, cwd) {
133
133
 
134
134
  function spawnElmMake(options, elmEntrypointPath, outputPath, cwd) {
135
135
  return new Promise(async (resolve, reject) => {
136
+ try {
137
+ await fsPromises.unlink(outputPath);
138
+ } catch (e) {
139
+ /* File may not exist, so ignore errors */
140
+ }
141
+
136
142
  const subprocess = spawnCallback(
137
143
  `lamdera`,
138
144
  [
@@ -152,13 +158,6 @@ function spawnElmMake(options, elmEntrypointPath, outputPath, cwd) {
152
158
  cwd: cwd,
153
159
  }
154
160
  );
155
- if (await fsHelpers.fileExists(outputPath)) {
156
- try {
157
- await fsPromises.unlink(outputPath, {
158
- force: true /* ignore errors if file doesn't exist */,
159
- });
160
- } catch (e) {}
161
- }
162
161
  let commandOutput = "";
163
162
 
164
163
  subprocess.stderr.on("data", function (data) {
@@ -412,12 +412,7 @@ async function outputString(
412
412
 
413
413
  /** @typedef { { head: any[]; errors: any[]; contentJson: any[]; html: string; route: string; title: string; } } Arg */
414
414
 
415
- async function runHttpJob(
416
- requestHash,
417
- portsFile,
418
- mode,
419
- requestToPerform,
420
- ) {
415
+ async function runHttpJob(requestHash, portsFile, mode, requestToPerform) {
421
416
  try {
422
417
  const lookupResponse = await lookupOrPerform(
423
418
  portsFile,
@@ -490,18 +485,13 @@ async function runInternalJob(
490
485
  portsFile
491
486
  ) {
492
487
  try {
493
- const cwd = path.resolve(...requestToPerform.dir);
494
- const quiet = requestToPerform.quiet;
495
- const env = { ...process.env, ...requestToPerform.env };
496
-
497
- const context = { cwd, quiet, env };
498
488
  switch (requestToPerform.url) {
499
489
  case "elm-pages-internal://log":
500
490
  return [requestHash, await runLogJob(requestToPerform)];
501
491
  case "elm-pages-internal://read-file":
502
492
  return [
503
493
  requestHash,
504
- await readFileJobNew(requestToPerform, patternsToWatch, context),
494
+ await readFileJobNew(requestToPerform, patternsToWatch),
505
495
  ];
506
496
  case "elm-pages-internal://read-file-binary":
507
497
  return [
@@ -539,7 +529,7 @@ async function runInternalJob(
539
529
  await runDecryptJob(requestToPerform, patternsToWatch),
540
530
  ];
541
531
  case "elm-pages-internal://write-file":
542
- return [requestHash, await runWriteFileJob(requestToPerform, context)];
532
+ return [requestHash, await runWriteFileJob(requestToPerform)];
543
533
  case "elm-pages-internal://sleep":
544
534
  return [requestHash, await runSleep(requestToPerform)];
545
535
  case "elm-pages-internal://which":
@@ -549,10 +539,7 @@ async function runInternalJob(
549
539
  case "elm-pages-internal://shell":
550
540
  return [requestHash, await runShell(requestToPerform)];
551
541
  case "elm-pages-internal://stream":
552
- return [
553
- requestHash,
554
- await runStream(requestToPerform, portsFile, context),
555
- ];
542
+ return [requestHash, await runStream(requestToPerform, portsFile)];
556
543
  case "elm-pages-internal://start-spinner":
557
544
  return [requestHash, runStartSpinner(requestToPerform)];
558
545
  case "elm-pages-internal://stop-spinner":
@@ -567,7 +554,19 @@ async function runInternalJob(
567
554
  }
568
555
  }
569
556
 
570
- async function readFileJobNew(req, patternsToWatch, { cwd }) {
557
+ /**
558
+ * @param {{ dir: string[]; quiet: boolean; env: { [key:string]: string; }; }} requestToPerform
559
+ */
560
+ function getContext(requestToPerform) {
561
+ const cwd = path.resolve(...requestToPerform.dir);
562
+ const quiet = requestToPerform.quiet;
563
+ const env = { ...process.env, ...requestToPerform.env };
564
+
565
+ return { cwd, quiet, env };
566
+ }
567
+
568
+ async function readFileJobNew(req, patternsToWatch) {
569
+ const { cwd } = getContext(req);
571
570
  // TODO use cwd
572
571
  const filePath = path.resolve(cwd, req.body.args[1]);
573
572
  try {
@@ -639,8 +638,9 @@ async function runQuestion(req) {
639
638
  return jsonResponse(req, await question(req.body.args[0]));
640
639
  }
641
640
 
642
- function runStream(req, portsFile, context) {
641
+ function runStream(req, portsFile) {
643
642
  return new Promise(async (resolve) => {
643
+ const context = getContext(req);
644
644
  let metadataResponse = null;
645
645
  let lastStream = null;
646
646
  try {
@@ -1153,7 +1153,8 @@ export async function question({ prompt }) {
1153
1153
  });
1154
1154
  }
1155
1155
 
1156
- async function runWriteFileJob(req, { cwd }) {
1156
+ async function runWriteFileJob(req) {
1157
+ const { cwd } = getContext(req);
1157
1158
  const data = req.body.args[0];
1158
1159
  const filePath = path.resolve(cwd, data.path);
1159
1160
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elm-pages",
3
3
  "type": "module",
4
- "version": "3.0.25",
4
+ "version": "3.0.26",
5
5
  "homepage": "https://elm-pages.com",
6
6
  "moduleResolution": "node",
7
7
  "description": "Hybrid Elm framework with full-stack and static routes.",