auklet 0.0.2 → 0.0.4

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 (79) hide show
  1. package/README.md +81 -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 +39 -2
  7. package/dist/config.js +44 -3
  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 +6 -0
  12. package/dist/css/constants.js +6 -0
  13. package/dist/css/core/moduleGraph.d.ts +55 -0
  14. package/dist/css/core/moduleGraph.js +362 -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/moduleStyleImportCollector.d.ts +5 -3
  18. package/dist/css/core/moduleStyleImportCollector.js +27 -45
  19. package/dist/css/core/style/dependencies.d.ts +20 -0
  20. package/dist/css/core/style/dependencies.js +55 -0
  21. package/dist/css/core/style/files.d.ts +8 -0
  22. package/dist/css/core/style/files.js +19 -0
  23. package/dist/css/core/style/plan.d.ts +59 -0
  24. package/dist/css/core/style/plan.js +27 -0
  25. package/dist/css/core/style/specifier.d.ts +14 -0
  26. package/dist/css/core/style/specifier.js +27 -0
  27. package/dist/css/core/styleModuleEntryPlanner.d.ts +29 -0
  28. package/dist/css/core/styleModuleEntryPlanner.js +66 -0
  29. package/dist/css/core/stylePackageContext.d.ts +27 -0
  30. package/dist/css/core/stylePackageContext.js +57 -0
  31. package/dist/css/core/styleProcessor.d.ts +3 -3
  32. package/dist/css/core/styleProcessor.js +21 -41
  33. package/dist/css/core/workspaceStyleResolver.d.ts +4 -5
  34. package/dist/css/core/workspaceStyleResolver.js +12 -28
  35. package/dist/css/production/builder.d.ts +18 -0
  36. package/dist/css/production/builder.js +68 -0
  37. package/dist/css/production/format/componentWriter.d.ts +12 -0
  38. package/dist/css/production/format/componentWriter.js +67 -0
  39. package/dist/css/production/format/entryWriter.d.ts +12 -0
  40. package/dist/css/production/format/entryWriter.js +54 -0
  41. package/dist/css/production/format/externalWriter.d.ts +9 -0
  42. package/dist/css/production/format/externalWriter.js +39 -0
  43. package/dist/css/production/format/moduleWriter.d.ts +8 -0
  44. package/dist/css/production/format/moduleWriter.js +31 -0
  45. package/dist/css/production/format/shared.d.ts +20 -0
  46. package/dist/css/production/format/shared.js +8 -0
  47. package/dist/css/production/format/sourceWriter.d.ts +6 -0
  48. package/dist/css/production/format/sourceWriter.js +16 -0
  49. package/dist/css/production/format/themeWriter.d.ts +16 -0
  50. package/dist/css/production/format/themeWriter.js +80 -0
  51. package/dist/css/production/moduleOutputWriter.d.ts +26 -0
  52. package/dist/css/production/moduleOutputWriter.js +83 -0
  53. package/dist/css/production/packageEntryWriter.d.ts +20 -0
  54. package/dist/css/production/packageEntryWriter.js +55 -0
  55. package/dist/css/vite/hmr.d.ts +4 -4
  56. package/dist/css/vite/hmr.js +14 -27
  57. package/dist/css/vite/vitePlugin.d.ts +5 -5
  58. package/dist/css/vite/vitePlugin.js +21 -30
  59. package/dist/css/watch/{moduleCssWatcher.d.ts → watcher.d.ts} +7 -4
  60. package/dist/css/watch/watcher.js +82 -0
  61. package/dist/index.d.ts +17 -12
  62. package/dist/index.js +8 -4
  63. package/dist/types.d.ts +41 -23
  64. package/dist/utils.d.ts +5 -1
  65. package/dist/utils.js +37 -12
  66. package/package.json +12 -9
  67. package/dist/css/core/config.d.ts +0 -2
  68. package/dist/css/core/config.js +0 -18
  69. package/dist/css/core/constants.d.ts +0 -3
  70. package/dist/css/core/constants.js +0 -3
  71. package/dist/css/core/moduleCssGraph.d.ts +0 -51
  72. package/dist/css/core/moduleCssGraph.js +0 -412
  73. package/dist/css/core/path.d.ts +0 -4
  74. package/dist/css/core/path.js +0 -26
  75. package/dist/css/core/styleEntry.d.ts +0 -45
  76. package/dist/css/core/styleEntry.js +0 -108
  77. package/dist/css/production/moduleCssBuilder.d.ts +0 -33
  78. package/dist/css/production/moduleCssBuilder.js +0 -444
  79. package/dist/css/watch/moduleCssWatcher.js +0 -106
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { defineConfig } from 'tsdown/config';
4
4
  import { loadAukletConfig } from '#auklet/configLoader';
