@netlify/zip-it-and-ship-it 16.2.1 → 16.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -51,4 +51,5 @@ declare const getConfigForFunction: ({ config, configFileDirectories, func, }: {
51
51
  configFileDirectories?: string[];
52
52
  func: FunctionWithoutConfig;
53
53
  }) => Promise<FunctionConfig>;
54
+ export declare const withComputeResources: <T extends FunctionConfig>(merged: T, sources: Pick<FunctionConfig, "memory" | "vcpu">[]) => T;
54
55
  export { Config, FunctionConfig, FunctionWithoutConfig, getConfigForFunction };
package/dist/config.js CHANGED
@@ -75,10 +75,10 @@ const getConfigForFunction = async ({ config, configFileDirectories, func, }) =>
75
75
  return fromConfig;
76
76
  }
77
77
  const fromFile = await getFromFile(func);
78
- return {
78
+ return withComputeResources({
79
79
  ...fromConfig,
80
80
  ...fromFile,
81
- };
81
+ }, [fromConfig, fromFile]);
82
82
  };
83
83
  const getFromMainConfig = ({ config, func, }) => {
84
84
  if (!config) {
@@ -101,7 +101,29 @@ const getFromMainConfig = ({ config, func, }) => {
101
101
  })
102
102
  .sort(({ weight: weightA }, { weight: weightB }) => weightA - weightB)
103
103
  .map(({ expression }) => config[expression]);
104
- return mergeOptions.apply({ concatArrays: true, ignoreUndefined: true }, matches);
104
+ const merged = withComputeResources(mergeOptions.apply({ concatArrays: true, ignoreUndefined: true }, matches), matches);
105
+ const memory = merged.memory;
106
+ if (typeof memory === 'string') {
107
+ merged.memory = parseMemoryMB(memory);
108
+ }
109
+ return merged;
110
+ };
111
+ // memory and vcpu are two mutually exclusive ways of sizing a function, so
112
+ // they can't be merged key by key like other properties
113
+ // a wildcard block with memory and a more specific block with vcpu
114
+ // would otherwise produce both. Instead, the highest-priority source that
115
+ // sets either of them supplies the pair.
116
+ export const withComputeResources = (merged, sources) => {
117
+ const winner = [...sources].reverse().find((source) => source.memory !== undefined || source.vcpu !== undefined);
118
+ if (winner === undefined) {
119
+ return merged;
120
+ }
121
+ const { memory, vcpu, ...rest } = merged;
122
+ return {
123
+ ...rest,
124
+ ...(winner.memory === undefined ? {} : { memory: winner.memory }),
125
+ ...(winner.vcpu === undefined ? {} : { vcpu: winner.vcpu }),
126
+ };
105
127
  };
106
128
  const getFromFile = async (func) => {
107
129
  const filename = `${basename(func.mainFile, extname(func.mainFile))}.json`;
@@ -3,7 +3,7 @@ import { dirname } from 'path';
3
3
  // this dependency.
4
4
  import mergeOptions from 'merge-options';
5
5
  import { z } from 'zod';
6
- import { functionConfigShape } from '../../../config.js';
6
+ import { functionConfigShape, withComputeResources } from '../../../config.js';
7
7
  import { INVOCATION_MODE } from '../../../function.js';
8
8
  import { rateLimit } from '../../../rate_limit.js';
9
9
  import { ensureArray } from '../../../utils/ensure_array.js';
@@ -257,7 +257,7 @@ export const parseSource = (source, { functionName }) => {
257
257
  return result;
258
258
  };
259
259
  export const augmentFunctionConfig = (mainFile, tomlConfig, inSourceConfig = {}) => {
260
- const mergedConfig = mergeOptions.call({ concatArrays: true }, tomlConfig, inSourceConfig);
260
+ const mergedConfig = withComputeResources(mergeOptions.call({ concatArrays: true }, tomlConfig, inSourceConfig), [tomlConfig, inSourceConfig]);
261
261
  // We can't simply merge included files from the TOML and from in-source
262
262
  // configuration because their globs are relative to different base paths.
263
263
  // In the future, we could shift things around so we resolve each glob
@@ -52,7 +52,7 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
52
52
  pluginsModulesPath = undefined;
53
53
  }
54
54
  const staticAnalysisResult = await parseFile(mainFile, { functionName: name });
55
- const runtimeAPIVersion = staticAnalysisResult.runtimeAPIVersion === 2 ? 2 : 1;
55
+ const runtimeAPIVersion = isServer === true || staticAnalysisResult.runtimeAPIVersion === 2 ? 2 : 1;
56
56
  const mergedConfig = augmentFunctionConfig(mainFile, config, staticAnalysisResult.config);
57
57
  const { name: bundlerName, reason: bundlerReason } = await getBundlerName({
58
58
  config: mergedConfig,
package/dist/server.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import { extname, join, resolve } from 'path';
3
3
  import { ARCHIVE_FORMAT } from './archive.js';
4
- import { NODE_BUNDLER } from './runtimes/node/bundlers/types.js';
5
4
  import { getFunctionFromPath } from './runtimes/index.js';
6
5
  import { RUNTIME } from './runtimes/runtime.js';
7
6
  import { FunctionBundlingUserError } from './utils/error.js';
@@ -65,7 +64,7 @@ export const bundleServer = async (server, destFolder, { basePath, cache, featur
65
64
  archiveFormat: ARCHIVE_FORMAT.ZIP,
66
65
  basePath,
67
66
  cache,
68
- config: { ...source.config, nodeBundler: NODE_BUNDLER.NFT },
67
+ config: source.config,
69
68
  destFolder,
70
69
  extension: source.extension,
71
70
  featureFlags,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "16.2.1",
3
+ "version": "16.2.3",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -100,5 +100,5 @@
100
100
  "engines": {
101
101
  "node": ">=22.12.0"
102
102
  },
103
- "gitHead": "d99b17e8a25b18687ce7b7657621dd22827304b7"
103
+ "gitHead": "227492a17c9821682390f6b7554bd69dfa282d9e"
104
104
  }