|
4 | 4 | * Licensed under the BSD 3-Clause license.
|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6 | 6 | */
|
7 |
| -import * as fs from 'node:fs'; |
8 |
| -import * as path from 'node:path'; |
9 |
| -import { Logger, SfProject, SfProjectJson, Lifecycle } from '@salesforce/core'; |
| 7 | +import { Logger, SfProject, SfProjectJson, Lifecycle, SfError } from '@salesforce/core'; |
10 | 8 | import { deepFreeze } from '../utils/collections';
|
11 | 9 | import { MetadataRegistry } from './types';
|
12 | 10 | import * as registryData from './metadataRegistry.json';
|
| 11 | +import { presetMap } from './presets/presetMap'; |
13 | 12 |
|
14 | 13 | export type RegistryLoadInput = {
|
15 | 14 | /** The project directory to look at sfdx-project.json file
|
@@ -76,14 +75,18 @@ const maybeGetProject = (projectDir?: string): SfProjectJson | undefined => {
|
76 | 75 | };
|
77 | 76 |
|
78 | 77 | const loadPreset = (preset: string): MetadataRegistry => {
|
79 |
| - const pathToCheck = path.join(__dirname, 'presets', `${preset}.json`); |
80 |
| - |
81 |
| - try { |
82 |
| - const rawPreset = fs.readFileSync(pathToCheck, 'utf-8'); |
83 |
| - return JSON.parse(rawPreset) as MetadataRegistry; |
84 |
| - } catch (e) { |
85 |
| - throw new Error(`Failed to load preset ${preset} in ${pathToCheck}`); |
| 78 | + const matchedPreset = presetMap.get(preset); |
| 79 | + if (matchedPreset) { |
| 80 | + return matchedPreset; |
86 | 81 | }
|
| 82 | + throw SfError.create({ |
| 83 | + message: `Failed to load preset "${preset}"`, |
| 84 | + name: 'InvalidPreset', |
| 85 | + actions: [ |
| 86 | + `Use a valid preset. Currently available presets are: [${[...presetMap.keys()].join(', ')}]`, |
| 87 | + 'Updating your CLI may be required to get newer presets', |
| 88 | + ], |
| 89 | + }); |
87 | 90 | };
|
88 | 91 |
|
89 | 92 | const emptyRegistry = {
|
|
0 commit comments