@netlify/zip-it-and-ship-it 8.0.0 → 8.2.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.
Files changed (58) hide show
  1. package/README.md +1 -0
  2. package/dist/archive.d.ts +1 -1
  3. package/dist/config.d.ts +3 -3
  4. package/dist/feature_flags.d.ts +2 -2
  5. package/dist/feature_flags.js +6 -0
  6. package/dist/function.d.ts +2 -2
  7. package/dist/main.d.ts +1 -1
  8. package/dist/main.js +7 -3
  9. package/dist/runtimes/detect_runtime.d.ts +1 -3
  10. package/dist/runtimes/detect_runtime.js +4 -7
  11. package/dist/runtimes/go/index.js +14 -16
  12. package/dist/runtimes/index.d.ts +6 -3
  13. package/dist/runtimes/index.js +6 -12
  14. package/dist/runtimes/node/bundlers/esbuild/bundler.js +11 -0
  15. package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +2 -1
  16. package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +1 -0
  17. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +9 -7
  18. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +1 -1
  19. package/dist/runtimes/node/bundlers/esbuild/src_files.js +2 -2
  20. package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +3 -3
  21. package/dist/runtimes/node/bundlers/nft/es_modules.js +11 -10
  22. package/dist/runtimes/node/bundlers/nft/index.js +11 -12
  23. package/dist/runtimes/node/bundlers/types.d.ts +7 -5
  24. package/dist/runtimes/node/bundlers/zisi/list_imports.d.ts +3 -1
  25. package/dist/runtimes/node/bundlers/zisi/list_imports.js +19 -1
  26. package/dist/runtimes/node/bundlers/zisi/resolve.js +1 -1
  27. package/dist/runtimes/node/bundlers/zisi/src_files.js +2 -5
  28. package/dist/runtimes/node/finder.js +10 -8
  29. package/dist/runtimes/node/in_source_config/index.d.ts +2 -2
  30. package/dist/runtimes/node/index.js +3 -1
  31. package/dist/runtimes/node/parser/bindings.d.ts +2 -2
  32. package/dist/runtimes/node/parser/index.js +4 -0
  33. package/dist/runtimes/node/utils/node_version.d.ts +3 -3
  34. package/dist/runtimes/node/utils/package_json.d.ts +2 -1
  35. package/dist/runtimes/node/utils/package_json.js +8 -8
  36. package/dist/runtimes/node/utils/plugin_modules_path.js +1 -1
  37. package/dist/runtimes/node/utils/zip.d.ts +3 -1
  38. package/dist/runtimes/node/utils/zip.js +5 -5
  39. package/dist/runtimes/runtime.d.ts +12 -11
  40. package/dist/runtimes/rust/builder.d.ts +4 -2
  41. package/dist/runtimes/rust/builder.js +6 -5
  42. package/dist/runtimes/rust/index.js +17 -19
  43. package/dist/utils/cache.d.ts +16 -0
  44. package/dist/utils/cache.js +10 -0
  45. package/dist/utils/error.d.ts +1 -1
  46. package/dist/utils/format_result.d.ts +1 -1
  47. package/dist/utils/fs.d.ts +5 -11
  48. package/dist/utils/fs.js +26 -15
  49. package/dist/utils/logger.d.ts +8 -0
  50. package/dist/utils/logger.js +15 -0
  51. package/dist/utils/remove_undefined.js +3 -2
  52. package/dist/utils/shell.d.ts +2 -20
  53. package/dist/utils/shell.js +1 -1
  54. package/dist/utils/timer.d.ts +2 -0
  55. package/dist/utils/timer.js +12 -0
  56. package/dist/zip.d.ts +6 -3
  57. package/dist/zip.js +38 -4
  58. package/package.json +13 -13
@@ -0,0 +1,15 @@
1
+ const noopLogger = () => {
2
+ // no-op
3
+ };
4
+ const getLogger = (systemLogger, debug = false) => {
5
+ // If there is a system logger configured, we'll use that. If there isn't,
6
+ // we'll pipe system logs to stdout if `debug` is enabled and swallow them
7
+ // otherwise.
8
+ const system = systemLogger ?? (debug ? console.log : noopLogger);
9
+ return {
10
+ system,
11
+ user: console.log,
12
+ };
13
+ };
14
+ export { getLogger };
15
+ //# sourceMappingURL=logger.js.map
@@ -1,5 +1,6 @@
1
- import filterObj from 'filter-obj';
1
+ import { includeKeys } from 'filter-obj';
2
+ const isUndefined = (key, value) => value !== undefined;
2
3
  export const removeUndefined = function (obj) {
3
- return filterObj(obj, (key, value) => value !== undefined);
4
+ return includeKeys(obj, isUndefined);
4
5
  };
