@netlify/zip-it-and-ship-it 5.9.2 → 5.10.2

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 (30) hide show
  1. package/dist/config.js +2 -2
  2. package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +2 -2
  3. package/dist/runtimes/node/bundlers/esbuild/index.js +2 -1
  4. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +2 -2
  5. package/dist/runtimes/node/bundlers/esbuild/src_files.js +7 -3
  6. package/dist/runtimes/node/bundlers/index.d.ts +5 -1
  7. package/dist/runtimes/node/bundlers/nft/index.d.ts +1 -2
  8. package/dist/runtimes/node/bundlers/nft/index.js +13 -9
  9. package/dist/runtimes/node/bundlers/zisi/index.js +2 -1
  10. package/dist/runtimes/node/bundlers/zisi/published.js +2 -7
  11. package/dist/runtimes/node/bundlers/zisi/src_files.js +4 -3
  12. package/dist/runtimes/node/bundlers/zisi/tree_files.d.ts +1 -1
  13. package/dist/runtimes/node/bundlers/zisi/tree_files.js +2 -7
  14. package/dist/runtimes/node/in_source_config/index.js +4 -2
  15. package/dist/runtimes/node/in_source_config/properties/schedule.d.ts +2 -1
  16. package/dist/runtimes/node/in_source_config/properties/schedule.js +8 -2
  17. package/dist/runtimes/node/index.js +4 -2
  18. package/dist/runtimes/node/parser/bindings.d.ts +5 -0
  19. package/dist/runtimes/node/parser/bindings.js +50 -0
  20. package/dist/runtimes/node/parser/exports.d.ts +3 -2
  21. package/dist/runtimes/node/parser/exports.js +36 -12
  22. package/dist/runtimes/node/utils/included_files.d.ts +3 -3
  23. package/dist/runtimes/node/utils/included_files.js +13 -18
  24. package/dist/runtimes/node/utils/node_version.d.ts +2 -2
  25. package/dist/runtimes/node/utils/package_json.js +3 -6
  26. package/dist/runtimes/runtime.d.ts +1 -0
  27. package/dist/utils/fs.d.ts +2 -0
  28. package/dist/utils/matching.d.ts +9 -0
  29. package/dist/utils/matching.js +32 -0
  30. package/package.json +7 -6
package/dist/config.js CHANGED
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getConfigForFunction = void 0;
7
7
  const merge_options_1 = __importDefault(require("merge-options"));
