auklet 0.0.7 → 0.0.9

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
@@ -21,7 +21,6 @@ Build utilities for TypeScript packages and module CSS output.
21
21
  ## Requirements
22
22
 
23
23
  - Node.js `>=22`
24
- - pnpm `10.27.0`
25
24
 
26
25
  ## CLI
27
26
 
@@ -38,7 +37,7 @@ pnpm auk dev
38
37
 
39
38
  Commands:
40
39
 
41
- - `build` removes `dist`, builds JavaScript output, then builds CSS output.
40
+ - `build` removes the configured `output` directory, builds JavaScript output, then builds CSS output.
42
41
  - `build-js` runs tsdown with the default auklet tsdown config unless a config flag is passed.
43
42
  - `build-css` generates module CSS output.
44
43
  - `build-css --watch` watches source/config files and rebuilds CSS.
@@ -77,6 +76,16 @@ export const config: AukletConfig = {
77
76
  build: {
78
77
  formats: ['esm', 'cjs'],
79
78
  target: 'es2020',
79
+ globals: {
80
+ react: 'React',
81
+ },
82
+ configureTsdown(config, context) {
83
+ if (context.kind !== 'bundle') return config;
84
+ return {
85
+ ...config,
86
+ sourcemap: true,
87
+ };
88
+ },
80
89
  tsconfig: 'tsconfig.json',
81
90
  },
82
91
  };
@@ -85,7 +94,7 @@ export const config: AukletConfig = {
85
94
  ### Style Options
86
95
 
87
96
  - `source`: source directory relative to the package root. Defaults to `src`.
88
- - `output`: build output directory relative to the package root. Defaults to `dist`.
97
+ - `output`: build output directory relative to the package root. Defaults to `dist`. `auk build` removes this directory before writing JavaScript and CSS output.
89
98
  - `styles.themes`: package theme style entries. Defaults to `{}`.
90
99
  - `styles.dependencies`: external package style dependencies. Defaults to `{}`.
91
100
 
@@ -136,6 +145,8 @@ export const config: AukletConfig = {
136
145
  - `build.platform`: build target runtime platform: `neutral`, `node`, or `browser`. Defaults to `neutral`.
137
146
  - `build.banner`: custom bundle banner. Defaults to a package name/version banner.
138
147
  - `build.externals`: additional external packages. Defaults to `[]`.
148
+ - `build.globals`: IIFE external global names passed to tsdown `output.globals`. Values override auklet's generated global names.
149
+ - `build.configureTsdown`: final customization hook for each generated tsdown config. It receives `(config, context)` and should return a tsdown config.
139
150
  - `build.tsconfig`: TypeScript config path relative to the package root. Defaults to the nearest `tsconfig.json` found from the package root upward.
140
151
 
141
152
  ### Build Constants
package/bin/entry.cjs CHANGED
@@ -16,12 +16,18 @@ const runVersion = async () => {
16
16
  return 0;
17
17
  };
18
18
 
19
- const runBuildStyle = async (args) => {
20
- const shouldWatch = args.includes('--watch') || args.includes('-w');
19
+ const loadCurrentAukletConfig = async (options) => {
21
20
  const { loadAukletConfig } = await import('../dist/configLoader.js');
22
- const aukletConfig = await loadAukletConfig(process.cwd(), {
23
- cacheBust: shouldWatch,
24
- });
21
+ return loadAukletConfig(process.cwd(), options);
22
+ };
23
+
24
+ const runBuildStyle = async (args, options = {}) => {
25
+ const shouldWatch = args.includes('--watch') || args.includes('-w');
26
+ const aukletConfig =
27
+ options.aukletConfig ??
28
+ (await loadCurrentAukletConfig({
29
+ cacheBust: shouldWatch,
30
+ }));
25
31
 
26
32
  if (shouldWatch) {
27
33
  const { ModuleStyleWatcher } = await import('../dist/css/watch/watcher.js');
@@ -53,15 +59,16 @@ const runBuildJs = async (args) => {
53
59
  };
54
60
 
55
61
  const runBuild = async (args) => {
56
- fs.rmSync(path.join(process.cwd(), 'dist'), {
57
- recursive: true,
58
- force: true,
59
- });
62
+ const aukletConfig = await loadCurrentAukletConfig();
63
+ const { cleanAukletOutputByConfig } = await import(
64
+ '../dist/build/cleanOutput.js'
65
+ );
66
+ cleanAukletOutputByConfig(process.cwd(), aukletConfig);
60
67
 
61
68
  const jsExitCode = await runBuildJs(args);
62
69
  if (jsExitCode) return jsExitCode;
63
70
 
64
- return runBuildStyle([]);
71
+ return runBuildStyle([], { aukletConfig });
65
72
  };
66
73
 
67
74
  const runDev = async () => {
@@ -0,0 +1,9 @@
1
+ import type { AukletConfig, LoadAukletConfigOptions } from '#auklet/types';
2
+ export declare function cleanAukletOutputByConfig(
3
+ packageRoot: string,
4
+ config?: AukletConfig,
5
+ ): void;
6
+ export declare function cleanAukletOutput(
7
+ packageRoot: string,
8
+ options?: LoadAukletConfigOptions,
9
+ ): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { normalizeAukletConfig } from '#auklet/config';
4
+ import { loadAukletConfig } from '#auklet/configLoader';
5
+ export function cleanAukletOutputByConfig(packageRoot, config = {}) {
6
+ const normalizedConfig = normalizeAukletConfig(config);
7
+ fs.rmSync(path.join(packageRoot, normalizedConfig.output), {
8
+ recursive: true,
9
+ force: true,
10
+ });
11
+ }
12
+ export async function cleanAukletOutput(packageRoot, options = {}) {
13
+ const rawConfig = await loadAukletConfig(packageRoot, options);
14
+ cleanAukletOutputByConfig(packageRoot, rawConfig);
15
+ }
@@ -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,11 @@ 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
+ globals: options.globals ?? {},
139
143
  globalName: getGlobalName(pkg),
140
144
  platform: options.platform,
141
145
  target: options.target,
146
+ configureTsdown: options.configureTsdown,
142
147
  tsconfig: options.tsconfig
143
148
  ? path.resolve(packageRoot, options.tsconfig)
144
149
  : findWorkspaceTsconfig(packageRoot),
@@ -162,6 +167,16 @@ const createCommonConfig = (context, deps) => {
162
167
  },
163
168
  };
164
169
  };
170
+ const configureTsdown = (context, config, options) => {
171
+ return (
172
+ context.configureTsdown?.(config, {
173
+ ...options,
174
+ packageRoot: context.packageRoot,
175
+ output: context.output,
176
+ packageName: context.pkg.name,
177
+ }) ?? config
178
+ );
179
+ };
165
180
  const createBundleConfigs = (context, formats) => {
166
181
  const outputConfigs = [];
167
182
  let hasDtsConfig = false;
@@ -184,39 +199,47 @@ const createBundleConfigs = (context, formats) => {
184
199
  : {
185
200
  neverBundle: context.packageExternal,
186
201
  };
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) : {},
202
+ return configureTsdown(
203
+ context,
204
+ {
205
+ ...createCommonConfig(context, deps),
206
+ entry: getBundleEntry(context.packageRoot),
207
+ format,
208
+ globalName: context.globalName,
209
+ outDir: context.output,
210
+ dts,
211
+ treeshake: true,
212
+ banner: context.banner,
213
+ outExtensions: () => ({
214
+ js: extname,
215
+ }),
216
+ outputOptions: {
217
+ entryFileNames: `[name]${extname}`,
218
+ chunkFileNames: `[name]-[hash]${extname}`,
219
+ globals: format === 'iife' ? getIifeGlobals(context) : {},
220
+ },
203
221
  },
204
- };
222
+ { kind: 'bundle', format },
223
+ );
205
224
  });
206
225
  };
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
- };
226
+ const createModuleConfig = (context, commonConfig, entry, format, outDir) => {
227
+ return configureTsdown(
228
+ context,
229
+ {
230
+ ...commonConfig,
231
+ entry,
232
+ format,
233
+ outDir,
234
+ dts: true,
235
+ unbundle: true,
236
+ outExtensions: () => ({
237
+ js: '.js',
238
+ dts: '.d.ts',
239
+ }),
240
+ },
241
+ { kind: 'module', format },
242
+ );
220
243
  };
