@netlify/zip-it-and-ship-it 4.23.4 → 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.
- package/dist/archive.d.ts +8 -0
- package/dist/archive.js +39 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +67 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +26 -0
- package/dist/feature_flags.d.ts +12 -0
- package/dist/feature_flags.js +10 -0
- package/dist/main.d.ts +15 -0
- package/dist/main.js +80 -0
- package/dist/manifest.d.ts +4 -0
- package/dist/manifest.js +25 -0
- package/dist/node_dependencies/index.d.ts +15 -0
- package/dist/node_dependencies/index.js +132 -0
- package/dist/node_dependencies/module.d.ts +1 -0
- package/dist/node_dependencies/module.js +10 -0
- package/dist/node_dependencies/nested.d.ts +10 -0
- package/{src → dist}/node_dependencies/nested.js +39 -60
- package/dist/node_dependencies/package_json.d.ts +1 -0
- package/dist/node_dependencies/package_json.js +29 -0
- package/dist/node_dependencies/published.d.ts +1 -0
- package/dist/node_dependencies/published.js +42 -0
- package/dist/node_dependencies/resolve.d.ts +2 -0
- package/dist/node_dependencies/resolve.js +114 -0
- package/dist/node_dependencies/side_files.d.ts +1 -0
- package/dist/node_dependencies/side_files.js +14 -0
- package/dist/node_dependencies/special_cases.d.ts +6 -0
- package/dist/node_dependencies/special_cases.js +44 -0
- package/dist/node_dependencies/traverse.d.ts +39 -0
- package/dist/node_dependencies/traverse.js +120 -0
- package/dist/node_dependencies/tree_files.d.ts +3 -0
- package/dist/node_dependencies/tree_files.js +32 -0
- package/dist/node_dependencies/tree_shake.d.ts +1 -0
- package/{src → dist}/node_dependencies/tree_shake.js +8 -12
- package/dist/runtimes/detect_runtime.d.ts +4 -0
- package/dist/runtimes/detect_runtime.js +27 -0
- package/dist/runtimes/go/builder.d.ts +12 -0
- package/dist/runtimes/go/builder.js +39 -0
- package/dist/runtimes/go/index.d.ts +18 -0
- package/dist/runtimes/go/index.js +78 -0
- package/dist/runtimes/index.d.ts +9 -0
- package/dist/runtimes/index.js +87 -0
- package/dist/runtimes/node/base_path.d.ts +1 -0
- package/dist/runtimes/node/base_path.js +8 -0
- package/dist/runtimes/node/bundler.d.ts +20 -0
- package/dist/runtimes/node/bundler.js +135 -0
- package/dist/runtimes/node/bundler_target.d.ts +1 -0
- package/dist/runtimes/node/bundler_target.js +16 -0
- package/dist/runtimes/node/detect_es_module.d.ts +3 -0
- package/dist/runtimes/node/detect_es_module.js +28 -0
- package/dist/runtimes/node/dynamic_imports/parser.d.ts +8 -0
- package/dist/runtimes/node/dynamic_imports/parser.js +135 -0
- package/dist/runtimes/node/dynamic_imports/plugin.d.ts +10 -0
- package/dist/runtimes/node/dynamic_imports/plugin.js +102 -0
- package/dist/runtimes/node/finder.d.ts +12 -0
- package/dist/runtimes/node/finder.js +82 -0
- package/dist/runtimes/node/index.d.ts +16 -0
- package/dist/runtimes/node/index.js +118 -0
- package/dist/runtimes/node/list_imports.d.ts +4 -0
- package/dist/runtimes/node/list_imports.js +68 -0
- package/dist/runtimes/node/native_modules/detector.d.ts +7 -0
- package/dist/runtimes/node/native_modules/detector.js +14 -0
- package/dist/runtimes/node/native_modules/plugin.d.ts +4 -0
- package/dist/runtimes/node/native_modules/plugin.js +65 -0
- package/dist/runtimes/node/src_files.d.ts +20 -0
- package/dist/runtimes/node/src_files.js +84 -0
- package/dist/runtimes/node/zip_esbuild.d.ts +22 -0
- package/dist/runtimes/node/zip_esbuild.js +95 -0
- package/dist/runtimes/node/zip_zisi.d.ts +20 -0
- package/dist/runtimes/node/zip_zisi.js +42 -0
- package/dist/runtimes/rust/builder.d.ts +9 -0
- package/dist/runtimes/rust/builder.js +100 -0
- package/dist/runtimes/rust/constants.d.ts +2 -0
- package/dist/runtimes/rust/constants.js +3 -0
- package/dist/runtimes/rust/index.d.ts +20 -0
- package/dist/runtimes/rust/index.js +101 -0
- package/dist/utils/consts.d.ts +8 -0
- package/dist/utils/consts.js +10 -0
- package/dist/utils/fs.d.ts +14 -0
- package/dist/utils/fs.js +86 -0
- package/dist/utils/polyfills.d.ts +1 -0
- package/{src → dist}/utils/polyfills.js +1 -1
- package/dist/utils/remove_falsy.d.ts +1 -0
- package/dist/utils/remove_falsy.js +9 -0
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.js +2 -0
- package/dist/zip.d.ts +15 -0
- package/dist/zip.js +116 -0
- package/dist/zip_binary.d.ts +7 -0
- package/dist/zip_binary.js +20 -0
- package/dist/zip_node.d.ts +4 -0
- package/dist/zip_node.js +143 -0
- package/package.json +18 -13
- package/src/archive.js +0 -36
- package/src/bin.js +0 -53
- package/src/config.js +0 -32
- package/src/feature_flags.js +0 -20
- package/src/main.js +0 -91
- package/src/manifest.js +0 -22
- package/src/node_dependencies/index.js +0 -161
- package/src/node_dependencies/module.js +0 -13
- package/src/node_dependencies/package_json.js +0 -21
- package/src/node_dependencies/published.js +0 -37
- package/src/node_dependencies/resolve.js +0 -108
- package/src/node_dependencies/side_files.js +0 -18
- package/src/node_dependencies/special_cases.js +0 -42
- package/src/node_dependencies/traverse.js +0 -147
- package/src/node_dependencies/tree_files.js +0 -20
- package/src/runtimes/detect_runtime.js +0 -20
- package/src/runtimes/go/builder.js +0 -37
- package/src/runtimes/go/index.js +0 -89
- package/src/runtimes/index.js +0 -96
- package/src/runtimes/node/base_path.js +0 -11
- package/src/runtimes/node/bundler.js +0 -151
- package/src/runtimes/node/bundler_target.js +0 -22
- package/src/runtimes/node/detect_es_module.js +0 -24
- package/src/runtimes/node/dynamic_imports/parser.js +0 -162
- package/src/runtimes/node/dynamic_imports/plugin.js +0 -116
- package/src/runtimes/node/finder.js +0 -93
- package/src/runtimes/node/index.js +0 -122
- package/src/runtimes/node/list_imports.js +0 -59
- package/src/runtimes/node/native_modules/detector.js +0 -21
- package/src/runtimes/node/native_modules/plugin.js +0 -77
- package/src/runtimes/node/src_files.js +0 -99
- package/src/runtimes/node/zip_esbuild.js +0 -119
- package/src/runtimes/node/zip_zisi.js +0 -50
- package/src/runtimes/rust/builder.js +0 -114
- package/src/runtimes/rust/constants.js +0 -4
- package/src/runtimes/rust/index.js +0 -112
- package/src/utils/consts.js +0 -10
- package/src/utils/fs.js +0 -88
- package/src/utils/remove_falsy.js +0 -12
- package/src/utils/shell.js +0 -3
- package/src/zip.js +0 -161
- package/src/zip_binary.js +0 -11
- package/src/zip_node.js +0 -179
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { findFunctionsInPaths } from "./finder";
|
|
2
|
+
declare function getSrcFilesWithBundler(parameters: any): Promise<any[]>;
|
|
3
|
+
import { RUNTIME_JS } from "../../utils/consts";
|
|
4
|
+
declare function zipWithFunctionWithFallback({ config, ...parameters }: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
config?: {};
|
|
7
|
+
}): Promise<{
|
|
8
|
+
bundler: string;
|
|
9
|
+
config: any;
|
|
10
|
+
inputs: any[];
|
|
11
|
+
path: string;
|
|
12
|
+
} | {
|
|
13
|
+
config: {};
|
|
14
|
+
path: string;
|
|
15
|
+
}>;
|
|
16
|
+
export { findFunctionsInPaths, getSrcFilesWithBundler as getSrcFiles, RUNTIME_JS as name, zipWithFunctionWithFallback as zipFunction };
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
const { join } = require('path');
|
|
22
|
+
const cpFile = require('cp-file');
|
|
23
|
+
const { JS_BUNDLER_ESBUILD, JS_BUNDLER_ESBUILD_ZISI, JS_BUNDLER_ZISI, RUNTIME_JS } = require('../../utils/consts');
|
|
24
|
+
const { detectEsModule } = require('./detect_es_module');
|
|
25
|
+
const { findFunctionsInPaths } = require('./finder');
|
|
26
|
+
const { getSrcFiles } = require('./src_files');
|
|
27
|
+
const { zipEsbuild } = require('./zip_esbuild');
|
|
28
|
+
const { zipZisi } = require('./zip_zisi');
|
|
29
|
+
// We use ZISI as the default bundler, except for certain extensions, for which
|
|
30
|
+
// esbuild is the only option.
|
|
31
|
+
const getDefaultBundler = ({ extension, mainFile, featureFlags = {} }) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (['.mjs', '.ts'].includes(extension)) {
|
|
33
|
+
return JS_BUNDLER_ESBUILD;
|
|
34
|
+
}
|
|
35
|
+
if (featureFlags.defaultEsModulesToEsbuild) {
|
|
36
|
+
const isEsModule = yield detectEsModule({ mainFile });
|
|
37
|
+
if (isEsModule) {
|
|
38
|
+
return JS_BUNDLER_ESBUILD;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return JS_BUNDLER_ZISI;
|
|
42
|
+
});
|
|
43
|
+
// A proxy for the `getSrcFiles` function which adds a default `bundler` using
|
|
44
|
+
// the `getDefaultBundler` function.
|
|
45
|
+
const getSrcFilesWithBundler = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const bundler = parameters.config.nodeBundler || (yield getDefaultBundler({ extension: parameters.extension }));
|
|
47
|
+
return getSrcFiles(Object.assign(Object.assign({}, parameters), { bundler }));
|
|
48
|
+
});
|
|
49
|
+
const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const bundler = config.nodeBundler || (yield getDefaultBundler({ extension, mainFile, featureFlags }));
|
|
52
|
+
// If the file is a zip, we assume the function is bundled and ready to go.
|
|
53
|
+
// We simply copy it to the destination path with no further processing.
|
|
54
|
+
if (extension === '.zip') {
|
|
55
|
+
const destPath = join(destFolder, filename);
|
|
56
|
+
yield cpFile(srcPath, destPath);
|
|
57
|
+
return { config, path: destPath };
|
|
58
|
+
}
|
|
59
|
+
if (bundler === JS_BUNDLER_ZISI) {
|
|
60
|
+
return zipZisi({
|
|
61
|
+
archiveFormat,
|
|
62
|
+
basePath,
|
|
63
|
+
config,
|
|
64
|
+
destFolder,
|
|
65
|
+
extension,
|
|
66
|
+
featureFlags,
|
|
67
|
+
filename,
|
|
68
|
+
mainFile,
|
|
69
|
+
name,
|
|
70
|
+
pluginsModulesPath,
|
|
71
|
+
srcDir,
|
|
72
|
+
srcPath,
|
|
73
|
+
stat,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return zipEsbuild({
|
|
77
|
+
archiveFormat,
|
|
78
|
+
basePath,
|
|
79
|
+
config,
|
|
80
|
+
destFolder,
|
|
81
|
+
extension,
|
|
82
|
+
filename,
|
|
83
|
+
mainFile,
|
|
84
|
+
name,
|
|
85
|
+
pluginsModulesPath,
|
|
86
|
+
srcDir,
|
|
87
|
+
srcPath,
|
|
88
|
+
stat,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const zipWithFunctionWithFallback = (_a) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
var { config = {} } = _a, parameters = __rest(_a, ["config"]);
|
|
94
|
+
// If a specific JS bundler version is specified, we'll use it.
|
|
95
|
+
if (config.nodeBundler !== JS_BUNDLER_ESBUILD_ZISI) {
|
|
96
|
+
return zipFunction(Object.assign(Object.assign({}, parameters), { config }));
|
|
97
|
+
}
|
|
98
|
+
// Otherwise, we'll try to bundle with esbuild and, if that fails, fallback
|
|
99
|
+
// to zisi.
|
|
100
|
+
try {
|
|
101
|
+
return yield zipFunction(Object.assign(Object.assign({}, parameters), { config: Object.assign(Object.assign({}, config), { nodeBundler: JS_BUNDLER_ESBUILD }) }));
|
|
102
|
+
}
|
|
103
|
+
catch (esbuildError) {
|
|
104
|
+
try {
|
|
105
|
+
const data = yield zipFunction(Object.assign(Object.assign({}, parameters), { config: Object.assign(Object.assign({}, config), { nodeBundler: JS_BUNDLER_ZISI }) }));
|
|
106
|
+
return Object.assign(Object.assign({}, data), { bundlerErrors: esbuildError.errors });
|
|
107
|
+
}
|
|
108
|
+
catch (zisiError) {
|
|
109
|
+
throw esbuildError;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
module.exports = {
|
|
114
|
+
findFunctionsInPaths,
|
|
115
|
+
getSrcFiles: getSrcFilesWithBundler,
|
|
116
|
+
name: RUNTIME_JS,
|
|
117
|
+
zipFunction: zipWithFunctionWithFallback,
|
|
118
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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 esbuild = require('@netlify/esbuild');
|
|
11
|
+
const isBuiltinModule = require('is-builtin-module');
|
|
12
|
+
const { tmpName } = require('tmp-promise');
|
|
13
|
+
const { JS_BUNDLER_ZISI, RUNTIME_JS } = require('../../utils/consts');
|
|
14
|
+
const { safeUnlink } = require('../../utils/fs');
|
|
15
|
+
// Maximum number of log messages that an esbuild instance will produce. This
|
|
16
|
+
// limit is important to avoid out-of-memory errors due to too much data being
|
|
17
|
+
// sent in the Go<>Node IPC channel.
|
|
18
|
+
const ESBUILD_LOG_LIMIT = 10;
|
|
19
|
+
const getListImportsPlugin = ({ imports, path }) => ({
|
|
20
|
+
name: 'list-imports',
|
|
21
|
+
setup(build) {
|
|
22
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
23
|
+
const isEntryPoint = args.path === path;
|
|
24
|
+
const isImport = !isEntryPoint && !isBuiltinModule(args.path);
|
|
25
|
+
if (isImport) {
|
|
26
|
+
imports.add(args.path);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
namespace: 'list-imports',
|
|
30
|
+
external: isImport,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const listImports = ({ functionName, path }) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
// We're not interested in the output that esbuild generates, we're just
|
|
37
|
+
// using it for its parsing capabilities in order to find import/require
|
|
38
|
+
// statements. However, if we don't give esbuild a path in `outfile`, it
|
|
39
|
+
// will pipe the output to stdout, which we also don't want. So we create
|
|
40
|
+
// a temporary file to serve as the esbuild output and then get rid of it
|
|
41
|
+
// when we're done.
|
|
42
|
+
const targetPath = yield tmpName();
|
|
43
|
+
const imports = new Set();
|
|
44
|
+
try {
|
|
45
|
+
yield esbuild.build({
|
|
46
|
+
bundle: true,
|
|
47
|
+
entryPoints: [path],
|
|
48
|
+
logLevel: 'error',
|
|
49
|
+
logLimit: ESBUILD_LOG_LIMIT,
|
|
50
|
+
outfile: targetPath,
|
|
51
|
+
platform: 'node',
|
|
52
|
+
plugins: [getListImportsPlugin({ imports, path })],
|
|
53
|
+
target: 'esnext',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
error.customErrorInfo = {
|
|
58
|
+
type: 'functionsBundling',
|
|
59
|
+
location: { bundler: JS_BUNDLER_ZISI, functionName, runtime: RUNTIME_JS },
|
|
60
|
+
};
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
yield safeUnlink(targetPath);
|
|
65
|
+
}
|
|
66
|
+
return [...imports];
|
|
67
|
+
});
|
|
68
|
+
module.exports = { listImports };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { extname } = require('path');
|
|
2
|
+
const markerModules = ['bindings', 'nan', 'node-gyp', 'node-gyp-build', 'node-pre-gyp', 'prebuild'];
|
|
3
|
+
const isNativeModule = ({ binary, dependencies = {}, devDependencies = {}, files = [], gypfile }) => {
|
|
4
|
+
if (binary || gypfile) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
const hasMarkerModule = markerModules.some((marker) => dependencies[marker] || devDependencies[marker]);
|
|
8
|
+
if (hasMarkerModule) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const hasBinaryFile = files.some((path) => !path.startsWith('!') && extname(path) === '.node');
|
|
12
|
+
return hasBinaryFile;
|
|
13
|
+
};
|
|
14
|
+
module.exports = { isNativeModule };
|
|
@@ -0,0 +1,65 @@
|
|
|
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 path = require('path');
|
|
11
|
+
const readPackageJson = require('read-package-json-fast');
|
|
12
|
+
const { isNativeModule } = require('./detector');
|
|
13
|
+
// Filters out relative or absolute file paths.
|
|
14
|
+
const packageFilter = /^([^./]*)$/;
|
|
15
|
+
// Filters valid package names and extracts the base directory.
|
|
16
|
+
const packageName = /^([^@][^/]*|@[^/]*\/[^/]+)(?:\/|$)/;
|
|
17
|
+
const findNativeModule = (packageJsonPath, cache) => {
|
|
18
|
+
if (cache[packageJsonPath] === undefined) {
|
|
19
|
+
// eslint-disable-next-line no-param-reassign, promise/prefer-await-to-then
|
|
20
|
+
cache[packageJsonPath] = readPackageJson(packageJsonPath).then((data) => [Boolean(isNativeModule(data), data), data], () => []);
|
|
21
|
+
}
|
|
22
|
+
return cache[packageJsonPath];
|
|
23
|
+
};
|
|
24
|
+
const getNativeModulesPlugin = (externalizedModules) => ({
|
|
25
|
+
name: 'external-native-modules',
|
|
26
|
+
setup(build) {
|
|
27
|
+
const cache = {};
|
|
28
|
+
// eslint-disable-next-line complexity, max-statements
|
|
29
|
+
build.onResolve({ filter: packageFilter }, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const package = packageName.exec(args.path);
|
|
31
|
+
if (!package)
|
|
32
|
+
return;
|
|
33
|
+
let directory = args.resolveDir;
|
|
34
|
+
while (true) {
|
|
35
|
+
if (path.basename(directory) !== 'node_modules') {
|
|
36
|
+
const modulePath = path.join(directory, 'node_modules', package[1]);
|
|
37
|
+
const packageJsonPath = path.join(modulePath, 'package.json');
|
|
38
|
+
// eslint-disable-next-line no-await-in-loop
|
|
39
|
+
const [isNative, packageJsonData] = yield findNativeModule(packageJsonPath, cache);
|
|
40
|
+
// eslint-disable-next-line max-depth
|
|
41
|
+
if (isNative === true) {
|
|
42
|
+
// eslint-disable-next-line max-depth
|
|
43
|
+
if (externalizedModules[args.path] === undefined) {
|
|
44
|
+
// eslint-disable-next-line no-param-reassign
|
|
45
|
+
externalizedModules[args.path] = {};
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line no-param-reassign
|
|
48
|
+
externalizedModules[args.path][modulePath] = packageJsonData.version;
|
|
49
|
+
return { path: args.path, external: true };
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line max-depth
|
|
52
|
+
if (isNative === false) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const parentDirectory = path.dirname(directory);
|
|
57
|
+
if (parentDirectory === directory) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
directory = parentDirectory;
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
module.exports = { getNativeModulesPlugin };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function getSrcFiles({ config, ...parameters }: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
config: any;
|
|
4
|
+
}): Promise<any[]>;
|
|
5
|
+
export function getSrcFilesAndExternalModules({ bundler, externalNodeModules, featureFlags, includedFiles, includedFilesBasePath, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }: {
|
|
6
|
+
bundler: any;
|
|
7
|
+
externalNodeModules?: any[];
|
|
8
|
+
featureFlags: any;
|
|
9
|
+
includedFiles?: any[];
|
|
10
|
+
includedFilesBasePath: any;
|
|
11
|
+
mainFile: any;
|
|
12
|
+
name: any;
|
|
13
|
+
pluginsModulesPath: any;
|
|
14
|
+
srcDir: any;
|
|
15
|
+
srcPath: any;
|
|
16
|
+
stat: any;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
moduleNames: any[];
|
|
19
|
+
paths: any[];
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
const { normalize } = require('path');
|
|
22
|
+
const { promisify } = require('util');
|
|
23
|
+
const glob = require('glob');
|
|
24
|
+
const pGlob = promisify(glob);
|
|
25
|
+
const { getDependencyNamesAndPathsForDependencies, listFilesUsingLegacyBundler } = require('../../node_dependencies');
|
|
26
|
+
const { JS_BUNDLER_ZISI } = require('../../utils/consts');
|
|
27
|
+
const getPathsOfIncludedFiles = (includedFiles, basePath) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
// Some of the globs in `includedFiles` might be exclusion patterns, which
|
|
29
|
+
// means paths that should NOT be included in the bundle. We need to treat
|
|
30
|
+
// these differently, so we iterate on the array and put those paths in a
|
|
31
|
+
// `exclude` array and the rest of the paths in an `include` array.
|
|
32
|
+
const { include, exclude } = includedFiles.reduce((acc, path) => {
|
|
33
|
+
if (path.startsWith('!')) {
|
|
34
|
+
return Object.assign(Object.assign({}, acc), { exclude: [...acc.exclude, path.slice(1)] });
|
|
35
|
+
}
|
|
36
|
+
return Object.assign(Object.assign({}, acc), { include: [...acc.include, path] });
|
|
37
|
+
}, { include: [], exclude: [] });
|
|
38
|
+
const pathGroups = yield Promise.all(include.map((expression) => pGlob(expression, { absolute: true, cwd: basePath, ignore: exclude, nodir: true })));
|
|
39
|
+
// `pathGroups` is an array containing the paths for each expression in the
|
|
40
|
+
// `include` array. We flatten it into a single dimension.
|
|
41
|
+
const paths = pathGroups.flat();
|
|
42
|
+
const normalizedPaths = paths.map(normalize);
|
|
43
|
+
return [...new Set(normalizedPaths)];
|
|
44
|
+
});
|
|
45
|
+
const getSrcFiles = function (_a) {
|
|
46
|
+
var { config } = _a, parameters = __rest(_a, ["config"]);
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const { paths } = yield getSrcFilesAndExternalModules(Object.assign(Object.assign({}, parameters), { externalNodeModules: config.externalNodeModules }));
|
|
49
|
+
return paths;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const getSrcFilesAndExternalModules = function ({ bundler, externalNodeModules = [], featureFlags, includedFiles = [], includedFilesBasePath, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const includedFilePaths = yield getPathsOfIncludedFiles(includedFiles, includedFilesBasePath);
|
|
55
|
+
if (bundler === JS_BUNDLER_ZISI) {
|
|
56
|
+
const paths = yield listFilesUsingLegacyBundler({
|
|
57
|
+
featureFlags,
|
|
58
|
+
srcPath,
|
|
59
|
+
mainFile,
|
|
60
|
+
name,
|
|
61
|
+
srcDir,
|
|
62
|
+
stat,
|
|
63
|
+
pluginsModulesPath,
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
moduleNames: [],
|
|
67
|
+
paths: [...paths, ...includedFilePaths],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (externalNodeModules.length !== 0) {
|
|
71
|
+
const { moduleNames, paths } = yield getDependencyNamesAndPathsForDependencies({
|
|
72
|
+
dependencies: externalNodeModules,
|
|
73
|
+
basedir: srcDir,
|
|
74
|
+
pluginsModulesPath,
|
|
75
|
+
});
|
|
76
|
+
return { moduleNames, paths: [...paths, ...includedFilePaths, mainFile] };
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
moduleNames: externalNodeModules,
|
|
80
|
+
paths: [mainFile, ...includedFilePaths],
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
module.exports = { getSrcFiles, getSrcFilesAndExternalModules };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function zipEsbuild({ archiveFormat, basePath, config, destFolder, extension, filename, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }: {
|
|
2
|
+
archiveFormat: any;
|
|
3
|
+
basePath: any;
|
|
4
|
+
config?: {};
|
|
5
|
+
destFolder: any;
|
|
6
|
+
extension: any;
|
|
7
|
+
filename: any;
|
|
8
|
+
mainFile: any;
|
|
9
|
+
name: any;
|
|
10
|
+
pluginsModulesPath: any;
|
|
11
|
+
srcDir: any;
|
|
12
|
+
srcPath: any;
|
|
13
|
+
stat: any;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
bundler: string;
|
|
16
|
+
bundlerWarnings: import("@netlify/esbuild").Message[];
|
|
17
|
+
config: {};
|
|
18
|
+
inputs: string[];
|
|
19
|
+
nativeNodeModules: {};
|
|
20
|
+
nodeModulesWithDynamicImports: any[];
|
|
21
|
+
path: string;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,95 @@
|
|
|
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, normalize } = require('path');
|
|
11
|
+
const { getExternalAndIgnoredModulesFromSpecialCases } = require('../../node_dependencies');
|
|
12
|
+
const { JS_BUNDLER_ESBUILD } = require('../../utils/consts');
|
|
13
|
+
const { getPathWithExtension } = require('../../utils/fs');
|
|
14
|
+
const { zipNodeJs } = require('../../zip_node');
|
|
15
|
+
const { getBasePath } = require('./base_path');
|
|
16
|
+
const { bundleJsFile } = require('./bundler');
|
|
17
|
+
const { getSrcFilesAndExternalModules } = require('./src_files');
|
|
18
|
+
const getFunctionBasePath = ({ basePathFromConfig, mainFile, supportingSrcFiles }) => {
|
|
19
|
+
// If there is a base path defined in the config, we use that.
|
|
20
|
+
if (basePathFromConfig !== undefined) {
|
|
21
|
+
return basePathFromConfig;
|
|
22
|
+
}
|
|
23
|
+
// If not, the base path is the common path prefix between all the supporting
|
|
24
|
+
// files and the main file.
|
|
25
|
+
const dirnames = [...supportingSrcFiles, mainFile].map((filePath) => normalize(dirname(filePath)));
|
|
26
|
+
return getBasePath(dirnames);
|
|
27
|
+
};
|
|
28
|
+
// Convenience method for retrieving external and ignored modules from
|
|
29
|
+
// different places and merging them together.
|
|
30
|
+
const getExternalAndIgnoredModules = ({ config, srcDir }) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const { externalNodeModules: externalModulesFromConfig = [], ignoredNodeModules: ignoredModulesFromConfig = [] } = config;
|
|
32
|
+
const { externalModules: externalModulesFromSpecialCases, ignoredModules: ignoredModulesFromSpecialCases } = yield getExternalAndIgnoredModulesFromSpecialCases({ srcDir });
|
|
33
|
+
const externalModules = [...new Set([...externalModulesFromConfig, ...externalModulesFromSpecialCases])];
|
|
34
|
+
const ignoredModules = [...ignoredModulesFromConfig, ...ignoredModulesFromSpecialCases];
|
|
35
|
+
return { externalModules, ignoredModules };
|
|
36
|
+
});
|
|
37
|
+
const zipEsbuild = ({ archiveFormat, basePath, config = {}, destFolder, extension, filename, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { externalModules, ignoredModules } = yield getExternalAndIgnoredModules({ config, srcDir });
|
|
39
|
+
const { additionalPaths, bundlePaths, cleanTempFiles, inputs, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = yield bundleJsFile({
|
|
40
|
+
additionalModulePaths: pluginsModulesPath ? [pluginsModulesPath] : [],
|
|
41
|
+
basePath,
|
|
42
|
+
config,
|
|
43
|
+
destFilename: filename,
|
|
44
|
+
externalModules,
|
|
45
|
+
ignoredModules,
|
|
46
|
+
name,
|
|
47
|
+
srcDir,
|
|
48
|
+
srcFile: mainFile,
|
|
49
|
+
});
|
|
50
|
+
const bundlerWarnings = warnings.length === 0 ? undefined : warnings;
|
|
51
|
+
const { paths: srcFiles } = yield getSrcFilesAndExternalModules({
|
|
52
|
+
externalNodeModules: [...externalModules, ...Object.keys(nativeNodeModules)],
|
|
53
|
+
bundler: JS_BUNDLER_ESBUILD,
|
|
54
|
+
includedFiles: [...(config.includedFiles || []), ...additionalPaths],
|
|
55
|
+
includedFilesBasePath: config.includedFilesBasePath || basePath,
|
|
56
|
+
mainFile,
|
|
57
|
+
name,
|
|
58
|
+
srcPath,
|
|
59
|
+
srcDir,
|
|
60
|
+
pluginsModulesPath,
|
|
61
|
+
stat,
|
|
62
|
+
});
|
|
63
|
+
// We want to remove `mainFile` from `srcFiles` because it represents the
|
|
64
|
+
// path of the original, pre-bundling function file. We'll add the actual
|
|
65
|
+
// bundled file further below.
|
|
66
|
+
const supportingSrcFiles = srcFiles.filter((path) => path !== mainFile);
|
|
67
|
+
const normalizedMainFile = getPathWithExtension(mainFile, '.js');
|
|
68
|
+
const functionBasePath = getFunctionBasePath({ basePathFromConfig: basePath, mainFile, supportingSrcFiles });
|
|
69
|
+
try {
|
|
70
|
+
const path = yield zipNodeJs({
|
|
71
|
+
aliases: bundlePaths,
|
|
72
|
+
archiveFormat,
|
|
73
|
+
basePath: functionBasePath,
|
|
74
|
+
destFolder,
|
|
75
|
+
extension,
|
|
76
|
+
filename,
|
|
77
|
+
mainFile: normalizedMainFile,
|
|
78
|
+
pluginsModulesPath,
|
|
79
|
+
srcFiles: [...supportingSrcFiles, ...bundlePaths.keys()],
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
bundler: JS_BUNDLER_ESBUILD,
|
|
83
|
+
bundlerWarnings,
|
|
84
|
+
config,
|
|
85
|
+
inputs,
|
|
86
|
+
nativeNodeModules,
|
|
87
|
+
nodeModulesWithDynamicImports,
|
|
88
|
+
path,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
yield cleanTempFiles();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
module.exports = { zipEsbuild };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function zipZisi({ archiveFormat, basePath, config, destFolder, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }: {
|
|
2
|
+
archiveFormat: any;
|
|
3
|
+
basePath: any;
|
|
4
|
+
config: any;
|
|
5
|
+
destFolder: any;
|
|
6
|
+
extension: any;
|
|
7
|
+
featureFlags: any;
|
|
8
|
+
filename: any;
|
|
9
|
+
mainFile: any;
|
|
10
|
+
name: any;
|
|
11
|
+
pluginsModulesPath: any;
|
|
12
|
+
srcDir: any;
|
|
13
|
+
srcPath: any;
|
|
14
|
+
stat: any;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
bundler: string;
|
|
17
|
+
config: any;
|
|
18
|
+
inputs: any[];
|
|
19
|
+
path: string;
|
|
20
|
+
}>;
|
|
@@ -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 { dirname, normalize } = require('path');
|
|
11
|
+
const { JS_BUNDLER_ZISI } = require('../../utils/consts');
|
|
12
|
+
const { zipNodeJs } = require('../../zip_node');
|
|
13
|
+
const { getBasePath } = require('./base_path');
|
|
14
|
+
const { getSrcFilesAndExternalModules } = require('./src_files');
|
|
15
|
+
const zipZisi = ({ archiveFormat, basePath, config, destFolder, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const { paths: srcFiles } = yield getSrcFilesAndExternalModules({
|
|
17
|
+
bundler: JS_BUNDLER_ZISI,
|
|
18
|
+
extension,
|
|
19
|
+
featureFlags,
|
|
20
|
+
includedFiles: config.includedFiles,
|
|
21
|
+
includedFilesBasePath: config.includedFilesBasePath || basePath,
|
|
22
|
+
mainFile,
|
|
23
|
+
name,
|
|
24
|
+
pluginsModulesPath,
|
|
25
|
+
srcDir,
|
|
26
|
+
srcPath,
|
|
27
|
+
stat,
|
|
28
|
+
});
|
|
29
|
+
const dirnames = srcFiles.map((filePath) => normalize(dirname(filePath)));
|
|
30
|
+
const path = yield zipNodeJs({
|
|
31
|
+
archiveFormat,
|
|
32
|
+
basePath: getBasePath(dirnames),
|
|
33
|
+
destFolder,
|
|
34
|
+
extension,
|
|
35
|
+
filename,
|
|
36
|
+
mainFile,
|
|
37
|
+
pluginsModulesPath,
|
|
38
|
+
srcFiles,
|
|
39
|
+
});
|
|
40
|
+
return { bundler: JS_BUNDLER_ZISI, config, inputs: srcFiles, path };
|
|
41
|
+
});
|
|
42
|
+
module.exports = { zipZisi };
|