Skip to content

Commit

Permalink
fix: allow to import JSON schema as JS module
Browse files Browse the repository at this point in the history
This makes it easier to work from ESM code bases.
  • Loading branch information
targos committed Oct 10, 2024
1 parent 9bfc38d commit a9e3c8f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FilterXYSchema.js
FilterXYSchema.json

# Logs
Expand Down
2 changes: 2 additions & 0 deletions FilterXYSchema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const schema: typeof import('./FilterXYSchema.json')
export = schema;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"src",
"lib",
"lib-esm",
"FilterXYSchema.d.ts",
"FilterXYSchema.js",
"FilterXYSchema.json"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"createSchema": "typescript-json-schema --refs false ./tsconfig.json FilterXYType > FilterXYSchema.json",
"postcreateSchema": "node scripts/create_js_schema.mjs",
"eslint": "eslint src --cache",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "npm run createSchema && npm run tsc",
Expand Down
9 changes: 9 additions & 0 deletions scripts/create_js_schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'node:fs';

const schema = fs.readFileSync(new URL('../FilterXYSchema.json', import.meta.url), 'utf8');

const schemaJs = `'use strict';
module.exports = ${schema}`;

fs.writeFileSync(new URL('../FilterXYSchema.js', import.meta.url), schemaJs);

0 comments on commit a9e3c8f

Please sign in to comment.