| 71 | } |
| 72 | |
| 73 | export const build: BuildV2 = async args => { |
| 74 | // Reject `module:function` colon syntax in entrypoints. fs-detectors |
| 75 | // parses it into `Service.handlerFunction` regardless of service |
| 76 | // type. |
| 77 | if (typeof args.config?.handlerFunction === 'string') { |
| 78 | throw new Error( |
| 79 | `Named-function entrypoints are not supported for JavaScript services (got "${args.entrypoint}:${args.config.handlerFunction}"). Put each handler in its own file with a default export.` |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | const downloadResult = await downloadInstallAndBundle(args); |
| 84 | const nodeVersion = await getNodeVersion( |
| 85 | args.workPath, |
| 86 | undefined, |
| 87 | args.config, |
| 88 | args.meta |
| 89 | ); |
| 90 | const isBun = isBunVersion(nodeVersion); |
| 91 | const builderName = '@vercel/backends'; |
| 92 | |
| 93 | const span = |
| 94 | args.span ?? |
| 95 | new Span({ |
| 96 | name: builderName, |
| 97 | }); |
| 98 | |
| 99 | span.setAttributes({ |
| 100 | 'builder.name': builderName, |
| 101 | }); |
| 102 | |
| 103 | const buildSpan = span.child('vc.builder.backends.build'); |
| 104 | |
| 105 | return buildSpan.trace(async () => { |
| 106 | const entrypoint = await findEntrypointWithHintOrThrow( |
| 107 | args.workPath, |
| 108 | args.entrypoint |
| 109 | ); |
| 110 | debug('Entrypoint', entrypoint); |
| 111 | args.entrypoint = entrypoint; |
| 112 | |
| 113 | const serviceName = |
| 114 | typeof args.config?.serviceName === 'string' && |
| 115 | args.config.serviceName !== '' |
| 116 | ? args.config.serviceName |
| 117 | : undefined; |
| 118 | |
| 119 | // Edge Runtime is not supported in services. Without this check the Node |
| 120 | // service builder silently ignores an in-file |
| 121 | // `export const config = { runtime: 'edge' }` and ships a Node lambda; |
| 122 | // surface it as a clear build error instead. |
| 123 | if (serviceName) { |
| 124 | const staticConfig = getConfig( |
| 125 | new Project(), |
| 126 | join(args.workPath, entrypoint) |
| 127 | ); |
| 128 | const configuredRuntime = staticConfig?.runtime; |
| 129 | if ( |
| 130 | typeof configuredRuntime === 'string' && |
no test coverage detected