Skip to content

Commit

Permalink
To 2.1.1 (#929)
Browse files Browse the repository at this point in the history
* Revert "SUSHI now loads lower case package names by default (#912)"

This reverts commit 36f2509.

* 2.1.1
  • Loading branch information
ngfreiter authored Oct 8, 2021
1 parent fae385f commit 627b66f
Show file tree
Hide file tree
Showing 178 changed files with 297 additions and 161 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "fsh-sushi",
"version": "2.1.0",
"version": "2.1.1",
"description": "Sushi Unshortens Short Hand Inputs (FSH Compiler)",
"scripts": {
"build": "del-cli dist && tsc && cpy src/utils/init-project dist/utils/init-project",
Expand Down
23 changes: 10 additions & 13 deletions src/fhirdefs/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export async function loadDependency(
cachePath: string = path.join(os.homedir(), '.fhir', 'packages')
): Promise<FHIRDefinitions> {
let fullPackageName = `${packageName}#${version}`;
const loadPath = path.join(cachePath, fullPackageName, 'package');
let loadPath = path.join(cachePath, fullPackageName, 'package');
let loadedPackage: string;

// First, try to load the package from the local cache
logger.info(`Checking local cache for ${fullPackageName}...`);
loadedPackage = loadFromPath(cachePath, fullPackageName, FHIRDefs);
loadedPackage = loadFromPath(loadPath, fullPackageName, FHIRDefs);
if (loadedPackage) {
logger.info(`Found ${fullPackageName} in local cache.`);
} else {
Expand All @@ -46,7 +46,8 @@ export async function loadDependency(
);
version = 'current';
fullPackageName = `${packageName}#${version}`;
loadedPackage = loadFromPath(cachePath, fullPackageName, FHIRDefs);
loadPath = path.join(cachePath, fullPackageName, 'package');
loadedPackage = loadFromPath(loadPath, fullPackageName, FHIRDefs);
}

let packageUrl;
Expand Down Expand Up @@ -262,28 +263,24 @@ export function loadCustomResources(resourceDir: string, defs: FHIRDefinitions):
}

/**
* Locates the targetPackage within the cachePath and loads the set of JSON files into FHIRDefs
* @param {string} cachePath - The path to the directory containing cached packages
* Loads a set of JSON files at targetPath into FHIRDefs
* @param {string} targetPath - The path to the directory containing the JSON definitions
* @param {string} targetPackage - The name of the package we are trying to load
* @param {FHIRDefinitions} FHIRDefs - The FHIRDefinitions object to load defs into
* @returns {string} the name of the loaded package if successful
*/
export function loadFromPath(
cachePath: string,
targetPath: string,
targetPackage: string,
FHIRDefs: FHIRDefinitions
): string {
if (FHIRDefs.packages.indexOf(targetPackage) < 0) {
const originalSize = FHIRDefs.size();
const packages = fs.existsSync(cachePath) ? fs.readdirSync(cachePath) : [];
const cachedPackage = packages.find(packageName => packageName.toLowerCase() === targetPackage);
if (cachedPackage) {
const files = fs.readdirSync(path.join(cachePath, cachedPackage, 'package'));
if (fs.existsSync(targetPath)) {
const files = fs.readdirSync(targetPath);
for (const file of files) {
if (file.endsWith('.json')) {
const def = JSON.parse(
fs.readFileSync(path.join(cachePath, cachedPackage, 'package', file), 'utf-8').trim()
);
const def = JSON.parse(fs.readFileSync(path.join(targetPath, file), 'utf-8').trim());
FHIRDefs.add(def);
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/import/importConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,6 @@ function parseDependencies(
return;
}
return Object.entries(yamlDependencies).map(([packageId, versionOrDetails]) => {
if (/[A-Z]/.test(packageId)) {
logger.warn(
`${packageId} contains uppercase characters, which is discouraged. SUSHI will use ${packageId.toLowerCase()} as the package name.`
);
packageId = packageId.toLowerCase();
}
if (typeof versionOrDetails === 'string' || typeof versionOrDetails === 'number') {
return { packageId, version: `${versionOrDetails}` };
} else if (versionOrDetails == null) {
Expand Down
6 changes: 5 additions & 1 deletion test/export/CodeSystemExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ describe('CodeSystemExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/FHIRExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ describe('FHIRExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
12 changes: 10 additions & 2 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ describe('InstanceExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down Expand Up @@ -3882,7 +3886,11 @@ describe('InstanceExporter R5', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r5-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r5-definitions'),
'r5',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/MappingExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ describe('MappingExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/StructureDefinition.ExtensionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ describe('ExtensionExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/StructureDefinition.LogicalExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ describe('LogicalExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/StructureDefinition.ProfileExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ describe('ProfileExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/StructureDefinition.ResourceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ describe('ResourceExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
12 changes: 10 additions & 2 deletions test/export/StructureDefinitionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ describe('StructureDefinitionExporter R4', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down Expand Up @@ -6972,7 +6976,11 @@ describe('StructureDefinitionExporter R5', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r5-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r5-definitions'),
'r5',
defs
);
});

beforeEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion test/export/ValueSetExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ describe('ValueSetExporter', () => {

beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testPackage',
defs
);
});

beforeEach(() => {
Expand Down
12 changes: 10 additions & 2 deletions test/fhirdefs/FHIRDefinitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ describe('FHIRDefinitions', () => {
let defs: FHIRDefinitions;
beforeAll(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'test#1.1.1',
defs
);
// Supplemental R3 defs needed to test fishing for implied extensions
const r3Defs = new FHIRDefinitions(true);
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r3-definitions', r3Defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r3-definitions'),
'hl7.fhir.r3.core#3.0.2',
r3Defs
);
defs.addSupplementalFHIRDefinitions('hl7.fhir.r3.core#3.0.2', r3Defs);
// Run the dependency resources through TestFisher to force them into the testhelpers cache
const fisher = new TestFisher().withFHIR(defs);
Expand Down

This file was deleted.

24 changes: 0 additions & 24 deletions test/fhirdefs/fixtures/sUshI-tESt-CaPs#0.1.0/package/package.json

This file was deleted.

36 changes: 30 additions & 6 deletions test/fhirdefs/impliedExtension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,31 @@ describe('impliedExtensions', () => {
let defs: FHIRDefinitions;
beforeEach(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'testdefs',
defs
);
const r2Defs = new FHIRDefinitions(true);
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r2-definitions', r2Defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r2-definitions'),
'hl7.fhir.r2.core#1.0.2',
r2Defs
);
defs.addSupplementalFHIRDefinitions('hl7.fhir.r2.core#1.0.2', r2Defs);
const r3Defs = new FHIRDefinitions(true);
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r3-definitions', r3Defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r3-definitions'),
'hl7.fhir.r3.core#3.0.2',
r3Defs
);
defs.addSupplementalFHIRDefinitions('hl7.fhir.r3.core#3.0.2', r3Defs);
const r5Defs = new FHIRDefinitions(true);
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r5-definitions', r5Defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r5-definitions'),
'hl7.fhir.r5.core#4.6.0',
r5Defs
);
defs.addSupplementalFHIRDefinitions('hl7.fhir.r5.core#current', r5Defs);
loggerSpy.reset();
});
Expand Down Expand Up @@ -1314,9 +1330,17 @@ describe('impliedExtensions', () => {
let defs: FHIRDefinitions;
beforeEach(() => {
defs = new FHIRDefinitions();
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r5-definitions', defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'r5-definitions'),
'hl7.fhir.r5.core#4.6.0',
defs
);
const r4Defs = new FHIRDefinitions(true);
loadFromPath(path.join(__dirname, '..', 'testhelpers', 'testdefs'), 'r4-definitions', r4Defs);
loadFromPath(
path.join(__dirname, '..', 'testhelpers', 'testdefs', 'package'),
'hl7.fhir.r4.core#4.0.1',
r4Defs
);
defs.addSupplementalFHIRDefinitions('hl7.fhir.r4.core#4.0.1', r4Defs);
loggerSpy.reset();
});
Expand Down
Loading

0 comments on commit 627b66f

Please sign in to comment.