5
+ import { normalizeAukletConfig } from '#auklet/config';
5
6
  const formatMap = {
6
7
  cjs: '.cjs',
7
8
  iife: '.global.js',
@@ -16,23 +17,19 @@ const getExternal = (names) => {
16
17
  return [...external];
17
18
  };
18
19
  const getPackageExternal = (pkg, options) => {
19
- var _a, _b, _c;
20
20
  return getExternal([
21
- ...Object.keys((_a = pkg.dependencies) !== null && _a !== void 0 ? _a : {}),
22
- ...Object.keys(
23
- (_b = pkg.peerDependencies) !== null && _b !== void 0 ? _b : {},
24
- ),
25
- ...((_c = options.externals) !== null && _c !== void 0 ? _c : []),
21
+ ...Object.keys(pkg.dependencies ?? {}),
22
+ ...Object.keys(pkg.peerDependencies ?? {}),
23
+ ...Object.keys(pkg.optionalDependencies ?? {}),
24
+ ...Object.keys(pkg.devDependencies ?? {}),
25
+ ...(options.externals ?? []),
26
26
  ]);
27
27
  };
28
28
  const getPeerExternal = (pkg, options) => {
29
- var _a, _b;
30
29
  return [
31
30
  ...new Set([
32
- ...Object.keys(
33
- (_a = pkg.peerDependencies) !== null && _a !== void 0 ? _a : {},
34
- ),
35
- ...((_b = options.externals) !== null && _b !== void 0 ? _b : []),
31
+ ...Object.keys(pkg.peerDependencies ?? {}),
32
+ ...(options.externals ?? []),
36
33
  ]),
37
34
  ];
38
35
  };
@@ -50,7 +47,7 @@ const getIifeGlobals = (context) => {
50
47
  );
51
48
  };
