Skip to content

Commit

Permalink
Merge pull request #230 from jacob-alford/ab-imports
Browse files Browse the repository at this point in the history
Chore: fix esm build process and dts errors
  • Loading branch information
jacob-alford authored Jan 7, 2023
2 parents 0ab5162 + 775e801 commit 27ed73d
Show file tree
Hide file tree
Showing 229 changed files with 751 additions and 883 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
uses: actions/checkout@v2.3.1
- name: Install
run: yarn install
- name: Build
run: yarn run build:pack
- name: Generate docs
run: yarn run docs
- name: Deploy
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<br>
<div align="center">
<img src="./assets/the-school-of-athens-crop-2.jpg" style="margin-top: 48px; width: 100%; max-width: 846px; border: 5px solid rgba(205,127,50,0.5); filter: drop-shadow(0 0 0.5rem rgba(0,0,0,0.5));"/>
</div>

<br><br>
<h1 align="center" style="margin: 12px 0px 12px 0px; padding-bottom: 12px;">
schemata-ts
</h1>
Expand All @@ -12,14 +13,14 @@ Write domain types once. A collection of Schemata inspired by io-ts-types and v

<div align="center">

![Build Status](https://github.com/jacob-alford/schemata-ts/actions/workflows/build.yml/badge.svg)
[![NPM Version](https://badge.fury.io/js/schemata-ts.svg)](https://badge.fury.io/js/schemata-ts)
[![Coverage Status](https://coveralls.io/repos/github/jacob-alford/schemata-ts/badge.svg?branch=main)](https://coveralls.io/github/jacob-alford/schemata-ts?branch=main)
![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/schemata-ts)
![License](https://img.shields.io/github/license/jacob-alford/schemata-ts)

</div>

<br><br>

## Welcome

A schema is an expression of a type structure that can be used to generate typeclass instances from a single declaration. Typeclass instances can perform a variety of tasks, for instance `Decoder` can take a pesky `unknown` value and give you an Either in return where the success case abides by the `schema` that generated it. The example below constructs a `User` schema.
Expand Down
11 changes: 10 additions & 1 deletion docs-ts.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"exclude": ["src/internal/*", "src/schemables/**/*"]
"exclude": ["src/internal/*", "src/schemables/**/*"],
"theme": "just-the-docs/just-the-docs",
"compilerOptions": {
"noEmit": true,
"strict": true,
"paths": {
"schemata-ts": ["./src/index.ts"],
"schemata-ts/*": ["./src/*"]
}
}
}
4 changes: 3 additions & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
remote_theme: pmarsceill/just-the-docs
remote_theme: just-the-docs/just-the-docs

color_scheme: dark

# Enable or disable the site search
search_enabled: true
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ module.exports = {
statements: 100,
},
},
moduleNameMapper: {
'^schemata-ts$': '<rootDir>/src/index.ts',
'^schemata-ts/(.*)$': '<rootDir>/src/$1',
},
}
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "schemata-ts",
"version": "1.2.0",
"version": "1.2.1",
"description": "A collection of Schemata inspired by io-ts-types and validators.js",
"homepage": "https://jacob-alford.github.io/schemata-ts/",
"repository": {
Expand All @@ -14,11 +14,17 @@
"access": "public"
},
"main": "./dist/index.js",
"module": "./dist/esm/index.js",
"module": "./dist/esm/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/esm/index.mjs",
"types": "./dist/index.d.ts"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/esm/*.js"
"import": "./dist/esm/*.mjs",
"types": "./dist/*.d.ts"
}
},
"typesVersions": {
Expand All @@ -43,7 +49,7 @@
"clean": "rm -rf dist build",
"build": "tsc -b ./tsconfig.build.json",
"build:watch": "yarn build --watch",
"build:mjs": "babel build/esm --config-file ./.babel.esm.json --out-dir build/esm --out-file-extension .js --source-maps",
"build:mjs": "babel build/esm --config-file ./.babel.esm.json --out-dir build/mjs --out-file-extension .mjs --source-maps",
"build:cjs": "babel build/esm --config-file ./.babel.cjs.json --out-dir build/cjs --out-file-extension .js --source-maps",
"build:pack": "yarn build && yarn concurrently \"yarn build:cjs\" \"yarn build:mjs\" && yarn ts-node scripts/pack.ts",
"generate:schemables": "yarn ts-node scripts/generate-schemables.ts",
Expand Down Expand Up @@ -82,7 +88,7 @@
"colorette": "^2.0.19",
"concurrently": "^7.2.2",
"cspell": "^5.5.2",
"docs-ts": "^0.6.10",
"docs-ts": "^0.7.0",
"eslint": "^7.27.0",
"eslint-import-resolver-typescript": "^3.1.1",
"eslint-plugin-import": "^2.26.0",
Expand Down
17 changes: 10 additions & 7 deletions scripts/generate-schemables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ const makeSchemableExtContents: (
schemableExtHeaderComment,
makeDestructureImport(['URIS', 'URIS2'], 'fp-ts/HKT'),
makeDestructureImport(['Schemable1', 'Schemable2C'], 'io-ts/Schemable'),
makeDestructureImport(['Schemable2', 'SchemableHKT2'], './base/SchemableBase'),
makeDestructureImport(
['Schemable2', 'SchemableHKT2'],
'schemata-ts/base/SchemableBase',
),
...pipe(
schemables,
RA.map(([schemable, path]) =>
Expand Down Expand Up @@ -184,7 +187,7 @@ const makeInstanceTypeExport: (tc: SchemableTypeclasses) => ts.ExportDeclaration
true,
),
]),
_.createStringLiteral(`./base/${typeclassName}Base`),
_.createStringLiteral(`schemata-ts/base/${typeclassName}Base`),
undefined,
)

Expand Down Expand Up @@ -283,15 +286,15 @@ const makeSchemableInstanceModuleContents: (
return pipe(
[
moduleHeaderComment(module, sinceVersion),
makeModuleStarImport(accessor, `./base/${module}Base`),
makeDestructureImport([schemableInstance], './SchemableExt'),
makeDestructureImport(['interpret'], './SchemaExt'),
makeModuleStarImport(accessor, `schemata-ts/base/${module}Base`),
makeDestructureImport([schemableInstance], 'schemata-ts/SchemableExt'),
makeDestructureImport(['interpret'], 'schemata-ts/SchemaExt'),
...pipe(
schemables,
RA.map(([schemable]) =>
makeModuleStarImport(
schemable,
`./schemables/${schemable}/instances/${lowercaseModule}`,
`schemata-ts/schemables/${schemable}/instances/${lowercaseModule}`,
),
),
),
Expand Down Expand Up @@ -346,7 +349,7 @@ const getSchemables: Build<ReadonlyArray<Schemable>> = C =>
TE.map(
RA.map(fileName => {
const schemable = getSchemableName(fileName)
return tuple(schemable, `./schemables/${schemable}`)
return tuple(schemable, `schemata-ts/schemables/${schemable}`)
}),
),
)
Expand Down
10 changes: 5 additions & 5 deletions scripts/generate-schemata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const makeSchemableSchemaExport = ([
false,
),
]),
_.createStringLiteral(`./schemables/${nameWith}/instances/schema`),
_.createStringLiteral(`schemata-ts/schemables/${nameWith}/instances/schema`),
undefined,
)

Expand All @@ -93,7 +93,7 @@ const makeSchemaExport = (
true,
),
]),
_.createStringLiteral(`./schemata/${category}/${name}`),
_.createStringLiteral(`schemata-ts/schemata/${category}/${name}`),
undefined,
)

Expand All @@ -120,7 +120,7 @@ const typeUtilityReexports = _.createExportDeclaration(
true,
),
]),
_.createStringLiteral('./SchemaExt'),
_.createStringLiteral('schemata-ts/SchemaExt'),
undefined,
)

Expand Down Expand Up @@ -149,7 +149,7 @@ const makeSchemaExportsFile: (
undefined,
false,
undefined,
_.createStringLiteral('./base/SchemaBase'),
_.createStringLiteral('schemata-ts/base/SchemaBase'),
undefined,
),
_.createJSDocComment('schemables'),
Expand Down Expand Up @@ -227,7 +227,7 @@ const getSchemables: Build<ReadonlyArray<Schemable>> = C =>
TE.map(
RA.map(file => {
const schemable = getSchemableName(file)
return tuple(schemable, schemable.slice(4), `./schemables/${schemable}`)
return tuple(schemable, schemable.slice(4), `schemata-ts/schemables/${schemable}`)
}),
),
TE.chain(
Expand Down
18 changes: 9 additions & 9 deletions scripts/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export const copyPackageJson: Build<void> = C =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const clone = Object.assign({}, json as any, {
main: './index.js',
module: './_esm/index.js',
module: './_esm/index.mjs',
exports: {
'.': { import: './_esm/index.js', require: './index.js' },
'./*': { import: './_esm/*.js', require: './*.js' },
'.': {
import: './_esm/index.mjs',
require: './index.js',
types: './index.d.ts',
},
'./*': { import: './_esm/*.mjs', require: './*.js', types: './*.d.ts' },
},
publishConfig: {
access: 'public',
Expand Down Expand Up @@ -83,8 +87,7 @@ export const rewriteSourceMap: (
})
: v,
),
J.stringify,
E.mapLeft(E.toError),
E.tryCatchK(clone => JSON.stringify(clone, null, 2), E.toError),
)
}),
)
Expand All @@ -106,16 +109,13 @@ export const copyBuildFiles: Build<void> = C =>

/* Copy build/esm to dist/_esm */
TE.chain(() => C.mkdir('./dist/_esm')),
TE.chain(() => C.exec('cp -r ./build/esm/* ./dist/_esm')),
TE.chain(() => C.exec('cp -r ./build/mjs/* ./dist/_esm')),

/* Copy build/cjs to dist */
TE.chain(() => C.exec('cp -r ./build/cjs/* ./dist')),

/* Copy types to dist */
TE.chain(() => C.exec('cp -r ./build/dts/* ./dist')),

/* Copy docs to dist/docs */
TE.chain(() => C.exec('cp -r ./docs ./dist/docs')),
)

export const overwriteSourceMaps: Build<void> = C =>
Expand Down
38 changes: 19 additions & 19 deletions src/Arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
*
* @since 1.0.0
*/
import * as Arb from './base/ArbitraryBase'
import { SchemableExt1 } from './SchemableExt'
import * as WithAnnotate from './schemables/WithAnnotate/instances/arbitrary'
import * as WithBrand from './schemables/WithBrand/instances/arbitrary'
import * as WithCheckDigit from './schemables/WithCheckDigit/instances/arbitrary'
import * as WithDate from './schemables/WithDate/instances/arbitrary'
import * as WithFloat from './schemables/WithFloat/instances/arbitrary'
import * as WithInt from './schemables/WithInt/instances/arbitrary'
import * as WithInvariant from './schemables/WithInvariant/instances/arbitrary'
import * as WithJson from './schemables/WithJson/instances/arbitrary'
import * as WithMap from './schemables/WithMap/instances/arbitrary'
import * as WithOption from './schemables/WithOption/instances/arbitrary'
import * as WithOptional from './schemables/WithOptional/instances/arbitrary'
import * as WithPadding from './schemables/WithPadding/instances/arbitrary'
import * as WithPattern from './schemables/WithPattern/instances/arbitrary'
import * as WithRefine from './schemables/WithRefine/instances/arbitrary'
import * as WithUnknownContainers from './schemables/WithUnknownContainers/instances/arbitrary'
import { interpret } from './SchemaExt'
import * as Arb from 'schemata-ts/base/ArbitraryBase'
import { SchemableExt1 } from 'schemata-ts/SchemableExt'
import * as WithAnnotate from 'schemata-ts/schemables/WithAnnotate/instances/arbitrary'
import * as WithBrand from 'schemata-ts/schemables/WithBrand/instances/arbitrary'
import * as WithCheckDigit from 'schemata-ts/schemables/WithCheckDigit/instances/arbitrary'
import * as WithDate from 'schemata-ts/schemables/WithDate/instances/arbitrary'
import * as WithFloat from 'schemata-ts/schemables/WithFloat/instances/arbitrary'
import * as WithInt from 'schemata-ts/schemables/WithInt/instances/arbitrary'
import * as WithInvariant from 'schemata-ts/schemables/WithInvariant/instances/arbitrary'
import * as WithJson from 'schemata-ts/schemables/WithJson/instances/arbitrary'
import * as WithMap from 'schemata-ts/schemables/WithMap/instances/arbitrary'
import * as WithOption from 'schemata-ts/schemables/WithOption/instances/arbitrary'
import * as WithOptional from 'schemata-ts/schemables/WithOptional/instances/arbitrary'
import * as WithPadding from 'schemata-ts/schemables/WithPadding/instances/arbitrary'
import * as WithPattern from 'schemata-ts/schemables/WithPattern/instances/arbitrary'
import * as WithRefine from 'schemata-ts/schemables/WithRefine/instances/arbitrary'
import * as WithUnknownContainers from 'schemata-ts/schemables/WithUnknownContainers/instances/arbitrary'
import { interpret } from 'schemata-ts/SchemaExt'
export type {
/**
* @since 1.0.0
* @category Model
*/
Arbitrary,
} from './base/ArbitraryBase'
} from 'schemata-ts/base/ArbitraryBase'

/**
* @since 1.0.0
Expand Down
12 changes: 6 additions & 6 deletions src/Codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@
* E.right(testUsers),
* )
*/
import { Decoder, getDecoder } from './Decoder'
import { Encoder, getEncoder } from './Encoder'
import { getGuard, Guard } from './Guard'
import { getJsonDeserializer, JsonDeserializer } from './JsonDeserializer'
import { getJsonSerializer, JsonSerializer } from './JsonSerializer'
import { SchemaExt } from './SchemaExt'
import { Decoder, getDecoder } from 'schemata-ts/Decoder'
import { Encoder, getEncoder } from 'schemata-ts/Encoder'
import { getGuard, Guard } from 'schemata-ts/Guard'
import { getJsonDeserializer, JsonDeserializer } from 'schemata-ts/JsonDeserializer'
import { getJsonSerializer, JsonSerializer } from 'schemata-ts/JsonSerializer'
import { SchemaExt } from 'schemata-ts/SchemaExt'

/**
* @since 1.0.1
Expand Down
38 changes: 19 additions & 19 deletions src/Decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
*
* @since 1.0.0
*/
import * as D from './base/DecoderBase'
import { SchemableExt2C } from './SchemableExt'
import * as WithAnnotate from './schemables/WithAnnotate/instances/decoder'
import * as WithBrand from './schemables/WithBrand/instances/decoder'
import * as WithCheckDigit from './schemables/WithCheckDigit/instances/decoder'
import * as WithDate from './schemables/WithDate/instances/decoder'
import * as WithFloat from './schemables/WithFloat/instances/decoder'
import * as WithInt from './schemables/WithInt/instances/decoder'
import * as WithInvariant from './schemables/WithInvariant/instances/decoder'
import * as WithJson from './schemables/WithJson/instances/decoder'
import * as WithMap from './schemables/WithMap/instances/decoder'
import * as WithOption from './schemables/WithOption/instances/decoder'
import * as WithOptional from './schemables/WithOptional/instances/decoder'
import * as WithPadding from './schemables/WithPadding/instances/decoder'
import * as WithPattern from './schemables/WithPattern/instances/decoder'
import * as WithRefine from './schemables/WithRefine/instances/decoder'
import * as WithUnknownContainers from './schemables/WithUnknownContainers/instances/decoder'
import { interpret } from './SchemaExt'
import * as D from 'schemata-ts/base/DecoderBase'
import { SchemableExt2C } from 'schemata-ts/SchemableExt'
import * as WithAnnotate from 'schemata-ts/schemables/WithAnnotate/instances/decoder'
import * as WithBrand from 'schemata-ts/schemables/WithBrand/instances/decoder'
import * as WithCheckDigit from 'schemata-ts/schemables/WithCheckDigit/instances/decoder'
import * as WithDate from 'schemata-ts/schemables/WithDate/instances/decoder'
import * as WithFloat from 'schemata-ts/schemables/WithFloat/instances/decoder'
import * as WithInt from 'schemata-ts/schemables/WithInt/instances/decoder'
import * as WithInvariant from 'schemata-ts/schemables/WithInvariant/instances/decoder'
import * as WithJson from 'schemata-ts/schemables/WithJson/instances/decoder'
import * as WithMap from 'schemata-ts/schemables/WithMap/instances/decoder'
import * as WithOption from 'schemata-ts/schemables/WithOption/instances/decoder'
import * as WithOptional from 'schemata-ts/schemables/WithOptional/instances/decoder'
import * as WithPadding from 'schemata-ts/schemables/WithPadding/instances/decoder'
import * as WithPattern from 'schemata-ts/schemables/WithPattern/instances/decoder'
import * as WithRefine from 'schemata-ts/schemables/WithRefine/instances/decoder'
import * as WithUnknownContainers from 'schemata-ts/schemables/WithUnknownContainers/instances/decoder'
import { interpret } from 'schemata-ts/SchemaExt'
export type {
/**
* @since 1.0.0
* @category Model
*/
Decoder,
} from './base/DecoderBase'
} from 'schemata-ts/base/DecoderBase'

/**
* @since 1.0.0
Expand Down
Loading

0 comments on commit 27ed73d

Please sign in to comment.