@netlify/zip-it-and-ship-it 4.28.2 → 4.29.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/dist/archive.d.ts +2 -1
- package/dist/feature_flags.js +1 -0
- package/dist/main.d.ts +2 -3
- package/dist/main.js +6 -10
- package/dist/runtimes/node/bundlers/esbuild/index.d.ts +1 -1
- package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +1 -1
- package/dist/runtimes/node/bundlers/index.d.ts +8 -2
- package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +9 -2
- package/dist/runtimes/node/bundlers/nft/es_modules.js +48 -16
- package/dist/runtimes/node/bundlers/nft/index.js +6 -7
- package/dist/runtimes/node/bundlers/nft/transpile.d.ts +2 -2
- package/dist/runtimes/node/bundlers/nft/transpile.js +2 -10
- package/dist/runtimes/node/bundlers/zisi/index.d.ts +1 -1
- package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +1 -1
- package/dist/runtimes/node/index.js +7 -4
- package/dist/runtimes/node/utils/package_json.d.ts +2 -1
- package/dist/runtimes/node/utils/package_json.js +12 -3
- package/dist/runtimes/node/utils/plugin_modules_path.d.ts +2 -1
- package/dist/runtimes/node/utils/plugin_modules_path.js +12 -1
- package/dist/runtimes/node/utils/zip.d.ts +0 -1
- package/dist/runtimes/node/utils/zip.js +8 -13
- package/dist/runtimes/runtime.d.ts +0 -2
- package/dist/zip.d.ts +1 -2
- package/dist/zip.js +2 -12
- package/package.json +4 -4
package/dist/archive.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ declare const addZipFile: (archive: Archiver, file: string, name: string, stat:
|
|
|
11
11
|
declare const addZipContent: (archive: Archiver, content: Buffer | string, name: string) => void;
|
|
12
12
|
declare const endZip: (archive: Archiver, output: Writable) => Promise<void>;
|
|
13
13
|
export { startZip, addZipFile, addZipContent, endZip };
|
|
14
|
-
export type { ArchiveFormat
|
|
14
|
+
export type { ArchiveFormat };
|
|
15
|
+
export { Archiver as ZipArchive } from 'archiver';
|
package/dist/feature_flags.js
CHANGED
|
@@ -6,6 +6,7 @@ const FLAGS = {
|
|
|
6
6
|
buildGoSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
|
|
7
7
|
buildRustSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
|
|
8
8
|
defaultEsModulesToEsbuild: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_DEFAULT_ES_MODULES_TO_ESBUILD),
|
|
9
|
+
nftTranspile: false,
|
|
9
10
|
parseWithEsbuild: false,
|
|
10
11
|
traceWithNft: false,
|
|
11
12
|
};
|
package/dist/main.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import './utils/polyfills';
|
|
|
2
2
|
import { Config } from './config';
|
|
3
3
|
import { FeatureFlags } from './feature_flags';
|
|
4
4
|
import { RuntimeName } from './runtimes/runtime';
|
|
5
|
-
import { zipFunction, zipFunctions } from './zip';
|
|
6
5
|
interface ListedFunction {
|
|
7
6
|
name: string;
|
|
8
7
|
mainFile: string;
|
|
@@ -16,10 +15,10 @@ interface ListFunctionsOptions {
|
|
|
16
15
|
basePath?: string;
|
|
17
16
|
config?: Config;
|
|
18
17
|
featureFlags?: FeatureFlags;
|
|
19
|
-
pluginsModulesPath?: string;
|
|
20
18
|
}
|
|
21
19
|
declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags }?: {
|
|
22
20
|
featureFlags?: FeatureFlags;
|
|
23
21
|
}) => Promise<ListedFunction[]>;
|
|
24
22
|
declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
|
|
25
|
-
export {
|
|
23
|
+
export { listFunctions, listFunctionsFiles };
|
|
24
|
+
export { zipFunction, zipFunctions } from './zip';
|
package/dist/main.js
CHANGED
|
@@ -20,16 +20,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunctions = void 0;
|
|
24
24
|
const path_1 = require("path");
|
|
25
25
|
require("./utils/polyfills");
|
|
26
26
|
const feature_flags_1 = require("./feature_flags");
|
|
27
27
|
const runtimes_1 = require("./runtimes");
|
|
28
|
-
const plugin_modules_path_1 = require("./runtimes/node/utils/plugin_modules_path");
|
|
29
28
|
const fs_1 = require("./utils/fs");
|
|
30
|
-
const zip_1 = require("./zip");
|
|
31
|
-
Object.defineProperty(exports, "zipFunction", { enumerable: true, get: function () { return zip_1.zipFunction; } });
|
|
32
|
-
Object.defineProperty(exports, "zipFunctions", { enumerable: true, get: function () { return zip_1.zipFunctions; } });
|
|
33
29
|
// List all Netlify Functions main entry files for a specific directory
|
|
34
30
|
const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags } = {}) {
|
|
35
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -48,11 +44,8 @@ const listFunctionsFiles = function (relativeSrcFolders, { basePath, config, fea
|
|
|
48
44
|
const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
|
|
49
45
|
const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
|
|
50
46
|
const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
(0, plugin_modules_path_1.getPluginsModulesPath)(srcFolders[0]),
|
|
54
|
-
]);
|
|
55
|
-
const listedFunctionsFiles = yield Promise.all([...functions.values()].map((func) => getListedFunctionFiles(func, { basePath, featureFlags, pluginsModulesPath })));
|
|
47
|
+
const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { config, featureFlags });
|
|
48
|
+
const listedFunctionsFiles = yield Promise.all([...functions.values()].map((func) => getListedFunctionFiles(func, { basePath, featureFlags })));
|
|
56
49
|
return listedFunctionsFiles.flat();
|
|
57
50
|
});
|
|
58
51
|
};
|
|
@@ -79,4 +72,7 @@ const getSrcFiles = function (_a) {
|
|
|
79
72
|
srcPath }, args));
|
|
80
73
|
});
|
|
81
74
|
};
|
|
75
|
+
var zip_1 = require("./zip");
|
|
76
|
+
Object.defineProperty(exports, "zipFunction", { enumerable: true, get: function () { return zip_1.zipFunction; } });
|
|
77
|
+
Object.defineProperty(exports, "zipFunctions", { enumerable: true, get: function () { return zip_1.zipFunctions; } });
|
|
82
78
|
//# sourceMappingURL=main.js.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Message } from '@netlify/esbuild';
|
|
2
2
|
import type { NodeBundlerName } from '..';
|
|
3
3
|
import { FunctionConfig } from '../../../config';
|
|
4
|
-
import { FeatureFlag } from '../../../feature_flags';
|
|
4
|
+
import { FeatureFlag, FeatureFlags } from '../../../feature_flags';
|
|
5
5
|
import { FunctionSource } from '../../../function';
|
|
6
|
-
import { GetSrcFilesFunction } from '../../runtime';
|
|
7
6
|
declare type BundlerWarning = Message;
|
|
8
7
|
declare type CleanupFunction = () => Promise<void>;
|
|
9
8
|
declare type NativeNodeModules = Record<string, Record<string, string | undefined>>;
|
|
@@ -25,6 +24,13 @@ declare type BundleFunction = (args: {
|
|
|
25
24
|
nodeModulesWithDynamicImports?: string[];
|
|
26
25
|
srcFiles: string[];
|
|
27
26
|
}>;
|
|
27
|
+
declare type GetSrcFilesFunction = (args: {
|
|
28
|
+
basePath?: string;
|
|
29
|
+
config: FunctionConfig;
|
|
30
|
+
featureFlags: FeatureFlags;
|
|
31
|
+
pluginsModulesPath?: string;
|
|
32
|
+
repositoryRoot?: string;
|
|
33
|
+
} & FunctionSource) => Promise<string[]>;
|
|
28
34
|
interface NodeBundler {
|
|
29
35
|
bundle: BundleFunction;
|
|
30
36
|
getSrcFiles: GetSrcFilesFunction;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { NodeFileTraceReasons } from '@vercel/nft';
|
|
2
|
+
import type { FunctionConfig } from '../../../../config';
|
|
2
3
|
import { FsCache } from '../../../../utils/fs';
|
|
3
|
-
declare const
|
|
4
|
-
|
|
4
|
+
declare const transpileESM: ({ basePath, config, esmPaths, fsCache, reasons, }: {
|
|
5
|
+
basePath: string | undefined;
|
|
6
|
+
config: FunctionConfig;
|
|
7
|
+
esmPaths: Set<string>;
|
|
8
|
+
fsCache: FsCache;
|
|
9
|
+
reasons: NodeFileTraceReasons;
|
|
10
|
+
}) => Promise<Map<string, string>>;
|
|
11
|
+
export { transpileESM };
|
|
@@ -9,23 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.transpileESM = void 0;
|
|
13
13
|
const path_1 = require("path");
|
|
14
14
|
const fs_1 = require("../../../../utils/fs");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
.filter(([, reason]) => {
|
|
18
|
-
if (reason.type !== 'resolve') {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
const hasESMParent = [...reason.parents].some((parentPath) => esmPaths.has(parentPath));
|
|
22
|
-
return hasESMParent;
|
|
23
|
-
})
|
|
24
|
-
.map(([path]) => (basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path)));
|
|
25
|
-
return packageJsons;
|
|
26
|
-
};
|
|
27
|
-
const getPatchedESMPackages = (esmPaths, reasons, fsCache, basePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
const packages = getESMPackageJsons(esmPaths, reasons, basePath);
|
|
15
|
+
const transpile_1 = require("./transpile");
|
|
16
|
+
const getPatchedESMPackages = (packages, fsCache) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
17
|
const patchedPackages = yield Promise.all(packages.map((path) => patchESMPackage(path, fsCache)));
|
|
30
18
|
const patchedPackagesMap = new Map();
|
|
31
19
|
packages.forEach((packagePath, index) => {
|
|
@@ -33,11 +21,55 @@ const getPatchedESMPackages = (esmPaths, reasons, fsCache, basePath) => __awaite
|
|
|
33
21
|
});
|
|
34
22
|
return patchedPackagesMap;
|
|
35
23
|
});
|
|
36
|
-
exports.getPatchedESMPackages = getPatchedESMPackages;
|
|
37
24
|
const patchESMPackage = (path, fsCache) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
25
|
const file = (yield (0, fs_1.cachedReadFile)(fsCache, path, 'utf8'));
|
|
39
26
|
const packageJson = JSON.parse(file);
|
|
40
27
|
const patchedPackageJson = Object.assign(Object.assign({}, packageJson), { type: 'commonjs' });
|
|
41
28
|
return JSON.stringify(patchedPackageJson);
|
|
42
29
|
});
|
|
30
|
+
const shouldTranspile = (path, cache, reasons) => {
|
|
31
|
+
if (cache.has(path)) {
|
|
32
|
+
return cache.get(path);
|
|
33
|
+
}
|
|
34
|
+
const reason = reasons.get(path);
|
|
35
|
+
// This isn't an expected case, but if the path doesn't exist in `reasons` we
|
|
36
|
+
// don't transpile it.
|
|
37
|
+
if (reason === undefined) {
|
|
38
|
+
cache.set(path, false);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const { parents } = reason;
|
|
42
|
+
// If the path doesn't have any parents, it's safe to transpile.
|
|
43
|
+
if (parents.size === 0) {
|
|
44
|
+
cache.set(path, true);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// The path should be transpiled if every parent will also be transpiled, or
|
|
48
|
+
// if there is no parent.
|
|
49
|
+
const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, reasons));
|
|
50
|
+
cache.set(path, shouldTranspilePath);
|
|
51
|
+
return shouldTranspilePath;
|
|
52
|
+
};
|
|
53
|
+
const transpileESM = ({ basePath, config, esmPaths, fsCache, reasons, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const cache = new Map();
|
|
55
|
+
const paths = [...esmPaths].filter((path) => shouldTranspile(path, cache, reasons));
|
|
56
|
+
const pathsSet = new Set(paths);
|
|
57
|
+
const packageJsonPaths = [...reasons.entries()]
|
|
58
|
+
.filter(([path, reason]) => {
|
|
59
|
+
if ((0, path_1.basename)(path) !== 'package.json') {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const needsPatch = [...reason.parents].some((parentPath) => pathsSet.has(parentPath));
|
|
63
|
+
return needsPatch;
|
|
64
|
+
})
|
|
65
|
+
.map(([path]) => (basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path)));
|
|
66
|
+
const rewrites = yield getPatchedESMPackages(packageJsonPaths, fsCache);
|
|
67
|
+
yield Promise.all(paths.map((path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const absolutePath = basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path);
|
|
69
|
+
const transpiled = yield (0, transpile_1.transpile)(absolutePath, config);
|
|
70
|
+
rewrites.set(absolutePath, transpiled);
|
|
71
|
+
})));
|
|
72
|
+
return rewrites;
|
|
73
|
+
});
|
|
74
|
+
exports.transpileESM = transpileESM;
|
|
43
75
|
//# sourceMappingURL=es_modules.js.map
|
|
@@ -21,11 +21,10 @@ const fs_1 = require("../../../../utils/fs");
|
|
|
21
21
|
const base_path_1 = require("../../utils/base_path");
|
|
22
22
|
const included_files_1 = require("../../utils/included_files");
|
|
23
23
|
const es_modules_1 = require("./es_modules");
|
|
24
|
-
const transpile_1 = require("./transpile");
|
|
25
24
|
// Paths that will be excluded from the tracing process.
|
|
26
25
|
const ignore = ['node_modules/aws-sdk/**'];
|
|
27
26
|
const appearsToBeModuleName = (name) => !name.startsWith('.');
|
|
28
|
-
const bundle = ({ basePath, config, mainFile, pluginsModulesPath, repositoryRoot = basePath, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const bundle = ({ basePath, config, featureFlags, mainFile, pluginsModulesPath, repositoryRoot = basePath, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
28
|
const { includedFiles = [], includedFilesBasePath } = config;
|
|
30
29
|
const { exclude: excludedPaths, paths: includedFilePaths } = yield (0, included_files_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath || basePath);
|
|
31
30
|
const { paths: dependencyPaths, rewrites } = yield traceFilesAndTranspile({
|
|
@@ -33,6 +32,7 @@ const bundle = ({ basePath, config, mainFile, pluginsModulesPath, repositoryRoot
|
|
|
33
32
|
config,
|
|
34
33
|
mainFile,
|
|
35
34
|
pluginsModulesPath,
|
|
35
|
+
transpile: featureFlags.nftTranspile,
|
|
36
36
|
});
|
|
37
37
|
const filteredIncludedPaths = (0, included_files_1.filterExcludedPaths)([...dependencyPaths, ...includedFilePaths], excludedPaths);
|
|
38
38
|
const dirnames = filteredIncludedPaths.map((filePath) => (0, path_1.normalize)((0, path_1.dirname)(filePath))).sort();
|
|
@@ -51,7 +51,7 @@ const ignoreFunction = (path) => {
|
|
|
51
51
|
const shouldIgnore = ignore.some((expression) => (0, minimatch_1.default)(normalizedPath, expression));
|
|
52
52
|
return shouldIgnore;
|
|
53
53
|
};
|
|
54
|
-
const traceFilesAndTranspile = function ({ basePath, config, mainFile, pluginsModulesPath, }) {
|
|
54
|
+
const traceFilesAndTranspile = function ({ basePath, config, mainFile, pluginsModulesPath, transpile, }) {
|
|
55
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
56
|
const fsCache = {};
|
|
57
57
|
const { fileList: dependencyPaths, esmFileList, reasons, } = yield (0, nft_1.nodeFileTrace)([mainFile], {
|
|
@@ -86,10 +86,9 @@ const traceFilesAndTranspile = function ({ basePath, config, mainFile, pluginsMo
|
|
|
86
86
|
}),
|
|
87
87
|
});
|
|
88
88
|
const normalizedDependencyPaths = [...dependencyPaths].map((path) => basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path));
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const rewrites = new Map([...transpiledPaths, ...patchedESMPackages]);
|
|
89
|
+
const rewrites = transpile
|
|
90
|
+
? yield (0, es_modules_1.transpileESM)({ basePath, config, esmPaths: esmFileList, fsCache, reasons })
|
|
91
|
+
: undefined;
|
|
93
92
|
return {
|
|
94
93
|
paths: normalizedDependencyPaths,
|
|
95
94
|
rewrites,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { FunctionConfig } from '../../../../config';
|
|
2
|
-
declare const
|
|
3
|
-
export {
|
|
2
|
+
declare const transpile: (path: string, config: FunctionConfig) => Promise<string>;
|
|
3
|
+
export { transpile };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.transpile = void 0;
|
|
13
13
|
const esbuild_1 = require("@netlify/esbuild");
|
|
14
14
|
const bundler_target_1 = require("../esbuild/bundler_target");
|
|
15
15
|
const transpile = (path, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -27,13 +27,5 @@ const transpile = (path, config) => __awaiter(void 0, void 0, void 0, function*
|
|
|
27
27
|
});
|
|
28
28
|
return transpiled.outputFiles[0].text;
|
|
29
29
|
});
|
|
30
|
-
|
|
31
|
-
const transpiledPaths = new Map();
|
|
32
|
-
yield Promise.all(paths.map((path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
const transpiled = yield transpile(path, config);
|
|
34
|
-
transpiledPaths.set(path, transpiled);
|
|
35
|
-
})));
|
|
36
|
-
return transpiledPaths;
|
|
37
|
-
});
|
|
38
|
-
exports.transpileMany = transpileMany;
|
|
30
|
+
exports.transpile = transpile;
|
|
39
31
|
//# sourceMappingURL=transpile.js.map
|
|
@@ -28,6 +28,7 @@ const cp_file_1 = __importDefault(require("cp-file"));
|
|
|
28
28
|
const bundlers_1 = require("./bundlers");
|
|
29
29
|
const finder_1 = require("./finder");
|
|
30
30
|
const detect_es_module_1 = require("./utils/detect_es_module");
|
|
31
|
+
const plugin_modules_path_1 = require("./utils/plugin_modules_path");
|
|
31
32
|
const zip_1 = require("./utils/zip");
|
|
32
33
|
// We use ZISI as the default bundler, except for certain extensions, for which
|
|
33
34
|
// esbuild is the only option.
|
|
@@ -50,6 +51,7 @@ const getDefaultBundler = ({ extension, mainFile, featureFlags, }) => __awaiter(
|
|
|
50
51
|
// A proxy for the `getSrcFiles` function which adds a default `bundler` using
|
|
51
52
|
// the `getDefaultBundler` function.
|
|
52
53
|
const getSrcFilesWithBundler = (parameters) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const pluginsModulesPath = yield (0, plugin_modules_path_1.getPluginsModulesPath)(parameters.srcDir);
|
|
53
55
|
const bundlerName = parameters.config.nodeBundler ||
|
|
54
56
|
(yield getDefaultBundler({
|
|
55
57
|
extension: parameters.extension,
|
|
@@ -57,10 +59,11 @@ const getSrcFilesWithBundler = (parameters) => __awaiter(void 0, void 0, void 0,
|
|
|
57
59
|
mainFile: parameters.mainFile,
|
|
58
60
|
}));
|
|
59
61
|
const bundler = (0, bundlers_1.getBundler)(bundlerName);
|
|
60
|
-
return bundler.getSrcFiles(Object.assign({}, parameters));
|
|
62
|
+
return bundler.getSrcFiles(Object.assign(Object.assign({}, parameters), { pluginsModulesPath }));
|
|
61
63
|
});
|
|
62
|
-
const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name,
|
|
64
|
+
const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
|
|
63
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const pluginsModulesPath = yield (0, plugin_modules_path_1.getPluginsModulesPath)(srcDir);
|
|
64
67
|
const bundlerName = config.nodeBundler || (yield getDefaultBundler({ extension, mainFile, featureFlags }));
|
|
65
68
|
const bundler = (0, bundlers_1.getBundler)(bundlerName);
|
|
66
69
|
// If the file is a zip, we assume the function is bundled and ready to go.
|
|
@@ -70,7 +73,7 @@ const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder
|
|
|
70
73
|
yield (0, cp_file_1.default)(srcPath, destPath);
|
|
71
74
|
return { config, path: destPath };
|
|
72
75
|
}
|
|
73
|
-
const { aliases, cleanupFunction, basePath: finalBasePath, bundlerWarnings, inputs, mainFile: finalMainFile = mainFile, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = yield bundler.bundle({
|
|
76
|
+
const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, inputs, mainFile: finalMainFile = mainFile, nativeNodeModules, nodeModulesWithDynamicImports, rewrites, srcFiles, } = yield bundler.bundle({
|
|
74
77
|
basePath,
|
|
75
78
|
config,
|
|
76
79
|
extension,
|
|
@@ -85,6 +88,7 @@ const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder
|
|
|
85
88
|
srcPath,
|
|
86
89
|
stat,
|
|
87
90
|
});
|
|
91
|
+
(0, plugin_modules_path_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
|
|
88
92
|
const zipPath = yield (0, zip_1.zipNodeJs)({
|
|
89
93
|
aliases,
|
|
90
94
|
archiveFormat,
|
|
@@ -93,7 +97,6 @@ const zipFunction = function ({ archiveFormat, basePath, config = {}, destFolder
|
|
|
93
97
|
extension,
|
|
94
98
|
filename,
|
|
95
99
|
mainFile: finalMainFile,
|
|
96
|
-
pluginsModulesPath,
|
|
97
100
|
rewrites,
|
|
98
101
|
srcFiles,
|
|
99
102
|
});
|
|
@@ -13,5 +13,6 @@ interface PackageJson {
|
|
|
13
13
|
binary?: boolean;
|
|
14
14
|
type?: string;
|
|
15
15
|
}
|
|
16
|
+
declare const sanitisePackageJson: (packageJson: Record<string, unknown>) => PackageJson;
|
|
16
17
|
declare const getPackageJson: (srcDir: string) => Promise<PackageJson>;
|
|
17
|
-
export { getPackageJson, PackageJson };
|
|
18
|
+
export { getPackageJson, PackageJson, sanitisePackageJson };
|
|
@@ -12,8 +12,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getPackageJson = void 0;
|
|
15
|
+
exports.sanitisePackageJson = exports.getPackageJson = void 0;
|
|
16
16
|
const pkg_dir_1 = __importDefault(require("pkg-dir"));
|
|
17
|
+
const sanitiseFiles = (files) => {
|
|
18
|
+
if (!Array.isArray(files)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return files.filter((file) => typeof file === 'string');
|
|
22
|
+
};
|
|
23
|
+
const sanitisePackageJson = (packageJson) => (Object.assign(Object.assign({}, packageJson), { files: sanitiseFiles(packageJson.files) }));
|
|
24
|
+
exports.sanitisePackageJson = sanitisePackageJson;
|
|
17
25
|
// Retrieve the `package.json` of a specific project or module
|
|
18
26
|
const getPackageJson = function (srcDir) {
|
|
19
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -24,8 +32,9 @@ const getPackageJson = function (srcDir) {
|
|
|
24
32
|
const packageJsonPath = `${packageRoot}/package.json`;
|
|
25
33
|
try {
|
|
26
34
|
// The path depends on the user's build, i.e. must be dynamic
|
|
27
|
-
// eslint-disable-next-line import/no-dynamic-require, node/global-require
|
|
28
|
-
|
|
35
|
+
// eslint-disable-next-line import/no-dynamic-require, node/global-require, @typescript-eslint/no-var-requires
|
|
36
|
+
const packageJson = require(packageJsonPath);
|
|
37
|
+
return sanitisePackageJson(packageJson);
|
|
29
38
|
}
|
|
30
39
|
catch (error) {
|
|
31
40
|
throw new Error(`${packageJsonPath} is invalid JSON: ${error.message}`);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
declare const createAliases: (paths: string[], pluginsModulesPath: string | undefined, aliases: Map<string, string>, basePath: string) => void;
|
|
1
2
|
declare const getPluginsModulesPath: (srcDir: string) => Promise<string | undefined>;
|
|
2
|
-
export { getPluginsModulesPath };
|
|
3
|
+
export { createAliases, getPluginsModulesPath };
|
|
@@ -3,9 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPluginsModulesPath = void 0;
|
|
6
|
+
exports.getPluginsModulesPath = exports.createAliases = void 0;
|
|
7
|
+
const path_1 = require("path");
|
|
7
8
|
const find_up_1 = __importDefault(require("find-up"));
|
|
8
9
|
const AUTO_PLUGINS_DIR = '.netlify/plugins/';
|
|
10
|
+
const createAliases = (paths, pluginsModulesPath, aliases, basePath) => {
|
|
11
|
+
paths.forEach((path) => {
|
|
12
|
+
if (pluginsModulesPath === undefined || !path.startsWith(pluginsModulesPath)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const relativePath = (0, path_1.relative)(pluginsModulesPath, path);
|
|
16
|
+
aliases.set(path, (0, path_1.join)(basePath, 'node_modules', relativePath));
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
exports.createAliases = createAliases;
|
|
9
20
|
const getPluginsModulesPath = (srcDir) => (0, find_up_1.default)(`${AUTO_PLUGINS_DIR}node_modules`, { cwd: srcDir, type: 'directory' });
|
|
10
21
|
exports.getPluginsModulesPath = getPluginsModulesPath;
|
|
11
22
|
//# sourceMappingURL=plugin_modules_path.js.map
|
|
@@ -43,7 +43,7 @@ const COPY_FILE_CONCURRENCY = os_1.default.cpus().length === 0 ? 2 : os_1.defaul
|
|
|
43
43
|
// Sub-directory to place all user-defined files (i.e. everything other than
|
|
44
44
|
// the entry file generated by zip-it-and-ship-it).
|
|
45
45
|
const DEFAULT_USER_SUBDIRECTORY = 'src';
|
|
46
|
-
const createDirectory = function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile,
|
|
46
|
+
const createDirectory = function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, rewrites = new Map(), srcFiles, }) {
|
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
48
|
const { contents: entryContents, filename: entryFilename } = getEntryFile({
|
|
49
49
|
commonPrefix: basePath,
|
|
@@ -63,7 +63,6 @@ const createDirectory = function ({ aliases = new Map(), basePath, destFolder, e
|
|
|
63
63
|
const normalizedDestPath = normalizeFilePath({
|
|
64
64
|
commonPrefix: basePath,
|
|
65
65
|
path: destPath,
|
|
66
|
-
pluginsModulesPath,
|
|
67
66
|
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
68
67
|
});
|
|
69
68
|
const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
|
|
@@ -75,7 +74,7 @@ const createDirectory = function ({ aliases = new Map(), basePath, destFolder, e
|
|
|
75
74
|
return functionFolder;
|
|
76
75
|
});
|
|
77
76
|
};
|
|
78
|
-
const createZipArchive = function ({ aliases, basePath, destFolder, extension, filename, mainFile,
|
|
77
|
+
const createZipArchive = function ({ aliases, basePath, destFolder, extension, filename, mainFile, rewrites, srcFiles, }) {
|
|
79
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
79
|
const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
|
|
81
80
|
const { archive, output } = (0, archive_1.startZip)(destPath);
|
|
@@ -103,7 +102,6 @@ const createZipArchive = function ({ aliases, basePath, destFolder, extension, f
|
|
|
103
102
|
aliases,
|
|
104
103
|
archive,
|
|
105
104
|
commonPrefix: basePath,
|
|
106
|
-
pluginsModulesPath,
|
|
107
105
|
rewrites,
|
|
108
106
|
srcFile,
|
|
109
107
|
stat,
|
|
@@ -141,9 +139,9 @@ const getEntryFile = ({ commonPrefix, filename, mainFile, userNamespace, }) => {
|
|
|
141
139
|
filename: entryFilename,
|
|
142
140
|
};
|
|
143
141
|
};
|
|
144
|
-
const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix,
|
|
142
|
+
const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, rewrites = new Map(), stat, srcFile, userNamespace, }) {
|
|
145
143
|
const destPath = aliases.get(srcFile) || srcFile;
|
|
146
|
-
const normalizedDestPath = normalizeFilePath({ commonPrefix, path: destPath,
|
|
144
|
+
const normalizedDestPath = normalizeFilePath({ commonPrefix, path: destPath, userNamespace });
|
|
147
145
|
if (rewrites.has(srcFile)) {
|
|
148
146
|
(0, archive_1.addZipContent)(archive, rewrites.get(srcFile), normalizedDestPath);
|
|
149
147
|
}
|
|
@@ -154,15 +152,12 @@ const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, plugin
|
|
|
154
152
|
// `adm-zip` and `require()` expect Unix paths.
|
|
155
153
|
// We remove the common path prefix.
|
|
156
154
|
// With files on different Windows drives, we remove the drive letter.
|
|
157
|
-
const normalizeFilePath = function ({ commonPrefix, path,
|
|
155
|
+
const normalizeFilePath = function ({ commonPrefix, path, userNamespace, }) {
|
|
158
156
|
const userNamespacePathSegment = userNamespace ? `${userNamespace}${path_1.sep}` : '';
|
|
159
157
|
const pathA = (0, path_1.normalize)(path);
|
|
160
|
-
const pathB =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const pathC = pathB.replace(commonPrefix, userNamespacePathSegment);
|
|
164
|
-
const pathD = (0, unixify_1.default)(pathC);
|
|
165
|
-
return pathD;
|
|
158
|
+
const pathB = pathA.replace(commonPrefix, userNamespacePathSegment);
|
|
159
|
+
const pathC = (0, unixify_1.default)(pathB);
|
|
160
|
+
return pathC;
|
|
166
161
|
};
|
|
167
162
|
/* eslint-enable max-lines */
|
|
168
163
|
//# sourceMappingURL=zip.js.map
|
|
@@ -14,7 +14,6 @@ declare type GetSrcFilesFunction = (args: {
|
|
|
14
14
|
basePath?: string;
|
|
15
15
|
config: FunctionConfig;
|
|
16
16
|
featureFlags: FeatureFlags;
|
|
17
|
-
pluginsModulesPath?: string;
|
|
18
17
|
repositoryRoot?: string;
|
|
19
18
|
} & FunctionSource) => Promise<string[]>;
|
|
20
19
|
interface ZipFunctionResult {
|
|
@@ -33,7 +32,6 @@ declare type ZipFunction = (args: {
|
|
|
33
32
|
config: FunctionConfig;
|
|
34
33
|
destFolder: string;
|
|
35
34
|
featureFlags: FeatureFlags;
|
|
36
|
-
pluginsModulesPath?: string;
|
|
37
35
|
repositoryRoot?: string;
|
|
38
36
|
} & FunctionSource) => Promise<ZipFunctionResult>;
|
|
39
37
|
interface Runtime {
|
package/dist/zip.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ interface ZipFunctionOptions {
|
|
|
6
6
|
basePath?: string;
|
|
7
7
|
config?: Config;
|
|
8
8
|
featureFlags?: FeatureFlags;
|
|
9
|
-
pluginsModulesPath?: string;
|
|
10
9
|
repositoryRoot?: string;
|
|
11
10
|
}
|
|
12
11
|
declare type ZipFunctionsOptions = ZipFunctionOptions & {
|
|
@@ -14,5 +13,5 @@ declare type ZipFunctionsOptions = ZipFunctionOptions & {
|
|
|
14
13
|
parallelLimit?: number;
|
|
15
14
|
};
|
|
16
15
|
declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, }?: ZipFunctionsOptions) => Promise<import("./utils/format_result").FunctionResult[]>;
|
|
17
|
-
declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags,
|
|
16
|
+
declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, }?: ZipFunctionOptions) => Promise<import("./utils/format_result").FunctionResult | undefined>;
|
|
18
17
|
export { zipFunction, zipFunctions };
|
package/dist/zip.js
CHANGED
|
@@ -19,7 +19,6 @@ const p_map_1 = __importDefault(require("p-map"));
|
|
|
19
19
|
const feature_flags_1 = require("./feature_flags");
|
|
20
20
|
const manifest_1 = require("./manifest");
|
|
21
21
|
const runtimes_1 = require("./runtimes");
|
|
22
|
-
const plugin_modules_path_1 = require("./runtimes/node/utils/plugin_modules_path");
|
|
23
22
|
const archive_size_1 = require("./utils/archive_size");
|
|
24
23
|
const format_result_1 = require("./utils/format_result");
|
|
25
24
|
const fs_1 = require("./utils/fs");
|
|
@@ -39,13 +38,7 @@ const zipFunctions = function (relativeSrcFolders, destFolder, { archiveFormat =
|
|
|
39
38
|
const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
|
|
40
39
|
const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
|
|
41
40
|
const [paths] = yield Promise.all([(0, fs_1.listFunctionsDirectories)(srcFolders), (0, make_dir_1.default)(destFolder)]);
|
|
42
|
-
const
|
|
43
|
-
(0, runtimes_1.getFunctionsFromPaths)(paths, { config, dedupe: true, featureFlags }),
|
|
44
|
-
// All function directories should be part of the same project root, so we
|
|
45
|
-
// can get away with computing the plugins modules path from any of the
|
|
46
|
-
// source directories.
|
|
47
|
-
(0, plugin_modules_path_1.getPluginsModulesPath)(srcFolders[0]),
|
|
48
|
-
]);
|
|
41
|
+
const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { config, dedupe: true, featureFlags });
|
|
49
42
|
const results = yield (0, p_map_1.default)(functions.values(), (func) => __awaiter(this, void 0, void 0, function* () {
|
|
50
43
|
const zipResult = yield func.runtime.zipFunction({
|
|
51
44
|
archiveFormat,
|
|
@@ -56,7 +49,6 @@ const zipFunctions = function (relativeSrcFolders, destFolder, { archiveFormat =
|
|
|
56
49
|
filename: func.filename,
|
|
57
50
|
mainFile: func.mainFile,
|
|
58
51
|
name: func.name,
|
|
59
|
-
pluginsModulesPath,
|
|
60
52
|
repositoryRoot,
|
|
61
53
|
runtime: func.runtime,
|
|
62
54
|
srcDir: func.srcDir,
|
|
@@ -79,7 +71,7 @@ const zipFunctions = function (relativeSrcFolders, destFolder, { archiveFormat =
|
|
|
79
71
|
});
|
|
80
72
|
};
|
|
81
73
|
exports.zipFunctions = zipFunctions;
|
|
82
|
-
const zipFunction = function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags,
|
|
74
|
+
const zipFunction = function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, } = {}) {
|
|
83
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
76
|
validateArchiveFormat(archiveFormat);
|
|
85
77
|
const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
|
|
@@ -89,7 +81,6 @@ const zipFunction = function (relativeSrcPath, destFolder, { archiveFormat = 'zi
|
|
|
89
81
|
return;
|
|
90
82
|
}
|
|
91
83
|
const { config, extension, filename, mainFile, name, runtime, srcDir, stat: stats, } = functions.values().next().value;
|
|
92
|
-
const pluginsModulesPath = defaultModulesPath === undefined ? yield (0, plugin_modules_path_1.getPluginsModulesPath)(srcPath) : defaultModulesPath;
|
|
93
84
|
yield (0, make_dir_1.default)(destFolder);
|
|
94
85
|
const zipResult = yield runtime.zipFunction({
|
|
95
86
|
archiveFormat,
|
|
@@ -101,7 +92,6 @@ const zipFunction = function (relativeSrcPath, destFolder, { archiveFormat = 'zi
|
|
|
101
92
|
filename,
|
|
102
93
|
mainFile,
|
|
103
94
|
name,
|
|
104
|
-
pluginsModulesPath,
|
|
105
95
|
repositoryRoot,
|
|
106
96
|
runtime,
|
|
107
97
|
srcDir,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.29.2",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"p-map": "^4.0.0",
|
|
82
82
|
"path-exists": "^4.0.0",
|
|
83
83
|
"pkg-dir": "^5.0.0",
|
|
84
|
-
"precinct": "^8.
|
|
84
|
+
"precinct": "^8.2.0",
|
|
85
85
|
"read-package-json-fast": "^2.0.2",
|
|
86
86
|
"require-package-name": "^2.0.1",
|
|
87
87
|
"resolve": "^2.0.0-next.1",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@babel/types": "^7.15.6",
|
|
97
|
-
"@netlify/eslint-config-node": "^3.3.
|
|
97
|
+
"@netlify/eslint-config-node": "^3.3.6",
|
|
98
98
|
"@types/archiver": "^5.1.1",
|
|
99
99
|
"@types/end-of-stream": "^1.4.1",
|
|
100
100
|
"@types/resolve": "^1.20.1",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"husky": "^4.3.8",
|
|
110
110
|
"npm-run-all": "^4.1.5",
|
|
111
111
|
"nyc": "^15.0.0",
|
|
112
|
-
"sinon": "^
|
|
112
|
+
"sinon": "^12.0.0",
|
|
113
113
|
"sort-on": "^4.1.1",
|
|
114
114
|
"throat": "^6.0.1",
|
|
115
115
|
"typescript": "^4.4.3"
|