Skip to content

Commit

Permalink
feat: updated all of postdfm to use esmodules correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
spiltcoffee committed Apr 9, 2021
1 parent e91b50a commit 7713eec
Show file tree
Hide file tree
Showing 57 changed files with 1,041 additions and 815 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./eslint.config.cjs")();
1 change: 0 additions & 1 deletion .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname $0)/_/husky.sh"

yarn run commitlint --edit $1
yarn run commitlint --config commitlint.config.cjs --edit $1
8 changes: 4 additions & 4 deletions __test__/__fixtures__/transform/everything/plugin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// eslint-disable-next-line node/no-extraneous-require
const { Plugin } = require("@postdfm/plugin");
// eslint-disable-next-line node/no-extraneous-import
import { Plugin } from "@postdfm/plugin";

function reverseString(str) {
return str.split("").reverse().join("");
}

module.exports = class ReverseEverythingPlugin extends Plugin {
export default class ReverseEverythingPlugin extends Plugin {
PLUGIN_NAME = "ReverseEverythingPlugin";

hookCallback;
Expand Down Expand Up @@ -134,4 +134,4 @@ module.exports = class ReverseEverythingPlugin extends Plugin {
// nothing to reverse here
});
}
};
}
8 changes: 4 additions & 4 deletions __test__/__fixtures__/transform/hello-world/plugin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// eslint-disable-next-line node/no-extraneous-require
const { Plugin } = require("@postdfm/plugin");
// eslint-disable-next-line node/no-extraneous-import
import { Plugin } from "@postdfm/plugin";

module.exports = class HelloWorldPlugin extends Plugin {
export default class HelloWorldPlugin extends Plugin {
install(hooks) {
hooks.property.tap("HelloWorldPlugin", (node) => {
node.name = node.name.split("").reverse().join("");
return node;
});
}
};
}
3 changes: 3 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"]
};
3 changes: 0 additions & 3 deletions commitlint.config.js

This file was deleted.

24 changes: 12 additions & 12 deletions eslint.config.js → eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ module.exports = function getConfig(enableTypeChecking) {
settings: {
node: {
allowModules: ["@postdfm/ast2dfm", "@postdfm/ast", "@postdfm/dfm2ast"],
tryExtensions: [".js", ".ts", ".json", ".node"],
},
tryExtensions: [".js", ".cjs", ".ts", ".json", ".node"]
}
},
ignorePatterns: [".eslintrc.js"],
parserOptions: {
project: "./tsconfig.json",
extraFileExtensions: [".cjs"],
project: "./tsconfig.json"
},
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:jest/recommended",
"prettier",
"prettier"
],
overrides: [
{
Expand All @@ -30,17 +30,17 @@ module.exports = function getConfig(enableTypeChecking) {
enableTypeChecking &&
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier",
"prettier/@typescript-eslint",
"prettier/@typescript-eslint"
].filter((v) => !!v),
rules: {
"node/no-unsupported-features/es-syntax": [
"error",
{
ignores: ["modules"],
},
],
},
},
],
ignores: ["modules", "dynamicImport"]
}
]
}
}
]
};
};
28 changes: 0 additions & 28 deletions jest.config.js

This file was deleted.

34 changes: 34 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"reporters": [
"default",
[
"jest-junit",
{
"usePathForSuiteName": "true",
"classNameTemplate": "[{classname}]",
"titleTemplate": "{title}",
"outputDirectory": "test-results/jest",
"outputName": "./report.xml"
}
]
],
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.ts",
"!**/node_modules/**",
"!**/dist/**",
"!packages/@postdfm/dfm2ast/src/grammar.ts"
],
"coverageReporters": ["lcov", "text"],
"coverageDirectory": "coverage",
"rootDir": "./"
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"packages/postdfm"
],
"description": "Provides an API for easily transforming Delphi Forms",
"type": "module",
"scripts": {
"postinstall": "husky install",
"ci": "yarn --frozen-lockfile && yarn run compile && yarn run lint:check && yarn run format:check && yarn test && yarn docs",
Expand All @@ -15,7 +16,7 @@
"format:fix": "yarn format --write --list-different",
"format:check": "yarn format --check",
"compile": "yarn workspaces run compile",
"test": "jest --coverage",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose --maxWorkers=16",
"docs": "yarn workspaces run docs",
"release": "semantic-release",
"snyk-protect": "snyk protect",
Expand All @@ -33,20 +34,21 @@
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"commitlint": "^12.0.1",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.0.2",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-node": "^11.1.0",
"execa": "^4.0.0",
"husky": "^5.0.6",
"jest": "^26.0.0",
"jest": "^27.0.0-next.7",
"jest-junit": "^10.0.0",
"lint-staged": "^10.0.3",
"nearley": "^2.16.0",
"prettier": "^2.2.1",
"semantic-release": "^17.3.8",
"ts-jest": "^26.4.4",
"semantic-release": "^17.4.0",
"ts-jest": "^27.0.0-next.10",
"typedoc": "^0.20.24",
"typescript": "^4.1.3"
},
Expand Down
1 change: 1 addition & 0 deletions packages/@postdfm/ast/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../../eslint.config.cjs")(true);
1 change: 0 additions & 1 deletion packages/@postdfm/ast/.eslintrc.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/@postdfm/ast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"description": "Abstract Syntax Tree classes for postdfm",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"compile": "tsc --listEmittedFiles",
"docs": "typedoc --options typedoc.config.js"
"docs": "typedoc --options typedoc.config.cjs"
},
"author": "SpiltCoffee",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions packages/@postdfm/ast/typedoc.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = require("../../../typedoc.config.cjs")({
entryPoints: ["src/index.ts"],
out: "@postdfm/ast"
});
4 changes: 0 additions & 4 deletions packages/@postdfm/ast/typedoc.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/@postdfm/ast2dfm/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../../eslint.config.cjs")(true);
1 change: 0 additions & 1 deletion packages/@postdfm/ast2dfm/.eslintrc.js

