auklet 0.0.3 → 0.0.5

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.
Files changed (81) hide show
  1. package/README.md +99 -42
  2. package/bin/entry.cjs +33 -11
  3. package/dist/build/runTsdown.js +2 -3
  4. package/dist/build/tsdownConfig.d.ts +138 -2
  5. package/dist/build/tsdownConfig.js +108 -63
  6. package/dist/config.d.ts +38 -6
  7. package/dist/config.js +43 -7
  8. package/dist/configLoader.js +1 -2
  9. package/dist/css/config.d.ts +2 -0
  10. package/dist/css/config.js +10 -0
  11. package/dist/css/constants.d.ts +7 -0
  12. package/dist/css/constants.js +7 -0
  13. package/dist/css/core/moduleGraph.d.ts +55 -0
  14. package/dist/css/core/moduleGraph.js +363 -0
  15. package/dist/css/core/moduleGraphRequestCache.d.ts +80 -0
  16. package/dist/css/core/moduleGraphRequestCache.js +92 -0
  17. package/dist/css/core/style/dependencies.d.ts +20 -0
  18. package/dist/css/core/style/dependencies.js +55 -0
  19. package/dist/css/core/style/files.d.ts +8 -0
  20. package/dist/css/core/style/files.js +19 -0
  21. package/dist/css/core/style/plan.d.ts +59 -0
  22. package/dist/css/core/style/plan.js +27 -0
  23. package/dist/css/core/style/specifier.d.ts +14 -0
  24. package/dist/css/core/style/specifier.js +27 -0
  25. package/dist/css/core/{moduleStyleImportCollector.d.ts → styleImports/collector.d.ts} +5 -5
  26. package/dist/css/core/{moduleStyleImportCollector.js → styleImports/collector.js} +36 -99
  27. package/dist/css/core/styleImports/sourceReference.d.ts +19 -0
  28. package/dist/css/core/styleImports/sourceReference.js +193 -0
  29. package/dist/css/core/styleModuleEntryPlanner.d.ts +29 -0
  30. package/dist/css/core/styleModuleEntryPlanner.js +67 -0
  31. package/dist/css/core/stylePackageContext.d.ts +27 -0
  32. package/dist/css/core/stylePackageContext.js +57 -0
  33. package/dist/css/core/styleProcessor.d.ts +3 -3
  34. package/dist/css/core/styleProcessor.js +18 -35
  35. package/dist/css/core/workspaceStyleResolver.d.ts +4 -5
  36. package/dist/css/core/workspaceStyleResolver.js +12 -28
  37. package/dist/css/production/builder.d.ts +18 -0
  38. package/dist/css/production/builder.js +68 -0
  39. package/dist/css/production/format/componentWriter.d.ts +12 -0
  40. package/dist/css/production/format/componentWriter.js +67 -0
  41. package/dist/css/production/format/entryWriter.d.ts +12 -0
  42. package/dist/css/production/format/entryWriter.js +54 -0
  43. package/dist/css/production/format/externalWriter.d.ts +9 -0
  44. package/dist/css/production/format/externalWriter.js +39 -0
  45. package/dist/css/production/format/moduleWriter.d.ts +8 -0
  46. package/dist/css/production/format/moduleWriter.js +31 -0
  47. package/dist/css/production/format/shared.d.ts +20 -0
  48. package/dist/css/production/format/shared.js +8 -0
  49. package/dist/css/production/format/sourceWriter.d.ts +6 -0
  50. package/dist/css/production/format/sourceWriter.js +16 -0
  51. package/dist/css/production/format/themeWriter.d.ts +16 -0
  52. package/dist/css/production/format/themeWriter.js +80 -0
  53. package/dist/css/production/moduleOutputWriter.d.ts +26 -0
  54. package/dist/css/production/moduleOutputWriter.js +83 -0
  55. package/dist/css/production/packageEntryWriter.d.ts +20 -0
  56. package/dist/css/production/packageEntryWriter.js +55 -0
  57. package/dist/css/vite/hmr.d.ts +4 -4
  58. package/dist/css/vite/hmr.js +14 -27
  59. package/dist/css/vite/vitePlugin.d.ts +5 -5
  60. package/dist/css/vite/vitePlugin.js +21 -30
  61. package/dist/css/watch/{moduleCssWatcher.d.ts → watcher.d.ts} +8 -4
  62. package/dist/css/watch/watcher.js +91 -0
  63. package/dist/index.d.ts +15 -12
  64. package/dist/index.js +6 -5
  65. package/dist/types.d.ts +40 -20
  66. package/dist/utils.d.ts +5 -1
  67. package/dist/utils.js +37 -12
  68. package/package.json +19 -14
  69. package/dist/css/core/config.d.ts +0 -2
  70. package/dist/css/core/config.js +0 -11
  71. package/dist/css/core/constants.d.ts +0 -3
  72. package/dist/css/core/constants.js +0 -3
  73. package/dist/css/core/moduleCssGraph.d.ts +0 -51
  74. package/dist/css/core/moduleCssGraph.js +0 -416
  75. package/dist/css/core/path.d.ts +0 -4
  76. package/dist/css/core/path.js +0 -26
  77. package/dist/css/core/styleEntry.d.ts +0 -45
  78. package/dist/css/core/styleEntry.js +0 -108
  79. package/dist/css/production/moduleCssBuilder.d.ts +0 -33
  80. package/dist/css/production/moduleCssBuilder.js +0 -445
  81. package/dist/css/watch/moduleCssWatcher.js +0 -106
