elm-pages 3.0.0-beta.16 → 3.0.0-beta.17

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.
@@ -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: 2665303026, fuzzRuns: 100, filter: null };
78
+ const flags = { initialSeed: 4015861069, 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: 2665303026,
85
+ initialSeed: 4015861069,
86
86
  fuzzRuns: 100,
87
87
  mode: "consoleNoColor",
88
88
  verbosity: verbosity,
@@ -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: 4260939212, fuzzRuns: 100, filter: null };
78
+ const flags = { initialSeed: 1374716823, 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: 4260939212,
85
+ initialSeed: 1374716823,
86
86
  fuzzRuns: 100,
87
87
  mode: "consoleNoColor",
88
88
  verbosity: verbosity,
@@ -143,9 +143,9 @@ async function run(options) {
143
143
 
144
144
  const portBackendTaskCompiled = esbuild
145
145
  .build({
146
- entryPoints: ["./port-data-source"],
146
+ entryPoints: ["./custom-backend-task"],
147
147
  platform: "node",
148
- outfile: ".elm-pages/compiled-ports/port-data-source.js",
148
+ outfile: ".elm-pages/compiled-ports/custom-backend-task.js",
149
149
  assetNames: "[name]-[hash]",
150
150
  chunkNames: "chunks/[name]-[hash]",
151
151
  outExtension: { ".js": ".js" },
@@ -161,11 +161,11 @@ async function run(options) {
161
161
  })
162
162
  .catch((error) => {
163
163
  const portBackendTaskFileFound =
164
- globby.sync("./port-data-source.*").length > 0;
164
+ globby.sync("./custom-backend-task.*").length > 0;
165
165
  if (portBackendTaskFileFound) {
166
- // don't present error if there are no files matching port-data-source
167
- // if there are files matching port-data-source, warn the user in case something went wrong loading it
168
- console.error("Failed to start port-data-source watcher", error);
166
+ // don't present error if there are no files matching custom-backend-task
167
+ // if there are files matching custom-backend-task, warn the user in case something went wrong loading it
168
+ console.error("Failed to start custom-backend-task watcher", error);
169
169
  }
170
170
  });
171
171
  // TODO extract common code for compiling ports file?
@@ -617,7 +617,7 @@ async function runAdapter(adaptFn, processedIndexTemplate) {
617
617
  apiRoutePatterns: JSON.parse(
618
618
  await fsPromises.readFile("./dist/api-patterns.json", "utf-8")
619
619
  ),
620
- portsFilePath: "./.elm-pages/compiled-ports/port-data-source.js",
620
+ portsFilePath: "./.elm-pages/compiled-ports/custom-backend-task.js",
621
621
  htmlTemplate: processedIndexTemplate,
622
622
  });
623
623
  console.log("Success - Adapter script complete");
@@ -131,9 +131,9 @@ async function main() {
131
131
 
132
132
  const portBackendTaskCompiled = esbuild
133
133
  .build({
134
- entryPoints: ["./port-data-source"],
134
+ entryPoints: ["./custom-backend-task"],
135
135
  platform: "node",
136
- outfile: ".elm-pages/compiled-ports/port-data-source.js",
136
+ outfile: ".elm-pages/compiled-ports/custom-backend-task.js",
137
137
  assetNames: "[name]-[hash]",
138
138
  chunkNames: "chunks/[name]-[hash]",
139
139
  outExtension: { ".js": ".js" },
@@ -151,11 +151,14 @@ async function main() {
151
151
  })
152
152
  .catch((error) => {
153
153
  const portBackendTaskFileFound =
154
- globby.sync("./port-data-source.*").length > 0;
154
+ globby.sync("./custom-backend-task.*").length > 0;
155
155
  if (portBackendTaskFileFound) {
156
- // don't present error if there are no files matching port-data-source
157
- // if there are files matching port-data-source, warn the user in case something went wrong loading it
158
- console.error("Failed to start port-data-source watcher", error);
156
+ // don't present error if there are no files matching custom-backend-task
157
+ // if there are files matching custom-backend-task, warn the user in case something went wrong loading it
158
+ console.error(
159
+ "Failed to start custom-backend-task watcher",
160
+ error
161
+ );
159
162
  }
160
163
  });
161
164
  const portsPath = await portBackendTaskCompiled;
@@ -140,7 +140,7 @@ async function start(options) {
140
140
  );
141
141
  esbuild
142
142
  .build({
143
- entryPoints: ["./port-data-source"],
143
+ entryPoints: ["./custom-backend-task"],
144
144
  platform: "node",
145
145
  assetNames: "[name]-[hash]",
146
146
  chunkNames: "chunks/[name]-[hash]",
@@ -171,15 +171,15 @@ async function start(options) {
171
171
  ],
172
172
  })
173
173
  .then((result) => {
174
- console.log("Watching port-data-source...");
174
+ console.log("Watching custom-backend-task...");
175
175
  })
176
176
  .catch((error) => {
177
177
  const portBackendTaskFileFound =
178
- globby.sync("./port-data-source.*").length > 0;
178
+ globby.sync("./custom-backend-task.*").length > 0;
179
179
  if (portBackendTaskFileFound) {
180
- // don't present error if there are no files matching port-data-source
181
- // if there are files matching port-data-source, warn the user in case something went wrong loading it
182
- console.error("Failed to start port-data-source watcher", error);
180
+ // don't present error if there are no files matching custom-backend-task
181
+ // if there are files matching custom-backend-task, warn the user in case something went wrong loading it
182
+ console.error("Failed to start custom-backend-task watcher", error);
183
183
  }
184
184
  });
185
185
 
@@ -27,7 +27,7 @@ async function run({ pathname, serverRequest }) {
27
27
  console.log("Compiling DONE");
28
28
 
29
29
  const portsFilePath =
30
- ".elm-pages/compiled-ports/port-data-source-FA2IJND6.js";
30
+ ".elm-pages/compiled-ports/custom-backend-task-FA2IJND6.js";
31
31
  const mode = "dev-server";
32
32
 
33
33
  const renderResult = await renderer.render(
@@ -43,21 +43,21 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
43
43
  resolve({
44
44
  kind: "response-json",
45
45
  value: jsonResponse({
46
- "elm-pages-internal-error": "PortNotDefined",
46
+ "elm-pages-internal-error": "CustomBackendTaskNotDefined",
47
47
  }),
48
48
  });
49
49
  } else if (portBackendTaskImportError === "missing") {
50
50
  resolve({
51
51
  kind: "response-json",
52
52
  value: jsonResponse({
53
- "elm-pages-internal-error": "MissingPortsFile",
53
+ "elm-pages-internal-error": "MissingCustomBackendTaskFile",
54
54
  }),
55
55
  });
56
56
  } else {
57
57
  resolve({
58
58
  kind: "response-json",
59
59
  value: jsonResponse({
60
- "elm-pages-internal-error": "ErrorInPortsFile",
60
+ "elm-pages-internal-error": "ErrorInCustomBackendTaskFile",
61
61
  error:
62
62
  (portBackendTaskImportError &&
63
63
  portBackendTaskImportError.stack) ||
@@ -83,7 +83,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
83
83
  resolve({
84
84
  kind: "response-json",
85
85
  value: jsonResponse({
86
- "elm-pages-internal-error": "PortCallException",
86
+ "elm-pages-internal-error": "CustomBackendTaskException",
87
87
  error: portCallError,
88
88
  }),
89
89
  });
@@ -92,7 +92,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
92
92
  } catch (error) {
93
93
  console.trace(error);
94
94
  reject({
95
- title: "BackendTask.Port Error",
95
+ title: "BackendTask.Custom Error",
96
96
  message: error.toString(),
97
97
  });
98
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elm-pages",
3
- "version": "3.0.0-beta.16",
3
+ "version": "3.0.0-beta.17",
4
4
  "homepage": "https://elm-pages.com",
5
5
  "moduleResolution": "node",
6
6
  "description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
@@ -1,30 +1,30 @@
1
- module BackendTask.Port exposing
2
- ( get
1
+ module BackendTask.Custom exposing
2
+ ( run
3
3
  , Error(..)
4
4
  )
5
5
 
6
6
  {-| In a vanilla Elm application, ports let you either send or receive JSON data between your Elm application and the JavaScript context in the user's browser at runtime.
7
7
 
8
- With `BackendTask.Port`, you send and receive JSON to JavaScript running in NodeJS. As with any `BackendTask`, Port BackendTask's are either run at build-time (for pre-rendered routes) or at request-time (for server-rendered routes). See [`BackendTask`](BackendTask) for more about the
8
+ With `BackendTask.Custom`, you send and receive JSON to JavaScript running in NodeJS. As with any `BackendTask`, Custom BackendTask's are either run at build-time (for pre-rendered routes) or at request-time (for server-rendered routes). See [`BackendTask`](BackendTask) for more about the
9
9
  lifecycle of `BackendTask`'s.
10
10
 
11
11
  This means that you can call shell scripts, run NPM packages that are installed, or anything else you could do with NodeJS to perform custom side-effects, get some data, or both.
12
12
 
13
- A `BackendTask.Port` will call an async JavaScript function with the given name from the definition in a file called `port-data-source.js` in your project's root directory. The function receives the input JSON value, and the Decoder is used to decode the return value of the async function.
13
+ A `BackendTask.Custom` will call an async JavaScript function with the given name from the definition in a file called `custom-backend-task.js` in your project's root directory. The function receives the input JSON value, and the Decoder is used to decode the return value of the async function.
14
14
 
15
- @docs get
15
+ @docs run
16
16
 
17
- Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or an `FatalError BackendTask.Port.Error` if it isn't found). In this example,
17
+ Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or an `FatalError BackendTask.Custom.Error` if it isn't found). In this example,
18
18
  we're using `BackendTask.allowFatal` to let the framework treat that as an unexpected exception, but we could also handle the possible failures of the `FatalError` (see [`FatalError`](FatalError)).
19
19
 
20
20
  import BackendTask exposing (BackendTask)
21
- import BackendTask.Port
21
+ import BackendTask.Custom
22
22
  import Json.Encode
23
23
  import OptimizedDecoder as Decode
24
24
 
25
25
  data : BackendTask FatalError String
26
26
  data =
27
- BackendTask.Port.get "environmentVariable"
27
+ BackendTask.Custom.run "environmentVariable"
28
28
  (Json.Encode.string "EDITOR")
29
29
  Decode.string
30
30
  |> BackendTask.allowFatal
@@ -32,7 +32,7 @@ we're using `BackendTask.allowFatal` to let the framework treat that as an unexp
32
32
  -- will resolve to "VIM" if you run `EDITOR=vim elm-pages dev`
33
33
 
34
34
  ```javascript
35
- // port-data-source.js
35
+ // custom-backend-task.js
36
36
 
37
37
  module.exports =
38
38
  /**
@@ -60,37 +60,37 @@ ${Object.keys(process.env).join("\n")}
60
60
  ## Performance
61
61
 
62
62
  As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using `fs.readFileSync`, because blocking IO can slow down your elm-pages builds and dev server. `elm-pages` performances all `BackendTask`'s in parallel whenever possible.
63
- So if you do `BackendTask.map2 Tuple.pair myHttpBackendTask myPortBackendTask`, it will resolve those two in parallel. NodeJS performs best when you take advantage of its ability to do non-blocking I/O (file reads, HTTP requests, etc.). If you use `BackendTask.andThen`,
64
- it will need to resolve them in sequence rather than in parallel, but it's still best to avoid blocking IO operations in your BackendTask Port definitions.
63
+ So if you do `BackendTask.map2 Tuple.pair myHttpBackendTask myCustomBackendTask`, it will resolve those two in parallel. NodeJS performs best when you take advantage of its ability to do non-blocking I/O (file reads, HTTP requests, etc.). If you use `BackendTask.andThen`,
64
+ it will need to resolve them in sequence rather than in parallel, but it's still best to avoid blocking IO operations in your Custom BackendTask definitions.
65
65
 
66
66
 
67
67
  ## Error Handling
68
68
 
69
- There are a few different things that can go wrong when running a port-data-source. These possible errors are captured in the `BackendTask.Port.Error` type.
69
+ There are a few different things that can go wrong when running a custom-backend-task. These possible errors are captured in the `BackendTask.Custom.Error` type.
70
70
 
71
71
  @docs Error
72
72
 
73
- Any time you throw a JavaScript exception from a BackendTask.Port definition, it will give you a `PortCallException`. It's usually easier to add a `try`/`catch` in your JavaScript code in `port-data-source.js`
74
- to handle possible errors, but you can throw a JSON value and handle it in Elm in the `PortCallException` call error.
73
+ Any time you throw a JavaScript exception from a BackendTask.Custom definition, it will give you a `CustomBackendTaskException`. It's usually easier to add a `try`/`catch` in your JavaScript code in `custom-backend-task.js`
74
+ to handle possible errors, but you can throw a JSON value and handle it in Elm in the `CustomBackendTaskException` call error.
75
75
 
76
76
  -}
77
77
 
78
78
  import BackendTask
79
79
  import BackendTask.Http
80
80
  import BackendTask.Internal.Request
81
- import FatalError exposing (FatalError, Recoverable)
81
+ import FatalError exposing (FatalError)
82
82
  import Json.Decode as Decode exposing (Decoder)
83
83
  import Json.Encode as Encode
84
84
  import TerminalText
85
85
 
86
86
 
87
87
  {-| -}
88
- get :
88
+ run :
89
89
  String
90
90
  -> Encode.Value
91
91
  -> Decoder b
92
92
  -> BackendTask.BackendTask { fatal : FatalError, recoverable : Error } b
93
- get portName input decoder =
93
+ run portName input decoder =
94
94
  BackendTask.Internal.Request.request
95
95
  { name = "port"
96
96
  , body =
@@ -104,17 +104,17 @@ get portName input decoder =
104
104
  [ Decode.field "elm-pages-internal-error" Decode.string
105
105
  |> Decode.andThen
106
106
  (\errorKind ->
107
- if errorKind == "PortNotDefined" then
107
+ if errorKind == "CustomBackendTaskNotDefined" then
108
108
  FatalError.recoverable
109
- { title = "Port Error"
109
+ { title = "Custom BackendTask Error"
110
110
  , body =
111
- [ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I expected to find a port named `"
111
+ [ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I expected to find a port named `"
112
112
  , TerminalText.yellow portName
113
- , TerminalText.text "` but I couldn't find it. Is the function exported in your port-data-source file?"
113
+ , TerminalText.text "` but I couldn't find it. Is the function exported in your custom-backend-task file?"
114
114
  ]
115
115
  |> TerminalText.toString
116
116
  }
117
- (PortNotDefined { name = portName })
117
+ (CustomBackendTaskNotDefined { name = portName })
118
118
  |> Decode.succeed
119
119
 
120
120
  else if errorKind == "ExportIsNotFunction" then
@@ -122,78 +122,78 @@ get portName input decoder =
122
122
  |> Decode.maybe
123
123
  |> Decode.map (Maybe.withDefault "")
124
124
  |> Decode.map
125
- (\incorrectPortType ->
125
+ (\incorrectType ->
126
126
  FatalError.recoverable
127
- { title = "Port Error"
127
+ { title = "Custom BackendTask Error"
128
128
  , body =
129
- [ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I found an export called `"
129
+ [ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I found an export called `"
130
130
  , TerminalText.yellow portName
131
131
  , TerminalText.text "` but I expected its type to be function, but instead its type was: "
132
- , TerminalText.red incorrectPortType
132
+ , TerminalText.red incorrectType
133
133
  ]
134
134
  |> TerminalText.toString
135
135
  }
136
136
  ExportIsNotFunction
137
137
  )
138
138
 
139
- else if errorKind == "MissingPortsFile" then
139
+ else if errorKind == "MissingCustomBackendTaskFile" then
140
140
  FatalError.recoverable
141
- { title = "Port Error"
141
+ { title = "Custom BackendTask Error"
142
142
  , body =
143
- [ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I couldn't find your port-data-source file. Be sure to create a 'port-data-source.ts' or 'port-data-source.js' file."
143
+ [ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I couldn't find your custom-backend-task file. Be sure to create a 'custom-backend-task.ts' or 'custom-backend-task.js' file."
144
144
  ]
145
145
  |> TerminalText.toString
146
146
  }
147
- MissingPortsFile
147
+ MissingCustomBackendTaskFile
148
148
  |> Decode.succeed
149
149
 
150
- else if errorKind == "ErrorInPortsFile" then
150
+ else if errorKind == "ErrorInCustomBackendTaskFile" then
151
151
  Decode.field "error" Decode.string
152
152
  |> Decode.maybe
153
153
  |> Decode.map (Maybe.withDefault "")
154
154
  |> Decode.map
155
155
  (\errorMessage ->
156
156
  FatalError.recoverable
157
- { title = "Port Error"
157
+ { title = "Custom BackendTask Error"
158
158
  , body =
159
- [ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I couldn't import the port definitions file, because of this exception:\n\n"
159
+ [ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I couldn't import the port definitions file, because of this exception:\n\n"
160
160
  , TerminalText.red errorMessage
161
161
  , TerminalText.text "\n\nAre there syntax errors or exceptions thrown during import?"
162
162
  ]
163
163
  |> TerminalText.toString
164
164
  }
165
- ErrorInPortsFile
165
+ ErrorInCustomBackendTaskFile
166
166
  )
167
167
 
168
- else if errorKind == "PortCallException" then
168
+ else if errorKind == "CustomBackendTaskException" then
169
169
  Decode.field "error" Decode.value
170
170
  |> Decode.maybe
171
171
  |> Decode.map (Maybe.withDefault Encode.null)
172
172
  |> Decode.map
173
173
  (\portCallError ->
174
174
  FatalError.recoverable
175
- { title = "Port Error"
175
+ { title = "Custom BackendTask Error"
176
176
  , body =
177
- [ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I was able to import the port definitions file, but when running it I encountered this exception:\n\n"
177
+ [ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I was able to import the port definitions file, but when running it I encountered this exception:\n\n"
178
178
  , TerminalText.red (Encode.encode 2 portCallError)
179
- , TerminalText.text "\n\nYou could add a `try`/`catch` in your `port-data-source` JavaScript code to handle that error."
179
+ , TerminalText.text "\n\nYou could add a `try`/`catch` in your `custom-backend-task` JavaScript code to handle that error."
180
180
  ]
181
181
  |> TerminalText.toString
182
182
  }
183
- (PortCallException portCallError)
183
+ (CustomBackendTaskException portCallError)
184
184
  )
185
185
 
186
186
  else
187
187
  FatalError.recoverable
188
- { title = "Port Error"
188
+ { title = "Custom BackendTask Error"
189
189
  , body =
190
- [ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I expected to find a port named `"
190
+ [ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I expected to find a port named `"
191
191
  , TerminalText.yellow portName
192
192
  , TerminalText.text "`."
193
193
  ]
194
194
  |> TerminalText.toString
195
195
  }
196
- ErrorInPortsFile
196
+ ErrorInCustomBackendTaskFile
197
197
  |> Decode.succeed
198
198
  )
199
199
  |> Decode.map Err
@@ -207,8 +207,8 @@ get portName input decoder =
207
207
  {-| -}
208
208
  type Error
209
209
  = Error
210
- | ErrorInPortsFile
211
- | MissingPortsFile
212
- | PortNotDefined { name : String }
213
- | PortCallException Decode.Value
210
+ | ErrorInCustomBackendTaskFile
211
+ | MissingCustomBackendTaskFile
212
+ | CustomBackendTaskNotDefined { name : String }
213
+ | CustomBackendTaskException Decode.Value
214
214
  | ExportIsNotFunction
@@ -366,7 +366,7 @@ errorDecoder :
366
366
  String
367
367
  ->
368
368
  Decoder
369
- { fatal : FatalError.FatalError
369
+ { fatal : FatalError
370
370
  , recoverable : FileReadError decoding
371
371
  }
372
372
  errorDecoder filePath =
@@ -16,7 +16,7 @@ A `BackendTask` lets you pull in data from:
16
16
  - Local files ([`BackendTask.File`](BackendTask-File))
17
17
  - HTTP requests ([`BackendTask.Http`](BackendTask-Http))
18
18
  - Globs, i.e. listing out local files based on a pattern like `content/*.txt` ([`BackendTask.Glob`](BackendTask-Glob))
19
- - Ports, i.e. getting JSON data from running custom NodeJS, similar to a port in a vanilla Elm app except run at build-time in NodeJS, rather than at run-time in the browser ([`BackendTask.Port`](BackendTask-Port))
19
+ - Ports, i.e. getting JSON data from running custom NodeJS, similar to a port in a vanilla Elm app except run at build-time in NodeJS, rather than at run-time in the browser ([`BackendTask.Custom`](BackendTask-Custom))
20
20
  - Hardcoded data (`BackendTask.succeed "Hello!"`)
21
21
  - Or any combination of the above, using `BackendTask.map2`, `BackendTask.andThen`, or other combining/continuing helpers from this module
22
22
 
@@ -2,7 +2,7 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), empty, ne
2
2
 
3
3
  import BackendTask exposing (BackendTask)
4
4
  import BuildError exposing (BuildError)
5
- import FatalError exposing (FatalError, Recoverable)
5
+ import FatalError exposing (FatalError)
6
6
  import List.Extra
7
7
  import Pages.Internal.FatalError
8
8
  import Pages.StaticHttp.Request as HashRequest