diff --git a/.vscode/launch.json b/.vscode/launch.json index 7a57f633..40f586ce 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,11 +16,11 @@ "request": "launch", "runtimeArgs": [ "--test", - "./lib/umd/test/**/*.test.js" + "./lib/esm/test/**/*.test.js" ], "cwd": "${workspaceRoot}", "sourceMaps": true, - "outFiles": [ "${workspaceRoot}/lib/umd/**/*.js" ], + "outFiles": [ "${workspaceRoot}/lib/esm/**/*.js" ], "preLaunchTask": "npm: watch" }, { diff --git a/build/bundle-schemas.cjs b/build/bundle-schemas.js similarity index 90% rename from build/bundle-schemas.cjs rename to build/bundle-schemas.js index 220e2ff6..76b538c2 100644 --- a/build/bundle-schemas.cjs +++ b/build/bundle-schemas.js @@ -3,23 +3,23 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -const fs = require('fs').promises; -const Bundler = require("@hyperjump/json-schema-bundle"); +import { writeFile } from 'node:fs/promises'; +import Bundler from '@hyperjump/json-schema-bundle'; (async function () { - bundle(`https://json-schema.org/draft/2019-09/schema`, 'draft-2019-09', 'https://json-schema.org/draft/2019-09'); - bundle(`https://json-schema.org/draft/2020-12/schema`, 'draft-2020-12', 'https://json-schema.org/draft/2020-12'); + bundle('https://json-schema.org/draft/2019-09/schema', 'draft-2019-09', 'https://json-schema.org/draft/2019-09'); + bundle('https://json-schema.org/draft/2020-12/schema', 'draft-2020-12', 'https://json-schema.org/draft/2020-12'); }()); async function bundle(uri, filename, derivedURL) { const metaSchema = await Bundler.get(uri); let bundle = await Bundler.bundle(metaSchema); bundle = JSON.parse(JSON.stringify(bundle, null, 2).replace(/"undefined": ""/g, '"$dynamicAnchor": "meta"')); - fs.writeFile(`./${filename}.json`, JSON.stringify(bundle, null, 2), 'utf8'); + await writeFile(`./${filename}.json`, JSON.stringify(bundle, null, 2), 'utf8'); bundle = flattenDraftMetaSchema(bundle); const jsified = getCopyright(derivedURL) + 'export default ' + printObject(bundle); - fs.writeFile(`./${filename}-flat.json`, JSON.stringify(bundle, null, 2), 'utf8'); - fs.writeFile(`./src/services/schemas/${filename}-flat.ts`, jsified, 'utf8'); + await writeFile(`./${filename}-flat.json`, JSON.stringify(bundle, null, 2), 'utf8'); + await writeFile(`./src/services/schemas/${filename}-flat.ts`, jsified, 'utf8'); } function getCopyright(derivedURL) { return [ @@ -55,7 +55,7 @@ function indent(level) { function printObject(obj, indentLevel = 0) { const result = []; if (Array.isArray(obj)) { - result.push(`[`); + result.push('['); for (const item of obj) { if (typeof item === 'object' && item !== null) { result.push(`${indent(indentLevel + 1)}${printObject(item, indentLevel + 1)},`); @@ -67,11 +67,11 @@ function printObject(obj, indentLevel = 0) { return result.join('\n'); } if (obj === null) { - result.push(`null`); + result.push('null'); return result.join('\n'); } - result.push(`{`); + result.push('{'); for (const [key, value] of Object.entries(obj)) { if (typeof value === 'object' && value !== null) { result.push(`${indent(indentLevel + 1)}${printKey(key)}: ${printObject(value, indentLevel + 1)},`); @@ -106,9 +106,9 @@ function replaceDynamicRefs(node, anchorName = DEFAULT_ANCHOR) { visit(node, (n, k) => { const v = n[k]; if (k === '$dynamicRef' && v === '#' + anchorName) { - n['$ref'] = '#'; - delete n['$dynamicRef']; - }; + n.$ref = '#'; + delete n.$dynamicRef; + } }); } @@ -117,9 +117,9 @@ function replaceRecursiveRefs(node, anchorName = DEFAULT_ANCHOR) { visit(node, (n, k) => { const v = n[k]; if (k === '$recursiveRef') { - n['$ref'] = v; - delete n['$recursiveRef']; - }; + n.$ref = v; + delete n.$recursiveRef; + } }); } @@ -130,7 +130,7 @@ function replaceOldRefs(node, anchorName = DEFAULT_ANCHOR) { if (k === '$ref' && typeof v === 'string' && v.startsWith(anchorName + '/')) { const segments = v.split('#'); if (segments.length === 2) { - n['$ref'] = `#${segments[1]}`; + n.$ref = `#${segments[1]}`; } } }); @@ -149,7 +149,7 @@ function stripDynamicAnchors(node) { function collectVocabularies(schema) { const vocabularies = []; const defs = schema.$defs || {}; - for (const [key, value] of Object.entries(defs)) { + for (const [, value] of Object.entries(defs)) { if (value && typeof value === 'object' && !Array.isArray(value) && value.$id && value.$dynamicAnchor === DEFAULT_ANCHOR && value.properties) { vocabularies.push(value); } @@ -251,4 +251,4 @@ function flattenDraftMetaSchema(original) { } return schema; -} +} \ No newline at end of file diff --git a/build/remove-sourcemap-refs.js b/build/remove-sourcemap-refs.js index 4c008223..582d408e 100644 --- a/build/remove-sourcemap-refs.js +++ b/build/remove-sourcemap-refs.js @@ -3,30 +3,33 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -const fs = require('fs'); -const path = require('path'); +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); function deleteRefs(dir) { const files = fs.readdirSync(dir); - for (let file of files) { + for (const file of files) { const filePath = path.join(dir, file); const stat = fs.statSync(filePath); if (stat.isDirectory()) { deleteRefs(filePath); } else if (path.extname(file) === '.js') { const content = fs.readFileSync(filePath, 'utf8'); - const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '') + const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, ''); if (content.length !== newContent.length) { console.log('remove sourceMappingURL in ' + filePath); fs.writeFileSync(filePath, newContent); } } else if (path.extname(file) === '.map') { - fs.unlinkSync(filePath) + fs.unlinkSync(filePath); console.log('remove ' + filePath); } } } -let location = path.join(__dirname, '..', 'lib'); +const location = path.join(__dirname, '..', 'lib'); console.log('process ' + location); deleteRefs(location); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index db59f87b..fdda6fb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-json-languageservice", - "version": "5.7.2", + "version": "6.0.0-next.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-json-languageservice", - "version": "5.7.2", + "version": "6.0.0-next.1", "license": "MIT", "dependencies": { "@vscode/l10n": "^0.0.18", diff --git a/package.json b/package.json index de780e43..b17e094b 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,15 @@ { "name": "vscode-json-languageservice", - "version": "5.7.2", + "version": "6.0.0-next.1", "description": "Language service for JSON", - "main": "./lib/umd/jsonLanguageService.js", - "typings": "./lib/umd/jsonLanguageService", - "module": "./lib/esm/jsonLanguageService.js", + "type": "module", + "types": "./lib/esm/jsonLanguageService.d.ts", + "exports": { + ".": { + "types": "./lib/esm/jsonLanguageService.d.ts", + "import": "./lib/esm/jsonLanguageService.js" + } + }, "author": "Microsoft Corporation", "repository": { "type": "git", @@ -31,18 +36,18 @@ "@vscode/l10n": "^0.0.18" }, "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", - "compile-esm": "tsc -p ./src/tsconfig.esm.json", "clean": "rimraf lib", + "bundle-schemas": "node ./build/bundle-schemas.js", "remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js", "watch": "tsc -w -p ./src", "pretest": "npm run compile", - "test": "node --test ./lib/umd/test/**/*.test.js", + "test": "node --test ./lib/esm/test/**/*.test.js", "posttest": "npm run lint", "coverage": "npx nyc -r lcov npm run test", "lint": "eslint src/**/*.ts", "install-types-next": "npm install vscode-languageserver-types@next -f -S && npm install vscode-languageserver-textdocument@next -f -S", - "sample": "npm run compile && node ./lib/umd/example/sample.js" + "sample": "npm run compile && node ./lib/esm/example/sample.js" } } diff --git a/src/example/sample.ts b/src/example/sample.ts index b45e4aac..dd2a9925 100644 --- a/src/example/sample.ts +++ b/src/example/sample.ts @@ -1,6 +1,6 @@ -import { getLanguageService, TextDocument } from '../jsonLanguageService'; +import { getLanguageService, TextDocument } from '../jsonLanguageService.js'; async function main() { const jsonContentUri = 'foo://server/example.data.json'; diff --git a/src/jsonContributions.ts b/src/jsonContributions.ts index fe5be120..dfe8c4da 100644 --- a/src/jsonContributions.ts +++ b/src/jsonContributions.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MarkedString, CompletionItem } from './jsonLanguageService'; +import { MarkedString, CompletionItem } from './jsonLanguageService.js'; export interface JSONWorkerContribution { getInfoContribution(uri: string, location: JSONPath): PromiseLike; diff --git a/src/jsonLanguageService.ts b/src/jsonLanguageService.ts index 56d3f795..4a0c90df 100644 --- a/src/jsonLanguageService.ts +++ b/src/jsonLanguageService.ts @@ -3,18 +3,18 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { JSONCompletion } from './services/jsonCompletion'; -import { JSONHover } from './services/jsonHover'; -import { JSONValidation } from './services/jsonValidation'; +import { JSONCompletion } from './services/jsonCompletion.js'; +import { JSONHover } from './services/jsonHover.js'; +import { JSONValidation } from './services/jsonValidation.js'; -import { JSONDocumentSymbols } from './services/jsonDocumentSymbols'; -import { parse as parseJSON, newJSONDocument } from './parser/jsonParser'; -import { schemaContributions } from './services/configuration'; -import { JSONSchemaService } from './services/jsonSchemaService'; -import { getFoldingRanges } from './services/jsonFolding'; -import { getSelectionRanges } from './services/jsonSelectionRanges'; -import { sort } from './utils/sort'; -import { format } from './utils/format'; +import { JSONDocumentSymbols } from './services/jsonDocumentSymbols.js'; +import { parse as parseJSON, newJSONDocument } from './parser/jsonParser.js'; +import { schemaContributions } from './services/configuration.js'; +import { JSONSchemaService } from './services/jsonSchemaService.js'; +import { getFoldingRanges } from './services/jsonFolding.js'; +import { getSelectionRanges } from './services/jsonSelectionRanges.js'; +import { sort } from './utils/sort.js'; +import { format } from './utils/format.js'; import { ASTNode, @@ -24,15 +24,15 @@ import { TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus, SortOptions -} from './jsonLanguageTypes'; -import { findLinks } from './services/jsonLinks'; +} from './jsonLanguageTypes.js'; +import { findLinks } from './services/jsonLinks.js'; import { DocumentLink } from 'vscode-languageserver-types'; export type JSONDocument = { root: ASTNode | undefined; getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined; }; -export * from './jsonLanguageTypes'; +export * from './jsonLanguageTypes.js'; export interface LanguageService { configure(settings: LanguageSettings): void; diff --git a/src/jsonLanguageTypes.ts b/src/jsonLanguageTypes.ts index 855fa921..ae32f5e0 100644 --- a/src/jsonLanguageTypes.ts +++ b/src/jsonLanguageTypes.ts @@ -3,8 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions'; -import { JSONSchema } from './jsonSchema'; +import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions.js'; +import { JSONSchema } from './jsonSchema.js'; import { Range, Position, DocumentUri, MarkupContent, MarkupKind, Color, ColorInformation, ColorPresentation, diff --git a/src/parser/jsonParser.ts b/src/parser/jsonParser.ts index ebd5f5fe..ad5adb8d 100644 --- a/src/parser/jsonParser.ts +++ b/src/parser/jsonParser.ts @@ -4,10 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import * as Json from 'jsonc-parser'; -import { JSONSchema, JSONSchemaRef } from '../jsonSchema'; -import { isNumber, equals, isBoolean, isString, isDefined, isObject } from '../utils/objects'; -import { extendedRegExp, stringLength } from '../utils/strings'; -import { TextDocument, ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, JSONPath, ErrorCode, Diagnostic, DiagnosticSeverity, Range, SchemaDraft } from '../jsonLanguageTypes'; +import { JSONSchema, JSONSchemaRef } from '../jsonSchema.js'; +import { isNumber, equals, isBoolean, isString, isDefined, isObject } from '../utils/objects.js'; +import { extendedRegExp, stringLength } from '../utils/strings.js'; +import { TextDocument, ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, JSONPath, ErrorCode, Diagnostic, DiagnosticSeverity, Range, SchemaDraft } from '../jsonLanguageTypes.js'; import { URI } from 'vscode-uri'; import * as l10n from '@vscode/l10n'; diff --git a/src/services/configuration.ts b/src/services/configuration.ts index 6578dba3..c2800dbd 100644 --- a/src/services/configuration.ts +++ b/src/services/configuration.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ISchemaContributions } from './jsonSchemaService'; -import draft201909Flat from './schemas/draft-2019-09-flat'; -import draft202012Flat from './schemas/draft-2020-12-flat'; +import { ISchemaContributions } from './jsonSchemaService.js'; +import draft201909Flat from './schemas/draft-2019-09-flat.js'; +import draft202012Flat from './schemas/draft-2020-12-flat.js'; import * as l10n from '@vscode/l10n'; diff --git a/src/services/jsonCompletion.ts b/src/services/jsonCompletion.ts index 61946ccd..458ae3be 100644 --- a/src/services/jsonCompletion.ts +++ b/src/services/jsonCompletion.ts @@ -3,20 +3,20 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as Parser from '../parser/jsonParser'; +import * as Parser from '../parser/jsonParser.js'; import * as Json from 'jsonc-parser'; -import * as SchemaService from './jsonSchemaService'; -import { JSONSchema, JSONSchemaRef } from '../jsonSchema'; -import { JSONWorkerContribution, CompletionsCollector, JSONCompletionItem } from '../jsonContributions'; -import { stringifyObject } from '../utils/json'; -import { endsWith, extendedRegExp } from '../utils/strings'; -import { isDefined } from '../utils/objects'; +import * as SchemaService from './jsonSchemaService.js'; +import { JSONSchema, JSONSchemaRef } from '../jsonSchema.js'; +import { JSONWorkerContribution, CompletionsCollector, JSONCompletionItem } from '../jsonContributions.js'; +import { stringifyObject } from '../utils/json.js'; +import { endsWith, extendedRegExp } from '../utils/strings.js'; +import { isDefined } from '../utils/objects.js'; import { PromiseConstructor, ASTNode, ObjectASTNode, ArrayASTNode, PropertyASTNode, ClientCapabilities, TextDocument, CompletionItem, CompletionItemKind, CompletionList, Position, Range, TextEdit, InsertTextFormat, MarkupContent, MarkupKind -} from '../jsonLanguageTypes'; +} from '../jsonLanguageTypes.js'; import * as l10n from '@vscode/l10n'; diff --git a/src/services/jsonDocumentSymbols.ts b/src/services/jsonDocumentSymbols.ts index e3b752ca..74941241 100644 --- a/src/services/jsonDocumentSymbols.ts +++ b/src/services/jsonDocumentSymbols.ts @@ -3,17 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as Parser from '../parser/jsonParser'; -import * as Strings from '../utils/strings'; -import { colorFromHex } from '../utils/colors'; +import * as Parser from '../parser/jsonParser.js'; +import * as Strings from '../utils/strings.js'; +import { colorFromHex } from '../utils/colors.js'; import * as l10n from '@vscode/l10n'; import { TextDocument, ColorInformation, ColorPresentation, Color, ASTNode, PropertyASTNode, DocumentSymbolsContext, Range, TextEdit, SymbolInformation, SymbolKind, DocumentSymbol, Location -} from "../jsonLanguageTypes"; +} from "../jsonLanguageTypes.js"; -import { IJSONSchemaService } from "./jsonSchemaService"; +import { IJSONSchemaService } from "./jsonSchemaService.js"; export class JSONDocumentSymbols { diff --git a/src/services/jsonFolding.ts b/src/services/jsonFolding.ts index d04afc13..5460339e 100644 --- a/src/services/jsonFolding.ts +++ b/src/services/jsonFolding.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { createScanner, SyntaxKind, ScanError } from 'jsonc-parser'; -import { TextDocument, FoldingRangeKind, FoldingRange, FoldingRangesContext, Position } from '../jsonLanguageTypes'; +import { TextDocument, FoldingRangeKind, FoldingRange, FoldingRangesContext, Position } from '../jsonLanguageTypes.js'; export function getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[] { const ranges: FoldingRange[] = []; diff --git a/src/services/jsonHover.ts b/src/services/jsonHover.ts index 381d085e..c29d7fc1 100644 --- a/src/services/jsonHover.ts +++ b/src/services/jsonHover.ts @@ -3,10 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as Parser from '../parser/jsonParser'; -import * as SchemaService from './jsonSchemaService'; -import { JSONWorkerContribution } from '../jsonContributions'; -import { TextDocument, PromiseConstructor, Position, Range, Hover, MarkedString } from '../jsonLanguageTypes'; +import * as Parser from '../parser/jsonParser.js'; +import * as SchemaService from './jsonSchemaService.js'; +import { JSONWorkerContribution } from '../jsonContributions.js'; +import { TextDocument, PromiseConstructor, Position, Range, Hover, MarkedString } from '../jsonLanguageTypes.js'; export class JSONHover { diff --git a/src/services/jsonLinks.ts b/src/services/jsonLinks.ts index 51d29364..fd47428d 100644 --- a/src/services/jsonLinks.ts +++ b/src/services/jsonLinks.ts @@ -4,8 +4,8 @@ *--------------------------------------------------------------------------------------------*/ import { DocumentLink } from 'vscode-languageserver-types'; -import { TextDocument, ASTNode, PropertyASTNode, Range } from '../jsonLanguageTypes'; -import { JSONDocument } from '../parser/jsonParser'; +import { TextDocument, ASTNode, PropertyASTNode, Range } from '../jsonLanguageTypes.js'; +import { JSONDocument } from '../parser/jsonParser.js'; export function findLinks(document: TextDocument, doc: JSONDocument): PromiseLike { const links: DocumentLink[] = []; diff --git a/src/services/jsonSchemaService.ts b/src/services/jsonSchemaService.ts index 1b753a67..33010d79 100644 --- a/src/services/jsonSchemaService.ts +++ b/src/services/jsonSchemaService.ts @@ -4,15 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import * as Json from 'jsonc-parser'; -import { JSONSchema, JSONSchemaMap, JSONSchemaRef } from '../jsonSchema'; +import { JSONSchema, JSONSchemaMap, JSONSchemaRef } from '../jsonSchema.js'; import { URI } from 'vscode-uri'; -import * as Strings from '../utils/strings'; -import { asSchema, getSchemaDraftFromId, JSONDocument, normalizeId } from '../parser/jsonParser'; -import { SchemaRequestService, WorkspaceContextService, PromiseConstructor, MatchingSchema, TextDocument, SchemaConfiguration, SchemaDraft, ErrorCode } from '../jsonLanguageTypes'; +import * as Strings from '../utils/strings.js'; +import { asSchema, getSchemaDraftFromId, JSONDocument, normalizeId } from '../parser/jsonParser.js'; +import { SchemaRequestService, WorkspaceContextService, PromiseConstructor, MatchingSchema, TextDocument, SchemaConfiguration, SchemaDraft, ErrorCode } from '../jsonLanguageTypes.js'; import * as l10n from '@vscode/l10n'; -import { createRegex } from '../utils/glob'; -import { isObject, isString } from '../utils/objects'; +import { createRegex } from '../utils/glob.js'; +import { isObject, isString } from '../utils/objects.js'; import { DiagnosticRelatedInformation, Range } from 'vscode-languageserver-types'; export interface IJSONSchemaService { diff --git a/src/services/jsonSelectionRanges.ts b/src/services/jsonSelectionRanges.ts index 277105a8..7a1f19ba 100644 --- a/src/services/jsonSelectionRanges.ts +++ b/src/services/jsonSelectionRanges.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Range, Position, SelectionRange, TextDocument } from '../jsonLanguageTypes'; +import { Range, Position, SelectionRange, TextDocument } from '../jsonLanguageTypes.js'; -import { JSONDocument } from '../parser/jsonParser'; +import { JSONDocument } from '../parser/jsonParser.js'; import { SyntaxKind, createScanner } from 'jsonc-parser'; export function getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[] { diff --git a/src/services/jsonValidation.ts b/src/services/jsonValidation.ts index f1f49a67..3bca6fb9 100644 --- a/src/services/jsonValidation.ts +++ b/src/services/jsonValidation.ts @@ -3,13 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService'; -import { JSONDocument } from '../parser/jsonParser'; +import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService.js'; +import { JSONDocument } from '../parser/jsonParser.js'; -import { TextDocument, ErrorCode, PromiseConstructor, LanguageSettings, DocumentLanguageSettings, SeverityLevel, Diagnostic, DiagnosticSeverity, Range, JSONLanguageStatus } from '../jsonLanguageTypes'; +import { TextDocument, ErrorCode, PromiseConstructor, LanguageSettings, DocumentLanguageSettings, SeverityLevel, Diagnostic, DiagnosticSeverity, Range, JSONLanguageStatus } from '../jsonLanguageTypes.js'; import * as l10n from '@vscode/l10n'; -import { JSONSchemaRef, JSONSchema } from '../jsonSchema'; -import { isBoolean } from '../utils/objects'; +import { JSONSchemaRef, JSONSchema } from '../jsonSchema.js'; +import { isBoolean } from '../utils/objects.js'; import { DiagnosticRelatedInformation } from 'vscode-languageserver-types'; export class JSONValidation { diff --git a/src/test/completion.test.ts b/src/test/completion.test.ts index 1ed8ec73..c4930ca3 100644 --- a/src/test/completion.test.ts +++ b/src/test/completion.test.ts @@ -6,8 +6,8 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import { getLanguageService, JSONSchema, TextDocument, ClientCapabilities, CompletionList, CompletionItemKind, Position, MarkupContent, TextEdit } from '../jsonLanguageService'; -import { repeat } from '../utils/strings'; +import { getLanguageService, JSONSchema, TextDocument, ClientCapabilities, CompletionList, CompletionItemKind, Position, MarkupContent, TextEdit } from '../jsonLanguageService.js'; +import { repeat } from '../utils/strings.js'; import { CompletionItemLabelDetails } from 'vscode-languageserver-types'; const applyEdits = TextDocument.applyEdits; diff --git a/src/test/documentSymbols.test.ts b/src/test/documentSymbols.test.ts index 8e8a01de..80ea00a2 100644 --- a/src/test/documentSymbols.test.ts +++ b/src/test/documentSymbols.test.ts @@ -5,14 +5,14 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import * as JsonSchema from '../jsonSchema'; +import * as JsonSchema from '../jsonSchema.js'; import { getLanguageService, ClientCapabilities, DocumentSymbolsContext, TextDocument, Color, SymbolInformation, SymbolKind, Range, Position, TextEdit, DocumentSymbol -} from "../jsonLanguageService"; -import { colorFrom256RGB } from '../utils/colors'; +} from "../jsonLanguageService.js"; +import { colorFrom256RGB } from '../utils/colors.js'; suite('JSON Document Symbols', () => { diff --git a/src/test/folding.test.ts b/src/test/folding.test.ts index 02afaf33..c10092f6 100644 --- a/src/test/folding.test.ts +++ b/src/test/folding.test.ts @@ -5,7 +5,7 @@ import { suite, test } from 'node:test'; import * as assert from 'assert'; -import { TextDocument, getLanguageService } from '../jsonLanguageService'; +import { TextDocument, getLanguageService } from '../jsonLanguageService.js'; interface ExpectedIndentRange { startLine: number; diff --git a/src/test/formatter.test.ts b/src/test/formatter.test.ts index bbff1570..3a58f16d 100644 --- a/src/test/formatter.test.ts +++ b/src/test/formatter.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { getLanguageService, ClientCapabilities, Range, TextDocument } from '../jsonLanguageService'; +import { getLanguageService, ClientCapabilities, Range, TextDocument } from '../jsonLanguageService.js'; import * as assert from 'assert'; import { suite, test } from 'node:test'; diff --git a/src/test/glob.test.ts b/src/test/glob.test.ts index 5503aea5..1ee3b12e 100644 --- a/src/test/glob.test.ts +++ b/src/test/glob.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import { createRegex } from '../utils/glob'; +import { createRegex } from '../utils/glob.js'; suite('Glob', () => { @@ -61,10 +61,10 @@ suite('Glob', () => { const regex = createRegex(pattern, { extended: true, globstar: true }); const result = regex.test(input); if (result !== expected) { - assert(false, `pattern: ${pattern}, regex: ${regex.source}, input: ${input}, should match ${expected}`); + assert.fail(`pattern: ${pattern}, regex: ${regex.source}, input: ${input}, should match ${expected}`); } } catch (e) { - assert(false, `pattern: ${pattern}, input: ${input}, should match ${expected}`); + assert.fail(`pattern: ${pattern}, input: ${input}, should match ${expected}`); } } diff --git a/src/test/hover.test.ts b/src/test/hover.test.ts index 8e67b0d0..3e663fd1 100644 --- a/src/test/hover.test.ts +++ b/src/test/hover.test.ts @@ -6,7 +6,7 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import { Hover, Position, TextDocument, getLanguageService, JSONSchema, LanguageServiceParams } from '../jsonLanguageService'; +import { Hover, Position, TextDocument, getLanguageService, JSONSchema, LanguageServiceParams } from '../jsonLanguageService.js'; suite('JSON Hover', () => { @@ -24,7 +24,7 @@ suite('JSON Hover', () => { const document = TextDocument.create(uri, 'json', 0, value); const jsonDoc = service.parseJSONDocument(document); const hover = await service.doHover(document, position, jsonDoc); - assert(hover, 'expected hover to be returned'); + assert.ok(hover, 'expected hover to be returned'); return hover; } diff --git a/src/test/jsonSchemaTestSuite.test.ts b/src/test/jsonSchemaTestSuite.test.ts index 94c27d7c..5f2d4263 100644 --- a/src/test/jsonSchemaTestSuite.test.ts +++ b/src/test/jsonSchemaTestSuite.test.ts @@ -5,13 +5,14 @@ import * as assert from 'assert'; import { suite, test, after } from 'node:test'; -import * as Parser from '../parser/jsonParser'; +import * as Parser from '../parser/jsonParser.js'; import * as fs from 'fs'; import * as url from 'url'; import * as path from 'path'; -import { getLanguageService, SchemaDraft, TextDocument } from '../jsonLanguageService'; +import { getLanguageService, SchemaDraft, TextDocument } from '../jsonLanguageService.js'; import { URI } from 'vscode-uri'; +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const testsPath = path.join(__dirname, "../../../node_modules/json-schema-test-suite/tests"); const drafts = [ diff --git a/src/test/links.test.ts b/src/test/links.test.ts index b788afa9..49df7cc8 100644 --- a/src/test/links.test.ts +++ b/src/test/links.test.ts @@ -6,7 +6,7 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import { getLanguageService, Range, TextDocument, ClientCapabilities } from '../jsonLanguageService'; +import { getLanguageService, Range, TextDocument, ClientCapabilities } from '../jsonLanguageService.js'; suite('JSON Find Links', () => { const testFindLinksFor = function (value: string, expected: {offset: number, length: number, target: number} | null): PromiseLike { diff --git a/src/test/parser.test.ts b/src/test/parser.test.ts index 87152d8c..06cba385 100644 --- a/src/test/parser.test.ts +++ b/src/test/parser.test.ts @@ -5,8 +5,8 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import { getNodePath, getNodeValue, JSONDocument } from '../parser/jsonParser'; -import { TextDocument, Range, ErrorCode, ASTNode, ObjectASTNode, getLanguageService, JSONSchema, SchemaDraft } from '../jsonLanguageService'; +import { getNodePath, getNodeValue, JSONDocument } from '../parser/jsonParser.js'; +import { TextDocument, Range, ErrorCode, ASTNode, ObjectASTNode, getLanguageService, JSONSchema, SchemaDraft } from '../jsonLanguageService.js'; import { DiagnosticSeverity } from 'vscode-languageserver-types'; suite('JSON Parser', () => { diff --git a/src/test/schema.test.ts b/src/test/schema.test.ts index 41f8a6d6..db790fe2 100644 --- a/src/test/schema.test.ts +++ b/src/test/schema.test.ts @@ -5,13 +5,15 @@ import * as assert from 'assert'; import { suite, test } from 'node:test'; -import * as SchemaService from '../services/jsonSchemaService'; -import * as Parser from '../parser/jsonParser'; +import * as SchemaService from '../services/jsonSchemaService.js'; +import * as Parser from '../parser/jsonParser.js'; import { promises as fs } from 'fs'; import * as url from 'url'; import * as path from 'path'; -import { getLanguageService, JSONSchema, SchemaRequestService, TextDocument, MatchingSchema, LanguageService } from '../jsonLanguageService'; -import { DiagnosticSeverity, ErrorCode, Range, SchemaConfiguration } from '../jsonLanguageTypes'; +import { getLanguageService, JSONSchema, SchemaRequestService, TextDocument, MatchingSchema, LanguageService } from '../jsonLanguageService.js'; +import { DiagnosticSeverity, ErrorCode, Range, SchemaConfiguration } from '../jsonLanguageTypes.js'; + +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); function toDocument(text: string, config?: Parser.JSONDocumentConfig, uri = 'foo://bar/file.json'): { textDoc: TextDocument, jsonDoc: Parser.JSONDocument } { diff --git a/src/test/selectionRanges.test.ts b/src/test/selectionRanges.test.ts index ce20d180..b58408be 100644 --- a/src/test/selectionRanges.test.ts +++ b/src/test/selectionRanges.test.ts @@ -5,7 +5,7 @@ import { suite, test } from 'node:test'; import * as assert from 'assert'; -import { getLanguageService, TextDocument } from '../jsonLanguageService'; +import { getLanguageService, TextDocument } from '../jsonLanguageService.js'; import { SelectionRange } from 'vscode-languageserver-types'; function assertRanges(content: string, expected: (number | string)[][]): void { diff --git a/src/test/sort.test.ts b/src/test/sort.test.ts index abc8d942..6ab66e1c 100644 --- a/src/test/sort.test.ts +++ b/src/test/sort.test.ts @@ -1,5 +1,5 @@ -import { getLanguageService, ClientCapabilities, TextDocument, SortOptions } from '../jsonLanguageService'; +import { getLanguageService, ClientCapabilities, TextDocument, SortOptions } from '../jsonLanguageService.js'; import * as assert from 'assert'; import { suite, test } from 'node:test'; diff --git a/src/test/stringify.test.ts b/src/test/stringify.test.ts index f54d3689..f6e87996 100644 --- a/src/test/stringify.test.ts +++ b/src/test/stringify.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { stringifyObject } from '../utils/json'; +import { stringifyObject } from '../utils/json.js'; import * as assert from 'assert'; import { suite, test } from 'node:test'; diff --git a/src/tsconfig.esm.json b/src/tsconfig.esm.json index 387739c8..c9011ba2 100644 --- a/src/tsconfig.esm.json +++ b/src/tsconfig.esm.json @@ -1,14 +1,3 @@ { - "compilerOptions": { - "target": "es2020", - "module": "es6", - "moduleResolution": "node", - "sourceMap": true, - "declaration": true, - "stripInternal": true, - "outDir": "../lib/esm", - "lib": [ - "es2020" - ] - } + "extends": "./tsconfig.json" } \ No newline at end of file diff --git a/src/tsconfig.json b/src/tsconfig.json index e903a2bf..c3853271 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", "lib": [ "es2020" ], diff --git a/src/utils/colors.ts b/src/utils/colors.ts index 1d710601..3513930f 100644 --- a/src/utils/colors.ts +++ b/src/utils/colors.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Color } from "../jsonLanguageTypes"; +import { Color } from "../jsonLanguageTypes.js"; const Digit0 = 48; const Digit9 = 57; diff --git a/src/utils/format.ts b/src/utils/format.ts index 14f4d94c..7cf6b071 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -1,5 +1,5 @@ import { format as formatJSON, Range as JSONCRange } from 'jsonc-parser'; -import { TextDocument, Range, TextEdit, FormattingOptions } from '../jsonLanguageTypes'; +import { TextDocument, Range, TextEdit, FormattingOptions } from '../jsonLanguageTypes.js'; export function format(documentToFormat: TextDocument, formattingOptions?: FormattingOptions, formattingRange?: Range | undefined): TextEdit[] { let range: JSONCRange | undefined = undefined; diff --git a/src/utils/sort.ts b/src/utils/sort.ts index 2f3d539d..9dd8c57c 100644 --- a/src/utils/sort.ts +++ b/src/utils/sort.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import { createScanner, SyntaxKind, JSONScanner } from 'jsonc-parser'; -import { TextDocument, TextEdit, FormattingOptions, Position, Range, TextDocumentContentChangeEvent, SortOptions } from '../jsonLanguageTypes'; -import { format } from './format'; -import { PropertyTree, Container } from './propertyTree'; +import { TextDocument, TextEdit, FormattingOptions, Position, Range, TextDocumentContentChangeEvent, SortOptions } from '../jsonLanguageTypes.js'; +import { format } from './format.js'; +import { PropertyTree, Container } from './propertyTree.js'; export function sort(documentToSort: TextDocument, formattingOptions: SortOptions): TextEdit[] { const options: FormattingOptions = {