babelfhir-ts 1.5.14 → 1.5.16
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/out/src/generator/index.js +29 -2
- package/package.json +1 -1
|
@@ -102,12 +102,39 @@ function copyFhirAmbientDeclaration(outputDir) {
|
|
|
102
102
|
log.warn(`Warning: ${dtsFileName} not found. Run: npm run generate:fhir-module`);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Locate the `@types` directory that ships with babelfhir-ts itself (the one
|
|
107
|
+
* containing `@types/fhir`). The generated output imports base FHIR types via the
|
|
108
|
+
* ambient `fhir/r4` module, which aliases `fhir4.*` from `@types/fhir`. Under
|
|
109
|
+
* `--skip-install` the generated package's own dependencies (including
|
|
110
|
+
* `@types/fhir`) are never installed into its `node_modules`, so the output
|
|
111
|
+
* typecheck would resolve `fhir4.Observation` to an empty type and any validator
|
|
112
|
+
* accessing a base-inherited field not restated locally (e.g. `Observation.code`
|
|
113
|
+
* on a profile that only slices `code.coding`) would fail TS2339. Pointing
|
|
114
|
+
* `typeRoots` at babelfhir's own always-present `@types` makes the typecheck
|
|
115
|
+
* robust regardless of the output's install state.
|
|
116
|
+
*/
|
|
117
|
+
function resolveGeneratorTypeRoots() {
|
|
118
|
+
let dir = __generatorDir;
|
|
119
|
+
for (let i = 0; i < 6; i++) {
|
|
120
|
+
const atTypes = path.join(dir, 'node_modules', '@types');
|
|
121
|
+
if (fs.existsSync(path.join(atTypes, 'fhir')))
|
|
122
|
+
return [atTypes];
|
|
123
|
+
const parent = path.dirname(dir);
|
|
124
|
+
if (parent === dir)
|
|
125
|
+
break;
|
|
126
|
+
dir = parent;
|
|
127
|
+
}
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
105
130
|
/** Compile TypeScript files to JavaScript with declaration files */
|
|
106
131
|
async function compileTypeScriptToJS(dir) {
|
|
107
132
|
return new Promise((resolve, reject) => {
|
|
108
133
|
const tscCmd = process.platform === 'win32' ? 'tsc.cmd' : 'tsc';
|
|
109
134
|
// Create a temporary tsconfig.json for compilation
|
|
110
|
-
// Paths are relative to tsconfig location (which is `dir` itself)
|
|
135
|
+
// Paths are relative to tsconfig location (which is `dir` itself); the
|
|
136
|
+
// generator's own @types (absolute) is appended so `@types/fhir` resolves
|
|
137
|
+
// even when the output's deps were skipped (see resolveGeneratorTypeRoots).
|
|
111
138
|
const tsconfig = {
|
|
112
139
|
compilerOptions: {
|
|
113
140
|
target: 'ES2020',
|
|
@@ -121,7 +148,7 @@ async function compileTypeScriptToJS(dir) {
|
|
|
121
148
|
allowSyntheticDefaultImports: true,
|
|
122
149
|
strict: true,
|
|
123
150
|
resolveJsonModule: true,
|
|
124
|
-
typeRoots: ['./node_modules/@types'],
|
|
151
|
+
typeRoots: ['./node_modules/@types', ...resolveGeneratorTypeRoots()],
|
|
125
152
|
types: ['node']
|
|
126
153
|
},
|
|
127
154
|
include: ['./**/*.ts'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babelfhir-ts",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.16",
|
|
4
4
|
"description": "BabelFHIR-TS: generate TypeScript interfaces, validators, and helper classes from FHIR R4/R4B/R5 StructureDefinitions (profiles) directly inside package archives.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "out/src/main.js",
|