@netlify/zip-it-and-ship-it 5.3.0 → 5.4.1

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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/archive.js +16 -16
  3. package/dist/bin.js +13 -35
  4. package/dist/feature_flags.js +4 -1
  5. package/dist/main.d.ts +13 -4
  6. package/dist/main.js +54 -57
  7. package/dist/manifest.js +4 -13
  8. package/dist/runtimes/detect_runtime.js +16 -27
  9. package/dist/runtimes/go/builder.js +5 -14
  10. package/dist/runtimes/go/index.js +35 -47
  11. package/dist/runtimes/index.d.ts +8 -1
  12. package/dist/runtimes/index.js +54 -41
  13. package/dist/runtimes/node/bundlers/esbuild/bundler.js +81 -92
  14. package/dist/runtimes/node/bundlers/esbuild/index.js +14 -18
  15. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +13 -22
  16. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +3 -13
  17. package/dist/runtimes/node/bundlers/esbuild/special_cases.js +8 -17
  18. package/dist/runtimes/node/bundlers/esbuild/src_files.js +28 -41
  19. package/dist/runtimes/node/bundlers/nft/es_modules.js +16 -22
  20. package/dist/runtimes/node/bundlers/nft/index.js +47 -60
  21. package/dist/runtimes/node/bundlers/nft/transpile.js +3 -12
  22. package/dist/runtimes/node/bundlers/zisi/index.js +7 -13
  23. package/dist/runtimes/node/bundlers/zisi/list_imports.js +5 -14
  24. package/dist/runtimes/node/bundlers/zisi/published.js +8 -19
  25. package/dist/runtimes/node/bundlers/zisi/resolve.js +37 -55
  26. package/dist/runtimes/node/bundlers/zisi/side_files.js +6 -17
  27. package/dist/runtimes/node/bundlers/zisi/src_files.js +58 -75
  28. package/dist/runtimes/node/bundlers/zisi/traverse.js +41 -56
  29. package/dist/runtimes/node/bundlers/zisi/tree_files.js +8 -19
  30. package/dist/runtimes/node/finder.d.ts +4 -6
  31. package/dist/runtimes/node/finder.js +48 -65
  32. package/dist/runtimes/node/in_source_config/index.js +5 -14
  33. package/dist/runtimes/node/index.js +65 -87
  34. package/dist/runtimes/node/parser/index.js +11 -20
  35. package/dist/runtimes/node/utils/detect_es_module.js +4 -15
  36. package/dist/runtimes/node/utils/included_files.js +3 -12
  37. package/dist/runtimes/node/utils/package_json.js +19 -27
  38. package/dist/runtimes/node/utils/zip.js +63 -94
  39. package/dist/runtimes/runtime.d.ts +7 -1
  40. package/dist/runtimes/rust/builder.js +23 -36
  41. package/dist/runtimes/rust/index.js +48 -60
  42. package/dist/utils/archive_size.js +5 -14
  43. package/dist/utils/format_result.js +6 -1
  44. package/dist/utils/fs.d.ts +6 -10
  45. package/dist/utils/fs.js +35 -63
  46. package/dist/zip.js +60 -73
  47. package/dist/zip_binary.js +5 -16
  48. package/package.json +7 -15
package/dist/zip.js CHANGED
@@ -1,27 +1,18 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.zipFunctions = exports.zipFunction = void 0;
7
+ const fs_1 = require("fs");
16
8
  const path_1 = require("path");
17
- const make_dir_1 = __importDefault(require("make-dir"));
18
9
  const p_map_1 = __importDefault(require("p-map"));
19
10
  const feature_flags_1 = require("./feature_flags");
20
11
  const manifest_1 = require("./manifest");
21
12
  const runtimes_1 = require("./runtimes");
22
13
  const archive_size_1 = require("./utils/archive_size");
23
14
  const format_result_1 = require("./utils/format_result");
24
- const fs_1 = require("./utils/fs");
15
+ const fs_2 = require("./utils/fs");
25
16
  const non_nullable_1 = require("./utils/non_nullable");
26
17
  const DEFAULT_PARALLEL_LIMIT = 5;
27
18
  // TODO: now that we have types, do we still need runtime validation?
@@ -32,74 +23,70 @@ const validateArchiveFormat = (archiveFormat) => {
32
23
  };
33
24
  // Zip `srcFolder/*` (Node.js or Go files) to `destFolder/*.zip` so it can be
34
25
  // used by AWS Lambda
