@netlify/zip-it-and-ship-it 4.23.3 → 4.23.5-setup-typescript-4

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 (136) hide show
  1. package/dist/archive.d.ts +8 -0
  2. package/dist/archive.js +39 -0
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +67 -0
  5. package/dist/config.d.ts +4 -0
  6. package/dist/config.js +26 -0
  7. package/dist/feature_flags.d.ts +12 -0
  8. package/dist/feature_flags.js +10 -0
  9. package/dist/main.d.ts +15 -0
  10. package/dist/main.js +80 -0
  11. package/dist/manifest.d.ts +4 -0
  12. package/dist/manifest.js +25 -0
  13. package/dist/node_dependencies/index.d.ts +15 -0
  14. package/dist/node_dependencies/index.js +132 -0
  15. package/dist/node_dependencies/module.d.ts +1 -0
  16. package/dist/node_dependencies/module.js +10 -0
  17. package/dist/node_dependencies/nested.d.ts +10 -0
  18. package/{src → dist}/node_dependencies/nested.js +39 -60
  19. package/dist/node_dependencies/package_json.d.ts +1 -0
  20. package/dist/node_dependencies/package_json.js +29 -0
  21. package/dist/node_dependencies/published.d.ts +1 -0
  22. package/dist/node_dependencies/published.js +42 -0
  23. package/dist/node_dependencies/resolve.d.ts +2 -0
  24. package/dist/node_dependencies/resolve.js +114 -0
  25. package/dist/node_dependencies/side_files.d.ts +1 -0
  26. package/dist/node_dependencies/side_files.js +14 -0
  27. package/dist/node_dependencies/special_cases.d.ts +6 -0
  28. package/dist/node_dependencies/special_cases.js +44 -0
  29. package/dist/node_dependencies/traverse.d.ts +39 -0
  30. package/dist/node_dependencies/traverse.js +120 -0
  31. package/dist/node_dependencies/tree_files.d.ts +3 -0
  32. package/dist/node_dependencies/tree_files.js +32 -0
  33. package/dist/node_dependencies/tree_shake.d.ts +1 -0
  34. package/{src → dist}/node_dependencies/tree_shake.js +8 -12
  35. package/dist/runtimes/detect_runtime.d.ts +4 -0
  36. package/dist/runtimes/detect_runtime.js +27 -0
  37. package/dist/runtimes/go/builder.d.ts +12 -0
  38. package/dist/runtimes/go/builder.js +39 -0
  39. package/dist/runtimes/go/index.d.ts +18 -0
  40. package/dist/runtimes/go/index.js +78 -0
  41. package/dist/runtimes/index.d.ts +9 -0
  42. package/dist/runtimes/index.js +87 -0
  43. package/dist/runtimes/node/base_path.d.ts +1 -0
  44. package/dist/runtimes/node/base_path.js +8 -0
  45. package/dist/runtimes/node/bundler.d.ts +20 -0
  46. package/dist/runtimes/node/bundler.js +135 -0
  47. package/dist/runtimes/node/bundler_target.d.ts +1 -0
  48. package/dist/runtimes/node/bundler_target.js +16 -0
  49. package/dist/runtimes/node/detect_es_module.d.ts +3 -0
  50. package/dist/runtimes/node/detect_es_module.js +28 -0
  51. package/dist/runtimes/node/dynamic_imports/parser.d.ts +8 -0
  52. package/dist/runtimes/node/dynamic_imports/parser.js +135 -0
  53. package/dist/runtimes/node/dynamic_imports/plugin.d.ts +10 -0
  54. package/dist/runtimes/node/dynamic_imports/plugin.js +102 -0
  55. package/dist/runtimes/node/finder.d.ts +12 -0
  56. package/dist/runtimes/node/finder.js +82 -0
  57. package/dist/runtimes/node/index.d.ts +16 -0
  58. package/dist/runtimes/node/index.js +118 -0
  59. package/dist/runtimes/node/list_imports.d.ts +4 -0
  60. package/dist/runtimes/node/list_imports.js +68 -0
  61. package/dist/runtimes/node/native_modules/detector.d.ts +7 -0
  62. package/dist/runtimes/node/native_modules/detector.js +14 -0
  63. package/dist/runtimes/node/native_modules/plugin.d.ts +4 -0
  64. package/dist/runtimes/node/native_modules/plugin.js +65 -0
  65. package/dist/runtimes/node/src_files.d.ts +20 -0
  66. package/dist/runtimes/node/src_files.js +84 -0
  67. package/dist/runtimes/node/zip_esbuild.d.ts +22 -0
  68. package/dist/runtimes/node/zip_esbuild.js +95 -0
  69. package/dist/runtimes/node/zip_zisi.d.ts +20 -0
  70. package/dist/runtimes/node/zip_zisi.js +42 -0
  71. package/dist/runtimes/rust/builder.d.ts +9 -0
  72. package/dist/runtimes/rust/builder.js +100 -0
  73. package/dist/runtimes/rust/constants.d.ts +2 -0
  74. package/dist/runtimes/rust/constants.js +3 -0
  75. package/dist/runtimes/rust/index.d.ts +20 -0
  76. package/dist/runtimes/rust/index.js +101 -0
  77. package/dist/utils/consts.d.ts +8 -0
  78. package/dist/utils/consts.js +10 -0
  79. package/dist/utils/fs.d.ts +14 -0
  80. package/dist/utils/fs.js +86 -0
  81. package/dist/utils/polyfills.d.ts +1 -0
  82. package/{src → dist}/utils/polyfills.js +1 -1
  83. package/dist/utils/remove_falsy.d.ts +1 -0
  84. package/dist/utils/remove_falsy.js +9 -0
  85. package/dist/utils/shell.d.ts +2 -0
  86. package/dist/utils/shell.js +2 -0
  87. package/dist/zip.d.ts +15 -0
  88. package/dist/zip.js +116 -0
  89. package/dist/zip_binary.d.ts +7 -0
  90. package/dist/zip_binary.js +20 -0
  91. package/dist/zip_node.d.ts +4 -0
  92. package/dist/zip_node.js +143 -0
  93. package/package.json +19 -13
  94. package/src/archive.js +0 -36
  95. package/src/bin.js +0 -53
  96. package/src/config.js +0 -32
  97. package/src/feature_flags.js +0 -20
  98. package/src/main.js +0 -91
  99. package/src/manifest.js +0 -22
  100. package/src/node_dependencies/index.js +0 -161
  101. package/src/node_dependencies/module.js +0 -13
  102. package/src/node_dependencies/package_json.js +0 -21
  103. package/src/node_dependencies/published.js +0 -37
  104. package/src/node_dependencies/resolve.js +0 -108
  105. package/src/node_dependencies/side_files.js +0 -18
  106. package/src/node_dependencies/special_cases.js +0 -42
  107. package/src/node_dependencies/traverse.js +0 -147
  108. package/src/node_dependencies/tree_files.js +0 -20
  109. package/src/runtimes/detect_runtime.js +0 -20
  110. package/src/runtimes/go/builder.js +0 -37
  111. package/src/runtimes/go/index.js +0 -89
  112. package/src/runtimes/index.js +0 -96
  113. package/src/runtimes/node/base_path.js +0 -11
  114. package/src/runtimes/node/bundler.js +0 -151
  115. package/src/runtimes/node/bundler_target.js +0 -22
  116. package/src/runtimes/node/detect_es_module.js +0 -24
  117. package/src/runtimes/node/dynamic_imports/parser.js +0 -162
  118. package/src/runtimes/node/dynamic_imports/plugin.js +0 -116
  119. package/src/runtimes/node/finder.js +0 -93
  120. package/src/runtimes/node/index.js +0 -122
  121. package/src/runtimes/node/list_imports.js +0 -59
  122. package/src/runtimes/node/native_modules/detector.js +0 -21
  123. package/src/runtimes/node/native_modules/plugin.js +0 -77
  124. package/src/runtimes/node/src_files.js +0 -99
  125. package/src/runtimes/node/zip_esbuild.js +0 -119
  126. package/src/runtimes/node/zip_zisi.js +0 -50
  127. package/src/runtimes/rust/builder.js +0 -114
  128. package/src/runtimes/rust/constants.js +0 -4
  129. package/src/runtimes/rust/index.js +0 -112
  130. package/src/utils/consts.js +0 -10
  131. package/src/utils/fs.js +0 -88
  132. package/src/utils/remove_falsy.js +0 -12
  133. package/src/utils/shell.js +0 -3
  134. package/src/zip.js +0 -161
  135. package/src/zip_binary.js +0 -11
  136. package/src/zip_node.js +0 -179
