@netlify/zip-it-and-ship-it 9.3.0 → 9.4.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/dist/archive.js CHANGED
@@ -1,12 +1,9 @@
1
1
  import { createWriteStream, readlinkSync } from 'fs';
2
- import { promisify } from 'util';
3
2
  import archiver from 'archiver';
4
- import endOfStream from 'end-of-stream';
5
3
  export const ARCHIVE_FORMAT = {
6
4
  NONE: 'none',
7
5
  ZIP: 'zip',
8
6
  };
9
- const pEndOfStream = promisify(endOfStream);
10
7
  // Start zipping files
11
8
  export const startZip = function (destPath) {
12
9
  const output = createWriteStream(destPath);
@@ -36,7 +33,11 @@ export const addZipContent = function (archive, content, name) {
36
33
  };
37
34
  // End zipping files
38
35
  export const endZip = async function (archive, output) {
39
- archive.finalize();
40
- await pEndOfStream(output);
36
+ const result = new Promise((resolve, reject) => {
37
+ output.on('error', (error) => reject(error));
38
+ output.on('finish', () => resolve());
39
+ });
40
+ await archive.finalize();
41
+ return result;
41
42
  };
42
43
  //# sourceMappingURL=archive.js.map
@@ -2,6 +2,12 @@
2
2
  import { Stats } from 'fs';
3
3
  import type { FunctionConfig } from './config.js';
4
4
  import type { Runtime, ZipFunctionResult } from './runtimes/runtime.js';
5
+ import { ObjectValues } from './types/utils.js';
6
+ export declare const INVOCATION_MODE: {
7
+ readonly Buffer: "buffer";
8
+ readonly Stream: "stream";
9
+ };
10
+ export type InvocationMode = ObjectValues<typeof INVOCATION_MODE>;
5
11
  export type FunctionArchive = ZipFunctionResult & {
6
12
  mainFile: string;
7
13
  name: string;
package/dist/function.js CHANGED
@@ -1,2 +1,5 @@
1
- export {};
1
+ export const INVOCATION_MODE = {
2
+ Buffer: 'buffer',
3
+ Stream: 'stream',
4
+ };
2
5
  //# sourceMappingURL=function.js.map
@@ -1,6 +1,8 @@
1
1
  import type { FeatureFlags } from './feature_flags.js';
2
+ import type { InvocationMode } from './function.js';
2
3
  import type { FunctionResult } from './utils/format_result.js';
3
4
  interface ManifestFunction {
5
+ invocationMode?: InvocationMode;
4
6
  mainFile: string;
5
7
  name: string;
6
8
  path: string;
package/dist/manifest.js CHANGED
@@ -12,10 +12,11 @@ export const createManifest = async ({ featureFlags, functions, path, }) => {
12
12
  };
13
13
  await fs.writeFile(path, JSON.stringify(payload));
14
14
  };
15
- const formatFunctionForManifest = ({ bundler, displayName, generator, mainFile, name, path, runtime, runtimeVersion, schedule }, featureFlags) => ({
15
+ const formatFunctionForManifest = ({ bundler, displayName, generator, invocationMode, mainFile, name, path, runtime, runtimeVersion, schedule, }, featureFlags) => ({
16
16
  bundler,
17
17
  displayName,
18
18
  generator,
19
+ invocationMode,
19
20
  mainFile,
20
21
  name,
21
22
  runtimeVersion: featureFlags.functions_inherit_build_nodejs_version ? runtimeVersion : undefined,
@@ -1,8 +1,11 @@
1
1
  import { basename, dirname, extname, resolve } from 'path';
2
+ import { FunctionBundlingUserError } from '../../../../utils/error.js';
2
3
  import { cachedReadFile } from '../../../../utils/fs.js';
4
+ import { RUNTIME } from '../../../runtime.js';
3
5
  import { MODULE_FILE_EXTENSION, MODULE_FORMAT } from '../../utils/module_format.js';
4
6
  import { getNodeSupportMatrix } from '../../utils/node_version.js';
5
7
  import { getPackageJsonIfAvailable } from '../../utils/package_json.js';
8
+ import { NODE_BUNDLER } from '../types.js';
6
9
  import { transpile } from './transpile.js';
7
10
  const getPatchedESMPackages = async (packages, cache) => {
8
11
  const patchedPackages = await Promise.all(packages.map((path) => patchESMPackage(path, cache)));
@@ -30,24 +33,41 @@ export const processESM = async ({ basePath, cache, config, esmPaths, featureFla
30
33
  const extension = extname(mainFile);
31
34
  // If this is a .mjs file and we want to output pure ESM files, we don't need
32
35
  // to transpile anything.
33
- if (extension === MODULE_FILE_EXTENSION.MJS && featureFlags.zisi_pure_esm_mjs) {
36
+ if (extension === MODULE_FILE_EXTENSION.MJS &&
37
+ (featureFlags.zisi_pure_esm_mjs || featureFlags.zisi_functions_api_v2)) {
34
38
  return {
35
39
  moduleFormat: MODULE_FORMAT.ESM,
36
40
  };
37
41
  }
38
42
  const entrypointIsESM = isEntrypointESM({ basePath, esmPaths, mainFile });
39
43
  if (!entrypointIsESM) {
44
+ if (featureFlags.zisi_functions_api_v2) {
45
+ throw new FunctionBundlingUserError(`The function '${name}' must use the ES module syntax. To learn more, visit https://ntl.fyi/esm.`, {
46
+ functionName: name,
47
+ runtime: RUNTIME.JAVASCRIPT,
48
+ bundler: NODE_BUNDLER.NFT,
49
+ });
50
+ }
40
51
  return {
41
52
  moduleFormat: MODULE_FORMAT.COMMONJS,
42
53
  };
43
54
  }
44
55
  const packageJson = await getPackageJsonIfAvailable(dirname(mainFile));
45
56
  const nodeSupport = getNodeSupportMatrix(config.nodeVersion);
46
- if (featureFlags.zisi_pure_esm && packageJson.type === 'module' && nodeSupport.esm) {
57
+ if ((featureFlags.zisi_pure_esm || featureFlags.zisi_functions_api_v2) &&
58
+ packageJson.type === 'module' &&
59
+ nodeSupport.esm) {
47
60
  return {
48
61
  moduleFormat: MODULE_FORMAT.ESM,
49
62
  };
50
63
  }
64
+ if (featureFlags.zisi_functions_api_v2) {
65
+ throw new FunctionBundlingUserError(`The function '${name}' must use the ES module syntax. To learn more, visit https://ntl.fyi/esm.`, {
66
+ functionName: name,
67
+ runtime: RUNTIME.JAVASCRIPT,
68
+ bundler: NODE_BUNDLER.NFT,
69
+ });
70
+ }
51
71
  const rewrites = await transpileESM({ basePath, cache, config, esmPaths, reasons, name });
52
72
  return {
53
73
  moduleFormat: MODULE_FORMAT.COMMONJS,
@@ -1,5 +1,6 @@
1
1
  import { join } from 'path';
2
2
  import { copyFile } from 'cp-file';
3
+ import { INVOCATION_MODE } from '../../function.js';
3
4
  import getInternalValue from '../../utils/get_internal_value.js';
4
5
  import { RUNTIME } from '../runtime.js';
5
6
  import { getBundler, getBundlerName } from './bundlers/index.js';
@@ -72,6 +73,7 @@ const zipFunction = async function ({ archiveFormat, basePath, cache, config = {
72
73
  srcFiles,
73
74
  });
74
75
  await cleanupFunction?.();
76
+ const invocationMode = featureFlags.zisi_functions_api_v2 ? INVOCATION_MODE.Stream : INVOCATION_MODE.Buffer;
75
77
  return {
76
78
  bundler: bundlerName,
77
79
  bundlerWarnings,
@@ -79,6 +81,7 @@ const zipFunction = async function ({ archiveFormat, basePath, cache, config = {
79
81
  inputs,
80
82
  includedFiles,
81
83
  inSourceConfig,
84
+ invocationMode,
82
85
  nativeNodeModules,
83
86
  nodeModulesWithDynamicImports,
84
87
  path: zipPath,
@@ -9,7 +9,7 @@ const getEntryFileContents = (mainPath, moduleFormat, featureFlags) => {
9
9
  const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
10
10
  if (featureFlags.zisi_functions_api_v2) {
11
11
  return [
12
- `import func from '${importPath}'`,
12
+ `import * as func from '${importPath}'`,
13
13
  `import { getLambdaHandler } from './${BOOTSTRAP_FILE_NAME}'`,
14
14
  `export const handler = getLambdaHandler(func)`,
15
15
  ].join(';');
@@ -1,10 +1,9 @@
1
1
  import { Buffer } from 'buffer';
2
- import { promises as fs } from 'fs';
2
+ import { mkdir, rm, writeFile } from 'fs/promises';
3
3
  import os from 'os';
4
4
  import { basename, join } from 'path';
5
5
  import { getPath as getV2APIPath } from '@netlify/serverless-functions-api';
6
6
  import { copyFile } from 'cp-file';
7
- import { deleteAsync as deleteFiles } from 'del';
8
7
  import pMap from 'p-map';
9
8
  import { startZip, addZipFile, addZipContent, endZip, ARCHIVE_FORMAT, } from '../../../archive.js';
10
9
  import { cachedLstat, mkdirAndWriteFile } from '../../../utils/fs.js';
@@ -26,10 +25,10 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
26
25
  });
27
26
  const functionFolder = join(destFolder, basename(filename, extension));
28
27
  // Deleting the functions directory in case it exists before creating it.
29
- await deleteFiles(functionFolder, { force: true });
30
- await fs.mkdir(functionFolder, { recursive: true });
28
+ await rm(functionFolder, { recursive: true, force: true, maxRetries: 3 });
29
+ await mkdir(functionFolder, { recursive: true });
31
30
  // Writing entry file.
32
- await fs.writeFile(join(functionFolder, entryFilename), entryContents);
31
+ await writeFile(join(functionFolder, entryFilename), entryContents);
33
32
  // Copying source files.
34
33
  await pMap(srcFiles, (srcFile) => {
35
34
  const destPath = aliases.get(srcFile) || srcFile;
@@ -1,7 +1,7 @@
1
1
  import type { ArchiveFormat } from '../archive.js';
2
2
  import type { FunctionConfig } from '../config.js';
3
3
  import type { FeatureFlags } from '../feature_flags.js';
4
- import type { FunctionSource, SourceFile } from '../function.js';
4
+ import type { FunctionSource, InvocationMode, SourceFile } from '../function.js';
5
5
  import { ObjectValues } from '../types/utils.js';
6
6
  import type { RuntimeCache } from '../utils/cache.js';
7
7
  import type { NodeBundlerName } from './node/bundlers/types.js';
@@ -38,6 +38,7 @@ export interface ZipFunctionResult {
38
38
  inputs?: string[];
39
39
  includedFiles?: string[];
40
40
  inSourceConfig?: ISCValues;
41
+ invocationMode?: InvocationMode;
41
42
  nativeNodeModules?: object;
42
43
  nodeModulesWithDynamicImports?: string[];
43
44
  path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "9.3.0",
3
+ "version": "9.4.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -62,8 +62,6 @@
62
62
  "archiver": "^5.3.0",
63
63
  "common-path-prefix": "^3.0.0",
64
64
  "cp-file": "^10.0.0",
65
- "del": "^7.0.0",
66
- "end-of-stream": "^1.4.4",
67
65
  "es-module-lexer": "^1.0.0",
68
66
  "execa": "^6.0.0",
69
67
  "filter-obj": "^5.0.0",
@@ -78,7 +76,7 @@
78
76
  "normalize-path": "^3.0.0",
79
77
  "p-map": "^5.0.0",
80
78
  "path-exists": "^5.0.0",
81
- "precinct": "^10.0.0",
79
+ "precinct": "^11.0.0",
82
80
  "require-package-name": "^2.0.1",
83
81
  "resolve": "^2.0.0-next.1",
84
82
  "semver": "^7.0.0",
@@ -91,8 +89,8 @@
91
89
  "@babel/types": "^7.15.6",
92
90
  "@netlify/eslint-config-node": "^7.0.1",
93
91
  "@types/archiver": "^5.1.1",
94
- "@types/end-of-stream": "^1.4.1",
95
92
  "@types/glob": "^8.1.0",
93
+ "@types/is-ci": "^3.0.0",
96
94
  "@types/node": "^14.18.32",
97
95
  "@types/normalize-path": "^3.0.0",
98
96
  "@types/resolve": "^1.20.2",
@@ -105,11 +103,10 @@
105
103
  "deepmerge": "^4.2.2",
106
104
  "get-stream": "^6.0.0",
107
105
  "husky": "^8.0.0",
106
+ "is-ci": "^3.0.1",
108
107
  "lambda-local": "^2.0.3",
109
108
  "npm-run-all": "^4.1.5",
110
- "sort-on": "^5.0.0",
111
109
  "source-map-support": "^0.5.21",
112
- "throat": "^6.0.1",
113
110
  "typescript": "^5.0.0",
114
111
  "vite": "^4.0.0",
115
112
  "vitest": "^0.31.0"