diff --git a/package-lock.json b/package-lock.json index 69786b6da0..7b6238d504 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19595,7 +19595,6 @@ "version": "11.0.0", "resolved": "https://registry.npmjs.org/read-package-up/-/read-package-up-11.0.0.tgz", "integrity": "sha512-MbgfoNPANMdb4oRBNg5eqLbB2t2r+o5Ua1pNt8BqGp4I0FJZhuVSOj3PaBPni4azWuSzEdNn2evevzVmEk1ohQ==", - "license": "MIT", "dependencies": { "find-up-simple": "^1.0.0", "read-pkg": "^9.0.0", @@ -24272,6 +24271,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", diff --git a/packages/build/src/utils/json.ts b/packages/build/src/utils/json.ts index 7476b256a8..e704646c07 100644 --- a/packages/build/src/utils/json.ts +++ b/packages/build/src/utils/json.ts @@ -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 } @@ -14,7 +13,7 @@ const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', impor export const importJsonFile = async function (filePath: string): Promise { 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 diff --git a/packages/config/package.json b/packages/config/package.json index a3aa89ab3e..2d3b46dd2d 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -3,7 +3,9 @@ "version": "23.0.11", "description": "Netlify config module", "type": "module", - "exports": "./lib/index.js", + "exports": { + ".": "./lib/index.js" + }, "main": "./lib/index.js", "types": "./lib/index.d.ts", "bin": { @@ -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", diff --git a/packages/config/src/utils/extensions/auto-install-extensions.ts b/packages/config/src/utils/extensions/auto-install-extensions.ts index 07590cf2de..019f4d1044 100644 --- a/packages/config/src/utils/extensions/auto-install-extensions.ts +++ b/packages/config/src/utils/extensions/auto-install-extensions.ts @@ -110,6 +110,7 @@ export async function handleAutoInstallExtensions({ netlifyToken: token, slug: ext.slug, hostSiteUrl: ext.hostSiteUrl, + extensionInstallationSource: mode, }) }), ) diff --git a/packages/config/src/utils/extensions/utils.ts b/packages/config/src/utils/extensions/utils.ts index 481b9f079d..4c94a6a2ba 100644 --- a/packages/config/src/utils/extensions/utils.ts +++ b/packages/config/src/utils/extensions/utils.ts @@ -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 export type InstallExtensionResult = | { slug: string @@ -18,12 +21,15 @@ export const installExtension = async ({ accountId, slug, hostSiteUrl, + extensionInstallationSource, }: { netlifyToken: string accountId: string slug: string hostSiteUrl: string + extensionInstallationSource: ModeOption }): Promise => { + const userAgent = `Netlify Config (mode:${extensionInstallationSource}) / ${configVersion}` const extensionOnInstallUrl = new URL('/.netlify/functions/handler/on-install', hostSiteUrl) const installedResponse = await fetch(extensionOnInstallUrl, { method: 'POST', @@ -32,6 +38,7 @@ export const installExtension = async ({ }), headers: { 'netlify-token': netlifyToken, + 'User-Agent': userAgent, }, }) diff --git a/packages/config/src/utils/json.ts b/packages/config/src/utils/json.ts new file mode 100644 index 0000000000..e704646c07 --- /dev/null +++ b/packages/config/src/utils/json.ts @@ -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 { + 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