Skip to content

Commit

Permalink
rename parsedConfig -> context
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Nov 21, 2022
1 parent bc1a409 commit 3c23d36
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/__snapshots__/context.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Vitest Snapshot v1

exports[`parseConfig > flags > rootDir=outDir 1`] = `"Directory rootDir(.) and outDir(.) are conflict! Please specify different directory for one of them."`;
4 changes: 2 additions & 2 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { Reporter } from './report';
import { cli } from './cli';
import { loadTargets } from './target';
import { loadImportMaps, normalizeImportMaps, validateImportMaps } from './importMaps';
import { getEntriesFromConfig } from './entry';
import { getEntriesFromContext } from './entry';
import { buildCommand } from './commands/build';
import { makePlugin as makeEmbedPlugin } from './plugins/esbuildEmbedPlugin';
import { makePlugin as makeImportMapsPlugin } from './plugins/esbuildImportMapsPlugin';
Expand Down Expand Up @@ -144,7 +144,7 @@ try {
const targets = await loadTargets({ basePath });
reporter.debug(`targets to ${targets.join(', ')}`);

const entries = getEntriesFromConfig({
const entries = getEntriesFromContext({
config,
reporter,
resolvePath,
Expand Down
6 changes: 3 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from 'esbuild';

import type { PathResolver } from './common';
import type { ParsedConfig } from './config';
import type { Context } from './context';
import type { Entry } from './entry';
import type { EntryGroup } from './entryGroup';
import type { Reporter } from './report';
Expand All @@ -32,7 +32,7 @@ interface MakeBuildOptions {
(props: {
resolvePath: PathResolver;
reporter: Reporter,
config: ParsedConfig,
config: Context,
entryGroup: EntryGroup,
targets: string[],
}): Promise<BuildOptions[]>;
Expand Down Expand Up @@ -105,7 +105,7 @@ export const makeBuildOptions: MakeBuildOptions = async ({
interface EnsureSourceFile {
(props: {
entry: Entry,
config: ParsedConfig,
config: Context,
resolvePath: PathResolver,
}): Promise<[string, string]>;
}
Expand Down
16 changes: 8 additions & 8 deletions src/config.test.ts → src/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, test, expect } from 'vitest';
import type { TSConfig } from 'pkg-types';

import { parseConfig } from './config';
import type { ParsedConfig } from './config';
import { parseConfig } from './context';
import type { Context } from './context';
import type { Flags } from './cli';
import type { Manifest } from './manifest';

Expand Down Expand Up @@ -37,7 +37,7 @@ describe('parseConfig', () => {
manifest: defaultManifest,
});

expect(result).toEqual<ParsedConfig>({
expect(result).toEqual<Context>({
cwd: '/project',
module: 'commonjs',
platform: 'netural',
Expand All @@ -60,7 +60,7 @@ describe('parseConfig', () => {
manifest: defaultManifest,
});

expect(result).toEqual<ParsedConfig>({
expect(result).toEqual<Context>({
cwd: '/project',
module: 'commonjs',
platform: 'netural',
Expand All @@ -82,7 +82,7 @@ describe('parseConfig', () => {
manifest: defaultManifest,
});

expect(result).toEqual<ParsedConfig>({
expect(result).toEqual<Context>({
cwd: '/project',
module: 'commonjs',
platform: 'netural',
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('parseConfig', () => {
tsconfig: defaultTsConfig,
});

expect(result).toEqual<ParsedConfig>({
expect(result).toEqual<Context>({
cwd: '/project',
module: 'commonjs',
platform: 'netural',
Expand All @@ -140,7 +140,7 @@ describe('parseConfig', () => {
},
});

expect(result).toEqual<ParsedConfig>({
expect(result).toEqual<Context>({
cwd: '/project',
module: 'commonjs',
platform: 'netural',
Expand All @@ -163,7 +163,7 @@ describe('parseConfig', () => {
tsconfig: defaultTsConfig,
});

expect(result).toEqual<ParsedConfig>({
expect(result).toEqual<Context>({
cwd: '/project',
module: 'commonjs',
platform: 'netural',
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts → src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class NanobundleConfigError extends Error {
name = 'NanobundleConfigError';
}

export type ParsedConfig = {
export type Context = {
cwd: string,
module: Entry['module'],
platform: Entry['platform'],
Expand All @@ -27,7 +27,7 @@ export type Config = {
};

interface ParseConfig {
(config: Config): ParsedConfig;
(config: Config): Context;
}
export const parseConfig: ParseConfig = ({
flags,
Expand Down
12 changes: 6 additions & 6 deletions src/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as path from "node:path";
import { describe, test, expect, vi } from "vitest";

import type { Flags } from './cli';
import { parseConfig } from "./config";
import { parseConfig } from './context';
import type { Manifest } from "./manifest";
import type { Reporter } from "./report";
import type { Entry } from "./entry";
import { getEntriesFromConfig } from "./entry";
import { getEntriesFromContext } from "./entry";

describe("getEntriesFromConfig", () => {
describe("getEntriesFromContext", () => {
const resolvePath = (cwd: string, to: string) => path.join(cwd, to);

const reporter: Reporter = {
Expand All @@ -33,13 +33,13 @@ describe("getEntriesFromConfig", () => {
};

const getEntriesFromManifest = (manifest: Manifest) => {
const config = parseConfig({
const context = parseConfig({
flags: defaultFlags,
manifest,
});

return getEntriesFromConfig({
config,
return getEntriesFromContext({
context,
resolvePath,
reporter,
});
Expand Down
12 changes: 6 additions & 6 deletions src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'node:path';
import type { ConditionalExport } from './manifest';
import type { ParsedConfig } from './config';
import type { Context } from './context';
import type { Reporter } from './report';

export type Entry = {
Expand All @@ -15,15 +15,15 @@ export type Entry = {
outputFile: string;
};

interface GetEntriesFromConfig {
interface GetEntriesFromContext {
(props: {
config: ParsedConfig;
context: Context;
resolvePath: (cwd: string, path: string) => string;
reporter: Reporter;
}): Entry[];
}
export const getEntriesFromConfig: GetEntriesFromConfig = ({
config,
export const getEntriesFromContext: GetEntriesFromContext = ({
context,
reporter,
resolvePath: resolvePathFrom,
}) => {
Expand All @@ -37,7 +37,7 @@ export const getEntriesFromConfig: GetEntriesFromConfig = ({
module: defaultModule,
sourcemap,
manifest,
} = config;
} = context;
const resolvePath = (path: string) => resolvePathFrom(cwd, path);
const resolvedRootDir = resolvePath(rootDir);
const resolvedOutDir = resolvePath(outDir);
Expand Down

0 comments on commit 3c23d36

Please sign in to comment.