@@ -0,0 +1,42 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { promisify } = require('util');
11
+ const glob = require('glob');
12
+ const pGlob = promisify(glob);
13
+ // We use all the files published by the Node.js except some that are not needed
14
+ const getPublishedFiles = function (modulePath) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const ignore = getIgnoredFiles(modulePath);
17
+ const publishedFiles = yield pGlob(`${modulePath}/**`, {
18
+ ignore,
19
+ nodir: true,
20
+ absolute: true,
21
+ dot: true,
22
+ });
23
+ return publishedFiles;
24
+ });
25
+ };
26
+ const getIgnoredFiles = function (modulePath) {
27
+ return IGNORED_FILES.map((ignoreFile) => `${modulePath}/${ignoreFile}`);
28
+ };
29
+ // To make the zip archive smaller, we remove those.
30
+ const IGNORED_FILES = [
31
+ 'node_modules/**',
32
+ '.npmignore',
33
+ 'package-lock.json',
34
+ 'yarn.lock',
35
+ '*.log',
36
+ '*.lock',
37
+ '*~',
38
+ '*.map',
39
+ '*.ts',
40
+ '*.patch',
41
+ ];
42
+ module.exports = { getPublishedFiles };
@@ -0,0 +1,2 @@
1
+ export function resolvePackage(moduleName: any, baseDirs: any): Promise<any>;
2
+ export function resolvePathPreserveSymlinks(path: any, baseDirs: any): Promise<any>;
@@ -0,0 +1,114 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { version: nodeVersion } = require('process');
11
+ const findUp = require('find-up');
12
+ const pathExists = require('path-exists');
13
+ const resolveLib = require('resolve');
14
+ const { lt: ltVersion } = require('semver');
15
+ const BACKSLASH_REGEXP = /\\/g;
16
+ // Find the path to a module's `package.json`
17
+ // We need to use `resolve` instead of `require.resolve()` because:
18
+ // - it is async
19
+ // - it preserves symlinks:
20
+ // - this is important because if a file does a `require('./symlink')`, we
21
+ // need to bundle the symlink and its target, not only the target
22
+ // - `path.resolve()` cannot be used for relative|absolute file paths
23
+ // because it does not resolve ommitted file extension,
24
+ // e.g. `require('./file')` instead of `require('./file.js')`
25
+ // - the CLI flag `--preserve-symlinks` can be used with Node.js, but it
26
+ // cannot be set runtime
27
+ // However it does not give helpful error messages.
28
+ // https://github.com/browserify/resolve/issues/223
29
+ // So, on errors, we fallback to `require.resolve()`
30
+ const resolvePackage = function (moduleName, baseDirs) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ try {
33
+ return yield resolvePathPreserveSymlinks(`${moduleName}/package.json`, baseDirs);
34
+ }
35
+ catch (error) {
36
+ if (ltVersion(nodeVersion, REQUEST_RESOLVE_MIN_VERSION)) {
37
+ throw error;
38
+ }
39
+ try {
40
+ return resolvePathFollowSymlinks(`${moduleName}/package.json`, baseDirs);
41
+ }
42
+ catch (error_) {
43
+ return yield resolvePackageFallback(moduleName, baseDirs, error_);
44
+ }
45
+ }
46
+ });
47
+ };
48
+ // TODO: remove after dropping support for Node <8.9.0
49
+ // `require.resolve()` option `paths` was introduced in Node 8.9.0
50
+ const REQUEST_RESOLVE_MIN_VERSION = '8.9.0';
51
+ // We need to use `new Promise()` due to a bug with `utils.promisify()` on
52
+ // `resolve`:
53
+ // https://github.com/browserify/resolve/issues/151#issuecomment-368210310
54
+ const resolvePathPreserveSymlinksForDir = function (path, basedir) {
55
+ return new Promise((resolve, reject) => {
56
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
57
+ resolveLib(path, { basedir, preserveSymlinks: true }, (error, resolvedLocation) => {
58
+ if (error) {
59
+ return reject(error);
60
+ }
61
+ resolve(resolvedLocation);
62
+ });
63
+ });
64
+ };
65
+ // the resolve library has a `paths` option but it's not the same as multiple basedirs
66
+ // see https://github.com/browserify/resolve/issues/188#issuecomment-679010477
67
+ // we return the first resolved location or the first error if all failed
68
+ const resolvePathPreserveSymlinks = function (path, baseDirs) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ let firstError;
71
+ for (const basedir of baseDirs) {
72
+ try {
73
+ // eslint-disable-next-line no-await-in-loop
74
+ return yield resolvePathPreserveSymlinksForDir(path, basedir);
75
+ }
76
+ catch (error) {
77
+ firstError = firstError || error;
78
+ }
79
+ }
80
+ throw firstError;
81
+ });
82
+ };
83
+ const resolvePathFollowSymlinks = function (path, baseDirs) {
84
+ return require.resolve(path, { paths: baseDirs });
85
+ };
86
+ // `require.resolve()` on a module's specific file (like `package.json`)
87
+ // can be forbidden by the package author by using an `exports` field in
88
+ // their `package.json`. We need this fallback.
89
+ // It looks for the first directory up from a package's `main` file that:
90
+ // - is named like the package
91
+ // - has a `package.json`
92
+ // Theoretically, this might not the root `package.json`, but this is very
93
+ // unlikely, and we don't have any better alternative.
94
+ const resolvePackageFallback = function (moduleName, baseDirs, error) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ const mainFilePath = resolvePathFollowSymlinks(moduleName, baseDirs);
97
+ const packagePath = yield findUp(isPackageDir.bind(null, moduleName), { cwd: mainFilePath, type: 'directory' });
98
+ if (packagePath === undefined) {
99
+ throw error;
100
+ }
101
+ return packagePath;
102
+ });
103
+ };
104
+ const isPackageDir = function (moduleName, dir) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ // Need to use `endsWith()` to take into account `@scope/package`.
107
+ // Backslashes need to be converted for Windows.
108
+ if (!dir.replace(BACKSLASH_REGEXP, '/').endsWith(moduleName) || !(yield pathExists(`${dir}/package.json`))) {
109
+ return;
110
+ }
111
+ return dir;
112
+ });
113
+ };
114
+ module.exports = { resolvePackage, resolvePathPreserveSymlinks };
@@ -0,0 +1 @@
1
+ export function getSideFiles(modulePath: any, moduleName: any): any[] | Promise<string[]>;
@@ -0,0 +1,14 @@
1
+ const { getPublishedFiles } = require('./published');
2
+ // Some modules generate source files on `postinstall` that are not located
3
+ // inside the module's directory itself.
4
+ const getSideFiles = function (modulePath, moduleName) {
5
+ const sideFiles = SIDE_FILES[moduleName];
6
+ if (sideFiles === undefined) {
7
+ return [];
8
+ }
9
+ return getPublishedFiles(`${modulePath}/${sideFiles}`);
10
+ };
11
+ const SIDE_FILES = {
12
+ '@prisma/client': '../../.prisma',
13
+ };
14
+ module.exports = { getSideFiles };
@@ -0,0 +1,6 @@
1
+ export function getExternalAndIgnoredModulesFromSpecialCases({ srcDir }: {
2
+ srcDir: any;
3
+ }): Promise<{
4
+ externalModules: string[];
5
+ ignoredModules: any[];
6
+ }>;
@@ -0,0 +1,44 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { getPackageJson } = require('./package_json');
11
+ const EXTERNAL_MODULES = ['@prisma/client'];
12
+ const IGNORED_MODULES = ['aws-sdk'];
13
+ const getPackageJsonIfAvailable = (srcDir) => __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const packageJson = yield getPackageJson(srcDir);
16
+ return packageJson;
17
+ }
18
+ catch (_) {
19
+ return {};
20
+ }
21
+ });
22
+ const getModulesForNextJs = ({ dependencies, devDependencies }) => {
23
+ const allDependencies = Object.assign(Object.assign({}, dependencies), devDependencies);
24
+ const externalModules = allDependencies.next ? ['critters', 'nanoid'] : [];
25
+ const ignoredModules = [];
26
+ return {
27
+ externalModules,
28
+ ignoredModules,
29
+ };
30
+ };
31
+ const getExternalAndIgnoredModulesFromSpecialCases = ({ srcDir }) => __awaiter(this, void 0, void 0, function* () {
32
+ const { dependencies = {}, devDependencies = {} } = yield getPackageJsonIfAvailable(srcDir);
33
+ const { externalModules: nextJsExternalModules, ignoredModules: nextJsIgnoredModules } = getModulesForNextJs({
34
+ dependencies,
35
+ devDependencies,
36
+ });
37
+ const externalModules = [...EXTERNAL_MODULES, ...nextJsExternalModules];
38
+ const ignoredModules = [...IGNORED_MODULES, ...nextJsIgnoredModules];
39
+ return {
40
+ externalModules,
41
+ ignoredModules,
42
+ };
43
+ });
44
+ module.exports = { getExternalAndIgnoredModulesFromSpecialCases };
@@ -0,0 +1,39 @@
1
+ export function getDependencyPathsForDependency({ dependency, basedir, state, packageJson, pluginsModulesPath, }: {
2
+ dependency: any;
3
+ basedir: any;
4
+ state: any;
5
+ packageJson: any;
6
+ pluginsModulesPath: any;
7
+ }): any;
8
+ export function getDependencyNamesAndPathsForDependencies({ dependencies: dependencyNames, basedir, state, pluginsModulesPath, }: {
9
+ dependencies: any;
10
+ basedir: any;
11
+ state?: {
12
+ localFiles: Set<any>;
13
+ moduleNames: Set<any>;
14
+ modulePaths: Set<any>;
15
+ };
16
+ pluginsModulesPath: any;
17
+ }): Promise<{
18
+ moduleNames: any[];
19
+ paths: any[];
20
+ }>;
21
+ export function getDependencyNamesAndPathsForDependency({ dependency, basedir, state, packageJson, pluginsModulesPath, }: {
22
+ dependency: any;
23
+ basedir: any;
24
+ state?: {
25
+ localFiles: Set<any>;
26
+ moduleNames: Set<any>;
27
+ modulePaths: Set<any>;
28
+ };
29
+ packageJson: any;
30
+ pluginsModulesPath: any;
31
+ }): Promise<{
32
+ moduleNames: any[];
33
+ paths: any;
34
+ }>;
35
+ export function getNewCache(): {
36
+ localFiles: Set<any>;
37
+ moduleNames: Set<any>;
38
+ modulePaths: Set<any>;
39
+ };
@@ -0,0 +1,120 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { dirname } = require('path');
11
+ const { getModuleName } = require('./module');
12
+ const { getNestedDependencies, handleModuleNotFound } = require('./nested');
13
+ const { getPackageJson } = require('./package_json');
14
+ const { getPublishedFiles } = require('./published');
15
+ const { resolvePackage } = require('./resolve');
16
+ const { getSideFiles } = require('./side_files');
17
+ const EXCLUDED_MODULES = new Set(['aws-sdk']);
18
+ // Local cache used for optimizing the traversal of module dependencies.
19
+ const getNewCache = () => ({ localFiles: new Set(), moduleNames: new Set(), modulePaths: new Set() });
20
+ // When a file requires a module, we find its path inside `node_modules` and
21
+ // use all its published files. We also recurse on the module's dependencies.
22
+ const getDependencyPathsForDependency = function ({ dependency, basedir, state, packageJson, pluginsModulesPath, }) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const moduleName = getModuleName(dependency);
25
+ // Happens when doing require("@scope") (not "@scope/name") or other oddities
26
+ // Ignore those.
27
+ if (moduleName === null) {
28
+ return [];
29
+ }
30
+ try {
31
+ return yield getDependenciesForModuleName({ moduleName, basedir, state, pluginsModulesPath });
32
+ }
33
+ catch (error) {
34
+ return handleModuleNotFound({ error, moduleName, packageJson });
35
+ }
36
+ });
37
+ };
38
+ const getDependencyNamesAndPathsForDependencies = function ({ dependencies: dependencyNames, basedir, state = getNewCache(), pluginsModulesPath, }) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const packageJson = yield getPackageJson(basedir);
41
+ const dependencies = yield Promise.all(dependencyNames.map((dependencyName) => getDependencyNamesAndPathsForDependency({
42
+ dependency: dependencyName,
43
+ basedir,
44
+ state,
45
+ packageJson,
46
+ pluginsModulesPath,
47
+ })));
48
+ const moduleNames = new Set(dependencies.flatMap((dependency) => [...dependency.moduleNames]));
49
+ const paths = new Set(dependencies.flatMap((dependency) => [...dependency.paths]));
50
+ return {
51
+ moduleNames: [...moduleNames],
52
+ paths: [...paths],
53
+ };
54
+ });
55
+ };
56
+ const getDependencyNamesAndPathsForDependency = function ({ dependency, basedir, state = getNewCache(), packageJson, pluginsModulesPath, }) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ try {
59
+ const paths = yield getDependencyPathsForDependency({ dependency, basedir, state, packageJson, pluginsModulesPath });
60
+ return {
61
+ moduleNames: [...state.moduleNames],
62
+ paths,
63
+ };
64
+ }
65
+ catch (error) {
66
+ if (error.code === 'MODULE_NOT_FOUND') {
67
+ return {
68
+ moduleNames: [],
69
+ paths: [],
70
+ };
71
+ }
72
+ throw error;
73
+ }
74
+ });
75
+ };
76
+ const getDependenciesForModuleName = function ({ moduleName, basedir, state, pluginsModulesPath }) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (isExcludedModule(moduleName)) {
79
+ return [];
80
+ }
81
+ // Find the Node.js module directory path
82
+ const packagePath = yield resolvePackage(moduleName, [basedir, pluginsModulesPath].filter(Boolean));
83
+ if (packagePath === undefined) {
84
+ return [];
85
+ }
86
+ const modulePath = dirname(packagePath);
87
+ if (state.modulePaths.has(modulePath)) {
88
+ return [];
89
+ }
90
+ state.moduleNames.add(moduleName);
91
+ state.modulePaths.add(modulePath);
92
+ // The path depends on the user's build, i.e. must be dynamic
93
+ // eslint-disable-next-line import/no-dynamic-require, node/global-require
94
+ const packageJson = require(packagePath);
95
+ const [publishedFiles, sideFiles, depsPaths] = yield Promise.all([
96
+ getPublishedFiles(modulePath),
97
+ getSideFiles(modulePath, moduleName),
98
+ getNestedModules({ modulePath, state, packageJson, pluginsModulesPath }),
99
+ ]);
100
+ return [...publishedFiles, ...sideFiles, ...depsPaths];
101
+ });
102
+ };
103
+ const isExcludedModule = function (moduleName) {
104
+ return EXCLUDED_MODULES.has(moduleName) || moduleName.startsWith('@types/');
105
+ };
106
+ const getNestedModules = function ({ modulePath, state, packageJson, pluginsModulesPath }) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const dependencies = getNestedDependencies(packageJson);
109
+ const depsPaths = yield Promise.all(dependencies.map((dependency) => getDependencyPathsForDependency({ dependency, basedir: modulePath, state, packageJson, pluginsModulesPath })));
110
+ // TODO: switch to Array.flat() once we drop support for Node.js < 11.0.0
111
+ // eslint-disable-next-line unicorn/prefer-spread
112
+ return [].concat(...depsPaths);
113
+ });
114
+ };
115
+ module.exports = {
116
+ getDependencyPathsForDependency,
117
+ getDependencyNamesAndPathsForDependencies,
118
+ getDependencyNamesAndPathsForDependency,
119
+ getNewCache,
120
+ };
@@ -0,0 +1,3 @@
1
+ import { Stats } from 'fs';
2
+ declare const getTreeFiles: (srcPath: string, stat: Stats) => Promise<string[]>;
3
+ export { getTreeFiles };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getTreeFiles = void 0;
16
+ const util_1 = require("util");
17
+ const glob_1 = __importDefault(require("glob"));
18
+ const pGlob = (0, util_1.promisify)(glob_1.default);
19
+ // When using a directory, we include all its descendants except `node_modules`
20
+ const getTreeFiles = function (srcPath, stat) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ if (!stat.isDirectory()) {
23
+ return [srcPath];
24
+ }
25
+ return yield pGlob(`${srcPath}/**`, {
26
+ ignore: `${srcPath}/**/node_modules/**`,
27
+ nodir: true,
28
+ absolute: true,
29
+ });
30
+ });
31
+ };
32
+ exports.getTreeFiles = getTreeFiles;
@@ -0,0 +1 @@
1
+ export function shouldTreeShake(dependency: any, treeShakeNext: any): boolean;
@@ -1,18 +1,14 @@
1
- const { getModuleName } = require('./module')
2
-
3
- const LOCAL_IMPORT_REGEXP = /^(\.|\/)/
4
-
1
+ const { getModuleName } = require('./module');
2
+ const LOCAL_IMPORT_REGEXP = /^(\.|\/)/;
5
3
  // we tree shake direct local requires to bundle only relevant code
