eve 0.91.0 → 1.0.0-rc.0
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 +21 -34
- package/README.md +1 -3
- package/dist/src/channel/routes.d.ts +7 -3
- package/dist/src/channel/skill-files.d.ts +22 -25
- package/dist/src/channel/skill-files.js +1 -1
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +3 -3
- package/dist/src/compiled/semver/index.d.ts +5 -1
- package/dist/src/compiler/channel-route-plan.d.ts +2 -0
- package/dist/src/compiler/channel-route-plan.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/extensions/git/extension/lib/gh-tool.js +1 -1
- package/dist/src/framework/host-inventory.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.d.ts +0 -11
- package/dist/src/internal/application/compiled-artifacts.js +3 -3
- package/dist/src/internal/application/import-specifier.d.ts +6 -0
- package/dist/src/internal/application/import-specifier.js +1 -1
- package/dist/src/internal/application/paths.d.ts +2 -10
- package/dist/src/internal/application/paths.js +1 -1
- package/dist/src/internal/application/stamped-package-version.js +1 -1
- package/dist/src/internal/authored-asset-import-plugin.d.ts +18 -1
- package/dist/src/internal/authored-asset-import-plugin.js +1 -1
- 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/bundler/extension-mount-plugin.d.ts +19 -1
- package/dist/src/internal/bundler/extension-scope-plugin.d.ts +15 -5
- package/dist/src/internal/bundler/extension-scope-plugin.js +2 -2
- package/dist/src/internal/bundler/filters.d.ts +7 -0
- package/dist/src/internal/bundler/filters.js +1 -0
- package/dist/src/internal/bundler/pseudo-packages.d.ts +17 -7
- package/dist/src/internal/bundler/pseudo-packages.js +1 -1
- package/dist/src/internal/bundler/vendored-dependency-log.d.ts +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts-retention.d.ts +0 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts-retention.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.d.ts +2 -6
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-local-roots.d.ts +0 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-local-roots.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot.js +1 -1
- package/dist/src/internal/nitro/development-generation.d.ts +18 -6
- package/dist/src/internal/nitro/development-generation.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/create-host-nitro.d.ts +7 -0
- package/dist/src/internal/nitro/host/create-host-nitro.js +1 -0
- package/dist/src/internal/nitro/host/dev-authored-rebuild-coordinator.d.ts +2 -0
- package/dist/src/internal/nitro/host/dev-authored-rebuild-coordinator.js +1 -1
- package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
- package/dist/src/internal/nitro/host/dev-build-operations.js +1 -1
- package/dist/src/internal/nitro/host/dev-host-fingerprint.d.ts +4 -0
- package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -1
- package/dist/src/internal/nitro/host/drained-nitro-dev-server.js +1 -1
- package/dist/src/internal/nitro/host/extension-external-dependencies.d.ts +7 -0
- package/dist/src/internal/nitro/host/extension-external-dependencies.js +1 -0
- package/dist/src/internal/nitro/host/{external-dependency-output-check-plugin.d.ts → external-dependency-output-check.d.ts} +4 -9
- package/dist/src/internal/nitro/host/external-dependency-output-check.js +3 -0
- package/dist/src/internal/nitro/host/externals-policy.d.ts +21 -0
- package/dist/src/internal/nitro/host/externals-policy.js +1 -0
- package/dist/src/internal/nitro/host/host-plugins.d.ts +41 -0
- package/dist/src/internal/nitro/host/host-plugins.js +1 -0
- package/dist/src/internal/nitro/host/host-routes.d.ts +90 -0
- package/dist/src/internal/nitro/host/host-routes.js +1 -0
- package/dist/src/internal/nitro/host/host-spec.d.ts +65 -0
- package/dist/src/internal/nitro/host/host-spec.js +1 -0
- package/dist/src/internal/nitro/host/hosted-graph-plugin.d.ts +41 -0
- package/dist/src/internal/nitro/host/hosted-graph-plugin.js +5 -0
- package/dist/src/internal/nitro/host/instrumentation-entry.d.ts +35 -3
- package/dist/src/internal/nitro/host/instrumentation-entry.js +2 -2
- package/dist/src/internal/nitro/host/nitro-bundler-config.d.ts +2 -5
- package/dist/src/internal/nitro/host/nitro-bundler-config.js +1 -1
- package/dist/src/internal/nitro/host/nitro-routing-import-specifier-plugin.d.ts +14 -4
- package/dist/src/internal/nitro/host/nitro-routing-import-specifier-plugin.js +1 -1
- package/dist/src/internal/nitro/host/ports.d.ts +10 -0
- package/dist/src/internal/nitro/host/ports.js +1 -1
- package/dist/src/internal/nitro/host/route-handlers.d.ts +62 -0
- package/dist/src/internal/nitro/host/route-handlers.js +9 -0
- package/dist/src/internal/nitro/host/skill-files-plugin.d.ts +21 -0
- package/dist/src/internal/nitro/host/skill-files-plugin.js +2 -0
- package/dist/src/internal/nitro/host/start-development-server.js +2 -2
- package/dist/src/internal/nitro/host/start-production-server.js +1 -1
- package/dist/src/internal/nitro/host/vercel-build-output-config.d.ts +16 -19
- package/dist/src/internal/nitro/host/vercel-build-output-config.js +1 -1
- package/dist/src/internal/nitro/host/vercel-output.d.ts +15 -0
- package/dist/src/internal/nitro/host/vercel-output.js +1 -0
- package/dist/src/internal/nitro/host/workspace-extensions.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.d.ts +4 -3
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/connection-events.js +1 -1
- package/dist/src/internal/nitro/routes/dev-schedule-dispatch.d.ts +1 -1
- package/dist/src/internal/nitro/routes/method-guard.d.ts +6 -0
- package/dist/src/internal/nitro/routes/method-guard.js +1 -0
- package/dist/src/internal/nitro/routes/schedule-collection-consumer.js +1 -1
- package/dist/src/internal/workflow-bundle/builder-support.d.ts +0 -9
- package/dist/src/internal/workflow-bundle/builder.d.ts +9 -5
- package/dist/src/internal/workflow-bundle/builder.js +2 -2
- package/dist/src/internal/workflow-bundle/flow-route.d.ts +2 -0
- package/dist/src/internal/workflow-bundle/flow-route.js +1 -0
- package/dist/src/internal/workflow-bundle/nitro-step-entry.d.ts +7 -5
- package/dist/src/internal/workflow-bundle/nitro-step-entry.js +2 -2
- package/dist/src/runtime/sessions/runtime-session.d.ts +3 -0
- package/dist/src/runtime/sessions/runtime-session.js +1 -1
- package/dist/src/runtime/subagents/workflow.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/path-inside.d.ts +2 -0
- package/dist/src/shared/path-inside.js +1 -0
- package/dist/src/shared/workflow-sandbox.d.ts +5 -1
- package/dist/src/shared/workflow-sandbox.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/docs/README.md +0 -2
- package/docs/channels/custom.mdx +6 -0
- package/docs/channels/mcp.mdx +1 -1
- package/docs/channels/slack.mdx +34 -58
- package/docs/concepts/meta.json +0 -1
- package/docs/getting-started.mdx +1 -1
- package/docs/guides/deployment/overview.md +2 -0
- package/docs/guides/upgrade/agent-files.md +178 -0
- package/docs/guides/upgrade/channels.md +61 -0
- package/docs/guides/upgrade/clients.md +130 -0
- package/docs/guides/upgrade/evals-and-cli.md +44 -0
- package/docs/guides/upgrade/index.md +90 -0
- package/docs/guides/upgrade/meta.json +13 -0
- package/docs/guides/upgrade/saved-history.md +86 -0
- package/docs/guides/upgrade/session-events.md +139 -0
- package/docs/meta.json +1 -1
- package/docs/reference/typescript-api.md +4 -2
- package/package.json +2 -2
- package/dist/src/internal/application/cache-metadata.d.ts +0 -9
- package/dist/src/internal/application/cache-metadata.js +0 -1
- package/dist/src/internal/nitro/host/application-route-registry.d.ts +0 -54
- package/dist/src/internal/nitro/host/application-route-registry.js +0 -1
- package/dist/src/internal/nitro/host/channel-routes.d.ts +0 -21
- package/dist/src/internal/nitro/host/channel-routes.js +0 -5
- package/dist/src/internal/nitro/host/compiled-sandbox-provider-prune-plugin.d.ts +0 -18
- package/dist/src/internal/nitro/host/compiled-sandbox-provider-prune-plugin.js +0 -3
- package/dist/src/internal/nitro/host/configure-nitro-routes.d.ts +0 -12
- package/dist/src/internal/nitro/host/configure-nitro-routes.js +0 -3
- package/dist/src/internal/nitro/host/create-application-nitro.d.ts +0 -34
- package/dist/src/internal/nitro/host/create-application-nitro.js +0 -1
- package/dist/src/internal/nitro/host/cron-handler-route.d.ts +0 -41
- package/dist/src/internal/nitro/host/cron-handler-route.js +0 -1
- package/dist/src/internal/nitro/host/development-runtime-prune-plugin.d.ts +0 -12
- package/dist/src/internal/nitro/host/development-runtime-prune-plugin.js +0 -3
- package/dist/src/internal/nitro/host/extension-external-dependency-plugin.d.ts +0 -16
- package/dist/src/internal/nitro/host/extension-external-dependency-plugin.js +0 -1
- package/dist/src/internal/nitro/host/external-dependency-output-check-plugin.js +0 -3
- package/dist/src/internal/nitro/host/optional-engine-dependency-plugin.d.ts +0 -28
- package/dist/src/internal/nitro/host/optional-engine-dependency-plugin.js +0 -1
- package/dist/src/internal/nitro/host/schedule-task-routes.d.ts +0 -36
- package/dist/src/internal/nitro/host/schedule-task-routes.js +0 -2
- package/dist/src/internal/nitro/host/skill-server-assets.d.ts +0 -29
- package/dist/src/internal/nitro/host/skill-server-assets.js +0 -1
- package/dist/src/internal/workflow-bundle/build-queue.d.ts +0 -1
- package/dist/src/internal/workflow-bundle/build-queue.js +0 -1
- package/dist/src/internal/workflow-bundle/eve-service-route-output.d.ts +0 -5
- package/dist/src/internal/workflow-bundle/eve-service-route-output.js +0 -1
- package/dist/src/internal/workflow-bundle/vercel-workflow-output.d.ts +0 -34
- package/dist/src/internal/workflow-bundle/vercel-workflow-output.js +0 -1
- package/docs/concepts/upgrade-to-v27-events.md +0 -197
- package/docs/guides/prepare-for-1-0.md +0 -277
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash}from"node:crypto";import{existsSync,readFileSync,readdirSync,rmSync}from"node:fs";import{join,resolve}from"node:path";import{resolveInstalledPackageInfo,resolvePackageRoot,resolvePackageSourceDirectoryPath}from"#internal/application/package.js";import{EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV,EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV}from"#internal/application/build-output-environment.js";import{workflowEntryReference}from"#execution/workflow-runtime.js";function resolveApplicationRoot(e=process.cwd()){return resolve(e)}function getWorkflowBuildCacheKey(e){return createHash(`sha256`).update(e).digest(`hex`).slice(0,12)}function isVercelBuildEnvironment(){return!!process.env.VERCEL}function resolveWorkflowBuildDirectory(e){let t=join(resolvePackageRoot(),`.eve`,`workflow-cache`);return pruneStaleWorkflowCacheSiblings(t),join(t,getWorkflowBuildCacheKey(e))}function pruneStaleWorkflowCacheSiblings(e){if(!existsSync(e))return;let t=resolveInstalledPackageInfo().version,n;try{n=readdirSync(e)}catch{return}for(let r of n){let n=join(e,r),i=join(n,`eve-cache.json`);if(existsSync(i))try{let e=JSON.parse(readFileSync(i,`utf8`));typeof e.eveVersion==`string`&&e.eveVersion!==t&&rmSync(n,{force:!0,recursive:!0})}catch{}}}function resolveSandboxCacheDirectory(e){return join(e,`.eve`,`sandbox-cache`)}function resolveOutputDirectory(e){return isVercelBuildEnvironment()?join(e,`.vercel`,`output`):join(e,`.output`)}function getApplicationInfo(e){return{appRoot:e,outputDir:resolveOutputDirectory(e),workflowId:workflowEntryReference.workflowId,workflowBuildDir:resolveWorkflowBuildDirectory(e),workflowSourceDir:resolvePackageSourceDirectoryPath(`src/execution`)}}export{EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV,EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV,getApplicationInfo,
|
|
1
|
+
import{createHash}from"node:crypto";import{existsSync,readFileSync,readdirSync,rmSync}from"node:fs";import{join,resolve}from"node:path";import{resolveInstalledPackageInfo,resolvePackageRoot,resolvePackageSourceDirectoryPath}from"#internal/application/package.js";import{EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV,EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV}from"#internal/application/build-output-environment.js";import{workflowEntryReference}from"#execution/workflow-runtime.js";function resolveApplicationRoot(e=process.cwd()){return resolve(e)}function getWorkflowBuildCacheKey(e){return createHash(`sha256`).update(e).digest(`hex`).slice(0,12)}function isVercelBuildEnvironment(){return!!process.env.VERCEL}function resolveWorkflowBuildDirectory(e){let t=join(resolvePackageRoot(),`.eve`,`workflow-cache`);return pruneStaleWorkflowCacheSiblings(t),join(t,getWorkflowBuildCacheKey(e))}function pruneStaleWorkflowCacheSiblings(e){if(!existsSync(e))return;let t=resolveInstalledPackageInfo().version,n;try{n=readdirSync(e)}catch{return}for(let r of n){let n=join(e,r),i=join(n,`eve-cache.json`);if(existsSync(i))try{let e=JSON.parse(readFileSync(i,`utf8`));typeof e.eveVersion==`string`&&e.eveVersion!==t&&rmSync(n,{force:!0,recursive:!0})}catch{}}}function resolveSandboxCacheDirectory(e){return join(e,`.eve`,`sandbox-cache`)}function resolveOutputDirectory(e){return isVercelBuildEnvironment()?join(e,`.vercel`,`output`):join(e,`.output`)}function getApplicationInfo(e){return{appRoot:e,outputDir:resolveOutputDirectory(e),workflowId:workflowEntryReference.workflowId,workflowBuildDir:resolveWorkflowBuildDirectory(e),workflowSourceDir:resolvePackageSourceDirectoryPath(`src/execution`)}}export{EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV,EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV,getApplicationInfo,resolveApplicationRoot,resolveOutputDirectory,resolveSandboxCacheDirectory,resolveWorkflowBuildDirectory};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const STAMPED_PACKAGE_VERSION=`0.
|
|
1
|
+
const STAMPED_PACKAGE_VERSION=`1.0.0-rc.0`;function readStampedPackageVersion(){return STAMPED_PACKAGE_VERSION.startsWith(`__`)?void 0:STAMPED_PACKAGE_VERSION}export{readStampedPackageVersion};
|
|
@@ -14,4 +14,21 @@ export declare function createAuthoredAssetImportPlugin(input: {
|
|
|
14
14
|
* installed dependency imports stay with the host bundler.
|
|
15
15
|
*/
|
|
16
16
|
readonly authoredSourceOnly?: boolean;
|
|
17
|
-
}):
|
|
17
|
+
}): {
|
|
18
|
+
name: string;
|
|
19
|
+
resolveId: {
|
|
20
|
+
filter: {
|
|
21
|
+
id: RegExp;
|
|
22
|
+
};
|
|
23
|
+
handler(source: string, importer: string | undefined): string | undefined;
|
|
24
|
+
};
|
|
25
|
+
load: {
|
|
26
|
+
filter: {
|
|
27
|
+
id: RegExp[];
|
|
28
|
+
};
|
|
29
|
+
handler(id: string): Promise<{
|
|
30
|
+
code: string;
|
|
31
|
+
moduleType: "js";
|
|
32
|
+
} | undefined>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile}from"node:fs/promises";import{realpathSync}from"node:fs";import{dirname,extname,isAbsolute,
|
|
1
|
+
import{readFile}from"node:fs/promises";import{realpathSync}from"node:fs";import{dirname,extname,isAbsolute,resolve}from"node:path";import{isPathInsideOrEqual}from"#shared/path-inside.js";import{findAuthoredPackageRoot,isNodeModulesPath}from"#internal/authored-package-boundary.js";const AUTHORED_ASSET_CODE_EXTENSIONS=[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],RESOLVE_FILTER=/^(?:\.|\/|[A-Za-z]:[\\/])/;function createAuthoredAssetImportPlugin(e){let t=toCanonicalPath(e.packageRoot),n=[/\?raw$/,new RegExp(String.raw`\.(?!(?:${AUTHORED_ASSET_CODE_EXTENSIONS.map(e=>e.slice(1)).join(`|`)}|node)(?:[?#]|$))[^./?#]*(?:[?#].*)?$`)],handles=t=>e.authoredSourceOnly!==!0||isAbsolute(t)&&!isNodeModulesPath(t);return{name:`eve-authored-asset-import`,resolveId:{filter:{id:RESOLVE_FILTER},handler(e,n){if(!isPotentialAuthoredAssetImport(e)||n===void 0||!handles(n))return;let{path:r,suffix:i}=splitImportSuffix(e),a=toCanonicalPath(isAbsolute(r)?r:resolve(dirname(n),r)),o=findAuthoredPackageRoot(dirname(toCanonicalPath(n)))??t;if(!isPathInsideOrEqual(a,t)&&!isPathInsideOrEqual(a,o))throw Error(`Authored asset import "${e}" from "${n}" resolves outside package root "${o}".`);return`${a}${i}`}},load:{filter:{id:n},async handler(e){let{path:t,suffix:n}=splitImportSuffix(e);if(!isPotentialAuthoredAssetImport(e)||!handles(t))return;if(n===`?raw`){let e=await readAssetText(t);return e===void 0?void 0:{code:`export default ${JSON.stringify(e)};`,moduleType:`js`}}let r=await readAssetDataUrl(t);if(r!==void 0)return{code:`export default ${JSON.stringify(r)};`,moduleType:`js`}}}}}function toCanonicalPath(e){let t=resolve(e);try{return realpathSync.native(t)}catch{return t}}async function readAssetText(e){try{return await readFile(e,`utf8`)}catch(e){if(isPathNotFoundError(e))return;throw e}}function isPotentialAuthoredAssetImport(e){if(e.startsWith(`\0`)||e.startsWith(`node:`)||e.startsWith(`data:`)||e.startsWith(`file:`))return!1;let{path:t,suffix:n}=splitImportSuffix(e);if(!t.startsWith(`.`)&&!t.startsWith(`/`)&&!/^[A-Za-z]:[\\/]/.test(t))return!1;if(n===`?raw`)return!0;let r=extname(t);return r.length>0&&r!==`.node`&&!AUTHORED_ASSET_CODE_EXTENSIONS.includes(r)}function splitImportSuffix(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?{path:e,suffix:``}:{path:e.slice(0,r),suffix:e.slice(r)}}async function readAssetDataUrl(e){try{let t=await readFile(e);return`data:${getAssetMimeType(e)};base64,${t.toString(`base64`)}`}catch(e){if(isPathNotFoundError(e))return;throw e}}function isPathNotFoundError(e){return typeof e==`object`&&!!e&&`code`in e&&(e.code===`ENOENT`||e.code===`ENOTDIR`)}function getAssetMimeType(e){switch(extname(e).toLowerCase()){case`.css`:return`text/css`;case`.csv`:return`text/csv`;case`.gif`:return`image/gif`;case`.html`:return`text/html`;case`.jpg`:case`.jpeg`:return`image/jpeg`;case`.png`:return`image/png`;case`.svg`:return`image/svg+xml`;case`.txt`:return`text/plain`;case`.wasm`:return`application/wasm`;case`.webp`:return`image/webp`;default:return`application/octet-stream`}}export{createAuthoredAssetImportPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire,isBuiltin}from"node:module";import{existsSync,readFileSync,realpathSync}from"node:fs";import{dirname,join,resolve
|
|
1
|
+
import{createRequire,isBuiltin}from"node:module";import{existsSync,readFileSync,realpathSync}from"node:fs";import{dirname,join,resolve}from"node:path";import{resolvePackageDependencyPath,resolvePackageRoot,resolveWorkflowModulePath}from"#internal/application/package.js";import{fileURLToPath}from"node:url";import{normalizeEsmImportSpecifier}from"#internal/application/import-specifier.js";import{isPathInsideOrEqual}from"#shared/path-inside.js";const 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)||e.extensionSpecifiers?.has(t))return;if(isFrameworkRuntimeImport(t,n))return e.extensionSpecifiers?.has(t)?void 0:{external:!0,id:toExternalModuleId(resolveFrameworkRuntimeImport(t),r.kind)};if(t.startsWith(`#`)){let r=resolvePackageImport(t,n,e.packageRoot);if(r!==void 0)return{id:r}}let i=await resolveConfiguredExternalModule.call(this,{externalDependencies:e.externalDependencies,importer:n,kind:r.kind,packageRoot:e.packageRoot,source:t});if(i!==void 0)return{external:!0,id:e.resolveExternalPaths?toExternalModuleId(normalizeEsmImportSpecifier(i.resolvedId),r.kind):t}}}}function createRuntimeLoaderPackageBoundaryPlugin(e){let t=toCanonicalPath(e.packageRoot);return{name:`eve-runtime-loader-package-boundary`,async resolveId(n,r,i){if(!isPackageImport(n)||e.extensionSpecifiers?.has(n)===!0)return;if(isFrameworkRuntimeImport(n,r))return{external:!0,id:toExternalModuleId(resolveRuntimeLoaderFrameworkImport(n),i.kind)};if(n.startsWith(`#`)){let t=resolvePackageImport(n,r,e.packageRoot);if(t!==void 0)return isFrameworkPackagePath(t)?{external:!0,id:toExternalModuleId(normalizeEsmImportSpecifier(t),i.kind)}:{id:t}}let a=await resolveConfiguredExternalModule.call(this,{externalDependencies:e.externalDependencies,importer:r,kind:i.kind,packageRoot:e.packageRoot,source:n});if(a!==void 0){let e=resolveExistingExternalFilePath(a.resolvedId)??a.resolvedId;return{external:!0,id:toExternalModuleId(normalizeEsmImportSpecifier(e),i.kind)}}let o=r===void 0||r.startsWith(`\0`)?void 0:resolve(r);if(o!==void 0&&isPathInsideOrEqual(toCanonicalPath(o),t)){let e=await this.resolve(n,r,{kind:i.kind,skipSelf:!0});if(e===null||typeof e.id!=`string`)throw Error(`Cannot resolve package "${n}" imported from "${o}". 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}}}}}function createDistributionPackageBoundaryPlugin(e){let t=new Set(e.runtimeDependencies);return{name:`eve-extension-distribution-package-boundary`,async resolveId(n,r,i){if(!isPackageImport(n))return;if(n.startsWith(`#`)){let a=await this.resolve(n,r,{kind:i.kind,skipSelf:!0});if(a!==null&&typeof a.id==`string`&&!isPathInsideOrEqual(toCanonicalPath(a.id),toCanonicalPath(e.packageRoot))){let e=nearestPackageName(a.id);if(e!==void 0&&!t.has(e))throw Error(`Package import "${n}" resolves to undeclared package "${e}". Add "${e}" to dependencies, optionalDependencies, or peerDependencies.`)}return}if(isBuiltin(n))return{external:!0,id:n};let a=packageImportName(n);if(!t.has(a))throw Error(`Package "${n}" is not declared by the extension. Add "${a}" to dependencies, optionalDependencies, or peerDependencies.`);let o=await this.resolve(n,r,{kind:i.kind,skipSelf:!0});if(o===null&&(o=await this.resolve(n,join(e.packageRoot,`package.json`),{kind:i.kind,skipSelf:!0})),o===null||typeof o.id!=`string`)throw Error(`Cannot resolve declared package "${n}". Install the extension's dependencies before building.`);return{external:!0,id:n}}}}async function resolveConfiguredExternalModule(e){let t=resolveConfiguredExternalDependency(e.source,e.externalDependencies);if(t===void 0)return;let n=await this.resolve(e.source,e.importer,{kind:e.kind,skipSelf:!0});if(n===null&&(n=await this.resolve(e.source,join(e.packageRoot,`package.json`),{kind:e.kind,skipSelf:!0})),n===null||typeof n.id!=`string`)throw Error(`Cannot resolve external package "${e.source}".`);return{packageName:t,resolvedId:n.id}}function normalizeExternalDependencies(e=[]){return[...new Set(e)].sort()}function resolveConfiguredExternalDependency(e,t){return t.find(t=>e===t||e.startsWith(`${t}/`))}function packageImportName(e){return e.startsWith(`@`)?e.split(`/`,2).join(`/`):e.split(`/`,1)[0]}function nearestPackageName(e){let t=nearestPackageRoot(e);if(t!==void 0)try{let e=JSON.parse(readFileSync(join(t,`package.json`),`utf8`));return typeof e.name==`string`&&e.name.length>0?e.name:void 0}catch{return}}function nearestPackageRoot(e){let t=dirname(toCanonicalPath(e));for(;;){if(existsSync(join(t,`package.json`)))return t;let e=dirname(t);if(e===t)return;t=e}}function resolvePackageImport(e,t,n){let r=t===void 0||t.startsWith(`\0`)?n:nearestPackageRoot(t)??n;try{let t=createRequire(join(r,`package.json`)).resolve(e);return isPathInsideOrEqual(toCanonicalPath(t),toCanonicalPath(r))?t:void 0}catch{return}}let canonicalFrameworkPackageRoot;function isFrameworkPackagePath(e){return canonicalFrameworkPackageRoot??=toCanonicalPath(resolvePackageRoot()),nearestPackageRoot(e)===canonicalFrameworkPackageRoot}function toExternalModuleId(e,t){return t===`require-call`&&e.startsWith(`file:`)?fileURLToPath(e):e}function resolveExistingExternalFilePath(e){if(existsSync(e))return e;for(let t of RESOLVE_EXTENSIONS){let n=`${e}${t}`;if(existsSync(n))return n}}function isPackageImport(e){return isPathImport(e)||/^(?:node|data|file):/.test(e)?!1:!e.startsWith(`@/`)}function isPathImport(e){return e.startsWith(`.`)||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)}const SELF_MODIFICATION_MOUNT_SPECIFIERS=new Set([`eve/self-modification`,`eve/extensions/self-modification/local`,`eve/extensions/self-modification/remote`]);function isFrameworkRuntimeImport(e,t){return SELF_MODIFICATION_MOUNT_SPECIFIERS.has(e)?!1:e===`eve`||e.startsWith(`eve/`)?!0:e===`workflow`||e.startsWith(`workflow/`)||e.startsWith(`@workflow/`)?t===void 0||!isNodeModulesPath(t):!1}function resolveFrameworkRuntimeImport(e){return e===`eve`||e.startsWith(`eve/`)?e:normalizeEsmImportSpecifier(resolveWorkflowModulePath(e))}function resolveRuntimeLoaderFrameworkImport(e){return e===`eve`||e.startsWith(`eve/`)?normalizeEsmImportSpecifier(resolvePackageDependencyPath(e)):resolveFrameworkRuntimeImport(e)}function isNodeModulesPath(e){return e.replaceAll(`\\`,`/`).includes(`/node_modules/`)}function resolveAuthoredPackageRoot(e){let t=findAuthoredPackageRoot(dirname(e));if(t===void 0)throw Error(`Failed to resolve the authored package root for "${e}".`);return t}function findAuthoredPackageRoot(e){let t=e;for(;;){if(existsSync(join(t,`package.json`)))return realpathSync(t);let e=dirname(t);if(e===t)return;t=e}}function toCanonicalPath(e){try{return realpathSync(e)}catch{return resolve(e)}}export{RESOLVE_EXTENSIONS,createDistributionPackageBoundaryPlugin,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,findAuthoredPackageRoot,isNodeModulesPath,isPathImport,normalizeExternalDependencies,packageImportName,resolveAuthoredPackageRoot,resolveConfiguredExternalDependency};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile,stat}from"node:fs/promises";import{dirname,join,resolve
|
|
1
|
+
import{readFile,stat}from"node:fs/promises";import{dirname,join,resolve}from"node:path";import{parse}from"#compiled/jsonc-parser/index.js";import{isPathInsideOrEqual}from"#shared/path-inside.js";const NON_PACKAGE_IMPORT_FILTER=/^(?:\.|\/|[A-Za-z]:[\\/]|node:|data:|file:)/,packageTsConfigPathsCache=new Map,nearestPackageRootCache=new Map;function createAuthoredPackageTsConfigPathsPlugin(e){let t=createCachedStatProbe();return{name:`eve-package-tsconfig-paths`,resolveId:{filter:{id:{exclude:NON_PACKAGE_IMPORT_FILTER}},async handler(n,r,i){if(r===void 0||!isPackageImport(n))return;let a=resolve(r);if(isPathInsideOrEqual(a,e.appPackageRoot))return;let o=await resolveNearestPackageRoot(a,t);if(o===void 0||isPathInsideOrEqual(o,e.appPackageRoot))return;let s=await loadPackageTsConfigPaths(o);if(s!==void 0)for(let a of createTsConfigPathCandidates(n,s)){let n=await this.resolve(a,r,{kind:i.kind,skipSelf:!0});if(n!==null)return n;let o=await resolveExistingPath(a,e.extensions,t);if(o!==void 0)return{id:o}}}}}}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(e){let t=await readPackageConfig(e);if(t===void 0)return;let n=[],r=parse(t.source,n,{allowTrailingComma:!0});if(n.length>0||!isObjectRecord(r))return;let i=r.compilerOptions;if(!isObjectRecord(i)||!isObjectRecord(i.paths))return;let a=dirname(t.path),o=typeof i.baseUrl==`string`?resolve(a,i.baseUrl):a,s=Object.entries(i.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(s.length!==0)return{baseDirectory:o,entries:s}}async function readPackageConfig(e){for(let t of[`tsconfig.json`,`jsconfig.json`]){let n=join(e,t);try{return{path:n,source:await readFile(n,`utf8`)}}catch(e){if(!isPathNotFoundError(e))throw e}}}function createTsConfigPathCandidates(e,t){let n=[];for(let r of t.entries){let i=matchTsConfigPathPattern(e,r.pattern);if(i!==void 0)for(let e of r.targets){let r=e.includes(`*`)?e.replaceAll(`*`,i):e;n.push(resolve(t.baseDirectory,r))}}return n}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,t,n){if(await existsAsFile(e,n))return e;for(let r of t){let t=`${e}${r}`;if(await existsAsFile(t,n))return t}for(let r of t){let t=join(e,`index${r}`);if(await existsAsFile(t,n))return t}}async function existsAsFile(e,t){return(await t(e))?.isFile()??!1}function resolveNearestPackageRoot(e,t){let n=dirname(e),r=nearestPackageRootCache.get(n);if(r!==void 0)return r;let i=findNearestPackageRoot(n,t);return nearestPackageRootCache.set(n,i),i}async function findNearestPackageRoot(e,t){let n=e;for(;;){if(await pathExists(join(n,`package.json`),t))return n;let e=dirname(n);if(e===n)return;n=e}}async function pathExists(e,t){return await t(e)!==void 0}function createCachedStatProbe(){let e=new Map;return t=>{let n=e.get(t);if(n!==void 0)return n;let r=stat(t).catch(()=>void 0);return e.set(t,r),r}}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)}export{createAuthoredPackageTsConfigPathsPlugin};
|
|
@@ -14,5 +14,23 @@ interface Mount {
|
|
|
14
14
|
/** Whether `path` is the extension's own code: its source, or a chunk shared by that source. */
|
|
15
15
|
export declare function isExtensionModule(path: string, root: string): boolean;
|
|
16
16
|
/** Isolates extension-owned source modules, but leaves ordinary dependencies shared. */
|
|
17
|
-
export declare function createExtensionMountPlugin(mounts: readonly Mount[], overridePaths?: ReadonlyMap<string, string>):
|
|
17
|
+
export declare function createExtensionMountPlugin(mounts: readonly Mount[], overridePaths?: ReadonlyMap<string, string>): {
|
|
18
|
+
name: string;
|
|
19
|
+
resolveId(this: {
|
|
20
|
+
resolve: (source: string, importer?: string, options?: {
|
|
21
|
+
skipSelf: boolean;
|
|
22
|
+
kind?: "import-statement";
|
|
23
|
+
}) => Promise<{
|
|
24
|
+
id: string;
|
|
25
|
+
external?: boolean;
|
|
26
|
+
} | null>;
|
|
27
|
+
}, source: string, importer?: string): Promise<{
|
|
28
|
+
id: string;
|
|
29
|
+
external?: boolean;
|
|
30
|
+
} | null | undefined>;
|
|
31
|
+
load(id: string): {
|
|
32
|
+
code: string;
|
|
33
|
+
moduleType: string;
|
|
34
|
+
} | undefined;
|
|
35
|
+
} | null;
|
|
18
36
|
export {};
|
|
@@ -9,11 +9,21 @@ interface ExtensionScope {
|
|
|
9
9
|
/** The subset of the rolldown/rollup plugin shape this plugin implements. */
|
|
10
10
|
export interface ExtensionScopeBundlerPlugin {
|
|
11
11
|
readonly name: string;
|
|
12
|
-
resolveId
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
readonly resolveId: {
|
|
13
|
+
readonly filter: {
|
|
14
|
+
readonly id: RegExp;
|
|
15
|
+
};
|
|
16
|
+
handler(source: string, importer: string | undefined): string | undefined;
|
|
17
|
+
};
|
|
18
|
+
readonly load: {
|
|
19
|
+
readonly filter: {
|
|
20
|
+
readonly id: RegExp;
|
|
21
|
+
};
|
|
22
|
+
handler(id: string): {
|
|
23
|
+
code: string;
|
|
24
|
+
moduleType: "js";
|
|
25
|
+
} | undefined;
|
|
26
|
+
};
|
|
17
27
|
}
|
|
18
28
|
/**
|
|
19
29
|
* Path-containment scope plugin for the whole-application bundle (the production
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{realpathSync}from"node:fs";import{resolve}from"node:path";import{isExtensionModule}from"#internal/bundler/extension-mount-plugin.js";const VIRTUAL_PREFIX=`\0eve-ext-scope:`;function canonicalize(e){try{return realpathSync(e)}catch{return resolve(e)}}function importerPath(e){let t=e.indexOf(`?`);return canonicalize(t===-1?e:e.slice(0,t))}function shimSource(e){return[`import { defineMountedState } from "eve/internal/mount-state";`,`export function defineState(name, initial) {`,` return defineMountedState(${JSON.stringify(e)}, name, initial);`,`}`,``].join(`
|
|
2
|
-
`)}function scopeHooks(e,t){return{name:e,resolveId(e,n){if(e!==`eve/context`||n===void 0||n.startsWith(`\0`))return;let r=t(n);if(r!==void 0)return`${VIRTUAL_PREFIX}context:${encodeURIComponent(r)}`},load(e){if(!e.startsWith(VIRTUAL_PREFIX))return;let t=e.slice(15),n=t.indexOf(`:`);return t.slice(0,n)===`context`?{code:shimSource(decodeURIComponent(t.slice(n+1))),moduleType:`js`}:void 0}}}function createExtensionScopePlugin(e){if(e.length===0)return null;let t=e.map(e=>({root:canonicalize(e.sourceRoot),mountId:e.mountId}));return scopeHooks(`eve-extension-scope`,e=>{let n=e.indexOf(`?eve-mount=`);if(n>=0){let r=decodeURIComponent(e.slice(n+11)),i=t.find(e=>e.mountId===r);if(i===void 0)throw Error(`Unknown extension mount "${r}".`);return isExtensionModule(importerPath(e),i.root)?i.mountId:void 0}let r=importerPath(e),i=t.filter(e=>isExtensionModule(r,e.root));if(i.length!==0){if(i.length>1)throw Error(`Ambiguous extension scope for "${r}".`);return i[0].mountId}})}function createFixedMountScopePlugin(e){return scopeHooks(`eve-extension-scope-fixed`,()=>e)}export{createExtensionScopePlugin,createFixedMountScopePlugin};
|
|
1
|
+
import{realpathSync}from"node:fs";import{resolve}from"node:path";import{isExtensionModule}from"#internal/bundler/extension-mount-plugin.js";import{exactRegex,prefixRegex}from"#internal/bundler/filters.js";const VIRTUAL_PREFIX=`\0eve-ext-scope:`;function canonicalize(e){try{return realpathSync(e)}catch{return resolve(e)}}function importerPath(e){let t=e.indexOf(`?`);return canonicalize(t===-1?e:e.slice(0,t))}function shimSource(e){return[`import { defineMountedState } from "eve/internal/mount-state";`,`export function defineState(name, initial) {`,` return defineMountedState(${JSON.stringify(e)}, name, initial);`,`}`,``].join(`
|
|
2
|
+
`)}function scopeHooks(e,t){return{name:e,resolveId:{filter:{id:exactRegex(`eve/context`)},handler(e,n){if(e!==`eve/context`||n===void 0||n.startsWith(`\0`))return;let r=t(n);if(r!==void 0)return`${VIRTUAL_PREFIX}context:${encodeURIComponent(r)}`}},load:{filter:{id:prefixRegex(VIRTUAL_PREFIX)},handler(e){if(!e.startsWith(VIRTUAL_PREFIX))return;let t=e.slice(15),n=t.indexOf(`:`);return t.slice(0,n)===`context`?{code:shimSource(decodeURIComponent(t.slice(n+1))),moduleType:`js`}:void 0}}}}function createExtensionScopePlugin(e){if(e.length===0)return null;let t=e.map(e=>({root:canonicalize(e.sourceRoot),mountId:e.mountId}));return scopeHooks(`eve-extension-scope`,e=>{let n=e.indexOf(`?eve-mount=`);if(n>=0){let r=decodeURIComponent(e.slice(n+11)),i=t.find(e=>e.mountId===r);if(i===void 0)throw Error(`Unknown extension mount "${r}".`);return isExtensionModule(importerPath(e),i.root)?i.mountId:void 0}let r=importerPath(e),i=t.filter(e=>isExtensionModule(r,e.root));if(i.length!==0){if(i.length>1)throw Error(`Ambiguous extension scope for "${r}".`);return i[0].mountId}})}function createFixedMountScopePlugin(e){return scopeHooks(`eve-extension-scope-fixed`,()=>e)}export{createExtensionScopePlugin,createFixedMountScopePlugin};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function exactRegex(value: string, flags?: string): RegExp;
|
|
2
|
+
export declare function prefixRegex(value: string, flags?: string): RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Matches any of `paths` as a module id, ignoring a query or hash suffix.
|
|
5
|
+
* Windows paths compare case-insensitively, as the filesystem does.
|
|
6
|
+
*/
|
|
7
|
+
export declare function pathsRegex(paths: readonly string[], platform?: NodeJS.Platform): RegExp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const ESCAPE_REGEX_RE=/[-/\\^$*+?.()|[\]{}]/g;function escapeRegex(e){return e.replace(ESCAPE_REGEX_RE,`\\$&`)}function exactRegex(e,t){return RegExp(`^${escapeRegex(e)}$`,t)}function prefixRegex(e,t){return RegExp(`^${escapeRegex(e)}`,t)}function pathsRegex(e,t=process.platform){let n=e.map(e=>escapeRegex(e.replaceAll(`\\`,`/`)));return RegExp(`^(?:${n.join(`|`)})(?:[?#].*)?$`,t===`win32`?`i`:void 0)}export{exactRegex,pathsRegex,prefixRegex};
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/** Must run before any plugin that externalizes or resolves package imports. */
|
|
2
2
|
export declare function createPseudoPackagePlugin(): {
|
|
3
3
|
name: string;
|
|
4
|
-
resolveId
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
resolveId: {
|
|
5
|
+
filter: {
|
|
6
|
+
id: RegExp[];
|
|
7
|
+
};
|
|
8
|
+
handler: (source: string) => {
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
load: {
|
|
13
|
+
filter: {
|
|
14
|
+
id: RegExp;
|
|
15
|
+
};
|
|
16
|
+
handler: () => {
|
|
17
|
+
code: string;
|
|
18
|
+
moduleType: "js";
|
|
19
|
+
};
|
|
20
|
+
};
|
|
11
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const PSEUDO_PACKAGES=new Set([`server-only`,`client-only`,`next/dist/compiled/server-only`,`next/dist/compiled/client-only`]),PSEUDO_PACKAGE_ID_PREFIX=`\0eve-pseudo-package:`;function createPseudoPackagePlugin(){return{name:`eve-pseudo-packages`,resolveId
|
|
1
|
+
import{exactRegex,prefixRegex}from"#internal/bundler/filters.js";const PSEUDO_PACKAGES=new Set([`server-only`,`client-only`,`next/dist/compiled/server-only`,`next/dist/compiled/client-only`]),PSEUDO_PACKAGE_ID_PREFIX=`\0eve-pseudo-package:`;function createPseudoPackagePlugin(){return{name:`eve-pseudo-packages`,resolveId:{filter:{id:[...PSEUDO_PACKAGES].map(e=>exactRegex(e))},handler:e=>({id:`${PSEUDO_PACKAGE_ID_PREFIX}${e}`})},load:{filter:{id:prefixRegex(PSEUDO_PACKAGE_ID_PREFIX)},handler:()=>({code:``,moduleType:`js`})}}}export{createPseudoPackagePlugin};
|
|
@@ -4,4 +4,4 @@ export type BundlerDefaultLogHandler = (level: string, log: unknown) => void;
|
|
|
4
4
|
* dependency code (`node_modules` or eve's compiled vendor modules), which the
|
|
5
5
|
* user cannot act on, and forwards everything else.
|
|
6
6
|
*/
|
|
7
|
-
export declare function onVendoredDependencyLog(level:
|
|
7
|
+
export declare function onVendoredDependencyLog<Level extends string, Log>(level: Level, log: Log, defaultHandler: (level: Level, log: Log) => void): void;
|
|
@@ -6,7 +6,6 @@ export declare function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(input:
|
|
|
6
6
|
readonly activeSnapshotRoot: string | undefined;
|
|
7
7
|
readonly gracePeriodMs?: number;
|
|
8
8
|
readonly now?: number;
|
|
9
|
-
readonly protectAll: boolean;
|
|
10
9
|
readonly retainCount?: number;
|
|
11
10
|
readonly snapshotsDirectory: string;
|
|
12
11
|
}): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile,readdir,rm,stat,writeFile}from"node:fs/promises";import{existsSync}from"node:fs";import{join,resolve}from"node:path";const DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER=`activated`,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA=`retired.json`;async function recordRetiredDevelopmentRuntimeArtifactsSnapshot(e,t=Date.now()){await writeFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`${JSON.stringify({retiredAt:t})}\n`)}async function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(e){
|
|
1
|
+
import{readFile,readdir,rm,stat,writeFile}from"node:fs/promises";import{existsSync}from"node:fs";import{join,resolve}from"node:path";const DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER=`activated`,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA=`retired.json`;async function recordRetiredDevelopmentRuntimeArtifactsSnapshot(e,t=Date.now()){await writeFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`${JSON.stringify({retiredAt:t})}\n`)}async function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(e){let t=e.now??Date.now(),n=Math.max(0,e.gracePeriodMs??18e5),r=Math.max(0,Math.trunc(e.retainCount??5)),i;try{i=await readdir(e.snapshotsDirectory,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return!1;throw e}let a=e.activeSnapshotRoot===void 0?void 0:resolve(e.activeSnapshotRoot),o=await Promise.all(i.filter(e=>e.isDirectory()).map(async n=>{let r=join(e.snapshotsDirectory,n.name),i=a===resolve(r),o=existsSync(join(r,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER)),s;if(o&&!i)try{s=await readRetiredAt(r),s===void 0&&(await recordRetiredDevelopmentRuntimeArtifactsSnapshot(r,t),s=t)}catch(e){console.warn(`[eve:dev] failed to read or initialize runtime generation retirement metadata for "${r}": ${String(e)}`)}return{activated:o,active:i,path:r,retiredAt:s,mtimeMs:(await stat(r)).mtimeMs}})),s=new Set(o.flatMap(e=>e.retiredAt===void 0?[]:[{path:e.path,retiredAt:e.retiredAt}]).sort((e,t)=>t.retiredAt-e.retiredAt).slice(0,r).map(e=>e.path)),c=new Set(o.filter(e=>!e.activated).sort((e,t)=>t.mtimeMs-e.mtimeMs).slice(0,r).map(e=>e.path));return(await Promise.all(o.map(async e=>e.active||e.activated&&e.retiredAt===void 0||s.has(e.path)||c.has(e.path)||e.retiredAt!==void 0&&t-e.retiredAt<=n||!e.activated&&t-e.mtimeMs<=n?!1:(await rm(e.path,{force:!0,recursive:!0}),!0)))).some(Boolean)}async function readRetiredAt(e){let t;try{t=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 n;try{n=JSON.parse(t)}catch{return}if(typeof n==`object`&&n&&!Array.isArray(n)&&`retiredAt`in n&&typeof n.retiredAt==`number`&&Number.isFinite(n.retiredAt)&&n.retiredAt>=0)return n.retiredAt}export{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot};
|
|
@@ -13,10 +13,6 @@ export interface ActiveDevelopmentRuntimeArtifactsSnapshot {
|
|
|
13
13
|
readonly runtimeAppRoot: string;
|
|
14
14
|
readonly snapshotRoot: string;
|
|
15
15
|
}
|
|
16
|
-
export interface DevelopmentRuntimeArtifactsActivation {
|
|
17
|
-
commit(): void;
|
|
18
|
-
rollback(): Promise<void>;
|
|
19
|
-
}
|
|
20
16
|
/**
|
|
21
17
|
* Resolves the dev-server pointer that records the latest runtime artifact
|
|
22
18
|
* snapshot for new sessions.
|
|
@@ -29,10 +25,10 @@ export declare function stageDevelopmentRuntimeArtifactsSnapshot(compileResult:
|
|
|
29
25
|
/**
|
|
30
26
|
* Moves the dev runtime pointer so future sessions use a staged snapshot.
|
|
31
27
|
*/
|
|
32
|
-
export declare function
|
|
28
|
+
export declare function activateDevelopmentRuntimeArtifactsSnapshot(input: {
|
|
33
29
|
readonly appRoot: string;
|
|
34
30
|
readonly snapshot: DevelopmentRuntimeArtifactsSnapshot;
|
|
35
|
-
}): Promise<
|
|
31
|
+
}): Promise<void>;
|
|
36
32
|
/**
|
|
37
33
|
* Reads the latest dev runtime snapshot root when the dev server has one.
|
|
38
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID}from"node:crypto";import{cp,mkdir,readFile,rm,symlink,writeFile}from"node:fs/promises";import{resolveDevelopmentStateDirectory}from"#internal/application/dev-environment.js";import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{resolvePackageRoot}from"#internal/application/package.js";import{readMaterializedAuthoredModuleIndex}from"#internal/materialized-authored-modules.js";import{renameWithTransientBusyRetry}from"#shared/rename-with-retry.js";import{copyDevelopmentSourceSnapshot}from"#internal/nitro/dev-runtime-source-snapshot-copy.js";import{resolveExtensionExternalDependencyPaths}from"#internal/nitro/host/extension-external-dependency-plugin.js";import{createDevelopmentSourceSnapshotPlan,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";import{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts-retention.js";import{resolveDevelopmentRuntimeArtifactsSnapshotsDirectory}from"#internal/nitro/dev-runtime-generation-metadata.js";function resolveDevelopmentRuntimeArtifactsPointerPath(e){return join(resolveDevelopmentStateDirectory(e),`dev-runtime`,`current.json`)}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,authoredSourceRoots:collectExtensionMountSourceRoots(e.manifest),snapshotRoot:t});try{await copyDevelopmentSourceSnapshot(n),await mountFrameworkPackage(n.runtimeAppRoot),await mountExtensionExternalDependencies({manifest:e.manifest,runtimeAppRoot:n.runtimeAppRoot}),await cp(e.paths.compileDirectoryPath,join(n.runtimeAppRoot,`.eve`,`compile`),{recursive:!0}),await rewriteSnapshotCompiledManifest({appRoot:e.project.appRoot,extensionPackageRoots:(e.manifest?.subagents??[]).flatMap(e=>e.owner.kind===`extension`?[{sourceRoot:e.agent.appRoot,packageName:e.owner.packageName}]:[]),manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:n.runtimeAppRoot,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}),await validateSnapshotCompiledManifestRoots({manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),snapshotSourceRoot:n.snapshotSourceRoot}),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{sourceWatchPaths:n.watchPaths,runtimeAppRoot:n.runtimeAppRoot,snapshotRoot:t,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}}async function mountFrameworkPackage(e){let t=join(e,`node_modules`,`eve`);await mkdir(dirname(t),{recursive:!0}),await rm(t,{force:!0,recursive:!0}),await symlink(resolvePackageRoot(),t,`junction`)}async function mountExtensionExternalDependencies(e){if(e.manifest===void 0)return;let t=[e.manifest,...(e.manifest.subagents??[]).map(e=>e.agent)].flatMap(e=>e.extensionMounts??[]).filter(e=>(e.externalDependencies??[]).length>0);for(let[n,r]of Object.entries(resolveExtensionExternalDependencyPaths(t))){let t=findPackageRoot(r,n),i=join(e.runtimeAppRoot,`node_modules`,...n.split(`/`));await mkdir(dirname(i),{recursive:!0}),await rm(i,{force:!0,recursive:!0}),await symlink(t,i,`junction`)}}function findPackageRoot(e,t){let n=dirname(e);for(;;){let e=join(n,`package.json`);if(existsSync(e))try{if(JSON.parse(readFileSync(e,`utf8`)).name===t)return n}catch{}let r=dirname(n);if(r===n)throw Error(`Cannot locate package root for extension external dependency "${t}".`);n=r}}async function activateDevelopmentRuntimeArtifactsSnapshotTransaction(e){let t=await readMaterializedAuthoredModuleIndex(e.snapshot.runtimeAppRoot);if(t===void 0||!existsSync(join(e.snapshot.runtimeAppRoot,`.eve`,`compile`,t.moduleMap)))throw Error(`Cannot activate development runtime generation "${e.snapshot.snapshotRoot}" before its authored modules are materialized.`);let n=join(e.snapshot.snapshotRoot,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER),r=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),i=readDevelopmentRuntimeArtifactsPointer(r),a=await readOptionalFile(r);try{await writeFile(n,``),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:n,pointerPath:r,previousPointerSource:a})}let o=!1;return{commit(){o=!0},async rollback(){if(o)return;o=!0;let e=await restoreDevelopmentRuntimeArtifactsActivation({markerPath:n,pointerPath:r,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));return 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 collectExtensionMountSourceRoots(e){return e===void 0?[]:[e,...(e.subagents??[]).map(e=>e.agent)].flatMap(e=>(e.extensionMounts??[]).map(e=>e.sourceRoot))}function readDevelopmentRuntimeArtifactsPointer(e){if(e!==void 0&&existsSync(e))try{let t=JSON.parse(readFileSync(e,`utf8`));return t.kind!==`eve-dev-runtime-artifacts-pointer`||typeof t.version!=`number`?void 0:t.version===1&&typeof t.appRoot==`string`&&t.appRoot.length>0?{appRoot:t.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,version:1}:t.version===2&&typeof t.appRoot==`string`&&typeof t.runtimeAppRoot==`string`&&t.runtimeAppRoot.length>0&&typeof t.snapshotRoot==`string`&&t.snapshotRoot.length>0?{appRoot:t.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:t.runtimeAppRoot,snapshotRoot:t.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,extensionPackageRoots:e.extensionPackageRoots,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,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]=isPathInsideOrEqual(r,e.appRoot)||e.extensionPackageRoots.some(e=>isPathInsideOrEqual(r,e.sourceRoot))?rewritePathWithinAppRoot({appRoot:e.appRoot,extensionPackageRoots:e.extensionPackageRoots,path:r,runtimeAppRoot:e.runtimeAppRoot}):rewritePathWithinSourceRoot({path:r,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot});continue}if(typeof r==`string`&&n===`sourceRoot`){t[n]=rewritePathWithinSourceRoot({path:r,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot});continue}t[n]=rewriteManifestRoots({appRoot:e.appRoot,extensionPackageRoots:e.extensionPackageRoots,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:r})}return t}function rewritePathWithinSourceRoot(e){return isPathInsideOrEqual(e.path,e.sourceRoot)?toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:e.path,sourceRoot:e.sourceRoot}):e.path}function rewritePathWithinAppRoot(e){if(!isPathInsideOrEqual(e.path,e.appRoot)){let t=e.extensionPackageRoots.find(t=>isPathInsideOrEqual(e.path,t.sourceRoot));return t===void 0?e.path:join(e.runtimeAppRoot,`node_modules`,t.packageName,relative(t.sourceRoot,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 n=`${e}.${randomUUID()}.tmp`;await mkdir(dirname(e),{recursive:!0}),await writeFile(n,t);try{await renameWithTransientBusyRetry(n,e)}catch(e){throw await rm(n,{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.snapshotSourceRoot))throw Error(`Development runtime snapshot manifest root "${n}" is outside runtime snapshot source root "${e.snapshotSourceRoot}".`)}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{activateDevelopmentRuntimeArtifactsSnapshotTransaction,pruneDevelopmentRuntimeArtifactsSnapshots,readActiveDevelopmentRuntimeArtifactsSnapshot,readDevelopmentRuntimeArtifactsRevision,readDevelopmentRuntimeArtifactsSnapshotRoot,resolveDevelopmentRuntimeArtifactsPointerPath,stageDevelopmentRuntimeArtifactsSnapshot};
|
|
1
|
+
import{randomUUID}from"node:crypto";import{cp,mkdir,readFile,rm,symlink,writeFile}from"node:fs/promises";import{resolveDevelopmentStateDirectory}from"#internal/application/dev-environment.js";import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve}from"node:path";import{resolvePackageRoot}from"#internal/application/package.js";import{isPathInsideOrEqual}from"#shared/path-inside.js";import{readMaterializedAuthoredModuleIndex}from"#internal/materialized-authored-modules.js";import{renameWithTransientBusyRetry}from"#shared/rename-with-retry.js";import{copyDevelopmentSourceSnapshot}from"#internal/nitro/dev-runtime-source-snapshot-copy.js";import{resolveExtensionExternalDependencyPaths}from"#internal/nitro/host/extension-external-dependencies.js";import{createDevelopmentSourceSnapshotPlan,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";import{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts-retention.js";import{resolveDevelopmentRuntimeArtifactsSnapshotsDirectory}from"#internal/nitro/dev-runtime-generation-metadata.js";function resolveDevelopmentRuntimeArtifactsPointerPath(e){return join(resolveDevelopmentStateDirectory(e),`dev-runtime`,`current.json`)}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,authoredSourceRoots:collectExtensionMountSourceRoots(e.manifest),snapshotRoot:t});try{await copyDevelopmentSourceSnapshot(n),await mountFrameworkPackage(n.runtimeAppRoot),await mountExtensionExternalDependencies({manifest:e.manifest,runtimeAppRoot:n.runtimeAppRoot}),await cp(e.paths.compileDirectoryPath,join(n.runtimeAppRoot,`.eve`,`compile`),{recursive:!0}),await rewriteSnapshotCompiledManifest({appRoot:e.project.appRoot,extensionPackageRoots:(e.manifest?.subagents??[]).flatMap(e=>e.owner.kind===`extension`?[{sourceRoot:e.agent.appRoot,packageName:e.owner.packageName}]:[]),manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:n.runtimeAppRoot,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}),await validateSnapshotCompiledManifestRoots({manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),snapshotSourceRoot:n.snapshotSourceRoot}),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{sourceWatchPaths:n.watchPaths,runtimeAppRoot:n.runtimeAppRoot,snapshotRoot:t,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}}async function mountFrameworkPackage(e){let t=join(e,`node_modules`,`eve`);await mkdir(dirname(t),{recursive:!0}),await rm(t,{force:!0,recursive:!0}),await symlink(resolvePackageRoot(),t,`junction`)}async function mountExtensionExternalDependencies(e){if(e.manifest===void 0)return;let t=[e.manifest,...(e.manifest.subagents??[]).map(e=>e.agent)].flatMap(e=>e.extensionMounts??[]).filter(e=>(e.externalDependencies??[]).length>0);for(let[n,r]of Object.entries(resolveExtensionExternalDependencyPaths(t))){let t=findPackageRoot(r,n),i=join(e.runtimeAppRoot,`node_modules`,...n.split(`/`));await mkdir(dirname(i),{recursive:!0}),await rm(i,{force:!0,recursive:!0}),await symlink(t,i,`junction`)}}function findPackageRoot(e,t){let n=dirname(e);for(;;){let e=join(n,`package.json`);if(existsSync(e))try{if(JSON.parse(readFileSync(e,`utf8`)).name===t)return n}catch{}let r=dirname(n);if(r===n)throw Error(`Cannot locate package root for extension external dependency "${t}".`);n=r}}async function activateDevelopmentRuntimeArtifactsSnapshot(e){let t=await readMaterializedAuthoredModuleIndex(e.snapshot.runtimeAppRoot);if(t===void 0||!existsSync(join(e.snapshot.runtimeAppRoot,`.eve`,`compile`,t.moduleMap)))throw Error(`Cannot activate development runtime generation "${e.snapshot.snapshotRoot}" before its authored modules are materialized.`);let n=join(e.snapshot.snapshotRoot,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER),r=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),i=readDevelopmentRuntimeArtifactsPointer(r),a=await readOptionalFile(r);try{await writeFile(n,``),await writeDevelopmentRuntimeArtifactsPointer(e),i!==void 0&&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:n,pointerPath:r,previousPointerSource:a})}}function readDevelopmentRuntimeArtifactsSnapshotRoot(e){return readDevelopmentRuntimeArtifactsPointer(e)?.runtimeAppRoot}function readActiveDevelopmentRuntimeArtifactsSnapshot(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e));if(t!==void 0)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));return await pruneDevelopmentRuntimeArtifactsSnapshotDirectory({activeSnapshotRoot:t?.snapshotRoot,gracePeriodMs:e.gracePeriodMs,now:e.now,retainCount:e.retainCount,snapshotsDirectory:resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e.appRoot)})}function collectExtensionMountSourceRoots(e){return e===void 0?[]:[e,...(e.subagents??[]).map(e=>e.agent)].flatMap(e=>(e.extensionMounts??[]).map(e=>e.sourceRoot))}function readDevelopmentRuntimeArtifactsPointer(e){if(e!==void 0&&existsSync(e))try{let t=JSON.parse(readFileSync(e,`utf8`));return t.kind===`eve-dev-runtime-artifacts-pointer`&&t.version===2&&typeof t.appRoot==`string`&&typeof t.runtimeAppRoot==`string`&&t.runtimeAppRoot.length>0&&typeof t.snapshotRoot==`string`&&t.snapshotRoot.length>0?{appRoot:t.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:t.runtimeAppRoot,snapshotRoot:t.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,extensionPackageRoots:e.extensionPackageRoots,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,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]=isPathInsideOrEqual(r,e.appRoot)||e.extensionPackageRoots.some(e=>isPathInsideOrEqual(r,e.sourceRoot))?rewritePathWithinAppRoot({appRoot:e.appRoot,extensionPackageRoots:e.extensionPackageRoots,path:r,runtimeAppRoot:e.runtimeAppRoot}):rewritePathWithinSourceRoot({path:r,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot});continue}if(typeof r==`string`&&n===`sourceRoot`){t[n]=rewritePathWithinSourceRoot({path:r,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot});continue}t[n]=rewriteManifestRoots({appRoot:e.appRoot,extensionPackageRoots:e.extensionPackageRoots,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:r})}return t}function rewritePathWithinSourceRoot(e){return isPathInsideOrEqual(e.path,e.sourceRoot)?toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:e.path,sourceRoot:e.sourceRoot}):e.path}function rewritePathWithinAppRoot(e){if(!isPathInsideOrEqual(e.path,e.appRoot)){let t=e.extensionPackageRoots.find(t=>isPathInsideOrEqual(e.path,t.sourceRoot));return t===void 0?e.path:join(e.runtimeAppRoot,`node_modules`,t.packageName,relative(t.sourceRoot,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 n=`${e}.${randomUUID()}.tmp`;await mkdir(dirname(e),{recursive:!0}),await writeFile(n,t);try{await renameWithTransientBusyRetry(n,e)}catch(e){throw await rm(n,{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.snapshotSourceRoot))throw Error(`Development runtime snapshot manifest root "${n}" is outside runtime snapshot source root "${e.snapshotSourceRoot}".`)}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}export{activateDevelopmentRuntimeArtifactsSnapshot,pruneDevelopmentRuntimeArtifactsSnapshots,readActiveDevelopmentRuntimeArtifactsSnapshot,readDevelopmentRuntimeArtifactsRevision,readDevelopmentRuntimeArtifactsSnapshotRoot,resolveDevelopmentRuntimeArtifactsPointerPath,stageDevelopmentRuntimeArtifactsSnapshot};
|
|
@@ -12,4 +12,3 @@ export declare function resolveLocalTsConfigPathTargetRoots(input: {
|
|
|
12
12
|
export declare function resolveNearestPackageRoot(path: string, sourceRoot: string): Promise<string | undefined>;
|
|
13
13
|
/** Returns whether a path is authored workspace source rather than installed dependency data. */
|
|
14
14
|
export declare function isAuthoredSourcePath(path: string, sourceRoot: string): boolean;
|
|
15
|
-
export declare function isPathInsideOrEqual(path: string, directory: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lstat}from"node:fs/promises";import{existsSync}from"node:fs";import{dirname,join,relative,resolve
|
|
1
|
+
import{lstat}from"node:fs/promises";import{existsSync}from"node:fs";import{dirname,join,relative,resolve}from"node:path";import{isPathInsideOrEqual}from"#shared/path-inside.js";import{parseTsConfigObject,readTextFileIfExists}from"#internal/application/tsconfig-dependencies.js";async function resolveLocalTsConfigPathTargetRoots(e){let t=await readTextFileIfExists(e.configPath);if(t===void 0)return[];let n=parseTsConfigObject(t),r=isObjectRecord(n?.compilerOptions)?n.compilerOptions:void 0,i=isObjectRecord(r?.paths)?r.paths:void 0;if(r===void 0||i===void 0)return[];let a=typeof r.baseUrl==`string`?resolve(dirname(e.configPath),r.baseUrl):dirname(e.configPath),o=new Set;for(let t of Object.values(i))if(Array.isArray(t))for(let n of t){if(typeof n!=`string`||n.length===0)continue;let t=await resolveLocalTsConfigPathTargetRoot({baseDirectory:a,sourceRoot:e.sourceRoot,target:n});t!==void 0&&o.add(t)}return[...o].sort((e,t)=>e.localeCompare(t))}async function resolveNearestPackageRoot(e,t){let n=resolve(e);try{(await lstat(n)).isDirectory()||(n=dirname(n))}catch{n=dirname(n)}for(;isAuthoredSourcePath(n,t);){if(existsSync(join(n,`package.json`)))return n;let e=dirname(n);if(e===n)return;n=e}}function isAuthoredSourcePath(e,t){return isPathInsideOrEqual(e,t)?!relative(t,e).split(/[\\/]/).includes(`node_modules`):!1}async function resolveLocalTsConfigPathTargetRoot(e){let t=e.target.includes(`*`),n=t?e.target.slice(0,e.target.indexOf(`*`)):e.target;if(n.length===0||n===`.`||n===`./`)return;let r=resolve(e.baseDirectory,n);if(!isAuthoredSourcePath(r,e.sourceRoot))return;let i=await resolveExistingPathOrAncestor({path:r,stopDirectory:e.sourceRoot});if(i===void 0)return;let a=await resolveNearestPackageRoot(i,e.sourceRoot);if(a!==void 0&&a!==e.sourceRoot)return a;if(!t)return i===e.sourceRoot?void 0:i}async function resolveExistingPathOrAncestor(e){let t=resolve(e.path);for(;isAuthoredSourcePath(t,e.stopDirectory);){if(existsSync(t))return t;let e=dirname(t);if(e===t)return;t=e}}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{isAuthoredSourcePath,resolveLocalTsConfigPathTargetRoots,resolveNearestPackageRoot};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lstat,readlink,realpath}from"node:fs/promises";import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve}from"node:path";import{readTextFileIfExists,resolveTsConfigDependencyPaths}from"#internal/application/tsconfig-dependencies.js";import{isAuthoredSourcePath,isAuthoredSourcePath as isAuthoredSourcePath$1,
|
|
1
|
+
import{lstat,readlink,realpath}from"node:fs/promises";import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve}from"node:path";import{isPathInsideOrEqual}from"#shared/path-inside.js";import{readTextFileIfExists,resolveTsConfigDependencyPaths}from"#internal/application/tsconfig-dependencies.js";import{isAuthoredSourcePath,isAuthoredSourcePath as isAuthoredSourcePath$1,resolveLocalTsConfigPathTargetRoots,resolveNearestPackageRoot}from"#internal/nitro/dev-runtime-source-snapshot-local-roots.js";const SOURCE_ROOT_MARKER_NAMES=[`.git`,`pnpm-workspace.yaml`],WORKSPACE_METADATA_FILE_NAMES=[`package.json`,`pnpm-workspace.yaml`,`pnpm-lock.yaml`,`package-lock.json`,`yarn.lock`,`bun.lock`,`bun.lockb`,`.npmrc`],PACKAGE_DEPENDENCY_FIELDS=[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`];var DevelopmentRuntimeSourceSnapshotError=class extends Error{constructor(e){super(e),this.name=`DevelopmentRuntimeSourceSnapshotError`}};async function createDevelopmentSourceSnapshotPlan(e){let t=resolve(e.appRoot),n=resolve(e.snapshotRoot),r=resolveDevelopmentSourceRoot(t),i=join(n,`source`),a={appRoot:t,copyFiles:new Set,dependencyMountsByPath:new Map,localRootsToProcess:[t],processedLocalRoots:new Set,snapshotRoot:n,snapshotSourceRoot:i,sourceRoot:r,tsconfigPaths:new Set},o=join(t,`package.json`);for(existsSync(o)&&a.copyFiles.add(o),await addAuthoredSourceRoots(a,e.authoredSourceRoots??[]);a.localRootsToProcess.length>0;){let e=a.localRootsToProcess.shift();if(e===void 0)continue;let t=resolve(e);!a.processedLocalRoots.has(t)&&isAuthoredSourcePath$1(t,r)&&(a.processedLocalRoots.add(t),await addTsConfigDependenciesForRoot(a,t),await addDependencyMountsForRoot(a,t))}let s=[...a.copyFiles].filter(e=>isPathInsideOrEqual(e,r)).sort((e,t)=>e.localeCompare(t)),c=[...a.tsconfigPaths].filter(e=>isPathInsideOrEqual(e,r)).sort((e,t)=>e.localeCompare(t)),l=[...a.dependencyMountsByPath.values()].sort((e,t)=>e.mountPath.localeCompare(t.mountPath)),u=createWatchPaths({appRoot:t,copyFiles:s,dependencyMounts:l,localRoots:[...a.processedLocalRoots],sourceRoot:r,tsconfigPaths:c});return{appRoot:t,copyFiles:s,dependencyMounts:l,runtimeAppRoot:toSnapshotPath({sourcePath:t,sourceRoot:r,snapshotSourceRoot:i}),snapshotRoot:n,snapshotSourceRoot:i,sourceRoot:r,tsconfigPaths:c,watchPaths:u}}async function resolveDevelopmentSourceSnapshotWatchPaths(e){return[...(await createDevelopmentSourceSnapshotPlan({appRoot:e,snapshotRoot:join(resolve(e),`.eve`,`dev-runtime`,`__watch-plan__`)})).watchPaths]}function toDevelopmentSourceSnapshotPath(e){return toSnapshotPath(e)}function resolveDevelopmentSourceRoot(e){let t=resolve(e);for(;;){if(SOURCE_ROOT_MARKER_NAMES.some(e=>existsSync(join(t,e)))||isWorkspaceManifestRoot(t))return t;let n=dirname(t);if(n===t)return resolve(e);t=n}}async function addAuthoredSourceRoots(e,t){for(let n of t){let t=resolve(n);isAuthoredSourcePath$1(t,e.sourceRoot)&&enqueueLocalRoot(e,await resolveNearestPackageRoot(t,e.sourceRoot)??t)}}async function addTsConfigDependenciesForRoot(e,t){let n=await resolveTsConfigDependencyPaths(t);for(let t of n)if(isPathInsideOrEqual(t,e.sourceRoot)){e.tsconfigPaths.add(t);for(let n of await resolveLocalTsConfigPathTargetRoots({configPath:t,sourceRoot:e.sourceRoot}))enqueueLocalRoot(e,n)}}async function addDependencyMountsForRoot(e,t){let n=await readPackageDependencyNames(resolveDependencyDeclarationRoot(t,e.sourceRoot));for(let r of n)for(let n of listAncestorNodeModulesRoots(t,e.sourceRoot))await addDependencyMount(e,joinNodeModulesPackagePath(n,r))}function resolveDependencyDeclarationRoot(e,t){let n=resolve(e),r=resolve(t);for(;isPathInsideOrEqual(n,r);){if(existsSync(join(n,`package.json`)))return n;let e=dirname(n);if(e===n)break;n=e}return e}function listAncestorNodeModulesRoots(e,t){let n=resolve(t),r=new Set,i=resolve(e);for(;isPathInsideOrEqual(i,n);){r.add(i);let e=dirname(i);if(e===i)break;i=e}return r.add(resolve(e)),r.add(n),[...r]}function isWorkspaceManifestRoot(e){let t=join(e,`package.json`);if(!existsSync(t))return!1;try{let e=JSON.parse(readFileSync(t,`utf8`));return isObjectRecord(e)&&e.workspaces!==void 0}catch{return!1}}async function addDependencyMount(e,t){let n;try{n=await lstat(t)}catch{return}if(!n.isDirectory()&&!n.isSymbolicLink())return;let r=await resolveDependencySourcePathCandidates(t),i=r.find(t=>isAuthoredSourcePath$1(t,e.sourceRoot));if(i!==void 0){await addWorkspaceDependencyMount({mountPath:t,state:e,sourcePath:i});return}let a=r.find(e=>existsSync(e));a!==void 0&&e.dependencyMountsByPath.set(resolve(t),{mountPath:resolve(t),sourceKind:`installed`,sourcePath:a})}async function addWorkspaceDependencyMount(e){let t=await resolveNearestPackageRoot(e.sourcePath,e.state.sourceRoot);if(t===void 0||!isAuthoredSourcePath$1(t,e.state.sourceRoot))return;let{state:n}=e;enqueueLocalRoot(n,t),n.dependencyMountsByPath.set(resolve(e.mountPath),{mountPath:resolve(e.mountPath),sourceKind:`workspace`,sourcePath:t})}async function resolveDependencySourcePathCandidates(e){let t=new Set;try{let n=await readlink(e);t.add(resolve(dirname(e),n))}catch{}try{t.add(await realpath(e))}catch{}return[...t]}function enqueueLocalRoot(e,t){let n=resolve(t);e.processedLocalRoots.has(n)||e.localRootsToProcess.includes(n)||!isAuthoredSourcePath$1(n,e.sourceRoot)||e.localRootsToProcess.push(n)}async function readPackageDependencyNames(e){let t=join(e,`package.json`),n=await readTextFileIfExists(t);if(n===void 0)return[];let r;try{r=JSON.parse(n)}catch{return[]}if(!isObjectRecord(r))return[];let i=new Set;for(let e of PACKAGE_DEPENDENCY_FIELDS){let t=r[e];if(isObjectRecord(t))for(let e of Object.keys(t))i.add(e)}return[...i].sort((e,t)=>e.localeCompare(t))}function createWatchPaths(e){let t=new Set([join(e.appRoot,`package.json`),...e.copyFiles,...e.tsconfigPaths]);for(let n of e.localRoots)n!==e.appRoot&&t.add(n);for(let n of e.dependencyMounts)n.sourceKind===`workspace`&&n.sourcePath!==e.appRoot&&t.add(n.sourcePath);if(e.sourceRoot!==e.appRoot)for(let n of WORKSPACE_METADATA_FILE_NAMES){let r=join(e.sourceRoot,n);existsSync(r)&&t.add(r)}return[...t].sort((e,t)=>e.localeCompare(t))}function joinNodeModulesPackagePath(e,t){return join(e,`node_modules`,...t.split(`/`))}function toSnapshotPath(e){if(!isPathInsideOrEqual(e.sourcePath,e.sourceRoot))throw new DevelopmentRuntimeSourceSnapshotError(`Cannot map source path "${e.sourcePath}" into a development runtime snapshot because it is outside source root "${e.sourceRoot}".`);return join(e.snapshotSourceRoot,relative(e.sourceRoot,e.sourcePath))}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{DevelopmentRuntimeSourceSnapshotError,createDevelopmentSourceSnapshotPlan,isAuthoredSourcePath,resolveDevelopmentSourceRoot,resolveDevelopmentSourceSnapshotWatchPaths,toDevelopmentSourceSnapshotPath};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AuthoredWorkflowModules } from "#internal/workflow-bundle/builder-support.js";
|
|
2
2
|
import type { CompileAgentResult } from "#compiler/compile-agent.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type DevelopmentRuntimeArtifactsSnapshot } from "#internal/nitro/dev-runtime-artifacts.js";
|
|
4
4
|
export interface DevelopmentGeneration extends DevelopmentRuntimeArtifactsSnapshot {
|
|
5
5
|
readonly authoredWorkflowModules?: AuthoredWorkflowModules;
|
|
6
6
|
readonly fingerprint: string;
|
|
@@ -8,14 +8,26 @@ export interface DevelopmentGeneration extends DevelopmentRuntimeArtifactsSnapsh
|
|
|
8
8
|
readonly workflowSourceFingerprint?: string;
|
|
9
9
|
}
|
|
10
10
|
export declare function stageDevelopmentGeneration(compileResult: CompileAgentResult): Promise<DevelopmentGeneration>;
|
|
11
|
+
/** Moves the dev runtime pointer so new sessions load `generation`. */
|
|
11
12
|
export declare function activateDevelopmentGeneration(input: {
|
|
12
13
|
readonly appRoot: string;
|
|
13
14
|
readonly generation: DevelopmentGeneration;
|
|
14
|
-
readonly onRuntimePruned?: () => Promise<void>;
|
|
15
15
|
}): Promise<void>;
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function discardDevelopmentGeneration(generation: DevelopmentGeneration): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a serial queue that prunes retired generations in the background.
|
|
19
|
+
* Requests made while a prune runs coalesce into one more pass. When a pass
|
|
20
|
+
* removes snapshots, `onRuntimePruned` reconciles the Workflow runs they
|
|
21
|
+
* owned; a failed reconciliation, or a failed prune that may have removed
|
|
22
|
+
* some, is retried after the next pass even if that pass removes nothing.
|
|
23
|
+
* `close()` drops pending requests and resolves once the running pass ends.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createDevelopmentGenerationPruner(input: {
|
|
17
26
|
readonly appRoot: string;
|
|
18
|
-
readonly generation: DevelopmentGeneration;
|
|
19
27
|
readonly onRuntimePruned?: () => Promise<void>;
|
|
20
|
-
}):
|
|
21
|
-
export
|
|
28
|
+
}): DevelopmentGenerationPruner;
|
|
29
|
+
export interface DevelopmentGenerationPruner {
|
|
30
|
+
/** Requests a pass; ignored once closed. */
|
|
31
|
+
request(): void;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{rm}from"node:fs/promises";import{
|
|
1
|
+
import{rm}from"node:fs/promises";import{isPathInsideOrEqual}from"#shared/path-inside.js";import{prepareAuthoredRuntimeModules}from"#internal/authored-runtime-modules.js";import{writeMaterializedAuthoredModules}from"#internal/materialized-authored-modules.js";import{activateDevelopmentRuntimeArtifactsSnapshot,pruneDevelopmentRuntimeArtifactsSnapshots,stageDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts.js";async function stageDevelopmentGeneration(e){let[t,n]=await Promise.allSettled([prepareAuthoredRuntimeModules({appRoot:e.project.appRoot,manifest:e.manifest,moduleMapPath:e.paths.moduleMapPath}),stageDevelopmentRuntimeArtifactsSnapshot(e)]);if(n.status===`rejected`)throw t.status===`rejected`?AggregateError([t.reason,n.reason],`Failed to stage development generation.`):n.reason;let r=n.value;try{if(t.status===`rejected`)throw t.reason;let n=t.value,i=await writeMaterializedAuthoredModules({prepared:n,runtimeAppRoot:r.runtimeAppRoot}),a={...r,authoredWorkflowModules:n.authoredWorkflowModules,fingerprint:i.fingerprint,sourceWatchPaths:[...r.sourceWatchPaths??[],...n.sourceModules.filter(t=>!isPathInsideOrEqual(t,e.manifest.agentRoot))]};return n.workflowSourceFingerprint===void 0?a:{...a,workflowSourceFingerprint:n.workflowSourceFingerprint}}catch(e){try{await rm(r.snapshotRoot,{force:!0,recursive:!0})}catch(t){throw AggregateError([e,t],`Failed to materialize and discard development generation "${r.snapshotRoot}".`)}throw e}}async function activateDevelopmentGeneration(e){await activateDevelopmentRuntimeArtifactsSnapshot({appRoot:e.appRoot,snapshot:e.generation})}async function discardDevelopmentGeneration(e){await rm(e.snapshotRoot,{force:!0,recursive:!0})}function createDevelopmentGenerationPruner(e){let t=!1,n=!1,r,i=!1,run=async()=>{for(;t&&!n;){t=!1;try{let t=await pruneDevelopmentRuntimeArtifactsSnapshots({appRoot:e.appRoot});i||=t}catch(e){i=!0,console.warn(`[eve:dev] failed to prune runtime generations: ${String(e)}`);continue}if(i&&e.onRuntimePruned!==void 0)try{await e.onRuntimePruned(),i=!1}catch(e){console.warn(`[eve:dev] failed to reconcile expired Workflow runs: ${String(e)}`)}}r=void 0};return{request(){n||(t=!0,r??=run())},async close(){n=!0,await r}}}export{activateDevelopmentGeneration,createDevelopmentGenerationPruner,discardDevelopmentGeneration,stageDevelopmentGeneration};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile}from"node:fs/promises";import{createDiskRuntimeCompiledArtifactsSource}from"#runtime/compiled-artifacts-source.js";import{isObject}from"#shared/guards.js";import{EVE_ROUTE_PREFIX}from"#protocol/routes.js";import{dirname,
|
|
1
|
+
import{readFile}from"node:fs/promises";import{createDiskRuntimeCompiledArtifactsSource}from"#runtime/compiled-artifacts-source.js";import{isObject}from"#shared/guards.js";import{EVE_ROUTE_PREFIX}from"#protocol/routes.js";import{dirname,join,resolve}from"node:path";import{resolveDiscoveryProject}from"#discover/project.js";import{resolveInstalledPackageInfo,resolvePackageSourceFilePath}from"#internal/application/package.js";import{normalizePublicRoutePrefix}from"#shared/public-route-prefix.js";import{tryReadExtensionBuildConfig}from"#internal/nitro/host/build-extension.js";import{toErrorMessage}from"#shared/errors.js";import{isPathInsideOrEqual}from"#shared/path-inside.js";import{build,copyPublicAssets,prepare,prerender}from"nitro/builder";import{createApplicationBuildWorkspace,removeApplicationBuildWorkspace}from"#internal/application/build-workspace.js";import{ApplicationBuildProfiler,createApplicationBuildProfile,measureApplicationBuildOutput,writeApplicationBuildProfile}from"#internal/application/build-profile.js";import{RecoverablePublicationError,publishApplicationBuildArtifacts}from"#internal/application/output-publication.js";import{stageProductionCompilerArtifacts}from"#internal/application/production-compiler-artifacts.js";import{stageBuildDeploymentId}from"#internal/nitro/host/stage-build-deployment-id.js";import{createHostNitro}from"#internal/nitro/host/create-host-nitro.js";import{createHostSpec}from"#internal/nitro/host/host-spec.js";import{normalizeVercelServiceOutput}from"#internal/nitro/host/vercel-output.js";import{emitVercelAgentSummary}from"#internal/nitro/host/build-vercel-agent-summary.js";import{emitConnectManifest}from"#internal/external-resources.js";import{copyHostMiddlewareFunctions}from"#internal/nitro/host/copy-host-middleware.js";import{normalizeVercelServiceCrons}from"#internal/nitro/host/normalize-vercel-service-crons.js";import{prepareProductionApplicationHost,refreshProductionCompiledArtifacts}from"#internal/nitro/host/prepare-application-host.js";import{createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{runVercelBuildPrewarm}from"#internal/nitro/host/vercel-build-prewarm.js";import{prewarmAppSandboxes}from"#execution/sandbox/prewarm.js";import{findClosestVercelOutputDirectory}from"#shared/vercel-output-directory.js";import{resolveEveServicePrefixByRoot}from"#internal/vercel/vercel-service-config-operations.js";import{parseVercelServicesConfig}from"#internal/vercel/vercel-services-config.js";function trimTrailingSlash(e){return e.replace(/[\\/]+$/,``)}async function measureBuildPhase(e,t,n){return e===void 0?n():e.measure(t,n)}function assertProfileOutputOutsideBuildOutput(e,t){if(e!==void 0&&isPathInsideOrEqual(e,t))throw Error(`Build profile path ${e} must be outside the published output directory ${t}.`)}async function writeOptionalApplicationBuildProfile(e){try{assertProfileOutputOutsideBuildOutput(e.profileOutputPath,e.outputDirectory);let t=e.profiler.finish(),n=await measureApplicationBuildOutput(e.outputDirectory);await writeApplicationBuildProfile(e.profileOutputPath,createApplicationBuildProfile({deploymentId:e.deploymentId,output:n,target:process.env.VERCEL?`vercel`:`local`,timing:t}))}catch(t){console.warn(`eve: failed to write optional build profile to ${e.profileOutputPath}; continuing with the published build output: ${toErrorMessage(t)}`)}}async function resolveEveServicePrefixForVercelFunctionOutput(e,t){let n=Array.from(new Set([resolve(e),resolve(t)])),r=await findClosestVercelOutputDirectory(e);if(r!==void 0)try{let e=join(r,`config.json`),t=parseVercelServicesConfig(JSON.parse(await readFile(e,`utf8`)),e),i=resolveEveServicePrefixByRoot({appRoots:n,configRoot:await resolveVercelOutputConfigRoot(r),config:t});if(i!==void 0)return i}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let i=e;for(;;){for(let e of[join(i,`vercel.json`),join(i,`.vercel`,`output`,`config.json`)])try{let t=parseVercelServicesConfig(JSON.parse(await readFile(e,`utf8`)),e),r=e.endsWith(`vercel.json`)?i:await resolveVercelOutputConfigRoot(dirname(e)),a=resolveEveServicePrefixByRoot({appRoots:n,configRoot:r,config:t});if(a!==void 0)return a}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let e=dirname(i);if(e===i)return;i=e}}async function resolveVercelOutputConfigRoot(e){let t=dirname(dirname(e));try{let e=JSON.parse(await readFile(join(t,`.vercel`,`project.json`),`utf8`));if(isObject(e)&&isObject(e.settings)){let n=e.settings.rootDirectory;if(typeof n==`string`&&n.trim().length>0)return resolve(t,n)}}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}return t}async function buildNitroOutput(e,t,n){let r=trimTrailingSlash(e.options.output.dir);return await measureBuildPhase(t,`${n}.prepare`,()=>prepare(e)),await measureBuildPhase(t,`${n}.public-assets`,()=>copyPublicAssets(e)),await measureBuildPhase(t,`${n}.prerender`,()=>prerender(e)),await measureBuildPhase(t,`${n}.bundle`,()=>build(e)),r}async function buildApplication(e,t){let n=t.profileOutputPath===void 0?void 0:resolve(t.profileOutputPath),r=n===void 0?void 0:new ApplicationBuildProfiler,i=await measureBuildPhase(r,`extension.check`,()=>tryReadExtensionBuildConfig(e));if(i!==null)throw Error(`Package "${i.packageName}" is an eve extension. Run \`eve extension build\` instead of \`eve build\`.`);let a=await measureBuildPhase(r,`project.resolve`,()=>resolveDiscoveryProject(e)),o=await measureBuildPhase(r,`workspace.create`,()=>createApplicationBuildWorkspace(a.appRoot,t.vercelServiceOutput?.serviceOutputDirectory)),s=!1,c;try{c=await buildApplicationInWorkspace(o,t,r)}catch(e){throw s=e instanceof RecoverablePublicationError,e}finally{s||await measureBuildPhase(r,`workspace.remove`,()=>removeApplicationBuildWorkspace(o))}return r!==void 0&&n!==void 0&&await writeOptionalApplicationBuildProfile({deploymentId:c.deploymentId,outputDirectory:c.outputDirectory,profileOutputPath:n,profiler:r}),c.outputDirectory}async function buildApplicationInWorkspace(e,t,n){let r=await measureBuildPhase(n,`host.prepare`,()=>prepareProductionApplicationHost(e)),i=!!process.env.VERCEL,a=i?await measureBuildPhase(n,`vercel.service-prefix.resolve`,()=>resolveEveServicePrefixForVercelFunctionOutput(r.appRoot,r.compileResult.project.agentRoot)):void 0,o=normalizePublicRoutePrefix(a),s=o===EVE_ROUTE_PREFIX?void 0:o;if(t.publicRoutePrefix!==void 0&&s!==void 0&&t.publicRoutePrefix!==s)throw Error(`EVE_PUBLIC_ROUTE_PREFIX ${JSON.stringify(t.publicRoutePrefix)} conflicts with the configured Vercel service prefix ${JSON.stringify(a)}.`);let c=t.publicRoutePrefix??s,l=createProductionNitroArtifactsConfig(e.appRoot).sandboxScope,u=createHostSpec(r,{kind:`production`,preset:i?`vercel`:void 0,publicRoutePrefix:c,workspaceMember:t.workspaceMember},{buildDir:e.nitro.buildDir,outputDir:e.publication.output.stagedDir}),d=await measureBuildPhase(n,`nitro.create`,()=>createHostNitro(u));try{if(!t.skipSandboxPrewarm){let t={appRoot:r.appRoot,compiledArtifactsSource:createDiskRuntimeCompiledArtifactsSource(e.compiler.rootDir,{moduleMapLoaderPath:resolvePackageSourceFilePath(`src/internal/authored-module-map-loader.ts`),sandboxAppRoot:r.appRoot,sandboxScope:l}),log(e){console.log(e)}};await measureBuildPhase(n,`sandbox.prewarm`,async()=>{i?await runVercelBuildPrewarm(t):await prewarmAppSandboxes(t)}),await refreshProductionCompiledArtifacts(r,e.host.artifactsDir)}await buildNitroOutput(d,n,`nitro`),a!==void 0&&await measureBuildPhase(n,`vercel.functions.normalize`,()=>normalizeVercelServiceOutput(e.publication.output.stagedDir,u.routes));let o=t.vercelServiceOutput;o!==void 0&&(await measureBuildPhase(n,`vercel.service-crons.normalize`,()=>normalizeVercelServiceCrons({publicRoutePrefix:c,serviceOutputDirectory:e.publication.output.stagedDir})),await measureBuildPhase(n,`vercel.host-middleware.copy`,()=>copyHostMiddlewareFunctions({hostOutputDirectory:o.hostOutputDirectory,serviceOutputDirectory:e.publication.output.stagedDir}))),await measureBuildPhase(n,`agent-summary.emit`,()=>emitVercelAgentSummary({manifest:r.compileResult.manifest,outputPath:e.publication.summary.stagedPath})),await measureBuildPhase(n,`connect-manifest.emit`,()=>emitConnectManifest({appRoot:r.appRoot,generatorVersion:resolveInstalledPackageInfo().version,manifest:r.compileResult.manifest,outputDirectory:e.publication.output.stagedDir,publicRoutePrefix:c})),i||await measureBuildPhase(n,`compiler-artifacts.stage`,()=>stageProductionCompilerArtifacts({compilerArtifactsRoot:e.compiler.artifactsDir,outputDir:e.publication.output.stagedDir}))}finally{await measureBuildPhase(n,`nitro.close`,()=>d.close())}let f=d.options.preset===`node-server`?await measureBuildPhase(n,`id.compute`,()=>stageBuildDeploymentId(e.publication.output.stagedDir)):void 0;return await measureBuildPhase(n,`output.publish`,()=>publishCompletedApplicationBuild(e)),{deploymentId:f,outputDirectory:e.publication.output.finalDir}}async function publishCompletedApplicationBuild(e){await publishApplicationBuildArtifacts({appRoot:e.appRoot,finalOutputDir:e.publication.output.finalDir,finalSummaryPath:e.publication.summary.finalPath,scratchDir:e.rootDir,stagedOutputDir:e.publication.output.stagedDir,stagedSummaryPath:e.publication.summary.stagedPath})}export{buildApplication};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Nitro } from "nitro/types";
|
|
2
|
+
import type { HostSpec } from "#internal/nitro/host/host-spec.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates eve's Nitro host: one isolated candidate for `eve dev`, or one
|
|
5
|
+
* production build. The returned Nitro is configured entirely by its config.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createHostNitro(spec: HostSpec): Promise<Nitro>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{join}from"node:path";import{WORKFLOW_MODULE_SPECIFIERS,resolvePackageRoot,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{createNitro}from"nitro/builder";import{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{createHostNoExternals}from"#internal/nitro/host/externals-policy.js";import{createHostPlugins}from"#internal/nitro/host/host-plugins.js";import{renderHostRoutes}from"#internal/nitro/host/host-routes.js";import{createInstrumentationEntry}from"#internal/nitro/host/instrumentation-entry.js";import{onNitroBundlerLog}from"#internal/nitro/host/nitro-bundler-config.js";import{SKILL_FILES_PLUGIN_ID,writeSkillFilesPlugin}from"#internal/nitro/host/skill-files-plugin.js";import{WorkflowBundleBuilder}from"#internal/workflow-bundle/builder.js";const INSTRUMENTATION_ALIAS_PATHS={"eve/instrumentation":`src/public/instrumentation/index.ts`,"eve/instrumentation/otel":`src/public/instrumentation/otel.ts`};function createNitroLoadOptions(e){return{c12:{configFile:join(e,`nitro.config`),packageJson:!1,rcFile:!1},dotenv:!1}}async function createHostNitro(e){let{locations:t}=e,n=await new WorkflowBundleBuilder({agentName:e.agentName,appRoot:t.appRoot,authoredWorkflowModules:t.compiledArtifacts.authoredWorkflowModules,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot()}).build(),r=e.runtimePlugins.includes(`skill-files`)?await writeSkillFilesPlugin({skills:e.skills,skillsRoot:t.skillsRoot,stagingDirectory:join(t.buildDir,`eve-skill-files`)}):void 0,i=await renderHostRoutes(e.routes,{artifactsConfig:e.development?createDevelopmentNitroArtifactsConfig({appRoot:t.appRoot,configuredWorld:e.world}):createProductionNitroArtifactsConfig(t.appRoot),artifactsConfigPath:join(t.buildDir,`eve-route-config.json`),workflowArtifacts:n,workflowWorldPluginPath:t.compiledArtifacts.workflowWorldPluginPath});return await createNitro(toNitroConfig(e,{routes:i,skillFilesPlugin:r,workflowArtifacts:n}),createNitroLoadOptions(t.buildDir))}function toNitroConfig(e,t){let{compiledArtifacts:n,...r}=e.locations,i=n.instrumentationPluginPath===void 0?void 0:createInstrumentationEntry(n.instrumentationPluginPath);return{...t.routes,alias:{...Object.fromEntries(WORKFLOW_MODULE_SPECIFIERS.map(e=>[e,resolveWorkflowModulePath(e)])),...Object.fromEntries(Object.entries(INSTRUMENTATION_ALIAS_PATHS).map(([e,t])=>[e,resolvePackageSourceFilePath(t)]))},buildDir:r.buildDir,builder:`rolldown`,compatibilityDate:`2026-09-03`,dev:e.development,features:{websocket:e.websocket},...i&&{inlineDynamicImports:i.inlineDynamicImports},logLevel:e.development?1:void 0,logging:e.development?void 0:{compressedSizes:!1},modules:i?[i.module]:[],noExternals:createHostNoExternals(t.workflowArtifacts.stepTargets),output:{dir:r.outputDir},plugins:e.runtimePlugins.map(e=>resolveRuntimePluginPath(e,n)),preset:e.preset,publicAssets:[],renderer:!1,rolldownConfig:{onLog:onNitroBundlerLog,output:{sourcemapIgnoreList:/node_modules/},plugins:createHostPlugins({appRoot:r.appRoot,authoredPackageRoot:e.authored.packageRoot,externals:e.externals,extensionMounts:e.extensionMounts,extensionOverridePaths:e.extensionOverridePaths,instrumentationEntryPlugin:i?.plugin,instrumentationSourcePaths:n.instrumentationSourcePaths,workflowArtifacts:t.workflowArtifacts}),tsconfig:e.authored.tsconfig,...!e.development&&{experimental:{attachDebugInfo:`none`}}},rootDir:r.appRoot,scanDirs:[],serverDir:!1,serverEntry:!1,traceDeps:[...e.externals.traceDeps],vercel:e.vercel,virtual:{...t.routes.virtual,...t.skillFilesPlugin!==void 0&&{[SKILL_FILES_PLUGIN_ID]:t.skillFilesPlugin}}}}const EVE_RUNTIME_PLUGIN_PATHS={"local-schedules":`src/internal/nitro/host/local-schedules-runtime-plugin.ts`,"local-tracing":`src/internal/nitro/host/local-tracing-runtime-plugin.ts`,"sandbox-shutdown":`src/internal/nitro/host/sandbox-shutdown-plugin.ts`,"workflow-sandbox":`src/internal/nitro/host/workflow-sandbox-runtime-plugin.ts`};function resolveRuntimePluginPath(e,t){switch(e){case`compiled-artifacts`:return t.bootstrapPath;case`instrumentation`:if(t.instrumentationPluginPath===void 0)throw Error(`Instrumented host has no instrumentation plugin.`);return t.instrumentationPluginPath;case`skill-files`:return SKILL_FILES_PLUGIN_ID;case`workflow-world`:return t.workflowWorldPluginPath;default:return resolvePackageSourceFilePath(EVE_RUNTIME_PLUGIN_PATHS[e])}}export{createHostNitro};
|
|
@@ -27,6 +27,8 @@ export interface DevelopmentAuthoredRebuildCoordinator {
|
|
|
27
27
|
rebuild(input: {
|
|
28
28
|
readonly changedPaths: readonly string[];
|
|
29
29
|
}): Promise<DevelopmentRebuildResult>;
|
|
30
|
+
/** Stops generation pruning, waiting for a running pass. */
|
|
31
|
+
close(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export declare function createDevelopmentAuthoredRebuildCoordinator(input: {
|
|
32
34
|
readonly builds: DevelopmentBuilds;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stageDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{toErrorMessage}from"#shared/errors.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{computeDevelopmentHostFingerprint}from"#internal/nitro/host/dev-host-fingerprint.js";import{removeDevelopmentHostWorkspace}from"#internal/nitro/host/dev-host-workspace.js";import"#internal/nitro/host/drained-nitro-dev-server.js";import{activateDevelopmentGeneration,discardDevelopmentGeneration}from"#internal/nitro/development-generation.js";var PostCommitDevelopmentRebuildError=class extends Error{constructor(e){super(`The development worker was replaced but its generation failed to activate. The server keeps serving the previous generation; the next rebuild retries activation.`,{cause:e}),this.name=`PostCommitDevelopmentRebuildError`}},DevelopmentWorkflowWorldChangeRequiresRestartError=class extends Error{constructor(){super(`Changing experimental.workflow.world between the parent-owned local World and a custom World requires restarting eve dev.`),this.name=`DevelopmentWorkflowWorldChangeRequiresRestartError`}};async function createDevelopmentAuthoredRebuildCoordinator(e){return new TransactionalDevelopmentAuthoredRebuildCoordinator({builds:e.builds,currentHostFingerprint:await computeDevelopmentHostFingerprint(e.initialHost),developmentExtensions:e.developmentExtensions,currentRuntimeFingerprint:e.initialHost.generation.fingerprint,devServer:e.devServer,initialHost:e.initialHost,onRuntimePruned:e.onRuntimePruned})}var TransactionalDevelopmentAuthoredRebuildCoordinator=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){this.#e=e.builds,this.#t=e.initialHost,this.#s=e.onRuntimePruned,this.#n=e.currentHostFingerprint,this.#i=e.developmentExtensions,this.#r=e.currentRuntimeFingerprint,this.#a=e.devServer,this.#o=usesParentDevelopmentWorkflowWorld(e.initialHost.compileResult.manifest.config.experimental?.workflow?.world)}async rebuild(e){let t=this.#t,n=stageDevelopmentEnvironmentFiles(t.appRoot),r=this.#e.begin(),i;try{if(i=await r.prepare({appRoot:t.appRoot,changedPaths:e.changedPaths,developmentExtensions:this.#i,previousExtensions:t.workspaceExtensions}),usesParentDevelopmentWorkflowWorld(i.compileResult.manifest.config.experimental?.workflow?.world)!==this.#o)throw new DevelopmentWorkflowWorldChangeRequiresRestartError;let a=await computeDevelopmentHostFingerprint(i),o=i.generation.fingerprint,s=a!==this.#n,c=o!==this.#r;if(!s&&!c){let e={...t,workspaceExtensions:i.workspaceExtensions};return await discardPreparedHost(i),i=void 0,this.#u(e,this.#n,this.#r),n.commit(),{host:e,kind:`unchanged`}}if(!s){await removeDevelopmentHostWorkspace(i.workspace);let e=retainActiveHostWorkspace(t,i);return await activateDevelopmentGeneration({appRoot:e.appRoot,generation:e.generation,
|
|
1
|
+
import{stageDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{toErrorMessage}from"#shared/errors.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{computeDevelopmentHostFingerprint}from"#internal/nitro/host/dev-host-fingerprint.js";import{removeDevelopmentHostWorkspace}from"#internal/nitro/host/dev-host-workspace.js";import"#internal/nitro/host/drained-nitro-dev-server.js";import{activateDevelopmentGeneration,createDevelopmentGenerationPruner,discardDevelopmentGeneration}from"#internal/nitro/development-generation.js";var PostCommitDevelopmentRebuildError=class extends Error{constructor(e){super(`The development worker was replaced but its generation failed to activate. The server keeps serving the previous generation; the next rebuild retries activation.`,{cause:e}),this.name=`PostCommitDevelopmentRebuildError`}},DevelopmentWorkflowWorldChangeRequiresRestartError=class extends Error{constructor(){super(`Changing experimental.workflow.world between the parent-owned local World and a custom World requires restarting eve dev.`),this.name=`DevelopmentWorkflowWorldChangeRequiresRestartError`}};async function createDevelopmentAuthoredRebuildCoordinator(e){return new TransactionalDevelopmentAuthoredRebuildCoordinator({builds:e.builds,currentHostFingerprint:await computeDevelopmentHostFingerprint(e.initialHost),developmentExtensions:e.developmentExtensions,currentRuntimeFingerprint:e.initialHost.generation.fingerprint,devServer:e.devServer,initialHost:e.initialHost,onRuntimePruned:e.onRuntimePruned})}var TransactionalDevelopmentAuthoredRebuildCoordinator=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){this.#e=e.builds,this.#t=e.initialHost,this.#s=createDevelopmentGenerationPruner({appRoot:e.initialHost.appRoot,onRuntimePruned:e.onRuntimePruned}),this.#s.request(),this.#n=e.currentHostFingerprint,this.#i=e.developmentExtensions,this.#r=e.currentRuntimeFingerprint,this.#a=e.devServer,this.#o=usesParentDevelopmentWorkflowWorld(e.initialHost.compileResult.manifest.config.experimental?.workflow?.world)}async close(){await this.#s.close()}async rebuild(e){let t=this.#t,n=stageDevelopmentEnvironmentFiles(t.appRoot),r=this.#e.begin(),i;try{if(i=await r.prepare({appRoot:t.appRoot,changedPaths:e.changedPaths,developmentExtensions:this.#i,previousExtensions:t.workspaceExtensions}),usesParentDevelopmentWorkflowWorld(i.compileResult.manifest.config.experimental?.workflow?.world)!==this.#o)throw new DevelopmentWorkflowWorldChangeRequiresRestartError;let a=await computeDevelopmentHostFingerprint(i),o=i.generation.fingerprint,s=a!==this.#n,c=o!==this.#r;if(!s&&!c){let e={...t,workspaceExtensions:i.workspaceExtensions};return await discardPreparedHost(i),i=void 0,this.#u(e,this.#n,this.#r),n.commit(),{host:e,kind:`unchanged`}}if(!s){await removeDevelopmentHostWorkspace(i.workspace);let e=retainActiveHostWorkspace(t,i);return await activateDevelopmentGeneration({appRoot:e.appRoot,generation:e.generation}),this.#s.request(),this.#u(e,a,o),i=void 0,n.commit(),await this.#c(),{host:e,kind:`runtime`}}let l=await this.#l({build:r,hasRuntimeChange:c,nextHost:i,nextHostFingerprint:a,nextRuntimeFingerprint:o});return i=void 0,n.commit(),this.#a.prepareSpareWorker(),l}catch(e){throw e instanceof PostCommitDevelopmentRebuildError?(n.commit(),e):(n.rollback(),i===void 0?e:await discardFailedHost(e,i))}finally{r.close()}}async#c(){try{await this.#a.recycleWorker()}catch(e){console.warn(`[eve:dev] could not start a fresh dev worker; the current worker keeps serving: ${toErrorMessage(e)}`)}this.#a.prepareSpareWorker()}async#l(e){let t=e.nextHost;e.hasRuntimeChange||(await discardDevelopmentGeneration(e.nextHost.generation),t={...e.nextHost,generation:this.#t.generation});let n=await e.build.buildHost(t),r=t.workspace;if(await this.#a.replaceWorker({dispose:async()=>await removeDevelopmentHostWorkspace(r),entry:n.entry,workerData:n.workerData}),e.hasRuntimeChange)try{await activateDevelopmentGeneration({appRoot:t.appRoot,generation:t.generation}),this.#s.request()}catch(n){throw await discardDevelopmentGeneration(t.generation).catch(()=>void 0),this.#u({...t,generation:this.#t.generation},e.nextHostFingerprint,this.#r),new PostCommitDevelopmentRebuildError(n)}return this.#u(t,e.nextHostFingerprint,e.hasRuntimeChange?e.nextRuntimeFingerprint:this.#r),{host:t,kind:`structural`}}#u(e,t,n){this.#t=e,this.#n=t,this.#r=n}};function retainActiveHostWorkspace(e,t){return{...t,compiledArtifacts:e.compiledArtifacts,workflowBuildDir:e.workflowBuildDir,workspace:e.workspace}}async function discardPreparedHost(e){let t=(await Promise.allSettled([discardDevelopmentGeneration(e.generation),removeDevelopmentHostWorkspace(e.workspace)])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length>0)throw AggregateError(t,`Failed to discard development host "${e.workspace.rootDir}".`)}async function discardFailedHost(e,t){try{return await discardPreparedHost(t),e}catch(t){return AggregateError([e,t],`Development rebuild rollback failed.`,{cause:e})}}export{DevelopmentWorkflowWorldChangeRequiresRestartError,PostCommitDevelopmentRebuildError,createDevelopmentAuthoredRebuildCoordinator};
|