@netlify/zip-it-and-ship-it 5.7.2 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +19 -38
  2. package/dist/archive.d.ts +6 -8
  3. package/dist/bin.js +2 -2
  4. package/dist/config.d.ts +7 -8
  5. package/dist/feature_flags.d.ts +4 -6
  6. package/dist/feature_flags.js +3 -4
  7. package/dist/function.d.ts +5 -6
  8. package/dist/main.d.ts +7 -8
  9. package/dist/main.js +19 -19
  10. package/dist/manifest.d.ts +4 -5
  11. package/dist/runtimes/detect_runtime.d.ts +3 -4
  12. package/dist/runtimes/detect_runtime.js +2 -2
  13. package/dist/runtimes/go/builder.d.ts +1 -2
  14. package/dist/runtimes/go/builder.js +2 -2
  15. package/dist/runtimes/go/index.d.ts +1 -1
  16. package/dist/runtimes/go/index.js +13 -13
  17. package/dist/runtimes/index.d.ts +6 -6
  18. package/dist/runtimes/index.js +10 -10
  19. package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +6 -4
  20. package/dist/runtimes/node/bundlers/esbuild/bundler.js +23 -17
  21. package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +7 -1
  22. package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +19 -3
  23. package/dist/runtimes/node/bundlers/esbuild/index.d.ts +2 -2
  24. package/dist/runtimes/node/bundlers/esbuild/index.js +15 -14
  25. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.d.ts +1 -2
  26. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +2 -2
  27. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.d.ts +2 -3
  28. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +2 -2
  29. package/dist/runtimes/node/bundlers/esbuild/plugin_node_builtin.d.ts +1 -2
  30. package/dist/runtimes/node/bundlers/esbuild/special_cases.d.ts +1 -2
  31. package/dist/runtimes/node/bundlers/esbuild/special_cases.js +2 -2
  32. package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +2 -3
  33. package/dist/runtimes/node/bundlers/esbuild/src_files.js +10 -10
  34. package/dist/runtimes/node/bundlers/index.d.ts +10 -11
  35. package/dist/runtimes/node/bundlers/index.js +12 -13
  36. package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +5 -6
  37. package/dist/runtimes/node/bundlers/nft/es_modules.js +8 -8
  38. package/dist/runtimes/node/bundlers/nft/index.d.ts +2 -2
  39. package/dist/runtimes/node/bundlers/nft/index.js +14 -14
  40. package/dist/runtimes/node/bundlers/nft/transpile.d.ts +2 -3
  41. package/dist/runtimes/node/bundlers/nft/transpile.js +2 -2
  42. package/dist/runtimes/node/bundlers/zisi/index.d.ts +2 -2
  43. package/dist/runtimes/node/bundlers/zisi/index.js +5 -5
  44. package/dist/runtimes/node/bundlers/zisi/list_imports.d.ts +1 -2
  45. package/dist/runtimes/node/bundlers/zisi/list_imports.js +3 -3
  46. package/dist/runtimes/node/bundlers/zisi/nested.d.ts +3 -4
  47. package/dist/runtimes/node/bundlers/zisi/published.d.ts +1 -2
  48. package/dist/runtimes/node/bundlers/zisi/resolve.d.ts +2 -3
  49. package/dist/runtimes/node/bundlers/zisi/resolve.js +1 -1
  50. package/dist/runtimes/node/bundlers/zisi/side_files.d.ts +1 -2
  51. package/dist/runtimes/node/bundlers/zisi/side_files.js +2 -2
  52. package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +2 -3
  53. package/dist/runtimes/node/bundlers/zisi/src_files.js +19 -19
  54. package/dist/runtimes/node/bundlers/zisi/traverse.d.ts +3 -4
  55. package/dist/runtimes/node/bundlers/zisi/traverse.js +15 -15
  56. package/dist/runtimes/node/bundlers/zisi/tree_files.d.ts +1 -2
  57. package/dist/runtimes/node/bundlers/zisi/tree_shake.d.ts +1 -2
  58. package/dist/runtimes/node/bundlers/zisi/tree_shake.js +2 -2
  59. package/dist/runtimes/node/finder.d.ts +3 -4
  60. package/dist/runtimes/node/finder.js +3 -3
  61. package/dist/runtimes/node/in_source_config/index.d.ts +6 -8
  62. package/dist/runtimes/node/in_source_config/index.js +13 -14
  63. package/dist/runtimes/node/in_source_config/properties/schedule.d.ts +1 -1
  64. package/dist/runtimes/node/index.d.ts +2 -2
  65. package/dist/runtimes/node/index.js +16 -16
  66. package/dist/runtimes/node/parser/exports.d.ts +2 -3
  67. package/dist/runtimes/node/parser/exports.js +2 -2
  68. package/dist/runtimes/node/parser/helpers.d.ts +3 -4
  69. package/dist/runtimes/node/parser/imports.d.ts +1 -2
  70. package/dist/runtimes/node/parser/imports.js +6 -6
  71. package/dist/runtimes/node/parser/index.d.ts +2 -3
  72. package/dist/runtimes/node/parser/index.js +2 -2
  73. package/dist/runtimes/node/utils/base_path.d.ts +1 -2
  74. package/dist/runtimes/node/utils/detect_es_module.d.ts +1 -2
  75. package/dist/runtimes/node/utils/detect_native_module.d.ts +2 -3
  76. package/dist/runtimes/node/utils/entry_file.d.ts +3 -4
  77. package/dist/runtimes/node/utils/entry_file.js +2 -2
  78. package/dist/runtimes/node/utils/included_files.d.ts +2 -3
  79. package/dist/runtimes/node/utils/module.d.ts +1 -2
  80. package/dist/runtimes/node/utils/node_version.d.ts +7 -7
  81. package/dist/runtimes/node/utils/node_version.js +4 -5
  82. package/dist/runtimes/node/utils/normalize_path.d.ts +1 -2
  83. package/dist/runtimes/node/utils/package_json.d.ts +9 -5
  84. package/dist/runtimes/node/utils/package_json.js +46 -21
  85. package/dist/runtimes/node/utils/plugin_modules_path.d.ts +2 -3
  86. package/dist/runtimes/node/utils/traversal_cache.d.ts +2 -3
  87. package/dist/runtimes/node/utils/zip.d.ts +4 -4
  88. package/dist/runtimes/node/utils/zip.js +14 -14
  89. package/dist/runtimes/runtime.d.ts +14 -15
  90. package/dist/runtimes/rust/builder.d.ts +2 -3
  91. package/dist/runtimes/rust/builder.js +8 -8
  92. package/dist/runtimes/rust/cargo_manifest.d.ts +1 -2
  93. package/dist/runtimes/rust/constants.d.ts +2 -3
  94. package/dist/runtimes/rust/constants.js +2 -4
  95. package/dist/runtimes/rust/index.d.ts +1 -1
  96. package/dist/runtimes/rust/index.js +17 -17
  97. package/dist/utils/archive_size.d.ts +2 -3
  98. package/dist/utils/format_result.d.ts +4 -6
  99. package/dist/utils/format_result.js +2 -2
  100. package/dist/utils/fs.d.ts +10 -12
  101. package/dist/utils/fs.js +7 -10
  102. package/dist/utils/non_nullable.d.ts +1 -2
  103. package/dist/utils/remove_undefined.d.ts +1 -2
  104. package/dist/zip.d.ts +7 -7
  105. package/dist/zip.js +19 -19
  106. package/dist/zip_binary.d.ts +2 -3
  107. package/dist/zip_binary.js +5 -5
  108. package/package.json +4 -4
