|
1 | 1 | // @ts-check |
2 | | -import { mkdir } from 'fs/promises' |
| 2 | +import { mkdir, stat } from 'fs/promises' |
3 | 3 | import { createRequire } from 'module' |
4 | 4 | import { basename, extname, isAbsolute, join, resolve } from 'path' |
5 | 5 | import { env } from 'process' |
@@ -39,6 +39,7 @@ export class FunctionsRegistry { |
39 | 39 | debug = false, |
40 | 40 | isConnected = false, |
41 | 41 | logLambdaCompat, |
| 42 | + manifest, |
42 | 43 | projectRoot, |
43 | 44 | settings, |
44 | 45 | timeouts, |
@@ -96,6 +97,14 @@ export class FunctionsRegistry { |
96 | 97 | * @type {boolean} |
97 | 98 | */ |
98 | 99 | this.logLambdaCompat = Boolean(logLambdaCompat) |
| 100 | + |
| 101 | + /** |
| 102 | + * Contents of a `manifest.json` file that can be looked up when dealing |
| 103 | + * with built functions. |
| 104 | + * |
| 105 | + * @type {object} |
| 106 | + */ |
| 107 | + this.manifest = manifest |
99 | 108 | } |
100 | 109 |
|
101 | 110 | checkTypesPackage() { |
@@ -390,12 +399,30 @@ export class FunctionsRegistry { |
390 | 399 | FunctionsRegistry.logEvent('extracted', { func }) |
391 | 400 | } |
392 | 401 |
|
393 | | - func.mainFile = join(unzippedDirectory, `${func.name}.js`) |
| 402 | + // If there's a manifest file, look up the function in order to extract |
| 403 | + // the build data. |
| 404 | + const manifestEntry = (this.manifest?.functions || []).find((manifestFunc) => manifestFunc.name === func.name) |
| 405 | + |
| 406 | + func.buildData = manifestEntry?.buildData || {} |
| 407 | + |
| 408 | + // When we look at an unzipped function, we don't know whether it uses |
| 409 | + // the legacy entry file format (i.e. `[function name].js`) or the new |
| 410 | + // one (i.e. `___netlify-entry-point.mjs`). Let's look for the new one |
| 411 | + // and use it if it exists, otherwise use the old one. |
| 412 | + try { |
| 413 | + const v2EntryPointPath = join(unzippedDirectory, '___netlify-entry-point.mjs') |
| 414 | + |
| 415 | + await stat(v2EntryPointPath) |
| 416 | + |
| 417 | + func.mainFile = v2EntryPointPath |
| 418 | + } catch { |
| 419 | + func.mainFile = join(unzippedDirectory, `${func.name}.js`) |
| 420 | + } |
| 421 | + } else { |
| 422 | + this.buildFunctionAndWatchFiles(func, !isReload) |
394 | 423 | } |
395 | 424 |
|
396 | 425 | this.functions.set(name, func) |
397 | | - |
398 | | - this.buildFunctionAndWatchFiles(func, !isReload) |
399 | 426 | } |
400 | 427 |
|
401 | 428 | /** |
|
0 commit comments