Skip to content

Commit 8e76286

Browse files
authored
feat: upgrade dependence & option sort & add output option (#20)
1 parent fe54ea3 commit 8e76286

File tree

7 files changed

+84
-65
lines changed

7 files changed

+84
-65
lines changed

.changeset/great-keys-beg.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'farmup': patch
3+
---
4+
5+
upgrade dependence & option sort & add output option

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ feature
1212

1313
- cross import CommonJs and EsModule
1414
- watch mode
15+
- support html
1516

1617
## Setup
1718

@@ -54,9 +55,7 @@ farmup build index.ts --no-exec
5455
- more cli options
5556
- sourcemap
5657
- ignore some watch file
57-
- command output
58-
- start to tmp file
59-
- build to local file
58+
- execute without output file
6059

6160
## options
6261

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"dependencies": {
4747
"@changesets/cli": "^2.27.3",
48-
"@farmfe/core": "^1.1.9",
48+
"@farmfe/core": "^1.1.12",
4949
"cac": "^6.7.14",
5050
"fs-extra": "^11.2.0",
5151
"glob": "^10.3.15",

pnpm-lock.yaml

+41-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/normalize/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function normalizedTargetEnv(
115115
config: UserConfig,
116116
commonOptions: CommonOptions,
117117
options: ResolvedCommonOptions,
118-
logger: Logger,
118+
logger: Logger
119119
) {
120120
config.compilation?.output?.targetEnv;
121121
if (commonOptions.target) {
@@ -164,7 +164,7 @@ async function normalizedSimpleConfig(
164164
config: UserConfig,
165165
commonOptions: CommonOptions,
166166
options: ResolvedCommonOptions,
167-
logger: Logger,
167+
logger: Logger
168168
) {
169169
const inputs = await tryFindEntryFromUserConfig(logger, config, commonOptions);
170170

@@ -186,6 +186,7 @@ async function normalizedSimpleConfig(
186186
? { target: commonOptions.target || config.compilation?.output?.targetEnv }
187187
: {}),
188188
...(commonOptions.autoExternal ? { autoExternal: !!commonOptions.autoExternal } : {}),
189+
outputDir: commonOptions.outputDir ?? config.compilation.output?.path ?? './dist',
189190
noExecute: commonOptions.noExecute ?? false,
190191
noWatch: commonOptions.noWatch ?? true,
191192
watchFiles: await normalizeWatchFiles(commonOptions),
@@ -231,12 +232,10 @@ export class NormalizeOption {
231232
autoExternal: false,
232233
noExecute: false,
233234
watchFiles: [],
235+
outputDir: './dist',
234236
};
235237

236-
constructor(
237-
private commonOption: CommonOptions,
238-
private logger: Logger,
239-
) {}
238+
constructor(private commonOption: CommonOptions, private logger: Logger) {}
240239

241240
async config(config: UserConfig): Promise<UserConfig> {
242241
await normalizedSimpleConfig(config, this.commonOption, this.options, this.logger);
@@ -248,11 +247,12 @@ export class NormalizeOption {
248247
...pick(this.options, ['format', 'mode']),
249248
...(this.options.target ? { targetEnv: this.options.target } : {}),
250249
...(this.options.outputEntry ? { entryFilename: this.options.outputEntry.name } : {}),
250+
path: this.options.outputDir,
251251
},
252252
...pick(this.options, 'minify'),
253253
},
254254
},
255-
this.options,
255+
this.options
256256
);
257257
}
258258

src/index.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ExecuteMode, type CommonOptions } from './types/options';
1616
import autoExternal from './plugins/auto-external';
1717
import path from 'node:path';
1818
import { isBoolean, isString } from 'lodash-es';
19+
import { logger } from './config/constant';
1920

2021
const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)).toString());
2122

@@ -38,6 +39,7 @@ function createInlineConfig(options: CommonOptions): InlineConfig {
3839
root: options.root,
3940
configPath: options.config,
4041
plugins: buildPluginsByCommonOption(options),
42+
logger: logger,
4143
};
4244
}
4345

