1
Fork 0

typescript(option): chore: fixed build process

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-22 17:38:10 +02:00 committed by prescientmoon
parent 906096a5cb
commit 6f93885507
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
6 changed files with 1132 additions and 153 deletions

View file

@ -3,8 +3,8 @@
"version": "0.0.0-development", "version": "0.0.0-development",
"description": "Typescript version of fsharps Option module", "description": "Typescript version of fsharps Option module",
"main": "dist/bundle.cjs.js", "main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js", "module": "dist/index.esm.js",
"typings": "dist/index.d.ts", "typings": "dist/index.esm.d.ts",
"scripts": { "scripts": {
"prebuild": "rimraf dist", "prebuild": "rimraf dist",
"build": "rollup -c rollup.config.ts" "build": "rollup -c rollup.config.ts"
@ -24,15 +24,15 @@
], ],
"sideEffects": false, "sideEffects": false,
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-node-resolve": "^6.0.0", "@rollup/plugin-node-resolve": "^6.0.0",
"@types/node": "^12.12.21",
"@wessberg/rollup-plugin-ts": "^1.1.83",
"rimraf": "^3.0.0", "rimraf": "^3.0.0",
"rollup": "^1.27.13", "rollup": "^1.27.13",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-dts": "^1.1.13",
"rollup-plugin-terser": "^5.1.3", "rollup-plugin-terser": "^5.1.3",
"rollup-plugin-typescript2": "^0.25.3", "semantic-release": "^15.14.0",
"semantic-release": "^15.13.31", "typescript": "^3.7.4"
"typescript": "^3.7.3"
}, },
"author": "Matei Adriel", "author": "Matei Adriel",
"license": "SEE LICENSE IN LICENSE" "license": "SEE LICENSE IN LICENSE"

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,6 @@
import commonjs from 'rollup-plugin-commonjs'
import nodeResolve from '@rollup/plugin-node-resolve'
import dts from 'rollup-plugin-dts'
import typescript from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser' import { terser } from 'rollup-plugin-terser'
import { resolve } from 'path' import { resolve } from 'path'
import ts from '@wessberg/rollup-plugin-ts'
const outputDirectory = resolve(__dirname, 'dist') const outputDirectory = resolve(__dirname, 'dist')
const inputFile = resolve(__dirname, 'src/index.ts') const inputFile = resolve(__dirname, 'src/index.ts')
@ -19,36 +16,36 @@ export default [
external, external,
output: [ output: [
{ {
file: `${outputDirectory}/bundle.cjs.js`, file: `${outputDirectory}/index.cjs.js`,
format: 'cjs', format: 'cjs',
sourcemap: true sourcemap: true
}, },
{ {
file: `${outputDirectory}/bundle.esm.js`, file: `${outputDirectory}/index.amd.js`,
format: 'esm',
sourcemap: true
},
{
file: `${outputDirectory}/bundle.amd.js`,
sourcemap: true, sourcemap: true,
format: 'amd', format: 'amd',
name: 'Option' name: 'Option'
} }
], ],
plugins: [ plugins: [ts(), !dev && terser()]
nodeResolve({
extensions: ['.ts']
}),
commonjs(),
typescript({
tsconfig: resolve(__dirname, 'tsconfig.json')
}),
!dev && terser()
]
}, },
{ {
input: inputFile, input: inputFile,
output: [{ file: `${outputDirectory}/index.d.ts`, format: 'es' }], external,
plugins: [dts()] output: [
{
file: `${outputDirectory}/index.esm.js`,
format: 'esm',
sourcemap: true
}
],
plugins: [
ts({
tsconfig: {
declaration: true
}
}),
!dev && terser()
]
} }
] ]

View file

@ -10,18 +10,16 @@ import {
import { identity } from './internalHelperts' import { identity } from './internalHelperts'
import { none, some } from './internals' import { none, some } from './internals'
export const isSome = <T>(option: Option<T>): option is Some<T> => export const isSome = <T>(option: Option<T>) => option._type === some
option.type === some export const isNothing = <T>(option: Option<T>) => option._type === none
export const isNothing = <T>(option: Option<T>): option is None =>
option.type === none
const match = <T, U>( const match = <T, U>(
caseSome: Mapper<T, U>, caseSome: Mapper<T, U>,
_default: U, _default: U,
option: Option<T> option: Option<T>
) => { ) => {
if (isSome(option)) { if (option._type === some) {
return caseSome(option.value as T) return caseSome(option.value)
} }
return _default return _default
@ -72,7 +70,7 @@ export const forall = <T>(predicate: Predicate<T>, option: Option<T>) => {
} }
export const get = <T>(option: Option<T>): T => { export const get = <T>(option: Option<T>): T => {
if (isSome(option)) { if (option._type === some) {
return option.value return option.value
} }
@ -80,7 +78,7 @@ export const get = <T>(option: Option<T>): T => {
} }
export const iter = <T>(mapper: Mapper<T, void>, option: Option<T>) => { export const iter = <T>(mapper: Mapper<T, void>, option: Option<T>) => {
if (isSome(option)) { if (option._type === some) {
mapper(option.value) mapper(option.value)
} }
} }

View file

@ -1,7 +1,7 @@
export const some = Symbol('some') export const some = 'some'
export const none = Symbol('none') export const none = 'none'
export type NominalTyped<T, U> = { export type NominalTyped<T, U> = {
type: T _type: T
value: U value: U
} }

View file

@ -1,16 +1,16 @@
import { NominalTyped, none, some } from './internals' import { NominalTyped, none, some } from './internals'
export type None = NominalTyped<typeof none, null> export type None = NominalTyped<'none', null>
export type Some<T> = NominalTyped<typeof some, T> export type Some<T> = NominalTyped<'some', T>
export type Option<T> = Some<T> | None export type Option<T> = Some<T> | None
export const None: Option<any> = { export const None: Option<any> = {
type: none, _type: 'none',
value: null value: null
} }
export const Some = <T>(value: T): Option<T> => ({ export const Some = <T>(value: T): Option<T> => ({
type: some, _type: 'some',
value value
}) })