Skip to content

Commit

Permalink
Fix (de)serialization of maps (resolves #656)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 27, 2024
1 parent 24c1355 commit 3ab95ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ jobs:
- run: |
cd query
pnpm install
knip
knip --cache
knip --cache
- name: Test Knip against argos-ci/argos
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/src/CacheConsultant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const dummyFileDescriptor = { key: '', changed: true, notFound: true, meta: unde

const isEnabled = isCache || isWatch;

const version = '2';
const version = '3';

export class CacheConsultant<T> {
private cache: undefined | FileEntryCache;
Expand Down
16 changes: 14 additions & 2 deletions packages/knip/src/util/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import type { SerializableFile } from '../types/serializable-map.js';

const keys = new Set(['importedAs', 'reExportedBy', 'reExportedAs', 'reExportedNs']);

// biome-ignore lint/suspicious/noExplicitAny: TODO
const setisfy = (obj: any) => {
if (obj instanceof Set) return Array.from(obj);
if (typeof obj === 'object') for (const key in obj) obj[key] = setisfy(obj[key]);
if (obj instanceof Map) return setisfy(Object.fromEntries(obj.entries()));
if (typeof obj === 'object')
for (const key in obj) {
obj[key] = setisfy(obj[key]);
}
return obj;
};

// biome-ignore lint/suspicious/noExplicitAny: TODO
const unsetisfy = (obj: any) => {
if (Array.isArray(obj)) return new Set(obj);
if (typeof obj === 'object') for (const key in obj) obj[key] = unsetisfy(obj[key]);
if (typeof obj === 'object') {
for (const key in obj) {
if (keys.has(key)) {
if (!(obj[key] instanceof Map)) obj[key] = new Map(Object.entries(obj[key]).map(v => [v[0], unsetisfy(v[1])]));
} else obj[key] = unsetisfy(obj[key]);
}
}
return obj;
};

Expand Down

0 comments on commit 3ab95ef

Please sign in to comment.