35
- const zipFunctions = function (relativeSrcFolders, destFolder, { archiveFormat = 'zip', basePath, config = {}, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, } = {}) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- validateArchiveFormat(archiveFormat);
38
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
39
- const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
40
- const [paths] = yield Promise.all([(0, fs_1.listFunctionsDirectories)(srcFolders), (0, make_dir_1.default)(destFolder)]);
41
- const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { config, dedupe: true, featureFlags });
42
- const results = yield (0, p_map_1.default)(functions.values(), (func) => __awaiter(this, void 0, void 0, function* () {
43
- const zipResult = yield func.runtime.zipFunction({
44
- archiveFormat,
45
- basePath,
46
- config: func.config,
47
- destFolder,
48
- extension: func.extension,
49
- filename: func.filename,
50
- mainFile: func.mainFile,
51
- name: func.name,
52
- repositoryRoot,
53
- runtime: func.runtime,
54
- srcDir: func.srcDir,
55
- srcPath: func.srcPath,
56
- stat: func.stat,
57
- featureFlags,
58
- });
59
- return Object.assign(Object.assign({}, zipResult), { mainFile: func.mainFile, name: func.name, runtime: func.runtime });
60
- }), {
61
- concurrency: parallelLimit,
62
- });
63
- const formattedResults = yield Promise.all(results.filter(non_nullable_1.nonNullable).map((result) => __awaiter(this, void 0, void 0, function* () {
64
- const resultWithSize = yield (0, archive_size_1.addArchiveSize)(result);
65
- return (0, format_result_1.formatZipResult)(resultWithSize);
66
- })));
67
- if (manifest !== undefined) {
68
- yield (0, manifest_1.createManifest)({ functions: formattedResults, path: (0, path_1.resolve)(manifest) });
69
- }
70
- return formattedResults;
71
- });
72
- };
73
- exports.zipFunctions = zipFunctions;
74
- const zipFunction = function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, } = {}) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- validateArchiveFormat(archiveFormat);
77
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
78
- const srcPath = (0, path_1.resolve)(relativeSrcPath);
79
- const functions = yield (0, runtimes_1.getFunctionsFromPaths)([srcPath], { config: inputConfig, dedupe: true, featureFlags });
80
- if (functions.size === 0) {
81
- return;
82
- }
83
- const { config, extension, filename, mainFile, name, runtime, srcDir, stat: stats, } = functions.values().next().value;
84
- yield (0, make_dir_1.default)(destFolder);
85
- const zipResult = yield runtime.zipFunction({
26
+ const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFormat = 'zip', basePath, config = {}, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, } = {}) {
27
+ validateArchiveFormat(archiveFormat);
28
+ const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
29
+ const srcFolders = (0, fs_2.resolveFunctionsDirectories)(relativeSrcFolders);
30
+ const [paths] = await Promise.all([(0, fs_2.listFunctionsDirectories)(srcFolders), fs_1.promises.mkdir(destFolder, { recursive: true })]);
31
+ const functions = await (0, runtimes_1.getFunctionsFromPaths)(paths, { config, dedupe: true, featureFlags });
32
+ const results = await (0, p_map_1.default)(functions.values(), async (func) => {
33
+ const zipResult = await func.runtime.zipFunction({
86
34
  archiveFormat,
87
35
  basePath,
88
- config,
36
+ config: func.config,
89
37
  destFolder,
90
- extension,
91
- featureFlags,
92
- filename,
93
- mainFile,
94
- name,
38
+ extension: func.extension,
39
+ filename: func.filename,
40
+ mainFile: func.mainFile,
41
+ name: func.name,
95
42
  repositoryRoot,
96
- runtime,
97
- srcDir,
98
- srcPath,
99
- stat: stats,
43
+ runtime: func.runtime,
44
+ srcDir: func.srcDir,
45
+ srcPath: func.srcPath,
46
+ stat: func.stat,
47
+ featureFlags,
100
48
  });
101
- return (0, format_result_1.formatZipResult)(Object.assign(Object.assign({}, zipResult), { mainFile, name, runtime }));
49
+ return { ...zipResult, mainFile: func.mainFile, name: func.name, runtime: func.runtime };
50
+ }, {
51
+ concurrency: parallelLimit,
52
+ });
53
+ const formattedResults = await Promise.all(results.filter(non_nullable_1.nonNullable).map(async (result) => {
54
+ const resultWithSize = await (0, archive_size_1.addArchiveSize)(result);
55
+ return (0, format_result_1.formatZipResult)(resultWithSize);
56
+ }));
57
+ if (manifest !== undefined) {
58
+ await (0, manifest_1.createManifest)({ functions: formattedResults, path: (0, path_1.resolve)(manifest) });
59
+ }
60
+ return formattedResults;
61
+ };
62
+ exports.zipFunctions = zipFunctions;
63
+ const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, } = {}) {
64
+ validateArchiveFormat(archiveFormat);
65
+ const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
66
+ const srcPath = (0, path_1.resolve)(relativeSrcPath);
67
+ const functions = await (0, runtimes_1.getFunctionsFromPaths)([srcPath], { config: inputConfig, dedupe: true, featureFlags });
68
+ if (functions.size === 0) {
69
+ return;
70
+ }
71
+ const { config, extension, filename, mainFile, name, runtime, srcDir, stat: stats, } = functions.values().next().value;
72
+ await fs_1.promises.mkdir(destFolder, { recursive: true });
73
+ const zipResult = await runtime.zipFunction({
74
+ archiveFormat,
75
+ basePath,
76
+ config,
77
+ destFolder,
78
+ extension,
79
+ featureFlags,
80
+ filename,
81
+ mainFile,
82
+ name,
83
+ repositoryRoot,
84
+ runtime,
85
+ srcDir,
86
+ srcPath,
87
+ stat: stats,
102
88
  });
89
+ return (0, format_result_1.formatZipResult)({ ...zipResult, mainFile, name, runtime });
103
90
  };
