@netlify/zip-it-and-ship-it 5.6.0 → 5.7.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/config.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { FunctionSource } from './function';
2
- import type { NodeBundlerName, NodeVersion } from './runtimes/node';
2
+ import type { NodeVersionString } from './runtimes/node';
3
+ import type { NodeBundlerName } from './runtimes/node/bundlers';
3
4
  interface FunctionConfig {
4
5
  externalNodeModules?: string[];
5
6
  includedFiles?: string[];
@@ -7,7 +8,7 @@ interface FunctionConfig {
7
8
  ignoredNodeModules?: string[];
8
9
  nodeBundler?: NodeBundlerName;
9
10
  nodeSourcemap?: boolean;
10
- nodeVersion?: NodeVersion;
11
+ nodeVersion?: NodeVersionString;
11
12
  processDynamicNodeImports?: boolean;
12
13
  rustTargetDirectory?: string;
13
14
  schedule?: string;
@@ -8,6 +8,7 @@ const FLAGS = {
8
8
  defaultEsModulesToEsbuild: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_DEFAULT_ES_MODULES_TO_ESBUILD),
9
9
  parseWithEsbuild: false,
10
10
  traceWithNft: false,
11
+ zisi_pure_esm: false,
11
12
  };
12
13
  exports.defaultFlags = FLAGS;
13
14
  // List of supported flags and their default value.
@@ -78,6 +78,7 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
78
78
  bundlerWarnings,
79
79
  inputs,
80
80
  mainFile: normalizedMainFile,
81
+ moduleFormat: 'cjs',
81
82
  nativeNodeModules,
82
83
  nodeModulesWithDynamicImports,
83
84
  srcFiles: [...supportingSrcFiles, ...bundlePaths.keys()],
@@ -1,8 +1,9 @@
1
1
  import type { Message } from '@netlify/esbuild';
2
- import type { NodeBundlerName } from '..';
3
2
  import { FunctionConfig } from '../../../config';
4
3
  import { FeatureFlag, FeatureFlags } from '../../../feature_flags';
5
4
  import { FunctionSource } from '../../../function';
5
+ import { ModuleFormat } from '../utils/module_format';
6
+ export declare type NodeBundlerName = 'esbuild' | 'esbuild_zisi' | 'nft' | 'zisi';
6
7
  declare type BundlerWarning = Message;
7
8
  declare type CleanupFunction = () => Promise<void>;
8
9
  declare type NativeNodeModules = Record<string, Record<string, string | undefined>>;
@@ -20,6 +21,7 @@ declare type BundleFunction = (args: {
20
21
  cleanupFunction?: CleanupFunction;
21
22
  inputs: string[];
22
23
  mainFile: string;
24
+ moduleFormat: ModuleFormat;
23
25
  nativeNodeModules?: NativeNodeModules;
24
26
  nodeModulesWithDynamicImports?: string[];
25
27
  srcFiles: string[];
@@ -36,5 +38,10 @@ interface NodeBundler {
36
38
  getSrcFiles: GetSrcFilesFunction;
37
39
  }
38
40
  declare const getBundler: (name: NodeBundlerName) => NodeBundler;
39
- export { getBundler };
41
+ declare const getDefaultBundler: ({ extension, mainFile, featureFlags, }: {
42
+ extension: string;
43
+ mainFile: string;
44
+ featureFlags: FeatureFlags;
45
+ }) => Promise<NodeBundlerName>;
46
+ export { getBundler, getDefaultBundler };
40
47
  export type { BundleFunction, GetSrcFilesFunction, NativeNodeModules };
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBundler = void 0;
6
+ exports.getDefaultBundler = exports.getBundler = void 0;
7
+ const detect_es_module_1 = require("../utils/detect_es_module");
7
8
  const esbuild_1 = __importDefault(require("./esbuild"));
8
9
  const nft_1 = __importDefault(require("./nft"));
9
10
  const zisi_1 = __importDefault(require("./zisi"));
@@ -21,4 +22,23 @@ const getBundler = (name) => {
21
22
  }
22
23
  };
23
24
  exports.getBundler = getBundler;
25
+ // We use ZISI as the default bundler, except for certain extensions, for which
26
+ // esbuild is the only option.
27
+ const getDefaultBundler = async ({ extension, mainFile, featureFlags, }) => {
28
+ const { defaultEsModulesToEsbuild, traceWithNft } = featureFlags;
29
+ if (['.mjs', '.ts'].includes(extension)) {
30
+ return 'esbuild';
31
+ }
32
+ if (traceWithNft) {
33
+ return 'nft';
34
+ }
35
+ if (defaultEsModulesToEsbuild) {
36
+ const isEsModule = await (0, detect_es_module_1.detectEsModule)({ mainFile });
37
+ if (isEsModule) {
38
+ return 'esbuild';
39
+ }
40
+ }
41
+ return 'zisi';
42
+ };
43
+ exports.getDefaultBundler = getDefaultBundler;
24
44
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,18 @@
1
1
  import { NodeFileTraceReasons } from '@vercel/nft';
2
2
  import type { FunctionConfig } from '../../../../config';
3
+ import { FeatureFlags } from '../../../../feature_flags';
3
4
  import { FsCache } from '../../../../utils/fs';
4
- declare const transpileESM: ({ basePath, config, esmPaths, fsCache, reasons, }: {
5
+ import { ModuleFormat } from '../../utils/module_format';
6
+ declare const processESM: ({ basePath, config, esmPaths, featureFlags, fsCache, mainFile, reasons, }: {
5
7
  basePath: string | undefined;
6
8
  config: FunctionConfig;
7
9
  esmPaths: Set<string>;
10
+ featureFlags: FeatureFlags;
8
11
  fsCache: FsCache;
12
+ mainFile: string;
9
13
  reasons: NodeFileTraceReasons;
10
- }) => Promise<Map<string, string>>;
11
- export { transpileESM };
14
+ }) => Promise<{
15
+ rewrites?: Map<string, string> | undefined;
16
+ moduleFormat: ModuleFormat;
17
+ }>;
18
+ export { processESM };
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transpileESM = void 0;
3
+ exports.processESM = void 0;
4
4
  const path_1 = require("path");
5
5
  const fs_1 = require("../../../../utils/fs");
6
+ const node_version_1 = require("../../utils/node_version");
7
+ const package_json_1 = require("../../utils/package_json");
6
8
  const transpile_1 = require("./transpile");
7
9
  const getPatchedESMPackages = async (packages, fsCache) => {
8
10
  const patchedPackages = await Promise.all(packages.map((path) => patchESMPackage(path, fsCache)));
@@ -12,6 +14,11 @@ const getPatchedESMPackages = async (packages, fsCache) => {
12
14
  });
13
15
  return patchedPackagesMap;
14
16
  };
17
+ const isEntrypointESM = ({ basePath, esmPaths, mainFile, }) => {
18
+ const absoluteESMPaths = new Set([...esmPaths].map((path) => resolvePath(path, basePath)));
19
+ const entrypointIsESM = absoluteESMPaths.has(mainFile);
20
+ return entrypointIsESM;
21
+ };
15
22
  const patchESMPackage = async (path, fsCache) => {
16
23
  const file = (await (0, fs_1.cachedReadFile)(fsCache, path, 'utf8'));
17
24
  const packageJson = JSON.parse(file);
@@ -21,6 +28,28 @@ const patchESMPackage = async (path, fsCache) => {
21
28
  };
22
29
  return JSON.stringify(patchedPackageJson);
23
30
  };
31
+ const processESM = async ({ basePath, config, esmPaths, featureFlags, fsCache, mainFile, reasons, }) => {
32
+ const entrypointIsESM = isEntrypointESM({ basePath, esmPaths, mainFile });
33
+ if (!entrypointIsESM) {
34
+ return {
35
+ moduleFormat: 'cjs',
36
+ };
37
+ }
38
+ const packageJson = await (0, package_json_1.getPackageJson)((0, path_1.dirname)(mainFile));
39
+ const nodeSupport = (0, node_version_1.getNodeSupportMatrix)(config.nodeVersion);
40
+ if (featureFlags.zisi_pure_esm && packageJson.type === 'module' && nodeSupport.esm) {
41
+ return {
42
+ moduleFormat: 'esm',
43
+ };
44
+ }
45
+ const rewrites = await transpileESM({ basePath, config, esmPaths, fsCache, reasons });
46
+ return {
47
+ moduleFormat: 'cjs',
48
+ rewrites,
49
+ };
50
+ };
51
+ exports.processESM = processESM;
52
+ const resolvePath = (relativePath, basePath) => basePath ? (0, path_1.resolve)(basePath, relativePath) : (0, path_1.resolve)(relativePath);
24
53
  const shouldTranspile = (path, cache, esmPaths, reasons) => {
25
54
  if (cache.has(path)) {
26
55
  return cache.get(path);
@@ -60,11 +89,10 @@ const transpileESM = async ({ basePath, config, esmPaths, fsCache, reasons, }) =
60
89
  .map(([path]) => (basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path)));
61
90
  const rewrites = await getPatchedESMPackages(packageJsonPaths, fsCache);
62
91
  await Promise.all(pathsToTranspile.map(async (path) => {
63
- const absolutePath = basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path);
92
+ const absolutePath = resolvePath(path, basePath);
64
93
  const transpiled = await (0, transpile_1.transpile)(absolutePath, config);
65
94
  rewrites.set(absolutePath, transpiled);
66
95
  }));
67
96
  return rewrites;
68
97
  };
