Skip to content

Commit 54d6346

Browse files
authored
migrate to ESM only, prepare 6.0.0-next.1 (#314)
* migrate to ESM only, prepare 6.0.0-next.1 * update
1 parent 2f8b5be commit 54d6346

37 files changed

+139
-139
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"request": "launch",
1717
"runtimeArgs": [
1818
"--test",
19-
"./lib/umd/test/**/*.test.js"
19+
"./lib/esm/test/**/*.test.js"
2020
],
2121
"cwd": "${workspaceRoot}",
2222
"sourceMaps": true,
23-
"outFiles": [ "${workspaceRoot}/lib/umd/**/*.js" ],
23+
"outFiles": [ "${workspaceRoot}/lib/esm/**/*.js" ],
2424
"preLaunchTask": "npm: watch"
2525
},
2626
{
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);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
22
"name": "vscode-json-languageservice",
3-
"version": "5.7.2",
3+
"version": "6.0.0-next.1",
44
"description": "Language service for JSON",
5-
"main": "./lib/umd/jsonLanguageService.js",
6-
"typings": "./lib/umd/jsonLanguageService",
7-
"module": "./lib/esm/jsonLanguageService.js",
5+
"type": "module",
6+
"types": "./lib/esm/jsonLanguageService.d.ts",
7+
"exports": {
8+
".": {
9+
"types": "./lib/esm/jsonLanguageService.d.ts",
10+
"import": "./lib/esm/jsonLanguageService.js"
11+
}
12+
},
813
"author": "Microsoft Corporation",
914
"repository": {
1015
"type": "git",
@@ -31,18 +36,18 @@
3136
"@vscode/l10n": "^0.0.18"
3237
},
3338
"scripts": {
34-
"prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
39+
"prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs",
3540
"compile": "tsc -p ./src",
36-
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
3741
"clean": "rimraf lib",
42+
"bundle-schemas": "node ./build/bundle-schemas.js",
3843
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
3944
"watch": "tsc -w -p ./src",
4045
"pretest": "npm run compile",
41-
"test": "node --test ./lib/umd/test/**/*.test.js",
46+
"test": "node --test ./lib/esm/test/**/*.test.js",
4247
"posttest": "npm run lint",
4348
"coverage": "npx nyc -r lcov npm run test",
4449
"lint": "eslint src/**/*.ts",
4550
"install-types-next": "npm install vscode-languageserver-types@next -f -S && npm install vscode-languageserver-textdocument@next -f -S",
46-
"sample": "npm run compile && node ./lib/umd/example/sample.js"
51+
"sample": "npm run compile && node ./lib/esm/example/sample.js"
4752
}
4853
}

src/example/sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
import { getLanguageService, TextDocument } from '../jsonLanguageService';
3+
import { getLanguageService, TextDocument } from '../jsonLanguageService.js';
44

55
async function main() {
66
const jsonContentUri = 'foo://server/example.data.json';

src/jsonContributions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { MarkedString, CompletionItem } from './jsonLanguageService';
5+
import { MarkedString, CompletionItem } from './jsonLanguageService.js';
66

77
export interface JSONWorkerContribution {
88
getInfoContribution(uri: string, location: JSONPath): PromiseLike<MarkedString[]>;

src/jsonLanguageService.ts

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

6-
import { JSONCompletion } from './services/jsonCompletion';
7-
import { JSONHover } from './services/jsonHover';
8-
import { JSONValidation } from './services/jsonValidation';
6+
import { JSONCompletion } from './services/jsonCompletion.js';
7+
import { JSONHover } from './services/jsonHover.js';
8+
import { JSONValidation } from './services/jsonValidation.js';
99

10-
import { JSONDocumentSymbols } from './services/jsonDocumentSymbols';
11-
import { parse as parseJSON, newJSONDocument } from './parser/jsonParser';
12-
import { schemaContributions } from './services/configuration';
13-
import { JSONSchemaService } from './services/jsonSchemaService';
14-
import { getFoldingRanges } from './services/jsonFolding';
15-
import { getSelectionRanges } from './services/jsonSelectionRanges';
16-
import { sort } from './utils/sort';
17-
import { format } from './utils/format';
10+
import { JSONDocumentSymbols } from './services/jsonDocumentSymbols.js';
11+
import { parse as parseJSON, newJSONDocument } from './parser/jsonParser.js';
12+
import { schemaContributions } from './services/configuration.js';
13+
import { JSONSchemaService } from './services/jsonSchemaService.js';
14+
import { getFoldingRanges } from './services/jsonFolding.js';
15+
import { getSelectionRanges } from './services/jsonSelectionRanges.js';
16+
import { sort } from './utils/sort.js';
17+
import { format } from './utils/format.js';
1818

1919
import {
2020
ASTNode,
@@ -24,15 +24,15 @@ import {
2424
TextDocument,
2525
Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic,
2626
TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus, SortOptions
27-
} from './jsonLanguageTypes';
28-
import { findLinks } from './services/jsonLinks';
27+
} from './jsonLanguageTypes.js';
28+
import { findLinks } from './services/jsonLinks.js';
2929
import { DocumentLink } from 'vscode-languageserver-types';
3030

3131
export type JSONDocument = {
3232
root: ASTNode | undefined;
3333
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
3434
};
35-
export * from './jsonLanguageTypes';
35+
export * from './jsonLanguageTypes.js';
3636

3737
export interface LanguageService {
3838
configure(settings: LanguageSettings): void;

src/jsonLanguageTypes.ts

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

6-
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
7-
import { JSONSchema } from './jsonSchema';
6+
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions.js';
7+
import { JSONSchema } from './jsonSchema.js';
88
import {
99
Range, Position, DocumentUri, MarkupContent, MarkupKind,
1010
Color, ColorInformation, ColorPresentation,

src/parser/jsonParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as Json from 'jsonc-parser';
7-
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
8-
import { isNumber, equals, isBoolean, isString, isDefined, isObject } from '../utils/objects';
9-
import { extendedRegExp, stringLength } from '../utils/strings';
10-
import { TextDocument, ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, JSONPath, ErrorCode, Diagnostic, DiagnosticSeverity, Range, SchemaDraft } from '../jsonLanguageTypes';
7+
import { JSONSchema, JSONSchemaRef } from '../jsonSchema.js';
8+
import { isNumber, equals, isBoolean, isString, isDefined, isObject } from '../utils/objects.js';
9+
import { extendedRegExp, stringLength } from '../utils/strings.js';
10+
import { TextDocument, ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, JSONPath, ErrorCode, Diagnostic, DiagnosticSeverity, Range, SchemaDraft } from '../jsonLanguageTypes.js';
1111
import { URI } from 'vscode-uri';
1212

1313
import * as l10n from '@vscode/l10n';

0 commit comments

Comments
 (0)