@marko/run 0.1.9 → 0.1.11
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/index.cjs +32 -15
- package/dist/adapter/index.js +32 -15
- package/dist/cli/index.mjs +7 -2
- package/dist/vite/index.cjs +84 -9
- package/dist/vite/index.js +84 -9
- package/dist/vite/utils/server.d.ts +4 -0
- package/package.json +1 -1
package/dist/adapter/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ async function createViteDevServer(config2) {
|
|
|
66
66
|
const devServer = await (0, import_vite.createServer)({
|
|
67
67
|
...config2,
|
|
68
68
|
appType: "custom",
|
|
69
|
-
server: { middlewareMode: true }
|
|
69
|
+
server: { ...config2 == null ? void 0 : config2.server, middlewareMode: true }
|
|
70
70
|
});
|
|
71
71
|
const originalClose = devServer.close;
|
|
72
72
|
devServer.close = () => {
|
|
@@ -124,7 +124,10 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
124
124
|
proc.kill();
|
|
125
125
|
};
|
|
126
126
|
try {
|
|
127
|
-
await
|
|
127
|
+
await Promise.race([
|
|
128
|
+
waitForError(proc, port),
|
|
129
|
+
waitForServer(port, wait)
|
|
130
|
+
]);
|
|
128
131
|
} catch (err) {
|
|
129
132
|
close();
|
|
130
133
|
throw err;
|
|
@@ -161,6 +164,14 @@ async function spawnServerWorker(module2, args = [], port = 0, env) {
|
|
|
161
164
|
import_cluster.default.settings.execArgv = originalArgs;
|
|
162
165
|
}
|
|
163
166
|
}
|
|
167
|
+
async function waitForError(proc, port) {
|
|
168
|
+
return new Promise((_, reject) => {
|
|
169
|
+
proc.once("error", reject);
|
|
170
|
+
proc.once("exit", (code) => {
|
|
171
|
+
reject(new Error(`Process exited with code ${code} while waiting for server to start on port "${port}".`));
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
164
175
|
async function waitForServer(port, wait = 0) {
|
|
165
176
|
let remaining = wait > 0 ? wait : Infinity;
|
|
166
177
|
let connection;
|
|
@@ -170,12 +181,29 @@ async function waitForServer(port, wait = 0) {
|
|
|
170
181
|
await sleep(100);
|
|
171
182
|
} else {
|
|
172
183
|
throw new Error(
|
|
173
|
-
`
|
|
184
|
+
`Timeout while wating for server to start on port "${port}".`
|
|
174
185
|
);
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
return connection;
|
|
178
189
|
}
|
|
190
|
+
async function waitForWorker(worker, port) {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
function listening(address) {
|
|
193
|
+
if (address.port === port) {
|
|
194
|
+
worker.off("listening", listening);
|
|
195
|
+
resolve();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
worker.on("listening", listening).once("error", reject).once("exit", (code) => {
|
|
199
|
+
reject(
|
|
200
|
+
new Error(
|
|
201
|
+
`Worker exited with code ${code} while waiting for dev server to start on port "${port}".`
|
|
202
|
+
)
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
179
207
|
async function getConnection(port) {
|
|
180
208
|
return new Promise((resolve) => {
|
|
181
209
|
const connection = import_net.default.connect(port).setNoDelay(true).setKeepAlive(false).on("error", () => {
|
|
@@ -266,7 +294,7 @@ function adapter() {
|
|
|
266
294
|
});
|
|
267
295
|
},
|
|
268
296
|
async startPreview(entry, options) {
|
|
269
|
-
const { port, envFile } = options;
|
|
297
|
+
const { port = 3e3, envFile } = options;
|
|
270
298
|
const { nodeArgs } = (0, import_parse_node_args.default)(options.args);
|
|
271
299
|
const args = [...nodeArgs, entry];
|
|
272
300
|
const server = await spawnServer("node", args, port, envFile);
|
|
@@ -275,17 +303,6 @@ function adapter() {
|
|
|
275
303
|
}
|
|
276
304
|
};
|
|
277
305
|
}
|
|
278
|
-
async function waitForWorker(worker, port) {
|
|
279
|
-
return new Promise((resolve) => {
|
|
280
|
-
function listening(address) {
|
|
281
|
-
if (address.port === port) {
|
|
282
|
-
worker.off("listening", listening);
|
|
283
|
-
resolve();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
worker.on("listening", listening);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
306
|
// Annotate the CommonJS export names for ESM import in node:
|
|
290
307
|
0 && (module.exports = {
|
|
291
308
|
activeDevServers,
|
package/dist/adapter/index.js
CHANGED
|
@@ -32,7 +32,7 @@ async function createViteDevServer(config2) {
|
|
|
32
32
|
const devServer = await createServer({
|
|
33
33
|
...config2,
|
|
34
34
|
appType: "custom",
|
|
35
|
-
server: { middlewareMode: true }
|
|
35
|
+
server: { ...config2 == null ? void 0 : config2.server, middlewareMode: true }
|
|
36
36
|
});
|
|
37
37
|
const originalClose = devServer.close;
|
|
38
38
|
devServer.close = () => {
|
|
@@ -90,7 +90,10 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
90
90
|
proc.kill();
|
|
91
91
|
};
|
|
92
92
|
try {
|
|
93
|
-
await
|
|
93
|
+
await Promise.race([
|
|
94
|
+
waitForError(proc, port),
|
|
95
|
+
waitForServer(port, wait)
|
|
96
|
+
]);
|
|
94
97
|
} catch (err) {
|
|
95
98
|
close();
|
|
96
99
|
throw err;
|
|
@@ -127,6 +130,14 @@ async function spawnServerWorker(module, args = [], port = 0, env) {
|
|
|
127
130
|
cluster.settings.execArgv = originalArgs;
|
|
128
131
|
}
|
|
129
132
|
}
|
|
133
|
+
async function waitForError(proc, port) {
|
|
134
|
+
return new Promise((_, reject) => {
|
|
135
|
+
proc.once("error", reject);
|
|
136
|
+
proc.once("exit", (code) => {
|
|
137
|
+
reject(new Error(`Process exited with code ${code} while waiting for server to start on port "${port}".`));
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
130
141
|
async function waitForServer(port, wait = 0) {
|
|
131
142
|
let remaining = wait > 0 ? wait : Infinity;
|
|
132
143
|
let connection;
|
|
@@ -136,12 +147,29 @@ async function waitForServer(port, wait = 0) {
|
|
|
136
147
|
await sleep(100);
|
|
137
148
|
} else {
|
|
138
149
|
throw new Error(
|
|
139
|
-
`
|
|
150
|
+
`Timeout while wating for server to start on port "${port}".`
|
|
140
151
|
);
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
154
|
return connection;
|
|
144
155
|
}
|
|
156
|
+
async function waitForWorker(worker, port) {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
function listening(address) {
|
|
159
|
+
if (address.port === port) {
|
|
160
|
+
worker.off("listening", listening);
|
|
161
|
+
resolve();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
worker.on("listening", listening).once("error", reject).once("exit", (code) => {
|
|
165
|
+
reject(
|
|
166
|
+
new Error(
|
|
167
|
+
`Worker exited with code ${code} while waiting for dev server to start on port "${port}".`
|
|
168
|
+
)
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
145
173
|
async function getConnection(port) {
|
|
146
174
|
return new Promise((resolve) => {
|
|
147
175
|
const connection = net.connect(port).setNoDelay(true).setKeepAlive(false).on("error", () => {
|
|
@@ -231,7 +259,7 @@ function adapter() {
|
|
|
231
259
|
});
|
|
232
260
|
},
|
|
233
261
|
async startPreview(entry, options) {
|
|
234
|
-
const { port, envFile } = options;
|
|
262
|
+
const { port = 3e3, envFile } = options;
|
|
235
263
|
const { nodeArgs } = parseNodeArgs(options.args);
|
|
236
264
|
const args = [...nodeArgs, entry];
|
|
237
265
|
const server = await spawnServer("node", args, port, envFile);
|
|
@@ -240,17 +268,6 @@ function adapter() {
|
|
|
240
268
|
}
|
|
241
269
|
};
|
|
242
270
|
}
|
|
243
|
-
async function waitForWorker(worker, port) {
|
|
244
|
-
return new Promise((resolve) => {
|
|
245
|
-
function listening(address) {
|
|
246
|
-
if (address.port === port) {
|
|
247
|
-
worker.off("listening", listening);
|
|
248
|
-
resolve();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
worker.on("listening", listening);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
271
|
export {
|
|
255
272
|
activeDevServers,
|
|
256
273
|
createDevServer,
|
package/dist/cli/index.mjs
CHANGED
|
@@ -90,12 +90,17 @@ async function resolveAdapter(root, options, log) {
|
|
|
90
90
|
const { resolvePackageData } = await import("vite");
|
|
91
91
|
const pkg = resolvePackageData(".", root);
|
|
92
92
|
if (pkg) {
|
|
93
|
-
const dependecies = {
|
|
93
|
+
const dependecies = {
|
|
94
|
+
...pkg.data.dependecies,
|
|
95
|
+
...pkg.data.devDependencies
|
|
96
|
+
};
|
|
94
97
|
for (const name of Object.keys(dependecies)) {
|
|
95
98
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
96
99
|
try {
|
|
97
100
|
const module2 = await import(name);
|
|
98
|
-
log && console.log(
|
|
101
|
+
log && console.log(
|
|
102
|
+
`Using adapter ${name} listed in your package.json dependecies`
|
|
103
|
+
);
|
|
99
104
|
return module2.default();
|
|
100
105
|
} catch (err) {
|
|
101
106
|
log && console.warn(`Attempt to use package '${name}' failed`, err);
|
package/dist/vite/index.cjs
CHANGED
|
@@ -1379,7 +1379,7 @@ function markoRun(opts = {}) {
|
|
|
1379
1379
|
const filepath = import_path2.default.join(typesDir, "routes.d.ts");
|
|
1380
1380
|
const data = await renderRouteTypeInfo(
|
|
1381
1381
|
routes,
|
|
1382
|
-
import_path2.default.relative(typesDir, resolvedRoutesDir),
|
|
1382
|
+
normalizePath(import_path2.default.relative(typesDir, resolvedRoutesDir)),
|
|
1383
1383
|
adapter
|
|
1384
1384
|
);
|
|
1385
1385
|
if (data !== typesFile || !import_fs2.default.existsSync(filepath)) {
|
|
@@ -1452,7 +1452,7 @@ function markoRun(opts = {}) {
|
|
|
1452
1452
|
name: "marko-run-vite:pre",
|
|
1453
1453
|
enforce: "pre",
|
|
1454
1454
|
async config(config2, env) {
|
|
1455
|
-
var _a, _b, _c;
|
|
1455
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1456
1456
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
1457
1457
|
if (externalPluginOptions) {
|
|
1458
1458
|
opts = (0, import_vite.mergeConfig)(opts, externalPluginOptions);
|
|
@@ -1460,7 +1460,11 @@ function markoRun(opts = {}) {
|
|
|
1460
1460
|
root = normalizePath(config2.root || process.cwd());
|
|
1461
1461
|
isBuild = env.command === "build";
|
|
1462
1462
|
isSSRBuild = isBuild && Boolean((_a = config2.build) == null ? void 0 : _a.ssr);
|
|
1463
|
-
adapter = await resolveAdapter(
|
|
1463
|
+
adapter = await resolveAdapter(
|
|
1464
|
+
root,
|
|
1465
|
+
opts,
|
|
1466
|
+
config2.logLevel !== "silent" && !isBuild || isSSRBuild
|
|
1467
|
+
);
|
|
1464
1468
|
if (adapter) {
|
|
1465
1469
|
const externalAdapterConfig = getExternalAdapterOptions(config2);
|
|
1466
1470
|
if (externalAdapterConfig && adapter.configure) {
|
|
@@ -1487,6 +1491,44 @@ function markoRun(opts = {}) {
|
|
|
1487
1491
|
typesDir = import_path2.default.join(root, ".marko-run");
|
|
1488
1492
|
devEntryFile = import_path2.default.join(root, "index.html");
|
|
1489
1493
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
1494
|
+
const assetsDir = ((_c = config2.build) == null ? void 0 : _c.assetsDir) || "assets";
|
|
1495
|
+
let rollupOutputOptions = (_e = (_d = config2.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output;
|
|
1496
|
+
if (isBuild && !isSSRBuild) {
|
|
1497
|
+
const defaultRollupOutputOptions = {
|
|
1498
|
+
assetFileNames({ name }) {
|
|
1499
|
+
if (name && name.indexOf("_marko-virtual_id_") < 0) {
|
|
1500
|
+
return `${assetsDir}/${getEntryFileName(name) || "[name]"}-[hash].[ext]`;
|
|
1501
|
+
}
|
|
1502
|
+
return `${assetsDir}/_[hash].[ext]`;
|
|
1503
|
+
},
|
|
1504
|
+
entryFileNames(info) {
|
|
1505
|
+
let name = getEntryFileName(info.facadeModuleId);
|
|
1506
|
+
if (!name) {
|
|
1507
|
+
for (let id of info.moduleIds) {
|
|
1508
|
+
name = getEntryFileName(id);
|
|
1509
|
+
if (name) {
|
|
1510
|
+
break;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return `${assetsDir}/${name || "[name]"}-[hash].js`;
|
|
1515
|
+
},
|
|
1516
|
+
chunkFileNames: `${assetsDir}/_[hash].js`
|
|
1517
|
+
};
|
|
1518
|
+
if (!rollupOutputOptions) {
|
|
1519
|
+
rollupOutputOptions = defaultRollupOutputOptions;
|
|
1520
|
+
} else if (!Array.isArray(rollupOutputOptions)) {
|
|
1521
|
+
rollupOutputOptions = {
|
|
1522
|
+
...defaultRollupOutputOptions,
|
|
1523
|
+
...rollupOutputOptions
|
|
1524
|
+
};
|
|
1525
|
+
} else {
|
|
1526
|
+
rollupOutputOptions = rollupOutputOptions.map((options) => ({
|
|
1527
|
+
...defaultRollupOutputOptions,
|
|
1528
|
+
...options
|
|
1529
|
+
}));
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1490
1532
|
let pluginConfig = {
|
|
1491
1533
|
logLevel: isBuild ? "warn" : void 0,
|
|
1492
1534
|
define: isBuild ? {
|
|
@@ -1496,10 +1538,13 @@ function markoRun(opts = {}) {
|
|
|
1496
1538
|
noExternal: /@marko\/run/
|
|
1497
1539
|
},
|
|
1498
1540
|
build: {
|
|
1499
|
-
emptyOutDir: isSSRBuild
|
|
1541
|
+
emptyOutDir: isSSRBuild,
|
|
1542
|
+
rollupOptions: {
|
|
1543
|
+
output: rollupOutputOptions
|
|
1544
|
+
}
|
|
1500
1545
|
}
|
|
1501
1546
|
};
|
|
1502
|
-
const adapterConfig = await ((
|
|
1547
|
+
const adapterConfig = await ((_f = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _f.call(adapter, config2));
|
|
1503
1548
|
if (adapterConfig) {
|
|
1504
1549
|
pluginConfig = (0, import_vite.mergeConfig)(pluginConfig, adapterConfig);
|
|
1505
1550
|
}
|
|
@@ -1619,6 +1664,15 @@ function markoRun(opts = {}) {
|
|
|
1619
1664
|
{
|
|
1620
1665
|
name: "marko-run-vite:post",
|
|
1621
1666
|
enforce: "post",
|
|
1667
|
+
generateBundle(options, bundle) {
|
|
1668
|
+
if (options.sourcemap && options.sourcemap !== "inline") {
|
|
1669
|
+
for (const key of Object.keys(bundle)) {
|
|
1670
|
+
if (key.endsWith(".map") && !bundle[key.slice(0, -4)]) {
|
|
1671
|
+
delete bundle[key];
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
},
|
|
1622
1676
|
async writeBundle(options, bundle) {
|
|
1623
1677
|
var _a;
|
|
1624
1678
|
if (isSSRBuild) {
|
|
@@ -1735,12 +1789,17 @@ async function resolveAdapter(root, options, log) {
|
|
|
1735
1789
|
const { resolvePackageData } = await import("vite");
|
|
1736
1790
|
const pkg = resolvePackageData(".", root);
|
|
1737
1791
|
if (pkg) {
|
|
1738
|
-
const dependecies = {
|
|
1792
|
+
const dependecies = {
|
|
1793
|
+
...pkg.data.dependecies,
|
|
1794
|
+
...pkg.data.devDependencies
|
|
1795
|
+
};
|
|
1739
1796
|
for (const name of Object.keys(dependecies)) {
|
|
1740
1797
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
1741
1798
|
try {
|
|
1742
1799
|
const module3 = await import(name);
|
|
1743
|
-
log && console.log(
|
|
1800
|
+
log && console.log(
|
|
1801
|
+
`Using adapter ${name} listed in your package.json dependecies`
|
|
1802
|
+
);
|
|
1744
1803
|
return module3.default();
|
|
1745
1804
|
} catch (err) {
|
|
1746
1805
|
log && console.warn(`Attempt to use package '${name}' failed`, err);
|
|
@@ -1753,6 +1812,11 @@ async function resolveAdapter(root, options, log) {
|
|
|
1753
1812
|
log && console.log("Using default adapter");
|
|
1754
1813
|
return module2.default();
|
|
1755
1814
|
}
|
|
1815
|
+
var markoEntryFileRegex = /__marko-run__([^_]+)__(.+)\.marko.([^.]+)$/;
|
|
1816
|
+
function getEntryFileName(file) {
|
|
1817
|
+
const match = file && markoEntryFileRegex.exec(file);
|
|
1818
|
+
return match ? `${match[2].replace(/__/g, "-")}` : void 0;
|
|
1819
|
+
}
|
|
1756
1820
|
|
|
1757
1821
|
// src/vite/utils/server.ts
|
|
1758
1822
|
var import_net = __toESM(require("net"), 1);
|
|
@@ -1788,7 +1852,10 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
1788
1852
|
proc.kill();
|
|
1789
1853
|
};
|
|
1790
1854
|
try {
|
|
1791
|
-
await
|
|
1855
|
+
await Promise.race([
|
|
1856
|
+
waitForError(proc, port),
|
|
1857
|
+
waitForServer(port, wait)
|
|
1858
|
+
]);
|
|
1792
1859
|
} catch (err) {
|
|
1793
1860
|
close();
|
|
1794
1861
|
throw err;
|
|
@@ -1798,6 +1865,14 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
1798
1865
|
close
|
|
1799
1866
|
};
|
|
1800
1867
|
}
|
|
1868
|
+
async function waitForError(proc, port) {
|
|
1869
|
+
return new Promise((_, reject) => {
|
|
1870
|
+
proc.once("error", reject);
|
|
1871
|
+
proc.once("exit", (code) => {
|
|
1872
|
+
reject(new Error(`Process exited with code ${code} while waiting for server to start on port "${port}".`));
|
|
1873
|
+
});
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1801
1876
|
async function waitForServer(port, wait = 0) {
|
|
1802
1877
|
let remaining = wait > 0 ? wait : Infinity;
|
|
1803
1878
|
let connection;
|
|
@@ -1807,7 +1882,7 @@ async function waitForServer(port, wait = 0) {
|
|
|
1807
1882
|
await sleep(100);
|
|
1808
1883
|
} else {
|
|
1809
1884
|
throw new Error(
|
|
1810
|
-
`
|
|
1885
|
+
`Timeout while wating for server to start on port "${port}".`
|
|
1811
1886
|
);
|
|
1812
1887
|
}
|
|
1813
1888
|
}
|
package/dist/vite/index.js
CHANGED
|
@@ -1341,7 +1341,7 @@ function markoRun(opts = {}) {
|
|
|
1341
1341
|
const filepath = path2.join(typesDir, "routes.d.ts");
|
|
1342
1342
|
const data = await renderRouteTypeInfo(
|
|
1343
1343
|
routes,
|
|
1344
|
-
path2.relative(typesDir, resolvedRoutesDir),
|
|
1344
|
+
normalizePath(path2.relative(typesDir, resolvedRoutesDir)),
|
|
1345
1345
|
adapter
|
|
1346
1346
|
);
|
|
1347
1347
|
if (data !== typesFile || !fs2.existsSync(filepath)) {
|
|
@@ -1414,7 +1414,7 @@ function markoRun(opts = {}) {
|
|
|
1414
1414
|
name: "marko-run-vite:pre",
|
|
1415
1415
|
enforce: "pre",
|
|
1416
1416
|
async config(config2, env) {
|
|
1417
|
-
var _a, _b, _c;
|
|
1417
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1418
1418
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
1419
1419
|
if (externalPluginOptions) {
|
|
1420
1420
|
opts = mergeConfig(opts, externalPluginOptions);
|
|
@@ -1422,7 +1422,11 @@ function markoRun(opts = {}) {
|
|
|
1422
1422
|
root = normalizePath(config2.root || process.cwd());
|
|
1423
1423
|
isBuild = env.command === "build";
|
|
1424
1424
|
isSSRBuild = isBuild && Boolean((_a = config2.build) == null ? void 0 : _a.ssr);
|
|
1425
|
-
adapter = await resolveAdapter(
|
|
1425
|
+
adapter = await resolveAdapter(
|
|
1426
|
+
root,
|
|
1427
|
+
opts,
|
|
1428
|
+
config2.logLevel !== "silent" && !isBuild || isSSRBuild
|
|
1429
|
+
);
|
|
1426
1430
|
if (adapter) {
|
|
1427
1431
|
const externalAdapterConfig = getExternalAdapterOptions(config2);
|
|
1428
1432
|
if (externalAdapterConfig && adapter.configure) {
|
|
@@ -1449,6 +1453,44 @@ function markoRun(opts = {}) {
|
|
|
1449
1453
|
typesDir = path2.join(root, ".marko-run");
|
|
1450
1454
|
devEntryFile = path2.join(root, "index.html");
|
|
1451
1455
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
1456
|
+
const assetsDir = ((_c = config2.build) == null ? void 0 : _c.assetsDir) || "assets";
|
|
1457
|
+
let rollupOutputOptions = (_e = (_d = config2.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output;
|
|
1458
|
+
if (isBuild && !isSSRBuild) {
|
|
1459
|
+
const defaultRollupOutputOptions = {
|
|
1460
|
+
assetFileNames({ name }) {
|
|
1461
|
+
if (name && name.indexOf("_marko-virtual_id_") < 0) {
|
|
1462
|
+
return `${assetsDir}/${getEntryFileName(name) || "[name]"}-[hash].[ext]`;
|
|
1463
|
+
}
|
|
1464
|
+
return `${assetsDir}/_[hash].[ext]`;
|
|
1465
|
+
},
|
|
1466
|
+
entryFileNames(info) {
|
|
1467
|
+
let name = getEntryFileName(info.facadeModuleId);
|
|
1468
|
+
if (!name) {
|
|
1469
|
+
for (let id of info.moduleIds) {
|
|
1470
|
+
name = getEntryFileName(id);
|
|
1471
|
+
if (name) {
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
return `${assetsDir}/${name || "[name]"}-[hash].js`;
|
|
1477
|
+
},
|
|
1478
|
+
chunkFileNames: `${assetsDir}/_[hash].js`
|
|
1479
|
+
};
|
|
1480
|
+
if (!rollupOutputOptions) {
|
|
1481
|
+
rollupOutputOptions = defaultRollupOutputOptions;
|
|
1482
|
+
} else if (!Array.isArray(rollupOutputOptions)) {
|
|
1483
|
+
rollupOutputOptions = {
|
|
1484
|
+
...defaultRollupOutputOptions,
|
|
1485
|
+
...rollupOutputOptions
|
|
1486
|
+
};
|
|
1487
|
+
} else {
|
|
1488
|
+
rollupOutputOptions = rollupOutputOptions.map((options) => ({
|
|
1489
|
+
...defaultRollupOutputOptions,
|
|
1490
|
+
...options
|
|
1491
|
+
}));
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1452
1494
|
let pluginConfig = {
|
|
1453
1495
|
logLevel: isBuild ? "warn" : void 0,
|
|
1454
1496
|
define: isBuild ? {
|
|
@@ -1458,10 +1500,13 @@ function markoRun(opts = {}) {
|
|
|
1458
1500
|
noExternal: /@marko\/run/
|
|
1459
1501
|
},
|
|
1460
1502
|
build: {
|
|
1461
|
-
emptyOutDir: isSSRBuild
|
|
1503
|
+
emptyOutDir: isSSRBuild,
|
|
1504
|
+
rollupOptions: {
|
|
1505
|
+
output: rollupOutputOptions
|
|
1506
|
+
}
|
|
1462
1507
|
}
|
|
1463
1508
|
};
|
|
1464
|
-
const adapterConfig = await ((
|
|
1509
|
+
const adapterConfig = await ((_f = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _f.call(adapter, config2));
|
|
1465
1510
|
if (adapterConfig) {
|
|
1466
1511
|
pluginConfig = mergeConfig(pluginConfig, adapterConfig);
|
|
1467
1512
|
}
|
|
@@ -1581,6 +1626,15 @@ function markoRun(opts = {}) {
|
|
|
1581
1626
|
{
|
|
1582
1627
|
name: "marko-run-vite:post",
|
|
1583
1628
|
enforce: "post",
|
|
1629
|
+
generateBundle(options, bundle) {
|
|
1630
|
+
if (options.sourcemap && options.sourcemap !== "inline") {
|
|
1631
|
+
for (const key of Object.keys(bundle)) {
|
|
1632
|
+
if (key.endsWith(".map") && !bundle[key.slice(0, -4)]) {
|
|
1633
|
+
delete bundle[key];
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
},
|
|
1584
1638
|
async writeBundle(options, bundle) {
|
|
1585
1639
|
var _a;
|
|
1586
1640
|
if (isSSRBuild) {
|
|
@@ -1697,12 +1751,17 @@ async function resolveAdapter(root, options, log) {
|
|
|
1697
1751
|
const { resolvePackageData } = await import("vite");
|
|
1698
1752
|
const pkg = resolvePackageData(".", root);
|
|
1699
1753
|
if (pkg) {
|
|
1700
|
-
const dependecies = {
|
|
1754
|
+
const dependecies = {
|
|
1755
|
+
...pkg.data.dependecies,
|
|
1756
|
+
...pkg.data.devDependencies
|
|
1757
|
+
};
|
|
1701
1758
|
for (const name of Object.keys(dependecies)) {
|
|
1702
1759
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
1703
1760
|
try {
|
|
1704
1761
|
const module2 = await import(name);
|
|
1705
|
-
log && console.log(
|
|
1762
|
+
log && console.log(
|
|
1763
|
+
`Using adapter ${name} listed in your package.json dependecies`
|
|
1764
|
+
);
|
|
1706
1765
|
return module2.default();
|
|
1707
1766
|
} catch (err) {
|
|
1708
1767
|
log && console.warn(`Attempt to use package '${name}' failed`, err);
|
|
@@ -1715,6 +1774,11 @@ async function resolveAdapter(root, options, log) {
|
|
|
1715
1774
|
log && console.log("Using default adapter");
|
|
1716
1775
|
return module.default();
|
|
1717
1776
|
}
|
|
1777
|
+
var markoEntryFileRegex = /__marko-run__([^_]+)__(.+)\.marko.([^.]+)$/;
|
|
1778
|
+
function getEntryFileName(file) {
|
|
1779
|
+
const match = file && markoEntryFileRegex.exec(file);
|
|
1780
|
+
return match ? `${match[2].replace(/__/g, "-")}` : void 0;
|
|
1781
|
+
}
|
|
1718
1782
|
|
|
1719
1783
|
// src/vite/utils/server.ts
|
|
1720
1784
|
import net from "net";
|
|
@@ -1750,7 +1814,10 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
1750
1814
|
proc.kill();
|
|
1751
1815
|
};
|
|
1752
1816
|
try {
|
|
1753
|
-
await
|
|
1817
|
+
await Promise.race([
|
|
1818
|
+
waitForError(proc, port),
|
|
1819
|
+
waitForServer(port, wait)
|
|
1820
|
+
]);
|
|
1754
1821
|
} catch (err) {
|
|
1755
1822
|
close();
|
|
1756
1823
|
throw err;
|
|
@@ -1760,6 +1827,14 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
1760
1827
|
close
|
|
1761
1828
|
};
|
|
1762
1829
|
}
|
|
1830
|
+
async function waitForError(proc, port) {
|
|
1831
|
+
return new Promise((_, reject) => {
|
|
1832
|
+
proc.once("error", reject);
|
|
1833
|
+
proc.once("exit", (code) => {
|
|
1834
|
+
reject(new Error(`Process exited with code ${code} while waiting for server to start on port "${port}".`));
|
|
1835
|
+
});
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1763
1838
|
async function waitForServer(port, wait = 0) {
|
|
1764
1839
|
let remaining = wait > 0 ? wait : Infinity;
|
|
1765
1840
|
let connection;
|
|
@@ -1769,7 +1844,7 @@ async function waitForServer(port, wait = 0) {
|
|
|
1769
1844
|
await sleep(100);
|
|
1770
1845
|
} else {
|
|
1771
1846
|
throw new Error(
|
|
1772
|
-
`
|
|
1847
|
+
`Timeout while wating for server to start on port "${port}".`
|
|
1773
1848
|
);
|
|
1774
1849
|
}
|
|
1775
1850
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { type Socket } from "net";
|
|
4
|
+
import { ChildProcess } from "child_process";
|
|
3
5
|
import { type Worker } from "cluster";
|
|
4
6
|
export interface SpawnedServer {
|
|
5
7
|
port: number;
|
|
@@ -9,7 +11,9 @@ export declare function parseEnv(envFile: string): Promise<import("dotenv").Dote
|
|
|
9
11
|
export declare function loadEnv(envFile: string): void;
|
|
10
12
|
export declare function spawnServer(cmd: string, args?: string[], port?: number, env?: string | Record<string, string>, cwd?: string, wait?: number): Promise<SpawnedServer>;
|
|
11
13
|
export declare function spawnServerWorker(module: string, args?: string[], port?: number, env?: string | Record<string, string>): Promise<Worker>;
|
|
14
|
+
export declare function waitForError(proc: ChildProcess, port: number): Promise<void>;
|
|
12
15
|
export declare function waitForServer(port: number, wait?: number): Promise<Socket>;
|
|
16
|
+
export declare function waitForWorker(worker: Worker, port: number): Promise<void>;
|
|
13
17
|
export declare function getConnection(port: number): Promise<Socket | null>;
|
|
14
18
|
export declare function isPortInUse(port: number): Promise<boolean>;
|
|
15
19
|
export declare function getAvailablePort(): Promise<number>;
|