Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Migrate from commonjs to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 22, 2024
1 parent 2760e7a commit 7368bb6
Show file tree
Hide file tree
Showing 49 changed files with 279 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2021,
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
Expand Down
8 changes: 6 additions & 2 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
27 changes: 20 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
16 changes: 8 additions & 8 deletions src/ansibleLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions src/providers/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/providers/completionProviderUtils.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
10 changes: 6 additions & 4 deletions src/providers/definitionProvider.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/providers/hoverProvider.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,7 +25,7 @@ import {
isRoleParam,
isTaskParam,
parseAllDocuments,
} from "../utils/yaml";
} from "../utils/yaml.js";

export async function doHover(
document: TextDocument,
Expand Down
8 changes: 4 additions & 4 deletions src/providers/semanticTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,7 +31,7 @@ import {
isRoleParam,
isTaskParam,
parseAllDocuments,
} from "../utils/yaml";
} from "../utils/yaml.js";

export const tokenTypes = [
SemanticTokenTypes.method,
Expand Down
14 changes: 9 additions & 5 deletions src/providers/validationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// import _IntervalTree from "@flatten-js/interval-tree";
import IntervalTree from "@flatten-js/interval-tree";

import {
Connection,
Diagnostic,
DiagnosticSeverity,
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.
Expand Down Expand Up @@ -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<Diagnostic>();
const rangeTree = new IntervalTree.default<Diagnostic>();
yDocuments.forEach((yDoc) => {
yDoc.errors.forEach((error) => {
const [errStart, errEnd] = error.pos;
Expand Down
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions src/services/ansibleConfig.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/services/ansibleInventory.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/services/ansibleLint.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.
Expand Down
Loading

0 comments on commit 7368bb6

Please sign in to comment.