Skip to content

Commit

Permalink
feat: improve ESM output
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Apr 6, 2022
1 parent 699357c commit 8f026f3
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 64 deletions.
12 changes: 8 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ module.exports = {
// A set of global variables that need to be available in all test environments
globals: {
"ts-jest": {
useESM: true,
diagnostics: false,
},
},

// extensionsToTreatAsEsm: [".ts", ".tsx"],

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
Expand All @@ -75,7 +78,9 @@ module.exports = {
moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx", "node", "svelte"],

// A map from regular expressions to module names that allow to stub out resources with a single module
// moduleNameMapper: {},
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
Expand All @@ -87,7 +92,7 @@ module.exports = {
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: "ts-jest",
preset: "ts-jest/presets/default-esm",

// Run tests from one or more projects
// projects: null,
Expand Down Expand Up @@ -161,8 +166,7 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
"^.+\\.ts$": "ts-jest",
"^.+\\.tsx$": "ts-jest",
"^.+\\.tsx?$": "ts-jest",
"^.+\\.svelte$": [
"svelte-jester",
{
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
},
"files": [
"src",
"dist"
],
"scripts": {
Expand All @@ -48,7 +49,7 @@
"@semantic-release/github": "^8.0.4",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.3",
"@testing-library/svelte": "^3.0.3",
"@testing-library/svelte": "^3.1.0",
"@types/jest": "^27.4.0",
"@types/lodash.flatten": "^4.4.6",
"@types/lodash.isfunction": "^3.0.6",
Expand All @@ -75,7 +76,7 @@
"svelte-jester": "^2.3.2",
"ts-jest": "^27.0.7",
"typescript": "^4.6.2",
"svelte-preprocess": "^4.10.4",
"svelte-preprocess": "^4.10.5",
"svelte": "^3.46"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StateTransition } from "./state"
import { StateTransition } from "./state.js"

export class History<
T extends StateTransition<any, any, any> = StateTransition<any, any, any>,
Expand Down
15 changes: 8 additions & 7 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* eslint-disable @typescript-eslint/no-use-before-define, @typescript-eslint/no-misused-promises */
import { Task } from "@tdreyno/pretty-please"
import { Action, enter, exit, isAction } from "./action"
import { Context } from "./context"
import { __internalEffect, Effect, isEffect, log } from "./effect"
import { Action, enter, exit, isAction } from "./action.js"
import { Effect, __internalEffect, isEffect, log } from "./effect.js"
import { ExecuteResult, executeResultfromTask } from "./execute-result.js"
import {
MissingCurrentState,
StateDidNotRespondToAction,
UnknownStateReturnType,
} from "./errors"
import { isStateTransition, StateReturn, StateTransition } from "./state"
import { ExecuteResult, executeResultfromTask } from "./execute-result"
import { arraySingleton } from "./util"
import { StateReturn, StateTransition, isStateTransition } from "./state.js"

import { Context } from "./context.js"
import { Task } from "@tdreyno/pretty-please"
import { arraySingleton } from "./util.js"

const enterState = (
context: Context,
Expand Down
5 changes: 3 additions & 2 deletions src/effect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Subscription, Task } from "@tdreyno/pretty-please"
import { Action } from "./action"
import { Context } from "./context"

import { Action } from "./action.js"
import { Context } from "./context.js"

export interface Effect<T = any> {
label: string
Expand Down
4 changes: 2 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action } from "./action"
import { StateTransition } from "./state"
import { Action } from "./action.js"
import { StateTransition } from "./state.js"

export class StateDidNotRespondToAction extends Error {
constructor(
Expand Down
6 changes: 3 additions & 3 deletions src/execute-result.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Effect } from "./effect.js"
import { StateReturn } from "./state.js"
import { Task } from "@tdreyno/pretty-please"
import { Effect } from "./effect"
import { StateReturn } from "./state"
import { arraySingleton } from "./util"
import { arraySingleton } from "./util.js"

class ExecuteResult_ {
constructor(
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from "./action"
export * from "./context"
export * from "./core"
export * from "./effect"
export * from "./errors"
export * from "./runtime"
export * from "./state"
export * from "./subscriptions"
export * from "./execute-result"
export * from "./action.js"
export * from "./context.js"
export * from "./core.js"
export * from "./effect.js"
export * from "./errors.js"
export * from "./runtime.js"
export * from "./state.js"
export * from "./subscriptions.js"
export * from "./execute-result.js"
export { Task } from "@tdreyno/pretty-please"
13 changes: 7 additions & 6 deletions src/react/createFizzContext.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import isFunction from "lodash.isfunction"
import { Action, enter } from "../action.js"
import { BoundStateFn, StateTransition, stateWrapper } from "../state.js"
import { Context, createInitialContext } from "../context.js"
import React, {
ReactNode,
useContext,
useEffect,
useMemo,
useState,
} from "react"
import { Action, enter } from "../action"
import { Context, createInitialContext } from "../context"
import { noop } from "../effect"
import { createRuntime, Runtime } from "../runtime"
import { BoundStateFn, stateWrapper, StateTransition } from "../state"
import { Runtime, createRuntime } from "../runtime.js"

import isFunction from "lodash.isfunction"
import { noop } from "../effect.js"

export interface CreateProps<
SM extends { [key: string]: BoundStateFn<any, any, any> },
Expand Down
2 changes: 1 addition & 1 deletion src/react/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./createFizzContext"
export * from "./createFizzContext.js"
20 changes: 12 additions & 8 deletions src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Action, isAction } from "./action.js"
import { BoundStateFn, StateTransition } from "./state.js"
import { ExecuteResult, executeResultfromTask } from "./execute-result.js"
import { ExternalTask, Subscription, Task } from "@tdreyno/pretty-please"
import { Action, isAction } from "./action"
import { Context } from "./context"
import { execute, processStateReturn, runEffects } from "./core"
import { Effect } from "./effect"
import { NoStatesRespondToAction, StateDidNotRespondToAction } from "./errors"
import { ExecuteResult, executeResultfromTask } from "./execute-result"
import { BoundStateFn, StateTransition } from "./state"
import { isNotEmpty } from "./util"
import {
NoStatesRespondToAction,
StateDidNotRespondToAction,
} from "./errors.js"
import { execute, processStateReturn, runEffects } from "./core.js"

import { Context } from "./context.js"
import { Effect } from "./effect.js"
import { isNotEmpty } from "./util.js"

type ContextChangeSubscriber = (context: Context) => void

Expand Down
5 changes: 3 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Action, ActionName, ActionPayload } from "./action.js"

import { Effect } from "./effect.js"
import { Task } from "@tdreyno/pretty-please"
import isPlainObject from "lodash.isplainobject"
import mapValues from "lodash.mapvalues"
import { Action, ActionName, ActionPayload } from "./action"
import { Effect } from "./effect"

/**
* States can return either:
Expand Down
4 changes: 3 additions & 1 deletion src/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Action, onFrame } from "./action.js"

import { Subscription } from "@tdreyno/pretty-please"
import { Action, onFrame } from "./action"

export { Subscription }

export const onFrameSubscription = <A extends Action<any, any>>(
Expand Down
8 changes: 4 additions & 4 deletions src/svelte/createMachine.tsx → src/svelte/createMachine.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Action, enter } from "../action.js"
import { BoundStateFn, StateTransition } from "../state.js"
import { Context, createInitialContext } from "../context.js"
import { Readable, readable } from "svelte/store"
import { Action, enter } from "../action"
import { Context, createInitialContext } from "../context"
import { createRuntime, Runtime } from "../runtime"
import { BoundStateFn, StateTransition } from "../state"
import { Runtime, createRuntime } from "../runtime.js"

export interface ContextValue<
SM extends { [key: string]: BoundStateFn<any, any, any> },
Expand Down
2 changes: 1 addition & 1 deletion src/svelte/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./createMachine"
export * from "./createMachine.js"
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
"noEmit": false,
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"rootDir": "./src",
"outDir": "./dist/esm",
"resolveJsonModule": true
"outDir": "./dist/esm"
},
"include": ["./src"],
"exclude": ["build", "dist", "node_modules"]
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,10 @@
"@testing-library/dom" "^8.0.0"
"@types/react-dom" "*"

"@testing-library/svelte@^3.0.3":
version "3.0.3"
resolved "https://registry.npmjs.org/@testing-library/svelte/-/svelte-3.0.3.tgz"
integrity sha512-GxafAllShGM2nkntFGURZ7fYVlUYwv7K62lqv1aFqtTYzzeZ2Cu8zTVhtE/Qt3bk2zMl6+FPKP03wjLip/G8mA==
"@testing-library/svelte@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@testing-library/svelte/-/svelte-3.1.0.tgz#57dff119fe2a4776873990fd0331e83a0599916c"
integrity sha512-xTN6v4xRLQb75GTJn2mrjSUJN4PkhpNZFjwvtdzbOTS6OvxMrkRdm6hFRGauwiFd0LPV7/SqdWbbtMAOC7a+Dg==
dependencies:
"@testing-library/dom" "^7.0.3"

Expand Down Expand Up @@ -6388,10 +6388,10 @@ svelte-jester@^2.3.2:
resolved "https://registry.yarnpkg.com/svelte-jester/-/svelte-jester-2.3.2.tgz#9eb818da30807bbcc940b6130d15b2c34408d64f"
integrity sha512-JtxSz4FWAaCRBXbPsh4LcDs4Ua7zdXgLC0TZvT1R56hRV0dymmNP+abw67DTPF7sQPyNxWsOKd0Sl7Q8SnP8kg==

svelte-preprocess@^4.10.4:
version "4.10.4"
resolved "https://registry.yarnpkg.com/svelte-preprocess/-/svelte-preprocess-4.10.4.tgz#308a410266bfc55b4e608da8d552b63580141260"
integrity sha512-fuwol0N4UoHsNQolLFbMqWivqcJ9N0vfWO9IuPAiX/5okfoGXURyJ6nECbuEIv0nU3M8Xe2I1ONNje2buk7l6A==
svelte-preprocess@^4.10.5:
version "4.10.5"
resolved "https://registry.yarnpkg.com/svelte-preprocess/-/svelte-preprocess-4.10.5.tgz#c4d20fd67b92559e5cac80281154c813c1c17353"
integrity sha512-VKXPRScCzAZqeBZOGq4LLwtNrAu++mVn7XvQox3eFDV7Ciq0Lg70Q8QWjH9iXF7J+pMlXhPsSFwpCb2E+hoeyA==
dependencies:
"@types/pug" "^2.0.4"
"@types/sass" "^1.16.0"
Expand Down

0 comments on commit 8f026f3

Please sign in to comment.