Skip to content

Commit

Permalink
feat: convert to project to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
rellafella committed Apr 10, 2024
1 parent 98f2993 commit bcc1e02
Show file tree
Hide file tree
Showing 78 changed files with 3,054 additions and 2,561 deletions.
1 change: 1 addition & 0 deletions .eslintcache

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ extends:
- eslint:recommended
- plugin:prettier/recommended
- plugin:prettier-doc/recommended
- plugin:jest/recommended
plugins:
- import
root: true
env:
es6: true
node: true
jest: true
node: true
parserOptions:
ecmaVersion: 2017
ecmaVersion: 2024
sourceType: module
rules:
curly: error
import/no-extraneous-dependencies:
Expand Down
66 changes: 37 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
devenv.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, devenv, systems, ... } @ inputs:
outputs =
{
self,
nixpkgs,
devenv,
systems,
...
}@inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
Expand All @@ -15,38 +22,39 @@
devenv-up = self.devShells.${system}.default.config.procfileScript;
});

devShells = forEachSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
# https://devenv.sh/basics/
env.NODE_OPTIONS = "--experimental-vm-modules";
devShells = forEachSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
# https://devenv.sh/basics/
env.NODE_OPTIONS = "--experimental-vm-modules";

# https://devenv.sh/packages/
packages = [
pkgs.nodejs
pkgs.yarn
];
# https://devenv.sh/packages/
packages = [
pkgs.nodejs
pkgs.yarn
];

# https://devenv.sh/languages/
# languages.nix.enable = true;
# https://devenv.sh/languages/
# languages.nix.enable = true;

# https://devenv.sh/pre-commit-hooks/
# pre-commit.hooks.shellcheck.enable = true;
# https://devenv.sh/pre-commit-hooks/
# pre-commit.hooks.shellcheck.enable = true;

# https://devenv.sh/processes/
# processes.ping.exec = "ping example.com";
# https://devenv.sh/processes/
# processes.ping.exec = "ping example.com";

# See full reference at https://devenv.sh/reference/options/
}
];
};
});
# See full reference at https://devenv.sh/reference/options/
}
];
};
}
);
};
}
8 changes: 0 additions & 8 deletions jest.eslint.config.js

This file was deleted.

13 changes: 0 additions & 13 deletions jest.test.config.js

This file was deleted.

18 changes: 18 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"declaration": true,
"stripInternal": true,
"noImplicitOverride": true,
"noUncheckedIndexedAccess": true,
"removeComments": true,
"rootDir": ".",
"baseUrl": "./"
},
"exclude": ["node_modules"]
}
26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
"name": "@zackad/prettier-plugin-twig-melody",
"version": "0.6.0",
"description": "Prettier Plugin for Twig/Melody",
"main": "src",
"repository": "https://github.com/zackad/prettier-plugin-twig-melody",
"author": "Tom Bartel <[email protected]>",
"license": "Apache-2.0",
"author": "Tom Bartel <[email protected]>",
"type": "module",
"module": "./src/index.js",
"main": "./src/index.js",
"files": [
"src"
],
"engines": {
"node": ">=18"
},
"scripts": {
"lint": "jest -c jest.eslint.config.js",
"test": "jest",
"prettier": "prettier --plugin=. --parser=melody"
"lint": "eslint --cache --cache-strategy content --report-unused-disable-directives .",
"prettier": "prettier --plugin=./src/index.js --parser=melody",
"test": "vitest"
},
"dependencies": {
"babel-types": "^6.26.0",
Expand All @@ -30,15 +29,12 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^4.0.0 || ^5.0.0",
"eslint-plugin-prettier-doc": "^1.1.0",
"jest": "^30.0.0-alpha.3",
"jest-runner-eslint": "^2.1.2"
"vite": "^5.2.8",
"vitest": "^1.4.0"
},
"jest": {
"projects": [
"<rootDir>/jest.*.config.js"
]
"engines": {
"node": ">=18"
}
}
12 changes: 5 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"use strict";

const { print } = require("./printer.js");
const { parse } = require("./parser.js");
const symbols = require("./util/publicSymbols.js");
const publicFunctions = require("./util/publicFunctions.js");
import { print } from "./printer.js";
import { parse } from "./parser.js";
import * as symbols from "./util/publicSymbols.js";
import * as publicFunctions from "./util/publicFunctions.js";

