@ms-cloudpack/config 0.33.18 → 0.33.20
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/builtInSettings/builtInSettings.d.ts +5 -4
- package/lib/builtInSettings/builtInSettings.d.ts.map +1 -1
- package/lib/packageDefinitions/createPackageSettingsTransform.js +17 -3
- package/lib/packageDefinitions/createPackageSettingsTransform.js.map +1 -1
- package/lib/readConfig/readConfig.js +18 -3
- package/lib/readConfig/readConfig.js.map +1 -1
- package/package.json +4 -4
|
@@ -49,14 +49,15 @@ export declare const builtInSettings: {
|
|
|
49
49
|
readonly bundlerType?: string | undefined;
|
|
50
50
|
readonly ignoredBundlerWarnings?: readonly string[] | undefined;
|
|
51
51
|
readonly bundlerCapabilities?: {
|
|
52
|
-
readonly [x: string]:
|
|
53
|
-
readonly 'asset-inline'?:
|
|
52
|
+
readonly [x: string]: boolean | object;
|
|
53
|
+
readonly 'asset-inline'?: boolean | {
|
|
54
54
|
readonly extensions: readonly string[];
|
|
55
55
|
} | undefined;
|
|
56
|
-
readonly density?:
|
|
57
|
-
readonly alias?:
|
|
56
|
+
readonly density?: boolean | undefined;
|
|
57
|
+
readonly alias?: boolean | {
|
|
58
58
|
readonly [x: string]: string;
|
|
59
59
|
} | undefined;
|
|
60
|
+
readonly 'resolve-web-extensions'?: boolean | undefined;
|
|
60
61
|
} | undefined;
|
|
61
62
|
} | undefined;
|
|
62
63
|
readonly packageJson?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtInSettings.d.ts","sourceRoot":"","sources":["../../src/builtInSettings/builtInSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG/E,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,eAAe,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;IAC7D;;;;O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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgJ1B,CAAC"}
|
|
@@ -78,12 +78,15 @@ function computeDependencies(options) {
|
|
|
78
78
|
}
|
|
79
79
|
async function computeExports(options, context) {
|
|
80
80
|
const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;
|
|
81
|
-
const { appPath, routes } = context.config;
|
|
81
|
+
const { appPath, routes, features } = context.config;
|
|
82
|
+
const resolveWebExtensions = userPackageSettings?.bundlerCapabilities?.['resolve-web-extensions'] ??
|
|
83
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
84
|
+
Boolean(features?.resolveWebExtensions);
|
|
82
85
|
// If this is the app package and it has routes with entries, use those to create the exports map.
|
|
83
86
|
if (slash(appPath) === slash(packagePath) && routes?.length) {
|
|
84
87
|
const routeExports = {};
|
|
85
88
|
for (const route of routes) {
|
|
86
|
-
const { entry } = route;
|
|
89
|
+
const { entry, serverEntry } = route;
|
|
87
90
|
if (!entry?.length) {
|
|
88
91
|
continue;
|
|
89
92
|
}
|
|
@@ -94,6 +97,17 @@ async function computeExports(options, context) {
|
|
|
94
97
|
environmentCondition: 'browser',
|
|
95
98
|
filePath: entryItem.sourcePath,
|
|
96
99
|
importPath: entryItem.importPath,
|
|
100
|
+
resolveWebExtensions,
|
|
101
|
+
}, context);
|
|
102
|
+
}
|
|
103
|
+
if (serverEntry) {
|
|
104
|
+
await addExportsMapEntry({
|
|
105
|
+
exports: routeExports,
|
|
106
|
+
packagePath,
|
|
107
|
+
environmentCondition: 'node',
|
|
108
|
+
filePath: serverEntry.sourcePath,
|
|
109
|
+
importPath: serverEntry.importPath,
|
|
110
|
+
resolveWebExtensions,
|
|
97
111
|
}, context);
|
|
98
112
|
}
|
|
99
113
|
}
|
|
@@ -119,7 +133,7 @@ async function computeExports(options, context) {
|
|
|
119
133
|
}
|
|
120
134
|
else {
|
|
121
135
|
// Otherwise, generate an exports map from any other given entry points.
|
|
122
|
-
exports.push(await getExportsMap({ packagePath, disableTransforms: true }, context));
|
|
136
|
+
exports.push(await getExportsMap({ packagePath, disableTransforms: true, resolveWebExtensions }, context));
|
|
123
137
|
}
|
|
124
138
|
// Push generated exports.
|
|
125
139
|
if (generatedPackageSettings?.exports) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPackageSettingsTransform.js","sourceRoot":"","sources":["../../src/packageDefinitions/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAiC,MAAM,0CAA0C,CAAC;AAC7G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAElF;;;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,m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,EAAE,CAAC;YACrC,sFAAsF;YACtF,OAAO,YAAY,CAAC;QACtB,CAAC;IACH,CAAC;IAED,6FAA6F;IAC7F,MAAM,OAAO,GAAyB,EAAE,CAAC;IAEzC,iCAAiC;IACjC,IAAI,mBAAmB,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QAC/C,iGAAiG;QACjG,IAAI,mBAAmB,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;SAAM,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC5C,oEAAoE;QACpE,IAAI,UAAU,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAChC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,wEAAwE;QACxE,OAAO,CAAC,IAAI,CAAC,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,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 GeneratedExports,\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 '../packageSettings/getPackageSettings.js';\nimport { mergePackageSettings } from '../packageSettings/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 includeBuiltIn: true,\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, includedDependencies, excludedDependencies }),\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(options: {\n definition: PackageJson;\n /** Merged `includedDependencies` from the user, built-in, and generated configs */\n includedDependencies: string[] | undefined;\n /** Merged `excludedDependencies` from the user, built-in, and generated configs */\n excludedDependencies: string[] | undefined;\n}): PackageJsonDependencies {\n const { definition } = options;\n const { dependencies = {} } = definition;\n const newDependencies = { ...dependencies };\n\n // If we have included dependencies, add them.\n const includedDependencies = [...(options.includedDependencies || [])];\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 = [...(options.excludedDependencies || [])];\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 create the exports map.\n if (slash(appPath) === slash(packagePath) && routes?.length) {\n const routeExports: GeneratedExports = {};\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 // 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 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/packageDefinitions/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAiC,MAAM,0CAA0C,CAAC;AAC7G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAElF;;;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,E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C,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 GeneratedExports,\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 '../packageSettings/getPackageSettings.js';\nimport { mergePackageSettings } from '../packageSettings/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 includeBuiltIn: true,\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, includedDependencies, excludedDependencies }),\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(options: {\n definition: PackageJson;\n /** Merged `includedDependencies` from the user, built-in, and generated configs */\n includedDependencies: string[] | undefined;\n /** Merged `excludedDependencies` from the user, built-in, and generated configs */\n excludedDependencies: string[] | undefined;\n}): PackageJsonDependencies {\n const { definition } = options;\n const { dependencies = {} } = definition;\n const newDependencies = { ...dependencies };\n\n // If we have included dependencies, add them.\n const includedDependencies = [...(options.includedDependencies || [])];\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 = [...(options.excludedDependencies || [])];\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, features } = context.config;\n const resolveWebExtensions =\n userPackageSettings?.bundlerCapabilities?.['resolve-web-extensions'] ??\n // eslint-disable-next-line etc/no-deprecated\n Boolean(features?.resolveWebExtensions);\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: GeneratedExports = {};\n\n for (const route of routes) {\n const { entry, serverEntry } = 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 resolveWebExtensions,\n },\n context,\n );\n }\n\n if (serverEntry) {\n await addExportsMapEntry(\n {\n exports: routeExports,\n packagePath,\n environmentCondition: 'node',\n filePath: serverEntry.sourcePath,\n importPath: serverEntry.importPath,\n resolveWebExtensions,\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 // 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 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, resolveWebExtensions }, 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"]}
|
|
@@ -45,12 +45,27 @@ function expandRoutes(routes, appPath) {
|
|
|
45
45
|
return route;
|
|
46
46
|
}
|
|
47
47
|
// eslint-disable-next-line etc/no-deprecated
|
|
48
|
-
const { entry, exportEntry, ...rest } = route;
|
|
48
|
+
const { entry, exportEntry, serverEntry, ...rest } = route;
|
|
49
49
|
const renderedRoute = rest;
|
|
50
50
|
if (entry?.length) {
|
|
51
51
|
// Expand the entry to full info about the file path.
|
|
52
52
|
renderedRoute.entry = expandEntry({ entry, appPath, flattenedExports });
|
|
53
53
|
}
|
|
54
|
+
if (serverEntry) {
|
|
55
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
56
|
+
if (renderedRoute.renderScript) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
59
|
+
`A route cannot have both serverEntry ("${serverEntry}") and renderScript ("${renderedRoute.renderScript}").`);
|
|
60
|
+
}
|
|
61
|
+
renderedRoute.serverEntry = expandRouteEntry({
|
|
62
|
+
// Usually entryPath will be a source path, but also handle if it's an exports map key.
|
|
63
|
+
importPath: flattenedExports[serverEntry] ? serverEntry : undefined,
|
|
64
|
+
filePath: flattenedExports[serverEntry] || serverEntry,
|
|
65
|
+
entryType: 'serverEntry',
|
|
66
|
+
appPath,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
54
69
|
if (exportEntry) {
|
|
55
70
|
// Handle backwards compatibility with moving from exportEntry to entry.
|
|
56
71
|
const filePath = flattenedExports[exportEntry];
|
|
@@ -88,10 +103,10 @@ function getFlattenedExports(appPath) {
|
|
|
88
103
|
}
|
|
89
104
|
/** Expands shorthand route entries into fully qualified ones. */
|
|
90
105
|
function expandRouteEntry(options) {
|
|
91
|
-
const { filePath, appPath, importPath } = options;
|
|
106
|
+
const { filePath, appPath, importPath, entryType = 'entry' } = options;
|
|
92
107
|
const sourcePath = intermediateToSourcePath(filePath, appPath);
|
|
93
108
|
if (!sourcePath) {
|
|
94
|
-
throw new Error(`Could not resolve source path for
|
|
109
|
+
throw new Error(`Could not resolve source path for ${entryType}: ${filePath}`);
|
|
95
110
|
}
|
|
96
111
|
return {
|
|
97
112
|
// Used to derive bundle entry path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../../src/readConfig/readConfig.ts"],"names":[],"mappings":"AAUA,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,SAAS,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAU1E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe,EAAE,OAA2B;IAC3E,MAAM,EAAE,IAAI,GAAG,SAAS,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAE/E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,MAAM,aAAa,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAoB;QAC9B,GAAG,SAAS;QACZ,OAAO;QACP,IAAI;QACJ,SAAS,EAAE,eAAe;QAC1B,iBAAiB,EA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AW,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 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 { cloneJson, 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 type ReadConfigOptions = ReadAppConfigOptions & Partial<Pick<CloudpackConfig, 'mode' | 'logBundleInfo'>>;\n\n/**\n * Read the app config and generated config if they exist.\n *\n * Throws if there's an error reading a file or certain settings are invalid. (As of writing,\n * this doesn't do full schema validation; it only validates certain specific settings.)\n */\nexport async function readConfig(appPath: string, options?: ReadConfigOptions): Promise<CloudpackConfig> {\n const { mode = 'library', logBundleInfo, ...appConfigOptions } = options || {};\n\n const { routes, ...appConfig } = await readAppConfig(appPath, appConfigOptions);\n const generatedConfig = await readGeneratedConfig(appPath);\n\n const config: CloudpackConfig = {\n ...appConfig,\n appPath,\n mode,\n generated: generatedConfig,\n generatedSnapshot: cloneJson(generatedConfig),\n };\n\n if (logBundleInfo) {\n // Only set this if true, mainly to avoid interfering with tests.\n config.logBundleInfo = true;\n }\n\n // Expands all routes which refer to source files into fully transformed route objects.\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/readConfig.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,E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I,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,OAKzB;IACC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IACvE,MAAM,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,qCAAqC,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC;IACjF,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 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 { cloneJson, 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 type ReadConfigOptions = ReadAppConfigOptions & Partial<Pick<CloudpackConfig, 'mode' | 'logBundleInfo'>>;\n\n/**\n * Read the app config and generated config if they exist.\n *\n * Throws if there's an error reading a file or certain settings are invalid. (As of writing,\n * this doesn't do full schema validation; it only validates certain specific settings.)\n */\nexport async function readConfig(appPath: string, options?: ReadConfigOptions): Promise<CloudpackConfig> {\n const { mode = 'library', logBundleInfo, ...appConfigOptions } = options || {};\n\n const { routes, ...appConfig } = await readAppConfig(appPath, appConfigOptions);\n const generatedConfig = await readGeneratedConfig(appPath);\n\n const config: CloudpackConfig = {\n ...appConfig,\n appPath,\n mode,\n generated: generatedConfig,\n generatedSnapshot: cloneJson(generatedConfig),\n };\n\n if (logBundleInfo) {\n // Only set this if true, mainly to avoid interfering with tests.\n config.logBundleInfo = true;\n }\n\n // Expands all routes which refer to source files into fully transformed route objects.\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, serverEntry, ...rest } = route as ShorthandRenderedRoute;\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 (serverEntry) {\n // eslint-disable-next-line etc/no-deprecated\n if (renderedRoute.renderScript) {\n throw new Error(\n // eslint-disable-next-line etc/no-deprecated\n `A route cannot have both serverEntry (\"${serverEntry}\") and renderScript (\"${renderedRoute.renderScript}\").`,\n );\n }\n\n renderedRoute.serverEntry = expandRouteEntry({\n // Usually entryPath will be a source path, but also handle if it's an exports map key.\n importPath: flattenedExports[serverEntry] ? serverEntry : undefined,\n filePath: flattenedExports[serverEntry] || serverEntry,\n entryType: 'serverEntry',\n appPath,\n });\n }\n\n if (exportEntry) {\n // Handle backwards compatibility with moving from exportEntry to entry.\n const filePath = flattenedExports[exportEntry];\n\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\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: {\n importPath: string | undefined;\n filePath: string;\n appPath: string;\n entryType?: 'entry' | 'serverEntry';\n}): ExpandedSourcePath {\n const { filePath, appPath, importPath, entryType = 'entry' } = options;\n const sourcePath = intermediateToSourcePath(filePath, appPath);\n\n if (!sourcePath) {\n throw new Error(`Could not resolve source path for ${entryType}: ${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.33.
|
|
3
|
+
"version": "0.33.20",
|
|
4
4
|
"description": "Configuration handling for cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.24.10",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.10",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^12.0.1",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
22
|
-
"@ms-cloudpack/path-utilities": "^3.0.
|
|
22
|
+
"@ms-cloudpack/path-utilities": "^3.0.7",
|
|
23
23
|
"semver": "^7.6.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|