@netlify/zip-it-and-ship-it 9.0.0 → 9.2.0-test

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.
@@ -12,10 +12,12 @@ export const defaultFlags = {
12
12
  // Output pure (i.e. untranspiled) ESM files when the function file has a
13
13
  // `.mjs` extension.
14
14
  zisi_pure_esm_mjs: false,
15
- // Output CJS file extension
15
+ // Output CJS file extension.
16
16
  zisi_output_cjs_extension: false,
17
- // Do not allow ___netlify-entry-point as function or file name
17
+ // Do not allow ___netlify-entry-point as function or file name.
18
18
  zisi_disallow_new_entry_name: false,
19
+ // Inject the compatibility layer required for the v2 runtime API to work.
20
+ zisi_functions_api_v2: false,
19
21
  };
20
22
  // List of supported flags and their default value.
21
23
  export const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
@@ -17,7 +17,6 @@ export const ESBUILD_LOG_LIMIT = 10;
17
17
  // When resolving imports with no extension (e.g. require('./foo')), these are
18
18
  // the extensions that esbuild will look for, in this order.
19
19
  const RESOLVE_EXTENSIONS = ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts', '.json'];
20
- // eslint-disable-next-line max-statements
21
20
  export const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], featureFlags, ignoredModules = [], mainFile, name, srcDir, srcFile, }) {
22
21
  // We use a temporary directory as the destination for esbuild files to avoid
23
22
  // any naming conflicts with files generated by other functions.
@@ -16,7 +16,6 @@ export const getNativeModulesPlugin = (externalizedModules) => ({
16
16
  name: 'external-native-modules',
17
17
  setup(build) {
18
18
  const cache = {};
19
- // eslint-disable-next-line max-statements
20
19
  build.onResolve({ filter: packageFilter }, async (args) => {
21
20
  const pkg = packageName.exec(args.path);
22
21
  if (!pkg)
@@ -1,6 +1,7 @@
1
1
  import type { FeatureFlags } from '../../../feature_flags.js';
2
2
  import { ModuleFormat } from './module_format.js';
3
3
  export declare const ENTRY_FILE_NAME = "___netlify-entry-point";
4
+ export declare const BOOTSTRAP_FILE_NAME = "___netlify-bootstrap.js";
4
5
  export interface EntryFile {
5
6
  contents: string;
6
7
  filename: string;
@@ -4,8 +4,16 @@ import { RUNTIME } from '../../runtime.js';
4
4
  import { getFileExtensionForFormat, MODULE_FILE_EXTENSION, MODULE_FORMAT, } from './module_format.js';
5
5
  import { normalizeFilePath } from './normalize_path.js';
6
6
  export const ENTRY_FILE_NAME = '___netlify-entry-point';
7
- const getEntryFileContents = (mainPath, moduleFormat) => {
7
+ export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.js';
8
+ const getEntryFileContents = (mainPath, moduleFormat, featureFlags) => {
8
9
  const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
10
+ if (featureFlags.zisi_functions_api_v2) {
11
+ return [
12
+ `import func from '${importPath}'`,
13
+ `import { getLambdaHandler } from './${BOOTSTRAP_FILE_NAME}'`,
14
+ `export const handler = getLambdaHandler(func)`,
15
+ ].join(';\n');
16
+ }
9
17
  if (moduleFormat === MODULE_FORMAT.COMMONJS) {
10
18
  return `module.exports = require('${importPath}')`;
11
19
  }
@@ -47,7 +55,7 @@ export const getEntryFile = ({ commonPrefix, featureFlags, filename, mainFile, m
47
55
  const mainPath = normalizeFilePath({ commonPrefix, path: mainFile, userNamespace });
48
56
  const extension = getFileExtensionForFormat(moduleFormat, featureFlags);
49
57
  const entryFilename = getEntryFileName({ extension, filename });
50
- const contents = getEntryFileContents(mainPath, moduleFormat);
58
+ const contents = getEntryFileContents(mainPath, moduleFormat, featureFlags);
51
59
  return {
52
60
  contents,
53
61
  filename: entryFilename,
@@ -2,12 +2,13 @@ import { Buffer } from 'buffer';
2
2
  import { promises as fs } from 'fs';
3
3
  import os from 'os';
4
4
  import { basename, join } from 'path';
5
+ import { getPath as getV2APIPath } from '@netlify/serverless-functions-api';
5
6
  import { copyFile } from 'cp-file';
6
7
  import { deleteAsync as deleteFiles } from 'del';
7
8
  import pMap from 'p-map';
8
9
  import { startZip, addZipFile, addZipContent, endZip, ARCHIVE_FORMAT, } from '../../../archive.js';
9
10
  import { cachedLstat, mkdirAndWriteFile } from '../../../utils/fs.js';
10
- import { conflictsWithEntryFile, getEntryFile, isNamedLikeEntryFile } from './entry_file.js';
11
+ import { BOOTSTRAP_FILE_NAME, conflictsWithEntryFile, getEntryFile, isNamedLikeEntryFile, } from './entry_file.js';
11
12
  import { normalizeFilePath } from './normalize_path.js';
12
13
  // Taken from https://www.npmjs.com/package/cpy.
13
14
  const COPY_FILE_CONCURRENCY = os.cpus().length === 0 ? 2 : os.cpus().length * 2;
@@ -45,7 +46,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
45
46
  }, { concurrency: COPY_FILE_CONCURRENCY });
46
47
  return functionFolder;
47
48
  };
48
- const createZipArchive = async function ({ aliases, basePath, cache, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
49
+ const createZipArchive = async function ({ aliases = new Map(), basePath, cache, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
49
50
  const destPath = join(destFolder, `${basename(filename, extension)}.zip`);
50
51
  const { archive, output } = startZip(destPath);
51
52
  // There is a naming conflict with the entry file if one of the supporting
@@ -75,6 +76,14 @@ const createZipArchive = async function ({ aliases, basePath, cache, destFolder,
75
76
  });
76
77
  addEntryFileToZip(archive, entryFile);
77
78
  }
79
+ if (featureFlags.zisi_functions_api_v2) {
80
+ // This is the path to the file that contains all the code for the v2
81
+ // functions API. We add it to the list of source files and create an
82
+ // alias so that it's written as `BOOTSTRAP_FILE_NAME` in the ZIP.
83
+ const v2APIPath = getV2APIPath();
84
+ srcFiles.push(v2APIPath);
85
+ aliases.set(v2APIPath, BOOTSTRAP_FILE_NAME);
86
+ }
78
87
  const srcFilesInfos = await Promise.all(srcFiles.map((file) => addStat(cache, file)));
79
88
  // We ensure this is not async, so that the archive's checksum is
80
89
  // deterministic. Otherwise it depends on the order the files were added.
package/dist/zip.js CHANGED
@@ -84,7 +84,6 @@ export const zipFunctions = async function (relativeSrcFolders, destFolder, { ar
84
84
  }
85
85
  return formattedResults;
86
86
  };
87
- // eslint-disable-next-line max-statements
88
87
  export const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat = ARCHIVE_FORMAT.ZIP, basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, systemLog, debug, internalSrcFolder, } = {}) {
89
88
  validateArchiveFormat(archiveFormat);
90
89
  const logger = getLogger(systemLog, debug);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "9.0.0",
3
+ "version": "9.2.0-test",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -48,7 +48,7 @@
48
48
  ],
49
49
  "author": "Netlify, Inc",
50
50
  "license": "MIT",
51
- "repository": "netlify/zip-it-and-ship-it",
51
+ "repository": "https://github.com/netlify/zip-it-and-ship-it",
52
52
  "homepage": "https://github.com/netlify/zip-it-and-ship-it#README",
53
53
  "bugs": {
54
54
  "url": "https://github.com/netlify/zip-it-and-ship-it/issues"
@@ -57,6 +57,7 @@
57
57
  "@babel/parser": "7.16.8",
58
58
  "@netlify/binary-info": "^1.0.0",
59
59
  "@netlify/esbuild": "0.14.39",
60
+ "@netlify/serverless-functions-api": "^1.2.0",
60
61
  "@vercel/nft": "^0.22.0",
61
62
  "archiver": "^5.3.0",
62
63
  "common-path-prefix": "^3.0.0",
@@ -104,6 +105,7 @@
104
105
  "deepmerge": "^4.2.2",
105
106
  "get-stream": "^6.0.0",
106
107
  "husky": "^8.0.0",
108
+ "lambda-local": "^2.0.3",
107
109
  "npm-run-all": "^4.1.5",
108
110
  "sort-on": "^5.0.0",
109
111
  "source-map-support": "^0.5.21",