Skip to content

Commit 91d6e49

Browse files
authoredAug 23, 2024··
feat(build): add account id constant to plugins (#5811)
* feat(build): add account id constant to plugins * chore: forgot the test 🤦 * chore: add missing snapshot * chore: types * chore: make tsc happy
1 parent 4ae7f95 commit 91d6e49

File tree

8 files changed

+84
-4
lines changed

8 files changed

+84
-4
lines changed
 

Diff for: ‎packages/build/src/core/constants.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export interface NetlifyPluginConstants {
6363
* the Netlify site ID
6464
*/
6565
SITE_ID: string
66+
/**
67+
* the Netlify account ID
68+
*/
69+
ACCOUNT_ID?: string
6670
/**
6771
* the Netlify API access token
6872
*/
@@ -90,7 +94,7 @@ export const getConstants = async function ({
9094
edgeFunctionsDistDir,
9195
cacheDir,
9296
netlifyConfig,
93-
siteInfo: { id: siteId },
97+
siteInfo: { id: siteId, account_id: accountId },
9498
apiHost,
9599
token,
96100
mode,
@@ -118,6 +122,8 @@ export const getConstants = async function ({
118122
NETLIFY_BUILD_VERSION: ROOT_PACKAGE_JSON.version,
119123
// The Netlify Site ID
120124
SITE_ID: siteId,
125+
// The Netlify Account ID
126+
ACCOUNT_ID: accountId,
121127
// The Netlify API access token
122128
NETLIFY_API_TOKEN: token,
123129
// The Netlify API host
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: test
2+
inputs: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[plugins]]
2+
package = "./plugin"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const onPreBuild = function ({ constants: { ACCOUNT_ID } }) {
2+
console.log(ACCOUNT_ID)
3+
}

Diff for: ‎packages/build/tests/constants/snapshots/tests.js.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Snapshot report for `tests/constants/tests.js`
1+
# Snapshot report for `packages/build/tests/constants/tests.js`
22

33
The actual snapshot is saved in `tests.js.snap`.
44

@@ -1197,6 +1197,60 @@ Generated by [AVA](https://avajs.dev).
11971197
(Netlify Build completed in 1ms)␊
11981198
Build step duration: Netlify Build completed in 1ms`
11991199

1200+
## constants.ACCOUNT_ID
1201+
1202+
> Snapshot 1
1203+
1204+
`␊
1205+
Netlify Build ␊
1206+
────────────────────────────────────────────────────────────────␊
1207+
1208+
> Version␊
1209+
@netlify/build 1.0.0␊
1210+
1211+
> Flags␊
1212+
accountId: test-account␊
1213+
debug: true␊
1214+
repositoryRoot: packages/build/tests/constants/fixtures/account_id␊
1215+
testOpts:␊
1216+
pluginsListUrl: test␊
1217+
silentLingeringProcesses: true␊
1218+
1219+
> Current directory␊
1220+
packages/build/tests/constants/fixtures/account_id␊
1221+
1222+
> Config file␊
1223+
packages/build/tests/constants/fixtures/account_id/netlify.toml␊
1224+
1225+
> Resolved config␊
1226+
build:␊
1227+
publish: packages/build/tests/constants/fixtures/account_id␊
1228+
publishOrigin: default␊
1229+
plugins:␊
1230+
- inputs: {}␊
1231+
origin: config␊
1232+
package: ./plugin␊
1233+
1234+
> Context␊
1235+
production␊
1236+
1237+
> Loading plugins␊
1238+
- ./plugin@1.0.0 from netlify.toml␊
1239+
1240+
./plugin (onPreBuild event) ␊
1241+
────────────────────────────────────────────────────────────────␊
1242+
1243+
test-account␊
1244+
1245+
(./plugin onPreBuild completed in 1ms)␊
1246+
Build step duration: ./plugin onPreBuild completed in 1ms␊
1247+
1248+
Netlify Build Complete ␊
1249+
────────────────────────────────────────────────────────────────␊
1250+
1251+
(Netlify Build completed in 1ms)␊
1252+
Build step duration: Netlify Build completed in 1ms`
1253+
12001254
## constants.IS_LOCAL local
12011255

12021256
> Snapshot 1
69 Bytes
Binary file not shown.

Diff for: ‎packages/build/tests/constants/tests.js

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ test('constants.SITE_ID', async (t) => {
112112
t.snapshot(normalizeOutput(output))
113113
})
114114

115+
test('constants.ACCOUNT_ID', async (t) => {
116+
const output = await new Fixture('./fixtures/account_id').withFlags({ accountId: 'test-account' }).runWithBuild()
117+
t.snapshot(normalizeOutput(output))
118+
})
119+
115120
test('constants.IS_LOCAL local', async (t) => {
116121
const output = await new Fixture('./fixtures/is_local').runWithBuild()
117122
t.snapshot(normalizeOutput(output))

Diff for: ‎packages/zip-it-and-ship-it/src/runtimes/node/parser/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { promises as fs } from 'fs'
22
import { join, relative, resolve } from 'path'
33

44
import { parse } from '@babel/parser'
5-
import type { BinaryExpression, CallExpression, Expression, PrivateName, TemplateLiteral, TSType } from '@babel/types'
5+
import type {
6+
BinaryExpression,
7+
CallExpression,
8+
Expression,
9+
PrivateName,
10+
TemplateLiteral,
11+
TSType,
12+
Program,
13+
} from '@babel/types'
614

715
import { nonNullable } from '../../../utils/non_nullable.js'
816

@@ -120,7 +128,7 @@ const parseSource = (source: string) => {
120128

121129
// Parses a JS/TS source and returns the resulting AST. If there is a parsing
122130
// error, it will get swallowed and `null` will be returned.
123-
export const safelyParseSource = (source: string) => {
131+
export const safelyParseSource = (source: string): Program | null => {
124132
try {
125133
return parseSource(source)
126134
} catch {

0 commit comments

Comments
 (0)
Please sign in to comment.