@netlify/build 18.7.3 → 18.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "18.7.3",
3
+ "version": "18.9.0",
4
4
  "description": "Netlify build module",
5
5
  "main": "src/core/main.js",
6
6
  "bin": {
@@ -69,7 +69,7 @@
69
69
  "execa": "^5.1.1",
70
70
  "figures": "^3.2.0",
71
71
  "filter-obj": "^2.0.1",
72
- "got": "^9.6.0",
72
+ "got": "^10.0.0",
73
73
  "indent-string": "^4.0.0",
74
74
  "is-plain-obj": "^3.0.0",
75
75
  "js-yaml": "^4.0.0",
@@ -159,7 +159,7 @@ const runCommand = async function ({
159
159
  //
160
160
  // Otherwise, most failures will make the build fail. This includes:
161
161
  // - the build command failed
162
- // - Functions, Builders or Edge handlers bundling failed
162
+ // - Functions or Edge handlers bundling failed
163
163
  // - the deploy failed (deploying files to our CDN)
164
164
  // - a plugin `onPreBuild`, `onBuild` or `onPostBuild` event handler failed.
165
165
  // This includes uncaught exceptions and using `utils.build.failBuild()`
@@ -173,8 +173,8 @@ const runCommand = async function ({
173
173
  //
174
174
  // Finally, some plugins (only core plugins for the moment) might be enabled or
175
175
  // not depending on whether a specific action is happening during the build,
176
- // such as creating a file. For example, the Functions, Builders and Edge handlers core
177
- // plugins are disabled if no Functions, Builders or Edge handlers directory is specified
176
+ // such as creating a file. For example, the Functions and Edge handlers core
177
+ // plugins are disabled if no Functions or Edge handlers directory is specified
178
178
  // or available. However, one might be created by a build plugin, in which case,
179
179
  // those core plugins should be triggered. We use a dynamic `condition()` to
180
180
  // model this behavior.
@@ -43,16 +43,12 @@ const getConstants = async function ({
43
43
  // The directory where internal functions (i.e. generated programmatically
44
44
  // via plugins or others) live
45
45
  INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
46
- // The directory where internal builders (i.e. generated programmatically
47
- // via plugins or others) live
48
- INTERNAL_BUILDERS_SRC: `${buildDir}/${INTERNAL_BUILDERS_SRC}`,
49
46
  }
50
47
  const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig })
51
48
  return constantsA
52
49
  }
53
50
 
54
51
  const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
55
- const INTERNAL_BUILDERS_SRC = '.netlify/builders-internal'
56
52
 
57
53
  // Retrieve constants which might change during the build if a plugin modifies
58
54
  // `netlifyConfig` or creates some default directories.
@@ -63,9 +59,6 @@ const addMutableConstants = async function ({
63
59
  netlifyConfig: {
64
60
  build: { publish, edge_handlers: edgeHandlers },
65
61
  functionsDirectory,
66
- builders: {
67
- '*': { directory: buildersDirectory },
68
- },
69
62
  },
70
63
  }) {
71
64
  const constantsA = {
@@ -74,8 +67,6 @@ const addMutableConstants = async function ({
74
67
  PUBLISH_DIR: publish,
75
68
  // The directory where function source code lives
76
69
  FUNCTIONS_SRC: functionsDirectory,
77
- // The directory where builders source code lives
78
- BUILDERS_SRC: buildersDirectory,
79
70
  // The directory where edge handlers source code lives
80
71
  EDGE_HANDLERS_SRC: edgeHandlers,
81
72
  }
@@ -104,7 +95,6 @@ const DEFAULT_PATHS = [
104
95
  // @todo Remove once we drop support for the legacy default functions directory.
105
96
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
106
97
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
107
- { constantName: 'BUILDERS_SRC', defaultPath: 'netlify/builders' },
108
98
  { constantName: 'EDGE_HANDLERS_SRC', defaultPath: 'netlify/edge-handlers' },
109
99
  ]
110
100
 
@@ -154,8 +144,6 @@ const CONSTANT_PATHS = new Set([
154
144
  'FUNCTIONS_SRC',
155
145
  'FUNCTIONS_DIST',
156
146
  'INTERNAL_FUNCTIONS_SRC',
157
- 'BUILDERS_SRC',
158
- 'INTERNAL_BUILDERS_SRC',
159
147
  'EDGE_HANDLERS_SRC',
160
148
  'CACHE_DIR',
161
149
  ])
@@ -18,7 +18,7 @@ const getFeatureFlag = function (name) {
18
18
  // Default values for feature flags
19
19
  const DEFAULT_FEATURE_FLAGS = {
20
20
  zisiEsbuildDynamicImports: env.NETLIFY_EXPERIMENTAL_PROCESS_DYNAMIC_IMPORTS === 'true',
21
- buildbot_build_plugins_system_node_version: false,
21
+ netlify_build_warning_missing_headers: false,
22
22
  }
23
23
 
24
24
  module.exports = { normalizeCliFeatureFlags, DEFAULT_FEATURE_FLAGS }
package/src/core/flags.js CHANGED
@@ -104,13 +104,7 @@ Default: Current Node.js binary`,
104
104
  },
105
105
  functionsDistDir: {
106
106
  string: true,
107
- describe: `Path to the directory where packaged regular functions are kept.
108
- Default: automatically guessed`,
109
- hidden: true,
110
- },
111
- buildersDistDir: {
112
- string: true,
113
- describe: `Path to the directory where packaged builders functions are kept.
107
+ describe: `Path to the directory where packaged functions are kept.
114
108
  Default: automatically guessed`,
115
109
  hidden: true,
116
110
  },
package/src/core/main.js CHANGED
@@ -24,6 +24,7 @@ const { getConfigOpts, loadConfig } = require('./config')
24
24
  const { getConstants } = require('./constants')
25
25
  const { doDryRun } = require('./dry')
26
26
  const { warnOnLingeringProcesses } = require('./lingering')
27
+ const { warnOnMissingSideFiles } = require('./missing_side_file')
27
28
  const { normalizeFlags } = require('./normalize_flags')
28
29
  const { getSeverity } = require('./severity')
29
30
 
@@ -528,7 +529,10 @@ const initAndRunBuild = async function ({
528
529
  featureFlags,
529
530
  })
530
531
 
531
- await warnOnLingeringProcesses({ mode, logs, testOpts })
532
+ await Promise.all([
533
+ warnOnMissingSideFiles({ buildDir, netlifyConfig: netlifyConfigA, logs, featureFlags }),
534
+ warnOnLingeringProcesses({ mode, logs, testOpts }),
535
+ ])
532
536
 
533
537
  return {
534
538
  commandsCount,
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const { relative } = require('path')
4
+
5
+ const pathExists = require('path-exists')
6
+
7
+ const { logMissingSideFile } = require('../log/messages/core')
8
+
9
+ // Some files like `_headers` and `_redirects` must be copied to the publish
10
+ // directory to be used in production. When those are present in the repository
11
+ // but not in the publish directory, this most likely indicates that the build
12
+ // command accidentally forgot to copy those. We then print a warning message.
13
+ const warnOnMissingSideFiles = async function ({
14
+ buildDir,
15
+ netlifyConfig: {
16
+ build: { publish },
17
+ },
18
+ logs,
19
+ featureFlags,
20
+ }) {
21
+ if (!featureFlags.netlify_build_warning_missing_headers) {
22
+ return
23
+ }
24
+
25
+ await Promise.all(SIDE_FILES.map((sideFile) => warnOnMissingSideFile({ logs, sideFile, buildDir, publish })))
26
+ }
27
+
28
+ const SIDE_FILES = ['_headers', '_redirects']
29
+
30
+ const warnOnMissingSideFile = async function ({ logs, sideFile, buildDir, publish }) {
31
+ if (!(await pathExists(`${buildDir}/${sideFile}`)) || (await pathExists(`${publish}/${sideFile}`))) {
32
+ return
33
+ }
34
+
35
+ logMissingSideFile(logs, sideFile, relative(buildDir, publish))
36
+ }
37
+
38
+ module.exports = { warnOnMissingSideFiles }
@@ -42,7 +42,6 @@ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
42
42
  offline: false,
43
43
  telemetry: false,
44
44
  functionsDistDir: DEFAULT_FUNCTIONS_DIST,
45
- buildersDistDir: DEFAULT_BUILDERS_DIST,
46
45
  cacheDir: DEFAULT_CACHE_DIR,
47
46
  deployId: combinedEnv.DEPLOY_ID,
48
47
  buildId: combinedEnv.BUILD_ID,
@@ -65,7 +64,6 @@ const computeTelemetry = function (flags, envOpts) {
65
64
 
66
65
  const REQUIRE_MODE = 'require'
67
66
  const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
68
- const DEFAULT_BUILDERS_DIST = '.netlify/builders/'
69
67
  const DEFAULT_CACHE_DIR = '.netlify/cache/'
70
68
  const DEFAULT_STATSD_PORT = 8125
71
69
 
@@ -36,7 +36,6 @@ const TEST_FLAGS = ['buffer', 'telemetry']
36
36
  const INTERNAL_FLAGS = [
37
37
  'nodePath',
38
38
  'functionsDistDir',
39
- 'buildersDistDir',
40
39
  'defaultConfig',
41
40
  'cachedConfigPath',
42
41
  'sendStatus',
@@ -42,6 +42,14 @@ const logTimer = function (logs, durationNs, timerName) {
42
42
  log(logs, THEME.dimWords(`(${timerName} completed in ${duration})`))
43
43
  }
44
44
 
45
+ const logMissingSideFile = function (logs, sideFile, publish) {
46
+ logWarning(
47
+ logs,
48
+ `
49
+ A "${sideFile}" file is present in the repository but is missing in the publish directory "${publish}".`,
50
+ )
51
+ }
52
+
45
53
  // @todo use `terminal-link` (https://github.com/sindresorhus/terminal-link)
46
54
  // instead of `ansi-escapes` once
47
55
  // https://github.com/jamestalmage/supports-hyperlinks/pull/12 is fixed
@@ -68,5 +76,6 @@ module.exports = {
68
76
  logBuildError,
69
77
  logBuildSuccess,
70
78
  logTimer,
79
+ logMissingSideFile,
71
80
  logLingeringProcesses,
72
81
  }
@@ -33,7 +33,7 @@ const getPluginsList = async function ({ debug, logs, testOpts: { pluginsListUrl
33
33
 
34
34
  const fetchPluginsList = async function ({ logs, pluginsListUrl }) {
35
35
  try {
36
- const { body } = await got(pluginsListUrl, { json: true, timeout: PLUGINS_LIST_TIMEOUT })
36
+ const { body } = await got(pluginsListUrl, { responseType: 'json', timeout: PLUGINS_LIST_TIMEOUT })
37
37
 
38
38
  if (!isValidPluginsList(body)) {
39
39
  throw new Error(`Request succeeded but with an invalid response:\n${JSON.stringify(body, null, 2)}`)
@@ -60,8 +60,7 @@ const trackBuildComplete = async function ({
60
60
  const track = async function ({ payload, config: { origin, writeKey, timeout } }) {
61
61
  const url = `${origin}/track`
62
62
  await got.post(url, {
63
- json: true,
64
- body: payload,
63
+ json: payload,
65
64
  timeout,
66
65
  retry: 0,
67
66
  headers: { Authorization: `Basic ${writeKey}` },