Skip to content

Commit

Permalink
chore: Withdraw tsc logic code
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Oct 13, 2024
1 parent 66c6e96 commit 936a259
Show file tree
Hide file tree
Showing 50 changed files with 199 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"biome.enabled": true,
"editor.defaultFormatter": "biomejs.biome",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "biomejs.biome"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
2 changes: 1 addition & 1 deletion examples/refactor-react/farm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default defineConfig({
// alias: {
// "@": path.resolve("src"),
// },
alias: [{ find: "@", replacement: path.resolve("src") }],
// alias: [{ find: "@", replacement: path.resolve("src") }],
},
},
// timeUnit: "s",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {
resolveCliConfig,
resolveCommandOptions,
resolveCore
} from './utils';
} from './utils.js';

import type {
CleanOptions,
CliBuildOptions,
CliPreviewOptions,
CliServerOptions,
GlobalCliOptions
} from './types';
} from './types.js';

const cli = cac('farm');

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"outDir": "dist",
"declaration": false,
"noUnusedLocals": false,
"noUnusedParameters": false
"noUnusedParameters": false,
},
"exclude": ["node_modules"],
"include": ["src/**/*"],
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import path from 'node:path';

import { Compiler as BindingCompiler } from '../../binding/index';
import { Compiler as BindingCompiler } from '../../binding/index.js';
import type {
ResolvedCompilation,
ResolvedUserConfig,
Resource
} from '../index';
import type { JsUpdateResult } from '../types/binding';
} from '../index.js';
import type { JsUpdateResult } from '../types/binding.js';

export const VIRTUAL_FARM_DYNAMIC_IMPORT_SUFFIX =
'.farm_dynamic_import_virtual_module' as const;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import path from 'node:path';

import { parse } from 'dotenv';
import { type DotenvPopulateInput, expand } from 'dotenv-expand';
import { arraify, normalizePath, tryStatSync } from '../utils/index';
import { arraify, normalizePath, tryStatSync } from '../utils/index.js';

