Skip to content

Commit

Permalink
feat: tsc generate proper declaration (typing updated) (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
natterstefan authored Sep 1, 2020
1 parent c836461 commit 1e79f7d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ esm
lib
*.tgz
storybook-static
*.d.ts.map

# Optional npm cache directory
.npm
Expand Down
2 changes: 1 addition & 1 deletion .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = ({ config }) => {
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('awesome-typescript-loader'),
loader: require.resolve('ts-loader'),
},
{
loader: require.resolve('react-docgen-typescript-loader'),
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
"postbuild": "npm run size",
"release-minor": "HUSKY_SKIP_HOOKS=1 standard-version --release-as minor",
"release-patch": "HUSKY_SKIP_HOOKS=1 standard-version --release-as patch",
"start": "start-storybook",
"start": "start-storybook -p 6006 --ci",
"size": "size-limit",
"storybook": "start-storybook -p 6006 --ci",
"test": "echo \"Error: no test specified\" && exit 1"
},
"peerDependencies": {
Expand Down Expand Up @@ -89,7 +88,6 @@
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"all-contributors-cli": "^6.14.0",
"awesome-typescript-loader": "^5.2.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"commitizen": "^4.0.3",
Expand Down Expand Up @@ -119,7 +117,8 @@
"start-server-and-test": "^1.10.11",
"storybook-readme": "^5.0.8",
"terser-webpack-plugin": "^2.3.5",
"typescript": "^3.8.3",
"ts-loader": "^8.0.3",
"typescript": "^3.9.7",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
},
Expand Down
34 changes: 25 additions & 9 deletions src/tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,37 @@
import * as EditorJS from '@editorjs/editorjs'

type Props = {
/**
* Object that defines rules for automatic sanitizing.
* @see https://editorjs.io/tools-api#sanitize
* @default undefined
*/
sanitize?: {}
/**
* [Shortcut](https://github.com/codex-team/codex.shortcuts) to apply
* [Tool's render and inserting behaviour](https://editorjs.io/tools-api#shortcut)
* @default undefined
*/
shortcut?: string
/**
* text [formatting tag](https://www.w3schools.com/html/html_formatting.asp)
* (eg. `bold`)
* @default undefined
*/
tagName: string
/**
* Icon for the tools [inline toolbar](https://editorjs.io/inline-tools-api-1#render)
* @default undefined
*/
toolboxIcon: string
}

/**
* GenericInlineTool returns an EditorJS.InlineTool capable of wrapping a
* selected text with any given `tagName`.
*
* basic structure of the class below is inspired by
* - https://github.com/editor-js/marker/blob/c306bcb33c88eaa3c172eaf387fbcd06ae6b297f/src/index.js
*
* @param {String} tagName - tag which should wrap the selected text
* @return {EditorJS.InlineTool}
* inspired by
* @see https://github.com/editor-js/marker/blob/c306bcb33c88eaa3c172eaf387fbcd06ae6b297f/src/index.js
*/
const createGenericInlineTool = ({
sanitize,
Expand All @@ -25,13 +41,13 @@ const createGenericInlineTool = ({
toolboxIcon,
}: Props) => {
return class GenericInlineTool implements EditorJS.InlineTool {
private api: EditorJS.API = null
api: EditorJS.API = null

private button: HTMLButtonElement = null
button: HTMLButtonElement = null

private tag: string = null
tag: string = null

private iconClasses: {
iconClasses: {
active: string
base: string
} = null
Expand Down
14 changes: 6 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
/* inspired by https://github.com/marmelab/react-admin/blob/HEAD@%7B2019-10-20T17:02:44Z%7D/tsconfig.json */
"compilerOptions": {
/* Basic Options */
"target": "es5" /* Specify ECMAScript target version: 'es3' (default), 'es5', 'es2015', 'es2016', 'es2017','es2018' or 'esnext'. */,
"lib": ["es2015", "dom"],
"declaration": false /* Generates corresponding '.d.ts' file. (set to true in npm script) */,
"declarationMap": false /* Generates a sourcemap for each corresponding '.d.ts' file. (set to true in npm script) */,
"target": "es2015" /* Specify ECMAScript target version: 'es3' (default), 'es5', 'es2015', 'es2016', 'es2017','es2018' or 'esnext'. */,
"lib": ["DOM"],
"module": "es2015",
"declaration": true /* Generates corresponding '.d.ts' file. (set to true in npm script) */,
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. (set to true in npm script) */,
"sourceMap": true /* Generates corresponding '.map' file. */,
"removeComments": false /* Do emit comments to output. */,
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
/* Strict Type-Checking Options */
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
/* source structure and types */
"baseUrl": "./",
"typeRoots": ["node_modules/@types", "@types"]
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"include": ["src/**/*", "@types"],
"exclude": ["node_modules", "src/**/__tests__", "src/**/__stories__/*"]
Expand Down
8 changes: 4 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ module.exports = {
module: {
rules: [
{
test: /\.(ts)x?$/,
exclude: /node_modules/,
test: /\.(t|j)sx?$/,
loader: 'awesome-typescript-loader',
loader: 'ts-loader',
options: {
useCache: true,
transpileOnly: true,
},
},
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
cache: true,
output: {
comments: false,
},
Expand Down
54 changes: 30 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2797,20 +2797,6 @@ autoprefixer@^9.4.9:
postcss "^7.0.23"
postcss-value-parser "^4.0.2"

awesome-typescript-loader@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-5.2.1.tgz#a41daf7847515f4925cdbaa3075d61f289e913fc"
integrity sha512-slv66OAJB8orL+UUaTI3pKlLorwIvS4ARZzYR9iJJyGsEgOqueMfOMdKySWzZ73vIkEe3fcwFgsKMg4d8zyb1g==
dependencies:
chalk "^2.4.1"
enhanced-resolve "^4.0.0"
loader-utils "^1.1.0"
lodash "^4.17.5"
micromatch "^3.1.9"
mkdirp "^0.5.1"
source-map-support "^0.5.3"
webpack-log "^1.2.0"

aws-sign2@~0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
Expand Down Expand Up @@ -3570,7 +3556,7 @@ caseless@~0.12.0:
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=

chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
Expand Down Expand Up @@ -5094,7 +5080,16 @@ enhanced-resolve@4.1.0:
memory-fs "^0.4.0"
tapable "^1.0.0"

enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.0:
enhanced-resolve@^4.0.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126"
integrity sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ==
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.5.0"
tapable "^1.0.0"

enhanced-resolve@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.1.tgz#2937e2b8066cd0fe7ce0990a98f0d71a35189f66"
integrity sha512-98p2zE+rL7/g/DzMHMTF4zZlCgeVdJ7yr6xzEpJRYwFYrGi9ANdn5DnJURg6RpBkyk60XYDnWIv51VfIhfNGuA==
Expand Down Expand Up @@ -8235,7 +8230,7 @@ microevent.ts@~0.1.1:
resolved "https://registry.yarnpkg.com/microevent.ts/-/microevent.ts-0.1.1.tgz#70b09b83f43df5172d0205a63025bce0f7357fa0"
integrity sha512-jo1OfR4TaEwd5HOrt5+tAZ9mqT4jmpNAusXtyfNzqVm9uiSYFZlKM1wYL4oU7azZW/PxQW53wM0S6OR1JHNa2g==

micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4, micromatch@^3.1.9:
micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4:
version "3.1.10"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
integrity sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg==
Expand All @@ -8254,7 +8249,7 @@ micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4, micromatch@^3.1.9:
snapdragon "^0.8.1"
to-regex "^3.0.2"

micromatch@^4.0.2:
micromatch@^4.0.0, micromatch@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.2.tgz#4fcb0999bf9fbc2fcbdd212f6d629b9a56c39259"
integrity sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==
Expand Down Expand Up @@ -11246,7 +11241,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"

source-map-support@^0.5.3, source-map-support@~0.5.12:
source-map-support@~0.5.12:
version "0.5.16"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042"
integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==
Expand Down Expand Up @@ -12066,6 +12061,17 @@ tryer@^1.0.1:
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==

ts-loader@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-8.0.3.tgz#56858f4296edf1ed55e01f8520552984d3f0911c"
integrity sha512-wsqfnVdB7xQiqhqbz2ZPLGHLPZbHVV5Qn/MNFZkCFxRU1miDyxKORucDGxKtsQJ63Rfza0udiUxWF5nHY6bpdQ==
dependencies:
chalk "^2.3.0"
enhanced-resolve "^4.0.0"
loader-utils "^1.0.2"
micromatch "^4.0.0"
semver "^6.0.0"

ts-pnp@^1.1.2:
version "1.1.5"
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.5.tgz#840e0739c89fce5f3abd9037bb091dbff16d9dec"
Expand Down Expand Up @@ -12150,10 +12156,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
typescript@^3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

ua-parser-js@^0.7.18:
version "0.7.20"
Expand Down Expand Up @@ -12494,7 +12500,7 @@ webpack-hot-middleware@^2.25.0:
querystring "^0.2.0"
strip-ansi "^3.0.0"

webpack-log@^1.1.2, webpack-log@^1.2.0:
webpack-log@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-1.2.0.tgz#a4b34cda6b22b518dbb0ab32e567962d5c72a43d"
integrity sha512-U9AnICnu50HXtiqiDxuli5gLB5PGBo7VvcHx36jRZHwK4vzOYLbImqT4lwWwoMHdQWwEKw736fCHEekokTEKHA==
Expand Down

0 comments on commit 1e79f7d

Please sign in to comment.