@ms-cloudpack/package-utilities 7.7.1 → 7.8.1
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/flattenExportsMap.d.ts.map +1 -1
- package/lib/flattenExportsMap.js +2 -10
- package/lib/flattenExportsMap.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/mergeArrayDefaults.d.ts +7 -0
- package/lib/mergeArrayDefaults.d.ts.map +1 -0
- package/lib/mergeArrayDefaults.js +17 -0
- package/lib/mergeArrayDefaults.js.map +1 -0
- package/lib/mergeObjects.d.ts +27 -0
- package/lib/mergeObjects.d.ts.map +1 -0
- package/lib/mergeObjects.js +42 -0
- package/lib/mergeObjects.js.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAO/F;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBxB"}
|
package/lib/flattenExportsMap.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { cleanEntry } from './cleanEntry.js';
|
|
3
3
|
import glob from 'fast-glob';
|
|
4
|
+
import { mergeArrayDefaults } from './mergeArrayDefaults.js';
|
|
4
5
|
const defaultConditions = ['browser', 'module', 'import', 'default'];
|
|
5
6
|
/**
|
|
6
7
|
* Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
|
|
@@ -18,16 +19,7 @@ const defaultConditions = ['browser', 'module', 'import', 'default'];
|
|
|
18
19
|
*/
|
|
19
20
|
export function flattenExportsMap(exportsMap, options = {}) {
|
|
20
21
|
const { requiredConditions, packagePath } = options;
|
|
21
|
-
|
|
22
|
-
if (conditions) {
|
|
23
|
-
const defaultIndex = conditions.indexOf('...');
|
|
24
|
-
if (defaultIndex !== -1) {
|
|
25
|
-
conditions = [...conditions.slice(0, defaultIndex), ...defaultConditions, ...conditions.slice(defaultIndex + 1)];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
conditions = defaultConditions;
|
|
30
|
-
}
|
|
22
|
+
const conditions = mergeArrayDefaults(options.conditions, defaultConditions);
|
|
31
23
|
if (typeof exportsMap === 'string' && conditions.includes('default')) {
|
|
32
24
|
return {
|
|
33
25
|
'.': cleanEntry(exportsMap),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAA8B,EAC9B,UAII,EAAE;IAEN,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IACpD,IAAI,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;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC;YACxC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { cleanEntry } from './cleanEntry.js';\nimport glob from 'fast-glob';\n\nconst defaultConditions = ['browser', 'module', 'import', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are supported only for generated config. A null export signals to Cloudpack\n * that the entry should be completely dropped from the flattened exports map.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n conditions?: string[];\n requiredConditions?: string[];\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath } = options;\n let { conditions } = options;\n\n if (conditions) {\n const defaultIndex = conditions.indexOf('...');\n if (defaultIndex !== -1) {\n conditions = [...conditions.slice(0, defaultIndex), ...defaultConditions, ...conditions.slice(defaultIndex + 1)];\n }\n } else {\n conditions = defaultConditions;\n }\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports({\n exports,\n conditions,\n requiredConditions,\n flatExports = {},\n importMatch = '.',\n matchedConditions = [],\n packagePath = undefined,\n}: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** The cumulative flat exports map to add the exports to. */\n flatExports?: Record<string, string>;\n /** The import path to match (default `.`). */\n importMatch?: string;\n /** The conditions that have been matched so far. */\n matchedConditions?: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}) {\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({\n exports: exportEntry,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions,\n packagePath,\n });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const exportsObject = (exports as PackageJsonExportsObject)[condition];\n\n if (exportsObject) {\n extractExports({\n exports: exportsObject as PackageJsonExports,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: matchedConditions.concat(condition),\n packagePath,\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (key.startsWith('.')) {\n importMatch = key;\n\n if (typeof value === 'string') {\n if (!flatExports[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key: importMatch, value, packagePath });\n }\n } else if (value) {\n extractExports({\n exports: value,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: [...matchedConditions, key],\n packagePath,\n });\n } else {\n delete flatExports[key];\n }\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry({\n flatExports,\n key,\n value,\n packagePath,\n}: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}) {\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAA8B,EAC9B,UAII,EAAE;IAEN,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEpD,MAAM,UAAU,GAAG,kBAAkB,CAAC,OAAO,CAAC,UAAU,EAAE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W,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC3B,WAAW,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAa,EAAE,gBAAwB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/E,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,GAAG,MAAM,CAAC;IACxB,CAAC;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;IACzF,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAa,EAAE,gBAAwB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/E,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IACnC,CAAC;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC;YACxC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { cleanEntry } from './cleanEntry.js';\nimport glob from 'fast-glob';\nimport { mergeArrayDefaults } from './mergeArrayDefaults.js';\n\nconst defaultConditions = ['browser', 'module', 'import', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are supported only for generated config. A null export signals to Cloudpack\n * that the entry should be completely dropped from the flattened exports map.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n conditions?: string[];\n requiredConditions?: string[];\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath } = options;\n\n const conditions = mergeArrayDefaults(options.conditions, defaultConditions);\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports({\n exports,\n conditions,\n requiredConditions,\n flatExports = {},\n importMatch = '.',\n matchedConditions = [],\n packagePath = undefined,\n}: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** The cumulative flat exports map to add the exports to. */\n flatExports?: Record<string, string>;\n /** The import path to match (default `.`). */\n importMatch?: string;\n /** The conditions that have been matched so far. */\n matchedConditions?: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}) {\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({\n exports: exportEntry,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions,\n packagePath,\n });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const exportsObject = (exports as PackageJsonExportsObject)[condition];\n\n if (exportsObject) {\n extractExports({\n exports: exportsObject as PackageJsonExports,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: matchedConditions.concat(condition),\n packagePath,\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (key.startsWith('.')) {\n importMatch = key;\n\n if (typeof value === 'string') {\n if (!flatExports[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key: importMatch, value, packagePath });\n }\n } else if (value) {\n extractExports({\n exports: value,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: [...matchedConditions, key],\n packagePath,\n });\n } else {\n delete flatExports[key];\n }\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry({\n flatExports,\n key,\n value,\n packagePath,\n}: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}) {\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -23,4 +23,6 @@ export { findProjectRoot } from './findProjectRoot.js';
|
|
|
23
23
|
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
24
24
|
export { ensurePackageJsonDependencies } from './ensurePackageJsonDependencies.js';
|
|
25
25
|
export { getSourceEntry } from './getSourceEntry.js';
|
|
26
|
+
export { mergeArrayDefaults } from './mergeArrayDefaults.js';
|
|
27
|
+
export { mergeObjects } from './mergeObjects.js';
|
|
26
28
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC1G,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,yB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ePackage.js';
|
|
25
25
|
export { ensurePackageJsonDependencies } from './ensurePackageJsonDependencies.js';
|
|
26
26
|
export { getSourceEntry } from './getSourceEntry.js';
|
|
27
|
+
// Object utilities which could be moved to a separate package if we add more of them
|
|
28
|
+
export { mergeArrayDefaults } from './mergeArrayDefaults.js';
|
|
29
|
+
export { mergeObjects } from './mergeObjects.js';
|
|
27
30
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAG1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAkC,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAA+D,MAAM,wBAAwB,CAAC;AACxH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './PackageDefinitions.js';\n\n// ResolveMap creation\nexport { createResolveMap } from './createResolveMap/createResolveMap.js';\nexport type { ResolveMap } from './types/ResolveMap.js';\nexport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nexport { findResolveMapEntry } from './findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './createResolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './createResolveMap/diffResolveMaps.js';\nexport type { LinkedPath } from './types/LinkedPath.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './flattenExportsMap.js';\nexport { createExportsMap } from './createExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './addExportsMapEntry.js';\nexport { getExportsMap } from './getExportsMap.js';\nexport { ensureResolveMapEntry } from './ensureResolveMapEntry.js';\n\n// Import resolution utilities\nexport { resolve } from './resolve.js';\n\n// Other package utilities\nexport { detectModuleType } from './detectModuleType.js';\nexport { isExternalPackage } from './isExternalPackage.js';\nexport { findFileInPackage, type FindFileInPackageOptions, type FindFileInPackageResult } from './findFileInPackage.js';\nexport { getDisplayVersion } from './getDisplayVersion.js';\nexport { getVersion } from './getVersion.js';\nexport { getDependencies } from './getDependencies.js';\nexport { getUnusedDependencies } from './getUnusedDependencies.js';\nexport { findProjectRoot } from './findProjectRoot.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.js';\nexport { ensurePackageJsonDependencies } from './ensurePackageJsonDependencies.js';\nexport { getSourceEntry } from './getSourceEntry.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAG1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAkC,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAA+D,MAAM,wBAAwB,CAAC;AACxH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,qFAAqF;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './PackageDefinitions.js';\n\n// ResolveMap creation\nexport { createResolveMap } from './createResolveMap/createResolveMap.js';\nexport type { ResolveMap } from './types/ResolveMap.js';\nexport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nexport { findResolveMapEntry } from './findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './createResolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './createResolveMap/diffResolveMaps.js';\nexport type { LinkedPath } from './types/LinkedPath.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './flattenExportsMap.js';\nexport { createExportsMap } from './createExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './addExportsMapEntry.js';\nexport { getExportsMap } from './getExportsMap.js';\nexport { ensureResolveMapEntry } from './ensureResolveMapEntry.js';\n\n// Import resolution utilities\nexport { resolve } from './resolve.js';\n\n// Other package utilities\nexport { detectModuleType } from './detectModuleType.js';\nexport { isExternalPackage } from './isExternalPackage.js';\nexport { findFileInPackage, type FindFileInPackageOptions, type FindFileInPackageResult } from './findFileInPackage.js';\nexport { getDisplayVersion } from './getDisplayVersion.js';\nexport { getVersion } from './getVersion.js';\nexport { getDependencies } from './getDependencies.js';\nexport { getUnusedDependencies } from './getUnusedDependencies.js';\nexport { findProjectRoot } from './findProjectRoot.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.js';\nexport { ensurePackageJsonDependencies } from './ensurePackageJsonDependencies.js';\nexport { getSourceEntry } from './getSourceEntry.js';\n\n// Object utilities which could be moved to a separate package if we add more of them\nexport { mergeArrayDefaults } from './mergeArrayDefaults.js';\nexport { mergeObjects } from './mergeObjects.js';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace a '...' in an array with the provided defaults.
|
|
3
|
+
* Returns a new array regardless of whether a replacement was made.
|
|
4
|
+
* If `values` is undefined, returns a copy of the defaults array.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mergeArrayDefaults<T>(values: (T | '...')[] | undefined, defaults: T[]): T[];
|
|
7
|
+
//# sourceMappingURL=mergeArrayDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeArrayDefaults.d.ts","sourceRoot":"","sources":["../src/mergeArrayDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAU3F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace a '...' in an array with the provided defaults.
|
|
3
|
+
* Returns a new array regardless of whether a replacement was made.
|
|
4
|
+
* If `values` is undefined, returns a copy of the defaults array.
|
|
5
|
+
*/
|
|
6
|
+
export function mergeArrayDefaults(values, defaults) {
|
|
7
|
+
if (!values) {
|
|
8
|
+
return [...defaults];
|
|
9
|
+
}
|
|
10
|
+
values = [...values];
|
|
11
|
+
const defaultsIndex = values.indexOf('...');
|
|
12
|
+
if (defaultsIndex > -1) {
|
|
13
|
+
values.splice(defaultsIndex, 1, ...defaults);
|
|
14
|
+
}
|
|
15
|
+
return values;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=mergeArrayDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeArrayDefaults.js","sourceRoot":"","sources":["../src/mergeArrayDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAI,MAAiC,EAAE,QAAa;IACpF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IACrB,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAa,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Replace a '...' in an array with the provided defaults.\n * Returns a new array regardless of whether a replacement was made.\n * If `values` is undefined, returns a copy of the defaults array.\n */\nexport function mergeArrayDefaults<T>(values: (T | '...')[] | undefined, defaults: T[]): T[] {\n if (!values) {\n return [...defaults];\n }\n values = [...values];\n const defaultsIndex = values.indexOf('...');\n if (defaultsIndex > -1) {\n values.splice(defaultsIndex, 1, ...defaults);\n }\n return values as T[];\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively merge objects.
|
|
3
|
+
* Array values are concatenated by default, but this is configurable.
|
|
4
|
+
* Assumes that the types of any defined keys stay consistent across all objects;
|
|
5
|
+
* if this isn't true, provide a `customMerge` function for that key.
|
|
6
|
+
* (`customMerge` must also be used to customize merging for nested objects.)
|
|
7
|
+
*/
|
|
8
|
+
export declare function mergeObjects<T extends object>(objects: T[], options?: {
|
|
9
|
+
/**
|
|
10
|
+
* Whether to concatenate all arrays (default) or overwrite with new values.
|
|
11
|
+
* Applies to top-level and nested objects.
|
|
12
|
+
*/
|
|
13
|
+
arrayMerge?: 'concat' | 'overwrite';
|
|
14
|
+
/**
|
|
15
|
+
* Overwrite the values of these object or array keys instead of merging.
|
|
16
|
+
* Applies to the top-level object only.
|
|
17
|
+
*/
|
|
18
|
+
overwriteKeys?: (keyof T)[];
|
|
19
|
+
/**
|
|
20
|
+
* Custom merging for key values. The function should return the merged value.
|
|
21
|
+
* Applies to the top-level object only.
|
|
22
|
+
*/
|
|
23
|
+
customMerge?: {
|
|
24
|
+
[K in keyof T]?: (prev: T[K] | undefined, curr: T[K]) => T[K];
|
|
25
|
+
};
|
|
26
|
+
}): T;
|
|
27
|
+
//# sourceMappingURL=mergeObjects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeObjects.d.ts","sourceRoot":"","sources":["../src/mergeObjects.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,OAAO,EAAE,CAAC,EAAE,EACZ,OAAO,GAAE;IACP;;;OAGG;IACH,UAAU,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;IACpC;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE;SACX,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC9D,CAAC;CACE,GACL,CAAC,CAkCH"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively merge objects.
|
|
3
|
+
* Array values are concatenated by default, but this is configurable.
|
|
4
|
+
* Assumes that the types of any defined keys stay consistent across all objects;
|
|
5
|
+
* if this isn't true, provide a `customMerge` function for that key.
|
|
6
|
+
* (`customMerge` must also be used to customize merging for nested objects.)
|
|
7
|
+
*/
|
|
8
|
+
export function mergeObjects(objects, options = {}) {
|
|
9
|
+
// NOTE: If other options are added, consider whether they should apply recursively,
|
|
10
|
+
// and if so, update the mergeObjects() recursive call.
|
|
11
|
+
const { customMerge, arrayMerge = 'concat', overwriteKeys } = options;
|
|
12
|
+
const acc = {};
|
|
13
|
+
for (const obj of objects) {
|
|
14
|
+
if (!obj || typeof obj !== 'object') {
|
|
15
|
+
throw new Error('mergeObjects: all arguments must be objects');
|
|
16
|
+
}
|
|
17
|
+
for (const pair of Object.entries(obj)) {
|
|
18
|
+
const key = pair[0];
|
|
19
|
+
const val = pair[1];
|
|
20
|
+
const customMergeKey = customMerge?.[key];
|
|
21
|
+
if (customMergeKey) {
|
|
22
|
+
acc[key] = customMergeKey(acc[key], val);
|
|
23
|
+
}
|
|
24
|
+
else if (overwriteKeys?.includes(key)) {
|
|
25
|
+
acc[key] = val;
|
|
26
|
+
}
|
|
27
|
+
else if (Array.isArray(val)) {
|
|
28
|
+
acc[key] = arrayMerge === 'concat' ? [...(acc[key] || []), ...val] : val;
|
|
29
|
+
}
|
|
30
|
+
else if (val && typeof val === 'object') {
|
|
31
|
+
// Recursively merge objects. arrayMerge makes sense to apply recursively, but customMerge
|
|
32
|
+
// and overwriteKeys are specific to the keys of the top-level object.
|
|
33
|
+
acc[key] = mergeObjects([(acc[key] || {}), val], { arrayMerge });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
acc[key] = val;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return acc;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mergeObjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeObjects.js","sourceRoot":"","sources":["../src/mergeObjects.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAY,EACZ,UAkBI,EAAE;IAEN,oFAAoF;IACpF,uDAAuD;IACvD,MAAM,EAAE,WAAW,EAAE,UAAU,GAAG,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAEtE,MAAM,GAAG,GAAG,EAA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C;iBAAM,CAAC;gBACN,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Recursively merge objects.\n * Array values are concatenated by default, but this is configurable.\n * Assumes that the types of any defined keys stay consistent across all objects;\n * if this isn't true, provide a `customMerge` function for that key.\n * (`customMerge` must also be used to customize merging for nested objects.)\n */\nexport function mergeObjects<T extends object>(\n objects: T[],\n options: {\n /**\n * Whether to concatenate all arrays (default) or overwrite with new values.\n * Applies to top-level and nested objects.\n */\n arrayMerge?: 'concat' | 'overwrite';\n /**\n * Overwrite the values of these object or array keys instead of merging.\n * Applies to the top-level object only.\n */\n overwriteKeys?: (keyof T)[];\n /**\n * Custom merging for key values. The function should return the merged value.\n * Applies to the top-level object only.\n */\n customMerge?: {\n [K in keyof T]?: (prev: T[K] | undefined, curr: T[K]) => T[K];\n };\n } = {},\n): T {\n // NOTE: If other options are added, consider whether they should apply recursively,\n // and if so, update the mergeObjects() recursive call.\n const { customMerge, arrayMerge = 'concat', overwriteKeys } = options;\n\n const acc = {} as T;\n\n for (const obj of objects) {\n if (!obj || typeof obj !== 'object') {\n throw new Error('mergeObjects: all arguments must be objects');\n }\n\n for (const pair of Object.entries(obj)) {\n const key = pair[0] as keyof T;\n const val = pair[1] as T[typeof key];\n const customMergeKey = customMerge?.[key];\n\n if (customMergeKey) {\n acc[key] = customMergeKey(acc[key], val);\n } else if (overwriteKeys?.includes(key)) {\n acc[key] = val;\n } else if (Array.isArray(val)) {\n acc[key] = arrayMerge === 'concat' ? ([...((acc[key] as unknown[]) || []), ...val] as typeof val) : val;\n } else if (val && typeof val === 'object') {\n // Recursively merge objects. arrayMerge makes sense to apply recursively, but customMerge\n // and overwriteKeys are specific to the keys of the top-level object.\n acc[key] = mergeObjects([(acc[key] || {}) as typeof val, val], { arrayMerge });\n } else {\n acc[key] = val;\n }\n }\n }\n\n return acc;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.1",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.10.0",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.4",
|
|
19
|
-
"@ms-cloudpack/package-overrides": "^0.9.
|
|
19
|
+
"@ms-cloudpack/package-overrides": "^0.9.8",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.3",
|
|
21
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^2.7.22",
|
|
22
22
|
"@ms-cloudpack/task-reporter": "^0.14.1",
|
|
23
23
|
"acorn": "^8.11.2",
|
|
24
24
|
"acorn-walk": "^8.2.1",
|