export function loadEnv(
mode: string,
Expand Down
40 changes: 20 additions & 20 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import path from 'node:path';
import { pathToFileURL } from 'node:url';
import fse from 'fs-extra';

import { bindingPath } from '../../binding/index';
import { OutputConfig } from '../types/binding';
import { bindingPath } from '../../binding/index.js';
import { OutputConfig } from '../types/binding.js';

import { JsPlugin } from '../index';
import { JsPlugin } from '../index.js';
import {
getSortedPlugins,
handleVitePlugins,
resolveAsyncPlugins,
resolveConfigHook,
resolveConfigResolvedHook,
resolveFarmPlugins
} from '../plugin/index';
} from '../plugin/index.js';
import {
Logger,
clearScreen,
Expand All @@ -26,9 +26,9 @@ import {
isObject,
isWindows,
normalizePath
} from '../utils/index';
import { traceDependencies } from '../utils/trace-dependencies';
import { __FARM_GLOBAL__ } from './_global';
} from '../utils/index.js';
import { traceDependencies } from '../utils/trace-dependencies.js';
import { __FARM_GLOBAL__ } from './_global.js';
import {
CompilationMode,
getExistsEnvFiles,
Expand All @@ -38,23 +38,23 @@ import {
import {
getValidPublicPath,
normalizeOutput
} from './normalize-config/normalize-output';
import { normalizePersistentCache } from './normalize-config/normalize-persistent-cache';
import { parseUserConfig } from './schema';

import { externalAdapter } from '../plugin/js/external-adapter';
import { convertErrorMessage } from '../utils/error';
import { resolveHostname } from '../utils/http';
import merge from '../utils/merge';
} from './normalize-config/normalize-output.js';
import { normalizePersistentCache } from './normalize-config/normalize-persistent-cache.js';
import { parseUserConfig } from './schema.js';

import { externalAdapter } from '../plugin/js/external-adapter.js';
import { convertErrorMessage } from '../utils/error.js';
import { resolveHostname } from '../utils/http.js';
import merge from '../utils/merge.js';
import {
CUSTOM_KEYS,
DEFAULT_CONFIG_NAMES,
FARM_DEFAULT_NAMESPACE
} from './constants';
import { mergeConfig, mergeFarmCliConfig } from './mergeConfig';
import { normalizeCss } from './normalize-config/normalize-css';
import { normalizeExternal } from './normalize-config/normalize-external';
import { normalizeResolve } from './normalize-config/normalize-resolve';
} from './constants.js';
import { mergeConfig, mergeFarmCliConfig } from './mergeConfig.js';
import { normalizeCss } from './normalize-config/normalize-css.js';
import { normalizeExternal } from './normalize-config/normalize-external.js';
import { normalizeResolve } from './normalize-config/normalize-resolve.js';
import type {
ConfigEnv,
FarmCliOptions,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/config/mergeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path, { isAbsolute } from 'node:path';
import { isString } from '../plugin/js/utils';
import { isArray, isObject } from '../utils/share';
import { FarmCliOptions, UserConfig } from './types';
import { isString } from '../plugin/js/utils.js';
import { isArray, isObject } from '../utils/share.js';
import { FarmCliOptions, UserConfig } from './types.js';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function mergeConfig<T extends Record<string, any>>(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/config/normalize-config/normalize-css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CUSTOM_KEYS } from '../constants';
import { ResolvedCompilation, UserConfig } from '../types';
import { CUSTOM_KEYS } from '../constants.js';
import { ResolvedCompilation, UserConfig } from '../types.js';
export function normalizeCss(
config: UserConfig,
resolvedCompilation: ResolvedCompilation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import module from 'node:module';
import { existsSync, readFileSync } from 'node:fs';
import path from 'node:path';

import { Config } from '../../types/binding';
import { isObject, safeJsonParse } from '../../utils';
import { CUSTOM_KEYS } from '../constants';
import { Config } from '../../types/binding.js';
import { isObject, safeJsonParse } from '../../utils/index.js';
import { CUSTOM_KEYS } from '../constants.js';

import type { ResolvedCompilation, UserConfig } from '../types';
import type { ResolvedCompilation, UserConfig } from '../types.js';

type PartialExternal = [string[], Record<string, string>];

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/config/normalize-config/normalize-output.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { browsersWithSupportForFeatures } from 'farm-browserslist-generator';

import path, { isAbsolute } from 'node:path';
import { Config } from '../../types/binding';
import { urlRegex } from '../../utils/http';
import { Logger } from '../../utils/logger';
import { Config } from '../../types/binding.js';
import { urlRegex } from '../../utils/http.js';
import { Logger } from '../../utils/logger.js';
import {
FARM_TARGET_BROWSER_ENVS,
mapTargetEnvValue,
normalizePath
} from '../../utils/share';
import { ResolvedCompilation } from '../types';
} from '../../utils/share.js';
import { ResolvedCompilation } from '../types.js';

export function normalizeOutput(
config: ResolvedCompilation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { existsSync, readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import path from 'node:path';

import { RustPlugin } from '../../plugin/index';
import { Config } from '../../types/binding';
import { traceDependencies } from '../../utils/trace-dependencies';
import { isDisableCache } from '../env';
import { ResolvedUserConfig } from '../index';
import { RustPlugin } from '../../plugin/index.js';
import { Config } from '../../types/binding.js';
import { traceDependencies } from '../../utils/trace-dependencies.js';
import { isDisableCache } from '../env.js';
import { ResolvedUserConfig } from '../index.js';

const defaultGlobalBuiltinCacheKeyStrategy = {
define: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CUSTOM_KEYS } from '../constants';
import { ResolvedCompilation, UserConfig } from '../types';
import { CUSTOM_KEYS } from '../constants.js';
import { ResolvedCompilation, UserConfig } from '../types.js';

export function normalizeResolve(
config: UserConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SecureServerOptions } from 'node:http2';
import { z } from 'zod';
import { fromZodError } from 'zod-validation-error';

import type { UserConfig } from './types';
import type { UserConfig } from './types.js';

const TARGET_ENV = {
BROWSER: 'browser',
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SecureServerOptions } from 'node:http2';
import { Server } from '../index';
import { Server } from '../index.js';

import type { OutgoingHttpHeaders } from 'http';
import { WatchOptions } from 'chokidar';
import type { RustPlugin } from '../plugin/rust/index';
import type { JsPlugin } from '../plugin/type';
import { HMRChannel } from '../server/hmr';
import type { Config, CssConfig } from '../types/binding';
import type { Logger } from '../utils/index';
import type { RustPlugin } from '../plugin/rust/index.js';
import type { JsPlugin } from '../plugin/type.js';
import { HMRChannel } from '../server/hmr.js';
import type { Config, CssConfig } from '../types/binding.js';
import type { Logger } from '../utils/index.js';

// export interface HmrOptions {
// protocol?: string;
Expand Down
41 changes: 22 additions & 19 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
export * from './compiler/index';
export * from './config/index';
export * from './server/index';
export * from './plugin/type';
export * from './utils/index';
export * from './compiler/index.js';
export * from './config/index.js';
export * from './server/index.js';
export * from './plugin/type.js';
export * from './utils/index.js';

export { defineFarmConfig as defineConfig } from './config/index';
export { defineFarmConfig as defineConfig } from './config/index.js';

export type { Compiler as BindingCompiler } from './types/binding';
export type { Compiler as BindingCompiler } from './types/binding.js';

import fs from 'node:fs/promises';

import { createCompiler } from './compiler/index';
import { __FARM_GLOBAL__ } from './config/_global';
import { UserConfig, resolveConfig } from './config/index';
import { getPluginHooks } from './plugin/index';
import { Server } from './server/index';
import { PersistentCacheConfig } from './types/binding';
import { PersistentCacheBrand, bold, colors, green } from './utils/color';
import { createCompiler } from './compiler/index.js';
import { __FARM_GLOBAL__ } from './config/_global.js';
import { UserConfig, resolveConfig } from './config/index.js';
import { getPluginHooks } from './plugin/index.js';
import { Server } from './server/index.js';
import { PersistentCacheConfig } from './types/binding.js';
import {
PersistentCacheBrand,
bold,
colors,
copyPublicDirectory,
findNodeModulesRecursively
} from './utils/fsUtils.js';
import { getShortName } from './utils/path';
import { handlerWatcher } from './watcher/index';
findNodeModulesRecursively,
getShortName,
green
} from './utils/index.js';
import { handlerWatcher } from './watcher/index.js';

import type { FarmCliOptions } from './config/types';
import type { FarmCliOptions } from './config/types.js';

export async function start(
inlineConfig?: FarmCliOptions & UserConfig
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isArray, isObject } from '../utils';
import { convertPlugin } from './js/index';
import { rustPluginResolver } from './rust';
import { isArray, isObject } from '../utils/index.js';
import { convertPlugin } from './js/index.js';
import { rustPluginResolver } from './rust/index.js';

import { ResolvedUserConfig, type UserConfig } from '../config';
import merge from '../utils/merge';
import type { JsPlugin } from './type';
import { ResolvedUserConfig, type UserConfig } from '../config/index.js';
import merge from '../utils/merge.js';
import type { JsPlugin } from './type.js';

export * from './js';
export * from './rust';
export * from './js/index.js';
export * from './rust/index.js';

export async function resolveFarmPlugins(config: UserConfig) {
const plugins = config.plugins ?? [];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugin/js/adapter-plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 2. unwrap the css code from `` after post plugins execute
*/

import { JsPlugin } from '../../type';
import { normalizeFilterPath } from '../utils';
import { JsPlugin } from '../../type.js';
import { normalizeFilterPath } from '../utils.js';

const BEGIN = '__farm_vite_css_hack_start__=`';
const END = '`;__farm_vite_css_hack_end__';
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/plugin/js/adapter-plugins/default-load.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { existsSync, readFileSync } from 'node:fs';
import { isAbsolute } from 'node:path';
import { UserConfig } from '../../../config/types';
import { Logger } from '../../../utils/logger';
import { JsPlugin } from '../../type';
import { UserConfig } from '../../../config/types.js';
import { Logger } from '../../../utils/logger.js';
import { JsPlugin } from '../../type.js';
import {
VITE_PLUGIN_DEFAULT_MODULE_TYPE,
getCssModuleType,
normalizeFilterPath
} from '../utils';
import { VitePluginAdapter } from '../vite-plugin-adapter';
} from '../utils.js';
import { VitePluginAdapter } from '../vite-plugin-adapter.js';

export function defaultLoadPlugin(options: {
filtersUnion: Set<string>;
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/plugin/js/external-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CUSTOM_KEYS } from '../../config/constants';
import { CUSTOM_KEYS } from '../../config/constants.js';
import {
mergeCustomExternal,
partialExternal
} from '../../config/normalize-config/normalize-external';
import { UserConfig } from '../../config/types';
import { isArray } from '../../utils/share';
import { JsPlugin } from '../type';
} from '../../config/normalize-config/normalize-external.js';
import { UserConfig } from '../../config/types.js';
import { isArray } from '../../utils/share.js';
import { JsPlugin } from '../type.js';

/**
* avoid add new external in config hook
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/plugin/js/farm-to-vite-config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { UserConfig as ViteUserConfig } from 'vite';
import type { UserConfig } from '../../config/types';
import { Logger } from '../../index';
import merge from '../../utils/merge';
import { EXTERNAL_KEYS, VITE_DEFAULT_ASSETS } from './constants';
import type { UserConfig } from '../../config/types.js';
import { Logger } from '../../index.js';
import merge from '../../utils/merge.js';
import { EXTERNAL_KEYS, VITE_DEFAULT_ASSETS } from './constants.js';
import {
deleteUndefinedPropertyDeeply,
throwIncompatibleError
Expand Down
Loading

0 comments on commit 936a259

Please sign in to comment.