auklet 0.1.2 → 0.1.3
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/dist/publish/api/npmrc.d.ts +4 -0
- package/dist/publish/api/npmrc.js +37 -0
- package/dist/publish/api/pnpmApi.d.ts +9 -3
- package/dist/publish/api/pnpmApi.js +10 -5
- package/dist/publish/cli.js +12 -3
- package/dist/publish/inspect.js +6 -1
- package/dist/publish/publishRunner.js +1 -1
- package/dist/publish/runner/packageBuilder.d.ts +2 -1
- package/dist/publish/runner/packageBuilder.js +5 -1
- package/dist/publish/runner/publishPreflight.d.ts +1 -0
- package/dist/publish/runner/publishPreflight.js +9 -1
- package/dist/publish/targetResolver.d.ts +1 -1
- package/dist/publish/targetResolver.js +3 -1
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export type NpmrcAuthEnvOptions = {
|
|
2
|
+
token?: string;
|
|
3
|
+
};
|
|
1
4
|
export declare function findNpmrcWithAuthToken(packageRoot: string, root: string, registry?: string): string | undefined;
|
|
2
5
|
export declare function findNpmrcFiles(packageRoot: string, root: string): string[];
|
|
6
|
+
export declare function validateNpmrcAuthEnv(packageRoot: string, root: string, options?: NpmrcAuthEnvOptions): void;
|
|
3
7
|
export declare function hasAuthToken(content: string, registry?: string): boolean;
|
|
4
8
|
export declare function toNpmrcRegistryKey(registry: string): string;
|
|
@@ -23,6 +23,19 @@ export function findNpmrcFiles(packageRoot, root) {
|
|
|
23
23
|
}
|
|
24
24
|
return files;
|
|
25
25
|
}
|
|
26
|
+
export function validateNpmrcAuthEnv(packageRoot, root, options = {}) {
|
|
27
|
+
const env = createAvailableAuthEnv(options);
|
|
28
|
+
for (const file of findNpmrcFiles(packageRoot, root)) {
|
|
29
|
+
const missing = findMissingNpmrcEnvVars(fs.readFileSync(file, 'utf8'), env);
|
|
30
|
+
if (!missing.length)
|
|
31
|
+
continue;
|
|
32
|
+
const variable = missing[0];
|
|
33
|
+
throw new Error(`[publish] npmrc auth environment is missing: ${variable}\n` +
|
|
34
|
+
`[publish] file: ${file}\n` +
|
|
35
|
+
`[publish] Set ${variable} before retrying, or use --token with an npmrc entry such as:\n` +
|
|
36
|
+
' //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
26
39
|
export function hasAuthToken(content, registry) {
|
|
27
40
|
const lines = content
|
|
28
41
|
.split(/\r?\n/)
|
|
@@ -50,3 +63,27 @@ const parseRegistryUrl = (registry) => {
|
|
|
50
63
|
});
|
|
51
64
|
}
|
|
52
65
|
};
|
|
66
|
+
const findMissingNpmrcEnvVars = (content, env) => {
|
|
67
|
+
return getNpmrcAuthLines(content)
|
|
68
|
+
.flatMap((line) => [...line.matchAll(/\$\{([^}]+)\}/g)])
|
|
69
|
+
.map((match) => match[1])
|
|
70
|
+
.filter((name) => name && !env[name]);
|
|
71
|
+
};
|
|
72
|
+
const getNpmrcAuthLines = (content) => {
|
|
73
|
+
return content
|
|
74
|
+
.split(/\r?\n/)
|
|
75
|
+
.map((line) => line.trim())
|
|
76
|
+
.filter((line) => line &&
|
|
77
|
+
!line.startsWith('#') &&
|
|
78
|
+
!line.startsWith(';') &&
|
|
79
|
+
line.includes('_authToken'));
|
|
80
|
+
};
|
|
81
|
+
const createAvailableAuthEnv = (options) => {
|
|
82
|
+
if (!options.token)
|
|
83
|
+
return process.env;
|
|
84
|
+
return {
|
|
85
|
+
...process.env,
|
|
86
|
+
NODE_AUTH_TOKEN: options.token,
|
|
87
|
+
NPM_TOKEN: options.token,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -8,9 +8,15 @@ export declare class NpmPackageVersionExistsError extends Error {
|
|
|
8
8
|
constructor(packageName: string, version: string, registry?: string);
|
|
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
|
-
export declare function ensurePnpm(
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export declare function ensurePnpm(options?: {
|
|
12
|
+
token?: string;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
export declare function readPnpmWorkspacePackages(root: string, options?: {
|
|
15
|
+
token?: string;
|
|
16
|
+
}): Promise<WorkspacePackage[]>;
|
|
17
|
+
export declare function runPnpmBuild(packageRoot: string, options?: {
|
|
18
|
+
token?: string;
|
|
19
|
+
}): Promise<void>;
|
|
14
20
|
export declare function runPnpmPublish(packageRoot: string, args: Array<string>, options?: {
|
|
15
21
|
token?: string;
|
|
16
22
|
}): Promise<void>;
|
|
@@ -50,8 +50,10 @@ export async function withPnpmTimeout(subprocess, timeout) {
|
|
|
50
50
|
subprocess.catch(() => { });
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
53
|
-
export async function ensurePnpm() {
|
|
54
|
-
const result = await runPnpm(['--version']
|
|
53
|
+
export async function ensurePnpm(options = {}) {
|
|
54
|
+
const result = await runPnpm(['--version'], {
|
|
55
|
+
env: createPnpmAuthEnv(options.token),
|
|
56
|
+
});
|
|
55
57
|
const stdout = String(result.stdout ?? '');
|
|
56
58
|
if (hasFailedPnpmResult(result) || !stdout) {
|
|
57
59
|
throw new Error('[publish] pnpm is required for publishing.\n' +
|
|
@@ -66,9 +68,11 @@ export async function ensurePnpm() {
|
|
|
66
68
|
}
|
|
67
69
|
return version;
|
|
68
70
|
}
|
|
69
|
-
export async function readPnpmWorkspacePackages(root) {
|
|
71
|
+
export async function readPnpmWorkspacePackages(root, options = {}) {
|
|
70
72
|
try {
|
|
71
|
-
return (await readPnpmWorkspacePackageInfo(root
|
|
73
|
+
return (await readPnpmWorkspacePackageInfo(root, {
|
|
74
|
+
env: createPnpmAuthEnv(options.token),
|
|
75
|
+
})).map((item) => {
|
|
72
76
|
if (!isWorkspacePackage(item))
|
|
73
77
|
throwInvalidWorkspacePackages();
|
|
74
78
|
return item;
|
|
@@ -80,9 +84,10 @@ export async function readPnpmWorkspacePackages(root) {
|
|
|
80
84
|
});
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
|
-
export async function runPnpmBuild(packageRoot) {
|
|
87
|
+
export async function runPnpmBuild(packageRoot, options = {}) {
|
|
84
88
|
const result = await runPnpm(['run', 'build'], {
|
|
85
89
|
cwd: packageRoot,
|
|
90
|
+
env: createPnpmAuthEnv(options.token),
|
|
86
91
|
stdio: 'inherit',
|
|
87
92
|
});
|
|
88
93
|
if (hasFailedPnpmResult(result)) {
|
package/dist/publish/cli.js
CHANGED
|
@@ -2,7 +2,9 @@ import minimist from 'minimist';
|
|
|
2
2
|
import { isArray } from 'aidly';
|
|
3
3
|
import { OwnerRunner } from '#auklet/publish/ownerRunner';
|
|
4
4
|
import { PublishRunner } from '#auklet/publish/publishRunner';
|
|
5
|
+
import { validateNpmrcAuthEnv } from '#auklet/publish/api/npmrc';
|
|
5
6
|
import { ensurePnpm } from '#auklet/publish/api/pnpmApi';
|
|
7
|
+
import { findWorkspaceRoot } from '#auklet/workspace/root';
|
|
6
8
|
const publishFlags = new Set([
|
|
7
9
|
'_',
|
|
8
10
|
'filter',
|
|
@@ -17,8 +19,10 @@ const publishFlags = new Set([
|
|
|
17
19
|
]);
|
|
18
20
|
const ownerFlags = new Set(['_', 'filter', 'package', 'otp']);
|
|
19
21
|
export async function runPublishCli(args) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const options = resolvePublishCliOptions(args);
|
|
23
|
+
validatePublishCliNpmrcAuthEnv(options.cwd, options.token);
|
|
24
|
+
await ensurePnpm({ token: options.token });
|
|
25
|
+
await new PublishRunner(options).run();
|
|
22
26
|
}
|
|
23
27
|
export function resolvePublishCliOptions(args, cwd = process.cwd()) {
|
|
24
28
|
const argv = parsePublishArgs(args);
|
|
@@ -66,9 +70,11 @@ export async function runOwnerCli(args) {
|
|
|
66
70
|
if (!users.length) {
|
|
67
71
|
throw new Error('[publish] owner add requires at least one user.');
|
|
68
72
|
}
|
|
73
|
+
const cwd = process.cwd();
|
|
74
|
+
validatePublishCliNpmrcAuthEnv(cwd);
|
|
69
75
|
await ensurePnpm();
|
|
70
76
|
await new OwnerRunner({
|
|
71
|
-
cwd
|
|
77
|
+
cwd,
|
|
72
78
|
users,
|
|
73
79
|
filters: toArray(argv.filter),
|
|
74
80
|
packages: toArray(argv.package),
|
|
@@ -105,3 +111,6 @@ const stringOption = (value) => {
|
|
|
105
111
|
return String(value.at(-1));
|
|
106
112
|
return String(value);
|
|
107
113
|
};
|
|
114
|
+
const validatePublishCliNpmrcAuthEnv = (cwd, token) => {
|
|
115
|
+
validateNpmrcAuthEnv(cwd, findWorkspaceRoot(cwd) ?? cwd, { token });
|
|
116
|
+
};
|
package/dist/publish/inspect.js
CHANGED
|
@@ -4,13 +4,18 @@ import { createAukletLogger } from '#auklet/logger';
|
|
|
4
4
|
import { resolvePublishTag } from '#auklet/publish/api/publishArgs';
|
|
5
5
|
import { getPublishRegistry } from '#auklet/publish/api/registry';
|
|
6
6
|
import { ensurePnpm } from '#auklet/publish/api/pnpmApi';
|
|
7
|
+
import { validateNpmrcAuthEnv } from '#auklet/publish/api/npmrc';
|
|
7
8
|
import { resolvePublishCliOptions } from '#auklet/publish/cli';
|
|
9
|
+
import { findWorkspaceRoot } from '#auklet/workspace/root';
|
|
8
10
|
import { inspectPublishRegistry, } from '#auklet/publish/inspectRegistry';
|
|
9
11
|
import { inspectPackageFiles, PackInspectReporter, } from '#auklet/publish/inspectPack';
|
|
10
12
|
import { resolvePublishPlan } from '#auklet/publish/targetResolver';
|
|
11
13
|
export async function runInspectPublishCli(args) {
|
|
12
|
-
await ensurePnpm();
|
|
13
14
|
const options = resolvePublishCliOptions(args);
|
|
15
|
+
validateNpmrcAuthEnv(options.cwd, findWorkspaceRoot(options.cwd) ?? options.cwd, {
|
|
16
|
+
token: options.token,
|
|
17
|
+
});
|
|
18
|
+
await ensurePnpm({ token: options.token });
|
|
14
19
|
const logger = createAukletLogger({ scope: 'inspect' });
|
|
15
20
|
const plan = await resolvePublishPlan(options, logger);
|
|
16
21
|
const packageFileChecks = inspectPackageFiles(plan.targets);
|
|
@@ -36,7 +36,7 @@ export class PublishRunner {
|
|
|
36
36
|
await runPublishHook({ status: 'beforeBuild', plan });
|
|
37
37
|
failureHookEnabled = true;
|
|
38
38
|
this.versions.writeBeforeBuild(plan);
|
|
39
|
-
await runPackageBuilds(plan.targets, this.logger);
|
|
39
|
+
await runPackageBuilds(plan.targets, this.logger, this.options);
|
|
40
40
|
await runPublishHook({ status: 'afterBuild', plan });
|
|
41
41
|
await formatPublishOutputs(plan.targets, this.options.format);
|
|
42
42
|
await runPublishHook({ status: 'beforePublish', plan });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PublishTarget } from '#auklet/publish/types';
|
|
2
2
|
import type { AukletLogger } from '#auklet/logger';
|
|
3
|
+
import type { PublishOptions } from '#auklet/publish/types';
|
|
3
4
|
export declare function validateBuildScript(targets: Array<PublishTarget>): void;
|
|
4
|
-
export declare function runPackageBuilds(targets: Array<PublishTarget>, logger: AukletLogger): Promise<void>;
|
|
5
|
+
export declare function runPackageBuilds(targets: Array<PublishTarget>, logger: AukletLogger, options?: Pick<PublishOptions, 'token'>): Promise<void>;
|
|
@@ -8,9 +8,13 @@ export function validateBuildScript(targets) {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export async function runPackageBuilds(targets, logger) {
|
|
11
|
+
export async function runPackageBuilds(targets, logger, options = {}) {
|
|
12
12
|
for (const target of targets) {
|
|
13
13
|
logger.step('build ', logger.package(target.packageName));
|
|
14
|
+
if (options.token) {
|
|
15
|
+
await runPnpmBuild(target.packageRoot, { token: options.token });
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
14
18
|
await runPnpmBuild(target.packageRoot);
|
|
15
19
|
}
|
|
16
20
|
}
|
|
@@ -7,6 +7,7 @@ export declare class PublishPreflight {
|
|
|
7
7
|
constructor(options: PublishOptions, logger: AukletLogger);
|
|
8
8
|
run(plan: PublishPlan): Promise<void>;
|
|
9
9
|
verifyBeforeBuild(plan: PublishPlan): Promise<void>;
|
|
10
|
+
private verifyNpmrcAuthEnv;
|
|
10
11
|
private verifyTokenConfig;
|
|
11
12
|
private verifyAuthentication;
|
|
12
13
|
private verifyPnpmPublishDryRun;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PnpmPublishApi } from '#auklet/publish/api/pnpmPublishApi';
|
|
2
2
|
import { hasPublishedPackageVersion, NpmPackageVersionExistsError, runPnpmWhoami, } from '#auklet/publish/api/pnpmApi';
|
|
3
|
-
import { findNpmrcFiles, findNpmrcWithAuthToken, toNpmrcRegistryKey, } from '#auklet/publish/api/npmrc';
|
|
3
|
+
import { findNpmrcFiles, findNpmrcWithAuthToken, toNpmrcRegistryKey, validateNpmrcAuthEnv, } from '#auklet/publish/api/npmrc';
|
|
4
4
|
import { getPublishRegistry } from '#auklet/publish/api/registry';
|
|
5
5
|
import { logAuthenticationError } from '#auklet/publish/runner/packagePublisher';
|
|
6
6
|
import { PublishTargetError } from '#auklet/publish/runner/publishTargetError';
|
|
@@ -16,12 +16,20 @@ export class PublishPreflight {
|
|
|
16
16
|
await this.verifyPnpmPublishDryRun(plan);
|
|
17
17
|
}
|
|
18
18
|
async verifyBeforeBuild(plan) {
|
|
19
|
+
this.verifyNpmrcAuthEnv(plan);
|
|
19
20
|
this.verifyTokenConfig(plan);
|
|
20
21
|
if (plan.dryRun)
|
|
21
22
|
return;
|
|
22
23
|
await this.verifyAuthentication(plan);
|
|
23
24
|
await this.verifyPackageVersions(plan);
|
|
24
25
|
}
|
|
26
|
+
verifyNpmrcAuthEnv(plan) {
|
|
27
|
+
for (const target of plan.targets) {
|
|
28
|
+
validateNpmrcAuthEnv(target.packageRoot, plan.root, {
|
|
29
|
+
token: this.options.token,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
verifyTokenConfig(plan) {
|
|
26
34
|
if (!this.options.token)
|
|
27
35
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AukletLogger } from '#auklet/logger';
|
|
2
2
|
import type { OwnerOptions, PublishOptions, PublishPlan } from '#auklet/publish/types';
|
|
3
|
-
type ResolvePublishTargetsOptions = Pick<PublishOptions, 'cwd' | 'filters' | 'version' | 'dryRun'>;
|
|
3
|
+
type ResolvePublishTargetsOptions = Pick<PublishOptions, 'cwd' | 'filters' | 'version' | 'dryRun' | 'token'>;
|
|
4
4
|
type ResolveOwnerTargetsOptions = Pick<OwnerOptions, 'cwd' | 'filters' | 'packages'>;
|
|
5
5
|
export declare function resolvePublishPlan(options: ResolvePublishTargetsOptions, logger?: AukletLogger): Promise<PublishPlan>;
|
|
6
6
|
export declare function resolveOwnerPackageNames(options: ResolveOwnerTargetsOptions): Promise<string[]>;
|
|
@@ -59,7 +59,9 @@ const resolveMonorepoPublishPlan = async (options, logger) => {
|
|
|
59
59
|
const root = requireWorkspaceRoot(options.cwd);
|
|
60
60
|
const rootPackageJson = readPackageJson(root);
|
|
61
61
|
const rootVersion = requirePackageVersion(root, rootPackageJson);
|
|
62
|
-
const workspacePackages = await readPnpmWorkspacePackages(root
|
|
62
|
+
const workspacePackages = await readPnpmWorkspacePackages(root, {
|
|
63
|
+
token: options.token,
|
|
64
|
+
});
|
|
63
65
|
const selectedPackages = filterWorkspacePackages(workspacePackages, options.filters);
|
|
64
66
|
const targets = selectedPackages
|
|
65
67
|
.filter((item) => {
|