Skip to content

Commit

Permalink
feat: update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxdmm committed Feb 5, 2024
1 parent ee23654 commit ded682a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 46 deletions.
File renamed without changes.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"build": "esno ./scripts/build.ts",
"dev": "rollup -c rollup.config.js -w",
"dev": "rollup -c rollup.config.ts --configPlugin rollup-plugin-esbuild -w",
"lint": "eslint . --fix",
"test:dev": "vitest dev",
"test": "vitest run",
Expand All @@ -33,15 +33,15 @@
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"moxios": "^0.4.0",
"prettier": "^3.2.5",
"prettier-plugin-jsdoc": "^1.3.0",
"rimraf": "^5.0.5",
"rollup": "^4.9.6",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"vitest": "^1.2.2",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"prettier-plugin-jsdoc": "^1.3.0",
"rollup-plugin-pure": "^0.2.1",
"syncpack": "^12.3.0",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.2.2"
}
}
}
10 changes: 5 additions & 5 deletions packages/easy-axios/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export interface IHttpConfig<T> {
autoSetting: boolean
errorFlag: string
codeHandler: ICodeHandler<T>[]
request(config: AxiosRequestConfig, ins: SetupAxios<T>): AxiosRequestConfig
interceptorOptions(
request: (config: AxiosRequestConfig, ins: SetupAxios<T>) => AxiosRequestConfig
interceptorOptions: (
type: InterceptorOptionsType,
ins: SetupAxios<T>,
): AxiosInterceptorOptions
response(res: AxiosResponse, ins: SetupAxios<T>): AxiosResponse
transIns(ins: AxiosInstance, setUpIns: SetupAxios<T>): void
) => AxiosInterceptorOptions
response: (res: AxiosResponse, ins: SetupAxios<T>) => AxiosResponse
transIns: (ins: AxiosInstance, setUpIns: SetupAxios<T>) => void
}

export interface DynamicRequestConfig<T, R = any> {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/__tests__/object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('resutful', async () => {
it('get', () => {
const s = Symbol('obj')
const obj = {
a: {
'a': {
b: {
c: 1,
e: null,
Expand Down Expand Up @@ -89,10 +89,10 @@ describe('resutful', async () => {
},
}),
).toBe(null)
expect(get(obj, 'a.b.f', 20, (v) => v === '')).toBe(20)
expect(get(obj, 'a.b.f', 20, v => v === '')).toBe(20)
expect(
get(obj, 'a.b.f', 20, {
condition: (v) => v === '',
condition: v => v === '',
}),
).toBe(20)
expect(get(obj, 'a.b.c', 20, { strict: true })).toBe(10)
Expand Down
21 changes: 13 additions & 8 deletions packages/shared/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ export function get<T = any>(
emptyPathReturn: () => {
if (alterVal === undefined) {
return source as T
} else {
}
else {
if (config.warn) {
console.warn(
"Because your provided path is empty and alterValue is not undefined, so we use the default 'config.emptyPathReturn' to return the alterValue, If you want to change the result please pass your own emptyPathReturn function !",
'Because your provided path is empty and alterValue is not undefined, so we use the default \'config.emptyPathReturn\' to return the alterValue, If you want to change the result please pass your own emptyPathReturn function !',
)
}
return alterVal
}
},
}

if (isFunction(conditionOrConfig)) config.condition = conditionOrConfig
if (isFunction(conditionOrConfig))
config.condition = conditionOrConfig

if (isObject<GetConfig>(conditionOrConfig))
Object.assign(config, conditionOrConfig)
Expand All @@ -68,16 +70,18 @@ export function get<T = any>(

const resolvedPath: PrimitiveKey[] = strict
? !isArray(path)
? [path]
: path
? [path]
: path
: pathResolve(path)

if (resolvedPath.length === 0) return emptyPathBack()
if (resolvedPath.length === 0)
return emptyPathBack()

let result = source
for (let i = 0; i < resolvedPath.length; i++) {
const curPath = resolvedPath[i]
if (isString(curPath) && curPath.trim() === '') continue
if (isString(curPath) && curPath.trim() === '')
continue

if (isUndef(curPath)) {
if (!skipNullable)
Expand All @@ -89,7 +93,8 @@ export function get<T = any>(
if (condition(out)) {
result = alterCondition(resolvedPath.slice(0, i + 1), out, alterVal as T)
break
} else {
}
else {
result = out
}
}
Expand Down
2 changes: 0 additions & 2 deletions rollup.config.js

This file was deleted.

14 changes: 10 additions & 4 deletions scripts/rollup.config.ts → rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import type { OutputOptions, RollupOptions } from 'rollup'
import dts from 'rollup-plugin-dts'
import esbuild, { minify } from 'rollup-plugin-esbuild'
import { PluginPure as pure } from 'rollup-plugin-pure'
import { ModuleResolutionKind } from 'typescript'
import PreBundler from './bundler.json'

// TODO why?
// [!] SyntaxError: Named export 'ModuleResolutionKind' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
// CommonJS modules can always be imported via the default export, for example using:
// import pkg from 'typescript';
// const { ModuleResolutionKind } = pkg;
import pkg from 'typescript';
const { ModuleResolutionKind } = pkg;

const shouldBuildLibs = process.env?.PKGS?.split(',').filter(Boolean) || []
const namespace = '@monan/'
Expand All @@ -23,8 +29,8 @@ interface Meta {
rowPkg: Record<string, any>
}

const Bundler = PreBundler as unknown as Record<string, Meta>
const root = resolve(__dirname, '../')
const Bundler = JSON.parse(fs.readFileSync("./bundler.json").toString()) as unknown as Record<string, Meta>
const root = resolve('./')
const configs: RollupOptions[] = []
function getBundler(dir: string): Meta {
const pkgJson = JSON.parse(fs.readFileSync(join(dir, 'package.json')).toString())
Expand Down
6 changes: 3 additions & 3 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ async function work(
await task()
}

async function runRollup(isWatch) {
async function runRollup(isWatch: boolean) {
if (isWatch)
await $$`pnpm exec env-cmd -e build rollup -c rollup.config.js -w`
await $$`pnpm exec env-cmd -e build rollup -c rollup.config.ts --configPlugin rollup-plugin-esbuild -w`

else
await $$`pnpm exec env-cmd -e build rollup -c rollup.config.js`
await $$`pnpm exec env-cmd -e build rollup -c rollup.config.ts --configPlugin rollup-plugin-esbuild`
}

(async () => {
Expand Down
22 changes: 11 additions & 11 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
"@monan/*": ["packages/*/index.ts"]
},
"resolveJsonModule": true,
"strict": true,
"noImplicitThis": true,
"preserveValueImports": true,
"importsNotUsedAsValues": "error",
"ignoreDeprecations": "5.0",
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"types": ["node"],
"allowJs": true,
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"skipLibCheck": true,
"noImplicitThis": true,
"declaration": true,
"declarationMap": true,
"importHelpers": true,
"importsNotUsedAsValues": "error",
"preserveValueImports": true,
"ignoreDeprecations": "5.0",
"sourceMap": true,
"types": ["node"],
// "suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
},
"exclude": ["dist", "node_modules/"]
}
13 changes: 10 additions & 3 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"extends": "./tsconfig.base.json",
"include": ["scripts"],
"exclude": ["**/__tests__", "**/dist", "**/node_modules"]
}
"include": [
"scripts",
"rollup.config.ts"
],
"exclude": [
"**/__tests__",
"**/dist",
"**/node_modules"
]
}

0 comments on commit ded682a

Please sign in to comment.