vite-plugin-fastly 0.0.2 → 0.0.3
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/plugin.js +8 -38
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createProxy } from "http-proxy-3";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { execSync, spawn } from "child_process";
|
|
5
|
-
import {
|
|
5
|
+
import { launchAndTest } from "kill-em-all";
|
|
6
6
|
|
|
7
7
|
// src/plugin/expose-environment.ts
|
|
8
8
|
function exposeEnvironment() {
|
|
@@ -197,41 +197,11 @@ function fastly(options = {}) {
|
|
|
197
197
|
this.info(`[${uniqueName}] Launching Fastly Dev Server with command:`);
|
|
198
198
|
this.info(`[${uniqueName}] ${launchCommand}`);
|
|
199
199
|
const fastlyDevServerProcess = await spawnCommand(launchCommand);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const maxAttempts = 60;
|
|
204
|
-
let attempts = 0;
|
|
205
|
-
const interval = setInterval(async () => {
|
|
206
|
-
attempts++;
|
|
207
|
-
if (attempts > maxAttempts) {
|
|
208
|
-
clearInterval(interval);
|
|
209
|
-
reject(
|
|
210
|
-
new Error(
|
|
211
|
-
`[${uniqueName}] Fastly Dev Server did not become ready in time.`
|
|
212
|
-
)
|
|
213
|
-
);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
const response = await fetch(
|
|
218
|
-
`http://${fastlyDevServerAddress}/@vite-plugin-fastly/ready`
|
|
219
|
-
);
|
|
220
|
-
if (response.ok) {
|
|
221
|
-
clearInterval(interval);
|
|
222
|
-
resolve();
|
|
223
|
-
}
|
|
224
|
-
} catch {
|
|
225
|
-
}
|
|
226
|
-
}, checkInterval);
|
|
227
|
-
}).catch(async (error) => {
|
|
228
|
-
await doKillProcesses(this, uniqueName);
|
|
229
|
-
throw error;
|
|
230
|
-
});
|
|
231
|
-
fastlyProcesses.set(
|
|
232
|
-
uniqueName,
|
|
233
|
-
await getRecursiveChildProcesses(fastlyDevServerProcess.pid)
|
|
200
|
+
const kill = await launchAndTest(
|
|
201
|
+
fastlyDevServerProcess,
|
|
202
|
+
`http://${fastlyDevServerAddress}/@vite-plugin-fastly/ready`
|
|
234
203
|
);
|
|
204
|
+
fastlyProcesses.set(uniqueName, kill);
|
|
235
205
|
this.info(
|
|
236
206
|
`[${uniqueName}] Fastly Dev Server is running at http://${fastlyDevServerAddress}`
|
|
237
207
|
);
|
|
@@ -395,11 +365,11 @@ function statOrNull(path) {
|
|
|
395
365
|
}
|
|
396
366
|
}
|
|
397
367
|
async function doKillProcesses(ctx, name) {
|
|
398
|
-
const
|
|
399
|
-
if (!
|
|
368
|
+
const kill = fastlyProcesses.get(name);
|
|
369
|
+
if (!kill) return;
|
|
400
370
|
fastlyProcesses.delete(name);
|
|
401
371
|
ctx.info(`[${name}] Shutting down Fastly dev server`);
|
|
402
|
-
await
|
|
372
|
+
await kill();
|
|
403
373
|
ctx.info(`[${name}] Fastly dev server shut down`);
|
|
404
374
|
}
|
|
405
375
|
async function spawnCommand(command) {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin/plugin.ts","../src/plugin/expose-environment.ts"],"sourcesContent":["import type { ConfigPluginContext, Connect, HttpServer, Plugin } from \"vite\";\nimport { createProxy, type ServerOptions } from \"http-proxy-3\";\nimport type { IncomingMessage } from \"node:http\";\nimport fs from \"node:fs\";\nimport { ChildProcess, execSync, spawn } from \"node:child_process\";\nimport { getRecursiveChildProcesses, killProcesses } from \"kill-em-all\";\nimport exposeEnvironment from \"./expose-environment\";\n\nexport interface FastlyPluginOptions {\n\t/**\n\t * A unique key to identify the plugin instance. This is required if you\n\t * have multiple Fastly plugin instances in the same Vite configuration.\n\t *\n\t * @default \"vite-plugin-fastly\"\n\t */\n\tuniqueName?: string;\n\n\t/**\n\t * Vite environment name that the Fastly plugin should configure.\n\t *\n\t * @default \"ssr\"\n\t */\n\tviteEnvironmentName?: string;\n\n\t/**\n\t * Function that returns the command to build the Fastly Module Runner.\n\t * The callback receives the input and output file paths.\n\t *\n\t * @default (input, output) => `js-compute-runtime ${input} ${output}`\n\t */\n\tgetRunnerBuildCommand?: (input: string, output: string) => string;\n\n\t/**\n\t * IPv4 address of the Fastly Dev Server to proxy requests to during development.\n\t * If you have multiple Fastly plugin instances, make sure each instance uses\n\t * a unique address.\n\t *\n\t * @default \"127.0.0.1:7676\"\n\t */\n\tfastlyDevServerAddress?: string;\n\n\t/**\n\t * Function that returns the command to launch the Fastly Dev Server.\n\t * The callback receives the compiled wasm file path and the address to bind to.\n\t *\n\t * @default (wasmFile, address) => `fastly compute serve --file=${wasmFile} --addr=${address}`\n\t */\n\tgetLaunchDevServerCommand?: (wasmFile: string, address: string) => string;\n\n\t/**\n\t * Options to pass to the HTTP proxy server.\n\t *\n\t * @default {}\n\t */\n\tproxyOptions?: ServerOptions;\n}\n\n// Map of uniqueName to Fastly Dev Server child processes\nconst fastlyProcesses = new Map<string, number[]>();\n\nexport function fastly(options: FastlyPluginOptions = {}): Plugin[] {\n\tconst {\n\t\tuniqueName = \"vite-plugin-fastly\",\n\t\tviteEnvironmentName = \"ssr\",\n\t\tfastlyDevServerAddress = \"127.0.0.1:7676\",\n\t\tgetRunnerBuildCommand = (input: string, output: string) =>\n\t\t\t`js-compute-runtime ${input} ${output}`,\n\t\tgetLaunchDevServerCommand = (wasmFile, address) =>\n\t\t\t`fastly compute serve --file=${wasmFile} --addr=${address}`,\n\t\tproxyOptions = {},\n\t} = options;\n\n\tlet command: \"serve\" | \"build\";\n\tlet handlerEntry: string | undefined;\n\tlet fastlyProcessKilled = false;\n\tlet clientConfigured = false;\n\tlet buildCommand: string | undefined;\n\n\treturn [\n\t\texposeEnvironment(),\n\t\t{\n\t\t\tname: uniqueName,\n\n\t\t\tconfig(_, env) {\n\t\t\t\treturn {\n\t\t\t\t\tenvironments: {\n\t\t\t\t\t\t[viteEnvironmentName]: {\n\t\t\t\t\t\t\toptimizeDeps: {\n\t\t\t\t\t\t\t\tnoDiscovery: false,\n\t\t\t\t\t\t\t\texclude: [\n\t\t\t\t\t\t\t\t\t\"fastly:acl\",\n\t\t\t\t\t\t\t\t\t\"fastly:backend\",\n\t\t\t\t\t\t\t\t\t\"fastly:cache\",\n\t\t\t\t\t\t\t\t\t\"fastly:cache-override\",\n\t\t\t\t\t\t\t\t\t\"fastly:compute\",\n\t\t\t\t\t\t\t\t\t\"fastly:config-store\",\n\t\t\t\t\t\t\t\t\t\"fastly:device\",\n\t\t\t\t\t\t\t\t\t\"fastly:dictionary\",\n\t\t\t\t\t\t\t\t\t\"fastly:edge-rate-limiter\",\n\t\t\t\t\t\t\t\t\t\"fastly:env\",\n\t\t\t\t\t\t\t\t\t\"fastly:experimental\",\n\t\t\t\t\t\t\t\t\t\"fastly:fanout\",\n\t\t\t\t\t\t\t\t\t\"fastly:geolocation\",\n\t\t\t\t\t\t\t\t\t\"fastly:html-rewriter\",\n\t\t\t\t\t\t\t\t\t\"fastly:image-optimizer\",\n\t\t\t\t\t\t\t\t\t\"fastly:kv-store\",\n\t\t\t\t\t\t\t\t\t\"fastly:logger\",\n\t\t\t\t\t\t\t\t\t\"fastly:secret-store\",\n\t\t\t\t\t\t\t\t\t\"fastly:websocket\",\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tesbuildOptions: {\n\t\t\t\t\t\t\t\t\tplatform: \"neutral\",\n\t\t\t\t\t\t\t\t\tminify: true,\n\t\t\t\t\t\t\t\t\tdefine: {\n\t\t\t\t\t\t\t\t\t\t\"process.env.NODE_ENV\": JSON.stringify(env.mode),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tresolve: {\n\t\t\t\t\t\t\t\tbuiltins: [/^fastly:/],\n\t\t\t\t\t\t\t\tnoExternal: true,\n\t\t\t\t\t\t\t\tconditions: [\"fastly\", \"workerd\"],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\t\t\tinlineDynamicImports: true,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdev: {},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\n\t\t\tapi: {\n\t\t\t\tfastly: {\n\t\t\t\t\taddress: fastlyDevServerAddress,\n\t\t\t\t},\n\t\t\t},\n\n\t\t\tconfigResolved(config) {\n\t\t\t\tcommand = config.command;\n\t\t\t\tif (command !== \"serve\") return;\n\n\t\t\t\t// Scan plugins for multiple instances with the same uniqueName\n\t\t\t\tlet sameNameInstanceCount = 0;\n\t\t\t\tlet sameAddressInstanceCount = 0;\n\t\t\t\tfor (const plugin of config.plugins) {\n\t\t\t\t\tif (plugin.name === uniqueName) {\n\t\t\t\t\t\tsameNameInstanceCount++;\n\t\t\t\t\t}\n\t\t\t\t\tif (plugin.api?.fastly?.address === fastlyDevServerAddress) {\n\t\t\t\t\t\tsameAddressInstanceCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (sameNameInstanceCount > 1) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] Multiple Fastly plugin instances with the same uniqueName \"${uniqueName}\" detected.`,\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] If you really need multiple instances, give each instance a unique \"uniqueName\".`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (sameAddressInstanceCount > 1) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] Multiple Fastly plugin instances configured to use the same Fastly Dev Server address \"${fastlyDevServerAddress}\".`,\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] If you really need multiple instances, give each instance a unique \"fastlyDevServerAddress\"`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (sameNameInstanceCount > 1 || sameAddressInstanceCount > 1) {\n\t\t\t\t\t// This is a fatal error, we cannot continue\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\n\t\t\t\tconst clientInput =\n\t\t\t\t\tconfig.environments.client?.build.rollupOptions.input;\n\t\t\t\tif (typeof clientInput === \"string\") {\n\t\t\t\t\tclientConfigured = true;\n\t\t\t\t} else if (Array.isArray(clientInput) && clientInput.length > 0) {\n\t\t\t\t\tclientConfigured = true;\n\t\t\t\t} else if (\n\t\t\t\t\ttypeof clientInput === \"object\" &&\n\t\t\t\t\tclientInput !== null &&\n\t\t\t\t\tObject.keys(clientInput).length > 0\n\t\t\t\t) {\n\t\t\t\t\tclientConfigured = true;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync configEnvironment(name, config, env) {\n\t\t\t\tif (name !== viteEnvironmentName || env.command !== \"serve\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst input = config.build?.rollupOptions?.input;\n\t\t\t\tif (typeof input === \"string\") {\n\t\t\t\t\thandlerEntry = input;\n\t\t\t\t} else if (Array.isArray(input)) {\n\t\t\t\t\thandlerEntry = input[0];\n\t\t\t\t} else if (typeof input === \"object\" && input !== null) {\n\t\t\t\t\tconst values = Object.values(input);\n\t\t\t\t\thandlerEntry = values[0];\n\t\t\t\t}\n\n\t\t\t\tif (!handlerEntry) {\n\t\t\t\t\treturn this.error(\n\t\t\t\t\t\t`[${uniqueName}] No entry point found in Rollup options. Please specify an input in environments.${viteEnvironmentName}.build.rollupOptions.input.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Kill previous Fastly Dev Server process if any\n\t\t\t\tfastlyProcessKilled = true;\n\t\t\t\tawait doKillProcesses(this, uniqueName);\n\n\t\t\t\tconst wasmFile = buildDevRunnerIfNecessary(\n\t\t\t\t\tthis,\n\t\t\t\t\tuniqueName,\n\t\t\t\t\tgetRunnerBuildCommand,\n\t\t\t\t);\n\n\t\t\t\tconst launchCommand = getLaunchDevServerCommand(\n\t\t\t\t\twasmFile,\n\t\t\t\t\tfastlyDevServerAddress,\n\t\t\t\t);\n\n\t\t\t\tthis.info(`[${uniqueName}] Launching Fastly Dev Server with command:`);\n\t\t\t\tthis.info(`[${uniqueName}] ${launchCommand}`);\n\t\t\t\tconst fastlyDevServerProcess = await spawnCommand(launchCommand);\n\n\t\t\t\tfastlyProcesses.set(uniqueName, [fastlyDevServerProcess.pid!]);\n\n\t\t\t\t// Wait until server is ready\n\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\tconst checkInterval = 500;\n\t\t\t\t\tconst maxAttempts = 60; // 30 seconds\n\t\t\t\t\tlet attempts = 0;\n\n\t\t\t\t\tconst interval = setInterval(async () => {\n\t\t\t\t\t\tattempts++;\n\t\t\t\t\t\tif (attempts > maxAttempts) {\n\t\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\t\treject(\n\t\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t\t`[${uniqueName}] Fastly Dev Server did not become ready in time.`,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst response = await fetch(\n\t\t\t\t\t\t\t\t`http://${fastlyDevServerAddress}/@vite-plugin-fastly/ready`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (response.ok) {\n\t\t\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore errors, server is not ready yet\n\t\t\t\t\t\t}\n\t\t\t\t\t}, checkInterval);\n\t\t\t\t}).catch(async (error) => {\n\t\t\t\t\tawait doKillProcesses(this, uniqueName);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\n\t\t\t\tfastlyProcesses.set(\n\t\t\t\t\tuniqueName,\n\t\t\t\t\tawait getRecursiveChildProcesses(fastlyDevServerProcess.pid!),\n\t\t\t\t);\n\n\t\t\t\tthis.info(\n\t\t\t\t\t`[${uniqueName}] Fastly Dev Server is running at http://${fastlyDevServerAddress}`,\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tasync writeBundle(outputOptions, bundle) {\n\t\t\t\tif (\n\t\t\t\t\tcommand !== \"build\" ||\n\t\t\t\t\tthis.environment.name !== viteEnvironmentName\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst jsFile = Object.values(bundle).find(\n\t\t\t\t\t(file) => file.type === \"chunk\" && file.isEntry,\n\t\t\t\t);\n\t\t\t\tif (!jsFile) {\n\t\t\t\t\tthrow new Error(`[${uniqueName}] No JS entry chunk found in bundle.`);\n\t\t\t\t}\n\n\t\t\t\tconst input = outputOptions.dir + \"/\" + jsFile.fileName;\n\t\t\t\tconst output = outputOptions.dir + \"/app.wasm\";\n\n\t\t\t\tbuildCommand = `js-compute-runtime ${input} ${output}`;\n\t\t\t},\n\n\t\t\tasync closeBundle(error) {\n\t\t\t\tif (\n\t\t\t\t\terror ||\n\t\t\t\t\tcommand !== \"build\" ||\n\t\t\t\t\tthis.environment.name !== viteEnvironmentName\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.info(`Building Fastly WASM module with command:`);\n\t\t\t\tthis.info(buildCommand!);\n\t\t\t\texecSync(buildCommand!, { stdio: \"inherit\" });\n\t\t\t},\n\n\t\t\tasync buildEnd() {\n\t\t\t\tif (command === \"build\" || fastlyProcessKilled) return;\n\t\t\t\tfastlyProcessKilled = true;\n\t\t\t\tawait doKillProcesses(this, uniqueName);\n\t\t\t},\n\n\t\t\tconfigureServer(server) {\n\t\t\t\tconst environment = server.environments[viteEnvironmentName]!;\n\t\t\t\tlet address: string | null = null;\n\n\t\t\t\tserver.httpServer?.on(\"listening\", () => {\n\t\t\t\t\taddress = getServerAddress(server.httpServer);\n\t\t\t\t});\n\n\t\t\t\tserver.httpServer?.on(\"close\", () => {\n\t\t\t\t\taddress = null;\n\t\t\t\t});\n\n\t\t\t\t// Transport endpoint for the runner\n\t\t\t\tserver.middlewares.use((req, res, next) => {\n\t\t\t\t\tif (\n\t\t\t\t\t\treq.method !== \"POST\" ||\n\t\t\t\t\t\treq.url !== \"/@vite-plugin-fastly/transport\"\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn next();\n\t\t\t\t\t}\n\n\t\t\t\t\tvoid (async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Read the body\n\t\t\t\t\t\t\tconst body = await readyBody(req);\n\t\t\t\t\t\t\tconst data = JSON.parse(body);\n\n\t\t\t\t\t\t\tconst result = await environment.hot.handleInvoke(data);\n\n\t\t\t\t\t\t\tres.setHeader(\"Content-Type\", \"application/json\");\n\t\t\t\t\t\t\tres.end(JSON.stringify(result));\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\treturn next(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t});\n\n\t\t\t\tconst proxy = createProxy(proxyOptions);\n\n\t\t\t\tconst proxyMiddleware: Connect.NextHandleFunction = (\n\t\t\t\t\treq,\n\t\t\t\t\tres,\n\t\t\t\t\tnext,\n\t\t\t\t) => {\n\t\t\t\t\tif (!address) {\n\t\t\t\t\t\treturn next(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t`[${uniqueName}] Vite server address is not available for proxying`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tproxy.web(\n\t\t\t\t\t\t\treq,\n\t\t\t\t\t\t\tres,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttarget: `http://${fastlyDevServerAddress}`,\n\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t\"Vite-Plugin-Fastly-Vite-Server-Address\": address,\n\t\t\t\t\t\t\t\t\t\"Vite-Plugin-Fastly-Handler-Entry\": handlerEntry,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\t\tnext(error);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tnext(error);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// If a client build is configured, add the proxy middleware after Vite's own middlewares.\n\t\t\t\t// Otherwise, assume a pure server-side setup and add the proxy as the first middleware.\n\t\t\t\tif (clientConfigured) {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tserver.middlewares.use(proxyMiddleware);\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\tserver.middlewares.use(proxyMiddleware);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t];\n}\n\nasync function readyBody(req: IncomingMessage): Promise<string> {\n\treturn new Promise<string>((resolve, reject) => {\n\t\tlet body = \"\";\n\t\treq.on(\"data\", (chunk) => {\n\t\t\tbody += chunk;\n\t\t});\n\n\t\treq.on(\"end\", () => {\n\t\t\tresolve(body);\n\t\t});\n\n\t\treq.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n\nfunction getServerAddress(server: HttpServer | null): string | null {\n\tconst address = server?.address();\n\tif (!address) {\n\t\treturn null;\n\t}\n\n\tlet host: string;\n\n\tif (typeof address === \"string\") {\n\t\thost = address;\n\t} else {\n\t\tswitch (address.address) {\n\t\t\tcase \"127.0.0.1\":\n\t\t\tcase \"::\":\n\t\t\tcase \"::1\":\n\t\t\tcase \"0000:0000:0000:0000:0000:0000:0000:0001\":\n\t\t\t\thost = \"localhost\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\thost = address.address;\n\t\t}\n\n\t\thost = `http://${host}:${address.port}`;\n\t}\n\n\treturn host;\n}\n\nfunction buildDevRunnerIfNecessary(\n\tctx: ConfigPluginContext,\n\tuniqueName: string,\n\tgetCommand: (input: string, output: string) => string,\n): string {\n\tconst jsComputeRuntimeVersion = getJsComputeRuntimeVersion(uniqueName);\n\tconst input = \"node_modules/vite-plugin-fastly/dist/runner.js\";\n\tconst output = `node_modules/.vite-plugin-fastly/runner.${jsComputeRuntimeVersion}.wasm`;\n\n\tconst inputStat = fs.statSync(input);\n\tconst outputStat = statOrNull(output);\n\n\tif (\n\t\toutputStat &&\n\t\toutputStat.isFile() &&\n\t\toutputStat.mtimeMs >= inputStat.mtimeMs\n\t) {\n\t\t// Up to date\n\t\treturn output;\n\t}\n\n\tctx.info(`[${uniqueName}] Building Fastly Module Runner for dev server...`);\n\n\texecSync(getCommand(input, output), { stdio: \"inherit\" });\n\n\treturn output;\n}\n\nfunction getJsComputeRuntimeVersion(uniqueName: string): string {\n\tconst output = execSync(\"js-compute-runtime --version\").toString();\n\n\t// Parse version from something like \"js-compute-runtime-cli.js 3.38.2\\n\"\n\tconst lastSpaceIndex = output.lastIndexOf(\" \");\n\tif (lastSpaceIndex === -1) {\n\t\tthrow new Error(\n\t\t\t`[${uniqueName}] Unexpected js-compute-runtime version output: ${output}`,\n\t\t);\n\t}\n\n\treturn output.slice(lastSpaceIndex + 1).trim();\n}\n\nfunction statOrNull(path: string): fs.Stats | null {\n\ttry {\n\t\treturn fs.statSync(path);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function doKillProcesses(\n\tctx: {\n\t\tinfo: (msg: string) => void;\n\t},\n\tname: string,\n) {\n\tconst proc = fastlyProcesses.get(name);\n\tif (!proc) return;\n\n\tfastlyProcesses.delete(name);\n\n\tctx.info(`[${name}] Shutting down Fastly dev server`);\n\tawait killProcesses(proc, \"SIGINT\");\n\n\tctx.info(`[${name}] Fastly dev server shut down`);\n}\n\nasync function spawnCommand(command: string): Promise<ChildProcess> {\n\tconst child = spawn(command, {\n\t\tshell: true,\n\t\tstdio: \"inherit\",\n\t});\n\n\treturn await new Promise((resolve, reject) => {\n\t\tchild.on(\"spawn\", () => {\n\t\t\tif (!child.pid) {\n\t\t\t\treturn reject(new Error(\"Failed to spawn process\"));\n\t\t\t}\n\n\t\t\tresolve(child);\n\t\t});\n\n\t\tchild.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n\nlet killAllInProgress = false;\n\nasync function killAll() {\n\tkillAllInProgress = true;\n\tconst promises: Promise<void>[] = [];\n\tfor (const name of fastlyProcesses.keys()) {\n\t\tpromises.push(\n\t\t\tdoKillProcesses(\n\t\t\t\t{\n\t\t\t\t\tinfo: (msg: string) => {\n\t\t\t\t\t\tprocess.stdout.write(msg + \"\\n\");\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tname,\n\t\t\t),\n\t\t);\n\t}\n\tawait Promise.all(promises);\n}\n\nfunction cleanupOnExit() {\n\tif (!killAllInProgress) {\n\t\tvoid killAll().finally(() => {\n\t\t\tprocess.exit(0);\n\t\t});\n\t}\n}\n\nprocess.on(\"SIGINT\", cleanupOnExit);\nprocess.on(\"SIGTERM\", cleanupOnExit);\nprocess.on(\"exit\", cleanupOnExit);\n","import type { Plugin } from \"vite\";\n\nexport default function exposeEnvironment(): Plugin {\n\tlet devServerUrl: string | undefined;\n\tlet command: \"serve\" | \"build\";\n\n\tfunction getModuleContents(environmentName: string) {\n\t\tconst url = devServerUrl ? JSON.stringify(devServerUrl) : \"undefined\";\n\n\t\treturn (\n\t\t\t`export const name = ${JSON.stringify(environmentName)}\\n` +\n\t\t\t`export const command = ${JSON.stringify(command)}\\n` +\n\t\t\t`export const devServerUrl = ${url}`\n\t\t);\n\t}\n\n\treturn {\n\t\tname: \"vite-plugin-fastly/expose-environment\",\n\n\t\tenforce: \"pre\",\n\n\t\tresolveId: {\n\t\t\tfilter: {\n\t\t\t\tid: /^vite-plugin-fastly:environment$/,\n\t\t\t},\n\t\t\thandler(source) {\n\t\t\t\tif (source === \"vite-plugin-fastly:environment\") {\n\t\t\t\t\treturn \"\\0virtual:vite-plugin-fastly:environment\";\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\n\t\tload: {\n\t\t\tfilter: {\n\t\t\t\tid: /^\\0virtual:vite-plugin-fastly:environment$/,\n\t\t\t},\n\t\t\thandler(id) {\n\t\t\t\tif (id !== \"\\0virtual:vite-plugin-fastly:environment\") return;\n\t\t\t\treturn getModuleContents(this.environment.name);\n\t\t\t},\n\t\t},\n\n\t\tconfigResolved(config) {\n\t\t\tcommand = config.command;\n\t\t},\n\n\t\tconfigureServer(server) {\n\t\t\tserver.httpServer?.once(\"listening\", () => {\n\t\t\t\tdevServerUrl = server.resolvedUrls?.local[0];\n\t\t\t});\n\t\t},\n\t} satisfies Plugin;\n}\n"],"mappings":";AACA,SAAS,mBAAuC;AAEhD,OAAO,QAAQ;AACf,SAAuB,UAAU,aAAa;AAC9C,SAAS,4BAA4B,qBAAqB;;;ACH3C,SAAR,oBAA6C;AACnD,MAAI;AACJ,MAAI;AAEJ,WAAS,kBAAkB,iBAAyB;AACnD,UAAM,MAAM,eAAe,KAAK,UAAU,YAAY,IAAI;AAE1D,WACC,uBAAuB,KAAK,UAAU,eAAe,CAAC;AAAA,yBAC5B,KAAK,UAAU,OAAO,CAAC;AAAA,8BAClB,GAAG;AAAA,EAEpC;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,IAEN,SAAS;AAAA,IAET,WAAW;AAAA,MACV,QAAQ;AAAA,QACP,IAAI;AAAA,MACL;AAAA,MACA,QAAQ,QAAQ;AACf,YAAI,WAAW,kCAAkC;AAChD,iBAAO;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,IAEA,MAAM;AAAA,MACL,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AAAA,UAChC;AAAA,QACD;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,QAAM,QAAQ,IAAI,QAAQ;AAC3B;AAEA,SAAS,gBAAgB;AACxB,MAAI,CAAC,mBAAmB;AACvB,SAAK,QAAQ,EAAE,QAAQ,MAAM;AAC5B,cAAQ,KAAK,CAAC;AAAA,IACf,CAAC;AAAA,EACF;AACD;AAEA,QAAQ,GAAG,UAAU,aAAa;AAClC,QAAQ,GAAG,WAAW,aAAa;AACnC,QAAQ,GAAG,QAAQ,aAAa;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/plugin/plugin.ts","../src/plugin/expose-environment.ts"],"sourcesContent":["import type { ConfigPluginContext, Connect, HttpServer, Plugin } from \"vite\";\nimport { createProxy, type ServerOptions } from \"http-proxy-3\";\nimport type { IncomingMessage } from \"node:http\";\nimport fs from \"node:fs\";\nimport { ChildProcess, execSync, spawn } from \"node:child_process\";\nimport { launchAndTest, type LaunchAndTestCleanupFunction } from \"kill-em-all\";\nimport exposeEnvironment from \"./expose-environment\";\n\nexport interface FastlyPluginOptions {\n\t/**\n\t * A unique key to identify the plugin instance. This is required if you\n\t * have multiple Fastly plugin instances in the same Vite configuration.\n\t *\n\t * @default \"vite-plugin-fastly\"\n\t */\n\tuniqueName?: string;\n\n\t/**\n\t * Vite environment name that the Fastly plugin should configure.\n\t *\n\t * @default \"ssr\"\n\t */\n\tviteEnvironmentName?: string;\n\n\t/**\n\t * Function that returns the command to build the Fastly Module Runner.\n\t * The callback receives the input and output file paths.\n\t *\n\t * @default (input, output) => `js-compute-runtime ${input} ${output}`\n\t */\n\tgetRunnerBuildCommand?: (input: string, output: string) => string;\n\n\t/**\n\t * IPv4 address of the Fastly Dev Server to proxy requests to during development.\n\t * If you have multiple Fastly plugin instances, make sure each instance uses\n\t * a unique address.\n\t *\n\t * @default \"127.0.0.1:7676\"\n\t */\n\tfastlyDevServerAddress?: string;\n\n\t/**\n\t * Function that returns the command to launch the Fastly Dev Server.\n\t * The callback receives the compiled wasm file path and the address to bind to.\n\t *\n\t * @default (wasmFile, address) => `fastly compute serve --file=${wasmFile} --addr=${address}`\n\t */\n\tgetLaunchDevServerCommand?: (wasmFile: string, address: string) => string;\n\n\t/**\n\t * Options to pass to the HTTP proxy server.\n\t *\n\t * @default {}\n\t */\n\tproxyOptions?: ServerOptions;\n}\n\n// Map of uniqueName to Fastly Dev Server child processes\nconst fastlyProcesses = new Map<string, LaunchAndTestCleanupFunction>();\n\nexport function fastly(options: FastlyPluginOptions = {}): Plugin[] {\n\tconst {\n\t\tuniqueName = \"vite-plugin-fastly\",\n\t\tviteEnvironmentName = \"ssr\",\n\t\tfastlyDevServerAddress = \"127.0.0.1:7676\",\n\t\tgetRunnerBuildCommand = (input: string, output: string) =>\n\t\t\t`js-compute-runtime ${input} ${output}`,\n\t\tgetLaunchDevServerCommand = (wasmFile, address) =>\n\t\t\t`fastly compute serve --file=${wasmFile} --addr=${address}`,\n\t\tproxyOptions = {},\n\t} = options;\n\n\tlet command: \"serve\" | \"build\";\n\tlet handlerEntry: string | undefined;\n\tlet fastlyProcessKilled = false;\n\tlet clientConfigured = false;\n\tlet buildCommand: string | undefined;\n\n\treturn [\n\t\texposeEnvironment(),\n\t\t{\n\t\t\tname: uniqueName,\n\n\t\t\tconfig(_, env) {\n\t\t\t\treturn {\n\t\t\t\t\tenvironments: {\n\t\t\t\t\t\t[viteEnvironmentName]: {\n\t\t\t\t\t\t\toptimizeDeps: {\n\t\t\t\t\t\t\t\tnoDiscovery: false,\n\t\t\t\t\t\t\t\texclude: [\n\t\t\t\t\t\t\t\t\t\"fastly:acl\",\n\t\t\t\t\t\t\t\t\t\"fastly:backend\",\n\t\t\t\t\t\t\t\t\t\"fastly:cache\",\n\t\t\t\t\t\t\t\t\t\"fastly:cache-override\",\n\t\t\t\t\t\t\t\t\t\"fastly:compute\",\n\t\t\t\t\t\t\t\t\t\"fastly:config-store\",\n\t\t\t\t\t\t\t\t\t\"fastly:device\",\n\t\t\t\t\t\t\t\t\t\"fastly:dictionary\",\n\t\t\t\t\t\t\t\t\t\"fastly:edge-rate-limiter\",\n\t\t\t\t\t\t\t\t\t\"fastly:env\",\n\t\t\t\t\t\t\t\t\t\"fastly:experimental\",\n\t\t\t\t\t\t\t\t\t\"fastly:fanout\",\n\t\t\t\t\t\t\t\t\t\"fastly:geolocation\",\n\t\t\t\t\t\t\t\t\t\"fastly:html-rewriter\",\n\t\t\t\t\t\t\t\t\t\"fastly:image-optimizer\",\n\t\t\t\t\t\t\t\t\t\"fastly:kv-store\",\n\t\t\t\t\t\t\t\t\t\"fastly:logger\",\n\t\t\t\t\t\t\t\t\t\"fastly:secret-store\",\n\t\t\t\t\t\t\t\t\t\"fastly:websocket\",\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tesbuildOptions: {\n\t\t\t\t\t\t\t\t\tplatform: \"neutral\",\n\t\t\t\t\t\t\t\t\tminify: true,\n\t\t\t\t\t\t\t\t\tdefine: {\n\t\t\t\t\t\t\t\t\t\t\"process.env.NODE_ENV\": JSON.stringify(env.mode),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tresolve: {\n\t\t\t\t\t\t\t\tbuiltins: [/^fastly:/],\n\t\t\t\t\t\t\t\tnoExternal: true,\n\t\t\t\t\t\t\t\tconditions: [\"fastly\", \"workerd\"],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\t\t\tinlineDynamicImports: true,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdev: {},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\n\t\t\tapi: {\n\t\t\t\tfastly: {\n\t\t\t\t\taddress: fastlyDevServerAddress,\n\t\t\t\t},\n\t\t\t},\n\n\t\t\tconfigResolved(config) {\n\t\t\t\tcommand = config.command;\n\t\t\t\tif (command !== \"serve\") return;\n\n\t\t\t\t// Scan plugins for multiple instances with the same uniqueName\n\t\t\t\tlet sameNameInstanceCount = 0;\n\t\t\t\tlet sameAddressInstanceCount = 0;\n\t\t\t\tfor (const plugin of config.plugins) {\n\t\t\t\t\tif (plugin.name === uniqueName) {\n\t\t\t\t\t\tsameNameInstanceCount++;\n\t\t\t\t\t}\n\t\t\t\t\tif (plugin.api?.fastly?.address === fastlyDevServerAddress) {\n\t\t\t\t\t\tsameAddressInstanceCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (sameNameInstanceCount > 1) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] Multiple Fastly plugin instances with the same uniqueName \"${uniqueName}\" detected.`,\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] If you really need multiple instances, give each instance a unique \"uniqueName\".`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (sameAddressInstanceCount > 1) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] Multiple Fastly plugin instances configured to use the same Fastly Dev Server address \"${fastlyDevServerAddress}\".`,\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[vite-plugin-fastly] If you really need multiple instances, give each instance a unique \"fastlyDevServerAddress\"`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (sameNameInstanceCount > 1 || sameAddressInstanceCount > 1) {\n\t\t\t\t\t// This is a fatal error, we cannot continue\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\n\t\t\t\tconst clientInput =\n\t\t\t\t\tconfig.environments.client?.build.rollupOptions.input;\n\t\t\t\tif (typeof clientInput === \"string\") {\n\t\t\t\t\tclientConfigured = true;\n\t\t\t\t} else if (Array.isArray(clientInput) && clientInput.length > 0) {\n\t\t\t\t\tclientConfigured = true;\n\t\t\t\t} else if (\n\t\t\t\t\ttypeof clientInput === \"object\" &&\n\t\t\t\t\tclientInput !== null &&\n\t\t\t\t\tObject.keys(clientInput).length > 0\n\t\t\t\t) {\n\t\t\t\t\tclientConfigured = true;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync configEnvironment(name, config, env) {\n\t\t\t\tif (name !== viteEnvironmentName || env.command !== \"serve\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst input = config.build?.rollupOptions?.input;\n\t\t\t\tif (typeof input === \"string\") {\n\t\t\t\t\thandlerEntry = input;\n\t\t\t\t} else if (Array.isArray(input)) {\n\t\t\t\t\thandlerEntry = input[0];\n\t\t\t\t} else if (typeof input === \"object\" && input !== null) {\n\t\t\t\t\tconst values = Object.values(input);\n\t\t\t\t\thandlerEntry = values[0];\n\t\t\t\t}\n\n\t\t\t\tif (!handlerEntry) {\n\t\t\t\t\treturn this.error(\n\t\t\t\t\t\t`[${uniqueName}] No entry point found in Rollup options. Please specify an input in environments.${viteEnvironmentName}.build.rollupOptions.input.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Kill previous Fastly Dev Server process if any\n\t\t\t\tfastlyProcessKilled = true;\n\t\t\t\tawait doKillProcesses(this, uniqueName);\n\n\t\t\t\tconst wasmFile = buildDevRunnerIfNecessary(\n\t\t\t\t\tthis,\n\t\t\t\t\tuniqueName,\n\t\t\t\t\tgetRunnerBuildCommand,\n\t\t\t\t);\n\n\t\t\t\tconst launchCommand = getLaunchDevServerCommand(\n\t\t\t\t\twasmFile,\n\t\t\t\t\tfastlyDevServerAddress,\n\t\t\t\t);\n\n\t\t\t\tthis.info(`[${uniqueName}] Launching Fastly Dev Server with command:`);\n\t\t\t\tthis.info(`[${uniqueName}] ${launchCommand}`);\n\t\t\t\tconst fastlyDevServerProcess = await spawnCommand(launchCommand);\n\n\t\t\t\tconst kill = await launchAndTest(\n\t\t\t\t\tfastlyDevServerProcess,\n\t\t\t\t\t`http://${fastlyDevServerAddress}/@vite-plugin-fastly/ready`,\n\t\t\t\t);\n\n\t\t\t\tfastlyProcesses.set(uniqueName, kill);\n\n\t\t\t\tthis.info(\n\t\t\t\t\t`[${uniqueName}] Fastly Dev Server is running at http://${fastlyDevServerAddress}`,\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tasync writeBundle(outputOptions, bundle) {\n\t\t\t\tif (\n\t\t\t\t\tcommand !== \"build\" ||\n\t\t\t\t\tthis.environment.name !== viteEnvironmentName\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst jsFile = Object.values(bundle).find(\n\t\t\t\t\t(file) => file.type === \"chunk\" && file.isEntry,\n\t\t\t\t);\n\t\t\t\tif (!jsFile) {\n\t\t\t\t\tthrow new Error(`[${uniqueName}] No JS entry chunk found in bundle.`);\n\t\t\t\t}\n\n\t\t\t\tconst input = outputOptions.dir + \"/\" + jsFile.fileName;\n\t\t\t\tconst output = outputOptions.dir + \"/app.wasm\";\n\n\t\t\t\tbuildCommand = `js-compute-runtime ${input} ${output}`;\n\t\t\t},\n\n\t\t\tasync closeBundle(error) {\n\t\t\t\tif (\n\t\t\t\t\terror ||\n\t\t\t\t\tcommand !== \"build\" ||\n\t\t\t\t\tthis.environment.name !== viteEnvironmentName\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.info(`Building Fastly WASM module with command:`);\n\t\t\t\tthis.info(buildCommand!);\n\t\t\t\texecSync(buildCommand!, { stdio: \"inherit\" });\n\t\t\t},\n\n\t\t\tasync buildEnd() {\n\t\t\t\tif (command === \"build\" || fastlyProcessKilled) return;\n\t\t\t\tfastlyProcessKilled = true;\n\t\t\t\tawait doKillProcesses(this, uniqueName);\n\t\t\t},\n\n\t\t\tconfigureServer(server) {\n\t\t\t\tconst environment = server.environments[viteEnvironmentName]!;\n\t\t\t\tlet address: string | null = null;\n\n\t\t\t\tserver.httpServer?.on(\"listening\", () => {\n\t\t\t\t\taddress = getServerAddress(server.httpServer);\n\t\t\t\t});\n\n\t\t\t\tserver.httpServer?.on(\"close\", () => {\n\t\t\t\t\taddress = null;\n\t\t\t\t});\n\n\t\t\t\t// Transport endpoint for the runner\n\t\t\t\tserver.middlewares.use((req, res, next) => {\n\t\t\t\t\tif (\n\t\t\t\t\t\treq.method !== \"POST\" ||\n\t\t\t\t\t\treq.url !== \"/@vite-plugin-fastly/transport\"\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn next();\n\t\t\t\t\t}\n\n\t\t\t\t\tvoid (async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Read the body\n\t\t\t\t\t\t\tconst body = await readyBody(req);\n\t\t\t\t\t\t\tconst data = JSON.parse(body);\n\n\t\t\t\t\t\t\tconst result = await environment.hot.handleInvoke(data);\n\n\t\t\t\t\t\t\tres.setHeader(\"Content-Type\", \"application/json\");\n\t\t\t\t\t\t\tres.end(JSON.stringify(result));\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\treturn next(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t});\n\n\t\t\t\tconst proxy = createProxy(proxyOptions);\n\n\t\t\t\tconst proxyMiddleware: Connect.NextHandleFunction = (\n\t\t\t\t\treq,\n\t\t\t\t\tres,\n\t\t\t\t\tnext,\n\t\t\t\t) => {\n\t\t\t\t\tif (!address) {\n\t\t\t\t\t\treturn next(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t`[${uniqueName}] Vite server address is not available for proxying`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tproxy.web(\n\t\t\t\t\t\t\treq,\n\t\t\t\t\t\t\tres,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttarget: `http://${fastlyDevServerAddress}`,\n\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t\"Vite-Plugin-Fastly-Vite-Server-Address\": address,\n\t\t\t\t\t\t\t\t\t\"Vite-Plugin-Fastly-Handler-Entry\": handlerEntry,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\t\tnext(error);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tnext(error);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// If a client build is configured, add the proxy middleware after Vite's own middlewares.\n\t\t\t\t// Otherwise, assume a pure server-side setup and add the proxy as the first middleware.\n\t\t\t\tif (clientConfigured) {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tserver.middlewares.use(proxyMiddleware);\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\tserver.middlewares.use(proxyMiddleware);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t];\n}\n\nasync function readyBody(req: IncomingMessage): Promise<string> {\n\treturn new Promise<string>((resolve, reject) => {\n\t\tlet body = \"\";\n\t\treq.on(\"data\", (chunk) => {\n\t\t\tbody += chunk;\n\t\t});\n\n\t\treq.on(\"end\", () => {\n\t\t\tresolve(body);\n\t\t});\n\n\t\treq.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n\nfunction getServerAddress(server: HttpServer | null): string | null {\n\tconst address = server?.address();\n\tif (!address) {\n\t\treturn null;\n\t}\n\n\tlet host: string;\n\n\tif (typeof address === \"string\") {\n\t\thost = address;\n\t} else {\n\t\tswitch (address.address) {\n\t\t\tcase \"127.0.0.1\":\n\t\t\tcase \"::\":\n\t\t\tcase \"::1\":\n\t\t\tcase \"0000:0000:0000:0000:0000:0000:0000:0001\":\n\t\t\t\thost = \"localhost\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\thost = address.address;\n\t\t}\n\n\t\thost = `http://${host}:${address.port}`;\n\t}\n\n\treturn host;\n}\n\nfunction buildDevRunnerIfNecessary(\n\tctx: ConfigPluginContext,\n\tuniqueName: string,\n\tgetCommand: (input: string, output: string) => string,\n): string {\n\tconst jsComputeRuntimeVersion = getJsComputeRuntimeVersion(uniqueName);\n\tconst input = \"node_modules/vite-plugin-fastly/dist/runner.js\";\n\tconst output = `node_modules/.vite-plugin-fastly/runner.${jsComputeRuntimeVersion}.wasm`;\n\n\tconst inputStat = fs.statSync(input);\n\tconst outputStat = statOrNull(output);\n\n\tif (\n\t\toutputStat &&\n\t\toutputStat.isFile() &&\n\t\toutputStat.mtimeMs >= inputStat.mtimeMs\n\t) {\n\t\t// Up to date\n\t\treturn output;\n\t}\n\n\tctx.info(`[${uniqueName}] Building Fastly Module Runner for dev server...`);\n\n\texecSync(getCommand(input, output), { stdio: \"inherit\" });\n\n\treturn output;\n}\n\nfunction getJsComputeRuntimeVersion(uniqueName: string): string {\n\tconst output = execSync(\"js-compute-runtime --version\").toString();\n\n\t// Parse version from something like \"js-compute-runtime-cli.js 3.38.2\\n\"\n\tconst lastSpaceIndex = output.lastIndexOf(\" \");\n\tif (lastSpaceIndex === -1) {\n\t\tthrow new Error(\n\t\t\t`[${uniqueName}] Unexpected js-compute-runtime version output: ${output}`,\n\t\t);\n\t}\n\n\treturn output.slice(lastSpaceIndex + 1).trim();\n}\n\nfunction statOrNull(path: string): fs.Stats | null {\n\ttry {\n\t\treturn fs.statSync(path);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function doKillProcesses(\n\tctx: {\n\t\tinfo: (msg: string) => void;\n\t},\n\tname: string,\n) {\n\tconst kill = fastlyProcesses.get(name);\n\tif (!kill) return;\n\n\tfastlyProcesses.delete(name);\n\n\tctx.info(`[${name}] Shutting down Fastly dev server`);\n\tawait kill();\n\tctx.info(`[${name}] Fastly dev server shut down`);\n}\n\nasync function spawnCommand(command: string): Promise<ChildProcess> {\n\tconst child = spawn(command, {\n\t\tshell: true,\n\t\tstdio: \"inherit\",\n\t});\n\n\treturn await new Promise((resolve, reject) => {\n\t\tchild.on(\"spawn\", () => {\n\t\t\tif (!child.pid) {\n\t\t\t\treturn reject(new Error(\"Failed to spawn process\"));\n\t\t\t}\n\n\t\t\tresolve(child);\n\t\t});\n\n\t\tchild.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n\nlet killAllInProgress = false;\n\nasync function killAll() {\n\tkillAllInProgress = true;\n\tconst promises: Promise<void>[] = [];\n\tfor (const name of fastlyProcesses.keys()) {\n\t\tpromises.push(\n\t\t\tdoKillProcesses(\n\t\t\t\t{\n\t\t\t\t\tinfo: (msg: string) => {\n\t\t\t\t\t\tprocess.stdout.write(msg + \"\\n\");\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tname,\n\t\t\t),\n\t\t);\n\t}\n\tawait Promise.all(promises);\n}\n\nfunction cleanupOnExit() {\n\tif (!killAllInProgress) {\n\t\tvoid killAll().finally(() => {\n\t\t\tprocess.exit(0);\n\t\t});\n\t}\n}\n\nprocess.on(\"SIGINT\", cleanupOnExit);\nprocess.on(\"SIGTERM\", cleanupOnExit);\nprocess.on(\"exit\", cleanupOnExit);\n","import type { Plugin } from \"vite\";\n\nexport default function exposeEnvironment(): Plugin {\n\tlet devServerUrl: string | undefined;\n\tlet command: \"serve\" | \"build\";\n\n\tfunction getModuleContents(environmentName: string) {\n\t\tconst url = devServerUrl ? JSON.stringify(devServerUrl) : \"undefined\";\n\n\t\treturn (\n\t\t\t`export const name = ${JSON.stringify(environmentName)}\\n` +\n\t\t\t`export const command = ${JSON.stringify(command)}\\n` +\n\t\t\t`export const devServerUrl = ${url}`\n\t\t);\n\t}\n\n\treturn {\n\t\tname: \"vite-plugin-fastly/expose-environment\",\n\n\t\tenforce: \"pre\",\n\n\t\tresolveId: {\n\t\t\tfilter: {\n\t\t\t\tid: /^vite-plugin-fastly:environment$/,\n\t\t\t},\n\t\t\thandler(source) {\n\t\t\t\tif (source === \"vite-plugin-fastly:environment\") {\n\t\t\t\t\treturn \"\\0virtual:vite-plugin-fastly:environment\";\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\n\t\tload: {\n\t\t\tfilter: {\n\t\t\t\tid: /^\\0virtual:vite-plugin-fastly:environment$/,\n\t\t\t},\n\t\t\thandler(id) {\n\t\t\t\tif (id !== \"\\0virtual:vite-plugin-fastly:environment\") return;\n\t\t\t\treturn getModuleContents(this.environment.name);\n\t\t\t},\n\t\t},\n\n\t\tconfigResolved(config) {\n\t\t\tcommand = config.command;\n\t\t},\n\n\t\tconfigureServer(server) {\n\t\t\tserver.httpServer?.once(\"listening\", () => {\n\t\t\t\tdevServerUrl = server.resolvedUrls?.local[0];\n\t\t\t});\n\t\t},\n\t} satisfies Plugin;\n}\n"],"mappings":";AACA,SAAS,mBAAuC;AAEhD,OAAO,QAAQ;AACf,SAAuB,UAAU,aAAa;AAC9C,SAAS,qBAAwD;;;ACHlD,SAAR,oBAA6C;AACnD,MAAI;AACJ,MAAI;AAEJ,WAAS,kBAAkB,iBAAyB;AACnD,UAAM,MAAM,eAAe,KAAK,UAAU,YAAY,IAAI;AAE1D,WACC,uBAAuB,KAAK,UAAU,eAAe,CAAC;AAAA,yBAC5B,KAAK,UAAU,OAAO,CAAC;AAAA,8BAClB,GAAG;AAAA,EAEpC;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,IAEN,SAAS;AAAA,IAET,WAAW;AAAA,MACV,QAAQ;AAAA,QACP,IAAI;AAAA,MACL;AAAA,MACA,QAAQ,QAAQ;AACf,YAAI,WAAW,kCAAkC;AAChD,iBAAO;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,IAEA,MAAM;AAAA,MACL,QAAQ;AAAA,QACP,IAAI;AAAA,MACL;AAAA,MACA,QAAQ,IAAI;AACX,YAAI,OAAO,2CAA4C;AACvD,eAAO,kBAAkB,KAAK,YAAY,IAAI;AAAA,MAC/C;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,SAAS,WAAW;AAC7C,UAAM,GAAG,SAAS,MAAM;AACvB,UAAI,CAAC,MAAM,KAAK;AACf,eAAO,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAAA,MACnD;AAEA,cAAQ,KAAK;AAAA,IACd,CAAC;AAED,UAAM,GAAG,SAAS,CAAC,QAAQ;AAC1B,aAAO,GAAG;AAAA,IACX,CAAC;AAAA,EACF,CAAC;AACF;AAEA,IAAI,oBAAoB;AAExB,eAAe,UAAU;AACxB,sBAAoB;AACpB,QAAM,WAA4B,CAAC;AACnC,aAAW,QAAQ,gBAAgB,KAAK,GAAG;AAC1C,aAAS;AAAA,MACR;AAAA,QACC;AAAA,UACC,MAAM,CAAC,QAAgB;AACtB,oBAAQ,OAAO,MAAM,MAAM,IAAI;AAAA,UAChC;AAAA,QACD;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,QAAM,QAAQ,IAAI,QAAQ;AAC3B;AAEA,SAAS,gBAAgB;AACxB,MAAI,CAAC,mBAAmB;AACvB,SAAK,QAAQ,EAAE,QAAQ,MAAM;AAC5B,cAAQ,KAAK,CAAC;AAAA,IACf,CAAC;AAAA,EACF;AACD;AAEA,QAAQ,GAAG,UAAU,aAAa;AAClC,QAAQ,GAAG,WAAW,aAAa;AACnC,QAAQ,GAAG,QAAQ,aAAa;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-fastly",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"http-proxy-3": "^1.23.2",
|
|
51
|
-
"kill-em-all": "0.0.
|
|
51
|
+
"kill-em-all": "0.0.3"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "tsup --clean",
|