@netlify/zip-it-and-ship-it 5.6.0 → 5.7.3

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 (91) hide show
  1. package/README.md +19 -38
  2. package/dist/archive.d.ts +6 -8
  3. package/dist/bin.js +2 -1
  4. package/dist/config.d.ts +7 -7
  5. package/dist/feature_flags.d.ts +4 -6
  6. package/dist/feature_flags.js +3 -3
  7. package/dist/function.d.ts +3 -4
  8. package/dist/main.d.ts +4 -5
  9. package/dist/main.js +4 -4
  10. package/dist/manifest.d.ts +3 -4
  11. package/dist/runtimes/detect_runtime.d.ts +1 -2
  12. package/dist/runtimes/go/builder.d.ts +1 -2
  13. package/dist/runtimes/go/builder.js +1 -1
  14. package/dist/runtimes/index.d.ts +3 -3
  15. package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +2 -3
  16. package/dist/runtimes/node/bundlers/esbuild/bundler.js +3 -4
  17. package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +2 -2
  18. package/dist/runtimes/node/bundlers/esbuild/index.js +1 -0
  19. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.d.ts +1 -2
  20. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.d.ts +1 -2
  21. package/dist/runtimes/node/bundlers/esbuild/plugin_node_builtin.d.ts +1 -2
  22. package/dist/runtimes/node/bundlers/esbuild/special_cases.d.ts +1 -2
  23. package/dist/runtimes/node/bundlers/esbuild/special_cases.js +1 -10
  24. package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +1 -2
  25. package/dist/runtimes/node/bundlers/index.d.ts +13 -7
  26. package/dist/runtimes/node/bundlers/index.js +21 -1
  27. package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +9 -3
  28. package/dist/runtimes/node/bundlers/nft/es_modules.js +34 -5
  29. package/dist/runtimes/node/bundlers/nft/index.js +15 -4
  30. package/dist/runtimes/node/bundlers/nft/transpile.d.ts +1 -2
  31. package/dist/runtimes/node/bundlers/zisi/index.js +1 -0
  32. package/dist/runtimes/node/bundlers/zisi/list_imports.d.ts +1 -2
  33. package/dist/runtimes/node/bundlers/zisi/list_imports.js +6 -2
  34. package/dist/runtimes/node/bundlers/zisi/nested.d.ts +2 -3
  35. package/dist/runtimes/node/bundlers/zisi/nested.js +8 -4
  36. package/dist/runtimes/node/bundlers/zisi/published.d.ts +1 -2
  37. package/dist/runtimes/node/bundlers/zisi/resolve.d.ts +2 -3
  38. package/dist/runtimes/node/bundlers/zisi/resolve.js +6 -4
  39. package/dist/runtimes/node/bundlers/zisi/side_files.d.ts +1 -2
  40. package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +1 -2
  41. package/dist/runtimes/node/bundlers/zisi/traverse.d.ts +1 -2
  42. package/dist/runtimes/node/bundlers/zisi/traverse.js +3 -3
  43. package/dist/runtimes/node/bundlers/zisi/tree_files.d.ts +1 -2
  44. package/dist/runtimes/node/bundlers/zisi/tree_shake.d.ts +1 -2
  45. package/dist/runtimes/node/finder.d.ts +2 -3
  46. package/dist/runtimes/node/finder.js +1 -1
  47. package/dist/runtimes/node/in_source_config/index.d.ts +5 -7
  48. package/dist/runtimes/node/in_source_config/index.js +5 -6
  49. package/dist/runtimes/node/index.d.ts +1 -2
  50. package/dist/runtimes/node/index.js +4 -22
  51. package/dist/runtimes/node/parser/exports.d.ts +1 -2
  52. package/dist/runtimes/node/parser/helpers.d.ts +3 -4
  53. package/dist/runtimes/node/parser/imports.d.ts +1 -2
  54. package/dist/runtimes/node/parser/index.d.ts +2 -3
  55. package/dist/runtimes/node/utils/base_path.d.ts +1 -2
  56. package/dist/runtimes/node/utils/detect_es_module.d.ts +1 -2
  57. package/dist/runtimes/node/utils/detect_native_module.d.ts +1 -2
  58. package/dist/runtimes/node/utils/entry_file.d.ts +12 -0
  59. package/dist/runtimes/node/utils/entry_file.js +24 -0
  60. package/dist/runtimes/node/utils/included_files.d.ts +2 -3
  61. package/dist/runtimes/node/utils/module.d.ts +1 -2
  62. package/dist/runtimes/node/utils/module_format.d.ts +1 -0
  63. package/dist/runtimes/node/utils/module_format.js +3 -0
  64. package/dist/runtimes/node/utils/node_version.d.ts +9 -5
  65. package/dist/runtimes/node/utils/node_version.js +11 -4
  66. package/dist/runtimes/node/utils/normalize_path.d.ts +5 -0
  67. package/dist/runtimes/node/utils/normalize_path.js +20 -0
  68. package/dist/runtimes/node/utils/package_json.d.ts +4 -4
  69. package/dist/runtimes/node/utils/package_json.js +14 -4
  70. package/dist/runtimes/node/utils/plugin_modules_path.d.ts +2 -3
  71. package/dist/runtimes/node/utils/traversal_cache.d.ts +2 -3
  72. package/dist/runtimes/node/utils/zip.d.ts +5 -3
  73. package/dist/runtimes/node/utils/zip.js +9 -28
  74. package/dist/runtimes/runtime.d.ts +8 -9
  75. package/dist/runtimes/rust/builder.d.ts +1 -2
  76. package/dist/runtimes/rust/builder.js +4 -4
  77. package/dist/runtimes/rust/cargo_manifest.d.ts +1 -2
  78. package/dist/runtimes/rust/constants.d.ts +2 -3
  79. package/dist/runtimes/rust/constants.js +2 -4
  80. package/dist/utils/archive_size.d.ts +1 -2
  81. package/dist/utils/format_result.d.ts +2 -4
  82. package/dist/utils/fs.d.ts +10 -12
  83. package/dist/utils/fs.js +5 -8
  84. package/dist/utils/non_nullable.d.ts +1 -2
  85. package/dist/utils/remove_undefined.d.ts +1 -2
  86. package/dist/utils/shell.d.ts +21 -1
  87. package/dist/utils/shell.js +2 -2
  88. package/dist/zip.d.ts +3 -3
  89. package/dist/zip.js +1 -1
  90. package/dist/zip_binary.d.ts +1 -2
  91. package/package.json +5 -5