@@ -75,19 +77,20 @@ async function build(options: CommonOptions) {
7577

7678
const cli = cac('farmup');
7779

78-
cli.option(
79-
'--target [target]',
80-
"target for output, default is node, support 'browser'、'node'、'node16'、'node-legacy'、'node-next'、'browser-legacy'、'browser-es2015'、'browser-es2017'、'browser-esnext'",
81-
)
80+
cli.option('-w, --watch [...files]', 'watch files', { default: false })
81+
.option('-e, --exec [file]', 'custom execute command')
82+
.option('-o, --output [dir]', 'output directory, default "./dist" if not set in config')
8283
.option('--mode [mode]', 'mode for build, default is development, choose one from "development" or "production"')
8384
.option('--minify', 'minify for output')
84-
.option('--config [config]', 'config path, if not path, it will be auto find')
85+
.option('-c, --config [config]', 'config path, if not path, it will be auto find')
8586
.option('--no-config', 'if farm.config.[ext] exists, it will be ignore')
8687
.option('--format [format]', 'choose one from "cjs" or "esm"')
8788
.option('--external [...external]', 'external')
88-
.option('-w, --watch [...files]', 'watch files', { default: false })
8989
.option('--no-auto-external', 'if not found module, auto as external', { default: true })
90-
.option('-e, --exec [file]', 'custom execute command');
90+
.option(
91+
'--target [target]',
92+
"target for output, default is node, support 'browser'、'node'、'node16'、'node-legacy'、'node-next'、'browser-legacy'、'browser-es2015'、'browser-es2017'、'browser-esnext'"
93+
);
9194

9295
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
9396
async function commonOptionsFromArgs(args: Record<string, any>): Promise<Partial<CommonOptions>> {
@@ -98,8 +101,8 @@ async function commonOptionsFromArgs(args: Record<string, any>): Promise<Partial
98101
? args.config
99102
: path.resolve(root, args.config)
100103
: args.config
101-
? await getConfigFilePath(root)
102-
: undefined;
104+
? await getConfigFilePath(root)
105+
: undefined;
103106
const execute = isString(args.exec) && !isBoolean(args.exec) ? args.exec : undefined;
104107

105108
return {
@@ -118,6 +121,7 @@ async function commonOptionsFromArgs(args: Record<string, any>): Promise<Partial
118121
.flat()
119122
.map((item) => (item === true ? undefined : item))
120123
.filter(Boolean),
124+
outputDir: args.output || './dist',
121125
};
122126
}
123127

src/types/options.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export type TargetEnv = Exclude<Required<Required<UserConfig>['compilation']>['o
66
type Get<T extends Record<keyof any, any>, K extends keyof any> = K extends `${infer PREFIX}.${infer LAST}`
77
? Get<Exclude<T[PREFIX], undefined>, LAST>
88
: K extends keyof T
9-
? T[K]
10-
: never;
9+
? T[K]
10+
: never;
1111

1212
export type Format = Get<UserConfig, 'compilation.output.format'>;
1313

@@ -54,9 +54,15 @@ export interface CommonOptions {
5454

5555
root?: string;
5656

57+
/** watch files, support glob pattern */
5758
watchFiles?: string[];
58-
59-
name?: string,
59+
/** name for plugin or logger prefix */
60+
name?: string;
61+
/**
62+
* output directory for build
63+
* @default './dist'
64+
*/
65+
outputDir?: string;
6066
}
6167

6268
export interface ResolvedCommonOptions {
@@ -81,6 +87,11 @@ export interface ResolvedCommonOptions {
8187
matchEntryName: (name: string, inputs: Record<string, string>) => string | undefined;
8288
name: string;
8389
};
90+
91+
/**
92+
* @default './dist'
93+
*/
94+
outputDir: string;
8495
}
8596

8697
export enum ExecuteMode {

0 commit comments

Comments
 (0)