elm-pages 3.0.19 → 3.0.21

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.
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  - [elm-pages Docs Site](https://elm-pages.com/docs)
13
13
  - [elm-pages site showcase](https://elm-pages.com/showcase/)
14
- - [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.1.0/)
14
+ - [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.2.0/)
15
15
  - [Quick start repo](https://github.com/dillonkearns/elm-pages-starter) [(live site hosted here)](https://elm-pages-starter.netlify.com)
16
16
  - [Introducing `elm-pages` blog post](https://elm-pages.com/blog/introducing-elm-pages)
17
17
  - [`examples` folder](https://github.com/dillonkearns/elm-pages/blob/master/examples/) (includes https://elm-pages.com site source) Use `git clone --recurse-submodules https://github.com/dillonkearns/elm-pages.git` so that there aren't missing files when you try to build the examples.
@@ -10,8 +10,8 @@
10
10
  "elm/core": "1.0.5",
11
11
  "elm/json": "1.1.3",
12
12
  "elm-community/result-extra": "2.4.0",
13
- "jfmengels/elm-review": "2.14.0",
14
- "stil4m/elm-syntax": "7.3.2"
13
+ "jfmengels/elm-review": "2.15.1",
14
+ "stil4m/elm-syntax": "7.3.8"
15
15
  },
16
16
  "indirect": {
17
17
  "elm/bytes": "1.0.8",
@@ -23,7 +23,6 @@
23
23
  "elm/time": "1.0.0",
24
24
  "elm/virtual-dom": "1.0.3",
25
25
  "elm-explorations/test": "2.2.0",
26
- "miniBill/elm-unicode": "1.1.1",
27
26
  "rtfeldman/elm-hex": "1.0.0",
28
27
  "stil4m/structured-writer": "1.0.3"
29
28
  }
@@ -143,7 +143,7 @@ placeholder moduleName =
143
143
  , details =
144
144
  [ "" ]
145
145
  , under =
146
- """import Html.Styled as Html"""
146
+ """import Html.Styled as Html exposing (Html)"""
147
147
  }
148
148
  |> Review.Test.whenFixed
149
149
  """module View exposing (View, map, placeholder)
@@ -11,9 +11,9 @@
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.14.0",
15
- "mdgriffith/elm-codegen": "5.0.0",
16
- "stil4m/elm-syntax": "7.3.2",
14
+ "jfmengels/elm-review": "2.15.1",
15
+ "mdgriffith/elm-codegen": "5.2.0",
16
+ "stil4m/elm-syntax": "7.3.8",
17
17
  "the-sett/elm-syntax-dsl": "6.0.3"
18
18
  },
19
19
  "indirect": {
@@ -30,7 +30,7 @@
30
30
  "miniBill/elm-unicode": "1.1.1",
31
31
  "rtfeldman/elm-hex": "1.0.0",
32
32
  "stil4m/structured-writer": "1.0.3",
33
- "the-sett/elm-pretty-printer": "3.1.0"
33
+ "the-sett/elm-pretty-printer": "3.1.1"
34
34
  }
35
35
  },
36
36
  "test-dependencies": {
@@ -73,7 +73,11 @@ export async function run(options) {
73
73
  // This is a temporary hack to avoid this warning. elm-pages manages compiling the Elm code without Vite's involvement, so it is external to Vite.
74
74
  // There is a pending issue to allow having external scripts in Vite, once this issue is fixed we can remove this hack:
75
75
  // https://github.com/vitejs/vite/issues/3533
76
- if (messages && messages[0] && !messages[0].startsWith(`<script src="/elm.js">`)) {
76
+ if (
77
+ messages &&
78
+ messages[0] &&
79
+ !messages[0].startsWith(`<script src="/elm.js">`)
80
+ ) {
77
81
  console.info(...messages);
78
82
  }
79
83
  };
@@ -97,13 +101,11 @@ export async function run(options) {
97
101
  configFile: false,
98
102
  root: process.cwd(),
99
103
  base: options.base,
100
- assetsInclude: [
101
- '/elm-pages.js'
102
- ],
104
+ assetsInclude: ["/elm-pages.js"],
103
105
  ssr: false,
104
106
 
105
107
  build: {
106
- manifest: '___vite-manifest___.json',
108
+ manifest: "___vite-manifest___.json",
107
109
  outDir: "dist",
108
110
  rollupOptions: {
109
111
  input: "elm-stuff/elm-pages/index.html",
@@ -126,7 +128,10 @@ export async function run(options) {
126
128
  fullOutputPath,
127
129
  withoutExtension
128
130
  );
129
- const assetManifestPath = path.join(process.cwd(), "dist/___vite-manifest___.json");
131
+ const assetManifestPath = path.join(
132
+ process.cwd(),
133
+ "dist/___vite-manifest___.json"
134
+ );
130
135
  const manifest = JSON.parse(
131
136
  await fsPromises.readFile(assetManifestPath, { encoding: "utf-8" })
132
137
  );
@@ -292,7 +297,7 @@ export async function render(request) {
292
297
  processedIndexTemplate
293
298
  );
294
299
  } catch (error) {
295
- if(error) {
300
+ if (error) {
296
301
  console.error(restoreColorSafe(error));
297
302
  }
298
303
  buildError = true;
@@ -486,9 +491,7 @@ async function spawnElmMake(mode, options, elmEntrypointPath, outputPath, cwd) {
486
491
  }
487
492
  await fsPromises.writeFile(
488
493
  outputPath,
489
- (
490
- await fsPromises.readFile(outputPath, "utf-8")
491
- ).replace(
494
+ (await fsPromises.readFile(outputPath, "utf-8")).replace(
492
495
  /return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_FORM_TO_STRING.\)/g,
493
496
  "function appendSubmitter (myFormData, event) { event.submitter && event.submitter.name && event.submitter.name.length > 0 ? myFormData.append(event.submitter.name, event.submitter.value) : myFormData; return myFormData }; return " +
494
497
  (options.debug
@@ -685,19 +688,26 @@ function _HtmlAsJson_toJson(html) {
685
688
 
686
689
  await fsPromises.writeFile(
687
690
  ELM_FILE_PATH().replace(/\.js$/, ".cjs"),
688
- applyScriptPatches(options, elmFileContent
689
- .replace(
690
- /return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
691
- `return ${forceThunksSource}
691
+ applyScriptPatches(
692
+ options,
693
+ elmFileContent
694
+ .replace(
695
+ /return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
696
+ `return ${forceThunksSource}
692
697
  return _Json_wrap(forceThunks(html));
693
698
  `
694
- )
695
- .replace(`console.log('App dying')`, "")));
699
+ )
700
+ .replace(`console.log('App dying')`, "")
701
+ )
702
+ );
696
703
  }
697
704
 
698
705
  function applyScriptPatches(options, input) {
699
706
  if (options.isScript) {
700
- return input.replace(`_Debug_crash(8, moduleName, region, message)`, "console.error('TODO in module `' + moduleName + '` ' + _Debug_regionToString(region) + '\\n\\n' + message); process.exitCode = 1; debugger; throw 'CRASH!';");
707
+ return input.replace(
708
+ `_Debug_crash(8, moduleName, region, message)`,
709
+ "console.error('TODO in module `' + moduleName + '` ' + _Debug_regionToString(region) + '\\n\\n' + message); process.exitCode = 1; debugger; throw 'CRASH!';"
710
+ );
701
711
  } else {
702
712
  return input;
703
713
  }
@@ -344,7 +344,9 @@ async function requireElm(compiledElmPath) {
344
344
  const warnOriginal = console.warn;
345
345
  console.warn = function () {};
346
346
 
347
- let Elm = (await import(url.pathToFileURL(path.resolve(compiledElmPath)).href)).default;
347
+ let Elm = (
348
+ await import(url.pathToFileURL(path.resolve(compiledElmPath)).href)
349
+ ).default;
348
350
  console.warn = warnOriginal;
349
351
  return Elm;
350
352
  }
@@ -1,3 +1,3 @@
1
1
  export const compatibilityKey = 22;
2
2
 
3
- export const packageVersion = "3.0.19";
3
+ export const packageVersion = "3.0.21";
@@ -37,7 +37,11 @@ const __dirname = path.dirname(__filename);
37
37
  */
38
38
  export async function start(options) {
39
39
  console.error = function (...messages) {
40
- if (messages && messages[0] && !messages[0].startsWith("Failed to load url")) {
40
+ if (
41
+ messages &&
42
+ messages[0] &&
43
+ !messages[0].startsWith("Failed to load url")
44
+ ) {
41
45
  console.info(...messages);
42
46
  }
43
47
  };
@@ -175,9 +179,7 @@ export async function start(options) {
175
179
  base: options.base,
176
180
  port: options.port,
177
181
  },
178
- assetsInclude: [
179
- '/elm-pages.js'
180
- ],
182
+ assetsInclude: ["/elm-pages.js"],
181
183
  appType: "custom",
182
184
  configFile: false,
183
185
  root: process.cwd(),
@@ -66,7 +66,9 @@ export async function generateTemplateModuleConnector(basePath, phase) {
66
66
  async function runElmCodegenCli(templates, basePath, phase) {
67
67
  const __filename = fileURLToPath(import.meta.url);
68
68
  const __dirname = path.dirname(__filename);
69
- const filePath = pathToFileURL(path.join(__dirname, `../../codegen/elm-pages-codegen.cjs`)).href;
69
+ const filePath = pathToFileURL(
70
+ path.join(__dirname, `../../codegen/elm-pages-codegen.cjs`)
71
+ ).href;
70
72
 
71
73
  const promise = new Promise(async (resolve, reject) => {
72
74
  const elmPagesCodegen = (await import(filePath)).default.Elm.Generate;
@@ -48,11 +48,12 @@ export function templateHtml(devMode, userHeadTagsTemplate) {
48
48
  ${indent(userHeadTagsTemplate({ cliVersion: packageVersion }))}
49
49
  <!-- PLACEHOLDER_HEAD_AND_DATA -->
50
50
  </head>
51
- <body>
52
- <div data-url="" display="none"></div>
53
- <!-- PLACEHOLDER_HTML -->
54
- </body>
55
- </html>`;
51
+ <body><div data-elm data-url="" style="display: none;"></div><div data-elm id="elm-pages-announcer" aria-live="assertive" aria-atomic="true" style="position: absolute; top: 0; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); whiteSpace: nowrap; border: 0;"></div><!-- PLACEHOLDER_HTML --></body></html>`;
52
+ // NOTE: The above line needs to:
53
+ // - Be in sync with `view` in Platform.elm (render the same elements).
54
+ // - Have `data-elm` on each child of `<body>`.
55
+ // - Not include any extra whitespace. Even whitespace between </body> and </html> is parsed by browsers as a text node _inside_ <body>.
56
+ // This is to avoid unnecessary rerenders on init (when the first `view` call is diffed with the virtualized form of the above HTML).
56
57
  }
57
58
 
58
59
  /**
@@ -21,6 +21,14 @@ export function lookupOrPerform(
21
21
  hasFsAccess,
22
22
  useCache
23
23
  ) {
24
+ const uniqueTimeId =
25
+ Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
26
+ const timeStart = (message) => {
27
+ !rawRequest.quiet && console.time(`${message} ${uniqueTimeId}`);
28
+ };
29
+ const timeEnd = (message) => {
30
+ !rawRequest.quiet && console.timeEnd(`${message} ${uniqueTimeId}`);
31
+ };
24
32
  const makeFetchHappen = makeFetchHappenOriginal.defaults({
25
33
  cache: mode === "build" ? "no-cache" : "default",
26
34
  });
@@ -92,8 +100,7 @@ export function lookupOrPerform(
92
100
  }),
93
101
  });
94
102
  } else {
95
- !rawRequest.quiet &&
96
- console.time(`BackendTask.Custom.run "${portName}"`);
103
+ timeStart(`BackendTask.Custom.run "${portName}"`);
97
104
  let context = {
98
105
  cwd: path.resolve(...rawRequest.dir),
99
106
  quiet: rawRequest.quiet,
@@ -135,8 +142,7 @@ export function lookupOrPerform(
135
142
  });
136
143
  }
137
144
  }
138
- !rawRequest.quiet &&
139
- console.timeEnd(`BackendTask.Custom.run "${portName}"`);
145
+ timeEnd(`BackendTask.Custom.run "${portName}"`);
140
146
  }
141
147
  } catch (error) {
142
148
  console.trace(error);
@@ -147,7 +153,7 @@ export function lookupOrPerform(
147
153
  }
148
154
  } else {
149
155
  try {
150
- !rawRequest.quiet && console.time(`fetch ${request.url}`);
156
+ timeStart(`fetch ${request.url}`);
151
157
  const response = await safeFetch(makeFetchHappen, request.url, {
152
158
  method: request.method,
153
159
  body: request.body,
@@ -158,7 +164,7 @@ export function lookupOrPerform(
158
164
  ...rawRequest.cacheOptions,
159
165
  });
160
166
 
161
- !rawRequest.quiet && console.timeEnd(`fetch ${request.url}`);
167
+ timeEnd(`fetch ${request.url}`);
162
168
  const expectString = request.headers["elm-pages-internal"];
163
169
 
164
170
  let body;
@@ -1,25 +1,31 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- import * as readline from 'readline';
3
+ import * as readline from "readline";
4
4
  import * as chalk from "kleur/colors";
5
- import cliCursor from 'cli-cursor';
6
-
7
-
8
- import { purgeSpinnerOptions, purgeSpinnersOptions, colorOptions, breakText, getLinesLength, terminalSupportsUnicode } from './utils.js';
9
- import { dots, dashes, writeStream, cleanStream } from './utils.js';
5
+ import cliCursor from "cli-cursor";
6
+
7
+ import {
8
+ purgeSpinnerOptions,
9
+ purgeSpinnersOptions,
10
+ colorOptions,
11
+ breakText,
12
+ getLinesLength,
13
+ terminalSupportsUnicode,
14
+ } from "./utils.js";
15
+ import { dots, dashes, writeStream, cleanStream } from "./utils.js";
10
16
 
11
17
  export class Spinnies {
12
18
  constructor(options = {}) {
13
19
  options = purgeSpinnersOptions(options);
14
20
  this.options = {
15
- // TODO kleur doesn't support brightGreen, only nested function or chained syntax
16
- // spinnerColor: 'brightGreen',
17
- spinnerColor: 'green',
18
- succeedColor: 'green',
19
- failColor: 'red',
21
+ // TODO kleur doesn't support brightGreen, only nested function or chained syntax
22
+ // spinnerColor: 'brightGreen',
23
+ spinnerColor: "green",
24
+ succeedColor: "green",
25
+ failColor: "red",
20
26
  spinner: terminalSupportsUnicode() ? dots : dashes,
21
27
  disableSpins: false,
22
- ...options
28
+ ...options,
23
29
  };
24
30
  this.spinners = {};
25
31
  this.isCursorHidden = false;
@@ -27,7 +33,11 @@ export class Spinnies {
27
33
  this.stream = process.stderr;
28
34
  this.lineCount = 0;
29
35
  this.currentFrameIndex = 0;
30
- this.spin = !this.options.disableSpins && !process.env.CI && process.stderr && process.stderr.isTTY;
36
+ this.spin =
37
+ !this.options.disableSpins &&
38
+ !process.env.CI &&
39
+ process.stderr &&
40
+ process.stderr.isTTY;
31
41
  this.bindSigint();
32
42
  }
33
43
 
@@ -36,13 +46,14 @@ export class Spinnies {
36
46
  }
37
47
 
38
48
  add(name, options = {}) {
39
- if (typeof name !== 'string') throw Error('A spinner reference name must be specified');
49
+ if (typeof name !== "string")
50
+ throw Error("A spinner reference name must be specified");
40
51
  if (!options.text) options.text = name;
41
52
  const spinnerProperties = {
42
53
  ...colorOptions(this.options),
43
54
  succeedPrefix: this.options.succeedPrefix,
44
55
  failPrefix: this.options.failPrefix,
45
- status: 'spinning',
56
+ status: "spinning",
46
57
  ...purgeSpinnerOptions(options),
47
58
  };
48
59
 
@@ -61,37 +72,42 @@ export class Spinnies {
61
72
  }
62
73
 
63
74
  succeed(name, options = {}) {
64
- this.setSpinnerProperties(name, options, 'succeed');
75
+ this.setSpinnerProperties(name, options, "succeed");
65
76
  this.updateSpinnerState();
66
77
 
67
78
  return this.spinners[name];
68
79
  }
69
80
 
70
81
  fail(name, options = {}) {
71
- this.setSpinnerProperties(name, options, 'fail');
82
+ this.setSpinnerProperties(name, options, "fail");
72
83
  this.updateSpinnerState();
73
84
 
74
85
  return this.spinners[name];
75
86
  }
76
87
 
77
88
  remove(name) {
78
- if (typeof name !== 'string') throw Error('A spinner reference name must be specified');
89
+ if (typeof name !== "string")
90
+ throw Error("A spinner reference name must be specified");
79
91
  const spinner = this.spinners[name];
80
92
  delete this.spinners[name];
81
93
 
82
94
  return spinner;
83
95
  }
84
96
 
85
- stopAll(newStatus = 'stopped') {
86
- Object.keys(this.spinners).forEach(name => {
97
+ stopAll(newStatus = "stopped") {
98
+ Object.keys(this.spinners).forEach((name) => {
87
99
  const { status: currentStatus } = this.spinners[name];
88
- if (currentStatus !== 'fail' && currentStatus !== 'succeed' && currentStatus !== 'non-spinnable') {
89
- if (newStatus === 'succeed' || newStatus === 'fail') {
100
+ if (
101
+ currentStatus !== "fail" &&
102
+ currentStatus !== "succeed" &&
103
+ currentStatus !== "non-spinnable"
104
+ ) {
105
+ if (newStatus === "succeed" || newStatus === "fail") {
90
106
  this.spinners[name].status = newStatus;
91
107
  this.spinners[name].color = this.options[`${newStatus}Color`];
92
108
  } else {
93
- this.spinners[name].status = 'stopped';
94
- this.spinners[name].color = 'grey';
109
+ this.spinners[name].status = "stopped";
110
+ this.spinners[name].color = "grey";
95
111
  }
96
112
  }
97
113
  });
@@ -101,14 +117,18 @@ export class Spinnies {
101
117
  }
102
118
 
103
119
  hasActiveSpinners() {
104
- return !!Object.values(this.spinners).find(({ status }) => status === 'spinning');
120
+ return !!Object.values(this.spinners).find(
121
+ ({ status }) => status === "spinning"
122
+ );
105
123
  }
106
124
 
107
125
  setSpinnerProperties(name, options, status) {
108
- if (typeof name !== 'string') throw Error('A spinner reference name must be specified');
109
- if (!this.spinners[name]) throw Error(`No spinner initialized with name ${name}`);
126
+ if (typeof name !== "string")
127
+ throw Error("A spinner reference name must be specified");
128
+ if (!this.spinners[name])
129
+ throw Error(`No spinner initialized with name ${name}`);
110
130
  options = purgeSpinnerOptions(options);
111
- status = status || 'spinning';
131
+ status = status || "spinning";
112
132
 
113
133
  this.spinners[name] = { ...this.spinners[name], ...options, status };
114
134
  }
@@ -129,29 +149,41 @@ export class Spinnies {
129
149
  const { frames, interval } = this.options.spinner;
130
150
  return setInterval(() => {
131
151
  this.setStreamOutput(frames[this.currentFrameIndex]);
132
- this.currentFrameIndex = this.currentFrameIndex === frames.length - 1 ? 0 : ++this.currentFrameIndex
152
+ this.currentFrameIndex =
153
+ this.currentFrameIndex === frames.length - 1
154
+ ? 0
155
+ : ++this.currentFrameIndex;
133
156
  }, interval);
134
157
  }
135
158
 
136
- setStreamOutput(frame = '') {
137
- let output = '';
159
+ setStreamOutput(frame = "") {
160
+ let output = "";
138
161
  const linesLength = [];
139
162
  const hasActiveSpinners = this.hasActiveSpinners();
140
- Object
141
- .values(this.spinners)
142
- .map(({ text, status, color, spinnerColor, succeedColor, failColor, succeedPrefix, failPrefix, indent }) => {
163
+ Object.values(this.spinners).map(
164
+ ({
165
+ text,
166
+ status,
167
+ color,
168
+ spinnerColor,
169
+ succeedColor,
170
+ failColor,
171
+ succeedPrefix,
172
+ failPrefix,
173
+ indent,
174
+ }) => {
143
175
  let line;
144
176
  let prefixLength = indent || 0;
145
- if (status === 'spinning') {
177
+ if (status === "spinning") {
146
178
  prefixLength += frame.length + 1;
147
179
  text = breakText(text, prefixLength);
148
180
  line = `${chalk[spinnerColor](frame)} ${color ? chalk[color](text) : text}`;
149
181
  } else {
150
- if (status === 'succeed') {
182
+ if (status === "succeed") {
151
183
  prefixLength += succeedPrefix.length + 1;
152
184
  if (hasActiveSpinners) text = breakText(text, prefixLength);
153
185
  line = `${chalk.green(succeedPrefix)} ${chalk[succeedColor](text)}`;
154
- } else if (status === 'fail') {
186
+ } else if (status === "fail") {
155
187
  prefixLength += failPrefix.length + 1;
156
188
  if (hasActiveSpinners) text = breakText(text, prefixLength);
157
189
  line = `${chalk.red(failPrefix)} ${chalk[failColor](text)}`;
@@ -162,16 +194,17 @@ export class Spinnies {
162
194
  }
163
195
  linesLength.push(...getLinesLength(text, prefixLength));
164
196
  output += indent ? `${" ".repeat(indent)}${line}\n` : `${line}\n`;
165
- });
197
+ }
198
+ );
166
199
 
167
- if(!hasActiveSpinners) readline.clearScreenDown(this.stream);
200
+ if (!hasActiveSpinners) readline.clearScreenDown(this.stream);
168
201
  writeStream(this.stream, output, linesLength);
169
202
  if (hasActiveSpinners) cleanStream(this.stream, linesLength);
170
203
  this.lineCount = linesLength.length;
171
204
  }
172
205
 
173
206
  setRawStreamOutput() {
174
- Object.values(this.spinners).forEach(i => {
207
+ Object.values(this.spinners).forEach((i) => {
175
208
  process.stderr.write(`- ${i.text}\n`);
176
209
  });
177
210
  }
@@ -190,8 +223,8 @@ export class Spinnies {
190
223
  }
191
224
 
192
225
  bindSigint(lines) {
193
- process.removeAllListeners('SIGINT');
194
- process.on('SIGINT', () => {
226
+ process.removeAllListeners("SIGINT");
227
+ process.on("SIGINT", () => {
195
228
  cliCursor.show();
196
229
  readline.moveCursor(process.stderr, 0, this.lineCount);
197
230
  process.exit(0);