Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 38 additions & 102 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions packages/build/tests/core/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,24 @@ Generated by [AVA](https://avajs.dev).
"general"␊
],␊
"value": "false"␊
},␊
"SITE_ID": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"SITE_NAME": {␊
"sources": [␊
"general"␊
],␊
"value": "site-name"␊
},␊
"URL": {␊
"sources": [␊
"general"␊
],␊
"value": "https://site-name.netlify.app"␊
}␊
},␊
"headersPath": "packages/build/tests/core/fixtures/basereldir/_headers",␊
Expand Down
Binary file modified packages/build/tests/core/snapshots/tests.js.snap
Binary file not shown.
19 changes: 19 additions & 0 deletions packages/build/tests/monitor/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be produced for those "mock" values?

@hrishikesh-k hrishikesh-k May 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, yes. These lines are coming from here:

const getBuildLogs = function ({ SITE_NAME, DEPLOY_ID }) {
if (SITE_NAME === undefined || DEPLOY_ID === undefined) {
return
}
return `${NETLIFY_ORIGIN}/sites/${SITE_NAME}/deploys/${DEPLOY_ID}`
}
const NETLIFY_ORIGIN = 'https://app.netlify.com'
. Previously, DEPLOY_ID existed, SITE_NAME didn't. Now SITE_NAME also exists resulting in the line existing. Based on the code, I think it makes sense to have these lines printed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit conflicted on this - not sure if one is worse then the other, but that buildLogs url won't ever work, so that's why I was wondering wether we should return undefined for the mocked values case (as in expand conditions that are checked to avoid constructing url if values are mocked)

But I guess same can be same about mocked SITE_NAME and all the others, that they won't work either in practice - so probably matter of degree on what make sense to "mock" and what does not 🤔

