@netlify/zip-it-and-ship-it 5.4.0 → 5.5.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.
- package/README.md +1 -1
- package/dist/archive.js +3 -14
- package/dist/bin.js +13 -35
- package/dist/config.d.ts +1 -0
- package/dist/feature_flags.js +4 -1
- package/dist/main.js +42 -70
- package/dist/manifest.js +4 -13
- package/dist/runtimes/detect_runtime.js +16 -27
- package/dist/runtimes/go/builder.js +5 -14
- package/dist/runtimes/go/index.js +61 -48
- package/dist/runtimes/index.js +34 -37
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +81 -92
- package/dist/runtimes/node/bundlers/esbuild/index.js +14 -18
- package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +13 -22
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +3 -13
- package/dist/runtimes/node/bundlers/esbuild/special_cases.js +8 -17
- package/dist/runtimes/node/bundlers/esbuild/src_files.js +28 -41
- package/dist/runtimes/node/bundlers/nft/es_modules.js +16 -22
- package/dist/runtimes/node/bundlers/nft/index.js +47 -60
- package/dist/runtimes/node/bundlers/nft/transpile.js +3 -12
- package/dist/runtimes/node/bundlers/zisi/index.js +7 -13
- package/dist/runtimes/node/bundlers/zisi/list_imports.js +5 -14
- package/dist/runtimes/node/bundlers/zisi/published.js +8 -19
- package/dist/runtimes/node/bundlers/zisi/resolve.js +37 -55
- package/dist/runtimes/node/bundlers/zisi/side_files.js +6 -17
- package/dist/runtimes/node/bundlers/zisi/src_files.js +58 -75
- package/dist/runtimes/node/bundlers/zisi/traverse.js +41 -56
- package/dist/runtimes/node/bundlers/zisi/tree_files.js +8 -19
- package/dist/runtimes/node/finder.js +46 -63
- package/dist/runtimes/node/in_source_config/index.js +5 -14
- package/dist/runtimes/node/index.js +64 -87
- package/dist/runtimes/node/parser/index.js +11 -20
- package/dist/runtimes/node/utils/detect_es_module.js +4 -15
- package/dist/runtimes/node/utils/included_files.js +3 -12
- package/dist/runtimes/node/utils/package_json.js +19 -27
- package/dist/runtimes/node/utils/zip.js +63 -94
- package/dist/runtimes/rust/builder.js +23 -36
- package/dist/runtimes/rust/index.js +46 -61
- package/dist/utils/archive_size.js +5 -14
- package/dist/utils/format_result.js +6 -1
- package/dist/utils/fs.d.ts +6 -10
- package/dist/utils/fs.js +35 -63
- package/dist/zip.d.ts +1 -0
- package/dist/zip.js +59 -72
- package/dist/zip_binary.js +5 -16
- package/package.json +8 -15
|
@@ -1,24 +1,4 @@
|
|
|
1
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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
@@ -33,7 +13,7 @@ const plugin_modules_path_1 = require("./utils/plugin_modules_path");
|
|
|
33
13
|
const zip_1 = require("./utils/zip");
|
|
34
14
|
// We use ZISI as the default bundler, except for certain extensions, for which
|
|
35
15
|
// esbuild is the only option.
|
|
36
|
-
const getDefaultBundler = ({ extension, mainFile, featureFlags, }) =>
|
|
16
|
+
const getDefaultBundler = async ({ extension, mainFile, featureFlags, }) => {
|
|
37
17
|
const { defaultEsModulesToEsbuild, traceWithNft } = featureFlags;
|
|
38
18
|
if (['.mjs', '.ts'].includes(extension)) {
|
|
39
19
|
return 'esbuild';
|
|
@@ -42,100 +22,97 @@ const getDefaultBundler = ({ extension, mainFile, featureFlags, }) => __awaiter(
|
|
|
42
22
|
return 'nft';
|
|
43
23
|
}
|
|
44
24
|
if (defaultEsModulesToEsbuild) {
|
|
45
|
-
const isEsModule =
|
|
25
|
+
const isEsModule = await (0, detect_es_module_1.detectEsModule)({ mainFile });
|
|
46
26
|
if (isEsModule) {
|
|
47
27
|
return 'esbuild';
|
|
48
28
|
}
|
|
49
29
|
}
|
|
50
30
|
return 'zisi';
|
|
51
|
-
}
|
|
31
|
+
};
|
|
52
32
|
// A proxy for the `getSrcFiles` function which adds a default `bundler` using
|
|
53
33
|
// the `getDefaultBundler` function.
|
|
54
|
-
const getSrcFilesWithBundler = (parameters) =>
|
|
55
|
-
const pluginsModulesPath =
|
|
34
|
+
const getSrcFilesWithBundler = async (parameters) => {
|
|
35
|
+
const pluginsModulesPath = await (0, plugin_modules_path_1.getPluginsModulesPath)(parameters.srcDir);
|
|
56
36
|
const bundlerName = parameters.config.nodeBundler ||
|
|
57
|
-
(
|
|
37
|
+
(await getDefaultBundler({
|
|
58
38
|
extension: parameters.extension,
|
|
59
39
|
featureFlags: parameters.featureFlags,
|
|
60
40
|
mainFile: parameters.mainFile,
|
|
61
41
|
}));
|
|
62
42
|
const bundler = (0, bundlers_1.getBundler)(bundlerName);
|
|
63
|
-
return bundler.getSrcFiles(
|
|
64
|
-
}
|
|
65
|
-
const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
stat,
|
|
91
|
-
});
|
|
92
|
-
const inSourceConfig = yield (0, in_source_config_1.findISCDeclarationsInPath)(mainFile);
|
|
93
|
-
(0, plugin_modules_path_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
|
|
94
|
-
const zipPath = yield (0, zip_1.zipNodeJs)({
|
|
95
|
-
aliases,
|
|
96
|
-
archiveFormat,
|
|
97
|
-
basePath: finalBasePath,
|
|
98
|
-
destFolder,
|
|
99
|
-
extension,
|
|
100
|
-
filename,
|
|
101
|
-
mainFile: finalMainFile,
|
|
102
|
-
rewrites,
|
|
103
|
-
srcFiles,
|
|
104
|
-
});
|
|
105
|
-
yield (cleanupFunction === null || cleanupFunction === void 0 ? void 0 : cleanupFunction());
|
|
106
|
-
return {
|
|
107
|
-
bundler: bundlerName,
|
|
108
|
-
bundlerWarnings,
|
|
109
|
-
config,
|
|
110
|
-
inputs,
|
|
111
|
-
inSourceConfig,
|
|
112
|
-
nativeNodeModules,
|
|
113
|
-
nodeModulesWithDynamicImports,
|
|
114
|
-
path: zipPath,
|
|
115
|
-
};
|
|
43
|
+
return bundler.getSrcFiles({ ...parameters, pluginsModulesPath });
|
|
44
|
+
};
|
|
45
|
+
const zipFunction = async function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
|
|
46
|
+
const pluginsModulesPath = await (0, plugin_modules_path_1.getPluginsModulesPath)(srcDir);
|
|
47
|
+
const bundlerName = config.nodeBundler || (await getDefaultBundler({ extension, mainFile, featureFlags }));
|
|
48
|
+
const bundler = (0, bundlers_1.getBundler)(bundlerName);
|
|
49
|
+
// If the file is a zip, we assume the function is bundled and ready to go.
|
|
50
|
+
// We simply copy it to the destination path with no further processing.
|
|
51
|
+
if (extension === '.zip') {
|
|
52
|
+
const destPath = (0, path_1.join)(destFolder, filename);
|
|
53
|
+
await (0, cp_file_1.default)(srcPath, destPath);
|
|
54
|
+
return { config, path: destPath };
|
|
55
|
+
}
|
|
56
|
+
const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, inputs, mainFile: finalMainFile = mainFile, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = await bundler.bundle({
|
|
57
|
+
basePath,
|
|
58
|
+
config,
|
|
59
|
+
extension,
|
|
60
|
+
featureFlags,
|
|
61
|
+
filename,
|
|
62
|
+
mainFile,
|
|
63
|
+
name,
|
|
64
|
+
pluginsModulesPath,
|
|
65
|
+
repositoryRoot,
|
|
66
|
+
runtime,
|
|
67
|
+
srcDir,
|
|
68
|
+
srcPath,
|
|
69
|
+
stat,
|
|
116
70
|
});
|
|
71
|
+
const inSourceConfig = await (0, in_source_config_1.findISCDeclarationsInPath)(mainFile);
|
|
72
|
+
(0, plugin_modules_path_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
|
|
73
|
+
const zipPath = await (0, zip_1.zipNodeJs)({
|
|
74
|
+
aliases,
|
|
75
|
+
archiveFormat,
|
|
76
|
+
basePath: finalBasePath,
|
|
77
|
+
destFolder,
|
|
78
|
+
extension,
|
|
79
|
+
filename,
|
|
80
|
+
mainFile: finalMainFile,
|
|
81
|
+
rewrites,
|
|
82
|
+
srcFiles,
|
|
83
|
+
});
|
|
84
|
+
await (cleanupFunction === null || cleanupFunction === void 0 ? void 0 : cleanupFunction());
|
|
85
|
+
return {
|
|
86
|
+
bundler: bundlerName,
|
|
87
|
+
bundlerWarnings,
|
|
88
|
+
config,
|
|
89
|
+
inputs,
|
|
90
|
+
inSourceConfig,
|
|
91
|
+
nativeNodeModules,
|
|
92
|
+
nodeModulesWithDynamicImports,
|
|
93
|
+
path: zipPath,
|
|
94
|
+
};
|
|
117
95
|
};
|
|
118
|
-
const zipWithFunctionWithFallback =
|
|
119
|
-
var { config = {} } = _a, parameters = __rest(_a, ["config"]);
|
|
96
|
+
const zipWithFunctionWithFallback = async ({ config = {}, ...parameters }) => {
|
|
120
97
|
// If a specific JS bundler version is specified, we'll use it.
|
|
121
98
|
if (config.nodeBundler !== 'esbuild_zisi') {
|
|
122
|
-
return zipFunction(
|
|
99
|
+
return zipFunction({ ...parameters, config });
|
|
123
100
|
}
|
|
124
101
|
// Otherwise, we'll try to bundle with esbuild and, if that fails, fallback
|
|
125
102
|
// to zisi.
|
|
126
103
|
try {
|
|
127
|
-
return
|
|
104
|
+
return await zipFunction({ ...parameters, config: { ...config, nodeBundler: 'esbuild' } });
|
|
128
105
|
}
|
|
129
106
|
catch (esbuildError) {
|
|
130
107
|
try {
|
|
131
|
-
const data =
|
|
132
|
-
return
|
|
108
|
+
const data = await zipFunction({ ...parameters, config: { ...config, nodeBundler: 'zisi' } });
|
|
109
|
+
return { ...data, bundlerErrors: esbuildError.errors };
|
|
133
110
|
}
|
|
134
|
-
catch
|
|
111
|
+
catch {
|
|
135
112
|
throw esbuildError;
|
|
136
113
|
}
|
|
137
114
|
}
|
|
138
|
-
}
|
|
115
|
+
};
|
|
139
116
|
const runtime = {
|
|
140
117
|
findFunctionsInPaths: finder_1.findFunctionsInPaths,
|
|
141
118
|
findFunctionInPath: finder_1.findFunctionInPath,
|
|
@@ -1,19 +1,10 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.safelyParseFile = exports.parseExpression = void 0;
|
|
13
4
|
/* eslint-disable max-lines */
|
|
5
|
+
const fs_1 = require("fs");
|
|
14
6
|
const path_1 = require("path");
|
|
15
7
|
const parser_1 = require("@babel/parser");
|
|
16
|
-
const fs_1 = require("../../../utils/fs");
|
|
17
8
|
const non_nullable_1 = require("../../../utils/non_nullable");
|
|
18
9
|
const GLOB_WILDCARD = '**';
|
|
19
10
|
// Transforms an array of glob nodes into a glob string including an absolute
|
|
@@ -80,34 +71,34 @@ const parseExpression = ({ basePath, expression: rawExpression, resolveDir, }) =
|
|
|
80
71
|
type: expression.callee.name,
|
|
81
72
|
};
|
|
82
73
|
}
|
|
83
|
-
catch
|
|
74
|
+
catch {
|
|
84
75
|
// no-op
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
78
|
};
|
|
88
79
|
exports.parseExpression = parseExpression;
|
|
89
80
|
// Parses a JS/TS file and returns the resulting AST.
|
|
90
|
-
const parseFile = (path) =>
|
|
91
|
-
const code =
|
|
81
|
+
const parseFile = async (path) => {
|
|
82
|
+
const code = await fs_1.promises.readFile(path, 'utf8');
|
|
92
83
|
const ast = (0, parser_1.parse)(code, {
|
|
93
84
|
plugins: ['typescript'],
|
|
94
85
|
sourceType: 'module',
|
|
95
86
|
});
|
|
96
87
|
return ast.program;
|
|
97
|
-
}
|
|
98
|
-
//
|
|
88
|
+
};
|
|
89
|
+
// Attempts to parse a JS/TS file at the given path, returning its AST if
|
|
99
90
|
// successful, or `null` if not.
|
|
100
|
-
const safelyParseFile = (path) =>
|
|
91
|
+
const safelyParseFile = async (path) => {
|
|
101
92
|
if (!path) {
|
|
102
93
|
return null;
|
|
103
94
|
}
|
|
104
95
|
try {
|
|
105
|
-
return
|
|
96
|
+
return await parseFile(path);
|
|
106
97
|
}
|
|
107
|
-
catch
|
|
98
|
+
catch {
|
|
108
99
|
return null;
|
|
109
100
|
}
|
|
110
|
-
}
|
|
101
|
+
};
|
|
111
102
|
exports.safelyParseFile = safelyParseFile;
|
|
112
103
|
// Parses a `require()` and returns a glob string with an absolute path.
|
|
113
104
|
const parseRequire = ({ basePath, expression, resolveDir, }) => {
|
|
@@ -121,7 +112,7 @@ const parseRequire = ({ basePath, expression, resolveDir, }) => {
|
|
|
121
112
|
const globNodes = parseBinaryExpression(firstArg);
|
|
122
113
|
return getAbsoluteGlob({ basePath, globNodes, resolveDir });
|
|
123
114
|
}
|
|
124
|
-
catch
|
|
115
|
+
catch {
|
|
125
116
|
// no-op
|
|
126
117
|
}
|
|
127
118
|
}
|
|
@@ -1,32 +1,21 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.detectEsModule = void 0;
|
|
13
4
|
const fs_1 = require("fs");
|
|
14
|
-
const util_1 = require("util");
|
|
15
5
|
const es_module_lexer_1 = require("es-module-lexer");
|
|
16
|
-
const
|
|
17
|
-
const detectEsModule = ({ mainFile }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6
|
+
const detectEsModule = async ({ mainFile }) => {
|
|
18
7
|
if (!mainFile) {
|
|
19
8
|
return false;
|
|
20
9
|
}
|
|
21
10
|
try {
|
|
22
|
-
const [mainFileContents] =
|
|
11
|
+
const [mainFileContents] = await Promise.all([fs_1.promises.readFile(mainFile, 'utf8'), es_module_lexer_1.init]);
|
|
23
12
|
const [imports, exports] = (0, es_module_lexer_1.parse)(mainFileContents);
|
|
24
13
|
return imports.length !== 0 || exports.length !== 0;
|
|
25
14
|
}
|
|
26
|
-
catch
|
|
15
|
+
catch {
|
|
27
16
|
// If there are any problems with init or parsing, assume it's not an ES module
|
|
28
17
|
return false;
|
|
29
18
|
}
|
|
30
|
-
}
|
|
19
|
+
};
|
|
31
20
|
exports.detectEsModule = detectEsModule;
|
|
32
21
|
//# sourceMappingURL=detect_es_module.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -28,7 +19,7 @@ const filterExcludedPaths = (paths, exclude = []) => {
|
|
|
28
19
|
return excludedPaths;
|
|
29
20
|
};
|
|
30
21
|
exports.filterExcludedPaths = filterExcludedPaths;
|
|
31
|
-
const getPathsOfIncludedFiles = (includedFiles, basePath) =>
|
|
22
|
+
const getPathsOfIncludedFiles = async (includedFiles, basePath) => {
|
|
32
23
|
if (basePath === undefined) {
|
|
33
24
|
return { exclude: [], paths: [] };
|
|
34
25
|
}
|
|
@@ -49,12 +40,12 @@ const getPathsOfIncludedFiles = (includedFiles, basePath) => __awaiter(void 0, v
|
|
|
49
40
|
exclude: acc.exclude,
|
|
50
41
|
};
|
|
51
42
|
}, { include: [], exclude: [] });
|
|
52
|
-
const pathGroups =
|
|
43
|
+
const pathGroups = await Promise.all(include.map((expression) => pGlob(expression, { absolute: true, cwd: basePath, ignore: exclude, nodir: true })));
|
|
53
44
|
// `pathGroups` is an array containing the paths for each expression in the
|
|
54
45
|
// `include` array. We flatten it into a single dimension.
|
|
55
46
|
const paths = pathGroups.flat();
|
|
56
47
|
const normalizedPaths = paths.map(path_1.normalize);
|
|
57
48
|
return { exclude, paths: [...new Set(normalizedPaths)] };
|
|
58
|
-
}
|
|
49
|
+
};
|
|
59
50
|
exports.getPathsOfIncludedFiles = getPathsOfIncludedFiles;
|
|
60
51
|
//# sourceMappingURL=included_files.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -20,26 +11,27 @@ const sanitiseFiles = (files) => {
|
|
|
20
11
|
}
|
|
21
12
|
return files.filter((file) => typeof file === 'string');
|
|
22
13
|
};
|
|
23
|
-
const sanitisePackageJson = (packageJson) => (
|
|
14
|
+
const sanitisePackageJson = (packageJson) => ({
|
|
15
|
+
...packageJson,
|
|
16
|
+
files: sanitiseFiles(packageJson.files),
|
|
17
|
+
});
|
|
24
18
|
exports.sanitisePackageJson = sanitisePackageJson;
|
|
25
19
|
// Retrieve the `package.json` of a specific project or module
|
|
26
|
-
const getPackageJson = function (srcDir) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
});
|
|
20
|
+
const getPackageJson = async function (srcDir) {
|
|
21
|
+
const packageRoot = await (0, pkg_dir_1.default)(srcDir);
|
|
22
|
+
if (packageRoot === undefined) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
const packageJsonPath = `${packageRoot}/package.json`;
|
|
26
|
+
try {
|
|
27
|
+
// The path depends on the user's build, i.e. must be dynamic
|
|
28
|
+
// eslint-disable-next-line import/no-dynamic-require, node/global-require, @typescript-eslint/no-var-requires
|
|
29
|
+
const packageJson = require(packageJsonPath);
|
|
30
|
+
return sanitisePackageJson(packageJson);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new Error(`${packageJsonPath} is invalid JSON: ${error.message}`);
|
|
34
|
+
}
|
|
43
35
|
};
|
|
44
36
|
exports.getPackageJson = getPackageJson;
|
|
45
37
|
//# sourceMappingURL=package_json.js.map
|
|
@@ -1,24 +1,4 @@
|
|
|
1
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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
@@ -26,95 +6,86 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
6
|
exports.zipNodeJs = void 0;
|
|
27
7
|
/* eslint-disable max-lines */
|
|
28
8
|
const buffer_1 = require("buffer");
|
|
29
|
-
const fs_1 =
|
|
9
|
+
const fs_1 = require("fs");
|
|
30
10
|
const os_1 = __importDefault(require("os"));
|
|
31
11
|
const path_1 = require("path");
|
|
32
|
-
const util_1 = require("util");
|
|
33
12
|
const cp_file_1 = __importDefault(require("cp-file"));
|
|
34
13
|
const del_1 = __importDefault(require("del"));
|
|
35
|
-
const make_dir_1 = __importDefault(require("make-dir"));
|
|
36
14
|
const p_map_1 = __importDefault(require("p-map"));
|
|
37
15
|
const unixify_1 = __importDefault(require("unixify"));
|
|
38
16
|
const archive_1 = require("../../../archive");
|
|
39
17
|
const fs_2 = require("../../../utils/fs");
|
|
40
|
-
const pLstat = (0, util_1.promisify)(fs_1.default.lstat);
|
|
41
|
-
const pWriteFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
|
42
18
|
// Taken from https://www.npmjs.com/package/cpy.
|
|
43
19
|
const COPY_FILE_CONCURRENCY = os_1.default.cpus().length === 0 ? 2 : os_1.default.cpus().length * 2;
|
|
44
20
|
// Sub-directory to place all user-defined files (i.e. everything other than
|
|
45
21
|
// the entry file generated by zip-it-and-ship-it).
|
|
46
22
|
const DEFAULT_USER_SUBDIRECTORY = 'src';
|
|
47
|
-
const createDirectory = function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, rewrites = new Map(), srcFiles, }) {
|
|
48
|
-
|
|
49
|
-
|
|
23
|
+
const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, rewrites = new Map(), srcFiles, }) {
|
|
24
|
+
const { contents: entryContents, filename: entryFilename } = getEntryFile({
|
|
25
|
+
commonPrefix: basePath,
|
|
26
|
+
filename,
|
|
27
|
+
mainFile,
|
|
28
|
+
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
29
|
+
});
|
|
30
|
+
const functionFolder = (0, path_1.join)(destFolder, (0, path_1.basename)(filename, extension));
|
|
31
|
+
// Deleting the functions directory in case it exists before creating it.
|
|
32
|
+
await (0, del_1.default)(functionFolder, { force: true });
|
|
33
|
+
await fs_1.promises.mkdir(functionFolder, { recursive: true });
|
|
34
|
+
// Writing entry file.
|
|
35
|
+
await fs_1.promises.writeFile((0, path_1.join)(functionFolder, entryFilename), entryContents);
|
|
36
|
+
// Copying source files.
|
|
37
|
+
await (0, p_map_1.default)(srcFiles, (srcFile) => {
|
|
38
|
+
const destPath = aliases.get(srcFile) || srcFile;
|
|
39
|
+
const normalizedDestPath = normalizeFilePath({
|
|
50
40
|
commonPrefix: basePath,
|
|
51
|
-
|
|
52
|
-
mainFile,
|
|
41
|
+
path: destPath,
|
|
53
42
|
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
54
43
|
});
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
yield (0, make_dir_1.default)(functionFolder);
|
|
59
|
-
// Writing entry file.
|
|
60
|
-
yield pWriteFile((0, path_1.join)(functionFolder, entryFilename), entryContents);
|
|
61
|
-
// Copying source files.
|
|
62
|
-
yield (0, p_map_1.default)(srcFiles, (srcFile) => {
|
|
63
|
-
const destPath = aliases.get(srcFile) || srcFile;
|
|
64
|
-
const normalizedDestPath = normalizeFilePath({
|
|
65
|
-
commonPrefix: basePath,
|
|
66
|
-
path: destPath,
|
|
67
|
-
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
68
|
-
});
|
|
69
|
-
const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
|
|
70
|
-
if (rewrites.has(srcFile)) {
|
|
71
|
-
return (0, fs_2.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
|
|
72
|
-
}
|
|
73
|
-
return (0, cp_file_1.default)(srcFile, absoluteDestPath);
|
|
74
|
-
}, { concurrency: COPY_FILE_CONCURRENCY });
|
|
75
|
-
return functionFolder;
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
const createZipArchive = function ({ aliases, basePath, destFolder, extension, filename, mainFile, rewrites, srcFiles, }) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
|
|
81
|
-
const { archive, output } = (0, archive_1.startZip)(destPath);
|
|
82
|
-
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
83
|
-
const entryFilePath = (0, path_1.resolve)(basePath, entryFilename);
|
|
84
|
-
// We don't need an entry file if it would end up with the same path as the
|
|
85
|
-
// function's main file.
|
|
86
|
-
const needsEntryFile = entryFilePath !== mainFile;
|
|
87
|
-
// There is a naming conflict with the entry file if one of the supporting
|
|
88
|
-
// files (i.e. not the main file) has the path that the entry file needs to
|
|
89
|
-
// take.
|
|
90
|
-
const hasEntryFileConflict = srcFiles.some((srcFile) => srcFile === entryFilePath && srcFile !== mainFile);
|
|
91
|
-
// If there is a naming conflict, we move all user files (everything other
|
|
92
|
-
// than the entry file) to its own sub-directory.
|
|
93
|
-
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
|
94
|
-
if (needsEntryFile) {
|
|
95
|
-
const entryFile = getEntryFile({ commonPrefix: basePath, filename, mainFile, userNamespace });
|
|
96
|
-
addEntryFileToZip(archive, entryFile);
|
|
44
|
+
const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
|
|
45
|
+
if (rewrites.has(srcFile)) {
|
|
46
|
+
return (0, fs_2.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
|
|
97
47
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
48
|
+
return (0, cp_file_1.default)(srcFile, absoluteDestPath);
|
|
49
|
+
}, { concurrency: COPY_FILE_CONCURRENCY });
|
|
50
|
+
return functionFolder;
|
|
51
|
+
};
|
|
52
|
+
const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, rewrites, srcFiles, }) {
|
|
53
|
+
const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
|
|
54
|
+
const { archive, output } = (0, archive_1.startZip)(destPath);
|
|
55
|
+
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
56
|
+
const entryFilePath = (0, path_1.resolve)(basePath, entryFilename);
|
|
57
|
+
// We don't need an entry file if it would end up with the same path as the
|
|
58
|
+
// function's main file.
|
|
59
|
+
const needsEntryFile = entryFilePath !== mainFile;
|
|
60
|
+
// There is a naming conflict with the entry file if one of the supporting
|
|
61
|
+
// files (i.e. not the main file) has the path that the entry file needs to
|
|
62
|
+
// take.
|
|
63
|
+
const hasEntryFileConflict = srcFiles.some((srcFile) => srcFile === entryFilePath && srcFile !== mainFile);
|
|
64
|
+
// If there is a naming conflict, we move all user files (everything other
|
|
65
|
+
// than the entry file) to its own sub-directory.
|
|
66
|
+
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
|
67
|
+
if (needsEntryFile) {
|
|
68
|
+
const entryFile = getEntryFile({ commonPrefix: basePath, filename, mainFile, userNamespace });
|
|
69
|
+
addEntryFileToZip(archive, entryFile);
|
|
70
|
+
}
|
|
71
|
+
const srcFilesInfos = await Promise.all(srcFiles.map(addStat));
|
|
72
|
+
// We ensure this is not async, so that the archive's checksum is
|
|
73
|
+
// deterministic. Otherwise it depends on the order the files were added.
|
|
74
|
+
srcFilesInfos.forEach(({ srcFile, stat }) => {
|
|
75
|
+
zipJsFile({
|
|
76
|
+
aliases,
|
|
77
|
+
archive,
|
|
78
|
+
commonPrefix: basePath,
|
|
79
|
+
rewrites,
|
|
80
|
+
srcFile,
|
|
81
|
+
stat,
|
|
82
|
+
userNamespace,
|
|
111
83
|
});
|
|
112
|
-
yield (0, archive_1.endZip)(archive, output);
|
|
113
|
-
return destPath;
|
|
114
84
|
});
|
|
85
|
+
await (0, archive_1.endZip)(archive, output);
|
|
86
|
+
return destPath;
|
|
115
87
|
};
|
|
116
|
-
const zipNodeJs = function (
|
|
117
|
-
var { archiveFormat } = _a, options = __rest(_a, ["archiveFormat"]);
|
|
88
|
+
const zipNodeJs = function ({ archiveFormat, ...options }) {
|
|
118
89
|
if (archiveFormat === 'zip') {
|
|
119
90
|
return createZipArchive(options);
|
|
120
91
|
}
|
|
@@ -125,11 +96,9 @@ const addEntryFileToZip = function (archive, { contents, filename }) {
|
|
|
125
96
|
const contentBuffer = buffer_1.Buffer.from(contents);
|
|
126
97
|
(0, archive_1.addZipContent)(archive, contentBuffer, filename);
|
|
127
98
|
};
|
|
128
|
-
const addStat = function (srcFile) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return { srcFile, stat };
|
|
132
|
-
});
|
|
99
|
+
const addStat = async function (srcFile) {
|
|
100
|
+
const stat = await fs_1.promises.lstat(srcFile);
|
|
101
|
+
return { srcFile, stat };
|
|
133
102
|
};
|
|
134
103
|
const getEntryFile = ({ commonPrefix, filename, mainFile, userNamespace, }) => {
|
|
135
104
|
const mainPath = normalizeFilePath({ commonPrefix, path: mainFile, userNamespace });
|