@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
@@ -5,28 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = require("path");
7
7
  const cp_file_1 = __importDefault(require("cp-file"));
8
- const bundlers_1 = require("./bundlers");
9
- const finder_1 = require("./finder");
10
- const in_source_config_1 = require("./in_source_config");
11
- const plugin_modules_path_1 = require("./utils/plugin_modules_path");
12
- const zip_1 = require("./utils/zip");
8
+ const index_js_1 = require("./bundlers/index.js");
9
+ const finder_js_1 = require("./finder.js");
10
+ const index_js_2 = require("./in_source_config/index.js");
11
+ const plugin_modules_path_js_1 = require("./utils/plugin_modules_path.js");
12
+ const zip_js_1 = require("./utils/zip.js");
13
13
  // A proxy for the `getSrcFiles` function which adds a default `bundler` using
14
14
  // the `getDefaultBundler` function.
15
15
  const getSrcFilesWithBundler = async (parameters) => {
16
- const pluginsModulesPath = await (0, plugin_modules_path_1.getPluginsModulesPath)(parameters.srcDir);
16
+ const pluginsModulesPath = await (0, plugin_modules_path_js_1.getPluginsModulesPath)(parameters.srcDir);
17
17
  const bundlerName = parameters.config.nodeBundler ||
18
- (await (0, bundlers_1.getDefaultBundler)({
18
+ (await (0, index_js_1.getDefaultBundler)({
19
19
  extension: parameters.extension,
20
20
  featureFlags: parameters.featureFlags,
21
21
  mainFile: parameters.mainFile,
22
22
  }));
23
- const bundler = (0, bundlers_1.getBundler)(bundlerName);
23
+ const bundler = (0, index_js_1.getBundler)(bundlerName);
24
24
  return bundler.getSrcFiles({ ...parameters, pluginsModulesPath });
25
25
  };
26
26
  const zipFunction = async function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
27
- const pluginsModulesPath = await (0, plugin_modules_path_1.getPluginsModulesPath)(srcDir);
28
- const bundlerName = config.nodeBundler || (await (0, bundlers_1.getDefaultBundler)({ extension, mainFile, featureFlags }));
29
- const bundler = (0, bundlers_1.getBundler)(bundlerName);
27
+ const pluginsModulesPath = await (0, plugin_modules_path_js_1.getPluginsModulesPath)(srcDir);
28
+ const bundlerName = config.nodeBundler || (await (0, index_js_1.getDefaultBundler)({ extension, mainFile, featureFlags }));
29
+ const bundler = (0, index_js_1.getBundler)(bundlerName);
30
30
  // If the file is a zip, we assume the function is bundled and ready to go.
31
31
  // We simply copy it to the destination path with no further processing.
32
32
  if (extension === '.zip') {
@@ -49,9 +49,9 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
49
49
  srcPath,
50
50
  stat,
51
51
  });
52
- const inSourceConfig = await (0, in_source_config_1.findISCDeclarationsInPath)(mainFile);
53
- (0, plugin_modules_path_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
54
- const zipPath = await (0, zip_1.zipNodeJs)({
52
+ const inSourceConfig = await (0, index_js_2.findISCDeclarationsInPath)(mainFile);
53
+ (0, plugin_modules_path_js_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
54
+ const zipPath = await (0, zip_js_1.zipNodeJs)({
55
55
  aliases,
56
56
  archiveFormat,
57
57
  basePath: finalBasePath,
@@ -96,8 +96,8 @@ const zipWithFunctionWithFallback = async ({ config = {}, ...parameters }) => {
96
96
  }
97
97
  };
98
98
  const runtime = {
99
- findFunctionsInPaths: finder_1.findFunctionsInPaths,
100
- findFunctionInPath: finder_1.findFunctionInPath,
99
+ findFunctionsInPaths: finder_js_1.findFunctionsInPaths,
100
+ findFunctionInPath: finder_js_1.findFunctionInPath,
101
101
  getSrcFiles: getSrcFilesWithBundler,
102
102
  name: 'js',
103
103
  zipFunction: zipWithFunctionWithFallback,
@@ -1,4 +1,3 @@
1
1
  import { Statement } from '@babel/types';
2
- import type { ISCExport } from '../in_source_config';
3
- declare const getMainExport: (nodes: Statement[]) => ISCExport[];
4
- export { getMainExport };
2
+ import type { ISCExport } from '../in_source_config/index.js';
3
+ export declare const getMainExport: (nodes: Statement[]) => ISCExport[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMainExport = void 0;
4
- const helpers_1 = require("./helpers");
4
+ const helpers_js_1 = require("./helpers.js");
5
5
  // Finds the main handler export in an AST.
6
6
  const getMainExport = (nodes) => {
7
7
  let handlerExport = [];
@@ -28,7 +28,7 @@ const getMainExportFromCJS = (node) => {
28
28
  ['exports', 'handler'],
29
29
  ];
30
30
  return handlerPaths.flatMap((handlerPath) => {
31
- if (!(0, helpers_1.isModuleExports)(node, handlerPath) || node.expression.right.type !== 'CallExpression') {
31
+ if (!(0, helpers_js_1.isModuleExports)(node, handlerPath) || node.expression.right.type !== 'CallExpression') {
32
32
  return [];
33
33
  }
34
34
  return getExportsFromCallExpression(node.expression.right);
@@ -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,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getImports = void 0;
4
- const non_nullable_1 = require("../../../utils/non_nullable");
5
- const helpers_1 = require("./helpers");
4
+ const non_nullable_js_1 = require("../../../utils/non_nullable.js");
5
+ const helpers_js_1 = require("./helpers.js");
6
6
  // Finds import/require statements of a given path in an AST.
7
7
  const getImports = (node, importPath) => {
8
8
  const esmImports = getImportsFromESM(node, importPath);
@@ -19,7 +19,7 @@ const getImportsFromCJS = (node, importPath) => {
19
19
  return [];
20
20
  }
21
21
  const { declarations } = node;
22
- const requireDeclaration = declarations.find((declaration) => declaration.type === 'VariableDeclarator' && (0, helpers_1.isRequire)(declaration.init, importPath));
22
+ const requireDeclaration = declarations.find((declaration) => declaration.type === 'VariableDeclarator' && (0, helpers_js_1.isRequire)(declaration.init, importPath));
23
23
  if (requireDeclaration === undefined || requireDeclaration.id.type !== 'ObjectPattern') {
24
24
  return [];
25
25
  }
@@ -34,12 +34,12 @@ const getImportsFromCJS = (node, importPath) => {
34
34
  }
35
35
  return { imported: key.name, local: value.name };
36
36
  })
37
- .filter(non_nullable_1.nonNullable);
37
+ .filter(non_nullable_js_1.nonNullable);
38
38
  return imports;
39
39
  };
40
40
  // Finds import/require statements of a given path in an ESM AST.
41
41
  const getImportsFromESM = (node, importPath) => {
42
- if (!(0, helpers_1.isImport)(node, importPath)) {
42
+ if (!(0, helpers_js_1.isImport)(node, importPath)) {
43
43
  return [];
44
44
  }
45
45
  const { specifiers } = node;
@@ -54,7 +54,7 @@ const getImportsFromESM = (node, importPath) => {
54
54
  }
55
55
  return { imported: imported.name, local: local.name };
56
56
  })
57
- .filter(non_nullable_1.nonNullable);
57
+ .filter(non_nullable_js_1.nonNullable);
58
58
  return imports;
59
59
  };
60
60
  //# sourceMappingURL=imports.js.map
@@ -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>;
@@ -5,7 +5,7 @@ exports.safelyParseFile = exports.parseExpression = void 0;
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
7
  const parser_1 = require("@babel/parser");
8
- const non_nullable_1 = require("../../../utils/non_nullable");
8
+ const non_nullable_js_1 = require("../../../utils/non_nullable.js");
9
9
  const GLOB_WILDCARD = '**';
10
10
  // Transforms an array of glob nodes into a glob string including an absolute
11
11
  // path.
@@ -159,7 +159,7 @@ const parseTemplateLiteral = (expression) => {
159
159
  return getWildcardFromASTNode(part);
160
160
  }
161
161
  });
162
- return globNodes.filter(non_nullable_1.nonNullable);
162
+ return globNodes.filter(non_nullable_js_1.nonNullable);
163
163
  };
164
164
  // For our purposes, we consider a glob to be valid if all the nodes are
165
165
  // strings and the first node is static (i.e. not a wildcard character).
@@ -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
- import { PackageJson } from './package_json';
2
- declare const isNativeModule: ({ binary, dependencies, devDependencies, files, gypfile, }: PackageJson) => boolean;
3
- export { isNativeModule };
1
+ import { PackageJson } from './package_json.js';
2
+ export declare const isNativeModule: ({ binary, dependencies, devDependencies, files, gypfile, }: PackageJson) => boolean;
@@ -1,13 +1,12 @@
1
- import type { ModuleFormat } from './module_format';
2
- interface EntryFile {
1
+ import type { ModuleFormat } from './module_format.js';
2
+ export interface EntryFile {
3
3
  contents: string;
4
4
  filename: string;
5
5
  }
6
- declare const getEntryFile: ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }: {
6
+ export declare const getEntryFile: ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }: {
7
7
  commonPrefix: string;
8
8
  filename: string;
9
9
  mainFile: string;
10
10
  moduleFormat: ModuleFormat;
11
11
  userNamespace: string;
12
12
  }) => EntryFile;
13
- export { EntryFile, getEntryFile };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEntryFile = void 0;
4
4
  const path_1 = require("path");
5
- const normalize_path_1 = require("./normalize_path");
5
+ const normalize_path_js_1 = require("./normalize_path.js");
6
6
  const getEntryFileContents = (mainPath, moduleFormat) => {
7
7
  const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
8
8
  if (moduleFormat === 'cjs') {
@@ -11,7 +11,7 @@ const getEntryFileContents = (mainPath, moduleFormat) => {
11
11
  return `export { handler } from '${importPath}'`;
12
12
  };
13
13
  const getEntryFile = ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }) => {
14
- const mainPath = (0, normalize_path_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
14
+ const mainPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
15
15
  const extension = (0, path_1.extname)(filename);
16
16
  const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
17
17
  const contents = getEntryFileContents(mainPath, moduleFormat);
@@ -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;
@@ -1,10 +1,10 @@
1
1
  declare type SupportedVersionNumbers = 8 | 10 | 12 | 14;
2
- declare type NodeVersionString = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`;
3
- interface NodeVersionSupport {
2
+ export declare type NodeVersionString = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`;
3
+ export interface NodeVersionSupport {
4
4
  esm: boolean;
5
5
  }
6
- declare const DEFAULT_NODE_VERSION = 14;
7
- declare const getNodeVersion: (configVersion?: string | undefined) => number;
8
- declare const getNodeSupportMatrix: (configVersion?: string | undefined) => NodeVersionSupport;
9
- declare const parseVersion: (input: string | undefined) => number | undefined;
10
- export { DEFAULT_NODE_VERSION, getNodeSupportMatrix, getNodeVersion, NodeVersionString, NodeVersionSupport, parseVersion, };
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 {};
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseVersion = exports.getNodeVersion = exports.getNodeSupportMatrix = exports.DEFAULT_NODE_VERSION = void 0;
3
+ exports.parseVersion = exports.getNodeSupportMatrix = exports.getNodeVersion = exports.DEFAULT_NODE_VERSION = void 0;
4
4
  // Must match the default version used in Bitballoon.
5
- const DEFAULT_NODE_VERSION = 14;
6
- exports.DEFAULT_NODE_VERSION = DEFAULT_NODE_VERSION;
5
+ exports.DEFAULT_NODE_VERSION = 14;
7
6
  const VERSION_REGEX = /(nodejs)?(\d+)\.x/;
8
- const getNodeVersion = (configVersion) => { var _a; return (_a = parseVersion(configVersion)) !== null && _a !== void 0 ? _a : DEFAULT_NODE_VERSION; };
7
+ const getNodeVersion = (configVersion) => { var _a; return (_a = (0, exports.parseVersion)(configVersion)) !== null && _a !== void 0 ? _a : exports.DEFAULT_NODE_VERSION; };
9
8
  exports.getNodeVersion = getNodeVersion;
10
9
  const getNodeSupportMatrix = (configVersion) => {
11
- const versionNumber = getNodeVersion(configVersion);
10
+ const versionNumber = (0, exports.getNodeVersion)(configVersion);
12
11
  return {
13
12
  esm: versionNumber >= 14,
14
13
  };
@@ -1,6 +1,5 @@
1
- declare const normalizeFilePath: ({ commonPrefix, path, userNamespace, }: {
1
+ export declare const normalizeFilePath: ({ commonPrefix, path, userNamespace, }: {
2
2
  commonPrefix: string;
3
3
  path: string;
4
4
  userNamespace: string;
5
5
  }) => string;
6
- export { normalizeFilePath };
@@ -1,4 +1,4 @@
1
- interface PackageJson {
1
+ export interface PackageJson {
2
2
  name?: string;
3
3
  version?: string;
4
4
  dependencies?: Record<string, string>;
@@ -13,7 +13,11 @@ interface PackageJson {
13
13
  binary?: boolean;
14
14
  type?: string;
15
15
  }
16
- declare const sanitisePackageJson: (packageJson: Record<string, unknown>) => PackageJson;
17
- declare const getPackageJson: (srcDir: string) => Promise<PackageJson>;
18
- declare const getPackageJsonIfAvailable: (srcDir: string) => Promise<PackageJson>;
19
- export { getPackageJson, getPackageJsonIfAvailable, PackageJson, sanitisePackageJson };
16
+ export interface PackageJsonFile {
17
+ contents: PackageJson;
18
+ path: string;
19
+ }
20
+ export declare const getClosestPackageJson: (resolveDir: string) => Promise<PackageJsonFile | null>;
21
+ export declare const getPackageJson: (srcDir: string) => Promise<PackageJson>;
22
+ export declare const getPackageJsonIfAvailable: (srcDir: string) => Promise<PackageJson>;
23
+ export declare const sanitisePackageJson: (packageJson: Record<string, unknown>) => PackageJson;
@@ -3,40 +3,44 @@ 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.sanitisePackageJson = exports.getPackageJsonIfAvailable = exports.getPackageJson = void 0;
6
+ exports.sanitisePackageJson = exports.getPackageJsonIfAvailable = exports.getPackageJson = exports.getClosestPackageJson = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const find_up_1 = __importDefault(require("find-up"));
7
10
  const pkg_dir_1 = __importDefault(require("pkg-dir"));
8
- const sanitiseFiles = (files) => {
9
- if (!Array.isArray(files)) {
10
- return undefined;
11
+ const getClosestPackageJson = async (resolveDir) => {
12
+ const packageJsonPath = await (0, find_up_1.default)(async (directory) => {
13
+ // We stop traversing if we're about to leave the boundaries of any
14
+ // node_modules directory.
15
+ if ((0, path_1.basename)(directory) === 'node_modules') {
16
+ return find_up_1.default.stop;
17
+ }
18
+ const path = (0, path_1.join)(directory, 'package.json');
19
+ const hasPackageJson = await find_up_1.default.exists(path);
20
+ return hasPackageJson ? path : undefined;
21
+ }, { cwd: resolveDir });
22
+ if (packageJsonPath === undefined) {
23
+ return null;
11
24
  }
12
- return files.filter((file) => typeof file === 'string');
25
+ const packageJson = await readPackageJson(packageJsonPath);
26
+ return {
27
+ contents: packageJson,
28
+ path: packageJsonPath,
29
+ };
13
30
  };
14
- const sanitisePackageJson = (packageJson) => ({
15
- ...packageJson,
16
- files: sanitiseFiles(packageJson.files),
17
- });
18
- exports.sanitisePackageJson = sanitisePackageJson;
31
+ exports.getClosestPackageJson = getClosestPackageJson;
19
32
  // Retrieve the `package.json` of a specific project or module
20
33
  const getPackageJson = async function (srcDir) {
21
34
  const packageRoot = await (0, pkg_dir_1.default)(srcDir);
22
35
  if (packageRoot === undefined) {
23
36
  return {};
24
37
  }
25
- const packageJsonPath = `${packageRoot}/package.json`;
26
- try {
27
- // The path depends on the user's build, i.e. must be dynamic
28
- // eslint-disable-next-line import/no-dynamic-require, node/global-require, @typescript-eslint/no-var-requires
29
- const packageJson = require(packageJsonPath);
30
- return sanitisePackageJson(packageJson);
31
- }
32
- catch (error) {
33
- throw new Error(`${packageJsonPath} is invalid JSON: ${error.message}`);
34
- }
38
+ return readPackageJson(`${packageRoot}/package.json`);
35
39
  };
36
40
  exports.getPackageJson = getPackageJson;
37
41
  const getPackageJsonIfAvailable = async (srcDir) => {
38
42
  try {
39
- const packageJson = await getPackageJson(srcDir);
43
+ const packageJson = await (0, exports.getPackageJson)(srcDir);
40
44
  return packageJson;
41
45
  }
42
46
  catch {
@@ -44,4 +48,25 @@ const getPackageJsonIfAvailable = async (srcDir) => {
44
48
  }
45
49
  };
46
50
  exports.getPackageJsonIfAvailable = getPackageJsonIfAvailable;
51
+ const readPackageJson = async (path) => {
52
+ try {
53
+ // The path depends on the user's build, i.e. must be dynamic
54
+ const packageJson = JSON.parse(await fs_1.promises.readFile(path, 'utf8'));
55
+ return (0, exports.sanitisePackageJson)(packageJson);
56
+ }
57
+ catch (error) {
58
+ throw new Error(`${path} is invalid JSON: ${error.message}`);
59
+ }
60
+ };
61
+ const sanitiseFiles = (files) => {
62
+ if (!Array.isArray(files)) {
63
+ return undefined;
64
+ }
65
+ return files.filter((file) => typeof file === 'string');
66
+ };
67
+ const sanitisePackageJson = (packageJson) => ({
68
+ ...packageJson,
69
+ files: sanitiseFiles(packageJson.files),
70
+ });
71
+ exports.sanitisePackageJson = sanitisePackageJson;
47
72
  //# sourceMappingURL=package_json.js.map
@@ -1,3 +1,2 @@
1
- declare const createAliases: (paths: string[], pluginsModulesPath: string | undefined, aliases: Map<string, string>, basePath: string) => void;
2
- declare const getPluginsModulesPath: (srcDir: string) => Promise<string | undefined>;
3
- export { createAliases, getPluginsModulesPath };
1
+ export declare const createAliases: (paths: string[], pluginsModulesPath: string | undefined, aliases: Map<string, string>, basePath: string) => void;
2
+ export declare const getPluginsModulesPath: (srcDir: string) => Promise<string | undefined>;
@@ -1,7 +1,6 @@
1
- interface TraversalCache {
1
+ export interface TraversalCache {
2
2
  localFiles: Set<string>;
3
3
  moduleNames: Set<string>;
4
4
  modulePaths: Set<string>;
5
5
  }
6
- declare const getNewCache: () => TraversalCache;
7
- export { TraversalCache, getNewCache };
6
+ export declare const getNewCache: () => TraversalCache;
@@ -1,5 +1,5 @@
1
- import type { ModuleFormat } from './module_format';
2
- declare type ArchiveFormat = 'none' | 'zip';
1
+ import type { ModuleFormat } from './module_format.js';
2
+ export declare type ArchiveFormat = 'none' | 'zip';
3
3
  interface ZipNodeParameters {
4
4
  aliases?: Map<string, string>;
5
5
  basePath: string;
@@ -11,7 +11,7 @@ interface ZipNodeParameters {
11
11
  rewrites?: Map<string, string>;
12
12
  srcFiles: string[];
13
13
  }
14
- declare const zipNodeJs: ({ archiveFormat, ...options }: ZipNodeParameters & {
14
+ export declare const zipNodeJs: ({ archiveFormat, ...options }: ZipNodeParameters & {
15
15
  archiveFormat: ArchiveFormat;
16
16
  }) => Promise<string>;
17
- export { ArchiveFormat, zipNodeJs };
17
+ export {};
@@ -11,17 +11,17 @@ const path_1 = require("path");
11
11
  const cp_file_1 = __importDefault(require("cp-file"));
12
12
  const del_1 = __importDefault(require("del"));
13
13
  const p_map_1 = __importDefault(require("p-map"));
14
- const archive_1 = require("../../../archive");
15
- const fs_2 = require("../../../utils/fs");
16
- const entry_file_1 = require("./entry_file");
17
- const normalize_path_1 = require("./normalize_path");
14
+ const archive_js_1 = require("../../../archive.js");
15
+ const fs_js_1 = require("../../../utils/fs.js");
16
+ const entry_file_js_1 = require("./entry_file.js");
17
+ const normalize_path_js_1 = require("./normalize_path.js");
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
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)({
24
+ const { contents: entryContents, filename: entryFilename } = (0, entry_file_js_1.getEntryFile)({
25
25
  commonPrefix: basePath,
26
26
  filename,
27
27
  mainFile,
@@ -37,14 +37,14 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
37
37
  // Copying source files.
38
38
  await (0, p_map_1.default)(srcFiles, (srcFile) => {
39
39
  const destPath = aliases.get(srcFile) || srcFile;
40
- const normalizedDestPath = (0, normalize_path_1.normalizeFilePath)({
40
+ const normalizedDestPath = (0, normalize_path_js_1.normalizeFilePath)({
41
41
  commonPrefix: basePath,
42
42
  path: destPath,
43
43
  userNamespace: DEFAULT_USER_SUBDIRECTORY,
44
44
  });
45
45
  const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
46
46
  if (rewrites.has(srcFile)) {
47
- return (0, fs_2.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
47
+ return (0, fs_js_1.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
48
48
  }
49
49
  return (0, cp_file_1.default)(srcFile, absoluteDestPath);
50
50
  }, { concurrency: COPY_FILE_CONCURRENCY });
@@ -52,7 +52,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
52
52
  };
53
53
  const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
54
54
  const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
55
- const { archive, output } = (0, archive_1.startZip)(destPath);
55
+ const { archive, output } = (0, archive_js_1.startZip)(destPath);
56
56
  const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
57
57
  const entryFilePath = (0, path_1.resolve)(basePath, entryFilename);
58
58
  // We don't need an entry file if it would end up with the same path as the
@@ -66,7 +66,7 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
66
66
  // than the entry file) to its own sub-directory.
67
67
  const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
68
68
  if (needsEntryFile) {
69
- const entryFile = (0, entry_file_1.getEntryFile)({ commonPrefix: basePath, filename, mainFile, moduleFormat, userNamespace });
69
+ const entryFile = (0, entry_file_js_1.getEntryFile)({ commonPrefix: basePath, filename, mainFile, moduleFormat, userNamespace });
70
70
  addEntryFileToZip(archive, entryFile);
71
71
  }
72
72
  const srcFilesInfos = await Promise.all(srcFiles.map(addStat));
@@ -83,7 +83,7 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
83
83
  userNamespace,
84
84
  });
85
85
  });
86
- await (0, archive_1.endZip)(archive, output);
86
+ await (0, archive_js_1.endZip)(archive, output);
87
87
  return destPath;
88
88
  };
89
89
  const zipNodeJs = function ({ archiveFormat, ...options }) {
@@ -95,7 +95,7 @@ const zipNodeJs = function ({ archiveFormat, ...options }) {
95
95
  exports.zipNodeJs = zipNodeJs;
96
96
  const addEntryFileToZip = function (archive, { contents, filename }) {
97
97
  const contentBuffer = buffer_1.Buffer.from(contents);
98
- (0, archive_1.addZipContent)(archive, contentBuffer, filename);
98
+ (0, archive_js_1.addZipContent)(archive, contentBuffer, filename);
99
99
  };
100
100
  const addStat = async function (srcFile) {
101
101
  const stat = await fs_1.promises.lstat(srcFile);
@@ -103,12 +103,12 @@ const addStat = async function (srcFile) {
103
103
  };
104
104
  const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, rewrites = new Map(), stat, srcFile, userNamespace, }) {
105
105
  const destPath = aliases.get(srcFile) || srcFile;
106
- const normalizedDestPath = (0, normalize_path_1.normalizeFilePath)({ commonPrefix, path: destPath, userNamespace });
106
+ const normalizedDestPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: destPath, userNamespace });
107
107
  if (rewrites.has(srcFile)) {
108
- (0, archive_1.addZipContent)(archive, rewrites.get(srcFile), normalizedDestPath);
108
+ (0, archive_js_1.addZipContent)(archive, rewrites.get(srcFile), normalizedDestPath);
109
109
  }
110
110
  else {
111
- (0, archive_1.addZipFile)(archive, srcFile, normalizedDestPath, stat);
111
+ (0, archive_js_1.addZipFile)(archive, srcFile, normalizedDestPath, stat);
112
112
  }
113
113
  };
114
114
  //# sourceMappingURL=zip.js.map
@@ -1,28 +1,28 @@
1
- import { ArchiveFormat } from '../archive';
2
- import { FunctionConfig } from '../config';
3
- import { FeatureFlags } from '../feature_flags';
4
- import { FunctionSource, SourceFile } from '../function';
5
- import { FsCache } from '../utils/fs';
6
- import type { NodeBundlerName } from './node/bundlers';
7
- import type { ISCValues } from './node/in_source_config';
8
- declare type RuntimeName = 'go' | 'js' | 'rs';
9
- declare type FindFunctionsInPathsFunction = (args: {
1
+ import { ArchiveFormat } from '../archive.js';
2
+ import { FunctionConfig } from '../config.js';
3
+ import { FeatureFlags } from '../feature_flags.js';
4
+ import { FunctionSource, SourceFile } from '../function.js';
5
+ import { FsCache } from '../utils/fs.js';
6
+ import type { NodeBundlerName } from './node/bundlers/index.js';
7
+ import type { ISCValues } from './node/in_source_config/index.js';
8
+ export declare type RuntimeName = 'go' | 'js' | 'rs';
9
+ export declare type FindFunctionsInPathsFunction = (args: {
10
10
  featureFlags: FeatureFlags;
11
11
  fsCache: FsCache;
12
12
  paths: string[];
13
13
  }) => Promise<SourceFile[]>;
14
- declare type FindFunctionInPathFunction = (args: {
14
+ export declare type FindFunctionInPathFunction = (args: {
15
15
  featureFlags: FeatureFlags;
16
16
  fsCache: FsCache;
17
17
  path: string;
18
18
  }) => Promise<SourceFile | undefined>;
19
- declare type GetSrcFilesFunction = (args: {
19
+ export declare type GetSrcFilesFunction = (args: {
20
20
  basePath?: string;
21
21
  config: FunctionConfig;
22
22
  featureFlags: FeatureFlags;
23
23
  repositoryRoot?: string;
24
24
  } & FunctionSource) => Promise<string[]>;
25
- interface ZipFunctionResult {
25
+ export interface ZipFunctionResult {
26
26
  bundler?: NodeBundlerName;
27
27
  bundlerErrors?: object[];
28
28
  bundlerWarnings?: object[];
@@ -33,7 +33,7 @@ interface ZipFunctionResult {
33
33
  nodeModulesWithDynamicImports?: string[];
34
34
  path: string;
35
35
  }
36
- declare type ZipFunction = (args: {
36
+ export declare type ZipFunction = (args: {
37
37
  archiveFormat: ArchiveFormat;
38
38
  basePath?: string;
39
39
  config: FunctionConfig;
@@ -41,11 +41,10 @@ declare type ZipFunction = (args: {
41
41
  featureFlags: FeatureFlags;
42
42
  repositoryRoot?: string;
43
43
  } & FunctionSource) => Promise<ZipFunctionResult>;
44
- interface Runtime {
44
+ export interface Runtime {
45
45
  findFunctionsInPaths: FindFunctionsInPathsFunction;
46
46
  findFunctionInPath: FindFunctionInPathFunction;
47
47
  getSrcFiles?: GetSrcFilesFunction;
48
48
  name: RuntimeName;
49
49
  zipFunction: ZipFunction;
50
50
  }
51
- export { FindFunctionInPathFunction, FindFunctionsInPathsFunction, GetSrcFilesFunction, Runtime, RuntimeName, ZipFunction, ZipFunctionResult, };
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { FunctionConfig } from '../../config';
3
- declare const build: ({ config, name, srcDir }: {
2
+ import { FunctionConfig } from '../../config.js';
3
+ export declare const build: ({ config, name, srcDir }: {
4
4
  config: FunctionConfig;
5
5
  name: string;
6
6
  srcDir: string;
@@ -8,4 +8,3 @@ declare const build: ({ config, name, srcDir }: {
8
8
  path: string;
9
9
  stat: import("fs").Stats;
10
10
  }>;
11
- export { build };