@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.
- 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 +19 -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
package/dist/zip_node.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
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 { Buffer } = require('buffer');
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const os = require('os');
|
|
24
|
+
const { basename, extname, join, normalize, resolve, sep } = require('path');
|
|
25
|
+
const { promisify } = require('util');
|
|
26
|
+
const copyFile = require('cp-file');
|
|
27
|
+
const deleteFiles = require('del');
|
|
28
|
+
const makeDir = require('make-dir');
|
|
29
|
+
const pMap = require('p-map');
|
|
30
|
+
const unixify = require('unixify');
|
|
31
|
+
const { startZip, addZipFile, addZipContent, endZip } = require('./archive');
|
|
32
|
+
const { ARCHIVE_FORMAT_ZIP } = require('./utils/consts');
|
|
33
|
+
const pStat = promisify(fs.stat);
|
|
34
|
+
const pWriteFile = promisify(fs.writeFile);
|
|
35
|
+
// Taken from https://www.npmjs.com/package/cpy.
|
|
36
|
+
const COPY_FILE_CONCURRENCY = os.cpus().length === 0 ? 2 : os.cpus().length * 2;
|
|
37
|
+
// Sub-directory to place all user-defined files (i.e. everything other than
|
|
38
|
+
// the entry file generated by zip-it-and-ship-it).
|
|
39
|
+
const DEFAULT_USER_SUBDIRECTORY = 'src';
|
|
40
|
+
const createDirectory = function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, pluginsModulesPath, srcFiles, }) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const { contents: entryContents, filename: entryFilename } = getEntryFile({
|
|
43
|
+
commonPrefix: basePath,
|
|
44
|
+
filename,
|
|
45
|
+
mainFile,
|
|
46
|
+
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
47
|
+
});
|
|
48
|
+
const functionFolder = join(destFolder, basename(filename, extension));
|
|
49
|
+
// Deleting the functions directory in case it exists before creating it.
|
|
50
|
+
yield deleteFiles(functionFolder, { force: true });
|
|
51
|
+
yield makeDir(functionFolder);
|
|
52
|
+
// Writing entry file.
|
|
53
|
+
yield pWriteFile(join(functionFolder, entryFilename), entryContents);
|
|
54
|
+
// Copying source files.
|
|
55
|
+
yield pMap(srcFiles, (srcFile) => {
|
|
56
|
+
const srcPath = aliases.get(srcFile) || srcFile;
|
|
57
|
+
const normalizedSrcPath = normalizeFilePath({
|
|
58
|
+
commonPrefix: basePath,
|
|
59
|
+
path: srcPath,
|
|
60
|
+
pluginsModulesPath,
|
|
61
|
+
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
62
|
+
});
|
|
63
|
+
const destPath = join(functionFolder, normalizedSrcPath);
|
|
64
|
+
return copyFile(srcFile, destPath);
|
|
65
|
+
}, { concurrency: COPY_FILE_CONCURRENCY });
|
|
66
|
+
return functionFolder;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const createZipArchive = function ({ aliases, basePath, destFolder, extension, filename, mainFile, pluginsModulesPath, srcFiles, }) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const destPath = join(destFolder, `${basename(filename, extension)}.zip`);
|
|
72
|
+
const { archive, output } = startZip(destPath);
|
|
73
|
+
const entryFilename = `${basename(filename, extension)}.js`;
|
|
74
|
+
const entryFilePath = resolve(basePath, entryFilename);
|
|
75
|
+
// We don't need an entry file if it would end up with the same path as the
|
|
76
|
+
// function's main file.
|
|
77
|
+
const needsEntryFile = entryFilePath !== mainFile;
|
|
78
|
+
// There is a naming conflict with the entry file if one of the supporting
|
|
79
|
+
// files (i.e. not the main file) has the path that the entry file needs to
|
|
80
|
+
// take.
|
|
81
|
+
const hasEntryFileConflict = srcFiles.some((srcFile) => srcFile === entryFilePath && srcFile !== mainFile);
|
|
82
|
+
// If there is a naming conflict, we move all user files (everything other
|
|
83
|
+
// than the entry file) to its own sub-directory.
|
|
84
|
+
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
|
85
|
+
if (needsEntryFile) {
|
|
86
|
+
const entryFile = getEntryFile({ commonPrefix: basePath, filename, mainFile, userNamespace });
|
|
87
|
+
addEntryFileToZip(archive, entryFile);
|
|
88
|
+
}
|
|
89
|
+
const srcFilesInfos = yield Promise.all(srcFiles.map(addStat));
|
|
90
|
+
// We ensure this is not async, so that the archive's checksum is
|
|
91
|
+
// deterministic. Otherwise it depends on the order the files were added.
|
|
92
|
+
srcFilesInfos.forEach(({ srcFile, stat }) => {
|
|
93
|
+
zipJsFile({ srcFile, commonPrefix: basePath, pluginsModulesPath, archive, stat, aliases, userNamespace });
|
|
94
|
+
});
|
|
95
|
+
yield endZip(archive, output);
|
|
96
|
+
return destPath;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const zipNodeJs = function (_a) {
|
|
100
|
+
var { archiveFormat } = _a, options = __rest(_a, ["archiveFormat"]);
|
|
101
|
+
if (archiveFormat === ARCHIVE_FORMAT_ZIP) {
|
|
102
|
+
return createZipArchive(options);
|
|
103
|
+
}
|
|
104
|
+
return createDirectory(options);
|
|
105
|
+
};
|
|
106
|
+
const addEntryFileToZip = function (archive, { contents, filename }) {
|
|
107
|
+
const contentBuffer = Buffer.from(contents);
|
|
108
|
+
addZipContent(archive, contentBuffer, filename);
|
|
109
|
+
};
|
|
110
|
+
const addStat = function (srcFile) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const stat = yield pStat(srcFile);
|
|
113
|
+
return { srcFile, stat };
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const getEntryFile = ({ commonPrefix, filename, mainFile, userNamespace }) => {
|
|
117
|
+
const mainPath = normalizeFilePath({ commonPrefix, path: mainFile, userNamespace });
|
|
118
|
+
const extension = extname(filename);
|
|
119
|
+
const entryFilename = `${basename(filename, extension)}.js`;
|
|
120
|
+
return {
|
|
121
|
+
contents: `module.exports = require('.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}')`,
|
|
122
|
+
filename: entryFilename,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const zipJsFile = function ({ srcFile, commonPrefix, pluginsModulesPath, archive, stat, aliases = new Map(), userNamespace, }) {
|
|
126
|
+
const filename = aliases.get(srcFile) || srcFile;
|
|
127
|
+
const normalizedFilename = normalizeFilePath({ commonPrefix, path: filename, pluginsModulesPath, userNamespace });
|
|
128
|
+
addZipFile(archive, srcFile, normalizedFilename, stat);
|
|
129
|
+
};
|
|
130
|
+
// `adm-zip` and `require()` expect Unix paths.
|
|
131
|
+
// We remove the common path prefix.
|
|
132
|
+
// With files on different Windows drives, we remove the drive letter.
|
|
133
|
+
const normalizeFilePath = function ({ commonPrefix, path, pluginsModulesPath, userNamespace }) {
|
|
134
|
+
const userNamespacePathSegment = userNamespace ? `${userNamespace}${sep}` : '';
|
|
135
|
+
const pathA = normalize(path);
|
|
136
|
+
const pathB = pluginsModulesPath === undefined
|
|
137
|
+
? pathA
|
|
138
|
+
: pathA.replace(pluginsModulesPath, `${userNamespacePathSegment}node_modules`);
|
|
139
|
+
const pathC = pathB.replace(commonPrefix, userNamespacePathSegment);
|
|
140
|
+
const pathD = unixify(pathC);
|
|
141
|
+
return pathD;
|
|
142
|
+
};
|
|
143
|
+
module.exports = { zipNodeJs };
|
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.5-setup-typescript-4",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./dist/main.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"zip-it-and-ship-it": "
|
|
7
|
+
"zip-it-and-ship-it": "dist/bin.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"
|
|
10
|
+
"dist/**/*.js",
|
|
11
|
+
"dist/**/*.d.ts"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
14
|
"prepublishOnly": "npm ci && npm test",
|
|
15
|
+
"prepack": "npm run build",
|
|
16
|
+
"build": "tsc",
|
|
14
17
|
"benchmark": "./benchmarks/run.sh",
|
|
15
|
-
"test": "run-s format test:dev",
|
|
16
|
-
"format": "run-s format:check-fix:*",
|
|
17
|
-
"format:ci": "run-s format:check:*",
|
|
18
|
+
"test": "run-s build format test:dev",
|
|
19
|
+
"format": "run-s build format:check-fix:*",
|
|
20
|
+
"format:ci": "run-s build format:check:*",
|
|
18
21
|
"format:check-fix:lint": "run-e format:check:lint format:fix:lint",
|
|
19
22
|
"format:check:lint": "cross-env-shell eslint $npm_package_config_eslint",
|
|
20
23
|
"format:fix:lint": "cross-env-shell eslint --fix $npm_package_config_eslint",
|
|
@@ -22,11 +25,11 @@
|
|
|
22
25
|
"format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
|
|
23
26
|
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
|
|
24
27
|
"test:dev": "ava",
|
|
25
|
-
"test:ci": "nyc -r lcovonly -r text -r json ava"
|
|
28
|
+
"test:ci": "npm run build && nyc -r lcovonly -r text -r json ava"
|
|
26
29
|
},
|
|
27
30
|
"config": {
|
|
28
|
-
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,tests,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
|
|
29
|
-
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,tests,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \".*.{js,yml,json,html}\" \"!package-lock.json\""
|
|
31
|
+
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,tests,.github}/**/*.{js,ts,md,html}\" \"*.{js,ts,md,html}\" \".*.{js,ts,md,html}\"",
|
|
32
|
+
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,tests,.github}/**/*.{js,ts,md,yml,json,html}\" \"*.{js,ts,yml,json,html}\" \".*.{js,ts,yml,json,html}\" \"!package-lock.json\""
|
|
30
33
|
},
|
|
31
34
|
"eslintIgnore": [
|
|
32
35
|
"benchmarks/fixtures/**"
|
|
@@ -84,26 +87,29 @@
|
|
|
84
87
|
"semver": "^7.0.0",
|
|
85
88
|
"tmp-promise": "^3.0.2",
|
|
86
89
|
"toml": "^3.0.0",
|
|
90
|
+
"typescript": "^4.4.3",
|
|
87
91
|
"unixify": "^1.0.0",
|
|
88
92
|
"yargs": "^16.0.0"
|
|
89
93
|
},
|
|
90
94
|
"devDependencies": {
|
|
91
|
-
"@netlify/eslint-config-node": "^3.
|
|
95
|
+
"@netlify/eslint-config-node": "^3.3.0",
|
|
92
96
|
"adm-zip": "0.5.5",
|
|
93
97
|
"ava": "^3.0.0",
|
|
94
98
|
"cpy": "^8.0.0",
|
|
99
|
+
"deepmerge": "^4.2.2",
|
|
95
100
|
"get-stream": "^6.0.0",
|
|
96
101
|
"husky": "^4.3.8",
|
|
97
102
|
"npm-run-all": "^4.1.5",
|
|
98
103
|
"nyc": "^15.0.0",
|
|
99
|
-
"sinon": "^11.1.1"
|
|
104
|
+
"sinon": "^11.1.1",
|
|
105
|
+
"typescript": "^4.4.3"
|
|
100
106
|
},
|
|
101
107
|
"engines": {
|
|
102
108
|
"node": ">=10.18.0"
|
|
103
109
|
},
|
|
104
110
|
"ava": {
|
|
105
111
|
"files": [
|
|
106
|
-
"tests
|
|
112
|
+
"tests/*"
|
|
107
113
|
],
|
|
108
114
|
"verbose": true,
|
|
109
115
|
"timeout": "2m"
|
package/src/archive.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const { createWriteStream } = require('fs')
|
|
2
|
-
const { promisify } = require('util')
|
|
3
|
-
|
|
4
|
-
const archiver = require('archiver')
|
|
5
|
-
const endOfStream = require('end-of-stream')
|
|
6
|
-
|
|
7
|
-
const pEndOfStream = promisify(endOfStream)
|
|
8
|
-
|
|
9
|
-
// Start zipping files
|
|
10
|
-
const startZip = function (destPath) {
|
|
11
|
-
const output = createWriteStream(destPath)
|
|
12
|
-
const archive = archiver('zip', { level: ZIP_LEVEL })
|
|
13
|
-
archive.pipe(output)
|
|
14
|
-
return { archive, output }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ZIP_LEVEL = 9
|
|
18
|
-
|
|
19
|
-
// Add new file to zip
|
|
20
|
-
const addZipFile = function (archive, file, name, stat) {
|
|
21
|
-
// Ensure sha256 stability regardless of mtime
|
|
22
|
-
archive.file(file, { name, mode: stat.mode, date: new Date(0), stats: stat })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Add new file content to zip
|
|
26
|
-
const addZipContent = function (archive, content, name) {
|
|
27
|
-
archive.append(content, { name, date: new Date(0) })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// End zipping files
|
|
31
|
-
const endZip = async function (archive, output) {
|
|
32
|
-
archive.finalize()
|
|
33
|
-
await pEndOfStream(output)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = { startZip, addZipFile, addZipContent, endZip }
|
package/src/bin.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { exit } = require('process')
|
|
3
|
-
|
|
4
|
-
const yargs = require('yargs')
|
|
5
|
-
|
|
6
|
-
const zipIt = require('./main')
|
|
7
|
-
const { ARCHIVE_FORMAT_NONE, ARCHIVE_FORMAT_ZIP } = require('./utils/consts')
|
|
8
|
-
|
|
9
|
-
// CLI entry point
|
|
10
|
-
const runCli = async function () {
|
|
11
|
-
const { destFolder, srcFolder, ...options } = parseArgs()
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const zipped = await zipIt.zipFunctions(srcFolder, destFolder, options)
|
|
15
|
-
console.log(JSON.stringify(zipped, null, 2))
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.error(error.toString())
|
|
18
|
-
exit(1)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const parseArgs = function () {
|
|
23
|
-
return yargs.command('* <srcFolder> <destFolder>').options(OPTIONS).usage(USAGE).strict().parse()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const OPTIONS = {
|
|
27
|
-
'archive-format': {
|
|
28
|
-
string: true,
|
|
29
|
-
choices: [ARCHIVE_FORMAT_NONE, ARCHIVE_FORMAT_ZIP],
|
|
30
|
-
default: ARCHIVE_FORMAT_ZIP,
|
|
31
|
-
describe: 'Format of the archive created for each function',
|
|
32
|
-
},
|
|
33
|
-
config: {
|
|
34
|
-
default: {},
|
|
35
|
-
describe:
|
|
36
|
-
'An object matching glob-like expressions to objects containing configuration properties. Whenever a function name matches one of the expressions, it inherits the configuration properties',
|
|
37
|
-
},
|
|
38
|
-
manifest: {
|
|
39
|
-
string: true,
|
|
40
|
-
describe: 'If a manifest file is to be created, specifies its path',
|
|
41
|
-
},
|
|
42
|
-
'parallel-limit': {
|
|
43
|
-
number: true,
|
|
44
|
-
describe: 'Maximum number of Functions to bundle at the same time',
|
|
45
|
-
},
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const USAGE = `$0 [OPTIONS...] FUNCTIONS_DIRECTORY OUTPUT_DIRECTORY
|
|
49
|
-
|
|
50
|
-
Zip all function files inside FUNCTIONS_DIRECTORY so that they can be uploaded
|
|
51
|
-
to AWS Lambda.`
|
|
52
|
-
|
|
53
|
-
runCli()
|
package/src/config.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const mergeOptions = require('merge-options')
|
|
2
|
-
const minimatch = require('minimatch')
|
|
3
|
-
|
|
4
|
-
const getConfigForFunction = ({ config, func }) => {
|
|
5
|
-
if (!config) {
|
|
6
|
-
return {}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// It's safe to mutate the array because it's local to this function.
|
|
10
|
-
const matches = Object.keys(config)
|
|
11
|
-
.filter((expression) => minimatch(func.name, expression))
|
|
12
|
-
.map((expression) => {
|
|
13
|
-
const wildcardCount = [...expression].filter((char) => char === '*').length
|
|
14
|
-
|
|
15
|
-
// The weight increases with the number of hardcoded (i.e. non-wildcard)
|
|
16
|
-
// characters — e.g. "netlify" has a higher weight than "net*". We do a
|
|
17
|
-
// subtraction of 1 if there is at least one wildcard character, so that
|
|
18
|
-
// "netlify" has a higher weight than "netlify*".
|
|
19
|
-
const weight = expression.length - wildcardCount - (wildcardCount === 0 ? 0 : 1)
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
expression,
|
|
23
|
-
weight,
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
.sort(({ weight: weightA }, { weight: weightB }) => weightA - weightB)
|
|
27
|
-
.map(({ expression }) => config[expression])
|
|
28
|
-
|
|
29
|
-
return mergeOptions.apply({ concatArrays: true, ignoreUndefined: true }, matches)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
module.exports = { getConfigForFunction }
|
package/src/feature_flags.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const { env } = require('process')
|
|
2
|
-
|
|
3
|
-
// List of supported flags and their default value.
|
|
4
|
-
const FLAGS = {
|
|
5
|
-
buildGoSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
|
|
6
|
-
buildRustSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
|
|
7
|
-
defaultEsModulesToEsbuild: Boolean(env.NETLIFY_EXPERIMENTAL_DEFAULT_ES_MODULES_TO_ESBUILD),
|
|
8
|
-
parseWithEsbuild: false,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const getFlags = (input = {}, flags = FLAGS) =>
|
|
12
|
-
Object.entries(flags).reduce(
|
|
13
|
-
(result, [key, defaultValue]) => ({
|
|
14
|
-
...result,
|
|
15
|
-
[key]: input[key] === undefined ? defaultValue : input[key],
|
|
16
|
-
}),
|
|
17
|
-
{},
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
module.exports = { FLAGS, getFlags }
|
package/src/main.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
const { extname } = require('path')
|
|
2
|
-
|
|
3
|
-
require('./utils/polyfills')
|
|
4
|
-
const { getFlags } = require('./feature_flags')
|
|
5
|
-
const { getPluginsModulesPath } = require('./node_dependencies')
|
|
6
|
-
const { getFunctionsFromPaths } = require('./runtimes')
|
|
7
|
-
const { listFunctionsDirectories, resolveFunctionsDirectories } = require('./utils/fs')
|
|
8
|
-
const { zipFunction, zipFunctions } = require('./zip')
|
|
9
|
-
|
|
10
|
-
// List all Netlify Functions main entry files for a specific directory
|
|
11
|
-
const listFunctions = async function (relativeSrcFolders, { featureFlags: inputFeatureFlags } = {}) {
|
|
12
|
-
const featureFlags = getFlags(inputFeatureFlags)
|
|
13
|
-
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders)
|
|
14
|
-
const paths = await listFunctionsDirectories(srcFolders)
|
|
15
|
-
const functions = await getFunctionsFromPaths(paths, { featureFlags })
|
|
16
|
-
const listedFunctions = [...functions.values()].map(getListedFunction)
|
|
17
|
-
return listedFunctions
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// List all Netlify Functions files for a specific directory
|
|
21
|
-
const listFunctionsFiles = async function (relativeSrcFolders, { config, featureFlags: inputFeatureFlags } = {}) {
|
|
22
|
-
const featureFlags = getFlags(inputFeatureFlags)
|
|
23
|
-
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders)
|
|
24
|
-
const paths = await listFunctionsDirectories(srcFolders)
|
|
25
|
-
const [functions, pluginsModulesPath] = await Promise.all([
|
|
26
|
-
getFunctionsFromPaths(paths, { config, featureFlags }),
|
|
27
|
-
getPluginsModulesPath(srcFolders[0]),
|
|
28
|
-
])
|
|
29
|
-
const listedFunctionsFiles = await Promise.all(
|
|
30
|
-
[...functions.values()].map((func) => getListedFunctionFiles(func, { featureFlags, pluginsModulesPath })),
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
// TODO: switch to Array.flat() once we drop support for Node.js < 11.0.0
|
|
34
|
-
// eslint-disable-next-line unicorn/prefer-spread
|
|
35
|
-
return [].concat(...listedFunctionsFiles)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const getListedFunction = function ({ runtime, name, mainFile, extension }) {
|
|
39
|
-
return { name, mainFile, runtime: runtime.name, extension }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const getListedFunctionFiles = async function (
|
|
43
|
-
{ config, runtime, name, stat, mainFile, extension, srcPath, srcDir },
|
|
44
|
-
{ featureFlags, pluginsModulesPath },
|
|
45
|
-
) {
|
|
46
|
-
const srcFiles = await getSrcFiles({
|
|
47
|
-
featureFlags,
|
|
48
|
-
runtime,
|
|
49
|
-
stat,
|
|
50
|
-
mainFile,
|
|
51
|
-
extension,
|
|
52
|
-
srcPath,
|
|
53
|
-
srcDir,
|
|
54
|
-
pluginsModulesPath,
|
|
55
|
-
config,
|
|
56
|
-
})
|
|
57
|
-
return srcFiles.map((srcFile) => ({ srcFile, name, mainFile, runtime: runtime.name, extension: extname(srcFile) }))
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const getSrcFiles = function ({
|
|
61
|
-
bundler,
|
|
62
|
-
config,
|
|
63
|
-
featureFlags,
|
|
64
|
-
runtime,
|
|
65
|
-
stat,
|
|
66
|
-
mainFile,
|
|
67
|
-
extension,
|
|
68
|
-
srcPath,
|
|
69
|
-
srcDir,
|
|
70
|
-
pluginsModulesPath,
|
|
71
|
-
}) {
|
|
72
|
-
const { getSrcFiles: getRuntimeSrcFiles } = runtime
|
|
73
|
-
|
|
74
|
-
if (extension === '.zip' || typeof getRuntimeSrcFiles !== 'function') {
|
|
75
|
-
return [srcPath]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return getRuntimeSrcFiles({
|
|
79
|
-
bundler,
|
|
80
|
-
config,
|
|
81
|
-
extension,
|
|
82
|
-
featureFlags,
|
|
83
|
-
srcPath,
|
|
84
|
-
mainFile,
|
|
85
|
-
srcDir,
|
|
86
|
-
stat,
|
|
87
|
-
pluginsModulesPath,
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = { zipFunctions, zipFunction, listFunctions, listFunctionsFiles }
|
package/src/manifest.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const { resolve } = require('path')
|
|
2
|
-
const { arch, platform } = require('process')
|
|
3
|
-
|
|
4
|
-
const { writeFile } = require('./utils/fs')
|
|
5
|
-
|
|
6
|
-
const MANIFEST_VERSION = 1
|
|
7
|
-
|
|
8
|
-
const createManifest = async ({ functions, path }) => {
|
|
9
|
-
const formattedFunctions = functions.map(formatFunction)
|
|
10
|
-
const payload = {
|
|
11
|
-
functions: formattedFunctions,
|
|
12
|
-
system: { arch, platform },
|
|
13
|
-
timestamp: Date.now(),
|
|
14
|
-
version: MANIFEST_VERSION,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
await writeFile(path, JSON.stringify(payload))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const formatFunction = ({ mainFile, name, path, runtime }) => ({ mainFile, name, path: resolve(path), runtime })
|
|
21
|
-
|
|
22
|
-
module.exports = { createManifest }
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
const { dirname, basename, normalize } = require('path')
|
|
2
|
-
|
|
3
|
-
const findUp = require('find-up')
|
|
4
|
-
const { not: notJunk } = require('junk')
|
|
5
|
-
const precinct = require('precinct')
|
|
6
|
-
|
|
7
|
-
const { listImports } = require('../runtimes/node/list_imports')
|
|
8
|
-
|
|
9
|
-
const { getPackageJson } = require('./package_json')
|
|
10
|
-
const { resolvePathPreserveSymlinks } = require('./resolve')
|
|
11
|
-
const { getExternalAndIgnoredModulesFromSpecialCases } = require('./special_cases')
|
|
12
|
-
const {
|
|
13
|
-
getDependencyPathsForDependency,
|
|
14
|
-
getDependencyNamesAndPathsForDependencies,
|
|
15
|
-
getDependencyNamesAndPathsForDependency,
|
|
16
|
-
getNewCache,
|
|
17
|
-
} = require('./traverse')
|
|
18
|
-
const { getTreeFiles } = require('./tree_files')
|
|
19
|
-
const { shouldTreeShake } = require('./tree_shake')
|
|
20
|
-
|
|
21
|
-
const AUTO_PLUGINS_DIR = '.netlify/plugins/'
|
|
22
|
-
|
|
23
|
-
const getPluginsModulesPath = (srcDir) => findUp(`${AUTO_PLUGINS_DIR}node_modules`, { cwd: srcDir, type: 'directory' })
|
|
24
|
-
|
|
25
|
-
// Retrieve the paths to the Node.js files to zip.
|
|
26
|
-
// We only include the files actually needed by the function because AWS Lambda
|
|
27
|
-
// has a size limit for the zipped file. It also makes cold starts faster.
|
|
28
|
-
const listFilesUsingLegacyBundler = async function ({
|
|
29
|
-
featureFlags,
|
|
30
|
-
srcPath,
|
|
31
|
-
mainFile,
|
|
32
|
-
srcDir,
|
|
33
|
-
stat,
|
|
34
|
-
pluginsModulesPath,
|
|
35
|
-
}) {
|
|
36
|
-
const [treeFiles, depFiles] = await Promise.all([
|
|
37
|
-
getTreeFiles(srcPath, stat),
|
|
38
|
-
getDependencies(mainFile, srcDir, pluginsModulesPath, featureFlags),
|
|
39
|
-
])
|
|
40
|
-
const files = [...treeFiles, ...depFiles].map(normalize)
|
|
41
|
-
const uniqueFiles = [...new Set(files)]
|
|
42
|
-
|
|
43
|
-
// We sort so that the archive's checksum is deterministic.
|
|
44
|
-
// Mutating is fine since `Array.filter()` returns a shallow copy
|
|
45
|
-
const filteredFiles = uniqueFiles.filter(isNotJunk).sort()
|
|
46
|
-
return filteredFiles
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Remove temporary files like *~, *.swp, etc.
|
|
50
|
-
const isNotJunk = function (file) {
|
|
51
|
-
return notJunk(basename(file))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Retrieve all the files recursively required by a Node.js file
|
|
55
|
-
const getDependencies = async function (mainFile, srcDir, pluginsModulesPath, featureFlags) {
|
|
56
|
-
const packageJson = await getPackageJson(srcDir)
|
|
57
|
-
const state = getNewCache()
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
return await getFileDependencies({ featureFlags, path: mainFile, packageJson, pluginsModulesPath, state })
|
|
61
|
-
} catch (error) {
|
|
62
|
-
error.message = `In file "${mainFile}"\n${error.message}`
|
|
63
|
-
throw error
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const getFileDependencies = async function ({
|
|
68
|
-
featureFlags,
|
|
69
|
-
path,
|
|
70
|
-
packageJson,
|
|
71
|
-
pluginsModulesPath,
|
|
72
|
-
state,
|
|
73
|
-
treeShakeNext,
|
|
74
|
-
}) {
|
|
75
|
-
if (state.localFiles.has(path)) {
|
|
76
|
-
return []
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
state.localFiles.add(path)
|
|
80
|
-
|
|
81
|
-
const basedir = dirname(path)
|
|
82
|
-
const dependencies = featureFlags.parseWithEsbuild
|
|
83
|
-
? await listImports({ path })
|
|
84
|
-
: precinct.paperwork(path, { includeCore: false })
|
|
85
|
-
const depsPaths = await Promise.all(
|
|
86
|
-
dependencies.filter(Boolean).map((dependency) =>
|
|
87
|
-
getImportDependencies({
|
|
88
|
-
dependency,
|
|
89
|
-
basedir,
|
|
90
|
-
featureFlags,
|
|
91
|
-
packageJson,
|
|
92
|
-
pluginsModulesPath,
|
|
93
|
-
state,
|
|
94
|
-
treeShakeNext,
|
|
95
|
-
}),
|
|
96
|
-
),
|
|
97
|
-
)
|
|
98
|
-
// TODO: switch to Array.flat() once we drop support for Node.js < 11.0.0
|
|
99
|
-
// eslint-disable-next-line unicorn/prefer-spread
|
|
100
|
-
return [].concat(...depsPaths)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const getImportDependencies = function ({
|
|
104
|
-
dependency,
|
|
105
|
-
basedir,
|
|
106
|
-
featureFlags,
|
|
107
|
-
packageJson,
|
|
108
|
-
pluginsModulesPath,
|
|
109
|
-
state,
|
|
110
|
-
treeShakeNext,
|
|
111
|
-
}) {
|
|
112
|
-
const shouldTreeShakeNext = treeShakeNext || isNextOnNetlify(dependency)
|
|
113
|
-
if (shouldTreeShake(dependency, shouldTreeShakeNext)) {
|
|
114
|
-
return getTreeShakedDependencies({
|
|
115
|
-
dependency,
|
|
116
|
-
basedir,
|
|
117
|
-
featureFlags,
|
|
118
|
-
packageJson,
|
|
119
|
-
pluginsModulesPath,
|
|
120
|
-
state,
|
|
121
|
-
treeShakeNext: shouldTreeShakeNext,
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return getDependencyPathsForDependency({ dependency, basedir, state, packageJson, pluginsModulesPath })
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const isNextOnNetlify = function (dependency) {
|
|
129
|
-
return basename(dependency, '.js') === 'renderNextPage'
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// When a file requires another one, we apply the top-level logic recursively
|
|
133
|
-
const getTreeShakedDependencies = async function ({
|
|
134
|
-
dependency,
|
|
135
|
-
basedir,
|
|
136
|
-
featureFlags,
|
|
137
|
-
packageJson,
|
|
138
|
-
pluginsModulesPath,
|
|
139
|
-
state,
|
|
140
|
-
treeShakeNext,
|
|
141
|
-
}) {
|
|
142
|
-
const path = await resolvePathPreserveSymlinks(dependency, [basedir, pluginsModulesPath].filter(Boolean))
|
|
143
|
-
const depsPath = await getFileDependencies({
|
|
144
|
-
featureFlags,
|
|
145
|
-
path,
|
|
146
|
-
packageJson,
|
|
147
|
-
pluginsModulesPath,
|
|
148
|
-
state,
|
|
149
|
-
treeShakeNext,
|
|
150
|
-
})
|
|
151
|
-
return [path, ...depsPath]
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
module.exports = {
|
|
155
|
-
getDependencyPathsForDependency,
|
|
156
|
-
getDependencyNamesAndPathsForDependencies,
|
|
157
|
-
getDependencyNamesAndPathsForDependency,
|
|
158
|
-
getExternalAndIgnoredModulesFromSpecialCases,
|
|
159
|
-
getPluginsModulesPath,
|
|
160
|
-
listFilesUsingLegacyBundler,
|
|
161
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const requirePackageName = require('require-package-name')
|
|
2
|
-
|
|
3
|
-
// Windows path normalization
|
|
4
|
-
const BACKSLASH_REGEXP = /\\/g
|
|
5
|
-
|
|
6
|
-
// When doing require("moduleName/file/path"), only keep `moduleName`
|
|
7
|
-
const getModuleName = function (dependency) {
|
|
8
|
-
const dependencyA = dependency.replace(BACKSLASH_REGEXP, '/')
|
|
9
|
-
const moduleName = requirePackageName(dependencyA)
|
|
10
|
-
return moduleName
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = { getModuleName }
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const pkgDir = require('pkg-dir')
|
|
2
|
-
|
|
3
|
-
// Retrieve the `package.json` of a specific project or module
|
|
4
|
-
const getPackageJson = async function (srcDir) {
|
|
5
|
-
const packageRoot = await pkgDir(srcDir)
|
|
6
|
-
|
|
7
|
-
if (packageRoot === undefined) {
|
|
8
|
-
return {}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const packageJsonPath = `${packageRoot}/package.json`
|
|
12
|
-
try {
|
|
13
|
-
// The path depends on the user's build, i.e. must be dynamic
|
|
14
|
-
// eslint-disable-next-line import/no-dynamic-require, node/global-require
|
|
15
|
-
return require(packageJsonPath)
|
|
16
|
-
} catch (error) {
|
|
17
|
-
throw new Error(`${packageJsonPath} is invalid JSON: ${error.message}`)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = { getPackageJson }
|