Skip to content

Commit e3cb42a

Browse files
committed
migration to ESM
1 parent d59e1af commit e3cb42a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+139
-137
lines changed

.mocharc.js renamed to .mocharc.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ require("tsconfig-paths/register");
55

66
module.exports = {
77
diff: true,
8-
extension: ['ts'],
8+
extension: ['mts'],
99
package: '../package.json',
1010
timeout: 10000,
11+
12+
"node-option": [
13+
"loader=ts-node/esm",
14+
],
1115
};

example/webpack-example/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
4545
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
4646
"paths": {
47-
"@msgpack/msgpack": ["../../"]
47+
"@msgpack/msgpack": ["../../index.mjs"]
4848
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4949
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
5050
// "typeRoots": [], /* List of folders to include type definitions from. */

karma.conf.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// import * as path from "path";
12
const path = require("path");
23
// const webpack = require("webpack");
34

45
// eslint-disable-next-line import/no-default-export
5-
export default function configure(config: any) {
6+
module.exports = function configure(config: any) {
67
config.set({
78
customLaunchers: {
89
// To debug it wih IE11,
@@ -18,10 +19,10 @@ export default function configure(config: any) {
1819

1920
basePath: "",
2021
frameworks: ["mocha"],
21-
files: ["./test/karma-run.ts"],
22+
files: ["./test/karma-run.mts"],
2223
exclude: [],
2324
preprocessors: {
24-
"**/*.ts": ["webpack", "sourcemap"],
25+
"**/*.mts": ["webpack", "sourcemap"],
2526
},
2627
reporters: ["dots"],
2728
port: 9876,
@@ -36,7 +37,7 @@ export default function configure(config: any) {
3637
mode: "production",
3738

3839
resolve: {
39-
extensions: [".ts", ".tsx", ".mjs", ".js", ".json", ".wasm"],
40+
extensions: [".ts", ".tsx", ".mts", ".mjs", ".js", ".json", ".wasm"],
4041
alias: {
4142
"@msgpack/msgpack": path.resolve(__dirname, "src"),
4243
},
@@ -64,7 +65,7 @@ export default function configure(config: any) {
6465
devtool: "inline-source-map",
6566
},
6667
mime: {
67-
"text/x-typescript": ["ts", "tsx"],
68+
"text/x-typescript": ["ts", "tsx", "mts"],
6869
},
6970
client: {
7071
mocha: {

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"description": "MessagePack for ECMA-262/JavaScript/TypeScript",
55
"author": "The MessagePack community",
66
"license": "ISC",
7+
"type": "module",
8+
"exports": {
9+
"import": "./dist.es5+esm/index.mjs",
10+
"require": "./dist/index.js"
11+
},
712
"main": "./dist/index.js",
813
"module": "./dist.es5+esm/index.mjs",
914
"cdn": "./dist.es5+umd/msgpack.min.js",
@@ -12,12 +17,12 @@
1217
"sideEffects": false,
1318
"scripts": {
1419
"build": "npm publish --dry-run",
15-
"prepare": "npm run clean && webpack --bail && tsc --build tsconfig.dist.json tsconfig.dist.es5+esm.json && ts-node tools/esmify.ts dist.es5+esm/*.js dist.es5+esm/*/*.js",
20+
"prepare": "npm run clean && webpack --bail && tsc --build tsconfig.dist.json tsconfig.dist.es5+esm.json",
1621
"prepublishOnly": "run-p 'test:dist:*' && npm run test:browser",
1722
"clean": "rimraf build dist dist.*",
18-
"test": "mocha 'test/**/*.test.ts'",
19-
"test:purejs": "TEXT_ENCODING=never mocha 'test/**/*.test.ts'",
20-
"test:te": "TEXT_ENCODING=force mocha 'test/**/*.test.ts'",
23+
"test": "mocha 'test/**/*.test.mts'",
24+
"test:purejs": "TEXT_ENCODING=never mocha 'test/**/*.test.mts'",
25+
"test:te": "TEXT_ENCODING=force mocha 'test/**/*.test.mts'",
2126
"test:dist:purejs": "TS_NODE_PROJECT=tsconfig.test-dist-es5-purejs.json npm run test:purejs -- --reporter=dot",
2227
"test:cover": "npm run cover:clean && npm-run-all 'test:cover:*' && npm run cover:report",
2328
"test:cover:purejs": "npx nyc --no-clean npm run test:purejs",
@@ -30,9 +35,9 @@
3035
"test:browser:firefox": "karma start --single-run --browsers FirefoxHeadless",
3136
"test:browser:chrome": "karma start --single-run --browsers ChromeHeadless",
3237
"test:watch:browser": "karma start --browsers ChromeHeadless,FirefoxHeadless",
33-
"test:watch:nodejs": "mocha -w 'test/**/*.test.ts'",
34-
"lint": "eslint --ext .ts src test",
35-
"lint:fix": "prettier --loglevel=warn --write 'src/**/*.ts' 'test/**/*.ts' && eslint --fix --ext .ts src test",
38+
"test:watch:nodejs": "mocha -w 'test/**/*.test.mts'",
39+
"lint": "eslint --ext .ts --ext .mts src test",
40+
"lint:fix": "prettier --loglevel=warn --write 'src/**/*.mts' 'test/**/*.mts' && eslint --fix --ext .ts --ext .mts src test",
3641
"lint:print-config": "eslint --print-config .eslintrc.js",
3742
"update-dependencies": "npx rimraf node_modules/ package-lock.json ; npm install ; npm audit fix --force ; git restore package.json ; npm install"
3843
},
@@ -51,7 +56,7 @@
5156
"universal"
5257
],
5358
"engines": {
54-
"node": ">= 10"
59+
"node": ">= 14"
5560
},
5661
"devDependencies": {
5762
"@bitjourney/check-es-version-webpack-plugin": "latest",

src/CachedKeyDecoder.ts renamed to src/CachedKeyDecoder.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { utf8DecodeJs } from "./utils/utf8";
1+
import { utf8DecodeJs } from "./utils/utf8.mjs";
22

33
const DEFAULT_MAX_KEY_LENGTH = 16;
44
const DEFAULT_MAX_LENGTH_PER_KEY = 16;
File renamed without changes.

src/Decoder.ts renamed to src/Decoder.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { prettyByte } from "./utils/prettyByte";
2-
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec";
3-
import { getInt64, getUint64, UINT32_MAX } from "./utils/int";
4-
import { utf8DecodeJs, TEXT_DECODER_THRESHOLD, utf8DecodeTD } from "./utils/utf8";
5-
import { createDataView, ensureUint8Array } from "./utils/typedArrays";
6-
import { CachedKeyDecoder, KeyDecoder } from "./CachedKeyDecoder";
7-
import { DecodeError } from "./DecodeError";
1+
import { prettyByte } from "./utils/prettyByte.mjs";
2+
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec.mjs";
3+
import { getInt64, getUint64, UINT32_MAX } from "./utils/int.mjs";
4+
import { utf8DecodeJs, TEXT_DECODER_THRESHOLD, utf8DecodeTD } from "./utils/utf8.mjs";
5+
import { createDataView, ensureUint8Array } from "./utils/typedArrays.mjs";
6+
import { CachedKeyDecoder, KeyDecoder } from "./CachedKeyDecoder.mjs";
7+
import { DecodeError } from "./DecodeError.mjs";
88

99
const STATE_ARRAY = "array";
1010
const STATE_MAP_KEY = "map_key";

src/Encoder.ts renamed to src/Encoder.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { utf8EncodeJs, utf8Count, TEXT_ENCODER_THRESHOLD, utf8EncodeTE } from "./utils/utf8";
2-
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec";
3-
import { setInt64, setUint64 } from "./utils/int";
4-
import { ensureUint8Array } from "./utils/typedArrays";
5-
import type { ExtData } from "./ExtData";
1+
import { utf8EncodeJs, utf8Count, TEXT_ENCODER_THRESHOLD, utf8EncodeTE } from "./utils/utf8.mjs";
2+
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec.mjs";
3+
import { setInt64, setUint64 } from "./utils/int.mjs";
4+
import { ensureUint8Array } from "./utils/typedArrays.mjs";
5+
import type { ExtData } from "./ExtData.mjs";
66

77
export const DEFAULT_MAX_DEPTH = 100;
88
export const DEFAULT_INITIAL_BUFFER_SIZE = 2048;
File renamed without changes.

src/ExtensionCodec.ts renamed to src/ExtensionCodec.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ExtensionCodec to handle MessagePack extensions
22

3-
import { ExtData } from "./ExtData";
4-
import { timestampExtension } from "./timestamp";
3+
import { ExtData } from "./ExtData.mjs";
4+
import { timestampExtension } from "./timestamp.mjs";
55

66
export type ExtensionDecoderType<ContextType> = (
77
data: Uint8Array,

0 commit comments

Comments
 (0)