52
49
  const getIifeAlwaysBundle = (context) => {
53
- const names = new Set(context.dependencyNames);
50
+ const names = new Set(context.runtimeDependencyNames);
54
51
  if (context.peerExternal.includes('react')) {
55
52
  names.add('react/jsx-runtime');
56
53
  names.add('react/jsx-dev-runtime');
@@ -58,13 +55,7 @@ const getIifeAlwaysBundle = (context) => {
58
55
  return [...names];
59
56
  };
60
57
  const getGlobalName = (pkg) => {
61
- var _a;
62
- return (
63
- (_a = pkg === null || pkg === void 0 ? void 0 : pkg.name) !== null &&
64
- _a !== void 0
65
- ? _a
66
- : ''
67
- )
58
+ return (pkg?.name ?? '')
68
59
  .replace(/@/g, '')
69
60
  .split(/[/-]/g)
70
61
  .map((label) => label[0].toUpperCase() + label.slice(1))
@@ -80,43 +71,89 @@ const findWorkspaceTsconfig = (packageRoot) => {
80
71
  current = parent;
81
72
  }
82
73
  };
83
- const createBuildContext = (packageRoot, options) => {
84
- var _a, _b;
74
+ const getBundleEntry = (packageRoot) => {
75
+ const tsEntry = 'src/index.ts';
76
+ const tsxEntry = 'src/index.tsx';
77
+ if (fs.existsSync(path.join(packageRoot, tsEntry))) {
78
+ return { index: tsEntry };
79
+ }
80
+ if (fs.existsSync(path.join(packageRoot, tsxEntry))) {
81
+ return { index: tsxEntry };
82
+ }
83
+ return { index: tsEntry };
84
+ };
85
+ const toPosixPath = (value) => {
86
+ return value.split(path.sep).join('/');
87
+ };
88
+ const getModuleEntries = (packageRoot) => {
89
+ const sourceRoot = path.join(packageRoot, 'src');
90
+ const entries = {};
91
+ if (!fs.existsSync(sourceRoot)) {
92
+ return getBundleEntry(packageRoot);
93
+ }
94
+ const collect = (dir) => {
95
+ const dirEntries = fs
96
+ .readdirSync(dir, { withFileTypes: true })
97
+ .sort((a, b) => a.name.localeCompare(b.name));
98
+ for (const dirEntry of dirEntries) {
99
+ const file = path.join(dir, dirEntry.name);
100
+ if (dirEntry.isDirectory()) {
101
+ if (dirEntry.name !== '__tests__') collect(file);
102
+ continue;
103
+ }
104
+ if (!/\.(ts|tsx)$/.test(dirEntry.name)) continue;
105
+ if (/\.d\.ts$/.test(dirEntry.name)) continue;
106
+ if (/\.(spec|test)\.(ts|tsx)$/.test(dirEntry.name)) continue;
107
+ const sourceRelative = toPosixPath(path.relative(packageRoot, file));
108
+ const entryName = toPosixPath(path.relative(sourceRoot, file)).replace(
109
+ /\.(ts|tsx)$/,
110
+ '',
111
+ );
112
+ entries[entryName] ??= sourceRelative;
113
+ }
114
+ };
115
+ collect(sourceRoot);
116
+ return Object.keys(entries).length > 0
117
+ ? entries
118
+ : getBundleEntry(packageRoot);
119
+ };
120
+ const createBuildContext = (packageRoot, options, output) => {
85
121
  const pkg = JSON.parse(
86
122
  fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'),
87
123
  );
88
124
  const banner =
89
- (_a = options.banner) !== null && _a !== void 0
90
- ? _a
91
- : '/*!\n' +
92
- ` * ${pkg.name}.js v${pkg.version}\n` +
93
- (pkg.author
94
- ? ` * (c) 2026-${new Date().getFullYear()} ${pkg.author}\n`
95
- : '') +
96
- ' */';
125
+ options.banner ??
126
+ '/*!\n' +
127
+ ` * ${pkg.name}.js v${pkg.version}\n` +
128
+ (pkg.author
129
+ ? ` * (c) 2026-${new Date().getFullYear()} ${pkg.author}\n`
130
+ : '') +
131
+ ' */';
97
132
  return {
98
- packageRoot,
99
- tsconfig: options.tsconfig
100
- ? path.resolve(packageRoot, options.tsconfig)
101
- : findWorkspaceTsconfig(packageRoot),
102
133
  pkg,
103
- dependencyNames: Object.keys(
104
- (_b = pkg.dependencies) !== null && _b !== void 0 ? _b : {},
105
- ),
134
+ banner,
135
+ packageRoot,
136
+ output,
137
+ runtimeDependencyNames: Object.keys(pkg.dependencies ?? {}),
106
138
  packageExternal: getPackageExternal(pkg, options),
107
139
  peerExternal: getPeerExternal(pkg, options),
108
140
  globalName: getGlobalName(pkg),
109
- banner,
141
+ platform: options.platform,
142
+ target: options.target,
143
+ tsconfig: options.tsconfig
144
+ ? path.resolve(packageRoot, options.tsconfig)
145
+ : findWorkspaceTsconfig(packageRoot),
110
146
  };
111
147
  };
112
148
  const createCommonConfig = (context, deps) => {
113
149
  return {
114
150
  cwd: context.packageRoot,
151
+ root: context.packageRoot,
115
152
  clean: false,
116
153
  sourcemap: false,
117
154
  tsconfig: context.tsconfig,
118
- target: 'es2018',
119
- platform: 'browser',
155
+ target: context.target,
156
+ platform: context.platform,
120
157
  deps,
121
158
  define: {
122
159
  __TEST__: 'false',
@@ -128,13 +165,16 @@ const createCommonConfig = (context, deps) => {
128
165
  };
129
166
  const createBundleConfigs = (context, formats) => {
130
167
  const outputConfigs = [];
168
+ let hasDtsConfig = false;
131
169
  for (const format of formats) {
132
170
  const extnames = formatMap[format];
133
171
  for (const extname of Array.isArray(extnames) ? extnames : [extnames]) {
134
- outputConfigs.push({ format, extname });
172
+ const emitDts = !hasDtsConfig;
173
+ outputConfigs.push({ format, extname, dts: emitDts });
174
+ hasDtsConfig ||= emitDts;
135
175
  }
136
176
  }
137
- return outputConfigs.map(({ format, extname }) => {
177
+ return outputConfigs.map(({ format, extname, dts }) => {
138
178
  const deps =
139
179
  format === 'iife'
140
180
  ? {
@@ -147,11 +187,11 @@ const createBundleConfigs = (context, formats) => {
147
187
  };
148
188
  return {
149
189
  ...createCommonConfig(context, deps),
150
- entry: ['src/index.ts'],
190
+ entry: getBundleEntry(context.packageRoot),
151
191
  format,
152
192
  globalName: context.globalName,
153
- outDir: 'dist',
154
- dts: false,
193
+ outDir: context.output,
194
+ dts,
155
195
  treeshake: true,
156
196
  banner: context.banner,
157
197
  outExtensions: () => ({
@@ -165,17 +205,10 @@ const createBundleConfigs = (context, formats) => {
165
205
  };
166
206
  });
167
207
  };
168
- const createModuleConfig = (commonConfig, format, outDir) => {
208
+ const createModuleConfig = (commonConfig, entry, format, outDir) => {
169
209
  return {
170
210
  ...commonConfig,
171
- entry: [
172
- 'src/**/*.ts',
173
- 'src/**/*.tsx',
174
- '!src/**/*.d.ts',
175
- '!src/**/__tests__/**',
176
- '!src/**/*.spec.ts',
177
- '!src/**/*.spec.tsx',
178
- ],
211
+ entry,
179
212
  format,
180
213
  outDir,
181
214
  dts: true,
@@ -190,24 +223,36 @@ const createModuleConfigs = (context) => {
190
223
  const commonConfig = createCommonConfig(context, {
191
224
  neverBundle: context.packageExternal,
192
225
  });
226
+ const entry = getModuleEntries(context.packageRoot);
193
227
  return [
194
- createModuleConfig(commonConfig, 'esm', 'dist/es'),
195
- createModuleConfig(commonConfig, 'cjs', 'dist/lib'),
228
+ createModuleConfig(
229
+ commonConfig,
230
+ entry,
231
+ 'esm',
232
+ path.join(context.output, 'es'),
233
+ ),
234
+ createModuleConfig(
235
+ commonConfig,
236
+ entry,
237
+ 'cjs',
238
+ path.join(context.output, 'lib'),
239
+ ),
196
240
  ];
197
241
  };
198
242
  export function defineKernelPackageConfigFromOptions(
199
243
  packageRoot = process.cwd(),
200
244
  config = {},
201
245
  ) {
202
- var _a, _b;
203
- const buildOptions = (_a = config.build) !== null && _a !== void 0 ? _a : {};
204
- const formats =
205
- (_b = buildOptions.formats) !== null && _b !== void 0
206
- ? _b
207
- : ['cjs', 'esm', 'iife'];
208
- const context = createBuildContext(packageRoot, buildOptions);
246
+ const normalizedConfig = normalizeAukletConfig(config);
247
+ const buildOptions = normalizedConfig.build;
248
+ const formats = buildOptions.formats;
249
+ const context = createBuildContext(
250
+ packageRoot,
251
+ buildOptions,
252
+ normalizedConfig.output,
253
+ );
209
254
  const bundleConfigs = createBundleConfigs(context, formats);
210
- const moduleConfigs = buildOptions.modules
255
+ const moduleConfigs = normalizedConfig.modules
211
256
  ? createModuleConfigs(context)
212
257
  : [];
213
258
  return [...bundleConfigs, ...moduleConfigs];
package/dist/config.d.ts CHANGED
@@ -1,3 +1,40 @@
1
- import type { CssDependencyGroup } from '#auklet/types';
1
+ import type { AukletConfig, StyleDependencyGroup } from '#auklet/types';
2
2
  export declare const aukletConfigFile = 'auklet.config.ts';
3
- export declare const aukletDefaultCssDependencyConfig: CssDependencyGroup;
3
+ export declare const aukletDefaultOptions: {
4
+ source: string;
5
+ output: string;
6
+ modules: false;
7
+ build: {
8
+ formats: ('cjs' | 'esm' | 'iife')[];
9
+ target: string;
10
+ platform: 'neutral';
11
+ };
12
+ styles: {
13
+ themes: {};
14
+ dependencies: {};
15
+ };
16
+ };
17
+ export declare const aukletDefaultStyleDependencyConfig: StyleDependencyGroup;
18
+ export declare function normalizeAukletConfig(config?: AukletConfig): {
19
+ source: string;
20
+ output: string;
21
+ modules: boolean;
22
+ build: {
23
+ formats: Array<import('#auklet/types').PackageBuildFormat>;
24
+ target: import('#auklet/types').PackageBuildTarget;
25
+ platform: import('#auklet/types').PackageBuildPlatform;
26
+ banner?: string;
27
+ externals?: Array<string>;
28
+ tsconfig?: string;
29
+ };
30
+ styles: {
31
+ themes: {};
32
+ dependencies: {
33
+ [k: string]: {
34
+ entry: string | string[] | undefined;
35
+ themes: Record<string, string> | undefined;
36
+ components: string | string[] | undefined;
37
+ };
38
+ };
39
+ };
40
+ };
package/dist/config.js CHANGED
@@ -1,9 +1,50 @@
1
1
  export const aukletConfigFile = 'auklet.config.ts';
2
- export const aukletDefaultCssDependencyConfig = {
3
- global: '/style.css',
4
- component: ['/pages/**.css', '/components/**.css'],
2
+ export const aukletDefaultOptions = {
3
+ source: 'src',
4
+ output: 'dist',
5
+ modules: false,
6
+ build: {
7
+ formats: ['cjs', 'esm', 'iife'],
8
+ target: 'es2020',
9
+ platform: 'neutral',
10
+ },
11
+ styles: {
12
+ themes: {},
13
+ dependencies: {},
14
+ },
15
+ };
16
+ export const aukletDefaultStyleDependencyConfig = {
17
+ entry: '/style.css',
18
+ components: ['/pages/**.css', '/components/**.css'],
5
19
  themes: {
6
20
  dark: '/themes/dark.css',
7
21
  light: '/themes/light.css',
8
22
  },
9
23
  };
24
+ const normalizeStyleDependency = (dependency) => ({
25
+ entry: dependency.entry,
26
+ themes: dependency.themes,
27
+ components: dependency.components,
28
+ });
29
+ export function normalizeAukletConfig(config = {}) {
30
+ const dependencies =
31
+ config.styles?.dependencies ?? aukletDefaultOptions.styles.dependencies;
32
+ return {
33
+ source: config.source ?? aukletDefaultOptions.source,
34
+ output: config.output ?? aukletDefaultOptions.output,
35
+ modules: config.modules ?? aukletDefaultOptions.modules,
36
+ build: {
37
+ ...aukletDefaultOptions.build,
38
+ ...config.build,
39
+ },
40
+ styles: {
41
+ themes: config.styles?.themes ?? aukletDefaultOptions.styles.themes,
42
+ dependencies: Object.fromEntries(
43
+ Object.entries(dependencies).map(([packageName, dependency]) => [
44
+ packageName,
45
+ normalizeStyleDependency(dependency),
46
+ ]),
47
+ ),
48
+ },
49
+ };
50
+ }
@@ -64,10 +64,9 @@ export function resolveAukletConfigModule(module) {
64
64
  return {};
65
65
  }
66
66
  export async function loadAukletConfig(packageRoot, options = {}) {
67
- var _a;
68
67
  const configPath = path.join(
69
68
  packageRoot,
70
- (_a = options.configFile) !== null && _a !== void 0 ? _a : aukletConfigFile,
69
+ options.configFile ?? aukletConfigFile,
71
70
  );
72
71
  if (!fs.existsSync(configPath)) {
73
72
  return {};
@@ -0,0 +1,2 @@
1
+ import type { ModuleStyleBuildConfig } from '#auklet/types';
2
+ export declare const moduleStyleBuildConfig: ModuleStyleBuildConfig;
@@ -0,0 +1,10 @@
1
+ export const moduleStyleBuildConfig = {
2
+ styleExtensions: ['.css'],
3
+ output: {
4
+ styleDir: 'style',
5
+ indexStyleFile: 'index.css',
6
+ moduleStyleFile: 'module.css',
7
+ externalStyleFile: 'external.css',
8
+ outputFormats: ['es', 'lib'],
9
+ },
10
+ };
@@ -0,0 +1,6 @@
1
+ export declare const NODE_MODULES_DIR = 'node_modules';
2
+ export declare const THEMES_DIR = 'themes';
3
+ export declare const THEMES_ENTRY_PREFIX = 'themes/';
4
+ export declare const STYLE_ENTRY = 'style.css';
5
+ export declare const MODULE_ENTRY = 'module.css';
6
+ export declare const EXTERNAL_ENTRY = 'external.css';
@@ -0,0 +1,6 @@
1
+ export const NODE_MODULES_DIR = 'node_modules';
2
+ export const THEMES_DIR = 'themes';
3
+ export const THEMES_ENTRY_PREFIX = 'themes/';
4
+ export const STYLE_ENTRY = 'style.css';
5
+ export const MODULE_ENTRY = 'module.css';
6
+ export const EXTERNAL_ENTRY = 'external.css';
@@ -0,0 +1,55 @@
1
+ import { type LoadAukletConfig } from '#auklet/css/core/moduleGraphRequestCache';
2
+ import type { ModuleStyleBuildConfig } from '#auklet/types';
3
+ export interface ModuleStyleGraphOptions {
4
+ workspaceRoot: string;
5
+ packagesDir?: string;
6
+ config?: ModuleStyleBuildConfig;
7
+ loadAukletConfig?: LoadAukletConfig;
8
+ }
9
+ export type PackageStyleId = {
10
+ packageName: string;
11
+ stylePath: string;
12
+ };
13
+ export type PackageStyleLoadResult = {
14
+ code: string;
15
+ watchFiles: Array<string>;
16
+ };
17
+ export declare class ModuleStyleGraph {
18
+ private readonly config;
19
+ private readonly workspaceRoot;
20
+ private readonly packagesDir;
21
+ private readonly loadAukletConfig;
22
+ constructor(options: ModuleStyleGraphOptions);
23
+ parsePackageStyleId(id: string): {
24
+ packageName: string;
25
+ stylePath: string;
26
+ } | null;
27
+ isWorkspaceSourceGraphFile(file: string): boolean;
28
+ isStyleConfigFile(file: string): boolean;
29
+ isStyleFile(file: string): boolean;
30
+ getWorkspacePackageNames(): string[];
31
+ getWatchRoots(): string[];
32
+ createPackageStyleCode(parsed: PackageStyleId): Promise<{
33
+ code: string;
34
+ watchFiles: string[];
35
+ }>;
36
+ private createPackageStyleCodeWithCache;
37
+ private createStyleCode;
38
+ private createDependencyStyleCode;
39
+ private createExternalStyleCode;
40
+ private createThemeStyleCode;
41
+ private createModuleStyleCode;
42
+ private createSourceModuleStyleCode;
43
+ private toDevModuleImportSpecifier;
44
+ private toDevExternalStyleSpecifier;
45
+ private parsePackageStyleIdInRequest;
46
+ private isWorkspacePackageName;
47
+ private createRequestCache;
48
+ }
49
+ export declare function parsePackageStyleId(
50
+ id: string,
51
+ packageNames: Array<string>,
52
+ ): {
53
+ packageName: string;
54
+ stylePath: string;
55
+ } | null;