auklet 0.0.19 → 0.0.21
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/LICENSE +21 -0
- package/README.md +183 -393
- package/bin/entry.mjs +5 -0
- package/dist/build/bundleConfig.js +3 -2
- package/dist/build/cliOverrides.d.ts +22 -0
- package/dist/build/cliOverrides.js +22 -0
- package/dist/build/moduleConfig.js +1 -1
- package/dist/build/runTsdown.d.ts +2 -0
- package/dist/build/runTsdown.js +4 -3
- package/dist/build/tsdown/common.d.ts +2 -2
- package/dist/build/tsdown/context.d.ts +2 -1
- package/dist/build/tsdown/context.js +2 -1
- package/dist/build/tsdown/define.js +3 -2
- package/dist/build/tsdown/dependencies.js +3 -1
- package/dist/build/tsdown/entries.d.ts +2 -2
- package/dist/build/tsdown/entries.js +10 -10
- package/dist/build/tsdown/types.d.ts +1 -0
- package/dist/cli/build.d.ts +5 -0
- package/dist/cli/build.js +30 -0
- package/dist/cli/buildArgs.d.ts +8 -0
- package/dist/cli/buildArgs.js +114 -0
- package/dist/cli/buildCss.d.ts +12 -0
- package/dist/cli/buildCss.js +53 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/dev.js +39 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +95 -0
- package/dist/cli/publish.d.ts +2 -0
- package/dist/cli/publish.js +9 -0
- package/dist/config.d.ts +3 -1
- package/dist/config.js +7 -1
- package/dist/configLoader.d.ts +1 -0
- package/dist/configLoader.js +42 -61
- package/dist/css/production/buildReporter.d.ts +3 -0
- package/dist/css/production/buildReporter.js +19 -0
- package/dist/css/production/builder.d.ts +8 -3
- package/dist/css/production/builder.js +9 -13
- package/dist/css/vite/hmr.js +10 -8
- package/dist/css/vite/moduleGraph/graph.js +2 -3
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +5 -1
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +42 -33
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +3 -3
- package/dist/css/vite/moduleGraph/requestCache.d.ts +4 -4
- package/dist/css/vite/moduleGraph/requestCache.js +8 -4
- package/dist/css/vite/moduleGraph/styleCodeFactory.js +4 -4
- package/dist/css/vite/moduleGraph/types.d.ts +0 -1
- package/dist/css/watch/watcher.d.ts +0 -1
- package/dist/css/watch/watcher.js +9 -15
- package/dist/index.d.ts +6 -7
- package/dist/index.js +5 -5
- package/dist/logger.d.ts +5 -0
- package/dist/logger.js +14 -0
- package/dist/publish/api/gitApi.d.ts +7 -0
- package/dist/publish/api/gitApi.js +55 -0
- package/dist/publish/api/packageJsonApi.d.ts +7 -0
- package/dist/publish/api/packageJsonApi.js +35 -0
- package/dist/publish/api/pnpmApi.d.ts +9 -0
- package/dist/publish/api/pnpmApi.js +85 -0
- package/dist/publish/api/pnpmPublishApi.d.ts +4 -0
- package/dist/publish/api/pnpmPublishApi.js +7 -0
- package/dist/publish/api/publishArgs.d.ts +2 -0
- package/dist/publish/api/publishArgs.js +25 -0
- package/dist/publish/api/publishHookApi.d.ts +10 -0
- package/dist/publish/api/publishHookApi.js +53 -0
- package/dist/publish/cli.d.ts +2 -0
- package/dist/publish/cli.js +95 -0
- package/dist/publish/ownerRunner.d.ts +6 -0
- package/dist/publish/ownerRunner.js +22 -0
- package/dist/publish/publishRunner.d.ts +16 -0
- package/dist/publish/publishRunner.js +108 -0
- package/dist/publish/runner/packageBuilder.d.ts +4 -0
- package/dist/publish/runner/packageBuilder.js +16 -0
- package/dist/publish/runner/packagePublisher.d.ts +7 -0
- package/dist/publish/runner/packagePublisher.js +21 -0
- package/dist/publish/runner/publishFailureReporter.d.ts +3 -0
- package/dist/publish/runner/publishFailureReporter.js +14 -0
- package/dist/publish/runner/publishOutputFormatter.d.ts +2 -0
- package/dist/publish/runner/publishOutputFormatter.js +83 -0
- package/dist/publish/runner/publishPreflight.d.ts +8 -0
- package/dist/publish/runner/publishPreflight.js +26 -0
- package/dist/publish/runner/publishSummaryReporter.d.ts +10 -0
- package/dist/publish/runner/publishSummaryReporter.js +81 -0
- package/dist/publish/runner/publishTargetError.d.ts +9 -0
- package/dist/publish/runner/publishTargetError.js +14 -0
- package/dist/publish/runner/releaseGitController.d.ts +10 -0
- package/dist/publish/runner/releaseGitController.js +41 -0
- package/dist/publish/runner/versionWriter.d.ts +13 -0
- package/dist/publish/runner/versionWriter.js +78 -0
- package/dist/publish/targetResolver.d.ts +7 -0
- package/dist/publish/targetResolver.js +195 -0
- package/dist/publish/types.d.ts +70 -0
- package/dist/publish/types.js +0 -0
- package/dist/publish/version.d.ts +5 -0
- package/dist/publish/version.js +55 -0
- package/dist/types.d.ts +8 -7
- package/dist/workspace/packages.d.ts +9 -0
- package/dist/workspace/packages.js +62 -0
- package/dist/workspace/root.d.ts +1 -0
- package/dist/workspace/root.js +14 -0
- package/package.json +15 -7
- package/bin/entry.cjs +0 -163
package/bin/entry.mjs
ADDED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isArray } from 'aidly';
|
|
1
2
|
import { getBundleEntry } from '#auklet/build/tsdown/entries';
|
|
2
3
|
import { getIifeAlwaysBundle, getIifeGlobals, } from '#auklet/build/tsdown/dependencies';
|
|
3
4
|
import { configureTsdown, createCommonConfig, } from '#auklet/build/tsdown/common';
|
|
@@ -26,7 +27,7 @@ export function createBundleConfigs(context, formats) {
|
|
|
26
27
|
let hasDtsConfig = false;
|
|
27
28
|
for (const format of formats) {
|
|
28
29
|
const extnames = formatMap[format];
|
|
29
|
-
for (const extname of
|
|
30
|
+
for (const extname of isArray(extnames) ? extnames : [extnames]) {
|
|
30
31
|
const emitDts = !hasDtsConfig;
|
|
31
32
|
outputConfigs.push({ format, extname, dts: emitDts });
|
|
32
33
|
hasDtsConfig ||= emitDts;
|
|
@@ -47,7 +48,7 @@ export function createBundleConfigs(context, formats) {
|
|
|
47
48
|
: undefined;
|
|
48
49
|
return configureTsdown(context, {
|
|
49
50
|
...createCommonConfig(context, deps),
|
|
50
|
-
entry: getBundleEntry(context.packageRoot),
|
|
51
|
+
entry: getBundleEntry(context.packageRoot, context.source),
|
|
51
52
|
format,
|
|
52
53
|
globalName: context.globalName,
|
|
53
54
|
outDir: context.output,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AukletConfig } from '#auklet/types';
|
|
2
|
+
export declare const aukletCliConfigOverridesEnv = "AUKLET_CONFIG_OVERRIDES";
|
|
3
|
+
export declare function encodeAukletCliConfigOverrides(config: AukletConfig): string;
|
|
4
|
+
export declare function readAukletCliConfigOverrides(): AukletConfig;
|
|
5
|
+
export declare function mergeAukletConfigOverrides(config: AukletConfig, overrides: AukletConfig): {
|
|
6
|
+
build: {
|
|
7
|
+
formats?: Array<import("#auklet/types").PackageBuildFormat>;
|
|
8
|
+
target?: import("#auklet/types").PackageBuildTarget;
|
|
9
|
+
platform?: import("#auklet/types").PackageBuildPlatform;
|
|
10
|
+
banner?: string;
|
|
11
|
+
externals?: Array<string>;
|
|
12
|
+
alias?: Record<string, string>;
|
|
13
|
+
mainFields?: Array<string>;
|
|
14
|
+
globals?: Record<string, string>;
|
|
15
|
+
configureTsdown?: import("#auklet/types").ConfigureTsdown;
|
|
16
|
+
tsconfig?: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
source?: string;
|
|
19
|
+
output?: string;
|
|
20
|
+
modules?: boolean;
|
|
21
|
+
styles?: import("#auklet/types").StyleOptions;
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const aukletCliConfigOverridesEnv = 'AUKLET_CONFIG_OVERRIDES';
|
|
2
|
+
export function encodeAukletCliConfigOverrides(config) {
|
|
3
|
+
return JSON.stringify(config);
|
|
4
|
+
}
|
|
5
|
+
export function readAukletCliConfigOverrides() {
|
|
6
|
+
const rawConfig = process.env[aukletCliConfigOverridesEnv];
|
|
7
|
+
if (!rawConfig)
|
|
8
|
+
return {};
|
|
9
|
+
return JSON.parse(rawConfig);
|
|
10
|
+
}
|
|
11
|
+
export function mergeAukletConfigOverrides(config, overrides) {
|
|
12
|
+
return {
|
|
13
|
+
...config,
|
|
14
|
+
...overrides,
|
|
15
|
+
build: config.build || overrides.build
|
|
16
|
+
? {
|
|
17
|
+
...config.build,
|
|
18
|
+
...overrides.build,
|
|
19
|
+
}
|
|
20
|
+
: undefined,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -19,7 +19,7 @@ export function createModuleConfigs(context) {
|
|
|
19
19
|
const commonConfig = createCommonConfig(context, {
|
|
20
20
|
neverBundle: context.packageExternal,
|
|
21
21
|
});
|
|
22
|
-
const entry = getModuleEntries(context.packageRoot);
|
|
22
|
+
const entry = getModuleEntries(context.packageRoot, context.source);
|
|
23
23
|
return [
|
|
24
24
|
createModuleConfig(context, commonConfig, entry, 'esm', path.join(context.output, 'es')),
|
|
25
25
|
createModuleConfig(context, commonConfig, entry, 'cjs', path.join(context.output, 'lib')),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export declare function hasTsdownConfigArg(args: Array<string>): boolean;
|
|
1
2
|
export type RunTsdownOptions = {
|
|
2
3
|
cwd?: string;
|
|
4
|
+
env?: Record<string, string>;
|
|
3
5
|
};
|
|
4
6
|
export declare function createTsdownArgs(args: Array<string>): string[];
|
|
5
7
|
export declare function runTsdown(args: Array<string>, options?: RunTsdownOptions): Promise<number>;
|
package/dist/build/runTsdown.js
CHANGED
|
@@ -5,16 +5,16 @@ const require = createRequire(import.meta.url);
|
|
|
5
5
|
const tsdownRunFile = require.resolve('tsdown/run');
|
|
6
6
|
const currentExtension = import.meta.url.endsWith('.ts') ? 'ts' : 'js';
|
|
7
7
|
const defaultConfigFile = fileURLToPath(new URL(`./tsdownConfig.${currentExtension}`, import.meta.url));
|
|
8
|
-
|
|
8
|
+
export function hasTsdownConfigArg(args) {
|
|
9
9
|
return args.some((arg, index) => arg === '--no-config' ||
|
|
10
10
|
arg === '-c' ||
|
|
11
11
|
arg === '--config' ||
|
|
12
12
|
arg.startsWith('--config=') ||
|
|
13
13
|
args[index - 1] === '-c' ||
|
|
14
14
|
args[index - 1] === '--config');
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
export function createTsdownArgs(args) {
|
|
17
|
-
const tsdownArgs =
|
|
17
|
+
const tsdownArgs = hasTsdownConfigArg(args)
|
|
18
18
|
? args
|
|
19
19
|
: ['--config', defaultConfigFile, ...args];
|
|
20
20
|
return [tsdownRunFile, ...tsdownArgs];
|
|
@@ -23,6 +23,7 @@ export async function runTsdown(args, options = {}) {
|
|
|
23
23
|
const tsdownArgs = createTsdownArgs(args);
|
|
24
24
|
const result = await execa(process.execPath, tsdownArgs, {
|
|
25
25
|
cwd: options.cwd ?? process.cwd(),
|
|
26
|
+
env: options.env,
|
|
26
27
|
stdio: 'inherit',
|
|
27
28
|
reject: false,
|
|
28
29
|
});
|
|
@@ -6,8 +6,8 @@ export declare function createCommonConfig(context: BuildContext, deps: TsdownDe
|
|
|
6
6
|
clean: false;
|
|
7
7
|
sourcemap: false;
|
|
8
8
|
tsconfig: string;
|
|
9
|
-
target: NonNullable<import("
|
|
10
|
-
platform: NonNullable<import("
|
|
9
|
+
target: NonNullable<import("../..").PackageBuildTarget | undefined>;
|
|
10
|
+
platform: NonNullable<import("../..").PackageBuildPlatform | undefined>;
|
|
11
11
|
alias: Record<string, string>;
|
|
12
12
|
deps: import("node_modules/tsdown/dist/types-CQaSBA5U.mjs").L;
|
|
13
13
|
define: {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { PackageBuildOptions } from '#auklet/types';
|
|
2
2
|
import type { PackageJsonLike } from '#auklet/build/tsdown/types';
|
|
3
|
-
export declare function createBuildContext(packageRoot: string, options: PackageBuildOptions, output: string): {
|
|
3
|
+
export declare function createBuildContext(packageRoot: string, options: PackageBuildOptions, source: string, output: string): {
|
|
4
4
|
pkg: PackageJsonLike;
|
|
5
5
|
banner: string;
|
|
6
6
|
packageRoot: string;
|
|
7
|
+
source: string;
|
|
7
8
|
output: string;
|
|
8
9
|
runtimeDependencyNames: string[];
|
|
9
10
|
packageExternal: string[];
|
|
@@ -20,7 +20,7 @@ const findWorkspaceTsconfig = (packageRoot) => {
|
|
|
20
20
|
current = parent;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
export function createBuildContext(packageRoot, options, output) {
|
|
23
|
+
export function createBuildContext(packageRoot, options, source, output) {
|
|
24
24
|
const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
25
25
|
const banner = options.banner ??
|
|
26
26
|
'/*!\n' +
|
|
@@ -31,6 +31,7 @@ export function createBuildContext(packageRoot, options, output) {
|
|
|
31
31
|
pkg,
|
|
32
32
|
banner,
|
|
33
33
|
packageRoot,
|
|
34
|
+
source,
|
|
34
35
|
output,
|
|
35
36
|
runtimeDependencyNames: Object.keys(pkg.dependencies ?? {}),
|
|
36
37
|
packageExternal: getPackageExternal(pkg, options),
|
|
@@ -3,11 +3,12 @@ import { normalizeAukletConfig } from '#auklet/config';
|
|
|
3
3
|
import { createBundleConfigs } from '#auklet/build/bundleConfig';
|
|
4
4
|
import { createModuleConfigs } from '#auklet/build/moduleConfig';
|
|
5
5
|
import { createBuildContext } from '#auklet/build/tsdown/context';
|
|
6
|
+
import { mergeAukletConfigOverrides, readAukletCliConfigOverrides, } from '#auklet/build/cliOverrides';
|
|
6
7
|
export function defineKernelPackageConfigFromOptions(packageRoot = process.cwd(), config = {}) {
|
|
7
8
|
const normalizedConfig = normalizeAukletConfig(config);
|
|
8
9
|
const buildOptions = normalizedConfig.build;
|
|
9
10
|
const formats = buildOptions.formats;
|
|
10
|
-
const context = createBuildContext(packageRoot, buildOptions, normalizedConfig.output);
|
|
11
|
+
const context = createBuildContext(packageRoot, buildOptions, normalizedConfig.source, normalizedConfig.output);
|
|
11
12
|
const bundleConfigs = createBundleConfigs(context, formats);
|
|
12
13
|
const moduleConfigs = normalizedConfig.modules
|
|
13
14
|
? createModuleConfigs(context)
|
|
@@ -15,6 +16,6 @@ export function defineKernelPackageConfigFromOptions(packageRoot = process.cwd()
|
|
|
15
16
|
return [...bundleConfigs, ...moduleConfigs];
|
|
16
17
|
}
|
|
17
18
|
export async function defineKernelPackageConfigFromFile(packageRoot = process.cwd()) {
|
|
18
|
-
const config = await loadAukletConfig(packageRoot, { cacheBust: true });
|
|
19
|
+
const config = mergeAukletConfigOverrides(await loadAukletConfig(packageRoot, { cacheBust: true }), readAukletCliConfigOverrides());
|
|
19
20
|
return defineKernelPackageConfigFromOptions(packageRoot, config);
|
|
20
21
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { parseModuleId } from '#auklet/build/tsdown/parseModuleId';
|
|
2
|
+
import { createScopedAukletLogger } from '#auklet/logger';
|
|
3
|
+
const logger = createScopedAukletLogger('build');
|
|
2
4
|
const getExternal = (names) => {
|
|
3
5
|
const external = new Set();
|
|
4
6
|
for (const name of names) {
|
|
@@ -53,7 +55,7 @@ export function getIifeAlwaysBundle(context) {
|
|
|
53
55
|
catch (error) {
|
|
54
56
|
if (!warnedParseFailures.has(id)) {
|
|
55
57
|
warnedParseFailures.add(id);
|
|
56
|
-
|
|
58
|
+
logger.warn(`Unable to parse module id for IIFE bundle dependency classification: ${id}`, error);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
return peerDependencies.has(id) ? false : runtimeDependencies.has(id);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare function getBundleEntry(packageRoot: string): {
|
|
1
|
+
export declare function getBundleEntry(packageRoot: string, source?: string): {
|
|
2
2
|
index: string;
|
|
3
3
|
};
|
|
4
|
-
export declare function getModuleEntries(packageRoot: string): Record<string, string> | {
|
|
4
|
+
export declare function getModuleEntries(packageRoot: string, source?: string): Record<string, string> | {
|
|
5
5
|
index: string;
|
|
6
6
|
};
|
|
@@ -3,22 +3,22 @@ import path from 'node:path';
|
|
|
3
3
|
const toPosixPath = (value) => {
|
|
4
4
|
return value.split(path.sep).join('/');
|
|
5
5
|
};
|
|
6
|
-
export function getBundleEntry(packageRoot) {
|
|
7
|
-
const tsEntry = '
|
|
8
|
-
const tsxEntry = '
|
|
6
|
+
export function getBundleEntry(packageRoot, source = 'src') {
|
|
7
|
+
const tsEntry = path.join(source, 'index.ts');
|
|
8
|
+
const tsxEntry = path.join(source, 'index.tsx');
|
|
9
9
|
if (fs.existsSync(path.join(packageRoot, tsEntry))) {
|
|
10
|
-
return { index: tsEntry };
|
|
10
|
+
return { index: toPosixPath(tsEntry) };
|
|
11
11
|
}
|
|
12
12
|
if (fs.existsSync(path.join(packageRoot, tsxEntry))) {
|
|
13
|
-
return { index: tsxEntry };
|
|
13
|
+
return { index: toPosixPath(tsxEntry) };
|
|
14
14
|
}
|
|
15
|
-
return { index: tsEntry };
|
|
15
|
+
return { index: toPosixPath(tsEntry) };
|
|
16
16
|
}
|
|
17
|
-
export function getModuleEntries(packageRoot) {
|
|
18
|
-
const sourceRoot = path.join(packageRoot,
|
|
17
|
+
export function getModuleEntries(packageRoot, source = 'src') {
|
|
18
|
+
const sourceRoot = path.join(packageRoot, source);
|
|
19
19
|
const entries = {};
|
|
20
20
|
if (!fs.existsSync(sourceRoot)) {
|
|
21
|
-
return getBundleEntry(packageRoot);
|
|
21
|
+
return getBundleEntry(packageRoot, source);
|
|
22
22
|
}
|
|
23
23
|
const collect = (dir) => {
|
|
24
24
|
const dirEntries = fs
|
|
@@ -45,5 +45,5 @@ export function getModuleEntries(packageRoot) {
|
|
|
45
45
|
collect(sourceRoot);
|
|
46
46
|
return Object.keys(entries).length > 0
|
|
47
47
|
? entries
|
|
48
|
-
: getBundleEntry(packageRoot);
|
|
48
|
+
: getBundleEntry(packageRoot, source);
|
|
49
49
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cleanAukletOutputByConfig } from '#auklet/build/cleanOutput';
|
|
2
|
+
import { mergeAukletConfigOverrides } from '#auklet/build/cliOverrides';
|
|
3
|
+
import { runTsdown } from '#auklet/build/runTsdown';
|
|
4
|
+
import { loadAukletConfig } from '#auklet/configLoader';
|
|
5
|
+
import { createBuildEnv, resolveBuildCliArgs } from '#auklet/cli/buildArgs';
|
|
6
|
+
import { runBuildCss } from '#auklet/cli/buildCss';
|
|
7
|
+
import { createAukletLogger } from '#auklet/logger';
|
|
8
|
+
export async function runBuildJs(args, options = {}) {
|
|
9
|
+
const buildArgs = resolveBuildCliArgs(args);
|
|
10
|
+
const config = mergeAukletConfigOverrides(options.config ?? {}, buildArgs.config);
|
|
11
|
+
const logger = createAukletLogger();
|
|
12
|
+
return logger.group('Build JavaScript', async () => {
|
|
13
|
+
return runTsdown(buildArgs.args, {
|
|
14
|
+
cwd: process.cwd(),
|
|
15
|
+
env: createBuildEnv(config),
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export async function runBuild(args) {
|
|
20
|
+
const buildArgs = resolveBuildCliArgs(args);
|
|
21
|
+
const aukletConfig = mergeAukletConfigOverrides(await loadAukletConfig(process.cwd()), buildArgs.config);
|
|
22
|
+
cleanAukletOutputByConfig(process.cwd(), aukletConfig);
|
|
23
|
+
const jsExitCode = await runBuildJs(buildArgs.args, {
|
|
24
|
+
config: buildArgs.config,
|
|
25
|
+
});
|
|
26
|
+
if (jsExitCode)
|
|
27
|
+
return jsExitCode;
|
|
28
|
+
createAukletLogger().newline();
|
|
29
|
+
return runBuildCss([], { aukletConfig });
|
|
30
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AukletConfig } from '#auklet/types';
|
|
2
|
+
export declare function resolveBuildCliArgs(args: Array<string>): {
|
|
3
|
+
args: string[];
|
|
4
|
+
config: AukletConfig;
|
|
5
|
+
};
|
|
6
|
+
export declare function createBuildEnv(config: AukletConfig): {
|
|
7
|
+
AUKLET_CONFIG_OVERRIDES: string;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { hasTsdownConfigArg } from '#auklet/build/runTsdown';
|
|
2
|
+
import { aukletCliConfigOverridesEnv, encodeAukletCliConfigOverrides, } from '#auklet/build/cliOverrides';
|
|
3
|
+
const buildFormats = new Set(['cjs', 'esm', 'iife']);
|
|
4
|
+
const buildPlatforms = new Set(['node', 'neutral', 'browser']);
|
|
5
|
+
const hasAukletConfig = (config) => {
|
|
6
|
+
return Object.keys(config).length > 0;
|
|
7
|
+
};
|
|
8
|
+
export function resolveBuildCliArgs(args) {
|
|
9
|
+
const remainingArgs = [];
|
|
10
|
+
const config = {};
|
|
11
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
12
|
+
const arg = args[index];
|
|
13
|
+
const [name, inlineValue] = arg.split('=', 2);
|
|
14
|
+
if (name === '--source') {
|
|
15
|
+
config.source = getFlagValue(args, index, inlineValue, name);
|
|
16
|
+
if (inlineValue === undefined)
|
|
17
|
+
index += 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (name === '--output') {
|
|
21
|
+
config.output = getFlagValue(args, index, inlineValue, name);
|
|
22
|
+
if (inlineValue === undefined)
|
|
23
|
+
index += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (name === '--modules') {
|
|
27
|
+
config.modules = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (name === '--no-modules') {
|
|
31
|
+
config.modules = false;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (name === '--build.formats') {
|
|
35
|
+
config.build = {
|
|
36
|
+
...config.build,
|
|
37
|
+
formats: parseBuildFormats(getFlagValue(args, index, inlineValue, name)),
|
|
38
|
+
};
|
|
39
|
+
if (inlineValue === undefined)
|
|
40
|
+
index += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (name === '--build.target') {
|
|
44
|
+
config.build = {
|
|
45
|
+
...config.build,
|
|
46
|
+
target: getFlagValue(args, index, inlineValue, name),
|
|
47
|
+
};
|
|
48
|
+
if (inlineValue === undefined)
|
|
49
|
+
index += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (name === '--build.platform') {
|
|
53
|
+
config.build = {
|
|
54
|
+
...config.build,
|
|
55
|
+
platform: parseBuildPlatform(getFlagValue(args, index, inlineValue, name)),
|
|
56
|
+
};
|
|
57
|
+
if (inlineValue === undefined)
|
|
58
|
+
index += 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (name === '--build.tsconfig') {
|
|
62
|
+
config.build = {
|
|
63
|
+
...config.build,
|
|
64
|
+
tsconfig: getFlagValue(args, index, inlineValue, name),
|
|
65
|
+
};
|
|
66
|
+
if (inlineValue === undefined)
|
|
67
|
+
index += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
remainingArgs.push(arg);
|
|
71
|
+
}
|
|
72
|
+
if (hasAukletConfig(config) && hasTsdownConfigArg(remainingArgs)) {
|
|
73
|
+
throw new Error('Auklet build config flags cannot be used with tsdown --config, -c, or --no-config.');
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
args: remainingArgs,
|
|
77
|
+
config,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function createBuildEnv(config) {
|
|
81
|
+
if (!hasAukletConfig(config))
|
|
82
|
+
return undefined;
|
|
83
|
+
return {
|
|
84
|
+
[aukletCliConfigOverridesEnv]: encodeAukletCliConfigOverrides(config),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const getFlagValue = (args, index, inlineValue, flag) => {
|
|
88
|
+
const value = inlineValue ?? args[index + 1];
|
|
89
|
+
if (!value || value.startsWith('--')) {
|
|
90
|
+
throw new Error(`${flag} requires a value.`);
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
};
|
|
94
|
+
const parseBuildFormats = (value) => {
|
|
95
|
+
const formats = value
|
|
96
|
+
.split(',')
|
|
97
|
+
.map((format) => format.trim())
|
|
98
|
+
.filter(Boolean);
|
|
99
|
+
if (!formats.length) {
|
|
100
|
+
throw new Error('--build.formats requires at least one format.');
|
|
101
|
+
}
|
|
102
|
+
for (const format of formats) {
|
|
103
|
+
if (!buildFormats.has(format)) {
|
|
104
|
+
throw new Error(`Unknown build format: ${format}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return formats;
|
|
108
|
+
};
|
|
109
|
+
const parseBuildPlatform = (value) => {
|
|
110
|
+
if (!buildPlatforms.has(value)) {
|
|
111
|
+
throw new Error(`Unknown build platform: ${value}`);
|
|
112
|
+
}
|
|
113
|
+
return value;
|
|
114
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModuleStyleWatcher } from '#auklet/css/watch/watcher';
|
|
2
|
+
import type { AukletConfig } from '#auklet/types';
|
|
3
|
+
export declare function resolveBuildCssConfig(args: Array<string>, options?: {
|
|
4
|
+
aukletConfig?: AukletConfig;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
aukletConfig: AukletConfig;
|
|
7
|
+
shouldWatch: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function startBuildCssWatch(aukletConfig: AukletConfig): Promise<ModuleStyleWatcher>;
|
|
10
|
+
export declare function runBuildCss(args: Array<string>, options?: {
|
|
11
|
+
aukletConfig?: AukletConfig;
|
|
12
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createAukletLogger } from '#auklet/logger';
|
|
2
|
+
import { loadAukletConfig } from '#auklet/configLoader';
|
|
3
|
+
import { resolveBuildCliArgs } from '#auklet/cli/buildArgs';
|
|
4
|
+
import { ModuleStyleWatcher } from '#auklet/css/watch/watcher';
|
|
5
|
+
import { ModuleStyleBuilder } from '#auklet/css/production/builder';
|
|
6
|
+
import { mergeAukletConfigOverrides } from '#auklet/build/cliOverrides';
|
|
7
|
+
import { logModuleStyleBuildResult } from '#auklet/css/production/buildReporter';
|
|
8
|
+
export async function resolveBuildCssConfig(args, options = {}) {
|
|
9
|
+
const buildArgs = resolveBuildCliArgs(args);
|
|
10
|
+
const shouldWatch = buildArgs.args.includes('--watch') || buildArgs.args.includes('-w');
|
|
11
|
+
const aukletConfig = options.aukletConfig ??
|
|
12
|
+
mergeAukletConfigOverrides(await loadAukletConfig(process.cwd(), {
|
|
13
|
+
cacheBust: shouldWatch,
|
|
14
|
+
}), buildArgs.config);
|
|
15
|
+
return {
|
|
16
|
+
aukletConfig,
|
|
17
|
+
shouldWatch,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function startBuildCssWatch(aukletConfig) {
|
|
21
|
+
const logger = createAukletLogger();
|
|
22
|
+
return logger.group('Build CSS', async () => {
|
|
23
|
+
const css = logger.child('css');
|
|
24
|
+
const watcher = new ModuleStyleWatcher({ aukletConfig });
|
|
25
|
+
await watcher.watch();
|
|
26
|
+
css.success('watch mode ready');
|
|
27
|
+
return watcher;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export async function runBuildCss(args, options = {}) {
|
|
31
|
+
const logger = createAukletLogger();
|
|
32
|
+
const { aukletConfig, shouldWatch } = await resolveBuildCssConfig(args, options);
|
|
33
|
+
if (shouldWatch) {
|
|
34
|
+
const watcher = await startBuildCssWatch(aukletConfig);
|
|
35
|
+
const close = () => {
|
|
36
|
+
watcher
|
|
37
|
+
.close()
|
|
38
|
+
.catch(console.error)
|
|
39
|
+
.finally(() => process.exit(0));
|
|
40
|
+
};
|
|
41
|
+
process.once('SIGINT', close);
|
|
42
|
+
process.once('SIGTERM', close);
|
|
43
|
+
await new Promise(() => { });
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
const builder = new ModuleStyleBuilder({ aukletConfig });
|
|
47
|
+
await logger.group('Build CSS', async () => {
|
|
48
|
+
const timer = logger.timer();
|
|
49
|
+
const result = await builder.build();
|
|
50
|
+
logModuleStyleBuildResult(logger.child('css'), result, timer.elapsed());
|
|
51
|
+
});
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runDev(args: Array<string>): Promise<number>;
|
package/dist/cli/dev.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { createTsdownArgs } from '#auklet/build/runTsdown';
|
|
3
|
+
import { createBuildEnv, resolveBuildCliArgs } from '#auklet/cli/buildArgs';
|
|
4
|
+
import { resolveBuildCssConfig, startBuildCssWatch, } from '#auklet/cli/buildCss';
|
|
5
|
+
export async function runDev(args) {
|
|
6
|
+
let closed = false;
|
|
7
|
+
let jsProcess = null;
|
|
8
|
+
const buildArgs = resolveBuildCliArgs(args);
|
|
9
|
+
const { aukletConfig } = await resolveBuildCssConfig(['--watch', ...args]);
|
|
10
|
+
const cssWatcher = await startBuildCssWatch(aukletConfig);
|
|
11
|
+
const close = async () => {
|
|
12
|
+
if (closed)
|
|
13
|
+
return;
|
|
14
|
+
closed = true;
|
|
15
|
+
jsProcess?.kill('SIGTERM');
|
|
16
|
+
await cssWatcher.close();
|
|
17
|
+
};
|
|
18
|
+
const closeAndExit = () => {
|
|
19
|
+
close()
|
|
20
|
+
.catch(console.error)
|
|
21
|
+
.finally(() => process.exit(0));
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
jsProcess = execa(process.execPath, createTsdownArgs([...buildArgs.args, '--watch']), {
|
|
25
|
+
cwd: process.cwd(),
|
|
26
|
+
env: createBuildEnv(buildArgs.config),
|
|
27
|
+
stdio: 'inherit',
|
|
28
|
+
reject: false,
|
|
29
|
+
});
|
|
30
|
+
process.once('SIGINT', closeAndExit);
|
|
31
|
+
process.once('SIGTERM', closeAndExit);
|
|
32
|
+
return await jsProcess.then((result) => result.exitCode ?? 0);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
process.off('SIGINT', closeAndExit);
|
|
36
|
+
process.off('SIGTERM', closeAndExit);
|
|
37
|
+
await close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runAukletCli(argv?: string[]): Promise<void>;
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { cac } from 'cac';
|
|
5
|
+
import { createAukletLogger } from '#auklet/logger';
|
|
6
|
+
import { runDev } from '#auklet/cli/dev';
|
|
7
|
+
import { runBuildCss } from '#auklet/cli/buildCss';
|
|
8
|
+
import { runBuild, runBuildJs } from '#auklet/cli/build';
|
|
9
|
+
import { runOwner, runPublish } from '#auklet/cli/publish';
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const getPackageVersion = () => {
|
|
12
|
+
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../package.json'), 'utf8'));
|
|
13
|
+
return packageJson.version;
|
|
14
|
+
};
|
|
15
|
+
const runVersion = async () => {
|
|
16
|
+
console.log(getPackageVersion());
|
|
17
|
+
return 0;
|
|
18
|
+
};
|
|
19
|
+
const getCommandArgs = (argv, command) => {
|
|
20
|
+
const rawArgs = argv.slice(2);
|
|
21
|
+
const commandIndex = rawArgs.indexOf(command);
|
|
22
|
+
return commandIndex >= 0 ? rawArgs.slice(commandIndex + 1) : [];
|
|
23
|
+
};
|
|
24
|
+
const runCliCommand = (runner, args) => {
|
|
25
|
+
return runner(args).then((exitCode) => {
|
|
26
|
+
process.exit(exitCode ?? 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
async function runCli(argv) {
|
|
30
|
+
const cli = cac('auk');
|
|
31
|
+
cli
|
|
32
|
+
.command('build [...args]', 'Build package JavaScript and CSS output')
|
|
33
|
+
.allowUnknownOptions()
|
|
34
|
+
.action(() => runCliCommand(runBuild, getCommandArgs(argv, 'build')));
|
|
35
|
+
cli
|
|
36
|
+
.command('build-js [...args]', 'Build package JavaScript output with tsdown')
|
|
37
|
+
.allowUnknownOptions()
|
|
38
|
+
.action(() => runCliCommand(runBuildJs, getCommandArgs(argv, 'build-js')));
|
|
39
|
+
cli
|
|
40
|
+
.command('build-css [...args]', 'Build package module CSS output')
|
|
41
|
+
.option('-w, --watch', 'Watch module CSS output')
|
|
42
|
+
.allowUnknownOptions()
|
|
43
|
+
.action(() => runCliCommand(runBuildCss, getCommandArgs(argv, 'build-css')));
|
|
44
|
+
cli
|
|
45
|
+
.command('dev [...args]', 'Watch package JavaScript and CSS output')
|
|
46
|
+
.allowUnknownOptions()
|
|
47
|
+
.action(() => runCliCommand(runDev, getCommandArgs(argv, 'dev')));
|
|
48
|
+
cli
|
|
49
|
+
.command('publish [...args]', 'Build and publish package output with pnpm')
|
|
50
|
+
.allowUnknownOptions()
|
|
51
|
+
.action(() => runCliCommand(runPublish, getCommandArgs(argv, 'publish')));
|
|
52
|
+
cli
|
|
53
|
+
.command('owner [...args]', 'Manage npm package owners with pnpm')
|
|
54
|
+
.allowUnknownOptions()
|
|
55
|
+
.action(() => runCliCommand(runOwner, getCommandArgs(argv, 'owner')));
|
|
56
|
+
cli
|
|
57
|
+
.command('version', 'Print auklet version')
|
|
58
|
+
.action(() => runCliCommand(runVersion, []));
|
|
59
|
+
cli.option('-v, --version', 'Print auklet version');
|
|
60
|
+
cli.help();
|
|
61
|
+
if (argv.length <= 2) {
|
|
62
|
+
cli.outputHelp();
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
cli.parse(argv, { run: false });
|
|
66
|
+
if (!cli.matchedCommand && cli.options.version) {
|
|
67
|
+
console.log(getPackageVersion());
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
70
|
+
if (cli.options.help) {
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
if (!cli.matchedCommand) {
|
|
74
|
+
const [command] = argv.slice(2);
|
|
75
|
+
if (command) {
|
|
76
|
+
const logger = createAukletLogger({ scope: 'cli' });
|
|
77
|
+
logger.error(`Unknown auk command: ${command}`);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
cli.outputHelp();
|
|
81
|
+
}
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
await cli.runMatchedCommand();
|
|
85
|
+
}
|
|
86
|
+
export async function runAukletCli(argv = process.argv) {
|
|
87
|
+
try {
|
|
88
|
+
await runCli(argv);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const logger = createAukletLogger({ scope: 'cli' });
|
|
92
|
+
logger.error(error);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
}
|