69
- exports.transpileESM = transpileESM;
70
98
  //# sourceMappingURL=es_modules.js.map
@@ -15,12 +15,13 @@ const es_modules_1 = require("./es_modules");
15
15
  // Paths that will be excluded from the tracing process.
16
16
  const ignore = ['node_modules/aws-sdk/**'];
17
17
  const appearsToBeModuleName = (name) => !name.startsWith('.');
18
- const bundle = async ({ basePath, config, mainFile, pluginsModulesPath, repositoryRoot = basePath, }) => {
18
+ const bundle = async ({ basePath, config, featureFlags, mainFile, pluginsModulesPath, repositoryRoot = basePath, }) => {
19
19
  const { includedFiles = [], includedFilesBasePath } = config;
20
20
  const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath || basePath);
21
- const { paths: dependencyPaths, rewrites } = await traceFilesAndTranspile({
21
+ const { moduleFormat, paths: dependencyPaths, rewrites, } = await traceFilesAndTranspile({
22
22
  basePath: repositoryRoot,
23
23
  config,
24
+ featureFlags,
24
25
  mainFile,
25
26
  pluginsModulesPath,
26
27
  });
@@ -32,6 +33,7 @@ const bundle = async ({ basePath, config, mainFile, pluginsModulesPath, reposito
32
33
  basePath: (0, base_path_1.getBasePath)(dirnames),
33
34
  inputs: dependencyPaths,
34
35
  mainFile,
36
+ moduleFormat,
35
37
  rewrites,
36
38
  srcFiles,
37
39
  };
@@ -41,7 +43,7 @@ const ignoreFunction = (path) => {
41
43
  const shouldIgnore = ignore.some((expression) => (0, minimatch_1.default)(normalizedPath, expression));
42
44
  return shouldIgnore;
43
45
  };
44
- const traceFilesAndTranspile = async function ({ basePath, config, mainFile, pluginsModulesPath, }) {
46
+ const traceFilesAndTranspile = async function ({ basePath, config, featureFlags, mainFile, pluginsModulesPath, }) {
45
47
  const fsCache = {};
46
48
  const { fileList: dependencyPaths, esmFileList, reasons, } = await (0, nft_1.nodeFileTrace)([mainFile], {
47
49
  base: basePath,
@@ -75,8 +77,17 @@ const traceFilesAndTranspile = async function ({ basePath, config, mainFile, plu
75
77
  },
76
78
  });
77
79
  const normalizedDependencyPaths = [...dependencyPaths].map((path) => basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path));
78
- const rewrites = await (0, es_modules_1.transpileESM)({ basePath, config, esmPaths: esmFileList, fsCache, reasons });
80
+ const { moduleFormat, rewrites } = await (0, es_modules_1.processESM)({
81
+ basePath,
82
+ config,
83
+ esmPaths: esmFileList,
84
+ featureFlags,
85
+ fsCache,
86
+ mainFile,
87
+ reasons,
88
+ });
79
89
  return {
90
+ moduleFormat,
80
91
  paths: normalizedDependencyPaths,
81
92
  rewrites,
82
93
  };
@@ -26,6 +26,7 @@ const bundle = async ({ basePath, config, extension, featureFlags, filename, mai
26
26
  basePath: (0, base_path_1.getBasePath)(dirnames),
27
27
  inputs: srcFiles,
28
28
  mainFile,
29
+ moduleFormat: 'cjs',
29
30
  srcFiles,
30
31
  };
31
32
  };
@@ -1,5 +1,4 @@
1
1
  import { Runtime } from '../runtime';
2
- export declare type NodeBundlerName = 'esbuild' | 'esbuild_zisi' | 'nft' | 'zisi';
3
- export { NodeVersion } from './utils/node_version';
2
+ export { NodeVersionString } from './utils/node_version';
4
3
  declare const runtime: Runtime;
5
4
  export default runtime;
@@ -8,33 +8,14 @@ const cp_file_1 = __importDefault(require("cp-file"));
8
8
  const bundlers_1 = require("./bundlers");
9
9
  const finder_1 = require("./finder");
10
10
  const in_source_config_1 = require("./in_source_config");
11
- const detect_es_module_1 = require("./utils/detect_es_module");
12
11
  const plugin_modules_path_1 = require("./utils/plugin_modules_path");
13
12
  const zip_1 = require("./utils/zip");
14
- // We use ZISI as the default bundler, except for certain extensions, for which
15
- // esbuild is the only option.
16
- const getDefaultBundler = async ({ extension, mainFile, featureFlags, }) => {
17
- const { defaultEsModulesToEsbuild, traceWithNft } = featureFlags;
18
- if (['.mjs', '.ts'].includes(extension)) {
19
- return 'esbuild';
20
- }
21
- if (traceWithNft) {
22
- return 'nft';
23
- }
24
- if (defaultEsModulesToEsbuild) {
25
- const isEsModule = await (0, detect_es_module_1.detectEsModule)({ mainFile });
26
- if (isEsModule) {
27
- return 'esbuild';
28
- }
29
- }
30
- return 'zisi';
31
- };
32
13
  // A proxy for the `getSrcFiles` function which adds a default `bundler` using
33
14
  // the `getDefaultBundler` function.
34
15
  const getSrcFilesWithBundler = async (parameters) => {
35
16
  const pluginsModulesPath = await (0, plugin_modules_path_1.getPluginsModulesPath)(parameters.srcDir);
36
17
  const bundlerName = parameters.config.nodeBundler ||
37
- (await getDefaultBundler({
18
+ (await (0, bundlers_1.getDefaultBundler)({
38
19
  extension: parameters.extension,
39
20
  featureFlags: parameters.featureFlags,
40
21
  mainFile: parameters.mainFile,
@@ -44,7 +25,7 @@ const getSrcFilesWithBundler = async (parameters) => {
44
25
  };
45
26
  const zipFunction = async function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
46
27
  const pluginsModulesPath = await (0, plugin_modules_path_1.getPluginsModulesPath)(srcDir);
47
- const bundlerName = config.nodeBundler || (await getDefaultBundler({ extension, mainFile, featureFlags }));
28
+ const bundlerName = config.nodeBundler || (await (0, bundlers_1.getDefaultBundler)({ extension, mainFile, featureFlags }));
48
29
  const bundler = (0, bundlers_1.getBundler)(bundlerName);
49
30
  // If the file is a zip, we assume the function is bundled and ready to go.
50
31
  // We simply copy it to the destination path with no further processing.
@@ -53,7 +34,7 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
53
34
  await (0, cp_file_1.default)(srcPath, destPath);
54
35
  return { config, path: destPath };
55
36
  }
56
- const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, inputs, mainFile: finalMainFile = mainFile, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = await bundler.bundle({
37
+ const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, inputs, mainFile: finalMainFile = mainFile, moduleFormat, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = await bundler.bundle({
57
38
  basePath,
58
39
  config,
59
40
  extension,
@@ -78,6 +59,7 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
78
59
  extension,
79
60
  filename,
80
61
  mainFile: finalMainFile,
62
+ moduleFormat,
81
63
  rewrites,
82
64
  srcFiles,
83
65
  });
@@ -0,0 +1,13 @@
1
+ import type { ModuleFormat } from './module_format';
2
+ interface EntryFile {
3
+ contents: string;
4
+ filename: string;
5
+ }
6
+ declare const getEntryFile: ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }: {
7
+ commonPrefix: string;
8
+ filename: string;
9
+ mainFile: string;
10
+ moduleFormat: ModuleFormat;
11
+ userNamespace: string;
12
+ }) => EntryFile;
13
+ export { EntryFile, getEntryFile };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntryFile = void 0;
4
+ const path_1 = require("path");
5
+ const normalize_path_1 = require("./normalize_path");
6
+ const getEntryFileContents = (mainPath, moduleFormat) => {
7
+ const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
8
+ if (moduleFormat === 'cjs') {
9
+ return `module.exports = require('${importPath}')`;
10
+ }
11
+ return `export { handler } from '${importPath}'`;
12
+ };
13
+ const getEntryFile = ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }) => {
14
+ const mainPath = (0, normalize_path_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
15
+ const extension = (0, path_1.extname)(filename);
16
+ const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
17
+ const contents = getEntryFileContents(mainPath, moduleFormat);
18
+ return {
19
+ contents,
20
+ filename: entryFilename,
21
+ };
22
+ };
23
+ exports.getEntryFile = getEntryFile;
24
+ //# sourceMappingURL=entry_file.js.map
@@ -0,0 +1 @@
1
+ export declare type ModuleFormat = 'cjs' | 'esm';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=module_format.js.map
@@ -1,6 +1,10 @@
1
1
  declare type SupportedVersionNumbers = 8 | 10 | 12 | 14;
2
- declare type NodeVersion = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`;
2
+ declare type NodeVersionString = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`;
3
+ interface NodeVersionSupport {
4
+ esm: boolean;
5
+ }
3
6
  declare const DEFAULT_NODE_VERSION = 14;
4
7
  declare const getNodeVersion: (configVersion?: string | undefined) => number;
8
+ declare const getNodeSupportMatrix: (configVersion?: string | undefined) => NodeVersionSupport;
5
9
  declare const parseVersion: (input: string | undefined) => number | undefined;
6
- export { DEFAULT_NODE_VERSION, getNodeVersion, parseVersion, NodeVersion };
10
+ export { DEFAULT_NODE_VERSION, getNodeSupportMatrix, getNodeVersion, NodeVersionString, NodeVersionSupport, parseVersion, };
@@ -1,12 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseVersion = exports.getNodeVersion = exports.DEFAULT_NODE_VERSION = void 0;
3
+ exports.parseVersion = exports.getNodeVersion = exports.getNodeSupportMatrix = exports.DEFAULT_NODE_VERSION = void 0;
4
4
  // Must match the default version used in Bitballoon.
5
5
  const DEFAULT_NODE_VERSION = 14;
6
6
  exports.DEFAULT_NODE_VERSION = DEFAULT_NODE_VERSION;
7
7
  const VERSION_REGEX = /(nodejs)?(\d+)\.x/;
8
8
  const getNodeVersion = (configVersion) => { var _a; return (_a = parseVersion(configVersion)) !== null && _a !== void 0 ? _a : DEFAULT_NODE_VERSION; };
9
9
  exports.getNodeVersion = getNodeVersion;
10
+ const getNodeSupportMatrix = (configVersion) => {
11
+ const versionNumber = getNodeVersion(configVersion);
12
+ return {
13
+ esm: versionNumber >= 14,
14
+ };
15
+ };
16
+ exports.getNodeSupportMatrix = getNodeSupportMatrix;
10
17
  // Takes a string in the format defined by the `NodeVersion` type and returns
11
18
  // the numeric major version (e.g. "nodejs14.x" => 14).
12
19
  const parseVersion = (input) => {
@@ -24,4 +31,5 @@ const parseVersion = (input) => {
24
31
  return version;
25
32
  };
26
33
  exports.parseVersion = parseVersion;
34
+ /* eslint-enable no-magic-numbers */
27
35
  //# sourceMappingURL=node_version.js.map
@@ -0,0 +1,6 @@
1
+ declare const normalizeFilePath: ({ commonPrefix, path, userNamespace, }: {
2
+ commonPrefix: string;
3
+ path: string;
4
+ userNamespace: string;
5
+ }) => string;
6
+ export { normalizeFilePath };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeFilePath = void 0;
7
+ const path_1 = require("path");
8
+ const unixify_1 = __importDefault(require("unixify"));
9
+ // `adm-zip` and `require()` expect Unix paths.
10
+ // We remove the common path prefix.
11
+ // With files on different Windows drives, we remove the drive letter.
12
+ const normalizeFilePath = function ({ commonPrefix, path, userNamespace, }) {
13
+ const userNamespacePathSegment = userNamespace ? `${userNamespace}${path_1.sep}` : '';
14
+ const pathA = (0, path_1.normalize)(path);
15
+ const pathB = pathA.replace(commonPrefix, userNamespacePathSegment);
16
+ const pathC = (0, unixify_1.default)(pathB);
17
+ return pathC;
18
+ };
19
+ exports.normalizeFilePath = normalizeFilePath;
20
+ //# sourceMappingURL=normalize_path.js.map
@@ -1,3 +1,4 @@
1
+ import type { ModuleFormat } from './module_format';
1
2
  declare type ArchiveFormat = 'none' | 'zip';
2
3
  interface ZipNodeParameters {
3
4
  aliases?: Map<string, string>;
@@ -6,6 +7,7 @@ interface ZipNodeParameters {
6
7
  extension: string;
7
8
  filename: string;
8
9
  mainFile: string;
10
+ moduleFormat: ModuleFormat;
9
11
  rewrites?: Map<string, string>;
10
12
  srcFiles: string[];
11
13
  }
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.zipNodeJs = void 0;
7
- /* eslint-disable max-lines */
8
7
  const buffer_1 = require("buffer");
9
8
  const fs_1 = require("fs");
10
9
  const os_1 = __importDefault(require("os"));
@@ -12,19 +11,21 @@ const path_1 = require("path");
12
11
  const cp_file_1 = __importDefault(require("cp-file"));
13
12
  const del_1 = __importDefault(require("del"));
14
13
  const p_map_1 = __importDefault(require("p-map"));
15
- const unixify_1 = __importDefault(require("unixify"));
16
14
  const archive_1 = require("../../../archive");
17
15
  const fs_2 = require("../../../utils/fs");
16
+ const entry_file_1 = require("./entry_file");
17
+ const normalize_path_1 = require("./normalize_path");
18
18
  // Taken from https://www.npmjs.com/package/cpy.
19
19
  const COPY_FILE_CONCURRENCY = os_1.default.cpus().length === 0 ? 2 : os_1.default.cpus().length * 2;
20
20
  // Sub-directory to place all user-defined files (i.e. everything other than
21
21
  // the entry file generated by zip-it-and-ship-it).
22
22
  const DEFAULT_USER_SUBDIRECTORY = 'src';
23
- const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, rewrites = new Map(), srcFiles, }) {
24
- const { contents: entryContents, filename: entryFilename } = getEntryFile({
23
+ const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites = new Map(), srcFiles, }) {
24
+ const { contents: entryContents, filename: entryFilename } = (0, entry_file_1.getEntryFile)({
25
25
  commonPrefix: basePath,
26
26
  filename,
27
27
  mainFile,
28
+ moduleFormat,
28
29
  userNamespace: DEFAULT_USER_SUBDIRECTORY,
29
30
  });
30
31
  const functionFolder = (0, path_1.join)(destFolder, (0, path_1.basename)(filename, extension));
@@ -36,7 +37,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
36
37
  // Copying source files.
37
38
  await (0, p_map_1.default)(srcFiles, (srcFile) => {
38
39
  const destPath = aliases.get(srcFile) || srcFile;
39
- const normalizedDestPath = normalizeFilePath({
40
+ const normalizedDestPath = (0, normalize_path_1.normalizeFilePath)({
40
41
  commonPrefix: basePath,
41
42
  path: destPath,
42
43
  userNamespace: DEFAULT_USER_SUBDIRECTORY,
@@ -49,7 +50,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
49
50
  }, { concurrency: COPY_FILE_CONCURRENCY });
50
51
  return functionFolder;
51
52
  };
52
- const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, rewrites, srcFiles, }) {
53
+ const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
53
54
  const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
54
55
  const { archive, output } = (0, archive_1.startZip)(destPath);
55
56
  const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
@@ -65,7 +66,7 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
65
66
  // than the entry file) to its own sub-directory.
66
67
  const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
67
68
  if (needsEntryFile) {
68
- const entryFile = getEntryFile({ commonPrefix: basePath, filename, mainFile, userNamespace });
69
+ const entryFile = (0, entry_file_1.getEntryFile)({ commonPrefix: basePath, filename, mainFile, moduleFormat, userNamespace });
69
70
  addEntryFileToZip(archive, entryFile);
70
71
  }
71
72
  const srcFilesInfos = await Promise.all(srcFiles.map(addStat));
@@ -100,18 +101,9 @@ const addStat = async function (srcFile) {
100
101
  const stat = await fs_1.promises.lstat(srcFile);
101
102
  return { srcFile, stat };
102
103
  };
103
- const getEntryFile = ({ commonPrefix, filename, mainFile, userNamespace, }) => {
104
- const mainPath = normalizeFilePath({ commonPrefix, path: mainFile, userNamespace });
105
- const extension = (0, path_1.extname)(filename);
106
- const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
107
- return {
108
- contents: `module.exports = require('.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}')`,
109
- filename: entryFilename,
110
- };
111
- };
112
104
  const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, rewrites = new Map(), stat, srcFile, userNamespace, }) {
113
105
  const destPath = aliases.get(srcFile) || srcFile;
114
- const normalizedDestPath = normalizeFilePath({ commonPrefix, path: destPath, userNamespace });
106
+ const normalizedDestPath = (0, normalize_path_1.normalizeFilePath)({ commonPrefix, path: destPath, userNamespace });
115
107
  if (rewrites.has(srcFile)) {
116
108
  (0, archive_1.addZipContent)(archive, rewrites.get(srcFile), normalizedDestPath);
117
109
  }
@@ -119,15 +111,4 @@ const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, rewrit
119
111
  (0, archive_1.addZipFile)(archive, srcFile, normalizedDestPath, stat);
120
112
  }
121
113
  };
122
- // `adm-zip` and `require()` expect Unix paths.
123
- // We remove the common path prefix.
124
- // With files on different Windows drives, we remove the drive letter.
125
- const normalizeFilePath = function ({ commonPrefix, path, userNamespace, }) {
126
- const userNamespacePathSegment = userNamespace ? `${userNamespace}${path_1.sep}` : '';
127
- const pathA = (0, path_1.normalize)(path);
128
- const pathB = pathA.replace(commonPrefix, userNamespacePathSegment);
129
- const pathC = (0, unixify_1.default)(pathB);
130
- return pathC;
131
- };
132
- /* eslint-enable max-lines */
133
114
  //# sourceMappingURL=zip.js.map
@@ -3,7 +3,7 @@ import { FunctionConfig } from '../config';
3
3
  import { FeatureFlags } from '../feature_flags';
4
4
  import { FunctionSource, SourceFile } from '../function';
5
5
  import { FsCache } from '../utils/fs';
6
- import type { NodeBundlerName } from './node';
6
+ import type { NodeBundlerName } from './node/bundlers';
7
7
  import type { ISCValues } from './node/in_source_config';
8
8
  declare type RuntimeName = 'go' | 'js' | 'rs';
9
9
  declare type FindFunctionsInPathsFunction = (args: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "5.6.0",
3
+ "version": "5.7.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {
@@ -87,7 +87,7 @@
87
87
  },
88
88
  "devDependencies": {
89
89
  "@babel/types": "^7.15.6",
90
- "@netlify/eslint-config-node": "^5.1.2",
90
+ "@netlify/eslint-config-node": "^5.1.4",
91
91
  "@types/archiver": "^5.1.1",
92
92
  "@types/end-of-stream": "^1.4.1",
93
93
  "@types/resolve": "^1.20.1",