5
6
  //# sourceMappingURL=remove_undefined.js.map
@@ -1,22 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import execa from 'execa';
1
+ import { execa } from 'execa';
3
2
  export declare const shellUtils: {
4
- runCommand: {
5
- (file: string, arguments?: readonly string[] | undefined, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
6
- (file: string, arguments?: readonly string[] | undefined, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
7
- (file: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
8
- (file: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
9
- sync(file: string, arguments?: readonly string[] | undefined, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
10
- sync(file: string, arguments?: readonly string[] | undefined, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
11
- sync(file: string, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
12
- sync(file: string, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
13
- command(command: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
14
- command(command: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
15
- commandSync(command: string, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
16
- commandSync(command: string, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
17
- node(scriptPath: string, arguments?: readonly string[] | undefined, options?: execa.NodeOptions<string> | undefined): execa.ExecaChildProcess<string>;
18
- node(scriptPath: string, arguments?: readonly string[] | undefined, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
19
- node(scriptPath: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
20
- node(scriptPath: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
21
- };
3
+ runCommand: typeof execa;
22
4
  };
@@ -1,3 +1,3 @@
1
- import execa from 'execa';
1
+ import { execa } from 'execa';
2
2
  export const shellUtils = { runCommand: execa };
3
3
  //# sourceMappingURL=shell.js.map
@@ -0,0 +1,2 @@
1
+ export declare const startTimer: () => [number, number];
2
+ export declare const endTimer: ([startSecs, startNsecs]: [number, number]) => number;
@@ -0,0 +1,12 @@
1
+ import { hrtime } from 'process';
2
+ const NANOSECS_TO_SECS = 1e9;
3
+ export const startTimer = function () {
4
+ return hrtime();
5
+ };
6
+ // returns the time in nanoseconds
7
+ export const endTimer = function ([startSecs, startNsecs]) {
8
+ const [endSecs, endNsecs] = hrtime();
9
+ const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs;
10
+ return durationNs;
11
+ };
12
+ //# sourceMappingURL=timer.js.map
package/dist/zip.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ArchiveFormat } from './archive.js';
2
2
  import { Config } from './config.js';
3
3
  import { FeatureFlags } from './feature_flags.js';
4
+ import { LogFunction } from './utils/logger.js';
4
5
  interface ZipFunctionOptions {
5
6
  archiveFormat?: ArchiveFormat;
6
7
  basePath?: string;
@@ -8,15 +9,17 @@ interface ZipFunctionOptions {
8
9
  featureFlags?: FeatureFlags;
9
10
  repositoryRoot?: string;
10
11
  zipGo?: boolean;
12
+ systemLog?: LogFunction;
13
+ debug?: boolean;
11
14
  }
12
- export declare type ZipFunctionsOptions = ZipFunctionOptions & {
15
+ export type ZipFunctionsOptions = ZipFunctionOptions & {
13
16
  configFileDirectories?: string[];
14
17
  manifest?: string;
15
18
  parallelLimit?: number;
16
19
  };
17
- export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, }?: ZipFunctionsOptions) => Promise<(Omit<import("./function.js").FunctionArchive, "runtime"> & {
20
+ export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, systemLog, debug, }?: ZipFunctionsOptions) => Promise<(Omit<import("./function.js").FunctionArchive, "runtime"> & {
18
21
  runtime: import("./main.js").RuntimeType;
19
22
  schedule?: string | undefined;
20
23
  })[]>;
21
- export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, }?: ZipFunctionOptions) => Promise<import("./utils/format_result.js").FunctionResult | undefined>;
24
+ export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, systemLog, debug, }?: ZipFunctionOptions) => Promise<import("./utils/format_result.js").FunctionResult | undefined>;
22
25
  export {};
package/dist/zip.js CHANGED
@@ -5,9 +5,12 @@ import { getFlags } from './feature_flags.js';
5
5
  import { createManifest } from './manifest.js';
6
6
  import { getFunctionsFromPaths } from './runtimes/index.js';
7
7
  import { addArchiveSize } from './utils/archive_size.js';
8
+ import { RuntimeCache } from './utils/cache.js';
8
9
  import { formatZipResult } from './utils/format_result.js';
9
10
  import { listFunctionsDirectories, resolveFunctionsDirectories } from './utils/fs.js';
11
+ import { getLogger } from './utils/logger.js';
10
12
  import { nonNullable } from './utils/non_nullable.js';
13
+ import { endTimer, startTimer } from './utils/timer.js';
11
14
  const DEFAULT_PARALLEL_LIMIT = 5;
12
15
  // TODO: now that we have types, do we still need runtime validation?
13
16
  const validateArchiveFormat = (archiveFormat) => {
@@ -17,12 +20,20 @@ const validateArchiveFormat = (archiveFormat) => {
17
20
  };
18
21
  // Zip `srcFolder/*` (Node.js or Go files) to `destFolder/*.zip` so it can be
19
22
  // used by AWS Lambda
20
- export const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFormat = 'zip', basePath, config = {}, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, } = {}) {
23
+ export const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFormat = 'zip', basePath, config = {}, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, systemLog, debug, } = {}) {
21
24
  validateArchiveFormat(archiveFormat);
25
+ const logger = getLogger(systemLog, debug);
26
+ const cache = new RuntimeCache();
22
27
  const featureFlags = getFlags(inputFeatureFlags);
23
28
  const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
24
29
  const [paths] = await Promise.all([listFunctionsDirectories(srcFolders), fs.mkdir(destFolder, { recursive: true })]);
25
- const functions = await getFunctionsFromPaths(paths, { config, configFileDirectories, dedupe: true, featureFlags });
30
+ const functions = await getFunctionsFromPaths(paths, {
31
+ cache,
32
+ config,
33
+ configFileDirectories,
34
+ dedupe: true,
35
+ featureFlags,
36
+ });
26
37
  const results = await pMap(functions.values(), async (func) => {
27
38
  const functionFlags = {
28
39
  ...featureFlags,
@@ -30,9 +41,11 @@ export const zipFunctions = async function (relativeSrcFolders, destFolder, { ar
30
41
  // extend the feature flags with `zisi_pure_esm_mjs` enabled.
31
42
  ...(func.config.nodeModuleFormat === "esm" /* ModuleFormat.ESM */ ? { zisi_pure_esm_mjs: true } : {}),
32
43
  };
44
+ const startIntervalTime = startTimer();
33
45
  const zipResult = await func.runtime.zipFunction({
34
46
  archiveFormat,
35
47
  basePath,
48
+ cache,
36
49
  config: func.config,
37
50
  destFolder,
38
51
  extension: func.extension,
@@ -46,6 +59,14 @@ export const zipFunctions = async function (relativeSrcFolders, destFolder, { ar
46
59
  srcPath: func.srcPath,
47
60
  stat: func.stat,
48
61
  });
62
+ const durationNs = endTimer(startIntervalTime);
63
+ const logObject = {
64
+ name: func.name,
65
+ config: func.config,
66
+ featureFlags: functionFlags,
67
+ durationNs,
68
+ };
69
+ logger.system(`Function details: ${JSON.stringify(logObject, null, 2)}`);
49
70
  return { ...zipResult, mainFile: func.mainFile, name: func.name, runtime: func.runtime };
50
71
  }, {
51
72
  concurrency: parallelLimit,
@@ -59,11 +80,14 @@ export const zipFunctions = async function (relativeSrcFolders, destFolder, { ar
59
80
  }
60
81
  return formattedResults;
61
82
  };
62
- export const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, } = {}) {
83
+ // eslint-disable-next-line max-statements
84
+ export const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, systemLog, debug, } = {}) {
63
85
  validateArchiveFormat(archiveFormat);
86
+ const logger = getLogger(systemLog, debug);
64
87
  const featureFlags = getFlags(inputFeatureFlags);
65
88
  const srcPath = resolve(relativeSrcPath);
66
- const functions = await getFunctionsFromPaths([srcPath], { config: inputConfig, dedupe: true, featureFlags });
89
+ const cache = new RuntimeCache();
90
+ const functions = await getFunctionsFromPaths([srcPath], { cache, config: inputConfig, dedupe: true, featureFlags });
67
91
  if (functions.size === 0) {
68
92
  return;
69
93
  }
@@ -75,9 +99,11 @@ export const zipFunction = async function (relativeSrcPath, destFolder, { archiv
75
99
  // extend the feature flags with `zisi_pure_esm_mjs` enabled.
76
100
  ...(config.nodeModuleFormat === "esm" /* ModuleFormat.ESM */ ? { zisi_pure_esm_mjs: true } : {}),
77
101
  };
102
+ const startIntervalTime = startTimer();
78
103
  const zipResult = await runtime.zipFunction({
79
104
  archiveFormat,
80
105
  basePath,
106
+ cache,
81
107
  config,
82
108
  destFolder,
83
109
  extension,
@@ -91,6 +117,14 @@ export const zipFunction = async function (relativeSrcPath, destFolder, { archiv
91
117
  srcPath,
92
118
  stat: stats,
93
119
  });
120
+ const durationNs = endTimer(startIntervalTime);
121
+ const logObject = {
122
+ name,
123
+ config,
124
+ featureFlags: functionFlags,
125
+ durationNs,
126
+ };
127
+ logger.system(`Function details: ${JSON.stringify(logObject, null, 2)}`);
94
128
  return formatZipResult({ ...zipResult, mainFile, name, runtime });
95
129
  };
96
130
  //# sourceMappingURL=zip.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "8.0.0",
3
+ "version": "8.2.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -63,21 +63,20 @@
63
63
  "del": "^7.0.0",
64
64
  "end-of-stream": "^1.4.4",
65
65
  "es-module-lexer": "^1.0.0",
66
- "execa": "^5.0.0",
67
- "filter-obj": "^2.0.1",
68
- "find-up": "^5.0.0",
66
+ "execa": "^6.0.0",
67
+ "filter-obj": "^5.0.0",
68
+ "find-up": "^6.0.0",
69
69
  "glob": "^8.0.3",
70
70
  "is-builtin-module": "^3.1.0",
71
- "is-path-inside": "^3.0.3",
72
- "junk": "^3.1.0",
73
- "locate-path": "^6.0.0",
71
+ "is-path-inside": "^4.0.0",
72
+ "junk": "^4.0.0",
73
+ "locate-path": "^7.0.0",
74
74
  "merge-options": "^3.0.4",
75
75
  "minimatch": "^5.0.0",
76
76
  "normalize-path": "^3.0.0",
77
- "p-map": "^4.0.0",
77
+ "p-map": "^5.0.0",
78
78
  "path-exists": "^5.0.0",
79
79
  "precinct": "^9.0.1",
80
- "read-package-json-fast": "^2.0.2",
81
80
  "require-package-name": "^2.0.1",
82
81
  "resolve": "^2.0.0-next.1",
83
82
  "semver": "^7.0.0",
@@ -88,16 +87,17 @@
88
87
  },
89
88
  "devDependencies": {
90
89
  "@babel/types": "^7.15.6",
91
- "@netlify/eslint-config-node": "^7.0.0",
90
+ "@netlify/eslint-config-node": "^7.0.1",
92
91
  "@types/archiver": "^5.1.1",
93
92
  "@types/end-of-stream": "^1.4.1",
94
93
  "@types/node": "^14.18.32",
95
94
  "@types/normalize-path": "^3.0.0",
96
95
  "@types/resolve": "^1.20.2",
97
96
  "@types/semver": "^7.3.8",
97
+ "@types/tmp": "^0.2.3",
98
98
  "@types/unixify": "^1.0.0",
99
99
  "@types/yargs": "^17.0.4",
100
- "@vitest/coverage-c8": "^0.24.3",
100
+ "@vitest/coverage-c8": "^0.25.0",
101
101
  "cpy": "^9.0.0",
102
102
  "deepmerge": "^4.2.2",
103
103
  "get-stream": "^6.0.0",
@@ -107,8 +107,8 @@
107
107
  "source-map-support": "^0.5.21",
108
108
  "throat": "^6.0.1",
109
109
  "typescript": "^4.8.4",
110
- "vite": "^3.1.8",
111
- "vitest": "^0.24.3"
110
+ "vite": "^4.0.0",
111
+ "vitest": "^0.25.0"
112
112
  },
113
113
  "engines": {
114
114
  "node": "^14.16.0 || >=16.0.0"