@netlify/zip-it-and-ship-it 16.0.0 → 16.1.0
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/main.d.ts +3 -2
- package/dist/main.js +1 -1
- package/dist/manifest.d.ts +16 -1
- package/dist/manifest.js +22 -3
- package/dist/runtimes/node/index.js +2 -1
- package/dist/runtimes/node/utils/entry_file.d.ts +1 -0
- package/dist/runtimes/node/utils/entry_file.js +1 -0
- package/dist/runtimes/node/utils/zip.d.ts +1 -0
- package/dist/runtimes/node/utils/zip.js +6 -3
- package/dist/runtimes/runtime.d.ts +1 -0
- package/dist/server.d.ts +40 -0
- package/dist/server.js +76 -0
- package/dist/zip.d.ts +45 -1
- package/dist/zip.js +46 -6
- package/package.json +2 -2
package/dist/main.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import { ModuleFormat } from './runtimes/node/utils/module_format.js';
|
|
|
5
5
|
import { RuntimeName } from './runtimes/runtime.js';
|
|
6
6
|
import type { ExtendedRoute, Route } from './utils/routes.js';
|
|
7
7
|
export { Config, FunctionConfig } from './config.js';
|
|
8
|
-
export { zipFunction, zipFunctions, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js';
|
|
9
|
-
export type {
|
|
8
|
+
export { bundle, zipFunction, zipFunctions, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js';
|
|
9
|
+
export type { BundleOptions, BundleResult, FunctionsOptions, ServerOptions, ServerResult } from './zip.js';
|
|
10
|
+
export type { FunctionsBag, MixedPaths } from './paths.js';
|
|
10
11
|
export { ArchiveFormat, ARCHIVE_FORMAT } from './archive.js';
|
|
11
12
|
export type { TrafficRules } from './rate_limit.js';
|
|
12
13
|
export type { ExtendedRoute, Route } from './utils/routes.js';
|
package/dist/main.js
CHANGED
|
@@ -6,7 +6,7 @@ import { parseFile } from './runtimes/node/in_source_config/index.js';
|
|
|
6
6
|
import { RUNTIME } from './runtimes/runtime.js';
|
|
7
7
|
import { RuntimeCache } from './utils/cache.js';
|
|
8
8
|
import { listFunctionsDirectories, resolveFunctionsDirectories } from './utils/fs.js';
|
|
9
|
-
export { zipFunction, zipFunctions } from './zip.js';
|
|
9
|
+
export { bundle, zipFunction, zipFunctions } from './zip.js';
|
|
10
10
|
export { ARCHIVE_FORMAT } from './archive.js';
|
|
11
11
|
export { NODE_BUNDLER } from './runtimes/node/bundlers/types.js';
|
|
12
12
|
export { RUNTIME } from './runtimes/runtime.js';
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { InvocationMode } from './function.js';
|
|
2
2
|
import type { TrafficRules } from './rate_limit.js';
|
|
3
|
+
import type { ServerResult } from './server.js';
|
|
3
4
|
import type { FunctionResult } from './utils/format_result.js';
|
|
4
5
|
import type { ExtendedRoute, Route } from './utils/routes.js';
|
|
5
6
|
interface ManifestFunction {
|
|
@@ -24,8 +25,21 @@ interface ManifestFunction {
|
|
|
24
25
|
trafficRules?: TrafficRules;
|
|
25
26
|
vcpu?: number;
|
|
26
27
|
}
|
|
28
|
+
interface ManifestServer {
|
|
29
|
+
bundler?: string;
|
|
30
|
+
excludedRoutes?: Route[];
|
|
31
|
+
mainFile: string;
|
|
32
|
+
memory?: number;
|
|
33
|
+
path: string;
|
|
34
|
+
region?: string;
|
|
35
|
+
routes?: ExtendedRoute[];
|
|
36
|
+
runtime: string;
|
|
37
|
+
runtimeVersion?: string;
|
|
38
|
+
vcpu?: number;
|
|
39
|
+
}
|
|
27
40
|
export interface Manifest {
|
|
28
41
|
functions: ManifestFunction[];
|
|
42
|
+
server?: ManifestServer;
|
|
29
43
|
system: {
|
|
30
44
|
arch: string;
|
|
31
45
|
platform: string;
|
|
@@ -33,8 +47,9 @@ export interface Manifest {
|
|
|
33
47
|
timestamp: number;
|
|
34
48
|
version: number;
|
|
35
49
|
}
|
|
36
|
-
export declare const createManifest: ({ functions, path }: {
|
|
50
|
+
export declare const createManifest: ({ functions, path, server, }: {
|
|
37
51
|
functions: FunctionResult[];
|
|
38
52
|
path: string;
|
|
53
|
+
server?: ServerResult;
|
|
39
54
|
}) => Promise<void>;
|
|
40
55
|
export {};
|
package/dist/manifest.js
CHANGED
|
@@ -2,16 +2,35 @@ import { promises as fs } from 'fs';
|
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
import { arch, platform } from 'process';
|
|
4
4
|
const MANIFEST_VERSION = 1;
|
|
5
|
-
export const createManifest = async ({ functions, path }) => {
|
|
6
|
-
const formattedFunctions = functions.map((func) => formatFunctionForManifest(func));
|
|
5
|
+
export const createManifest = async ({ functions, path, server, }) => {
|
|
7
6
|
const payload = {
|
|
8
|
-
functions:
|
|
7
|
+
functions: functions.map((func) => formatFunctionForManifest(func)),
|
|
8
|
+
server: server && formatServerForManifest(server),
|
|
9
9
|
system: { arch, platform },
|
|
10
10
|
timestamp: Date.now(),
|
|
11
11
|
version: MANIFEST_VERSION,
|
|
12
12
|
};
|
|
13
13
|
await fs.writeFile(path, JSON.stringify(payload));
|
|
14
14
|
};
|
|
15
|
+
const formatServerForManifest = ({ bundler, excludedRoutes, mainFile, memory, path, region, routes, runtime, runtimeVersion, vcpu, }) => {
|
|
16
|
+
const server = {
|
|
17
|
+
bundler,
|
|
18
|
+
mainFile,
|
|
19
|
+
memory,
|
|
20
|
+
path: resolve(path),
|
|
21
|
+
region,
|
|
22
|
+
runtime,
|
|
23
|
+
runtimeVersion,
|
|
24
|
+
vcpu,
|
|
25
|
+
};
|
|
26
|
+
if (routes?.length) {
|
|
27
|
+
server.routes = routes;
|
|
28
|
+
}
|
|
29
|
+
if (excludedRoutes?.length) {
|
|
30
|
+
server.excludedRoutes = excludedRoutes;
|
|
31
|
+
}
|
|
32
|
+
return server;
|
|
33
|
+
};
|
|
15
34
|
const formatFunctionForManifest = ({ bootstrapVersion, bundler, displayName, eventSubscriptions, excludedRoutes, generator, invocationMode, mainFile, memory, name, path, priority, region, trafficRules, routes, runtime, runtimeVersion, runtimeAPIVersion, schedule, timeout, vcpu, }) => {
|
|
16
35
|
const manifestFunction = {
|
|
17
36
|
bundler,
|
|
@@ -32,7 +32,7 @@ const getSrcFilesWithBundler = async (parameters) => {
|
|
|
32
32
|
const result = await bundler.getSrcFiles({ ...parameters, pluginsModulesPath });
|
|
33
33
|
return result.srcFiles;
|
|
34
34
|
};
|
|
35
|
-
const zipFunction = async function ({ archiveFormat, basePath, branch, cache, config = {}, destFolder, extension, featureFlags, filename, isInternal, logger, mainFile, name, repositoryRoot, runtime, span, srcDir, srcPath, stat, }) {
|
|
35
|
+
const zipFunction = async function ({ archiveFormat, basePath, branch, cache, config = {}, destFolder, extension, featureFlags, filename, isInternal, isServer, logger, mainFile, name, repositoryRoot, runtime, span, srcDir, srcPath, stat, }) {
|
|
36
36
|
// If the file is a zip, we assume the function is bundled and ready to go.
|
|
37
37
|
// We simply copy it to the destination path with no further processing.
|
|
38
38
|
if (extension === '.zip') {
|
|
@@ -106,6 +106,7 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
|
|
|
106
106
|
extension,
|
|
107
107
|
featureFlags,
|
|
108
108
|
filename,
|
|
109
|
+
isServer,
|
|
109
110
|
mainFile: finalMainFile,
|
|
110
111
|
moduleFormat,
|
|
111
112
|
name,
|
|
@@ -4,6 +4,7 @@ export declare const ENTRY_FILE_NAME = "___netlify-entry-point";
|
|
|
4
4
|
export declare const BOOTSTRAP_FILE_NAME = "___netlify-bootstrap.mjs";
|
|
5
5
|
export declare const METADATA_FILE_NAME = "___netlify-metadata.json";
|
|
6
6
|
export declare const TELEMETRY_FILE_NAME = "___netlify-telemetry.mjs";
|
|
7
|
+
export declare const SERVER_MARKER_FILENAME = "___netlify-server.json";
|
|
7
8
|
export interface EntryFile {
|
|
8
9
|
contents: string;
|
|
9
10
|
filename: string;
|
|
@@ -9,6 +9,7 @@ export const ENTRY_FILE_NAME = '___netlify-entry-point';
|
|
|
9
9
|
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.mjs';
|
|
10
10
|
export const METADATA_FILE_NAME = '___netlify-metadata.json';
|
|
11
11
|
export const TELEMETRY_FILE_NAME = '___netlify-telemetry.mjs';
|
|
12
|
+
export const SERVER_MARKER_FILENAME = '___netlify-server.json';
|
|
12
13
|
const require = createRequire(import.meta.url);
|
|
13
14
|
/**
|
|
14
15
|
* A minimal implementation of kebab-case.
|
|
@@ -7,7 +7,7 @@ import { copyFile } from 'copy-file';
|
|
|
7
7
|
import pMap from 'p-map';
|
|
8
8
|
import { addZipContent, addZipFile, ARCHIVE_FORMAT, endZip, startTar, startZip, } from '../../../archive.js';
|
|
9
9
|
import { cachedLstat, mkdirAndWriteFile } from '../../../utils/fs.js';
|
|
10
|
-
import { BOOTSTRAP_FILE_NAME, METADATA_FILE_NAME, conflictsWithEntryFile, getEntryFile, getTelemetryFile, isNamedLikeEntryFile, } from './entry_file.js';
|
|
10
|
+
import { BOOTSTRAP_FILE_NAME, METADATA_FILE_NAME, conflictsWithEntryFile, getEntryFile, getTelemetryFile, isNamedLikeEntryFile, SERVER_MARKER_FILENAME, } from './entry_file.js';
|
|
11
11
|
import { NETLIFY_PLAY_BOOTSTRAP_VERSION, useNetlifyPlay } from './play.js';
|
|
12
12
|
import { getMetadataFile } from './metadata_file.js';
|
|
13
13
|
import { normalizeFilePath } from './normalize_path.js';
|
|
@@ -101,8 +101,8 @@ const createDirectory = async function ({ aliases = new Map(), basePath, cache,
|
|
|
101
101
|
});
|
|
102
102
|
return { path: functionFolder, entryFilename };
|
|
103
103
|
};
|
|
104
|
-
const createZipArchive = async function ({ aliases = new Map(), basePath, branch, cache, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, runtimeAPIVersion, srcFiles, generator, }) {
|
|
105
|
-
const isPlay = useNetlifyPlay(featureFlags, mainFile);
|
|
104
|
+
const createZipArchive = async function ({ aliases = new Map(), basePath, branch, cache, destFolder, extension, featureFlags, filename, isServer, mainFile, moduleFormat, rewrites, runtimeAPIVersion, srcFiles, generator, }) {
|
|
105
|
+
const isPlay = isServer === true || useNetlifyPlay(featureFlags, mainFile);
|
|
106
106
|
const format = isPlay ? ARCHIVE_FORMAT.TAR : ARCHIVE_FORMAT.ZIP;
|
|
107
107
|
const archiveExtension = format === ARCHIVE_FORMAT.TAR ? '.tgz' : '.zip';
|
|
108
108
|
const destPath = join(destFolder, `${basename(filename, extension)}${archiveExtension}`);
|
|
@@ -141,6 +141,9 @@ const createZipArchive = async function ({ aliases = new Map(), basePath, branch
|
|
|
141
141
|
entryFilename = entryFile.filename;
|
|
142
142
|
addEntryFileToZip(archive, entryFile);
|
|
143
143
|
}
|
|
144
|
+
if (isServer === true) {
|
|
145
|
+
addEntryFileToZip(archive, { contents: '{}', filename: SERVER_MARKER_FILENAME });
|
|
146
|
+
}
|
|
144
147
|
const telemetryFile = getTelemetryFile(generator);
|
|
145
148
|
if (featureFlags.zisi_add_instrumentation_loader === true) {
|
|
146
149
|
addEntryFileToZip(archive, telemetryFile);
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FeatureFlags } from './feature_flags.js';
|
|
2
|
+
import type { RuntimeName } from './runtimes/runtime.js';
|
|
3
|
+
import type { RuntimeCache } from './utils/cache.js';
|
|
4
|
+
import type { getLogger } from './utils/logger.js';
|
|
5
|
+
import type { ExtendedRoute, Route } from './utils/routes.js';
|
|
6
|
+
/**
|
|
7
|
+
* A bundled Netlify Server. It is built like a function, but it is described on
|
|
8
|
+
* its own terms: it carries no schedule, event subscriptions, invocation mode,
|
|
9
|
+
* priority or timeout, because it is not invoked per request.
|
|
10
|
+
*/
|
|
11
|
+
export type ServerResult = {
|
|
12
|
+
bundler?: string;
|
|
13
|
+
excludedRoutes?: Route[];
|
|
14
|
+
mainFile: string;
|
|
15
|
+
memory?: number;
|
|
16
|
+
path: string;
|
|
17
|
+
region?: string;
|
|
18
|
+
routes?: ExtendedRoute[];
|
|
19
|
+
runtime: RuntimeName;
|
|
20
|
+
runtimeVersion?: string;
|
|
21
|
+
size?: number;
|
|
22
|
+
vcpu?: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The deploy's Netlify Server, and how to bundle it. Set by whatever generates
|
|
26
|
+
* the server, not by the user.
|
|
27
|
+
*/
|
|
28
|
+
export interface ServerOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Path of the user's server entry file.
|
|
31
|
+
*/
|
|
32
|
+
path: string;
|
|
33
|
+
}
|
|
34
|
+
export declare const bundleServer: (server: ServerOptions, destFolder: string, { basePath, cache, featureFlags, logger, repositoryRoot, }: {
|
|
35
|
+
basePath?: string;
|
|
36
|
+
cache: RuntimeCache;
|
|
37
|
+
featureFlags: FeatureFlags;
|
|
38
|
+
logger: ReturnType<typeof getLogger>;
|
|
39
|
+
repositoryRoot?: string;
|
|
40
|
+
}) => Promise<ServerResult>;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { extname, join, resolve } from 'path';
|
|
3
|
+
import { ARCHIVE_FORMAT } from './archive.js';
|
|
4
|
+
import { getFunctionFromPath } from './runtimes/index.js';
|
|
5
|
+
import { formatZipResult } from './utils/format_result.js';
|
|
6
|
+
import { removeUndefined } from './utils/remove_undefined.js';
|
|
7
|
+
import { getRoutes } from './utils/routes.js';
|
|
8
|
+
// A server claims every path the rest of the deploy does not.
|
|
9
|
+
const SERVER_ROUTE = '/*';
|
|
10
|
+
// Names the server's output folder and its archive.
|
|
11
|
+
const SERVER_NAME = 'server';
|
|
12
|
+
// A server that cannot be read leaves the deploy with no backend at all, so it
|
|
13
|
+
// fails the build rather than coming up empty.
|
|
14
|
+
const readServerSource = async (srcPath, { cache, featureFlags }) => {
|
|
15
|
+
let source;
|
|
16
|
+
try {
|
|
17
|
+
source = await getFunctionFromPath(srcPath, { cache, featureFlags });
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error(`Could not read the Netlify Server at ${srcPath}: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
if (source === undefined) {
|
|
23
|
+
throw new Error(`Could not read the Netlify Server at ${srcPath}`);
|
|
24
|
+
}
|
|
25
|
+
return source;
|
|
26
|
+
};
|
|
27
|
+
// Bundles a Netlify Server through the same runtime as a function, into its own
|
|
28
|
+
// folder so its archive does not land among theirs.
|
|
29
|
+
export const bundleServer = async (server, destFolder, { basePath, cache, featureFlags, logger, repositoryRoot, }) => {
|
|
30
|
+
const srcPath = resolve(server.path);
|
|
31
|
+
const source = await readServerSource(srcPath, { cache, featureFlags });
|
|
32
|
+
const serverFolder = join(destFolder, SERVER_NAME);
|
|
33
|
+
await fs.mkdir(serverFolder, { recursive: true });
|
|
34
|
+
const zipResult = await source.runtime.zipFunction({
|
|
35
|
+
archiveFormat: ARCHIVE_FORMAT.ZIP,
|
|
36
|
+
basePath,
|
|
37
|
+
cache,
|
|
38
|
+
config: source.config,
|
|
39
|
+
destFolder: serverFolder,
|
|
40
|
+
extension: source.extension,
|
|
41
|
+
featureFlags,
|
|
42
|
+
filename: source.filename,
|
|
43
|
+
isInternal: true,
|
|
44
|
+
isServer: true,
|
|
45
|
+
logger,
|
|
46
|
+
mainFile: source.mainFile,
|
|
47
|
+
name: SERVER_NAME,
|
|
48
|
+
repositoryRoot,
|
|
49
|
+
runtime: source.runtime,
|
|
50
|
+
srcDir: source.srcDir,
|
|
51
|
+
srcPath,
|
|
52
|
+
stat: source.stat,
|
|
53
|
+
});
|
|
54
|
+
const path = join(serverFolder, `${SERVER_NAME}${extname(zipResult.path)}`);
|
|
55
|
+
await fs.rename(zipResult.path, path);
|
|
56
|
+
const result = formatZipResult({
|
|
57
|
+
...zipResult,
|
|
58
|
+
mainFile: source.mainFile,
|
|
59
|
+
name: SERVER_NAME,
|
|
60
|
+
path,
|
|
61
|
+
runtime: source.runtime,
|
|
62
|
+
});
|
|
63
|
+
return removeUndefined({
|
|
64
|
+
bundler: result.bundler,
|
|
65
|
+
excludedRoutes: result.excludedRoutes,
|
|
66
|
+
mainFile: result.mainFile,
|
|
67
|
+
memory: result.memory,
|
|
68
|
+
path: result.path,
|
|
69
|
+
region: result.region,
|
|
70
|
+
routes: getRoutes(SERVER_NAME, SERVER_ROUTE).map((route) => ({ ...route, prefer_static: true })),
|
|
71
|
+
runtime: result.runtime,
|
|
72
|
+
runtimeVersion: result.runtimeVersion,
|
|
73
|
+
size: result.size,
|
|
74
|
+
vcpu: result.vcpu,
|
|
75
|
+
});
|
|
76
|
+
};
|
package/dist/zip.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ArchiveFormat } from './archive.js';
|
|
2
2
|
import { Config } from './config.js';
|
|
3
3
|
import { FeatureFlags } from './feature_flags.js';
|
|
4
|
+
import { type ServerOptions, type ServerResult } from './server.js';
|
|
4
5
|
import { type MixedPaths } from './paths.js';
|
|
5
6
|
import { FunctionResult } from './utils/format_result.js';
|
|
6
7
|
import { LogFunction } from './utils/logger.js';
|
|
@@ -16,10 +17,53 @@ export interface ZipFunctionOptions {
|
|
|
16
17
|
debug?: boolean;
|
|
17
18
|
internalSrcFolder?: string;
|
|
18
19
|
}
|
|
20
|
+
export interface BundleResult {
|
|
21
|
+
/**
|
|
22
|
+
* The bundled functions. A server is never among them.
|
|
23
|
+
*/
|
|
24
|
+
functions: FunctionResult[];
|
|
25
|
+
/**
|
|
26
|
+
* The bundled Netlify Server, when one was given.
|
|
27
|
+
*/
|
|
28
|
+
server?: ServerResult;
|
|
29
|
+
}
|
|
19
30
|
export type ZipFunctionsOptions = ZipFunctionOptions & {
|
|
20
31
|
configFileDirectories?: string[];
|
|
21
32
|
manifest?: string;
|
|
22
33
|
parallelLimit?: number;
|
|
23
34
|
};
|
|
24
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The deploy's functions, and how to bundle them.
|
|
37
|
+
*/
|
|
38
|
+
export interface FunctionsOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Directories to search, specific function paths, or both.
|
|
41
|
+
*/
|
|
42
|
+
paths: MixedPaths;
|
|
43
|
+
archiveFormat?: ArchiveFormat;
|
|
44
|
+
config?: Config;
|
|
45
|
+
configFileDirectories?: string[];
|
|
46
|
+
parallelLimit?: number;
|
|
47
|
+
}
|
|
48
|
+
export type { ServerOptions, ServerResult };
|
|
49
|
+
export interface BundleOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Where the archives and the manifest are written.
|
|
52
|
+
*/
|
|
53
|
+
destFolder: string;
|
|
54
|
+
functions?: FunctionsOptions;
|
|
55
|
+
server?: ServerOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Path of the manifest file. Defaults to `manifest.json` inside `destFolder`.
|
|
58
|
+
*/
|
|
59
|
+
manifest?: string;
|
|
60
|
+
basePath?: string;
|
|
61
|
+
branch?: string;
|
|
62
|
+
debug?: boolean;
|
|
63
|
+
featureFlags?: FeatureFlags;
|
|
64
|
+
repositoryRoot?: string;
|
|
65
|
+
systemLog?: LogFunction;
|
|
66
|
+
}
|
|
67
|
+
export declare const zipFunctions: (input: MixedPaths, destFolder: string, { archiveFormat, basePath, branch, config, configFileDirectories, debug, featureFlags, manifest, parallelLimit, repositoryRoot, systemLog, }?: ZipFunctionsOptions) => Promise<FunctionResult[]>;
|
|
68
|
+
export declare const bundle: ({ basePath, branch, debug, destFolder, featureFlags: inputFeatureFlags, functions: functionsOptions, manifest, repositoryRoot, server, systemLog, }: BundleOptions) => Promise<BundleResult>;
|
|
25
69
|
export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, systemLog, debug, internalSrcFolder, }?: ZipFunctionOptions) => Promise<FunctionResult | undefined>;
|
package/dist/zip.js
CHANGED
|
@@ -5,6 +5,7 @@ import pMap from 'p-map';
|
|
|
5
5
|
import { ARCHIVE_FORMAT } from './archive.js';
|
|
6
6
|
import { getFlags } from './feature_flags.js';
|
|
7
7
|
import { createManifest } from './manifest.js';
|
|
8
|
+
import { bundleServer } from './server.js';
|
|
8
9
|
import { getFunctionsFromPaths } from './runtimes/index.js';
|
|
9
10
|
import { MODULE_FORMAT } from './runtimes/node/utils/module_format.js';
|
|
10
11
|
import { getFunctionsBag } from './paths.js';
|
|
@@ -22,15 +23,41 @@ const validateArchiveFormat = (archiveFormat) => {
|
|
|
22
23
|
};
|
|
23
24
|
// Zip `srcFolder/*` (Node.js or Go files) to `destFolder/*.zip` so it can be
|
|
24
25
|
// used by AWS Lambda
|
|
25
|
-
export const zipFunctions = async function (input, destFolder, { archiveFormat
|
|
26
|
+
export const zipFunctions = async function (input, destFolder, { archiveFormat, basePath, branch, config, configFileDirectories, debug, featureFlags, manifest, parallelLimit, repositoryRoot, systemLog, } = {}) {
|
|
27
|
+
const { functions } = await bundle({
|
|
28
|
+
basePath,
|
|
29
|
+
branch,
|
|
30
|
+
debug,
|
|
31
|
+
destFolder,
|
|
32
|
+
featureFlags,
|
|
33
|
+
functions: {
|
|
34
|
+
archiveFormat,
|
|
35
|
+
config,
|
|
36
|
+
configFileDirectories,
|
|
37
|
+
parallelLimit,
|
|
38
|
+
paths: input,
|
|
39
|
+
},
|
|
40
|
+
manifest,
|
|
41
|
+
repositoryRoot,
|
|
42
|
+
systemLog,
|
|
43
|
+
});
|
|
44
|
+
return functions;
|
|
45
|
+
};
|
|
46
|
+
// Bundles a deploy's functions and its Netlify Server, writing the one manifest
|
|
47
|
+
// that describes both.
|
|
48
|
+
export const bundle = async function ({ basePath, branch, debug, destFolder, featureFlags: inputFeatureFlags, functions: functionsOptions, manifest, repositoryRoot = basePath, server, systemLog, }) {
|
|
49
|
+
const { archiveFormat = ARCHIVE_FORMAT.ZIP, config = {}, configFileDirectories, parallelLimit = DEFAULT_PARALLEL_LIMIT, paths, } = functionsOptions ?? { paths: [] };
|
|
26
50
|
validateArchiveFormat(archiveFormat);
|
|
27
51
|
const logger = getLogger(systemLog, debug);
|
|
28
52
|
const cache = new RuntimeCache();
|
|
29
53
|
const featureFlags = getFlags(inputFeatureFlags);
|
|
30
|
-
const bag = getFunctionsBag(
|
|
54
|
+
const bag = getFunctionsBag(paths);
|
|
31
55
|
const srcFolders = resolveFunctionsDirectories([...bag.generated.directories, ...bag.user.directories]);
|
|
32
|
-
const [
|
|
33
|
-
|
|
56
|
+
const [foundPaths] = await Promise.all([
|
|
57
|
+
listFunctionsDirectories(srcFolders),
|
|
58
|
+
fs.mkdir(destFolder, { recursive: true }),
|
|
59
|
+
]);
|
|
60
|
+
const functions = await getFunctionsFromPaths([...foundPaths, ...bag.generated.functions, ...bag.user.functions], {
|
|
34
61
|
cache,
|
|
35
62
|
config,
|
|
36
63
|
configFileDirectories,
|
|
@@ -74,8 +101,21 @@ export const zipFunctions = async function (input, destFolder, { archiveFormat =
|
|
|
74
101
|
const resultWithSize = await addArchiveSize(result);
|
|
75
102
|
return formatZipResult(resultWithSize);
|
|
76
103
|
}));
|
|
77
|
-
|
|
78
|
-
|
|
104
|
+
const serverResult = server === undefined
|
|
105
|
+
? undefined
|
|
106
|
+
: await bundleServer(server, destFolder, {
|
|
107
|
+
basePath,
|
|
108
|
+
cache,
|
|
109
|
+
featureFlags,
|
|
110
|
+
logger,
|
|
111
|
+
repositoryRoot,
|
|
112
|
+
});
|
|
113
|
+
await createManifest({
|
|
114
|
+
functions: formattedResults,
|
|
115
|
+
path: resolve(manifest || join(destFolder, 'manifest.json')),
|
|
116
|
+
server: serverResult,
|
|
117
|
+
});
|
|
118
|
+
return { functions: formattedResults, server: serverResult };
|
|
79
119
|
};
|
|
80
120
|
export const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat = ARCHIVE_FORMAT.ZIP, basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, systemLog, debug, internalSrcFolder, } = {}) {
|
|
81
121
|
validateArchiveFormat(archiveFormat);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=22.12.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "22902a5992a5909a97bb366c88c96f6d95c18b33"
|
|
104
104
|
}
|