Skip to content

Commit

Permalink
feat: /basic, /core and /browser subpath exports (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Apr 18, 2023
1 parent c8c0d52 commit 17df639
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ Will display in the terminal:

<img width="760" alt="image" src="https://user-images.githubusercontent.com/5158436/231029244-abc79f48-ca16-4eaa-b592-7abd271ecb1f.png">

You can use smaller core builds without fancy reporter to save 80% of the bundle size:

```ts
import { consola, createConsola } from "consola/basic";
import { consola, createConsola } from "consola/browser";
import { createConsola } from "consola/core";
```

## Methods

#### `<type>(logObject)` `<type>(args...)`
Expand Down
1 change: 1 addition & 0 deletions basic.d.ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/index.basic";
1 change: 1 addition & 0 deletions browser.d.ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/index.browser";
1 change: 1 addition & 0 deletions core.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/index.core";
26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,36 @@
"types": "./dist/index.browser.d.ts",
"import": "./dist/index.browser.mjs"
}
},
"./browser": {
"types": "./dist/index.browser.d.ts",
"import": "./dist/index.browser.mjs"
},
"./basic": {
"node": {
"types": "./dist/index.basic.d.ts",
"import": "./dist/index.basic.mjs",
"require": "./dist/index.basic.cjs"
},
"default": {
"types": "./dist/index.browser.d.ts",
"import": "./dist/index.browser.mjs"
}
},
"./core": {
"types": "./dist/index.core.d.ts",
"import": "./dist/index.core.mjs",
"require": "./dist/index.core.cjs"
}
},
"main": "./lib/index.cjs",
"module": "./dist/index.mjs",
"browser": "./dist/index.browser.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"lib"
"lib",
"*.d.ts"
],
"scripts": {
"build": "unbuild",
Expand Down Expand Up @@ -70,4 +92,4 @@
"winston": "^3.8.2"
},
"packageManager": "[email protected]"
}
}
2 changes: 1 addition & 1 deletion src/consola.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Consola.prototype.pause = Consola.prototype.pauseLogs;
Consola.prototype.resume = Consola.prototype.resumeLogs;

export function createConsola(
options: Partial<ConsolaOptions>
options: Partial<ConsolaOptions> = {}
): ConsolaInstance {
return new Consola(options) as ConsolaInstance;
}
32 changes: 32 additions & 0 deletions src/index.basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LogLevels, LogLevel } from "./constants";
import type { ConsolaOptions } from "./types";
import { BasicReporter } from "./reporters/basic";
import { ConsolaInstance, createConsola as _createConsola } from "./consola";

export * from "./index.shared";

export function createConsola(
options: Partial<ConsolaOptions & { fancy: boolean }> = {}
): ConsolaInstance {
// Log level
let level: LogLevel = LogLevels.info;
if (process.env.CONSOLA_LEVEL) {
level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
}

// Create new consola instance
const consola = _createConsola({
level,
defaults: { level },
stdout: process.stdout,
stderr: process.stderr,
reporters: options.reporters || [new BasicReporter()],
...options,
});

return consola;
}

export const consola = createConsola();

export default consola;
2 changes: 2 additions & 0 deletions src/index.core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { createConsola } from "./consola";
export * from "./index.shared";

0 comments on commit 17df639

Please sign in to comment.