@netlify/build 36.3.4 → 36.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.
@@ -11,9 +11,9 @@ const getFeatureFlag = function (name) {
11
11
  // Default values for feature flags
12
12
  export const DEFAULT_FEATURE_FLAGS = {
13
13
  buildbot_zisi_trace_nft: false,
14
- buildbot_zisi_esbuild_parser: false,
15
14
  netlify_build_updated_plugin_compatibility: false,
16
15
  netlify_build_plugin_system_log: false,
17
16
  edge_bundler_generate_tarball: false,
18
17
  netlify_build_db_setup: false,
18
+ netlify_build_server_entry: false,
19
19
  };
@@ -1,5 +1,4 @@
1
1
  export const getZisiFeatureFlags = (featureFlags) => ({
2
2
  ...featureFlags,
3
- parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
4
3
  traceWithNft: featureFlags.buildbot_zisi_trace_nft,
5
4
  });
@@ -6,12 +6,13 @@ export declare const bundleFunctions: {
6
6
  coreStepId: string;
7
7
  coreStepName: string;
8
8
  coreStepDescription: () => string;
9
- condition: ({ buildDir, constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC }, packagePath, returnValues, }: {
9
+ condition: ({ buildDir, constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC }, featureFlags, packagePath, returnValues, }: {
10
10
  buildDir: any;
11
11
  constants: {
12
12
  INTERNAL_FUNCTIONS_SRC: any;
13
13
  FUNCTIONS_SRC: any;
14
14
  };
15
+ featureFlags: any;
15
16
  packagePath: any;
16
17
  returnValues: any;
17
18
  }) => Promise<boolean>;
@@ -7,6 +7,7 @@ import { getGeneratedFunctions } from '../../steps/return_values.js';
7
7
  import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle, trackBundleResults, } from '../../log/messages/core_steps.js';
8
8
  import { FRAMEWORKS_API_FUNCTIONS_PATH } from '../../utils/frameworks_api.js';
9
9
  import { getZipError } from './error.js';
10
+ import { getServerEntry } from './server_entry.js';
10
11
  import { getUserAndInternalFunctions, validateFunctionsSrc } from './utils.js';
11
12
  import { getZisiParameters } from './zisi.js';
12
13
  // see https://docs.netlify.com/functions/trigger-on-events/#available-triggers
@@ -101,6 +102,10 @@ const coreStep = async function ({ childEnv, constants: { INTERNAL_FUNCTIONS_SRC
101
102
  }
102
103
  }
103
104
  const generatedFunctions = getGeneratedFunctions(returnValues);
105
+ const serverEntry = await getServerEntry({ buildDir, packagePath, featureFlags });
106
+ if (serverEntry) {
107
+ log(logs, `Netlify Server detected at ${serverEntry.relativeEntryPath}`);
108
+ }
104
109
  logFunctionsToBundle({
105
110
  logs,
106
111
  userFunctions,
@@ -114,7 +119,8 @@ const coreStep = async function ({ childEnv, constants: { INTERNAL_FUNCTIONS_SRC
114
119
  if (userFunctions.length === 0 &&
115
120
  internalFunctions.length === 0 &&
116
121
  frameworkFunctions.length === 0 &&
117
- generatedFunctions.length === 0) {
122
+ generatedFunctions.length === 0 &&
123
+ serverEntry === undefined) {
118
124
  return {};
119
125
  }
120
126
  const { bundlers, fallbackCount, warningsCount } = await zipFunctionsAndLogResults({
@@ -132,7 +138,10 @@ const coreStep = async function ({ childEnv, constants: { INTERNAL_FUNCTIONS_SRC
132
138
  repositoryRoot,
133
139
  userNodeVersion,
134
140
  systemLog,
135
- generatedFunctions: generatedFunctions.map((func) => func.path),
141
+ generatedFunctions: [
142
+ ...generatedFunctions.map((func) => func.path),
143
+ ...(serverEntry ? [serverEntry.shimPath] : []),
144
+ ],
136
145
  });
137
146
  const fallback = fallbackCount > 0 ? 'true' : 'false';
138
147
  const warnings = warningsCount > 0 ? 'true' : 'false';
@@ -150,7 +159,11 @@ const coreStep = async function ({ childEnv, constants: { INTERNAL_FUNCTIONS_SRC
150
159
  // one configured by the user or the internal one) exists. We use a dynamic
151
160
  // `condition` because the directories might be created by the build command
152
161
  // or plugins.
153
- const hasFunctionsDirectories = async function ({ buildDir, constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC }, packagePath, returnValues, }) {
162
+ const hasFunctionsDirectories = async function ({ buildDir, constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC }, featureFlags, packagePath, returnValues, }) {
163
+ if (featureFlags?.netlify_build_server_entry &&
164
+ (await pathExists(resolve(buildDir, packagePath || '', 'netlify/server')))) {
165
+ return true;
166
+ }
154
167
  const hasFunctionsSrc = FUNCTIONS_SRC !== undefined && FUNCTIONS_SRC !== '';
155
168
  if (hasFunctionsSrc) {
156
169
  return true;
@@ -0,0 +1,12 @@
1
+ import { type FeatureFlags } from '../../core/feature_flags.js';
2
+ export declare const SERVER_ENTRY_FUNCTION_NAME = "___netlify-server";
3
+ export interface ServerEntry {
4
+ entryPath: string;
5
+ shimPath: string;
6
+ relativeEntryPath: string;
7
+ }
8
+ export declare const getServerEntry: ({ buildDir, packagePath, featureFlags, }: {
9
+ buildDir: string;
10
+ packagePath?: string;
11
+ featureFlags?: FeatureFlags;
12
+ }) => Promise<ServerEntry | undefined>;
@@ -0,0 +1,53 @@
1
+ import { mkdir, readdir, writeFile } from 'fs/promises';
2
+ import { join, resolve } from 'path';
3
+ import { pathExists } from 'path-exists';
4
+ import { addErrorInfo } from '../../error/info.js';
5
+ export const SERVER_ENTRY_FUNCTION_NAME = '___netlify-server';
6
+ const SERVER_ENTRY_DIR = 'netlify/server';
7
+ const SERVER_ENTRY_BASENAMES = new Set(['index.js', 'index.mjs', 'index.ts', 'index.mts']);
8
+ const SERVER_SHIM_DIR = '.netlify/server-entry';
9
+ // Finds the user's server entrypoint and materializes the function entry it is
10
+ // deployed as.
11
+ export const getServerEntry = async ({ buildDir, packagePath, featureFlags, }) => {
12
+ if (!featureFlags?.netlify_build_server_entry) {
13
+ return undefined;
14
+ }
15
+ const packageRoot = resolve(buildDir, packagePath ?? '');
16
+ const serverDir = join(packageRoot, SERVER_ENTRY_DIR);
17
+ if (!(await pathExists(serverDir))) {
18
+ return undefined;
19
+ }
20
+ const candidates = (await readdir(serverDir)).filter((name) => SERVER_ENTRY_BASENAMES.has(name)).sort();
21
+ if (candidates.length === 0) {
22
+ return undefined;
23
+ }
24
+ if (candidates.length > 1) {
25
+ const error = new Error(`Found multiple server entrypoints in ${SERVER_ENTRY_DIR} (${candidates.join(', ')}). A site can have one server only.`);
26
+ addErrorInfo(error, { type: 'resolveConfig' });
27
+ throw error;
28
+ }
29
+ const entryPath = join(serverDir, candidates[0]);
30
+ const shimDir = join(packageRoot, SERVER_SHIM_DIR);
31
+ const shimPath = join(shimDir, `${SERVER_ENTRY_FUNCTION_NAME}.mjs`);
32
+ await mkdir(shimDir, { recursive: true });
33
+ await writeFile(shimPath, getShimContents(entryPath));
34
+ return {
35
+ entryPath,
36
+ shimPath,
37
+ relativeEntryPath: `${SERVER_ENTRY_DIR}/${candidates[0]}`,
38
+ };
39
+ };
40
+ // The shim gives the server the deploy surface of a function without touching
41
+ // the user's code.
42
+ const getShimContents = (entryPath) => `import * as server from ${JSON.stringify(entryPath)}
43
+
44
+ export default server.default ?? server
45
+ export const shutdown = server.shutdown
46
+
47
+ export const config = {
48
+ name: "Netlify Server",
49
+ generator: "netlify-server",
50
+ path: "/*",
51
+ preferStatic: true,
52
+ }
53
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "36.3.4",
3
+ "version": "36.4.0",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -69,14 +69,14 @@
69
69
  "@bugsnag/js": "^8.0.0",
70
70
  "@netlify/blobs": "^10.4.4",
71
71
  "@netlify/cache-utils": "^7.1.1",
72
- "@netlify/config": "^25.2.2",
72
+ "@netlify/config": "^25.2.3",
73
73
  "@netlify/edge-bundler": "16.0.3",
74
- "@netlify/functions-utils": "^7.1.3",
74
+ "@netlify/functions-utils": "^7.1.5",
75
75
  "@netlify/git-utils": "^7.1.0",
76
76
  "@netlify/opentelemetry-utils": "^3.1.0",
77
77
  "@netlify/plugins-list": "^6.81.6",
78
78
  "@netlify/run-utils": "^7.1.0",
79
- "@netlify/zip-it-and-ship-it": "15.3.3",
79
+ "@netlify/zip-it-and-ship-it": "15.4.0",
80
80
  "@sindresorhus/slugify": "^2.0.0",
81
81
  "ansi-escapes": "^7.0.0",
82
82
  "ansis": "^4.1.0",
@@ -152,5 +152,5 @@
152
152
  "engines": {
153
153
  "node": ">=22.12.0"
154
154
  },
155
- "gitHead": "724a4f230b81cf9c6d46f50122d128c220756a6c"
155
+ "gitHead": "aaee524cfed2fc082e6cb7268ce7230071b39068"
156
156
  }