Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use createRequire for comapeo/geometry #25

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/faker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { JSONSchemaFaker } from 'json-schema-faker'
import { faker } from '@faker-js/faker'
import deref from 'dereference-json-schema'
import { readFile } from 'node:fs/promises'

const geometryPath = new URL(
'../node_modules/@comapeo/geometry/json/geometry.json',
import.meta.url,
).pathname
const Geometry = JSON.parse(await readFile(geometryPath, 'utf-8'))
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const Geometry = require('@comapeo/geometry/json/geometry.json')

/**
* @typedef {typeof import('@comapeo/schema').docSchemas[import('@comapeo/schema/dist/types.js').SchemaName]} ValidSchema
Expand Down Expand Up @@ -176,8 +172,9 @@ function createFakerSchema(schema) {
return s
}
case 'RemoteDetectionAlert':
// @ts-ignore
s.properties.geometry = {
$ref: Geometry.$id,
//$ref: Geometry.$id,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this change from 03eb40c since keeping $ref returns an invalid object (it doesn't respect the geometry schema...)

...deref.dereferenceSync(Geometry),
}
return s
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"emitDeclarationOnly": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true,
"declarationDir": "./types"
"declarationDir": "./types",
"resolveJsonModule": true
},
"include": ["./index.js", "lib/**/*.js"],
"exclude": ["bin"]
Expand Down