Skip to content

Commit

Permalink
🔀 Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon-clown committed Apr 11, 2020
2 parents baf5496 + d6344eb commit 5cd06e4
Show file tree
Hide file tree
Showing 33 changed files with 340 additions and 97 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"plusplus",
"postbuild",
"prebuild",
"rimraf",
"rollup",
"sourcemap",
"styl",
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
"bootstrap": "lerna bootstrap",
"build": "lerna exec --concurrency 1 -- 'echo && pwd && yarn build'",
"lint:fix": "lerna exec --concurrency 1 -- 'echo && pwd && yarn lint:fix'",
"clean": "lerna clean --yes",
"clean": "lerna clean --yes && yarn install",
"rebuild": "lerna exec -- 'rimraf lib/' && yarn build",
"find-inconsistent": "node ./node_modules/@barusu/tool-find-inconsistent-packages/lib/cjs/cli.js"
},
"workspaces": [
"packages/*"
],
"devDependencies": {
"cross-env": "^7.0.2",
"lerna": "^3.20.2",
"rimraf": "^3.0.2",
"ts-node": "^8.8.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.8.2"
}
}
2 changes: 1 addition & 1 deletion packages/blob-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"prebuild": "rimraf lib/",
"build": "rollup -c rollup.config.js",
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
"prepublishOnly": "yarn build"
"prepublishOnly": "cross-env ROLLUP_USE_SOURCE_MAP=false yarn build"
},
"devDependencies": {
"@barusu/eslint-config": "^0.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/blob-util/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import manifest from './package.json'
const resolvePath = p => path.resolve(__dirname, p)
const paths = {
eslintrc: resolvePath('.eslintrc.js'),
tsconfig: resolvePath('tsconfig.json'),
tsconfig: resolvePath('tsconfig.src.json'),
}


Expand Down
12 changes: 5 additions & 7 deletions packages/blob-util/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"extends": "../../tsconfig.settings",
"extends": "../../tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declarationDir": "lib/types",
"target": "es2015",
"module": "es2015"
"module": "commonjs"
},
"include": [
"src"
"src",
"script",
"test"
]
}
13 changes: 13 additions & 0 deletions packages/blob-util/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.settings",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declarationDir": "lib/types",
"target": "es2015",
"module": "es2015"
},
"include": [
"src"
]
}
2 changes: 1 addition & 1 deletion packages/option-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"prebuild": "rimraf lib/",
"build": "rollup -c rollup.config.js",
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
"prepublishOnly": "yarn build"
"prepublishOnly": "cross-env ROLLUP_USE_SOURCE_MAP=false yarn build"
},
"devDependencies": {
"@barusu/eslint-config": "^0.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/option-util/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import manifest from './package.json'
const resolvePath = p => path.resolve(__dirname, p)
const paths = {
eslintrc: resolvePath('.eslintrc.js'),
tsconfig: resolvePath('tsconfig.json'),
tsconfig: resolvePath('tsconfig.src.json'),
}


Expand Down
12 changes: 5 additions & 7 deletions packages/option-util/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"extends": "../../tsconfig.settings",
"extends": "../../tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declarationDir": "lib/types",
"target": "es2015",
"module": "es2015"
"module": "commonjs"
},
"include": [
"src"
"src",
"script",
"test"
]
}
13 changes: 13 additions & 0 deletions packages/option-util/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.settings",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declarationDir": "lib/types",
"target": "es2015",
"module": "es2015"
},
"include": [
"src"
]
}
6 changes: 3 additions & 3 deletions packages/rollup-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
],
"scripts": {
"prebuild": "yarn lint:fix && rimraf *.tsbuildinfo lib/",
"build": "tsc -b tsconfig.json",
"postbuild": "rimraf lib/package.json lib/test lib/**/*.tsbuildinfo && mv lib/src/* lib && rimraf lib/src/",
"build": "tsc -p tsconfig.src.json --sourceMap --declarationMap",
"postbuild": "rimraf lib/**/*.tsbuildinfo",
"lint:fix": "eslint 'src/**/*.ts' --fix",
"prepublishOnly": "yarn build"
"prepublishOnly": "yarn prebuild && tsc -p tsconfig.src.json"
},
"dependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
Expand Down
23 changes: 20 additions & 3 deletions packages/rollup-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import {
PeerDepsExternalOptions,
EslintOptions,
} from './types/options'
import { convertToBoolean, coverBoolean } from './util'


