Skip to content

Commit

Permalink
build(typescript): add typescript and setup the build to build with t…
Browse files Browse the repository at this point in the history
…ypescript
  • Loading branch information
Rebecca Stevens committed Nov 12, 2020
1 parent 83491c1 commit bdb2204
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist/*
types/*
22 changes: 19 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
"readme.md"
],
"scripts": {
"build": "rollup -c",
"build": "rollup -c && npm run typedef",
"size": "npm run build && terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c",
"test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript",
"test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts"
"test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts",
"typedef": "tsc -p tsconfig.typedef.json"
},
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-typescript": "^6.1.0",
"@types/node": "^8.10.54",
"is-mergeable-object": "1.1.0",
"is-plain-obj": "^3.0.0",
Expand All @@ -43,7 +45,8 @@
"tape": "^5.0.1",
"terser": "^5.3.8",
"ts-node": "^9.0.0",
"typescript": "=2.2.2"
"tslib": "^2.0.3",
"typescript": "^4.1.1-rc"
},
"engines": {
"node": ">=0.10.0"
Expand Down
6 changes: 4 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript';
import pkg from './package.json'

export default {
input: `src/index.js`,
input: `src/index.ts`,
plugins: [
commonjs(),
resolve(),
commonjs(),
typescript()
],
output: [
{
Expand Down
9 changes: 4 additions & 5 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var isPlainObj = require('is-plain-obj')
import isPlainObj from 'is-plain-obj';

function defaultIsMergeable(value) {
return Array.isArray(value) || isPlainObj(value)
}
Expand Down Expand Up @@ -75,7 +76,7 @@ function mergeObject(target, source, options) {
return destination
}

function deepmerge(target, source, options) {
export default function deepmerge(target, source, options) {
options = Object.assign({
arrayMerge: defaultArrayMerge,
isMergeable: defaultIsMergeable
Expand All @@ -96,7 +97,7 @@ function deepmerge(target, source, options) {
}
}

deepmerge.all = function deepmergeAll(array, options) {
export function deepmergeAll(array, options) {
if (!Array.isArray(array)) {
throw new Error('first argument should be an array')
}
Expand All @@ -105,5 +106,3 @@ deepmerge.all = function deepmergeAll(array, options) {
return deepmerge(prev, next, options)
}, {})
}

module.exports = deepmerge
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"lib": [
"ES2020"
],
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src"
]
}
8 changes: 8 additions & 0 deletions tsconfig.typedef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "types/",
"emitDeclarationOnly": true
}
}
16 changes: 0 additions & 16 deletions types/index.d.ts

This file was deleted.

0 comments on commit bdb2204

Please sign in to comment.