auklet 0.0.1 → 0.0.2
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 +207 -0
- package/bin/entry.cjs +136 -0
- package/dist/build/runTsdown.d.ts +8 -0
- package/dist/build/runTsdown.js +36 -0
- package/dist/build/tsdownConfig.d.ts +12 -0
- package/dist/build/tsdownConfig.js +223 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +9 -0
- package/dist/configLoader.d.ts +8 -0
- package/dist/configLoader.js +85 -0
- package/dist/css/core/config.d.ts +2 -0
- package/dist/css/core/config.js +18 -0
- package/dist/css/core/constants.d.ts +3 -0
- package/dist/css/core/constants.js +3 -0
- package/dist/css/core/moduleCssGraph.d.ts +51 -0
- package/dist/css/core/moduleCssGraph.js +412 -0
- package/dist/css/core/moduleStyleImportCollector.d.ts +29 -0
- package/dist/css/core/moduleStyleImportCollector.js +285 -0
- package/dist/css/core/path.d.ts +4 -0
- package/dist/css/core/path.js +26 -0
- package/dist/css/core/styleEntry.d.ts +45 -0
- package/dist/css/core/styleEntry.js +108 -0
- package/dist/css/core/styleProcessor.d.ts +16 -0
- package/dist/css/core/styleProcessor.js +126 -0
- package/dist/css/core/workspaceStyleResolver.d.ts +18 -0
- package/dist/css/core/workspaceStyleResolver.js +100 -0
- package/dist/css/production/moduleCssBuilder.d.ts +33 -0
- package/dist/css/production/moduleCssBuilder.js +444 -0
- package/dist/css/vite/hmr.d.ts +15 -0
- package/dist/css/vite/hmr.js +153 -0
- package/dist/css/vite/vitePlugin.d.ts +24 -0
- package/dist/css/vite/vitePlugin.js +140 -0
- package/dist/css/watch/moduleCssWatcher.d.ts +19 -0
- package/dist/css/watch/moduleCssWatcher.js +106 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +9 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +59 -0
- package/package.json +80 -6
- package/index.js +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# auklet
|
|
2
|
+
|
|
3
|
+
Build utilities for TypeScript packages and module CSS output.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Build JavaScript/TypeScript package output with the bundled tsdown config.
|
|
8
|
+
- Generate package-level and module-level CSS entries.
|
|
9
|
+
- Infer component style dependencies from source imports.
|
|
10
|
+
- Generate theme and external style entry files.
|
|
11
|
+
- Provide a Vite dev plugin for virtual package CSS entries.
|
|
12
|
+
- Watch source/config changes and rebuild module CSS output.
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Node.js `>=22`
|
|
17
|
+
- pnpm `10.27.0`
|
|
18
|
+
|
|
19
|
+
## CLI
|
|
20
|
+
|
|
21
|
+
The package exposes both `auk` and `auklet` commands.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm auk --help
|
|
25
|
+
pnpm auk build
|
|
26
|
+
pnpm auk build-js
|
|
27
|
+
pnpm auk build-css
|
|
28
|
+
pnpm auk build-css --watch
|
|
29
|
+
pnpm auk dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Commands:
|
|
33
|
+
|
|
34
|
+
- `build` removes `dist`, builds JavaScript output, then builds CSS output.
|
|
35
|
+
- `build-js` runs tsdown with the default auklet tsdown config unless a config flag is passed.
|
|
36
|
+
- `build-css` generates module CSS output.
|
|
37
|
+
- `build-css --watch` watches source/config files and rebuilds CSS.
|
|
38
|
+
- `dev` runs JavaScript and CSS watch tasks together.
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
Create `auklet.config.ts` in the package root:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import type { AukletConfig } from 'auklet';
|
|
46
|
+
|
|
47
|
+
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'],
|
|
58
|
+
},
|
|
59
|
+
'@scope/theme': {
|
|
60
|
+
global: '/style.css',
|
|
61
|
+
themes: {
|
|
62
|
+
light: '/themes/light.css',
|
|
63
|
+
dark: '/themes/dark.css',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
build: {
|
|
68
|
+
formats: ['esm', 'cjs'],
|
|
69
|
+
modules: true,
|
|
70
|
+
tsconfig: 'tsconfig.json',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### CSS Options
|
|
76
|
+
|
|
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.
|
|
80
|
+
- `cssDependencies`: external package style dependencies.
|
|
81
|
+
|
|
82
|
+
Each `cssDependencies` entry may define:
|
|
83
|
+
|
|
84
|
+
- `global`: package-level style dependency.
|
|
85
|
+
- `themes`: theme style dependency map.
|
|
86
|
+
- `component`: glob-like component style rules used to infer style imports from source imports.
|
|
87
|
+
|
|
88
|
+
### Build Options
|
|
89
|
+
|
|
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.
|
|
95
|
+
|
|
96
|
+
## CSS Output
|
|
97
|
+
|
|
98
|
+
`build-css` generates package and module style entries under the output directory.
|
|
99
|
+
|
|
100
|
+
Typical output includes:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
dist/
|
|
104
|
+
index.css
|
|
105
|
+
es/
|
|
106
|
+
style/
|
|
107
|
+
index.css
|
|
108
|
+
module.css
|
|
109
|
+
external.css
|
|
110
|
+
themes/
|
|
111
|
+
light.css
|
|
112
|
+
dark.css
|
|
113
|
+
components/
|
|
114
|
+
Button/
|
|
115
|
+
index.css
|
|
116
|
+
style/index.css
|
|
117
|
+
lib/
|
|
118
|
+
...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Important entry semantics:
|
|
122
|
+
|
|
123
|
+
- `index.css`: package-level aggregate CSS.
|
|
124
|
+
- `style/index.css`: package style entry for a specific output format.
|
|
125
|
+
- `style/module.css`: current package module styles.
|
|
126
|
+
- `style/external.css`: external style entries.
|
|
127
|
+
- `components/*/style/index.css`: component-level style entry.
|
|
128
|
+
- `themes/*.css`: theme style entry.
|
|
129
|
+
|
|
130
|
+
## Vite Plugin
|
|
131
|
+
|
|
132
|
+
Use `aukletCssPlugin` in Vite dev mode to load virtual package CSS entries.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { aukletCssPlugin } from 'auklet';
|
|
136
|
+
|
|
137
|
+
export default {
|
|
138
|
+
plugins: [aukletCssPlugin()],
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The plugin resolves package CSS ids such as:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import '@scope/app/style.css';
|
|
146
|
+
import '@scope/app/components/Button.css';
|
|
147
|
+
import '@scope/app/themes/light.css';
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Programmatic API
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import {
|
|
154
|
+
ModuleCssBuilder,
|
|
155
|
+
ModuleCssWatcher,
|
|
156
|
+
aukletCssPlugin,
|
|
157
|
+
loadAukletConfig,
|
|
158
|
+
runTsdown,
|
|
159
|
+
} from 'auklet';
|
|
160
|
+
|
|
161
|
+
const aukletConfig = await loadAukletConfig(process.cwd());
|
|
162
|
+
|
|
163
|
+
await new ModuleCssBuilder({
|
|
164
|
+
packageRoot: process.cwd(),
|
|
165
|
+
aukletConfig,
|
|
166
|
+
}).build();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Public exports include:
|
|
170
|
+
|
|
171
|
+
- `ModuleCssBuilder`
|
|
172
|
+
- `ModuleCssWatcher`
|
|
173
|
+
- `aukletCssPlugin`
|
|
174
|
+
- `loadAukletConfig`
|
|
175
|
+
- `resolveAukletConfigModule`
|
|
176
|
+
- `createTsdownArgs`
|
|
177
|
+
- `runTsdown`
|
|
178
|
+
- related TypeScript types
|
|
179
|
+
|
|
180
|
+
## Development
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
pnpm i
|
|
184
|
+
pnpm run test
|
|
185
|
+
pnpm run typecheck
|
|
186
|
+
pnpm run build
|
|
187
|
+
pnpm run format
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Notes:
|
|
191
|
+
|
|
192
|
+
- `pnpm run build` rewrites `dist`.
|
|
193
|
+
- `pnpm run format` formats `bin`, `src`, and `dist`.
|
|
194
|
+
- `TESTING.md` defines the testing architecture and style rules for future changes.
|
|
195
|
+
|
|
196
|
+
## Testing
|
|
197
|
+
|
|
198
|
+
Tests are organized into:
|
|
199
|
+
|
|
200
|
+
- `src/__tests__/e2e`: project-level output structure and dependency-chain tests.
|
|
201
|
+
- `src/__tests__/css`: module/API tests for CSS and style logic.
|
|
202
|
+
- `src/__tests__/fixtures`: shared virtual project and style structure helpers.
|
|
203
|
+
- `src/__tests__/build`: tsdown/build config tests.
|
|
204
|
+
|
|
205
|
+
Temporary test projects are created under `src/__tests__/.tmp/` and ignored by git.
|
|
206
|
+
|
|
207
|
+
Read `TESTING.md` before adding or changing tests.
|
package/bin/entry.cjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const minimist = require('minimist');
|
|
6
|
+
|
|
7
|
+
const runBuildCss = async (args) => {
|
|
8
|
+
const shouldWatch = args.includes('--watch') || args.includes('-w');
|
|
9
|
+
const { loadAukletConfig } = await import('../dist/configLoader.js');
|
|
10
|
+
const aukletConfig = await loadAukletConfig(process.cwd(), {
|
|
11
|
+
cacheBust: shouldWatch,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (shouldWatch) {
|
|
15
|
+
const { ModuleCssWatcher } = await import(
|
|
16
|
+
'../dist/css/watch/moduleCssWatcher.js'
|
|
17
|
+
);
|
|
18
|
+
const watcher = new ModuleCssWatcher({ aukletConfig, logger: console });
|
|
19
|
+
await watcher.watch();
|
|
20
|
+
const close = () => {
|
|
21
|
+
watcher
|
|
22
|
+
.close()
|
|
23
|
+
.catch(console.error)
|
|
24
|
+
.finally(() => process.exit(0));
|
|
25
|
+
};
|
|
26
|
+
process.once('SIGINT', close);
|
|
27
|
+
process.once('SIGTERM', close);
|
|
28
|
+
await new Promise(() => {});
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { ModuleCssBuilder } = await import(
|
|
33
|
+
'../dist/css/production/moduleCssBuilder.js'
|
|
34
|
+
);
|
|
35
|
+
const builder = new ModuleCssBuilder({ aukletConfig, logger: console });
|
|
36
|
+
await builder.build();
|
|
37
|
+
return 0;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const runBuildJs = async (args) => {
|
|
41
|
+
const { runTsdown } = await import('../dist/build/runTsdown.js');
|
|
42
|
+
return runTsdown(args, { cwd: process.cwd() });
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const runBuild = async (args) => {
|
|
46
|
+
fs.rmSync(path.join(process.cwd(), 'dist'), {
|
|
47
|
+
recursive: true,
|
|
48
|
+
force: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const jsExitCode = await runBuildJs(args);
|
|
52
|
+
if (jsExitCode) return jsExitCode;
|
|
53
|
+
|
|
54
|
+
return runBuildCss([]);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const runDev = async () => {
|
|
58
|
+
const { execa } = await import('execa');
|
|
59
|
+
const { createTsdownArgs } = await import('../dist/build/runTsdown.js');
|
|
60
|
+
const entries = [
|
|
61
|
+
createTsdownArgs(['--watch']),
|
|
62
|
+
[path.resolve(__dirname, './entry.cjs'), 'build-css', '--watch'],
|
|
63
|
+
];
|
|
64
|
+
const processes = entries.map((args) =>
|
|
65
|
+
execa(process.execPath, args, {
|
|
66
|
+
cwd: process.cwd(),
|
|
67
|
+
stdio: 'inherit',
|
|
68
|
+
reject: false,
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const close = () => {
|
|
73
|
+
for (const item of processes) {
|
|
74
|
+
item.kill('SIGTERM');
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
process.once('SIGINT', close);
|
|
79
|
+
process.once('SIGTERM', close);
|
|
80
|
+
|
|
81
|
+
for (const item of processes) {
|
|
82
|
+
item.then((result) => {
|
|
83
|
+
if (result.exitCode) close();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const results = await Promise.all(processes);
|
|
88
|
+
const failed = results.find((result) => result.exitCode);
|
|
89
|
+
return failed?.exitCode ?? 0;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const argv = minimist(process.argv.slice(2), {
|
|
93
|
+
boolean: ['help'],
|
|
94
|
+
alias: {
|
|
95
|
+
h: 'help',
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
const [command, ...args] = argv._;
|
|
99
|
+
const commandIndex = process.argv.indexOf(command);
|
|
100
|
+
const commandArgs =
|
|
101
|
+
commandIndex >= 0 ? process.argv.slice(commandIndex + 1) : args;
|
|
102
|
+
|
|
103
|
+
if (argv.help || !command) {
|
|
104
|
+
console.log('Usage: auk <command>');
|
|
105
|
+
console.log('');
|
|
106
|
+
console.log('Commands:');
|
|
107
|
+
console.log(' build Build package JavaScript and CSS output');
|
|
108
|
+
console.log(' build-js Build package JavaScript output with tsdown');
|
|
109
|
+
console.log(' build-css Build package module CSS output, supports --watch');
|
|
110
|
+
console.log(' dev Watch package JavaScript and CSS output');
|
|
111
|
+
process.exit(argv.help ? 0 : 1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const runners = {
|
|
115
|
+
build: runBuild,
|
|
116
|
+
'build-js': runBuildJs,
|
|
117
|
+
'build-css': runBuildCss,
|
|
118
|
+
dev: runDev,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const runner = runners[command];
|
|
122
|
+
|
|
123
|
+
if (runner) {
|
|
124
|
+
runner(commandArgs)
|
|
125
|
+
.then((exitCode) => {
|
|
126
|
+
process.exit(exitCode ?? 0);
|
|
127
|
+
})
|
|
128
|
+
.catch((error) => {
|
|
129
|
+
console.error(error);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.error(`Unknown auk command: ${command}`);
|
|
136
|
+
process.exit(1);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const tsdownRunFile = require.resolve('tsdown/run');
|
|
6
|
+
const currentExtension = import.meta.url.endsWith('.ts') ? 'ts' : 'js';
|
|
7
|
+
const defaultConfigFile = fileURLToPath(
|
|
8
|
+
new URL(`./tsdownConfig.${currentExtension}`, import.meta.url),
|
|
9
|
+
);
|
|
10
|
+
const hasConfigArg = (args) => {
|
|
11
|
+
return args.some(
|
|
12
|
+
(arg, index) =>
|
|
13
|
+
arg === '--no-config' ||
|
|
14
|
+
arg === '-c' ||
|
|
15
|
+
arg === '--config' ||
|
|
16
|
+
arg.startsWith('--config=') ||
|
|
17
|
+
args[index - 1] === '-c' ||
|
|
18
|
+
args[index - 1] === '--config',
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
export function createTsdownArgs(args) {
|
|
22
|
+
const tsdownArgs = hasConfigArg(args)
|
|
23
|
+
? args
|
|
24
|
+
: ['--config', defaultConfigFile, ...args];
|
|
25
|
+
return [tsdownRunFile, ...tsdownArgs];
|
|
26
|
+
}
|
|
27
|
+
export async function runTsdown(args, options = {}) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const tsdownArgs = createTsdownArgs(args);
|
|
30
|
+
const result = await execa(process.execPath, tsdownArgs, {
|
|
31
|
+
cwd: (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(),
|
|
32
|
+
stdio: 'inherit',
|
|
33
|
+
reject: false,
|
|
34
|
+
});
|
|
35
|
+
return (_b = result.exitCode) !== null && _b !== void 0 ? _b : 0;
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type UserConfig } from 'tsdown/config';
|
|
2
|
+
import type { AukletConfig, PackageBuildFormat } from '#auklet/types';
|
|
3
|
+
export type TsdownFormat = PackageBuildFormat;
|
|
4
|
+
export declare function defineKernelPackageConfigFromOptions(
|
|
5
|
+
packageRoot?: string,
|
|
6
|
+
config?: AukletConfig,
|
|
7
|
+
): Array<UserConfig>;
|
|
8
|
+
export declare function defineKernelPackageConfigFromFile(
|
|
9
|
+
packageRoot?: string,
|
|
10
|
+
): Promise<Array<UserConfig>>;
|
|
11
|
+
declare const _default: Promise<UserConfig[]>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { defineConfig } from 'tsdown/config';
|
|
4
|
+
import { loadAukletConfig } from '#auklet/configLoader';
|
|
5
|
+
const formatMap = {
|
|
6
|
+
cjs: '.cjs',
|
|
7
|
+
iife: '.global.js',
|
|
8
|
+
esm: ['.js', '.mjs'],
|
|
9
|
+
};
|
|
10
|
+
const getExternal = (names) => {
|
|
11
|
+
const external = new Set();
|
|
12
|
+
for (const name of names) {
|
|
13
|
+
external.add(name);
|
|
14
|
+
external.add(`${name}/*`);
|
|
15
|
+
}
|
|
16
|
+
return [...external];
|
|
17
|
+
};
|
|
18
|
+
const getPackageExternal = (pkg, options) => {
|
|
19
|
+
var _a, _b, _c;
|
|
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 : []),
|
|
26
|
+
]);
|
|
27
|
+
};
|
|
28
|
+
const getPeerExternal = (pkg, options) => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
return [
|
|
31
|
+
...new Set([
|
|
32
|
+
...Object.keys(
|
|
33
|
+
(_a = pkg.peerDependencies) !== null && _a !== void 0 ? _a : {},
|
|
34
|
+
),
|
|
35
|
+
...((_b = options.externals) !== null && _b !== void 0 ? _b : []),
|
|
36
|
+
]),
|
|
37
|
+
];
|
|
38
|
+
};
|
|
39
|
+
const getDependencyGlobalName = (name) => {
|
|
40
|
+
return name
|
|
41
|
+
.replace(/^@/, '')
|
|
42
|
+
.split(/[/-]/g)
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.map((label) => label[0].toUpperCase() + label.slice(1))
|
|
45
|
+
.join('');
|
|
46
|
+
};
|
|
47
|
+
const getIifeGlobals = (context) => {
|
|
48
|
+
return Object.fromEntries(
|
|
49
|
+
context.peerExternal.map((name) => [name, getDependencyGlobalName(name)]),
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
const getIifeAlwaysBundle = (context) => {
|
|
53
|
+
const names = new Set(context.dependencyNames);
|
|
54
|
+
if (context.peerExternal.includes('react')) {
|
|
55
|
+
names.add('react/jsx-runtime');
|
|
56
|
+
names.add('react/jsx-dev-runtime');
|
|
57
|
+
}
|
|
58
|
+
return [...names];
|
|
59
|
+
};
|
|
60
|
+
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
|
+
)
|
|
68
|
+
.replace(/@/g, '')
|
|
69
|
+
.split(/[/-]/g)
|
|
70
|
+
.map((label) => label[0].toUpperCase() + label.slice(1))
|
|
71
|
+
.join('');
|
|
72
|
+
};
|
|
73
|
+
const findWorkspaceTsconfig = (packageRoot) => {
|
|
74
|
+
let current = packageRoot;
|
|
75
|
+
while (true) {
|
|
76
|
+
const tsconfig = path.join(current, 'tsconfig.json');
|
|
77
|
+
if (fs.existsSync(tsconfig)) return tsconfig;
|
|
78
|
+
const parent = path.dirname(current);
|
|
79
|
+
if (parent === current) return path.join(packageRoot, 'tsconfig.json');
|
|
80
|
+
current = parent;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const createBuildContext = (packageRoot, options) => {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const pkg = JSON.parse(
|
|
86
|
+
fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'),
|
|
87
|
+
);
|
|
88
|
+
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
|
+
' */';
|
|
97
|
+
return {
|
|
98
|
+
packageRoot,
|
|
99
|
+
tsconfig: options.tsconfig
|
|
100
|
+
? path.resolve(packageRoot, options.tsconfig)
|
|
101
|
+
: findWorkspaceTsconfig(packageRoot),
|
|
102
|
+
pkg,
|
|
103
|
+
dependencyNames: Object.keys(
|
|
104
|
+
(_b = pkg.dependencies) !== null && _b !== void 0 ? _b : {},
|
|
105
|
+
),
|
|
106
|
+
packageExternal: getPackageExternal(pkg, options),
|
|
107
|
+
peerExternal: getPeerExternal(pkg, options),
|
|
108
|
+
globalName: getGlobalName(pkg),
|
|
109
|
+
banner,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const createCommonConfig = (context, deps) => {
|
|
113
|
+
return {
|
|
114
|
+
cwd: context.packageRoot,
|
|
115
|
+
clean: false,
|
|
116
|
+
sourcemap: false,
|
|
117
|
+
tsconfig: context.tsconfig,
|
|
118
|
+
target: 'es2018',
|
|
119
|
+
platform: 'browser',
|
|
120
|
+
deps,
|
|
121
|
+
define: {
|
|
122
|
+
__TEST__: 'false',
|
|
123
|
+
__VERSION__: JSON.stringify(context.pkg.version),
|
|
124
|
+
__DEV__:
|
|
125
|
+
'(typeof process !== "undefined" ? (process.env?.NODE_ENV !== "production") : false)',
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const createBundleConfigs = (context, formats) => {
|
|
130
|
+
const outputConfigs = [];
|
|
131
|
+
for (const format of formats) {
|
|
132
|
+
const extnames = formatMap[format];
|
|
133
|
+
for (const extname of Array.isArray(extnames) ? extnames : [extnames]) {
|
|
134
|
+
outputConfigs.push({ format, extname });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return outputConfigs.map(({ format, extname }) => {
|
|
138
|
+
const deps =
|
|
139
|
+
format === 'iife'
|
|
140
|
+
? {
|
|
141
|
+
neverBundle: context.peerExternal,
|
|
142
|
+
alwaysBundle: getIifeAlwaysBundle(context),
|
|
143
|
+
onlyBundle: false,
|
|
144
|
+
}
|
|
145
|
+
: {
|
|
146
|
+
neverBundle: context.packageExternal,
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
...createCommonConfig(context, deps),
|
|
150
|
+
entry: ['src/index.ts'],
|
|
151
|
+
format,
|
|
152
|
+
globalName: context.globalName,
|
|
153
|
+
outDir: 'dist',
|
|
154
|
+
dts: false,
|
|
155
|
+
treeshake: true,
|
|
156
|
+
banner: context.banner,
|
|
157
|
+
outExtensions: () => ({
|
|
158
|
+
js: extname,
|
|
159
|
+
}),
|
|
160
|
+
outputOptions: {
|
|
161
|
+
entryFileNames: `[name]${extname}`,
|
|
162
|
+
chunkFileNames: `[name]-[hash]${extname}`,
|
|
163
|
+
globals: format === 'iife' ? getIifeGlobals(context) : {},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
const createModuleConfig = (commonConfig, format, outDir) => {
|
|
169
|
+
return {
|
|
170
|
+
...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
|
+
],
|
|
179
|
+
format,
|
|
180
|
+
outDir,
|
|
181
|
+
dts: true,
|
|
182
|
+
unbundle: true,
|
|
183
|
+
outExtensions: () => ({
|
|
184
|
+
js: '.js',
|
|
185
|
+
dts: '.d.ts',
|
|
186
|
+
}),
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const createModuleConfigs = (context) => {
|
|
190
|
+
const commonConfig = createCommonConfig(context, {
|
|
191
|
+
neverBundle: context.packageExternal,
|
|
192
|
+
});
|
|
193
|
+
return [
|
|
194
|
+
createModuleConfig(commonConfig, 'esm', 'dist/es'),
|
|
195
|
+
createModuleConfig(commonConfig, 'cjs', 'dist/lib'),
|
|
196
|
+
];
|
|
197
|
+
};
|
|
198
|
+
export function defineKernelPackageConfigFromOptions(
|
|
199
|
+
packageRoot = process.cwd(),
|
|
200
|
+
config = {},
|
|
201
|
+
) {
|
|
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);
|
|
209
|
+
const bundleConfigs = createBundleConfigs(context, formats);
|
|
210
|
+
const moduleConfigs = buildOptions.modules
|
|
211
|
+
? createModuleConfigs(context)
|
|
212
|
+
: [];
|
|
213
|
+
return [...bundleConfigs, ...moduleConfigs];
|
|
214
|
+
}
|
|
215
|
+
export async function defineKernelPackageConfigFromFile(
|
|
216
|
+
packageRoot = process.cwd(),
|
|
217
|
+
) {
|
|
218
|
+
const config = await loadAukletConfig(packageRoot, { cacheBust: true });
|
|
219
|
+
return defineKernelPackageConfigFromOptions(packageRoot, config);
|
|
220
|
+
}
|
|
221
|
+
export default defineKernelPackageConfigFromFile(process.cwd()).then((config) =>
|
|
222
|
+
defineConfig(config),
|
|
223
|
+
);
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AukletConfig, LoadAukletConfigOptions } from '#auklet/types';
|
|
2
|
+
export declare function resolveAukletConfigModule(
|
|
3
|
+
module: Record<string, unknown>,
|
|
4
|
+
): AukletConfig;
|
|
5
|
+
export declare function loadAukletConfig(
|
|
6
|
+
packageRoot: string,
|
|
7
|
+
options?: LoadAukletConfigOptions,
|
|
8
|
+
): Promise<AukletConfig>;
|