Skip to content

Commit

Permalink
fix: lint fix, use union @1stg/app-config
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Nov 2, 2019
1 parent 7aa1937 commit ec3d54c
Show file tree
Hide file tree
Showing 9 changed files with 708 additions and 91 deletions.
22 changes: 4 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,16 @@
"w:build": "ts-node --files packages/webpack/src/cli",
"w:dev": "ts-node -T --files packages/webpack/src/cli"
},
"dependencies": {
"rollup": "^1.26.3"
},
"devDependencies": {
"@1stg/commitlint-config": "^0.2.0",
"@1stg/eslint-config": "^0.14.2",
"@1stg/husky-config": "^0.4.0",
"@1stg/lint-staged": "^0.9.0",
"@1stg/prettier-config": "^0.5.2",
"@1stg/remark-config": "^0.2.2",
"@1stg/tsconfig": "^0.7.0",
"@1stg/app-config": "^0.1.3",
"@1stg/tslint-config": "^0.5.2",
"@angular/common": "^8.2.13",
"@angular/compiler": "^8.2.13",
"@angular/compiler-cli": "^8.2.13",
"@angular/core": "^8.2.13",
"@angular/platform-browser": "^8.2.13",
"@angular/platform-browser-dynamic": "^8.2.13",
"@babel/core": "^7.6.4",
"@babel/types": "^7.6.3",
"@commitlint/cli": "^8.2.0",
"@d-ts/bin": "^0.3.3",
"@d-ts/core": "^0.6.0",
"@d-ts/svelte": "^0.1.0",
Expand Down Expand Up @@ -89,16 +78,12 @@
"@types/webpack-env": "^1.14.1",
"@types/workbox-webpack-plugin": "^4.1.0",
"core-js": "^3.3.6",
"eslint": "^6.6.0",
"fbjs": "^1.0.0",
"husky": "^3.0.9",
"is-glob": "^4.0.1",
"jest": "^24.9.0",
"lerna": "^3.18.3",
"lerna-changelog": "^0.8.2",
"lint-staged": "^9.4.2",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"prop-types": "^15.7.2",
"react": "^16.11.0",
"react-dom": "^16.11.0",
Expand All @@ -113,13 +98,14 @@
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"type-coverage": "^2.3.0",
"typescript": "~3.6.4",
"typescript": "~3.5.3",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10",
"zone.js": "^0.10.2"
},
"resolutions": {
"rollup": "^1.26.0",
"prettier": "^1.18.2",
"rollup": "^1.26.3",
"typescript": "~3.5.3"
},
"commitlint": {
Expand Down
6 changes: 4 additions & 2 deletions packages/named-exports/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable node/no-extraneous-import */

import { writeFile } from 'fs'
import isGlob from 'is-glob'
import path from 'path'
import { promisify } from 'util'

import isGlob from 'is-glob'
import prettier from 'prettier'
import glob from 'tiny-glob'
import { promisify } from 'util'

interface Pkg {
core: string
Expand Down Expand Up @@ -33,6 +34,7 @@ const combinePkg = (pkg: string, exports: {}) =>
[pkg]: Object.keys(require(pkg)).filter(key => !/^[_$]/.test(key)),
})

// eslint-disable-next-line sonarjs/cognitive-complexity
const namedExports = PKGS.reduce(async (exported, pkg) => {
const exports = await exported
const { core, extra }: Pkg = typeof pkg === 'string' ? { core: pkg } : pkg
Expand Down
52 changes: 25 additions & 27 deletions packages/rollup/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {
normalizePkg,
upperCamelCase,
} from '@pkgr/umd-globals'
import { EXTENSIONS, PROD, __DEV__, __PROD__, tryPkg } from '@pkgr/utils'
import {
EXTENSIONS,
PROD,
__DEV__,
__PROD__,
identify,
tryPkg,
} from '@pkgr/utils'
import replace from '@rollup/plugin-replace'
import alias, { AliasOptions } from '@rxts/rollup-plugin-alias'
import builtinModules from 'builtin-modules'
Expand Down Expand Up @@ -82,11 +89,6 @@ const cjs = (sourceMap: boolean) =>
sourceMap,
})

const BASIC_PLUGINS = [
json(),
url({ include: IMAGE_EXTENSIONS.map(ext => `**/*${ext}`) }),
]

const DEFAULT_FORMATS = ['cjs', 'es2015', 'esm']

const isTsAvailable = tryPkg('typescript')
Expand Down Expand Up @@ -323,39 +325,35 @@ ConfigOptions = {}): RollupOptions[] => {
],
],
}),
].concat(
resolve({
deps,
node: !!node,
}),
cjs(sourceMap),
copy(copyOptions),
BASIC_PLUGINS,
json(),
url({ include: IMAGE_EXTENSIONS.map(ext => `**/*${ext}`) }),
postcss(postcssOpts),
// __DEV__ will always be replaced while `process.env.NODE_ENV` will be preserved except on production
prod
? [
replace(
define
? {
...defineValues,
__DEV__: JSON.stringify(false),
__PROD__: JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify(PROD),
}
: undefined,
),
terser(),
]
: replace(
define
].concat(
[
// __DEV__ will always be replaced while `process.env.NODE_ENV` will be preserved except on production
define &&
replace(
prod
? {
...defineValues,
__DEV__: JSON.stringify(false),
__PROD__: JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify(PROD),
}
: {
...defineValues,
__DEV__: JSON.stringify(__DEV__),
__PROD__: JSON.stringify(__PROD__),
}
: undefined,
},
),
prod && terser(),
].filter(identify),
),
}
})
Expand Down
10 changes: 6 additions & 4 deletions packages/umd-globals/test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import _, {
upperCamelCaseReducer,
} from '..'