This file was deleted.

14 changes: 9 additions & 5 deletions packages/@postdfm/ast2dfm/__test__/broken/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as AST from "@postdfm/ast";
import * as fs from "fs";
import * as path from "path";
import fs from "fs";
import { fileURLToPath } from "url";

import { Root } from "@postdfm/ast";
import stringify from "../../src";

describe("dfm2ast", () => {
test("broken AST throws error", () => {
const ast = JSON.parse(
fs.readFileSync(path.join(__dirname, "ast.json"), "utf8")
) as AST.Root;
fs.readFileSync(
fileURLToPath(new URL("./ast.json", import.meta.url)),
"utf8"
)
) as Root;

expect(() => stringify(ast)).toThrow("Cannot stringify astType unknown");
});
Expand Down
3 changes: 2 additions & 1 deletion packages/@postdfm/ast2dfm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"description": "Convert DFM Abstract Syntax Trees to a Delphi Form file",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"compile": "tsc --listEmittedFiles",
"docs": "typedoc --options typedoc.config.js"
"docs": "typedoc --options typedoc.config.cjs"
},
"author": "SpiltCoffee",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions packages/@postdfm/ast2dfm/typedoc.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = require("../../../typedoc.config.cjs")({
entryPoints: ["src/index.ts"],
out: "@postdfm/ast2dfm"
});
4 changes: 0 additions & 4 deletions packages/@postdfm/ast2dfm/typedoc.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/@postdfm/dfm2ast/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../../eslint.config.cjs")(true);
1 change: 0 additions & 1 deletion packages/@postdfm/dfm2ast/.eslintrc.js

This file was deleted.

9 changes: 6 additions & 3 deletions packages/@postdfm/dfm2ast/__test__/broken/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as fs from "fs";
import * as path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
import parse from "../../src";

describe("dfm2ast", () => {
test("broken DFM throws error", () => {
const dfm = fs.readFileSync(path.join(__dirname, "form.dfm"), "ascii");
const dfm = fs.readFileSync(
fileURLToPath(new URL("./form.dfm", import.meta.url)),
"ascii"
);

expect(() => parse(dfm)).toThrow("Unexpected End Of Input");
});
Expand Down
26 changes: 16 additions & 10 deletions packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import * as fs from "fs";
import * as path from "path";
import fs from "fs";
import { ASTNode } from "@postdfm/ast";
import parse from "../../src";

const rootFixturesDir = path.join("__test__", "__fixtures__");
const parseFixturesDir = path.join(rootFixturesDir, "parse");
const parseFixturesPath = new URL(
"../../../../../__test__/__fixtures__/parse/",
import.meta.url
);

describe("dfm2ast", () => {
describe("parse fixtures", () => {
const fixtures = fs.readdirSync(parseFixturesDir);
const fixtures = fs.readdirSync(parseFixturesPath);
fixtures.forEach((fixture) => {
const formFile = path.join(parseFixturesDir, fixture, "form.dfm");
const astFile = path.join(parseFixturesDir, fixture, "ast.json");
const fixturePath = new URL(`./${fixture}/`, parseFixturesPath);
const formFile = fs.readFileSync(
new URL("./form.dfm", fixturePath),
"ascii"
);
const astJson = JSON.parse(
fs.readFileSync(new URL("./ast.json", fixturePath), "utf-8")
) as ASTNode;

test(`${fixture}`, () => {
expect(
JSON.parse(JSON.stringify(parse(fs.readFileSync(formFile, "ascii"))))
).toEqual(JSON.parse(fs.readFileSync(astFile, "utf8")));
expect(JSON.parse(JSON.stringify(parse(formFile)))).toEqual(astJson);
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/@postdfm/dfm2ast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "Convert Delphi Form files to an Abstract Syntax Tree",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"precompile": "nearleyc ne/grammar.ne -o src/grammar.ts",
"compile": "tsc --listEmittedFiles",
"docs": "typedoc --options typedoc.config.js"
"docs": "typedoc --options typedoc.config.cjs"
},
"author": "SpiltCoffee",
"license": "MIT",
Expand Down
9 changes: 8 additions & 1 deletion packages/@postdfm/dfm2ast/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Root } from "@postdfm/ast";
import { Grammar, Parser } from "nearley";

// nearley isn't a proper ESM module here (not even CommonJS - it's UMD)
import * as nearleyPkg from "nearley";
import type { Parser as ParserType, Grammar as GrammarType } from "nearley";
const { Parser, Grammar } = (<
{ default: { Parser: typeof ParserType; Grammar: typeof GrammarType } }
>(<unknown>nearleyPkg)).default;

import grammar from "./grammar";

function parse(dfm: string): Root {
Expand Down
4 changes: 4 additions & 0 deletions packages/@postdfm/dfm2ast/typedoc.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = require("../../../typedoc.config.cjs")({
entryPoints: ["src/index.ts"],
out: "@postdfm/dfm2ast"
});
4 changes: 0 additions & 4 deletions packages/@postdfm/dfm2ast/typedoc.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/@postdfm/plugin/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../../eslint.config.cjs")(true);
1 change: 0 additions & 1 deletion packages/@postdfm/plugin/.eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/@postdfm/plugin/__test__/plugin/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as AST from "@postdfm/ast";
import { Plugin, Hooks } from "../../src";
import { jest } from "@jest/globals";

class TapAllPlugin extends Plugin {
hookCallback: () => void;
Expand Down
Loading

0 comments on commit 7713eec

Please sign in to comment.