@@ -1,24 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ESBUILD_LOG_LIMIT = exports.bundleJsFile = void 0;
3
+ exports.bundleJsFile = exports.ESBUILD_LOG_LIMIT = void 0;
4
4
  const path_1 = require("path");
5
5
  const esbuild_1 = require("@netlify/esbuild");
6
6
  const tmp_promise_1 = require("tmp-promise");
7
- const fs_1 = require("../../../../utils/fs");
8
- const bundler_target_1 = require("./bundler_target");
9
- const plugin_dynamic_imports_1 = require("./plugin_dynamic_imports");
10
- const plugin_native_modules_1 = require("./plugin_native_modules");
11
- const plugin_node_builtin_1 = require("./plugin_node_builtin");
7
+ const fs_js_1 = require("../../../../utils/fs.js");
8
+ const bundler_target_js_1 = require("./bundler_target.js");
9
+ const plugin_dynamic_imports_js_1 = require("./plugin_dynamic_imports.js");
10
+ const plugin_native_modules_js_1 = require("./plugin_native_modules.js");
11
+ const plugin_node_builtin_js_1 = require("./plugin_node_builtin.js");
12
12
  // Maximum number of log messages that an esbuild instance will produce. This
13
13
  // limit is important to avoid out-of-memory errors due to too much data being
14
14
  // sent in the Go<>Node IPC channel.
15
- const ESBUILD_LOG_LIMIT = 10;
16
- exports.ESBUILD_LOG_LIMIT = ESBUILD_LOG_LIMIT;
15
+ exports.ESBUILD_LOG_LIMIT = 10;
17
16
  // When resolving imports with no extension (e.g. require('./foo')), these are
18
17
  // the extensions that esbuild will look for, in this order.
19
18
  const RESOLVE_EXTENSIONS = ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.json'];
20
19
  // eslint-disable-next-line max-statements
