diff --git a/.changeset/great-keys-beg.md b/.changeset/great-keys-beg.md new file mode 100644 index 0000000..49bba9f --- /dev/null +++ b/.changeset/great-keys-beg.md @@ -0,0 +1,5 @@ +--- +'farmup': patch +--- + +upgrade dependence & option sort & add output option diff --git a/README.md b/README.md index 4d9e2d6..4f48c34 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ feature - cross import CommonJs and EsModule - watch mode +- support html ## Setup @@ -54,9 +55,7 @@ farmup build index.ts --no-exec - more cli options - sourcemap - ignore some watch file -- command output - - start to tmp file - - build to local file +- execute without output file ## options diff --git a/package.json b/package.json index 49a3e60..30f1bf6 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "@changesets/cli": "^2.27.3", - "@farmfe/core": "^1.1.9", + "@farmfe/core": "^1.1.12", "cac": "^6.7.14", "fs-extra": "^11.2.0", "glob": "^10.3.15", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 490da34..4f7e926 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^2.27.3 version: 2.27.3 '@farmfe/core': - specifier: ^1.1.9 - version: 1.1.9 + specifier: ^1.1.12 + version: 1.1.12 cac: specifier: ^6.7.14 version: 6.7.14 @@ -139,62 +139,62 @@ packages: engines: {node: '>= 16'} hasBin: true - '@farmfe/core-darwin-arm64@1.1.9': - resolution: {integrity: sha512-GKKSbSOR6cXnqTnD+rX/4uJ8Bm9VS4QwOtsXcCYXr7W4om8OdjyjJfHNSmcmv1ryjI5darPeEbby8MPb4/maGA==} + '@farmfe/core-darwin-arm64@1.1.12': + resolution: {integrity: sha512-CJOl3nm/k1GayGwOJoa7QK1hjF2/0jhv3K6BPv6qfYT7oyHwkuEZjU30WyKNjMb8LofwGXl4ez1wIhIBZc/0yg==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] - '@farmfe/core-darwin-x64@1.1.9': - resolution: {integrity: sha512-F/5kYQYFdFqWQqq95VkxewfJ7vilb8zfDERk2rbxYdpQBy7oMo2HlPutbFZg84FJY8iv8Df0XgXxcuNmc81cZg==} + '@farmfe/core-darwin-x64@1.1.12': + resolution: {integrity: sha512-whYQFbnbJVILugtfQT96UtEZsT/xK+oFuCyGt0B7IVHtLCX+lPtgLkr/LNY7x8pp36EWRCbcngV5YvPZmfZOuw==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] - '@farmfe/core-linux-arm64-gnu@1.1.9': - resolution: {integrity: sha512-bKmycrynNvrJzo/z+leUQfgMG7z5qV3LsosTKp+ktsSYs69pE9BO/1BWC9z6fGg/BXJf6AOKf4a32HTTazDB6w==} + '@farmfe/core-linux-arm64-gnu@1.1.12': + resolution: {integrity: sha512-vy2TkrwZ642c3g3jJARIssk6qXEE6ebpRoXBv0QiN2/qjWcfo9oSqYTYbnNvyiTXJp9N9UsfCzlHl9jmEariKA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@farmfe/core-linux-arm64-musl@1.1.9': - resolution: {integrity: sha512-GIMIo6+jUyUsikJnXVz9iO+dSygMYS+yel9uXuVqSi2hbKk2YUuyYUcvu8JrBWKId/xNxerNrwfaqYwvsRXEFA==} + '@farmfe/core-linux-arm64-musl@1.1.12': + resolution: {integrity: sha512-1pTiy6NsEK2OwtD743hRl1IFDm9g1fPCjPGSI0gz4xZ9YKXZHYgIMpFf3yV3DRIQMBaYVMFvK8qwQMu14JQVFw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@farmfe/core-linux-x64-gnu@1.1.9': - resolution: {integrity: sha512-wPjLWNOFqG9axRpzyNPw1RxhZC43aMKIHxrpKXVr8Ctquy6jkmnJmYs1g2BxczjcbbM0PJdXquBBzRIsVA+nEQ==} + '@farmfe/core-linux-x64-gnu@1.1.12': + resolution: {integrity: sha512-yn+UL1k0qCCAhpywttsCOgapVhhdDTCzEFmnwLsiKRKyTH1r5H/4OwcVeQ69UqiBV1DR5SgMm0ZsAl13be0GMA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@farmfe/core-linux-x64-musl@1.1.9': - resolution: {integrity: sha512-HgVRyrC9EmkEosf0NYtwIvbAKBbYWdrHSY7FPdLkq+5vQvrdX/jk3r30ScIwAfnhKzmUabUBcOW93wRlyZA8sQ==} + '@farmfe/core-linux-x64-musl@1.1.12': + resolution: {integrity: sha512-odsTuMbyXD2Lh25d4WCaISOYnfdPFDsvVPrqtbP5OgWJuw42OPqswlwRtSmg7f9bFnIjNM/uzI3+Mg2chG38UA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@farmfe/core-win32-arm64-msvc@1.1.9': - resolution: {integrity: sha512-Xpbu5Yf7KdU07BP7MKBfIdnVp0kFqXgu7DPbRXuG6ugXmS3ntd9AqxiZ8+AJ+hD4NmeZkt0t1YqVYgPdkeU7LA==} + '@farmfe/core-win32-arm64-msvc@1.1.12': + resolution: {integrity: sha512-9WSjxeMTeKS9sDy+na24cvZpVG035OpEa0IvZFbTUFWVhxioevAbPnX4U4zSSVK44WiXlTxd/+VZBTIL1LJZOg==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] - '@farmfe/core-win32-ia32-msvc@1.1.9': - resolution: {integrity: sha512-GWpDl1oNjdO8aEhCMRi/24QQk4O/0karMxRFFeTnm3uJTHk8AnnIolzpYoDp1uPPb/HbXzDK/g/MFCpgtRdpkQ==} + '@farmfe/core-win32-ia32-msvc@1.1.12': + resolution: {integrity: sha512-NJ1RN+OlRhgA7TqvMlahPpMwZPh0jF4orth+zxZK5FdBA6iHHIpFsNA8/BTuaZGzaG5acF9CN05eADc9PTow8Q==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] - '@farmfe/core-win32-x64-msvc@1.1.9': - resolution: {integrity: sha512-rvyKlUY/65nKoVQQiURiZMQbIMvZC7qUKl9xEAg0EgupvIS7uEoAy/6p0Fk+BVQOP/qI0O0KW6r2jrDJ5Ie8yQ==} + '@farmfe/core-win32-x64-msvc@1.1.12': + resolution: {integrity: sha512-1zQtf+98skJ3FoPiJ/Ms5gA8sitix3m/0PMUVDtF3dyELgLXebvxSOuC8Fvk2IkMDTlj5tn3doDHmVSGRuhl8g==} engines: {node: '>= 10'} cpu: [x64] os: [win32] - '@farmfe/core@1.1.9': - resolution: {integrity: sha512-RBXzPDRkaLr8ccKmRq6pQTH4h2UzwiB5CkqvNwTPbBUHn3kTnjGcEVjbZbvAqXPHd1nCGan6OI/MMFm3NxAuVQ==} + '@farmfe/core@1.1.12': + resolution: {integrity: sha512-9tR29JoKff1p4erK7V7vj52kpAFq5qy3gEOsPpYtKQwbZwB/ijgr+dslsv9Uj0kIkYlqSwFOZHDAzLcqowSaiw==} engines: {node: '>=16.15.1'} '@farmfe/runtime-plugin-hmr@3.5.2': @@ -2102,34 +2102,34 @@ snapshots: inquirer: 9.2.19 walkdir: 0.4.1 - '@farmfe/core-darwin-arm64@1.1.9': + '@farmfe/core-darwin-arm64@1.1.12': optional: true - '@farmfe/core-darwin-x64@1.1.9': + '@farmfe/core-darwin-x64@1.1.12': optional: true - '@farmfe/core-linux-arm64-gnu@1.1.9': + '@farmfe/core-linux-arm64-gnu@1.1.12': optional: true - '@farmfe/core-linux-arm64-musl@1.1.9': + '@farmfe/core-linux-arm64-musl@1.1.12': optional: true - '@farmfe/core-linux-x64-gnu@1.1.9': + '@farmfe/core-linux-x64-gnu@1.1.12': optional: true - '@farmfe/core-linux-x64-musl@1.1.9': + '@farmfe/core-linux-x64-musl@1.1.12': optional: true - '@farmfe/core-win32-arm64-msvc@1.1.9': + '@farmfe/core-win32-arm64-msvc@1.1.12': optional: true - '@farmfe/core-win32-ia32-msvc@1.1.9': + '@farmfe/core-win32-ia32-msvc@1.1.12': optional: true - '@farmfe/core-win32-x64-msvc@1.1.9': + '@farmfe/core-win32-x64-msvc@1.1.12': optional: true - '@farmfe/core@1.1.9': + '@farmfe/core@1.1.12': dependencies: '@farmfe/runtime': 0.11.1 '@farmfe/runtime-plugin-hmr': 3.5.2 @@ -2159,15 +2159,15 @@ snapshots: zod: 3.22.5 zod-validation-error: 1.5.0(zod@3.22.5) optionalDependencies: - '@farmfe/core-darwin-arm64': 1.1.9 - '@farmfe/core-darwin-x64': 1.1.9 - '@farmfe/core-linux-arm64-gnu': 1.1.9 - '@farmfe/core-linux-arm64-musl': 1.1.9 - '@farmfe/core-linux-x64-gnu': 1.1.9 - '@farmfe/core-linux-x64-musl': 1.1.9 - '@farmfe/core-win32-arm64-msvc': 1.1.9 - '@farmfe/core-win32-ia32-msvc': 1.1.9 - '@farmfe/core-win32-x64-msvc': 1.1.9 + '@farmfe/core-darwin-arm64': 1.1.12 + '@farmfe/core-darwin-x64': 1.1.12 + '@farmfe/core-linux-arm64-gnu': 1.1.12 + '@farmfe/core-linux-arm64-musl': 1.1.12 + '@farmfe/core-linux-x64-gnu': 1.1.12 + '@farmfe/core-linux-x64-musl': 1.1.12 + '@farmfe/core-win32-arm64-msvc': 1.1.12 + '@farmfe/core-win32-ia32-msvc': 1.1.12 + '@farmfe/core-win32-x64-msvc': 1.1.12 transitivePeerDependencies: - bufferutil - debug diff --git a/src/config/normalize/index.ts b/src/config/normalize/index.ts index f175466..bd3c005 100644 --- a/src/config/normalize/index.ts +++ b/src/config/normalize/index.ts @@ -115,7 +115,7 @@ export function normalizedTargetEnv( config: UserConfig, commonOptions: CommonOptions, options: ResolvedCommonOptions, - logger: Logger, + logger: Logger ) { config.compilation?.output?.targetEnv; if (commonOptions.target) { @@ -164,7 +164,7 @@ async function normalizedSimpleConfig( config: UserConfig, commonOptions: CommonOptions, options: ResolvedCommonOptions, - logger: Logger, + logger: Logger ) { const inputs = await tryFindEntryFromUserConfig(logger, config, commonOptions); @@ -186,6 +186,7 @@ async function normalizedSimpleConfig( ? { target: commonOptions.target || config.compilation?.output?.targetEnv } : {}), ...(commonOptions.autoExternal ? { autoExternal: !!commonOptions.autoExternal } : {}), + outputDir: commonOptions.outputDir ?? config.compilation.output?.path ?? './dist', noExecute: commonOptions.noExecute ?? false, noWatch: commonOptions.noWatch ?? true, watchFiles: await normalizeWatchFiles(commonOptions), @@ -231,12 +232,10 @@ export class NormalizeOption { autoExternal: false, noExecute: false, watchFiles: [], + outputDir: './dist', }; - constructor( - private commonOption: CommonOptions, - private logger: Logger, - ) {} + constructor(private commonOption: CommonOptions, private logger: Logger) {} async config(config: UserConfig): Promise { await normalizedSimpleConfig(config, this.commonOption, this.options, this.logger); @@ -248,11 +247,12 @@ export class NormalizeOption { ...pick(this.options, ['format', 'mode']), ...(this.options.target ? { targetEnv: this.options.target } : {}), ...(this.options.outputEntry ? { entryFilename: this.options.outputEntry.name } : {}), + path: this.options.outputDir, }, ...pick(this.options, 'minify'), }, }, - this.options, + this.options ); } diff --git a/src/index.ts b/src/index.ts index a08d75d..ed662ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ import { ExecuteMode, type CommonOptions } from './types/options'; import autoExternal from './plugins/auto-external'; import path from 'node:path'; import { isBoolean, isString } from 'lodash-es'; +import { logger } from './config/constant'; const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)).toString()); @@ -38,6 +39,7 @@ function createInlineConfig(options: CommonOptions): InlineConfig { root: options.root, configPath: options.config, plugins: buildPluginsByCommonOption(options), + logger: logger, }; } @@ -75,19 +77,20 @@ async function build(options: CommonOptions) { const cli = cac('farmup'); -cli.option( - '--target [target]', - "target for output, default is node, support 'browser'、'node'、'node16'、'node-legacy'、'node-next'、'browser-legacy'、'browser-es2015'、'browser-es2017'、'browser-esnext'", -) +cli.option('-w, --watch [...files]', 'watch files', { default: false }) + .option('-e, --exec [file]', 'custom execute command') + .option('-o, --output [dir]', 'output directory, default "./dist" if not set in config') .option('--mode [mode]', 'mode for build, default is development, choose one from "development" or "production"') .option('--minify', 'minify for output') - .option('--config [config]', 'config path, if not path, it will be auto find') + .option('-c, --config [config]', 'config path, if not path, it will be auto find') .option('--no-config', 'if farm.config.[ext] exists, it will be ignore') .option('--format [format]', 'choose one from "cjs" or "esm"') .option('--external [...external]', 'external') - .option('-w, --watch [...files]', 'watch files', { default: false }) .option('--no-auto-external', 'if not found module, auto as external', { default: true }) - .option('-e, --exec [file]', 'custom execute command'); + .option( + '--target [target]', + "target for output, default is node, support 'browser'、'node'、'node16'、'node-legacy'、'node-next'、'browser-legacy'、'browser-es2015'、'browser-es2017'、'browser-esnext'" + ); // biome-ignore lint/suspicious/noExplicitAny: async function commonOptionsFromArgs(args: Record): Promise> { @@ -98,8 +101,8 @@ async function commonOptionsFromArgs(args: Record): Promise): Promise (item === true ? undefined : item)) .filter(Boolean), + outputDir: args.output || './dist', }; } diff --git a/src/types/options.ts b/src/types/options.ts index 9323ebf..95e6440 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -6,8 +6,8 @@ export type TargetEnv = Exclude['compilation']>['o type Get, K extends keyof any> = K extends `${infer PREFIX}.${infer LAST}` ? Get, LAST> : K extends keyof T - ? T[K] - : never; + ? T[K] + : never; export type Format = Get; @@ -54,9 +54,15 @@ export interface CommonOptions { root?: string; + /** watch files, support glob pattern */ watchFiles?: string[]; - - name?: string, + /** name for plugin or logger prefix */ + name?: string; + /** + * output directory for build + * @default './dist' + */ + outputDir?: string; } export interface ResolvedCommonOptions { @@ -81,6 +87,11 @@ export interface ResolvedCommonOptions { matchEntryName: (name: string, inputs: Record) => string | undefined; name: string; }; + + /** + * @default './dist' + */ + outputDir: string; } export enum ExecuteMode {