Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate module from CommonJS to ES-Module #393

Merged
merged 18 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"reporter": [
"lcov",
"text"
]
}
188 changes: 119 additions & 69 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
{
"env": {
"browser": true,
"es6": true,
"es2021": true,
"node": true
},
"extends": [],
"ignorePatterns": [],
"extends": [
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"project": "./tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"@typescript-eslint/tslint"
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"eslint-plugin-node",
"eslint-plugin-unicorn",
"@typescript-eslint"
],
"rules": {
"quotes": [
"off"
],
"@typescript-eslint/quotes": "off",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/array-type": [
"error",
{
"default": "array"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": {
"message": "Avoid using the `Object` type. Did you mean `object`?"
},
"Function": {
"message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
},
"Boolean": {
"message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
},
"Number": {
"message": "Avoid using the `Number` type. Did you mean `number`?"
},
"String": {
"message": "Avoid using the `String` type. Did you mean `string`?"
},
"Symbol": {
"message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
}
}
}
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/indent": [
"error",
2,
Expand All @@ -35,37 +64,55 @@
},
"FunctionExpression": {
"parameters": "first"
}
},
"SwitchCase": 1
}
],
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-empty-function": [
"error",
{
"allow": [
"constructors"
]
}
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-shadow": [
"error",
{
"hoist": "all"
}
],
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": [
"error",
"always"
],
/*
"@typescript-eslint/space-within-parens": [
"@typescript-eslint/triple-slash-reference": [
"error",
"always"
],*/
"@typescript-eslint/triple-slash-reference": "error",
{
"path": "always",
"types": "prefer-import",
"lib": "always"
}
],
"@typescript-eslint/unified-signatures": "error",
"arrow-parens": [
"error",
"as-needed"
],
"camelcase": "error",
"comma-dangle": "error",
"complexity": "off",
"constructor-super": "error",
Expand All @@ -77,9 +124,10 @@
"smart"
],
"guard-for-in": "off",
"id-blacklist": [
"id-denylist": [
"error",
"any",
"Number",
"number",
"String",
"string",
Expand All @@ -89,24 +137,19 @@
"undefined"
],
"id-match": "error",
/*
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": false
}
], */
/*
"import/no-internal-modules": [
"error",
{
"allow": [
"strtok3/*",
"file-type/*"
]
}
],*/
"error", {"devDependencies": ["test/**/*.ts"]}
],
"import/no-internal-modules": "off",
"import/order": "off",
"import/no-unresolved": ["error", {"caseSensitiveStrict": true }],
"indent": "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/newline-after-description": [
"error",
"never"
],
"max-classes-per-file": "off",
"max-len": [
"error",
Expand All @@ -123,6 +166,7 @@
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": "error",
"no-empty-function": "off",
"no-eval": "error",
"no-extra-bind": "error",
"no-fallthrough": "off",
Expand All @@ -132,12 +176,7 @@
"no-redeclare": "error",
"no-return-await": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
"hoist": "all"
}
],
"no-shadow": "off",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
Expand All @@ -147,46 +186,57 @@
"no-unsafe-finally": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-use-before-define": "off",
"no-var": "error",
"node/file-extension-in-import": ["error", "always"],
"node/no-extraneous-import": "error",
"object-shorthand": "error",
"one-var": [
"error",
"never"
],
// "prefer-arrow/prefer-arrow-functions": "error",
"prefer-const": "error",
"prefer-object-spread": "error",
"quote-props": [
"error",
"as-needed"
],
"quotes": "off",
"radix": "error",
"spaced-comment": "error",
"use-isnan": "error",
"valid-typeof": "off",
"@typescript-eslint/tslint/config": [
"semi": "error",
"space-in-parens": [
"error",
"never"
],
"spaced-comment": [
"error",
"always",
{
"rules": {
"jsdoc-format": [
true,
"check-multiline-start"
],
"no-reference-import": true,
"prefer-conditional-expression": true,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast",
"check-type-operator",
"check-rest-spread"
]
}
"markers": [
"/"
]
}
],
"unicorn/prefer-ternary": "error",
"use-isnan": "error",
"valid-typeof": "off"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx"
]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": [
"lib/tsconfig.json",
"test/tsconfig.json"
]
}
]
}
}
}

12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
version: 2

# CommonJS
# CommonJS (CJS)
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
interval: weekly
time: "04:00"
open-pull-requests-limit: 10
versioning-strategy: increase
target-branch: "master"
target-branch: "commonjs"
labels:
- dependencies
- CJS
ignore:
- dependency-name: "mocha"
update-types: [ "version-update:semver-major" ]
versions: ["10.x"]

# TypeScript Module
# ECMAScript Module (ESM)
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
time: "06:00"
open-pull-requests-limit: 10
versioning-strategy: increase
target-branch: "es-module"
target-branch: "master"
labels:
- dependencies
- ESM
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]
node-version: [14.x, 16.x, 18.x]

steps:

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ node_modules
**/*.js
**/*.js.map
**/*.d.ts
.nyc_output
coverage
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extension": ["ts", "tsx"],
"watch-files": ["lib/**/*.ts", "test/**/*.ts"],
"spec": ["test/*.ts"],
"loader": ["ts-node/esm"],
"extensions": ["ts", "tsx"]
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
A primitive token library used to read and write from a node `Buffer`.
Although it is possible to use this module directly, it is primary designed to be used with [strtok3 tokenizer](https://github.com/Borewit/strtok3).

## Compatibility

Module: version 5 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
JavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).

## Installation

```sh
Expand All @@ -34,8 +39,8 @@ npm install --save-dev @tokenizer/token
## Example

```js
const strtok3 = require('strtok3');
const token = require('token-types');
import * as strtok3 from 'strtok3';
import * as token from 'token-types';

(async () => {

Expand Down
Loading