Skip to content

Commit

Permalink
Fix for .d.ts inside node_modules complaining during ts build
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofVDB1 committed Feb 7, 2024
1 parent ef6302d commit e038b40
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/oslo-extractor-uml-ea/lib/MdbReaderWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import * as MDBReaderOriginal from 'mdb-reader';
// The workaround is to use the default import of the library and then access the default property
// of the default import, which will throw some errors in the editor, but will work as expected.

// This fix was implemented to fix the encoding problem that arose with using the mdb-reader library:
// This fix waks implemented to fix the encoding problem that arose with using the mdb-reader library:
// https://github.com/andipaetzold/mdb-reader/issues/172
// This was also something that our editors noticed and we had to fix it in order to use the library:
// https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues/36


const MDBReader = MDBReaderOriginal.default.default;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const MDBReader = (<any>MDBReaderOriginal.default).default;

export default MDBReader;
11 changes: 5 additions & 6 deletions scripts/esmtocjs.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const esbuild = require('esbuild');
const glob = require('glob');
const fs = require('fs').promises;
const fs = require('fs');
const path = require('path');

async function transpileNodeModules() {
const transpileNodeModules = async () => {
// Get package.json file of mdb-reader module
const packageJsonPath = 'packages/oslo-extractor-uml-ea/node_modules/mdb-reader/package.json';

try {
const json = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

// Skip unless the type of the package is ESM
if (!json.name || json.type !== 'module') {
return;
}

console.log(`🦀 Transpiling ${json.name}...`);
console.log(`🦀 Transpiling ${json?.name}...`);

const dir = path.dirname(packageJsonPath);

Expand Down Expand Up @@ -45,11 +45,10 @@ async function transpileNodeModules() {

// Change the type of the package to commonjs
json.type = 'commonjs';
await fs.writeFile(packageJsonPath, JSON.stringify(json, null, 2));
fs.writeFileSync(packageJsonPath, JSON.stringify(json, null, 2));
} catch (e) {
console.log('Error: Wasnt able to run postinstall script. Make sure the packages inside oslo-extractor-uml-ea are installed.')
console.error(e);
}
}

transpileNodeModules();
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"skipLibCheck": true,
"sourceMap": true,
"inlineSources": true,
"declaration": true,
Expand Down

0 comments on commit e038b40

Please sign in to comment.