@ms-cloudpack/config
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -1,3 +0,4 @@ | ||
import type { CloudpackConfig } from './types.js'; | ||
import type { CloudpackConfig, GeneratedConfig } from './types.js'; | ||
export declare const configFileName = "cloudpack.config.json"; | ||
export declare const generatedConfigFileName = "cloudpack.generated.json"; | ||
/** | ||
@@ -7,3 +8,6 @@ * @param cwd - base path of the config file | ||
*/ | ||
export declare function getConfigPath(cwd?: string): string; | ||
export declare function getConfigPath(cwd?: string): { | ||
configPath: string; | ||
overridesPath: string; | ||
}; | ||
/** | ||
@@ -22,12 +26,12 @@ * Reads the config file synchronously | ||
/** | ||
* Writes the config file asynchronously | ||
* Writes generated config. This is used for `init` to provide package overrides needed. | ||
* @param config - updated config object to be written | ||
* @param cwd - base path of the config file | ||
*/ | ||
export declare function writeConfig(config: CloudpackConfig, cwd?: string): Promise<void>; | ||
export declare function writeGeneratedConfig(config: GeneratedConfig, cwd?: string): Promise<void>; | ||
/** | ||
* Writes the config file synchronously | ||
* Writes generated config. This is used for `init` to provide package overrides needed. | ||
* @param config - updated config object to be written | ||
* @param cwd - base path of the config file | ||
*/ | ||
export declare function writeConfigSync(config: CloudpackConfig, cwd?: string): void; | ||
export declare function writeGeneratedConfigSync(config: GeneratedConfig, cwd?: string): void; |
import path from 'path'; | ||
import { readJson, readJsonSync, writeJson, writeJsonSync } from '@ms-cloudpack/json-utilities'; | ||
export const configFileName = 'cloudpack.config.json'; | ||
export const generatedConfigFileName = 'cloudpack.generated.json'; | ||
/** | ||
@@ -10,3 +11,6 @@ * @param cwd - base path of the config file | ||
const basePath = cwd || process.cwd(); | ||
return path.join(basePath, configFileName); | ||
return { | ||
configPath: path.join(basePath, configFileName), | ||
overridesPath: path.join(basePath, generatedConfigFileName), | ||
}; | ||
} | ||
@@ -19,5 +23,9 @@ /** | ||
export function readConfigSync(cwd) { | ||
const filePath = getConfigPath(cwd); | ||
const config = readJsonSync(filePath) || {}; | ||
return config; | ||
const { configPath, overridesPath } = getConfigPath(cwd); | ||
return { | ||
// eslint-disable-next-line no-restricted-syntax | ||
...(readJsonSync(configPath) || {}), | ||
// eslint-disable-next-line no-restricted-syntax | ||
...(readJsonSync(overridesPath) || {}), | ||
}; | ||
} | ||
@@ -30,28 +38,27 @@ /** | ||
export async function readConfig(cwd) { | ||
const filePath = getConfigPath(cwd); | ||
const config = (await readJson(filePath)) || {}; | ||
return config; | ||
const { configPath, overridesPath } = getConfigPath(cwd); | ||
return { | ||
...((await readJson(configPath)) || {}), | ||
...((await readJson(overridesPath)) || {}), | ||
}; | ||
} | ||
/** | ||
* Writes the config file asynchronously | ||
* Writes generated config. This is used for `init` to provide package overrides needed. | ||
* @param config - updated config object to be written | ||
* @param cwd - base path of the config file | ||
*/ | ||
export async function writeConfig(config, cwd) { | ||
const filePath = getConfigPath(cwd); | ||
return writeJson(filePath, { | ||
...config, | ||
}); | ||
export async function writeGeneratedConfig(config, cwd) { | ||
const { overridesPath } = getConfigPath(cwd); | ||
return writeJson(overridesPath, config); | ||
} | ||
/** | ||
* Writes the config file synchronously | ||
* Writes generated config. This is used for `init` to provide package overrides needed. | ||
* @param config - updated config object to be written | ||
* @param cwd - base path of the config file | ||
*/ | ||
export function writeConfigSync(config, cwd) { | ||
const filePath = getConfigPath(cwd); | ||
return writeJsonSync(filePath, { | ||
...config, | ||
}); | ||
export function writeGeneratedConfigSync(config, cwd) { | ||
const { overridesPath } = getConfigPath(cwd); | ||
// eslint-disable-next-line no-restricted-syntax | ||
return writeJsonSync(overridesPath, config); | ||
} | ||
//# sourceMappingURL=config.js.map |
export { configTemplate } from './configTemplate.js'; | ||
export { configFileName, getConfigPath, readConfig, readConfigSync, writeConfig, writeConfigSync } from './config.js'; | ||
export { configFileName, generatedConfigFileName, getConfigPath, readConfig, readConfigSync, writeGeneratedConfig, writeGeneratedConfigSync, } from './config.js'; | ||
export type { CloudpackConfig, DevServer, PackageOverride, Route, TelemetryConfig } from './types.js'; |
export { configTemplate } from './configTemplate.js'; | ||
export { configFileName, getConfigPath, readConfig, readConfigSync, writeConfig, writeConfigSync } from './config.js'; | ||
export { configFileName, generatedConfigFileName, getConfigPath, readConfig, readConfigSync, writeGeneratedConfig, writeGeneratedConfigSync, } from './config.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -68,11 +68,10 @@ import type { PackageJson } from '@ms-cloudpack/bundler-types'; | ||
/** | ||
* Per-application configuration for Cloudpack. | ||
* The merged result of user-provided and generated configuration for Cloudpack. | ||
*/ | ||
export interface CloudpackConfig { | ||
export type CloudpackConfig = UserConfig & GeneratedConfig; | ||
/** | ||
* Per-application user-provided configuration for Cloudpack. | ||
*/ | ||
export interface UserConfig { | ||
/** | ||
* An array of PackageOverride objects, used to provide overrides for packages without modifying their | ||
* definitions directly. This is primarily used for providing exports maps for packages that don't have them. | ||
*/ | ||
packageOverrides?: PackageOverride[]; | ||
/** | ||
* A set of options for configuring how the dev server works. | ||
@@ -97,1 +96,11 @@ */ | ||
} | ||
/** | ||
* Per-application generated configuration for Cloudpack. | ||
*/ | ||
export interface GeneratedConfig { | ||
/** | ||
* An array of PackageOverride objects, used to provide overrides for packages without modifying their | ||
* definitions directly. This is primarily used for providing exports maps for packages that don't have them. | ||
*/ | ||
packageOverrides?: PackageOverride[]; | ||
} |
{ | ||
"name": "@ms-cloudpack/config", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Configuration handling for cloudpack.", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"@ms-cloudpack/bundler-types": "^0.12.0", | ||
"@ms-cloudpack/create-express-app": "^1.3.2", | ||
"@ms-cloudpack/create-express-app": "^1.3.3", | ||
"@ms-cloudpack/json-utilities": "^0.0.6" | ||
@@ -20,0 +20,0 @@ }, |
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
19072
244