@netlify/build 35.12.0 → 35.13.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.
@@ -48,7 +48,7 @@ export interface NetlifyPluginConstants {
48
48
  EDGE_FUNCTIONS_SRC?: string;
49
49
  /**
50
50
  * the directory where database migration source files live.
51
- * `undefined` if no `netlify/db/migrations` directory exists and if not specified by the user.
51
+ * `undefined` if no `netlify/database/migrations` directory exists and if not specified by the user.
52
52
  */
53
53
  DB_MIGRATIONS_SRC?: string;
54
54
  /**
@@ -100,7 +100,7 @@ export declare const getConstants: ({ configPath, buildDir, packagePath, functio
100
100
  token: any;
101
101
  mode: any;
102
102
  }) => Promise<NetlifyPluginConstants>;
103
- export declare const addMutableConstants: ({ constants, buildDir, netlifyConfig: { build: { publish, edge_functions: edgeFunctions }, functionsDirectory, db, }, }: {
103
+ export declare const addMutableConstants: ({ constants, buildDir, netlifyConfig: { build: { publish, edge_functions: edgeFunctions }, functionsDirectory, database, }, }: {
104
104
  constants: any;
105
105
  buildDir: any;
106
106
  netlifyConfig: {
@@ -109,7 +109,7 @@ export declare const addMutableConstants: ({ constants, buildDir, netlifyConfig:
109
109
  edge_functions: any;
110
110
  };
111
111
  functionsDirectory: any;
112
- db: any;
112
+ database: any;
113
113
  };
114
114
  }) => Promise<{
115
115
  [k: string]: string | boolean | undefined;
@@ -52,7 +52,7 @@ const DB_MIGRATIONS_DIST = '.netlify/internal/db/migrations';
52
52
  // Retrieve constants which might change during the build if a plugin modifies
53
53
  // `netlifyConfig` or creates some default directories.
54
54
  // Unlike readonly constants, this is called again before each build step.
55
- export const addMutableConstants = async function ({ constants, buildDir, netlifyConfig: { build: { publish, edge_functions: edgeFunctions }, functionsDirectory, db, }, }) {
55
+ export const addMutableConstants = async function ({ constants, buildDir, netlifyConfig: { build: { publish, edge_functions: edgeFunctions }, functionsDirectory, database, }, }) {
56
56
  const constantsA = {
57
57
  ...constants,
58
58
  // Directory that contains the deploy-ready HTML files and assets generated by the build
@@ -62,7 +62,7 @@ export const addMutableConstants = async function ({ constants, buildDir, netlif
62
62
  // The directory where Edge Functions source code lives
63
63
  EDGE_FUNCTIONS_SRC: edgeFunctions,
64
64
  // The directory where database migration source files live
65
- DB_MIGRATIONS_SRC: db?.migrations?.path,
65
+ DB_MIGRATIONS_SRC: database?.migrations?.path,
66
66
  };
67
67
  const constantsB = await addDefaultConstants(constantsA, buildDir);
68
68
  const constantsC = normalizeConstantsPaths(constantsB, buildDir);
@@ -84,7 +84,7 @@ const DEFAULT_PATHS = [
84
84
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
85
85
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
86
86
  { constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
87
- { constantName: 'DB_MIGRATIONS_SRC', defaultPath: 'netlify/db/migrations' },
87
+ { constantName: 'DB_MIGRATIONS_SRC', defaultPath: 'netlify/database/migrations' },
88
88
  ];
89
89
  const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
90
90
  // Configuration paths are relative to the build directory.
@@ -1,8 +1,10 @@
1
1
  import { join } from 'node:path';
2
2
  import { logDbProvisioning, logDbMigrations } from '../../log/messages/core_steps.js';
3
3
  import { getPackageJson } from '../../utils/package.js';
4
- import { readMigrationEntries, getMigrationNames } from './utils.js';
5
- const NPM_PACKAGE_NAME = '@netlify/db';
4
+ import { readMigrationEntries, getMigrationNames, getMigrationsSrc } from './utils.js';
5
+ const NPM_PACKAGE_NAME = '@netlify/database';
6
+ // TODO: Remove once we stop supporting the legacy `@netlify/db` package name.
7
+ const NPM_PACKAGE_NAME_LEGACY = '@netlify/db';
6
8
  const condition = async ({ buildDir, packagePath, featureFlags }) => {
7
9
  if (!featureFlags?.netlify_build_db_setup) {
8
10
  return false;
@@ -22,10 +24,11 @@ const condition = async ({ buildDir, packagePath, featureFlags }) => {
22
24
  const coreStep = async ({ api, branch, buildDir, constants, context, logs }) => {
23
25
  const siteId = constants.SITE_ID;
24
26
  logDbProvisioning({ logs, branch, context });
25
- const entries = await readMigrationEntries(buildDir, constants.DB_MIGRATIONS_SRC);
27
+ const migrationsSrc = await getMigrationsSrc(buildDir, constants.DB_MIGRATIONS_SRC);
28
+ const entries = await readMigrationEntries(buildDir, migrationsSrc);
26
29
  const migrationNames = getMigrationNames(entries);
27
- if (migrationNames.length > 0) {
28
- logDbMigrations({ logs, migrations: migrationNames, srcDir: constants.DB_MIGRATIONS_SRC });
30
+ if (migrationNames.length > 0 && migrationsSrc) {
31
+ logDbMigrations({ logs, migrations: migrationNames, srcDir: migrationsSrc });
29
32
  }
30
33
  // @ts-expect-error This is an internal method for now so it isn't typed yet.
31
34
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
@@ -45,13 +48,16 @@ const coreStep = async ({ api, branch, buildDir, constants, context, logs }) =>
45
48
  };
46
49
  const hasDBPackage = (packageJSON) => {
47
50
  const { dependencies = {}, devDependencies = {} } = packageJSON;
48
- return NPM_PACKAGE_NAME in dependencies || NPM_PACKAGE_NAME in devDependencies;
51
+ return (NPM_PACKAGE_NAME in dependencies ||
52
+ NPM_PACKAGE_NAME in devDependencies ||
53
+ NPM_PACKAGE_NAME_LEGACY in dependencies ||
54
+ NPM_PACKAGE_NAME_LEGACY in devDependencies);
49
55
  };
50
56
  export const dbSetup = {
51
57
  event: 'onPreBuild',
52
58
  coreStep,
53
59
  coreStepId: 'db_provision',
54
- coreStepName: 'Netlify DB setup',
55
- coreStepDescription: () => 'Netlify DB setup',
60
+ coreStepName: 'Netlify Database setup',
61
+ coreStepDescription: () => 'Netlify Database setup',
56
62
  condition,
57
63
  };
@@ -1,22 +1,23 @@
1
1
  import { copyFile, mkdir } from 'node:fs/promises';
2
2
  import { join, resolve } from 'node:path';
3
3
  import { pathExists } from 'path-exists';
4
- import { readMigrationEntries } from './utils.js';
4
+ import { readMigrationEntries, getMigrationsSrc } from './utils.js';
5
5
  import { validateMigrations, formatValidationErrors } from './validation.js';
6
6
  const condition = async ({ featureFlags, constants, buildDir }) => {
7
7
  if (!featureFlags?.netlify_build_db_setup) {
8
8
  return false;
9
9
  }
10
- const srcDir = constants.DB_MIGRATIONS_SRC;
10
+ const srcDir = await getMigrationsSrc(buildDir, constants.DB_MIGRATIONS_SRC);
11
11
  if (!srcDir) {
12
12
  return false;
13
13
  }
14
14
  return pathExists(resolve(buildDir, srcDir));
15
15
  };
16
16
  const coreStep = async ({ constants, buildDir, systemLog }) => {
17
- const srcDir = resolve(buildDir, constants.DB_MIGRATIONS_SRC);
17
+ const migrationsSrc = await getMigrationsSrc(buildDir, constants.DB_MIGRATIONS_SRC);
18
+ const srcDir = resolve(buildDir, migrationsSrc);
18
19
  const destDir = resolve(buildDir, constants.DB_MIGRATIONS_DIST);
19
- const { dirNames, fileNames } = await readMigrationEntries(buildDir, constants.DB_MIGRATIONS_SRC);
20
+ const { dirNames, fileNames } = await readMigrationEntries(buildDir, migrationsSrc);
20
21
  if (dirNames.length === 0 && fileNames.length === 0) {
21
22
  systemLog('No migration directories found, skipping copy.');
22
23
  return {};
@@ -52,7 +53,7 @@ export const copyDbMigrations = {
52
53
  event: 'onBuild',
53
54
  coreStep,
54
55
  coreStepId: 'db_migrations_copy',
55
- coreStepName: 'Netlify DB migrations',
56
+ coreStepName: 'Netlify Database migrations',
56
57
  coreStepDescription: () => 'Copy database migrations to internal directory',
57
58
  condition,
58
59
  quiet: true,
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Returns the effective migrations source directory for the current build.
3
+ *
4
+ * If the user has set `database.migrations.path` in their config, or the new
5
+ * default `netlify/database/migrations` directory exists, that value will have
6
+ * been populated into `constants.DB_MIGRATIONS_SRC` upstream. If not, we fall
7
+ * back to the legacy `netlify/db/migrations` directory for backwards
8
+ * compatibility.
9
+ */
10
+ export declare const getMigrationsSrc: (buildDir: string, configuredSrc: string | undefined) => Promise<string | undefined>;
1
11
  export interface MigrationEntries {
2
12
  dirNames: string[];
3
13
  fileNames: string[];
@@ -1,6 +1,27 @@
1
1
  import { readdir, stat } from 'node:fs/promises';
2
2
  import { join, resolve } from 'node:path';
3
3
  import { pathExists } from 'path-exists';
4
+ // TODO: Remove once we drop support for the legacy `netlify/db/migrations` directory.
5
+ const LEGACY_DB_MIGRATIONS_SRC = 'netlify/db/migrations';
6
+ /**
7
+ * Returns the effective migrations source directory for the current build.
8
+ *
9
+ * If the user has set `database.migrations.path` in their config, or the new
10
+ * default `netlify/database/migrations` directory exists, that value will have
11
+ * been populated into `constants.DB_MIGRATIONS_SRC` upstream. If not, we fall
12
+ * back to the legacy `netlify/db/migrations` directory for backwards
13
+ * compatibility.
14
+ */
15
+ // TODO: Remove the legacy fallback once we drop support for `netlify/db/migrations`.
16
+ export const getMigrationsSrc = async (buildDir, configuredSrc) => {
17
+ if (configuredSrc) {
18
+ return configuredSrc;
19
+ }
20
+ if (await pathExists(resolve(buildDir, LEGACY_DB_MIGRATIONS_SRC))) {
21
+ return LEGACY_DB_MIGRATIONS_SRC;
22
+ }
23
+ return undefined;
24
+ };
4
25
  export const readMigrationEntries = async (buildDir, migrationsSrc) => {
5
26
  const empty = { dirNames: [], fileNames: [] };
6
27
  if (!migrationsSrc) {
@@ -25,11 +25,11 @@ interface NetlifyPlugin {
25
25
  package: string;
26
26
  inputs: PluginInputs;
27
27
  }
28
- interface DbMigrationsConfig {
28
+ interface DatabaseMigrationsConfig {
29
29
  path?: string;
30
30
  }
31
- interface DbConfig {
32
- migrations?: DbMigrationsConfig;
31
+ interface DatabaseConfig {
32
+ migrations?: DatabaseMigrationsConfig;
33
33
  }
34
34
  interface ImagesConfig {
35
35
  remote_images: string[];
@@ -60,6 +60,6 @@ export interface NetlifyConfig {
60
60
  /**
61
61
  * object with options for database configuration
62
62
  */
63
- db?: DbConfig;
63
+ database?: DatabaseConfig;
64
64
  }
65
65
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "35.12.0",
3
+ "version": "35.13.0",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -69,7 +69,7 @@
69
69
  "@bugsnag/js": "^8.0.0",
70
70
  "@netlify/blobs": "^10.4.4",
71
71
  "@netlify/cache-utils": "^6.0.5",
72
- "@netlify/config": "^24.4.4",
72
+ "@netlify/config": "^24.5.0",
73
73
  "@netlify/edge-bundler": "14.9.19",
74
74
  "@netlify/functions-utils": "^6.2.29",
75
75
  "@netlify/git-utils": "^6.0.4",
@@ -153,5 +153,5 @@
153
153
  "engines": {
154
154
  "node": ">=18.14.0"
155
155
  },
156
- "gitHead": "85ec413dbce5342df01289953b91169c1f84c34b"
156
+ "gitHead": "c77982ba1d1886e81f1a517318fcf93123f2a260"
157
157
  }