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
package/README.md CHANGED
@@ -163,8 +163,25 @@ package directory. Package-local `.npmrc` files and
163
163
  `package.json#publishConfig.registry` are respected.
164
164
  `--otp` is forwarded to `pnpm publish` for npm accounts or organizations that
165
165
  require publish 2FA, and to `pnpm owner add` for owner management 2FA.
166
- `--token` sets `NODE_AUTH_TOKEN` and `NPM_TOKEN` for publish subprocesses. The
167
- token still needs npmrc auth config, for example:
166
+ Build and publish commands load `.env` and `.env.local` files by default. In
167
+ monorepos, root env files are loaded before target package env files, and local
168
+ env files override normal env files. Shell environment values keep the highest
169
+ priority:
170
+
171
+ 1. `process.env`
172
+ 2. target package `.env.local`
173
+ 3. target package `.env`
174
+ 4. root `.env.local`
175
+ 5. root `.env`
176
+
177
+ String CLI values can reference the loaded environment with `env:NAME`, for
178
+ example `auk build --source env:AUKLET_SOURCE`. Boolean CLI values also support
179
+ `env:NAME` when passed explicitly, for example
180
+ `auk publish --dry-run=env:AUKLET_DRY_RUN`.
181
+ `--token <value>` sets `NODE_AUTH_TOKEN` and `NPM_TOKEN` for publish
182
+ subprocesses. Use `--token env:NODE_AUTH_TOKEN` to read the token from the
183
+ loaded environment instead of putting the token value in the command.
184
+ The token still needs npmrc auth config, for example:
168
185
 