6
4
  // we don't tree shake external dependencies since they can break our tree shaking logic by:
7
5
  // 1. doing dynamic requires (e.g. require(dynamicPath))
8
6
  // 2. reading files (e.g. fs.readFileSync(someNonJsFile))
9
7
  // an exception is when the function was generated by `next-on-netlify` to avoid bundling the entire `Next.js` framework
10
8
  const shouldTreeShake = function (dependency, treeShakeNext) {
11
- if (LOCAL_IMPORT_REGEXP.test(dependency)) {
12
- return true
13
- }
14
-
15
- return treeShakeNext && getModuleName(dependency) === 'next'
16
- }
17
-
18
- module.exports = { shouldTreeShake }
9
+ if (LOCAL_IMPORT_REGEXP.test(dependency)) {
10
+ return true;
11
+ }
12
+ return treeShakeNext && getModuleName(dependency) === 'next';
13
+ };
14
+ module.exports = { shouldTreeShake };
@@ -0,0 +1,4 @@
1
+ export function detectBinaryRuntime({ fsCache, path }: {
2
+ fsCache: any;
3
+ path: any;
4
+ }): Promise<string>;
@@ -0,0 +1,27 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { detect, Runtime } = require('elf-cam');
11
+ const { RUNTIME_GO, RUNTIME_RUST } = require('../utils/consts');
12
+ const { cachedReadFile } = require('../utils/fs');
13
+ // Try to guess the runtime by inspecting the binary file.
14
+ const detectBinaryRuntime = function ({ fsCache, path }) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const buffer = yield cachedReadFile(fsCache, path);
18
+ return RUNTIMES[detect(buffer)];
19
+ }
20
+ catch (error) { }
21
+ });
22
+ };
23
+ const RUNTIMES = {
24
+ [Runtime.Go]: RUNTIME_GO,
25
+ [Runtime.Rust]: RUNTIME_RUST,
26
+ };
27
+ module.exports = { detectBinaryRuntime };
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ export function build({ destPath, mainFile, srcDir }: {
3
+ destPath: any;
4
+ mainFile: any;
5
+ srcDir: any;
6
+ }): Promise<{
7
+ mainFile: any;
8
+ name: string;
9
+ srcDir: any;
10
+ srcPath: any;
11
+ stat: import("fs").Stats;
12
+ }>;
@@ -0,0 +1,39 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { basename } = require('path');
11
+ const { RUNTIME_GO } = require('../../utils/consts');
12
+ const { lstat } = require('../../utils/fs');
13
+ const { runCommand } = require('../../utils/shell');
14
+ const build = ({ destPath, mainFile, srcDir }) => __awaiter(this, void 0, void 0, function* () {
15
+ const functionName = basename(srcDir);
16
+ try {
17
+ yield runCommand('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
18
+ cwd: srcDir,
19
+ env: {
20
+ CGO_ENABLED: '0',
21
+ GOOS: 'linux',
22
+ },
23
+ });
24
+ }
25
+ catch (error) {
26
+ error.customErrorInfo = { type: 'functionsBundling', location: { functionName, runtime: RUNTIME_GO } };
27
+ console.error(`Could not compile Go function ${functionName}:\n`);
28
+ throw error;
29
+ }
30
+ const stat = yield lstat(destPath);
31
+ return {
32
+ mainFile,
33
+ name: functionName,
34
+ srcDir,
35
+ srcPath: destPath,
36
+ stat,
37
+ };
38
+ });
39
+ module.exports = { build };
@@ -0,0 +1,18 @@
1
+ export function findFunctionsInPaths({ featureFlags, fsCache, paths }: {
2
+ featureFlags: any;
3
+ fsCache: any;
4
+ paths: any;
5
+ }): Promise<any[]>;
6
+ import { RUNTIME_GO } from "../../utils/consts";
7
+ export function zipFunction({ config, destFolder, filename, mainFile, srcDir, srcPath }: {
8
+ config: any;
9
+ destFolder: any;
10
+ filename: any;
11
+ mainFile: any;
12
+ srcDir: any;
13
+ srcPath: any;
14
+ }): Promise<{
15
+ config: any;
16
+ path: string;
17
+ }>;
18
+ export { RUNTIME_GO as name };
@@ -0,0 +1,78 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ const { basename, dirname, extname, join } = require('path');
11
+ const cpFile = require('cp-file');
12
+ const { RUNTIME_GO } = require('../../utils/consts');
13
+ const { cachedLstat, cachedReaddir } = require('../../utils/fs');
14
+ const { detectBinaryRuntime } = require('../detect_runtime');
15
+ const { build } = require('./builder');
16
+ const detectGoFunction = ({ fsCache, path }) => __awaiter(this, void 0, void 0, function* () {
17
+ const stat = yield cachedLstat(fsCache, path);
18
+ if (!stat.isDirectory()) {
19
+ return;
20
+ }
21
+ const directoryName = basename(path);
22
+ const files = yield cachedReaddir(fsCache, path);
23
+ const mainFileName = [`${directoryName}.go`, 'main.go'].find((name) => files.includes(name));
24
+ if (mainFileName === undefined) {
25
+ return;
26
+ }
27
+ return mainFileName;
28
+ });
29
+ const findFunctionsInPaths = function ({ featureFlags, fsCache, paths }) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const functions = yield Promise.all(paths.map((path) => __awaiter(this, void 0, void 0, function* () {
32
+ const runtime = yield detectBinaryRuntime({ fsCache, path });
33
+ if (runtime === RUNTIME_GO) {
34
+ return processBinary({ fsCache, path });
35
+ }
36
+ if (featureFlags.buildGoSource !== true) {
37
+ return;
38
+ }
39
+ const goSourceFile = yield detectGoFunction({ fsCache, path });
40
+ if (goSourceFile) {
41
+ return processSource({ fsCache, mainFile: goSourceFile, path });
42
+ }
43
+ })));
44
+ return functions.filter(Boolean);
45
+ });
46
+ };
47
+ const processBinary = ({ fsCache, path }) => __awaiter(this, void 0, void 0, function* () {
48
+ const stat = yield cachedLstat(fsCache, path);
49
+ const name = basename(path, extname(path));
50
+ return {
51
+ mainFile: path,
52
+ name,
53
+ srcDir: dirname(path),
54
+ srcPath: path,
55
+ stat,
56
+ };
57
+ });
58
+ const processSource = ({ mainFile, path }) => {
59
+ const functionName = basename(path);
60
+ return {
61
+ mainFile: join(path, mainFile),
62
+ name: functionName,
63
+ srcDir: path,
64
+ srcPath: path,
65
+ };
66
+ };
67
+ const zipFunction = function ({ config, destFolder, filename, mainFile, srcDir, srcPath }) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const destPath = join(destFolder, filename);
70
+ const isSource = extname(mainFile) === '.go';
71
+ // If we're building a Go function from source, we call the build method and
72
+ // it'll take care of placing the binary in the right location. If not, we
73
+ // need to copy the existing binary file to the destination directory.
74
+ yield (isSource ? build({ destPath, mainFile, srcDir }) : cpFile(srcPath, destPath));
75
+ return { config, path: destPath };
76
+ });
77
+ };
78
+ module.exports = { findFunctionsInPaths, name: RUNTIME_GO, zipFunction };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets a list of functions found in a list of paths.
3
+ *
4
+ * @param {Object} config
5
+ * @param {Boolean} dedupe
6
+ * @param {String} path
7
+ * @returns {Promise<Map>}
8
+ */
9
+ export function getFunctionsFromPaths(paths: any, { config, dedupe, featureFlags }?: boolean): Promise<Map<any, any>>;