Skip to content

Commit

Permalink
Update fhir-package-loader dependency (#1304)
Browse files Browse the repository at this point in the history
fhir-package-loader now supports "latest" as a version string, so there
is no more need for custom logic to handle it.
  • Loading branch information
mint-thompson authored Jul 17, 2023
1 parent d404886 commit 7d9cbc8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
14 changes: 7 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"chalk": "^3.0.0",
"commander": "^8.2.0",
"fhir": "^4.9.0",
"fhir-package-loader": "^0.3.0",
"fhir-package-loader": "^0.4.0",
"fs-extra": "^8.1.0",
"html-minifier-terser": "5.1.1",
"https-proxy-agent": "^5.0.0",
Expand Down
34 changes: 2 additions & 32 deletions src/utils/Processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import readlineSync from 'readline-sync';
import YAML from 'yaml';
import { execSync } from 'child_process';
import { YAMLMap, Collection } from 'yaml/types';
import { cloneDeep, isPlainObject, padEnd, sortBy, upperFirst } from 'lodash';
import { isPlainObject, padEnd, sortBy, upperFirst } from 'lodash';
import { mergeDependency } from 'fhir-package-loader';
import { EOL } from 'os';
import { AxiosResponse } from 'axios';
Expand Down Expand Up @@ -342,7 +342,7 @@ export async function loadAutomaticDependencies(
defs: FHIRDefinitions
): Promise<void> {
// Load dependencies serially so dependency loading order is predictable and repeatable
for (let dep of AUTOMATIC_DEPENDENCIES) {
for (const dep of AUTOMATIC_DEPENDENCIES) {
// Skip dependencies not intended for this version of FHIR
if (dep.fhirVersion && !dep.fhirVersion.test(fhirVersion)) {
continue;
Expand All @@ -358,36 +358,6 @@ export async function loadAutomaticDependencies(
});
if (!alreadyConfigured) {
try {
if (dep.version === 'latest') {
// clone it before we modify it so we don't overwrite the global (mostly helpful for testing)
dep = cloneDeep(dep);
let res: AxiosResponse;
if (process.env.FPL_REGISTRY) {
res = await axiosGet(`${process.env.FPL_REGISTRY}/${dep.packageId}`, {
responseType: 'json'
});
} else {
try {
res = await axiosGet(`https://packages.fhir.org/${dep.packageId}`, {
responseType: 'json'
});
} catch (e) {
// Fallback to trying packages2.fhir.org
res = await axiosGet(`https://packages2.fhir.org/packages/${dep.packageId}`, {
responseType: 'json'
}).catch(() => {
// If the fallback failed too, just throw the original error
throw e;
});
}
}

if (res?.data?.['dist-tags']?.latest?.length) {
dep.version = res.data['dist-tags'].latest;
} else {
throw new Error(`Could not determine latest released version of ${dep.packageId}.`);
}
}
await mergeDependency(dep.packageId, dep.version, defs, undefined, logMessage);
} catch (e) {
let message = `Failed to load automatically-provided ${dep.packageId}#${dep.version}`;
Expand Down
3 changes: 3 additions & 0 deletions test/utils/Processing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ jest.mock('fhir-package-loader', () => {
...original,
mergeDependency: jest.fn(
async (packageName: string, version: string, FHIRDefs: FHIRDefinitions) => {
if (version === 'latest') {
version = await original.lookUpLatestVersion(packageName);
}
// the mock loader can find hl7.fhir.(r2|r3|r4|r5|us).core and auto dependencies
if (forceLoadErrorOnPackages.indexOf(packageName) !== -1) {
throw new PackageLoadError(`${packageName}#${version}`);
Expand Down

0 comments on commit 7d9cbc8

Please sign in to comment.