169
186
  ```ini
170
187
  //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
@@ -1,6 +1,6 @@
1
1
  import { parseModuleId } from 'conditional-export';
2
- import { createScopedAukletLogger } from '#auklet/logger';
3
- const logger = createScopedAukletLogger('build');
2
+ import { createAukletLogger } from '#auklet/logger';
3
+ const logger = createAukletLogger({ scope: 'build' });
4
4
  const getExternal = (names) => {
5
5
  const external = new Set();
6
6
  for (const name of names) {
package/dist/cli/build.js CHANGED
@@ -4,27 +4,37 @@ import { runTsdown } from '#auklet/build/runTsdown';
4
4
  import { loadAukletConfig } from '#auklet/configLoader';
5
5
  import { createBuildEnv, resolveBuildCliArgs } from '#auklet/cli/buildArgs';
6
6
  import { runBuildCss } from '#auklet/cli/buildCss';
7
+ import { AukletEnvContext } from '#auklet/env';
7
8
  import { createAukletLogger } from '#auklet/logger';
8
9
  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),
10
+ const envContext = new AukletEnvContext(process.cwd());
11
+ return envContext.run(async () => {
12
+ const buildArgs = resolveBuildCliArgs(args, envContext);
13
+ const config = mergeAukletConfigOverrides(options.config ?? {}, buildArgs.config);
14
+ const logger = createAukletLogger();
15
+ return logger.group('Build JavaScript', async () => {
16
+ return runTsdown(buildArgs.args, {
17
+ cwd: process.cwd(),
18
+ env: {
19
+ ...envContext.values,
20
+ ...createBuildEnv(config),
21
+ },
22
+ });
16
23
  });
17
24
  });
18
25
  }
19
26
  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,
27
+ const envContext = new AukletEnvContext(process.cwd());
28
+ return envContext.run(async () => {
29
+ const buildArgs = resolveBuildCliArgs(args, envContext);
30
+ const aukletConfig = mergeAukletConfigOverrides(await loadAukletConfig(process.cwd()), buildArgs.config);
31
+ cleanAukletOutputByConfig(process.cwd(), aukletConfig);
32
+ const jsExitCode = await runBuildJs(buildArgs.args, {
33
+ config: buildArgs.config,
34
+ });
35
+ if (jsExitCode)
36
+ return jsExitCode;
37
+ createAukletLogger().newline();
38
+ return runBuildCss([], { aukletConfig });
25
39
  });
26
- if (jsExitCode)
27
- return jsExitCode;
28
- createAukletLogger().newline();
29
- return runBuildCss([], { aukletConfig });
30
40
  }
@@ -1,5 +1,6 @@
1
+ import { AukletEnvContext } from '#auklet/env';
1
2
  import type { AukletConfig } from '#auklet/types';
2
- export declare function resolveBuildCliArgs(args: Array<string>): {
3
+ export declare function resolveBuildCliArgs(args: Array<string>, envContext?: AukletEnvContext): {
3
4
  args: string[];
4
5
  config: AukletConfig;
5
6
  };
@@ -1,30 +1,38 @@
1
1
  import { hasTsdownConfigArg } from '#auklet/build/runTsdown';
2
2
  import { aukletCliConfigOverridesEnv, encodeAukletCliConfigOverrides, } from '#auklet/build/cliOverrides';
3
+ import { resolveCliBoolean, resolveCliValue } from '#auklet/cli/values';
4
+ import { AukletEnvContext } from '#auklet/env';
3
5
  const buildFormats = new Set(['cjs', 'esm', 'iife']);
4
6
  const buildPlatforms = new Set(['node', 'neutral', 'browser']);
5
7
  const hasAukletConfig = (config) => {
6
8
  return Object.keys(config).length > 0;
7
9
  };
8
- export function resolveBuildCliArgs(args) {
10
+ export function resolveBuildCliArgs(args, envContext = new AukletEnvContext(process.cwd())) {
9
11
  const remainingArgs = [];
10
12
  const config = {};
11
13
  for (let index = 0; index < args.length; index += 1) {
12
14
  const arg = args[index];
13
15
  const [name, inlineValue] = arg.split('=', 2);
14
16
  if (name === '--source') {
15
- config.source = getFlagValue(args, index, inlineValue, name);
17
+ config.source = getResolvedFlagValue(args, index, inlineValue, name, envContext);
16
18
  if (inlineValue === undefined)
17
19
  index += 1;
18
20
  continue;
19
21
  }
20
22
  if (name === '--output') {
21
- config.output = getFlagValue(args, index, inlineValue, name);
23
+ config.output = getResolvedFlagValue(args, index, inlineValue, name, envContext);
22
24
  if (inlineValue === undefined)
23
25
  index += 1;
24
26
  continue;
25
27
  }
26
28
  if (name === '--modules') {
27
- config.modules = true;
29
+ const value = getOptionalFlagValue(args, index, inlineValue);
30
+ config.modules =
31
+ value === undefined
32
+ ? true
33
+ : resolveCliBoolean(value, { label: name, context: envContext });
34
+ if (inlineValue === undefined && value !== undefined)
35
+ index += 1;
28
36
  continue;
29
37
  }
30
38
  if (name === '--no-modules') {
@@ -34,7 +42,7 @@ export function resolveBuildCliArgs(args) {
34
42
  if (name === '--build.formats') {
35
43
  config.build = {
36
44
  ...config.build,
37
- formats: parseBuildFormats(getFlagValue(args, index, inlineValue, name)),
45
+ formats: parseBuildFormats(getResolvedFlagValue(args, index, inlineValue, name, envContext)),
38
46
  };
39
47
  if (inlineValue === undefined)
40
48
  index += 1;
@@ -43,7 +51,7 @@ export function resolveBuildCliArgs(args) {
43
51
  if (name === '--build.target') {
44
52
  config.build = {
45
53
  ...config.build,
46
- target: getFlagValue(args, index, inlineValue, name),
54
+ target: getResolvedFlagValue(args, index, inlineValue, name, envContext),
47
55
  };
48
56
  if (inlineValue === undefined)
49
57
  index += 1;
@@ -52,7 +60,7 @@ export function resolveBuildCliArgs(args) {
52
60
  if (name === '--build.platform') {
53
61
  config.build = {
54
62
  ...config.build,
55
- platform: parseBuildPlatform(getFlagValue(args, index, inlineValue, name)),
63
+ platform: parseBuildPlatform(getResolvedFlagValue(args, index, inlineValue, name, envContext)),
56
64
  };
57
65
  if (inlineValue === undefined)
58
66
  index += 1;
@@ -61,7 +69,7 @@ export function resolveBuildCliArgs(args) {
61
69
  if (name === '--build.tsconfig') {
62
70
  config.build = {
63
71
  ...config.build,
64
- tsconfig: getFlagValue(args, index, inlineValue, name),
72
+ tsconfig: getResolvedFlagValue(args, index, inlineValue, name, envContext),
65
73
  };
66
74
  if (inlineValue === undefined)
67
75
  index += 1;
@@ -91,6 +99,20 @@ const getFlagValue = (args, index, inlineValue, flag) => {
91
99
  }
92
100
  return value;
93
101
  };
102
+ const getOptionalFlagValue = (args, index, inlineValue) => {
103
+ if (inlineValue !== undefined)
104
+ return inlineValue;
105
+ const value = args[index + 1];
106
+ if (!value || value.startsWith('--'))
107
+ return undefined;
108
+ return value;
109
+ };
110
+ const getResolvedFlagValue = (args, index, inlineValue, flag, envContext) => {
111
+ return resolveCliValue(getFlagValue(args, index, inlineValue, flag), {
112
+ label: flag,
113
+ context: envContext,
114
+ });
115
+ };
94
116
  const parseBuildFormats = (value) => {
95
117
  const formats = value
96
118
  .split(',')
@@ -1,7 +1,9 @@
1
+ import { AukletEnvContext } from '#auklet/env';
1
2
  import { ModuleStyleWatcher } from '#auklet/css/watch/watcher';
2
3
  import type { AukletConfig } from '#auklet/types';
3
4
  export declare function resolveBuildCssConfig(args: Array<string>, options?: {
4
5
  aukletConfig?: AukletConfig;
6
+ envContext?: AukletEnvContext;
5
7
  }): Promise<{
6
8
  aukletConfig: AukletConfig;
7
9
  shouldWatch: boolean;
@@ -1,12 +1,13 @@
1
1
  import { createAukletLogger } from '#auklet/logger';
2
2
  import { loadAukletConfig } from '#auklet/configLoader';
3
3
  import { resolveBuildCliArgs } from '#auklet/cli/buildArgs';
4
+ import { AukletEnvContext } from '#auklet/env';
4
5
  import { ModuleStyleWatcher } from '#auklet/css/watch/watcher';
5
6
  import { ModuleStyleBuilder } from '#auklet/css/production/builder';
6
7
  import { mergeAukletConfigOverrides } from '#auklet/build/cliOverrides';
7
8
  import { logModuleStyleBuildResult } from '#auklet/css/production/buildReporter';
8
9
  export async function resolveBuildCssConfig(args, options = {}) {
9
- const buildArgs = resolveBuildCliArgs(args);
10
+ const buildArgs = resolveBuildCliArgs(args, options.envContext);
10
11
  const shouldWatch = buildArgs.args.includes('--watch') || buildArgs.args.includes('-w');
11
12
  const aukletConfig = options.aukletConfig ??
12
13
  mergeAukletConfigOverrides(await loadAukletConfig(process.cwd(), {
@@ -28,26 +29,32 @@ export async function startBuildCssWatch(aukletConfig) {
28
29
  });
29
30
  }
30
31
  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(() => { });
32
+ const envContext = new AukletEnvContext(process.cwd());
33
+ return envContext.run(async () => {
34
+ const logger = createAukletLogger();
35
+ const { aukletConfig, shouldWatch } = await resolveBuildCssConfig(args, {
36
+ ...options,
37
+ envContext,
38
+ });
39
+ if (shouldWatch) {
40
+ const watcher = await startBuildCssWatch(aukletConfig);
41
+ const close = () => {
42
+ watcher
43
+ .close()
44
+ .catch(console.error)
45
+ .finally(() => process.exit(0));
46
+ };
47
+ process.once('SIGINT', close);
48
+ process.once('SIGTERM', close);
49
+ await new Promise(() => { });
50
+ return 0;
51
+ }
52
+ const builder = new ModuleStyleBuilder({ aukletConfig });
53
+ await logger.group('Build CSS', async () => {
54
+ const timer = logger.timer();
55
+ const result = await builder.build();
56
+ logModuleStyleBuildResult(logger.child('css'), result, timer.elapsed());
57
+ });
44
58
  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
59
  });
52
- return 0;
53
60
  }
package/dist/cli/dev.js CHANGED
@@ -1,12 +1,19 @@
1
1
  import { execa } from 'execa';
2
2
  import { createTsdownArgs } from '#auklet/build/runTsdown';
3
3
  import { createBuildEnv, resolveBuildCliArgs } from '#auklet/cli/buildArgs';
4
+ import { AukletEnvContext } from '#auklet/env';
4
5
  import { resolveBuildCssConfig, startBuildCssWatch, } from '#auklet/cli/buildCss';
5
6
  export async function runDev(args) {
7
+ const envContext = new AukletEnvContext(process.cwd());
8
+ return envContext.run(async () => runDevWithEnv(args, envContext));
9
+ }
10
+ const runDevWithEnv = async (args, envContext) => {
6
11
  let closed = false;
7
12
  let jsProcess = null;
8
- const buildArgs = resolveBuildCliArgs(args);
9
- const { aukletConfig } = await resolveBuildCssConfig(['--watch', ...args]);
13
+ const buildArgs = resolveBuildCliArgs(args, envContext);
14
+ const { aukletConfig } = await resolveBuildCssConfig(['--watch', ...args], {
15
+ envContext,
16
+ });
10
17
  const cssWatcher = await startBuildCssWatch(aukletConfig);
11
18
  const close = async () => {
12
19
  if (closed)
@@ -23,7 +30,10 @@ export async function runDev(args) {
23
30
  try {
24
31
  jsProcess = execa(process.execPath, createTsdownArgs([...buildArgs.args, '--watch']), {
25
32
  cwd: process.cwd(),
26
- env: createBuildEnv(buildArgs.config),
33
+ env: {
34
+ ...envContext.values,
35
+ ...createBuildEnv(buildArgs.config),
36
+ },
27
37
  stdio: 'inherit',
28
38
  reject: false,
29
39
  });
@@ -36,4 +46,4 @@ export async function runDev(args) {
36
46
  process.off('SIGTERM', closeAndExit);
37
47
  await close();
38
48
  }
39
- }
49
+ };
@@ -0,0 +1,17 @@
1
+ import type { AukletEnvContext } from '#auklet/env';
2
+ export type CliValueOptions = {
3
+ label: string;
4
+ context: AukletEnvContext;
5
+ };
6
+ export type DeferredCliValue = {
7
+ raw: string;
8
+ resolve(context: AukletEnvContext): string | undefined;
9
+ };
10
+ export declare function createDeferredCliValue(value: string, options: {
11
+ label: string;
12
+ }): {
13
+ raw: string;
14
+ resolve(context: AukletEnvContext): string | undefined;
15
+ };
16
+ export declare function resolveCliValue(value: string | undefined, options: CliValueOptions): string | undefined;
17
+ export declare function resolveCliBoolean(value: boolean | string | undefined, options: CliValueOptions): boolean;
@@ -0,0 +1,14 @@
1
+ export function createDeferredCliValue(value, options) {
2
+ return {
3
+ raw: value,
4
+ resolve(context) {
5
+ return resolveCliValue(value, { label: options.label, context });
6
+ },
7
+ };
8
+ }
9
+ export function resolveCliValue(value, options) {
10
+ return options.context.resolveValue(value, { label: options.label });
11
+ }
12
+ export function resolveCliBoolean(value, options) {
13
+ return options.context.resolveBoolean(value, { label: options.label });
14
+ }
@@ -1,6 +1,5 @@
1
1
  import type { NormalizedAukletConfig } from '#auklet/types';
2
2
  export declare function getGlobalStyleDependencies(config: NormalizedAukletConfig): string[];
3
- export declare function getExternalStyleDependencies(config: NormalizedAukletConfig): string[];
4
3
  export declare function getThemeStyleDependencies(config: NormalizedAukletConfig, themeName: string): string[];
5
4
  export declare function getThemeNames(config: NormalizedAukletConfig): string[];
6
5
  export declare function getThemeStyleEntries(config: NormalizedAukletConfig): {
@@ -15,9 +15,6 @@ export function getGlobalStyleDependencies(config) {
15
15
  }
16
16
  return dependencies;
17
17
  }
18
- export function getExternalStyleDependencies(config) {
19
- return getGlobalStyleDependencies(config);
20
- }
21
18
  export function getThemeStyleDependencies(config, themeName) {
22
19
  const dependencies = [];
23
20
  for (const [packageName, dependency] of Object.entries(config.styles.dependencies)) {
@@ -1,4 +1,4 @@
1
- import { getExternalStyleDependencies, getGlobalStyleDependencies, getThemeNames, getThemeStyleDependencies, } from '#auklet/css/core/style/dependencies';
1
+ import { getGlobalStyleDependencies, getThemeNames, getThemeStyleDependencies, } from '#auklet/css/core/style/dependencies';
2
2
  import { StyleModuleEntryPlanner } from '#auklet/css/core/styleModuleEntryPlanner';
3
3
  const dependenciesPart = (specifiers) => ({ type: 'dependencies', specifiers });
4
4
  // 环境无关的 style entry graph。production writer 和 Vite/dev renderer 都从这里取入口语义。
@@ -21,7 +21,7 @@ export function createThemeEntryParts(config, themeName, options = {}) {
21
21
  }
22
22
  export function createExternalEntryParts(config) {
23
23
  return [
24
- dependenciesPart(getExternalStyleDependencies(config)),
24
+ dependenciesPart(getGlobalStyleDependencies(config)),
25
25
  ];
26
26
  }
27
27
  export function collectModuleStyleImports(packageContext) {
@@ -1,3 +1,2 @@
1
1
  export declare function groupStyleFilesByDir(sourceRoot: string, styleFiles: Array<string>): Map<string, string[]>;
2
2
  export declare function createStyleFileKeySet(styleFiles: Iterable<string>): Set<string>;
3
- export declare function createStyleFileKey(styleFile: string): string;
@@ -14,6 +14,3 @@ export function groupStyleFilesByDir(sourceRoot, styleFiles) {
14
14
  export function createStyleFileKeySet(styleFiles) {
15
15
  return new Set(Array.from(styleFiles, normalizeFileKey));
16
16
  }
17
- export function createStyleFileKey(styleFile) {
18
- return normalizeFileKey(styleFile);
19
- }
@@ -3,9 +3,9 @@ import path from 'node:path';
3
3
  import { ModuleStyleImportCollector } from '#auklet/css/core/styleImports/collector';
4
4
  import { StyleProcessor } from '#auklet/css/core/styleProcessor';
5
5
  import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
6
- import { createStyleFileKey, createStyleFileKeySet, } from '#auklet/css/core/style/files';
6
+ import { createStyleFileKeySet } from '#auklet/css/core/style/files';
7
7
  import { getThemeNames, resolveThemeStyleFiles, } from '#auklet/css/core/style/dependencies';
8
- import { fileWalker } from '#auklet/utils';
8
+ import { fileWalker, normalizeFileKey } from '#auklet/utils';
9
9
  export class StylePackageContext {
10
10
  options;
11
11
  normalizedConfig;
@@ -36,6 +36,6 @@ export class StylePackageContext {
36
36
  const themeFileKeys = createStyleFileKeySet(this.themeFiles.values());
37
37
  return files
38
38
  .filter((file) => this.options.config.styleExtensions.includes(path.extname(file)))
39
- .filter((styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)));
39
+ .filter((styleFile) => !themeFileKeys.has(normalizeFileKey(styleFile)));
40
40
  }
41
41
  }
@@ -1,10 +1,10 @@
1
1
  import path from 'node:path';
2
2
  import { isString } from 'aidly';
3
3
  import { normalizeFileKey } from '#auklet/utils';
4
- import { createScopedAukletLogger } from '#auklet/logger';
4
+ import { createAukletLogger } from '#auklet/logger';
5
5
  const FULL_RELOAD_SUPPRESS_MS = 100;
6
6
  const DUPLICATE_UPDATE_IGNORE_MS = 500;
7
- const logger = createScopedAukletLogger('css:vite');
7
+ const logger = createAukletLogger({ scope: 'css:vite' });
8
8
  const toBrowserVirtualPath = (id) => {
9
9
  return `/@id/${id.replace('\0', '__x00__')}`;
10
10
  };
@@ -1,4 +1,4 @@
1
- import type { WorkspacePackageInfo } from '#auklet/workspace/packages';
1
+ import { type WorkspacePackageInfo } from '#auklet/workspace/packages';
2
2
  import type { StylePackageInfo, StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
3
3
  export type MonorepoPackageSourceOptions = {
4
4
  root: string;
@@ -1,9 +1,9 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { aukletConfigFiles, isAukletConfigFile } from '#auklet/config';
4
3
  import { SOURCE_MODULE_RE } from '#auklet/css/constants';
4
+ import { aukletConfigFiles, isAukletConfigFile } from '#auklet/config';
5
5
  import { normalizeFileKey, toPosixPath, toWatchPath } from '#auklet/utils';
6
- import { readPnpmWorkspacePackageInfoSync } from '#auklet/workspace/packages';
6
+ import { readPnpmWorkspacePackageInfoSync, } from '#auklet/workspace/packages';
7
7
  export class MonorepoPackageSource {
8
8
  options;
9
9
  packages;
package/dist/env.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export declare class AukletEnvContext {
2
+ private readonly packageRoot;
3
+ private readonly root?;
4
+ private readonly env;
5
+ private readonly processEnv;
6
+ constructor(packageRoot: string, root?: string | undefined, options?: {
7
+ processEnv?: Record<string, string | undefined>;
8
+ });
9
+ get values(): Record<string, string | undefined>;
10
+ get normalizedValues(): Record<string, string | undefined> | undefined;
11
+ createPackageContext(packageRoot: string): AukletEnvContext;
12
+ resolveValue(value: string | undefined, options: {
13
+ label: string;
14
+ }): string | undefined;
15
+ resolveBoolean(value: boolean | string | undefined, options: {
16
+ label: string;
17
+ }): boolean;
18
+ run<T>(fn: () => Promise<T>): Promise<T>;
19
+ private readEnv;
20
+ private findEnvFiles;
21
+ private createProcessEnvOverrides;
22
+ }
package/dist/env.js ADDED
@@ -0,0 +1,105 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parseEnv } from 'node:util';
4
+ import { findWorkspaceRoot } from '#auklet/workspace/root';
5
+ const envFileNames = ['.env', '.env.local'];
6
+ export class AukletEnvContext {
7
+ packageRoot;
8
+ root;
9
+ env;
10
+ processEnv;
11
+ constructor(packageRoot, root, options = {}) {
12
+ this.packageRoot = packageRoot;
13
+ this.root = root;
14
+ this.processEnv = { ...(options.processEnv ?? process.env) };
15
+ this.env = this.createProcessEnvOverrides(this.readEnv());
16
+ }
17
+ get values() {
18
+ return this.env;
19
+ }
20
+ get normalizedValues() {
21
+ return Object.keys(this.values).length ? this.values : undefined;
22
+ }
23
+ createPackageContext(packageRoot) {
24
+ return new AukletEnvContext(packageRoot, this.root, {
25
+ processEnv: this.processEnv,
26
+ });
27
+ }
28
+ resolveValue(value, options) {
29
+ if (!value)
30
+ return undefined;
31
+ if (!value.startsWith('env:'))
32
+ return value;
33
+ const name = value.slice('env:'.length);
34
+ if (!name) {
35
+ throw new Error(`${options.label} env: requires an environment name.`);
36
+ }
37
+ const resolved = this.processEnv[name] ?? this.values[name];
38
+ if (!resolved) {
39
+ throw new Error(`${options.label} environment is missing: ${name}`);
40
+ }
41
+ return resolved;
42
+ }
43
+ resolveBoolean(value, options) {
44
+ if (value === undefined)
45
+ return false;
46
+ if (typeof value === 'boolean')
47
+ return value;
48
+ if (!value)
49
+ return true;
50
+ const resolved = this.resolveValue(value, options);
51
+ if (resolved === undefined || !resolved)
52
+ return true;
53
+ const normalized = resolved.toLowerCase();
54
+ if (['1', 'true', 'yes', 'on'].includes(normalized))
55
+ return true;
56
+ if (['0', 'false', 'no', 'off'].includes(normalized))
57
+ return false;
58
+ throw new Error(`${options.label} requires a boolean value.`);
59
+ }
60
+ async run(fn) {
61
+ const originalEnv = { ...process.env };
62
+ for (const [key, value] of Object.entries(this.values)) {
63
+ if (originalEnv[key] === undefined && value !== undefined) {
64
+ process.env[key] = value;
65
+ }
66
+ }
67
+ try {
68
+ return await fn();
69
+ }
70
+ finally {
71
+ process.env = originalEnv;
72
+ }
73
+ }
74
+ readEnv() {
75
+ const env = {};
76
+ for (const file of this.findEnvFiles()) {
77
+ Object.assign(env, parseEnv(fs.readFileSync(file, 'utf8')));
78
+ }
79
+ return env;
80
+ }
81
+ findEnvFiles() {
82
+ const files = [];
83
+ const packageDir = path.resolve(this.packageRoot);
84
+ const rootDir = path.resolve(this.root ?? findWorkspaceRoot(packageDir) ?? packageDir);
85
+ // Files are read in order and later files override earlier ones.
86
+ // Final priority is process.env > package .env.local > package .env >
87
+ // root .env.local > root .env.
88
+ const rootEnvFiles = envFileNames.map((fileName) => path.join(rootDir, fileName));
89
+ const packageEnvFiles = envFileNames.map((fileName) => path.join(packageDir, fileName));
90
+ for (const file of rootEnvFiles) {
91
+ if (fs.existsSync(file)) {
92
+ files.push(file);
93
+ }
94
+ }
95
+ for (const file of packageEnvFiles) {
96
+ if (!files.includes(file) && fs.existsSync(file)) {
97
+ files.push(file);
98
+ }
99
+ }
100
+ return files;
101
+ }
102
+ createProcessEnvOverrides(env) {
103
+ return Object.fromEntries(Object.entries(env).filter(([key]) => this.processEnv[key] === undefined));
104
+ }
105
+ }
package/dist/logger.d.ts CHANGED
@@ -2,4 +2,3 @@ import { Logger, type LoggerOptions } from 'briefing';
2
2
  export type AukletLogger = Logger;
3
3
  export type CreateAukletLoggerOptions = Pick<LoggerOptions, 'scope' | 'prefix' | 'colors' | 'silent' | 'verbose' | 'sink'>;
4
4
  export declare function createAukletLogger(options?: CreateAukletLoggerOptions): Logger;
5
- export declare function createScopedAukletLogger(scope: string): Logger;
package/dist/logger.js CHANGED
@@ -9,6 +9,3 @@ export function createAukletLogger(options = {}) {
9
9
  sink: options.sink,
10
10
  });
11
11
  }
12
- export function createScopedAukletLogger(scope) {
13
- return createAukletLogger({ scope });
14
- }
@@ -1,4 +1,8 @@
1
+ export type NpmrcAuthEnvOptions = {
2
+ env?: Record<string, string | undefined>;
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;