@marko/run 0.0.1-beta1 → 0.0.1-beta10
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 +385 -131
- package/dist/.tsbuildinfo +1 -0
- package/dist/adapter/default-entry.mjs +14 -5
- package/dist/adapter/dev-server.d.ts +1 -1
- package/dist/adapter/index.cjs +34 -10
- package/dist/adapter/index.d.ts +1 -0
- package/dist/adapter/index.js +34 -10
- package/dist/adapter/middleware.cjs +237 -0
- package/dist/adapter/middleware.d.ts +55 -0
- package/dist/adapter/middleware.js +209 -0
- package/dist/adapter/polyfill.d.ts +6 -0
- package/dist/cli/default.config.mjs +2 -2
- package/dist/cli/index.mjs +90 -59
- package/dist/runtime/index.cjs +0 -16
- package/dist/runtime/index.d.ts +21 -2
- package/dist/runtime/index.js +0 -7
- package/dist/runtime/internal.cjs +160 -0
- package/dist/runtime/internal.d.ts +11 -0
- package/dist/runtime/internal.js +126 -0
- package/dist/runtime/router.cjs +12 -10
- package/dist/runtime/router.d.ts +3 -4
- package/dist/runtime/router.js +9 -7
- package/dist/runtime/types.d.ts +39 -16
- package/dist/vite/codegen/index.d.ts +4 -3
- package/dist/vite/codegen/writer.d.ts +1 -1
- package/dist/vite/constants.d.ts +3 -2
- package/dist/vite/index.cjs +715 -312
- package/dist/vite/index.d.ts +4 -3
- package/dist/vite/index.js +712 -312
- package/dist/vite/types.d.ts +14 -7
- package/dist/vite/utils/config.d.ts +5 -3
- package/dist/vite/utils/route.d.ts +1 -1
- package/dist/vite/utils/server.d.ts +3 -1
- package/package.json +39 -17
- package/dist/adapter/server-old.d.ts +0 -3
- package/dist/adapter/server.d.ts +0 -6
- package/dist/adapters/node/index.d.ts +0 -5
- package/dist/adapters/node/server.d.ts +0 -3
- package/dist/adapters/static/crawler.d.ts +0 -9
- package/dist/adapters/static/default-entry.mjs +0 -1
- package/dist/adapters/static/index.cjs +0 -371
- package/dist/adapters/static/index.d.ts +0 -5
- package/dist/adapters/static/index.js +0 -341
- package/dist/adapters/static/server.d.ts +0 -3
- package/dist/runtime/request.d.ts +0 -4
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// src/adapter/polyfill.ts
|
|
2
|
+
import { ReadableStream as ReadableStream2, TransformStream, WritableStream } from "stream/web";
|
|
3
|
+
import { webcrypto as crypto } from "crypto";
|
|
4
|
+
import { fetch, Response, Request as Request2, Headers, FormData, File } from "undici";
|
|
5
|
+
import { OutgoingMessage } from "http";
|
|
6
|
+
var globals = {
|
|
7
|
+
crypto,
|
|
8
|
+
fetch,
|
|
9
|
+
Response,
|
|
10
|
+
Request: Request2,
|
|
11
|
+
Headers,
|
|
12
|
+
ReadableStream: ReadableStream2,
|
|
13
|
+
TransformStream,
|
|
14
|
+
WritableStream,
|
|
15
|
+
FormData,
|
|
16
|
+
File
|
|
17
|
+
};
|
|
18
|
+
if (typeof OutgoingMessage.prototype.appendHeader !== "function") {
|
|
19
|
+
const messageHeaders = /* @__PURE__ */ new WeakMap();
|
|
20
|
+
OutgoingMessage.prototype.appendHeader = function(name, value) {
|
|
21
|
+
let headers = messageHeaders.get(this);
|
|
22
|
+
if (!headers) {
|
|
23
|
+
headers = /* @__PURE__ */ new Map();
|
|
24
|
+
messageHeaders.set(this, headers);
|
|
25
|
+
}
|
|
26
|
+
const key = name.toLowerCase();
|
|
27
|
+
let existing = headers.get(key);
|
|
28
|
+
if (existing) {
|
|
29
|
+
if (Array.isArray(existing)) {
|
|
30
|
+
existing.push(value);
|
|
31
|
+
} else {
|
|
32
|
+
existing = [existing, value];
|
|
33
|
+
}
|
|
34
|
+
this.setHeader(name, existing);
|
|
35
|
+
headers.set(key, existing);
|
|
36
|
+
} else {
|
|
37
|
+
this.setHeader(name, value);
|
|
38
|
+
headers.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function installPolyfills() {
|
|
44
|
+
for (const name in globals) {
|
|
45
|
+
if (!(name in globalThis)) {
|
|
46
|
+
Object.defineProperty(globalThis, name, {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: globals[name]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/adapter/middleware.ts
|
|
57
|
+
installPolyfills();
|
|
58
|
+
function getForwardedHeader(req, name) {
|
|
59
|
+
const value = req.headers["x-forwarded-" + name];
|
|
60
|
+
if (value) {
|
|
61
|
+
if (typeof value === "string") {
|
|
62
|
+
const index = value.indexOf(",");
|
|
63
|
+
return index < 0 ? value : value.slice(0, index);
|
|
64
|
+
}
|
|
65
|
+
return value[0];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function getOrigin(req, protocol, host, trustProxy) {
|
|
69
|
+
var _a;
|
|
70
|
+
protocol ?? (protocol = req.protocol || trustProxy && getForwardedHeader(req, "proto") || ((_a = req.socket) == null ? void 0 : _a.encrypted) && "https" || "http");
|
|
71
|
+
host ?? (host = trustProxy && getForwardedHeader(req, "host") || req.headers.host);
|
|
72
|
+
if (!host) {
|
|
73
|
+
if (process.env.NODE_ENV !== "production") {
|
|
74
|
+
host = "localhost";
|
|
75
|
+
console.warn(
|
|
76
|
+
`Could not automatically determine the origin host, using 'localhost'. Use the 'origin' option or the 'ORIGIN' environment variable to set the origin explicitly.`
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Could not automatically determine the origin host. Use the 'origin' option or the 'ORIGIN' environment variable to set the origin explicitly.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return `${protocol}://${host}`;
|
|
85
|
+
}
|
|
86
|
+
function createMiddleware(fetch2, options = {}) {
|
|
87
|
+
const { trustProxy = process.env.TRUST_PROXY === "1", devServer } = options;
|
|
88
|
+
let { origin = process.env.ORIGIN } = options;
|
|
89
|
+
let protocol;
|
|
90
|
+
let host;
|
|
91
|
+
if (origin) {
|
|
92
|
+
({ protocol, host } = new URL(origin));
|
|
93
|
+
protocol = protocol.slice(0, -1);
|
|
94
|
+
}
|
|
95
|
+
return async (req, res, next) => {
|
|
96
|
+
origin ?? (origin = getOrigin(req, protocol, host, trustProxy));
|
|
97
|
+
const url = new URL(req.url, origin);
|
|
98
|
+
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
99
|
+
const headers = req.headers;
|
|
100
|
+
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
101
|
+
start(controller) {
|
|
102
|
+
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
103
|
+
req.on("end", () => controller.close());
|
|
104
|
+
req.on("error", (err) => controller.error(err));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const request = new Request(url, {
|
|
108
|
+
method: req.method,
|
|
109
|
+
headers,
|
|
110
|
+
body,
|
|
111
|
+
duplex: "half"
|
|
112
|
+
});
|
|
113
|
+
const response = await fetch2(request, {
|
|
114
|
+
ip,
|
|
115
|
+
request: req,
|
|
116
|
+
response: res,
|
|
117
|
+
setCookie(cookie) {
|
|
118
|
+
res.appendHeader("set-cookie", cookie);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (!response) {
|
|
122
|
+
if (next) {
|
|
123
|
+
next();
|
|
124
|
+
} else {
|
|
125
|
+
res.statusCode = 404;
|
|
126
|
+
res.setHeader("content-length", "0");
|
|
127
|
+
res.end();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
res.statusCode = response.status;
|
|
133
|
+
for (const [key, value] of response.headers) {
|
|
134
|
+
if (key === "set-cookie") {
|
|
135
|
+
let sepIndex = value.indexOf(",") + 1;
|
|
136
|
+
if (!sepIndex) {
|
|
137
|
+
res.setHeader(key, value);
|
|
138
|
+
} else {
|
|
139
|
+
let index = 0;
|
|
140
|
+
do {
|
|
141
|
+
res.appendHeader(key, value.slice(index, sepIndex - 1));
|
|
142
|
+
index = sepIndex;
|
|
143
|
+
sepIndex = value.indexOf(",", sepIndex) + 1;
|
|
144
|
+
} while (sepIndex);
|
|
145
|
+
res.appendHeader(key, value.slice(index));
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
res.setHeader(key, value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!response.body) {
|
|
152
|
+
if (!response.headers.has("content-length")) {
|
|
153
|
+
res.setHeader("content-length", "0");
|
|
154
|
+
}
|
|
155
|
+
res.end();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const reader = response.body.getReader();
|
|
159
|
+
if (res.destroyed) {
|
|
160
|
+
reader.cancel();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
res.on("close", cancel);
|
|
164
|
+
res.on("error", cancel);
|
|
165
|
+
write();
|
|
166
|
+
function cancel(error) {
|
|
167
|
+
res.off("close", cancel);
|
|
168
|
+
res.off("error", cancel);
|
|
169
|
+
reader.cancel(error).catch(() => {
|
|
170
|
+
});
|
|
171
|
+
if (error) {
|
|
172
|
+
if (process.env.NODE_ENV !== "production" && devServer) {
|
|
173
|
+
res.end();
|
|
174
|
+
devServer.ws.send({
|
|
175
|
+
type: "error",
|
|
176
|
+
err: { message: error.message, stack: error.stack || "" }
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
res.destroy(error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async function write() {
|
|
184
|
+
try {
|
|
185
|
+
while (true) {
|
|
186
|
+
const { done, value } = await reader.read();
|
|
187
|
+
if (done) {
|
|
188
|
+
res.end();
|
|
189
|
+
return;
|
|
190
|
+
} else if (!res.write(value)) {
|
|
191
|
+
res.once("drain", write);
|
|
192
|
+
return;
|
|
193
|
+
} else if (res.flush) {
|
|
194
|
+
res.flush();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
} catch (err) {
|
|
198
|
+
const error = err instanceof Error ? err : new Error("Error while writing to node response", {
|
|
199
|
+
cause: err
|
|
200
|
+
});
|
|
201
|
+
cancel(error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
createMiddleware,
|
|
208
|
+
getOrigin
|
|
209
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineConfig } from "vite";
|
|
2
2
|
import marko from "@marko/run/vite";
|
|
3
|
-
import
|
|
3
|
+
import nodeAdapter from "@marko/run/adapter";
|
|
4
4
|
|
|
5
5
|
export default defineConfig({
|
|
6
|
-
plugins: [marko({ adapter:
|
|
6
|
+
plugins: [marko({ adapter: nodeAdapter() })]
|
|
7
7
|
});
|
package/dist/cli/index.mjs
CHANGED
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
4
|
import path from "path";
|
|
5
|
-
import
|
|
5
|
+
import fs2 from "fs";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { build as viteBuild, resolveConfig } from "vite";
|
|
8
8
|
import sade from "sade";
|
|
9
9
|
|
|
10
10
|
// src/vite/utils/config.ts
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var PluginConfigKey = "__MARKO_RUN_PLUGIN_CONFIG__";
|
|
12
|
+
var AdapterConfigKey = "__MARKO_RUN_ADAPTER_CONFIG__";
|
|
13
|
+
function getConfig(obj, key) {
|
|
14
|
+
return obj[key];
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
return
|
|
16
|
+
function setConfig(obj, key, value) {
|
|
17
|
+
obj[key] = value;
|
|
18
|
+
return obj;
|
|
18
19
|
}
|
|
20
|
+
var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfigKey);
|
|
21
|
+
var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, PluginConfigKey, value);
|
|
22
|
+
var setExternalAdapterOptions = (viteConfig, value) => setConfig(viteConfig, AdapterConfigKey, value);
|
|
19
23
|
|
|
20
24
|
// src/cli/index.ts
|
|
21
25
|
import { MemoryStore } from "@marko/vite";
|
|
@@ -23,16 +27,27 @@ import { MemoryStore } from "@marko/vite";
|
|
|
23
27
|
// src/vite/utils/server.ts
|
|
24
28
|
import net from "net";
|
|
25
29
|
import cp from "child_process";
|
|
26
|
-
|
|
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) {
|
|
27
39
|
if (port <= 0) {
|
|
28
40
|
port = await getAvailablePort();
|
|
29
41
|
}
|
|
42
|
+
if (typeof env === "string") {
|
|
43
|
+
env = await parseEnv(env);
|
|
44
|
+
}
|
|
30
45
|
const proc = cp.spawn(cmd, {
|
|
31
46
|
cwd: cwd2,
|
|
32
47
|
shell: true,
|
|
33
48
|
stdio: "inherit",
|
|
34
49
|
windowsHide: true,
|
|
35
|
-
env: { NODE_ENV: "development", ...process.env, PORT: `${port}` }
|
|
50
|
+
env: { ...env, NODE_ENV: "development", ...process.env, PORT: `${port}` }
|
|
36
51
|
});
|
|
37
52
|
const close = () => {
|
|
38
53
|
proc.unref();
|
|
@@ -80,23 +95,27 @@ function sleep(ms) {
|
|
|
80
95
|
var __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
81
96
|
var cwd = process.cwd();
|
|
82
97
|
var defaultPort = +process.env.PORT || 3e3;
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
var defaultConfigFileBases = ["serve.config", "vite.config"];
|
|
99
|
+
var defaultConfigFileExts = [".js", ".cjs", ".mjs", ".ts", ".mts"];
|
|
100
|
+
var prog = sade("marko-run").version("0.0.1").option("-c, --config", `Provide path to a Vite config file (by default looks for a file starting with ${defaultConfigFileBases.join(" or ")} with one of these extensions: ${defaultConfigFileExts.join(", ")})`).option("-e, --env", "Provide path to a dotenv file");
|
|
101
|
+
prog.command("preview [entry]").describe("Start a production-like server for already-built app files").option("-o, --output", "Directory to serve files from, and write asset files to if `--build` (default: )").option("-p, --port", "Port the server should listen on (defaults: `$PORT` env variable or 3000)").option("-f, --file", "Output file to start").action(async (entry, opts) => {
|
|
102
|
+
process.env.NODE_ENV = "production";
|
|
103
|
+
const config2 = await getViteConfig(cwd, opts.config);
|
|
104
|
+
await build(entry, config2, opts.output, false, opts.env);
|
|
105
|
+
await preview(opts.entry, config2, opts.port, opts.output, opts.env);
|
|
88
106
|
});
|
|
89
|
-
prog.command("dev [entry]").describe("Start
|
|
107
|
+
prog.command("dev [entry]", "", { default: true }).describe("Start development server in watch mode").option("-p, --port", "Port the dev server should listen on (defaults: 'preview.port' in config, or `$PORT` env variable, or 3000)").example("dev --config vite.config.js").action(async (entry, opts) => {
|
|
90
108
|
const cmd = opts._.length ? `${entry} ${opts._.join(" ")}` : entry ? `node ${entry}` : void 0;
|
|
91
|
-
const
|
|
92
|
-
await dev(cmd,
|
|
109
|
+
const config2 = await getViteConfig(cwd, opts.config);
|
|
110
|
+
await dev(cmd, config2, opts.port, opts.env);
|
|
93
111
|
});
|
|
94
|
-
prog.command("build [entry]").describe("Build the application").option("-o, --output", "Directory to
|
|
95
|
-
|
|
96
|
-
await
|
|
112
|
+
prog.command("build [entry]").describe("Build the application (without serving it)").option("-o, --output", "Directory to write built files (default: 'build.outDir' in Vite config)").option("--skip-client", "Skip the client-side build").example("build --config vite.config.js").action(async (entry, opts) => {
|
|
113
|
+
process.env.NODE_ENV = "production";
|
|
114
|
+
const config2 = await getViteConfig(cwd, opts.config);
|
|
115
|
+
await build(entry, config2, opts.ouput, opts["skip-client"], opts.env);
|
|
97
116
|
});
|
|
98
117
|
prog.parse(process.argv);
|
|
99
|
-
async function preview(entry, configFile, port, outDir) {
|
|
118
|
+
async function preview(entry, configFile, port, outDir, envFile) {
|
|
100
119
|
const resolvedConfig = await resolveConfig(
|
|
101
120
|
{ root: cwd, configFile, build: { outDir } },
|
|
102
121
|
"serve"
|
|
@@ -106,15 +125,18 @@ async function preview(entry, configFile, port, outDir) {
|
|
|
106
125
|
}
|
|
107
126
|
const adapter = await resolveAdapter(resolvedConfig);
|
|
108
127
|
if (!adapter) {
|
|
109
|
-
throw new Error("No adapter specified for serve command");
|
|
128
|
+
throw new Error("No adapter specified for 'serve' command");
|
|
110
129
|
} else if (!adapter.startPreview) {
|
|
111
|
-
throw new Error(`Adapter ${adapter.name} does not support serve command`);
|
|
130
|
+
throw new Error(`Adapter ${adapter.name} does not support 'serve' command`);
|
|
112
131
|
}
|
|
113
132
|
const dir = path.resolve(cwd, resolvedConfig.build.outDir);
|
|
114
133
|
const entryFile = entry ? path.join(dir, entry) : await findFileWithExt(dir, "index", [".mjs", ".js"]);
|
|
115
|
-
|
|
134
|
+
if (envFile) {
|
|
135
|
+
envFile = path.resolve(cwd, envFile);
|
|
136
|
+
}
|
|
137
|
+
await adapter.startPreview(dir, entryFile, port, envFile);
|
|
116
138
|
}
|
|
117
|
-
async function dev(cmd, configFile, port) {
|
|
139
|
+
async function dev(cmd, configFile, port, envFile) {
|
|
118
140
|
const resolvedConfig = await resolveConfig(
|
|
119
141
|
{ root: cwd, configFile },
|
|
120
142
|
"build"
|
|
@@ -122,55 +144,63 @@ async function dev(cmd, configFile, port) {
|
|
|
122
144
|
if (port === void 0) {
|
|
123
145
|
port = resolvedConfig.preview.port ?? defaultPort;
|
|
124
146
|
}
|
|
147
|
+
if (envFile) {
|
|
148
|
+
envFile = path.resolve(cwd, envFile);
|
|
149
|
+
}
|
|
125
150
|
if (cmd) {
|
|
126
|
-
await spawnServer(cmd, port);
|
|
151
|
+
await spawnServer(cmd, port, envFile);
|
|
127
152
|
} else {
|
|
128
153
|
const adapter = await resolveAdapter(resolvedConfig);
|
|
129
154
|
if (!adapter) {
|
|
130
155
|
throw new Error(
|
|
131
|
-
"No adapter specified for dev command without custom target"
|
|
156
|
+
"No adapter specified for 'dev' command without custom target"
|
|
132
157
|
);
|
|
133
158
|
} else if (!adapter.startDev) {
|
|
134
|
-
throw new Error(`Adapter ${adapter.name} does not support serve command`);
|
|
159
|
+
throw new Error(`Adapter '${adapter.name}' does not support 'serve' command`);
|
|
135
160
|
} else {
|
|
136
|
-
await adapter.startDev(configFile, port);
|
|
161
|
+
await adapter.startDev(configFile, port, envFile);
|
|
137
162
|
}
|
|
138
163
|
}
|
|
139
164
|
}
|
|
140
|
-
async function build(entry, configFile, outDir, skipClient = false) {
|
|
165
|
+
async function build(entry, configFile, outDir, skipClient = false, envFile) {
|
|
141
166
|
var _a;
|
|
167
|
+
const resolvedConfig = await resolveConfig(
|
|
168
|
+
{ root: cwd, configFile },
|
|
169
|
+
"build"
|
|
170
|
+
);
|
|
171
|
+
const adapter = await resolveAdapter(resolvedConfig);
|
|
172
|
+
if (!adapter) {
|
|
173
|
+
throw new Error("No adapter specified for build command without entry");
|
|
174
|
+
}
|
|
142
175
|
if (!entry) {
|
|
143
|
-
const resolvedConfig = await resolveConfig(
|
|
144
|
-
{ root: cwd, configFile },
|
|
145
|
-
"build"
|
|
146
|
-
);
|
|
147
|
-
const adapter = await resolveAdapter(resolvedConfig);
|
|
148
|
-
if (!adapter) {
|
|
149
|
-
throw new Error("No adapter specified for build command without entry");
|
|
150
|
-
}
|
|
151
176
|
entry = await ((_a = adapter.getEntryFile) == null ? void 0 : _a.call(adapter));
|
|
152
177
|
if (!entry) {
|
|
153
178
|
throw new Error(
|
|
154
|
-
`Adapter ${adapter.name} does not support
|
|
179
|
+
`Adapter '${adapter.name}' does not support building without an entry`
|
|
155
180
|
);
|
|
156
181
|
}
|
|
157
182
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{
|
|
168
|
-
store: new MemoryStore()
|
|
183
|
+
if (envFile) {
|
|
184
|
+
envFile = path.resolve(cwd, envFile);
|
|
185
|
+
}
|
|
186
|
+
let buildConfig = {
|
|
187
|
+
root: cwd,
|
|
188
|
+
configFile,
|
|
189
|
+
build: {
|
|
190
|
+
ssr: false,
|
|
191
|
+
outDir
|
|
169
192
|
}
|
|
170
|
-
|
|
193
|
+
};
|
|
194
|
+
buildConfig = setExternalPluginOptions(buildConfig, {
|
|
195
|
+
store: new MemoryStore()
|
|
196
|
+
});
|
|
197
|
+
buildConfig = setExternalAdapterOptions(buildConfig, {
|
|
198
|
+
envFile
|
|
199
|
+
});
|
|
171
200
|
await viteBuild({
|
|
172
201
|
...buildConfig,
|
|
173
202
|
build: {
|
|
203
|
+
target: "esnext",
|
|
174
204
|
...buildConfig.build,
|
|
175
205
|
ssr: entry,
|
|
176
206
|
rollupOptions: {
|
|
@@ -190,19 +220,20 @@ async function build(entry, configFile, outDir, skipClient = false) {
|
|
|
190
220
|
});
|
|
191
221
|
}
|
|
192
222
|
}
|
|
193
|
-
function findFileWithExt(dir, base, extensions =
|
|
223
|
+
function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
|
|
194
224
|
for (const ext of extensions) {
|
|
195
225
|
const filePath = path.join(dir, base + ext);
|
|
196
|
-
if (
|
|
226
|
+
if (fs2.existsSync(filePath)) {
|
|
197
227
|
return filePath;
|
|
198
228
|
}
|
|
199
229
|
}
|
|
200
230
|
return void 0;
|
|
201
231
|
}
|
|
202
|
-
async function getViteConfig(dir, configFile, bases =
|
|
232
|
+
async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
|
|
203
233
|
if (configFile) {
|
|
204
|
-
|
|
205
|
-
|
|
234
|
+
const configFilePath = path.join(dir, configFile);
|
|
235
|
+
if (!fs2.existsSync(configFilePath)) {
|
|
236
|
+
throw new Error(`No config file found at '${configFilePath}'`);
|
|
206
237
|
}
|
|
207
238
|
return configFile;
|
|
208
239
|
}
|
|
@@ -214,10 +245,10 @@ async function getViteConfig(dir, configFile, bases = ["serve.config", "vite.con
|
|
|
214
245
|
}
|
|
215
246
|
return path.join(__dirname, "default.config.mjs");
|
|
216
247
|
}
|
|
217
|
-
async function resolveAdapter(
|
|
218
|
-
const options =
|
|
248
|
+
async function resolveAdapter(config2) {
|
|
249
|
+
const options = getExternalPluginOptions(config2);
|
|
219
250
|
if (!options) {
|
|
220
|
-
throw new Error("Unable to resolve
|
|
251
|
+
throw new Error("Unable to resolve @marko/serve options");
|
|
221
252
|
}
|
|
222
253
|
return options.adapter;
|
|
223
254
|
}
|
package/dist/runtime/index.cjs
CHANGED
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -19,16 +15,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
15
|
|
|
20
16
|
// src/runtime/index.ts
|
|
21
17
|
var runtime_exports = {};
|
|
22
|
-
__export(runtime_exports, {
|
|
23
|
-
getMatchedRoute: () => import_router.getMatchedRoute,
|
|
24
|
-
handler: () => import_router.handler,
|
|
25
|
-
router: () => import_router.router
|
|
26
|
-
});
|
|
27
18
|
module.exports = __toCommonJS(runtime_exports);
|
|
28
|
-
var import_router = require("@marko/run/router");
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
getMatchedRoute,
|
|
32
|
-
handler,
|
|
33
|
-
router
|
|
34
|
-
});
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { HandlerLike, ParamsObject, Route as AnyRoute, Context as AnyContext } from "./types";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Marko {
|
|
4
|
+
interface Global extends MarkoRun.Context {
|
|
5
|
+
}
|
|
6
|
+
interface Out {
|
|
7
|
+
global: Global;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
namespace MarkoRun {
|
|
11
|
+
const NotHandled: unique symbol;
|
|
12
|
+
const NotMatched: unique symbol;
|
|
13
|
+
interface Route extends AnyRoute {
|
|
14
|
+
}
|
|
15
|
+
interface Context extends AnyContext<Route> {
|
|
16
|
+
}
|
|
17
|
+
type Handler<Params extends ParamsObject = {}, Meta = unknown> = HandlerLike<AnyRoute<Params, Meta, string>>;
|
|
18
|
+
function route<Params extends ParamsObject = {}, Meta = unknown>(handler: Handler<Params, Meta>): typeof handler;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export type { Fetch, HandlerLike, InputObject, Invoke, Match, NextFunction, PathTemplate, Route, Context, ContextExtensions, RouteHandler, RouteWithHandler, RuntimeModule, ValidateHref, ValidatePath, } from "./types";
|