elm-pages 3.0.0-beta.17 → 3.0.0-beta.19
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/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +36 -30
- package/generator/src/cli.js +30 -23
- package/generator/src/codegen.js +19 -18
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/compile-elm.js +20 -22
- package/generator/src/config.js +2 -4
- package/generator/src/dev-server.js +47 -30
- package/generator/src/dir-helpers.js +9 -25
- package/generator/src/elm-codegen.js +2 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +5 -5
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +14 -15
- package/generator/src/init.js +8 -7
- package/generator/src/pre-render-html.js +11 -12
- package/generator/src/render-worker.js +21 -26
- package/generator/src/render.js +122 -162
- package/generator/src/request-cache.js +13 -8
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +5 -5
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +1 -3
- package/generator/src/vite-utils.js +1 -2
- package/package.json +9 -8
- package/src/BackendTask/Custom.elm +1 -1
- package/src/BackendTask/File.elm +1 -1
- package/src/BackendTask/Glob.elm +4 -2
- package/src/BackendTask/Http.elm +6 -6
- package/src/FatalError.elm +2 -14
- package/src/Form.elm +26 -47
- package/src/Pages/Generate.elm +42 -13
- package/src/Pages/Internal/Form.elm +14 -1
- package/src/Pages/Internal/Platform/Cli.elm +8 -6
- package/src/Pages/Internal/Platform/Effect.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +8 -6
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Script.elm +2 -2
- package/src/Server/Request.elm +21 -13
|
File without changes
|
|
Binary file
|
|
@@ -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:
|
|
78
|
+
const flags = { initialSeed: 3718366887, 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
|
|
Binary file
|
|
@@ -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:
|
|
78
|
+
const flags = { initialSeed: 1328864607, 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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// this middleware is only active when (config.base !== '/')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function baseMiddleware(base) {
|
|
4
4
|
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
5
5
|
return function viteBaseMiddleware(req, res, next) {
|
|
6
6
|
// `req.url` only contains the path, since that is what gets passed in the HTTP request.
|
|
@@ -34,11 +34,11 @@ module.exports = function baseMiddleware(base) {
|
|
|
34
34
|
const suggestionUrl = `${base}/${path.slice(1)}`;
|
|
35
35
|
res.end(
|
|
36
36
|
`The server is configured with a public base URL of ${base} - ` +
|
|
37
|
-
|
|
37
|
+
`did you mean to visit ${suggestionUrl} instead?`
|
|
38
38
|
);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
next();
|
|
43
43
|
};
|
|
44
|
-
}
|
|
44
|
+
}
|
package/generator/src/build.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import * as fs from "./dir-helpers.js";
|
|
2
|
+
import * as fsPromises from "fs/promises";
|
|
3
|
+
import { runElmReview } from "./compile-elm.js";
|
|
4
|
+
import { restoreColorSafe } from "./error-formatter.js";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { spawn as spawnCallback } from "cross-spawn";
|
|
7
|
+
import * as codegen from "./codegen.js";
|
|
8
|
+
import * as terser from "terser";
|
|
9
|
+
import * as os from "os";
|
|
10
|
+
import { Worker, SHARE_ENV } from "worker_threads";
|
|
11
|
+
import { ensureDirSync } from "./file-helpers.js";
|
|
12
|
+
import { generateClientFolder } from "./codegen.js";
|
|
13
|
+
import { default as which } from "which";
|
|
14
|
+
import { build } from "vite";
|
|
15
|
+
import * as preRenderHtml from "./pre-render-html.js";
|
|
16
|
+
import * as esbuild from "esbuild";
|
|
17
|
+
import { createHash } from "crypto";
|
|
18
|
+
import { merge_vite_configs } from "./vite-utils.js";
|
|
19
|
+
import { resolveConfig } from "./config.js";
|
|
20
|
+
import { globbySync } from "globby";
|
|
21
|
+
import { fileURLToPath } from "url";
|
|
22
|
+
import { copyFile } from "fs/promises";
|
|
22
23
|
|
|
23
24
|
let pool = [];
|
|
24
25
|
let pagesReady;
|
|
@@ -65,7 +66,7 @@ async function ensureRequiredExecutables() {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
async function run(options) {
|
|
69
|
+
export async function run(options) {
|
|
69
70
|
try {
|
|
70
71
|
await ensureRequiredDirs();
|
|
71
72
|
await ensureRequiredExecutables();
|
|
@@ -110,7 +111,11 @@ async function run(options) {
|
|
|
110
111
|
withoutExtension
|
|
111
112
|
);
|
|
112
113
|
const assetManifestPath = path.join(process.cwd(), "dist/manifest.json");
|
|
113
|
-
const manifest =
|
|
114
|
+
const manifest = (
|
|
115
|
+
await import(assetManifestPath, {
|
|
116
|
+
assert: { type: "json" },
|
|
117
|
+
})
|
|
118
|
+
).default;
|
|
114
119
|
const indexTemplate = await fsPromises.readFile(
|
|
115
120
|
"dist/elm-stuff/elm-pages/index.html",
|
|
116
121
|
"utf-8"
|
|
@@ -161,7 +166,7 @@ async function run(options) {
|
|
|
161
166
|
})
|
|
162
167
|
.catch((error) => {
|
|
163
168
|
const portBackendTaskFileFound =
|
|
164
|
-
|
|
169
|
+
globbySync("./custom-backend-task.*").length > 0;
|
|
165
170
|
if (portBackendTaskFileFound) {
|
|
166
171
|
// don't present error if there are no files matching custom-backend-task
|
|
167
172
|
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
@@ -170,7 +175,7 @@ async function run(options) {
|
|
|
170
175
|
});
|
|
171
176
|
// TODO extract common code for compiling ports file?
|
|
172
177
|
|
|
173
|
-
XMLHttpRequest = {};
|
|
178
|
+
global.XMLHttpRequest = {};
|
|
174
179
|
const compileCli = compileCliApp(options);
|
|
175
180
|
try {
|
|
176
181
|
await compileCli;
|
|
@@ -207,6 +212,7 @@ async function run(options) {
|
|
|
207
212
|
processedIndexTemplate
|
|
208
213
|
);
|
|
209
214
|
} catch (error) {
|
|
215
|
+
console.trace(error);
|
|
210
216
|
if (error) {
|
|
211
217
|
console.error(restoreColorSafe(error));
|
|
212
218
|
}
|
|
@@ -220,6 +226,8 @@ async function run(options) {
|
|
|
220
226
|
*/
|
|
221
227
|
function initWorker(basePath, whenDone) {
|
|
222
228
|
return new Promise((resolve, reject) => {
|
|
229
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
230
|
+
const __dirname = path.dirname(__filename);
|
|
223
231
|
activeWorkers += 1;
|
|
224
232
|
let newWorker = {
|
|
225
233
|
worker: new Worker(path.join(__dirname, "./render-worker.js"), {
|
|
@@ -369,7 +377,7 @@ function elmOptimizeLevel2(outputPath, cwd) {
|
|
|
369
377
|
|
|
370
378
|
subprocess.on("close", async (code) => {
|
|
371
379
|
if (code === 0) {
|
|
372
|
-
await
|
|
380
|
+
await copyFile(optimizedOutputPath, outputPath);
|
|
373
381
|
resolve();
|
|
374
382
|
} else {
|
|
375
383
|
if (!buildError) {
|
|
@@ -539,7 +547,7 @@ async function runTerser(filePath) {
|
|
|
539
547
|
}
|
|
540
548
|
}
|
|
541
549
|
|
|
542
|
-
async function compileCliApp(options) {
|
|
550
|
+
export async function compileCliApp(options) {
|
|
543
551
|
await spawnElmMake(
|
|
544
552
|
// TODO should be --optimize, but there seems to be an issue with the html to JSON with --optimize
|
|
545
553
|
options.debug ? "debug" : "optimize",
|
|
@@ -595,7 +603,7 @@ function _HtmlAsJson_toJson(html) {
|
|
|
595
603
|
`;
|
|
596
604
|
|
|
597
605
|
await fsPromises.writeFile(
|
|
598
|
-
ELM_FILE_PATH(),
|
|
606
|
+
ELM_FILE_PATH().replace(/\.js$/, ".cjs"),
|
|
599
607
|
elmFileContent
|
|
600
608
|
.replace(
|
|
601
609
|
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
|
|
@@ -671,5 +679,3 @@ function defaultPreloadForFile(file) {
|
|
|
671
679
|
* @param {string} contentJsonString
|
|
672
680
|
* @returns {string}
|
|
673
681
|
*/
|
|
674
|
-
|
|
675
|
-
module.exports = { run, compileCliApp };
|
package/generator/src/cli.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
import * as build from "./build.js";
|
|
5
|
+
import * as dev from "./dev-server.js";
|
|
6
|
+
import * as init from "./init.js";
|
|
7
|
+
import * as codegen from "./codegen.js";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import { restoreColorSafe } from "./error-formatter.js";
|
|
11
|
+
import * as renderer from "./render.js";
|
|
12
|
+
import { globbySync } from "globby";
|
|
13
|
+
import * as esbuild from "esbuild";
|
|
14
|
+
import { rewriteElmJson } from "./rewrite-elm-json.js";
|
|
15
|
+
import { ensureDirSync, deleteIfExists } from "./file-helpers.js";
|
|
16
|
+
|
|
17
|
+
import * as commander from "commander";
|
|
18
|
+
import { runElmCodegenInstall } from "./elm-codegen.js";
|
|
2
19
|
|
|
3
|
-
const build = require("./build.js");
|
|
4
|
-
const dirHelpers = require("./dir-helpers.js");
|
|
5
|
-
const dev = require("./dev-server.js");
|
|
6
|
-
const init = require("./init.js");
|
|
7
|
-
const codegen = require("./codegen.js");
|
|
8
|
-
const fs = require("fs");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const { restoreColorSafe } = require("./error-formatter");
|
|
11
|
-
const renderer = require("../../generator/src/render");
|
|
12
|
-
const globby = require("globby");
|
|
13
|
-
const esbuild = require("esbuild");
|
|
14
|
-
const copyModifiedElmJson = require("./rewrite-elm-json.js");
|
|
15
|
-
const { ensureDirSync, deleteIfExists } = require("./file-helpers.js");
|
|
16
|
-
|
|
17
|
-
const commander = require("commander");
|
|
18
|
-
const { runElmCodegenInstall } = require("./elm-codegen.js");
|
|
19
20
|
const Argument = commander.Argument;
|
|
20
21
|
const Option = commander.Option;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
import * as packageJson from "../../package.json" assert { type: "json" };
|
|
24
|
+
const packageVersion = packageJson.version;
|
|
23
25
|
|
|
24
26
|
async function main() {
|
|
25
27
|
const program = new commander.Command();
|
|
@@ -124,7 +126,7 @@ async function main() {
|
|
|
124
126
|
path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
|
|
125
127
|
generatorWrapperFile(moduleName)
|
|
126
128
|
);
|
|
127
|
-
await
|
|
129
|
+
await rewriteElmJson(
|
|
128
130
|
"./script/elm.json",
|
|
129
131
|
"./script/elm-stuff/elm-pages/elm.json"
|
|
130
132
|
);
|
|
@@ -151,7 +153,7 @@ async function main() {
|
|
|
151
153
|
})
|
|
152
154
|
.catch((error) => {
|
|
153
155
|
const portBackendTaskFileFound =
|
|
154
|
-
|
|
156
|
+
globbySync("./custom-backend-task.*").length > 0;
|
|
155
157
|
if (portBackendTaskFileFound) {
|
|
156
158
|
// don't present error if there are no files matching custom-backend-task
|
|
157
159
|
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
@@ -169,10 +171,15 @@ async function main() {
|
|
|
169
171
|
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
170
172
|
await build.compileCliApp({ debug: "debug" });
|
|
171
173
|
process.chdir("../");
|
|
174
|
+
fs.renameSync(
|
|
175
|
+
"./script/elm-stuff/elm-pages/elm.js",
|
|
176
|
+
"./script/elm-stuff/elm-pages/elm.cjs"
|
|
177
|
+
);
|
|
172
178
|
await renderer.runGenerator(
|
|
173
179
|
unprocessedCliOptions,
|
|
174
180
|
resolvedPortsPath,
|
|
175
|
-
requireElm("./script/elm-stuff/elm-pages/elm.
|
|
181
|
+
await requireElm("./script/elm-stuff/elm-pages/elm.cjs"),
|
|
182
|
+
moduleName
|
|
176
183
|
);
|
|
177
184
|
} catch (error) {
|
|
178
185
|
console.log(restoreColorSafe(error));
|
|
@@ -186,7 +193,7 @@ async function main() {
|
|
|
186
193
|
.option("--port <number>", "serve site at localhost:<port>", "8000")
|
|
187
194
|
.action(async (options) => {
|
|
188
195
|
await codegen.generate("/");
|
|
189
|
-
const DocServer =
|
|
196
|
+
const DocServer = (await import("elm-doc-preview")).default;
|
|
190
197
|
const server = new DocServer({
|
|
191
198
|
port: options.port,
|
|
192
199
|
browser: true,
|
|
@@ -256,11 +263,11 @@ function normalizeUrl(rawPagePath) {
|
|
|
256
263
|
/**
|
|
257
264
|
* @param {string} compiledElmPath
|
|
258
265
|
*/
|
|
259
|
-
function requireElm(compiledElmPath) {
|
|
266
|
+
async function requireElm(compiledElmPath) {
|
|
260
267
|
const warnOriginal = console.warn;
|
|
261
268
|
console.warn = function () {};
|
|
262
269
|
|
|
263
|
-
Elm =
|
|
270
|
+
let Elm = (await import(path.resolve(compiledElmPath))).default;
|
|
264
271
|
console.warn = warnOriginal;
|
|
265
272
|
return Elm;
|
|
266
273
|
}
|
package/generator/src/codegen.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as fsExtra from "fs-extra/esm";
|
|
3
|
+
import { rewriteElmJson } from "./rewrite-elm-json.js";
|
|
4
|
+
import { rewriteClientElmJson } from "./rewrite-client-elm-json.js";
|
|
5
|
+
import { elmPagesCliFile, elmPagesUiFile } from "./elm-file-constants.js";
|
|
6
|
+
import { spawn as spawnCallback } from "cross-spawn";
|
|
7
|
+
import { default as which } from "which";
|
|
8
|
+
import { generateTemplateModuleConnector } from "./generate-template-module-connector.js";
|
|
9
|
+
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { ensureDirSync, deleteIfExists } from "./file-helpers.js";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
13
13
|
global.builtAt = new Date();
|
|
14
14
|
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = path.dirname(__filename);
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* @param {string} basePath
|
|
17
20
|
*/
|
|
18
|
-
async function generate(basePath) {
|
|
21
|
+
export async function generate(basePath) {
|
|
19
22
|
const cliCode = await generateTemplateModuleConnector(basePath, "cli");
|
|
20
23
|
const browserCode = await generateTemplateModuleConnector(
|
|
21
24
|
basePath,
|
|
@@ -63,7 +66,7 @@ async function generate(basePath) {
|
|
|
63
66
|
browserCode.fetcherModules
|
|
64
67
|
),
|
|
65
68
|
// write modified elm.json to elm-stuff/elm-pages/
|
|
66
|
-
|
|
69
|
+
rewriteElmJson("./elm.json", "./elm-stuff/elm-pages/elm.json"),
|
|
67
70
|
// ...(await listFiles("./Pages/Internal")).map(copyToBoth),
|
|
68
71
|
]);
|
|
69
72
|
}
|
|
@@ -85,7 +88,7 @@ async function newCopyBoth(modulePath) {
|
|
|
85
88
|
);
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
async function generateClientFolder(basePath) {
|
|
91
|
+
export async function generateClientFolder(basePath) {
|
|
89
92
|
const browserCode = await generateTemplateModuleConnector(
|
|
90
93
|
basePath,
|
|
91
94
|
"browser"
|
|
@@ -97,7 +100,7 @@ async function generateClientFolder(basePath) {
|
|
|
97
100
|
await newCopyBoth("SharedTemplate.elm");
|
|
98
101
|
await newCopyBoth("SiteConfig.elm");
|
|
99
102
|
|
|
100
|
-
await
|
|
103
|
+
await rewriteClientElmJson();
|
|
101
104
|
await fsExtra.copy("./app", "./elm-stuff/elm-pages/client/app", {
|
|
102
105
|
recursive: true,
|
|
103
106
|
});
|
|
@@ -230,5 +233,3 @@ async function listFiles(dir) {
|
|
|
230
233
|
function merge(arrays) {
|
|
231
234
|
return [].concat.apply([], arrays);
|
|
232
235
|
}
|
|
233
|
-
|
|
234
|
-
module.exports = { generate, generateClientFolder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export const compatibilityKey = 6;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"browser-elm.js"
|
|
12
|
-
);
|
|
1
|
+
import { spawn as spawnCallback } from "cross-spawn";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as fsHelpers from "./dir-helpers.js";
|
|
4
|
+
import * as fsPromises from "fs/promises";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import * as kleur from "kleur/colors";
|
|
7
|
+
import { inject } from "elm-hot";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
13
11
|
|
|
14
|
-
async function compileElmForBrowser(options) {
|
|
12
|
+
export async function compileElmForBrowser(options) {
|
|
13
|
+
// TODO do I need to make sure this is run from the right cwd? Before it was run outside of this function in the global scope, need to make sure that doesn't change semantics.
|
|
14
|
+
const pathToClientElm = path.join(
|
|
15
|
+
process.cwd(),
|
|
16
|
+
"elm-stuff/elm-pages/",
|
|
17
|
+
"browser-elm.js"
|
|
18
|
+
);
|
|
15
19
|
await runElm(options, "./.elm-pages/Main.elm", pathToClientElm);
|
|
16
20
|
return fs.promises.writeFile(
|
|
17
21
|
"./.elm-pages/cache/elm.js",
|
|
@@ -26,7 +30,7 @@ async function compileElmForBrowser(options) {
|
|
|
26
30
|
);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
async function compileCliApp(
|
|
33
|
+
export async function compileCliApp(
|
|
30
34
|
options,
|
|
31
35
|
elmEntrypointPath,
|
|
32
36
|
outputPath,
|
|
@@ -79,7 +83,7 @@ function _HtmlAsJson_toJson(html) {
|
|
|
79
83
|
`;
|
|
80
84
|
|
|
81
85
|
await fsPromises.writeFile(
|
|
82
|
-
readFrom,
|
|
86
|
+
readFrom.replace(/\.js$/, ".cjs"),
|
|
83
87
|
elmFileContent
|
|
84
88
|
.replace(
|
|
85
89
|
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
|
|
@@ -211,7 +215,7 @@ async function runElm(options, elmEntrypointPath, outputPath, cwd) {
|
|
|
211
215
|
/**
|
|
212
216
|
* @param {string} [ cwd ]
|
|
213
217
|
*/
|
|
214
|
-
async function runElmReview(cwd) {
|
|
218
|
+
export async function runElmReview(cwd) {
|
|
215
219
|
const startTime = Date.now();
|
|
216
220
|
return new Promise((resolve, reject) => {
|
|
217
221
|
const child = spawnCallback(
|
|
@@ -284,12 +288,6 @@ function elmOptimizeLevel2(outputPath, cwd) {
|
|
|
284
288
|
});
|
|
285
289
|
}
|
|
286
290
|
|
|
287
|
-
module.exports = {
|
|
288
|
-
compileElmForBrowser,
|
|
289
|
-
runElmReview,
|
|
290
|
-
compileCliApp,
|
|
291
|
-
};
|
|
292
|
-
|
|
293
291
|
/**
|
|
294
292
|
* @param {number} start
|
|
295
293
|
* @param {number} subtract
|
package/generator/src/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as path from "path";
|
|
2
2
|
|
|
3
|
-
async function resolveConfig() {
|
|
3
|
+
export async function resolveConfig() {
|
|
4
4
|
const initialConfig = await await import(
|
|
5
5
|
path.join(process.cwd(), "elm-pages.config.mjs")
|
|
6
6
|
)
|
|
@@ -37,5 +37,3 @@ function defaultHeadTagsTemplate(context) {
|
|
|
37
37
|
<meta name="generator" content="elm-pages v${context.cliVersion}" />
|
|
38
38
|
`;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
module.exports = { resolveConfig };
|
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { default as which } from "which";
|
|
4
|
+
import * as chokidar from "chokidar";
|
|
5
|
+
import { URL } from "url";
|
|
6
|
+
import {
|
|
7
7
|
compileElmForBrowser,
|
|
8
8
|
runElmReview,
|
|
9
9
|
compileCliApp,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
} from "./compile-elm.js";
|
|
11
|
+
import * as http from "http";
|
|
12
|
+
import * as https from "https";
|
|
13
|
+
import * as codegen from "./codegen.js";
|
|
14
|
+
import * as kleur from "kleur/colors";
|
|
15
|
+
import { default as serveStatic } from "serve-static";
|
|
16
|
+
import { default as connect } from "connect";
|
|
17
|
+
import { restoreColorSafe } from "./error-formatter.js";
|
|
18
|
+
import { Worker, SHARE_ENV } from "worker_threads";
|
|
19
|
+
import * as os from "os";
|
|
20
|
+
import { ensureDirSync } from "./file-helpers.js";
|
|
21
|
+
import { baseMiddleware } from "./basepath-middleware.js";
|
|
22
|
+
import * as devcert from "devcert";
|
|
23
|
+
import * as busboy from "busboy";
|
|
24
|
+
import { createServer as createViteServer } from "vite";
|
|
25
|
+
import * as esbuild from "esbuild";
|
|
26
|
+
import { merge_vite_configs } from "./vite-utils.js";
|
|
27
|
+
import { templateHtml } from "./pre-render-html.js";
|
|
28
|
+
import { resolveConfig } from "./config.js";
|
|
29
|
+
import { globbySync } from "globby";
|
|
30
|
+
import * as packageJson from "../../package.json" assert { type: "json" };
|
|
31
|
+
import { fileURLToPath } from "url";
|
|
32
|
+
|
|
33
|
+
const cliVersion = packageJson.version;
|
|
34
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
35
|
+
const __dirname = path.dirname(__filename);
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
38
|
* @param {{ port: string; base: string; https: boolean; debug: boolean; }} options
|
|
34
39
|
*/
|
|
35
|
-
async function start(options) {
|
|
40
|
+
export async function start(options) {
|
|
36
41
|
let threadReadyQueue = [];
|
|
37
42
|
let pool = [];
|
|
43
|
+
|
|
44
|
+
function restartPool() {
|
|
45
|
+
pool.forEach((thread) => thread.worker.terminate());
|
|
46
|
+
const poolSize = Math.max(1, cpuCount / 2 - 1);
|
|
47
|
+
pool = [];
|
|
48
|
+
|
|
49
|
+
for (let index = 0; index < poolSize; index++) {
|
|
50
|
+
pool.push(initWorker(options.base));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
38
54
|
ensureDirSync(path.join(process.cwd(), ".elm-pages", "http-response-cache"));
|
|
39
55
|
const cpuCount = os.cpus().length;
|
|
40
56
|
|
|
@@ -46,6 +62,7 @@ async function start(options) {
|
|
|
46
62
|
const serveCachedFiles = serveStatic(".elm-pages/cache", { index: false });
|
|
47
63
|
const generatedFilesDirectory = "elm-stuff/elm-pages/generated-files";
|
|
48
64
|
fs.mkdirSync(generatedFilesDirectory, { recursive: true });
|
|
65
|
+
|
|
49
66
|
const serveStaticCode = serveStatic(
|
|
50
67
|
path.join(__dirname, "../static-code"),
|
|
51
68
|
{}
|
|
@@ -175,7 +192,7 @@ async function start(options) {
|
|
|
175
192
|
})
|
|
176
193
|
.catch((error) => {
|
|
177
194
|
const portBackendTaskFileFound =
|
|
178
|
-
|
|
195
|
+
globbySync("./custom-backend-task.*").length > 0;
|
|
179
196
|
if (portBackendTaskFileFound) {
|
|
180
197
|
// don't present error if there are no files matching custom-backend-task
|
|
181
198
|
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
@@ -246,6 +263,7 @@ async function start(options) {
|
|
|
246
263
|
}
|
|
247
264
|
}
|
|
248
265
|
elmMakeRunning = true;
|
|
266
|
+
restartPool();
|
|
249
267
|
if (codegenError) {
|
|
250
268
|
const errorJson = JSON.stringify({
|
|
251
269
|
type: "compile-errors",
|
|
@@ -784,4 +802,3 @@ function paramsToObject(entries) {
|
|
|
784
802
|
}
|
|
785
803
|
return result;
|
|
786
804
|
}
|
|
787
|
-
module.exports = { start };
|