-
Notifications
You must be signed in to change notification settings - Fork 0
/
packemon.config.ts
65 lines (61 loc) · 2.01 KB
/
packemon.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { TransformOptions as BabelOptions } from "@babel/core";
import type { Options as SwcOptions } from '@swc/core';
import { writeFileSync } from "fs";
import type { RollupOptions, OutputOptions as RollupOutputOptions } from 'rollup';
// #region Types copied from packemon because it doesn't export declarations
interface FeatureFlags {
decorators?: boolean;
flow?: boolean;
react?: 'automatic' | 'classic';
solid?: boolean;
strict?: boolean;
typescript?: boolean;
typescriptComposite?: boolean;
}
// CommonJS modules with ".js" file extension
type CommonFormat = 'lib';
type BrowserFormat =
| CommonFormat
// ECMAScript modules with ".js" file extension
| 'esm'
// Universal Module Definition with ".js" file extension
| 'umd';
type NodeFormat =
| CommonFormat
/* CommonJS modules with ".cjs" file extension */
| 'cjs'
// ECMAScript modules with ".mjs" file extension
| 'mjs';
interface BuildParams {
features: FeatureFlags;
format: BrowserFormat | NodeFormat;
platform: 'browser' | 'electron' | 'native' | 'node';
support: | 'current'
// Next/future version
| 'experimental'
// Unsupported version
| 'legacy'
// Oldest version still supported
| 'stable';
}
type ConfigMutator<T> = (config: T) => void;
type ConfigMutatorWithBuild<T> = (config: T, build: BuildParams) => void;
export interface ConfigFile {
babelInput?: ConfigMutator<BabelOptions>;
babelOutput?: ConfigMutatorWithBuild<BabelOptions>;
rollupInput?: ConfigMutator<RollupOptions>;
rollupOutput?: ConfigMutatorWithBuild<RollupOutputOptions>;
swc?: boolean;
swcInput?: ConfigMutator<SwcOptions>;
swcOutput?: ConfigMutatorWithBuild<SwcOptions>;
}
// #endregion Types
/**
* @type {ConfigFile}
*/
export default {
babelInput(config: BabelOptions) {
const tmp = { ...config, caller: undefined, configFile: undefined };
writeFileSync("./babel.config.json", `${JSON.stringify(tmp, undefined, 2)}`, { encoding: "utf8" });
}
};