@netlify/zip-it-and-ship-it 4.29.1 → 4.29.5

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.d.ts CHANGED
@@ -11,4 +11,5 @@ declare const addZipFile: (archive: Archiver, file: string, name: string, stat:
11
11
  declare const addZipContent: (archive: Archiver, content: Buffer | string, name: string) => void;
12
12
  declare const endZip: (archive: Archiver, output: Writable) => Promise<void>;
13
13
  export { startZip, addZipFile, addZipContent, endZip };
14
- export type { ArchiveFormat, Archiver as ZipArchive };
14
+ export type { ArchiveFormat };
15
+ export { Archiver as ZipArchive } from 'archiver';
package/dist/main.d.ts CHANGED
@@ -2,7 +2,6 @@ import './utils/polyfills';
2
2
  import { Config } from './config';
3
3
  import { FeatureFlags } from './feature_flags';
4
4
  import { RuntimeName } from './runtimes/runtime';
5
- import { zipFunction, zipFunctions } from './zip';
6
5
  interface ListedFunction {
7
6
  name: string;
8
7
  mainFile: string;
@@ -21,4 +20,5 @@ declare const listFunctions: (relativeSrcFolders: string | string[], { featureFl
21
20
  featureFlags?: FeatureFlags;
22
21
  }) => Promise<ListedFunction[]>;
23
22
  declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
24
- export { zipFunctions, zipFunction, listFunctions, listFunctionsFiles };
23
+ export { listFunctions, listFunctionsFiles };
24
+ export { zipFunction, zipFunctions } from './zip';
package/dist/main.js CHANGED
@@ -20,15 +20,12 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  return t;
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.listFunctionsFiles = exports.listFunctions = exports.zipFunction = exports.zipFunctions = void 0;
23
+ exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunctions = void 0;
24
24
  const path_1 = require("path");
25
25
  require("./utils/polyfills");
26
26
  const feature_flags_1 = require("./feature_flags");
27
27
  const runtimes_1 = require("./runtimes");
28
28
  const fs_1 = require("./utils/fs");
29
- const zip_1 = require("./zip");
30
- Object.defineProperty(exports, "zipFunction", { enumerable: true, get: function () { return zip_1.zipFunction; } });
31
- Object.defineProperty(exports, "zipFunctions", { enumerable: true, get: function () { return zip_1.zipFunctions; } });
32
29
  // List all Netlify Functions main entry files for a specific directory
33
30
  const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags } = {}) {
34
31
  return __awaiter(this, void 0, void 0, function* () {
@@ -75,4 +72,7 @@ const getSrcFiles = function (_a) {
75
72
  srcPath }, args));
76
73
  });
77
74
  };
75
+ var zip_1 = require("./zip");
76
+ Object.defineProperty(exports, "zipFunction", { enumerable: true, get: function () { return zip_1.zipFunction; } });
77
+ Object.defineProperty(exports, "zipFunctions", { enumerable: true, get: function () { return zip_1.zipFunctions; } });
78
78
  //# sourceMappingURL=main.js.map
@@ -17,6 +17,7 @@ const fs_1 = require("../../../../utils/fs");
17
17
  const bundler_target_1 = require("./bundler_target");
18
18
  const plugin_dynamic_imports_1 = require("./plugin_dynamic_imports");
19
19
  const plugin_native_modules_1 = require("./plugin_native_modules");
20
+ const plugin_node_builtin_1 = require("./plugin_node_builtin");
20
21
  // Maximum number of log messages that an esbuild instance will produce. This
21
22
  // limit is important to avoid out-of-memory errors due to too much data being
22
23
  // sent in the Go<>Node IPC channel.
