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 27, 2019
1 parent 0730931 commit e9c15ef
Show file tree
Hide file tree
Showing 31 changed files with 658 additions and 308 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/
7 changes: 6 additions & 1 deletion build/gulp/tasks/test-projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ const packStardustPackages = async (logger: Function): Promise<PackedPackages> =
await Promise.all(
Object.keys(stardustPackages).map(async (packageName: string) => {
const filename = tmp.tmpNameSync({ prefix: `stardust-`, postfix: '.tgz' })
const directory = stardustPackages[packageName]
// TODO: remove this condition
let directory = stardustPackages[packageName]

if (fs.existsSync(path.resolve(directory, 'pkg'))) {
directory = path.resolve(directory, 'pkg')
}

await runIn(directory)(`yarn pack --filename ${filename}`)
logger(`✔️Package "${packageName}" was packed to ${filename}`)
Expand Down
1 change: 1 addition & 0 deletions build/webpack.config.stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const makeConfig = (srcPath, name) => ({
new webpack.DefinePlugin(config.compiler_globals),
],
resolve: {
alias: lernaAliases('pkg'),
extensions: ['.ts', '.tsx', '.js', '.json'],
},
performance: {
Expand Down
20 changes: 10 additions & 10 deletions packages/docs-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
"version": "0.31.0",
"author": "Oleksandr Fediashov <a@fedyashov.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"@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"]
]
},
"dependencies": {
"object.values": "^1.1.0",
"prismjs": "^1.16.0",
"prop-types": "^15.6.1",
"tslib": "^1.9.3"
},
"files": [
"dist"
],
"homepage": "https://github.com/stardust-ui/react/tree/master/packages/docs-components",
"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 @@ -27,8 +29,6 @@
},
"repository": "stardust-ui/react.git",
"scripts": {
"build": "gulp bundle:package:no-umd --package docs-components"
},
"sideEffects": false,
"types": "dist/es/index.d.ts"
"build": "cross-env NODE_ENV=production pika-pack build"
}
}
2 changes: 1 addition & 1 deletion packages/docs-components/src/knobs/useKnobValues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as values from 'object.values'
import values from 'object.values'
import * as React from 'react'

import KnobsContext from './KnobContext'
Expand Down
3 changes: 3 additions & 0 deletions packages/internal-tooling/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = {
development: {
plugins: ['react-hot-loader/babel'],
},
production: {
plugins: ['lodash'],
},
test: {
presets: [['@babel/preset-env', { modules: 'commonjs' }]],
},
Expand Down
14 changes: 12 additions & 2 deletions packages/internal-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.4.0",
"@pika/plugin-build-web": "^0.4.0",
"@pika/plugin-standard-pkg": "^0.4.0",
"@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-lodash": "^3.3.4",
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
Expand All @@ -24,12 +30,16 @@
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.6.0",
"jest": "^24.5.0",
"jest-axe": "^3.1.1"
"jest-axe": "^3.1.1",
"rollup": "^1.11.3",
"rollup-plugin-dts": "^0.15.1",
"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 definitions with TypeScript and then creates a bundle from your TypeScript type definitions, using [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts).

## 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.
56 changes: 56 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,56 @@
const path = require('path')
const fs = require('fs')
const { rollup } = require('rollup')
const { dts } = require('rollup-plugin-dts')

const build = async ({ cwd, manifest, out, reporter }) => {
const tsConfig = path.join(cwd, 'tsconfig.json')

if (manifest.types) {
console.info(
[
'\n',
'ℹ️ dist-types/: ',
'Your "package.json" contains "types" field, generation is skipped.',
].join(' '),
)
return
}

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 typingsOutputDir = path.join(out, 'dist-types')
const typingsOutputFile = path.join(typingsOutputDir, 'index.d.ts')

await (async () => {
const result = await rollup({
// TODO: make this list configurable
external: ['fela', 'lodash', 'react', 'prop-types', 'react-dom'],
input: path.resolve(cwd, 'src', 'index.ts'),
plugins: [dts({ tsconfig: tsConfig })],
})

await result.write({
file: typingsOutputFile,
format: 'es',
})
})()

reporter.created(typingsOutputFile, 'types')
}

const manifest = manifest => {
manifest.types = 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.31.0",
"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.31.0",
"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": "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"
}
}
10 changes: 10 additions & 0 deletions packages/react-component-event-listener/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
"isolatedModules": false,
"outDir": "pkg/dist-types",
"rootDir": "src"
},
"include": ["src"]
}
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.31.0",
"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.31.0",
"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": "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"
}
}
10 changes: 10 additions & 0 deletions packages/react-component-nesting-registry/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
"isolatedModules": false,
"outDir": "pkg/dist-types",
"rootDir": "src"
},
"include": ["src"]
}
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.31.0",
"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.31.0",
"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.31.0",
"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": "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"
}
}
12 changes: 1 addition & 11 deletions packages/react-component-ref/src/Ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ import * as ReactIs from 'react-is'

import RefFindNode from './RefFindNode'
import RefForward from './RefForward'

export interface RefProps {
children: React.ReactElement<any>

/**
* Called when a child component will be mounted or updated.
*
* @param {HTMLElement} node - Referred node.
*/
innerRef: React.Ref<any>
}
import { RefProps } from './types'

const Ref: React.FunctionComponent<RefProps> = props => {
const { children, innerRef } = props
Expand Down

0 comments on commit e9c15ef

Please sign in to comment.