From 7368bb69251ed1055c94189fa5e96f98f086f1dc Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 22 Jan 2024 13:51:19 +0000 Subject: [PATCH] Migrate from commonjs to ESM --- .eslintrc.json | 2 +- .mocharc.yml | 8 ++++-- ...uage-server => ansible-language-server.js} | 4 ++- package-lock.json | 27 ++++++++++++++----- package.json | 10 ++++--- src/ansibleLanguageService.ts | 16 +++++------ src/providers/completionProvider.ts | 18 ++++++++----- src/providers/completionProviderUtils.ts | 5 ++-- src/providers/definitionProvider.ts | 10 ++++--- src/providers/hoverProvider.ts | 10 +++---- src/providers/semanticTokenProvider.ts | 8 +++--- src/providers/validationProvider.ts | 14 ++++++---- src/server.ts | 6 ++--- src/services/ansibleConfig.ts | 8 +++--- src/services/ansibleInventory.ts | 8 +++--- src/services/ansibleLint.ts | 10 ++++--- src/services/ansiblePlaybook.ts | 9 ++++--- src/services/docsLibrary.ts | 21 ++++++++------- src/services/docsLibraryUtilsForPAC.ts | 12 ++++----- src/services/executionEnvironment.ts | 17 +++++++----- src/services/metadataLibrary.ts | 9 ++++--- src/services/settingsManager.ts | 9 ++++--- src/services/validationManager.ts | 7 +++-- src/services/workspaceManager.ts | 21 ++++++++------- src/utils/commandRunner.ts | 11 ++++---- src/utils/docsFinder.ts | 8 +++--- src/utils/docsFormatter.ts | 4 +-- src/utils/docsParser.ts | 6 ++--- src/utils/execPath.ts | 2 +- src/utils/getAnsibleMetaData.ts | 9 ++++--- src/utils/imagePuller.ts | 2 +- src/utils/yaml.ts | 22 +++++++-------- test/helper.ts | 12 +++++---- test/index.ts | 2 +- test/providers/completionProvider.test.ts | 9 ++++--- test/providers/completionResolver.test.ts | 8 +++--- test/providers/definitionProvider.test.ts | 12 +++++---- test/providers/hoverProvider.test.ts | 6 ++--- test/providers/settingsManager.test.ts | 6 ++--- test/providers/validationProvider.test.ts | 8 +++--- test/rootMochaHooks.ts | 8 +++--- test/utils/getAnsibleMetaData.test.ts | 8 +++--- test/utils/pathUtils.test.ts | 6 +++-- .../resolveSuffixWhileCompletion.test.ts | 2 +- test/utils/runCommand.test.ts | 19 +++++++------ test/utils/withInterpreter.test.ts | 2 +- test/utils/yaml.test.ts | 4 +-- tools/settings-doc-generator.ts | 6 +++-- tsconfig.json | 18 ++++++++++--- 49 files changed, 279 insertions(+), 190 deletions(-) rename bin/{ansible-language-server => ansible-language-server.js} (62%) diff --git a/.eslintrc.json b/.eslintrc.json index 03bb86d6..8fa1d8ff 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,7 @@ "extends": ["plugin:@typescript-eslint/recommended", "prettier"], "parser": "@typescript-eslint/parser", "parserOptions": { - "ecmaVersion": 2021, + "ecmaVersion": "latest", "sourceType": "module" }, "plugins": ["@typescript-eslint"], diff --git a/.mocharc.yml b/.mocharc.yml index e3c5a70a..5919216e 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1,6 +1,10 @@ require: - - ts-node/register - - test/rootMochaHooks.ts + # - ts-node/register + # - tsx + - chai/register-expect.js + # - test/rootMochaHooks.ts # reporter: tap # more flat, also the only one that mentions totals for found, skipped and passed spec: './test/**/*.ts' timeout: 60000 # same as 60 seconds. This done to ensure that we have sufficient time to run tests on the CI as each test involves loading yaml files and docs library for ansible. +loader: ts-node/esm +# "require": ["chai/register-expect.js"] diff --git a/bin/ansible-language-server b/bin/ansible-language-server.js similarity index 62% rename from bin/ansible-language-server rename to bin/ansible-language-server.js index e503bab0..e7b6adf8 100755 --- a/bin/ansible-language-server +++ b/bin/ansible-language-server.js @@ -1,7 +1,9 @@ #!/usr/bin/env node +const { default: pkgJSON } = await import("../package.json", { + assert: { type: "json" }, +}); if (process.argv.includes("--version")) { - const pkgJSON = require("../package.json"); console.log(`${pkgJSON["version"]}`); } else { require("../out/server/src/server.js"); diff --git a/package-lock.json b/package-lock.json index 43afdea3..fb2319b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "yaml": "^2.2.2" }, "bin": { - "ansible-language-server": "bin/ansible-language-server" + "ansible-language-server": "bin/ansible-language-server.js" }, "devDependencies": { "@types/chai": "^4.3.4", @@ -39,6 +39,7 @@ "eslint-config-prettier": "^8.8.0", "fuse.js": "^6.6.2", "handlebars": "^4.7.7", + "lodash-es": "^4.17.21", "mocha": "^10.2.0", "npm-check-updates": "^16.8.0", "nyc": "^15.1.0", @@ -2957,9 +2958,9 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, "optional": true, @@ -4035,6 +4036,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "node_modules/lodash-es": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz", + "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==", + "dev": true + }, "node_modules/lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -9472,9 +9479,9 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "optional": true }, @@ -10265,6 +10272,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "lodash-es": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz", + "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==", + "dev": true + }, "lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", diff --git a/package.json b/package.json index 15cee430..50a4ab77 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "npm": ">=7.11.2" }, "bin": { - "ansible-language-server": "./bin/ansible-language-server" + "ansible-language-server": "./bin/ansible-language-server.js" }, - "main": "./out/server/src/server.js", + "exports": "./out/server/src/server.js", "types": "./out/server/src/server.d.ts", "files": [ "docs/changelog.md", @@ -75,6 +75,7 @@ "eslint-config-prettier": "^8.8.0", "fuse.js": "^6.6.2", "handlebars": "^4.7.7", + "lodash-es": "^4.17.21", "mocha": "^10.2.0", "npm-check-updates": "^16.8.0", "nyc": "^15.1.0", @@ -91,10 +92,11 @@ "//prepare": "Prepare is needed for installation from source", "prepare": "npm run compile", "watch": "tsc --watch -p .", - "test": "nyc -s -a mocha && nyc report --check-coverage", + "test": "mocha", "test-with-ee": "nyc -s -a mocha --grep @ee && nyc report --check-coverage", "test-without-ee": "nyc -s -a mocha --grep @ee --invert && nyc report --check-coverage", "generate-settings-readme": "ts-node tools/settings-doc-generator.ts" }, - "all": true + "all": true, + "type": "module" } diff --git a/src/ansibleLanguageService.ts b/src/ansibleLanguageService.ts index 8ae23640..514c01ac 100644 --- a/src/ansibleLanguageService.ts +++ b/src/ansibleLanguageService.ts @@ -11,18 +11,18 @@ import { TextDocument } from "vscode-languageserver-textdocument"; import { doCompletion, doCompletionResolve, -} from "./providers/completionProvider"; -import { getDefinition } from "./providers/definitionProvider"; -import { doHover } from "./providers/hoverProvider"; +} from "./providers/completionProvider.js"; +import { getDefinition } from "./providers/definitionProvider.js"; +import { doHover } from "./providers/hoverProvider.js"; import { doSemanticTokens, tokenModifiers, tokenTypes, -} from "./providers/semanticTokenProvider"; -import { doValidate } from "./providers/validationProvider"; -import { ValidationManager } from "./services/validationManager"; -import { WorkspaceManager } from "./services/workspaceManager"; -import { getAnsibleMetaData } from "./utils/getAnsibleMetaData"; +} from "./providers/semanticTokenProvider.js"; +import { doValidate } from "./providers/validationProvider.js"; +import { ValidationManager } from "./services/validationManager.js"; +import { WorkspaceManager } from "./services/workspaceManager.js"; +import { getAnsibleMetaData } from "./utils/getAnsibleMetaData.js"; /** * Initializes the connection and registers all lifecycle event handlers. diff --git a/src/providers/completionProvider.ts b/src/providers/completionProvider.ts index 6ac2b6a3..22da1ad2 100644 --- a/src/providers/completionProvider.ts +++ b/src/providers/completionProvider.ts @@ -9,17 +9,21 @@ import { } from "vscode-languageserver"; import { Position, TextDocument } from "vscode-languageserver-textdocument"; import { isScalar, Node, YAMLMap } from "yaml"; -import { IOption } from "../interfaces/module"; -import { WorkspaceFolderContext } from "../services/workspaceManager"; +import { IOption } from "../interfaces/module.js"; +import { WorkspaceFolderContext } from "../services/workspaceManager.js"; import { blockKeywords, playKeywords, playWithoutTaskKeywords, roleKeywords, taskKeywords, -} from "../utils/ansible"; -import { formatModule, formatOption, getDetails } from "../utils/docsFormatter"; -import { insert, toLspRange } from "../utils/misc"; +} from "../utils/ansible.js"; +import { + formatModule, + formatOption, + getDetails, +} from "../utils/docsFormatter.js"; +import { insert, toLspRange } from "../utils/misc.js"; import { AncestryBuilder, findProvidedModule, @@ -35,8 +39,8 @@ import { getPossibleOptionsForPath, isCursorInsideJinjaBrackets, isPlaybook, -} from "../utils/yaml"; -import { getVarsCompletion } from "./completionProviderUtils"; +} from "../utils/yaml.js"; +import { getVarsCompletion } from "./completionProviderUtils.js"; const priorityMap = { nameKeyword: 1, diff --git a/src/providers/completionProviderUtils.ts b/src/providers/completionProviderUtils.ts index 8012b02c..713bb34c 100644 --- a/src/providers/completionProviderUtils.ts +++ b/src/providers/completionProviderUtils.ts @@ -1,7 +1,8 @@ import { CompletionItem, CompletionItemKind } from "vscode-languageserver"; -import { URI } from "vscode-uri"; +import pkg from "vscode-uri"; +const { URI } = pkg; import { isScalar, Node, YAMLMap, YAMLSeq } from "yaml"; -import { AncestryBuilder, isPlayParam } from "../utils/yaml"; +import { AncestryBuilder, isPlayParam } from "../utils/yaml.js"; import * as pathUri from "path"; import { existsSync, readFileSync } from "fs"; import { parseDocument } from "yaml"; diff --git a/src/providers/definitionProvider.ts b/src/providers/definitionProvider.ts index c76363f7..741bc1d3 100644 --- a/src/providers/definitionProvider.ts +++ b/src/providers/definitionProvider.ts @@ -1,16 +1,18 @@ import { DefinitionLink, Range } from "vscode-languageserver"; import { Position, TextDocument } from "vscode-languageserver-textdocument"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; import { isScalar } from "yaml"; -import { DocsLibrary } from "../services/docsLibrary"; -import { toLspRange } from "../utils/misc"; +import { DocsLibrary } from "../services/docsLibrary.js"; +import { toLspRange } from "../utils/misc.js"; import { AncestryBuilder, getOrigRange, getPathAt, isTaskParam, parseAllDocuments, -} from "../utils/yaml"; +} from "../utils/yaml.js"; export async function getDefinition( document: TextDocument, diff --git a/src/providers/hoverProvider.ts b/src/providers/hoverProvider.ts index e92d9a35..43c534be 100644 --- a/src/providers/hoverProvider.ts +++ b/src/providers/hoverProvider.ts @@ -1,20 +1,20 @@ import { Hover, MarkupContent, MarkupKind } from "vscode-languageserver"; import { Position, TextDocument } from "vscode-languageserver-textdocument"; import { isScalar, Scalar } from "yaml"; -import { DocsLibrary } from "../services/docsLibrary"; +import { DocsLibrary } from "../services/docsLibrary.js"; import { blockKeywords, isTaskKeyword, playKeywords, roleKeywords, taskKeywords, -} from "../utils/ansible"; +} from "../utils/ansible.js"; import { formatModule, formatOption, formatTombstone, -} from "../utils/docsFormatter"; -import { toLspRange } from "../utils/misc"; +} from "../utils/docsFormatter.js"; +import { toLspRange } from "../utils/misc.js"; import { AncestryBuilder, getOrigRange, @@ -25,7 +25,7 @@ import { isRoleParam, isTaskParam, parseAllDocuments, -} from "../utils/yaml"; +} from "../utils/yaml.js"; export async function doHover( document: TextDocument, diff --git a/src/providers/semanticTokenProvider.ts b/src/providers/semanticTokenProvider.ts index 066c418c..019343ad 100644 --- a/src/providers/semanticTokenProvider.ts +++ b/src/providers/semanticTokenProvider.ts @@ -15,14 +15,14 @@ import { Scalar, YAMLMap, } from "yaml"; -import { IOption } from "../interfaces/module"; -import { DocsLibrary } from "../services/docsLibrary"; +import { IOption } from "../interfaces/module.js"; +import { DocsLibrary } from "../services/docsLibrary.js"; import { blockKeywords, isTaskKeyword, playKeywords, roleKeywords, -} from "../utils/ansible"; +} from "../utils/ansible.js"; import { findProvidedModule, getOrigRange, @@ -31,7 +31,7 @@ import { isRoleParam, isTaskParam, parseAllDocuments, -} from "../utils/yaml"; +} from "../utils/yaml.js"; export const tokenTypes = [ SemanticTokenTypes.method, diff --git a/src/providers/validationProvider.ts b/src/providers/validationProvider.ts index 09113cb3..4f1c4479 100644 --- a/src/providers/validationProvider.ts +++ b/src/providers/validationProvider.ts @@ -1,4 +1,6 @@ +// import _IntervalTree from "@flatten-js/interval-tree"; import IntervalTree from "@flatten-js/interval-tree"; + import { Connection, Diagnostic, @@ -6,10 +8,12 @@ import { Range, } from "vscode-languageserver"; import { TextDocument } from "vscode-languageserver-textdocument"; -import { ValidationManager } from "../services/validationManager"; -import { WorkspaceFolderContext } from "../services/workspaceManager"; -import { isPlaybook, parseAllDocuments } from "../utils/yaml"; -import { CommandRunner } from "../utils/commandRunner"; +import { ValidationManager } from "../services/validationManager.js"; +import { WorkspaceFolderContext } from "../services/workspaceManager.js"; +import { isPlaybook, parseAllDocuments } from "../utils/yaml.js"; +import { CommandRunner } from "../utils/commandRunner.js"; + +// const IntervalTree = _IntervalTree as unknown as typeof _IntervalTree.default; /** * Validates the given document. @@ -101,7 +105,7 @@ export async function doValidate( export function getYamlValidation(textDocument: TextDocument): Diagnostic[] { const diagnostics: Diagnostic[] = []; const yDocuments = parseAllDocuments(textDocument.getText()); - const rangeTree = new IntervalTree(); + const rangeTree = new IntervalTree.default(); yDocuments.forEach((yDoc) => { yDoc.errors.forEach((error) => { const [errStart, errEnd] = error.pos; diff --git a/src/server.ts b/src/server.ts index b5565876..cd7b307a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -6,9 +6,9 @@ import { NotificationHandler, ProposedFeatures, TextDocuments, -} from "vscode-languageserver/node"; -import { AnsibleLanguageService } from "./ansibleLanguageService"; -import { getUnsupportedError } from "./utils/misc"; +} from "vscode-languageserver/node.js"; +import { AnsibleLanguageService } from "./ansibleLanguageService.js"; +import { getUnsupportedError } from "./utils/misc.js"; // Create a connection for the server, using Node's IPC as a transport. // Also include all preview / proposed LSP features. diff --git a/src/services/ansibleConfig.ts b/src/services/ansibleConfig.ts index aafc782b..53f25761 100644 --- a/src/services/ansibleConfig.ts +++ b/src/services/ansibleConfig.ts @@ -1,10 +1,12 @@ import * as ini from "ini"; import * as _ from "lodash"; import * as path from "path"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; import { Connection } from "vscode-languageserver"; -import { WorkspaceFolderContext } from "./workspaceManager"; -import { CommandRunner } from "../utils/commandRunner"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; +import { CommandRunner } from "../utils/commandRunner.js"; export class AnsibleConfig { private connection: Connection; diff --git a/src/services/ansibleInventory.ts b/src/services/ansibleInventory.ts index 464d0b10..546654f9 100644 --- a/src/services/ansibleInventory.ts +++ b/src/services/ansibleInventory.ts @@ -1,7 +1,9 @@ import { Connection } from "vscode-languageserver"; -import { WorkspaceFolderContext } from "./workspaceManager"; -import { CommandRunner } from "../utils/commandRunner"; -import { URI } from "vscode-uri"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; +import { CommandRunner } from "../utils/commandRunner.js"; + +import pkg from "vscode-uri"; +const { URI } = pkg; /** * Class to extend ansible-inventory executable as a service diff --git a/src/services/ansibleLint.ts b/src/services/ansibleLint.ts index fa9edb1d..1353b334 100644 --- a/src/services/ansibleLint.ts +++ b/src/services/ansibleLint.ts @@ -1,6 +1,8 @@ import { ExecException } from "child_process"; import * as path from "path"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; import { Connection, Diagnostic, @@ -10,9 +12,9 @@ import { Range, } from "vscode-languageserver"; import { TextDocument } from "vscode-languageserver-textdocument"; -import { fileExists } from "../utils/misc"; -import { WorkspaceFolderContext } from "./workspaceManager"; -import { CommandRunner } from "../utils/commandRunner"; +import { fileExists } from "../utils/misc.js"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; +import { CommandRunner } from "../utils/commandRunner.js"; /** * Acts as and interface to ansible-lint and a cache of its output. diff --git a/src/services/ansiblePlaybook.ts b/src/services/ansiblePlaybook.ts index 80b0b315..f893a1f1 100644 --- a/src/services/ansiblePlaybook.ts +++ b/src/services/ansiblePlaybook.ts @@ -1,6 +1,9 @@ import * as child_process from "child_process"; import * as path from "path"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; + import { Connection, Diagnostic, @@ -10,8 +13,8 @@ import { Range, } from "vscode-languageserver"; import { TextDocument } from "vscode-languageserver-textdocument"; -import { WorkspaceFolderContext } from "./workspaceManager"; -import { CommandRunner } from "../utils/commandRunner"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; +import { CommandRunner } from "../utils/commandRunner.js"; /** * Acts as an interface to ansible-playbook command. diff --git a/src/services/docsLibrary.ts b/src/services/docsLibrary.ts index fb9ad48d..7c09944b 100644 --- a/src/services/docsLibrary.ts +++ b/src/services/docsLibrary.ts @@ -1,26 +1,29 @@ import { Connection } from "vscode-languageserver"; import { Node } from "yaml"; -import { getDeclaredCollections } from "../utils/yaml"; -import { findDocumentation, findPluginRouting } from "../utils/docsFinder"; -import { WorkspaceFolderContext } from "./workspaceManager"; +import { getDeclaredCollections } from "../utils/yaml.js"; +import { findDocumentation, findPluginRouting } from "../utils/docsFinder.js"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; import { IPluginRoute, IPluginRoutesByType, IPluginRoutingByCollection, -} from "../interfaces/pluginRouting"; +} from "../interfaces/pluginRouting.js"; import { processDocumentationFragments, processRawDocumentation, -} from "../utils/docsParser"; -import { IModuleMetadata } from "../interfaces/module"; +} from "../utils/docsParser.js"; +import { IModuleMetadata } from "../interfaces/module.js"; import * as path from "path"; import { existsSync, lstatSync } from "fs"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; + import { findModulesUtils, getModuleFqcnsUtils, -} from "./docsLibraryUtilsForPAC"; -import { globArray } from "../utils/pathUtils"; +} from "./docsLibraryUtilsForPAC.js"; +import { globArray } from "../utils/pathUtils.js"; export class DocsLibrary { private connection: Connection; private modules = new Map(); diff --git a/src/services/docsLibraryUtilsForPAC.ts b/src/services/docsLibraryUtilsForPAC.ts index ab141b3f..be0a3ebc 100644 --- a/src/services/docsLibraryUtilsForPAC.ts +++ b/src/services/docsLibraryUtilsForPAC.ts @@ -6,19 +6,19 @@ */ import { Node } from "yaml"; -import { IModuleMetadata } from "../interfaces/module"; +import { IModuleMetadata } from "../interfaces/module.js"; import { IPluginRoute, IPluginRoutesByType, IPluginRoutingByCollection, -} from "../interfaces/pluginRouting"; -import { findDocumentation, findPluginRouting } from "../utils/docsFinder"; +} from "../interfaces/pluginRouting.js"; +import { findDocumentation, findPluginRouting } from "../utils/docsFinder.js"; import { processDocumentationFragments, processRawDocumentation, -} from "../utils/docsParser"; -import { getDeclaredCollections } from "../utils/yaml"; -import { WorkspaceFolderContext } from "./workspaceManager"; +} from "../utils/docsParser.js"; +import { getDeclaredCollections } from "../utils/yaml.js"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; const playbookAdjacentPluginRouting: IPluginRoutingByCollection = new Map< string, diff --git a/src/services/executionEnvironment.ts b/src/services/executionEnvironment.ts index 0fee3ac4..c2a1d02b 100644 --- a/src/services/executionEnvironment.ts +++ b/src/services/executionEnvironment.ts @@ -1,18 +1,21 @@ import * as child_process from "child_process"; import * as fs from "fs"; import * as path from "path"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; + import { Connection } from "vscode-languageserver"; import { v4 as uuidv4 } from "uuid"; -import { AnsibleConfig } from "./ansibleConfig"; -import { ImagePuller } from "../utils/imagePuller"; -import { asyncExec } from "../utils/misc"; -import { WorkspaceFolderContext } from "./workspaceManager"; +import { AnsibleConfig } from "./ansibleConfig.js"; +import { ImagePuller } from "../utils/imagePuller.js"; +import { asyncExec } from "../utils/misc.js"; +import { WorkspaceFolderContext } from "./workspaceManager.js"; import { ExtensionSettings, IContainerEngine, -} from "../interfaces/extensionSettings"; -import { IVolumeMounts } from "../interfaces/extensionSettings"; +} from "../interfaces/extensionSettings.js"; +import { IVolumeMounts } from "../interfaces/extensionSettings.js"; export class ExecutionEnvironment { public isServiceInitialized: boolean; diff --git a/src/services/metadataLibrary.ts b/src/services/metadataLibrary.ts index 43ab0f61..e0c7e425 100644 --- a/src/services/metadataLibrary.ts +++ b/src/services/metadataLibrary.ts @@ -1,10 +1,13 @@ import { promises as fs } from "fs"; import { Connection } from "vscode-languageserver"; import { DidChangeWatchedFilesParams } from "vscode-languageserver-protocol"; -import { URI } from "vscode-uri"; + +import pkg from "vscode-uri"; +const { URI } = pkg; + import { parseAllDocuments } from "yaml"; -import { IDocumentMetadata } from "../interfaces/documentMeta"; -import { fileExists, hasOwnProperty } from "../utils/misc"; +import { IDocumentMetadata } from "../interfaces/documentMeta.js"; +import { fileExists, hasOwnProperty } from "../utils/misc.js"; export class MetadataLibrary { private connection: Connection; diff --git a/src/services/settingsManager.ts b/src/services/settingsManager.ts index 3f8b4d34..a1be849d 100644 --- a/src/services/settingsManager.ts +++ b/src/services/settingsManager.ts @@ -4,7 +4,10 @@ import { DidChangeConfigurationParams } from "vscode-languageserver-protocol"; import { ExtensionSettingsWithDescription, ExtensionSettings, -} from "../interfaces/extensionSettings"; +} from "../interfaces/extensionSettings.js"; + +import pkg from "lodash"; +const { cloneDeep, merge } = pkg; export class SettingsManager { private connection: Connection; @@ -129,7 +132,7 @@ export class SettingsManager { // Structure the settings similar to the ExtensionSettings interface for usage in the code private defaultSettings: ExtensionSettings = this._settingsAdjustment( - _.cloneDeep(this.defaultSettingsWithDescription), + cloneDeep(this.defaultSettingsWithDescription), ); public globalSettings: ExtensionSettings = this.defaultSettings; @@ -162,7 +165,7 @@ export class SettingsManager { // Recursively merge globalSettings with clientSettings to use: // - setting from client when provided // - default value of setting otherwise - const mergedSettings = _.merge(this.globalSettings, clientSettings); + const mergedSettings = merge(this.globalSettings, clientSettings); result = Promise.resolve(mergedSettings); this.documentSettings.set(uri, result); } diff --git a/src/services/validationManager.ts b/src/services/validationManager.ts index a7236e55..2833483b 100644 --- a/src/services/validationManager.ts +++ b/src/services/validationManager.ts @@ -1,4 +1,4 @@ -import IntervalTree from "@flatten-js/interval-tree"; +import _IntervalTree from "@flatten-js/interval-tree"; import { Connection, Diagnostic, @@ -8,6 +8,8 @@ import { } from "vscode-languageserver"; import { TextDocument } from "vscode-languageserver-textdocument"; +const IntervalTree = _IntervalTree as unknown as typeof _IntervalTree.default; + /** * Provides cache for selected diagnostics. * @@ -20,7 +22,8 @@ export class ValidationManager { private connection: Connection; private documents: TextDocuments; - private validationCache: Map> = new Map(); + private validationCache: Map> = + new Map(); /** * Mapping from file that generated diagnostics (origin), to files included in diff --git a/src/services/workspaceManager.ts b/src/services/workspaceManager.ts index 0bf0accd..1303b539 100644 --- a/src/services/workspaceManager.ts +++ b/src/services/workspaceManager.ts @@ -6,16 +6,19 @@ import { WorkspaceFolder, WorkspaceFoldersChangeEvent, } from "vscode-languageserver"; -import { AnsibleConfig } from "./ansibleConfig"; -import { AnsibleLint } from "./ansibleLint"; -import { AnsiblePlaybook } from "./ansiblePlaybook"; -import { DocsLibrary } from "./docsLibrary"; -import { ExecutionEnvironment } from "./executionEnvironment"; -import { MetadataLibrary } from "./metadataLibrary"; -import { SettingsManager } from "./settingsManager"; +import { AnsibleConfig } from "./ansibleConfig.js"; +import { AnsibleLint } from "./ansibleLint.js"; +import { AnsiblePlaybook } from "./ansiblePlaybook.js"; +import { DocsLibrary } from "./docsLibrary.js"; +import { ExecutionEnvironment } from "./executionEnvironment.js"; +import { MetadataLibrary } from "./metadataLibrary.js"; +import { SettingsManager } from "./settingsManager.js"; import * as path from "path"; -import { URI } from "vscode-uri"; -import { AnsibleInventory } from "./ansibleInventory"; + +import pkg from "vscode-uri"; +const { URI } = pkg; + +import { AnsibleInventory } from "./ansibleInventory.js"; /** * Holds the overall context for the whole workspace. diff --git a/src/utils/commandRunner.ts b/src/utils/commandRunner.ts index 08d86d7e..25d845ad 100644 --- a/src/utils/commandRunner.ts +++ b/src/utils/commandRunner.ts @@ -1,9 +1,10 @@ -import { URI } from "vscode-uri"; +import pkg from "vscode-uri"; +const { URI } = pkg; import { Connection } from "vscode-languageserver"; -import { withInterpreter, asyncExec } from "./misc"; -import { getAnsibleCommandExecPath } from "./execPath"; -import { WorkspaceFolderContext } from "../services/workspaceManager"; -import { ExtensionSettings } from "../interfaces/extensionSettings"; +import { withInterpreter, asyncExec } from "./misc.js"; +import { getAnsibleCommandExecPath } from "./execPath.js"; +import { WorkspaceFolderContext } from "../services/workspaceManager.js"; +import { ExtensionSettings } from "../interfaces/extensionSettings.js"; export class CommandRunner { private connection: Connection; diff --git a/src/utils/docsFinder.ts b/src/utils/docsFinder.ts index ce4a7dc2..e1228a87 100644 --- a/src/utils/docsFinder.ts +++ b/src/utils/docsFinder.ts @@ -1,13 +1,13 @@ import * as fs from "fs"; import * as path from "path"; import { parseDocument } from "yaml"; -import { LazyModuleDocumentation, parseRawRouting } from "./docsParser"; -import { IModuleMetadata } from "../interfaces/module"; +import { LazyModuleDocumentation, parseRawRouting } from "./docsParser.js"; +import { IModuleMetadata } from "../interfaces/module.js"; import { IPluginRoutesByType, IPluginRoutingByCollection, -} from "../interfaces/pluginRouting"; -import { globArray } from "./pathUtils"; +} from "../interfaces/pluginRouting.js"; +import { globArray } from "./pathUtils.js"; export async function findDocumentation( dir: string, diff --git a/src/utils/docsFormatter.ts b/src/utils/docsFormatter.ts index 41155354..1b822fbc 100644 --- a/src/utils/docsFormatter.ts +++ b/src/utils/docsFormatter.ts @@ -5,8 +5,8 @@ import { IDescription, IModuleDocumentation, IOption, -} from "../interfaces/module"; -import { IPluginRoute } from "../interfaces/pluginRouting"; +} from "../interfaces/module.js"; +import { IPluginRoute } from "../interfaces/pluginRouting.js"; export function formatModule( module: IModuleDocumentation, diff --git a/src/utils/docsParser.ts b/src/utils/docsParser.ts index 0256dde4..8aeab039 100644 --- a/src/utils/docsParser.ts +++ b/src/utils/docsParser.ts @@ -6,14 +6,14 @@ import { IModuleDocumentation, IModuleMetadata, IOption, -} from "../interfaces/module"; -import { hasOwnProperty, isObject } from "./misc"; +} from "../interfaces/module.js"; +import { hasOwnProperty, isObject } from "./misc.js"; import { IPluginRoute, IPluginRoutesByName, IPluginRoutesByType, IPluginTypes, -} from "../interfaces/pluginRouting"; +} from "../interfaces/pluginRouting.js"; const DOCUMENTATION = "DOCUMENTATION"; diff --git a/src/utils/execPath.ts b/src/utils/execPath.ts index 212a9458..c446e07f 100644 --- a/src/utils/execPath.ts +++ b/src/utils/execPath.ts @@ -1,6 +1,6 @@ // utils function to resolve executable path import * as path from "path"; -import { ExtensionSettings } from "../interfaces/extensionSettings"; +import { ExtensionSettings } from "../interfaces/extensionSettings.js"; /** * A method to return the path to the provided executable diff --git a/src/utils/getAnsibleMetaData.ts b/src/utils/getAnsibleMetaData.ts index fef23517..f2dc6167 100644 --- a/src/utils/getAnsibleMetaData.ts +++ b/src/utils/getAnsibleMetaData.ts @@ -1,7 +1,10 @@ import { Connection } from "vscode-languageserver"; -import { URI } from "vscode-uri"; -import { WorkspaceFolderContext } from "../services/workspaceManager"; -import { CommandRunner } from "./commandRunner"; + +import pkg from "vscode-uri"; +const { URI } = pkg; + +import { WorkspaceFolderContext } from "../services/workspaceManager.js"; +import { CommandRunner } from "./commandRunner.js"; import * as child_process from "child_process"; let context: WorkspaceFolderContext; diff --git a/src/utils/imagePuller.ts b/src/utils/imagePuller.ts index 90264efc..43061fa5 100644 --- a/src/utils/imagePuller.ts +++ b/src/utils/imagePuller.ts @@ -1,6 +1,6 @@ import * as child_process from "child_process"; import { Connection } from "vscode-languageserver"; -import { WorkspaceFolderContext } from "../services/workspaceManager"; +import { WorkspaceFolderContext } from "../services/workspaceManager.js"; export class ImagePuller { private connection: Connection; diff --git a/src/utils/yaml.ts b/src/utils/yaml.ts index c301c5a2..d7daac4e 100644 --- a/src/utils/yaml.ts +++ b/src/utils/yaml.ts @@ -1,4 +1,4 @@ -import * as _ from "lodash"; +import { find } from "lodash-es"; import { TextDocument } from "vscode-languageserver-textdocument"; import { Document, @@ -15,10 +15,10 @@ import { YAMLMap, YAMLSeq, } from "yaml"; -import { IModuleMetadata, IOption } from "../interfaces/module"; -import { DocsLibrary } from "../services/docsLibrary"; -import { isTaskKeyword, playExclusiveKeywords } from "./ansible"; -import { playKeywords, taskKeywords } from "../utils/ansible"; +import { IModuleMetadata, IOption } from "../interfaces/module.js"; +import { DocsLibrary } from "../services/docsLibrary.js"; +import { isTaskKeyword, playExclusiveKeywords } from "./ansible.js"; +import { playKeywords, taskKeywords } from "../utils/ansible.js"; import { Range, Position } from "vscode-languageserver"; type Options = ParseOptions & DocumentOptions & SchemaOptions; @@ -153,7 +153,7 @@ export function getPathAt( inclusive = false, ): Node[] | null { const offset = document.offsetAt(position); - const doc = _.find(docs, (d) => contains(d.contents, offset, inclusive)); + const doc = find(docs, (d) => contains(d.contents, offset, inclusive)); if (doc && doc.contents) { return getPathAtOffset([doc.contents], offset, inclusive, doc); } @@ -182,7 +182,7 @@ export function getPathAtOffset( if (path) { const currentNode = path[path.length - 1]; if (isMap(currentNode)) { - let pair = _.find(currentNode.items, (p) => + let pair = find(currentNode.items, (p) => contains(p.key as Node, offset, inclusive), ); if (pair) { @@ -193,7 +193,7 @@ export function getPathAtOffset( doc, ); } - pair = _.find(currentNode.items, (p) => + pair = find(currentNode.items, (p) => contains(p.value as Node, offset, inclusive), ); if (pair) { @@ -204,7 +204,7 @@ export function getPathAtOffset( doc, ); } - pair = _.find(currentNode.items, (p) => { + pair = find(currentNode.items, (p) => { const inBetweenNode = doc.createNode(null); const start = getOrigRange(p.key as Node)?.[1]; const end = getOrigRange(p.value as Node)?.[0]; @@ -217,7 +217,7 @@ export function getPathAtOffset( return path.concat(pair as unknown as Node, doc.createNode(null)); } } else if (isSeq(currentNode)) { - const item = _.find(currentNode.items, (n) => + const item = find(currentNode.items, (n) => contains(n as Node, offset, inclusive), ); if (item) { @@ -302,7 +302,7 @@ export function getDeclaredCollections(modulePath: Node[] | null): string[] { function getDeclaredCollectionsForMap(playNode: YAMLMap | null): string[] { const declaredCollections: string[] = []; - const collectionsPair = _.find( + const collectionsPair = find( playNode?.items, (pair) => isScalar(pair.key) && pair.key.value === "collections", ); diff --git a/test/helper.ts b/test/helper.ts index 93b9b513..19f261fd 100644 --- a/test/helper.ts +++ b/test/helper.ts @@ -1,13 +1,15 @@ import { TextDocument } from "vscode-languageserver-textdocument"; import * as path from "path"; import { readFileSync } from "fs"; -import { WorkspaceManager } from "../src/services/workspaceManager"; -import { createConnection, TextDocuments } from "vscode-languageserver/node"; -import { ValidationManager } from "../src/services/validationManager"; -import { ExtensionSettings } from "../src/interfaces/extensionSettings"; +import { WorkspaceManager } from "../src/services/workspaceManager.js"; +import { createConnection, TextDocuments } from "vscode-languageserver/node.js"; +import { ValidationManager } from "../src/services/validationManager.js"; +import { ExtensionSettings } from "../src/interfaces/extensionSettings.js"; // eslint-disable-next-line @typescript-eslint/no-var-requires -const Fuse = require("fuse.js"); +// import Fuse from 'fuse.js'; +// const Fuse = require("fuse.js"); +import Fuse from "fuse.js/dist/fuse.min.js"; export const FIXTURES_BASE_PATH = path.join("test", "fixtures"); export const ANSIBLE_COLLECTIONS_FIXTURES_BASE_PATH = path.resolve( diff --git a/test/index.ts b/test/index.ts index 6b3ac3fc..d3829f62 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,5 +1,5 @@ // This file is loaded automatically by mocha during the test run. -import { isWindows } from "./helper"; +import { isWindows } from "./helper.js"; import { execSync } from "child_process"; // Error code returned if we cannot even start testing: diff --git a/test/providers/completionProvider.test.ts b/test/providers/completionProvider.test.ts index dfaa7e43..96218bad 100644 --- a/test/providers/completionProvider.test.ts +++ b/test/providers/completionProvider.test.ts @@ -1,12 +1,13 @@ import { TextDocument } from "vscode-languageserver-textdocument"; import { expect } from "chai"; + import { Position, CompletionItemKind } from "vscode-languageserver"; import { doCompletion, doCompletionResolve, -} from "../../src/providers/completionProvider"; -import {} from "../../src/providers/validationProvider"; -import { WorkspaceFolderContext } from "../../src/services/workspaceManager"; +} from "../../src/providers/completionProvider.js"; +import {} from "../../src/providers/validationProvider.js"; +import { WorkspaceFolderContext } from "../../src/services/workspaceManager.js"; import { createTestWorkspaceManager, getDoc, @@ -17,7 +18,7 @@ import { setFixtureAnsibleCollectionPathEnv, setAnsibleConfigEnv, unsetAnsibleConfigEnv, -} from "../helper"; +} from "../helper.js"; function testPlayKeywords( context: WorkspaceFolderContext, diff --git a/test/providers/completionResolver.test.ts b/test/providers/completionResolver.test.ts index 91530460..2272f4f7 100644 --- a/test/providers/completionResolver.test.ts +++ b/test/providers/completionResolver.test.ts @@ -5,9 +5,9 @@ import { expect } from "chai"; import { EOL } from "os"; -import { doCompletionResolve } from "../../src/providers/completionProvider"; -import {} from "../../src/providers/validationProvider"; -import { WorkspaceFolderContext } from "../../src/services/workspaceManager"; +import { doCompletionResolve } from "../../src/providers/completionProvider.js"; +import {} from "../../src/providers/validationProvider.js"; +import { WorkspaceFolderContext } from "../../src/services/workspaceManager.js"; import { createTestWorkspaceManager, enableExecutionEnvironmentSettings, @@ -15,7 +15,7 @@ import { setFixtureAnsibleCollectionPathEnv, resolveDocUri, getDoc, -} from "../helper"; +} from "../helper.js"; function testFQCNEnabled(context: WorkspaceFolderContext) { const tests = [ diff --git a/test/providers/definitionProvider.test.ts b/test/providers/definitionProvider.test.ts index 5191c40d..8eba3d28 100644 --- a/test/providers/definitionProvider.test.ts +++ b/test/providers/definitionProvider.test.ts @@ -7,12 +7,14 @@ import { enableExecutionEnvironmentSettings, disableExecutionEnvironmentSettings, setFixtureAnsibleCollectionPathEnv, -} from "../helper"; +} from "../helper.js"; import { Position } from "vscode-languageserver"; -import { WorkspaceFolderContext } from "../../src/services/workspaceManager"; -import { getDefinition } from "../../src/providers/definitionProvider"; -import { fileExists } from "../../src/utils/misc"; -import { URI } from "vscode-uri"; +import { WorkspaceFolderContext } from "../../src/services/workspaceManager.js"; +import { getDefinition } from "../../src/providers/definitionProvider.js"; +import { fileExists } from "../../src/utils/misc.js"; + +import pkg from "vscode-uri"; +const { URI } = pkg; function testModuleNamesForDefinition( context: WorkspaceFolderContext, diff --git a/test/providers/hoverProvider.test.ts b/test/providers/hoverProvider.test.ts index bc5d40b1..1f44ac76 100644 --- a/test/providers/hoverProvider.test.ts +++ b/test/providers/hoverProvider.test.ts @@ -7,10 +7,10 @@ import { enableExecutionEnvironmentSettings, disableExecutionEnvironmentSettings, setFixtureAnsibleCollectionPathEnv, -} from "../helper"; -import { doHover } from "../../src/providers/hoverProvider"; +} from "../helper.js"; +import { doHover } from "../../src/providers/hoverProvider.js"; import { Position } from "vscode-languageserver"; -import { WorkspaceFolderContext } from "../../src/services/workspaceManager"; +import { WorkspaceFolderContext } from "../../src/services/workspaceManager.js"; function testPlayKeywords( context: WorkspaceFolderContext, diff --git a/test/providers/settingsManager.test.ts b/test/providers/settingsManager.test.ts index 0ba5385c..9c47e398 100644 --- a/test/providers/settingsManager.test.ts +++ b/test/providers/settingsManager.test.ts @@ -2,9 +2,9 @@ import { expect } from "chai"; import { WorkspaceFolderContext, WorkspaceManager, -} from "../../src/services/workspaceManager"; -import { createTestWorkspaceManager } from "../helper"; -import { ExtensionSettings } from "../../src/interfaces/extensionSettings"; +} from "../../src/services/workspaceManager.js"; +import { createTestWorkspaceManager } from "../helper.js"; +import { ExtensionSettings } from "../../src/interfaces/extensionSettings.js"; function simulateClientSettings(workspaceManager: WorkspaceManager, settings) { workspaceManager.clientCapabilities.workspace = { diff --git a/test/providers/validationProvider.test.ts b/test/providers/validationProvider.test.ts index 526da1fc..e0da58ff 100644 --- a/test/providers/validationProvider.test.ts +++ b/test/providers/validationProvider.test.ts @@ -4,8 +4,8 @@ import { Position, integer } from "vscode-languageserver"; import { doValidate, getYamlValidation, -} from "../../src/providers/validationProvider"; -import { WorkspaceFolderContext } from "../../src/services/workspaceManager"; +} from "../../src/providers/validationProvider.js"; +import { WorkspaceFolderContext } from "../../src/services/workspaceManager.js"; import { createTestValidationManager, createTestWorkspaceManager, @@ -14,8 +14,8 @@ import { enableExecutionEnvironmentSettings, disableExecutionEnvironmentSettings, setFixtureAnsibleCollectionPathEnv, -} from "../helper"; -import { ValidationManager } from "../../src/services/validationManager"; +} from "../helper.js"; +import { ValidationManager } from "../../src/services/validationManager.js"; function testValidationFromCache( validationManager: ValidationManager, diff --git a/test/rootMochaHooks.ts b/test/rootMochaHooks.ts index 170560e5..dc11ade1 100644 --- a/test/rootMochaHooks.ts +++ b/test/rootMochaHooks.ts @@ -1,7 +1,9 @@ -import * as chai from "chai"; -import { ConsoleOutput } from "./consoleOutput"; +// import * as chaiModule from "chai"; +import { ConsoleOutput } from "./consoleOutput.js"; -chai.config.truncateThreshold = 0; // disable truncating +// const chai = require('chai'); + +// chai.config.truncateThreshold = 0; // disable truncating export const mochaHooks = (): Mocha.RootHookObject => { const consoleOutput = new ConsoleOutput(); diff --git a/test/utils/getAnsibleMetaData.test.ts b/test/utils/getAnsibleMetaData.test.ts index 7b2bf6a5..2256f1a6 100644 --- a/test/utils/getAnsibleMetaData.test.ts +++ b/test/utils/getAnsibleMetaData.test.ts @@ -1,16 +1,18 @@ import { expect } from "chai"; -import path = require("path"); +import * as path from "path"; import { getAnsibleMetaData, getResultsThroughCommandRunner, -} from "../../src/utils/getAnsibleMetaData"; +} from "../../src/utils/getAnsibleMetaData.js"; import { createTestWorkspaceManager, disableExecutionEnvironmentSettings, enableExecutionEnvironmentSettings, getDoc, resolveDocUri, -} from "../helper"; +} from "../helper.js"; +import * as url from "url"; +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); function getAnsibleTestInfo() { const ansibleInfo = {}; diff --git a/test/utils/pathUtils.test.ts b/test/utils/pathUtils.test.ts index 4c1dcba8..c2f02824 100644 --- a/test/utils/pathUtils.test.ts +++ b/test/utils/pathUtils.test.ts @@ -1,6 +1,8 @@ import { expect } from "chai"; -import path = require("path"); -import { globArray } from "../../src/utils/pathUtils"; +import * as path from "path"; +import { globArray } from "../../src/utils/pathUtils.js"; +import * as url from "url"; +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); describe("docsFinder", () => { const dir = path.resolve(__dirname, "..", "fixtures", "utils", "docsFinder"); diff --git a/test/utils/resolveSuffixWhileCompletion.test.ts b/test/utils/resolveSuffixWhileCompletion.test.ts index fbccd632..18c01e61 100644 --- a/test/utils/resolveSuffixWhileCompletion.test.ts +++ b/test/utils/resolveSuffixWhileCompletion.test.ts @@ -1,5 +1,5 @@ import { EOL } from "os"; -import { resolveSuffix } from "../../src/providers/completionProvider"; +import { resolveSuffix } from "../../src/providers/completionProvider.js"; import { expect } from "chai"; function testResolveSuffixInPlaybook() { diff --git a/test/utils/runCommand.test.ts b/test/utils/runCommand.test.ts index f709b51e..ea70ba69 100644 --- a/test/utils/runCommand.test.ts +++ b/test/utils/runCommand.test.ts @@ -1,21 +1,24 @@ -import { CommandRunner } from "../../src/utils/commandRunner"; +import { CommandRunner } from "../../src/utils/commandRunner.js"; import { AssertionError, expect } from "chai"; -import { WorkspaceManager } from "../../src/services/workspaceManager"; -import { createConnection } from "vscode-languageserver/node"; -import { getDoc } from "../helper"; +import { WorkspaceManager } from "../../src/services/workspaceManager.js"; +import { createConnection } from "vscode-languageserver/node.js"; +import { getDoc } from "../helper.js"; import * as path from "path"; +import * as url from "url"; +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); +const { default: pkgJSON } = await import( + path.resolve(__dirname, "..", "..", "package.json"), + { assert: { type: "json" } } +); describe("commandRunner", () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const pkgJSON = require(path.resolve(__dirname, "..", "..", "package.json")); - const tests = [ { args: [ path.join( path.resolve(__dirname, "..", ".."), "bin", - "ansible-language-server", + "ansible-language-server.js", ), "--version", ], diff --git a/test/utils/withInterpreter.test.ts b/test/utils/withInterpreter.test.ts index 2dbbfa5b..182ba3f2 100644 --- a/test/utils/withInterpreter.test.ts +++ b/test/utils/withInterpreter.test.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { withInterpreter } from "../../src/utils/misc"; +import { withInterpreter } from "../../src/utils/misc.js"; describe("withInterpreter", () => { const tests = [ diff --git a/test/utils/yaml.test.ts b/test/utils/yaml.test.ts index 135ea40d..60ffcc25 100644 --- a/test/utils/yaml.test.ts +++ b/test/utils/yaml.test.ts @@ -11,8 +11,8 @@ import { isRoleParam, isTaskParam, parseAllDocuments, -} from "../../src/utils/yaml"; -import { getDoc, isWindows } from "../helper"; +} from "../../src/utils/yaml.js"; +import { getDoc, isWindows } from "../helper.js"; function getPathInFile(yamlFile: string, line: number, character: number) { const textDoc = getDoc(`yaml/${yamlFile}`); diff --git a/tools/settings-doc-generator.ts b/tools/settings-doc-generator.ts index 4b5aef14..6360b76e 100644 --- a/tools/settings-doc-generator.ts +++ b/tools/settings-doc-generator.ts @@ -1,8 +1,10 @@ -import Handlebars = require("handlebars"); +import * as Handlebars from "handlebars"; import * as fs from "fs"; -import { SettingsManager } from "../src/services/settingsManager"; +import { SettingsManager } from "../src/services/settingsManager.js"; import * as path from "path"; import * as _ from "lodash"; +import * as url from "url"; +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); // Get the default settings values from settingsManager class const settingsManager = new SettingsManager(null, null); diff --git a/tsconfig.json b/tsconfig.json index bba0e238..c73cd222 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,14 +3,24 @@ "alwaysStrict": true, "declaration": true, "forceConsistentCasingInFileNames": true, - "lib": ["es2016"], - "module": "commonjs", - "moduleResolution": "node", + "lib": ["ESNext"], + "module": "ESNext", + "moduleResolution": "NodeNext", "outDir": "./out/server", "sourceMap": true, - "target": "es6", + "target": "ESNext", "esModuleInterop": true, "skipLibCheck": true, + "allowJs": true, + "checkJs": false, + "isolatedModules": true, + "allowSyntheticDefaultImports": true, }, + "include": ["src/**/*.ts", "test/**/*.ts"], "exclude": ["node_modules", "out", "vscode-ansible"], + "ts-node": { + "moduleTypes": { + ".ts": "cjs", + }, + }, }