Skip to content

Commit 2a546c9

Browse files
authored
fix: export types (#556)
* fix: export types * chore: rename main entry file * chore: export types to correct path
1 parent 36175b8 commit 2a546c9

File tree

9 files changed

+33
-32
lines changed

9 files changed

+33
-32
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ typescript:
2020
@git reset master --soft && git add --all && git commit -m "chore: typescript"
2121
@echo "typescript: branch created, merge to master to complete coversion"
2222

23-
build:
23+
clean:
24+
rm -rf ./lib
2425
rm -rf ./built
26+
27+
build: clean
2528
npm run build-types
2629
npm run build
2730

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
"node": ">=8",
2323
"npm": ">=6"
2424
},
25-
"main": "main.js",
26-
"types": "main.d.ts",
25+
"main": "index.js",
26+
"types": "index.d.ts",
2727
"scripts": {
2828
"lint": "eslint ./src ./tests --ext .js,.ts",
2929
"commitlint": "commitlint-travis",
3030
"build": "webpack --mode=production",
3131
"build-watch": "webpack --mode=development --watch",
32-
"build-types": "rm -rf ./built && tsc --emitDeclarationOnly",
32+
"build-types": "tsc --emitDeclarationOnly",
3333
"test": "jest",
3434
"coveralls": "cat ./artifacts/coverage/lcov.info | coveralls",
3535
"typecheck": "tsc --noEmit",

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Stage } from "./types";
2+
13
const stageMessage = (m: TemplateStringsArray) => (m ? `\n${String(m)}` : "");
24

35
export const defaultStageMessages: Record<

src/globals.d.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Compiler } from "webpack";
22

33
import { logger } from "./logger";
44
import { defaultStageMessages } from "./constants";
5+
import { Options, Stage, StageListeners } from "./types";
56

67
const defaultListeners: Partial<StageListeners> = {
78
buildError: (e: Error) => {

src/types.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type Listener = (...args: any[]) => any | Promise<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
2+
3+
export type Stage =
4+
| "buildEnd"
5+
| "buildError"
6+
| "buildStart"
7+
| "compileEnd"
8+
| "compileStart"
9+
| "interrupt";
10+
export type StageListeners = Record<Stage, Listener>;
11+
export type StageMessages = Record<Stage, { enter?: string; exit?: string }>;
12+
13+
export interface Options {
14+
name: string;
15+
stageMessages?: Partial<StageMessages>;
16+
listeners: Partial<StageListeners>;
17+
}

tests/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Compiler } from "webpack";
22
import { WebpackCompilerPlugin } from "index";
33
import { logger } from "logger";
4+
import { Stage, StageListeners, StageMessages } from "../src/types";
45

56
const processExitSpy = jest
67
.spyOn(process, "exit")

webpack.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from "path";
22
import { Configuration } from "webpack";
33
import * as CopyPlugin from "copy-webpack-plugin";
44

5+
const outputPath = path.resolve(__dirname, "lib");
56
const configuration: Configuration = {
67
devtool: "source-map",
78
entry: "./src",
@@ -25,18 +26,17 @@ const configuration: Configuration = {
2526
],
2627
},
2728
output: {
28-
filename: "main.js",
29+
filename: "index.js",
2930
libraryTarget: "commonjs",
30-
path: path.resolve(__dirname, "lib"),
31+
path: outputPath,
3132
},
3233
plugins: [
3334
new CopyPlugin({
3435
patterns: [
35-
{ from: "built/src/index.d.ts", to: "main.d.ts" },
36-
"built/src/constants.d.ts",
37-
"src/globals.d.ts",
3836
"package.json",
3937
"README.md",
38+
"built/src",
39+
{ from: "src/types.d.ts", to: outputPath },
4040
],
4141
}),
4242
],

0 commit comments

Comments
 (0)