@ms-cloudpack/config 0.28.2 → 0.28.4
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.
- package/lib/createPackageDefinitions.js +1 -1
- package/lib/createPackageDefinitions.js.map +1 -1
- package/lib/createPackageSettingsTransform.d.ts.map +1 -1
- package/lib/createPackageSettingsTransform.js +19 -21
- package/lib/createPackageSettingsTransform.js.map +1 -1
- package/lib/readConfig.d.ts.map +1 -1
- package/lib/readConfig.js +45 -54
- package/lib/readConfig.js.map +1 -1
- package/lib/resolveModule.d.ts +2 -2
- package/lib/resolveModule.js +4 -4
- package/lib/resolveModule.js.map +1 -1
- package/lib/resolveParentConfig.d.ts.map +1 -1
- package/lib/resolveParentConfig.js +2 -1
- package/lib/resolveParentConfig.js.map +1 -1
- package/package.json +5 -4
|
@@ -7,7 +7,7 @@ import { createPackageSettingsTransform } from './createPackageSettingsTransform
|
|
|
7
7
|
export function createPackageDefinitions(params) {
|
|
8
8
|
const { config } = params;
|
|
9
9
|
const packages = new PackageDefinitions(undefined, config);
|
|
10
|
-
packages.registerTransform((newConfig) => createPackageSettingsTransform(newConfig));
|
|
10
|
+
packages.registerTransform((newConfig) => (newConfig ? createPackageSettingsTransform(newConfig) : () => undefined));
|
|
11
11
|
return packages;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=createPackageDefinitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPackageDefinitions.js","sourceRoot":"","sources":["../src/createPackageDefinitions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAmC;IAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC1B,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE3D,QAAQ,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,8BAA8B,CAAC,
|
|
1
|
+
{"version":3,"file":"createPackageDefinitions.js","sourceRoot":"","sources":["../src/createPackageDefinitions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAmC;IAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC1B,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE3D,QAAQ,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,8BAA8B,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAErH,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport { createPackageSettingsTransform } from './createPackageSettingsTransform.js';\n\n/**\n * Given a Cloudpack config, create a package definitions cache with transforms resulting from settings defined\n * within the config.\n */\nexport function createPackageDefinitions(params: { config: CloudpackConfig }): PackageDefinitionsCache {\n const { config } = params;\n const packages = new PackageDefinitions(undefined, config);\n\n packages.registerTransform((newConfig) => (newConfig ? createPackageSettingsTransform(newConfig) : () => undefined));\n\n return packages;\n}\n"]}
|
|
@@ -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;
|
|
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,5 +1,6 @@
|
|
|
1
|
-
import { getPackageSettings } from './getPackageSettings.js';
|
|
2
1
|
import { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';
|
|
2
|
+
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
3
|
+
import { getPackageSettings } from './getPackageSettings.js';
|
|
3
4
|
import { mergePackageSettings } from './mergePackageSettings.js';
|
|
4
5
|
/**
|
|
5
6
|
* Creates a transform to be registered with a PackageDefinitions registry for updating package.json
|
|
@@ -80,36 +81,33 @@ function computeDependencies(options) {
|
|
|
80
81
|
}
|
|
81
82
|
async function computeExports(options, context) {
|
|
82
83
|
const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;
|
|
83
|
-
const { appPath } = context.config;
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
// If this is the app package, ensure the routes are part of the exports map.
|
|
87
|
-
if (appPath === packagePath) {
|
|
88
|
-
const { routes = [] } = context.config;
|
|
84
|
+
const { appPath, routes } = context.config;
|
|
85
|
+
// If this is the app package and it has routes with entries, use those to define the exports map.
|
|
86
|
+
if (slash(appPath) === slash(packagePath) && routes?.length) {
|
|
89
87
|
const routeExports = {};
|
|
90
|
-
let hasRouteExports = false;
|
|
91
88
|
for (const route of routes) {
|
|
92
89
|
const { entry } = route;
|
|
93
|
-
if (entry?.length) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
90
|
+
if (!entry?.length) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
for (const entryItem of entry) {
|
|
94
|
+
await addExportsMapEntry({
|
|
95
|
+
exports: routeExports,
|
|
96
|
+
packagePath,
|
|
97
|
+
environmentCondition: 'browser',
|
|
98
|
+
filePath: entryItem.sourcePath,
|
|
99
|
+
importPath: entryItem.importPath,
|
|
100
|
+
}, context);
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
|
-
|
|
107
|
-
if (hasRouteExports) {
|
|
103
|
+
if (Object.keys(routeExports).length) {
|
|
108
104
|
// We short circuit here because we don't want to include any unused exports that might
|
|
109
105
|
// be pulled from package.json.
|
|
110
106
|
return routeExports;
|
|
111
107
|
}
|
|
112
108
|
}
|
|
109
|
+
// TODO: an array of export objects is not really valid per the spec and most implementations
|
|
110
|
+
const exports = [];
|
|
113
111
|
// Push exports from the package.
|
|
114
112
|
exports.push(userPackageSettings?.exports ||
|
|
115
113
|
definition.exports ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPackageSettingsTransform.js","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAiC,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,MAAuB;IACpE,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;QACrD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;QAErC,MAAM,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,GAAG,kBAAkB,CAAC;YAC3E,IAAI;YACJ,OAAO;YACP,mBAAmB,EAAE,MAAM,CAAC,eAAe;YAC3C,wB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B,UAAU,EAAE,SAAS,CAAC,UAAU;yBACjC,EACD,OAAO,CACR,CAAC,IAAI,eAAe,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;QAED,oEAAoE;QACpE,IAAI,eAAe,EAAE,CAAC;YACpB,uFAAuF;YACvF,+BAA+B;YAC/B,OAAO,YAAY,CAAC;QACtB,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,OAAO,CAAC,IAAI,CACV,mBAAmB,EAAE,OAAO;QAC1B,UAAU,CAAC,OAAO;QAClB,CAAC,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAC3E,CAAC;IAEF,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,OAAO,SAAS,CAAC;IACnB,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 { getPackageSettings, type GetPackageSettingsResult } from './getPackageSettings.js';\nimport { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';\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 } = context.config;\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, ensure the routes are part of the exports map.\n if (appPath === packagePath) {\n const { routes = [] } = context.config;\n const routeExports: PackageJsonExportsObject = {};\n let hasRouteExports = false;\n\n for (const route of routes) {\n const { entry } = route as RenderedRoute;\n\n if (entry?.length) {\n for (const entryItem of entry) {\n hasRouteExports =\n (await addExportsMapEntry(\n {\n exports: routeExports,\n packagePath,\n environmentCondition: 'browser',\n filePath: entryItem.sourcePath,\n importPath: entryItem.importPath,\n },\n context,\n )) || hasRouteExports;\n }\n }\n }\n\n // Insert them at the start, so that future exports have precedence.\n if (hasRouteExports) {\n // We short circuit here because we don't want to include any unused exports that might\n // be pulled from package.json.\n return routeExports;\n }\n }\n\n // Push exports from the package.\n exports.push(\n userPackageSettings?.exports ||\n definition.exports ||\n (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 return undefined;\n }\n\n if (exports.length === 1) {\n return exports[0];\n }\n\n return exports;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createP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,CAAC;IACnB,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 // If this is the app package and it has routes with entries, use those to define 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 // We short circuit here because we don't want to include any unused exports that might\n // be pulled from package.json.\n return routeExports;\n }\n }\n\n // TODO: an array of export objects is not really valid per the spec and most implementations\n const exports: PackageJsonExports[] = [];\n\n // Push exports from the package.\n exports.push(\n userPackageSettings?.exports ||\n definition.exports ||\n (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 return undefined;\n }\n\n if (exports.length === 1) {\n return exports[0];\n }\n\n return exports;\n}\n"]}
|
package/lib/readConfig.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readConfig.d.ts","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBxG"}
|
package/lib/readConfig.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { isShorthandBootstrapRoute, isShorthandRenderedRoute } from '@ms-cloudpack/common-types';
|
|
1
2
|
import { readAppConfig } from './readAppConfig.js';
|
|
2
3
|
import { readGeneratedConfig } from './readGeneratedConfig.js';
|
|
3
4
|
import { intermediateToSourcePath, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';
|
|
4
5
|
import { flattenExportsMap } from '@ms-cloudpack/package-utilities';
|
|
5
6
|
import path from 'path';
|
|
6
|
-
import {
|
|
7
|
+
import { readJsonSync } from '@ms-cloudpack/json-utilities';
|
|
7
8
|
/**
|
|
8
9
|
* Reads the config file asynchronously (and merges generated config into the result.)
|
|
9
10
|
*/
|
|
@@ -17,69 +18,59 @@ export async function readConfig(appPath, mode = 'library') {
|
|
|
17
18
|
generatedSnapshot: structuredClone(generatedConfig),
|
|
18
19
|
};
|
|
19
20
|
// Expands all routes which refer to source files into fully transformed route objects.
|
|
20
|
-
|
|
21
|
+
const routes = appConfig.routes;
|
|
22
|
+
if (routes?.length) {
|
|
23
|
+
config.routes = expandRoutes(routes, appPath);
|
|
24
|
+
}
|
|
21
25
|
return config;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
|
-
* Ensure all source entries in
|
|
28
|
+
* Ensure all source entries in routes are expanded to fully qualified entry paths.
|
|
25
29
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const renderedRoute = route;
|
|
35
|
-
renderedRoute.entry = ensureArray(shorthandRoute.entry)?.map((filePath) => expandRouteEntry({
|
|
36
|
-
filePath,
|
|
37
|
-
appPath,
|
|
38
|
-
}));
|
|
30
|
+
function expandRoutes(routes, appPath) {
|
|
31
|
+
// Cached flattened exports for appPath, used to expand deprecated exportEntry props if present
|
|
32
|
+
let flattenedExports;
|
|
33
|
+
return routes.map((route) => {
|
|
34
|
+
if (!isShorthandRenderedRoute(route) && !isShorthandBootstrapRoute(route)) {
|
|
35
|
+
// Skip extra processing for other route types.
|
|
36
|
+
return route;
|
|
37
|
+
}
|
|
39
38
|
// eslint-disable-next-line etc/no-deprecated
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
const { entry, exportEntry, ...rest } = route;
|
|
40
|
+
const renderedRoute = rest;
|
|
41
|
+
if (entry?.length) {
|
|
42
|
+
// Expand the entry to full info about the file path.
|
|
43
|
+
renderedRoute.entry = expandEntry(entry, appPath);
|
|
44
|
+
}
|
|
45
|
+
if (exportEntry) {
|
|
46
|
+
// Handle backwards compatibility with moving from exportEntry to entry.
|
|
47
|
+
flattenedExports ??= getFlattenedExports(appPath);
|
|
48
|
+
const filePath = flattenedExports[exportEntry];
|
|
49
|
+
if (!filePath) {
|
|
50
|
+
throw new Error(`A route referenced exportEntry "${exportEntry}" but this couldn't be resolved from the package.json.`);
|
|
45
51
|
}
|
|
46
|
-
|
|
52
|
+
const expanded = expandRouteEntry({ importPath: exportEntry, filePath, appPath });
|
|
53
|
+
console.warn('The route property "exportEntry" is deprecated. Update your route as follows:', JSON.stringify({ ...renderedRoute, entry: expanded.sourcePath }, null, 2));
|
|
54
|
+
(renderedRoute.entry ??= []).push(expanded);
|
|
47
55
|
}
|
|
48
|
-
|
|
56
|
+
return renderedRoute;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function expandEntry(entry, appPath) {
|
|
60
|
+
entry = Array.isArray(entry) ? entry : entry !== undefined ? [entry] : [];
|
|
61
|
+
return entry.map((filePath) => expandRouteEntry({ filePath, appPath }));
|
|
49
62
|
}
|
|
50
63
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
64
|
+
* Get flattened exports from package.json at `appPath`.
|
|
65
|
+
* If there's no export for `.`, it will be filled in from `module || main`.
|
|
53
66
|
*/
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
renderedRoute.entry = ensureArray(renderedRoute.entry);
|
|
62
|
-
const filePath = flattenedExports[exportEntry] || definition.module || definition.main;
|
|
63
|
-
if (!filePath) {
|
|
64
|
-
throw new Error(`A route referenced exportEntry "${exportEntry}" but this couldn't be resolved from the package.json.`);
|
|
65
|
-
}
|
|
66
|
-
// We are converting the exportEntry to an ExpandedSourcePath so that the route
|
|
67
|
-
// can be returned as a RenderedRoute.
|
|
68
|
-
renderedRoute.entry.push(expandRouteEntry({
|
|
69
|
-
importPath: exportEntry,
|
|
70
|
-
filePath,
|
|
71
|
-
appPath,
|
|
72
|
-
}));
|
|
73
|
-
// eslint-disable-next-line etc/no-deprecated
|
|
74
|
-
delete shorthandRoute.exportEntry;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/** Ensures the value is an array, or is wrapped in one. If a value is blank, will return a blank array. */
|
|
78
|
-
function ensureArray(value) {
|
|
79
|
-
if (Array.isArray(value)) {
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
return (value !== undefined ? [value] : []);
|
|
67
|
+
function getFlattenedExports(appPath) {
|
|
68
|
+
// We can't use PackageDefinitions.get here because we're reading the config, and definitions
|
|
69
|
+
// cache requires config resulting in a cycle.
|
|
70
|
+
const definition = readJsonSync(path.join(appPath, 'package.json')) || {};
|
|
71
|
+
const flatExports = flattenExportsMap(definition.exports || {});
|
|
72
|
+
flatExports['.'] ??= definition.module || definition.main;
|
|
73
|
+
return flatExports;
|
|
83
74
|
}
|
|
84
75
|
/** Expands shorthand route entries into fully qualified ones. */
|
|
85
76
|
function expandRouteEntry(options) {
|
package/lib/readConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"
|
|
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,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A6F;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,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,UAAU,CAAC,CAAC;IAE9D,OAAO;QACL,mCAAmC;QACnC,UAAU;QACV,gCAAgC;QAChC,UAAU,EAAE,UAAU,IAAI,gBAAgB;QAC1C,kCAAkC;QAClC,WAAW,EAAE,gBAAgB;KAC9B,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';\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 deprecated exportEntry props if present\n let flattenedExports: Record<string, string | undefined> | undefined;\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);\n }\n\n if (exportEntry) {\n // Handle backwards compatibility with moving from exportEntry to entry.\n flattenedExports ??= getFlattenedExports(appPath);\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(entry: ShorthandRenderedRoute['entry'], appPath: string): ExpandedSourcePath[] {\n entry = Array.isArray(entry) ? entry : entry !== undefined ? [entry] : [];\n return entry.map((filePath) => expandRouteEntry({ filePath, appPath }));\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 const intermediatePath = sourceToIntermediatePath(sourcePath);\n\n return {\n // Used to derive bundle entry path\n sourcePath,\n // Used to derive import map key\n importPath: importPath || intermediatePath,\n // Used to derive import map value\n requestPath: intermediatePath,\n };\n}\n"]}
|
package/lib/resolveModule.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolve a module specifier to a file
|
|
3
|
-
* @returns - The resolved file
|
|
2
|
+
* Resolve a module specifier to a file url (with protocol ie: file:). Throws if it can't be resolved.
|
|
3
|
+
* @returns - The resolved file url as a string.
|
|
4
4
|
*/
|
|
5
5
|
export declare function resolveModule(params: {
|
|
6
6
|
importSpecifier: string;
|
package/lib/resolveModule.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { moduleResolve } from 'import-meta-resolve';
|
|
2
|
-
import { pathToFileURL
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
3
|
// Conditions used for resolution if the package has an exports map.
|
|
4
4
|
// More could be added later if desired ("default" is implicitly included).
|
|
5
5
|
const conditions = new Set(['import', 'require', 'node']);
|
|
6
6
|
/**
|
|
7
|
-
* Resolve a module specifier to a file
|
|
8
|
-
* @returns - The resolved file
|
|
7
|
+
* Resolve a module specifier to a file url (with protocol ie: file:). Throws if it can't be resolved.
|
|
8
|
+
* @returns - The resolved file url as a string.
|
|
9
9
|
*/
|
|
10
10
|
export function resolveModule(params) {
|
|
11
11
|
const { importSpecifier, parentUrl } = params;
|
|
12
12
|
const resolvedUrl = moduleResolve(importSpecifier, pathToFileURL(parentUrl), conditions);
|
|
13
|
-
return
|
|
13
|
+
return resolvedUrl.toString();
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=resolveModule.js.map
|
package/lib/resolveModule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveModule.js","sourceRoot":"","sources":["../src/resolveModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"resolveModule.js","sourceRoot":"","sources":["../src/resolveModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,oEAAoE;AACpE,2EAA2E;AAC3E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAsD;IAClF,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAE9C,MAAM,WAAW,GAAG,aAAa,CAAC,eAAe,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;IACzF,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;AAChC,CAAC","sourcesContent":["import { moduleResolve } from 'import-meta-resolve';\nimport { pathToFileURL } from 'url';\n\n// Conditions used for resolution if the package has an exports map.\n// More could be added later if desired (\"default\" is implicitly included).\nconst conditions = new Set(['import', 'require', 'node']);\n\n/**\n * Resolve a module specifier to a file url (with protocol ie: file:). Throws if it can't be resolved.\n * @returns - The resolved file url as a string.\n */\nexport function resolveModule(params: { importSpecifier: string; parentUrl: string }): string {\n const { importSpecifier, parentUrl } = params;\n\n const resolvedUrl = moduleResolve(importSpecifier, pathToFileURL(parentUrl), conditions);\n return resolvedUrl.toString();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveParentConfig.d.ts","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveParentConfig.d.ts","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,MAAM,GAAG,SAAS,CAUrB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
1
2
|
import { resolveModule } from './resolveModule.js';
|
|
2
3
|
/**
|
|
3
4
|
* Resolve an import specifier for a parent config file.
|
|
@@ -6,7 +7,7 @@ import { resolveModule } from './resolveModule.js';
|
|
|
6
7
|
export function resolveParentConfig(params) {
|
|
7
8
|
const { importSpecifier } = params;
|
|
8
9
|
try {
|
|
9
|
-
return resolveModule({ importSpecifier, parentUrl: params.configPath });
|
|
10
|
+
return fileURLToPath(resolveModule({ importSpecifier, parentUrl: params.configPath }));
|
|
10
11
|
}
|
|
11
12
|
catch (err) {
|
|
12
13
|
console.warn(`Error resolving config "extends": "${importSpecifier}": ${err.message || err}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveParentConfig.js","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAKnC;IACC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAEnC,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveParentConfig.js","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAKnC;IACC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAEnC,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,aAAa,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACzF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,sCAAsC,eAAe,MAAO,GAAa,CAAC,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3G,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { fileURLToPath } from 'url';\nimport { resolveModule } from './resolveModule.js';\n\n/**\n * Resolve an import specifier for a parent config file.\n * Returns undefined if it can't be resolved or doesn't exist.\n */\nexport function resolveParentConfig(params: {\n /** Path of the config file being processed. */\n configPath: string;\n /** The import specifier for the parent (extends) config file. */\n importSpecifier: string;\n}): string | undefined {\n const { importSpecifier } = params;\n\n try {\n return fileURLToPath(resolveModule({ importSpecifier, parentUrl: params.configPath }));\n } catch (err) {\n console.warn(`Error resolving config \"extends\": \"${importSpecifier}\": ${(err as Error).message || err}`);\n }\n\n return undefined;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.4",
|
|
4
4
|
"description": "Configuration handling for cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.19.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.19.3",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.7",
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^10.0.
|
|
20
|
-
"@ms-cloudpack/path-
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^10.0.3",
|
|
20
|
+
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^2.7.40",
|
|
21
22
|
"import-meta-resolve": "^4.0.0",
|
|
22
23
|
"semver": "^7.6.0"
|
|
23
24
|
},
|