Skip to content

Commit

Permalink
feat: add @pkgr/named-exports package
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Sep 24, 2019
1 parent e87e420 commit 28e8da2
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@1stg/eslint-config/recommended"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
coverage
lib
node_modules
/packages/named-exports/index.ts
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"publish": {
"ignoreChanges": [
"test",
"tsconfig.json",
"*.md"
]
}
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"packages/*"
],
"scripts": {
"build": "run-p build:**",
"build": "lerna run build && run-p build:**",
"build:bundle": "r -e named -p",
"build:ts": "tsc -b",
"clean": "rm -rf packages/*/lib",
Expand All @@ -34,6 +34,8 @@
"@babel/core": "^7.6.2",
"@commitlint/cli": "^8.2.0",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.5",
"@types/prettier": "^1.18.2",
"eslint": "^6.4.0",
"husky": "^3.0.5",
"jest": "^24.9.0",
Expand All @@ -43,8 +45,11 @@
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"prettier-plugin-pkg": "^0.3.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"rollup": "^1.21.4",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"type-coverage": "^2.3.0",
"typescript": "^3.6.3"
},
Expand All @@ -53,13 +58,12 @@
"@1stg"
]
},
"eslintConfig": {
"extends": "@1stg/eslint-config/recommended"
},
"eslintIgnore": [
"coverage",
"lib",
"packages/*/CHANGELOG.md"
"packages/*/CHANGELOG.md",
"packages/named-exports/index.ts",
"!.*.js"
],
"jest": {
"preset": "ts-jest",
Expand Down
57 changes: 57 additions & 0 deletions packages/named-exports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# @pkgr/named-exports

[![npm](https://img.shields.io/npm/v/@pkgr/named-exports.svg)](https://www.npmjs.com/package/@pkgr/named-exports)
![npm bundle size](https://img.shields.io/bundlephobia/min/@pkgr/named-exports)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/@pkgr/named-exports)

[![David Peer](https://img.shields.io/david/peer/rx-ts/pkgr.svg?path=packages/named-exports)](https://david-dm.org/rx-ts/pkgr?path=packages/named-exports&type=peer)
[![David](https://img.shields.io/david/rx-ts/pkgr.svg?path=packages/named-exports)](https://david-dm.org/rx-ts/pkgr?path=packages/named-exports)
[![David Dev](https://img.shields.io/david/dev/rx-ts/pkgr.svg?path=packages/named-exports)](https://david-dm.org/rx-ts/pkgr?path=packages/named-exports&type=dev)

> Union `namedExports` definitions for [rollup-plugin-commonjs][].
## TOC <!-- omit in toc -->

- [Install](#install)
- [Usage](#usage)
- [Changelog](#changelog)
- [License](#license)

## Install

```sh
# yarn
yarn add -D @pkgr/named-exports

# npm
npm i -D @pkgr/named-exports
```

## Usage

```js
// rollup.config.js
import commonjs from 'rollup-plugin-commonjs'
import { namedExports } from '@pkgr/named-exports'

export default {
plugins: [
commonjs({
namedExports,
}),
],
}
```

## Changelog

Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).

## License

[MIT][] © [JounQin][]@[1stG.me][]

[1stg.me]: https://www.1stg.me
[jounqin]: https://GitHub.com/JounQin
[mit]: http://opensource.org/licenses/MIT
[rollup-plugin-commonjs]: https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports
25 changes: 25 additions & 0 deletions packages/named-exports/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs'
import path from 'path'

// eslint-disable-next-line node/no-extraneous-import
import prettier from 'prettier'

const PKGS = ['prettier', 'react', 'react-dom']

const namedExports = PKGS.reduce(
(acc, pkg) =>
Object.assign(acc, {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
[pkg]: Object.keys(require(pkg)).filter(key => !/^[_$]/.test(key)),
}),
{},
)

fs.writeFileSync(
path.resolve(__dirname, 'index.ts'),
prettier.format(`
export const namedExports = ${JSON.stringify(namedExports)}
export { namedExports as default }
`),
)
33 changes: 33 additions & 0 deletions packages/named-exports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@pkgr/named-exports",
"version": "0.0.0",
"description": "Union `namedExports` definitions for rollup-plugin-commonjs",
"repository": "git+https://github.com/rx-ts/pkgr.git",
"homepage": "https://github.com/rx-ts/pkgr/blob/master/packages/named-exports",
"author": "JounQin <admin@1stg.me>",
"license": "MIT",
"main": "lib/cjs",
"module": "lib",
"es2015": "lib/es2015",
"fesm5": "lib/esm",
"jsdelivr": "lib/umd",
"unpkg": "lib/umd",
"types": "lib",
"files": [
"lib"
],
"keywords": [
"named-exports",
"rollup",
"rollup-config",
"rollup-plugin",
"rollup-plugin-commonjs"
],
"scripts": {
"build": "ts-node -O '{\"module\":\"commonjs\"}' build"
},
"publishConfig": {
"access": "public"
},
"sideEffects": false
}
19 changes: 19 additions & 0 deletions packages/named-exports/test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import _, { namedExports } from '../index'

describe('named exports', () => {
it('default export and `namedExports` named export should be same exactly ', () =>
expect(_).toBe(namedExports))

it('should be a string array map', () =>
expect(
Object.values(namedExports).every(
exports =>
Array.isArray(exports) && exports.every(_ => typeof _ === 'string'),
),
).toBeTruthy())

it('should not include any private member nor property', () =>
expect(
Object.values(namedExports).every(_ => _.every(_ => !/^[_$]/.test(_))),
).toBeTruthy())
})
7 changes: 7 additions & 0 deletions packages/named-exports/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@1stg/tsconfig/composite",
"compilerOptions": {
"outDir": "lib"
},
"files": ["index.ts"]
}
2 changes: 1 addition & 1 deletion packages/umd-globals/test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import _, {
} from '../index'

describe('umd globals', () => {
it('default export and globals named export should be same exactly ', () =>
it('default export and `globals` named export should be same exactly ', () =>
expect(_).toBe(globals))

it('should be a string map', () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/umd-globals/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "lib"
},
"exclude": ["test"]
"exclude": ["lib", "test"]
}
3 changes: 0 additions & 3 deletions tsconfig.base.json

This file was deleted.

5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"extends": "./tsconfig.base.json",
"extends": "@1stg/tsconfig",
"compilerOptions": {
"incremental": false,
"noEmit": true
},
"references": [
{
"path": "packages/umd-globals"
},
{
"path": "packages/named-exports"
}
]
}
64 changes: 61 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,11 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==

"@types/prettier@^1.18.2":
version "1.18.2"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.18.2.tgz#069e7d132024d436fd1f5771f6932426a695f230"
integrity sha512-2JBasa5Qaj81Qsp/dxX2Njy+MdKC767WytHUDsRM7TYEfQvKPxsnGpnCBlBS1i2Aiv1YwCpmKSbQ6O6v8TpiKg==

"@types/resolve@0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
Expand Down Expand Up @@ -2847,6 +2852,11 @@ are-we-there-yet@~1.1.2:
delegates "^1.0.0"
readable-stream "^2.0.6"

arg@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.1.tgz#485f8e7c390ce4c5f78257dbea80d4be11feda4c"
integrity sha512-SlmP3fEA88MBv0PypnXZ8ZfJhwmDeIE3SP71j37AiXQBXYosPV0x6uISAaHYSlSVhmHOVkomen0tbGk6Anlebw==

argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
Expand Down Expand Up @@ -4053,6 +4063,11 @@ diff-sequences@^24.9.0:
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.9.0.tgz#5715d6244e2aa65f48bba0bc972db0b0b11e95b5"
integrity sha512-Dj6Wk3tWyTE+Fo1rW8v0Xhwk80um6yFYKbuAxc9c3EZxIHFDYwbi34Uk42u1CdnIiVorvt4RmlSDjIPyzGC2ew==

diff@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==

dir-glob@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.2.2.tgz#fa09f0694153c8918b18ba0deafae94769fc50c4"
Expand Down Expand Up @@ -6770,7 +6785,7 @@ longest-streak@^2.0.1:
resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-2.0.3.tgz#3de7a3f47ee18e9074ded8575b5c091f5d0a4105"
integrity sha512-9lz5IVdpwsKLMzQi0MQ+oD9EA0mIGcWYP7jXMTZVXP8D42PwuAk+M/HBFYQoxt1G5OR8m7aSIgb1UymfWGBWEw==

loose-envify@^1.0.0, loose-envify@^1.4.0:
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
Expand Down Expand Up @@ -6827,7 +6842,7 @@ make-dir@^2.1.0:
pify "^4.0.1"
semver "^5.6.0"

make-error@1.x:
make-error@1.x, make-error@^1.1.1:
version "1.3.5"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
Expand Down Expand Up @@ -8117,7 +8132,7 @@ promzard@^0.3.0:
dependencies:
read "1"

prop-types@^15.7.2:
prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
Expand Down Expand Up @@ -8227,11 +8242,30 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-dom@^16.9.0:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962"
integrity sha512-YFT2rxO9hM70ewk9jq0y6sQk8cL02xm4+IzYBz75CQGlClQQ1Bxq0nhHF6OtSbit+AIahujJgb/CPRibFkMNJQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.15.0"

react-is@^16.8.1, react-is@^16.8.4:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb"
integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw==

react@^16.9.0:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa"
integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"

read-cmd-shim@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/read-cmd-shim/-/read-cmd-shim-1.0.4.tgz#b4a53d43376211b45243f0072b6e603a8e37640d"
Expand Down Expand Up @@ -9492,6 +9526,14 @@ sax@^1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==

scheduler@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.15.0.tgz#6bfcf80ff850b280fed4aeecc6513bc0b4f17f8e"
integrity sha512-xAefmSfN6jqAa7Kuq7LIJY0bwAPG3xlCj0HMEBQk1lxYiDKZscY2xJ5U/61ZTrYbmNQbXa+gc7czPkVo11tnCg==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
Expand Down Expand Up @@ -10292,6 +10334,17 @@ ts-lib-utils@^2.2.0:
glob "7"
tslib "1"

ts-node@^8.4.1:
version "8.4.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.4.1.tgz#270b0dba16e8723c9fa4f9b4775d3810fd994b4f"
integrity sha512-5LpRN+mTiCs7lI5EtbXmF/HfMeCjzt7DH9CZwtkr6SywStrNQC723wG+aOWFiLNn7zT3kD/RnFqi3ZUfr4l5Qw==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.6"
yn "^3.0.0"

tsconfig-paths@^3.9.0:
version "3.9.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b"
Expand Down Expand Up @@ -10987,3 +11040,8 @@ yargs@^13.3.0:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.1"

yn@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

0 comments on commit 28e8da2

Please sign in to comment.