@@ -45,6 +46,7 @@ const bundleJsFile = function ({ additionalModulePaths, basePath, config, extern
45
46
  const dynamicImportsIncludedPaths = new Set();
46
47
  // The list of esbuild plugins to enable for this build.
47
48
  const plugins = [
49
+ (0, plugin_node_builtin_1.getNodeBuiltinPlugin)(),
48
50
  (0, plugin_native_modules_1.getNativeModulesPlugin)(nativeNodeModules),
49
51
  (0, plugin_dynamic_imports_1.getDynamicImportsPlugin)({
50
52
  basePath,
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '@netlify/esbuild';
2
+ declare const getNodeBuiltinPlugin: () => Plugin;
3
+ export { getNodeBuiltinPlugin };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNodeBuiltinPlugin = void 0;
4
+ const getNodeBuiltinPlugin = () => ({
5
+ name: 'builtin-modules',
6
+ setup(build) {
7
+ build.onResolve({ filter: /^node:/ }, (args) => ({ path: args.path.slice('node:'.length), external: true }));
8
+ },
9
+ });
10
+ exports.getNodeBuiltinPlugin = getNodeBuiltinPlugin;
11
+ //# sourceMappingURL=plugin_node_builtin.js.map
@@ -27,7 +27,7 @@ const patchESMPackage = (path, fsCache) => __awaiter(void 0, void 0, void 0, fun
27
27
  const patchedPackageJson = Object.assign(Object.assign({}, packageJson), { type: 'commonjs' });
28
28
  return JSON.stringify(patchedPackageJson);
29
29
  });
30
- const shouldTranspile = (path, cache, reasons) => {
30
+ const shouldTranspile = (path, cache, esmPaths, reasons) => {
31
31
  if (cache.has(path)) {
32
32
  return cache.get(path);
33
33
  }
@@ -39,32 +39,33 @@ const shouldTranspile = (path, cache, reasons) => {
39
39
  return false;
40
40
  }
41
41
  const { parents } = reason;
42
- // If the path doesn't have any parents, it's safe to transpile.
42
+ // If the path is an entrypoint, we transpile it only if it's an ESM file.
43
43
  if (parents.size === 0) {
44
- cache.set(path, true);
45
- return true;
44
+ const isESM = esmPaths.has(path);
45
+ cache.set(path, isESM);
46
+ return isESM;
46
47
  }
47
48
  // The path should be transpiled if every parent will also be transpiled, or
48
49
  // if there is no parent.
49
- const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, reasons));
50
+ const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, esmPaths, reasons));
50
51
  cache.set(path, shouldTranspilePath);
51
52
  return shouldTranspilePath;
52
53
  };
53
54
  const transpileESM = ({ basePath, config, esmPaths, fsCache, reasons, }) => __awaiter(void 0, void 0, void 0, function* () {
54
55
  const cache = new Map();
55
- const paths = [...esmPaths].filter((path) => shouldTranspile(path, cache, reasons));
56
- const pathsSet = new Set(paths);
56
+ const pathsToTranspile = [...esmPaths].filter((path) => shouldTranspile(path, cache, esmPaths, reasons));
57
+ const pathsToTranspileSet = new Set(pathsToTranspile);
57
58
  const packageJsonPaths = [...reasons.entries()]
58
59
  .filter(([path, reason]) => {
59
60
  if ((0, path_1.basename)(path) !== 'package.json') {
60
61
  return false;
61
62
  }
62
- const needsPatch = [...reason.parents].some((parentPath) => pathsSet.has(parentPath));
63
+ const needsPatch = [...reason.parents].some((parentPath) => pathsToTranspileSet.has(parentPath));
63
64
  return needsPatch;
64
65
  })
65
66
  .map(([path]) => (basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path)));
66
67
  const rewrites = yield getPatchedESMPackages(packageJsonPaths, fsCache);
67
- yield Promise.all(paths.map((path) => __awaiter(void 0, void 0, void 0, function* () {
68
+ yield Promise.all(pathsToTranspile.map((path) => __awaiter(void 0, void 0, void 0, function* () {
68
69
  const absolutePath = basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path);
69
70
  const transpiled = yield (0, transpile_1.transpile)(absolutePath, config);
70
71
  rewrites.set(absolutePath, transpiled);
@@ -13,5 +13,6 @@ interface PackageJson {
13
13
  binary?: boolean;
14
14
  type?: string;
15
15
  }
16
+ declare const sanitisePackageJson: (packageJson: Record<string, unknown>) => PackageJson;
16
17
  declare const getPackageJson: (srcDir: string) => Promise<PackageJson>;
17
- export { getPackageJson, PackageJson };
18
+ export { getPackageJson, PackageJson, sanitisePackageJson };
@@ -12,8 +12,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getPackageJson = void 0;
15
+ exports.sanitisePackageJson = exports.getPackageJson = void 0;
16
16
  const pkg_dir_1 = __importDefault(require("pkg-dir"));
17
+ const sanitiseFiles = (files) => {
18
+ if (!Array.isArray(files)) {
19
+ return undefined;
20
+ }
21
+ return files.filter((file) => typeof file === 'string');
22
+ };
23
+ const sanitisePackageJson = (packageJson) => (Object.assign(Object.assign({}, packageJson), { files: sanitiseFiles(packageJson.files) }));
24
+ exports.sanitisePackageJson = sanitisePackageJson;
17
25
  // Retrieve the `package.json` of a specific project or module
18
26
  const getPackageJson = function (srcDir) {
19
27
  return __awaiter(this, void 0, void 0, function* () {
@@ -24,8 +32,9 @@ const getPackageJson = function (srcDir) {
24
32
  const packageJsonPath = `${packageRoot}/package.json`;
25
33
  try {
26
34
  // The path depends on the user's build, i.e. must be dynamic
27
- // eslint-disable-next-line import/no-dynamic-require, node/global-require
28
- return require(packageJsonPath);
35
+ // eslint-disable-next-line import/no-dynamic-require, node/global-require, @typescript-eslint/no-var-requires
36
+ const packageJson = require(packageJsonPath);
37
+ return sanitisePackageJson(packageJson);
29
38
  }
30
39
  catch (error) {
31
40
  throw new Error(`${packageJsonPath} is invalid JSON: ${error.message}`);
@@ -36,6 +36,7 @@ const make_dir_1 = __importDefault(require("make-dir"));
36
36
  const p_map_1 = __importDefault(require("p-map"));
37
37
  const unixify_1 = __importDefault(require("unixify"));
38
38
  const archive_1 = require("../../../archive");
39
+ const fs_2 = require("../../../utils/fs");
39
40
  const pStat = (0, util_1.promisify)(fs_1.default.stat);
40
41
  const pWriteFile = (0, util_1.promisify)(fs_1.default.writeFile);
41
42
  // Taken from https://www.npmjs.com/package/cpy.
@@ -67,7 +68,7 @@ const createDirectory = function ({ aliases = new Map(), basePath, destFolder, e
67
68
  });
68
69
  const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
69
70
  if (rewrites.has(srcFile)) {
70
- return pWriteFile(absoluteDestPath, rewrites.get(srcFile));
71
+ return (0, fs_2.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
71
72
  }
72
73
  return (0, cp_file_1.default)(srcFile, absoluteDestPath);
73
74
  }, { concurrency: COPY_FILE_CONCURRENCY });
@@ -17,5 +17,6 @@ declare const safeUnlink: (path: string) => Promise<void>;
17
17
  declare const listFunctionsDirectories: (srcFolders: string[]) => Promise<string[]>;
18
18
  declare const listFunctionsDirectory: (srcFolder: string) => Promise<string[]>;
19
19
  declare const resolveFunctionsDirectories: (input: string | string[]) => string[];
20
- export { cachedLstat, cachedReaddir, cachedReadFile, pLstat as lstat, getPathWithExtension, listFunctionsDirectories, listFunctionsDirectory, resolveFunctionsDirectories, safeUnlink, pStat as stat, pWriteFile as writeFile, pReadFile as readFile, };
20
+ declare const mkdirAndWriteFile: typeof pWriteFile;
21
+ export { cachedLstat, cachedReaddir, cachedReadFile, pLstat as lstat, getPathWithExtension, listFunctionsDirectories, listFunctionsDirectory, resolveFunctionsDirectories, safeUnlink, pStat as stat, pWriteFile as writeFile, pReadFile as readFile, mkdirAndWriteFile, };
21
22
  export type { FsCache };
package/dist/utils/fs.js CHANGED
@@ -8,11 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.readFile = exports.writeFile = exports.stat = exports.safeUnlink = exports.resolveFunctionsDirectories = exports.listFunctionsDirectory = exports.listFunctionsDirectories = exports.getPathWithExtension = exports.lstat = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
15
+ exports.mkdirAndWriteFile = exports.readFile = exports.writeFile = exports.stat = exports.safeUnlink = exports.resolveFunctionsDirectories = exports.listFunctionsDirectory = exports.listFunctionsDirectories = exports.getPathWithExtension = exports.lstat = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
13
16
  const fs_1 = require("fs");
14
17
  const path_1 = require("path");
15
18
  const util_1 = require("util");
19
+ const make_dir_1 = __importDefault(require("make-dir"));
16
20
  const non_nullable_1 = require("./non_nullable");
17
21
  const pLstat = (0, util_1.promisify)(fs_1.lstat);
18
22
  exports.lstat = pLstat;
@@ -93,4 +97,12 @@ const resolveFunctionsDirectories = (input) => {
93
97
  return absoluteDirectories;
94
98
  };
95
99
  exports.resolveFunctionsDirectories = resolveFunctionsDirectories;
100
+ const mkdirAndWriteFile = (path, ...params) => __awaiter(void 0, void 0, void 0, function* () {
101
+ if (typeof path === 'string') {
102
+ const directory = (0, path_1.dirname)(path);
103
+ yield (0, make_dir_1.default)(directory);
104
+ }
105
+ return pWriteFile(path, ...params);
106
+ });
107
+ exports.mkdirAndWriteFile = mkdirAndWriteFile;
96
108
  //# sourceMappingURL=fs.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "4.29.1",
3
+ "version": "4.29.5",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {
@@ -94,7 +94,7 @@
94
94
  },
95
95
  "devDependencies": {
96
96
  "@babel/types": "^7.15.6",
97
- "@netlify/eslint-config-node": "^3.3.5",
97
+ "@netlify/eslint-config-node": "^3.3.7",
98
98
  "@types/archiver": "^5.1.1",
99
99
  "@types/end-of-stream": "^1.4.1",
100
100
  "@types/resolve": "^1.20.1",