@@ -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.getPackageJsonIfAvailable)((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);
@@ -33,15 +62,16 @@ const shouldTranspile = (path, cache, esmPaths, reasons) => {
33
62
  return false;
34
63
  }
35
64
  const { parents } = reason;
65
+ const parentPaths = [...parents].filter((parentPath) => parentPath !== path);
36
66
  // If the path is an entrypoint, we transpile it only if it's an ESM file.
37
- if (parents.size === 0) {
67
+ if (parentPaths.length === 0) {
38
68
  const isESM = esmPaths.has(path);
39
69
  cache.set(path, isESM);
40
70
  return isESM;
41
71
  }
42
72
  // The path should be transpiled if every parent will also be transpiled, or
43
73
  // if there is no parent.
44
- const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, esmPaths, reasons));
74
+ const shouldTranspilePath = parentPaths.every((parentPath) => shouldTranspile(parentPath, cache, esmPaths, reasons));
45
75
  cache.set(path, shouldTranspilePath);
46
76
  return shouldTranspilePath;
47
77
  };
@@ -60,11 +90,10 @@ const transpileESM = async ({ basePath, config, esmPaths, fsCache, reasons, }) =
60
90
  .map(([path]) => (basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path)));
61
91
  const rewrites = await getPatchedESMPackages(packageJsonPaths, fsCache);
62
92
  await Promise.all(pathsToTranspile.map(async (path) => {
63
- const absolutePath = basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path);
93
+ const absolutePath = resolvePath(path, basePath);
64
94
  const transpiled = await (0, transpile_1.transpile)(absolutePath, config);
65
95
  rewrites.set(absolutePath, transpiled);
66
96
  }));
