@storm-software/cloudflare-tools
Version:
A Nx plugin package that contains various executors, generators, and utilities that assist in managing Cloudflare services.
75 lines (65 loc) • 3.24 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunk7BG3OYEYjs = require('../../../chunk-7BG3OYEY.js');
var _chunkXKQ3HGETjs = require('../../../chunk-XKQ3HGET.js');
require('../../../chunk-WROOA5AX.js');
require('../../../chunk-OZPXCCZB.js');
var _chunkMCKGQKYUjs = require('../../../chunk-MCKGQKYU.js');
// src/executors/serve/executor.ts
var _asynciterable = require('@nx/devkit/src/utils/async-iterable');
var _waitforportopen = require('@nx/web/src/utils/wait-for-port-open');
var _child_process = require('child_process');
async function* serveExecutor(options, context) {
if (!_optionalChain([context, 'optionalAccess', _ => _.projectName]) || !_optionalChain([context, 'optionalAccess', _2 => _2.projectsConfigurations, 'optionalAccess', _3 => _3.projects, 'optionalAccess', _4 => _4[context.projectName], 'optionalAccess', _5 => _5.root])) {
throw new Error("Nx executor context was invalid");
}
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
const wranglerOptions = _chunkXKQ3HGETjs.createCliOptions.call(void 0, { ...options });
const wranglerBin = _chunkMCKGQKYUjs.__require.resolve("wrangler/bin/wrangler");
yield* _asynciterable.createAsyncIterable.call(void 0,
async ({ done, next, error }) => {
process.env.PWD = projectRoot;
const server = _child_process.fork.call(void 0, wranglerBin, ["dev", ...wranglerOptions], {
cwd: projectRoot,
stdio: "inherit"
});
server.once("exit", (code) => {
if (code === 0) {
done();
} else {
error(new Error(`Cloudflare worker exited with code ${code}`));
}
});
const killServer = () => {
if (server.connected) {
server.kill("SIGTERM");
}
};
process.on("exit", () => killServer());
process.on("SIGINT", () => killServer());
process.on("SIGTERM", () => killServer());
process.on("SIGHUP", () => killServer());
await _waitforportopen.waitForPortOpen.call(void 0, _nullishCoalesce(options.port, () => ( 4500)));
next({
success: true,
baseUrl: `http://localhost:${options.port}`
});
}
);
return {
success: true
};
}
var executor_default = _chunk7BG3OYEYjs.withRunExecutor.call(void 0,
"Cloudflare Serve executor",
serveExecutor,
{
skipReadingConfig: false,
hooks: {
applyDefaultOptions: (options) => {
options.port ??= 4500;
return options;
}
}
}
);
exports.default = executor_default; exports.serveExecutor = serveExecutor;