Skip to content

Commit

Permalink
refactor: switch from TSDX to my ts-library-base boilerplate
Browse files Browse the repository at this point in the history
- I've been away from OSS for a while due to abuse and toxicity and no
  one's maintained TSDX in my time away, so lots of things are dated now
  - and TSDX was a large source of the above as well
  - and this library doesn't need everything TSDX provides -- most don't

- use my boilerplate from https://github.com/agilgur5/ts-library-base
  - babel.config.js is basically a duplicate plus preset-react
  - tsconfig.json is dupe plus more excludes
  - tsconfig.build.json is dupe plus typings dir (and tsx ext for index)
  - jest.config.ts is dupe plus jsdom, enzyme, window-resizeto
  - rollup.config.ts is dupe minus CJS build and with some custom naming
    - similar for package.json#main,module,source,exports
    - fix: previously #main was changed to CJS, which could be
      considered breaking since it's currently UMD -- back to UMD now
  - package.json#scripts is a dupe plus lint and start
  - deps: add rollup, rollup-plugin-typescript2 for the config
  - deps: add @rollup/plugin-node-resolve, @rollup/plugin-commonjs,
    @rollup/plugin-babel, and rollup-plugin-terser for the build
    - and package-json-type and @babel/preset-typescript for typings
    - and @babel/runtime and @babel/plugin-transform-runtime for reusing
      Babel's runtime helpers instead of duplicating them
  - deps: add jest, jest-config, @jest/globals, @jest/types, ts-node
    for testing
    - RIP my jest-without-globals library
  - deps: add concurrently for parallel script execution
  - deps: add @tsconfig/strictest to extend tsconfig from
  - deps: add TS ofc

- ci: add type-checking to before script check
- ci: upgrade to Node 12 as oldest LTS

- typings: improve typings with newer TS and stricter tsconfig
  - required `override` and required `import type`
- fix(typings): move @types/react and @types/prop-types to deps
  - these are imported by the `.d.ts` declaration and even the DT lib:
    https://www.npmjs.com/package/@types/react-signature-canvas

- deps: upgrade to lockfile v2 that is auto-used with NPM v8

- deps: upgrade @babel/core and @babel/preset-react to latest minor
  - and add @babel/preset-env as a direct devDep too
  - should upgrade compat-table etc and might as well do so to match
    minors of other babel deps and while changing so many deps anyway

- deps: switch from eslint-config-standard-with-typescript to
  ts-standard
  - I didn't know this was a thing! standard-with-typescript was a
    relatively recent development in and of itself
  - should have used this from the beginning!
    - replaced all eslint deps with this one dep now
  - ignore the example dir for now as it errors (parsing?) and a line
    in the babel config as well (possibly due to old ESLint)
  • Loading branch information
agilgur5 committed Apr 20, 2022
1 parent feb4712 commit c70cc5a
Show file tree
Hide file tree
Showing 15 changed files with 30,043 additions and 20,331 deletions.
9 changes: 0 additions & 9 deletions .babelrc.js

This file was deleted.

15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: node_js
# default is the very old 0.10.48; match local version instead
node_js: '10.16.0'
# default is the very old 0.10.48; use oldest LTS instead
node_js: 12

before_script: npm run lint
before_script:
- npm run lint
- npm run tsc
script: npm test -- --coverage
after_script:
# upload coverage reports to CodeCov
Expand Down
24 changes: 24 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @type {import('@babel/core').ConfigFunction} */
module.exports = api => {
// eslint-disable-next-line dot-notation -- this conflicts with tsc, possibly due to outdated ESLint
api.cache.using(() => process.env['NODE_ENV']) // cache based on NODE_ENV

// normally use browserslistrc, but for Jest, use current version of Node
const isTest = api.env('test')
const jestTargets = { targets: { node: 'current' } }
/** @type {[import('@babel/core').PluginTarget, import('@babel/core').PluginOptions]} */
const presetEnv = ['@babel/preset-env', { bugfixes: true }]
if (isTest) presetEnv[1] = { ...presetEnv[1], ...jestTargets }

return {
presets: [
presetEnv,
'@babel/preset-typescript',
'@babel/preset-react'
],
plugins: [
// used with @rollup/plugin-babel
'@babel/plugin-transform-runtime'
]
}
}
19 changes: 0 additions & 19 deletions jest.config.js

This file was deleted.

19 changes: 19 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Config } from '@jest/types'
import { defaults } from 'jest-config'

const config: Config.InitialOptions = {
injectGlobals: false, // use @jest/globals
testEnvironment: 'jsdom',
setupFilesAfterEnv: [
// configure enzyme w/ react adapter
'<rootDir>/test/config/configure-enzyme.js',
// polyfill window.resizeTo
'window-resizeto/polyfill'
],
coveragePathIgnorePatterns: [
...defaults.coveragePathIgnorePatterns,
'<rootDir>/test/' // ignore any test helper files
]
}

export default config

0 comments on commit c70cc5a

Please sign in to comment.