221
244
  const createModuleConfigs = (context) => {
222
245
  const commonConfig = createCommonConfig(context, {
@@ -225,12 +248,14 @@ const createModuleConfigs = (context) => {
225
248
  const entry = getModuleEntries(context.packageRoot);
226
249
  return [
227
250
  createModuleConfig(
251
+ context,
228
252
  commonConfig,
229
253
  entry,
230
254
  'esm',
231
255
  path.join(context.output, 'es'),
232
256
  ),
233
257
  createModuleConfig(
258
+ context,
234
259
  commonConfig,
235
260
  entry,
236
261
  'cjs',
package/dist/config.d.ts CHANGED
@@ -25,6 +25,8 @@ export declare function normalizeAukletConfig(config?: AukletConfig): {
25
25
  platform: import('#auklet/types').PackageBuildPlatform;
26
26
  banner?: string;
27
27
  externals?: Array<string>;
28
+ globals?: Record<string, string>;
29
+ configureTsdown?: import('#auklet/types').ConfigureTsdown;
28
30
  tsconfig?: string;
29
31
  };
30
32
  styles: {
@@ -48,6 +48,8 @@ export declare class ModuleStyleGraphRequestCache {
48
48
  platform: import('#auklet/types').PackageBuildPlatform;
49
49
  banner?: string;
50
50
  externals?: Array<string>;
51
+ globals?: Record<string, string>;
52
+ configureTsdown?: import('#auklet/types').ConfigureTsdown;
51
53
  tsconfig?: string;
52
54
  };
53
55
  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,25 @@ 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
+ globals?: Record<string, string>;
47
+ configureTsdown?: ConfigureTsdown;
34
48
  tsconfig?: string;
35
49
  };
36
50
  export interface AukletConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auklet",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "author": "chentao.arthur",
6
6
  "packageManager": "pnpm@10.27.0",
@@ -53,6 +53,15 @@
53
53
  "dist",
54
54
  "!dist/__tests__"
55
55
  ],
56
+ "keywords": [
57
+ "build",
58
+ "typescript",
59
+ "css",
60
+ "vite",
61
+ "components",
62
+ "monorepo",
63
+ "tsdown"
64
+ ],
56
65
  "dependencies": {
57
66
  "unrun": "^0.3.0",
58
67
  "execa": "^9.1.0",