const UPPER_CAMEL_CASE = 'upper-camel-case'

describe('umd globals', () => {
it('default export and `globals` named export should be same exactly ', () =>
expect(_).toBe(globals))
Expand Down Expand Up @@ -48,18 +50,18 @@ describe('reducer', () => {
expect(asIsReducer('as-is')).toStrictEqual({
'as-is': 'as-is',
})
expect(upperCamelCaseReducer('upper-camel-case')).toStrictEqual({
'upper-camel-case': 'UpperCamelCase',
expect(upperCamelCaseReducer(UPPER_CAMEL_CASE)).toStrictEqual({
[UPPER_CAMEL_CASE]: 'UpperCamelCase',
})
})
it('should work with single object param', () => {
expect(asIsReducer({ 'as-is': 'as-is' })).toStrictEqual({
'as-is': 'as-is',
})
expect(
upperCamelCaseReducer({ 'upper-camel-case': 'UpperCamelCase' }),
upperCamelCaseReducer({ [UPPER_CAMEL_CASE]: 'UpperCamelCase' }),
).toStrictEqual({
'upper-camel-case': 'UpperCamelCase',
[UPPER_CAMEL_CASE]: 'UpperCamelCase',
})
})
})
1 change: 1 addition & 0 deletions packages/utils/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function startBrowserProcess(

// Fallback to open
// (It will always open new tab)
// tslint:disable-next-line no-try-promise
try {
const options = { app: browser, wait: false }
open(url, options).catch(() => {}) // Prevent `unhandledRejection` error.
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const isSvelteAvailable = isPkgAvailable('svelte')

export const isVueAvailable = isPkgAvailable('vue')

export const tryFile = (filePath?: string | string[], includeDir?: boolean) => {
export const tryFile = (filePath?: string | string[], includeDir = false) => {
if (typeof filePath === 'string') {
return fs.existsSync(filePath) &&
(includeDir || fs.statSync(filePath).isFile())
Expand All @@ -50,6 +50,7 @@ export const identify = <T>(
_: T,
): _ is Exclude<
T,
// tslint:disable-next-line max-union-size
(T extends boolean ? false : boolean) | '' | null | undefined
> => !!_

Expand Down
16 changes: 11 additions & 5 deletions packages/webpack/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// tslint:disable no-big-function
import { resolve, sep } from 'path'

import { AngularCompilerPlugin } from '@ngtools/webpack'
import { alias } from '@pkgr/es-modules'
import {
Expand Down Expand Up @@ -29,7 +32,6 @@ import HtmlWebpackInlineSourcePlugin from 'html-webpack-inline-source-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import LazyCompileWebpackPlugin from 'lazy-compile-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { resolve, sep } from 'path'
import { sync } from 'postcss-load-config'
import TsconfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin'
import webpack, { Configuration } from 'webpack'
Expand All @@ -39,6 +41,7 @@ const info = debug('w:info')

export interface ConfigOptions {
entry?: string
// tslint:disable-next-line max-union-size
type?: 'angular' | 'react' | 'svelte' | 'vue'
outputDir?: string
copies?: Array<
Expand Down Expand Up @@ -66,13 +69,16 @@ const extraLoaderOptions: Record<string, {}> = {

const configsPath = resolve(__dirname, '../.config')

const CACHE_LOADER = 'cache-loader'

export default ({
entry = 'src',
outputDir = 'dist',
type,
copies = [],
prod = __PROD__,
}: ConfigOptions = {}) => {
}: // eslint-disable-next-line sonarjs/cognitive-complexity
ConfigOptions = {}) => {
entry = tryFile(
['index', 'main', 'app'].map(_ =>
tryExtensions(resolve([entry, _].join('/'))),
Expand Down Expand Up @@ -120,7 +126,7 @@ export default ({
},
}

const babelLoader = ['cache-loader', 'thread-loader', baseBabelLoader]
const babelLoader = [CACHE_LOADER, 'thread-loader', baseBabelLoader]

let postcssConfig:
| {
Expand Down Expand Up @@ -156,7 +162,7 @@ export default ({
: vue
? 'vue-style-loader'
: 'style-loader',
'cache-loader',
CACHE_LOADER,
{
loader: 'css-loader',
options: {
Expand Down Expand Up @@ -278,7 +284,7 @@ export default ({
oneOf: [
angular && {
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
use: ['cache-loader', baseBabelLoader, '@ngtools/webpack'],
use: [CACHE_LOADER, baseBabelLoader, '@ngtools/webpack'],
},
{
use: babelLoader,
Expand Down
6 changes: 2 additions & 4 deletions src/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ declare global {
}
}

if (process.env.NODE_ENV === 'development') {
if (window.ng && !window.ng.probe) {
window.ng.probe = noop
}
if (process.env.NODE_ENV === 'development' && window.ng && !window.ng.probe) {
window.ng.probe = noop
}
Loading

0 comments on commit ec3d54c

Please sign in to comment.