Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
chore(package): use Babel and pika-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed May 10, 2019
1 parent bc99151 commit 81772f4
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ docs/src/exampleSources
docs/dist/
dll/
node_modules/
pkg/
stats/
.vscode/
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"connect-history-api-fallback": "^1.3.0",
"copy-to-clipboard": "^3.0.8",
"copy-webpack-plugin": "^4.5.2",
"cross-env": "^5.1.4",
"danger": "^6.0.5",
"doctoc": "^1.3.0",
"doctrine": "^2.0.0",
Expand Down Expand Up @@ -132,7 +131,6 @@
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.3.3333",
"webpack": "^4.30.0",
"webpack-dev-middleware": "^3.6.2",
"webpack-hot-middleware": "^2.24.3"
Expand Down
4 changes: 4 additions & 0 deletions packages/internal-tooling/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'entry',
},
],
Expand All @@ -21,5 +22,8 @@ module.exports = {
],
],
},
production: {
plugins: [['babel-plugin-transform-react-remove-prop-types', { mode: 'wrap' }]],
},
},
}
15 changes: 13 additions & 2 deletions packages/internal-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@pika/pack": "^0.3.5",
"@pika/plugin-build-node": "^0.3.14",
"@pika/plugin-build-web": "^0.3.14",
"@pika/plugin-standard-pkg": "^0.3.14",
"@types/jest": "^24.0.11",
"@types/jest-axe": "^2.2.3",
"@typescript-eslint/eslint-plugin": "^1.6.0",
"@typescript-eslint/parser": "^1.6.0",
"babel-jest": "^24.5.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"cross-env": "^5.2.0",
"dts-bundle-generator": "^2.1.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
Expand All @@ -22,13 +29,17 @@
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.6.0",
"execa": "^1.0.0",
"jest": "^24.5.0",
"jest-axe": "^3.1.1"
"jest-axe": "^3.1.1",
"rimraf": "^2.6.3",
"typescript": "^3.3.3333"
},
"files": [
"babel",
"eslint",
"jest"
"jest",
"pika-plugin-bundle-types"
],
"publishConfig": {
"access": "public"
Expand Down
38 changes: 38 additions & 0 deletions packages/internal-tooling/pika-plugin-bundle-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# @pika/plugin-build-types

> A [@pika/pack](https://github.com/pikapkg/pack) build plugin.
> Generates defintions with TypeScript and then creates a bundle from your TypeScript type definitions, using [DTS Bundle Generator](https://github.com/timocov/dts-bundle-generator).

## Install

```sh
# npm:
npm install @stardust-ui/internal-tooling --save-dev
# yarn:
yarn add @stardust-ui/internal-tooling --dev
```


## Usage

```json
{
"name": "example-package-json",
"version": "1.0.0",
"@pika/pack": {
"pipeline": [
["@pika/plugin-standard-pkg"],
["@stardust-ui/internal-tooling/pika-plugin-bundle-types"]
]
}
}
```

For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack).


## Result

1. Generates a single file with TypeScript definitions for your package build: `dist-types/`
1. Adds a "types" entrypoint to your built `package.json` manifest.
63 changes: 63 additions & 0 deletions packages/internal-tooling/pika-plugin-bundle-types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const { generateDtsBundle } = require('dts-bundle-generator')
const execa = require('execa')
const path = require('path')
const fs = require('fs')
const rimraf = require('rimraf')

const build = async ({ cwd, out, reporter }) => {
const tsBin = path.resolve(__dirname, '..', 'node_modules/.bin/tsc')
const tsConfig = path.join(cwd, 'tsconfig.json')

if (!fs.existsSync(tsConfig)) {
console.error(
['\n', '⚠️ dist-types/: ', 'Ensure that your package contains "tsconfig.json" file.'].join(
' ',
),
)
throw new Error(`Failed to build: dist-types/`)
}

const declarationOutputDir = path.join(out, 'dist-declarations')
const declarationOutputFiles = [
path.join(declarationOutputDir, 'index.d.ts'),
path.join(declarationOutputDir, 'src/index.d.ts'),
]

const typingsOutputDir = path.join(out, 'dist-types')
const typingsOutputFile = path.join(typingsOutputDir, 'index.d.ts')

await (async () => {
await execa(
tsBin,
[
'-d',
'--declarationMap',
'false',
'--declarationDir',
declarationOutputDir,
'--skipLibCheck',
'--emitDeclarationOnly',
],
{ cwd },
)

const declarationOutputFile = declarationOutputFiles.find(file => fs.existsSync(file))
const definitionBundle = generateDtsBundle([{ filePath: declarationOutputFile }])

rimraf.sync(declarationOutputDir)

fs.mkdirSync(typingsOutputDir)
fs.writeFileSync(typingsOutputFile, definitionBundle)
})()

reporter.created(declarationOutputDir, 'types')
}

const manifest = manifest => {
manifest.types = 'dist-types/index.d.ts'
}

module.exports = {
build,
manifest,
}
20 changes: 10 additions & 10 deletions packages/react-component-event-listener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"description": "React components for binding events on the global scope.",
"version": "0.29.1",
"author": "Oleksandr Fediashov <a@fedyashov.com>",
"@pika/pack": {
"pipeline": [
["@pika/plugin-standard-pkg", { "exclude": ["test/**/*"] }],
["@pika/plugin-build-node"],
["@pika/plugin-build-web"],
["@stardust-ui/internal-tooling/pika-plugin-bundle-types"]
]
},
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"prop-types": "^15.6.1",
Expand All @@ -12,14 +20,8 @@
"@stardust-ui/internal-tooling": "^0.29.1",
"lerna-alias": "^3.0.3-0"
},
"files": [
"dist"
],
"homepage": "https://github.com/stardust-ui/react/tree/master/packages/react-component-event-listener",
"jsnext:main": "dist/es/index.js",
"license": "MIT",
"main": "dist/commonjs/index.js",
"module": "dist/es/index.js",
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
Expand All @@ -29,8 +31,6 @@
},
"repository": "stardust-ui/react.git",
"scripts": {
"build": "cross-env TS_NODE_PROJECT=../../tsconfig.json gulp bundle:package:no-umd --package react-component-event-listener"
},
"sideEffects": false,
"types": "dist/es/index.d.ts"
"build": "cross-env NODE_ENV=production pika-pack build"
}
}
2 changes: 1 addition & 1 deletion packages/react-component-event-listener/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const windowRef: TargetRef = {

export { default as EventListener } from './EventListener'
export { default as StackableEventListener } from './StackableEventListener'
export { EventHandler, EventListenerProps, EventTypes, TargetRef } from './types'
export * from './types'
20 changes: 10 additions & 10 deletions packages/react-component-nesting-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"description": "Registers a DOM nodes within a context.",
"version": "0.29.1",
"author": "Oleksandr Fediashov <a@fedyashov.com>",
"@pika/pack": {
"pipeline": [
["@pika/plugin-standard-pkg", { "exclude": ["test/**/*"] }],
["@pika/plugin-build-node"],
["@pika/plugin-build-web"],
["@stardust-ui/internal-tooling/pika-plugin-bundle-types"]
]
},
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"prop-types": "^15.6.1",
Expand All @@ -12,14 +20,8 @@
"@stardust-ui/internal-tooling": "^0.29.1",
"lerna-alias": "^3.0.3-0"
},
"files": [
"dist"
],
"homepage": "https://github.com/stardust-ui/react/tree/master/packages/react-component-nesting-registry",
"jsnext:main": "dist/es/index.js",
"license": "MIT",
"main": "dist/commonjs/index.js",
"module": "dist/es/index.js",
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
Expand All @@ -29,8 +31,6 @@
},
"repository": "stardust-ui/react.git",
"scripts": {
"build": "cross-env TS_NODE_PROJECT=../../tsconfig.json gulp bundle:package:no-umd --package react-component-nesting-registry"
},
"sideEffects": false,
"types": "dist/es/index.d.ts"
"build": "cross-env NODE_ENV=production pika-pack build"
}
}
2 changes: 1 addition & 1 deletion packages/react-component-nesting-registry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as Unstable_NestingAuto } from './NestingAuto'
export { GetRefs, NodeRef } from './types'
export * from './types'
23 changes: 12 additions & 11 deletions packages/react-component-ref/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
"description": "A set of components and utils to deal with React refs.",
"version": "0.29.1",
"author": "Oleksandr Fediashov <olfedias@microsoft.com>",
"@pika/pack": {
"pipeline": [
["@pika/plugin-standard-pkg", { "exclude": ["test/**/*"] }],
["@pika/plugin-build-node"],
["@pika/plugin-build-web"],
["@stardust-ui/internal-tooling/pika-plugin-bundle-types"]
]
},
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"@stardust-ui/react-proptypes": "^0.29.1",
"prop-types": "^15.6.1",
"react-is": "^16.6.3"
"react-is": "^16.6.3",
"tslib": "^1.9.3"
},
"devDependencies": {
"@stardust-ui/internal-tooling": "^0.29.1",
"lerna-alias": "^3.0.3-0"
},
"files": [
"dist"
],
"homepage": "https://github.com/stardust-ui/react/tree/master/packages/react-component-ref",
"jsnext:main": "dist/es/index.js",
"license": "MIT",
"main": "dist/commonjs/index.js",
"module": "dist/es/index.js",
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
Expand All @@ -30,8 +33,6 @@
},
"repository": "stardust-ui/react.git",
"scripts": {
"build": "cross-env TS_NODE_PROJECT=../../tsconfig.json gulp bundle:package:no-umd --package react-component-ref"
},
"sideEffects": false,
"types": "dist/es/index.d.ts"
"build": "cross-env NODE_ENV=production pika-pack build"
}
}
20 changes: 10 additions & 10 deletions packages/react-proptypes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"description": "Set of custom reusable PropTypes for React components, some of them are specific for Stardust UI.",
"version": "0.29.1",
"author": "Oleksandr Fediashov <olfedias@microsoft.com>",
"@pika/pack": {
"pipeline": [
["@pika/plugin-standard-pkg", { "exclude": ["test/**/*"] }],
["@pika/plugin-build-node"],
["@pika/plugin-build-web"],
["@stardust-ui/internal-tooling/pika-plugin-bundle-types"]
]
},
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"lodash": "^4.17.11",
Expand All @@ -13,21 +21,13 @@
"@stardust-ui/internal-tooling": "^0.29.1",
"lerna-alias": "^3.0.3-0"
},
"files": [
"dist"
],
"homepage": "https://github.com/stardust-ui/react/tree/master/packages/react-proptypes",
"jsnext:main": "dist/es/index.js",
"license": "MIT",
"main": "dist/commonjs/index.js",
"module": "dist/es/index.js",
"publishConfig": {
"access": "public"
},
"repository": "stardust-ui/react.git",
"scripts": {
"build": "gulp bundle:package:no-umd --package react-proptypes"
},
"sideEffects": false,
"types": "dist/es/index.d.ts"
"build": "cross-env NODE_ENV=production pika-pack build"
}
}

0 comments on commit 81772f4

Please sign in to comment.