@netlify/build-info
Advanced tools
Comparing version 7.14.2 to 7.14.3
@@ -32,4 +32,6 @@ import type { PackageJson } from 'read-pkg'; | ||
packageJSON?: PackageJson; | ||
/** The config file that is associated with the framework */ | ||
/** The absolute path to config file that is associated with the framework */ | ||
config?: string; | ||
/** The name of config file that is associated with the framework */ | ||
configName?: string; | ||
}; | ||
@@ -114,3 +116,3 @@ export type FrameworkInfo = ReturnType<Framework['toJSON']>; | ||
export declare function sortFrameworksBasedOnAccuracy(a: DetectedFramework, b: DetectedFramework): number; | ||
/** Merges a list of detection results based on accuracy to get the one with the highest accuracy */ | ||
/** Merges a list of detection results based on accuracy to get the one with the highest accuracy that still contains information provided by all other detections */ | ||
export declare function mergeDetections(detections: Array<Detection | undefined>): Detection | undefined; | ||
@@ -117,0 +119,0 @@ export declare abstract class BaseFramework implements Framework { |
@@ -45,7 +45,19 @@ import { coerce, parse } from 'semver'; | ||
} | ||
/** Merges a list of detection results based on accuracy to get the one with the highest accuracy */ | ||
/** Merges a list of detection results based on accuracy to get the one with the highest accuracy that still contains information provided by all other detections */ | ||
export function mergeDetections(detections) { | ||
return detections | ||
.filter(Boolean) | ||
.sort((a, b) => (a.accuracy > b.accuracy ? -1 : a.accuracy < b.accuracy ? 1 : 0))?.[0]; | ||
const definedDetections = detections | ||
.filter(function isDetection(d) { | ||
return Boolean(d); | ||
}) | ||
.sort((a, b) => (a.accuracy > b.accuracy ? -1 : a.accuracy < b.accuracy ? 1 : 0)); | ||
if (definedDetections.length === 0) { | ||
return; | ||
} | ||
return definedDetections.slice(1).reduce((merged, detection) => { | ||
merged.config = merged.config ?? detection.config; | ||
merged.configName = merged.configName ?? detection.configName; | ||
merged.package = merged.package ?? detection.package; | ||
merged.packageJSON = merged.packageJSON ?? detection.packageJSON; | ||
return merged; | ||
}, definedDetections[0]); | ||
} | ||
@@ -162,2 +174,3 @@ export class BaseFramework { | ||
config, | ||
configName: this.project.fs.basename(config), | ||
}; | ||
@@ -174,9 +187,10 @@ } | ||
async detect() { | ||
// we can force frameworks as well | ||
if (this.detected?.accuracy === Accuracy.Forced) { | ||
return this; | ||
} | ||
const npm = await this.detectNpmDependency(); | ||
const config = await this.detectConfigFile(this.configFiles ?? []); | ||
this.detected = mergeDetections([npm, config]); | ||
this.detected = mergeDetections([ | ||
// we can force frameworks as well | ||
this.detected?.accuracy === Accuracy.Forced ? this.detected : undefined, | ||
npm, | ||
config, | ||
]); | ||
if (this.detected) { | ||
@@ -183,0 +197,0 @@ return this; |
@@ -6,2 +6,3 @@ import { BaseFramework, Category, DetectedFramework, Framework } from './framework.js'; | ||
npmDependencies: string[]; | ||
configFiles: string[]; | ||
category: Category; | ||
@@ -8,0 +9,0 @@ logo: { |
@@ -32,2 +32,3 @@ import { BaseFramework, Category } from './framework.js'; | ||
npmDependencies = ['@shopify/hydrogen']; | ||
configFiles = [...VITE_CONFIG_FILES, ...CLASSIC_COMPILER_CONFIG_FILES]; | ||
category = Category.SSG; | ||
@@ -42,5 +43,3 @@ logo = { | ||
if (this.detected) { | ||
const viteDetection = await this.detectConfigFile(VITE_CONFIG_FILES); | ||
if (viteDetection) { | ||
this.detected = viteDetection; | ||
if (this.detected.configName && VITE_CONFIG_FILES.includes(this.detected.configName)) { | ||
this.dev = VITE_DEV; | ||
@@ -50,5 +49,3 @@ this.build = VITE_BUILD; | ||
} | ||
const classicCompilerDetection = await this.detectConfigFile(CLASSIC_COMPILER_CONFIG_FILES); | ||
if (classicCompilerDetection) { | ||
this.detected = classicCompilerDetection; | ||
else { | ||
this.dev = CLASSIC_COMPILER_DEV; | ||
@@ -58,4 +55,2 @@ this.build = CLASSIC_COMPILER_BUILD; | ||
} | ||
// If neither config file exists, it can't be a valid Hydrogen site for Netlify anyway. | ||
return; | ||
} | ||
@@ -62,0 +57,0 @@ } |
@@ -7,2 +7,3 @@ import { BaseFramework, Category, DetectedFramework, Framework } from './framework.js'; | ||
excludedNpmDependencies: string[]; | ||
configFiles: string[]; | ||
category: Category; | ||
@@ -9,0 +10,0 @@ logo: { |
@@ -43,2 +43,3 @@ import { BaseFramework, Category } from './framework.js'; | ||
excludedNpmDependencies = ['@shopify/hydrogen']; | ||
configFiles = [...VITE_CONFIG_FILES, ...CLASSIC_COMPILER_CONFIG_FILES]; | ||
category = Category.SSG; | ||
@@ -53,5 +54,3 @@ logo = { | ||
if (this.detected) { | ||
const viteDetection = await this.detectConfigFile(VITE_CONFIG_FILES); | ||
if (viteDetection) { | ||
this.detected = viteDetection; | ||
if (this.detected.configName && VITE_CONFIG_FILES.includes(this.detected.configName)) { | ||
this.dev = VITE_DEV; | ||
@@ -61,5 +60,3 @@ this.build = VITE_BUILD; | ||
} | ||
const classicCompilerDetection = await this.detectConfigFile(CLASSIC_COMPILER_CONFIG_FILES); | ||
if (classicCompilerDetection) { | ||
this.detected = classicCompilerDetection; | ||
else { | ||
this.dev = CLASSIC_COMPILER_DEV; | ||
@@ -69,4 +66,2 @@ this.build = CLASSIC_COMPILER_BUILD; | ||
} | ||
// If neither config file exists, it can't be a valid Remix site for Netlify anyway. | ||
return; | ||
} | ||
@@ -73,0 +68,0 @@ } |
@@ -13,2 +13,4 @@ import { Accuracy } from './frameworks/framework.js'; | ||
} | ||
// this indicate that framework's custom "detect" method doesn't honor the forced framework | ||
throw new Error(`Forced framework "${frameworkId}" was not detected.`); | ||
} | ||
@@ -15,0 +17,0 @@ const frameworkIds = frameworkList |
{ | ||
"name": "@netlify/build-info", | ||
"version": "7.14.2", | ||
"version": "7.14.3", | ||
"description": "Build info utility", | ||
@@ -76,3 +76,3 @@ "type": "module", | ||
}, | ||
"gitHead": "e1756a3a7b6a91e5da6fdedf528acfd85c19b66f" | ||
"gitHead": "c7dc1e805b4f9cde9e9d71802aecd052e28221cb" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
327513
6012