@marko/run 0.1.4 → 0.1.6
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/dist/adapter/default-entry.mjs +2 -0
- package/dist/adapter/dev-entry.mjs +36 -0
- package/dist/adapter/dev-server.d.ts +4 -2
- package/dist/adapter/index.cjs +140 -25
- package/dist/adapter/index.d.ts +4 -3
- package/dist/adapter/index.js +137 -24
- package/dist/adapter/load-dev-worker.mjs +37 -0
- package/dist/cli/index.mjs +98 -144
- package/dist/index.html +1 -0
- package/dist/runtime/index.d.ts +3 -2
- package/dist/runtime/router.cjs +13 -7
- package/dist/runtime/router.js +13 -7
- package/dist/vite/index.cjs +58 -30
- package/dist/vite/index.js +58 -30
- package/dist/vite/types.d.ts +15 -3
- package/dist/vite/utils/server.d.ts +8 -2
- package/package.json +15 -7
package/dist/cli/index.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
|
+
import sade from "sade";
|
|
5
|
+
|
|
6
|
+
// src/cli/commands.ts
|
|
4
7
|
import path3 from "path";
|
|
5
|
-
import
|
|
8
|
+
import fs3 from "fs";
|
|
6
9
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7
10
|
import { build as viteBuild, resolveConfig } from "vite";
|
|
8
|
-
import sade from "sade";
|
|
9
11
|
|
|
10
12
|
// src/vite/utils/config.ts
|
|
11
13
|
var PluginConfigKey = "__MARKO_RUN_PLUGIN_CONFIG__";
|
|
@@ -21,82 +23,15 @@ var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfi
|
|
|
21
23
|
var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, PluginConfigKey, value);
|
|
22
24
|
var setExternalAdapterOptions = (viteConfig, value) => setConfig(viteConfig, AdapterConfigKey, value);
|
|
23
25
|
|
|
24
|
-
// src/cli/
|
|
26
|
+
// src/cli/commands.ts
|
|
25
27
|
import { MemoryStore } from "@marko/vite";
|
|
26
28
|
|
|
27
|
-
// src/vite/utils/server.ts
|
|
28
|
-
import net from "net";
|
|
29
|
-
import cp from "child_process";
|
|
30
|
-
import { parse, config } from "dotenv";
|
|
31
|
-
import fs from "fs";
|
|
32
|
-
async function parseEnv(envFile) {
|
|
33
|
-
if (fs.existsSync(envFile)) {
|
|
34
|
-
const content = await fs.promises.readFile(envFile, "utf8");
|
|
35
|
-
return parse(content);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function spawnServer(cmd, port = 0, env, cwd2 = process.cwd(), wait = 3e4) {
|
|
39
|
-
if (port <= 0) {
|
|
40
|
-
port = await getAvailablePort();
|
|
41
|
-
}
|
|
42
|
-
if (typeof env === "string") {
|
|
43
|
-
env = await parseEnv(env);
|
|
44
|
-
}
|
|
45
|
-
const proc = cp.spawn(cmd, {
|
|
46
|
-
cwd: cwd2,
|
|
47
|
-
shell: true,
|
|
48
|
-
stdio: "inherit",
|
|
49
|
-
windowsHide: true,
|
|
50
|
-
env: { ...env, NODE_ENV: "development", ...process.env, PORT: `${port}` }
|
|
51
|
-
});
|
|
52
|
-
const close = () => {
|
|
53
|
-
proc.unref();
|
|
54
|
-
proc.kill();
|
|
55
|
-
};
|
|
56
|
-
let remaining = wait > 0 ? wait : Infinity;
|
|
57
|
-
while (!await isPortInUse(port)) {
|
|
58
|
-
if (remaining >= 100) {
|
|
59
|
-
remaining -= 100;
|
|
60
|
-
await sleep(100);
|
|
61
|
-
} else {
|
|
62
|
-
close();
|
|
63
|
-
throw new Error(
|
|
64
|
-
`site-write: timeout while wating for server to start on port "${port}".`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
port,
|
|
70
|
-
close
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
async function isPortInUse(port) {
|
|
74
|
-
return new Promise((resolve) => {
|
|
75
|
-
const connection = net.connect(port).setNoDelay(true).setKeepAlive(false).on("error", () => done(false)).on("connect", () => done(true));
|
|
76
|
-
function done(connected) {
|
|
77
|
-
connection.end();
|
|
78
|
-
resolve(connected);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async function getAvailablePort() {
|
|
83
|
-
return new Promise((resolve) => {
|
|
84
|
-
const server = net.createServer().listen(0, () => {
|
|
85
|
-
const { port } = server.address();
|
|
86
|
-
server.close(() => resolve(port));
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function sleep(ms) {
|
|
91
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
29
|
// src/vite/plugin.ts
|
|
95
30
|
import path2 from "path";
|
|
96
31
|
import crypto from "crypto";
|
|
97
|
-
import
|
|
32
|
+
import fs2 from "fs";
|
|
98
33
|
import glob from "glob";
|
|
99
|
-
import { mergeConfig
|
|
34
|
+
import { mergeConfig } from "vite";
|
|
100
35
|
import markoVitePlugin, { FileStore } from "@marko/vite";
|
|
101
36
|
|
|
102
37
|
// src/vite/constants.ts
|
|
@@ -122,16 +57,16 @@ var routeableFileRegex = new RegExp(
|
|
|
122
57
|
);
|
|
123
58
|
|
|
124
59
|
// src/vite/routes/walk.ts
|
|
125
|
-
import
|
|
60
|
+
import fs from "fs";
|
|
126
61
|
import path from "path";
|
|
127
62
|
|
|
128
63
|
// src/vite/utils/ast.ts
|
|
129
64
|
import * as t from "@babel/types";
|
|
130
65
|
|
|
131
66
|
// src/vite/utils/log.ts
|
|
67
|
+
import zlib from "node:zlib";
|
|
132
68
|
import Table from "cli-table3";
|
|
133
69
|
import kleur from "kleur";
|
|
134
|
-
import { gzipSizeSync } from "gzip-size";
|
|
135
70
|
import format from "human-format";
|
|
136
71
|
var HttpVerbColors = {
|
|
137
72
|
get: kleur.green,
|
|
@@ -152,6 +87,7 @@ async function resolveAdapter(root, options, log) {
|
|
|
152
87
|
if (adapter !== void 0) {
|
|
153
88
|
return adapter;
|
|
154
89
|
}
|
|
90
|
+
const { resolvePackageData } = await import("vite");
|
|
155
91
|
const pkg = resolvePackageData(".", root);
|
|
156
92
|
if (pkg) {
|
|
157
93
|
const dependecies = { ...pkg.data.dependecies, ...pkg.data.devDependencies };
|
|
@@ -173,48 +109,12 @@ async function resolveAdapter(root, options, log) {
|
|
|
173
109
|
return module.default();
|
|
174
110
|
}
|
|
175
111
|
|
|
176
|
-
// src/cli/
|
|
112
|
+
// src/cli/commands.ts
|
|
177
113
|
var __dirname2 = fileURLToPath2(new URL(".", import.meta.url));
|
|
178
|
-
var cwd = process.cwd();
|
|
179
114
|
var defaultPort = +process.env.PORT || 3e3;
|
|
180
115
|
var defaultConfigFileBases = ["serve.config", "vite.config"];
|
|
181
116
|
var defaultConfigFileExts = [".js", ".cjs", ".mjs", ".ts", ".mts"];
|
|
182
|
-
|
|
183
|
-
"-c, --config",
|
|
184
|
-
`Provide path to a Vite config file (by default looks for a file starting with ${defaultConfigFileBases.join(
|
|
185
|
-
" or "
|
|
186
|
-
)} with one of these extensions: ${defaultConfigFileExts.join(", ")})`
|
|
187
|
-
).option("-e, --env", "Provide path to a dotenv file");
|
|
188
|
-
prog.command("preview [entry]").describe("Start a production-like server for already-built app files").option(
|
|
189
|
-
"-o, --output",
|
|
190
|
-
"Directory to serve files from, and write asset files to if `--build` (default: )"
|
|
191
|
-
).option(
|
|
192
|
-
"-p, --port",
|
|
193
|
-
"Port the server should listen on (defaults: `$PORT` env variable or 3000)"
|
|
194
|
-
).option("-f, --file", "Output file to start").action(async (entry, opts) => {
|
|
195
|
-
process.env.NODE_ENV = "production";
|
|
196
|
-
const config2 = await getViteConfig(cwd, opts.config);
|
|
197
|
-
await build(entry, config2, opts.output, false, opts.env);
|
|
198
|
-
await preview(opts.entry, config2, opts.port, opts.output, opts.env);
|
|
199
|
-
});
|
|
200
|
-
prog.command("dev [entry]", "", { default: true }).describe("Start development server in watch mode").option(
|
|
201
|
-
"-p, --port",
|
|
202
|
-
"Port the dev server should listen on (defaults: 'preview.port' in config, or `$PORT` env variable, or 3000)"
|
|
203
|
-
).example("dev --config vite.config.js").action(async (entry, opts) => {
|
|
204
|
-
const cmd = opts._.length ? `${entry} ${opts._.join(" ")}` : entry ? `node ${entry}` : void 0;
|
|
205
|
-
const config2 = await getViteConfig(cwd, opts.config);
|
|
206
|
-
await dev(cmd, config2, opts.port, opts.env);
|
|
207
|
-
});
|
|
208
|
-
prog.command("build [entry]").describe("Build the application (without serving it)").option(
|
|
209
|
-
"-o, --output",
|
|
210
|
-
"Directory to write built files (default: 'build.outDir' in Vite config)"
|
|
211
|
-
).option("--skip-client", "Skip the client-side build").example("build --config vite.config.js").action(async (entry, opts) => {
|
|
212
|
-
process.env.NODE_ENV = "production";
|
|
213
|
-
const config2 = await getViteConfig(cwd, opts.config);
|
|
214
|
-
await build(entry, config2, opts.ouput, opts["skip-client"], opts.env);
|
|
215
|
-
});
|
|
216
|
-
prog.parse(process.argv);
|
|
217
|
-
async function preview(entry, configFile, port, outDir, envFile) {
|
|
117
|
+
async function preview(entry, cwd, configFile, port, outDir, envFile, args = []) {
|
|
218
118
|
const resolvedConfig = await resolveConfig(
|
|
219
119
|
{ root: cwd, configFile, logLevel: "silent", build: { outDir } },
|
|
220
120
|
"serve"
|
|
@@ -233,9 +133,16 @@ async function preview(entry, configFile, port, outDir, envFile) {
|
|
|
233
133
|
if (envFile) {
|
|
234
134
|
envFile = path3.resolve(cwd, envFile);
|
|
235
135
|
}
|
|
236
|
-
|
|
136
|
+
const options = {
|
|
137
|
+
cwd,
|
|
138
|
+
dir,
|
|
139
|
+
args,
|
|
140
|
+
port,
|
|
141
|
+
envFile
|
|
142
|
+
};
|
|
143
|
+
return await adapter.startPreview(entryFile, options);
|
|
237
144
|
}
|
|
238
|
-
async function dev(
|
|
145
|
+
async function dev(entry, cwd, configFile, port, envFile, args = []) {
|
|
239
146
|
const resolvedConfig = await resolveConfig(
|
|
240
147
|
{ root: cwd, configFile, logLevel: "silent" },
|
|
241
148
|
"build"
|
|
@@ -246,24 +153,25 @@ async function dev(cmd, configFile, port, envFile) {
|
|
|
246
153
|
if (envFile) {
|
|
247
154
|
envFile = path3.resolve(cwd, envFile);
|
|
248
155
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
throw new Error(
|
|
259
|
-
`Adapter '${adapter.name}' does not support 'serve' command`
|
|
260
|
-
);
|
|
261
|
-
} else {
|
|
262
|
-
await adapter.startDev(configFile, port, envFile);
|
|
263
|
-
}
|
|
156
|
+
const adapter = await resolveAdapter2(resolvedConfig);
|
|
157
|
+
if (!adapter) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
"No adapter specified for 'dev' command without custom target"
|
|
160
|
+
);
|
|
161
|
+
} else if (!adapter.startDev) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Adapter '${adapter.name}' does not support 'serve' command`
|
|
164
|
+
);
|
|
264
165
|
}
|
|
166
|
+
const options = {
|
|
167
|
+
cwd,
|
|
168
|
+
args,
|
|
169
|
+
port,
|
|
170
|
+
envFile
|
|
171
|
+
};
|
|
172
|
+
return await adapter.startDev(entry, { root: cwd, configFile }, options);
|
|
265
173
|
}
|
|
266
|
-
async function build(entry, configFile, outDir,
|
|
174
|
+
async function build(entry, cwd, configFile, outDir, envFile) {
|
|
267
175
|
var _a;
|
|
268
176
|
const resolvedConfig = await resolveConfig(
|
|
269
177
|
{ root: cwd, configFile, logLevel: "silent" },
|
|
@@ -311,20 +219,18 @@ async function build(entry, configFile, outDir, skipClient = false, envFile) {
|
|
|
311
219
|
}
|
|
312
220
|
}
|
|
313
221
|
});
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
build
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
});
|
|
322
|
-
}
|
|
222
|
+
await viteBuild({
|
|
223
|
+
...buildConfig,
|
|
224
|
+
build: {
|
|
225
|
+
...buildConfig.build,
|
|
226
|
+
sourcemap: true
|
|
227
|
+
}
|
|
228
|
+
});
|
|
323
229
|
}
|
|
324
230
|
function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
|
|
325
231
|
for (const ext of extensions) {
|
|
326
232
|
const filePath = path3.join(dir, base + ext);
|
|
327
|
-
if (
|
|
233
|
+
if (fs3.existsSync(filePath)) {
|
|
328
234
|
return filePath;
|
|
329
235
|
}
|
|
330
236
|
}
|
|
@@ -333,7 +239,7 @@ function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
|
|
|
333
239
|
async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
|
|
334
240
|
if (configFile) {
|
|
335
241
|
const configFilePath = path3.join(dir, configFile);
|
|
336
|
-
if (!
|
|
242
|
+
if (!fs3.existsSync(configFilePath)) {
|
|
337
243
|
throw new Error(`No config file found at '${configFilePath}'`);
|
|
338
244
|
}
|
|
339
245
|
return configFile;
|
|
@@ -346,10 +252,58 @@ async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
|
|
|
346
252
|
}
|
|
347
253
|
return path3.join(__dirname2, "default.config.mjs");
|
|
348
254
|
}
|
|
349
|
-
async function resolveAdapter2(
|
|
350
|
-
const options = getExternalPluginOptions(
|
|
255
|
+
async function resolveAdapter2(config) {
|
|
256
|
+
const options = getExternalPluginOptions(config);
|
|
351
257
|
if (!options) {
|
|
352
258
|
throw new Error("Unable to resolve @marko/run options");
|
|
353
259
|
}
|
|
354
|
-
return resolveAdapter(
|
|
260
|
+
return resolveAdapter(config.root, options);
|
|
355
261
|
}
|
|
262
|
+
|
|
263
|
+
// src/cli/index.ts
|
|
264
|
+
var prog = sade("marko-run").version("0.0.1").option(
|
|
265
|
+
"-c, --config",
|
|
266
|
+
`Provide path to a Vite config file (by default looks for a file starting with ${defaultConfigFileBases.join(
|
|
267
|
+
" or "
|
|
268
|
+
)} with one of these extensions: ${defaultConfigFileExts.join(", ")})`
|
|
269
|
+
).option("-e, --env", "Provide path to a dotenv file");
|
|
270
|
+
prog.command("preview [entry]").describe("Start a production-like server for already-built app files").option(
|
|
271
|
+
"-o, --output",
|
|
272
|
+
"Directory to serve files from, and write asset files to if `--build` (default: 'build.outDir' in Vite config)"
|
|
273
|
+
).option(
|
|
274
|
+
"-p, --port",
|
|
275
|
+
"Port the server should listen on (defaults: `$PORT` env variable or 3000)"
|
|
276
|
+
).option("-f, --file", "Output file to start").action(async (entry, opts) => {
|
|
277
|
+
process.env.NODE_ENV = "production";
|
|
278
|
+
const cwd = process.cwd();
|
|
279
|
+
const args = process.argv.slice(entry ? 4 : 3);
|
|
280
|
+
const config = await getViteConfig(cwd, opts.config);
|
|
281
|
+
await build(entry, cwd, config, opts.output, opts.env);
|
|
282
|
+
await preview(
|
|
283
|
+
opts.file,
|
|
284
|
+
cwd,
|
|
285
|
+
config,
|
|
286
|
+
opts.port,
|
|
287
|
+
opts.output,
|
|
288
|
+
opts.env,
|
|
289
|
+
args
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
prog.command("dev [entry]", "", { default: true }).describe("Start development server in watch mode").option(
|
|
293
|
+
"-p, --port",
|
|
294
|
+
"Port the dev server should listen on (defaults: 'preview.port' in config, or `$PORT` env variable, or 3000)"
|
|
295
|
+
).example("dev --config vite.config.js").action(async (entry, opts) => {
|
|
296
|
+
const cwd = process.cwd();
|
|
297
|
+
const args = process.argv.slice(entry ? 4 : 3);
|
|
298
|
+
const config = await getViteConfig(cwd, opts.config);
|
|
299
|
+
await dev(entry, cwd, config, opts.port, opts.env, args);
|
|
300
|
+
});
|
|
301
|
+
prog.command("build [entry]").describe("Build the application (without serving it)").option(
|
|
302
|
+
"-o, --output",
|
|
303
|
+
"Directory to write built files (default: 'build.outDir' in Vite config)"
|
|
304
|
+
).example("build --config vite.config.js").action(async (entry, opts) => {
|
|
305
|
+
const cwd = process.cwd();
|
|
306
|
+
const config = await getViteConfig(cwd, opts.config);
|
|
307
|
+
await build(entry, cwd, config, opts.ouput, opts.env);
|
|
308
|
+
});
|
|
309
|
+
prog.parse(process.argv);
|
package/dist/index.html
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!doctype html><html lang=en><head><meta charset=UTF-8><title>@marko/run Test Fixture</title><script async type="module" crossorigin src="/assets/__marko-run__route__index.marko-3cfb730f.js"></script></head><body><div id=app>Page rendered</div></body></html>
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { HandlerLike, ParamsObject, Route as AnyRoute, Context as AnyContext } from "./types";
|
|
1
|
+
import type { HandlerLike, ParamsObject, Route as AnyRoute, Context as AnyContext, RuntimeModule } from "./types";
|
|
2
2
|
declare global {
|
|
3
|
+
var __marko_run__: RuntimeModule;
|
|
3
4
|
namespace MarkoRun {
|
|
4
5
|
const NotHandled: unique symbol;
|
|
5
6
|
const NotMatched: unique symbol;
|
|
6
7
|
interface Route extends AnyRoute {
|
|
7
8
|
}
|
|
8
|
-
interface Context extends AnyContext
|
|
9
|
+
interface Context extends AnyContext {
|
|
9
10
|
}
|
|
10
11
|
type Handler<Params extends ParamsObject = {}, Meta = unknown> = HandlerLike<AnyRoute<Params, Meta, string>>;
|
|
11
12
|
function route<Params extends ParamsObject = {}, Meta = unknown>(handler: Handler<Params, Meta>): typeof handler;
|
package/dist/runtime/router.cjs
CHANGED
|
@@ -25,14 +25,20 @@ __export(router_exports, {
|
|
|
25
25
|
match: () => match
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(router_exports);
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
function fromRuntime(name) {
|
|
29
|
+
return (...args) => {
|
|
30
|
+
const runtime = globalThis.__marko_run__;
|
|
31
|
+
if (!runtime) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"This should have been replaced by the @marko/run plugin at build/dev time"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return runtime[name](...args);
|
|
37
|
+
};
|
|
32
38
|
}
|
|
33
|
-
var fetch =
|
|
34
|
-
var match =
|
|
35
|
-
var invoke =
|
|
39
|
+
var fetch = fromRuntime("fetch");
|
|
40
|
+
var match = fromRuntime("match");
|
|
41
|
+
var invoke = fromRuntime("invoke");
|
|
36
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
43
|
0 && (module.exports = {
|
|
38
44
|
fetch,
|
package/dist/runtime/router.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// src/runtime/router.ts
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
function fromRuntime(name) {
|
|
3
|
+
return (...args) => {
|
|
4
|
+
const runtime = globalThis.__marko_run__;
|
|
5
|
+
if (!runtime) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"This should have been replaced by the @marko/run plugin at build/dev time"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return runtime[name](...args);
|
|
11
|
+
};
|
|
6
12
|
}
|
|
7
|
-
var fetch =
|
|
8
|
-
var match =
|
|
9
|
-
var invoke =
|
|
13
|
+
var fetch = fromRuntime("fetch");
|
|
14
|
+
var match = fromRuntime("match");
|
|
15
|
+
var invoke = fromRuntime("invoke");
|
|
10
16
|
export {
|
|
11
17
|
fetch,
|
|
12
18
|
invoke,
|
package/dist/vite/index.cjs
CHANGED
|
@@ -680,7 +680,9 @@ function renderRouter(routes, options = {
|
|
|
680
680
|
`import page${key} from '${virtualFilePrefix}/${markoRunFilePrefix}special__${key}.marko${serverEntryQuery}';`
|
|
681
681
|
);
|
|
682
682
|
}
|
|
683
|
-
writer.writeLines(
|
|
683
|
+
writer.writeLines(`
|
|
684
|
+
globalThis.__marko_run__ = { match, fetch, invoke };
|
|
685
|
+
`).writeBlockStart(`export function match(method, pathname) {`).writeLines(
|
|
684
686
|
`if (!pathname) {
|
|
685
687
|
pathname = '/';
|
|
686
688
|
} else if (pathname.charAt(0) !== '/') {
|
|
@@ -829,7 +831,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
829
831
|
if (terminal || (dynamic == null ? void 0 : dynamic.route)) {
|
|
830
832
|
closeCount++;
|
|
831
833
|
writer.writeBlockStart(`if (!${index} || ${index} === len) {`);
|
|
832
|
-
let value = `pathname.slice(${offset}, ${index} ? -1 : len)`;
|
|
834
|
+
let value = `decodeURIComponent(pathname.slice(${offset}, ${index} ? -1 : len))`;
|
|
833
835
|
if (dynamic == null ? void 0 : dynamic.route) {
|
|
834
836
|
const segment = `s${next}`;
|
|
835
837
|
writer.writeLines(`const ${segment} = ${value};`);
|
|
@@ -868,7 +870,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
868
870
|
writer.writeBlockStart(`if (${index} && ${index} !== len) {`);
|
|
869
871
|
closeCount++;
|
|
870
872
|
}
|
|
871
|
-
let value = `pathname.slice(${offset}, ${index} - 1)`;
|
|
873
|
+
let value = `decodeURIComponent(pathname.slice(${offset}, ${index} - 1))`;
|
|
872
874
|
if ((dynamic == null ? void 0 : dynamic.static) || (dynamic == null ? void 0 : dynamic.dynamic)) {
|
|
873
875
|
const segment = `s${next}`;
|
|
874
876
|
writer.writeLines(`const ${segment} = ${value};`);
|
|
@@ -880,11 +882,12 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
880
882
|
writer.writeBlockStart(`switch (${value}.toLowerCase()) {`);
|
|
881
883
|
}
|
|
882
884
|
for (const child of children) {
|
|
885
|
+
const decodedKey = decodeURIComponent(child.key);
|
|
883
886
|
if (useSwitch) {
|
|
884
|
-
writer.writeBlockStart(`case '${
|
|
887
|
+
writer.writeBlockStart(`case '${decodedKey}': {`);
|
|
885
888
|
} else {
|
|
886
889
|
writer.writeBlockStart(
|
|
887
|
-
`if (${value}.toLowerCase() === '${
|
|
890
|
+
`if (${value}.toLowerCase() === '${decodedKey}') {`
|
|
888
891
|
);
|
|
889
892
|
}
|
|
890
893
|
const nextOffset = typeof offset === "string" ? index : offset + child.key.length + 1;
|
|
@@ -914,6 +917,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
914
917
|
}
|
|
915
918
|
}
|
|
916
919
|
function wrapPropertyName(name) {
|
|
920
|
+
name = decodeURIComponent(name);
|
|
917
921
|
return /^[^A-Za-z_$]|[^A-Za-z0-9$_]/.test(name) ? `'${name}'` : name;
|
|
918
922
|
}
|
|
919
923
|
function renderParamsInfo(params, pathIndex) {
|
|
@@ -1014,7 +1018,10 @@ interface NoMeta {}
|
|
|
1014
1018
|
const routeType = `Route${route.index}`;
|
|
1015
1019
|
const pathType = `\`${route.path.replace(
|
|
1016
1020
|
/\/\$(\$?)([^\/]*)/,
|
|
1017
|
-
(_, catchAll, name) =>
|
|
1021
|
+
(_, catchAll, name) => {
|
|
1022
|
+
name = decodeURIComponent(name);
|
|
1023
|
+
return catchAll ? `/:${name || "rest"}*` : `/:${name}`;
|
|
1024
|
+
}
|
|
1018
1025
|
)}\``;
|
|
1019
1026
|
const paramsType = (params == null ? void 0 : params.length) ? renderParamsInfoType(params) : "NoParams";
|
|
1020
1027
|
let metaType = "NoMeta";
|
|
@@ -1022,10 +1029,10 @@ interface NoMeta {}
|
|
|
1022
1029
|
const isGet = page || ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes("get"));
|
|
1023
1030
|
const isPost = (_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes("post");
|
|
1024
1031
|
if (isGet || isPost) {
|
|
1025
|
-
const path3 = route.path.replace(
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
);
|
|
1032
|
+
const path3 = route.path.replace(/\$(\$?)([^/]+)/g, (_, catchAll, name) => {
|
|
1033
|
+
name = decodeURIComponent(name);
|
|
1034
|
+
return catchAll ? `\${...${name}}` : `\${${name}}`;
|
|
1035
|
+
});
|
|
1029
1036
|
const splatIndex = path3.indexOf("/${...");
|
|
1030
1037
|
if (splatIndex >= 0) {
|
|
1031
1038
|
const path22 = path3.slice(0, splatIndex) || "/";
|
|
@@ -1236,9 +1243,9 @@ function getExportIdentifiers(astProgramNode) {
|
|
|
1236
1243
|
}
|
|
1237
1244
|
|
|
1238
1245
|
// src/vite/utils/log.ts
|
|
1246
|
+
var import_node_zlib = __toESM(require("node:zlib"), 1);
|
|
1239
1247
|
var import_cli_table3 = __toESM(require("cli-table3"), 1);
|
|
1240
1248
|
var import_kleur = __toESM(require("kleur"), 1);
|
|
1241
|
-
var import_gzip_size = require("gzip-size");
|
|
1242
1249
|
var import_human_format = __toESM(require("human-format"), 1);
|
|
1243
1250
|
var HttpVerbColors = {
|
|
1244
1251
|
get: import_kleur.default.green,
|
|
@@ -1324,17 +1331,20 @@ function computeRouteSize(route, bundle) {
|
|
|
1324
1331
|
}
|
|
1325
1332
|
return [0, 0];
|
|
1326
1333
|
}
|
|
1327
|
-
function
|
|
1328
|
-
return
|
|
1334
|
+
function gzipSize(source) {
|
|
1335
|
+
return import_node_zlib.default.gzipSync(source, { level: 9 }).length;
|
|
1336
|
+
}
|
|
1337
|
+
function byteSize(source) {
|
|
1338
|
+
return new Blob([source]).size;
|
|
1329
1339
|
}
|
|
1330
1340
|
function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
|
|
1331
1341
|
if (chunk.type === "asset") {
|
|
1332
1342
|
return [
|
|
1333
1343
|
byteSize(chunk.source),
|
|
1334
|
-
(
|
|
1344
|
+
gzipSize(chunk.source)
|
|
1335
1345
|
];
|
|
1336
1346
|
}
|
|
1337
|
-
const size = [byteSize(chunk.code), (
|
|
1347
|
+
const size = [byteSize(chunk.code), gzipSize(chunk.code)];
|
|
1338
1348
|
for (const id of chunk.imports) {
|
|
1339
1349
|
if (!seen.has(id)) {
|
|
1340
1350
|
const [bytes, compBytes] = computeChunkSize(bundle[id], bundle, seen);
|
|
@@ -1424,7 +1434,7 @@ function markoRun(opts = {}) {
|
|
|
1424
1434
|
const filepath = import_path2.default.join(typesDir, "routes.d.ts");
|
|
1425
1435
|
const data = await renderRouteTypeInfo(
|
|
1426
1436
|
routes,
|
|
1427
|
-
import_path2.default.relative(typesDir,
|
|
1437
|
+
import_path2.default.relative(typesDir, resolvedRoutesDir),
|
|
1428
1438
|
adapter
|
|
1429
1439
|
);
|
|
1430
1440
|
if (data !== typesFile || !import_fs2.default.existsSync(filepath)) {
|
|
@@ -1537,6 +1547,9 @@ function markoRun(opts = {}) {
|
|
|
1537
1547
|
define: isBuild ? {
|
|
1538
1548
|
"process.env.NODE_ENV": "'production'"
|
|
1539
1549
|
} : void 0,
|
|
1550
|
+
ssr: {
|
|
1551
|
+
noExternal: /@marko\/run/
|
|
1552
|
+
},
|
|
1540
1553
|
build: {
|
|
1541
1554
|
emptyOutDir: isSSRBuild
|
|
1542
1555
|
}
|
|
@@ -1774,7 +1787,8 @@ async function resolveAdapter(root, options, log) {
|
|
|
1774
1787
|
if (adapter !== void 0) {
|
|
1775
1788
|
return adapter;
|
|
1776
1789
|
}
|
|
1777
|
-
const
|
|
1790
|
+
const { resolvePackageData } = await import("vite");
|
|
1791
|
+
const pkg = resolvePackageData(".", root);
|
|
1778
1792
|
if (pkg) {
|
|
1779
1793
|
const dependecies = { ...pkg.data.dependecies, ...pkg.data.devDependencies };
|
|
1780
1794
|
for (const name of Object.keys(dependecies)) {
|
|
@@ -1800,6 +1814,7 @@ var import_net = __toESM(require("net"), 1);
|
|
|
1800
1814
|
var import_child_process = __toESM(require("child_process"), 1);
|
|
1801
1815
|
var import_dotenv = require("dotenv");
|
|
1802
1816
|
var import_fs3 = __toESM(require("fs"), 1);
|
|
1817
|
+
var import_cluster = __toESM(require("cluster"), 1);
|
|
1803
1818
|
async function parseEnv(envFile) {
|
|
1804
1819
|
if (import_fs3.default.existsSync(envFile)) {
|
|
1805
1820
|
const content = await import_fs3.default.promises.readFile(envFile, "utf8");
|
|
@@ -1809,14 +1824,14 @@ async function parseEnv(envFile) {
|
|
|
1809
1824
|
function loadEnv(envFile) {
|
|
1810
1825
|
(0, import_dotenv.config)({ path: envFile });
|
|
1811
1826
|
}
|
|
1812
|
-
async function spawnServer(cmd, port = 0, env, cwd = process.cwd(), wait = 3e4) {
|
|
1827
|
+
async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), wait = 3e4) {
|
|
1813
1828
|
if (port <= 0) {
|
|
1814
1829
|
port = await getAvailablePort();
|
|
1815
1830
|
}
|
|
1816
1831
|
if (typeof env === "string") {
|
|
1817
1832
|
env = await parseEnv(env);
|
|
1818
1833
|
}
|
|
1819
|
-
const proc = import_child_process.default.spawn(cmd, {
|
|
1834
|
+
const proc = import_child_process.default.spawn(cmd, args, {
|
|
1820
1835
|
cwd,
|
|
1821
1836
|
shell: true,
|
|
1822
1837
|
stdio: "inherit",
|
|
@@ -1827,32 +1842,45 @@ async function spawnServer(cmd, port = 0, env, cwd = process.cwd(), wait = 3e4)
|
|
|
1827
1842
|
proc.unref();
|
|
1828
1843
|
proc.kill();
|
|
1829
1844
|
};
|
|
1845
|
+
try {
|
|
1846
|
+
await waitForServer(port, wait);
|
|
1847
|
+
} catch (err) {
|
|
1848
|
+
close();
|
|
1849
|
+
throw err;
|
|
1850
|
+
}
|
|
1851
|
+
return {
|
|
1852
|
+
port,
|
|
1853
|
+
close
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
async function waitForServer(port, wait = 0) {
|
|
1830
1857
|
let remaining = wait > 0 ? wait : Infinity;
|
|
1831
|
-
|
|
1858
|
+
let connection;
|
|
1859
|
+
while (!(connection = await getConnection(port))) {
|
|
1832
1860
|
if (remaining >= 100) {
|
|
1833
1861
|
remaining -= 100;
|
|
1834
1862
|
await sleep(100);
|
|
1835
1863
|
} else {
|
|
1836
|
-
close();
|
|
1837
1864
|
throw new Error(
|
|
1838
1865
|
`site-write: timeout while wating for server to start on port "${port}".`
|
|
1839
1866
|
);
|
|
1840
1867
|
}
|
|
1841
1868
|
}
|
|
1842
|
-
return
|
|
1843
|
-
port,
|
|
1844
|
-
close
|
|
1845
|
-
};
|
|
1869
|
+
return connection;
|
|
1846
1870
|
}
|
|
1847
|
-
async function
|
|
1871
|
+
async function getConnection(port) {
|
|
1848
1872
|
return new Promise((resolve) => {
|
|
1849
|
-
const connection = import_net.default.connect(port).setNoDelay(true).setKeepAlive(false).on("error", () =>
|
|
1850
|
-
function done(connected) {
|
|
1873
|
+
const connection = import_net.default.connect(port).setNoDelay(true).setKeepAlive(false).on("error", () => {
|
|
1851
1874
|
connection.end();
|
|
1852
|
-
resolve(
|
|
1853
|
-
}
|
|
1875
|
+
resolve(null);
|
|
1876
|
+
}).on("connect", () => {
|
|
1877
|
+
resolve(connection);
|
|
1878
|
+
});
|
|
1854
1879
|
});
|
|
1855
1880
|
}
|
|
1881
|
+
async function isPortInUse(port) {
|
|
1882
|
+
return Boolean(await getConnection(port));
|
|
1883
|
+
}
|
|
1856
1884
|
async function getAvailablePort() {
|
|
1857
1885
|
return new Promise((resolve) => {
|
|
1858
1886
|
const server = import_net.default.createServer().listen(0, () => {
|