Skip to content

Commit

Permalink
refactor: rename api of builtin-build export
Browse files Browse the repository at this point in the history
BREAKING CHANGES: rename `stopService` in `@siujs/builtin-build`
     - `stopService` => `stopEsBuildService`
     - export new api `startEsBuildService`
  • Loading branch information
buns committed Jan 19, 2021
1 parent c00fb81 commit c894748
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/builtin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ await builder.build({allowFormats:["umd-min"],sizeCalc:false}); // will create f
2. `rollup`+`esbuild`+multiple packages

```js
import { esbuildRollupPlugin, Config, SiuRollupBuilder, stopService, TOutputFormatKey } from "@siujs/builtin-build";
import { esbuildRollupPlugin, Config, SiuRollupBuilder, stopEsBuildService, TOutputFormatKey } from "@siujs/builtin-build";

const pkgDatas = [{
root:"../xxx",
Expand Down Expand Up @@ -93,7 +93,7 @@ for(let l = pkgDatas.length;l--;){
await builder.build({allowFormats:["es"]});
}

stopService();
stopEsBuildService();

// 设置closeImmedicate=false,可以让esbuild进程一直激活态,不会去关闭,这样可以可以节省多次开启和关闭带来的损耗;
// 一般在做批量packages构建使用esbuild的service情况下,都尽量设置closeImmedicate=false
Expand Down
10 changes: 5 additions & 5 deletions packages/builtin-build/lib/esbuildService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const debug = createDebugger("siu:build.esbuild");
// lazy start the service
let _service: Service;

const ensureService = async () => {
export const startEsBuildService = async () => {
if (!_service) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
_service = await require("esbuild").startService();
}
return _service;
};

export const stopService = () => {
export const stopEsBuildService = () => {
_service && _service.stop();
_service = undefined;
};
Expand Down Expand Up @@ -63,7 +63,7 @@ export async function esbuildTransform(
options: TransformOptions,
onwarn: (m: any, file: string, src: string) => void
): Promise<TransformResult> {
const service = await ensureService();
const service = await startEsBuildService();

const opts = {
loader,
Expand Down Expand Up @@ -150,7 +150,7 @@ export function esbuildRollupPlugin() {
return {
name: "esbuild",
async buildStart() {
ensureService();
startEsBuildService();
},
resolveId(importee, importer) {
if (!importer) return;
Expand Down Expand Up @@ -186,7 +186,7 @@ export function esbuildRollupPlugin() {
return esbuildTransform(code, id, loader, esbuildOptions, onwarn);
},
buildEnd() {
closeImmediate !== false && stopService();
closeImmediate !== false && stopEsBuildService();
}
} as Plugin;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/builtins/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
esbuildRollupPlugin,
SiuRollupBuilder,
SiuRollupConfig,
stopService,
stopEsBuildService,
TOutputFormatKey
} from "@siujs/builtin-build";
import { HookHandlerContext, PluginApi, ValueOf } from "@siujs/core";
Expand All @@ -30,6 +30,6 @@ export function asBuildFallback(api: ValueOf<PluginApi>) {
});

api.clean(() => {
stopService();
stopEsBuildService();
});
}

0 comments on commit c894748

Please sign in to comment.