eve 0.24.2 → 0.24.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/CHANGELOG.md +11 -0
- package/dist/src/cli/dev/environment.d.ts +6 -0
- package/dist/src/cli/dev/environment.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +2 -1
- package/dist/src/compiled/@chat-adapter/slack/index.js +12 -12
- package/dist/src/compiled/@chat-adapter/twilio/index.js +1 -1
- package/dist/src/compiled/@vercel/sandbox/index.js +19 -19
- package/dist/src/compiled/@workflow/world-local/index.d.ts +14 -0
- package/dist/src/compiled/_chunks/node/{auth-CWHn3Yve.js → auth-BuQkq4Gr.js} +2 -2
- package/dist/src/compiled/_chunks/node/{dist-BdTs18CF.js → chunk-BTyA9uPd.js} +1 -1
- package/dist/src/compiled/_chunks/node/{dist-W8yle6rh.js → dist-CdH_Yoxt.js} +5 -5
- package/dist/src/compiled/_chunks/node/{dist-RHRJZ03Q.js → dist-Drt-_JVK.js} +1 -1
- package/dist/src/compiled/_chunks/node/dist-DsNhwdzf.js +1 -0
- package/dist/src/compiled/_chunks/node/retry-DngYleaI.js +1 -0
- package/dist/src/compiled/_chunks/node/token-DabMnh8F.js +1 -0
- package/dist/src/compiled/_chunks/node/token-util-BoSJPKrG.js +1 -0
- package/dist/src/compiled/_chunks/node/token-util-DVigMYWS.js +1 -0
- package/dist/src/compiled/_chunks/node/virtual-loader-B8K8w9cr.js +1 -0
- package/dist/src/compiled/chat/index.js +1 -1
- package/dist/src/compiled/env-runner/LICENSE +21 -0
- package/dist/src/compiled/env-runner/index.d.ts +38 -0
- package/dist/src/compiled/env-runner/index.js +1 -0
- package/dist/src/compiled/env-runner/node-worker.d.ts +1 -0
- package/dist/src/compiled/env-runner/node-worker.js +12 -0
- package/dist/src/compiler/compile-agent.d.ts +4 -6
- package/dist/src/compiler/compile-agent.js +1 -1
- package/dist/src/execution/create-session-step.d.ts +2 -2
- package/dist/src/execution/create-session-step.js +1 -1
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.d.ts +13 -0
- package/dist/src/internal/application/compiled-artifacts.js +3 -2
- package/dist/src/internal/application/dev-environment.d.ts +4 -0
- package/dist/src/internal/application/dev-environment.js +1 -0
- package/dist/src/internal/application/optional-package-install.d.ts +2 -10
- package/dist/src/internal/application/optional-package-install.js +1 -1
- package/dist/src/internal/application/output-publication-lock.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/application/tsconfig-dependencies.js +1 -1
- package/dist/src/internal/authored-module-loader.d.ts +3 -9
- package/dist/src/internal/authored-module-loader.js +2 -2
- package/dist/src/internal/authored-package-boundary.d.ts +0 -2
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/authored-package-tsconfig-paths.js +1 -1
- package/dist/src/internal/compiled-manifest-fingerprint.d.ts +5 -0
- package/dist/src/internal/compiled-manifest-fingerprint.js +1 -0
- package/dist/src/internal/materialized-authored-modules.d.ts +0 -3
- package/dist/src/internal/materialized-authored-modules.js +1 -1
- package/dist/src/internal/nitro/dev-client-address.d.ts +22 -0
- package/dist/src/internal/nitro/dev-client-address.js +1 -0
- package/dist/src/internal/nitro/dev-runtime-artifacts-retention.d.ts +12 -0
- package/dist/src/internal/nitro/dev-runtime-artifacts-retention.js +1 -0
- package/dist/src/internal/nitro/dev-runtime-artifacts.d.ts +19 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/development-generation.d.ts +5 -1
- package/dist/src/internal/nitro/development-generation.js +1 -1
- package/dist/src/internal/nitro/host/artifacts-config.d.ts +2 -0
- package/dist/src/internal/nitro/host/artifacts-config.js +1 -1
- package/dist/src/internal/nitro/host/channel-routes.d.ts +1 -13
- package/dist/src/internal/nitro/host/channel-routes.js +3 -3
- package/dist/src/internal/nitro/host/configure-nitro-routes.d.ts +1 -2
- package/dist/src/internal/nitro/host/configure-nitro-routes.js +2 -2
- package/dist/src/internal/nitro/host/create-application-nitro.d.ts +3 -5
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/dev-authored-rebuild-coordinator.d.ts +32 -0
- package/dist/src/internal/nitro/host/dev-authored-rebuild-coordinator.js +1 -0
- package/dist/src/internal/nitro/host/dev-authored-source-watcher.d.ts +4 -15
- package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
- package/dist/src/internal/nitro/host/dev-host-candidate.d.ts +16 -0
- package/dist/src/internal/nitro/host/dev-host-candidate.js +1 -0
- package/dist/src/internal/nitro/host/dev-host-fingerprint.d.ts +2 -0
- package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -0
- package/dist/src/internal/nitro/host/dev-host-workspace.d.ts +10 -0
- package/dist/src/internal/nitro/host/dev-host-workspace.js +1 -0
- package/dist/src/internal/nitro/host/dev-runner.d.ts +21 -0
- package/dist/src/internal/nitro/host/dev-runner.js +1 -0
- package/dist/src/internal/nitro/host/dev-server-http.d.ts +5 -0
- package/dist/src/internal/nitro/host/dev-server-http.js +1 -0
- package/dist/src/internal/nitro/host/dev-server-url.d.ts +6 -0
- package/dist/src/internal/nitro/host/dev-server-url.js +1 -0
- package/dist/src/internal/nitro/host/dev-workflow-world-setup.d.ts +9 -0
- package/dist/src/internal/nitro/host/dev-workflow-world-setup.js +1 -0
- package/dist/src/internal/nitro/host/dispatch-schedule-in-dev.js +1 -1
- package/dist/src/internal/nitro/host/drained-nitro-dev-server.d.ts +53 -0
- package/dist/src/internal/nitro/host/drained-nitro-dev-server.js +1 -0
- package/dist/src/internal/nitro/host/prepare-application-host.d.ts +4 -5
- package/dist/src/internal/nitro/host/prepare-application-host.js +1 -1
- package/dist/src/internal/nitro/host/start-development-server.d.ts +2 -5
- package/dist/src/internal/nitro/host/start-development-server.js +2 -2
- package/dist/src/internal/nitro/host/types.d.ts +6 -0
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/runtime-artifacts.d.ts +7 -0
- package/dist/src/internal/nitro/routes/runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/routes/schedule-task.d.ts +9 -0
- package/dist/src/internal/nitro/routes/schedule-task.js +1 -1
- package/dist/src/internal/workflow/development-generation-context.d.ts +8 -0
- package/dist/src/internal/workflow/development-generation-context.js +1 -0
- package/dist/src/internal/workflow/development-world-client.d.ts +29 -0
- package/dist/src/internal/workflow/development-world-client.js +1 -0
- package/dist/src/internal/workflow/development-world-codec.d.ts +11 -0
- package/dist/src/internal/workflow/development-world-codec.js +1 -0
- package/dist/src/internal/workflow/development-world-protocol.d.ts +31 -0
- package/dist/src/internal/workflow/development-world-protocol.js +1 -0
- package/dist/src/internal/workflow/development-world-server.d.ts +27 -0
- package/dist/src/internal/workflow/development-world-server.js +1 -0
- package/dist/src/runtime/compiled-artifacts-source.d.ts +9 -0
- package/dist/src/runtime/compiled-artifacts-source.js +1 -1
- package/dist/src/runtime/durable-compiled-artifacts-source.d.ts +8 -0
- package/dist/src/runtime/durable-compiled-artifacts-source.js +1 -0
- package/dist/src/runtime/sessions/runtime-context-keys.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/atomic-write-file.d.ts +1 -1
- package/dist/src/shared/atomic-write-file.js +1 -1
- package/dist/src/shared/rename-with-retry.d.ts +5 -0
- package/dist/src/shared/rename-with-retry.js +1 -0
- package/docs/agent-config.md +2 -0
- package/docs/concepts/execution-model-and-durability.md +1 -1
- package/docs/reference/cli.md +1 -1
- package/package.json +2 -1
- package/dist/src/compiled/_chunks/node/retry-DkR2H1Y0.js +0 -1
- package/dist/src/compiled/_chunks/node/token-ORseRyWn.js +0 -1
- package/dist/src/internal/bundler/nitro-node-file-trace.d.ts +0 -10
- package/dist/src/internal/bundler/nitro-node-file-trace.js +0 -1
- package/dist/src/internal/materialize-authored-external-dependencies.d.ts +0 -10
- package/dist/src/internal/materialize-authored-external-dependencies.js +0 -2
- package/dist/src/internal/nitro/host/dev-live-virtual-modules.d.ts +0 -15
- package/dist/src/internal/nitro/host/dev-live-virtual-modules.js +0 -1
- package/dist/src/internal/nitro/host/server-external-packages.d.ts +0 -5
- package/dist/src/internal/nitro/host/server-external-packages.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{watch}from"node:fs";import{basename,dirname,isAbsolute,join,relative,resolve}from"node:path";import{mkdir,readdir,
|
|
1
|
+
import{watch}from"node:fs";import{basename,dirname,isAbsolute,join,relative,resolve}from"node:path";import{mkdir,readdir,rm,stat,utimes}from"node:fs/promises";import{isErrnoCode}from"#shared/guards.js";import{pathExists}from"#shared/path-exists.js";import{removeOutputPublicationBackups,rollbackOutputPublication}from"#internal/application/output-publication-artifacts.js";import{readOutputPublicationJournal,readRecoveryLeaseJournal,resolveJournalFilePath,writeOutputPublicationJournal,writeRecoveryLeaseJournal}from"#internal/application/output-publication-journal.js";import{renameWithTransientBusyRetry}from"#shared/rename-with-retry.js";const PUBLICATION_LOCK_TIMEOUT_MS=6e4,INCOMPLETE_LOCK_STALE_MS=5e3;function resolveOutputPublicationLockPath(e){return join(resolve(e),`.eve`,`locks`,`output-publication.lock`)}function startPublicationJournalHeartbeat(e){let t=resolveJournalFilePath(e),n=setInterval(()=>{let e=new Date;utimes(t,e,e).catch(()=>void 0)},1e3);return n.unref(),()=>{clearInterval(n)}}async function acquireOutputPublicationLock(e,t,r){let i=Date.now()+PUBLICATION_LOCK_TIMEOUT_MS,a=`${e}.recovery`;for(await mkdir(dirname(e),{recursive:!0});;){if(await pathExists(a)){if(await r(),await recoverStalePublication(e,a,t))continue;await waitForPublicationLockChange(e,i);continue}try{if(await mkdir(e),await pathExists(a)){await rm(e,{force:!0,recursive:!0}),await waitForPublicationLockChange(e,i);continue}try{await writeOutputPublicationJournal(e,t)}catch(t){throw await rm(e,{force:!0,recursive:!0}),t}return async()=>{if((await readOutputPublicationJournal(e))?.token!==t.token)return;let n=`${e}.released-${t.token}`;try{await renameWithTransientBusyRetry(e,n)}catch(e){if(isErrnoCode(e,`ENOENT`))return;throw e}await rm(n,{force:!0,recursive:!0})}}catch(e){if(!isErrnoCode(e,`EEXIST`))throw e}await r(),!await recoverStalePublication(e,a,t)&&await waitForPublicationLockChange(e,i)}}async function recoverStalePublication(e,t,n){let r=await acquireRecoveryLease(t,n.token);if(r===void 0)return!1;let a=startPublicationJournalHeartbeat(join(t,`lease`)),o=!1;try{let r=await readOutputPublicationJournal(e);if(r!==void 0&&r.liveness===`active`&&isProcessAlive(r.pid)&&!await isJournalStale(e)||r===void 0&&!await isPathStale(e))return!1;if(await pathExists(e)){let r=join(t,`owner-${n.token}`);try{await renameWithTransientBusyRetry(e,r),o=!0}catch(e){if(!isErrnoCode(e,`ENOENT`))throw e}}let a=await readdir(t,{withFileTypes:!0});o=a.some(e=>e.isDirectory()&&e.name.startsWith(`owner-`));for(let e of a)!e.isDirectory()||!e.name.startsWith(`owner-`)||await finishInterruptedPublication(join(t,e.name));return o=!1,!0}finally{a(),o?await r.release():await r.complete()}}async function acquireRecoveryLease(e,t){let n=join(e,`lease`),r={pid:process.pid,token:t};for(await mkdir(e,{recursive:!0});;){try{await mkdir(n);try{await writeRecoveryLeaseJournal(n,r)}catch(e){throw await rm(n,{force:!0,recursive:!0}),e}return{async complete(){if((await readRecoveryLeaseJournal(n))?.token!==t)return;let r=`${e}.released-${t}`;try{await renameWithTransientBusyRetry(e,r)}catch(e){if(isErrnoCode(e,`ENOENT`))return;throw e}await rm(r,{force:!0,recursive:!0})},async release(){if((await readRecoveryLeaseJournal(n))?.token!==t)return;let e=`${n}.released-${t}`;try{await renameWithTransientBusyRetry(n,e)}catch(e){if(isErrnoCode(e,`ENOENT`))return;throw e}await rm(e,{force:!0,recursive:!0})}}}catch(e){if(isErrnoCode(e,`ENOENT`))return;if(!isErrnoCode(e,`EEXIST`))throw e}let i=await readRecoveryLeaseJournal(n);if(i!==void 0&&isProcessAlive(i.pid)&&!await isJournalStale(n)||i===void 0&&!await isPathStale(n))return;let a=`${n}.stale-${t}`;try{await renameWithTransientBusyRetry(n,a)}catch(e){if(isErrnoCode(e,`ENOENT`))continue;throw e}await rm(a,{force:!0,recursive:!0})}}async function finishInterruptedPublication(e){let t=await readOutputPublicationJournal(e);if(t===void 0||!hasTokenDerivedBackupPaths(t)){await rm(e,{force:!0,recursive:!0});return}t.phase===`committed`?await removeOutputPublicationBackups(t):await rollbackOutputPublication(t),await removePublicationScratchDirectory(t),await rm(e,{force:!0,recursive:!0})}function hasTokenDerivedBackupPaths(e){return e.outputBackupPath===`${e.finalOutputDir}.eve-backup-${e.token}`&&e.summaryBackupPath===`${e.finalSummaryPath}.eve-backup-${e.token}`}async function removePublicationScratchDirectory(e){let t=relative(e.scratchDir,e.stagedOutputDir);t===``||t.startsWith(`..`)||isAbsolute(t)||await rm(e.scratchDir,{force:!0,recursive:!0})}async function waitForPublicationLockChange(r,i){let a=i-Date.now();if(a<=0)throw Error(`Timed out waiting ${PUBLICATION_LOCK_TIMEOUT_MS}ms to publish completed build output.`);let o=dirname(r),s=basename(r),c=await readPublicationLockState(r);await new Promise((t,n)=>{let i=!1,l=setTimeout(settleResolve,Math.min(a,INCOMPLETE_LOCK_STALE_MS)),u=watch(o,(e,t)=>{e===`rename`&&(t===null||t.toString().startsWith(s))&&settleResolve()});function cleanup(){clearTimeout(l),u.close()}function settleResolve(){i||(i=!0,cleanup(),t())}function settleReject(e){i||(i=!0,cleanup(),n(e))}u.once(`error`,settleReject),Promise.all([readPublicationLockState(r),pathExists(r),pathExists(`${r}.recovery`)]).then(([e,t,n])=>{(!t&&!n||e!==c)&&settleResolve()},settleReject)})}async function readPublicationLockState(e){let t=`${e}.recovery`,[n,r,a,o]=await Promise.all([readOutputPublicationJournal(e),readRecoveryLeaseJournal(join(t,`lease`)),pathExists(e),pathExists(t)]);return JSON.stringify({lockExists:a,lockToken:n?.token,recoveryExists:o,recoveryToken:r?.token})}async function isPathStale(e){try{return Date.now()-(await stat(e)).mtimeMs>=INCOMPLETE_LOCK_STALE_MS}catch(e){if(isErrnoCode(e,`ENOENT`))return!0;throw e}}async function isJournalStale(e){try{let t=await stat(resolveJournalFilePath(e));return Date.now()-t.mtimeMs>=15e3}catch(e){if(isErrnoCode(e,`ENOENT`))return!0;throw e}}function isProcessAlive(e){try{return process.kill(e,0),!0}catch(e){return!isErrnoCode(e,`ESRCH`)}}export{acquireOutputPublicationLock,resolveOutputPublicationLockPath,startPublicationJournalHeartbeat};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire}from"node:module";import{existsSync,readFileSync,realpathSync}from"node:fs";import{basename,dirname,join}from"node:path";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";import{fileURLToPath}from"node:url";let cachedPackageInfo;const BUNDLED_FALLBACK_PACKAGE_VERSION=`0.24.
|
|
1
|
+
import{createRequire}from"node:module";import{existsSync,readFileSync,realpathSync}from"node:fs";import{basename,dirname,join}from"node:path";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";import{fileURLToPath}from"node:url";let cachedPackageInfo;const BUNDLED_FALLBACK_PACKAGE_VERSION=`0.24.3`,WORKFLOW_MODULE_ALIASES={"workflow/errors":`src/compiled/@workflow/errors/index.js`,"workflow/internal/private":`src/compiled/@workflow/core/private.js`};function resolveFallbackPackageVersion(){return BUNDLED_FALLBACK_PACKAGE_VERSION.startsWith(`__`)?`0.0.0`:BUNDLED_FALLBACK_PACKAGE_VERSION}const FALLBACK_PACKAGE_INFO={name:EVE_PACKAGE_NAME,version:resolveFallbackPackageVersion()};function resolveCurrentModulePath(){return typeof __filename==`string`?__filename:resolveCurrentModulePathFromStack()}function resolveCurrentModulePathFromStack(){let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(e,t)=>t;let e=Error().stack?.[0]?.getFileName();if(typeof e!=`string`||e.length===0)throw Error(`Failed to resolve the current module path from the stack trace.`);return e.startsWith(`file:`)?fileURLToPath(e):e}finally{Error.prepareStackTrace=e}}const require=createRequire(resolveCurrentModulePath());function isBuildOutputPackageRoot(e){return basename(e)===`dist`&&existsSync(join(dirname(e),`package.json`))}function resolvePackageBuildRoot(){let e=dirname(realpathSync(resolveCurrentModulePath()));for(;;){if(isBuildOutputPackageRoot(e))return e;let t=dirname(e);if(t===e)return null;e=t}}function findNearestPackageRoot(e){let n=e;for(;;){if(existsSync(join(n,`package.json`))&&!isBuildOutputPackageRoot(n))return n;let r=dirname(n);if(r===n)throw Error(`Failed to resolve package root from "${e}".`);n=r}}function resolvePackageRoot(){return findNearestPackageRoot(dirname(realpathSync(resolveCurrentModulePath())))}function tryResolvePackageRoot(){try{return resolvePackageRoot()}catch{return}}function rewriteSourceFilePathForBuild(e){return e.replace(/\.[cm]?tsx?$/,`.js`)}function resolvePackageSourceFilePath(e){let t=resolvePackageBuildRoot();return t===null?join(resolvePackageRoot(),e):join(t,rewriteSourceFilePathForBuild(e))}function resolvePackageSourceDirectoryPath(e){let t=resolvePackageBuildRoot();return join(t===null?resolvePackageRoot():t,e)}function resolvePackageDependencyPath(e){return require.resolve(e)}function resolvePackageCompiledFilePath(e){let t=resolvePackageBuildRoot();return t===null?join(resolvePackageRoot(),`.generated`,`compiled`,e.replace(/^src\/compiled\//,``)):join(t,e)}function normalizeInstalledPackageInfo(e){let t=e;if(!(typeof t.name!=`string`||typeof t.version!=`string`))return{name:t.name,version:t.version}}function tryReadInstalledPackageInfo(e,t){let r=normalizeInstalledPackageInfo(JSON.parse(readFileSync(e,`utf8`)));if(r?.name===t)return r}function resolveInstalledPackageInfo(){if(cachedPackageInfo)return cachedPackageInfo;let e=tryResolvePackageRoot(),t=e===void 0?void 0:tryReadInstalledPackageInfo(join(e,`package.json`),EVE_PACKAGE_NAME);if(t)return cachedPackageInfo=t,cachedPackageInfo;try{let e=tryReadInstalledPackageInfo(require.resolve(`${EVE_PACKAGE_NAME}/package.json`),EVE_PACKAGE_NAME);if(e)return cachedPackageInfo=e,cachedPackageInfo}catch{}return cachedPackageInfo={...FALLBACK_PACKAGE_INFO},cachedPackageInfo}function readWorkflowVersionFromManifest(e){let t=e;for(let e of[t.devDependencies,t.dependencies,t.peerDependencies]){let t=e?.[`@workflow/core`];if(typeof t==`string`&&t.trim().length>0)return t}}function resolveExpectedWorkflowVersion(){let e=tryResolvePackageRoot();if(e!==void 0)try{return readWorkflowVersionFromManifest(JSON.parse(readFileSync(join(e,`package.json`),`utf8`)))}catch{}try{return readWorkflowVersionFromManifest(JSON.parse(readFileSync(require.resolve(`${EVE_PACKAGE_NAME}/package.json`),`utf8`)))}catch{return}}function resolveWorkflowModulePath(e){if(e===`workflow`)return resolvePackageSourceFilePath(`src/internal/workflow/index.ts`);if(e===`workflow/api`||e===`workflow/runtime`)return resolvePackageSourceFilePath(`src/internal/workflow/runtime.ts`);if(e===`workflow/internal/builtins`)return resolvePackageSourceFilePath(`src/internal/workflow/builtins.ts`);let t=WORKFLOW_MODULE_ALIASES[e];return t===void 0?require.resolve(e):resolvePackageCompiledFilePath(t)}export{resolveExpectedWorkflowVersion,resolveInstalledPackageInfo,resolvePackageCompiledFilePath,resolvePackageDependencyPath,resolvePackageRoot,resolvePackageSourceDirectoryPath,resolvePackageSourceFilePath,resolveWorkflowModulePath};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire}from"node:module";import{existsSync}from"node:fs";import{dirname,isAbsolute,join,resolve}from"node:path";import{readFile,readdir}from"node:fs/promises";import{parse
|
|
1
|
+
import{createRequire}from"node:module";import{existsSync}from"node:fs";import{dirname,isAbsolute,join,resolve}from"node:path";import{readFile,readdir}from"node:fs/promises";import{parse}from"#compiled/jsonc-parser/index.js";async function resolveTsConfigDependencyPaths(e){let t=await resolveRootTsConfigPaths(e),n=new Set,r=new Set;for(let e of t)await collectTsConfigDependencyPaths({configPath:e,resolvedConfigPaths:n,visitingConfigPaths:r});return[...n].sort((e,t)=>e.localeCompare(t))}async function resolveRootTsConfigPaths(e){let t=new Set([join(e,`tsconfig.json`),join(e,`jsconfig.json`)]);try{let n=await readdir(e,{withFileTypes:!0});for(let r of n)r.isFile()&&/^tsconfig\..+\.json$/i.test(r.name)&&t.add(join(e,r.name))}catch{}return[...t]}async function collectTsConfigDependencyPaths(e){let t=resolve(e.configPath);if(e.resolvedConfigPaths.has(t)||e.visitingConfigPaths.has(t))return;let n=await readTextFileIfExists(t);if(n!==void 0){e.resolvedConfigPaths.add(t),e.visitingConfigPaths.add(t);try{let r=extractTsConfigExtendsSpecifiers(n);for(let n of r)for(let r of resolveTsConfigExtendsTargetPaths({configPath:t,extendsSpecifier:n}))await collectTsConfigDependencyPaths({configPath:r,resolvedConfigPaths:e.resolvedConfigPaths,visitingConfigPaths:e.visitingConfigPaths})}finally{e.visitingConfigPaths.delete(t)}}}async function readTextFileIfExists(e){try{return await readFile(e,`utf8`)}catch{return}}function parseTsConfigObject(e){let t=[],n=parse(e,t,{allowTrailingComma:!0});if(!(t.length>0||typeof n!=`object`||!n||Array.isArray(n)))return n}function extractTsConfigExtendsSpecifiers(e){let t=parseTsConfigObject(e);if(t===void 0)return[];let n=t.extends;return typeof n==`string`?n.length>0?[n]:[]:Array.isArray(n)?n.filter(e=>typeof e==`string`&&e.length>0):[]}function resolveTsConfigExtendsTargetPaths(e){let t=new Set;if(isTsConfigFilePath(e.extendsSpecifier))for(let n of resolveFileExtendsCandidates({configPath:e.configPath,extendsSpecifier:e.extendsSpecifier}))t.add(n);else for(let n of resolvePackageExtendsCandidates({configPath:e.configPath,extendsSpecifier:e.extendsSpecifier}))t.add(n);return[...t]}function resolveFirstExistingTsConfigExtendsTarget(e){for(let n of resolveTsConfigExtendsTargetPaths(e))if(existsSync(n))return n}function resolveFileExtendsCandidates(e){let t=resolve(dirname(e.configPath),e.extendsSpecifier),r=new Set;return r.add(t),t.endsWith(`.json`)||(r.add(`${t}.json`),r.add(join(t,`tsconfig.json`))),[...r]}function resolvePackageExtendsCandidates(t){let n=new Set([t.extendsSpecifier]);t.extendsSpecifier.endsWith(`.json`)||(n.add(`${t.extendsSpecifier}.json`),n.add(`${t.extendsSpecifier}/tsconfig.json`));let r=new Set,i=createRequire(t.configPath);for(let e of n)try{r.add(i.resolve(e))}catch{}return[...r]}function isTsConfigFilePath(e){return e.startsWith(`.`)||isAbsolute(e)?!0:/^[A-Za-z]:[\\/]/.test(e)}export{collectTsConfigDependencyPaths,extractTsConfigExtendsSpecifiers,isTsConfigFilePath,parseTsConfigObject,readTextFileIfExists,resolveFirstExistingTsConfigExtendsTarget,resolveRootTsConfigPaths,resolveTsConfigDependencyPaths,resolveTsConfigExtendsTargetPaths};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ResolvedAuthoredExternalModule } from "#internal/materialize-authored-external-dependencies.js";
|
|
2
1
|
export interface AuthoredModuleLoadOptions {
|
|
3
2
|
readonly externalDependencies?: readonly string[];
|
|
4
3
|
/**
|
|
@@ -8,10 +7,6 @@ export interface AuthoredModuleLoadOptions {
|
|
|
8
7
|
*/
|
|
9
8
|
readonly extensionScopeNamespace?: string;
|
|
10
9
|
}
|
|
11
|
-
export interface AuthoredGenerationModuleBundle {
|
|
12
|
-
readonly code: string;
|
|
13
|
-
readonly externalModules: readonly ResolvedAuthoredExternalModule[];
|
|
14
|
-
}
|
|
15
10
|
/**
|
|
16
11
|
* Loads one authored module namespace from disk during compile-time
|
|
17
12
|
* discovery. Concurrent loads of the same `modulePath` share a single
|
|
@@ -26,8 +21,7 @@ export declare function bundleAuthoredModuleCode(modulePath: string, options?: A
|
|
|
26
21
|
/**
|
|
27
22
|
* Bundles one authored entry for an immutable development generation. Ordinary
|
|
28
23
|
* package dependencies are inlined so the emitted code stays executable after
|
|
29
|
-
* the original workspace changes; framework runtime imports and
|
|
30
|
-
* external dependencies
|
|
31
|
-
* bundle references is reported for closure materialization.
|
|
24
|
+
* the original workspace changes; framework runtime imports and explicitly
|
|
25
|
+
* configured external dependencies keep their normal runtime resolution.
|
|
32
26
|
*/
|
|
33
|
-
export declare function bundleAuthoredModuleForGeneration(modulePath: string, options?: AuthoredModuleLoadOptions): Promise<
|
|
27
|
+
export declare function bundleAuthoredModuleForGeneration(modulePath: string, options?: AuthoredModuleLoadOptions): Promise<string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{expectObjectRecord}from"#internal/authored-module.js";import{existsSync,mkdirSync,statSync,writeFileSync}from"node:fs";import{dirname,isAbsolute,join,resolve}from"node:path";import{createHash}from"node:crypto";import{buildWithNitroRolldown,getSingleRolldownChunk}from"#internal/bundler/nitro-rolldown.js";import{createAuthoredAssetImportPlugin}from"#internal/authored-asset-import-plugin.js";import{assertNoWorkflowDirectivePrologue}from"#internal/authored-directive-prologue.js";import{createAuthoredModuleBundleError}from"#internal/authored-module-bundle.js";import{createAuthoredPackageTsConfigPathsPlugin}from"#internal/authored-package-tsconfig-paths.js";import{createFixedNamespaceScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,isPathImport,normalizeExternalDependencies}from"#internal/authored-package-boundary.js";import{createNodeEsmCompatBannerPlugin}from"#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION=/\.[cm]?[jt]sx?$/,AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH=join(`node_modules`,`.cache`,`eve`,`authored-modules`),CHANNEL_MODULE_CACHE_KEY=`__eveChannelModuleCache__`;function getChannelModuleCache(){return globalThis[CHANNEL_MODULE_CACHE_KEY]}const inFlightModuleLoads=new Map;function loadAuthoredModuleNamespace(e,t={}){let n=createInFlightModuleLoadKey(resolve(e),t),r=inFlightModuleLoads.get(n);if(r!==void 0)return r;let i=(async()=>{try{return await doLoadAuthoredModuleNamespace(e,t)}finally{inFlightModuleLoads.delete(n)}})();return inFlightModuleLoads.set(n,i),i}async function doLoadAuthoredModuleNamespace(t,n){return expectObjectRecord(AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)?await loadBundledAuthoredModule(t,n):await import(createFileImportSpecifier(t)),`Expected "${t}" to export a module namespace object.`)}function createFileImportSpecifier(e){let t=e.replaceAll(`\\`,`/`);return/^[A-Za-z]:\//.test(t)?`file:///${encodeURI(t)}`:t.startsWith(`/`)?`file://${encodeURI(t)}`:t}async function bundleAuthoredModuleCode(e,t={}){return await buildAuthoredModuleBundle(e,t,{channelIdentity:!0,packageBoundaryPlugin:createRuntimeLoaderPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[],sourcemap:`inline`})}async function bundleAuthoredModuleForGeneration(e,t={}){
|
|
2
|
-
`),moduleType:`js`}}}:null,...n.plugins,t.extensionScopeNamespace===void 0?null:createFixedNamespaceScopePlugin(t.extensionScopeNamespace),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:i,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),n.packageBoundaryPlugin].filter(e=>e!==null);try{return getSingleRolldownChunk(await buildWithNitroRolldown({cwd:i,input:e,platform:`node`,plugins:o,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:a,write:!1,output:{comments:!1,format:`esm`,sourcemap:n.sourcemap}}),`authored module for "${e}"`).code}catch(t){throw createAuthoredModuleBundleError(e,t)}}function createAuthoredDirectiveGuardPlugin(){return{name:`eve-authored-directive-guard`,async transform(e,t){!AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)||isNodeModulesPath(t)||await assertNoWorkflowDirectivePrologue({filePath:t,source:e})}}}function removeRolldownModuleRegionComments(e){return e.split(`
|
|
1
|
+
import{expectObjectRecord}from"#internal/authored-module.js";import{existsSync,mkdirSync,statSync,writeFileSync}from"node:fs";import{dirname,isAbsolute,join,resolve}from"node:path";import{createHash}from"node:crypto";import{buildWithNitroRolldown,getSingleRolldownChunk}from"#internal/bundler/nitro-rolldown.js";import{createAuthoredAssetImportPlugin}from"#internal/authored-asset-import-plugin.js";import{assertNoWorkflowDirectivePrologue}from"#internal/authored-directive-prologue.js";import{createAuthoredModuleBundleError}from"#internal/authored-module-bundle.js";import{createAuthoredPackageTsConfigPathsPlugin}from"#internal/authored-package-tsconfig-paths.js";import{createFixedNamespaceScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,isPathImport,normalizeExternalDependencies}from"#internal/authored-package-boundary.js";import{createNodeEsmCompatBannerPlugin}from"#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION=/\.[cm]?[jt]sx?$/,AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH=join(`node_modules`,`.cache`,`eve`,`authored-modules`),CHANNEL_MODULE_CACHE_KEY=`__eveChannelModuleCache__`;function getChannelModuleCache(){return globalThis[CHANNEL_MODULE_CACHE_KEY]}const inFlightModuleLoads=new Map;function loadAuthoredModuleNamespace(e,t={}){let n=createInFlightModuleLoadKey(resolve(e),t),r=inFlightModuleLoads.get(n);if(r!==void 0)return r;let i=(async()=>{try{return await doLoadAuthoredModuleNamespace(e,t)}finally{inFlightModuleLoads.delete(n)}})();return inFlightModuleLoads.set(n,i),i}async function doLoadAuthoredModuleNamespace(t,n){return expectObjectRecord(AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)?await loadBundledAuthoredModule(t,n):await import(createFileImportSpecifier(t)),`Expected "${t}" to export a module namespace object.`)}function createFileImportSpecifier(e){let t=e.replaceAll(`\\`,`/`);return/^[A-Za-z]:\//.test(t)?`file:///${encodeURI(t)}`:t.startsWith(`/`)?`file://${encodeURI(t)}`:t}async function bundleAuthoredModuleCode(e,t={}){return await buildAuthoredModuleBundle(e,t,{channelIdentity:!0,packageBoundaryPlugin:createRuntimeLoaderPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[],sourcemap:`inline`})}async function bundleAuthoredModuleForGeneration(e,t={}){return removeRolldownModuleRegionComments(await buildAuthoredModuleBundle(e,t,{channelIdentity:!1,packageBoundaryPlugin:createGenerationPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[createAuthoredDirectiveGuardPlugin()],sourcemap:!1}))}async function buildAuthoredModuleBundle(e,t,n){let r=n.channelIdentity?getChannelModuleCache():void 0,i=resolveAuthoredPackageRoot(e),a=resolveAuthoredTsConfigPath(i),o=[r&&r.size>0?{name:`eve-channel-identity`,async resolveId(e,t,n){if(!/channels[/\\]/.test(e)||n.kind!==`import-statement`)return;let i=await this.resolve(e,t,{kind:n.kind,skipSelf:!0});if(i===null||typeof i.id!=`string`)return;let a=resolve(i.id);if(r.has(a))return{id:`${CACHED_CHANNEL_PREFIX}${a}`}},load(e){if(!e.startsWith(CACHED_CHANNEL_PREFIX))return;let t=e.slice(CACHED_CHANNEL_PREFIX.length);return{code:[`const cache = globalThis["${CHANNEL_MODULE_CACHE_KEY}"];`,`export default cache.get(${JSON.stringify(t)});`].join(`
|
|
2
|
+
`),moduleType:`js`}}}:null,...n.plugins,t.extensionScopeNamespace===void 0?null:createFixedNamespaceScopePlugin(t.extensionScopeNamespace),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:i,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),n.packageBoundaryPlugin].filter(e=>e!==null);try{return getSingleRolldownChunk(await buildWithNitroRolldown({cwd:i,input:e,platform:`node`,plugins:o,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:a,write:!1,output:{codeSplitting:!1,comments:!1,format:`esm`,sourcemap:n.sourcemap}}),`authored module for "${e}"`).code}catch(t){throw createAuthoredModuleBundleError(e,t)}}function createAuthoredDirectiveGuardPlugin(){return{name:`eve-authored-directive-guard`,async transform(e,t){!AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)||isNodeModulesPath(t)||await assertNoWorkflowDirectivePrologue({filePath:t,source:e})}}}function removeRolldownModuleRegionComments(e){return e.split(`
|
|
3
3
|
`).filter(e=>!e.startsWith(`//#region `)&&e!==`//#endregion`).join(`
|
|
4
4
|
`)}async function loadBundledAuthoredModule(e,r){let a=await bundleAuthoredModuleCode(e,r),o=normalizeExternalDependencies(r.externalDependencies),s=createHash(`sha1`).update(e).update(`\0`).update(o.join(`\0`)).update(`\0`).update(r.extensionScopeNamespace??``).update(`\0`).update(a).digest(`hex`),c=join(resolveAuthoredPackageRoot(e),AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH),l=join(c,`${s}.mjs`);return existsSync(l)||(mkdirSync(c,{recursive:!0}),writeFileSync(l,a)),await import(`${createFileImportSpecifier(l)}?v=${s}`)}function createAuthoredRelativeExtensionResolverPlugin(e){return{name:`eve-authored-relative-extension-resolver`,resolveId(t,n){if(n===void 0||n.startsWith(`\0`)||n.startsWith(CACHED_CHANNEL_PREFIX)||!isPathImport(t))return;let r=resolveExistingImportPath(isAbsolute(t)?t:resolve(dirname(n),t),e.extensions);if(r!==void 0)return{id:r}}}}function createInFlightModuleLoadKey(e,t){return`${e}\0${normalizeExternalDependencies(t.externalDependencies).join(`\0`)}\0${t.extensionScopeNamespace??``}`}function resolveExistingImportPath(e,t){if(isFile(e))return e;for(let n of t){let t=`${e}${n}`;if(isFile(t))return t}for(let n of t){let t=join(e,`index${n}`);if(isFile(t))return t}}function isFile(e){try{return statSync(e).isFile()}catch{return!1}}function resolveAuthoredTsConfigPath(e){for(let n of[`tsconfig.json`,`jsconfig.json`]){let r=join(e,n);if(existsSync(r))return r}return!1}function resolveAuthoredPackageRoot(e){let n=dirname(e);for(;;){if(existsSync(join(n,`package.json`)))return n;let r=dirname(n);if(r===n)throw Error(`Failed to resolve the authored package root for "${e}".`);n=r}}export{bundleAuthoredModuleCode,bundleAuthoredModuleForGeneration,loadAuthoredModuleNamespace};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ResolvedAuthoredExternalModule } from "#internal/materialize-authored-external-dependencies.js";
|
|
2
1
|
export declare const CACHED_CHANNEL_PREFIX = "eve-cached-channel:";
|
|
3
2
|
export declare const RESOLVE_EXTENSIONS: readonly [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".json"];
|
|
4
3
|
type RolldownResolveResult = {
|
|
@@ -13,7 +12,6 @@ export type RolldownResolveContext = {
|
|
|
13
12
|
export declare function createGenerationPackageBoundaryPlugin(input: {
|
|
14
13
|
readonly externalDependencies: readonly string[];
|
|
15
14
|
readonly packageRoot: string;
|
|
16
|
-
readonly recordExternalModule: (externalModule: ResolvedAuthoredExternalModule) => void;
|
|
17
15
|
}): Record<string, unknown>;
|
|
18
16
|
export declare function createRuntimeLoaderPackageBoundaryPlugin(input: {
|
|
19
17
|
readonly externalDependencies: readonly string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync,realpathSync}from"node:fs";import{join,resolve,sep}from"node:path";
|
|
1
|
+
import{existsSync,realpathSync}from"node:fs";import{join,resolve,sep}from"node:path";const CACHED_CHANNEL_PREFIX=`eve-cached-channel:`,RESOLVE_EXTENSIONS=[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`];function createGenerationPackageBoundaryPlugin(e){return{name:`eve-generation-package-boundary`,async resolveId(t,n,r){if(isPackageImport(t)&&(isFrameworkRuntimeImport(t,n)||await resolveConfiguredExternalModule.call(this,{externalDependencies:e.externalDependencies,importer:n,kind:r.kind,packageRoot:e.packageRoot,source:t})!==void 0))return{external:!0,id:t}}}}function createRuntimeLoaderPackageBoundaryPlugin(e){let t=toCanonicalPath(e.packageRoot);return{name:`eve-runtime-loader-package-boundary`,async resolveId(n,i,a){if(!isPackageImport(n))return;if(isFrameworkRuntimeImport(n,i))return{external:!0,id:n};let o=await resolveConfiguredExternalModule.call(this,{externalDependencies:e.externalDependencies,importer:i,kind:a.kind,packageRoot:e.packageRoot,source:n});if(o!==void 0)return{external:!0,id:resolveExistingExternalFilePath(o.resolvedId)??o.resolvedId};let s=i===void 0||i.startsWith(`\0`)||i.startsWith(`eve-cached-channel:`)?void 0:resolve(i);if(s!==void 0&&isPathInsideOrEqual(toCanonicalPath(s),t)){let e=await this.resolve(n,i,{kind:a.kind,skipSelf:!0});if(e===null||typeof e.id!=`string`)throw Error(`Cannot resolve package "${n}" imported from "${s}". Install it with your package manager (e.g. \`pnpm install\`); a running \`eve dev\` retries on the next rebuild.`);if(isNodeModulesPath(e.id))return{external:!0,id:n}}}}}async function resolveConfiguredExternalModule(e){let t=resolveConfiguredExternalDependency(e.source,e.externalDependencies);if(t===void 0)return;let r=await this.resolve(e.source,e.importer,{kind:e.kind,skipSelf:!0});if(r===null&&(r=await this.resolve(e.source,join(e.packageRoot,`package.json`),{kind:e.kind,skipSelf:!0})),r===null||typeof r.id!=`string`)throw Error(`Cannot resolve external package "${e.source}".`);return{packageName:t,resolvedId:r.id}}function normalizeExternalDependencies(e=[]){return[...new Set(e)].sort()}function resolveConfiguredExternalDependency(e,t){return t.find(t=>e===t||e.startsWith(`${t}/`))}function resolveExistingExternalFilePath(t){if(existsSync(t))return t;for(let n of RESOLVE_EXTENSIONS){let r=`${t}${n}`;if(existsSync(r))return r}}function isPackageImport(e){return isPathImport(e)||/^(?:node|data|file):/.test(e)||e.startsWith(`@/`)?!1:!e.startsWith(CACHED_CHANNEL_PREFIX)}function isPathImport(e){return e.startsWith(`.`)||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)}function isFrameworkRuntimeImport(e,t){return e===`eve`||e.startsWith(`eve/`)?!0:e===`workflow`||e.startsWith(`workflow/`)||e.startsWith(`@workflow/`)?t===void 0||!isNodeModulesPath(t):!1}function isNodeModulesPath(e){return e.replaceAll(`\\`,`/`).includes(`/node_modules/`)}function toCanonicalPath(e){try{return realpathSync(e)}catch{return resolve(e)}}function isPathInsideOrEqual(e,t){let n=resolve(e),a=resolve(t);return n===a||n.startsWith(`${a}${sep}`)}export{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,isPathImport,normalizeExternalDependencies};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname,join,resolve,sep}from"node:path";import{readFile,stat}from"node:fs/promises";import{parse
|
|
1
|
+
import{dirname,join,resolve,sep}from"node:path";import{readFile,stat}from"node:fs/promises";import{parse}from"#compiled/jsonc-parser/index.js";const packageTsConfigPathsCache=new Map,nearestPackageRootCache=new Map;function createAuthoredPackageTsConfigPathsPlugin(e){return{name:`eve-package-tsconfig-paths`,async resolveId(t,r,i){if(r===void 0||!isPackageImport(t))return;let a=resolve(r);if(isPathInsideOrEqual(a,e.appPackageRoot))return;let o=await resolveNearestPackageRoot(a);if(o===void 0||isPathInsideOrEqual(o,e.appPackageRoot))return;let s=await loadPackageTsConfigPaths(o);if(s!==void 0)for(let n of createTsConfigPathCandidates(t,s)){let t=await this.resolve(n,r,{kind:i.kind,skipSelf:!0});if(t!==null)return t;let a=await resolveExistingPath(n,e.extensions);if(a!==void 0)return{id:a}}}}}function loadPackageTsConfigPaths(e){let t=packageTsConfigPathsCache.get(e);if(t!==void 0)return t;let n=readPackageTsConfigPaths(e);return packageTsConfigPathsCache.set(e,n),n}async function readPackageTsConfigPaths(t){let r=await readPackageConfig(t);if(r===void 0)return;let i=[],a=parse(r.source,i,{allowTrailingComma:!0});if(i.length>0||!isObjectRecord(a))return;let s=a.compilerOptions;if(!isObjectRecord(s)||!isObjectRecord(s.paths))return;let c=dirname(r.path),l=typeof s.baseUrl==`string`?resolve(c,s.baseUrl):c,u=Object.entries(s.paths).flatMap(([e,t])=>!Array.isArray(t)||!t.every(e=>typeof e==`string`)?[]:[{pattern:e,targets:t}]).sort((e,t)=>t.pattern.length-e.pattern.length);if(u.length!==0)return{baseDirectory:l,entries:u}}async function readPackageConfig(e){for(let n of[`tsconfig.json`,`jsconfig.json`]){let r=join(e,n);try{return{path:r,source:await readFile(r,`utf8`)}}catch(e){if(!isPathNotFoundError(e))throw e}}}function createTsConfigPathCandidates(e,t){let r=[];for(let i of t.entries){let a=matchTsConfigPathPattern(e,i.pattern);if(a!==void 0)for(let e of i.targets){let i=e.includes(`*`)?e.replaceAll(`*`,a):e;r.push(resolve(t.baseDirectory,i))}}return r}function matchTsConfigPathPattern(e,t){let n=t.indexOf(`*`);if(n===-1)return e===t?``:void 0;let r=t.slice(0,n),i=t.slice(n+1);if(!(!e.startsWith(r)||!e.endsWith(i)))return e.slice(r.length,e.length-i.length)}async function resolveExistingPath(e,n){if(await existsAsFile(e))return e;for(let t of n){let n=`${e}${t}`;if(await existsAsFile(n))return n}for(let r of n){let n=join(e,`index${r}`);if(await existsAsFile(n))return n}}async function existsAsFile(e){try{return(await stat(e)).isFile()}catch{return!1}}function resolveNearestPackageRoot(t){let n=dirname(t),r=nearestPackageRootCache.get(n);if(r!==void 0)return r;let i=findNearestPackageRoot(n);return nearestPackageRootCache.set(n,i),i}async function findNearestPackageRoot(n){let r=n;for(;;){if(await pathExists(join(r,`package.json`)))return r;let n=dirname(r);if(n===r)return;r=n}}async function pathExists(e){try{return await stat(e),!0}catch{return!1}}function isPathNotFoundError(e){return typeof e==`object`&&!!e&&`code`in e&&(e.code===`ENOENT`||e.code===`ENOTDIR`)}function isPackageImport(e){return e.startsWith(`.`)||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)?!1:!/^(?:node|data|file):/.test(e)}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function isPathInsideOrEqual(e,t){let i=resolve(e),a=resolve(t);return i===a||i.startsWith(`${a}${sep}`)}export{createAuthoredPackageTsConfigPathsPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAbsolute,relative,sep}from"node:path";const RUNTIME_ROOT_TOKEN=`$runtime`;function serializeCompiledManifestForFingerprint(e){return JSON.stringify(normalizeValue(e.manifest,e.runtimeAppRoot))}function normalizeValue(e,t){return typeof e==`string`?normalizeRuntimePath(e,t):Array.isArray(e)?e.map(e=>normalizeValue(e,t)):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>[e,normalizeValue(n,t)]))}function normalizeRuntimePath(r,i){if(!isAbsolute(r))return r;let a=relative(i,r);return a===``?RUNTIME_ROOT_TOKEN:a===`..`||a.startsWith(`..${sep}`)||isAbsolute(a)?r:`${RUNTIME_ROOT_TOKEN}/${a.split(sep).join(`/`)}`}export{serializeCompiledManifestForFingerprint};
|
|
@@ -7,9 +7,6 @@ export interface MaterializedAuthoredModuleIndex {
|
|
|
7
7
|
readonly version: 1;
|
|
8
8
|
}
|
|
9
9
|
export declare function materializeAuthoredModules(input: {
|
|
10
|
-
readonly appRoot: string;
|
|
11
10
|
readonly runtimeAppRoot: string;
|
|
12
|
-
readonly snapshotSourceRoot: string;
|
|
13
|
-
readonly sourceRoot: string;
|
|
14
11
|
}): Promise<MaterializedAuthoredModuleIndex>;
|
|
15
12
|
export declare function readMaterializedAuthoredModuleIndex(runtimeAppRoot: string): Promise<MaterializedAuthoredModuleIndex | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync}from"node:fs";import{join,relative,sep}from"node:path";import{lstat,mkdir,readFile,readdir,readlink,writeFile}from"node:fs/promises";import{createHash}from"node:crypto";import{collectModuleRefsForManifest}from"#compiler/module-map.js";import{COMPILED_AGENT_MANIFEST_KIND,ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{bundleAuthoredModuleForGeneration}from"#internal/authored-module-loader.js";import{
|
|
1
|
+
import{existsSync}from"node:fs";import{join,relative,sep}from"node:path";import{lstat,mkdir,readFile,readdir,readlink,writeFile}from"node:fs/promises";import{createHash}from"node:crypto";import{collectModuleRefsForManifest}from"#compiler/module-map.js";import{COMPILED_AGENT_MANIFEST_KIND,ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{bundleAuthoredModuleForGeneration}from"#internal/authored-module-loader.js";import{serializeCompiledManifestForFingerprint}from"#internal/compiled-manifest-fingerprint.js";const MATERIALIZED_MODULES_DIRECTORY=`authored-modules`,MATERIALIZED_MODULES_INDEX=`authored-modules.json`,INSTRUMENTATION_EXTENSIONS=[`.ts`,`.mts`,`.js`,`.mjs`];async function materializeAuthoredModules(e){let n=join(e.runtimeAppRoot,`.eve`,`compile`),r=await readCompiledManifest(join(n,`compiled-agent-manifest.json`)),i=join(n,MATERIALIZED_MODULES_DIRECTORY),o=createExtensionScopeIndex(r),s={},c=createHash(`sha256`);await mkdir(i,{recursive:!0}),c.update(`manifest\0`).update(serializeCompiledManifestForFingerprint({manifest:r,runtimeAppRoot:e.runtimeAppRoot})).update(`\0`);for(let e of collectNodeManifests(r)){let n={};for(let r of collectModuleRefsForManifest(e.manifest).sort((e,t)=>e.sourceId.localeCompare(t.sourceId))){let a=await bundleAuthoredModuleForGeneration(join(e.agentRoot,r.logicalPath),{externalDependencies:e.manifest.config.build?.externalDependencies??[],extensionScopeNamespace:extensionNamespaceForSourceId(r.sourceId,o)}),s=createMaterializedModuleFileName(e.nodeId,r.sourceId,a);await writeFile(join(i,s),a),c.update(`module\0`).update(e.nodeId).update(`\0`).update(r.sourceId).update(`\0`).update(a).update(`\0`),n[r.sourceId]=join(MATERIALIZED_MODULES_DIRECTORY,s)}s[e.nodeId]={modules:n}}let u=resolveInstrumentationModule(r.agentRoot),d;if(u!==void 0){let e=await bundleAuthoredModuleForGeneration(u,{externalDependencies:r.config.build?.externalDependencies??[]}),n=createMaterializedModuleFileName(ROOT_COMPILED_AGENT_NODE_ID,`instrumentation`,e);await writeFile(join(i,n),e),d=join(MATERIALIZED_MODULES_DIRECTORY,n),c.update(`instrumentation\0`).update(e).update(`\0`)}await hashDirectoryIfPresent({fingerprint:c,path:join(n,`workspace-resources`),root:join(n,`workspace-resources`)});let f={fingerprint:c.digest(`hex`),nodes:s,version:1};return d!==void 0&&(f.instrumentation=d),await writeFile(join(n,MATERIALIZED_MODULES_INDEX),`${JSON.stringify(f)}\n`),f}async function readMaterializedAuthoredModuleIndex(n){let r=join(n,`.eve`,`compile`,MATERIALIZED_MODULES_INDEX);if(!existsSync(r))return;let i=JSON.parse(await readFile(r,`utf8`));if(i.version!==1||typeof i.fingerprint!=`string`||i.fingerprint.length===0||typeof i.nodes!=`object`||i.nodes===null||i.instrumentation!==void 0&&typeof i.instrumentation!=`string`)throw Error(`Invalid materialized authored module index at "${r}".`);return i}function collectNodeManifests(e){return[{agentRoot:e.agentRoot,manifest:e,nodeId:ROOT_COMPILED_AGENT_NODE_ID},...[...e.subagents].sort((e,t)=>e.nodeId.localeCompare(t.nodeId)).map(e=>({agentRoot:e.agent.agentRoot,manifest:e.agent,nodeId:e.nodeId}))]}function createExtensionScopeIndex(e){return{byMountNamespace:new Map(e.extensionMounts.map(e=>[e.namespace,e.packageNamespace]))}}function extensionNamespaceForSourceId(e,t){let n=e.match(/^ext:([^:]+):/u);return n===null?void 0:t.byMountNamespace.get(n[1])}async function readCompiledManifest(e){let t=JSON.parse(await readFile(e,`utf8`));if(t.kind!==COMPILED_AGENT_MANIFEST_KIND)throw Error(`Invalid compiled agent manifest at "${e}".`);return t}function resolveInstrumentationModule(n){for(let r of INSTRUMENTATION_EXTENSIONS){let i=join(n,`instrumentation${r}`);if(existsSync(i))return i}}function createMaterializedModuleFileName(e,t,n){return`${createHash(`sha256`).update(e).update(`\0`).update(t).update(`\0`).update(n).digest(`hex`)}.mjs`}async function hashDirectoryIfPresent(r){if(!existsSync(r.path))return;let a=await lstat(r.path),l=toPortablePath(relative(r.root,r.path));if(a.isSymbolicLink()){r.fingerprint.update(l).update(`\0link\0`).update(await readlink(r.path)).update(`\0`);return}if(a.isDirectory()){for(let e of(await readdir(r.path)).sort())await hashDirectoryIfPresent({...r,path:join(r.path,e)});return}a.isFile()&&r.fingerprint.update(l).update(`\0file\0`).update(await readFile(r.path)).update(`\0`)}function toPortablePath(e){return e.split(sep).join(`/`)}export{materializeAuthoredModules,readMaterializedAuthoredModuleIndex};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
+
export declare const DEVELOPMENT_CLIENT_ADDRESS_HEADER = "x-eve-dev-client-address";
|
|
3
|
+
export declare const DEVELOPMENT_CLIENT_ADDRESS_SIGNATURE_HEADER = "x-eve-dev-client-address-signature";
|
|
4
|
+
/**
|
|
5
|
+
* Stamps the accepted socket's peer address onto a request bound for the
|
|
6
|
+
* dev worker. Public copies of the metadata headers are dropped first, and
|
|
7
|
+
* the value is signed with the per-process dev transport secret: the
|
|
8
|
+
* worker's own HTTP port is reachable by other local processes, so an
|
|
9
|
+
* unsigned header could be forged by anything that discovers it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function stampDevelopmentClientAddress(headers: Headers | IncomingHttpHeaders, address: string | undefined, secret: string | undefined): void;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the parent-stamped client address when its signature verifies,
|
|
14
|
+
* `undefined` otherwise. Callers fall back to the socket peer, which in the
|
|
15
|
+
* proxied dev topology is the parent's loopback hop.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readTrustedDevelopmentClientAddress(headers: Headers, secret: string | undefined): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Constant-time string comparison over fixed-length digests, so neither the
|
|
20
|
+
* length nor the content of a secret comparison leaks through timing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function timingSafeEqualStrings(a: string, b: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createHash,createHmac,timingSafeEqual}from"node:crypto";const DEVELOPMENT_CLIENT_ADDRESS_HEADER=`x-eve-dev-client-address`,DEVELOPMENT_CLIENT_ADDRESS_SIGNATURE_HEADER=`x-eve-dev-client-address-signature`;function stampDevelopmentClientAddress(e,t,n){deleteHeader(e,DEVELOPMENT_CLIENT_ADDRESS_HEADER),deleteHeader(e,DEVELOPMENT_CLIENT_ADDRESS_SIGNATURE_HEADER),!(t===void 0||t.length===0||n===void 0||n.length===0)&&(setHeader(e,DEVELOPMENT_CLIENT_ADDRESS_HEADER,t),setHeader(e,DEVELOPMENT_CLIENT_ADDRESS_SIGNATURE_HEADER,signClientAddress(t,n)))}function readTrustedDevelopmentClientAddress(e,t){let n=e.get(DEVELOPMENT_CLIENT_ADDRESS_HEADER),i=e.get(DEVELOPMENT_CLIENT_ADDRESS_SIGNATURE_HEADER);if(!(n===null||i===null||t===void 0||t.length===0||!timingSafeEqualStrings(i,signClientAddress(n,t))))return n}function timingSafeEqualStrings(t,r){return timingSafeEqual(createHash(`sha256`).update(t).digest(),createHash(`sha256`).update(r).digest())}function signClientAddress(e,n){return createHmac(`sha256`,n).update(e).digest(`base64url`)}function deleteHeader(e,t){if(e instanceof Headers){e.delete(t);return}delete e[t]}function setHeader(e,t,n){if(e instanceof Headers){e.set(t,n);return}e[t]=n}export{DEVELOPMENT_CLIENT_ADDRESS_HEADER,DEVELOPMENT_CLIENT_ADDRESS_SIGNATURE_HEADER,readTrustedDevelopmentClientAddress,stampDevelopmentClientAddress,timingSafeEqualStrings};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER = "activated";
|
|
2
|
+
/** Records the instant at which an activated generation stopped being current. */
|
|
3
|
+
export declare function recordRetiredDevelopmentRuntimeArtifactsSnapshot(snapshotRoot: string, retiredAt?: number): Promise<void>;
|
|
4
|
+
/** Applies the bounded retention policy within one dev snapshot directory. */
|
|
5
|
+
export declare function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(input: {
|
|
6
|
+
readonly activeSnapshotRoot: string | undefined;
|
|
7
|
+
readonly gracePeriodMs?: number;
|
|
8
|
+
readonly now?: number;
|
|
9
|
+
readonly protectAll: boolean;
|
|
10
|
+
readonly retainCount?: number;
|
|
11
|
+
readonly snapshotsDirectory: string;
|
|
12
|
+
}): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync}from"node:fs";import{join,resolve}from"node:path";import{readFile,readdir,rm,stat,writeFile}from"node:fs/promises";const DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER=`activated`,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA=`retired.json`;async function recordRetiredDevelopmentRuntimeArtifactsSnapshot(e,n=Date.now()){await writeFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`${JSON.stringify({retiredAt:n})}\n`)}async function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(r){if(r.protectAll)return;let o=r.now??Date.now(),s=Math.max(0,r.gracePeriodMs??18e5),c=Math.max(0,Math.trunc(r.retainCount??5)),l;try{l=await readdir(r.snapshotsDirectory,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let u=r.activeSnapshotRoot===void 0?void 0:resolve(r.activeSnapshotRoot),d=await Promise.all(l.filter(e=>e.isDirectory()).map(async i=>{let a=join(r.snapshotsDirectory,i.name),s=u===resolve(a),c=existsSync(join(a,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER)),l;if(c&&!s)try{l=await readRetiredAt(a),l===void 0&&(await recordRetiredDevelopmentRuntimeArtifactsSnapshot(a,o),l=o)}catch(e){console.warn(`[eve:dev] failed to read or initialize runtime generation retirement metadata for "${a}": ${String(e)}`)}return{activated:c,active:s,path:a,retiredAt:l,mtimeMs:(await stat(a)).mtimeMs}})),f=new Set(d.flatMap(e=>e.retiredAt===void 0?[]:[{path:e.path,retiredAt:e.retiredAt}]).sort((e,t)=>t.retiredAt-e.retiredAt).slice(0,c).map(e=>e.path)),p=new Set(d.filter(e=>!e.activated).sort((e,t)=>t.mtimeMs-e.mtimeMs).slice(0,c).map(e=>e.path));await Promise.all(d.map(async e=>{e.active||e.activated&&e.retiredAt===void 0||f.has(e.path)||p.has(e.path)||e.retiredAt!==void 0&&o-e.retiredAt<=s||!e.activated&&o-e.mtimeMs<=s||await rm(e.path,{force:!0,recursive:!0})}))}async function readRetiredAt(e){let n;try{n=await readFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let i;try{i=JSON.parse(n)}catch{return}if(typeof i==`object`&&i&&!Array.isArray(i)&&`retiredAt`in i&&typeof i.retiredAt==`number`&&Number.isFinite(i.retiredAt)&&i.retiredAt>=0)return i.retiredAt}export{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot};
|
|
@@ -8,6 +8,14 @@ export interface DevelopmentRuntimeArtifactsSnapshot {
|
|
|
8
8
|
readonly snapshotSourceRoot: string;
|
|
9
9
|
readonly sourceRoot: string;
|
|
10
10
|
}
|
|
11
|
+
export interface ActiveDevelopmentRuntimeArtifactsSnapshot {
|
|
12
|
+
readonly runtimeAppRoot: string;
|
|
13
|
+
readonly snapshotRoot: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DevelopmentRuntimeArtifactsActivation {
|
|
16
|
+
commit(): void;
|
|
17
|
+
rollback(): Promise<void>;
|
|
18
|
+
}
|
|
11
19
|
/**
|
|
12
20
|
* Resolves the dev-server pointer that records the latest runtime artifact
|
|
13
21
|
* snapshot for new sessions.
|
|
@@ -24,17 +32,27 @@ export declare function activateDevelopmentRuntimeArtifactsSnapshot(input: {
|
|
|
24
32
|
readonly appRoot: string;
|
|
25
33
|
readonly snapshot: DevelopmentRuntimeArtifactsSnapshot;
|
|
26
34
|
}): Promise<void>;
|
|
35
|
+
export declare function activateDevelopmentRuntimeArtifactsSnapshotTransaction(input: {
|
|
36
|
+
readonly appRoot: string;
|
|
37
|
+
readonly snapshot: DevelopmentRuntimeArtifactsSnapshot;
|
|
38
|
+
}): Promise<DevelopmentRuntimeArtifactsActivation>;
|
|
27
39
|
/**
|
|
28
40
|
* Reads the latest dev runtime snapshot root when the dev server has one.
|
|
29
41
|
*/
|
|
30
42
|
export declare function readDevelopmentRuntimeArtifactsSnapshotRoot(pointerPath: string | undefined): string | undefined;
|
|
43
|
+
export declare function readActiveDevelopmentRuntimeArtifactsSnapshot(appRoot: string): ActiveDevelopmentRuntimeArtifactsSnapshot | undefined;
|
|
31
44
|
/**
|
|
32
45
|
* Reads a revision token for the latest dev runtime artifact snapshot.
|
|
33
46
|
*/
|
|
34
47
|
export declare function readDevelopmentRuntimeArtifactsRevision(appRoot: string): DevelopmentRuntimeArtifactsRevision;
|
|
48
|
+
/**
|
|
49
|
+
* Bounds dev snapshot storage without consulting a Workflow World. The active
|
|
50
|
+
* generation is always retained; retired generations receive a grace period,
|
|
51
|
+
* and the newest retired generations remain as a rebuild-rate safety net.
|
|
52
|
+
*/
|
|
35
53
|
export declare function pruneDevelopmentRuntimeArtifactsSnapshots(input: {
|
|
36
54
|
readonly appRoot: string;
|
|
55
|
+
readonly gracePeriodMs?: number;
|
|
37
56
|
readonly now?: number;
|
|
38
|
-
readonly recentWindowMs?: number;
|
|
39
57
|
readonly retainCount?: number;
|
|
40
58
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{cp,mkdir,readFile,
|
|
1
|
+
import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{cp,mkdir,readFile,rm,writeFile}from"node:fs/promises";import{randomUUID}from"node:crypto";import{renameWithTransientBusyRetry}from"#shared/rename-with-retry.js";import{copyDevelopmentSourceSnapshot}from"#internal/nitro/dev-runtime-source-snapshot-copy.js";import{createDevelopmentSourceSnapshotPlan}from"#internal/nitro/dev-runtime-source-snapshot.js";import{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts-retention.js";const DEV_RUNTIME_ARTIFACTS_DIRECTORY=`dev-runtime`;function resolveDevelopmentRuntimeArtifactsPointerPath(e){return join(e,`.eve`,DEV_RUNTIME_ARTIFACTS_DIRECTORY,`current.json`)}function resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e){return join(e,`.eve`,DEV_RUNTIME_ARTIFACTS_DIRECTORY,`snapshots`)}function isDevelopmentRuntimeArtifactsSnapshotRoot(e,t){return dirname(resolve(t))===resolve(resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e))}async function stageDevelopmentRuntimeArtifactsSnapshot(e){let t=join(resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e.project.appRoot),`${Date.now().toString(36)}-${randomUUID()}`),n=await createDevelopmentSourceSnapshotPlan({appRoot:e.project.appRoot,snapshotRoot:t});try{await copyDevelopmentSourceSnapshot(n),await cp(e.paths.compileDirectoryPath,join(n.runtimeAppRoot,`.eve`,`compile`),{recursive:!0}),await rewriteSnapshotCompiledManifest({appRoot:e.project.appRoot,manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:n.runtimeAppRoot}),await validateSnapshotCompiledManifestRoots({manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:n.runtimeAppRoot}),await writeFile(join(t,`generation.json`),`${JSON.stringify({runtimeAppRoot:n.runtimeAppRoot})}\n`)}catch(e){throw await rm(t,{force:!0,recursive:!0}).catch(()=>{}),e}return{runtimeAppRoot:n.runtimeAppRoot,snapshotRoot:t,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}}async function activateDevelopmentRuntimeArtifactsSnapshot(e){(await activateDevelopmentRuntimeArtifactsSnapshotTransaction(e)).commit()}async function activateDevelopmentRuntimeArtifactsSnapshotTransaction(e){let t=join(e.snapshot.snapshotRoot,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER),n=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),i=readDevelopmentRuntimeArtifactsPointer(n),a=await readOptionalFile(n);try{await writeFile(t,``),await writeDevelopmentRuntimeArtifactsPointer(e),i?.version===2&&i.snapshotRoot!==e.snapshot.snapshotRoot&&isDevelopmentRuntimeArtifactsSnapshotRoot(e.appRoot,i.snapshotRoot)&&await recordRetiredDevelopmentRuntimeArtifactsSnapshot(i.snapshotRoot).catch(e=>{console.warn(`[eve:dev] failed to record retired runtime generation "${i.snapshotRoot}": ${String(e)}`)})}catch(e){throw await rollbackFailedActivation({cause:e,markerPath:t,pointerPath:n,previousPointerSource:a})}let o=!1;return{commit(){o=!0},async rollback(){if(o)return;o=!0;let e=await restoreDevelopmentRuntimeArtifactsActivation({markerPath:t,pointerPath:n,previousPointerSource:a});if(e!==void 0)throw e}}}function readDevelopmentRuntimeArtifactsSnapshotRoot(e){let t=readDevelopmentRuntimeArtifactsPointer(e);if(t!==void 0)return t.version===1?t.appRoot:t.runtimeAppRoot}function readActiveDevelopmentRuntimeArtifactsSnapshot(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e));if(!(t===void 0||t.version===1))return{runtimeAppRoot:t.runtimeAppRoot,snapshotRoot:t.snapshotRoot}}function readDevelopmentRuntimeArtifactsRevision(e){return{revision:readDevelopmentRuntimeArtifactsSnapshotRoot(resolveDevelopmentRuntimeArtifactsPointerPath(e))??e}}async function pruneDevelopmentRuntimeArtifactsSnapshots(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot));await pruneDevelopmentRuntimeArtifactsSnapshotDirectory({activeSnapshotRoot:t?.version===2?t.snapshotRoot:void 0,gracePeriodMs:e.gracePeriodMs,now:e.now,protectAll:t?.version===1,retainCount:e.retainCount,snapshotsDirectory:resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e.appRoot)})}function readDevelopmentRuntimeArtifactsPointer(n){if(!(n===void 0||!existsSync(n)))try{let e=JSON.parse(readFileSync(n,`utf8`));return e.kind!==`eve-dev-runtime-artifacts-pointer`||typeof e.version!=`number`?void 0:e.version===1&&typeof e.appRoot==`string`&&e.appRoot.length>0?{appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,version:1}:e.version===2&&typeof e.appRoot==`string`&&typeof e.runtimeAppRoot==`string`&&e.runtimeAppRoot.length>0&&typeof e.snapshotRoot==`string`&&e.snapshotRoot.length>0?{appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:e.runtimeAppRoot,snapshotRoot:e.snapshotRoot,version:2}:void 0}catch{return}}async function rewriteSnapshotCompiledManifest(e){let t=JSON.parse(await readFile(e.manifestPath,`utf8`)),n=rewriteManifestRoots({appRoot:e.appRoot,runtimeAppRoot:e.runtimeAppRoot,value:t});await writeFile(e.manifestPath,`${JSON.stringify(n,null,2)}\n`)}function rewriteManifestRoots(e){if(Array.isArray(e.value))return e.value.map(t=>rewriteManifestRoots({...e,value:t}));if(e.value===null||typeof e.value!=`object`)return e.value;let t={};for(let[n,r]of Object.entries(e.value)){if(typeof r==`string`&&(n===`appRoot`||n===`agentRoot`)){t[n]=rewritePathWithinAppRoot({appRoot:e.appRoot,path:r,runtimeAppRoot:e.runtimeAppRoot});continue}t[n]=rewriteManifestRoots({appRoot:e.appRoot,runtimeAppRoot:e.runtimeAppRoot,value:r})}return t}function rewritePathWithinAppRoot(e){if(!isPathInsideOrEqual(e.path,e.appRoot))return e.path;let t=relative(e.appRoot,e.path);return t.length===0?e.runtimeAppRoot:join(e.runtimeAppRoot,t)}async function writeDevelopmentRuntimeArtifactsPointer(e){let t=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),n={appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:e.snapshot.runtimeAppRoot,snapshotRoot:e.snapshot.snapshotRoot,version:2};await writeDevelopmentRuntimeArtifactsPointerSource(t,`${JSON.stringify(n,null,2)}\n`)}async function writeDevelopmentRuntimeArtifactsPointerSource(e,t){let r=`${e}.${randomUUID()}.tmp`;await mkdir(dirname(e),{recursive:!0}),await writeFile(r,t);try{await renameWithTransientBusyRetry(r,e)}catch(e){throw await rm(r,{force:!0}).catch(()=>{}),e}}async function readOptionalFile(e){try{return await readFile(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}}async function rollbackFailedActivation(e){let t=await restoreDevelopmentRuntimeArtifactsActivation(e);return t===void 0?e.cause:AggregateError([e.cause,t],`Development runtime activation and rollback failed.`,{cause:e.cause})}async function restoreDevelopmentRuntimeArtifactsActivation(e){let t=(await Promise.allSettled([e.previousPointerSource===void 0?rm(e.pointerPath,{force:!0}):writeDevelopmentRuntimeArtifactsPointerSource(e.pointerPath,e.previousPointerSource),rm(e.markerPath,{force:!0})])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length!==0)return AggregateError(t,`Failed to restore development runtime activation.`)}async function validateSnapshotCompiledManifestRoots(e){let t=collectManifestRootPaths(JSON.parse(await readFile(e.manifestPath,`utf8`)));for(let n of t)if(!isPathInsideOrEqual(n,e.runtimeAppRoot))throw Error(`Development runtime snapshot manifest root "${n}" is outside runtime app root "${e.runtimeAppRoot}".`)}function collectManifestRootPaths(e){if(Array.isArray(e))return e.flatMap(e=>collectManifestRootPaths(e));if(typeof e!=`object`||!e)return[];let t=[];for(let[n,r]of Object.entries(e)){if((n===`appRoot`||n===`agentRoot`)&&typeof r==`string`){t.push(r);continue}t.push(...collectManifestRootPaths(r))}return t}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}export{activateDevelopmentRuntimeArtifactsSnapshot,activateDevelopmentRuntimeArtifactsSnapshotTransaction,pruneDevelopmentRuntimeArtifactsSnapshots,readActiveDevelopmentRuntimeArtifactsSnapshot,readDevelopmentRuntimeArtifactsRevision,readDevelopmentRuntimeArtifactsSnapshotRoot,resolveDevelopmentRuntimeArtifactsPointerPath,stageDevelopmentRuntimeArtifactsSnapshot};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CompileAgentResult } from "#compiler/compile-agent.js";
|
|
2
|
-
import { type DevelopmentRuntimeArtifactsSnapshot } from "#internal/nitro/dev-runtime-artifacts.js";
|
|
2
|
+
import { type DevelopmentRuntimeArtifactsActivation, type DevelopmentRuntimeArtifactsSnapshot } from "#internal/nitro/dev-runtime-artifacts.js";
|
|
3
3
|
export interface DevelopmentGeneration extends DevelopmentRuntimeArtifactsSnapshot {
|
|
4
4
|
readonly fingerprint: string;
|
|
5
5
|
}
|
|
@@ -9,4 +9,8 @@ export declare function activateDevelopmentGeneration(input: {
|
|
|
9
9
|
readonly appRoot: string;
|
|
10
10
|
readonly generation: DevelopmentGeneration;
|
|
11
11
|
}): Promise<void>;
|
|
12
|
+
export declare function activateDevelopmentGenerationTransaction(input: {
|
|
13
|
+
readonly appRoot: string;
|
|
14
|
+
readonly generation: DevelopmentGeneration;
|
|
15
|
+
}): Promise<DevelopmentRuntimeArtifactsActivation>;
|
|
12
16
|
export declare function discardDevelopmentGeneration(generation: DevelopmentGeneration): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{rm}from"node:fs/promises";import{materializeAuthoredModules}from"#internal/materialized-authored-modules.js";import{
|
|
1
|
+
import{rm}from"node:fs/promises";import{materializeAuthoredModules}from"#internal/materialized-authored-modules.js";import{activateDevelopmentRuntimeArtifactsSnapshotTransaction,pruneDevelopmentRuntimeArtifactsSnapshots,stageDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts.js";const developmentGenerationPruneStates=new Map;async function stageDevelopmentGeneration(n){let r=await stageDevelopmentRuntimeArtifactsSnapshot(n);try{let e=await materializeAuthoredModules({runtimeAppRoot:r.runtimeAppRoot});return{...r,fingerprint:e.fingerprint}}catch(t){try{await rm(r.snapshotRoot,{force:!0,recursive:!0})}catch(e){throw AggregateError([t,e],`Failed to materialize and discard development generation "${r.snapshotRoot}".`)}throw t}}async function publishDevelopmentGeneration(e){let t=await stageDevelopmentGeneration(e);return await activateDevelopmentGeneration({appRoot:e.project.appRoot,generation:t}),t}async function activateDevelopmentGeneration(e){(await activateDevelopmentGenerationTransaction(e)).commit()}async function activateDevelopmentGenerationTransaction(e){let t=await activateDevelopmentRuntimeArtifactsSnapshotTransaction({appRoot:e.appRoot,snapshot:e.generation}),r=!1;return{commit(){r||(r=!0,t.commit(),requestDevelopmentGenerationPrune(e.appRoot))},async rollback(){r||(r=!0,await t.rollback())}}}async function discardDevelopmentGeneration(t){await rm(t.snapshotRoot,{force:!0,recursive:!0})}function requestDevelopmentGenerationPrune(e){let t=developmentGenerationPruneStates.get(e)??{requested:!1,running:void 0};developmentGenerationPruneStates.set(e,t),t.requested=!0,t.running===void 0&&startDevelopmentGenerationPruning(e,t)}function startDevelopmentGenerationPruning(e,t){t.running=(async()=>{for(;t.requested;)t.requested=!1,await pruneDevelopmentRuntimeArtifactsSnapshots({appRoot:e})})().catch(e=>{console.warn(`[eve:dev] failed to prune runtime generations: ${String(e)}`)}).finally(()=>{t.running=void 0,t.requested?startDevelopmentGenerationPruning(e,t):developmentGenerationPruneStates.delete(e)})}export{activateDevelopmentGeneration,activateDevelopmentGenerationTransaction,discardDevelopmentGeneration,publishDevelopmentGeneration,stageDevelopmentGeneration};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DevelopmentNitroArtifactsConfig, ProductionNitroArtifactsConfig } from "#internal/nitro/routes/runtime-artifacts.js";
|
|
2
|
+
import type { AgentWorkflowWorldDefinition } from "#shared/agent-definition.js";
|
|
2
3
|
/**
|
|
3
4
|
* Runtime-artifacts wiring for the dev server: routes read compiled
|
|
4
5
|
* artifacts from the authored app root via the snapshot pointer so hot
|
|
@@ -6,6 +7,7 @@ import type { DevelopmentNitroArtifactsConfig, ProductionNitroArtifactsConfig }
|
|
|
6
7
|
*/
|
|
7
8
|
export declare function createDevelopmentNitroArtifactsConfig(input: {
|
|
8
9
|
readonly appRoot: string;
|
|
10
|
+
readonly configuredWorld?: AgentWorkflowWorldDefinition;
|
|
9
11
|
}): DevelopmentNitroArtifactsConfig;
|
|
10
12
|
/**
|
|
11
13
|
* Runtime-artifacts wiring for built output: routes require the artifacts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolvePackageSourceFilePath}from"#internal/application/package.js";import{resolveDevelopmentRuntimeArtifactsPointerPath}from"#internal/nitro/dev-runtime-artifacts.js";function createDevelopmentNitroArtifactsConfig(e){return{appRoot:e.appRoot,devRuntimeArtifactsPointerPath:resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),kind:`development`,moduleMapLoaderPath:resolvePackageSourceFilePath(`src/internal/authored-module-map-loader.ts`)}}function createProductionNitroArtifactsConfig(){return{kind:`production`}}export{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig};
|
|
1
|
+
import{resolvePackageSourceFilePath}from"#internal/application/package.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{resolveDevelopmentRuntimeArtifactsPointerPath}from"#internal/nitro/dev-runtime-artifacts.js";function createDevelopmentNitroArtifactsConfig(e){return{appRoot:e.appRoot,devRuntimeArtifactsPointerPath:resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),durableArtifactsReference:usesParentDevelopmentWorkflowWorld(e.configuredWorld)?`development-generation`:void 0,kind:`development`,moduleMapLoaderPath:resolvePackageSourceFilePath(`src/internal/authored-module-map-loader.ts`)}}function createProductionNitroArtifactsConfig(){return{kind:`production`}}export{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig};
|
|
@@ -4,10 +4,7 @@ import type { ChannelRouteMethod } from "#public/definitions/channel.js";
|
|
|
4
4
|
import type { NitroArtifactsConfig } from "#internal/nitro/routes/runtime-artifacts.js";
|
|
5
5
|
import type { PreparedApplicationHost } from "#internal/nitro/host/types.js";
|
|
6
6
|
interface ChannelRouteNitro {
|
|
7
|
-
options: Pick<Nitro["options"], "handlers" | "virtual">;
|
|
8
|
-
routing: {
|
|
9
|
-
sync(): void;
|
|
10
|
-
};
|
|
7
|
+
readonly options: Pick<Nitro["options"], "handlers" | "virtual">;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
10
|
* One Nitro route registration for an eve channel.
|
|
@@ -28,13 +25,4 @@ export declare function registerChannelVirtualHandlers(nitro: Pick<ChannelRouteN
|
|
|
28
25
|
readonly artifactsConfig: NitroArtifactsConfig;
|
|
29
26
|
readonly registrations: readonly NitroChannelRouteRegistration[];
|
|
30
27
|
}): void;
|
|
31
|
-
/**
|
|
32
|
-
* Replaces the currently-mounted eve channel virtual handlers when the route
|
|
33
|
-
* set changes.
|
|
34
|
-
*/
|
|
35
|
-
export declare function syncChannelVirtualHandlers(nitro: ChannelRouteNitro, input: {
|
|
36
|
-
readonly artifactsConfig: NitroArtifactsConfig;
|
|
37
|
-
readonly next: readonly NitroChannelRouteRegistration[];
|
|
38
|
-
readonly previous: readonly NitroChannelRouteRegistration[];
|
|
39
|
-
}): boolean;
|
|
40
28
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{resolvePackageDependencyPath,resolvePackageSourceFilePath}from"#internal/application/package.js";import{stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{getAllFrameworkChannelNames,getFrameworkChannelDefinitions}from"#runtime/framework-channels/index.js";
|
|
2
|
-
`);return}r.options.handlers.push({handler:s,method:i.method,route:i.route}),i.cors!==void 0&&addChannelCorsPreflightHandler(r,{cors:i.cors,nitroH3ModulePath:u,preflightRoutes:i.preflightRoutes,route:i.route}),r.options.virtual[s]=[...i.cors===void 0?[]:[`import { handleCors } from ${u};`,`const cors = ${JSON.stringify(i.cors)};`],`import { dispatchChannelRequest } from ${c};`,`const config = ${JSON.stringify(i.artifactsConfig)};`,i.cors===void 0?`export default (event) => dispatchChannelRequest(event, ${JSON.stringify(
|
|
1
|
+
import{resolvePackageDependencyPath,resolvePackageSourceFilePath}from"#internal/application/package.js";import{stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{getAllFrameworkChannelNames,getFrameworkChannelDefinitions}from"#runtime/framework-channels/index.js";const EVE_CHANNEL_VIRTUAL_ID_PREFIX=`#nitro/virtual/eve-channel/`;function computeChannelRouteRegistrations(e){let t=e.compileResult.manifest.channels,n=new Set,a=[],o=new Set,s=getAllFrameworkChannelNames();for(let e of t){if(e.kind===`disabled`){if(!s.has(e.name))throw Error(`agent/channels/${e.name}.ts exports disableRoute() but "${e.name}" is not a framework channel. Rename the file to one of: ${[...s].sort().join(`, `)}.`);o.add(e.name);continue}n.add(e.name),a.push({method:e.method,route:e.urlPath,cors:e.cors})}let c=getFrameworkChannelDefinitions().filter(e=>!n.has(e.name)&&!o.has(e.name)).map(e=>({method:e.method,route:e.urlPath,cors:e.cors})),l=new Set,u=[];for(let e of[...c,...a]){let t=createChannelRouteKey(e);l.has(t)||(l.add(t),u.push(e))}return u}function registerChannelVirtualHandlers(e,t){let n=new Set;for(let r of t.registrations)addChannelVirtualHandler(e,{artifactsConfig:t.artifactsConfig,cors:r.cors,method:r.method,preflightRoutes:n,route:r.route})}function createChannelRouteKey(e){return`${e.method.toUpperCase()} ${e.route}`}function addChannelVirtualHandler(r,i){let o=createChannelRouteKey(i),s=`${EVE_CHANNEL_VIRTUAL_ID_PREFIX}${o}`,c=stringifyEsmImportSpecifier(resolvePackageSourceFilePath(`src/internal/nitro/routes/channel-dispatch.ts`)),l=stringifyEsmImportSpecifier(resolvePackageDependencyPath(`nitro`)),u=stringifyEsmImportSpecifier(resolvePackageDependencyPath(`nitro/h3`));if(i.method===`WEBSOCKET`){r.options.handlers.push({handler:s,route:i.route}),r.options.virtual[s]=[`import { defineWebSocketHandler } from ${l};`,`import { dispatchChannelWebSocketRequest } from ${c};`,`const config = ${JSON.stringify(i.artifactsConfig)};`,`export default defineWebSocketHandler((event) => dispatchChannelWebSocketRequest(event, ${JSON.stringify(o)}, config));`].join(`
|
|
2
|
+
`);return}r.options.handlers.push({handler:s,method:i.method,route:i.route}),i.cors!==void 0&&addChannelCorsPreflightHandler(r,{cors:i.cors,nitroH3ModulePath:u,preflightRoutes:i.preflightRoutes,route:i.route}),r.options.virtual[s]=[...i.cors===void 0?[]:[`import { handleCors } from ${u};`,`const cors = ${JSON.stringify(i.cors)};`],`import { dispatchChannelRequest } from ${c};`,`const config = ${JSON.stringify(i.artifactsConfig)};`,i.cors===void 0?`export default (event) => dispatchChannelRequest(event, ${JSON.stringify(o)}, config);`:[`export default (event) => {`,` const corsResponse = handleCors(event, cors);`,` if (corsResponse !== false) return corsResponse;`,` return dispatchChannelRequest(event, ${JSON.stringify(o)}, config);`,`};`].join(`
|
|
3
3
|
`)].join(`
|
|
4
4
|
`)}function addChannelCorsPreflightHandler(e,t){if(t.preflightRoutes.has(t.route))return;t.preflightRoutes.add(t.route);let n=`${EVE_CHANNEL_VIRTUAL_ID_PREFIX}${`OPTIONS ${t.route}`}`;e.options.handlers.push({handler:n,method:`OPTIONS`,route:t.route}),e.options.virtual[n]=[`import { handleCors } from ${t.nitroH3ModulePath};`,`const cors = ${JSON.stringify(t.cors)};`,`export default (event) => {`,` const corsResponse = handleCors(event, cors);`,` if (corsResponse !== false) return corsResponse;`,` return new Response(null, { status: 204 });`,`};`].join(`
|
|
5
|
-
`)}
|
|
5
|
+
`)}export{computeChannelRouteRegistrations,registerChannelVirtualHandlers};
|
|
@@ -2,8 +2,7 @@ import type { Nitro } from "nitro/types";
|
|
|
2
2
|
import type { NitroBuildSurface, PreparedApplicationHost } from "#internal/nitro/host/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Wires eve's package-owned app, channel, workflow inspection, dev-control,
|
|
5
|
-
* and Workflow SDK endpoints into
|
|
6
|
-
* workflow bundles on reload.
|
|
5
|
+
* and Workflow SDK endpoints into one development Nitro candidate.
|
|
7
6
|
*/
|
|
8
7
|
export declare function configureDevelopmentNitroRoutes(nitro: Nitro, preparedHost: PreparedApplicationHost): Promise<void>;
|
|
9
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN,EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH,EVE_HEALTH_ROUTE_PATH}from"#protocol/routes.js";import{resolvePackageRoot,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{dirname,join,relative}from"node:path";import{mkdir,writeFile}from"node:fs/promises";import{isVercelBuildEnvironment}from"#internal/application/paths.js";import{normalizeEsmImportSpecifier,stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{WorkflowBundleBuilder}from"#internal/workflow-bundle/builder.js";import{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{deriveEveWorkflowQueuePrefix}from"#internal/workflow/queue-namespace.js";import{computeChannelRouteRegistrations,registerChannelVirtualHandlers}from"#internal/nitro/host/channel-routes.js";function includesApplicationRoutes(e){return e===`all`||e===`app`}function includesWorkflowBundles(e){return includesWorkflowRoute(e)}function includesWorkflowRoute(e){return e===`all`||e===`flow`}function registerHandler(e,t){let n=`#eve-route-handler/${t.method??`ALL`} ${t.route}`,r=stringifyEsmImportSpecifier(t.handlerPath);e.options.handlers.push({handler:n,method:t.method,route:t.route}),e.options.virtual[n]=[`import handler from ${r};`,`export default handler;`].join(`
|
|
1
|
+
import{EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN,EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH,EVE_HEALTH_ROUTE_PATH}from"#protocol/routes.js";import{resolvePackageRoot,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{dirname,join,relative}from"node:path";import{mkdir,writeFile}from"node:fs/promises";import{isVercelBuildEnvironment}from"#internal/application/paths.js";import{normalizeEsmImportSpecifier,stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{WorkflowBundleBuilder}from"#internal/workflow-bundle/builder.js";import{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{deriveEveWorkflowQueuePrefix}from"#internal/workflow/queue-namespace.js";import{computeChannelRouteRegistrations,registerChannelVirtualHandlers}from"#internal/nitro/host/channel-routes.js";function includesApplicationRoutes(e){return e===`all`||e===`app`}function includesWorkflowBundles(e){return includesWorkflowRoute(e)}function includesWorkflowRoute(e){return e===`all`||e===`flow`}function registerHandler(e,t){let n=`#eve-route-handler/${t.method??`ALL`} ${t.route}`,r=stringifyEsmImportSpecifier(t.handlerPath);e.options.handlers.push({handler:n,method:t.method,route:t.route}),e.options.virtual[n]=[`import handler from ${r};`,`export default handler;`].join(`
|
|
2
2
|
`)}function resolveNitroWorkflowBuildDirectory(e){return join(e.options.buildDir,`workflow`)}function createRelativeImportSpecifier(e,t){let n=relative(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function addWorkflowFileHandler(e,t){let n=join(resolveNitroWorkflowBuildDirectory(e),`${t.bundleName}-handler.mjs`),r=dirname(n),i=createRelativeImportSpecifier(r,t.bundlePath),a=t.directHandlers??[],s=a.length>0&&t.workflowWorldPluginPath!==void 0?createRelativeImportSpecifier(r,t.workflowWorldPluginPath):void 0,c=a.map(e=>{let t=createRelativeImportSpecifier(r,e.bundlePath);return{importSpecifier:t,isOwnBundle:t===i,queuePrefix:e.queuePrefix}});await mkdir(r,{recursive:!0}),await writeFile(n,buildWorkflowFileHandlerSource({bundlePath:i,directHandlers:c,runtimeImportSpecifier:t.runtimeImportSpecifier,workflowWorldPluginImportSpecifier:s})),e.options.handlers.push({handler:n,route:t.route})}function buildWorkflowFileHandlerSource(e){let t=[`// Generated by eve. Do not edit by hand.`,`import { POST } from ${JSON.stringify(e.bundlePath)};`];if(e.directHandlers.length>0&&e.runtimeImportSpecifier!==void 0){let n=0,r=e.directHandlers.map(e=>{if(e.isOwnBundle)return{...e,binding:`POST`};let t=`__eveWorkflowDirectHandler${n}`;return n+=1,{...e,binding:t}});for(let e of r)e.isOwnBundle||t.push(`import { POST as ${e.binding} } from ${JSON.stringify(e.importSpecifier)};`);e.workflowWorldPluginImportSpecifier!==void 0&&t.push(`import ${JSON.stringify(e.workflowWorldPluginImportSpecifier)};`),t.push(`import { getWorld as __eveGetWorkflowWorld } from ${JSON.stringify(e.runtimeImportSpecifier)};`,``,`try {`,` const __eveWorkflowWorld = await __eveGetWorkflowWorld();`,` if (typeof __eveWorkflowWorld?.registerHandler === "function") {`);for(let e of r)t.push(` __eveWorkflowWorld.registerHandler(${JSON.stringify(e.queuePrefix)}, ${e.binding});`);t.push(` }`,`} catch (err) {`,` console.warn("[eve] Failed to register direct workflow queue handlers:", err);`,`}`)}return t.push(``,`export default async ({ req }) => {`,` return await POST(req);`,`};`,``),t.join(`
|
|
3
3
|
`)}function addFrameworkVirtualHandler(e,t){let n=`#eve-route${t.route}`,r=stringifyEsmImportSpecifier(t.modulePath);e.options.handlers.push({handler:n,method:t.method,route:t.route}),e.options.virtual[n]=[`import { ${t.handlerExport} } from ${r};`,`export default async (event) => ${t.handlerExport}(${t.args}, event.req);`].join(`
|
|
4
|
-
`)}async function registerWorkflowArtifactBuildHook(e,t){let n=!0;await t(),e.hooks.hook(`build:before`,async()=>{if(n){n=!1;return}await t()})}function registerApplicationRoutes(e,t,r){addFrameworkVirtualHandler(e,{args:JSON.stringify({agentName:t.compileResult.manifest.config.name}),handlerExport:`handleHomePageRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/index.ts`),route:`/`});for(let t of[`GET`,`HEAD`])registerHandler(e,{handlerPath:resolvePackageSourceFilePath(`src/internal/nitro/routes/health.ts`),method:t,route:EVE_HEALTH_ROUTE_PATH});registerChannelVirtualHandlers(e,{artifactsConfig:r,registrations:computeChannelRouteRegistrations(t)})}function registerDevelopmentControlRoutes(n,r){addFrameworkVirtualHandler(n,{args:JSON.stringify({appRoot:r.appRoot}),handlerExport:`handleDevRuntimeArtifactsRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-runtime-artifacts.ts`),route:EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}),addFrameworkVirtualHandler(n,{args:JSON.stringify(r),handlerExport:`handleDevScheduleDispatchRequest`,method:`POST`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-schedule-dispatch.ts`),route:EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN})}function createWorkflowDirectHandlerEntry(e,t){return{bundlePath:t,queuePrefix:deriveEveWorkflowQueuePrefix(e.compileResult.manifest.config.name)}}async function registerWorkflowRoute(e,t,n,r){await addWorkflowFileHandler(e,{bundleName:`workflows`,bundlePath:n,directHandlers:r,route:`/.well-known/workflow/v1/flow`,runtimeImportSpecifier:r.length===0?void 0:normalizeEsmImportSpecifier(resolveWorkflowModulePath(`workflow/runtime`)),workflowWorldPluginPath:t.compiledArtifacts.workflowWorldPluginPath})}async function configureDevelopmentNitroRoutes(e,t){let n=resolveNitroWorkflowBuildDirectory(e),i=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!0}),
|
|
4
|
+
`)}async function registerWorkflowArtifactBuildHook(e,t){let n=!0;await t(),e.hooks.hook(`build:before`,async()=>{if(n){n=!1;return}await t()})}function registerApplicationRoutes(e,t,r){addFrameworkVirtualHandler(e,{args:JSON.stringify({agentName:t.compileResult.manifest.config.name}),handlerExport:`handleHomePageRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/index.ts`),route:`/`});for(let t of[`GET`,`HEAD`])registerHandler(e,{handlerPath:resolvePackageSourceFilePath(`src/internal/nitro/routes/health.ts`),method:t,route:EVE_HEALTH_ROUTE_PATH});registerChannelVirtualHandlers(e,{artifactsConfig:r,registrations:computeChannelRouteRegistrations(t)})}function registerDevelopmentControlRoutes(n,r){addFrameworkVirtualHandler(n,{args:JSON.stringify({appRoot:r.appRoot}),handlerExport:`handleDevRuntimeArtifactsRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-runtime-artifacts.ts`),route:EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}),addFrameworkVirtualHandler(n,{args:JSON.stringify(r),handlerExport:`handleDevScheduleDispatchRequest`,method:`POST`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-schedule-dispatch.ts`),route:EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN})}function createWorkflowDirectHandlerEntry(e,t){return{bundlePath:t,queuePrefix:deriveEveWorkflowQueuePrefix(e.compileResult.manifest.config.name)}}async function registerWorkflowRoute(e,t,n,r){await addWorkflowFileHandler(e,{bundleName:`workflows`,bundlePath:n,directHandlers:r,route:`/.well-known/workflow/v1/flow`,runtimeImportSpecifier:r.length===0?void 0:normalizeEsmImportSpecifier(resolveWorkflowModulePath(`workflow/runtime`)),workflowWorldPluginPath:t.compiledArtifacts.workflowWorldPluginPath})}async function configureDevelopmentNitroRoutes(e,t){let n=resolveNitroWorkflowBuildDirectory(e),i=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!0});await registerWorkflowArtifactBuildHook(e,async()=>{await i.build({nitroStepOutfile:join(n,`steps.mjs`),nitroWorkflowOutfile:join(n,`workflows.mjs`)})});let a=createDevelopmentNitroArtifactsConfig({appRoot:t.appRoot,configuredWorld:t.compileResult.manifest.config.experimental?.workflow?.world});registerApplicationRoutes(e,t,a),registerDevelopmentControlRoutes(e,a);let o=join(n,`workflows.mjs`),s=[];usesParentDevelopmentWorkflowWorld(t.compileResult.manifest.config.experimental?.workflow?.world)||s.push(createWorkflowDirectHandlerEntry(t,o)),await registerWorkflowRoute(e,t,o,s),e.routing.sync()}async function configureProductionNitroRoutes(e,t,n){if(includesWorkflowBundles(n)){let n=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!1});await registerWorkflowArtifactBuildHook(e,async()=>{await n.build({nitroStepOutfile:join(resolveNitroWorkflowBuildDirectory(e),`steps.mjs`)})})}if(includesApplicationRoutes(n)&®isterApplicationRoutes(e,t,createProductionNitroArtifactsConfig()),includesWorkflowRoute(n)){let n=join(t.workflowBuildDir,`workflows.mjs`),r=t.compileResult.manifest.config.experimental?.workflow?.world!==void 0;await registerWorkflowRoute(e,t,n,!isVercelBuildEnvironment()&&r?[createWorkflowDirectHandlerEntry(t,n)]:[])}e.routing.sync()}export{configureDevelopmentNitroRoutes,configureProductionNitroRoutes};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Nitro } from "nitro/types";
|
|
2
|
-
import type { NitroBuildSurface, PreparedApplicationHost } from "#internal/nitro/host/types.js";
|
|
2
|
+
import type { NitroBuildSurface, PreparedApplicationHost, PreparedDevelopmentApplicationHost } from "#internal/nitro/host/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hosted Vercel builds can prune local sandbox backends only when the
|
|
5
5
|
* app did not explicitly configure one. Omitted backends resolve through
|
|
@@ -11,11 +11,9 @@ export declare function shouldPruneLocalSandboxBackends(input: {
|
|
|
11
11
|
readonly preset: "vercel" | undefined;
|
|
12
12
|
}): boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Creates
|
|
15
|
-
* instance, live virtual modules, and hot-reload hooks wired to the authored
|
|
16
|
-
* source.
|
|
14
|
+
* Creates one isolated Nitro host candidate for `eve dev`.
|
|
17
15
|
*/
|
|
18
|
-
export declare function createDevelopmentApplicationNitro(preparedHost:
|
|
16
|
+
export declare function createDevelopmentApplicationNitro(preparedHost: PreparedDevelopmentApplicationHost): Promise<Nitro>;
|
|
19
17
|
interface ProductionApplicationNitroOptions {
|
|
20
18
|
readonly buildDir: string;
|
|
21
19
|
readonly outputDir: string;
|