auklet 0.1.2 → 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.
Files changed (50) hide show
  1. package/README.md +19 -2
  2. package/dist/build/tsdown/dependencies.js +2 -2
  3. package/dist/cli/build.js +26 -16
  4. package/dist/cli/buildArgs.d.ts +2 -1
  5. package/dist/cli/buildArgs.js +30 -8
  6. package/dist/cli/buildCss.d.ts +2 -0
  7. package/dist/cli/buildCss.js +28 -21
  8. package/dist/cli/dev.js +14 -4
  9. package/dist/cli/values.d.ts +17 -0
  10. package/dist/cli/values.js +14 -0
  11. package/dist/css/core/style/dependencies.d.ts +0 -1
  12. package/dist/css/core/style/dependencies.js +0 -3
  13. package/dist/css/core/style/entries.js +2 -2
  14. package/dist/css/core/style/files.d.ts +0 -1
  15. package/dist/css/core/style/files.js +0 -3
  16. package/dist/css/core/stylePackageContext.js +3 -3
  17. package/dist/css/vite/hmr.js +2 -2
  18. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +1 -1
  19. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +2 -2
  20. package/dist/env.d.ts +22 -0
  21. package/dist/env.js +105 -0
  22. package/dist/logger.d.ts +0 -1
  23. package/dist/logger.js +0 -3
  24. package/dist/publish/api/npmrc.d.ts +4 -0
  25. package/dist/publish/api/npmrc.js +34 -0
  26. package/dist/publish/api/pnpmApi.d.ts +12 -10
  27. package/dist/publish/api/pnpmApi.js +13 -16
  28. package/dist/publish/api/pnpmPublishApi.d.ts +2 -2
  29. package/dist/publish/api/pnpmPublishApi.js +5 -3
  30. package/dist/publish/cli.d.ts +6 -2
  31. package/dist/publish/cli.js +93 -46
  32. package/dist/publish/inspect.js +20 -5
  33. package/dist/publish/inspectPack.js +6 -2
  34. package/dist/publish/inspectRegistry.d.ts +3 -2
  35. package/dist/publish/inspectRegistry.js +11 -4
  36. package/dist/publish/publishEnv.d.ts +13 -0
  37. package/dist/publish/publishEnv.js +21 -0
  38. package/dist/publish/publishRunner.d.ts +3 -2
  39. package/dist/publish/publishRunner.js +9 -7
  40. package/dist/publish/runner/packageBuilder.d.ts +2 -2
  41. package/dist/publish/runner/packageBuilder.js +7 -1
  42. package/dist/publish/runner/packagePublisher.d.ts +3 -2
  43. package/dist/publish/runner/packagePublisher.js +4 -2
  44. package/dist/publish/runner/publishPreflight.d.ts +4 -2
  45. package/dist/publish/runner/publishPreflight.js +21 -6
  46. package/dist/publish/runner/versionWriter.d.ts +1 -1
  47. package/dist/publish/targetResolver.d.ts +3 -3
  48. package/dist/publish/targetResolver.js +11 -5
  49. package/dist/publish/types.d.ts +6 -1
  50. package/package.json +1 -1
@@ -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,24 @@ 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
+ return {
83
+ ...process.env,
84
+ ...options.env,
85
+ };
86
+ };
@@ -8,31 +8,33 @@ 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(): Promise<string>;
12
- export declare function readPnpmWorkspacePackages(root: string): Promise<WorkspacePackage[]>;
13
- export declare function runPnpmBuild(packageRoot: string): Promise<void>;
11
+ export declare function ensurePnpm(options?: {
12
+ env?: Record<string, string | undefined>;
13
+ }): Promise<string>;
14
+ export declare function readPnpmWorkspacePackages(root: string, options?: {
15
+ env?: Record<string, string | undefined>;
16
+ }): Promise<WorkspacePackage[]>;
17
+ export declare function runPnpmBuild(packageRoot: string, options?: {
18
+ env?: Record<string, string | undefined>;
19
+ }): Promise<void>;
14
20
  export declare function runPnpmPublish(packageRoot: string, args: Array<string>, options?: {
15
- token?: string;
21
+ env?: Record<string, string | undefined>;
16
22
  }): Promise<void>;