8
- const minimatch_1 = __importDefault(require("minimatch"));
8
+ const matching_js_1 = require("./utils/matching.js");
9
9
  const getConfigForFunction = ({ config, func, }) => {
10
10
  if (!config) {
11
11
  return {};
12
12
  }
13
13
  // It's safe to mutate the array because it's local to this function.
14
14
  const matches = Object.keys(config)
15
- .filter((expression) => (0, minimatch_1.default)(func.name, expression))
15
+ .filter((expression) => (0, matching_js_1.minimatch)(func.name, expression))
16
16
  .map((expression) => {
17
17
  const wildcardCount = [...expression].filter((char) => char === '*').length;
18
18
  // The weight increases with the number of hardcoded (i.e. non-wildcard)
@@ -8,8 +8,8 @@ declare const versionMap: {
8
8
  };
9
9
  declare type VersionKeys = keyof typeof versionMap;
10
10
  declare type VersionValues = typeof versionMap[VersionKeys];
11
- declare const getBundlerTarget: (suppliedVersion?: string | undefined) => VersionValues;
12
- declare const getModuleFormat: (srcDir: string, featureFlags: FeatureFlags, configVersion?: string | undefined) => Promise<{
11
+ declare const getBundlerTarget: (suppliedVersion?: string) => VersionValues;
12
+ declare const getModuleFormat: (srcDir: string, featureFlags: FeatureFlags, configVersion?: string) => Promise<{
13
13
  includedFiles: string[];
14
14
  moduleFormat: ModuleFormat;
15
15
  }>;
@@ -42,7 +42,7 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
42
42
  srcFile: mainFile,
43
43
  });
44
44
  const bundlerWarnings = warnings.length === 0 ? undefined : warnings;
45
- const srcFiles = await (0, src_files_js_1.getSrcFiles)({
45
+ const { srcFiles, includedFiles } = await (0, src_files_js_1.getSrcFiles)({
46
46
  basePath,
47
47
  config: {
48
48
  ...config,
@@ -77,6 +77,7 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
77
77
  cleanupFunction: cleanTempFiles,
78
78
  basePath: functionBasePath,
79
79
  bundlerWarnings,
80
+ includedFiles,
80
81
  inputs,
81
82
  mainFile: normalizedMainFile,
82
83
  moduleFormat,
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getDynamicImportsPlugin = void 0;
7
7
  const path_1 = require("path");
8
8
  const find_up_1 = __importDefault(require("find-up"));
9
+ const normalize_path_1 = __importDefault(require("normalize-path"));
9
10
  const read_package_json_fast_1 = __importDefault(require("read-package-json-fast"));
10
- const unixify_1 = __importDefault(require("unixify"));
11
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
@@ -81,7 +81,7 @@ const getShimContents = ({ expressionType, resolveDir, srcDir, }) => {
81
81
  // relative to the main bundle file, since esbuild will flatten everything
82
82
  // into a single file.
83
83
  const relativeResolveDir = (0, path_1.relative)(srcDir, resolveDir);
84
- const requireArg = relativeResolveDir ? `\`./${(0, unixify_1.default)(relativeResolveDir)}/$\{args}\`` : 'args';
84
+ const requireArg = relativeResolveDir ? `\`./${(0, normalize_path_1.default)(relativeResolveDir)}/$\{args}\`` : 'args';
85
85
  if (expressionType === 'require') {
86
86
  return `module.exports = args => require(${requireArg})`;
87
87
  }
@@ -7,14 +7,18 @@ const traversal_cache_js_1 = require("../../utils/traversal_cache.js");
7
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_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
10
+ const { excludePatterns, 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_js_1.filterExcludedPaths)([...dependencyPaths, ...includedFilePaths], excludedPaths);
17
- return [...includedPaths, mainFile];
16
+ const srcFiles = (0, included_files_js_1.filterExcludedPaths)(dependencyPaths, excludePatterns);
17
+ const includedPaths = (0, included_files_js_1.filterExcludedPaths)(includedFilePaths, excludePatterns);
18
+ return {
19
+ srcFiles: [...srcFiles, ...includedPaths, mainFile],
20
+ includedFiles: includedPaths,
21
+ };
18
22
  };
19
23
  exports.getSrcFiles = getSrcFiles;
20
24
  const getSrcFilesForDependencies = async function ({ dependencies: dependencyNames, basedir, state = (0, traversal_cache_js_1.getNewCache)(), pluginsModulesPath, }) {
@@ -19,6 +19,7 @@ export declare type BundleFunction = (args: {
19
19
  basePath: string;
20
20
  bundlerWarnings?: BundlerWarning[];
21
21
  cleanupFunction?: CleanupFunction;
22
+ includedFiles: string[];
22
23
  inputs: string[];
23
24
  mainFile: string;
24
25
  moduleFormat: ModuleFormat;
@@ -32,7 +33,10 @@ export declare type GetSrcFilesFunction = (args: {
32
33
  featureFlags: FeatureFlags;
33
34
  pluginsModulesPath?: string;
34
35
  repositoryRoot?: string;
35
- } & FunctionSource) => Promise<string[]>;
36
+ } & FunctionSource) => Promise<{
37
+ srcFiles: string[];
38
+ includedFiles: string[];
39
+ }>;
36
40
  interface NodeBundler {
37
41
  bundle: BundleFunction;
38
42
  getSrcFiles: GetSrcFilesFunction;
@@ -1,5 +1,4 @@
1
- import type { GetSrcFilesFunction } from '../../../runtime.js';
2
- import type { BundleFunction } from '../index.js';
1
+ import type { GetSrcFilesFunction, BundleFunction } from '../index.js';
3
2
  declare const bundler: {
4
3
  bundle: BundleFunction;
5
4
  getSrcFiles: GetSrcFilesFunction;
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = require("path");
7
7
  const nft_1 = require("@vercel/nft");
8
8
  const resolve_dependency_js_1 = __importDefault(require("@vercel/nft/out/resolve-dependency.js"));
9
- const minimatch_1 = __importDefault(require("minimatch"));
10
- const unixify_1 = __importDefault(require("unixify"));
11
9
  const fs_js_1 = require("../../../../utils/fs.js");
10
+ const matching_js_1 = require("../../../../utils/matching.js");
12
11
  const base_path_js_1 = require("../../utils/base_path.js");
13
12
  const included_files_js_1 = require("../../utils/included_files.js");
14
13
  const es_modules_js_1 = require("./es_modules.js");
@@ -17,7 +16,7 @@ const ignore = ['node_modules/aws-sdk/**'];
17
16
  const appearsToBeModuleName = (name) => !name.startsWith('.');
18
17
  const bundle = async ({ basePath, config, featureFlags, mainFile, name, pluginsModulesPath, repositoryRoot = basePath, }) => {
19
18
  const { includedFiles = [], includedFilesBasePath } = config;
20
- const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath || basePath);
19
+ const { excludePatterns, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath || basePath);
21
20
  const { moduleFormat, paths: dependencyPaths, rewrites, } = await traceFilesAndTranspile({
22
21
  basePath: repositoryRoot,
23
22
  config,
@@ -26,12 +25,14 @@ const bundle = async ({ basePath, config, featureFlags, mainFile, name, pluginsM
26
25
  pluginsModulesPath,
27
26
  name,
28
27
  });
29
- const filteredIncludedPaths = (0, included_files_js_1.filterExcludedPaths)([...dependencyPaths, ...includedFilePaths], excludedPaths);
28
+ const includedPaths = (0, included_files_js_1.filterExcludedPaths)(includedFilePaths, excludePatterns);
29
+ const filteredIncludedPaths = [...(0, included_files_js_1.filterExcludedPaths)(dependencyPaths, excludePatterns), ...includedPaths];
30
30
  const dirnames = filteredIncludedPaths.map((filePath) => (0, path_1.normalize)((0, path_1.dirname)(filePath))).sort();
31
31
  // Sorting the array to make the checksum deterministic.
32
32
  const srcFiles = [...filteredIncludedPaths].sort();
33
33
  return {
34
34
  basePath: (0, base_path_js_1.getBasePath)(dirnames),
35
+ includedFiles: includedPaths,
35
36
  inputs: dependencyPaths,
36
37
  mainFile,
37
38
  moduleFormat,
@@ -40,8 +41,7 @@ const bundle = async ({ basePath, config, featureFlags, mainFile, name, pluginsM
40
41
  };
41
42
  };
42
43
  const ignoreFunction = (path) => {
43
- const normalizedPath = (0, unixify_1.default)(path);
44
- const shouldIgnore = ignore.some((expression) => (0, minimatch_1.default)(normalizedPath, expression));
44
+ const shouldIgnore = ignore.some((expression) => (0, matching_js_1.minimatch)(path, expression));
45
45
  return shouldIgnore;
46
46
  };
47
47
  const traceFilesAndTranspile = async function ({ basePath, config, featureFlags, mainFile, pluginsModulesPath, name, }) {
@@ -96,11 +96,15 @@ const traceFilesAndTranspile = async function ({ basePath, config, featureFlags,
96
96
  };
97
97
  const getSrcFiles = async function ({ basePath, config, mainFile }) {
98
98
  const { includedFiles = [], includedFilesBasePath } = config;
99
- const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
99
+ const { excludePatterns, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
100
100
  const { fileList: dependencyPaths } = await (0, nft_1.nodeFileTrace)([mainFile], { base: basePath, ignore: ignoreFunction });
101
101
  const normalizedDependencyPaths = [...dependencyPaths].map((path) => basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path));
102
- const includedPaths = (0, included_files_js_1.filterExcludedPaths)([...normalizedDependencyPaths, ...includedFilePaths], excludedPaths);
103
- return includedPaths;
102
+ const srcFiles = (0, included_files_js_1.filterExcludedPaths)(normalizedDependencyPaths, excludePatterns);
103
+ const includedPaths = (0, included_files_js_1.filterExcludedPaths)(includedFilePaths, excludePatterns);
104
+ return {
105
+ srcFiles: [...srcFiles, ...includedPaths],
106
+ includedFiles: includedPaths,
107
+ };
104
108
  };
105
109
  const bundler = { bundle, getSrcFiles };
106
110
  exports.default = bundler;
@@ -4,7 +4,7 @@ const path_1 = require("path");
4
4
  const base_path_js_1 = require("../../utils/base_path.js");
5
5
  const src_files_js_1 = require("./src_files.js");
6
6
  const bundle = async ({ basePath, config, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, runtime, srcDir, srcPath, stat, }) => {
7
- const srcFiles = await (0, src_files_js_1.getSrcFiles)({
7
+ const { srcFiles, includedFiles } = await (0, src_files_js_1.getSrcFiles)({
8
8
  basePath,
9
9
  config: {
10
10
  ...config,
@@ -24,6 +24,7 @@ const bundle = async ({ basePath, config, extension, featureFlags, filename, mai
24
24
  const dirnames = srcFiles.map((filePath) => (0, path_1.normalize)((0, path_1.dirname)(filePath)));
25
25
  return {
26
26
  basePath: (0, base_path_js_1.getBasePath)(dirnames),
27
+ includedFiles,
27
28
  inputs: srcFiles,
28
29
  mainFile,
29
30
  moduleFormat: 'cjs',
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getPublishedFiles = void 0;
7
- const util_1 = require("util");
8
- const glob_1 = __importDefault(require("glob"));
9
- const pGlob = (0, util_1.promisify)(glob_1.default);
4
+ const matching_1 = require("../../../../utils/matching");
10
5
  // We use all the files published by the Node.js except some that are not needed
11
6
  const getPublishedFiles = async function (modulePath) {
12
7
  const ignore = getIgnoredFiles(modulePath);
13
- const publishedFiles = await pGlob(`${modulePath}/**`, {
8
+ const publishedFiles = await (0, matching_1.glob)(`${modulePath}/**`, {
14
9
  ignore,
15
10
  nodir: true,
16
11
  absolute: true,
@@ -22,7 +22,7 @@ const tree_shake_js_1 = require("./tree_shake.js");
22
22
  // has a size limit for the zipped file. It also makes cold starts faster.
23
23
  const getSrcFiles = async function ({ config, featureFlags, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }) {
24
24
  const { includedFiles = [], includedFilesBasePath } = config;
25
- const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
25
+ const { excludePatterns, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
26
26
  const [treeFiles, depFiles] = await Promise.all([
27
27
  (0, tree_files_js_1.getTreeFiles)(srcPath, stat),
28
28
  getDependencies({ featureFlags, functionName: name, mainFile, pluginsModulesPath, srcDir }),
@@ -32,8 +32,9 @@ const getSrcFiles = async function ({ config, featureFlags, mainFile, name, plug
32
32
  // We sort so that the archive's checksum is deterministic.
33
33
  // Mutating is fine since `Array.filter()` returns a shallow copy
34
34
  const filteredFiles = uniqueFiles.filter(isNotJunk).sort();
35
- const includedPaths = (0, included_files_js_1.filterExcludedPaths)([...filteredFiles, ...includedFilePaths], excludedPaths);
36
- return includedPaths;
35
+ const srcFiles = (0, included_files_js_1.filterExcludedPaths)(filteredFiles, excludePatterns);
36
+ const includedPaths = (0, included_files_js_1.filterExcludedPaths)(includedFilePaths, excludePatterns);
37
+ return { srcFiles: [...srcFiles, ...includedPaths], includedFiles: includedPaths };
37
38
  };
38
39
  exports.getSrcFiles = getSrcFiles;
39
40
  // Remove temporary files like *~, *.swp, etc.
@@ -1,2 +1,2 @@
1
- import { Stats } from 'fs';
1
+ import type { Stats } from 'fs';
2
2
  export declare const getTreeFiles: (srcPath: string, stat: Stats) => Promise<string[]>;
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getTreeFiles = void 0;
7
- const util_1 = require("util");
8
- const glob_1 = __importDefault(require("glob"));
9
- const pGlob = (0, util_1.promisify)(glob_1.default);
4
+ const matching_1 = require("../../../../utils/matching");
10
5
  // When using a directory, we include all its descendants except `node_modules`
11
6
  const getTreeFiles = async function (srcPath, stat) {
12
7
  if (!stat.isDirectory()) {
13
8
  return [srcPath];
14
9
  }
15
- return await pGlob(`${srcPath}/**`, {
10
+ return await (0, matching_1.glob)(`${srcPath}/**`, {
16
11
  ignore: `${srcPath}/**/node_modules/**`,
17
12
  nodir: true,
18
13
  absolute: true,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findISCDeclarationsInPath = exports.IN_SOURCE_CONFIG_MODULE = void 0;
4
4
  const non_nullable_js_1 = require("../../../utils/non_nullable.js");
5
+ const bindings_js_1 = require("../parser/bindings.js");
5
6
  const exports_js_1 = require("../parser/exports.js");
6
7
  const imports_js_1 = require("../parser/imports.js");
7
8
  const index_js_1 = require("../parser/index.js");
@@ -16,7 +17,8 @@ const findISCDeclarationsInPath = async (sourcePath) => {
16
17
  return {};
17
18
  }
18
19
  const imports = ast.body.flatMap((node) => (0, imports_js_1.getImports)(node, exports.IN_SOURCE_CONFIG_MODULE));
19
- const mainExports = (0, exports_js_1.getMainExport)(ast.body);
20
+ const getAllBindings = (0, bindings_js_1.createBindingsMethod)(ast.body);
21
+ const mainExports = (0, exports_js_1.getMainExport)(ast.body, getAllBindings);
20
22
  const iscExports = mainExports
21
23
  .map(({ args, local: exportName }) => {
22
24
  const matchingImport = imports.find(({ local: importName }) => importName === exportName);
@@ -25,7 +27,7 @@ const findISCDeclarationsInPath = async (sourcePath) => {
25
27
  }
26
28
  switch (matchingImport.imported) {
27
29
  case 'schedule':
28
- return (0, schedule_js_1.parse)({ args });
30
+ return (0, schedule_js_1.parse)({ args }, getAllBindings);
29
31
  default:
30
32
  // no-op
31
33
  }
@@ -1,6 +1,7 @@
1
+ import type { BindingMethod } from '../../parser/bindings.js';
1
2
  import type { ISCHandlerArg } from '../index.js';
2
3
  export declare const parse: ({ args }: {
3
4
  args: ISCHandlerArg[];
4
- }) => {
5
+ }, getAllBindings: BindingMethod) => {
5
6
  schedule: string | undefined;
6
7
  };
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parse = void 0;
4
- const parse = ({ args }) => {
5
- const [expression] = args;
4
+ const parse = ({ args }, getAllBindings) => {
5
+ let [expression] = args;
6
+ if (expression.type === 'Identifier') {
7
+ const binding = getAllBindings().get(expression.name);
8
+ if (binding) {
9
+ expression = binding;
10
+ }
11
+ }
6
12
  const schedule = expression.type === 'StringLiteral' ? expression.value : undefined;
7
13
  return {
8
14
  schedule,
@@ -21,7 +21,8 @@ const getSrcFilesWithBundler = async (parameters) => {
21
21
  mainFile: parameters.mainFile,
22
22
  }));
23
23
  const bundler = (0, index_js_1.getBundler)(bundlerName);
24
- return bundler.getSrcFiles({ ...parameters, pluginsModulesPath });
24
+ const result = await bundler.getSrcFiles({ ...parameters, pluginsModulesPath });
25
+ return result.srcFiles;
25
26
  };
26
27
  const zipFunction = async function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
27
28
  const pluginsModulesPath = await (0, plugin_modules_path_js_1.getPluginsModulesPath)(srcDir);
@@ -34,7 +35,7 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
34
35
  await (0, cp_file_1.default)(srcPath, destPath);
35
36
  return { config, path: destPath };
36
37
  }
37
- const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, inputs, mainFile: finalMainFile = mainFile, moduleFormat, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = await bundler.bundle({
38
+ const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, includedFiles, inputs, mainFile: finalMainFile = mainFile, moduleFormat, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = await bundler.bundle({
38
39
  basePath,
39
40
  config,
40
41
  extension,
@@ -69,6 +70,7 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
69
70
  bundlerWarnings,
70
71
  config,
71
72
  inputs,
73
+ includedFiles,
72
74
  inSourceConfig,
73
75
  nativeNodeModules,
74
76
  nodeModulesWithDynamicImports,
@@ -0,0 +1,5 @@
1
+ import type { Expression, Statement } from '@babel/types';
2
+ declare type Bindings = Map<string, Expression>;
3
+ export declare type BindingMethod = () => Bindings;
4
+ export declare const createBindingsMethod: (nodes: Statement[]) => BindingMethod;
5
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBindingsMethod = void 0;
4
+ const getBindingFromVariableDeclaration = function (node, bindings) {
5
+ node.declarations.forEach((declaration) => {
6
+ if (declaration.id.type === 'Identifier' && declaration.init) {
7
+ bindings.set(declaration.id.name, declaration.init);
8
+ }
9
+ });
10
+ };
11
+ // eslint-disable-next-line complexity
12
+ const getBindingsFromNode = function (node, bindings) {
13
+ var _a;
14
+ if (node.type === 'VariableDeclaration') {
15
+ // A variable was created, so create it and store the potential value
16
+ getBindingFromVariableDeclaration(node, bindings);
17
+ }
18
+ else if (node.type === 'ExpressionStatement' &&
19
+ node.expression.type === 'AssignmentExpression' &&
20
+ node.expression.left.type === 'Identifier') {
21
+ // The variable was reassigned, so let's store the new value
22
+ bindings.set(node.expression.left.name, node.expression.right);
23
+ }
24
+ else if (node.type === 'ExportNamedDeclaration' && ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.type) === 'VariableDeclaration') {
25
+ // A `export const|let ...` creates a binding that can later be referenced again
26
+ getBindingFromVariableDeclaration(node.declaration, bindings);
27
+ }
28
+ };
29
+ /**
30
+ * Goes through all relevant nodes and creates a map from binding name to assigned value/expression
31
+ */
32
+ const getAllBindings = function (nodes) {
33
+ const bindings = new Map();
34
+ nodes.forEach((node) => {
35
+ getBindingsFromNode(node, bindings);
36
+ });
37
+ return bindings;
38
+ };
39
+ const createBindingsMethod = function (nodes) {
40
+ // memoize the result for these nodes
41
+ let result;
42
+ return () => {
43
+ if (!result) {
44
+ result = getAllBindings(nodes);
45
+ }
46
+ return result;
47
+ };
48
+ };
49
+ exports.createBindingsMethod = createBindingsMethod;
50
+ //# sourceMappingURL=bindings.js.map
@@ -1,3 +1,4 @@
1
- import { Statement } from '@babel/types';
1
+ import type { Statement } from '@babel/types';
2
2
  import type { ISCExport } from '../in_source_config/index.js';
3
- export declare const getMainExport: (nodes: Statement[]) => ISCExport[];
3
+ import type { BindingMethod } from './bindings.js';
4
+ export declare const getMainExport: (nodes: Statement[], getAllBindings: BindingMethod) => ISCExport[];
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMainExport = void 0;
4
4
  const helpers_js_1 = require("./helpers.js");
5
5
  // Finds the main handler export in an AST.
6
- const getMainExport = (nodes) => {
6
+ const getMainExport = (nodes, getAllBindings) => {
7
7
  let handlerExport = [];
8
8
  nodes.find((node) => {
9
- const esmExports = getMainExportFromESM(node);
9
+ const esmExports = getMainExportFromESM(node, getAllBindings);
10
10
  if (esmExports.length !== 0) {
11
11
  handlerExport = esmExports;
12
12
  return true;
@@ -28,34 +28,58 @@ const getMainExportFromCJS = (node) => {
28
28
  ['exports', 'handler'],
29
29
  ];
30
30
  return handlerPaths.flatMap((handlerPath) => {
31
- if (!(0, helpers_js_1.isModuleExports)(node, handlerPath) || node.expression.right.type !== 'CallExpression') {
31
+ if (!(0, helpers_js_1.isModuleExports)(node, handlerPath)) {
32
32
  return [];
33
33
  }
34
- return getExportsFromCallExpression(node.expression.right);
34
+ return getExportsFromExpression(node.expression.right);
35
35
  });
36
36
  };
37
37
  // Finds the main handler export in an ESM AST.
38
- // eslint-disable-next-line complexity
39
- const getMainExportFromESM = (node) => {
40
- var _a;
38
+ const getMainExportFromESM = (node, getAllBindings) => {
41
39
  if (node.type !== 'ExportNamedDeclaration' || node.exportKind !== 'value') {
42
40
  return [];
43
41
  }
44
- const { declaration } = node;
45
- if (!declaration || declaration.type !== 'VariableDeclaration') {
42
+ const { declaration, specifiers } = node;
43
+ if ((specifiers === null || specifiers === void 0 ? void 0 : specifiers.length) > 0) {
44
+ return getExportsFromBindings(specifiers, getAllBindings);
45
+ }
46
+ if ((declaration === null || declaration === void 0 ? void 0 : declaration.type) !== 'VariableDeclaration') {
46
47
  return [];
47
48
  }
48
49
  const handlerDeclaration = declaration.declarations.find((childDeclaration) => {
49
50
  const { id, type } = childDeclaration;
50
51
  return type === 'VariableDeclarator' && id.type === 'Identifier' && id.name === 'handler';
51
52
  });
52
- if (((_a = handlerDeclaration === null || handlerDeclaration === void 0 ? void 0 : handlerDeclaration.init) === null || _a === void 0 ? void 0 : _a.type) !== 'CallExpression') {
53
+ const exports = getExportsFromExpression(handlerDeclaration === null || handlerDeclaration === void 0 ? void 0 : handlerDeclaration.init);
54
+ return exports;
55
+ };
56
+ // Check if the Node is an ExportSpecifier that has a named export called `handler`
57
+ // either with Identifier `export { handler }`
58
+ // or with StringLiteral `export { x as "handler" }`
59
+ const isHandlerExport = (node) => {
60
+ const { type, exported } = node;
61
+ return (type === 'ExportSpecifier' &&
62
+ ((exported.type === 'Identifier' && exported.name === 'handler') ||
63
+ (exported.type === 'StringLiteral' && exported.value === 'handler')));
64
+ };
65
+ // Tries to resolve the export from a binding (variable)
66
+ // for example `let handler; handler = () => {}; export { handler }` would
67
+ // resolve correctly to the handler function
68
+ const getExportsFromBindings = (specifiers, getAllBindings) => {
69
+ const specifier = specifiers.find(isHandlerExport);
70
+ if (!specifier) {
53
71
  return [];
54
72
  }
55
- const exports = getExportsFromCallExpression(handlerDeclaration.init);
73
+ const binding = getAllBindings().get(specifier.local.name);
74
+ const exports = getExportsFromExpression(binding);
56
75
  return exports;
57
76
  };
58
- const getExportsFromCallExpression = (node) => {
77
+ const getExportsFromExpression = (node) => {
78
+ // We're only interested in expressions representing function calls, because
79
+ // the ISC patterns we implement at the moment are all helper functions.
80
+ if ((node === null || node === void 0 ? void 0 : node.type) !== 'CallExpression') {
81
+ return [];
82
+ }
59
83
  const { arguments: args, callee } = node;
60
84
  if (callee.type !== 'Identifier') {
61
85
  return [];
@@ -1,5 +1,5 @@
1
- export declare const filterExcludedPaths: (paths: string[], exclude?: string[]) => string[];
2
- export declare const getPathsOfIncludedFiles: (includedFiles: string[], basePath?: string | undefined) => Promise<{
3
- exclude: string[];
1
+ export declare const filterExcludedPaths: (paths: string[], excludePattern?: string[]) => string[];
2
+ export declare const getPathsOfIncludedFiles: (includedFiles: string[], basePath?: string) => Promise<{
3
+ excludePatterns: string[];
4
4
  paths: string[];
5
5
  }>;
@@ -1,51 +1,46 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getPathsOfIncludedFiles = exports.filterExcludedPaths = void 0;
7
4
  const path_1 = require("path");
8
- const util_1 = require("util");
9
- const glob_1 = __importDefault(require("glob"));
10
- const minimatch_1 = __importDefault(require("minimatch"));
11
- const pGlob = (0, util_1.promisify)(glob_1.default);
5
+ const matching_1 = require("../../../utils/matching");
12
6
  // Returns the subset of `paths` that don't match any of the glob expressions
13
7
  // from `exclude`.
14
- const filterExcludedPaths = (paths, exclude = []) => {
15
- if (exclude.length === 0) {
8
+ const filterExcludedPaths = (paths, excludePattern = []) => {
9
+ if (excludePattern.length === 0) {
16
10
  return paths;
17
11
  }
18
- const excludedPaths = paths.filter((path) => !exclude.some((pattern) => (0, minimatch_1.default)(path, pattern)));
12
+ const excludedPaths = paths.filter((path) => !excludePattern.some((pattern) => (0, matching_1.minimatch)(path, pattern)));
19
13
  return excludedPaths;
20
14
  };
21
15
  exports.filterExcludedPaths = filterExcludedPaths;
22
16
  const getPathsOfIncludedFiles = async (includedFiles, basePath) => {
23
17
  if (basePath === undefined) {
24
- return { exclude: [], paths: [] };
18
+ return { excludePatterns: [], paths: [] };
25
19
  }
26
20
  // Some of the globs in `includedFiles` might be exclusion patterns, which
27
21
  // means paths that should NOT be included in the bundle. We need to treat
28
22
  // these differently, so we iterate on the array and put those paths in a
29
23
  // `exclude` array and the rest of the paths in an `include` array.
30
- const { include, exclude } = includedFiles.reduce((acc, path) => {
24
+ const { include, excludePatterns } = includedFiles.reduce((acc, path) => {
31
25
  if (path.startsWith('!')) {
32
- const excludePath = (0, path_1.resolve)(basePath, path.slice(1));
26
+ // convert to unix paths, as minimatch does not support windows paths in patterns
27
+ const excludePattern = (0, path_1.resolve)(basePath, path.slice(1));
33
28
  return {
34
29
  include: acc.include,
35
- exclude: [...acc.exclude, excludePath],
30
+ excludePatterns: [...acc.excludePatterns, excludePattern],
36
31
  };
37
32
  }
38
33
  return {
39
34
  include: [...acc.include, path],
40
- exclude: acc.exclude,
35
+ excludePatterns: acc.excludePatterns,
41
36
  };
42
- }, { include: [], exclude: [] });
43
- const pathGroups = await Promise.all(include.map((expression) => pGlob(expression, { absolute: true, cwd: basePath, ignore: exclude, nodir: true })));
37
+ }, { include: [], excludePatterns: [] });
38
+ const pathGroups = await Promise.all(include.map((expression) => (0, matching_1.glob)(expression, { absolute: true, cwd: basePath, ignore: excludePatterns, nodir: true })));
44
39
  // `pathGroups` is an array containing the paths for each expression in the
45
40
  // `include` array. We flatten it into a single dimension.
46
41
  const paths = pathGroups.flat();
47
42
  const normalizedPaths = paths.map(path_1.normalize);
48
- return { exclude, paths: [...new Set(normalizedPaths)] };
43
+ return { excludePatterns, paths: [...new Set(normalizedPaths)] };
49
44
  };
50
45
  exports.getPathsOfIncludedFiles = getPathsOfIncludedFiles;
51
46
  //# sourceMappingURL=included_files.js.map
@@ -4,7 +4,7 @@ export interface NodeVersionSupport {
4
4
  esm: boolean;
5
5
  }
6
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;
7
+ export declare const getNodeVersion: (configVersion?: string) => number;
8
+ export declare const getNodeSupportMatrix: (configVersion?: string) => NodeVersionSupport;
9
9
  export declare const parseVersion: (input: string | undefined) => number | undefined;
10
10
  export {};
@@ -7,7 +7,6 @@ exports.sanitisePackageJson = exports.getPackageJsonIfAvailable = exports.getPac
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = require("path");
9
9
  const find_up_1 = __importDefault(require("find-up"));
10
- const pkg_dir_1 = __importDefault(require("pkg-dir"));
11
10
  const getClosestPackageJson = async (resolveDir) => {
12
11
  const packageJsonPath = await (0, find_up_1.default)(async (directory) => {
13
12
  // We stop traversing if we're about to leave the boundaries of any
@@ -31,11 +30,9 @@ const getClosestPackageJson = async (resolveDir) => {
31
30
  exports.getClosestPackageJson = getClosestPackageJson;
32
31
  // Retrieve the `package.json` of a specific project or module
33
32
  const getPackageJson = async function (srcDir) {
34
- const packageRoot = await (0, pkg_dir_1.default)(srcDir);
35
- if (packageRoot === undefined) {
36
- return {};
37
- }
38
- return readPackageJson(`${packageRoot}/package.json`);
33
+ var _a;
34
+ const result = await (0, exports.getClosestPackageJson)(srcDir);
35
+ return (_a = result === null || result === void 0 ? void 0 : result.contents) !== null && _a !== void 0 ? _a : {};
39
36
  };
40
37
  exports.getPackageJson = getPackageJson;
41
38
  const getPackageJsonIfAvailable = async (srcDir) => {
@@ -28,6 +28,7 @@ export interface ZipFunctionResult {
28
28
  bundlerWarnings?: object[];
29
29
  config: FunctionConfig;
30
30
  inputs?: string[];
31
+ includedFiles?: string[];
31
32
  inSourceConfig?: ISCValues;
32
33
  nativeNodeModules?: object;
33
34
  nodeModulesWithDynamicImports?: string[];
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { promises as fs } from 'fs';
3
5
  export declare type FsCache = Record<string, unknown>;
4
6
  export declare const cachedLstat: (cache: FsCache, path: string, opts?: import("fs").StatOptions | undefined) => Promise<import("fs").Stats | import("fs").BigIntStats>;
@@ -0,0 +1,9 @@
1
+ import globFunction from 'glob';
2
+ import minimatchFunction from 'minimatch';
3
+ /**
4
+ * Both glob and minimatch only support unix style slashes in patterns
5
+ * For this reason we wrap them and ensure all patters are always unixified
6
+ * We use `normalize-path` here instead of `unixify` because we do not want to remove drive letters
7
+ */
8
+ export declare const glob: (pattern: string, options: globFunction.IOptions) => Promise<string[]>;
9
+ export declare const minimatch: (target: string, pattern: string, options?: minimatchFunction.IOptions) => boolean;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.minimatch = exports.glob = void 0;
7
+ const util_1 = require("util");
8
+ const glob_1 = __importDefault(require("glob"));
9
+ const minimatch_1 = __importDefault(require("minimatch"));
10
+ const normalize_path_1 = __importDefault(require("normalize-path"));
11
+ const pGlob = (0, util_1.promisify)(glob_1.default);
12
+ /**
13
+ * Both glob and minimatch only support unix style slashes in patterns
14
+ * For this reason we wrap them and ensure all patters are always unixified
15
+ * We use `normalize-path` here instead of `unixify` because we do not want to remove drive letters
16
+ */
17
+ const glob = function (pattern, options) {
18
+ let normalizedIgnore;
19
+ if (options.ignore) {
20
+ normalizedIgnore =
21
+ typeof options.ignore === 'string'
22
+ ? (0, normalize_path_1.default)(options.ignore)
23
+ : options.ignore.map((expression) => (0, normalize_path_1.default)(expression));
24
+ }
25
+ return pGlob((0, normalize_path_1.default)(pattern), { ...options, ignore: normalizedIgnore });
26
+ };
27
+ exports.glob = glob;
28
+ const minimatch = function (target, pattern, options) {
29
+ return (0, minimatch_1.default)(target, (0, normalize_path_1.default)(pattern), options);
30
+ };
31
+ exports.minimatch = minimatch;
32
+ //# sourceMappingURL=matching.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "5.9.2",
3
+ "version": "5.10.2",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@babel/parser": "7.16.8",
56
56
  "@netlify/esbuild": "0.14.25",
57
- "@vercel/nft": "^0.18.0",
57
+ "@vercel/nft": "^0.20.0",
58
58
  "archiver": "^5.3.0",
59
59
  "common-path-prefix": "^3.0.0",
60
60
  "cp-file": "^9.0.0",
@@ -65,15 +65,15 @@
65
65
  "execa": "^5.0.0",
66
66
  "filter-obj": "^2.0.1",
67
67
  "find-up": "^5.0.0",
68
- "glob": "^7.1.6",
68
+ "glob": "^8.0.3",
69
69
  "is-builtin-module": "^3.1.0",
70
70
  "junk": "^3.1.0",
71
71
  "locate-path": "^6.0.0",
72
72
  "merge-options": "^3.0.4",
73
- "minimatch": "^4.0.0",
73
+ "minimatch": "^5.0.0",
74
+ "normalize-path": "^3.0.0",
74
75
  "p-map": "^4.0.0",
75
76
  "path-exists": "^4.0.0",
76
- "pkg-dir": "^5.0.0",
77
77
  "precinct": "^9.0.1",
78
78
  "read-package-json-fast": "^2.0.2",
79
79
  "require-package-name": "^2.0.1",
@@ -82,13 +82,14 @@
82
82
  "tmp-promise": "^3.0.2",
83
83
  "toml": "^3.0.0",
84
84
  "unixify": "^1.0.0",
85
- "yargs": "^16.0.0"
85
+ "yargs": "^17.0.0"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@babel/types": "^7.15.6",
89
89
  "@netlify/eslint-config-node": "^6.0.0",
90
90
  "@types/archiver": "^5.1.1",
91
91
  "@types/end-of-stream": "^1.4.1",
92
+ "@types/normalize-path": "^3.0.0",
92
93
  "@types/resolve": "^1.20.1",
93
94
  "@types/semver": "^7.3.8",
94
95
  "@types/unixify": "^1.0.0",