diff --git a/.npmignore b/.npmignore index 6a1cd2f..00a357f 100644 --- a/.npmignore +++ b/.npmignore @@ -11,3 +11,4 @@ test/ .gitignore .mocharc.json .eslintrc.json +eslint.config.cjs diff --git a/.vscode/launch.json b/.vscode/launch.json index d7083da..58603d3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,11 +11,11 @@ "runtimeArgs": [ "--enable-source-maps", "--test", - "./lib/umd/test/**/*.test.js" + "./lib/esm/test/**/*.test.js" ], "env": {}, "sourceMaps": true, - "outFiles": ["${workspaceRoot}/lib/umd/**/*.js"], + "outFiles": ["${workspaceRoot}/lib/esm/**/*.js"], "preLaunchTask": "npm: watch" } ] diff --git a/CHANGELOG.md b/CHANGELOG.md index 3414a3f..d81a5fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +4.0.0-next.1 2026-03-04 +================= +- package is now ESM-only. +- remove UMD build and package entrypoints. + + 3.3.0 2022-06-24 ================= - `JSONVisitor.onObjectBegin` and `JSONVisitor.onArrayBegin` can now return `false` to instruct the visitor that no children should be visited. diff --git a/README.md b/README.md index 08aa17b..9092210 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ JSONC is JSON with JavaScript style comments. This node module provides a scanne Installation ------------ +`jsonc-parser` is published as an ESM-only package. + ``` npm install --save jsonc-parser ``` diff --git a/build/remove-sourcemap-refs.js b/build/remove-sourcemap-refs.cjs similarity index 100% rename from build/remove-sourcemap-refs.js rename to build/remove-sourcemap-refs.cjs diff --git a/eslint.config.js b/eslint.config.cjs similarity index 100% rename from eslint.config.js rename to eslint.config.cjs diff --git a/package-lock.json b/package-lock.json index 9a7d72d..43cd467 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "jsonc-parser", - "version": "3.3.1", + "version": "4.0.0-next.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "jsonc-parser", - "version": "3.3.1", + "version": "4.0.0-next.1", "license": "MIT", "devDependencies": { "@types/node": "22.x", diff --git a/package.json b/package.json index 4b40781..0a5eb82 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,15 @@ { "name": "jsonc-parser", - "version": "3.3.1", + "version": "4.0.0-next.1", "description": "Scanner and parser for JSON with comments.", - "main": "./lib/umd/main.js", - "typings": "./lib/umd/main.d.ts", - "module": "./lib/esm/main.js", + "type": "module", + "exports": { + ".": { + "types": "./lib/esm/main.d.ts", + "import": "./lib/esm/main.js" + } + }, + "types": "./lib/esm/main.d.ts", "author": "Microsoft Corporation", "repository": { "type": "git", @@ -23,13 +28,12 @@ "typescript": "^5.8.3" }, "scripts": { - "prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs", + "prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs", "compile": "tsc -p ./src && npm run lint", - "compile-esm": "tsc -p ./src/tsconfig.esm.json", - "remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js", + "remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.cjs", "clean": "rimraf lib", "watch": "tsc -w -p ./src", - "test": "npm run compile && node --enable-source-maps --test ./lib/umd/test/**/*.test.js", + "test": "npm run compile && node --enable-source-maps --test ./lib/esm/test/**/*.test.js", "lint": "eslint src/**/*.ts" } } diff --git a/src/impl/edit.ts b/src/impl/edit.ts index e810c6b..4ce554c 100644 --- a/src/impl/edit.ts +++ b/src/impl/edit.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { Edit, ParseError, Node, JSONPath, Segment, ModificationOptions } from '../main'; -import { format, isEOL } from './format'; -import { parseTree, findNodeAtLocation } from './parser'; +import { Edit, ParseError, Node, JSONPath, Segment, ModificationOptions } from '../main.js'; +import { format, isEOL } from './format.js'; +import { parseTree, findNodeAtLocation } from './parser.js'; export function removeProperty(text: string, path: JSONPath, options: ModificationOptions): Edit[] { return setProperty(text, path, void 0, options); diff --git a/src/impl/format.ts b/src/impl/format.ts index 383f2fb..e9081fb 100644 --- a/src/impl/format.ts +++ b/src/impl/format.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { Range, FormattingOptions, Edit, SyntaxKind, ScanError } from '../main'; -import { createScanner } from './scanner'; -import { cachedSpaces, cachedBreakLinesWithSpaces, supportedEols, SupportedEOL } from './string-intern'; +import { Range, FormattingOptions, Edit, SyntaxKind, ScanError } from '../main.js'; +import { createScanner } from './scanner.js'; +import { cachedSpaces, cachedBreakLinesWithSpaces, supportedEols, SupportedEOL } from './string-intern.js'; export function format(documentText: string, range: Range | undefined, options: FormattingOptions): Edit[] { let initialIndentLevel: number; diff --git a/src/impl/parser.ts b/src/impl/parser.ts index 36de808..13a2b3b 100644 --- a/src/impl/parser.ts +++ b/src/impl/parser.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { createScanner } from './scanner'; +import { createScanner } from './scanner.js'; import { JSONPath, JSONVisitor, @@ -17,7 +17,7 @@ import { ScanError, Segment, SyntaxKind -} from '../main'; +} from '../main.js'; namespace ParseOptionsConfigs { export const DEFAULT = { diff --git a/src/impl/scanner.ts b/src/impl/scanner.ts index 7c27882..daad8ff 100644 --- a/src/impl/scanner.ts +++ b/src/impl/scanner.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { ScanError, SyntaxKind, JSONScanner } from '../main'; +import { ScanError, SyntaxKind, JSONScanner } from '../main.js'; /** * Creates a JSON scanner on the given text. diff --git a/src/main.ts b/src/main.ts index 5bd3566..7de1974 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,10 +4,10 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import * as formatter from './impl/format'; -import * as edit from './impl/edit'; -import * as scanner from './impl/scanner'; -import * as parser from './impl/parser'; +import * as formatter from './impl/format.js'; +import * as edit from './impl/edit.js'; +import * as scanner from './impl/scanner.js'; +import * as parser from './impl/parser.js'; /** * Creates a JSON scanner on the given text. diff --git a/src/test/edit.test.ts b/src/test/edit.test.ts index 1be0622..5b57669 100644 --- a/src/test/edit.test.ts +++ b/src/test/edit.test.ts @@ -6,18 +6,18 @@ import * as assert from 'node:assert'; import { suite, test } from 'node:test'; -import { Edit, FormattingOptions, ModificationOptions, modify } from '../main'; +import { Edit, FormattingOptions, ModificationOptions, modify } from '../main.js'; suite('JSON - edits', () => { function assertEdit(content: string, edits: Edit[], expected: string) { - assert(edits); + assert.ok(edits); let lastEditOffset = content.length; for (let i = edits.length - 1; i >= 0; i--) { let edit = edits[i]; - assert(edit.offset >= 0 && edit.length >= 0 && edit.offset + edit.length <= content.length); - assert(typeof edit.content === 'string'); - assert(lastEditOffset >= edit.offset + edit.length); // make sure all edits are ordered + assert.ok(edit.offset >= 0 && edit.length >= 0 && edit.offset + edit.length <= content.length); + assert.ok(typeof edit.content === 'string'); + assert.ok(lastEditOffset >= edit.offset + edit.length); // make sure all edits are ordered lastEditOffset = edit.offset; content = content.substring(0, edit.offset) + edit.content + content.substring(edit.offset + edit.length); } diff --git a/src/test/format.test.ts b/src/test/format.test.ts index abd59b4..3d66fef 100644 --- a/src/test/format.test.ts +++ b/src/test/format.test.ts @@ -6,8 +6,8 @@ import * as assert from 'node:assert'; import { suite, test } from 'node:test'; -import * as Formatter from '../impl/format'; -import { Range } from '../main'; +import * as Formatter from '../impl/format.js'; +import { Range } from '../main.js'; suite('JSON - formatter', () => { diff --git a/src/test/json.test.ts b/src/test/json.test.ts index 245b25a..f6c7601 100644 --- a/src/test/json.test.ts +++ b/src/test/json.test.ts @@ -9,7 +9,7 @@ import { suite, test } from 'node:test'; import { SyntaxKind, createScanner, parse, getLocation, Node, ParseError, parseTree, ParseErrorCode, ParseOptions, Segment, findNodeAtLocation, getNodeValue, getNodePath, ScanError, visit, JSONVisitor, JSONPath -} from '../main'; +} from '../main.js'; function assertKinds(text: string, ...kinds: SyntaxKind[]): void { var scanner = createScanner(text); @@ -44,7 +44,7 @@ function assertInvalidParse(input: string, expected: any, options?: ParseOptions var errors: ParseError[] = []; var actual = parse(input, errors, options); - assert(errors.length > 0); + assert.ok(errors.length > 0); assert.deepStrictEqual(actual, expected); } @@ -118,7 +118,7 @@ function assertLocation(input: string, expectedSegments: Segment[], expectedNode var offset = input.indexOf('|'); input = input.substring(0, offset) + input.substring(offset + 1, input.length); var actual = getLocation(input, offset); - assert(actual); + assert.ok(actual); assert.deepStrictEqual(actual.path, expectedSegments, input); assert.strictEqual(actual.previousNode && actual.previousNode.type, expectedNodeType, input); assert.strictEqual(actual.isAtPropertyKey, expectedCompleteProperty, input); @@ -128,7 +128,7 @@ function assertMatchesLocation(input: string, matchingSegments: Segment[], expec var offset = input.indexOf('|'); input = input.substring(0, offset) + input.substring(offset + 1, input.length); var actual = getLocation(input, offset); - assert(actual); + assert.ok(actual); assert.strictEqual(actual.matches(matchingSegments), expectedResult); } diff --git a/src/test/string-intern.test.ts b/src/test/string-intern.test.ts index 2e5dd6d..b1a967e 100644 --- a/src/test/string-intern.test.ts +++ b/src/test/string-intern.test.ts @@ -1,6 +1,6 @@ import * as assert from 'node:assert'; import { suite, test } from 'node:test'; -import { cachedBreakLinesWithSpaces, cachedSpaces, supportedEols } from '../impl/string-intern'; +import { cachedBreakLinesWithSpaces, cachedSpaces, supportedEols } from '../impl/string-intern.js'; suite('string intern', () => { test('should correctly define spaces intern', () => { diff --git a/src/tsconfig.esm.json b/src/tsconfig.esm.json deleted file mode 100644 index 8c8246c..0000000 --- a/src/tsconfig.esm.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "target": "es2020", - "module": "es6", - "moduleResolution": "node", - "sourceMap": true, - "declaration": true, - "stripInternal": true, - "outDir": "../lib/esm", - "strict": true, - "preserveConstEnums": true, - "lib": [ - "es2020" - ] - } -} \ No newline at end of file diff --git a/src/tsconfig.json b/src/tsconfig.json index d399fcb..ffabd33 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,12 +1,12 @@ { "compilerOptions": { "target": "es2020", - "module": "umd", - "moduleResolution": "node", + "module": "NodeNext", + "moduleResolution": "NodeNext", "sourceMap": true, "declaration": true, "stripInternal": true, - "outDir": "../lib/umd", + "outDir": "../lib/esm", "strict": true, "preserveConstEnums": true, "lib": [