17
23
  export declare function runPnpmWhoami(packageRoot: string, options?: {
18
24
  packageName?: string;
19
25
  registry?: string;
20
26
  timeout?: number;
21
- token?: string;
27
+ env?: Record<string, string | undefined>;
22
28
  }): Promise<string>;
23
29
  export declare function hasPublishedPackageVersion(packageRoot: string, packageName: string, version: string, options?: {
24
30
  registry?: string;
25
31
  timeout?: number;
26
- token?: string;
32
+ env?: Record<string, string | undefined>;
27
33
  }): Promise<boolean>;
28
34
  export declare function runPnpmOwnerAdd(packageName: string, user: string, options: {
29
35
  cwd: string;
30
36
  otp?: string;
31
37
  }): Promise<void>;
32
- export declare function createPnpmAuthEnv(token?: string): {
33
- NODE_AUTH_TOKEN: string;
34
- NPM_TOKEN: string;
35
- } | undefined;
36
38
  export declare function hasNpmAuthChallenge(result: {
37
39
  stdout?: unknown;
38
40
  stderr?: unknown;
@@ -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: options.env,
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)).map((item) => {
73
+ return (await readPnpmWorkspacePackageInfo(root, {
74
+ env: options.env,
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: options.env,
86
91
  stdio: 'inherit',
87
92
  });
88
93
  if (hasFailedPnpmResult(result)) {
@@ -93,7 +98,7 @@ export async function runPnpmPublish(packageRoot, args, options = {}) {
93
98
  const isDryRun = args.includes('--dry-run');
94
99
  const result = await runPnpm(['publish', ...args], {
95
100
  cwd: packageRoot,
96
- env: createPnpmAuthEnv(options.token),
101
+ env: options.env,
97
102
  stdio: isDryRun ? 'pipe' : 'inherit',
98
103
  });
99
104
  if (isDryRun)
@@ -111,7 +116,7 @@ export async function runPnpmWhoami(packageRoot, options = {}) {
111
116
  args.push('--registry', options.registry);
112
117
  const result = await runPnpm(args, {
113
118
  cwd: packageRoot,
114
- env: createPnpmAuthEnv(options.token),
119
+ env: options.env,
115
120
  timeout: options.timeout,
116
121
  });
117
122
  if (hasFailedPnpmResult(result)) {
@@ -130,7 +135,7 @@ export async function hasPublishedPackageVersion(packageRoot, packageName, versi
130
135
  args.push('--registry', options.registry);
131
136
  const result = await runPnpm(args, {
132
137
  cwd: packageRoot,
133
- env: createPnpmAuthEnv(options.token),
138
+ env: options.env,
134
139
  timeout: options.timeout,
135
140
  });
136
141
  if (!hasFailedPnpmResult(result)) {
@@ -154,14 +159,6 @@ export async function runPnpmOwnerAdd(packageName, user, options) {
154
159
  throw new Error(`[publish] pnpm owner add failed for ${user} -> ${packageName}.`);
155
160
  }
156
161
  }
157
- export function createPnpmAuthEnv(token) {
158
- if (!token)
159
- return undefined;
160
- return {
161
- NODE_AUTH_TOKEN: token,
162
- NPM_TOKEN: token,
163
- };
164
- }
165
162
  const isWorkspacePackage = (value) => {
166
163
  if (!isPlainObject(value)) {
167
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
- if (options.token) {
7
- await runPnpmPublish(target.packageRoot, args, { token: options.token });
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);
@@ -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: string | undefined;
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>;
@@ -1,8 +1,13 @@
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
- import { ensurePnpm } from '#auklet/publish/api/pnpmApi';
7
+ import { validateNpmrcAuthEnv } from '#auklet/publish/api/npmrc';
8
+ import { resolveCliBoolean, resolveCliValue, createDeferredCliValue, } from '#auklet/cli/values';
9
+ import { createPublishRootEnv } from '#auklet/publish/publishEnv';
10
+ import { findWorkspaceRoot } from '#auklet/workspace/root';
6
11
  const publishFlags = new Set([
7
12
  '_',
8
13
  'filter',
@@ -17,63 +22,84 @@ const publishFlags = new Set([
17
22
  ]);
18
23
  const ownerFlags = new Set(['_', 'filter', 'package', 'otp']);
19
24
  export async function runPublishCli(args) {
20
- await ensurePnpm();
21
- await new PublishRunner(resolvePublishCliOptions(args)).run();
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
+ });
22
36
  }
23
- export function resolvePublishCliOptions(args, cwd = process.cwd()) {
37
+ export function resolvePublishCliOptions(args, cwd = process.cwd(), envContext = new AukletEnvContext(cwd)) {
24
38
  const argv = parsePublishArgs(args);
25
39
  if (argv._.length) {
26
40
  throw new Error(`[publish] unknown publish argument: ${argv._.join(' ')}`);
27
41
  }
28
42
  return {
29
43
  cwd,
30
- otp: stringOption(argv.otp),
31
- filters: toArray(argv.filter),
32
- version: stringOption(argv.version),
33
- git: argv.git !== false,
34
- format: argv.format !== false,
35
- dryRun: argv['dry-run'] === true,
36
- allowDirty: argv['allow-dirty'] === true,
37
- ignoreScripts: argv['ignore-scripts'] === true,
38
- token: stringOption(argv.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'),
39
53
  };
40
54
  }
41
55
  const parsePublishArgs = (args) => {
42
56
  const cliArgs = stripLeadingArgsSeparator(args);
43
57
  validateNoPrefixedFlags(cliArgs, new Set(['--no-format', '--no-git']));
44
58
  const argv = minimist(cliArgs, {
45
- string: ['filter', 'version', 'otp', 'token'],
46
- boolean: ['dry-run', 'format', 'git', 'ignore-scripts', 'allow-dirty'],
47
- default: {
48
- git: true,
49
- format: true,
50
- },
59
+ string: [
60
+ 'filter',
61
+ 'version',
62
+ 'otp',
63
+ 'token',
64
+ 'dry-run',
65
+ 'format',
66
+ 'git',
67
+ 'ignore-scripts',
68
+ 'allow-dirty',
69
+ ],
51
70
  });
52
71
  validateFlags(argv, publishFlags);
53
72
  return argv;
54
73
  };
55
74
  export async function runOwnerCli(args) {
56
- const cliArgs = stripLeadingArgsSeparator(args);
57
- validateNoPrefixedFlags(cliArgs, new Set());
58
- const argv = minimist(cliArgs, {
59
- string: ['filter', 'package', 'otp'],
75
+ const cwd = process.cwd();
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();
60
102
  });
61
- validateFlags(argv, ownerFlags);
62
- const [subcommand, ...users] = argv._;
63
- if (subcommand !== 'add') {
64
- throw new Error('[publish] expected owner command: auk owner add <user...>');
65
- }
66
- if (!users.length) {
67
- throw new Error('[publish] owner add requires at least one user.');
68
- }
69
- await ensurePnpm();
70
- await new OwnerRunner({
71
- cwd: process.cwd(),
72
- users,
73
- filters: toArray(argv.filter),
74
- packages: toArray(argv.package),
75
- otp: stringOption(argv.otp),
76
- }).run();
77
103
  }
78
104
  const validateFlags = (argv, allowedFlags) => {
79
105
  for (const flag of Object.keys(argv)) {
@@ -91,17 +117,38 @@ const validateNoPrefixedFlags = (args, allowedFlags) => {
91
117
  const stripLeadingArgsSeparator = (args) => {
92
118
  return args.filter((arg) => arg !== '--');
93
119
  };
94
- const toArray = (value) => {
120
+ const toArray = (value, label, envContext) => {
95
121
  if (value === undefined)
96
122
  return [];
97
- return isArray(value)
98
- ? value.map(String).filter(Boolean)
99
- : [String(value)].filter(Boolean);
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));
100
127
  };
101
- const stringOption = (value) => {
128
+ const stringOption = (value, label, envContext) => {
102
129
  if (value === undefined)
103
130
  return undefined;
104
131
  if (isArray(value))
105
- return String(value.at(-1));
106
- return String(value);
132
+ return stringOption(value.at(-1), label, envContext);
133
+ return resolveCliValue(String(value), { label, context: envContext });
134
+ };
135
+ const deferredStringOption = (value, label) => {
136
+ if (value === undefined)
137
+ return undefined;
138
+ if (isArray(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 });
151
+ };
152
+ const validatePublishCliNpmrcAuthEnv = (cwd, env) => {
153
+ validateNpmrcAuthEnv(cwd, findWorkspaceRoot(cwd) ?? cwd, { env });
107
154
  };
@@ -1,18 +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 { resolvePublishTag } from '#auklet/publish/api/publishArgs';
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 { getPublishRegistry } from '#auklet/publish/api/registry';
8
+ import { resolvePublishTag } from '#auklet/publish/api/publishArgs';
7
9
  import { resolvePublishCliOptions } from '#auklet/publish/cli';
10
+ import { validateNpmrcAuthEnv } from '#auklet/publish/api/npmrc';
11
+ import { createPublishRootEnv } from '#auklet/publish/publishEnv';
8
12
  import { inspectPublishRegistry, } from '#auklet/publish/inspectRegistry';
9
13
  import { inspectPackageFiles, PackInspectReporter, } from '#auklet/publish/inspectPack';
10
14
  import { resolvePublishPlan } from '#auklet/publish/targetResolver';
11
15
  export async function runInspectPublishCli(args) {
12
- await ensurePnpm();
13
- const options = resolvePublishCliOptions(args);
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 });
22
+ });
23
+ }
24
+ async function runInspectPublish(options, root, runtime) {
25
+ const { env } = createPublishRootEnv(options, runtime);
26
+ validateNpmrcAuthEnv(options.cwd, root, { env });
27
+ await ensurePnpm({ env });
14
28
  const logger = createAukletLogger({ scope: 'inspect' });
15
- const plan = await resolvePublishPlan(options, logger);
29
+ const plan = await resolvePublishPlan(options, runtime, logger);
16
30
  const packageFileChecks = inspectPackageFiles(plan.targets);
17
31
  const packageFileCheckFailed = packageFileChecks.some((check) => check.status === 'missing');
18
32
  if (packageFileCheckFailed) {
@@ -23,6 +37,7 @@ export async function runInspectPublishCli(args) {
23
37
  spinner.start();
24
38
  const registryChecks = await inspectPublishRegistry(plan, {
25
39
  token: options.token,
40
+ runtime,
26
41
  onCheck: (info) => {
27
42
  spinner.text([
28
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?: InspectPublishRegistryOptions): Promise<PublishRegistryCheck[]>;
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 { hasPublishedPackageVersion, runPnpmWhoami, } from '#auklet/publish/api/pnpmApi';
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
- token: options.token,
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
- token: options.token,
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
- constructor(options: PublishOptions);
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 { createScopedAukletLogger } from '#auklet/logger';
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
- constructor(options) {
20
+ runtime;
21
+ constructor(options, runtime) {
21
22
  this.options = options;
22
- this.logger = createScopedAukletLogger('publish');
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);
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,4 +1,4 @@
1
- import type { PublishTarget } from '#auklet/publish/types';
2
1
  import type { AukletLogger } from '#auklet/logger';
2
+ import type { PublishTarget, PublishOptions, PublishRuntime } from '#auklet/publish/types';
3
3
  export declare function validateBuildScript(targets: Array<PublishTarget>): void;
4
- export declare function runPackageBuilds(targets: Array<PublishTarget>, logger: AukletLogger): Promise<void>;
4
+ export declare function runPackageBuilds(targets: Array<PublishTarget>, logger: AukletLogger, options: Pick<PublishOptions, 'token'>, runtime: PublishRuntime): Promise<void>;