21
- const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], ignoredModules = [], name, srcDir, srcFile, }) {
20
+ const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], featureFlags, ignoredModules = [], name, srcDir, srcFile, }) {
22
21
  // We use a temporary directory as the destination for esbuild files to avoid
23
22
  // any naming conflicts with files generated by other functions.
24
23
  const targetDirectory = await (0, tmp_promise_1.tmpName)();
@@ -36,9 +35,9 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
36
35
  const dynamicImportsIncludedPaths = new Set();
37
36
  // The list of esbuild plugins to enable for this build.
38
37
  const plugins = [
39
- (0, plugin_node_builtin_1.getNodeBuiltinPlugin)(),
40
- (0, plugin_native_modules_1.getNativeModulesPlugin)(nativeNodeModules),
41
- (0, plugin_dynamic_imports_1.getDynamicImportsPlugin)({
38
+ (0, plugin_node_builtin_js_1.getNodeBuiltinPlugin)(),
39
+ (0, plugin_native_modules_js_1.getNativeModulesPlugin)(nativeNodeModules),
40
+ (0, plugin_dynamic_imports_js_1.getDynamicImportsPlugin)({
42
41
  basePath,
43
42
  includedPaths: dynamicImportsIncludedPaths,
44
43
  moduleNames: nodeModulesWithDynamicImports,
@@ -48,18 +47,23 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
48
47
  ];
49
48
  // The version of ECMAScript to use as the build target. This will determine
50
49
  // whether certain features are transpiled down or left untransformed.
51
- const nodeTarget = (0, bundler_target_1.getBundlerTarget)(config.nodeVersion);
50
+ const nodeTarget = (0, bundler_target_js_1.getBundlerTarget)(config.nodeVersion);
52
51
  // esbuild will format `sources` relative to the sourcemap file, which lives
53
52
  // in `destFolder`. We use `sourceRoot` to establish that relation. They are
54
53
  // URLs, not paths, so even on Windows they should use forward slashes.
55
54
  const sourceRoot = targetDirectory.replace(/\\/g, '/');
55
+ // Configuring the output format of esbuild. The `includedFiles` array we get
56
+ // here contains additional paths to include with the bundle, like the path
57
+ // to a `package.json` with {"type": "module"} in case of an ESM function.
58
+ const { includedFiles: includedFilesFromModuleDetection, moduleFormat } = await (0, bundler_target_js_1.getModuleFormat)(srcDir, featureFlags, config.nodeVersion);
56
59
  try {
57
60
  const { metafile = { inputs: {}, outputs: {} }, warnings } = await (0, esbuild_1.build)({
58
61
  bundle: true,
59
62
  entryPoints: [srcFile],
60
63
  external,
64
+ format: moduleFormat,
61
65
  logLevel: 'warning',
62
- logLimit: ESBUILD_LOG_LIMIT,
66
+ logLimit: exports.ESBUILD_LOG_LIMIT,
63
67
  metafile: true,
64
68
  nodePaths: additionalModulePaths,
65
69
  outdir: targetDirectory,
@@ -77,11 +81,13 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
77
81
  });
78
82
  const inputs = Object.keys(metafile.inputs).map((path) => (0, path_1.resolve)(path));
79
83
  const cleanTempFiles = getCleanupFunction([...bundlePaths.keys()]);
84
+ const additionalPaths = [...dynamicImportsIncludedPaths, ...includedFilesFromModuleDetection];
80
85
  return {
81
- additionalPaths: [...dynamicImportsIncludedPaths],
86
+ additionalPaths,
82
87
  bundlePaths,
83
88
  cleanTempFiles,
84
89
  inputs,
90
+ moduleFormat,
85
91
  nativeNodeModules,
86
92
  nodeModulesWithDynamicImports: [...nodeModulesWithDynamicImports],
87
93
  warnings,
@@ -117,7 +123,7 @@ const getBundlePaths = ({ destFolder, outputs, srcFile, }) => {
117
123
  const absolutePath = (0, path_1.join)(destFolder, filename);
118
124
  if (output.entryPoint && (0, path_1.basename)(output.entryPoint) === (0, path_1.basename)(srcFile)) {
119
125
  // Ensuring the main file has a `.js` extension.
120
- const normalizedSrcFile = (0, fs_1.getPathWithExtension)(srcFile, '.js');
126
+ const normalizedSrcFile = (0, fs_js_1.getPathWithExtension)(srcFile, '.js');
121
127
  bundlePaths.set(absolutePath, normalizedSrcFile);
122
128
  }
123
129
  else if (extension === '.js' || filename === `${bundleFilename}.map`) {
@@ -127,6 +133,6 @@ const getBundlePaths = ({ destFolder, outputs, srcFile, }) => {
127
133
  return bundlePaths;
128
134
  };
129
135
  const getCleanupFunction = (paths) => async () => {
130
- await Promise.all(paths.filter(Boolean).map(fs_1.safeUnlink));
136
+ await Promise.all(paths.filter(Boolean).map(fs_js_1.safeUnlink));
131
137
  };
132
138
  //# sourceMappingURL=bundler.js.map
@@ -1,3 +1,5 @@
1
+ import { FeatureFlags } from '../../../../feature_flags';
2
+ import { ModuleFormat } from '../../utils/module_format';
1
3
  declare const versionMap: {
2
4
  readonly '8.x': "node8";
3
5
  readonly '10.x': "node10";
@@ -7,4 +9,8 @@ declare const versionMap: {
7
9
  declare type VersionKeys = keyof typeof versionMap;
8
10
  declare type VersionValues = typeof versionMap[VersionKeys];
9
11
  declare const getBundlerTarget: (suppliedVersion?: string | undefined) => VersionValues;
10
- export { getBundlerTarget };
12
+ declare const getModuleFormat: (srcDir: string, featureFlags: FeatureFlags, configVersion?: string | undefined) => Promise<{
13
+ includedFiles: string[];
14
+ moduleFormat: ModuleFormat;
15
+ }>;
16
+ export { getBundlerTarget, getModuleFormat };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBundlerTarget = void 0;
4
- const DEFAULT_VERSION = 'node12';
3
+ exports.getModuleFormat = exports.getBundlerTarget = void 0;
4
+ const node_version_1 = require("../../utils/node_version");
5
+ const package_json_1 = require("../../utils/package_json");
5
6
  const versionMap = {
6
7
  '8.x': 'node8',
7
8
  '10.x': 'node10',
@@ -13,9 +14,24 @@ const getBundlerTarget = (suppliedVersion) => {
13
14
  if (version && version in versionMap) {
14
15
  return versionMap[version];
15
16
  }
16
- return DEFAULT_VERSION;
17
+ return versionMap[`${node_version_1.DEFAULT_NODE_VERSION}.x`];
17
18
  };
18
19
  exports.getBundlerTarget = getBundlerTarget;
20
+ const getModuleFormat = async (srcDir, featureFlags, configVersion) => {
21
+ const packageJsonFile = await (0, package_json_1.getClosestPackageJson)(srcDir);
22
+ const nodeSupport = (0, node_version_1.getNodeSupportMatrix)(configVersion);
23
+ if (featureFlags.zisi_pure_esm && (packageJsonFile === null || packageJsonFile === void 0 ? void 0 : packageJsonFile.contents.type) === 'module' && nodeSupport.esm) {
24
+ return {
25
+ includedFiles: [packageJsonFile.path],
26
+ moduleFormat: 'esm',
27
+ };
28
+ }
29
+ return {
30
+ includedFiles: [],
31
+ moduleFormat: 'cjs',
32
+ };
33
+ };
34
+ exports.getModuleFormat = getModuleFormat;
19
35
  const normalizeVersion = (version) => {
20
36
  const match = version && version.match(/^nodejs(.*)$/);
21
37
  return match ? match[1] : version;
@@ -1,6 +1,6 @@
1
- import type { BundleFunction } from '..';
1
+ import type { BundleFunction } from '../index.js';
2
2
  declare const bundler: {
3
3
  bundle: BundleFunction;
4
- getSrcFiles: import("..").GetSrcFilesFunction;
4
+ getSrcFiles: import("../index.js").GetSrcFilesFunction;
5
5
  };
6
6
  export default bundler;
@@ -1,47 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path_1 = require("path");
4
- const fs_1 = require("../../../../utils/fs");
5
- const non_nullable_1 = require("../../../../utils/non_nullable");
6
- const base_path_1 = require("../../utils/base_path");
7
- const bundler_1 = require("./bundler");
8
- const special_cases_1 = require("./special_cases");
9
- const src_files_1 = require("./src_files");
4
+ const fs_js_1 = require("../../../../utils/fs.js");
5
+ const non_nullable_js_1 = require("../../../../utils/non_nullable.js");
6
+ const base_path_js_1 = require("../../utils/base_path.js");
7
+ const bundler_js_1 = require("./bundler.js");
8
+ const special_cases_js_1 = require("./special_cases.js");
9
+ const src_files_js_1 = require("./src_files.js");
10
10
  const getFunctionBasePath = ({ basePathFromConfig, mainFile, repositoryRoot, supportingSrcFiles, }) => {
11
11
  // If there is a base path defined in the config, we use that. To account for
12
12
  // paths outside of `basePathFromConfig` but inside `repositoryRoot`, we use
13
13
  // the common path prefix between the two.
14
14
  if (basePathFromConfig !== undefined) {
15
- return (0, base_path_1.getBasePath)([basePathFromConfig, repositoryRoot].filter(non_nullable_1.nonNullable));
15
+ return (0, base_path_js_1.getBasePath)([basePathFromConfig, repositoryRoot].filter(non_nullable_js_1.nonNullable));
16
16
  }
17
17
  // If not, the base path is the common path prefix between all the supporting
18
18
  // files and the main file.
19
19
  const dirnames = [...supportingSrcFiles, mainFile].map((filePath) => (0, path_1.normalize)((0, path_1.dirname)(filePath)));
20
- return (0, base_path_1.getBasePath)(dirnames);
20
+ return (0, base_path_js_1.getBasePath)(dirnames);
21
21
  };
22
22
  // Convenience method for retrieving external and ignored modules from
23
23
  // different places and merging them together.
24
24
  const getExternalAndIgnoredModules = async ({ config, srcDir }) => {
25
25
  const { externalNodeModules: externalModulesFromConfig = [], ignoredNodeModules: ignoredModulesFromConfig = [] } = config;
26
- const { externalModules: externalModulesFromSpecialCases, ignoredModules: ignoredModulesFromSpecialCases } = await (0, special_cases_1.getExternalAndIgnoredModulesFromSpecialCases)({ srcDir });
26
+ const { externalModules: externalModulesFromSpecialCases, ignoredModules: ignoredModulesFromSpecialCases } = await (0, special_cases_js_1.getExternalAndIgnoredModulesFromSpecialCases)({ srcDir });
27
27
  const externalModules = [...new Set([...externalModulesFromConfig, ...externalModulesFromSpecialCases])];
28
28
  const ignoredModules = [...ignoredModulesFromConfig, ...ignoredModulesFromSpecialCases];
29
29
  return { externalModules, ignoredModules };
30
30
  };
31
31
  const bundle = async ({ basePath, config = {}, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, repositoryRoot, runtime, srcDir, srcPath, stat, }) => {
32
32
  const { externalModules, ignoredModules } = await getExternalAndIgnoredModules({ config, srcDir });
33
- const { additionalPaths, bundlePaths, cleanTempFiles, inputs, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = await (0, bundler_1.bundleJsFile)({
33
+ const { additionalPaths, bundlePaths, cleanTempFiles, inputs, moduleFormat, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = await (0, bundler_js_1.bundleJsFile)({
34
34
  additionalModulePaths: pluginsModulesPath ? [pluginsModulesPath] : [],
35
35
  basePath,
36
36
  config,
37
37
  externalModules,
38
+ featureFlags,
38
39
  ignoredModules,
39
40
  name,
40
41
  srcDir,
41
42
  srcFile: mainFile,
42
43
  });
43
44
  const bundlerWarnings = warnings.length === 0 ? undefined : warnings;
44
- const srcFiles = await (0, src_files_1.getSrcFiles)({
45
+ const srcFiles = await (0, src_files_js_1.getSrcFiles)({
45
46
  basePath,
46
47
  config: {
47
48
  ...config,
@@ -64,7 +65,7 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
64
65
  // path of the original, pre-bundling function file. We'll add the actual
65
66
  // bundled file further below.
66
67
  const supportingSrcFiles = srcFiles.filter((path) => path !== mainFile);
67
- const normalizedMainFile = (0, fs_1.getPathWithExtension)(mainFile, '.js');
68
+ const normalizedMainFile = (0, fs_js_1.getPathWithExtension)(mainFile, '.js');
68
69
  const functionBasePath = getFunctionBasePath({
69
70
  basePathFromConfig: basePath,
70
71
  mainFile,
@@ -78,12 +79,12 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
78
79
  bundlerWarnings,
79
80
  inputs,
80
81
  mainFile: normalizedMainFile,
81
- moduleFormat: 'cjs',
82
+ moduleFormat,
82
83
  nativeNodeModules,
83
84
  nodeModulesWithDynamicImports,
84
85
  srcFiles: [...supportingSrcFiles, ...bundlePaths.keys()],
85
86
  };
86
87
  };
87
- const bundler = { bundle, getSrcFiles: src_files_1.getSrcFiles };
88
+ const bundler = { bundle, getSrcFiles: src_files_js_1.getSrcFiles };
88
89
  exports.default = bundler;
89
90
  //# sourceMappingURL=index.js.map
@@ -1,9 +1,8 @@
1
1
  import type { Plugin } from '@netlify/esbuild';
2
- declare const getDynamicImportsPlugin: ({ basePath, includedPaths, moduleNames, processImports, srcDir, }: {
2
+ export declare const getDynamicImportsPlugin: ({ basePath, includedPaths, moduleNames, processImports, srcDir, }: {
3
3
  basePath?: string | undefined;
4
4
  includedPaths: Set<string>;
5
5
  moduleNames: Set<string>;
6
6
  processImports: boolean;
7
7
  srcDir: string;
8
8
  }) => Plugin;
9
- export { getDynamicImportsPlugin };
@@ -8,7 +8,7 @@ const path_1 = require("path");
8
8
  const find_up_1 = __importDefault(require("find-up"));
9
9
  const read_package_json_fast_1 = __importDefault(require("read-package-json-fast"));
10
10
  const unixify_1 = __importDefault(require("unixify"));
11
- const parser_1 = require("../../parser");
11
+ const index_js_1 = require("../../parser/index.js");
12
12
  // This plugin intercepts module imports using dynamic expressions and does a
13
13
  // couple of things with them. First of all, it figures out whether the call
14
14
  // is being made from within a Node module, and if so it adds the name of the
@@ -28,7 +28,7 @@ const getDynamicImportsPlugin = ({ basePath, includedPaths, moduleNames, process
28
28
  // Also don't parse the expression if we're not interested in processing
29
29
  // the dynamic import expressions.
30
30
  if (basePath && processImports) {
31
- const { includedPathsGlob, type: expressionType } = (0, parser_1.parseExpression)({ basePath, expression, resolveDir }) || {};
31
+ const { includedPathsGlob, type: expressionType } = (0, index_js_1.parseExpression)({ basePath, expression, resolveDir }) || {};
32
32
  if (includedPathsGlob) {
33
33
  // The parser has found a glob of paths that should be included in the
34
34
  // bundle to make this import work, so we add it to `includedPaths`.
@@ -1,4 +1,3 @@
1
1
  import type { Plugin } from '@netlify/esbuild';
2
- import type { NativeNodeModules } from '..';
3
- declare const getNativeModulesPlugin: (externalizedModules: NativeNodeModules) => Plugin;
4
- export { getNativeModulesPlugin };
2
+ import type { NativeNodeModules } from '../index.js';
3
+ export declare const getNativeModulesPlugin: (externalizedModules: NativeNodeModules) => Plugin;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getNativeModulesPlugin = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const read_package_json_fast_1 = __importDefault(require("read-package-json-fast"));
9
- const detect_native_module_1 = require("../../utils/detect_native_module");
9
+ const detect_native_module_js_1 = require("../../utils/detect_native_module.js");
10
10
  // Filters out relative or absolute file paths.
11
11
  const packageFilter = /^([^./]*)$/;
12
12
  // Filters valid package names and extracts the base directory.
@@ -14,7 +14,7 @@ const packageName = /^([^@][^/]*|@[^/]*\/[^/]+)(?:\/|$)/;
14
14
  const findNativeModule = (packageJsonPath, cache) => {
15
15
  if (cache[packageJsonPath] === undefined) {
16
16
  // eslint-disable-next-line no-param-reassign, promise/prefer-await-to-then
17
- cache[packageJsonPath] = (0, read_package_json_fast_1.default)(packageJsonPath).then((data) => [Boolean((0, detect_native_module_1.isNativeModule)(data)), data], () => [undefined, {}]);
17
+ cache[packageJsonPath] = (0, read_package_json_fast_1.default)(packageJsonPath).then((data) => [Boolean((0, detect_native_module_js_1.isNativeModule)(data)), data], () => [undefined, {}]);
18
18
  }
19
19
  return cache[packageJsonPath];
20
20
  };
@@ -1,3 +1,2 @@
1
1
  import type { Plugin } from '@netlify/esbuild';
2
- declare const getNodeBuiltinPlugin: () => Plugin;
3
- export { getNodeBuiltinPlugin };
2
+ export declare const getNodeBuiltinPlugin: () => Plugin;
@@ -1,7 +1,6 @@
1
- declare const getExternalAndIgnoredModulesFromSpecialCases: ({ srcDir }: {
1
+ export declare const getExternalAndIgnoredModulesFromSpecialCases: ({ srcDir }: {
2
2
  srcDir: string;
3
3
  }) => Promise<{
4
4
  externalModules: string[];
5
5
  ignoredModules: string[];
6
6
  }>;
7
- export { getExternalAndIgnoredModulesFromSpecialCases };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExternalAndIgnoredModulesFromSpecialCases = void 0;
4
- const package_json_1 = require("../../utils/package_json");
4
+ const package_json_js_1 = require("../../utils/package_json.js");
5
5
  const EXTERNAL_MODULES = ['@prisma/client'];
6
6
  const IGNORED_MODULES = ['aws-sdk'];
7
7
  const getModulesForNextJs = ({ dependencies, devDependencies }) => {
@@ -14,7 +14,7 @@ const getModulesForNextJs = ({ dependencies, devDependencies }) => {
14
14
  };
15
15
  };
16
16
  const getExternalAndIgnoredModulesFromSpecialCases = async ({ srcDir }) => {
17
- const { dependencies = {}, devDependencies = {} } = await (0, package_json_1.getPackageJsonIfAvailable)(srcDir);
17
+ const { dependencies = {}, devDependencies = {} } = await (0, package_json_js_1.getPackageJsonIfAvailable)(srcDir);
18
18
  const { externalModules: nextJsExternalModules, ignoredModules: nextJsIgnoredModules } = getModulesForNextJs({
19
19
  dependencies,
20
20
  devDependencies,
@@ -1,3 +1,2 @@
1
- import type { GetSrcFilesFunction } from '..';
2
- declare const getSrcFiles: GetSrcFilesFunction;
3
- export { getSrcFiles };
1
+ import type { GetSrcFilesFunction } from '../index.js';
2
+ export declare const getSrcFiles: GetSrcFilesFunction;
@@ -1,27 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSrcFiles = void 0;
4
- const included_files_1 = require("../../utils/included_files");
5
- const package_json_1 = require("../../utils/package_json");
6
- const traversal_cache_1 = require("../../utils/traversal_cache");
7
- const traverse_1 = require("../zisi/traverse");
4
+ const included_files_js_1 = require("../../utils/included_files.js");
5
+ const package_json_js_1 = require("../../utils/package_json.js");
6
+ const traversal_cache_js_1 = require("../../utils/traversal_cache.js");
7
+ const traverse_js_1 = require("../zisi/traverse.js");
8
8
  const getSrcFiles = async ({ config, mainFile, pluginsModulesPath, srcDir }) => {
9
9
  const { externalNodeModules = [], includedFiles = [], includedFilesBasePath } = config;
10
- const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
10
+ const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
11
11
  const dependencyPaths = await getSrcFilesForDependencies({
12
12
  dependencies: externalNodeModules,
13
13
  basedir: srcDir,
14
14
  pluginsModulesPath,
15
15
  });
16
- const includedPaths = (0, included_files_1.filterExcludedPaths)([...dependencyPaths, ...includedFilePaths], excludedPaths);
16
+ const includedPaths = (0, included_files_js_1.filterExcludedPaths)([...dependencyPaths, ...includedFilePaths], excludedPaths);
17
17
  return [...includedPaths, mainFile];
18
18
  };
19
19
  exports.getSrcFiles = getSrcFiles;
20
- const getSrcFilesForDependencies = async function ({ dependencies: dependencyNames, basedir, state = (0, traversal_cache_1.getNewCache)(), pluginsModulesPath, }) {
20
+ const getSrcFilesForDependencies = async function ({ dependencies: dependencyNames, basedir, state = (0, traversal_cache_js_1.getNewCache)(), pluginsModulesPath, }) {
21
21
  if (dependencyNames.length === 0) {
22
22
  return [];
23
23
  }
24
- const packageJson = await (0, package_json_1.getPackageJson)(basedir);
24
+ const packageJson = await (0, package_json_js_1.getPackageJson)(basedir);
25
25
  const dependencies = await Promise.all(dependencyNames.map((dependencyName) => getSrcFilesForDependency({
26
26
  dependency: dependencyName,
27
27
  basedir,
@@ -32,9 +32,9 @@ const getSrcFilesForDependencies = async function ({ dependencies: dependencyNam
32
32
  const paths = new Set(dependencies.flat());
33
33
  return [...paths];
34
34
  };
35
- const getSrcFilesForDependency = async function ({ dependency, basedir, state = (0, traversal_cache_1.getNewCache)(), packageJson, pluginsModulesPath, }) {
35
+ const getSrcFilesForDependency = async function ({ dependency, basedir, state = (0, traversal_cache_js_1.getNewCache)(), packageJson, pluginsModulesPath, }) {
36
36
  try {
37
- const paths = await (0, traverse_1.getDependencyPathsForDependency)({ dependency, basedir, state, packageJson, pluginsModulesPath });
37
+ const paths = await (0, traverse_js_1.getDependencyPathsForDependency)({ dependency, basedir, state, packageJson, pluginsModulesPath });
38
38
  return paths;
39
39
  }
40
40
  catch (error) {
@@ -1,13 +1,13 @@
1
1
  import type { Message } from '@netlify/esbuild';
2
- import { FunctionConfig } from '../../../config';
3
- import { FeatureFlag, FeatureFlags } from '../../../feature_flags';
4
- import { FunctionSource } from '../../../function';
5
- import { ModuleFormat } from '../utils/module_format';
2
+ import { FunctionConfig } from '../../../config.js';
3
+ import { FeatureFlag, FeatureFlags } from '../../../feature_flags.js';
4
+ import { FunctionSource } from '../../../function.js';
5
+ import { ModuleFormat } from '../utils/module_format.js';
6
6
  export declare type NodeBundlerName = 'esbuild' | 'esbuild_zisi' | 'nft' | 'zisi';
7
7
  declare type BundlerWarning = Message;
8
8
  declare type CleanupFunction = () => Promise<void>;
9
- declare type NativeNodeModules = Record<string, Record<string, string | undefined>>;
10
- declare type BundleFunction = (args: {
9
+ export declare type NativeNodeModules = Record<string, Record<string, string | undefined>>;
10
+ export declare type BundleFunction = (args: {
11
11
  basePath?: string;
12
12
  config: FunctionConfig;
13
13
  featureFlags: Record<FeatureFlag, boolean>;
@@ -26,7 +26,7 @@ declare type BundleFunction = (args: {
26
26
  nodeModulesWithDynamicImports?: string[];
27
27
  srcFiles: string[];
28
28
  }>;
29
- declare type GetSrcFilesFunction = (args: {
29
+ export declare type GetSrcFilesFunction = (args: {
30
30
  basePath?: string;
31
31
  config: FunctionConfig;
32
32
  featureFlags: FeatureFlags;
@@ -37,11 +37,10 @@ interface NodeBundler {
37
37
  bundle: BundleFunction;
38
38
  getSrcFiles: GetSrcFilesFunction;
39
39
  }
40
- declare const getBundler: (name: NodeBundlerName) => NodeBundler;
41
- declare const getDefaultBundler: ({ extension, mainFile, featureFlags, }: {
40
+ export declare const getBundler: (name: NodeBundlerName) => NodeBundler;
41
+ export declare const getDefaultBundler: ({ extension, mainFile, featureFlags, }: {
42
42
  extension: string;
43
43
  mainFile: string;
44
44
  featureFlags: FeatureFlags;
45
45
  }) => Promise<NodeBundlerName>;
46
- export { getBundler, getDefaultBundler };
47
- export type { BundleFunction, GetSrcFilesFunction, NativeNodeModules };
46
+ export {};
@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getDefaultBundler = exports.getBundler = void 0;
7
- const detect_es_module_1 = require("../utils/detect_es_module");
8
- const esbuild_1 = __importDefault(require("./esbuild"));
9
- const nft_1 = __importDefault(require("./nft"));
10
- const zisi_1 = __importDefault(require("./zisi"));
7
+ const detect_es_module_js_1 = require("../utils/detect_es_module.js");
8
+ const index_js_1 = __importDefault(require("./esbuild/index.js"));
9
+ const index_js_2 = __importDefault(require("./nft/index.js"));
10
+ const index_js_3 = __importDefault(require("./zisi/index.js"));
11
11
  const getBundler = (name) => {
12
12
  switch (name) {
13
13
  case 'esbuild':
14
14
  case 'esbuild_zisi':
15
- return esbuild_1.default;
15
+ return index_js_1.default;
16
16
  case 'nft':
17
- return nft_1.default;
17
+ return index_js_2.default;
18
18
  case 'zisi':
19
- return zisi_1.default;
19
+ return index_js_3.default;
20
20
  default:
21
21
  throw new Error(`Unsupported Node bundler: ${name}`);
22
22
  }
@@ -25,17 +25,16 @@ exports.getBundler = getBundler;
25
25
  // We use ZISI as the default bundler, except for certain extensions, for which
26
26
  // esbuild is the only option.
27
27
  const getDefaultBundler = async ({ extension, mainFile, featureFlags, }) => {
28
- const { defaultEsModulesToEsbuild, traceWithNft } = featureFlags;
29
28
  if (['.mjs', '.ts'].includes(extension)) {
30
29
  return 'esbuild';
31
30
  }
32
- if (traceWithNft) {
31
+ if (featureFlags.traceWithNft) {
33
32
  return 'nft';
34
33
  }
35
- if (defaultEsModulesToEsbuild) {
36
- const isEsModule = await (0, detect_es_module_1.detectEsModule)({ mainFile });
37
- if (isEsModule) {
38
- return 'esbuild';
34
+ if (featureFlags.zisi_detect_esm) {
35
+ const functionIsESM = await (0, detect_es_module_js_1.detectEsModule)({ mainFile });
36
+ if (functionIsESM) {
37
+ return 'nft';
39
38
  }
40
39
  }
41
40
  return 'zisi';
@@ -1,9 +1,9 @@
1
1
  import { NodeFileTraceReasons } from '@vercel/nft';
2
- import type { FunctionConfig } from '../../../../config';
3
- import { FeatureFlags } from '../../../../feature_flags';
4
- import { FsCache } from '../../../../utils/fs';
5
- import { ModuleFormat } from '../../utils/module_format';
6
- declare const processESM: ({ basePath, config, esmPaths, featureFlags, fsCache, mainFile, reasons, }: {
2
+ import type { FunctionConfig } from '../../../../config.js';
3
+ import { FeatureFlags } from '../../../../feature_flags.js';
4
+ import { FsCache } from '../../../../utils/fs.js';
5
+ import { ModuleFormat } from '../../utils/module_format.js';
6
+ export declare const processESM: ({ basePath, config, esmPaths, featureFlags, fsCache, mainFile, reasons, }: {
7
7
  basePath: string | undefined;
8
8
  config: FunctionConfig;
9
9
  esmPaths: Set<string>;
@@ -15,4 +15,3 @@ declare const processESM: ({ basePath, config, esmPaths, featureFlags, fsCache,
15
15
  rewrites?: Map<string, string> | undefined;
16
16
  moduleFormat: ModuleFormat;
17
17
  }>;
18
- export { processESM };
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processESM = void 0;
4
4
  const path_1 = require("path");
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");
8
- const transpile_1 = require("./transpile");
5
+ const fs_js_1 = require("../../../../utils/fs.js");
6
+ const node_version_js_1 = require("../../utils/node_version.js");
7
+ const package_json_js_1 = require("../../utils/package_json.js");
8
+ const transpile_js_1 = require("./transpile.js");
9
9
  const getPatchedESMPackages = async (packages, fsCache) => {
10
10
  const patchedPackages = await Promise.all(packages.map((path) => patchESMPackage(path, fsCache)));
11
11
  const patchedPackagesMap = new Map();
@@ -20,7 +20,7 @@ const isEntrypointESM = ({ basePath, esmPaths, mainFile, }) => {
20
20
  return entrypointIsESM;
21
21
  };
22
22
  const patchESMPackage = async (path, fsCache) => {
23
- const file = (await (0, fs_1.cachedReadFile)(fsCache, path, 'utf8'));
23
+ const file = (await (0, fs_js_1.cachedReadFile)(fsCache, path, 'utf8'));
24
24
  const packageJson = JSON.parse(file);
25
25
  const patchedPackageJson = {
26
26
  ...packageJson,
@@ -35,8 +35,8 @@ const processESM = async ({ basePath, config, esmPaths, featureFlags, fsCache, m
35
35
  moduleFormat: 'cjs',
36
36
  };
37
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);
38
+ const packageJson = await (0, package_json_js_1.getPackageJsonIfAvailable)((0, path_1.dirname)(mainFile));
39
+ const nodeSupport = (0, node_version_js_1.getNodeSupportMatrix)(config.nodeVersion);
40
40
  if (featureFlags.zisi_pure_esm && packageJson.type === 'module' && nodeSupport.esm) {
41
41
  return {
42
42
  moduleFormat: 'esm',
@@ -91,7 +91,7 @@ const transpileESM = async ({ basePath, config, esmPaths, fsCache, reasons, }) =
91
91
  const rewrites = await getPatchedESMPackages(packageJsonPaths, fsCache);
92
92
  await Promise.all(pathsToTranspile.map(async (path) => {
93
93
  const absolutePath = resolvePath(path, basePath);
94
- const transpiled = await (0, transpile_1.transpile)(absolutePath, config);
94
+ const transpiled = await (0, transpile_js_1.transpile)(absolutePath, config);
95
95
  rewrites.set(absolutePath, transpiled);
96
96
  }));
97
97
  return rewrites;
@@ -1,5 +1,5 @@
1
- import type { BundleFunction } from '..';
2
- import type { GetSrcFilesFunction } from '../../../runtime';
1
+ import type { GetSrcFilesFunction } from '../../../runtime.js';
2
+ import type { BundleFunction } from '../index.js';
3
3
  declare const bundler: {
4
4
  bundle: BundleFunction;
5
5
  getSrcFiles: GetSrcFilesFunction;