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

feat!: make SuperJSON esm-only #263

Merged
merged 5 commits into from
Oct 11, 2023
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
File renamed without changes.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:

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

env:
CI: true
Expand Down Expand Up @@ -36,8 +36,8 @@ jobs:
run: yarn lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2

run: yarn test
- name: Build
run: yarn build

Expand Down
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
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"version": "1.13.3",
"version": "1.13.4-0",
"license": "MIT",
"main": "dist/index.js",
"type": "module",
"typings": "dist/index.d.ts",
"module": "dist/esm/index.js",
"exports": {
".": "./dist/index.js"
},
"files": [
"dist",
"src"
"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",
"test": "tsdx test --notify --verbose",
"build": "tsc",
"test": "vitest run",
"lint": "tsdx lint",
"prepack": "yarn build",
"prepare": "husky install",
Expand Down Expand Up @@ -66,15 +65,14 @@
"mongodb": "^3.6.6",
"publish-please": "^5.5.2",
"tsdx": "^0.14.1",
"typescript": "^4.2.4"
"typescript": "^4.2.4",
"vitest": "^0.34.6"
},
"dependencies": {
"copy-anything": "^3.0.2"
},
"resolutions": {
"**/@typescript-eslint/eslint-plugin": "^4.11.1",
"**/@typescript-eslint/parser": "^4.11.1",
"**/jest": "^26.6.3",
"**/ts-jest": "^26.4.4"
"**/@typescript-eslint/parser": "^4.11.1"
}
}
4 changes: 3 additions & 1 deletion src/accessDeep.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { setDeep } from './accessDeep';
import { setDeep } from './accessDeep.js';

import { describe, it, expect } from 'vitest';

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
20 changes: 11 additions & 9 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

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';

import { describe, it, expect, test } from 'vitest';

const isNode10 = process.version.indexOf('v10') === 0;

describe('stringify & parse', () => {
Expand Down Expand Up @@ -1147,9 +1149,9 @@ test('regression #245: superjson referential equalities only use the top-most pa
// saying that a.children is equal to b.children is redundant since its already know that a === b
expect(res.meta?.referentialEqualities).not.toHaveProperty(['a.children']);
expect(res.meta).toMatchInlineSnapshot(`
Object {
"referentialEqualities": Object {
"a": Array [
{
"referentialEqualities": {
"a": [
"b",
],
},
Expand Down Expand Up @@ -1185,9 +1187,9 @@ test('dedupe=true', () => {
expect(json.b).toBeNull();

expect(json).toMatchInlineSnapshot(`
Object {
"a": Object {
"children": Array [],
{
"a": {
"children": [],
},
"b": null,
}
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
4 changes: 3 additions & 1 deletion src/is.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
isPlainObject,
isTypedArray,
isURL,
} from './is';
} from './is.js';

import { test, expect } from 'vitest';

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

import { test, describe, it, expect } from 'vitest';

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

import { test, expect } from 'vitest';

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
6 changes: 4 additions & 2 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Registry } from './registry';
import { Class } from './types';
import { Registry } from './registry.js';
import { Class } from './types.js';

import { test, expect } from 'vitest';

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
Loading
Loading