Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Dec 3, 2022
1 parent 9f90d8a commit c69caaf
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 417 deletions.
17 changes: 14 additions & 3 deletions src/__snapshots__/entry.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// Vitest Snapshot v1

exports[`getEntriesFromContext - in TypeScript project > types entry does not accept nesting 1`] = `"\\"types\\" entry must be .d.ts file and cannot be nested!"`;
exports[`getEntriesFromContext > throw if "main" and "module" is on conflict 1`] = `
"Hint: Did you forgot to set \\"type\\" to 'module' for ESM-first approach?
"
`;

exports[`getEntriesFromContext - in TypeScript project > types entry must has .d.ts extension 1`] = `"\\"types\\" entry must has .d.ts extension!"`;
exports[`getEntriesFromContext - in TypeScript project > types entry does not accept nesting 1`] = `
"\\"types\\" entry must be .d.ts file and cannot be nested!
"
`;

exports[`getEntriesFromContext - in TypeScript project > types entry must occur first in conditional exports 1`] = `"\\"types\\" entry must occur first in conditional exports for correct type resolution."`;
exports[`getEntriesFromContext - in TypeScript project > types entry must has .d.ts extension 1`] = `"Only .d.ts or .d.cts or .d.mts allowed for \\"types\\" entry."`;

exports[`getEntriesFromContext - in TypeScript project > types entry must occur first in conditional exports 1`] = `
"\\"types\\" entry must occur first in conditional exports for correct type resolution.
"
`;
4 changes: 2 additions & 2 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parse as parseTsConfig } from 'tsconfck';
import dedent from 'string-dedent';

import { cli } from './cli';
import { Reporter } from './reporter';
import { ConsoleReporter } from './reporter';
import { loadTargets } from './target';
import { loadManifest } from './manifest';
import { parseConfig } from './context';
Expand All @@ -15,7 +15,7 @@ import { buildCommand } from './commands/build/build';
const { flags, input } = cli;
const [command] = input;

const reporter = new Reporter(console);
const reporter = new ConsoleReporter(console);
reporter.level = process.env.DEBUG === 'true' ? 'debug' : 'default';

const resolve = (cwd: string, subpath: string) => path.resolve(cwd, subpath);
Expand Down
12 changes: 10 additions & 2 deletions src/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import { type PathResolver } from './common';
import { type Context } from './context';
import { type Flags } from './cli';
import { type Manifest } from './manifest';
import { Reporter } from './reporter';
import { type Reporter } from './reporter';
import { parseConfig } from './context';

class ViReporter implements Reporter {
debug = vi.fn();
info = vi.fn();
warn = vi.fn();
error = vi.fn();
captureException = vi.fn();
}

describe('parseConfig', () => {
const reporter = new Reporter(console);
const reporter = new ViReporter();
const resolve: PathResolver = vi.fn();
const defaultFlags: Flags = {
cwd: '/project',
Expand Down
Loading

0 comments on commit c69caaf

Please sign in to comment.