Skip to content

Commit d6e8322

Browse files
author
Keegan Caruso
committed
Merge remote-tracking branch 'upstream/main' into users/keegancaruso/2019-09-schema
2 parents 72d5ab6 + a78b2ff commit d6e8322

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+517
-1638
lines changed

.mocharc.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ test/
1010
.gitignore
1111
.travis.yml
1212
eslint.config.mjs
13-
gulpfile.js
14-
.mocharc.json
13+
gulpfile.js

.vscode/launch.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@
1414
"name": "Unit Tests",
1515
"type": "node",
1616
"request": "launch",
17-
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
18-
"stopOnEntry": false,
19-
"args": [
20-
"--timeout",
21-
"999999",
22-
"--colors"
17+
"runtimeArgs": [
18+
"--test",
19+
"./lib/esm/test/*.test.js"
2320
],
2421
"cwd": "${workspaceRoot}",
25-
"runtimeExecutable": null,
26-
"runtimeArgs": [],
27-
"env": {},
2822
"sourceMaps": true,
29-
"outFiles": [ "${workspaceRoot}/lib/umd/**/*.js" ],
23+
"outFiles": [ "${workspaceRoot}/lib/esm/**/*.js" ],
3024
"preLaunchTask": "npm: watch"
3125
},
3226
{

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
6.0.0-next.1 / 2026-03-04
2+
================
3+
* Breaking: the package is now ESM-only (`"type": "module"`) and exposes ESM entry points through `exports`.
4+
* Breaking: CommonJS/UMD output is no longer produced. Build, test and sample scripts now target `lib/esm`.
5+
* Updated TypeScript configuration to `NodeNext` module settings for Node ESM compatibility.
6+
* Removed `tsconfig.esm.json` as a separate build target (the main tsconfig now covers ESM output).
7+
* Converted build scripts in `build/` to ESM and added `npm run bundle-schemas`.
8+
19
5.7.0 / 2026-01-12
210
================
311
* the error code for `SchemaResolveError` is now 0x10000 plus the error code returned by the request service.
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
const fs = require('fs').promises;
7-
const Bundler = require("@hyperjump/json-schema-bundle");
6+
import { writeFile } from 'node:fs/promises';
7+
import Bundler from '@hyperjump/json-schema-bundle';
88

99
(async function () {
10-
bundle(`https://json-schema.org/draft/2019-09/schema`, 'draft-2019-09', 'https://json-schema.org/draft/2019-09');
11-
bundle(`https://json-schema.org/draft/2020-12/schema`, 'draft-2020-12', 'https://json-schema.org/draft/2020-12');
10+
bundle('https://json-schema.org/draft/2019-09/schema', 'draft-2019-09', 'https://json-schema.org/draft/2019-09');
11+
bundle('https://json-schema.org/draft/2020-12/schema', 'draft-2020-12', 'https://json-schema.org/draft/2020-12');
1212
}());
1313

1414
async function bundle(uri, filename, derivedURL) {
1515
const metaSchema = await Bundler.get(uri);
1616
let bundle = await Bundler.bundle(metaSchema);
1717
bundle = JSON.parse(JSON.stringify(bundle, null, 2).replace(/"undefined": ""/g, '"$dynamicAnchor": "meta"'));
18-
fs.writeFile(`./${filename}.json`, JSON.stringify(bundle, null, 2), 'utf8');
18+
await writeFile(`./${filename}.json`, JSON.stringify(bundle, null, 2), 'utf8');
1919
bundle = flattenDraftMetaSchema(bundle);
2020
const jsified = getCopyright(derivedURL) + 'export default ' + printObject(bundle);
21-
fs.writeFile(`./${filename}-flat.json`, JSON.stringify(bundle, null, 2), 'utf8');
22-
fs.writeFile(`./src/services/schemas/${filename}-flat.ts`, jsified, 'utf8');
21+
await writeFile(`./${filename}-flat.json`, JSON.stringify(bundle, null, 2), 'utf8');
22+
await writeFile(`./src/services/schemas/${filename}-flat.ts`, jsified, 'utf8');
2323
}
2424
function getCopyright(derivedURL) {
2525
return [
@@ -55,7 +55,7 @@ function indent(level) {
5555
function printObject(obj, indentLevel = 0) {
5656
const result = [];
5757
if (Array.isArray(obj)) {
58-
result.push(`[`);
58+
result.push('[');
5959
for (const item of obj) {
6060
if (typeof item === 'object' && item !== null) {
6161
result.push(`${indent(indentLevel + 1)}${printObject(item, indentLevel + 1)},`);
@@ -67,11 +67,11 @@ function printObject(obj, indentLevel = 0) {
6767
return result.join('\n');
6868
}
6969
if (obj === null) {
70-
result.push(`null`);
70+
result.push('null');
7171
return result.join('\n');
7272
}
7373

74-
result.push(`{`);
74+
result.push('{');
7575
for (const [key, value] of Object.entries(obj)) {
7676
if (typeof value === 'object' && value !== null) {
7777
result.push(`${indent(indentLevel + 1)}${printKey(key)}: ${printObject(value, indentLevel + 1)},`);
@@ -106,9 +106,9 @@ function replaceDynamicRefs(node, anchorName = DEFAULT_ANCHOR) {
106106
visit(node, (n, k) => {
107107
const v = n[k];
108108
if (k === '$dynamicRef' && v === '#' + anchorName) {
109-
n['$ref'] = '#';
110-
delete n['$dynamicRef'];
111-
};
109+
n.$ref = '#';
110+
delete n.$dynamicRef;
111+
}
112112
});
113113
}
114114

@@ -117,9 +117,9 @@ function replaceRecursiveRefs(node, anchorName = DEFAULT_ANCHOR) {
117117
visit(node, (n, k) => {
118118
const v = n[k];
119119
if (k === '$recursiveRef') {
120-
n['$ref'] = v;
121-
delete n['$recursiveRef'];
122-
};
120+
n.$ref = v;
121+
delete n.$recursiveRef;
122+
}
123123
});
124124
}
125125

@@ -130,7 +130,7 @@ function replaceOldRefs(node, anchorName = DEFAULT_ANCHOR) {
130130
if (k === '$ref' && typeof v === 'string' && v.startsWith(anchorName + '/')) {
131131
const segments = v.split('#');
132132
if (segments.length === 2) {
133-
n['$ref'] = `#${segments[1]}`;
133+
n.$ref = `#${segments[1]}`;
134134
}
135135
}
136136
});
@@ -149,7 +149,7 @@ function stripDynamicAnchors(node) {
149149
function collectVocabularies(schema) {
150150
const vocabularies = [];
151151
const defs = schema.$defs || {};
152-
for (const [key, value] of Object.entries(defs)) {
152+
for (const [, value] of Object.entries(defs)) {
153153
if (value && typeof value === 'object' && !Array.isArray(value) && value.$id && value.$dynamicAnchor === DEFAULT_ANCHOR && value.properties) {
154154
vocabularies.push(value);
155155
}
@@ -251,4 +251,4 @@ function flattenDraftMetaSchema(original) {
251251
}
252252

253253
return schema;
254-
}
254+
}

build/remove-sourcemap-refs.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,33 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
const fs = require('fs');
7-
const path = require('path');
6+
import fs from 'node:fs';
7+
import path from 'node:path';
8+
import { fileURLToPath } from 'node:url';
9+
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
811

912
function deleteRefs(dir) {
1013
const files = fs.readdirSync(dir);
11-
for (let file of files) {
14+
for (const file of files) {
1215
const filePath = path.join(dir, file);
1316
const stat = fs.statSync(filePath);
1417
if (stat.isDirectory()) {
1518
deleteRefs(filePath);
1619
} else if (path.extname(file) === '.js') {
1720
const content = fs.readFileSync(filePath, 'utf8');
18-
const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '')
21+
const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '');
1922
if (content.length !== newContent.length) {
2023
console.log('remove sourceMappingURL in ' + filePath);
2124
fs.writeFileSync(filePath, newContent);
2225
}
2326
} else if (path.extname(file) === '.map') {
24-
fs.unlinkSync(filePath)
27+
fs.unlinkSync(filePath);
2528
console.log('remove ' + filePath);
2629
}
2730
}
2831
}
2932

30-
let location = path.join(__dirname, '..', 'lib');
33+
const location = path.join(__dirname, '..', 'lib');
3134
console.log('process ' + location);
3235
deleteRefs(location);

0 commit comments

Comments
 (0)