@ms-cloudpack/package-utilities
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -5,3 +5,18 @@ { | ||
{ | ||
"date": "Fri, 20 May 2022 04:25:53 GMT", | ||
"date": "Sat, 21 May 2022 00:31:20 GMT", | ||
"tag": "@ms-cloudpack/package-utilities_v0.3.0", | ||
"version": "0.3.0", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"author": "dzearing@microsoft.com", | ||
"package": "@ms-cloudpack/package-utilities", | ||
"commit": "c26c7bcc7abda501d07180598e3da003b435b03b", | ||
"comment": "Adding api to generate an import map based on a resolve map." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Fri, 20 May 2022 04:26:15 GMT", | ||
"tag": "@ms-cloudpack/package-utilities_v0.2.0", | ||
@@ -8,0 +23,0 @@ "version": "0.2.0", |
# Change Log - @ms-cloudpack/package-utilities | ||
This log was last generated on Fri, 20 May 2022 04:25:53 GMT and should not be manually modified. | ||
This log was last generated on Sat, 21 May 2022 00:31:20 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 0.3.0 | ||
Sat, 21 May 2022 00:31:20 GMT | ||
### Minor changes | ||
- Adding api to generate an import map based on a resolve map. (dzearing@microsoft.com) | ||
## 0.2.0 | ||
Fri, 20 May 2022 04:25:53 GMT | ||
Fri, 20 May 2022 04:26:15 GMT | ||
@@ -11,0 +19,0 @@ ### Minor changes |
@@ -6,9 +6,11 @@ export declare type PackageNameVersion = `${string}@${string}`; | ||
path: string; | ||
requiredBy: string[]; | ||
scopedVersions?: { | ||
[packageId: PackageNameVersion]: PackageNameVersion; | ||
[version: string]: ResolveMapEntry; | ||
}; | ||
}; | ||
export declare type ResolveMap = { | ||
[packageId: PackageNameVersion | string]: ResolveMapEntry; | ||
export declare type PartialResolveMapEntry = Omit<ResolveMapEntry, 'requiredBy'> & { | ||
requiredBy: Set<string>; | ||
}; | ||
export declare type ResolveMap = Record<string, ResolveMapEntry>; | ||
export declare function createResolveMap(options: { | ||
@@ -15,0 +17,0 @@ appPath: string; |
@@ -7,3 +7,2 @@ import { getPackageDefinition } from './getPackageDefinition.js'; | ||
const pathsToVisit = [appPath, ...additionalPaths]; | ||
const relationships = {}; | ||
const allEntries = {}; | ||
@@ -16,3 +15,2 @@ while (pathsToVisit.length) { | ||
const packageId = `${definition.name}@${definition.version}`; | ||
allEntries[packageId] = createMapEntry(definition, packagePath); | ||
for (const depName of Object.keys(definition?.dependencies || {})) { | ||
@@ -22,7 +20,5 @@ const dependencyPath = findPackagePath(depName, packagePath); | ||
if (dependencyDefinition) { | ||
const depVersionList = (relationships[dependencyDefinition.name] = | ||
relationships[dependencyDefinition.name] || {}); | ||
const relationshipList = (depVersionList[dependencyDefinition.version] = | ||
depVersionList[dependencyDefinition.version] || []); | ||
relationshipList.push(packageId); | ||
const dependencyNamedEntries = (allEntries[dependencyDefinition.name] ??= {}); | ||
const dependencyEntry = (dependencyNamedEntries[dependencyDefinition.version] ??= createMapEntry(dependencyDefinition, dependencyPath)); | ||
dependencyEntry.requiredBy.add(packageId); | ||
if (!visitedPaths.has(dependencyPath)) { | ||
@@ -40,17 +36,15 @@ visitedPaths.add(dependencyPath); | ||
const resolveMap = {}; | ||
for (const [name, versions] of Object.entries(relationships)) { | ||
for (const [name, versions] of Object.entries(allEntries)) { | ||
const [dominantVersion, ...otherVersions] = Object.keys(versions).sort((a, b) => { | ||
return versions[a].length < versions[b].length ? 1 : -1; | ||
return versions[a].requiredBy.size < versions[b].requiredBy.size ? 1 : -1; | ||
}); | ||
const dominantId = `${name}@${dominantVersion}`; | ||
const entry = (resolveMap[name] = resolveMap[dominantId] = allEntries[dominantId]); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const entry = (resolveMap[name] = allEntries[name][dominantVersion]); | ||
entry.requiredBy = Array.from(entry.requiredBy); | ||
if (otherVersions?.length) { | ||
entry.scopedVersions = {}; | ||
for (const otherVersion of otherVersions) { | ||
const scopedId = `${name}@${otherVersion}`; | ||
const dependents = relationships[name][otherVersion]; | ||
resolveMap[scopedId] = allEntries[scopedId]; | ||
for (const dependentId of dependents) { | ||
entry.scopedVersions[dependentId] = scopedId; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const scopedEntry = (entry.scopedVersions[otherVersion] = versions[otherVersion]); | ||
scopedEntry.requiredBy = Array.from(scopedEntry.requiredBy); | ||
} | ||
@@ -67,4 +61,5 @@ } | ||
path: packagePath, | ||
requiredBy: new Set(), | ||
}; | ||
} | ||
//# sourceMappingURL=createResolveMap.js.map |
@@ -9,5 +9,24 @@ import { slash } from '@ms-cloudpack/path-utilities'; | ||
it('can create a resolve map', async () => { | ||
expect(await createResolveMapSafe({ appPath: testProject1Path })).toMatchSnapshot(); | ||
expect(await createResolveMapSafe({ appPath: testProject1Path })).toMatchInlineSnapshot(` | ||
Object { | ||
"b": Object { | ||
"name": "b", | ||
"path": "node_modules/b", | ||
"requiredBy": Array [ | ||
"test-project-1@0.0.1", | ||
], | ||
"version": "1.0.0", | ||
}, | ||
"c": Object { | ||
"name": "c", | ||
"path": "node_modules/c", | ||
"requiredBy": Array [ | ||
"test-project-1@0.0.1", | ||
], | ||
"version": "1.0.0", | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
//# sourceMappingURL=createResolveMap.test.js.map |
@@ -10,1 +10,2 @@ export { createResolveMap, type ResolveMapEntry, type ResolveMap } from './createResolveMap.js'; | ||
export { isExternalPackage } from './isExternalPackage.js'; | ||
export { createImportMap, type ImportMap } from './createImportMap.js'; |
@@ -9,2 +9,3 @@ export { createResolveMap } from './createResolveMap.js'; | ||
export { isExternalPackage } from './isExternalPackage.js'; | ||
export { createImportMap } from './createImportMap.js'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ms-cloudpack/package-utilities", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Utilities for resolving/parsing packages and their imports.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110455
84
1709