104
91
  exports.zipFunction = zipFunction;
105
92
  //# sourceMappingURL=zip.js.map
@@ -1,24 +1,13 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.zipBinary = void 0;
13
4
  const archive_1 = require("./archive");
14
5
  // Zip a binary function file
15
- const zipBinary = function ({ destPath, filename, runtime, srcPath, stat, }) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { archive, output } = (0, archive_1.startZip)(destPath);
18
- (0, archive_1.addZipFile)(archive, srcPath, filename, stat);
19
- (0, archive_1.addZipContent)(archive, JSON.stringify({ runtime: runtime.name }), 'netlify-toolchain');
20
- yield (0, archive_1.endZip)(archive, output);
21
- });
6
+ const zipBinary = async function ({ destPath, filename, runtime, srcPath, stat, }) {
7
+ const { archive, output } = (0, archive_1.startZip)(destPath);
8
+ (0, archive_1.addZipFile)(archive, srcPath, filename, stat);
9
+ (0, archive_1.addZipContent)(archive, JSON.stringify({ runtime: runtime.name }), 'netlify-toolchain');
10
+ await (0, archive_1.endZip)(archive, output);
22
11
  };
23
12
  exports.zipBinary = zipBinary;
24
13
  //# sourceMappingURL=zip_binary.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "5.3.0",
3
+ "version": "5.4.1",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {
@@ -11,6 +11,7 @@
11
11
  "dist/**/*.d.ts"
12
12
  ],
13
13
  "scripts": {
14
+ "prepare": "husky install node_modules/@netlify/eslint-config-node/.husky/",
14
15
  "prepublishOnly": "npm ci && npm test",
15
16
  "prepack": "npm run build",
16
17
  "build": "tsc",
@@ -25,7 +26,7 @@
25
26
  "format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
26
27
  "format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
27
28
  "test:dev": "npm run build && ava",
28
- "test:ci": "npm run build && nyc -r lcovonly -r text -r json ava"
29
+ "test:ci": "npm run build && c8 -r lcovonly -r text -r json ava"
29
30
  },
30
31
  "config": {
31
32
  "eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,tests,.github}/**/*.{js,ts,md,html}\" \"*.{js,ts,md,html}\" \".*.{js,ts,md,html}\"",
@@ -34,12 +35,6 @@
34
35
  "eslintIgnore": [
35
36
  "benchmarks/fixtures/**"
36
37
  ],
37
- "husky": {
38
- "hooks": {
39
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
40
- "pre-push": "npm run format"
41
- }
42
- },
43
38
  "keywords": [
44
39
  "api",
45
40
  "bundler",
@@ -74,7 +69,6 @@
74
69
  "is-builtin-module": "^3.1.0",
75
70
  "junk": "^3.1.0",
76
71
  "locate-path": "^6.0.0",
77
- "make-dir": "^3.1.0",
78
72
  "merge-options": "^3.0.4",
79
73
  "minimatch": "^3.0.4",
80
74
  "p-map": "^4.0.0",
@@ -93,27 +87,25 @@
93
87
  },
94
88
  "devDependencies": {
95
89
  "@babel/types": "^7.15.6",
96
- "@netlify/eslint-config-node": "^4.0.0",
90
+ "@netlify/eslint-config-node": "^4.1.5",
97
91
  "@types/archiver": "^5.1.1",
98
92
  "@types/end-of-stream": "^1.4.1",
99
93
  "@types/resolve": "^1.20.1",
100
94
  "@types/semver": "^7.3.8",
101
95
  "@types/unixify": "^1.0.0",
102
96
  "@types/yargs": "^17.0.4",
103
- "adm-zip": "0.5.5",
104
97
  "ava": "^3.0.0",
98
+ "c8": "^7.11.0",
105
99
  "cpy": "^8.0.0",
106
100
  "deepmerge": "^4.2.2",
107
101
  "get-stream": "^6.0.0",
108
- "husky": "^4.3.8",
102
+ "husky": "^7.0.4",
109
103
  "npm-run-all": "^4.1.5",
110
- "nyc": "^15.0.0",
111
104
  "p-every": "^2.0.0",
112
105
  "sinon": "^12.0.0",
113
106
  "sort-on": "^4.1.1",
114
107
  "source-map-support": "^0.5.20",
115
- "throat": "^6.0.1",
116
- "typescript": "^4.4.3"
108
+ "throat": "^6.0.1"
117
109
  },
118
110
  "engines": {
119
111
  "node": "^12.20.0 || ^14.14.0 || >=16.0.0"