@netlify/zip-it-and-ship-it 16.3.1 → 16.4.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/config.d.ts +6 -1
- package/dist/config.js +3 -7
- package/dist/main.d.ts +1 -1
- package/dist/manifest.d.ts +1 -2
- package/dist/manifest.js +2 -3
- package/dist/runtimes/node/in_source_config/index.d.ts +23 -2
- package/dist/runtimes/node/in_source_config/index.js +9 -3
- package/dist/server.d.ts +19 -4
- package/dist/server.js +29 -10
- package/dist/zip.d.ts +8 -3
- package/dist/zip.js +2 -2
- package/package.json +2 -2
package/dist/config.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { FunctionSource } from './function.js';
|
|
3
3
|
export declare const serverRegion: z.ZodPreprocess<z.ZodEnum<{
|
|
4
|
+
cmh: "cmh";
|
|
4
5
|
fra: "fra";
|
|
5
|
-
|
|
6
|
+
}>>;
|
|
7
|
+
export declare const serverSize: z.ZodPreprocess<z.ZodEnum<{
|
|
8
|
+
small: "small";
|
|
9
|
+
medium: "medium";
|
|
10
|
+
large: "large";
|
|
6
11
|
}>>;
|
|
7
12
|
export declare const functionConfigShape: z.ZodObject<{
|
|
8
13
|
background: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
package/dist/config.js
CHANGED
|
@@ -37,14 +37,10 @@ const FUNCTION_REGION_CODES = Object.keys(FUNCTION_REGION_KEYS);
|
|
|
37
37
|
// Accept any casing in source (`iad`, `IAD`, `Iad`) but normalize to lower
|
|
38
38
|
// case before validating and writing to the manifest.
|
|
39
39
|
const functionRegion = z.preprocess((input) => (typeof input === 'string' ? input.toLowerCase() : input), z.enum(FUNCTION_REGION_CODES));
|
|
40
|
-
|
|
41
|
-
// against `FunctionRegion`.
|
|
42
|
-
const SERVER_REGION_KEYS = {
|
|
43
|
-
fra: null,
|
|
44
|
-
iad: null,
|
|
45
|
-
};
|
|
46
|
-
const SERVER_REGION_CODES = Object.keys(SERVER_REGION_KEYS);
|
|
40
|
+
const SERVER_REGION_CODES = ['cmh', 'fra'];
|
|
47
41
|
export const serverRegion = z.preprocess((input) => (typeof input === 'string' ? input.toLowerCase() : input), z.enum(SERVER_REGION_CODES));
|
|
42
|
+
const SERVER_SIZES = ['small', 'medium', 'large'];
|
|
43
|
+
export const serverSize = z.preprocess((input) => (typeof input === 'string' ? input.toLowerCase() : input), z.enum(SERVER_SIZES));
|
|
48
44
|
const FUNCTION_MEMORY_MIN_MB = 1024;
|
|
49
45
|
const FUNCTION_MEMORY_MAX_MB = 4096;
|
|
50
46
|
const functionMemory = z.preprocess((input) => (typeof input === 'string' || typeof input === 'number' ? parseMemoryMB(input) : input), z.number().int().min(FUNCTION_MEMORY_MIN_MB).max(FUNCTION_MEMORY_MAX_MB));
|
package/dist/main.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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
8
|
export { zipFunction, zipFunctions, zipServer, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js';
|
|
9
|
-
export type { ServerOptions, ServerResult, ZipServerOptions } from './zip.js';
|
|
9
|
+
export type { NetlifyServerConfig, ServerOptions, ServerResult, ZipServerOptions } from './zip.js';
|
|
10
10
|
export { findServerEntry, getServerRoutes } from './server.js';
|
|
11
11
|
export type { FunctionsBag, MixedPaths } from './paths.js';
|
|
12
12
|
export { ArchiveFormat, ARCHIVE_FORMAT } from './archive.js';
|
package/dist/manifest.d.ts
CHANGED
|
@@ -28,14 +28,13 @@ interface ManifestFunction {
|
|
|
28
28
|
interface ManifestServer {
|
|
29
29
|
bundler?: string;
|
|
30
30
|
excludedRoutes?: Route[];
|
|
31
|
+
instanceSize?: string;
|
|
31
32
|
mainFile: string;
|
|
32
|
-
memory?: number;
|
|
33
33
|
path: string;
|
|
34
34
|
region?: string;
|
|
35
35
|
routes?: ExtendedRoute[];
|
|
36
36
|
runtime: string;
|
|
37
37
|
runtimeVersion?: string;
|
|
38
|
-
vcpu?: number;
|
|
39
38
|
}
|
|
40
39
|
interface ManifestBase {
|
|
41
40
|
system: {
|
package/dist/manifest.js
CHANGED
|
@@ -21,16 +21,15 @@ export const createServerManifest = async ({ path, server }) => {
|
|
|
21
21
|
};
|
|
22
22
|
await fs.writeFile(path, JSON.stringify(payload));
|
|
23
23
|
};
|
|
24
|
-
const formatServerForManifest = ({ bundler, excludedRoutes,
|
|
24
|
+
const formatServerForManifest = ({ bundler, excludedRoutes, instanceSize, mainFile, path, region, routes, runtime, runtimeVersion, }) => {
|
|
25
25
|
const server = {
|
|
26
26
|
bundler,
|
|
27
|
+
instanceSize,
|
|
27
28
|
mainFile,
|
|
28
|
-
memory,
|
|
29
29
|
path: resolve(path),
|
|
30
30
|
region,
|
|
31
31
|
runtime,
|
|
32
32
|
runtimeVersion,
|
|
33
|
-
vcpu,
|
|
34
33
|
};
|
|
35
34
|
if (routes?.length) {
|
|
36
35
|
server.routes = routes;
|
|
@@ -92,14 +92,35 @@ export declare const inSourceConfig: z.ZodObject<{
|
|
|
92
92
|
}, z.core.$strip>>>;
|
|
93
93
|
}, z.core.$strip>;
|
|
94
94
|
export type InSourceConfig = z.infer<typeof inSourceConfig>;
|
|
95
|
+
export declare const serverConfig: z.ZodObject<{
|
|
96
|
+
excludedPath: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>;
|
|
97
|
+
path: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>;
|
|
98
|
+
region: z.ZodOptional<z.ZodPreprocess<z.ZodEnum<{
|
|
99
|
+
cmh: "cmh";
|
|
100
|
+
fra: "fra";
|
|
101
|
+
}>>>;
|
|
102
|
+
size: z.ZodOptional<z.ZodPreprocess<z.ZodEnum<{
|
|
103
|
+
small: "small";
|
|
104
|
+
medium: "medium";
|
|
105
|
+
large: "large";
|
|
106
|
+
}>>>;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
export type ServerConfig = z.infer<typeof serverConfig>;
|
|
95
109
|
export declare const serverInSourceConfig: z.ZodObject<{
|
|
96
|
-
|
|
110
|
+
excludedPath: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>;
|
|
97
111
|
path: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>;
|
|
98
112
|
region: z.ZodOptional<z.ZodPreprocess<z.ZodEnum<{
|
|
113
|
+
cmh: "cmh";
|
|
99
114
|
fra: "fra";
|
|
100
|
-
iad: "iad";
|
|
101
115
|
}>>>;
|
|
116
|
+
size: z.ZodOptional<z.ZodPreprocess<z.ZodEnum<{
|
|
117
|
+
small: "small";
|
|
118
|
+
medium: "medium";
|
|
119
|
+
large: "large";
|
|
120
|
+
}>>>;
|
|
121
|
+
includedFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
102
122
|
}, z.core.$strict>;
|
|
123
|
+
export type ServerInSourceConfig = z.infer<typeof serverInSourceConfig>;
|
|
103
124
|
/**
|
|
104
125
|
* Loads a file at a given path, parses it into an AST, and returns a series of
|
|
105
126
|
* data points, such as in-source configuration properties and other metadata.
|
|
@@ -3,7 +3,7 @@ import { dirname } from 'path';
|
|
|
3
3
|
// this dependency.
|
|
4
4
|
import mergeOptions from 'merge-options';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { functionConfigShape, serverRegion, withComputeResources } from '../../../config.js';
|
|
6
|
+
import { functionConfigShape, serverRegion, serverSize, withComputeResources } from '../../../config.js';
|
|
7
7
|
import { INVOCATION_MODE } from '../../../function.js';
|
|
8
8
|
import { rateLimit } from '../../../rate_limit.js';
|
|
9
9
|
import { ensureArray } from '../../../utils/ensure_array.js';
|
|
@@ -56,11 +56,17 @@ export const inSourceConfig = functionConfigShape
|
|
|
56
56
|
message: '`memory` and `vcpu` cannot both be set.',
|
|
57
57
|
path: ['vcpu'],
|
|
58
58
|
});
|
|
59
|
-
export const
|
|
59
|
+
export const serverConfig = z
|
|
60
60
|
.object({
|
|
61
|
-
|
|
61
|
+
excludedPath: paths,
|
|
62
62
|
path: paths,
|
|
63
63
|
region: serverRegion.optional(),
|
|
64
|
+
size: serverSize.optional(),
|
|
65
|
+
})
|
|
66
|
+
.strict();
|
|
67
|
+
export const serverInSourceConfig = serverConfig
|
|
68
|
+
.extend({
|
|
69
|
+
includedFiles: z.array(z.string()).optional(),
|
|
64
70
|
})
|
|
65
71
|
.strict();
|
|
66
72
|
/**
|
package/dist/server.d.ts
CHANGED
|
@@ -8,28 +8,43 @@ import type { ExtendedRoute, Route } from './utils/routes.js';
|
|
|
8
8
|
* none.
|
|
9
9
|
*/
|
|
10
10
|
export declare const findServerEntry: (directory: string) => Promise<string | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Server configuration from the `[server]` block of the Netlify configuration
|
|
13
|
+
* file. The server's in-source configuration takes precedence over it.
|
|
14
|
+
*/
|
|
15
|
+
export interface NetlifyServerConfig {
|
|
16
|
+
excludedPath?: string | string[];
|
|
17
|
+
path?: string | string[];
|
|
18
|
+
region?: string;
|
|
19
|
+
size?: string;
|
|
20
|
+
}
|
|
11
21
|
/**
|
|
12
22
|
* Returns the routes the server at `entryPath` claims, read from its in-source
|
|
13
|
-
* configuration, without bundling it.
|
|
23
|
+
* configuration and the `config` given, without bundling it.
|
|
14
24
|
*/
|
|
15
|
-
export declare const getServerRoutes: (entryPath: string
|
|
25
|
+
export declare const getServerRoutes: (entryPath: string, { config }?: {
|
|
26
|
+
config?: NetlifyServerConfig;
|
|
27
|
+
}) => Promise<ExtendedRoute[]>;
|
|
16
28
|
export type ServerResult = {
|
|
17
29
|
bundler?: string;
|
|
18
30
|
excludedRoutes?: Route[];
|
|
31
|
+
instanceSize?: string;
|
|
19
32
|
mainFile: string;
|
|
20
|
-
memory?: number;
|
|
21
33
|
path: string;
|
|
22
34
|
region?: string;
|
|
23
35
|
routes?: ExtendedRoute[];
|
|
24
36
|
runtime: RuntimeName;
|
|
25
37
|
runtimeVersion?: string;
|
|
26
38
|
size?: number;
|
|
27
|
-
vcpu?: number;
|
|
28
39
|
};
|
|
29
40
|
/**
|
|
30
41
|
* The deploy's Netlify Server, and how to bundle it.
|
|
31
42
|
*/
|
|
32
43
|
export interface ServerOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Server configuration from the Netlify configuration file.
|
|
46
|
+
*/
|
|
47
|
+
config?: NetlifyServerConfig;
|
|
33
48
|
/**
|
|
34
49
|
* Path of the user's server entry file.
|
|
35
50
|
*/
|
package/dist/server.js
CHANGED
|
@@ -2,7 +2,7 @@ import { promises as fs } from 'fs';
|
|
|
2
2
|
import { extname, join, resolve } from 'path';
|
|
3
3
|
import { ARCHIVE_FORMAT } from './archive.js';
|
|
4
4
|
import { getFunctionFromPath } from './runtimes/index.js';
|
|
5
|
-
import { parseFile } from './runtimes/node/in_source_config/index.js';
|
|
5
|
+
import { parseFile, serverConfig, } from './runtimes/node/in_source_config/index.js';
|
|
6
6
|
import { RUNTIME } from './runtimes/runtime.js';
|
|
7
7
|
import { FunctionBundlingUserError } from './utils/error.js';
|
|
8
8
|
import { formatZipResult } from './utils/format_result.js';
|
|
@@ -40,13 +40,30 @@ export const findServerEntry = async (directory) => {
|
|
|
40
40
|
};
|
|
41
41
|
// A server always sets `preferStatic: true`.
|
|
42
42
|
const toServerRoutes = (paths = DEFAULT_SERVER_PATHS) => getRoutes(SERVER_NAME, paths).map((route) => ({ ...route, prefer_static: true }));
|
|
43
|
+
const toExcludedServerRoutes = (paths = []) => paths.length === 0 ? undefined : getRoutes(SERVER_NAME, paths);
|
|
44
|
+
const parseNetlifyServerConfig = (config = {}) => {
|
|
45
|
+
const { data, error, success } = serverConfig.safeParse(config);
|
|
46
|
+
if (success) {
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
const [issue] = error.issues;
|
|
50
|
+
const location = issue.path.length === 0 ? '' : ` on '${issue.path.join('.')}'`;
|
|
51
|
+
throw new FunctionBundlingUserError(`Netlify Server has a configuration error in the [server] block${location}: ${issue.message}`, { functionName: SERVER_NAME, runtime: RUNTIME.JAVASCRIPT });
|
|
52
|
+
};
|
|
53
|
+
const mergeServerConfig = (inSource, fromNetlifyConfig) => ({
|
|
54
|
+
excludedPath: inSource.excludedPath ?? fromNetlifyConfig.excludedPath,
|
|
55
|
+
path: inSource.path ?? fromNetlifyConfig.path,
|
|
56
|
+
region: inSource.region ?? fromNetlifyConfig.region,
|
|
57
|
+
size: inSource.size ?? fromNetlifyConfig.size,
|
|
58
|
+
});
|
|
43
59
|
/**
|
|
44
60
|
* Returns the routes the server at `entryPath` claims, read from its in-source
|
|
45
|
-
* configuration, without bundling it.
|
|
61
|
+
* configuration and the `config` given, without bundling it.
|
|
46
62
|
*/
|
|
47
|
-
export const getServerRoutes = async (entryPath) => {
|
|
48
|
-
const
|
|
49
|
-
|
|
63
|
+
export const getServerRoutes = async (entryPath, { config } = {}) => {
|
|
64
|
+
const fromNetlifyConfig = parseNetlifyServerConfig(config);
|
|
65
|
+
const { config: inSource } = await parseFile(resolve(entryPath), { functionName: SERVER_NAME, isServer: true });
|
|
66
|
+
return toServerRoutes(mergeServerConfig(inSource, fromNetlifyConfig).path);
|
|
50
67
|
};
|
|
51
68
|
const readServerSource = async (srcPath, { cache, featureFlags }) => {
|
|
52
69
|
let source;
|
|
@@ -68,6 +85,7 @@ const readServerSource = async (srcPath, { cache, featureFlags }) => {
|
|
|
68
85
|
return source;
|
|
69
86
|
};
|
|
70
87
|
export const bundleServer = async (server, destFolder, { basePath, cache, featureFlags, logger, repositoryRoot, }) => {
|
|
88
|
+
const fromNetlifyConfig = parseNetlifyServerConfig(server.config);
|
|
71
89
|
const srcPath = resolve(server.path);
|
|
72
90
|
const source = await readServerSource(srcPath, { cache, featureFlags });
|
|
73
91
|
const zipResult = await source.runtime.zipFunction({
|
|
@@ -99,17 +117,18 @@ export const bundleServer = async (server, destFolder, { basePath, cache, featur
|
|
|
99
117
|
path,
|
|
100
118
|
runtime: source.runtime,
|
|
101
119
|
});
|
|
120
|
+
const inSource = (zipResult.staticAnalysisResult?.config ?? {});
|
|
121
|
+
const config = mergeServerConfig(inSource, fromNetlifyConfig);
|
|
102
122
|
return removeUndefined({
|
|
103
123
|
bundler: result.bundler,
|
|
104
|
-
excludedRoutes:
|
|
124
|
+
excludedRoutes: toExcludedServerRoutes(config.excludedPath),
|
|
125
|
+
instanceSize: config.size,
|
|
105
126
|
mainFile: result.mainFile,
|
|
106
|
-
memory: result.memory,
|
|
107
127
|
path: result.path,
|
|
108
|
-
region:
|
|
109
|
-
routes: toServerRoutes(
|
|
128
|
+
region: config.region,
|
|
129
|
+
routes: toServerRoutes(config.path),
|
|
110
130
|
runtime: result.runtime,
|
|
111
131
|
runtimeVersion: result.runtimeVersion,
|
|
112
132
|
size: result.size,
|
|
113
|
-
vcpu: result.vcpu,
|
|
114
133
|
});
|
|
115
134
|
};
|
package/dist/zip.d.ts
CHANGED
|
@@ -1,7 +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
|
+
import { type NetlifyServerConfig, type ServerOptions, type ServerResult } from './server.js';
|
|
5
5
|
import { type MixedPaths } from './paths.js';
|
|
6
6
|
import { FunctionResult } from './utils/format_result.js';
|
|
7
7
|
import { LogFunction } from './utils/logger.js';
|
|
@@ -24,6 +24,11 @@ export type ZipFunctionsOptions = ZipFunctionOptions & {
|
|
|
24
24
|
};
|
|
25
25
|
export interface ZipServerOptions {
|
|
26
26
|
basePath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Server configuration from the `[server]` block of the Netlify
|
|
29
|
+
* configuration file.
|
|
30
|
+
*/
|
|
31
|
+
config?: NetlifyServerConfig;
|
|
27
32
|
debug?: boolean;
|
|
28
33
|
featureFlags?: FeatureFlags;
|
|
29
34
|
/**
|
|
@@ -33,7 +38,7 @@ export interface ZipServerOptions {
|
|
|
33
38
|
repositoryRoot?: string;
|
|
34
39
|
systemLog?: LogFunction;
|
|
35
40
|
}
|
|
36
|
-
export type { ServerOptions, ServerResult };
|
|
41
|
+
export type { NetlifyServerConfig, ServerOptions, ServerResult };
|
|
37
42
|
export declare const zipFunctions: (input: MixedPaths, destFolder: string, { archiveFormat, basePath, branch, config, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, systemLog, debug, }?: ZipFunctionsOptions) => Promise<FunctionResult[]>;
|
|
38
|
-
export declare const zipServer: (srcPath: string, destFolder: string, { basePath, debug, featureFlags: inputFeatureFlags, manifest, repositoryRoot, systemLog, }?: ZipServerOptions) => Promise<ServerResult>;
|
|
43
|
+
export declare const zipServer: (srcPath: string, destFolder: string, { basePath, config, debug, featureFlags: inputFeatureFlags, manifest, repositoryRoot, systemLog, }?: ZipServerOptions) => Promise<ServerResult>;
|
|
39
44
|
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
|
@@ -81,12 +81,12 @@ export const zipFunctions = async function (input, destFolder, { archiveFormat =
|
|
|
81
81
|
});
|
|
82
82
|
return formattedResults;
|
|
83
83
|
};
|
|
84
|
-
export const zipServer = async function (srcPath, destFolder, { basePath, debug, featureFlags: inputFeatureFlags, manifest, repositoryRoot = basePath, systemLog, } = {}) {
|
|
84
|
+
export const zipServer = async function (srcPath, destFolder, { basePath, config, debug, featureFlags: inputFeatureFlags, manifest, repositoryRoot = basePath, systemLog, } = {}) {
|
|
85
85
|
const logger = getLogger(systemLog, debug);
|
|
86
86
|
const cache = new RuntimeCache();
|
|
87
87
|
const featureFlags = getFlags(inputFeatureFlags);
|
|
88
88
|
await fs.mkdir(destFolder, { recursive: true });
|
|
89
|
-
const result = await bundleServer({ path: srcPath }, destFolder, {
|
|
89
|
+
const result = await bundleServer({ config, path: srcPath }, destFolder, {
|
|
90
90
|
basePath,
|
|
91
91
|
cache,
|
|
92
92
|
featureFlags,
|
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.4.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=22.12.0"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "19447a3826a8d26af1bcdc704754e8a8586597f1"
|
|
103
103
|
}
|