@ms-cloudpack/package-utilities 10.2.0 → 10.2.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/mergeObjects.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare function mergeObjects<T extends object>(objects: T[], options?: {
|
|
|
9
9
|
/**
|
|
10
10
|
* Whether to concatenate all arrays (default) or overwrite with new values.
|
|
11
11
|
* Applies to top-level and nested objects.
|
|
12
|
+
* @default 'concat'
|
|
12
13
|
*/
|
|
13
14
|
arrayMerge?: 'concat' | 'overwrite';
|
|
14
15
|
/**
|
|
@@ -1 +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
|
|
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;;;;OAIG;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"}
|
package/lib/mergeObjects.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeObjects.js","sourceRoot":"","sources":["../src/mergeObjects.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"mergeObjects.js","sourceRoot":"","sources":["../src/mergeObjects.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAY,EACZ,UAmBI,EAAE;IAEN,oFAAoF;IACpF,uDAAuD;IACvD,MAAM,EAAE,WAAW,EAAE,UAAU,GAAG,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAEtE,MAAM,GAAG,GAAG,EAAO,CAAC;IAEpB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAY,CAAC;YAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAkB,CAAC;YACrC,MAAM,cAAc,GAAG,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;YAE1C,IAAI,cAAc,EAAE,CAAC;gBACnB,GAAG,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;iBAAM,IAAI,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACxC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;YACjB,CAAC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9B,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAE,CAAC,GAAG,CAAE,GAAG,CAAC,GAAG,CAAe,IAAI,EAAE,CAAC,EAAE,GAAG,GAAG,CAAgB,CAAC,CAAC,CAAC,GAAG,CAAC;YAC1G,CAAC;iBAAM,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC1C,0FAA0F;gBAC1F,sEAAsE;gBACtE,GAAG,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAe,EAAE,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACjF,CAAC;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 * @default 'concat'\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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @deprecated Use the one from `@ms-cloudpack/bundler-utilities` instead.
|
|
3
|
+
* (can be deleted in version 11 or later)
|
|
4
4
|
*/
|
|
5
5
|
export declare function shouldExternalizePackage(params: {
|
|
6
6
|
id: string;
|
|
@@ -2,8 +2,8 @@ import path from 'path';
|
|
|
2
2
|
import { isBuiltin } from 'module';
|
|
3
3
|
import { parseImportString } from '@ms-cloudpack/path-string-parsing';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* @deprecated Use the one from `@ms-cloudpack/bundler-utilities` instead.
|
|
6
|
+
* (can be deleted in version 11 or later)
|
|
7
7
|
*/
|
|
8
8
|
export function shouldExternalizePackage(params) {
|
|
9
9
|
const { id, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAMxC;IACC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,wBAAwB,EAAE,GAAG,MAAM,CAAC;IAE9E,OAAO,CAAC,CACN,CAAC,wBAAwB,IAAI,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC3E,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnB,UAAU,CAAC,EAAE,CAAC;QACd,6FAA6F;QAC7F,CAAC,OAAO,EAAE,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CACzE,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,kDAAkD;AAClD,SAAS,oBAAoB,CAAC,EAAU,EAAE,QAA8B,EAAE,SAAkC;IAC1G,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC;AACxG,CAAC","sourcesContent":["import path from 'path';\nimport { isBuiltin } from 'module';\nimport { parseImportString } from '@ms-cloudpack/path-string-parsing';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"m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ing';\n\n/**\n * @deprecated Use the one from `@ms-cloudpack/bundler-utilities` instead.\n * (can be deleted in version 11 or later)\n */\nexport function shouldExternalizePackage(params: {\n id: string;\n inlined?: string[];\n external?: string[];\n polyfills?: Set<string>;\n shouldInlineNodeBuiltins: boolean;\n}): boolean {\n const { id, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;\n\n return !(\n (shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, external, polyfills)) ||\n path.isAbsolute(id) ||\n isRelative(id) ||\n // The length check ensures that parseImportString is only called when there are inlined deps\n (inlined?.length && inlined.includes(parseImportString(id).packageName))\n );\n}\n\n// We should inline node builtins that are handled by the nodePolyfills plugin.\n// Except if the dependency is listed as external.\nfunction isInlinedNodeBuiltin(id: string, external: string[] | undefined, polyfills: Set<string> | undefined) {\n return (isBuiltin(id) || polyfills?.has(id)) && !external?.find((ex) => id.startsWith(ex));\n}\n\nfunction isRelative(id: string) {\n return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';\n}\n"]}
|