Skip to content
Merged
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
1 change: 0 additions & 1 deletion packages/build/tests/core/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ Generated by [AVA](https://avajs.dev).

`{␊
"accounts": [],␊
"addons": [],␊
"branch": "branch",␊
"buildDir": "packages/build/tests/core/fixtures/basereldir/base",␊
"config": {␊
Expand Down
Binary file modified packages/build/tests/core/snapshots/tests.js.snap
Binary file not shown.
29 changes: 9 additions & 20 deletions packages/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const exampleFunction = async function () {
// },
// ...
// ],
// "addons": [],
// "env": {
// "NODE_VERSION": { "sources": ["configFile"], "value": "16" },
// ...
Expand Down Expand Up @@ -117,7 +116,7 @@ Path to the `netlify.toml`. It is either an absolute path or a path relative to
If not specified, it is searched in the following directories (by highest priority order):

- `base` directory
- [`repositoryRoot`](#repositoryRoot)
- [`repositoryRoot`](#repositoryroot)
- current directory
- any parent directory

Expand Down Expand Up @@ -205,7 +204,7 @@ _Default value_: environment variable `NETLIFY_SITE_ID`

Netlify Site ID.

This is used to retrieve [`siteInfo`](#siteinfo), [`accounts`](#accounts) and [`addons`](#addons).
This is used to retrieve [`siteInfo`](#siteinfo) and [`accounts`](#accounts).

#### env

Expand All @@ -227,8 +226,8 @@ What is calling `@netlify/config`. Can be:

This is used for the following cases:

- if `mode` is `buildbot`, [`siteInfo`](#siteinfo), [`accounts`](#accounts) and [`addons`](#addons) are not retrieved
because they are also passed using another internal option.
- if `mode` is `buildbot`, [`siteInfo`](#siteinfo) and [`accounts`](#accounts) are not retrieved because they are also
passed using another internal option.

#### defaultConfig

Expand Down Expand Up @@ -287,13 +286,13 @@ _Type_: `string`
Absolute path to the build directory.

The build directory is the current directory in which most build operations, including the build command, execute. It is
usually either the [`repositoryRoot`](#repositoryRoot) or (if specified) the `base` directory.
usually either the [`repositoryRoot`](#repositoryroot) or (if specified) the `base` directory.

#### repositoryRoot

_Type_: `string`

The computed value of [`repositoryRoot`](#repositoryRoot).
The computed value of [`repositoryRoot`](#repositoryroot).

#### context

Expand Down Expand Up @@ -326,15 +325,6 @@ environment variables.

This might be empty depending on the options passed.

#### addons

_Type_: `object[]`

Netlify addons retrieved using the `listServiceInstancesForSite` Netlify API endpoint. This is used to retrieve
addon-specific environment variables.

This might be empty depending on the options passed.

#### token

_Type_: `string`
Expand All @@ -346,8 +336,8 @@ variables.

_Type_: `NetlifyClient?`

Netlify [JavaScript client instance](https://github.com/netlify/js-client) used to retrieve [`siteInfo`](#siteinfo),
[`accounts`](#accounts) and [`addons`](#addons).
Copy link
Contributor

Choose a reason for hiding this comment

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

I did a humio search for path="/api/v1/sites/*/service-instances" and have a handful of requests with ua=netlify/js-client. Are they not coming from this repository? Do you have a sense of where they are coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are other consumers of the netlify package, so it's hard to say. Certainly at least some of those requests are originating from this repository (I'm removing the code that performs these requests), but I think the more salient question is: Is anyone using the data returned from this query? (Eduardo seems to think no (internal link))

If anyone actually is relying on this data, I've laid out the migration path. (I'd also be happy to help contribute changes if someone can tell me where we're using this data.) But as far as I've been able to figure out, this is just vestigial code.

Netlify [JavaScript client instance](https://github.com/netlify/js-client) used to retrieve [`siteInfo`](#siteinfo) and
[`accounts`](#accounts).

#### logs

Expand All @@ -365,14 +355,13 @@ Site's environment variables. Each environment variable value is an object with
- `sources` `string[]` among:
- `general`: general environment variables set for all sites
- `account`: environment variables set in the Netlify UI for a specific account
- `addons`: addon-specific environment variables
- `ui`: environment variables set in the Netlify UI for a specific site
- `configFile`: environment variables set in `netlify.toml`

# Usage (CLI)

```bash
$ netlify-config
netlify-config
```

Like [`resolveConfig()`](resolveconfig), but in the CLI. The return value is printed on `stdout`.
Expand Down
20 changes: 3 additions & 17 deletions packages/config/src/api/site_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ export const getSiteInfo = async function ({
})
: []

return { siteInfo, accounts: [], addons: [], integrations }
return { siteInfo, accounts: [], integrations }
}

const [siteInfo, accounts, addons, integrations] = await Promise.all([
const [siteInfo, accounts, integrations] = await Promise.all([
getSite(api, siteId, siteFeatureFlagPrefix),
getAccounts(api),
getAddons(api, siteId),
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl, mode }),
])

Expand All @@ -87,7 +86,7 @@ export const getSiteInfo = async function ({
siteInfo.build_settings.env = envelope
}

return { siteInfo, accounts, addons, integrations }
return { siteInfo, accounts, integrations }
}

const getSite = async function (api: NetlifyAPI, siteId: string, siteFeatureFlagPrefix: string) {
Expand Down Expand Up @@ -128,19 +127,6 @@ const getAccounts = async function (api: NetlifyAPI): Promise<MinimalAccount[]>
}
}

const getAddons = async function (api: NetlifyAPI, siteId: string) {
if (siteId === undefined) {
return []
}

try {
const addons = await (api as any).listServiceInstancesForSite({ siteId })
return Array.isArray(addons) ? addons : []
} catch (error) {
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
}
}

type GetIntegrationsOpts = {
siteId?: string
accountId?: string
Expand Down
21 changes: 4 additions & 17 deletions packages/config/src/env/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getEnvelope } from './envelope.js'
import { getGitEnv } from './git.js'

// Retrieve this site's environment variable. Also take into account team-wide
// environment variables and addons.
// environment variables.
// The buildbot already has the right environment variables. This is mostly
// meant so that local builds can mimic production builds
// TODO: add `netlify.toml` `build.environment`, after normalization
Expand All @@ -18,7 +18,6 @@ export const getEnv = async function ({
config,
siteInfo,
accounts,
addons,
buildDir,
branch,
deployId,
Expand All @@ -32,20 +31,18 @@ export const getEnv = async function ({

const internalEnv = getInternalEnv(cachedEnv)
const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context })
const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({
const [accountEnv, uiEnv, configFileEnv] = await getUserEnv({
api,
config,
siteInfo,
accounts,
addons,
context,
})

// Sources of environment variables, in descending order of precedence.
const sources = [
{ key: 'configFile', values: configFileEnv },
{ key: 'ui', values: uiEnv },
{ key: 'addons', values: addonsEnv },
{ key: 'account', values: accountEnv },
{ key: 'general', values: generalEnv },
{ key: 'internal', values: internalEnv },
Expand Down Expand Up @@ -164,12 +161,11 @@ const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
const DEFAULT_SITE_NAME = 'site-name'

// Environment variables specified by the user
const getUserEnv = async function ({ api, config, siteInfo, accounts, addons, context }) {
const getUserEnv = async function ({ api, config, siteInfo, accounts, context }) {
const accountEnv = await getAccountEnv({ api, siteInfo, accounts, context })
const addonsEnv = getAddonsEnv(addons)
const uiEnv = getUiEnv({ siteInfo })
const configFileEnv = getConfigFileEnv({ config })
return [accountEnv, addonsEnv, uiEnv, configFileEnv].map(cleanUserEnv)
return [accountEnv, uiEnv, configFileEnv].map(cleanUserEnv)
}

// Account-wide environment variables
Expand All @@ -191,15 +187,6 @@ const getAccountEnv = async function ({
return siteEnv
}

// Environment variables from addons
const getAddonsEnv = function (addons) {
return Object.assign({}, ...addons.map(getAddonEnv))
}

const getAddonEnv = function ({ env }) {
return env
}

// Site-specific environment variables set in the UI
const getUiEnv = function ({ siteInfo: { build_settings: { env = {} } = {} } }) {
return env
Expand Down
12 changes: 3 additions & 9 deletions packages/config/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { getRedirectsPath, addRedirects } from './redirects.js'

export type Config = {
accounts: MinimalAccount[] | undefined
addons: any
api: any
branch: any
buildDir: any
Expand Down Expand Up @@ -99,16 +98,14 @@ export const resolveConfig = async function (opts): Promise<Config> {
featureFlags,
} = await normalizeOpts(optsA)

let { siteInfo, accounts, addons, integrations } = parsedCachedConfig || {}
let { siteInfo, accounts, integrations } = parsedCachedConfig || {}

// If we have cached site info, we don't need to fetch it again
const useCachedSiteInfo = Boolean(
featureFlags?.use_cached_site_info && siteInfo && accounts && addons && integrations,
)
const useCachedSiteInfo = Boolean(featureFlags?.use_cached_site_info && siteInfo && accounts && integrations)

// I'm adding some debug logging to see if the logic is working as expected
if (featureFlags?.use_cached_site_info_logging) {
console.log('Checking site information', { useCachedSiteInfo, siteInfo, accounts, addons, integrations })
console.log('Checking site information', { useCachedSiteInfo, siteInfo, accounts, integrations })
}

if (!useCachedSiteInfo) {
Expand All @@ -128,7 +125,6 @@ export const resolveConfig = async function (opts): Promise<Config> {

siteInfo = updatedSiteInfo.siteInfo
accounts = updatedSiteInfo.accounts
addons = updatedSiteInfo.addons
integrations = updatedSiteInfo.integrations
}

Expand Down Expand Up @@ -162,7 +158,6 @@ export const resolveConfig = async function (opts): Promise<Config> {
config,
siteInfo,
accounts,
addons,
buildDir,
branch,
deployId,
Expand All @@ -184,7 +179,6 @@ export const resolveConfig = async function (opts): Promise<Config> {
siteInfo,
integrations: mergedIntegrations,
accounts,
addons,
env,
configPath,
redirectsPath,
Expand Down
Loading
Loading