auklet 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -76,6 +76,20 @@ export const config: AukletConfig = {
76
76
  build: {
77
77
  formats: ['esm', 'cjs'],
78
78
  target: 'es2020',
79
+ alias: {
80
+ '@shared': './src/shared',
81
+ },
82
+ mainFields: ['browser', 'module', 'main'],
83
+ globals: {
84
+ react: 'React',
85
+ },
86
+ configureTsdown(config, context) {
87
+ if (context.kind !== 'bundle') return config;
88
+ return {
89
+ ...config,
90
+ sourcemap: true,
91
+ };
92
+ },
79
93
  tsconfig: 'tsconfig.json',
80
94
  },
81
95
  };
@@ -135,6 +149,10 @@ export const config: AukletConfig = {
135
149
  - `build.platform`: build target runtime platform: `neutral`, `node`, or `browser`. Defaults to `neutral`.
136
150
  - `build.banner`: custom bundle banner. Defaults to a package name/version banner.
137
151
  - `build.externals`: additional external packages. Defaults to `[]`.
152
+ - `build.alias`: path aliases passed to tsdown `alias`. Defaults to `{}`.
153
+ - `build.mainFields`: bundle package entry resolution order passed to rolldown `resolve.mainFields`. When omitted, auklet only sets `['browser', 'module', 'main']` for IIFE bundles.
154
+ - `build.globals`: IIFE external global names passed to tsdown `output.globals`. Values override auklet's generated global names.
155
+ - `build.configureTsdown`: final customization hook for each generated tsdown config. It receives `(config, context)` and should return a tsdown config.
138
156
  - `build.tsconfig`: TypeScript config path relative to the package root. Defaults to the nearest `tsconfig.json` found from the package root upward.
139
157
 
140
158
  ### Build Constants
@@ -1,216 +1,12 @@
1
+ import type { UserConfig } from 'tsdown/config';
1
2
  import type { AukletConfig, PackageBuildFormat } from '#auklet/types';
2
3
  export type TsdownFormat = PackageBuildFormat;
3
4
  export declare function defineKernelPackageConfigFromOptions(
4
5
  packageRoot?: string,
5
6
  config?: AukletConfig,
6
- ): (
7
- | {
8
- entry: {
9
- index: string;
10
- };
11
- format: PackageBuildFormat;
12
- globalName: string;
13
- outDir: string;
14
- dts: boolean;
15
- treeshake: true;
16
- banner: string;
17
- outExtensions: () => {
18
- js: string;
19
- };
20
- outputOptions: {
21
- entryFileNames: string;
22
- chunkFileNames: string;
23
- globals: {
24
- [k: string]: string;
25
- };
26
- };
27
- cwd: string;
28
- root: string;
29
- clean: false;
30
- sourcemap: false;
31
- tsconfig: string;
32
- target: NonNullable<
33
- import('#auklet/types').PackageBuildTarget | undefined
34
- >;
35
- platform: NonNullable<
36
- import('#auklet/types').PackageBuildPlatform | undefined
37
- >;
38
- deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
39
- define: {
40
- __TEST__: string;
41
- __VERSION__: string;
42
- __DEV__: string;
43
- };
44
- }
45
- | {
46
- entry: Record<string, string>;
47
- format: 'cjs' | 'esm';
48
- outDir: string;
49
- dts: true;
50
- unbundle: true;
51
- outExtensions: () => {
52
- js: string;
53
- dts: string;
54
- };
55
- cwd: string;
56
- root: string;
57
- clean: false;
58
- sourcemap: false;
59
- tsconfig: string;
60
- target: NonNullable<
61
- import('#auklet/types').PackageBuildTarget | undefined
62
- >;
63
- platform: NonNullable<
64
- import('#auklet/types').PackageBuildPlatform | undefined
65
- >;
66
- deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
67
- define: {
68
- __TEST__: string;
69
- __VERSION__: string;
70
- __DEV__: string;
71
- };
72
- }
73
- )[];
7
+ ): UserConfig[];
74
8
  export declare function defineKernelPackageConfigFromFile(
75
9
  packageRoot?: string,
76
- ): Promise<
77
- (
78
- | {
79
- entry: {
80
- index: string;
81
- };
82
- format: PackageBuildFormat;
83
- globalName: string;
84
- outDir: string;
85
- dts: boolean;
86
- treeshake: true;
87
- banner: string;
88
- outExtensions: () => {
89
- js: string;
90
- };
91
- outputOptions: {
92
- entryFileNames: string;
93
- chunkFileNames: string;
94
- globals: {
95
- [k: string]: string;
96
- };
97
- };
98
- cwd: string;
99
- root: string;
100
- clean: false;
101
- sourcemap: false;
102
- tsconfig: string;
103
- target: NonNullable<
104
- import('#auklet/types').PackageBuildTarget | undefined
105
- >;
106
- platform: NonNullable<
107
- import('#auklet/types').PackageBuildPlatform | undefined
108
- >;
109
- deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
110
- define: {
111
- __TEST__: string;
112
- __VERSION__: string;
113
- __DEV__: string;
114
- };
115
- }
116
- | {
117
- entry: Record<string, string>;
118
- format: 'cjs' | 'esm';
119
- outDir: string;
120
- dts: true;
121
- unbundle: true;
122
- outExtensions: () => {
123
- js: string;
124
- dts: string;
125
- };
126
- cwd: string;
127
- root: string;
128
- clean: false;
129
- sourcemap: false;
130
- tsconfig: string;
131
- target: NonNullable<
132
- import('#auklet/types').PackageBuildTarget | undefined
133
- >;
134
- platform: NonNullable<
135
- import('#auklet/types').PackageBuildPlatform | undefined
136
- >;
137
- deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
138
- define: {
139
- __TEST__: string;
140
- __VERSION__: string;
141
- __DEV__: string;
142
- };
143
- }
144
- )[]
145
- >;
146
- declare const _default: Promise<
147
- (
148
- | {
149
- entry: {
150
- index: string;
151
- };
152
- format: PackageBuildFormat;
153
- globalName: string;
154
- outDir: string;
155
- dts: boolean;
156
- treeshake: true;
157
- banner: string;
158
- outExtensions: () => {
159
- js: string;
160
- };
161
- outputOptions: {
162
- entryFileNames: string;
163
- chunkFileNames: string;
164
- globals: {
165
- [k: string]: string;
166
- };
167
- };
168
- cwd: string;
169
- root: string;
170
- clean: false;
171
- sourcemap: false;
172
- tsconfig: string;
173
- target: NonNullable<
174
- import('#auklet/types').PackageBuildTarget | undefined
175
- >;
176
- platform: NonNullable<
177
- import('#auklet/types').PackageBuildPlatform | undefined
178
- >;
179
- deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
180
- define: {
181
- __TEST__: string;
182
- __VERSION__: string;
183
- __DEV__: string;
184
- };
185
- }
186
- | {
187
- entry: Record<string, string>;
188
- format: 'cjs' | 'esm';
189
- outDir: string;
190
- dts: true;
191
- unbundle: true;
192
- outExtensions: () => {
193
- js: string;
194
- dts: string;
195
- };
196
- cwd: string;
197
- root: string;
198
- clean: false;
199
- sourcemap: false;
200
- tsconfig: string;
201
- target: NonNullable<
202
- import('#auklet/types').PackageBuildTarget | undefined
203
- >;
204
- platform: NonNullable<
205
- import('#auklet/types').PackageBuildPlatform | undefined
206
- >;
207
- deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
208
- define: {
209
- __TEST__: string;
210
- __VERSION__: string;
211
- __DEV__: string;
212
- };
213
- }
214
- )[]
215
- >;
10
+ ): Promise<UserConfig[]>;
11
+ declare const _default: Promise<UserConfig[]>;
216
12
  export default _default;
