Skip to content
Merged
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/build/src/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { readFile } from 'fs/promises'
import { fileURLToPath } from 'url'

import type { PackageJson } from 'read-package-up'

// We know how our package.json looks like, so we can be very specific with the type
// and only add the properties we want to use
export type RootPackageJson = { name: string; version: string }
Expand All @@ -14,7 +13,7 @@ const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', impor
export const importJsonFile = async function (filePath: string): Promise<PackageJson> {
const fileContents = await readFile(filePath, 'utf-8')

return JSON.parse(fileContents)
return JSON.parse(fileContents) as PackageJson
}

export const ROOT_PACKAGE_JSON = (await importJsonFile(ROOT_PACKAGE_JSON_PATH)) as RootPackageJson
5 changes: 4 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "23.0.11",
"description": "Netlify config module",
"type": "module",
"exports": "./lib/index.js",
"exports": {
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to keep this change?

".": "./lib/index.js"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"bin": {
Expand Down Expand Up @@ -77,6 +79,7 @@
"omit.js": "^2.0.2",
"p-locate": "^6.0.0",
"path-type": "^6.0.0",
"read-package-up": "^11.0.0",
"tomlify-j0.4": "^3.0.0",
"validate-npm-package-name": "^5.0.0",
"yaml": "^2.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export async function handleAutoInstallExtensions({
netlifyToken: token,
slug: ext.slug,
hostSiteUrl: ext.hostSiteUrl,
extensionInstallationSource: mode,
})
}),
)
Expand Down
7 changes: 7 additions & 0 deletions packages/config/src/utils/extensions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { EXTENSION_API_BASE_URL } from '../../integrations.js'
import { ModeOption } from '../../types/options.js'
import { ROOT_PACKAGE_JSON } from '../json.js'

const configVersion = ROOT_PACKAGE_JSON.version
Copy link
Member

Choose a reason for hiding this comment

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

nit: This variable feels unnecessary.

export type InstallExtensionResult =
| {
slug: string
Expand All @@ -18,12 +21,15 @@ export const installExtension = async ({
accountId,
slug,
hostSiteUrl,
extensionInstallationSource,
}: {
netlifyToken: string
accountId: string
slug: string
hostSiteUrl: string
extensionInstallationSource: ModeOption
}): Promise<InstallExtensionResult> => {
const userAgent = `Netlify Config (mode:${extensionInstallationSource}) / ${configVersion}`
const extensionOnInstallUrl = new URL('/.netlify/functions/handler/on-install', hostSiteUrl)
const installedResponse = await fetch(extensionOnInstallUrl, {
method: 'POST',
Expand All @@ -32,6 +38,7 @@ export const installExtension = async ({
}),
headers: {
'netlify-token': netlifyToken,
'User-Agent': userAgent,
},
})

Expand Down
19 changes: 19 additions & 0 deletions packages/config/src/utils/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { readFile } from 'fs/promises'
import { fileURLToPath } from 'url'

import type { PackageJson } from 'read-package-up'
// We know how our package.json looks like, so we can be very specific with the type
// and only add the properties we want to use
export type RootPackageJson = { name: string; version: string }

const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', import.meta.url))

// TODO: Replace with dynamic `import()` once it is supported without
// experimental flags
export const importJsonFile = async function (filePath: string): Promise<PackageJson> {
const fileContents = await readFile(filePath, 'utf-8')

return JSON.parse(fileContents) as PackageJson
}

export const ROOT_PACKAGE_JSON = (await importJsonFile(ROOT_PACKAGE_JSON_PATH)) as RootPackageJson
Loading