package/README.md CHANGED
@@ -1,4 +1,11 @@
1
- # auklet
1
+ <div align="center">
2
+ <h2>auklet</h2>
3
+
4
+ [![NPM version](https://img.shields.io/npm/v/auklet.svg?style=flat-square)](https://www.npmjs.com/package/auklet)
5
+
6
+ </div>
7
+
8
+ <h1></h1>
2
9
 
3
10
  Build utilities for TypeScript packages and module CSS output.
4
11
 
@@ -45,59 +52,109 @@ Create `auklet.config.ts` in the package root:
45
52
  import type { AukletConfig } from 'auklet';
46
53
 
47
54
  export const config: AukletConfig = {
48
- sourceDir: 'src',
49
- outputDir: 'dist',
50
- themes: {
51
- light: './src/themes/light.css',
52
- dark: './src/themes/dark.css',
53
- },
54
- cssDependencies: {
55
- '@scope/ui': {
56
- global: '/style.css',
57
- component: ['/components/**.css'],
55
+ source: 'src',
56
+ output: 'dist',
57
+ styles: {
58
+ themes: {
59
+ light: './src/themes/light.css',
60
+ dark: './src/themes/dark.css',
58
61
  },
59
- '@scope/theme': {
60
- global: '/style.css',
61
- themes: {
62
- light: '/themes/light.css',
63
- dark: '/themes/dark.css',
62
+ dependencies: {
63
+ '@scope/ui': {
64
+ entry: '/style.css',
65
+ components: ['/components/**.css'],
66
+ },
67
+ '@scope/theme': {
68
+ entry: '/style.css',
69
+ themes: {
70
+ light: '/themes/light.css',
71
+ dark: '/themes/dark.css',
72
+ },
64
73
  },
65
74
  },
66
75
  },
76
+ modules: true,
67
77
  build: {
68
78
  formats: ['esm', 'cjs'],
69
- modules: true,
79
+ target: 'es2020',
70
80
  tsconfig: 'tsconfig.json',
71
81
  },
72
82
  };
73
83
  ```
74
84
 
75
- ### CSS Options
85
+ ### Style Options
76
86
 
77
- - `sourceDir`: source directory relative to the package root. Defaults to `src`.
78
- - `outputDir`: build output directory relative to the package root. Defaults to `dist`.
79
- - `themes`: package theme style entries. Defaults to no themes.
80
- - `cssDependencies`: external package style dependencies.
87
+ - `source`: source directory relative to the package root. Defaults to `src`.
88
+ - `output`: build output directory relative to the package root. Defaults to `dist`.
89
+ - `styles.themes`: package theme style entries. Defaults to `{}`.
90
+ - `styles.dependencies`: external package style dependencies. Defaults to `{}`.
81
91
 
82
- Each `cssDependencies` entry may define:
92
+ Each `styles.dependencies` entry may define:
83
93
 
84
- - `global`: package-level style dependency.
94
+ - `entry`: package-level style dependency.
85
95
  - `themes`: theme style dependency map.
86
- - `component`: glob-like component style rules used to infer style imports from source imports.
96
+ - `components`: glob-like component style rules used to infer style imports from source imports.
97
+
98
+ Component style inference only scans source `.tsx` files. Component imports or
99
+ re-exports in `.ts` files are ignored for CSS auto import, so component barrel
100
+ files that should drive component CSS must be `.tsx`.
101
+
102
+ Supported value forms include named imports, named re-exports, and local
103
+ re-exports that can be traced back to an import binding:
104
+
105
+ ```tsx
106
+ import { Button } from '@scope/ui';
107
+ export { Card } from '@scope/ui/components/Card';
108
+
109
+ import { Dialog as BaseDialog } from '@scope/ui';
110
+ export { BaseDialog as Dialog };
111
+ ```
112
+
113
+ `export * from '...'` is intentionally not supported for CSS auto import because
114
+ the exported component names cannot be inferred reliably.
115
+
116
+ Style configuration should use the grouped `styles` field.
117
+
118
+ ```ts
119
+ export const config: AukletConfig = {
120
+ styles: {
121
+ dependencies: {
122
+ '@scope/ui': {
123
+ entry: '/style.css',
124
+ components: ['/components/**.css'],
125
+ },
126
+ },
127
+ },
128
+ };
129
+ ```
87
130
 
88
131
  ### Build Options
89
132
 
90
- - `formats`: package bundle formats: `esm`, `cjs`, or `iife`.
91
- - `banner`: custom bundle banner.
92
- - `externals`: additional external packages.
93
- - `modules`: whether to generate unbundled `dist/es` and `dist/lib` output.
94
- - `tsconfig`: TypeScript config path relative to the package root.
133
+ - `modules`: whether to generate unbundled `dist/es` and `dist/lib` output. Defaults to `false`. CSS module style entries also follow this flag.
134
+ - `build.formats`: package bundle formats: `esm`, `cjs`, or `iife`. Defaults to `['cjs', 'esm', 'iife']`.
135
+ - `build.target`: JavaScript compilation target passed to tsdown. Defaults to `es2020` and is shared by bundle, global, and module output.
136
+ - `build.platform`: build target runtime platform: `neutral`, `node`, or `browser`. Defaults to `neutral`.
137
+ - `build.banner`: custom bundle banner. Defaults to a package name/version banner.
138
+ - `build.externals`: additional external packages. Defaults to `[]`.
139
+ - `build.tsconfig`: TypeScript config path relative to the package root. Defaults to the nearest `tsconfig.json` found from the package root upward.
140
+
141
+ ### Build Constants
142
+
143
+ `auk build` injects these compile-time constants into bundled output:
144
+
145
+ - `__DEV__`: `true` when `process.env.NODE_ENV !== 'production'`, otherwise `false`.
146
+ - `__TEST__`: always `false` in package builds.
147
+ - `__VERSION__`: current package version from `package.json`.
148
+
149
+ Vitest uses the same names with test-friendly values: `__DEV__` is `true`, `__TEST__` is `true`, and `__VERSION__` is `'unknown'`.
95
150
 
96
151
  ## CSS Output
97
152
 
98
- `build-css` generates package and module style entries under the output directory.
153
+ `build-css` always generates the package-level `index.css` when source styles exist.
154
+
155
+ Module style entries under `dist/es` and `dist/lib` are generated only when `modules` is `true`, matching the JavaScript module output.
99
156
 
100
- Typical output includes:
157
+ Typical module output includes:
101
158
 
102
159
  ```text
103
160
  dist/
@@ -129,13 +186,13 @@ Important entry semantics:
129
186
 
130
187
  ## Vite Plugin
131
188
 
132
- Use `aukletCssPlugin` in Vite dev mode to load virtual package CSS entries.
189
+ Use `aukletStylePlugin` in Vite dev mode to load virtual package CSS entries.
133
190
 
134
191
  ```ts
135
- import { aukletCssPlugin } from 'auklet';
192
+ import { aukletStylePlugin } from 'auklet';
136
193
 
137
194
  export default {
138
- plugins: [aukletCssPlugin()],
195
+ plugins: [aukletStylePlugin()],
139
196
  };
140
197
  ```
141
198
 
@@ -151,16 +208,16 @@ import '@scope/app/themes/light.css';
151
208
 
152
209
  ```ts
153
210
  import {
154
- ModuleCssBuilder,
155
- ModuleCssWatcher,
156
- aukletCssPlugin,
211
+ ModuleStyleBuilder,
212
+ ModuleStyleWatcher,
213
+ aukletStylePlugin,
157
214
  loadAukletConfig,
158
215
  runTsdown,
159
216
  } from 'auklet';
160
217
 
161
218
  const aukletConfig = await loadAukletConfig(process.cwd());
162
219
 
163
- await new ModuleCssBuilder({
220
+ await new ModuleStyleBuilder({
164
221
  packageRoot: process.cwd(),
165
222
  aukletConfig,
166
223
  }).build();
@@ -168,9 +225,9 @@ await new ModuleCssBuilder({
168
225
 
169
226
  Public exports include:
170
227
 
171
- - `ModuleCssBuilder`
172
- - `ModuleCssWatcher`
173
- - `aukletCssPlugin`
228
+ - `ModuleStyleBuilder`
229
+ - `ModuleStyleWatcher`
230
+ - `aukletStylePlugin`
174
231
  - `loadAukletConfig`
175
232
  - `resolveAukletConfigModule`
176
233
  - `createTsdownArgs`
package/bin/entry.cjs CHANGED
@@ -4,7 +4,19 @@ const fs = require('node:fs');
4
4
  const path = require('node:path');
5
5
  const minimist = require('minimist');
6
6
 
7
- const runBuildCss = async (args) => {
7
+ const getPackageVersion = () => {
8
+ const packageJson = JSON.parse(
9
+ fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'),
10
+ );
11
+ return packageJson.version;
12
+ };
13
+
14
+ const runVersion = async () => {
15
+ console.log(getPackageVersion());
16
+ return 0;
17
+ };
18
+
19
+ const runBuildStyle = async (args) => {
8
20
  const shouldWatch = args.includes('--watch') || args.includes('-w');
9
21
  const { loadAukletConfig } = await import('../dist/configLoader.js');
10
22
  const aukletConfig = await loadAukletConfig(process.cwd(), {
@@ -12,10 +24,8 @@ const runBuildCss = async (args) => {
12
24
  });
13
25
 
14
26
  if (shouldWatch) {
15
- const { ModuleCssWatcher } = await import(
16
- '../dist/css/watch/moduleCssWatcher.js'
17
- );
18
- const watcher = new ModuleCssWatcher({ aukletConfig, logger: console });
27
+ const { ModuleStyleWatcher } = await import('../dist/css/watch/watcher.js');
28
+ const watcher = new ModuleStyleWatcher({ aukletConfig, logger: console });
19
29
  await watcher.watch();
20
30
  const close = () => {
21
31
  watcher
@@ -29,10 +39,10 @@ const runBuildCss = async (args) => {
29
39
  return 0;
30
40
  }
31
41
 
32
- const { ModuleCssBuilder } = await import(
33
- '../dist/css/production/moduleCssBuilder.js'
42
+ const { ModuleStyleBuilder } = await import(
43
+ '../dist/css/production/builder.js'
34
44
  );
35
- const builder = new ModuleCssBuilder({ aukletConfig, logger: console });
45
+ const builder = new ModuleStyleBuilder({ aukletConfig, logger: console });
36
46
  await builder.build();
37
47
  return 0;
38
48
  };
@@ -51,7 +61,7 @@ const runBuild = async (args) => {
51
61
  const jsExitCode = await runBuildJs(args);
52
62
  if (jsExitCode) return jsExitCode;
53
63
 
54
- return runBuildCss([]);
64
+ return runBuildStyle([]);
55
65
  };
56
66
 
57
67
  const runDev = async () => {
@@ -90,9 +100,10 @@ const runDev = async () => {
90
100
  };
91
101
 
92
102
  const argv = minimist(process.argv.slice(2), {
93
- boolean: ['help'],
103
+ boolean: ['help', 'version'],
94
104
  alias: {
95
105
  h: 'help',
106
+ v: 'version',
96
107
  },
97
108
  });
98
109
  const [command, ...args] = argv._;
@@ -100,6 +111,11 @@ const commandIndex = process.argv.indexOf(command);
100
111
  const commandArgs =
101
112
  commandIndex >= 0 ? process.argv.slice(commandIndex + 1) : args;
102
113
 
114
+ if (argv.version) {
115
+ console.log(getPackageVersion());
116
+ process.exit(0);
117
+ }
118
+
103
119
  if (argv.help || !command) {
104
120
  console.log('Usage: auk <command>');
105
121
  console.log('');
@@ -108,14 +124,20 @@ if (argv.help || !command) {
108
124
  console.log(' build-js Build package JavaScript output with tsdown');
109
125
  console.log(' build-css Build package module CSS output, supports --watch');
110
126
  console.log(' dev Watch package JavaScript and CSS output');
127
+ console.log(' version Print auklet version');
128
+ console.log('');
129
+ console.log('Options:');
130
+ console.log(' -v, --version Print auklet version');
131
+ console.log(' -h, --help Print help');
111
132
  process.exit(argv.help ? 0 : 1);
112
133
  }
113
134
 
114
135
  const runners = {
115
136
  build: runBuild,
116
137
  'build-js': runBuildJs,
117
- 'build-css': runBuildCss,
138
+ 'build-css': runBuildStyle,
118
139
  dev: runDev,
140
+ version: runVersion,
119
141
  };
120
142
 
121
143
  const runner = runners[command];
@@ -25,12 +25,11 @@ export function createTsdownArgs(args) {
25
25
  return [tsdownRunFile, ...tsdownArgs];
26
26
  }
27
27
  export async function runTsdown(args, options = {}) {
28
- var _a, _b;
29
28
  const tsdownArgs = createTsdownArgs(args);
30
29
  const result = await execa(process.execPath, tsdownArgs, {
31
- cwd: (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(),
30
+ cwd: options.cwd ?? process.cwd(),
32
31
  stdio: 'inherit',
33
32
  reject: false,
34
33
  });
35
- return (_b = result.exitCode) !== null && _b !== void 0 ? _b : 0;
34
+ return result.exitCode ?? 0;
36
35
  }
@@ -4,9 +4,145 @@ export type TsdownFormat = PackageBuildFormat;
4
4
  export declare function defineKernelPackageConfigFromOptions(
5
5
  packageRoot?: string,
6
6
  config?: AukletConfig,
7
- ): Array<UserConfig>;
7
+ ): (
8
+ | {
9
+ entry: {
10
+ index: string;
11
+ };
12
+ format: PackageBuildFormat;
13
+ globalName: string;
14
+ outDir: string;
15
+ dts: boolean;
16
+ treeshake: true;
17
+ banner: string;
18
+ outExtensions: () => {
19
+ js: string;
20
+ };
21
+ outputOptions: {
22
+ entryFileNames: string;
23
+ chunkFileNames: string;
24
+ globals: {
25
+ [k: string]: string;
26
+ };
27
+ };
28
+ cwd: string;
29
+ root: string;
30
+ clean: false;
31
+ sourcemap: false;
32
+ tsconfig: string;
33
+ target: NonNullable<
34
+ import('#auklet/types').PackageBuildTarget | undefined
35
+ >;
36
+ platform: NonNullable<
37
+ import('#auklet/types').PackageBuildPlatform | undefined
38
+ >;
39
+ deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
40
+ define: {
41
+ __TEST__: string;
42
+ __VERSION__: string;
43
+ __DEV__: string;
44
+ };
45
+ }
46
+ | {
47
+ entry: Record<string, string>;
48
+ format: 'cjs' | 'esm';
49
+ outDir: string;
50
+ dts: true;
51
+ unbundle: true;
52
+ outExtensions: () => {
53
+ js: string;
54
+ dts: string;
55
+ };
56
+ cwd: string;
57
+ root: string;
58
+ clean: false;
59
+ sourcemap: false;
60
+ tsconfig: string;
61
+ target: NonNullable<
62
+ import('#auklet/types').PackageBuildTarget | undefined
63
+ >;
64
+ platform: NonNullable<
65
+ import('#auklet/types').PackageBuildPlatform | undefined
66
+ >;
67
+ deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
68
+ define: {
69
+ __TEST__: string;
70
+ __VERSION__: string;
71
+ __DEV__: string;
72
+ };
73
+ }
74
+ )[];
8
75
  export declare function defineKernelPackageConfigFromFile(
9
76
  packageRoot?: string,
10
- ): Promise<Array<UserConfig>>;
77
+ ): Promise<
78
+ (
79
+ | {
80
+ entry: {
81
+ index: string;
82
+ };
83
+ format: PackageBuildFormat;
84
+ globalName: string;
85
+ outDir: string;
86
+ dts: boolean;
87
+ treeshake: true;
88
+ banner: string;
89
+ outExtensions: () => {
90
+ js: string;
91
+ };
92
+ outputOptions: {
93
+ entryFileNames: string;
94
+ chunkFileNames: string;
95
+ globals: {
96
+ [k: string]: string;
97
+ };
98
+ };
99
+ cwd: string;
100
+ root: string;
101
+ clean: false;
102
+ sourcemap: false;
103
+ tsconfig: string;
104
+ target: NonNullable<
105
+ import('#auklet/types').PackageBuildTarget | undefined
106
+ >;
107
+ platform: NonNullable<
108
+ import('#auklet/types').PackageBuildPlatform | undefined
109
+ >;
110
+ deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
111
+ define: {
112
+ __TEST__: string;
113
+ __VERSION__: string;
114
+ __DEV__: string;
115
+ };
116
+ }
117
+ | {
118
+ entry: Record<string, string>;
119
+ format: 'cjs' | 'esm';
120
+ outDir: string;
121
+ dts: true;
122
+ unbundle: true;
123
+ outExtensions: () => {
124
+ js: string;
125
+ dts: string;
126
+ };
127
+ cwd: string;
128
+ root: string;
129
+ clean: false;
130
+ sourcemap: false;
131
+ tsconfig: string;
132
+ target: NonNullable<
133
+ import('#auklet/types').PackageBuildTarget | undefined
134
+ >;
135
+ platform: NonNullable<
136
+ import('#auklet/types').PackageBuildPlatform | undefined
137
+ >;
138
+ deps: import('node_modules/tsdown/dist/types-CQaSBA5U.mjs').L;
139
+ define: {
140
+ __TEST__: string;
141
+ __VERSION__: string;
142
+ __DEV__: string;
143
+ };
144
+ }
145
+ )[]
146
+ >;
11
147
  declare const _default: Promise<UserConfig[]>;
12
148
  export default _default;