auklet 0.1.3 → 0.1.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.
- package/README.md +19 -2
- package/dist/build/tsdown/dependencies.js +2 -2
- package/dist/cli/build.js +26 -16
- package/dist/cli/buildArgs.d.ts +2 -1
- package/dist/cli/buildArgs.js +30 -8
- package/dist/cli/buildCss.d.ts +2 -0
- package/dist/cli/buildCss.js +28 -21
- package/dist/cli/dev.js +14 -4
- package/dist/cli/values.d.ts +17 -0
- package/dist/cli/values.js +14 -0
- package/dist/css/core/style/dependencies.d.ts +0 -1
- package/dist/css/core/style/dependencies.js +0 -3
- package/dist/css/core/style/entries.js +2 -2
- package/dist/css/core/style/files.d.ts +0 -1
- package/dist/css/core/style/files.js +0 -3
- package/dist/css/core/stylePackageContext.js +3 -3
- package/dist/css/vite/hmr.js +2 -2
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +1 -1
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +2 -2
- package/dist/env.d.ts +22 -0
- package/dist/env.js +105 -0
- package/dist/logger.d.ts +0 -1
- package/dist/logger.js +0 -3
- package/dist/publish/api/npmrc.d.ts +1 -1
- package/dist/publish/api/npmrc.js +1 -4
- package/dist/publish/api/pnpmApi.d.ts +6 -10
- package/dist/publish/api/pnpmApi.js +6 -14
- package/dist/publish/api/pnpmPublishApi.d.ts +2 -2
- package/dist/publish/api/pnpmPublishApi.js +5 -3
- package/dist/publish/cli.d.ts +6 -2
- package/dist/publish/cli.js +90 -52
- package/dist/publish/inspect.js +19 -9
- package/dist/publish/inspectPack.js +6 -2
- package/dist/publish/inspectRegistry.d.ts +3 -2
- package/dist/publish/inspectRegistry.js +11 -4
- package/dist/publish/publishEnv.d.ts +13 -0
- package/dist/publish/publishEnv.js +21 -0
- package/dist/publish/publishRunner.d.ts +3 -2
- package/dist/publish/publishRunner.js +9 -7
- package/dist/publish/runner/packageBuilder.d.ts +2 -3
- package/dist/publish/runner/packageBuilder.js +5 -3
- package/dist/publish/runner/packagePublisher.d.ts +3 -2
- package/dist/publish/runner/packagePublisher.js +4 -2
- package/dist/publish/runner/publishPreflight.d.ts +3 -2
- package/dist/publish/runner/publishPreflight.js +13 -6
- package/dist/publish/runner/versionWriter.d.ts +1 -1
- package/dist/publish/targetResolver.d.ts +2 -2
- package/dist/publish/targetResolver.js +9 -5
- package/dist/publish/types.d.ts +6 -1
- package/package.json +1 -1
|
@@ -9,36 +9,32 @@ export declare class NpmPackageVersionExistsError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
export declare function withPnpmTimeout(subprocess: ReturnType<typeof execa>, timeout: number): Promise<import("node_modules/execa/types/return/result").CommonResult<false, Options> & import("node_modules/execa/types/return/result").OmitErrorIfReject<boolean | undefined>>;
|
|
11
11
|
export declare function ensurePnpm(options?: {
|
|
12
|
-
|
|
12
|
+
env?: Record<string, string | undefined>;
|
|
13
13
|
}): Promise<string>;
|
|
14
14
|
export declare function readPnpmWorkspacePackages(root: string, options?: {
|
|
15
|
-
|
|
15
|
+
env?: Record<string, string | undefined>;
|
|
16
16
|
}): Promise<WorkspacePackage[]>;
|
|
17
17
|
export declare function runPnpmBuild(packageRoot: string, options?: {
|
|
18
|
-
|
|
18
|
+
env?: Record<string, string | undefined>;
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
export declare function runPnpmPublish(packageRoot: string, args: Array<string>, options?: {
|
|
21
|
-
|
|
21
|
+
env?: Record<string, string | undefined>;
|
|
22
22
|
}): Promise<void>;
|
|
23
23
|
export declare function runPnpmWhoami(packageRoot: string, options?: {
|
|
24
24
|
packageName?: string;
|
|
25
25
|
registry?: string;
|
|
26
26
|
timeout?: number;
|
|
27
|
-
|
|
27
|
+
env?: Record<string, string | undefined>;
|
|
28
28
|
}): Promise<string>;
|
|
29
29
|
export declare function hasPublishedPackageVersion(packageRoot: string, packageName: string, version: string, options?: {
|
|
30
30
|
registry?: string;
|
|
31
31
|
timeout?: number;
|
|
32
|
-
|
|
32
|
+
env?: Record<string, string | undefined>;
|
|
33
33
|
}): Promise<boolean>;
|
|
34
34
|
export declare function runPnpmOwnerAdd(packageName: string, user: string, options: {
|
|
35
35
|
cwd: string;
|
|
36
36
|
otp?: string;
|
|
37
37
|
}): Promise<void>;
|
|
38
|
-
export declare function createPnpmAuthEnv(token?: string): {
|
|
39
|
-
NODE_AUTH_TOKEN: string;
|
|
40
|
-
NPM_TOKEN: string;
|
|
41
|
-
} | undefined;
|
|
42
38
|
export declare function hasNpmAuthChallenge(result: {
|
|
43
39
|
stdout?: unknown;
|
|
44
40
|
stderr?: unknown;
|
|
@@ -52,7 +52,7 @@ export async function withPnpmTimeout(subprocess, timeout) {
|
|
|
52
52
|
}
|
|
53
53
|
export async function ensurePnpm(options = {}) {
|
|
54
54
|
const result = await runPnpm(['--version'], {
|
|
55
|
-
env:
|
|
55
|
+
env: options.env,
|
|
56
56
|
});
|
|
57
57
|
const stdout = String(result.stdout ?? '');
|
|
58
58
|
if (hasFailedPnpmResult(result) || !stdout) {
|
|
@@ -71,7 +71,7 @@ export async function ensurePnpm(options = {}) {
|
|
|
71
71
|
export async function readPnpmWorkspacePackages(root, options = {}) {
|
|
72
72
|
try {
|
|
73
73
|
return (await readPnpmWorkspacePackageInfo(root, {
|
|
74
|
-
env:
|
|
74
|
+
env: options.env,
|
|
75
75
|
})).map((item) => {
|
|
76
76
|
if (!isWorkspacePackage(item))
|
|
77
77
|
throwInvalidWorkspacePackages();
|
|
@@ -87,7 +87,7 @@ export async function readPnpmWorkspacePackages(root, options = {}) {
|
|
|
87
87
|
export async function runPnpmBuild(packageRoot, options = {}) {
|
|
88
88
|
const result = await runPnpm(['run', 'build'], {
|
|
89
89
|
cwd: packageRoot,
|
|
90
|
-
env:
|
|
90
|
+
env: options.env,
|
|
91
91
|
stdio: 'inherit',
|
|
92
92
|
});
|
|
93
93
|
if (hasFailedPnpmResult(result)) {
|
|
@@ -98,7 +98,7 @@ export async function runPnpmPublish(packageRoot, args, options = {}) {
|
|
|
98
98
|
const isDryRun = args.includes('--dry-run');
|
|
99
99
|
const result = await runPnpm(['publish', ...args], {
|
|
100
100
|
cwd: packageRoot,
|
|
101
|
-
env:
|
|
101
|
+
env: options.env,
|
|
102
102
|
stdio: isDryRun ? 'pipe' : 'inherit',
|
|
103
103
|
});
|
|
104
104
|
if (isDryRun)
|
|
@@ -116,7 +116,7 @@ export async function runPnpmWhoami(packageRoot, options = {}) {
|
|
|
116
116
|
args.push('--registry', options.registry);
|
|
117
117
|
const result = await runPnpm(args, {
|
|
118
118
|
cwd: packageRoot,
|
|
119
|
-
env:
|
|
119
|
+
env: options.env,
|
|
120
120
|
timeout: options.timeout,
|
|
121
121
|
});
|
|
122
122
|
if (hasFailedPnpmResult(result)) {
|
|
@@ -135,7 +135,7 @@ export async function hasPublishedPackageVersion(packageRoot, packageName, versi
|
|
|
135
135
|
args.push('--registry', options.registry);
|
|
136
136
|
const result = await runPnpm(args, {
|
|
137
137
|
cwd: packageRoot,
|
|
138
|
-
env:
|
|
138
|
+
env: options.env,
|
|
139
139
|
timeout: options.timeout,
|
|
140
140
|
});
|
|
141
141
|
if (!hasFailedPnpmResult(result)) {
|
|
@@ -159,14 +159,6 @@ export async function runPnpmOwnerAdd(packageName, user, options) {
|
|
|
159
159
|
throw new Error(`[publish] pnpm owner add failed for ${user} -> ${packageName}.`);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
export function createPnpmAuthEnv(token) {
|
|
163
|
-
if (!token)
|
|
164
|
-
return undefined;
|
|
165
|
-
return {
|
|
166
|
-
NODE_AUTH_TOKEN: token,
|
|
167
|
-
NPM_TOKEN: token,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
162
|
const isWorkspacePackage = (value) => {
|
|
171
163
|
if (!isPlainObject(value)) {
|
|
172
164
|
return false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PublishOptions, PublishTarget } from '#auklet/publish/types';
|
|
1
|
+
import type { PublishOptions, PublishRuntime, PublishTarget } from '#auklet/publish/types';
|
|
2
2
|
export declare class PnpmPublishApi {
|
|
3
|
-
publish(target: PublishTarget, options: PublishOptions): Promise<void>;
|
|
3
|
+
publish(target: PublishTarget, options: PublishOptions, runtime: PublishRuntime): Promise<void>;
|
|
4
4
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { runPnpmPublish } from '#auklet/publish/api/pnpmApi';
|
|
2
2
|
import { createPublishArgs } from '#auklet/publish/api/publishArgs';
|
|
3
|
+
import { createPublishTargetEnv } from '#auklet/publish/publishEnv';
|
|
3
4
|
export class PnpmPublishApi {
|
|
4
|
-
async publish(target, options) {
|
|
5
|
+
async publish(target, options, runtime) {
|
|
5
6
|
const args = createPublishArgs(target, options);
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const { env } = createPublishTargetEnv(options, runtime, target);
|
|
8
|
+
if (env) {
|
|
9
|
+
await runPnpmPublish(target.packageRoot, args, { env });
|
|
8
10
|
return;
|
|
9
11
|
}
|
|
10
12
|
await runPnpmPublish(target.packageRoot, args);
|
package/dist/publish/cli.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AukletEnvContext } from '#auklet/env';
|
|
1
2
|
export declare function runPublishCli(args: Array<string>): Promise<void>;
|
|
2
|
-
export declare function resolvePublishCliOptions(args: Array<string>, cwd?: string): {
|
|
3
|
+
export declare function resolvePublishCliOptions(args: Array<string>, cwd?: string, envContext?: AukletEnvContext): {
|
|
3
4
|
cwd: string;
|
|
4
5
|
otp: string | undefined;
|
|
5
6
|
filters: string[];
|
|
@@ -9,6 +10,9 @@ export declare function resolvePublishCliOptions(args: Array<string>, cwd?: stri
|
|
|
9
10
|
dryRun: boolean;
|
|
10
11
|
allowDirty: boolean;
|
|
11
12
|
ignoreScripts: boolean;
|
|
12
|
-
token:
|
|
13
|
+
token: {
|
|
14
|
+
raw: string;
|
|
15
|
+
resolve(context: AukletEnvContext): string | undefined;
|
|
16
|
+
} | undefined;
|
|
13
17
|
};
|
|
14
18
|
export declare function runOwnerCli(args: Array<string>): Promise<void>;
|
package/dist/publish/cli.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import minimist from 'minimist';
|
|
2
2
|
import { isArray } from 'aidly';
|
|
3
|
+
import { AukletEnvContext } from '#auklet/env';
|
|
4
|
+
import { ensurePnpm } from '#auklet/publish/api/pnpmApi';
|
|
3
5
|
import { OwnerRunner } from '#auklet/publish/ownerRunner';
|
|
4
6
|
import { PublishRunner } from '#auklet/publish/publishRunner';
|
|
5
7
|
import { validateNpmrcAuthEnv } from '#auklet/publish/api/npmrc';
|
|
6
|
-
import {
|
|
8
|
+
import { resolveCliBoolean, resolveCliValue, createDeferredCliValue, } from '#auklet/cli/values';
|
|
9
|
+
import { createPublishRootEnv } from '#auklet/publish/publishEnv';
|
|
7
10
|
import { findWorkspaceRoot } from '#auklet/workspace/root';
|
|
8
11
|
const publishFlags = new Set([
|
|
9
12
|
'_',
|
|
@@ -19,67 +22,84 @@ const publishFlags = new Set([
|
|
|
19
22
|
]);
|
|
20
23
|
const ownerFlags = new Set(['_', 'filter', 'package', 'otp']);
|
|
21
24
|
export async function runPublishCli(args) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
await
|
|
25
|
+
const cwd = process.cwd();
|
|
26
|
+
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
27
|
+
const envContext = new AukletEnvContext(cwd, root);
|
|
28
|
+
await envContext.run(async () => {
|
|
29
|
+
const runtime = { envContext };
|
|
30
|
+
const options = resolvePublishCliOptions(args, cwd, envContext);
|
|
31
|
+
const { env } = createPublishRootEnv(options, runtime);
|
|
32
|
+
validatePublishCliNpmrcAuthEnv(options.cwd, env);
|
|
33
|
+
await ensurePnpm({ env });
|
|
34
|
+
await new PublishRunner(options, runtime).run();
|
|
35
|
+
});
|
|
26
36
|
}
|
|
27
|
-
export function resolvePublishCliOptions(args, cwd = process.cwd()) {
|
|
37
|
+
export function resolvePublishCliOptions(args, cwd = process.cwd(), envContext = new AukletEnvContext(cwd)) {
|
|
28
38
|
const argv = parsePublishArgs(args);
|
|
29
39
|
if (argv._.length) {
|
|
30
40
|
throw new Error(`[publish] unknown publish argument: ${argv._.join(' ')}`);
|
|
31
41
|
}
|
|
32
42
|
return {
|
|
33
43
|
cwd,
|
|
34
|
-
otp: stringOption(argv.otp),
|
|
35
|
-
filters: toArray(argv.filter),
|
|
36
|
-
version: stringOption(argv.version),
|
|
37
|
-
git: argv.git
|
|
38
|
-
format: argv.format
|
|
39
|
-
dryRun: argv['dry-run']
|
|
40
|
-
allowDirty: argv['allow-dirty']
|
|
41
|
-
ignoreScripts: argv['ignore-scripts']
|
|
42
|
-
token:
|
|
44
|
+
otp: stringOption(argv.otp, '--otp', envContext),
|
|
45
|
+
filters: toArray(argv.filter, '--filter', envContext),
|
|
46
|
+
version: stringOption(argv.version, '--version', envContext),
|
|
47
|
+
git: booleanOption(argv.git, '--git', envContext, true),
|
|
48
|
+
format: booleanOption(argv.format, '--format', envContext, true),
|
|
49
|
+
dryRun: booleanOption(argv['dry-run'], '--dry-run', envContext),
|
|
50
|
+
allowDirty: booleanOption(argv['allow-dirty'], '--allow-dirty', envContext),
|
|
51
|
+
ignoreScripts: booleanOption(argv['ignore-scripts'], '--ignore-scripts', envContext),
|
|
52
|
+
token: deferredStringOption(argv.token, '--token'),
|
|
43
53
|
};
|
|
44
54
|
}
|
|
45
55
|
const parsePublishArgs = (args) => {
|
|
46
56
|
const cliArgs = stripLeadingArgsSeparator(args);
|
|
47
57
|
validateNoPrefixedFlags(cliArgs, new Set(['--no-format', '--no-git']));
|
|
48
58
|
const argv = minimist(cliArgs, {
|
|
49
|
-
string: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
string: [
|
|
60
|
+
'filter',
|
|
61
|
+
'version',
|
|
62
|
+
'otp',
|
|
63
|
+
'token',
|
|
64
|
+
'dry-run',
|
|
65
|
+
'format',
|
|
66
|
+
'git',
|
|
67
|
+
'ignore-scripts',
|
|
68
|
+
'allow-dirty',
|
|
69
|
+
],
|
|
55
70
|
});
|
|
56
71
|
validateFlags(argv, publishFlags);
|
|
57
72
|
return argv;
|
|
58
73
|
};
|
|
59
74
|
export async function runOwnerCli(args) {
|
|
60
|
-
const cliArgs = stripLeadingArgsSeparator(args);
|
|
61
|
-
validateNoPrefixedFlags(cliArgs, new Set());
|
|
62
|
-
const argv = minimist(cliArgs, {
|
|
63
|
-
string: ['filter', 'package', 'otp'],
|
|
64
|
-
});
|
|
65
|
-
validateFlags(argv, ownerFlags);
|
|
66
|
-
const [subcommand, ...users] = argv._;
|
|
67
|
-
if (subcommand !== 'add') {
|
|
68
|
-
throw new Error('[publish] expected owner command: auk owner add <user...>');
|
|
69
|
-
}
|
|
70
|
-
if (!users.length) {
|
|
71
|
-
throw new Error('[publish] owner add requires at least one user.');
|
|
72
|
-
}
|
|
73
75
|
const cwd = process.cwd();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
77
|
+
const envContext = new AukletEnvContext(cwd, root);
|
|
78
|
+
await envContext.run(async () => {
|
|
79
|
+
const cliArgs = stripLeadingArgsSeparator(args);
|
|
80
|
+
validateNoPrefixedFlags(cliArgs, new Set());
|
|
81
|
+
const argv = minimist(cliArgs, {
|
|
82
|
+
string: ['filter', 'package', 'otp'],
|
|
83
|
+
});
|
|
84
|
+
validateFlags(argv, ownerFlags);
|
|
85
|
+
const [subcommand, ...users] = argv._;
|
|
86
|
+
if (subcommand !== 'add') {
|
|
87
|
+
throw new Error('[publish] expected owner command: auk owner add <user...>');
|
|
88
|
+
}
|
|
89
|
+
if (!users.length) {
|
|
90
|
+
throw new Error('[publish] owner add requires at least one user.');
|
|
91
|
+
}
|
|
92
|
+
const env = envContext.values;
|
|
93
|
+
validatePublishCliNpmrcAuthEnv(cwd, env);
|
|
94
|
+
await ensurePnpm({ env: envContext.normalizedValues });
|
|
95
|
+
await new OwnerRunner({
|
|
96
|
+
cwd,
|
|
97
|
+
users,
|
|
98
|
+
filters: toArray(argv.filter, '--filter', envContext),
|
|
99
|
+
packages: toArray(argv.package, '--package', envContext),
|
|
100
|
+
otp: stringOption(argv.otp, '--otp', envContext),
|
|
101
|
+
}).run();
|
|
102
|
+
});
|
|
83
103
|
}
|
|
84
104
|
const validateFlags = (argv, allowedFlags) => {
|
|
85
105
|
for (const flag of Object.keys(argv)) {
|
|
@@ -97,20 +117,38 @@ const validateNoPrefixedFlags = (args, allowedFlags) => {
|
|
|
97
117
|
const stripLeadingArgsSeparator = (args) => {
|
|
98
118
|
return args.filter((arg) => arg !== '--');
|
|
99
119
|
};
|
|
100
|
-
const toArray = (value) => {
|
|
120
|
+
const toArray = (value, label, envContext) => {
|
|
101
121
|
if (value === undefined)
|
|
102
122
|
return [];
|
|
103
|
-
|
|
104
|
-
? value.map(
|
|
105
|
-
: [
|
|
123
|
+
const values = isArray(value)
|
|
124
|
+
? value.map((item) => stringOption(item, label, envContext)).filter(Boolean)
|
|
125
|
+
: [stringOption(value, label, envContext)].filter(Boolean);
|
|
126
|
+
return values.filter((item) => Boolean(item));
|
|
127
|
+
};
|
|
128
|
+
const stringOption = (value, label, envContext) => {
|
|
129
|
+
if (value === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
if (isArray(value))
|
|
132
|
+
return stringOption(value.at(-1), label, envContext);
|
|
133
|
+
return resolveCliValue(String(value), { label, context: envContext });
|
|
106
134
|
};
|
|
107
|
-
const
|
|
135
|
+
const deferredStringOption = (value, label) => {
|
|
108
136
|
if (value === undefined)
|
|
109
137
|
return undefined;
|
|
110
138
|
if (isArray(value))
|
|
111
|
-
return
|
|
112
|
-
return String(value);
|
|
139
|
+
return deferredStringOption(value.at(-1), label);
|
|
140
|
+
return createDeferredCliValue(String(value), { label });
|
|
141
|
+
};
|
|
142
|
+
const booleanOption = (value, label, envContext, defaultValue = false) => {
|
|
143
|
+
if (value === undefined)
|
|
144
|
+
return defaultValue;
|
|
145
|
+
if (isArray(value)) {
|
|
146
|
+
return booleanOption(value.at(-1), label, envContext, defaultValue);
|
|
147
|
+
}
|
|
148
|
+
if (typeof value === 'boolean')
|
|
149
|
+
return value;
|
|
150
|
+
return resolveCliBoolean(String(value), { label, context: envContext });
|
|
113
151
|
};
|
|
114
|
-
const validatePublishCliNpmrcAuthEnv = (cwd,
|
|
115
|
-
validateNpmrcAuthEnv(cwd, findWorkspaceRoot(cwd) ?? cwd, {
|
|
152
|
+
const validatePublishCliNpmrcAuthEnv = (cwd, env) => {
|
|
153
|
+
validateNpmrcAuthEnv(cwd, findWorkspaceRoot(cwd) ?? cwd, { env });
|
|
116
154
|
};
|
package/dist/publish/inspect.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { isString } from 'aidly';
|
|
3
|
+
import { AukletEnvContext } from '#auklet/env';
|
|
3
4
|
import { createAukletLogger } from '#auklet/logger';
|
|
4
|
-
import {
|
|
5
|
-
import { getPublishRegistry } from '#auklet/publish/api/registry';
|
|
5
|
+
import { findWorkspaceRoot } from '#auklet/workspace/root';
|
|
6
6
|
import { ensurePnpm } from '#auklet/publish/api/pnpmApi';
|
|
7
|
-
import {
|
|
7
|
+
import { getPublishRegistry } from '#auklet/publish/api/registry';
|
|
8
|
+
import { resolvePublishTag } from '#auklet/publish/api/publishArgs';
|
|
8
9
|
import { resolvePublishCliOptions } from '#auklet/publish/cli';
|
|
9
|
-
import {
|
|
10
|
+
import { validateNpmrcAuthEnv } from '#auklet/publish/api/npmrc';
|
|
11
|
+
import { createPublishRootEnv } from '#auklet/publish/publishEnv';
|
|
10
12
|
import { inspectPublishRegistry, } from '#auklet/publish/inspectRegistry';
|
|
11
13
|
import { inspectPackageFiles, PackInspectReporter, } from '#auklet/publish/inspectPack';
|
|
12
14
|
import { resolvePublishPlan } from '#auklet/publish/targetResolver';
|
|
13
15
|
export async function runInspectPublishCli(args) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const cwd = process.cwd();
|
|
17
|
+
const root = findWorkspaceRoot(cwd) ?? cwd;
|
|
18
|
+
const envContext = new AukletEnvContext(cwd, root);
|
|
19
|
+
return envContext.run(async () => {
|
|
20
|
+
const options = resolvePublishCliOptions(args, cwd, envContext);
|
|
21
|
+
return runInspectPublish(options, root, { envContext });
|
|
17
22
|
});
|
|
18
|
-
|
|
23
|
+
}
|
|
24
|
+
async function runInspectPublish(options, root, runtime) {
|
|
25
|
+
const { env } = createPublishRootEnv(options, runtime);
|
|
26
|
+
validateNpmrcAuthEnv(options.cwd, root, { env });
|
|
27
|
+
await ensurePnpm({ env });
|
|
19
28
|
const logger = createAukletLogger({ scope: 'inspect' });
|
|
20
|
-
const plan = await resolvePublishPlan(options, logger);
|
|
29
|
+
const plan = await resolvePublishPlan(options, runtime, logger);
|
|
21
30
|
const packageFileChecks = inspectPackageFiles(plan.targets);
|
|
22
31
|
const packageFileCheckFailed = packageFileChecks.some((check) => check.status === 'missing');
|
|
23
32
|
if (packageFileCheckFailed) {
|
|
@@ -28,6 +37,7 @@ export async function runInspectPublishCli(args) {
|
|
|
28
37
|
spinner.start();
|
|
29
38
|
const registryChecks = await inspectPublishRegistry(plan, {
|
|
30
39
|
token: options.token,
|
|
40
|
+
runtime,
|
|
31
41
|
onCheck: (info) => {
|
|
32
42
|
spinner.text([
|
|
33
43
|
'Checking registry ',
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { isArray, isPlainObject, isString } from 'aidly';
|
|
4
|
+
import { AukletEnvContext } from '#auklet/env';
|
|
4
5
|
import { createAukletLogger } from '#auklet/logger';
|
|
6
|
+
import { findWorkspaceRoot } from '#auklet/workspace/root';
|
|
5
7
|
import { resolvePublishPlan } from '#auklet/publish/targetResolver';
|
|
6
8
|
export async function runInspectPackCli(args) {
|
|
7
9
|
const options = resolveInspectPackOptions(args);
|
|
10
|
+
const root = findWorkspaceRoot(options.cwd) ?? options.cwd;
|
|
11
|
+
const envContext = new AukletEnvContext(options.cwd, root);
|
|
8
12
|
const logger = createAukletLogger({ scope: 'inspect' });
|
|
9
|
-
const plan = await resolvePublishPlan({
|
|
13
|
+
const plan = await envContext.run(() => resolvePublishPlan({
|
|
10
14
|
cwd: options.cwd,
|
|
11
15
|
filters: options.filters,
|
|
12
16
|
dryRun: true,
|
|
13
17
|
version: undefined,
|
|
14
|
-
}, logger);
|
|
18
|
+
}, { envContext }, logger));
|
|
15
19
|
const checks = inspectPackageFiles(plan.targets);
|
|
16
20
|
new PackInspectReporter(options.cwd, plan.targets, checks).report();
|
|
17
21
|
return checks.some((check) => check.status === 'missing') ? 1 : 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PublishOptions, PublishPlan } from '#auklet/publish/types';
|
|
1
|
+
import type { PublishOptions, PublishPlan, PublishRuntime } from '#auklet/publish/types';
|
|
2
2
|
export type PublishRegistryCheckStatus = 'success' | 'error';
|
|
3
3
|
export type PublishRegistryCheck = {
|
|
4
4
|
packageName: string;
|
|
@@ -18,7 +18,8 @@ export type PublishRegistryRetryInfo = {
|
|
|
18
18
|
export type PublishRegistryCheckInfo = Pick<PublishRegistryRetryInfo, 'packageName' | 'registry' | 'check'>;
|
|
19
19
|
export type InspectPublishRegistryOptions = {
|
|
20
20
|
token?: PublishOptions['token'];
|
|
21
|
+
runtime: PublishRuntime;
|
|
21
22
|
onCheck?: (info: PublishRegistryCheckInfo) => void;
|
|
22
23
|
onRetry?: (info: PublishRegistryRetryInfo) => void;
|
|
23
24
|
};
|
|
24
|
-
export declare function inspectPublishRegistry(plan: PublishPlan, options
|
|
25
|
+
export declare function inspectPublishRegistry(plan: PublishPlan, options: InspectPublishRegistryOptions): Promise<PublishRegistryCheck[]>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { retry } from 'aidly';
|
|
2
2
|
import { getPublishRegistry } from '#auklet/publish/api/registry';
|
|
3
|
-
import {
|
|
3
|
+
import { runPnpmWhoami, hasPublishedPackageVersion, } from '#auklet/publish/api/pnpmApi';
|
|
4
|
+
import { createPublishTargetEnv } from '#auklet/publish/publishEnv';
|
|
4
5
|
const registryCheckTimeout = 5_000;
|
|
5
6
|
const registryCheckRetryTimes = 2;
|
|
6
|
-
export async function inspectPublishRegistry(plan, options
|
|
7
|
+
export async function inspectPublishRegistry(plan, options) {
|
|
7
8
|
const authResults = new Map();
|
|
8
9
|
const checks = [];
|
|
9
10
|
for (const target of plan.targets) {
|
|
@@ -26,6 +27,9 @@ export async function inspectPublishRegistry(plan, options = {}) {
|
|
|
26
27
|
return checks;
|
|
27
28
|
}
|
|
28
29
|
const checkAuth = async (authResults, authKey, packageRoot, packageName, registry, options) => {
|
|
30
|
+
const { env } = createPublishTargetEnv(options, options.runtime, {
|
|
31
|
+
packageRoot,
|
|
32
|
+
});
|
|
29
33
|
try {
|
|
30
34
|
options.onCheck?.({
|
|
31
35
|
packageName,
|
|
@@ -35,7 +39,7 @@ const checkAuth = async (authResults, authKey, packageRoot, packageName, registr
|
|
|
35
39
|
await retryWithLog(() => runPnpmWhoami(packageRoot, {
|
|
36
40
|
packageName,
|
|
37
41
|
registry,
|
|
38
|
-
|
|
42
|
+
env,
|
|
39
43
|
timeout: registryCheckTimeout,
|
|
40
44
|
}), {
|
|
41
45
|
check: 'auth',
|
|
@@ -53,6 +57,9 @@ const checkAuth = async (authResults, authKey, packageRoot, packageName, registr
|
|
|
53
57
|
}
|
|
54
58
|
};
|
|
55
59
|
const checkVersion = async (packageRoot, packageName, version, registry, options) => {
|
|
60
|
+
const { env } = createPublishTargetEnv(options, options.runtime, {
|
|
61
|
+
packageRoot,
|
|
62
|
+
});
|
|
56
63
|
try {
|
|
57
64
|
options.onCheck?.({
|
|
58
65
|
packageName,
|
|
@@ -61,7 +68,7 @@ const checkVersion = async (packageRoot, packageName, version, registry, options
|
|
|
61
68
|
});
|
|
62
69
|
const exists = await retryWithLog(() => hasPublishedPackageVersion(packageRoot, packageName, version, {
|
|
63
70
|
registry,
|
|
64
|
-
|
|
71
|
+
env,
|
|
65
72
|
timeout: registryCheckTimeout,
|
|
66
73
|
}), {
|
|
67
74
|
check: 'version',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PublishOptions, PublishRuntime, PublishTarget } from '#auklet/publish/types';
|
|
2
|
+
export type PublishPnpmEnv = {
|
|
3
|
+
env?: Record<string, string | undefined>;
|
|
4
|
+
token?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function createPublishRootEnv(options: Pick<PublishOptions, 'token'>, runtime: PublishRuntime): {
|
|
7
|
+
env: Record<string, string | undefined> | undefined;
|
|
8
|
+
token: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function createPublishTargetEnv(options: Pick<PublishOptions, 'token'>, runtime: PublishRuntime, target: Pick<PublishTarget, 'packageRoot'>): {
|
|
11
|
+
env: Record<string, string | undefined> | undefined;
|
|
12
|
+
token: string | undefined;
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function createPublishRootEnv(options, runtime) {
|
|
2
|
+
return createPublishPnpmEnv(options.token, runtime.envContext);
|
|
3
|
+
}
|
|
4
|
+
export function createPublishTargetEnv(options, runtime, target) {
|
|
5
|
+
const envContext = runtime.envContext.createPackageContext(target.packageRoot);
|
|
6
|
+
return createPublishPnpmEnv(options.token, envContext);
|
|
7
|
+
}
|
|
8
|
+
const createPublishPnpmEnv = (token, envContext) => {
|
|
9
|
+
const resolvedToken = token?.resolve(envContext);
|
|
10
|
+
const resolvedEnv = resolvedToken
|
|
11
|
+
? {
|
|
12
|
+
...envContext.values,
|
|
13
|
+
NODE_AUTH_TOKEN: resolvedToken,
|
|
14
|
+
NPM_TOKEN: resolvedToken,
|
|
15
|
+
}
|
|
16
|
+
: envContext.values;
|
|
17
|
+
return {
|
|
18
|
+
env: Object.keys(resolvedEnv).length ? resolvedEnv : undefined,
|
|
19
|
+
token: resolvedToken,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PublishOptions } from '#auklet/publish/types';
|
|
1
|
+
import type { PublishOptions, PublishRuntime } from '#auklet/publish/types';
|
|
2
2
|
export declare class PublishRunner {
|
|
3
3
|
private readonly git;
|
|
4
4
|
private readonly publisher;
|
|
@@ -6,7 +6,8 @@ export declare class PublishRunner {
|
|
|
6
6
|
private readonly versions;
|
|
7
7
|
private readonly logger;
|
|
8
8
|
private readonly options;
|
|
9
|
-
|
|
9
|
+
private readonly runtime;
|
|
10
|
+
constructor(options: PublishOptions, runtime: PublishRuntime);
|
|
10
11
|
run(): Promise<void>;
|
|
11
12
|
private publishWithPlan;
|
|
12
13
|
private handleFailure;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAukletLogger } from '#auklet/logger';
|
|
2
2
|
import { runPublishHook } from '#auklet/publish/api/publishHookApi';
|
|
3
3
|
import { runPackageBuilds, validateBuildScript, } from '#auklet/publish/runner/packageBuilder';
|
|
4
4
|
import { formatPublishOutputs } from '#auklet/publish/runner/publishOutputFormatter';
|
|
@@ -17,16 +17,18 @@ export class PublishRunner {
|
|
|
17
17
|
versions;
|
|
18
18
|
logger;
|
|
19
19
|
options;
|
|
20
|
-
|
|
20
|
+
runtime;
|
|
21
|
+
constructor(options, runtime) {
|
|
21
22
|
this.options = options;
|
|
22
|
-
this.
|
|
23
|
+
this.runtime = runtime;
|
|
24
|
+
this.logger = createAukletLogger({ scope: 'publish' });
|
|
23
25
|
this.git = new ReleaseGitController(this.options, this.logger);
|
|
24
|
-
this.publisher = new PackagePublisher(this.options, this.logger);
|
|
25
|
-
this.preflight = new PublishPreflight(this.options, this.logger);
|
|
26
|
+
this.publisher = new PackagePublisher(this.options, this.runtime, this.logger);
|
|
27
|
+
this.preflight = new PublishPreflight(this.options, this.runtime, this.logger);
|
|
26
28
|
this.versions = new VersionWriter(this.options, this.logger);
|
|
27
29
|
}
|
|
28
30
|
async run() {
|
|
29
|
-
const plan = await resolvePublishPlan(this.options, this.logger);
|
|
31
|
+
const plan = await resolvePublishPlan(this.options, this.runtime, this.logger);
|
|
30
32
|
let failureHookEnabled = false;
|
|
31
33
|
try {
|
|
32
34
|
validateBuildScript(plan.targets);
|
|
@@ -36,7 +38,7 @@ export class PublishRunner {
|
|
|
36
38
|
await runPublishHook({ status: 'beforeBuild', plan });
|
|
37
39
|
failureHookEnabled = true;
|
|
38
40
|
this.versions.writeBeforeBuild(plan);
|
|
39
|
-
await runPackageBuilds(plan.targets, this.logger, this.options);
|
|
41
|
+
await runPackageBuilds(plan.targets, this.logger, this.options, this.runtime);
|
|
40
42
|
await runPublishHook({ status: 'afterBuild', plan });
|
|
41
43
|
await formatPublishOutputs(plan.targets, this.options.format);
|
|
42
44
|
await runPublishHook({ status: 'beforePublish', plan });
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { PublishTarget } from '#auklet/publish/types';
|
|
2
1
|
import type { AukletLogger } from '#auklet/logger';
|
|
3
|
-
import type { PublishOptions } from '#auklet/publish/types';
|
|
2
|
+
import type { PublishTarget, PublishOptions, PublishRuntime } from '#auklet/publish/types';
|
|
4
3
|
export declare function validateBuildScript(targets: Array<PublishTarget>): void;
|
|
5
|
-
export declare function runPackageBuilds(targets: Array<PublishTarget>, logger: AukletLogger, options
|
|
4
|
+
export declare function runPackageBuilds(targets: Array<PublishTarget>, logger: AukletLogger, options: Pick<PublishOptions, 'token'>, runtime: PublishRuntime): Promise<void>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isString } from 'aidly';
|
|
2
2
|
import { runPnpmBuild } from '#auklet/publish/api/pnpmApi';
|
|
3
|
+
import { createPublishTargetEnv } from '#auklet/publish/publishEnv';
|
|
3
4
|
export function validateBuildScript(targets) {
|
|
4
5
|
for (const target of targets) {
|
|
5
6
|
const buildScript = target.packageJson.scripts?.build;
|
|
@@ -8,11 +9,12 @@ export function validateBuildScript(targets) {
|
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
export async function runPackageBuilds(targets, logger, options
|
|
12
|
+
export async function runPackageBuilds(targets, logger, options, runtime) {
|
|
12
13
|
for (const target of targets) {
|
|
13
14
|
logger.step('build ', logger.package(target.packageName));
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const { env } = createPublishTargetEnv(options, runtime, target);
|
|
16
|
+
if (env) {
|
|
17
|
+
await runPnpmBuild(target.packageRoot, { env });
|
|
16
18
|
continue;
|
|
17
19
|
}
|
|
18
20
|
await runPnpmBuild(target.packageRoot);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { AukletLogger } from '#auklet/logger';
|
|
2
|
-
import type { PublishOptions, PublishPlan } from '#auklet/publish/types';
|
|
2
|
+
import type { PublishOptions, PublishPlan, PublishRuntime } from '#auklet/publish/types';
|
|
3
3
|
export declare class PackagePublisher {
|
|
4
4
|
private readonly options;
|
|
5
|
+
private readonly runtime;
|
|
5
6
|
private readonly logger;
|
|
6
7
|
private readonly pnpm;
|
|
7
|
-
constructor(options: PublishOptions, logger: AukletLogger);
|
|
8
|
+
constructor(options: PublishOptions, runtime: PublishRuntime, logger: AukletLogger);
|
|
8
9
|
run(plan: PublishPlan): Promise<void>;
|
|
9
10
|
}
|
|
10
11
|
export declare function logAuthenticationError(logger: AukletLogger, error: unknown): void;
|
|
@@ -3,17 +3,19 @@ import { NpmPublishAuthenticationError } from '#auklet/publish/api/pnpmApi';
|
|
|
3
3
|
import { PublishTargetError } from '#auklet/publish/runner/publishTargetError';
|
|
4
4
|
export class PackagePublisher {
|
|
5
5
|
options;
|
|
6
|
+
runtime;
|
|
6
7
|
logger;
|
|
7
8
|
pnpm = new PnpmPublishApi();
|
|
8
|
-
constructor(options, logger) {
|
|
9
|
+
constructor(options, runtime, logger) {
|
|
9
10
|
this.options = options;
|
|
11
|
+
this.runtime = runtime;
|
|
10
12
|
this.logger = logger;
|
|
11
13
|
}
|
|
12
14
|
async run(plan) {
|
|
13
15
|
const publishedTargets = [];
|
|
14
16
|
for (const target of plan.targets) {
|
|
15
17
|
try {
|
|
16
|
-
await this.pnpm.publish(target, this.options);
|
|
18
|
+
await this.pnpm.publish(target, this.options, this.runtime);
|
|
17
19
|
publishedTargets.push(target);
|
|
18
20
|
}
|
|
19
21
|
catch (error) {
|