"buildCommand": "node --invalid",␊
"buildCommandOrigin": "config",␊
"configPath": "packages/build/tests/monitor/fixtures/command/netlify.toml"␊
Expand Down Expand Up @@ -212,6 +213,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "load",␊
"packageName": "./plugin.js",␊
"input": "test",␊
Expand Down Expand Up @@ -308,6 +310,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "load",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -396,6 +399,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -484,6 +488,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -572,6 +577,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -647,6 +653,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -739,6 +746,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -832,6 +840,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "error",␊
"unhandled": true,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/test",␊
"endpoint": "cancelSiteDeploy",␊
"parameters": {␊
"deploy_id": "test"␊
Expand Down Expand Up @@ -1040,6 +1049,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"buildCommand": "node --invalid",␊
"buildCommandOrigin": "config",␊
"configPath": "packages/build/tests/monitor/fixtures/command/netlify.toml"␊
Expand Down Expand Up @@ -1120,6 +1130,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"buildCommand": "node --invalid",␊
"buildCommandOrigin": "config",␊
"configPath": "packages/build/tests/monitor/fixtures/command/netlify.toml"␊
Expand Down Expand Up @@ -1199,6 +1210,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"buildCommand": "node --invalid",␊
"buildCommandOrigin": "config",␊
"configPath": "packages/build/tests/monitor/fixtures/command/netlify.toml"␊
Expand Down Expand Up @@ -1286,6 +1298,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -1373,6 +1386,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -1461,6 +1475,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"event": "onPreBuild",␊
"packageName": "./plugin.js",␊
"loadedFrom": "local",␊
Expand Down Expand Up @@ -1612,6 +1627,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"format": "eszip",␊
"runtime": "deno",␊
"functionType": "edge"␊
Expand Down Expand Up @@ -1690,6 +1706,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"bundler": "esbuild",␊
"functionName": "trouble",␊
"runtime": "js"␊
Expand Down Expand Up @@ -1781,6 +1798,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"functionName": "trouble",␊
"runtime": "rs"␊
},␊
Expand Down Expand Up @@ -1856,6 +1874,7 @@ Generated by [AVA](https://avajs.dev).
"severity": "info",␊
"unhandled": false,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0",␊
"bundler": "esbuild",␊
"functionName": "trouble",␊
"runtime": "js"␊
Expand Down
Binary file modified packages/build/tests/monitor/snapshots/tests.js.snap
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/build/tests/telemetry/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ Generated by [AVA](https://avajs.dev).
"groupingHash": "Telemetry error/nResponse code: 0",␊
"severity": "error",␊
"unhandled": true,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0"␊
},␊
"pluginPackageJson": false,␊
"BUILD_ID": "0",␊
"other": {␊
Expand Down Expand Up @@ -418,6 +421,9 @@ Generated by [AVA](https://avajs.dev).
"groupingHash": "Telemetry error/nThe operation was aborted due to timeout",␊
"severity": "error",␊
"unhandled": true,␊
"location": {␊
"buildLogs": "https://app.netlify.com/sites/site-name/deploys/0"␊
},␊
"pluginPackageJson": false,␊
"BUILD_ID": "0",␊
"other": {␊
Expand Down
Binary file modified packages/build/tests/telemetry/snapshots/tests.js.snap
Binary file not shown.
1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@netlify/api": "^14.0.19",
"@netlify/headers-parser": "^9.0.3",
"@netlify/redirect-parser": "^15.0.4",
"@sindresorhus/transliterate": "^1.6.0",
"chalk": "^5.0.0",
"cron-parser": "^4.1.0",
"deepmerge": "^4.2.2",
Expand Down
36 changes: 28 additions & 8 deletions packages/config/src/env/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import type { NetlifyAPI } from '@netlify/api'
import transliterate from '@sindresorhus/transliterate'
import omit from 'omit.js'
import { env } from 'node:process'

import { removeFalsy } from '../utils/remove_falsy.js'

import { getEnvelope } from './envelope.js'
import { getGitEnv } from './git.js'

const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
// `site.name` is `undefined` when there is no token or siteId
const DEFAULT_SITE_NAME = 'site-name'
const DEFAULT_SITE_ID = '00000000-0000-0000-0000-000000000000'

// Retrieve this site's environment variable. Also take into account team-wide
// environment variables.
// The buildbot already has the right environment variables. This is mostly
Expand Down Expand Up @@ -111,8 +118,8 @@ const getGeneralEnv = async function ({
const gitEnv = await getGitEnv(buildDir, branch)
const deployUrls = getDeployUrls({ siteInfo: siteInfo as $TSFixMe, branch, deployId })
return removeFalsy({
SITE_ID: id,
SITE_NAME: name,
SITE_ID: id ?? DEFAULT_SITE_ID,
SITE_NAME: name ?? env.SITE_NAME ?? DEFAULT_SITE_NAME, // env.SITE_NAME used in monitor/tests.js
DEPLOY_ID: deployId,
NETLIFY_SKEW_PROTECTION_TOKEN: skewProtectionToken,
BUILD_ID: buildId,
Expand Down Expand Up @@ -150,6 +157,19 @@ const getInternalEnv = function (
)
}

/**
* Function matching the backend logic to slugify strings
* @param str string to slugify
* @returns string
*/
const slugify = (str: string) =>
transliterate(str)
.replace(/[-\u2010\u2012\u2013\u2014\u2015\u2043\u2212\u00ad]/g, '-')
.toLowerCase()
.replace(/[^a-z0-9 ]/g, ' ')
.trim()
.replace(/ +/g, '-')

const getDeployUrls = function ({
siteInfo: {
name = DEFAULT_SITE_NAME,
Expand All @@ -160,17 +180,13 @@ const getDeployUrls = function ({
deployId,
}) {
return {
URL: sslUrl,
URL: sslUrl ?? `https://${name}${NETLIFY_DEFAULT_DOMAIN}`,
REPOSITORY_URL,
DEPLOY_PRIME_URL: `https://${branch}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
DEPLOY_PRIME_URL: `https://${slugify(branch)}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
DEPLOY_URL: `https://${deployId}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
}
}

const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
// `site.name` is `undefined` when there is no token or siteId
const DEFAULT_SITE_NAME = 'site-name'

// Environment variables specified by the user
const getUserEnv = async function ({ api, config, siteInfo, accounts, context }) {
const accountEnv = await getAccountEnv({ api, siteInfo, accounts, context })
Expand Down Expand Up @@ -223,8 +239,12 @@ const READONLY_ENV = [
'CACHED_COMMIT_REF',
'COMMIT_REF',
'CONTEXT',
'DEPLOY_ID',
'DEPLOY_PRIME_URL',
'DEPLOY_URL',
'HEAD',
'REPOSITORY_URL',
'SITE_ID',
'URL',

// CI builds set NETLIFY=true while CLI and programmatic builds set
Expand Down
Loading
Loading