nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: netlify/build
Pull request #3425 (2021-08-11 20:18:06)

feat: remove some double newlines in the build logs
This removes some double newlines currently shown in the build logs when in debug mode.


Patch:
diff --git a/packages/build/src/log/messages/config.js b/packages/build/src/log/messages/config.js
index 4646994f1..3cc2bd16b 100644
--- a/packages/build/src/log/messages/config.js
+++ b/packages/build/src/log/messages/config.js
@@ -141,7 +141,7 @@ const logConfigOnUpload = async function ({ logs, configPath, debug }) {
   }
 
   const configContents = await pReadFile(configPath, 'utf8')
-  logMessage(logs, configContents)
+  logMessage(logs, configContents.trim())
 }
 
 const logHeadersOnUpload = async function ({ logs, headersPath, debug }) {
@@ -157,7 +157,7 @@ const logHeadersOnUpload = async function ({ logs, headersPath, debug }) {
   }
 
   const headersContents = await pReadFile(headersPath, 'utf8')
-  logMessage(logs, headersContents)
+  logMessage(logs, headersContents.trim())
 }
 
 const logRedirectsOnUpload = async function ({ logs, redirectsPath, debug }) {
@@ -173,7 +173,7 @@ const logRedirectsOnUpload = async function ({ logs, redirectsPath, debug }) {
   }
 
   const redirectsContents = await pReadFile(redirectsPath, 'utf8')
-  logMessage(logs, `${redirectsContents}\n`)
+  logMessage(logs, `${redirectsContents.trim()}\n`)
 }
 
 module.exports = {


Test patch:
diff --git a/packages/build/tests/plugins/snapshots/tests.js.md b/packages/build/tests/plugins/snapshots/tests.js.md
index 6e09077df..78e3234c1 100644
--- a/packages/build/tests/plugins/snapshots/tests.js.md
+++ b/packages/build/tests/plugins/snapshots/tests.js.md
@@ -3046,7 +3046,6 @@ Generated by [AVA](https://ava.li).
       [build]␊
       command = "node command.js"␊
     ␊
-    ␊
     > Uploaded headers␊
       test: one␊
     ␊
Repository: netlify/build
Pull request #3632 (2021-09-20 10:48:17)

feat: add support for `parseWithEsbuild` feature flag
**Which problem is this pull request solving?**

Looks for the `buildbot_zisi_esbuild_parser` feature flag and passes it along to zip-it-and-ship-it as `parseWithEsbuild`, which is used by https://github.com/netlify/zip-it-and-ship-it/pull/659.

**Checklist**

Please add a `x` inside each checkbox:

- [x] I have read the [contribution guidelines](../blob/main/CONTRIBUTING.md).
- [x] The status checks are successful (continuous integration). Those can be seen below.



Patch:
diff --git a/packages/build/src/core/feature_flags.js b/packages/build/src/core/feature_flags.js
index 54e82352d..60528abd5 100644
--- a/packages/build/src/core/feature_flags.js
+++ b/packages/build/src/core/feature_flags.js
@@ -16,6 +16,7 @@ const getFeatureFlag = function (name) {
 // Default values for feature flags
 const DEFAULT_FEATURE_FLAGS = {
   buildbot_es_modules_esbuild: false,
+  buildbot_zisi_esbuild_parser: false,
 }
 
 module.exports = { normalizeCliFeatureFlags, DEFAULT_FEATURE_FLAGS }
diff --git a/packages/build/src/plugins_core/functions/index.js b/packages/build/src/plugins_core/functions/index.js
index c99697e2d..b4a6cdefd 100644
--- a/packages/build/src/plugins_core/functions/index.js
+++ b/packages/build/src/plugins_core/functions/index.js
@@ -53,6 +53,7 @@ const getZisiParameters = ({ buildDir, featureFlags, functionsConfig, functionsD
   ])
   const zisiFeatureFlags = {
     defaultEsModulesToEsbuild: featureFlags.buildbot_es_modules_esbuild,
+    parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
   }
 
   return { basePath: buildDir, config, manifest, featureFlags: zisiFeatureFlags }


Test patch:
diff --git a/packages/build/tests/core/tests.js b/packages/build/tests/core/tests.js
index 89e11af9a..949093708 100644
--- a/packages/build/tests/core/tests.js
+++ b/packages/build/tests/core/tests.js
@@ -333,6 +333,20 @@ test.serial(`Doesn't fail build for ES module function if feature flag is off`,
   t.false(callArgs[2].featureFlags.defaultEsModulesToEsbuild)
 })
 
+test.serial('Passes `parseWithEsbuild` feature flag to zip-it-and-ship-it', async (t) => {
+  const spy = sinon.spy(zipItAndShipIt, 'zipFunctions')
+
+  await runFixture(t, 'core', { snapshot: false })
+  await runFixture(t, 'core', {
+    flags: { featureFlags: { buildbot_zisi_esbuild_parser: true } },
+    snapshot: false,
+  })
+
+  t.is(spy.callCount, 2)
+  t.false(spy.firstCall.args[2].featureFlags.parseWithEsbuild)
+  t.true(spy.secondCall.args[2].featureFlags.parseWithEsbuild)
+})
+
 test('Print warning on lingering processes', async (t) => {
   const { returnValue } = await runFixture(t, 'lingering', {
     flags: { testOpts: { silentLingeringProcesses: false }, mode: 'buildbot' },
Repository: netlify/build
Pull request #3817 (2021-11-05 12:00:44)

feat: pass `nftTranspile` feature flag to ZISI
#### Summary

Passes the `nftTranspile` flag to zip-it-and-ship-it when the `buildbot_zisi_trace_nft` feature flag is set. I don't think we need a separate LaunchDarkly feature flag for this, because we want to enable transpilation in NFT when we're making it the default tracer.

**A picture of a cute animal (not mandatory, but encouraged)**

![sloth2](https://user-images.githubusercontent.com/4162329/140507256-9d838b1d-6f17-4bd2-9d8c-70d75753cf8f.jpg)





Patch:
diff --git a/packages/build/src/plugins_core/functions/feature_flags.js b/packages/build/src/plugins_core/functions/feature_flags.js
index 6d51a6607..ddab8d674 100644
--- a/packages/build/src/plugins_core/functions/feature_flags.js
+++ b/packages/build/src/plugins_core/functions/feature_flags.js
@@ -3,6 +3,7 @@
 const getZisiFeatureFlags = (featureFlags) => ({
   buildGoSource: featureFlags.buildbot_build_go_functions,
   defaultEsModulesToEsbuild: featureFlags.buildbot_es_modules_esbuild,
+  nftTranspile: featureFlags.buildbot_zisi_trace_nft,
   parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
   traceWithNft: featureFlags.buildbot_zisi_trace_nft,
 })


Test patch:
diff --git a/packages/build/tests/core/tests.js b/packages/build/tests/core/tests.js
index 9a3093bbb..ee50d34b3 100644
--- a/packages/build/tests/core/tests.js
+++ b/packages/build/tests/core/tests.js
@@ -385,8 +385,10 @@ test.serial('Passes the right feature flags to zip-it-and-ship-it', async (t) =>
   t.false(mockZipFunctions.getCall(0).args[2].featureFlags.traceWithNft)
   t.false(mockZipFunctions.getCall(0).args[2].featureFlags.buildGoSource)
   t.false(mockZipFunctions.getCall(0).args[2].featureFlags.parseWithEsbuild)
+  t.false(mockZipFunctions.getCall(0).args[2].featureFlags.nftTranspile)
 
   t.true(mockZipFunctions.getCall(1).args[2].featureFlags.traceWithNft)
+  t.true(mockZipFunctions.getCall(1).args[2].featureFlags.nftTranspile)
   t.true(mockZipFunctions.getCall(2).args[2].featureFlags.buildGoSource)
   t.true(mockZipFunctions.getCall(3).args[2].featureFlags.parseWithEsbuild)
Repository: netlify/build
Pull request #3854 (2021-11-17 19:11:05)

feat: add `buildbot_nft_transpile_esm` feature flag
#### Summary

Set the `nftTranspile` zip-it-and-ship-it flag when the `buildbot_nft_transpile_esm` LaunchDarkly flag is set.

eduardoboucas: oof! I messed up a test. https://github.com/netlify/build/pull/3854/commits/44d30616627b5ed1349959d96bdf3fbc1934a127 should fix it.
ehmicky: The CI tests are failing due to this line, which probably should be changed too:

https://github.com/netlify/build/commit/44d30616627b5ed1349959d96bdf3fbc1934a127#diff-c5f4f5e6539c85bb514eceaff7b009dcc833f0ecfbf5981c8348fbe2f0d886c8R403

Patch:
diff --git a/packages/build/src/plugins_core/functions/feature_flags.js b/packages/build/src/plugins_core/functions/feature_flags.js
index ddab8d674..63f83df67 100644
--- a/packages/build/src/plugins_core/functions/feature_flags.js
+++ b/packages/build/src/plugins_core/functions/feature_flags.js
@@ -3,7 +3,7 @@
 const getZisiFeatureFlags = (featureFlags) => ({
   buildGoSource: featureFlags.buildbot_build_go_functions,
   defaultEsModulesToEsbuild: featureFlags.buildbot_es_modules_esbuild,
-  nftTranspile: featureFlags.buildbot_zisi_trace_nft,
+  nftTranspile: featureFlags.buildbot_nft_transpile_esm || featureFlags.buildbot_zisi_trace_nft,
   parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
   traceWithNft: featureFlags.buildbot_zisi_trace_nft,
 })


Test patch:
diff --git a/packages/build/tests/core/tests.js b/packages/build/tests/core/tests.js
index ee50d34b3..4b7926711 100644
--- a/packages/build/tests/core/tests.js
+++ b/packages/build/tests/core/tests.js
@@ -376,11 +376,15 @@ test.serial('Passes the right feature flags to zip-it-and-ship-it', async (t) =>
     flags: { featureFlags: { buildbot_scheduled_functions: true } },
     snapshot: false,
   })
+  await runFixture(t, 'schedule', {
+    flags: { featureFlags: { buildbot_nft_transpile_esm: true } },
+    snapshot: false,
+  })
 
   stub.restore()
 
   // eslint-disable-next-line no-magic-numbers
-  t.is(mockZipFunctions.callCount, 5)
+  t.is(mockZipFunctions.callCount, 6)
 
   t.false(mockZipFunctions.getCall(0).args[2].featureFlags.traceWithNft)
   t.false(mockZipFunctions.getCall(0).args[2].featureFlags.buildGoSource)
@@ -391,6 +395,8 @@ test.serial('Passes the right feature flags to zip-it-and-ship-it', async (t) =>
   t.true(mockZipFunctions.getCall(1).args[2].featureFlags.nftTranspile)
   t.true(mockZipFunctions.getCall(2).args[2].featureFlags.buildGoSource)
   t.true(mockZipFunctions.getCall(3).args[2].featureFlags.parseWithEsbuild)
+  // eslint-disable-next-line no-magic-numbers
+  t.true(mockZipFunctions.getCall(5).args[2].featureFlags.nftTranspile)
 
   t.is(mockZipFunctions.getCall(0).args[2].config.test.schedule, undefined)
   // eslint-disable-next-line no-magic-numbers
Repository: netlify/build
Pull request #3908 (2021-12-01 12:28:32)

fix: correct redirect conditions type
#### Summary

Fixes the types for redirect conditions. The values are capitalized, and `Cookie` was missing.
---

For us to review and ship your PR efficiently, please perform the following steps:

- [ ] Open a [bug/issue](https://github.com/netlify/build/issues/new/choose) before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you\`re fixing a typo or something that\`s on fire 🔥 (e.g. incident related), you can skip this step.
- [x] Read the [contribution guidelines](../CONTRIBUTING.md) 📖. This ensures your code follows our style guide and
      passes our tests.
- [x] Update or add tests (if any source code was changed or added) 🧪
- [ ] Update or add documentation (if features were changed or added) 📝
- [ ] Make sure the status checks below are successful ✅

**A picture of a cute animal (not mandatory, but encouraged)**
![image](https://user-images.githubusercontent.com/213306/144234443-bb25df23-bcaa-44e8-b943-142757279a07.png)



Patch:
diff --git a/packages/build/types/config/netlify_config.d.ts b/packages/build/types/config/netlify_config.d.ts
index 697426979..fd75b8baf 100644
--- a/packages/build/types/config/netlify_config.d.ts
+++ b/packages/build/types/config/netlify_config.d.ts
@@ -14,7 +14,7 @@ interface Redirect {
   signed?: string
   query?: Partial<Record<string, string>>
   headers?: Partial<Record<string, string>>
-  conditions?: Record<'language' | 'role' | 'country', readonly string[]>
+  conditions?: Partial<Record<'Language' | 'Role' | 'Country' | 'Cookie', readonly string[]>>
 }
 
 interface Header {


Test patch:
diff --git a/packages/build/test-d/config/netlify_config.ts b/packages/build/test-d/config/netlify_config.ts
index 9ec31bee5..92f5812f4 100644
--- a/packages/build/test-d/config/netlify_config.ts
+++ b/packages/build/test-d/config/netlify_config.ts
@@ -50,7 +50,10 @@ const testNetlifyConfigRedirects: OnPreBuild = function ({
   expectType<string | undefined>(redirect.signed)
   expectType<string | undefined>(redirect.query && redirect.query.testVar)
   expectType<string | undefined>(redirect.headers && redirect.headers.testVar)
-  expectType<readonly string[] | undefined>(
-    redirect.conditions && redirect.conditions.language && redirect.conditions.language,
-  )
+  if (redirect.conditions !== undefined) {
+    expectType<readonly string[] | undefined>(redirect.conditions.Language)
+    expectType<readonly string[] | undefined>(redirect.conditions.Cookie)
+    expectType<readonly string[] | undefined>(redirect.conditions.Country)
+    expectType<readonly string[] | undefined>(redirect.conditions.Role)
+  }
 }
Repository: netlify/build
Pull request #1692 (2020-07-21 17:51:31)

Send metrics about plugins options loading
Part of https://github.com/netlify/buildbot/issues/856

This adds metrics about how long it takes to load the options and `manifest.yml` of plugins.


Patch:
diff --git a/packages/build/src/core/main.js b/packages/build/src/core/main.js
index 4d5c9293c..a893a5ca6 100644
--- a/packages/build/src/core/main.js
+++ b/packages/build/src/core/main.js
@@ -206,6 +206,8 @@ const initAndRunBuild = async function({
   testOpts,
 }) {
   const constants = await getConstants({ configPath, buildDir, functionsDistDir, netlifyConfig, siteInfo, mode })
+
+  const pluginsOptionsTimer = startTimer()
   const pluginsOptions = await getPluginsOptions({
     netlifyConfig,
     buildDir,
@@ -214,11 +216,13 @@ const initAndRunBuild = async function({
     buildImagePluginsDir,
     logs,
   })
+  const pluginsOptionsDurationMs = endTimer(pluginsOptionsTimer)
+  const timersA = addTimer(timers, 'buildbot.build.commands.getPluginsOptions', pluginsOptionsDurationMs)
 
   const startPluginsTimer = startTimer()
   const childProcesses = await startPlugins({ pluginsOptions, buildDir, nodePath, childEnv, mode, logs })
   const startPluginsDurationMs = endTimer(startPluginsTimer)
-  const timersA = addTimer(timers, 'buildbot.build.commands.startPlugins', startPluginsDurationMs)
+  const timersB = addTimer(timersA, 'buildbot.build.commands.startPlugins', startPluginsDurationMs)
 
   try {
     return await runBuild({
@@ -236,7 +240,7 @@ const initAndRunBuild = async function({
       errorMonitor,
       deployId,
       logs,
-      timers: timersA,
+      timers: timersB,
       testOpts,
     })
   } finally {


Test patch:
diff --git a/packages/build/tests/time/tests.js b/packages/build/tests/time/tests.js
index 262b28e42..ee96bb091 100644
--- a/packages/build/tests/time/tests.js
+++ b/packages/build/tests/time/tests.js
@@ -52,6 +52,7 @@ test('Prints all timings', async t => {
 })
 
 const TIMINGS = [
+  'buildbot.build.commands.getPluginsOptions',
   'buildbot.build.commands.startPlugins',
   'buildbot.build.commands.loadPlugins',
   'buildbot.build.commands.plugin.onBuild',
Repository: netlify/build
Pull request #1694 (2020-07-21 18:42:18)

Measure how long it takes to retrieve config
Part of https://github.com/netlify/buildbot/issues/856

This adds metrics about how long it takes to retrieve the configuration options.


Patch:
diff --git a/packages/build/src/core/main.js b/packages/build/src/core/main.js
index a893a5ca6..f74a9b5f7 100644
--- a/packages/build/src/core/main.js
+++ b/packages/build/src/core/main.js
@@ -61,6 +61,7 @@ const build = async function(flags = {}) {
     ...flagsA
   } = startBuild(flags)
 
+  const configTimer = startTimer()
   const { netlifyConfig, configPath, buildDir, childEnv, api, siteInfo, error } = await resolveConfig({
     ...flagsA,
     mode,
@@ -68,13 +69,16 @@ const build = async function(flags = {}) {
     logs,
     testOpts,
   })
+  const durationMs = endTimer(configTimer)
+  const timersA = addTimer(timers, 'buildbot.build.commands.resolveConfig', durationMs)
+
   if (error !== undefined) {
     await handleBuildError({ error, errorMonitor, netlifyConfig, childEnv, mode, logs, testOpts })
     return { success: false, logs }
   }
 
   try {
-    const { commandsCount, timers: timersA } = await runAndReportBuild({
+    const { commandsCount, timers: timersB } = await runAndReportBuild({
       netlifyConfig,
       configPath,
       buildDir,
@@ -89,7 +93,7 @@ const build = async function(flags = {}) {
       errorMonitor,
       deployId,
       logs,
-      timers,
+      timers: timersA,
       testOpts,
       buildbotServerSocket,
     })
@@ -102,7 +106,7 @@ const build = async function(flags = {}) {
       telemetry,
       mode,
       logs,
-      timers: timersA,
+      timers: timersB,
       timersFile,
       testOpts,
     })


Test patch:
diff --git a/packages/build/tests/time/tests.js b/packages/build/tests/time/tests.js
index ee96bb091..2c1d1167b 100644
--- a/packages/build/tests/time/tests.js
+++ b/packages/build/tests/time/tests.js
@@ -52,6 +52,7 @@ test('Prints all timings', async t => {
 })
 
 const TIMINGS = [
+  'buildbot.build.commands.resolveConfig',
   'buildbot.build.commands.getPluginsOptions',
   'buildbot.build.commands.startPlugins',
   'buildbot.build.commands.loadPlugins',
Repository: netlify/build
Pull request #1820 (2020-09-16 21:10:14)

Fix `token` returned by `@netlify/config`
Fixes https://github.com/netlify/build/issues/1816

When called as a binary, `@netlify/config` does not print the API `token` for security reasons. 

The return value of `@netlify/config` is printed on `stdout` which is used by the buildbot and passed back to `@netlify/config` using the `cachedConfig` option. When this happens, the `token` is therefore missing from `cachedConfig`. This results in `@netlify/config` return value missing the `token` under those conditions.

This means, in production, `constants.NETLIFY_API_TOKEN` passed to core plugins like the Edge handlers core plugins, is `undefined`. This PR fixes this problem. It also fixes the related integration test.


Patch:
diff --git a/packages/config/src/main.js b/packages/config/src/main.js
index c294bd388..6ab9067b1 100644
--- a/packages/config/src/main.js
+++ b/packages/config/src/main.js
@@ -26,9 +26,9 @@ const {
 // Takes an optional configuration file path as input and return the resolved
 // `config` together with related properties such as the `configPath`.
 const resolveConfig = async function(opts) {
-  const { cachedConfig, ...optsA } = addDefaultOpts(opts)
+  const { cachedConfig, token, ...optsA } = addDefaultOpts(opts)
   // `api` is not JSON-serializable, so we cannot cache it inside `cachedConfig`
-  const api = getApiClient(optsA)
+  const api = getApiClient({ ...optsA, token })
 
   // Performance optimization when @netlify/config caller has already previously
   // called it and cached the result.
@@ -36,7 +36,10 @@ const resolveConfig = async function(opts) {
   //  - first calls @netlify/config since it needs configuration property
   //  - later calls @netlify/build, which runs @netlify/config under the hood
   if (cachedConfig !== undefined) {
-    return { ...getConfig(cachedConfig, 'cached'), api }
+    // The CLI does not print the API `token` for security reasons, which means
+    // it might be missing from `cachedConfig`. We provide the one passed in
+    // `opts` as a fallback.
+    return { token, ...getConfig(cachedConfig, 'cached'), api }
   }
 
   const {
@@ -50,7 +53,6 @@ const resolveConfig = async function(opts) {
     branch,
     siteId,
     baseRelDir,
-    token,
     mode,
     debug,
     logs,


Test patch:
diff --git a/packages/config/tests/load/tests.js b/packages/config/tests/load/tests.js
index 2b1060641..b50d2f6ea 100644
--- a/packages/config/tests/load/tests.js
+++ b/packages/config/tests/load/tests.js
@@ -80,7 +80,7 @@ test('--cachedConfig with an invalid path', async t => {
 })
 
 test('--cachedConfig with a token', async t => {
-  const { returnValue } = await runFixture(t, 'cached_config', { snapshot: false, flags: { token: 'test' } })
+  const { returnValue } = await runFixture(t, 'cached_config', { snapshot: false })
   await runFixture(t, 'cached_config', { flags: { cachedConfig: returnValue, token: 'test' } })
 })
Repository: netlify/build
Pull request #1825 (2020-09-18 18:20:22)

Improve logging when Netlify Functions directory is invalid
When the `functions` setting is specified but it points to a non-existing file, we currently silently fail.
This PR adds a log message to indicate that the setting is invalid, which should help users diagnose the problem.


Patch:
diff --git a/packages/build/src/plugins_core/functions/plugin.js b/packages/build/src/plugins_core/functions/plugin.js
index faa49f194..18d1ba71d 100644
--- a/packages/build/src/plugins_core/functions/plugin.js
+++ b/packages/build/src/plugins_core/functions/plugin.js
@@ -19,6 +19,9 @@ const onBuild = async function({
   },
 }) {
   if (!(await pathExists(FUNCTIONS_SRC))) {
+    // TODO: use `utils.build.warn()` when available
+    // See https://github.com/netlify/build/issues/1248
+    console.log(`The Netlify Functions setting target a non-exiting directory: ${FUNCTIONS_SRC}`)
     return
   }
 


Test patch:
diff --git a/packages/build/tests/plugins/snapshots/tests.js.md b/packages/build/tests/plugins/snapshots/tests.js.md
index d7e1157d0..9ed52d026 100644
--- a/packages/build/tests/plugins/snapshots/tests.js.md
+++ b/packages/build/tests/plugins/snapshots/tests.js.md
@@ -506,6 +506,7 @@ Generated by [AVA](https://ava.li).
     │ 1. onPostBuild command from @netlify/plugin-functions-core │␊
     └────────────────────────────────────────────────────────────┘␊
     ␊
+    The Netlify Functions setting target a non-exiting directory: missing␊
     ␊
     (@netlify/plugin-functions-core onPostBuild completed in 1ms)␊
     ␊
@@ -2039,6 +2040,7 @@ Generated by [AVA](https://ava.li).
     │ 2. onPostBuild command from @netlify/plugin-functions-core │␊
     └────────────────────────────────────────────────────────────┘␊
     ␊
+    The Netlify Functions setting target a non-exiting directory: missing␊
     ␊
     (@netlify/plugin-functions-core onPostBuild completed in 1ms)␊
     ␊
@@ -2072,6 +2074,8 @@ Generated by [AVA](https://ava.li).
       /file/path␊
     ␊
     > Resolved config␊
+      build:␊
+        edge_handlers: /file/path␊
       plugins:␊
         - inputs: {}␊
           origin: config␊
@@ -2120,6 +2124,8 @@ Generated by [AVA](https://ava.li).
       }␊
     ␊
       Resolved config␊
+      build:␊
+        edge_handlers: /file/path␊
       plugins:␊
         - inputs: {}␊
           origin: config␊
@@ -2321,6 +2327,7 @@ Generated by [AVA](https://ava.li).
     │ 2. onPostBuild command from @netlify/plugin-functions-core │␊
     └────────────────────────────────────────────────────────────┘␊
     ␊
+    The Netlify Functions setting target a non-exiting directory: missing␊
     ␊
     (@netlify/plugin-functions-core onPostBuild completed in 1ms)␊
     ␊