@ms-cloudpack/config 0.30.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"createPackageSettingsTransform.d.ts","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAO3B,MAAM,4BAA4B,CAAC;AAMpC;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,GAAG,0BAA0B,CA6ClG"}
1
+ {"version":3,"file":"createPackageSettingsTransform.d.ts","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAO3B,MAAM,4BAA4B,CAAC;AAMpC;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,GAAG,0BAA0B,CA+ClG"}
@@ -15,9 +15,11 @@ export function createPackageSettingsTransform(config) {
15
15
  userPackageSettings: config.packageSettings,
16
16
  generatedPackageSettings: config.generated.packageSettings,
17
17
  });
18
- // Exclude all things not important in preserving within the package.json. This limits what we end up hashing
19
- // when we hash the definition.
18
+ // Exclude all things not important in preserving within the package.json.
19
+ // This limits what we end up hashing when we hash the definition.
20
20
  const { exports, includedDependencies, excludedDependencies, ...settings } = mergePackageSettings([
21
+ // NOTE: If we add any generated settings in the future where the user settings need to
22
+ // take precedence (such as `bundler` maybe), this merging will need to be adjusted.
21
23
  userPackageSettings || {},
22
24
  generatedPackageSettings || {},
23
25
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"createPackageSettingsTransform.js","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;A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AA0B;IAC1B,IAAI,wBAAwB,EAAE,OAAO,EAAE,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,+FAA+F;QAC/F,8FAA8F;QAC9F,mBAAmB;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionTransform,\n PackageDefinitionsCache,\n PackageJson,\n PackageJsonDependencies,\n PackageJsonExports,\n PackageJsonExportsObject,\n RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { getPackageSettings, type GetPackageSettingsResult } from './getPackageSettings.js';\nimport { mergePackageSettings } from './mergePackageSettings.js';\n\n/**\n * Creates a transform to be registered with a PackageDefinitions registry for updating package.json\n * based on package settings from the config.\n */\nexport function createPackageSettingsTransform(config: CloudpackConfig): PackageDefinitionTransform {\n return async ({ definition, packagePath, packages }) => {\n const { name, version } = definition;\n\n const { userPackageSettings, generatedPackageSettings } = getPackageSettings({\n name,\n version,\n userPackageSettings: config.packageSettings,\n generatedPackageSettings: config.generated.packageSettings,\n });\n\n // Exclude all things not important in preserving within the package.json. This limits what we end up hashing\n // when we hash the definition.\n const { exports, includedDependencies, excludedDependencies, ...settings } = mergePackageSettings([\n userPackageSettings || {},\n generatedPackageSettings || {},\n ]);\n\n const newDefinition: PackageJson = {\n name,\n version,\n exports: await computeExports(\n { packagePath, definition, userPackageSettings, generatedPackageSettings },\n { packages, config },\n ),\n dependencies: computeDependencies({ definition, userPackageSettings, generatedPackageSettings }),\n };\n\n if (definition.peerDependencies && !userPackageSettings?.excludedDependencies?.includes('$peerDependencies')) {\n newDefinition.peerDependencies = !excludedDependencies?.length\n ? definition.peerDependencies\n : Object.fromEntries(\n Object.entries(definition.peerDependencies).filter(([dep]) => !excludedDependencies.includes(dep)),\n );\n }\n\n if (config.mode || Object.keys(settings).length > 0) {\n newDefinition.cloudpack = {\n mode: config.mode,\n ...settings,\n };\n }\n\n return newDefinition;\n };\n}\n\nfunction computeDependencies(\n options: GetPackageSettingsResult & {\n definition: PackageJson;\n },\n): PackageJsonDependencies {\n const { definition, userPackageSettings, generatedPackageSettings } = options;\n const { dependencies = {} } = definition;\n const newDependencies = { ...dependencies };\n\n // If we have included dependencies, add them.\n const includedDependencies = [\n ...(userPackageSettings?.includedDependencies || []),\n ...(generatedPackageSettings?.includedDependencies || []),\n ];\n\n // Expand the $devDependencies placeholder to the actual dev dependencies.\n const includeDevDependencies = includedDependencies.indexOf('$devDependencies');\n\n if (includeDevDependencies !== -1) {\n includedDependencies.splice(includeDevDependencies, 1, ...Object.keys(definition.devDependencies || {}));\n }\n\n // Add the dependency from other sources, or use a wildcard.\n for (const dep of includedDependencies) {\n newDependencies[dep] =\n definition.dependencies?.[dep] ||\n definition.devDependencies?.[dep] ||\n definition.peerDependencies?.[dep] ||\n definition.optionalDependencies?.[dep] ||\n '*';\n }\n\n const excludedDependencies = [\n ...(userPackageSettings?.excludedDependencies || []),\n ...(generatedPackageSettings?.excludedDependencies || []),\n ];\n\n // Expand the $peerDependencies placeholder to the actual peer dependencies.\n const excludePeerDependencies = excludedDependencies.indexOf('$peerDependencies');\n\n if (excludePeerDependencies !== -1) {\n // Add peer dependencies to the list of excluded dependencies.\n excludedDependencies.splice(excludePeerDependencies, 1, ...Object.keys(definition.peerDependencies || {}));\n }\n\n for (const dep of excludedDependencies) {\n delete newDependencies[dep];\n }\n\n return newDependencies;\n}\n\nasync function computeExports(\n options: GetPackageSettingsResult & {\n packagePath: string;\n definition: PackageJson;\n },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n): Promise<PackageJsonExports | undefined> {\n const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;\n const { appPath, routes } = context.config;\n\n // TODO: an array of export objects is not really valid per the spec and most implementations\n const exports: PackageJsonExports[] = [];\n\n // If this is the app package and it has routes with entries, use those to create the exports map.\n if (slash(appPath) === slash(packagePath) && routes?.length) {\n const routeExports: PackageJsonExportsObject = {};\n\n for (const route of routes) {\n const { entry } = route as RenderedRoute;\n if (!entry?.length) {\n continue;\n }\n\n for (const entryItem of entry) {\n await addExportsMapEntry(\n {\n exports: routeExports,\n packagePath,\n environmentCondition: 'browser',\n filePath: entryItem.sourcePath,\n importPath: entryItem.importPath,\n },\n context,\n );\n }\n }\n\n if (Object.keys(routeExports).length) {\n // Currently route exports take precedence over all other exports for the app package.\n return routeExports;\n }\n }\n\n // Push exports from the package.\n if (userPackageSettings?.exports !== undefined) {\n // Prefer user settings over the original definition, including respecting null (remove exports).\n if (userPackageSettings.exports !== null) {\n exports.push(userPackageSettings.exports);\n }\n } else if (definition.exports !== undefined) {\n // Or take the original exports if specified (again respecting null)\n if (definition.exports !== null) {\n exports.push(definition.exports);\n }\n } else {\n // Otherwise, generate an exports map from any other given entry points.\n exports.push(await getExportsMap({ packagePath, disableTransforms: true }, context));\n }\n\n // Push generated exports.\n if (generatedPackageSettings?.exports) {\n exports.push(generatedPackageSettings.exports);\n }\n\n if (exports.length === 0) {\n // If nothing was pushed to the array, this means the exports from either user package settings\n // or the original definition must have been null (and we have no route or generated exports),\n // so respect that.\n return null;\n }\n\n if (exports.length === 1) {\n return exports[0];\n }\n\n return exports;\n}\n"]}
1
+ {"version":3,"file":"createPackageSettingsTransform.js","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,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AC,CAAC,CAAC;IACvF,CAAC;IAED,0BAA0B;IAC1B,IAAI,wBAAwB,EAAE,OAAO,EAAE,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,+FAA+F;QAC/F,8FAA8F;QAC9F,mBAAmB;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionTransform,\n PackageDefinitionsCache,\n PackageJson,\n PackageJsonDependencies,\n PackageJsonExports,\n PackageJsonExportsObject,\n RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { getPackageSettings, type GetPackageSettingsResult } from './getPackageSettings.js';\nimport { mergePackageSettings } from './mergePackageSettings.js';\n\n/**\n * Creates a transform to be registered with a PackageDefinitions registry for updating package.json\n * based on package settings from the config.\n */\nexport function createPackageSettingsTransform(config: CloudpackConfig): PackageDefinitionTransform {\n return async ({ definition, packagePath, packages }) => {\n const { name, version } = definition;\n\n const { userPackageSettings, generatedPackageSettings } = getPackageSettings({\n name,\n version,\n userPackageSettings: config.packageSettings,\n generatedPackageSettings: config.generated.packageSettings,\n });\n\n // Exclude all things not important in preserving within the package.json.\n // This limits what we end up hashing when we hash the definition.\n const { exports, includedDependencies, excludedDependencies, ...settings } = mergePackageSettings([\n // NOTE: If we add any generated settings in the future where the user settings need to\n // take precedence (such as `bundler` maybe), this merging will need to be adjusted.\n userPackageSettings || {},\n generatedPackageSettings || {},\n ]);\n\n const newDefinition: PackageJson = {\n name,\n version,\n exports: await computeExports(\n { packagePath, definition, userPackageSettings, generatedPackageSettings },\n { packages, config },\n ),\n dependencies: computeDependencies({ definition, userPackageSettings, generatedPackageSettings }),\n };\n\n if (definition.peerDependencies && !userPackageSettings?.excludedDependencies?.includes('$peerDependencies')) {\n newDefinition.peerDependencies = !excludedDependencies?.length\n ? definition.peerDependencies\n : Object.fromEntries(\n Object.entries(definition.peerDependencies).filter(([dep]) => !excludedDependencies.includes(dep)),\n );\n }\n\n if (config.mode || Object.keys(settings).length > 0) {\n newDefinition.cloudpack = {\n mode: config.mode,\n ...settings,\n };\n }\n\n return newDefinition;\n };\n}\n\nfunction computeDependencies(\n options: GetPackageSettingsResult & {\n definition: PackageJson;\n },\n): PackageJsonDependencies {\n const { definition, userPackageSettings, generatedPackageSettings } = options;\n const { dependencies = {} } = definition;\n const newDependencies = { ...dependencies };\n\n // If we have included dependencies, add them.\n const includedDependencies = [\n ...(userPackageSettings?.includedDependencies || []),\n ...(generatedPackageSettings?.includedDependencies || []),\n ];\n\n // Expand the $devDependencies placeholder to the actual dev dependencies.\n const includeDevDependencies = includedDependencies.indexOf('$devDependencies');\n\n if (includeDevDependencies !== -1) {\n includedDependencies.splice(includeDevDependencies, 1, ...Object.keys(definition.devDependencies || {}));\n }\n\n // Add the dependency from other sources, or use a wildcard.\n for (const dep of includedDependencies) {\n newDependencies[dep] =\n definition.dependencies?.[dep] ||\n definition.devDependencies?.[dep] ||\n definition.peerDependencies?.[dep] ||\n definition.optionalDependencies?.[dep] ||\n '*';\n }\n\n const excludedDependencies = [\n ...(userPackageSettings?.excludedDependencies || []),\n ...(generatedPackageSettings?.excludedDependencies || []),\n ];\n\n // Expand the $peerDependencies placeholder to the actual peer dependencies.\n const excludePeerDependencies = excludedDependencies.indexOf('$peerDependencies');\n\n if (excludePeerDependencies !== -1) {\n // Add peer dependencies to the list of excluded dependencies.\n excludedDependencies.splice(excludePeerDependencies, 1, ...Object.keys(definition.peerDependencies || {}));\n }\n\n for (const dep of excludedDependencies) {\n delete newDependencies[dep];\n }\n\n return newDependencies;\n}\n\nasync function computeExports(\n options: GetPackageSettingsResult & {\n packagePath: string;\n definition: PackageJson;\n },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n): Promise<PackageJsonExports | undefined> {\n const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;\n const { appPath, routes } = context.config;\n\n // TODO: an array of export objects is not really valid per the spec and most implementations\n const exports: PackageJsonExports[] = [];\n\n // If this is the app package and it has routes with entries, use those to create the exports map.\n if (slash(appPath) === slash(packagePath) && routes?.length) {\n const routeExports: PackageJsonExportsObject = {};\n\n for (const route of routes) {\n const { entry } = route as RenderedRoute;\n if (!entry?.length) {\n continue;\n }\n\n for (const entryItem of entry) {\n await addExportsMapEntry(\n {\n exports: routeExports,\n packagePath,\n environmentCondition: 'browser',\n filePath: entryItem.sourcePath,\n importPath: entryItem.importPath,\n },\n context,\n );\n }\n }\n\n if (Object.keys(routeExports).length) {\n // Currently route exports take precedence over all other exports for the app package.\n return routeExports;\n }\n }\n\n // Push exports from the package.\n if (userPackageSettings?.exports !== undefined) {\n // Prefer user settings over the original definition, including respecting null (remove exports).\n if (userPackageSettings.exports !== null) {\n exports.push(userPackageSettings.exports);\n }\n } else if (definition.exports !== undefined) {\n // Or take the original exports if specified (again respecting null)\n if (definition.exports !== null) {\n exports.push(definition.exports);\n }\n } else {\n // Otherwise, generate an exports map from any other given entry points.\n exports.push(await getExportsMap({ packagePath, disableTransforms: true }, context));\n }\n\n // Push generated exports.\n if (generatedPackageSettings?.exports) {\n exports.push(generatedPackageSettings.exports);\n }\n\n if (exports.length === 0) {\n // If nothing was pushed to the array, this means the exports from either user package settings\n // or the original definition must have been null (and we have no route or generated exports),\n // so respect that.\n return null;\n }\n\n if (exports.length === 1) {\n return exports[0];\n }\n\n return exports;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { getConfigPath } from './getConfigPath.js';
8
8
  export { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';
9
9
  export { getPackageSettings } from './getPackageSettings.js';
10
10
  export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
11
- export { readConfig } from './readConfig.js';
11
+ export { readConfig, type ReadConfigOptions } from './readConfig.js';
12
12
  export { readGeneratedConfig } from './readGeneratedConfig.js';
13
13
  export { readAppConfig } from './readAppConfig.js';
14
14
  export { readUserPreferences } from './readUserPreferences.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CA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,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { allUserPreferences } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getCachePath, getLocalCachePath } from './getCachePath.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { readUserPreferences } from './readUserPreferences.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';\nexport { updateUserPreference } from './updateUserPreference.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { allUserPreferences } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getCachePath, getLocalCachePath } from './getCachePath.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig, type ReadConfigOptions } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { readUserPreferences } from './readUserPreferences.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';\nexport { updateUserPreference } from './updateUserPreference.js';\n"]}
@@ -1,4 +1,10 @@
1
- import type { AppConfig } from '@ms-cloudpack/common-types';
1
+ import type { AppConfig, PackageSettings } from '@ms-cloudpack/common-types';
2
+ export interface ReadAppConfigOptions {
3
+ /**
4
+ * Extra package settings to add at the end of user-provided settings (so they take precedence).
5
+ */
6
+ extraPackageSettings?: PackageSettings[];
7
+ }
2
8
  /**
3
9
  * Reads the user config file and merges with any parent configs asynchronously.
4
10
  * Note this is only useful for making modifications to the user config.
@@ -6,5 +12,5 @@ import type { AppConfig } from '@ms-cloudpack/common-types';
6
12
  *
7
13
  * Throws an error if the config file exists but is not valid JSON (or there's some error reading it).
8
14
  */
9
- export declare function readAppConfig(appPath: string): Promise<AppConfig>;
15
+ export declare function readAppConfig(appPath: string, options?: ReadAppConfigOptions): Promise<AppConfig>;
10
16
  //# sourceMappingURL=readAppConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../src/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA8B,MAAM,4BAA4B,CAAC;AAOxF;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAIvE"}
1
+ {"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../src/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA8B,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAOzG,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,oBAAoB,CAAC,EAAE,eAAe,EAAE,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC,CAavG"}
@@ -10,9 +10,15 @@ import { resolveModule } from '@ms-cloudpack/package-utilities';
10
10
  *
11
11
  * Throws an error if the config file exists but is not valid JSON (or there's some error reading it).
12
12
  */
13
- export async function readAppConfig(appPath) {
13
+ export async function readAppConfig(appPath, options) {
14
+ const { extraPackageSettings } = options || {};
14
15
  const { appConfigPath } = getConfigPath(appPath);
15
- return (await readAppConfigInternal(appConfigPath)) || {};
16
+ const config = (await readAppConfigInternal(appConfigPath)) || {};
17
+ if (extraPackageSettings) {
18
+ // Add these last so they take precedence.
19
+ (config.packageSettings ??= []).push(...extraPackageSettings);
20
+ }
21
+ return config;
16
22
  }
17
23
  function tryResolveBundlerCapability(importSpecifier, parentUrl) {
18
24
  try {
@@ -1 +1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ppConfig, BundlerCapabilitiesOptions } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { getConfigPath } from './getConfigPath.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { resolveModule } from '@ms-cloudpack/package-utilities';\n\n/**\n * Reads the user config file and merges with any parent configs asynchronously.\n * Note this is only useful for making modifications to the user config.\n * For a full merged representation of config, use `readConfig` instead.\n *\n * Throws an error if the config file exists but is not valid JSON (or there's some error reading it).\n */\nexport async function readAppConfig(appPath: string): Promise<AppConfig> {\n const { appConfigPath } = getConfigPath(appPath);\n\n return (await readAppConfigInternal(appConfigPath)) || {};\n}\n\nfunction tryResolveBundlerCapability(importSpecifier: string, parentUrl: string) {\n try {\n return resolveModule({ parentUrl, importSpecifier });\n } catch (e) {\n console.warn(`Error resolving bundler capability \"${importSpecifier}\", Error:`, e);\n return undefined;\n }\n}\n\n/**\n * Reads the user config, with any `extends` parent configs merged in.\n * Throws an error if the config file exists but is not valid JSON, or there's some error reading it.\n */\nasync function readAppConfigInternal(configPath: string): Promise<AppConfig | undefined> {\n const AppConfig = await readJson<AppConfig>(configPath, { mode: 'permissive', throwOnError: true });\n if (!AppConfig) {\n return undefined;\n }\n\n // Resolve import specifiers for bundler capabilities registry\n if (AppConfig.bundlerCapabilitiesRegistry) {\n for (const [key, value] of Object.entries(AppConfig.bundlerCapabilitiesRegistry)) {\n const moduleUrl = tryResolveBundlerCapability(value, configPath);\n if (moduleUrl) {\n AppConfig.bundlerCapabilitiesRegistry[key] = moduleUrl;\n }\n }\n }\n\n // PackageSettings's bundlerCapabilities may contain short-hand keys that need to be resolved to full import specifiers before bundler capabilities can be processed\n // This is done by looking up the short-hand keys in the bundlerCapabilitiesRegistry\n // If the short-hand key is not found in the registry, it is assumed to be a full import specifier\n if (AppConfig.packageSettings && AppConfig.bundlerCapabilitiesRegistry) {\n for (const setting of AppConfig.packageSettings) {\n if (setting.bundlerCapabilities) {\n const newBundlerCapabilities: BundlerCapabilitiesOptions = {};\n for (const key in setting.bundlerCapabilities) {\n if (key in AppConfig.bundlerCapabilitiesRegistry) {\n const newKey = AppConfig.bundlerCapabilitiesRegistry[key];\n newBundlerCapabilities[newKey] = setting.bundlerCapabilities[key];\n } else {\n newBundlerCapabilities[key] = setting.bundlerCapabilities[key];\n }\n }\n setting.bundlerCapabilities = newBundlerCapabilities;\n }\n }\n }\n\n const extendsArray = AppConfig.extends\n ? Array.isArray(AppConfig.extends)\n ? AppConfig.extends\n : [AppConfig.extends]\n : [];\n\n // Recursively read any parent config files\n const parentConfigs: AppConfig[] = [];\n for (const importSpecifier of extendsArray) {\n const resolvedPath = resolveParentConfig({ configPath, importSpecifier });\n if (resolvedPath) {\n const parentConfig = await readAppConfigInternal(resolvedPath);\n if (parentConfig) {\n parentConfigs.push(parentConfig);\n }\n }\n }\n\n return processDeprecatedValues(mergeParentConfig({ AppConfig, parentConfigs }));\n}\n\n/**\n * Delete deprecated values and convert them to the new format. (This mutates the `config` object.)\n */\nfunction processDeprecatedValues(config: AppConfig) {\n /* eslint-disable etc/no-deprecated */\n const { devServer, server, packageSettings = [] } = config;\n\n if (devServer) {\n if (server) {\n throw new Error('Cannot have both \"devServer\" and \"server\" in the config file. Use \"server\" only.');\n }\n\n config.server = devServer;\n delete config.devServer;\n }\n\n if (server?.routes) {\n config.routes = server.routes;\n delete server.routes;\n }\n\n for (const setting of packageSettings) {\n if (setting.bundlerType) {\n setting.bundler = setting.bundlerType;\n delete setting.bundlerType;\n }\n }\n\n return config;\n /* eslint-enable etc/no-deprecated */\n}\n"]}
1
+ {"version":3,"file":"readAppConfig.js","sourceRoot":"","sources":["../src/readAppConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC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AAqC;AACvC,CAAC","sourcesContent":["import type { AppConfig, BundlerCapabilitiesOptions, PackageSettings } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { getConfigPath } from './getConfigPath.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { resolveModule } from '@ms-cloudpack/package-utilities';\n\nexport interface ReadAppConfigOptions {\n /**\n * Extra package settings to add at the end of user-provided settings (so they take precedence).\n */\n extraPackageSettings?: PackageSettings[];\n}\n\n/**\n * Reads the user config file and merges with any parent configs asynchronously.\n * Note this is only useful for making modifications to the user config.\n * For a full merged representation of config, use `readConfig` instead.\n *\n * Throws an error if the config file exists but is not valid JSON (or there's some error reading it).\n */\nexport async function readAppConfig(appPath: string, options?: ReadAppConfigOptions): Promise<AppConfig> {\n const { extraPackageSettings } = options || {};\n\n const { appConfigPath } = getConfigPath(appPath);\n\n const config = (await readAppConfigInternal(appConfigPath)) || {};\n\n if (extraPackageSettings) {\n // Add these last so they take precedence.\n (config.packageSettings ??= []).push(...extraPackageSettings);\n }\n\n return config;\n}\n\nfunction tryResolveBundlerCapability(importSpecifier: string, parentUrl: string) {\n try {\n return resolveModule({ parentUrl, importSpecifier });\n } catch (e) {\n console.warn(`Error resolving bundler capability \"${importSpecifier}\", Error:`, e);\n return undefined;\n }\n}\n\n/**\n * Reads the user config, with any `extends` parent configs merged in.\n * Throws an error if the config file exists but is not valid JSON, or there's some error reading it.\n */\nasync function readAppConfigInternal(configPath: string): Promise<AppConfig | undefined> {\n const AppConfig = await readJson<AppConfig>(configPath, { mode: 'permissive', throwOnError: true });\n if (!AppConfig) {\n return undefined;\n }\n\n // Resolve import specifiers for bundler capabilities registry\n if (AppConfig.bundlerCapabilitiesRegistry) {\n for (const [key, value] of Object.entries(AppConfig.bundlerCapabilitiesRegistry)) {\n const moduleUrl = tryResolveBundlerCapability(value, configPath);\n if (moduleUrl) {\n AppConfig.bundlerCapabilitiesRegistry[key] = moduleUrl;\n }\n }\n }\n\n // PackageSettings's bundlerCapabilities may contain short-hand keys that need to be resolved to full import specifiers before bundler capabilities can be processed\n // This is done by looking up the short-hand keys in the bundlerCapabilitiesRegistry\n // If the short-hand key is not found in the registry, it is assumed to be a full import specifier\n if (AppConfig.packageSettings && AppConfig.bundlerCapabilitiesRegistry) {\n for (const setting of AppConfig.packageSettings) {\n if (setting.bundlerCapabilities) {\n const newBundlerCapabilities: BundlerCapabilitiesOptions = {};\n for (const key in setting.bundlerCapabilities) {\n if (key in AppConfig.bundlerCapabilitiesRegistry) {\n const newKey = AppConfig.bundlerCapabilitiesRegistry[key];\n newBundlerCapabilities[newKey] = setting.bundlerCapabilities[key];\n } else {\n newBundlerCapabilities[key] = setting.bundlerCapabilities[key];\n }\n }\n setting.bundlerCapabilities = newBundlerCapabilities;\n }\n }\n }\n\n const extendsArray = AppConfig.extends\n ? Array.isArray(AppConfig.extends)\n ? AppConfig.extends\n : [AppConfig.extends]\n : [];\n\n // Recursively read any parent config files\n const parentConfigs: AppConfig[] = [];\n for (const importSpecifier of extendsArray) {\n const resolvedPath = resolveParentConfig({ configPath, importSpecifier });\n if (resolvedPath) {\n const parentConfig = await readAppConfigInternal(resolvedPath);\n if (parentConfig) {\n parentConfigs.push(parentConfig);\n }\n }\n }\n\n return processDeprecatedValues(mergeParentConfig({ AppConfig, parentConfigs }));\n}\n\n/**\n * Delete deprecated values and convert them to the new format. (This mutates the `config` object.)\n */\nfunction processDeprecatedValues(config: AppConfig) {\n /* eslint-disable etc/no-deprecated */\n const { devServer, server, packageSettings = [] } = config;\n\n if (devServer) {\n if (server) {\n throw new Error('Cannot have both \"devServer\" and \"server\" in the config file. Use \"server\" only.');\n }\n\n config.server = devServer;\n delete config.devServer;\n }\n\n if (server?.routes) {\n config.routes = server.routes;\n delete server.routes;\n }\n\n for (const setting of packageSettings) {\n if (setting.bundlerType) {\n setting.bundler = setting.bundlerType;\n delete setting.bundlerType;\n }\n }\n\n return config;\n /* eslint-enable etc/no-deprecated */\n}\n"]}
@@ -1,6 +1,14 @@
1
1
  import type { BundleMode, CloudpackConfig } from '@ms-cloudpack/common-types';
2
+ import { type ReadAppConfigOptions } from './readAppConfig.js';
3
+ export interface ReadConfigOptions extends ReadAppConfigOptions {
4
+ /**
5
+ * Override bundle mode.
6
+ * @default 'library'
7
+ */
8
+ mode?: BundleMode;
9
+ }
2
10
  /**
3
11
  * Reads the config file asynchronously (and merges generated config into the result.)
4
12
  */
5
- export declare function readConfig(appPath: string, mode?: BundleMode): Promise<CloudpackConfig>;
13
+ export declare function readConfig(appPath: string, options?: ReadConfigOptions): Promise<CloudpackConfig>;
6
14
  //# sourceMappingURL=readConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"readConfig.d.ts","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EAOhB,MAAM,4BAA4B,CAAC;AAgBpC;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBxG"}
1
+ {"version":3,"file":"readConfig.d.ts","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EAOhB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAc9E,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;IAC7D;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,CAuBvG"}
package/lib/readConfig.js CHANGED
@@ -9,8 +9,12 @@ import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
9
9
  /**
10
10
  * Reads the config file asynchronously (and merges generated config into the result.)
11
11
  */
12
- export async function readConfig(appPath, mode = 'library') {
13
- const [appConfig, generatedConfig] = await Promise.all([readAppConfig(appPath), readGeneratedConfig(appPath)]);
12
+ export async function readConfig(appPath, options) {
13
+ const { mode = 'library', extraPackageSettings } = options || {};
14
+ const [appConfig, generatedConfig] = await Promise.all([
15
+ readAppConfig(appPath, { extraPackageSettings }),
16
+ readGeneratedConfig(appPath),
17
+ ]);
14
18
  const config = {
15
19
  ...appConfig,
16
20
  appPath,
@@ -1 +1 @@
1
- {"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAQ1E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe,EAAE,OAAmB,SAAS;IAC5E,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/G,MAAM,MAAM,GAAG;QACb,GAAG,SAAS;QACZ,OAAO;QACP,IAAI;QACJ,SAAS,EAAE,eAAe;QAC1B,iBAAiB,EAAE,eAAe,CAAC,eAAe,CA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IAC1D,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,iEAAiE;AACjE,SAAS,gBAAgB,CAAC,OAAmE;IAC3F,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,mCAAmC;QACnC,UAAU;QACV,iBAAiB;QACjB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,UAAU,CAAC;KAClG,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BootstrapRoute,\n BundleMode,\n CloudpackConfig,\n ExpandedSourcePath,\n PackageJson,\n RenderedRoute,\n Route,\n ShorthandRenderedRoute,\n ShorthandRoute,\n} from '@ms-cloudpack/common-types';\nimport { isShorthandBootstrapRoute, isShorthandRenderedRoute } from '@ms-cloudpack/common-types';\nimport { readAppConfig } from './readAppConfig.js';\nimport { readGeneratedConfig } from './readGeneratedConfig.js';\nimport { intermediateToSourcePath, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport { flattenExportsMap } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * package.json with only the keys used in this file, since we're missing some logic from\n * PackageDefinitions which is assumed in the full type.\n */\ntype PartialPackageJson = Pick<PackageJson, 'exports' | 'module' | 'main'>;\n\n/**\n * Reads the config file asynchronously (and merges generated config into the result.)\n */\nexport async function readConfig(appPath: string, mode: BundleMode = 'library'): Promise<CloudpackConfig> {\n const [appConfig, generatedConfig] = await Promise.all([readAppConfig(appPath), readGeneratedConfig(appPath)]);\n const config = {\n ...appConfig,\n appPath,\n mode,\n generated: generatedConfig,\n generatedSnapshot: structuredClone(generatedConfig),\n } as CloudpackConfig;\n\n // Expands all routes which refer to source files into fully transformed route objects.\n const routes = appConfig.routes;\n if (routes?.length) {\n config.routes = expandRoutes(routes, appPath);\n }\n\n return config;\n}\n\n/**\n * Ensure all source entries in routes are expanded to fully qualified entry paths.\n */\nfunction expandRoutes(routes: ShorthandRoute[], appPath: string): Route[] {\n // Cached flattened exports for appPath, used to expand entries\n const flattenedExports = getFlattenedExports(appPath);\n\n return routes.map((route) => {\n if (!isShorthandRenderedRoute(route) && !isShorthandBootstrapRoute(route)) {\n // Skip extra processing for other route types.\n return route;\n }\n\n // eslint-disable-next-line etc/no-deprecated\n const { entry, exportEntry, ...rest } = route;\n const renderedRoute: RenderedRoute | BootstrapRoute = rest;\n\n if (entry?.length) {\n // Expand the entry to full info about the file path.\n renderedRoute.entry = expandEntry({ entry, appPath, flattenedExports });\n }\n\n if (exportEntry) {\n // Handle backwards compatibility with moving from exportEntry to entry.\n const filePath = flattenedExports[exportEntry];\n if (!filePath) {\n throw new Error(\n `A route referenced exportEntry \"${exportEntry}\" but this couldn't be resolved from the package.json.`,\n );\n }\n\n const expanded = expandRouteEntry({ importPath: exportEntry, filePath, appPath });\n console.warn(\n 'The route property \"exportEntry\" is deprecated. Update your route as follows:',\n JSON.stringify({ ...renderedRoute, entry: expanded.sourcePath }, null, 2),\n );\n (renderedRoute.entry ??= []).push(expanded);\n }\n\n return renderedRoute;\n });\n}\n\nfunction expandEntry(params: {\n entry: ShorthandRenderedRoute['entry'];\n appPath: string;\n flattenedExports: Record<string, string | undefined>;\n}): ExpandedSourcePath[] {\n const { entry, appPath, flattenedExports } = params;\n const entryArray = Array.isArray(entry) ? entry : entry !== undefined ? [entry] : [];\n\n return entryArray.map((entryPath) =>\n expandRouteEntry({\n // Usually entryPath will be a source path, but also handle if it's an exports map key.\n importPath: flattenedExports[entryPath] ? entryPath : undefined,\n filePath: flattenedExports[entryPath] || entryPath,\n appPath,\n }),\n );\n}\n\n/**\n * Get flattened exports from package.json at `appPath`.\n * If there's no export for `.`, it will be filled in from `module || main`.\n */\nfunction getFlattenedExports(appPath: string): Record<string, string | undefined> {\n // We can't use PackageDefinitions.get here because we're reading the config, and definitions\n // cache requires config resulting in a cycle.\n const definition = readJsonSync<PartialPackageJson>(path.join(appPath, 'package.json')) || {};\n const flatExports: Record<string, string | undefined> = flattenExportsMap(definition.exports || {});\n flatExports['.'] ??= definition.module || definition.main;\n return flatExports;\n}\n\n/** Expands shorthand route entries into fully qualified ones. */\nfunction expandRouteEntry(options: { importPath?: string; filePath: string; appPath: string }): ExpandedSourcePath {\n const { filePath, appPath, importPath } = options;\n const sourcePath = intermediateToSourcePath(filePath, appPath);\n\n if (!sourcePath) {\n throw new Error(`Could not resolve source path for entry: ${filePath}`);\n }\n\n return {\n // Used to derive bundle entry path\n sourcePath,\n // Import map key\n importPath: importPath ? normalizeRelativePath(importPath) : sourceToIntermediatePath(sourcePath),\n };\n}\n"]}
1
+ {"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAgB1E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe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S,CAAC,IAAI,SAAS;QAClD,OAAO;KACR,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,OAAe;IAC1C,6FAA6F;IAC7F,8CAA8C;IAC9C,MAAM,UAAU,GAAG,YAAY,CAAqB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9F,MAAM,WAAW,GAAuC,iBAAiB,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACpG,WAAW,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC;IAC1D,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,iEAAiE;AACjE,SAAS,gBAAgB,CAAC,OAAmE;IAC3F,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,mCAAmC;QACnC,UAAU;QACV,iBAAiB;QACjB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,UAAU,CAAC;KAClG,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BootstrapRoute,\n BundleMode,\n CloudpackConfig,\n ExpandedSourcePath,\n PackageJson,\n RenderedRoute,\n Route,\n ShorthandRenderedRoute,\n ShorthandRoute,\n} from '@ms-cloudpack/common-types';\nimport { isShorthandBootstrapRoute, isShorthandRenderedRoute } from '@ms-cloudpack/common-types';\nimport { readAppConfig, type ReadAppConfigOptions } from './readAppConfig.js';\nimport { readGeneratedConfig } from './readGeneratedConfig.js';\nimport { intermediateToSourcePath, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport { flattenExportsMap } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * package.json with only the keys used in this file, since we're missing some logic from\n * PackageDefinitions which is assumed in the full type.\n */\ntype PartialPackageJson = Pick<PackageJson, 'exports' | 'module' | 'main'>;\n\nexport interface ReadConfigOptions extends ReadAppConfigOptions {\n /**\n * Override bundle mode.\n * @default 'library'\n */\n mode?: BundleMode;\n}\n\n/**\n * Reads the config file asynchronously (and merges generated config into the result.)\n */\nexport async function readConfig(appPath: string, options?: ReadConfigOptions): Promise<CloudpackConfig> {\n const { mode = 'library', extraPackageSettings } = options || {};\n\n const [appConfig, generatedConfig] = await Promise.all([\n readAppConfig(appPath, { extraPackageSettings }),\n readGeneratedConfig(appPath),\n ]);\n\n const config = {\n ...appConfig,\n appPath,\n mode,\n generated: generatedConfig,\n generatedSnapshot: structuredClone(generatedConfig),\n } as CloudpackConfig;\n\n // Expands all routes which refer to source files into fully transformed route objects.\n const routes = appConfig.routes;\n if (routes?.length) {\n config.routes = expandRoutes(routes, appPath);\n }\n\n return config;\n}\n\n/**\n * Ensure all source entries in routes are expanded to fully qualified entry paths.\n */\nfunction expandRoutes(routes: ShorthandRoute[], appPath: string): Route[] {\n // Cached flattened exports for appPath, used to expand entries\n const flattenedExports = getFlattenedExports(appPath);\n\n return routes.map((route) => {\n if (!isShorthandRenderedRoute(route) && !isShorthandBootstrapRoute(route)) {\n // Skip extra processing for other route types.\n return route;\n }\n\n // eslint-disable-next-line etc/no-deprecated\n const { entry, exportEntry, ...rest } = route;\n const renderedRoute: RenderedRoute | BootstrapRoute = rest;\n\n if (entry?.length) {\n // Expand the entry to full info about the file path.\n renderedRoute.entry = expandEntry({ entry, appPath, flattenedExports });\n }\n\n if (exportEntry) {\n // Handle backwards compatibility with moving from exportEntry to entry.\n const filePath = flattenedExports[exportEntry];\n if (!filePath) {\n throw new Error(\n `A route referenced exportEntry \"${exportEntry}\" but this couldn't be resolved from the package.json.`,\n );\n }\n\n const expanded = expandRouteEntry({ importPath: exportEntry, filePath, appPath });\n console.warn(\n 'The route property \"exportEntry\" is deprecated. Update your route as follows:',\n JSON.stringify({ ...renderedRoute, entry: expanded.sourcePath }, null, 2),\n );\n (renderedRoute.entry ??= []).push(expanded);\n }\n\n return renderedRoute;\n });\n}\n\nfunction expandEntry(params: {\n entry: ShorthandRenderedRoute['entry'];\n appPath: string;\n flattenedExports: Record<string, string | undefined>;\n}): ExpandedSourcePath[] {\n const { entry, appPath, flattenedExports } = params;\n const entryArray = Array.isArray(entry) ? entry : entry !== undefined ? [entry] : [];\n\n return entryArray.map((entryPath) =>\n expandRouteEntry({\n // Usually entryPath will be a source path, but also handle if it's an exports map key.\n importPath: flattenedExports[entryPath] ? entryPath : undefined,\n filePath: flattenedExports[entryPath] || entryPath,\n appPath,\n }),\n );\n}\n\n/**\n * Get flattened exports from package.json at `appPath`.\n * If there's no export for `.`, it will be filled in from `module || main`.\n */\nfunction getFlattenedExports(appPath: string): Record<string, string | undefined> {\n // We can't use PackageDefinitions.get here because we're reading the config, and definitions\n // cache requires config resulting in a cycle.\n const definition = readJsonSync<PartialPackageJson>(path.join(appPath, 'package.json')) || {};\n const flatExports: Record<string, string | undefined> = flattenExportsMap(definition.exports || {});\n flatExports['.'] ??= definition.module || definition.main;\n return flatExports;\n}\n\n/** Expands shorthand route entries into fully qualified ones. */\nfunction expandRouteEntry(options: { importPath?: string; filePath: string; appPath: string }): ExpandedSourcePath {\n const { filePath, appPath, importPath } = options;\n const sourcePath = intermediateToSourcePath(filePath, appPath);\n\n if (!sourcePath) {\n throw new Error(`Could not resolve source path for entry: ${filePath}`);\n }\n\n return {\n // Used to derive bundle entry path\n sourcePath,\n // Import map key\n importPath: importPath ? normalizeRelativePath(importPath) : sourceToIntermediatePath(sourcePath),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/config",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "Configuration handling for cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",