67
97
  return rewrites;
68
98
  };
69
- exports.transpileESM = transpileESM;
70
99
  //# 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
  };
@@ -1,3 +1,2 @@
1
1
  import type { FunctionConfig } from '../../../../config';
2
- declare const transpile: (path: string, config: FunctionConfig) => Promise<string>;
3
- export { transpile };
2
+ export declare const transpile: (path: string, config: FunctionConfig) => Promise<string>;
@@ -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
- declare const listImports: ({ functionName, path }: {
1
+ export declare const listImports: ({ functionName, path, }: {
2
2
  functionName: string;
3
3
  path: string;
4
4
  }) => Promise<string[]>;
5
- export { listImports };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -47,7 +51,7 @@ const getListImportsPlugin = ({ imports, path }) => ({
47
51
  });
48
52
  },
49
53
  });
50
- const listImports = async ({ functionName, path }) => {
54
+ const listImports = async ({ functionName, path, }) => {
51
55
  // We're not interested in the output that esbuild generates, we're just
52
56
  // using it for its parsing capabilities in order to find import/require
53
57
  // statements. However, if we don't give esbuild a path in `outfile`, it
@@ -1,10 +1,9 @@
1
1
  import { PackageJson } from '../../utils/package_json';
2
- declare const getNestedDependencies: ({ dependencies, peerDependencies, optionalDependencies, }: PackageJson) => string[];
3
- declare const handleModuleNotFound: ({ error, moduleName, packageJson, }: {
2
+ export declare const getNestedDependencies: ({ dependencies, peerDependencies, optionalDependencies, }: PackageJson) => string[];
3
+ export declare const handleModuleNotFound: ({ error, moduleName, packageJson, }: {
4
4
  error: Error & {
5
5
  code: string;
6
6
  };
7
7
  moduleName: string;
8
8
  packageJson: PackageJson;
9
9
  }) => [] | never;
10
- export { getNestedDependencies, handleModuleNotFound };
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.handleModuleNotFound = exports.getNestedDependencies = void 0;
4
- const semver_1 = require("semver");
7
+ const semver_1 = __importDefault(require("semver"));
5
8
  // Apply the Node.js module logic recursively on its own dependencies, using
6
9
  // the `package.json` `dependencies`, `peerDependencies` and
7
10
  // `optionalDependencies` keys
@@ -57,7 +60,8 @@ const isOptionalModule = function (moduleName, { optionalDependencies = {}, peer
57
60
  peerDependencies[moduleName] !== undefined));
58
61
  };
59
62
  const MIN_NEXT_VERSION = '10.0.4';
60
- const satisfiesRange = (range) => Boolean((0, semver_1.validRange)(range)) && ((0, semver_1.satisfies)(MIN_NEXT_VERSION, range) || (0, semver_1.ltr)(MIN_NEXT_VERSION, range));
63
+ const satisfiesRange = (range) => Boolean(semver_1.default.validRange(range)) &&
64
+ (semver_1.default.satisfies(MIN_NEXT_VERSION, range) || semver_1.default.ltr(MIN_NEXT_VERSION, range));
61
65
  // 'critters' is used only in Next.js >= 10.0.4 when enabling an experimental option and has to be installed manually
62
66
  // we ignore it if it's missing
63
67
  const isExternalCrittersModule = function (moduleName, { dependencies = {}, devDependencies = {} }) {
@@ -70,8 +74,8 @@ const isExternalCrittersModule = function (moduleName, { dependencies = {}, devD
70
74
  }
71
75
  // can the declared Next.js version resolve to >=10.0.4 ?
72
76
  // test exact versions
73
- if ((0, semver_1.valid)(nextVersion)) {
74
- return (0, semver_1.gte)(nextVersion, MIN_NEXT_VERSION);
77
+ if (semver_1.default.valid(nextVersion)) {
78
+ return semver_1.default.gte(nextVersion, MIN_NEXT_VERSION);
75
79
  }
76
80
  return satisfiesRange(nextVersion);
77
81
  };
@@ -1,2 +1 @@
1
- declare const getPublishedFiles: (modulePath: string) => Promise<string[]>;
2
- export { getPublishedFiles };
1
+ export declare const getPublishedFiles: (modulePath: string) => Promise<string[]>;
@@ -1,3 +1,2 @@
1
- declare const resolvePackage: (moduleName: string, baseDirs: string[]) => Promise<string>;
2
- declare const resolvePathPreserveSymlinks: (path: string, baseDirs: string[]) => Promise<string>;
3
- export { resolvePackage, resolvePathPreserveSymlinks };
1
+ export declare const resolvePackage: (moduleName: string, baseDirs: string[]) => Promise<string>;
2
+ export declare const resolvePathPreserveSymlinks: (path: string, baseDirs: string[]) => Promise<string>;
@@ -4,11 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.resolvePathPreserveSymlinks = exports.resolvePackage = void 0;
7
+ const module_1 = require("module");
7
8
  const process_1 = require("process");
8
9
  const find_up_1 = __importDefault(require("find-up"));
9
10
  const path_exists_1 = __importDefault(require("path-exists"));
10
11
  const resolve_1 = __importDefault(require("resolve"));
11
- const semver_1 = require("semver");
12
+ const semver_1 = __importDefault(require("semver"));
13
+ const requireLib = (0, module_1.createRequire)(__filename);
12
14
  const BACKSLASH_REGEXP = /\\/g;
13
15
  // Find the path to a module's `package.json`
14
16
  // We need to use `resolve` instead of `require.resolve()` because:
@@ -26,10 +28,10 @@ const BACKSLASH_REGEXP = /\\/g;
26
28
  // So, on errors, we fallback to `require.resolve()`
27
29
  const resolvePackage = async function (moduleName, baseDirs) {
28
30
  try {
29
- return await resolvePathPreserveSymlinks(`${moduleName}/package.json`, baseDirs);
31
+ return await (0, exports.resolvePathPreserveSymlinks)(`${moduleName}/package.json`, baseDirs);
30
32
  }
31
33
  catch (error) {
32
- if ((0, semver_1.lt)(process_1.version, REQUEST_RESOLVE_MIN_VERSION)) {
34
+ if (semver_1.default.lt(process_1.version, REQUEST_RESOLVE_MIN_VERSION)) {
33
35
  throw error;
34
36
  }
35
37
  try {
@@ -75,7 +77,7 @@ const resolvePathPreserveSymlinks = async function (path, baseDirs) {
75
77
  };
76
78
  exports.resolvePathPreserveSymlinks = resolvePathPreserveSymlinks;
77
79
  const resolvePathFollowSymlinks = function (path, baseDirs) {
78
- return require.resolve(path, { paths: baseDirs });
80
+ return requireLib.resolve(path, { paths: baseDirs });
79
81
  };
80
82
  // `require.resolve()` on a module's specific file (like `package.json`)
81
83
  // can be forbidden by the package author by using an `exports` field in
@@ -1,2 +1 @@
1
- declare const getSideFiles: (modulePath: string, moduleName: string) => Promise<string[]>;
2
- export { getSideFiles };
1
+ export declare const getSideFiles: (modulePath: string, moduleName: string) => Promise<string[]>;
@@ -1,3 +1,2 @@
1
1
  import type { GetSrcFilesFunction } from '..';
2
- declare const getSrcFiles: GetSrcFilesFunction;
3
- export { getSrcFiles };
2
+ export declare const getSrcFiles: GetSrcFilesFunction;
@@ -1,10 +1,9 @@
1
1
  import { PackageJson } from '../../utils/package_json';
2
2
  import { TraversalCache } from '../../utils/traversal_cache';
3
- declare const getDependencyPathsForDependency: ({ dependency, basedir, state, packageJson, pluginsModulesPath, }: {
3
+ export declare const getDependencyPathsForDependency: ({ dependency, basedir, state, packageJson, pluginsModulesPath, }: {
4
4
  dependency: string;
5
5
  basedir: string;
6
6
  state: TraversalCache;
7
7
  packageJson: PackageJson;
8
8
  pluginsModulesPath?: string | undefined;
9
9
  }) => Promise<string[]>;
10
- export { getDependencyPathsForDependency };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDependencyPathsForDependency = void 0;
4
+ const fs_1 = require("fs");
4
5
  const path_1 = require("path");
5
6
  const non_nullable_1 = require("../../../../utils/non_nullable");
6
7
  const module_1 = require("../../utils/module");
@@ -42,8 +43,7 @@ const getDependenciesForModuleName = async function ({ moduleName, basedir, stat
42
43
  state.moduleNames.add(moduleName);
43
44
  state.modulePaths.add(modulePath);
44
45
  // The path depends on the user's build, i.e. must be dynamic
45
- // eslint-disable-next-line import/no-dynamic-require, node/global-require, @typescript-eslint/no-var-requires
46
- const packageJson = require(packagePath);
46
+ const packageJson = JSON.parse(await fs_1.promises.readFile(packagePath, 'utf8'));
47
47
  const [publishedFiles, sideFiles, depsPaths] = await Promise.all([
48
48
  (0, published_1.getPublishedFiles)(modulePath),
49
49
  (0, side_files_1.getSideFiles)(modulePath, moduleName),
@@ -56,7 +56,7 @@ const isExcludedModule = function (moduleName) {
56
56
  };
57
57
  const getNestedModules = async function ({ modulePath, state, packageJson, pluginsModulesPath, }) {
58
58
  const dependencies = (0, nested_1.getNestedDependencies)(packageJson);
59
- const depsPaths = await Promise.all(dependencies.map((dependency) => getDependencyPathsForDependency({ dependency, basedir: modulePath, state, packageJson, pluginsModulesPath })));
59
+ const depsPaths = await Promise.all(dependencies.map((dependency) => (0, exports.getDependencyPathsForDependency)({ dependency, basedir: modulePath, state, packageJson, pluginsModulesPath })));
60
60
  return depsPaths.flat();
61
61
  };
62
62
  //# sourceMappingURL=traverse.js.map
@@ -1,3 +1,2 @@
1
1
  import { Stats } from 'fs';
2
- declare const getTreeFiles: (srcPath: string, stat: Stats) => Promise<string[]>;
3
- export { getTreeFiles };
2
+ export declare const getTreeFiles: (srcPath: string, stat: Stats) => Promise<string[]>;
@@ -1,2 +1 @@
1
- declare const shouldTreeShake: (dependency: string, treeShakeNext: boolean) => boolean;
2
- export { shouldTreeShake };
1
+ export declare const shouldTreeShake: (dependency: string, treeShakeNext: boolean) => boolean;
@@ -1,4 +1,3 @@
1
1
  import { FindFunctionsInPathsFunction, FindFunctionInPathFunction } from '../runtime';
2
- declare const findFunctionsInPaths: FindFunctionsInPathsFunction;
3
- declare const findFunctionInPath: FindFunctionInPathFunction;
4
- export { findFunctionsInPaths, findFunctionInPath };
2
+ export declare const findFunctionsInPaths: FindFunctionsInPathsFunction;
3
+ export declare const findFunctionInPath: FindFunctionInPathFunction;
@@ -20,7 +20,7 @@ const sortByExtension = (fA, fB) => {
20
20
  return indexB - indexA;
21
21
  };
22
22
  const findFunctionsInPaths = async function ({ paths, fsCache, featureFlags }) {
23
- const functions = await Promise.all(paths.map((path) => findFunctionInPath({ path, fsCache, featureFlags })));
23
+ const functions = await Promise.all(paths.map((path) => (0, exports.findFunctionInPath)({ path, fsCache, featureFlags })));
24
24
  // It's fine to mutate the array since its scope is local to this function.
25
25
  const sortedFunctions = functions.filter(non_nullable_1.nonNullable).sort((fA, fB) => {
26
26
  // We first sort the functions array to put directories first. This is so
@@ -1,12 +1,10 @@
1
1
  import { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName } from '@babel/types';
2
2
  import { parse as parseSchedule } from './properties/schedule';
3
- declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions";
4
- declare type ISCValues = Partial<ReturnType<typeof parseSchedule>>;
5
- declare const findISCDeclarationsInPath: (sourcePath: string) => Promise<ISCValues>;
6
- declare type ISCHandlerArg = ArgumentPlaceholder | Expression | SpreadElement | JSXNamespacedName;
7
- interface ISCExport {
3
+ export declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions";
4
+ export declare type ISCValues = Partial<ReturnType<typeof parseSchedule>>;
5
+ export declare const findISCDeclarationsInPath: (sourcePath: string) => Promise<ISCValues>;
6
+ export declare type ISCHandlerArg = ArgumentPlaceholder | Expression | SpreadElement | JSXNamespacedName;
7
+ export interface ISCExport {
8
8
  local: string;
9
9
  args: ISCHandlerArg[];
10
10
  }
11
- export { findISCDeclarationsInPath, IN_SOURCE_CONFIG_MODULE };
12
- export type { ISCExport, ISCHandlerArg, ISCValues };
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IN_SOURCE_CONFIG_MODULE = exports.findISCDeclarationsInPath = void 0;
3
+ exports.findISCDeclarationsInPath = exports.IN_SOURCE_CONFIG_MODULE = void 0;
4
4
  const non_nullable_1 = require("../../../utils/non_nullable");
5
5
  const parser_1 = require("../parser");
6
6
  const exports_1 = require("../parser/exports");
7
7
  const imports_1 = require("../parser/imports");
8
8
  const schedule_1 = require("./properties/schedule");
9
- const IN_SOURCE_CONFIG_MODULE = '@netlify/functions';
10
- exports.IN_SOURCE_CONFIG_MODULE = IN_SOURCE_CONFIG_MODULE;
9
+ exports.IN_SOURCE_CONFIG_MODULE = '@netlify/functions';
11
10
  // Parses a JS/TS file and looks for in-source config declarations. It returns
12
11
  // an array of all declarations found, with `property` indicating the name of
13
12
  // the property and `data` its value.
@@ -16,9 +15,9 @@ const findISCDeclarationsInPath = async (sourcePath) => {
16
15
  if (ast === null) {
17
16
  return {};
18
17
  }
19
- const imports = ast.body.flatMap((node) => (0, imports_1.getImports)(node, IN_SOURCE_CONFIG_MODULE));
20
- const exports = (0, exports_1.getMainExport)(ast.body);
21
- const iscExports = exports
18
+ const imports = ast.body.flatMap((node) => (0, imports_1.getImports)(node, exports.IN_SOURCE_CONFIG_MODULE));
19
+ const mainExports = (0, exports_1.getMainExport)(ast.body);
20
+ const iscExports = mainExports
22
21
  .map(({ args, local: exportName }) => {
23
22
  const matchingImport = imports.find(({ local: importName }) => importName === exportName);
24
23
  if (matchingImport === undefined) {
@@ -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
  });
@@ -1,4 +1,3 @@
1
1
  import { Statement } from '@babel/types';
2
2
  import type { ISCExport } from '../in_source_config';
3
- declare const getMainExport: (nodes: Statement[]) => ISCExport[];
4
- export { getMainExport };
3
+ export declare const getMainExport: (nodes: Statement[]) => ISCExport[];
@@ -1,7 +1,6 @@
1
1
  import { AssignmentExpression, Expression, ExpressionStatement, ImportDeclaration, Statement } from '@babel/types';
2
- declare const isImport: (node: Statement, importPath: string) => node is ImportDeclaration;
3
- declare const isModuleExports: (node: Statement, dotExpression?: string[]) => node is ExpressionStatement & {
2
+ export declare const isImport: (node: Statement, importPath: string) => node is ImportDeclaration;
3
+ export declare const isModuleExports: (node: Statement, dotExpression?: string[]) => node is ExpressionStatement & {
4
4
  expression: AssignmentExpression;
5
5
  };
6
- declare const isRequire: (node: Expression | undefined | null, requirePath: string) => boolean;
7
- export { isImport, isModuleExports, isRequire };
6
+ export declare const isRequire: (node: Expression | undefined | null, requirePath: string) => boolean;
@@ -1,6 +1,5 @@
1
1
  import { Statement } from '@babel/types';
2
- declare const getImports: (node: Statement, importPath: string) => {
2
+ export declare const getImports: (node: Statement, importPath: string) => {
3
3
  imported: string;
4
4
  local: string;
5
5
  }[];
6
- export { getImports };
@@ -1,4 +1,4 @@
1
- declare const parseExpression: ({ basePath, expression: rawExpression, resolveDir, }: {
1
+ export declare const parseExpression: ({ basePath, expression: rawExpression, resolveDir, }: {
2
2
  basePath: string;
3
3
  expression: string;
4
4
  resolveDir: string;
@@ -6,5 +6,4 @@ declare const parseExpression: ({ basePath, expression: rawExpression, resolveDi
6
6
  includedPathsGlob: string | null | undefined;
7
7
  type: string;
8
8
  } | undefined;
9
- declare const safelyParseFile: (path: string) => Promise<import("@babel/types").Program | null>;
10
- export { parseExpression, safelyParseFile };
9
+ export declare const safelyParseFile: (path: string) => Promise<import("@babel/types").Program | null>;
@@ -1,2 +1 @@
1
- declare const getBasePath: (dirnames: string[]) => string;
2
- export { getBasePath };
1
+ export declare const getBasePath: (dirnames: string[]) => string;
@@ -1,4 +1,3 @@
1
- declare const detectEsModule: ({ mainFile }: {
1
+ export declare const detectEsModule: ({ mainFile }: {
2
2
  mainFile: string;
3
3
  }) => Promise<boolean>;
4
- export { detectEsModule };
@@ -1,3 +1,2 @@
1
1
  import { PackageJson } from './package_json';
2
- declare const isNativeModule: ({ binary, dependencies, devDependencies, files, gypfile, }: PackageJson) => boolean;
3
- export { isNativeModule };
2
+ export declare const isNativeModule: ({ binary, dependencies, devDependencies, files, gypfile, }: PackageJson) => boolean;
@@ -0,0 +1,12 @@
1
+ import type { ModuleFormat } from './module_format';
2
+ export interface EntryFile {
3
+ contents: string;
4
+ filename: string;
5
+ }
6
+ export 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;
@@ -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
@@ -1,6 +1,5 @@
1
- declare const filterExcludedPaths: (paths: string[], exclude?: string[]) => string[];
2
- declare const getPathsOfIncludedFiles: (includedFiles: string[], basePath?: string | undefined) => Promise<{
1
+ export declare const filterExcludedPaths: (paths: string[], exclude?: string[]) => string[];
2
+ export declare const getPathsOfIncludedFiles: (includedFiles: string[], basePath?: string | undefined) => Promise<{
3
3
  exclude: string[];
4
4
  paths: string[];
5
5
  }>;
6
- export { filterExcludedPaths, getPathsOfIncludedFiles };
@@ -1,2 +1 @@
1
- declare const getModuleName: (dependency: string) => string;
2
- export { getModuleName };
1
+ export declare const getModuleName: (dependency: string) => string;
@@ -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`;
3
- declare const DEFAULT_NODE_VERSION = 14;
4
- declare const getNodeVersion: (configVersion?: string | undefined) => number;
5
- declare const parseVersion: (input: string | undefined) => number | undefined;
6
- export { DEFAULT_NODE_VERSION, getNodeVersion, parseVersion, NodeVersion };
2
+ export declare type NodeVersionString = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`;
3
+ export interface NodeVersionSupport {
4
+ esm: boolean;
5
+ }
6
+ export declare const DEFAULT_NODE_VERSION = 14;
7
+ export declare const getNodeVersion: (configVersion?: string | undefined) => number;
8
+ export declare const getNodeSupportMatrix: (configVersion?: string | undefined) => NodeVersionSupport;
9
+ export declare const parseVersion: (input: string | undefined) => number | undefined;
10
+ export {};