const languages = [
{
Expand Down Expand Up @@ -137,4 +135,4 @@ const combinedExports = Object.assign(

// This exports defines the Prettier plugin
// See https://github.com/prettier/prettier/blob/master/docs/plugins.md
module.exports = combinedExports;
export default combinedExports;
13 changes: 5 additions & 8 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { CharStream, Lexer, TokenStream, Parser } = require("melody-parser");
const { extension: coreExtension } = require("melody-extension-core");
const {
import { CharStream, Lexer, TokenStream, Parser } from "melody-parser";
import { extension as coreExtension } from "melody-extension-core";
import {
getAdditionalMelodyExtensions,
getPluginPathsFromOptions
} = require("./util");
} from "./util/index.js";

const ORIGINAL_SOURCE = Symbol("ORIGINAL_SOURCE");

Expand Down Expand Up @@ -86,7 +86,4 @@ const parse = (text, parsers, options) => {
return ast;
};

module.exports = {
parse,
ORIGINAL_SOURCE
};
export { parse, ORIGINAL_SOURCE };
4 changes: 1 addition & 3 deletions src/print/AliasExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ const p = (node, path, print) => {
return [path.call(print, "name"), " as ", path.call(print, "alias")];
};

module.exports = {
printAliasExpression: p
};
export { p as printAliasExpression };
8 changes: 3 additions & 5 deletions src/print/ArrayExpression.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const prettier = require("prettier");
import prettier from "prettier";
const { group, softline, line, indent, join } = prettier.doc.builders;
const { STRING_NEEDS_QUOTES } = require("../util");
import { STRING_NEEDS_QUOTES } from "../util/index.js";

const p = (node, path, print) => {
node[STRING_NEEDS_QUOTES] = true;
Expand All @@ -10,6 +10,4 @@ const p = (node, path, print) => {
return group(["[", indent(indentedContent), softline, "]"]);
};

module.exports = {
printArrayExpression: p
};
export { p as printArrayExpression };
8 changes: 3 additions & 5 deletions src/print/Attribute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES } = require("../util");
const { Node } = require("melody-types");
import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES } from "../util/index.js";
import { Node } from "melody-types";

const mayCorrectWhitespace = attrName =>
["id", "class", "type"].indexOf(attrName) > -1;
Expand Down Expand Up @@ -47,6 +47,4 @@ const p = (node, path, print = print) => {
return docs;
};

module.exports = {
printAttribute: p
};
export { p as printAttribute };
8 changes: 3 additions & 5 deletions src/print/AutoescapeBlock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const prettier = require("prettier");
import prettier from "prettier";
const { hardline } = prettier.doc.builders;
const { printChildBlock, quoteChar } = require("../util");
import { printChildBlock, quoteChar } from "../util/index.js";

const createOpener = (node, options) => {
return [
Expand All @@ -27,6 +27,4 @@ const p = (node, path, print, options) => {
return parts;
};

module.exports = {
printAutoescapeBlock: p
};
export { p as printAutoescapeBlock };
14 changes: 6 additions & 8 deletions src/print/BinaryExpression.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const prettier = require("prettier");
import prettier from "prettier";
const { group, line, softline, indent } = prettier.doc.builders;
const { Node } = require("melody-types");
const {
import { Node } from "melody-types";
import {
EXPRESSION_NEEDED,
STRING_NEEDS_QUOTES,
INSIDE_OF_STRING,
Expand All @@ -10,8 +10,8 @@ const {
firstValueInAncestorChain,
findParentNode,
wrapExpressionIfNeeded
} = require("../util");
const { extension: coreExtension } = require("melody-extension-core");
} from "../util/index.js";
import { extension as coreExtension } from "melody-extension-core";
const ALREADY_INDENTED = Symbol("ALREADY_INDENTED");
const OPERATOR_PRECEDENCE = Symbol("OPERATOR_PRECEDENCE");
const NO_WHITESPACE_AROUND = [".."];
Expand Down Expand Up @@ -151,6 +151,4 @@ const p = (node, path, print, options) => {
return printBinaryExpression(node, path, print);
};

module.exports = {
printBinaryExpression: p
};
export { p as printBinaryExpression };
10 changes: 4 additions & 6 deletions src/print/BlockStatement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const prettier = require("prettier");
import prettier from "prettier";
const { hardline, group } = prettier.doc.builders;
const { Node } = require("melody-types");
const { EXPRESSION_NEEDED, printChildBlock } = require("../util");
import { Node } from "melody-types";
import { EXPRESSION_NEEDED, printChildBlock } from "../util/index.js";

const p = (node, path, print, options) => {
node[EXPRESSION_NEEDED] = false;
Expand Down Expand Up @@ -44,6 +44,4 @@ const p = (node, path, print, options) => {
}
};

module.exports = {
printBlockStatement: p
};
export { p as printBlockStatement };
12 changes: 5 additions & 7 deletions src/print/CallExpression.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const prettier = require("prettier");
import prettier from "prettier";
const { group, softline, line, indent, join } = prettier.doc.builders;
const {
import {
EXPRESSION_NEEDED,
STRING_NEEDS_QUOTES,
wrapExpressionIfNeeded
} = require("../util");
const { Node } = require("melody-types");
} from "../util/index.js";
import { Node } from "melody-types";

const p = (node, path, print) => {
node[EXPRESSION_NEEDED] = false;
Expand Down Expand Up @@ -34,6 +34,4 @@ const p = (node, path, print) => {
return group(parts);
};

module.exports = {
printCallExpression: p
};
export { p as printCallExpression };
10 changes: 4 additions & 6 deletions src/print/ConditionalExpression.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const prettier = require("prettier");
import prettier from "prettier";
const { line, indent, group } = prettier.doc.builders;
const {
import {
EXPRESSION_NEEDED,
STRING_NEEDS_QUOTES,
wrapExpressionIfNeeded
} = require("../util");
} from "../util/index.js";

const p = (node, path, print) => {
node[EXPRESSION_NEEDED] = false;
Expand All @@ -23,6 +23,4 @@ const p = (node, path, print) => {
return group(parts);
};

module.exports = {
printConditionalExpression: p
};
export { p as printConditionalExpression };
Loading

0 comments on commit bcc1e02

Please sign in to comment.