From 3c23d36f6a79158ac5f3bf359d56330be3bb2890 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 21 Nov 2022 10:12:01 +0900 Subject: [PATCH] rename parsedConfig -> context --- src/__snapshots__/context.test.ts.snap | 3 +++ src/bin.ts | 4 ++-- src/build.ts | 6 +++--- src/{config.test.ts => context.test.ts} | 16 ++++++++-------- src/{config.ts => context.ts} | 4 ++-- src/entry.test.ts | 12 ++++++------ src/entry.ts | 12 ++++++------ 7 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 src/__snapshots__/context.test.ts.snap rename src/{config.test.ts => context.test.ts} (91%) rename src/{config.ts => context.ts} (96%) diff --git a/src/__snapshots__/context.test.ts.snap b/src/__snapshots__/context.test.ts.snap new file mode 100644 index 00000000..8185e7db --- /dev/null +++ b/src/__snapshots__/context.test.ts.snap @@ -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."`; diff --git a/src/bin.ts b/src/bin.ts index 36aa7528..7f17bcf6 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -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'; @@ -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, diff --git a/src/build.ts b/src/build.ts index 1eb85c3f..3fdfa912 100644 --- a/src/build.ts +++ b/src/build.ts @@ -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'; @@ -32,7 +32,7 @@ interface MakeBuildOptions { (props: { resolvePath: PathResolver; reporter: Reporter, - config: ParsedConfig, + config: Context, entryGroup: EntryGroup, targets: string[], }): Promise; @@ -105,7 +105,7 @@ export const makeBuildOptions: MakeBuildOptions = async ({ interface EnsureSourceFile { (props: { entry: Entry, - config: ParsedConfig, + config: Context, resolvePath: PathResolver, }): Promise<[string, string]>; } diff --git a/src/config.test.ts b/src/context.test.ts similarity index 91% rename from src/config.test.ts rename to src/context.test.ts index ee78a04d..89bb93d0 100644 --- a/src/config.test.ts +++ b/src/context.test.ts @@ -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'; @@ -37,7 +37,7 @@ describe('parseConfig', () => { manifest: defaultManifest, }); - expect(result).toEqual({ + expect(result).toEqual({ cwd: '/project', module: 'commonjs', platform: 'netural', @@ -60,7 +60,7 @@ describe('parseConfig', () => { manifest: defaultManifest, }); - expect(result).toEqual({ + expect(result).toEqual({ cwd: '/project', module: 'commonjs', platform: 'netural', @@ -82,7 +82,7 @@ describe('parseConfig', () => { manifest: defaultManifest, }); - expect(result).toEqual({ + expect(result).toEqual({ cwd: '/project', module: 'commonjs', platform: 'netural', @@ -115,7 +115,7 @@ describe('parseConfig', () => { tsconfig: defaultTsConfig, }); - expect(result).toEqual({ + expect(result).toEqual({ cwd: '/project', module: 'commonjs', platform: 'netural', @@ -140,7 +140,7 @@ describe('parseConfig', () => { }, }); - expect(result).toEqual({ + expect(result).toEqual({ cwd: '/project', module: 'commonjs', platform: 'netural', @@ -163,7 +163,7 @@ describe('parseConfig', () => { tsconfig: defaultTsConfig, }); - expect(result).toEqual({ + expect(result).toEqual({ cwd: '/project', module: 'commonjs', platform: 'netural', diff --git a/src/config.ts b/src/context.ts similarity index 96% rename from src/config.ts rename to src/context.ts index 14272c15..902f16ab 100644 --- a/src/config.ts +++ b/src/context.ts @@ -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'], @@ -27,7 +27,7 @@ export type Config = { }; interface ParseConfig { - (config: Config): ParsedConfig; + (config: Config): Context; } export const parseConfig: ParseConfig = ({ flags, diff --git a/src/entry.test.ts b/src/entry.test.ts index fc3e5f12..b53502f2 100644 --- a/src/entry.test.ts +++ b/src/entry.test.ts @@ -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 = { @@ -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, }); diff --git a/src/entry.ts b/src/entry.ts index b0e1522d..5c300595 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -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 = { @@ -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, }) => { @@ -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);