@@ -41,9 +41,12 @@ const getDependencyGlobalName = (name) => {
41
41
  .join('');
42
42
  };
43
43
  const getIifeGlobals = (context) => {
44
- return Object.fromEntries(
45
- context.peerExternal.map((name) => [name, getDependencyGlobalName(name)]),
46
- );
44
+ return {
45
+ ...Object.fromEntries(
46
+ context.peerExternal.map((name) => [name, getDependencyGlobalName(name)]),
47
+ ),
48
+ ...context.globals,
49
+ };
47
50
  };
48
51
  const getIifeAlwaysBundle = (context) => {
49
52
  const names = new Set(context.runtimeDependencyNames);
@@ -136,9 +139,13 @@ const createBuildContext = (packageRoot, options, output) => {
136
139
  runtimeDependencyNames: Object.keys(pkg.dependencies ?? {}),
137
140
  packageExternal: getPackageExternal(pkg, options),
138
141
  peerExternal: getPeerExternal(pkg, options),
142
+ alias: options.alias ?? {},
143
+ mainFields: options.mainFields,
144
+ globals: options.globals ?? {},
139
145
  globalName: getGlobalName(pkg),
140
146
  platform: options.platform,
141
147
  target: options.target,
148
+ configureTsdown: options.configureTsdown,
142
149
  tsconfig: options.tsconfig
143
150
  ? path.resolve(packageRoot, options.tsconfig)
144
151
  : findWorkspaceTsconfig(packageRoot),
@@ -153,6 +160,7 @@ const createCommonConfig = (context, deps) => {
153
160
  tsconfig: context.tsconfig,
154
161
  target: context.target,
155
162
  platform: context.platform,
163
+ alias: context.alias,
156
164
  deps,
157
165
  define: {
158
166
  __TEST__: 'false',
@@ -162,6 +170,31 @@ const createCommonConfig = (context, deps) => {
162
170
  },
163
171
  };
164
172
  };
173
+ const createBundleInputOptions = (context, format) => {
174
+ const mainFields =
175
+ context.mainFields ??
176
+ (format === 'iife' ? ['browser', 'module', 'main'] : undefined);
177
+ return (options) => {
178
+ if (!mainFields) return options;
179
+ return {
180
+ ...options,
181
+ resolve: {
182
+ ...options.resolve,
183
+ mainFields,
184
+ },
185
+ };
186
+ };
187
+ };
188
+ const configureTsdown = (context, config, options) => {
189
+ return (
190
+ context.configureTsdown?.(config, {
191
+ ...options,
192
+ packageRoot: context.packageRoot,
193
+ output: context.output,
194
+ packageName: context.pkg.name,
195
+ }) ?? config
196
+ );
197
+ };
165
198
  const createBundleConfigs = (context, formats) => {
166
199
  const outputConfigs = [];
167
200
  let hasDtsConfig = false;
@@ -184,39 +217,52 @@ const createBundleConfigs = (context, formats) => {
184
217
  : {
185
218
  neverBundle: context.packageExternal,
186
219
  };
187
- return {
188
- ...createCommonConfig(context, deps),
189
- entry: getBundleEntry(context.packageRoot),
190
- format,
191
- globalName: context.globalName,
192
- outDir: context.output,
193
- dts,
194
- treeshake: true,
195
- banner: context.banner,
196
- outExtensions: () => ({
197
- js: extname,
198
- }),
199
- outputOptions: {
200
- entryFileNames: `[name]${extname}`,
201
- chunkFileNames: `[name]-[hash]${extname}`,
202
- globals: format === 'iife' ? getIifeGlobals(context) : {},
220
+ const inputOptions =
221
+ context.mainFields || format === 'iife'
222
+ ? createBundleInputOptions(context, format)
223
+ : undefined;
224
+ return configureTsdown(
225
+ context,
226
+ {
227
+ ...createCommonConfig(context, deps),
228
+ entry: getBundleEntry(context.packageRoot),
229
+ format,
230
+ globalName: context.globalName,
231
+ outDir: context.output,
232
+ dts,
233
+ treeshake: true,
234
+ banner: context.banner,
235
+ outExtensions: () => ({
236
+ js: extname,
237
+ }),
238
+ outputOptions: {
239
+ entryFileNames: `[name]${extname}`,
240
+ chunkFileNames: `[name]-[hash]${extname}`,
241
+ globals: format === 'iife' ? getIifeGlobals(context) : {},
242
+ },
243
+ inputOptions,
203
244
  },
204
- };
245
+ { kind: 'bundle', format },
246
+ );
205
247
  });
206
248
  };
207
- const createModuleConfig = (commonConfig, entry, format, outDir) => {
208
- return {
209
- ...commonConfig,
210
- entry,
211
- format,
212
- outDir,
213
- dts: true,
214
- unbundle: true,
215
- outExtensions: () => ({
216
- js: '.js',
217
- dts: '.d.ts',
218
- }),
219
- };
249
+ const createModuleConfig = (context, commonConfig, entry, format, outDir) => {
250
+ return configureTsdown(
251
+ context,
252
+ {
253
+ ...commonConfig,
254
+ entry,
255
+ format,
256
+ outDir,
257
+ dts: true,
258
+ unbundle: true,
259
+ outExtensions: () => ({
260
+ js: '.js',
261
+ dts: '.d.ts',
262
+ }),
263
+ },
264
+ { kind: 'module', format },
265
+ );
220
266
  };
221
267
  const createModuleConfigs = (context) => {
222
268
  const commonConfig = createCommonConfig(context, {
@@ -225,12 +271,14 @@ const createModuleConfigs = (context) => {
225
271
  const entry = getModuleEntries(context.packageRoot);
226
272
  return [
227
273
  createModuleConfig(
274
+ context,
228
275
  commonConfig,
229
276
  entry,
230
277
  'esm',
231
278
  path.join(context.output, 'es'),
232
279
  ),
233
280
  createModuleConfig(
281
+ context,
234
282
  commonConfig,
235
283
  entry,
236
284
  'cjs',
package/dist/config.d.ts CHANGED
@@ -25,6 +25,10 @@ export declare function normalizeAukletConfig(config?: AukletConfig): {
25
25
  platform: import('#auklet/types').PackageBuildPlatform;
26
26
  banner?: string;
27
27
  externals?: Array<string>;
28
+ alias?: Record<string, string>;
29
+ mainFields?: Array<string>;
30
+ globals?: Record<string, string>;
31
+ configureTsdown?: import('#auklet/types').ConfigureTsdown;
28
32
  tsconfig?: string;
29
33
  };
30
34
  styles: {
@@ -48,6 +48,10 @@ export declare class ModuleStyleGraphRequestCache {
48
48
  platform: import('#auklet/types').PackageBuildPlatform;
49
49
  banner?: string;
50
50
  externals?: Array<string>;
51
+ alias?: Record<string, string>;
52
+ mainFields?: Array<string>;
53
+ globals?: Record<string, string>;
54
+ configureTsdown?: import('#auklet/types').ConfigureTsdown;
51
55
  tsconfig?: string;
52
56
  };
53
57
  styles: {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export type {
2
2
  AukletConfig,
3
+ ConfigureTsdown,
4
+ ConfigureTsdownContext,
3
5
  LoadAukletConfigOptions,
4
6
  ModuleStyleBuildConfig,
5
7
  ModuleStyleBuildContext,
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { UserConfig } from 'tsdown/config';
1
2
  export type StyleDependencyGroup = {
2
3
  entry?: string | Array<string>;
3
4
  themes?: Record<string, string>;
@@ -25,12 +26,27 @@ export interface NormalizedAukletConfig {
25
26
  export type PackageBuildFormat = 'cjs' | 'esm' | 'iife';
26
27
  export type PackageBuildPlatform = 'node' | 'neutral' | 'browser';
27
28
  export type PackageBuildTarget = string | Array<string> | false;
29
+ export type ConfigureTsdownContext = {
30
+ kind: 'bundle' | 'module';
31
+ format: PackageBuildFormat;
32
+ packageRoot: string;
33
+ output: string;
34
+ packageName?: string;
35
+ };
36
+ export type ConfigureTsdown = (
37
+ config: UserConfig,
38
+ context: ConfigureTsdownContext,
39
+ ) => UserConfig;
28
40
  export type PackageBuildOptions = {
29
41
  formats?: Array<PackageBuildFormat>;
30
42
  target?: PackageBuildTarget;
31
43
  platform?: PackageBuildPlatform;
32
44
  banner?: string;
33
45
  externals?: Array<string>;
46
+ alias?: Record<string, string>;
47
+ mainFields?: Array<string>;
48
+ globals?: Record<string, string>;
49
+ configureTsdown?: ConfigureTsdown;
34
50
  tsconfig?: string;
35
51
  };
36
52
  export interface AukletConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auklet",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "author": "chentao.arthur",
6
6
  "packageManager": "pnpm@10.27.0",