export interface ProdConfigParams extends rollup.InputOptions {
/**
* 是否生成 sourceMap (包括 declarationMap)
*/
useSourceMap: boolean
manifest: {
/**
* 源文件入口
Expand Down Expand Up @@ -65,8 +70,15 @@ export interface ProdConfigParams extends rollup.InputOptions {


export const createRollupConfig = (props: ProdConfigParams): rollup.RollupOptions[] => {
const DEFAULT_USE_SOURCE_MAP = coverBoolean(true, convertToBoolean(process.env.ROLLUP_USE_SOURCE_MAP))

// process task
const { manifest, pluginOptions = {}, ...resetInputOptions } = props
const {
useSourceMap = DEFAULT_USE_SOURCE_MAP,
manifest,
pluginOptions = {},
...resetInputOptions
} = props
const {
eslintOptions = {},
nodeResolveOptions = {},
Expand All @@ -81,13 +93,13 @@ export const createRollupConfig = (props: ProdConfigParams): rollup.RollupOption
file: manifest.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
sourcemap: useSourceMap,
},
manifest.module && {
file: manifest.module,
format: 'es',
exports: 'named',
sourcemap: true,
sourcemap: useSourceMap,
}
].filter(Boolean) as rollup.OutputOptions[],
external: [
Expand Down Expand Up @@ -115,6 +127,11 @@ export const createRollupConfig = (props: ProdConfigParams): rollup.RollupOption
typescript: require('typescript'),
rollupCommonJSResolveHack: true,
include: ['src/**/*{.ts,.tsx}'],
tsconfigOverride: {
compilerOptions: {
declarationMap: useSourceMap,
}
},
...typescriptOptions,
}),
commonjs({
Expand Down
41 changes: 41 additions & 0 deletions packages/rollup-config/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 转换成布尔值
* - 若 @value 为 null/undefined,返回 undefined
* - 若 @value 为 string,则只有 true/false 才是有效值,其它值视为 undefined
* - 否则,返回 Boolean(@value)
* @param value
*/
export function convertToBoolean(value?: string | boolean | any): boolean | undefined {
if (value == null) return undefined
if (typeof value === 'string') {
switch (value.toLowerCase()) {
case 'false': return false
case 'true': return true
}
return undefined
}
return Boolean(value)
}


/**
* 当 value 为 null/undefined 时,返回 @defaultValue
* 否则返回 @value
* @param defaultValue
* @param value
*/
export function cover<T>(defaultValue: T, value: T | null | undefined): T {
if (value == null) return defaultValue
return value
}


/**
* 先将 @value 转成布尔值,然后调用 cover 函数
* @param defaultValue
* @param value
*/
export function coverBoolean(defaultValue: boolean, value?: any): boolean {
const v = convertToBoolean(value)
return cover<boolean>(defaultValue, v)
}
11 changes: 5 additions & 6 deletions packages/rollup-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "../../tsconfig.settings",
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": ".",
"target": "es5",
"module": "CommonJS",
"module": "commonjs"
},
"include": [
"src"
"src",
"script",
"test"
]
}
14 changes: 14 additions & 0 deletions packages/rollup-config/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.settings",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"target": "es2015",
"module": "commonjs",
"sourceMap": false,
"declarationMap": false
},
"include": [
"src"
]
}
4 changes: 3 additions & 1 deletion packages/template-ts-package/boilerplate/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"CHANGELOG.md",
"LICENSE",
"README.md",
"package.json"
"package.json",
"!lib/**/*.js.map",
"!lib/**/*.d.ts.map"
],
"scripts": {
"start": "rollup -w -c rollup.config.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/template-ts-package/boilerplate/rollup.config.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import manifest from './package.json'
const resolvePath = p => path.resolve(__dirname, p)
const paths = {
eslintrc: resolvePath('.eslintrc.js'),
tsconfig: resolvePath('tsconfig.json'),
tsconfig: resolvePath('tsconfig.src.json'),
}


Expand All @@ -21,7 +21,7 @@ const config = createRollupConfig({
useTsconfigDeclarationDir: true,
},
commonjsOptions: {
include: ['../../node_modules/**'],
include: ['{{{nodeModulesPath}}}/**'],
namedExports: {
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/template-ts-package/boilerplate/src/index.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!')
12 changes: 5 additions & 7 deletions packages/template-ts-package/boilerplate/tsconfig.json.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"extends": "../../tsconfig.settings",
"extends": "{{{tsconfigExtends}}}",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declarationDir": "lib/types",
"target": "es2015",
"module": "es2015"
"module": "commonjs"
},
"include": [
"src"
"src",
"script",
"test"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
"alwaysStrict": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "lib/types",
"downlevelIteration": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"module": "es2015"
"moduleResolution": "node",
"newLine": "LF",
"noEmit": false,
Expand All @@ -23,17 +21,11 @@
"pretty": false,
"removeComments": false,
"resolveJsonModule": true,
"rootDir": "src",
"sourceMap": true,
"strict": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es2015",
"outDir": "lib"
},
"include": [
"src"
]
"suppressImplicitAnyIndexErrors": true
}
}
13 changes: 13 additions & 0 deletions packages/template-ts-package/boilerplate/tsconfig.src.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "{{{tsconfigSrcExtends}}}",
"compilerOptions": {
"rootDir": ".",
"outDir": "lib",
"declarationDir": "lib/types",
"target": "es2015",
"module": "es2015"
},
"include": [
"src"
]
}
Loading

0 comments on commit 5cd06e4

Please sign in to comment.