UNPKG

1.99 kBPlain TextView Raw
1import * as webpack from "webpack";
2import * as fs from "fs-extra";
3import * as path from "path";
4import {Logger} from "@simplism/core";
5import * as child_process from "child_process";
6
7export class TsCheckAndDeclarationPlugin implements webpack.Plugin {
8 public constructor(private readonly _options: {
9 tsConfigPath?: string;
10 packageName: string;
11 logger: Logger;
12 projectPath?: string;
13 }) {
14
15 }
16
17 public apply(compiler: webpack.Compiler): void {
18 let worker: child_process.ChildProcess;
19 compiler.hooks.watchRun.tap("TsCheckAndDeclarationPlugin", () => {
20 if (!worker) {
21 worker = child_process.fork(
22 this._loadersPath("ts-check-and-declaration-worker.js"),
23 [
24 this._options.packageName,
25 "watch",
26 this._options.tsConfigPath
27 ].filterExists(),
28 {
29 stdio: [undefined, undefined, undefined, "ipc"]
30 }
31 );
32 worker.on("message", message => {
33 this._options.logger.error(`타입 에러:`, message);
34 });
35 }
36 });
37
38 compiler.hooks.run.tap("TsCheckAndDeclarationPlugin", () => {
39 worker = child_process.fork(
40 this._loadersPath("ts-check-and-declaration-worker.js"),
41 [
42 this._options.packageName,
43 "build",
44 this._options.tsConfigPath
45 ].filterExists(),
46 {
47 stdio: [undefined, undefined, undefined, "ipc"]
48 }
49 );
50 worker.on("message", message => {
51 this._options.logger.error(`타입 에러:`, message);
52 });
53 });
54 }
55
56 private _loadersPath(...args: string[]): string {
57 return fs.existsSync(path.resolve(this._options.projectPath || process.cwd(), "node_modules/@simplism/cli/loaders"))
58 ? path.resolve(this._options.projectPath || process.cwd(), "node_modules/@simplism/cli/loaders", ...args)
59 : path.resolve(__dirname, "../../loaders", ...args);
60 }
61}
\No newline at end of file