diff --git a/jest.config.js b/jest.config.js index e3539f4..8bfb86c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,8 +1,9 @@ -module.exports = { - roots: [], - transform: { - "\\.ts$": "ts-jest", - }, - testRegex: "\\.spec\\.(ts|js)$", - moduleFileExtensions: ["ts", "js", "json"], +import presets from "ts-jest/presets/index.js"; +const { defaultsESM: tsjPreset } = presets; + +export default { + preset: "ts-jest", + testEnvironment: "node", + ...tsjPreset, + moduleNameMapper: { "^(\\.|\\.\\.)\\/(.+)\\.js": "$1/$2" }, }; diff --git a/package.json b/package.json index 80bc08e..6d9aabb 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,9 @@ "volta": { "node": "20.12.2" }, - "type": "commonjs", - "main": "dist/index.js", + "type": "module", "typings": "dist/index.d.ts", - "module": "dist.module/index.js", + "module": "dist/index.js", "sideEffects": false, "bundlewatch": { "files": [ @@ -50,13 +49,13 @@ }, "scripts": { "version": "npm run build", - "build": "rimraf dist/ dist.module/ && tsc && tsc -P tsconfig.module.json", + "build": "rimraf dist/ && tsc", "lint": "eslint **/*.{ts,js,json} --ignore-path .gitignore", "lint-fix": "eslint **/*.{ts,js,json} --ignore-path .gitignore --fix", "postlint": "prettier **/*.{md,yml,yaml} --ignore-path .gitignore --check", "postlint-fix": "prettier **/*.{md,yml,yaml} --ignore-path .gitignore --write", "test": "jest --roots src/", - "test-dist": "jest --roots dist/" + "test-dist": "node --experimental-vm-modules node_modules/jest/bin/jest.js --roots dist/" }, "devDependencies": { "@types/jest": "^29.5.12", diff --git a/src/Encoding.spec.ts b/src/Encoding.spec.ts index 8fa1bdc..b8d4695 100644 --- a/src/Encoding.spec.ts +++ b/src/Encoding.spec.ts @@ -1,4 +1,4 @@ -import { isEncoding } from "./Encoding"; +import { isEncoding } from "./Encoding.js"; describe("isEncoding", () => { it("handle truthy cases", () => { diff --git a/src/Endianness.spec.ts b/src/Endianness.spec.ts index d15ad70..6973b30 100644 --- a/src/Endianness.spec.ts +++ b/src/Endianness.spec.ts @@ -1,4 +1,4 @@ -import { isEndianness } from "./Endianness"; +import { isEndianness } from "./Endianness.js"; describe("isEndianness", () => { it("handle truthy cases", () => { diff --git a/src/WalkableBuffer.spec.ts b/src/WalkableBuffer.spec.ts index a2bc4ae..5e6aede 100644 --- a/src/WalkableBuffer.spec.ts +++ b/src/WalkableBuffer.spec.ts @@ -1,5 +1,5 @@ -import { BYTE, LONG, LONGLONG, SHORT } from "./constants"; -import { WalkableBuffer } from "./WalkableBuffer"; +import { BYTE, LONG, LONGLONG, SHORT } from "./constants.js"; +import { WalkableBuffer } from "./WalkableBuffer.js"; describe("constructor", () => { describe("parameters", () => { diff --git a/src/WalkableBuffer.ts b/src/WalkableBuffer.ts index f9aed63..c9874d9 100644 --- a/src/WalkableBuffer.ts +++ b/src/WalkableBuffer.ts @@ -4,10 +4,10 @@ import { DEFAULT_INITIAL_CURSOR, DEFAULT_SIGNED, LONG, -} from "./constants"; -import { Encoding, isEncoding } from "./Encoding"; -import { Endianness, isEndianness } from "./Endianness"; -import { WalkableBufferOptions } from "./WalkableBufferOptions"; +} from "./constants.js"; +import { Encoding, isEncoding } from "./Encoding.js"; +import { Endianness, isEndianness } from "./Endianness.js"; +import { WalkableBufferOptions } from "./WalkableBufferOptions.js"; /** * > _🚶🛡️ A class for easily reading data from binary Buffers_ diff --git a/src/WalkableBufferOptions.ts b/src/WalkableBufferOptions.ts index 2de9a2c..61d5b8d 100644 --- a/src/WalkableBufferOptions.ts +++ b/src/WalkableBufferOptions.ts @@ -1,5 +1,5 @@ -import { Encoding } from "./Encoding"; -import { Endianness } from "./Endianness"; +import { Encoding } from "./Encoding.js"; +import { Endianness } from "./Endianness.js"; /** * The options to provide into the constructor of `WalkableBuffer`. diff --git a/src/constants.ts b/src/constants.ts index d7877f1..9c1af21 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,5 @@ -import { Encoding } from "./Encoding"; -import { Endianness } from "./Endianness"; +import { Encoding } from "./Encoding.js"; +import { Endianness } from "./Endianness.js"; export const OCTET = 1; export const BYTE = OCTET; diff --git a/src/index.ts b/src/index.ts index dc69644..be4d157 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,8 @@ export { LONGLONG, OCTET, SHORT, -} from "./constants"; -export { Encoding, isEncoding } from "./Encoding"; -export { Endianness, isEndianness } from "./Endianness"; -export { WalkableBuffer as default, WalkableBuffer } from "./WalkableBuffer"; -export { WalkableBufferOptions } from "./WalkableBufferOptions"; +} from "./constants.js"; +export { Encoding, isEncoding } from "./Encoding.js"; +export { Endianness, isEndianness } from "./Endianness.js"; +export { WalkableBuffer as default, WalkableBuffer } from "./WalkableBuffer.js"; +export { WalkableBufferOptions } from "./WalkableBufferOptions.js"; diff --git a/tsconfig.json b/tsconfig.json index b3cbd59..1a52a73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,73 +1,19 @@ { "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ - "target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, - "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, - "lib": [ - "es2018" - ] /* Specify library files to be included in the compilation. */, - // "allowJs": true,/* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - "declaration": true /* Generates corresponding '.d.ts' file. */, - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true /* Generates corresponding '.map' file. */, - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "dist" /* Redirect output structure to the directory. */, - "rootDir": "src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, - // "composite": true, /* Enable project compilation */ - // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */, - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - "noUnusedLocals": true /* Report errors on unused locals. */, - "noUnusedParameters": true /* Report errors on unused parameters. */, - "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, - "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, - "noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */, - - /* Module Resolution Options */ - "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - "inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */, - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "skipLibCheck": true /* Skip type checking of declaration files. */, - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ - }, - "include": ["src/**/*"] + "target": "ES2022", + "module": "node16", + "lib": ["ES2022"], + "declaration": true, + "sourceMap": true, + "outDir": "dist", + "rootDir": "src", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true + } } diff --git a/tsconfig.module.json b/tsconfig.module.json deleted file mode 100644 index 2c7cfe2..0000000 --- a/tsconfig.module.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "es2015", - "outDir": "dist.module/" - } -}