Skip to content

Commit

Permalink
feat!: make SuperJSON esm-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Oct 11, 2023
1 parent aa68fa8 commit 7c4402d
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 48 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Benchmark = require('benchmark');
const SuperJSON = require('./dist/').default;
import Benchmark from "benchmark"
import SuperJSON from "./dist/index.js"

const instances = {
'toy example': {
Expand Down
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{
"version": "1.13.3",
"license": "MIT",
"main": "dist/index.js",
"type": "module",
"typings": "dist/index.d.ts",
"module": "dist/esm/index.js",
"files": [
"dist",
"src"
],
"exports": {
".": "./dist/index.js"
},
"files": ["dist"],
"engines": {
"node": ">=10"
"node": ">=16"
},
"scripts": {
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc",
"build:esm": "tsc --module es2015 --outDir dist/esm",
"build": "tsc",
"test": "tsdx test --notify --verbose",
"lint": "tsdx lint",
"prepack": "yarn build",
Expand Down
2 changes: 1 addition & 1 deletion src/accessDeep.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setDeep } from './accessDeep';
import { setDeep } from './accessDeep.js';

describe('setDeep', () => {
it('correctly sets values in maps', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/accessDeep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isMap, isArray, isPlainObject, isSet } from './is';
import { includes } from './util';
import { isMap, isArray, isPlainObject, isSet } from './is.js';
import { includes } from './util.js';

const getNthKey = (value: Map<any, any> | Set<any>, n: number): any => {
const keys = value.keys();
Expand Down
4 changes: 2 additions & 2 deletions src/class-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Registry } from './registry';
import { Class } from './types';
import { Registry } from './registry.js';
import { Class } from './types.js';

export interface RegisterOptions {
identifier?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/custom-transformer-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSONValue } from './types';
import { find } from './util';
import { JSONValue } from './types.js';
import { find } from './util.js';

export interface CustomTransfomer<I, O extends JSONValue> {
name: string;
Expand Down
6 changes: 3 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import * as fs from 'fs';

import SuperJSON from './';
import { JSONValue, SuperJSONResult, SuperJSONValue } from './types';
import SuperJSON from './index.js';
import { JSONValue, SuperJSONResult, SuperJSONValue } from './types.js';
import {
isArray,
isMap,
isPlainObject,
isPrimitive,
isSet,
isTypedArray,
} from './is';
} from './is.js';

import { ObjectID } from 'mongodb';
import { Decimal } from 'decimal.js';
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types';
import { ClassRegistry, RegisterOptions } from './class-registry';
import { Registry } from './registry';
import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types.js';
import { ClassRegistry, RegisterOptions } from './class-registry.js';
import { Registry } from './registry.js';
import {
CustomTransfomer,
CustomTransformerRegistry,
} from './custom-transformer-registry';
} from './custom-transformer-registry.js';
import {
applyReferentialEqualityAnnotations,
applyValueAnnotations,
generateReferentialEqualityAnnotations,
walker,
} from './plainer';
} from './plainer.js';
import { copy } from 'copy-anything';

export default class SuperJSON {
Expand Down
2 changes: 1 addition & 1 deletion src/is.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
isPlainObject,
isTypedArray,
isURL,
} from './is';
} from './is.js';

test('Basic true tests', () => {
expect(isUndefined(undefined)).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion src/pathstringifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parsePath, escapeKey } from './pathstringifier';
import { parsePath, escapeKey } from './pathstringifier.js';

describe('parsePath', () => {
it.each([
Expand Down
4 changes: 2 additions & 2 deletions src/plainer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SuperJSON from '.';
import { walker } from './plainer';
import SuperJSON from './index.js';
import { walker } from './plainer.js';

test('walker', () => {
expect(
Expand Down
14 changes: 7 additions & 7 deletions src/plainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import {
isPlainObject,
isPrimitive,
isSet,
} from './is';
import { escapeKey, stringifyPath } from './pathstringifier';
} from './is.js';
import { escapeKey, stringifyPath } from './pathstringifier.js';
import {
isInstanceOfRegisteredClass,
transformValue,
TypeAnnotation,
untransformValue,
} from './transformer';
import { includes, forEach } from './util';
import { parsePath } from './pathstringifier';
import { getDeep, setDeep } from './accessDeep';
import SuperJSON from '.';
} from './transformer.js';
import { includes, forEach } from './util.js';
import { parsePath } from './pathstringifier.js';
import { getDeep, setDeep } from './accessDeep.js';
import SuperJSON from './index.js';

type Tree<T> = InnerNode<T> | Leaf<T>;
type Leaf<T> = [T];
Expand Down
4 changes: 2 additions & 2 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Registry } from './registry';
import { Class } from './types';
import { Registry } from './registry.js';
import { Class } from './types.js';

test('class registry', () => {
const registry = new Registry<Class>(c => c.name);
Expand Down
2 changes: 1 addition & 1 deletion src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DoubleIndexedKV } from './double-indexed-kv';
import { DoubleIndexedKV } from './double-indexed-kv.js';

export class Registry<T> {
private kv = new DoubleIndexedKV<string, T>();
Expand Down
6 changes: 3 additions & 3 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
isTypedArray,
TypedArrayConstructor,
isURL,
} from './is';
import { findArr } from './util';
import SuperJSON from '.';
} from './is.js';
import { findArr } from './util.js';
import SuperJSON from './index.js';

export type PrimitiveTypeAnnotation = 'number' | 'undefined' | 'bigint';

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TypeAnnotation } from './transformer';
import { MinimisedTree, ReferentialEqualityAnnotations } from './plainer';
import { TypeAnnotation } from './transformer.js';
import { MinimisedTree, ReferentialEqualityAnnotations } from './plainer.js';

export type Class = { new (...args: any[]): any };

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"include": ["src"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"compilerOptions": {
"module": "CommonJS",
"module": "ES6",
"moduleResolution": "node",
"lib": ["esnext"],
"importHelpers": false,
"declaration": true,
Expand All @@ -14,7 +15,6 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"esModuleInterop": true,
"downlevelIteration": true
}
Expand Down

0 comments on commit 7c4402d

Please sign in to comment.