auklet 0.3.2 → 0.3.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.
@@ -15,6 +15,7 @@ export declare function mergeAukletConfigOverrides(config: AukletConfig, overrid
15
15
  configureTsdown?: import("#auklet/types").ConfigureTsdown;
16
16
  tsconfig?: string;
17
17
  } | undefined;
18
+ debug?: boolean;
18
19
  source?: string;
19
20
  output?: string;
20
21
  modules?: boolean;
package/dist/cli/help.js CHANGED
@@ -1,4 +1,8 @@
1
1
  export const buildOverrideOptions = [
2
+ [
3
+ '--debug [value]',
4
+ 'Enable debug logging for package CSS build, watch, and HMR flows',
5
+ ],
2
6
  ['--source <dir>', 'Source directory'],
3
7
  ['--output <dir>', 'Output directory'],
4
8
  ['--modules [value]', 'Enable unbundled module output'],
@@ -54,6 +54,16 @@ export function parseBuildOverrideArgs(args, envContext) {
54
54
  index += 1;
55
55
  continue;
56
56
  }
57
+ if (name === '--debug') {
58
+ const value = readOptionalFlagValue(args, index, inlineValue);
59
+ config.debug =
60
+ value === undefined
61
+ ? true
62
+ : resolveCliBoolean(value, { label: name, context: envContext });
63
+ if (inlineValue === undefined && value !== undefined)
64
+ index += 1;
65
+ continue;
66
+ }
57
67
  if (name === '--output') {
58
68
  config.output = getResolvedFlagValue(args, index, inlineValue, name, envContext);
59
69
  if (inlineValue === undefined)
package/dist/config.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { AukletConfig } from '#auklet/types';
2
2
  export declare const aukletConfigFiles: string[];
3
3
  export declare function isAukletConfigFile(file: string): boolean;
4
4
  export declare const aukletDefaultOptions: {
5
+ debug: false;
5
6
  source: string;
6
7
  output: string;
7
8
  modules: false;
@@ -17,6 +18,7 @@ export declare const aukletDefaultOptions: {
17
18
  };
18
19
  };
19
20
  export declare function normalizeAukletConfig(config?: AukletConfig): {
21
+ debug: boolean;
20
22
  source: string;
21
23
  output: string;
22
24
  modules: boolean;
package/dist/config.js CHANGED
@@ -4,6 +4,7 @@ export function isAukletConfigFile(file) {
4
4
  return aukletConfigFiles.includes(file);
5
5
  }
6
6
  export const aukletDefaultOptions = {
7
+ debug: false,
7
8
  source: 'src',
8
9
  output: 'dist',
9
10
  modules: false,
@@ -40,6 +41,7 @@ const normalizeStyleShared = (shared) => {
40
41
  export function normalizeAukletConfig(config = {}) {
41
42
  const dependencies = config.styles?.dependencies ?? aukletDefaultOptions.styles.dependencies;
42
43
  return {
44
+ debug: config.debug ?? aukletDefaultOptions.debug,
43
45
  source: config.source ?? aukletDefaultOptions.source,
44
46
  output: config.output ?? aukletDefaultOptions.output,
45
47
  modules: config.modules ?? aukletDefaultOptions.modules,
@@ -29,6 +29,8 @@ export declare class StylePackageContext {
29
29
  constructor(options: StylePackageContextOptions);
30
30
  getStyleFiles(files: Array<string>): string[];
31
31
  getModuleStyleImports(): Map<string, string[]>;
32
+ invalidateModuleStyleImports(): void;
33
+ invalidateStyleContentCaches(): void;
32
34
  getModuleStyleEntryPlanner(): StyleModuleEntryPlanner;
33
35
  getStyleEntryFiles(): string[];
34
36
  isSharedStyleFile(file: string): boolean;
@@ -59,6 +59,15 @@ export class StylePackageContext {
59
59
  this.moduleStyleImports ??= this.importCollector.collect(this.sourceFiles, this.normalizedConfig);
60
60
  return this.moduleStyleImports;
61
61
  }
62
+ invalidateModuleStyleImports() {
63
+ this.moduleStyleImports = undefined;
64
+ this.moduleStyleEntryPlanner = undefined;
65
+ }
66
+ invalidateStyleContentCaches() {
67
+ this.moduleStyleEntryPlanner = undefined;
68
+ this.hasValidatedSourceRootLocalStyleImports = false;
69
+ this.hasValidatedPreservedLocalStyleImports = false;
70
+ }
62
71
  getModuleStyleEntryPlanner() {
63
72
  this.moduleStyleEntryPlanner ??= new StyleModuleEntryPlanner(this);
64
73
  return this.moduleStyleEntryPlanner;
@@ -47,6 +47,7 @@ export declare function resolveInspectCssOptions(args: Array<string>): Promise<{
47
47
  configureTsdown?: import("#auklet/types").ConfigureTsdown;
48
48
  tsconfig?: string;
49
49
  } | undefined;
50
+ debug?: boolean;
50
51
  source?: string;
51
52
  output?: string;
52
53
  modules?: boolean;
@@ -1,9 +1,13 @@
1
+ import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
1
2
  import type { ModuleStyleBuildConfig, ModuleStyleBuildContext, ModuleStyleBuildOptions } from '#auklet/types';
3
+ type ModuleStyleBuildInternalOptions = ModuleStyleBuildOptions & {
4
+ packageContext?: StylePackageContext;
5
+ };
2
6
  export declare class ModuleStyleBuilder {
3
7
  private readonly config;
4
8
  private readonly context;
5
9
  constructor(context?: ModuleStyleBuildContext, config?: ModuleStyleBuildConfig);
6
- build(options?: ModuleStyleBuildOptions): Promise<{
10
+ build(options?: ModuleStyleBuildInternalOptions): Promise<{
7
11
  packageRoot: string;
8
12
  styleFiles: string[];
9
13
  outputs: {
@@ -11,6 +15,8 @@ export declare class ModuleStyleBuilder {
11
15
  size: number;
12
16
  }[];
13
17
  }>;
18
+ createPackageContext(options?: ModuleStyleBuildOptions): StylePackageContext;
14
19
  private createBuildContext;
15
- private createPackageContext;
20
+ private createStylePackageContext;
16
21
  }
22
+ export {};
@@ -20,7 +20,8 @@ export class ModuleStyleBuilder {
20
20
  const rawConfig = options.aukletConfig ?? this.context.aukletConfig ?? {};
21
21
  const normalizedConfig = normalizeAukletConfig(rawConfig);
22
22
  const context = this.createBuildContext(normalizedConfig);
23
- const packageContext = this.createPackageContext(context, normalizedConfig);
23
+ const packageContext = options.packageContext ??
24
+ this.createStylePackageContext(context, normalizedConfig);
24
25
  packageContext.assertNoSourceRootEscapingLocalStyleImports();
25
26
  const writerOptions = {
26
27
  config: this.config,
@@ -42,6 +43,12 @@ export class ModuleStyleBuilder {
42
43
  })),
43
44
  };
44
45
  }
46
+ createPackageContext(options = {}) {
47
+ const rawConfig = options.aukletConfig ?? this.context.aukletConfig ?? {};
48
+ const normalizedConfig = normalizeAukletConfig(rawConfig);
49
+ const context = this.createBuildContext(normalizedConfig);
50
+ return this.createStylePackageContext(context, normalizedConfig);
51
+ }
45
52
  createBuildContext(config) {
46
53
  return {
47
54
  packageRoot: this.context.packageRoot,
@@ -49,7 +56,7 @@ export class ModuleStyleBuilder {
49
56
  outputDir: this.context.output ?? config.output,
50
57
  };
51
58
  }
52
- createPackageContext(context, normalizedConfig) {
59
+ createStylePackageContext(context, normalizedConfig) {
53
60
  return new StylePackageContext({
54
61
  config: this.config,
55
62
  context,
@@ -147,7 +147,7 @@ export class AukletStyleHmr {
147
147
  ? this.createTrackedVirtualStyleResults(graph, entryEntries)
148
148
  : null;
149
149
  if (isSourceGraphFile) {
150
- graph.invalidateFile(context.file);
150
+ graph.invalidateFileLoadResults(context.file);
151
151
  }
152
152
  else {
153
153
  this.invalidateTrackedVirtualPackages(graph, dependencyEntries);
@@ -155,14 +155,13 @@ export class AukletStyleHmr {
155
155
  if (this.isDuplicateUpdate(context.file)) {
156
156
  return [];
157
157
  }
158
- const updates = [
159
- ...(dependencyEntries.length
160
- ? this.createTrackedVirtualStyleUpdates(context.server, dependencyEntries, context.timestamp)
161
- : []),
162
- ...(entryEntries.length
163
- ? await this.refreshTrackedVirtualStyleUpdates(context.server, entryEntries, previousResults, context.timestamp)
164
- : []),
165
- ];
158
+ const dependencyUpdates = dependencyEntries.length
159
+ ? this.createTrackedVirtualStyleUpdates(context.server, dependencyEntries, context.timestamp)
160
+ : [];
161
+ const entryUpdates = entryEntries.length
162
+ ? await this.refreshTrackedVirtualStyleUpdates(context.server, entryEntries, previousResults, context.timestamp)
163
+ : [];
164
+ const updates = [...dependencyUpdates, ...entryUpdates];
166
165
  if (!updates.length) {
167
166
  return undefined;
168
167
  }
@@ -18,7 +18,9 @@ export declare class ModuleStyleGraph {
18
18
  createPackageStyleCode(parsed: PackageStyleId): Promise<import("#auklet/css/vite/moduleGraph/types").PackageStyleLoadResult>;
19
19
  peekPackageStyleCode(parsed: PackageStyleId): import("#auklet/css/vite/moduleGraph/types").PackageStyleLoadResult | null;
20
20
  invalidatePackage(packageName: string): void;
21
+ invalidateFileLoadResults(file: string): string | null;
21
22
  invalidateFile(file: string): string | null;
22
23
  isSourceModuleFile(file: string): boolean;
24
+ private getFilePackageName;
23
25
  private isPackageFile;
24
26
  }
@@ -66,20 +66,31 @@ export class ModuleStyleGraph {
66
66
  invalidatePackage(packageName) {
67
67
  this.requestCache.invalidatePackage(packageName);
68
68
  }
69
+ invalidateFileLoadResults(file) {
70
+ const packageName = this.getFilePackageName(file);
71
+ if (!packageName)
72
+ return null;
73
+ this.requestCache.invalidatePackageLoadResults(packageName);
74
+ return packageName;
75
+ }
69
76
  invalidateFile(file) {
77
+ const packageName = this.getFilePackageName(file);
78
+ if (!packageName)
79
+ return null;
80
+ this.invalidatePackage(packageName);
81
+ return packageName;
82
+ }
83
+ isSourceModuleFile(file) {
84
+ return SOURCE_MODULE_RE.test(normalizeFileKey(file));
85
+ }
86
+ getFilePackageName(file) {
70
87
  if (!this.isSourceGraphFile(file))
71
88
  return null;
72
89
  const normalizedFile = normalizeFileKey(file);
73
90
  const stylePackage = this.packageSource
74
91
  .getPackages()
75
92
  .find((item) => this.isPackageFile(item.packageRoot, normalizedFile));
76
- if (!stylePackage)
77
- return null;
78
- this.invalidatePackage(stylePackage.packageName);
79
- return stylePackage.packageName;
80
- }
81
- isSourceModuleFile(file) {
82
- return SOURCE_MODULE_RE.test(normalizeFileKey(file));
93
+ return stylePackage?.packageName ?? null;
83
94
  }
84
95
  isPackageFile(packageRoot, file) {
85
96
  const normalizedPackageRoot = normalizeFileKey(packageRoot);
@@ -28,6 +28,7 @@ export type ModuleStyleGraphRequestCacheOptions = {
28
28
  export declare class ModuleStyleGraphRequestCache {
29
29
  private readonly options;
30
30
  private readonly contexts;
31
+ private readonly settledContexts;
31
32
  private readonly loadResults;
32
33
  private readonly settledLoadResults;
33
34
  private readonly loadResultsByPackage;
@@ -45,6 +46,7 @@ export declare class ModuleStyleGraphRequestCache {
45
46
  configPaths: string[];
46
47
  packageContext: StylePackageContext;
47
48
  normalizedConfig: {
49
+ debug: boolean;
48
50
  source: string;
49
51
  output: string;
50
52
  modules: boolean;
@@ -79,6 +81,7 @@ export declare class ModuleStyleGraphRequestCache {
79
81
  } | null>;
80
82
  getLoadResult(parsed: PackageStyleId, create: () => Promise<LoadResultEntry>): Promise<PackageStyleLoadResult>;
81
83
  invalidatePackage(packageName: string): void;
84
+ invalidatePackageLoadResults(packageName: string): void;
82
85
  readPersistentLoadResult(parsed: PackageStyleId, context: PackageStyleContext): PackageStyleLoadResult | null;
83
86
  writePersistentLoadResult(parsed: PackageStyleId, context: PackageStyleContext, result: PackageStyleLoadResult): {
84
87
  cacheInputFiles: string[];
@@ -7,6 +7,7 @@ import { normalizeFileKey, toPosixPath } from '#auklet/utils';
7
7
  export class ModuleStyleGraphRequestCache {
8
8
  options;
9
9
  contexts = new Map();
10
+ settledContexts = new Map();
10
11
  loadResults = new Map();
11
12
  settledLoadResults = new Map();
12
13
  loadResultsByPackage = new Map();
@@ -35,6 +36,20 @@ export class ModuleStyleGraphRequestCache {
35
36
  return cachedContext;
36
37
  const context = this.createContext(parsed);
37
38
  this.contexts.set(parsed.packageName, context);
39
+ context.then((resolvedContext) => {
40
+ if (this.contexts.get(parsed.packageName) !== context)
41
+ return;
42
+ if (resolvedContext) {
43
+ this.settledContexts.set(parsed.packageName, resolvedContext);
44
+ }
45
+ else {
46
+ this.settledContexts.delete(parsed.packageName);
47
+ }
48
+ }, () => {
49
+ if (this.contexts.get(parsed.packageName) !== context)
50
+ return;
51
+ this.settledContexts.delete(parsed.packageName);
52
+ });
38
53
  return context;
39
54
  }
40
55
  getLoadResult(parsed, create) {
@@ -91,6 +106,14 @@ export class ModuleStyleGraphRequestCache {
91
106
  invalidatePackage(packageName) {
92
107
  this.bumpGraphVersion();
93
108
  this.contexts.delete(packageName);
109
+ this.settledContexts.delete(packageName);
110
+ this.invalidateLoadResults(packageName);
111
+ }
112
+ invalidatePackageLoadResults(packageName) {
113
+ this.bumpGraphVersion();
114
+ this.settledContexts
115
+ .get(packageName)
116
+ ?.packageContext.invalidateStyleContentCaches();
94
117
  this.invalidateLoadResults(packageName);
95
118
  }
96
119
  readPersistentLoadResult(parsed, context) {
@@ -150,7 +150,8 @@ export function aukletStylePlugin(options = {}) {
150
150
  reloadStyleGraph(file);
151
151
  }
152
152
  else if (graph.isStyleFile(file)) {
153
- if (hmr.hasTrackedStyleDependency(file)) {
153
+ const tracked = hmr.hasTrackedStyleDependency(file);
154
+ if (tracked) {
154
155
  await hmr.handleStyleHotUpdate({
155
156
  file,
156
157
  modules: [],
@@ -161,7 +162,7 @@ export function aukletStylePlugin(options = {}) {
161
162
  });
162
163
  }
163
164
  else {
164
- graph.invalidateFile(file);
165
+ graph.invalidateFileLoadResults(file);
165
166
  }
166
167
  }
167
168
  else if (graph.isSourceModuleFile(file)) {
@@ -11,6 +11,7 @@ export declare class ModuleStyleWatcher {
11
11
  private shouldRebuild;
12
12
  private watcher;
13
13
  private readonly lastErrorLogTimes;
14
+ private packageContext;
14
15
  constructor(context?: ModuleStyleBuildContext, config?: ModuleStyleBuildConfig, logger?: ModuleStyleWatcherLogger | null);
15
16
  watch(): Promise<void>;
16
17
  private rebuild;
@@ -18,6 +19,8 @@ export declare class ModuleStyleWatcher {
18
19
  private logError;
19
20
  private scheduleBuild;
20
21
  private shouldRebuildForFile;
22
+ private handleFileEvent;
23
+ private invalidateBuildCache;
21
24
  close(): Promise<void>;
22
25
  }
23
26
  export {};
@@ -18,6 +18,7 @@ export class ModuleStyleWatcher {
18
18
  shouldRebuild = false;
19
19
  watcher = null;
20
20
  lastErrorLogTimes = new Map();
21
+ packageContext = null;
21
22
  constructor(context = {}, config = moduleStyleBuildConfig, logger = null) {
22
23
  this.context = {
23
24
  packageRoot: process.cwd(),
@@ -42,7 +43,13 @@ export class ModuleStyleWatcher {
42
43
  try {
43
44
  try {
44
45
  const builder = new ModuleStyleBuilder(this.context, this.config);
45
- await builder.build();
46
+ this.packageContext ??= builder.createPackageContext({
47
+ aukletConfig: this.context.aukletConfig,
48
+ });
49
+ await builder.build({
50
+ aukletConfig: this.context.aukletConfig,
51
+ packageContext: this.packageContext,
52
+ });
46
53
  }
47
54
  catch (error) {
48
55
  this.logError('build', 'CSS build failed; waiting for changes.', error);
@@ -82,13 +89,8 @@ export class ModuleStyleWatcher {
82
89
  interval: 300,
83
90
  usePolling: true,
84
91
  });
85
- this.watcher.on('all', (_event, file) => {
86
- if (this.closed)
87
- return;
88
- if (isString(file) && !this.shouldRebuildForFile(file)) {
89
- return;
90
- }
91
- this.scheduleBuild();
92
+ this.watcher.on('all', (event, file) => {
93
+ this.handleFileEvent(event, file);
92
94
  });
93
95
  this.watcher.on('error', (error) => {
94
96
  if (this.closed)
@@ -123,6 +125,34 @@ export class ModuleStyleWatcher {
123
125
  return true;
124
126
  return this.config.styleExtensions.includes(path.extname(file));
125
127
  }
128
+ handleFileEvent(event, file) {
129
+ if (this.closed || !isString(file))
130
+ return;
131
+ if (!this.shouldRebuildForFile(file))
132
+ return;
133
+ this.invalidateBuildCache(event, file);
134
+ this.scheduleBuild();
135
+ }
136
+ invalidateBuildCache(event, file) {
137
+ if (isAukletConfigFile(path.basename(file))) {
138
+ this.packageContext = null;
139
+ return;
140
+ }
141
+ if (event === 'add' ||
142
+ event === 'unlink' ||
143
+ event === 'addDir' ||
144
+ event === 'unlinkDir') {
145
+ this.packageContext = null;
146
+ return;
147
+ }
148
+ if (SOURCE_MODULE_RE.test(file)) {
149
+ this.packageContext?.invalidateModuleStyleImports();
150
+ return;
151
+ }
152
+ if (this.config.styleExtensions.includes(path.extname(file))) {
153
+ this.packageContext?.invalidateStyleContentCaches();
154
+ }
155
+ }
126
156
  async close() {
127
157
  this.closed = true;
128
158
  this.shouldRebuild = false;
package/dist/types.d.ts CHANGED
@@ -15,6 +15,7 @@ export type NormalizedStyleDependencyGroup = {
15
15
  components?: string | Array<string>;
16
16
  };
17
17
  export interface NormalizedAukletConfig {
18
+ debug: boolean;
18
19
  source: string;
19
20
  output: string;
20
21
  modules: boolean;
@@ -49,6 +50,7 @@ export type PackageBuildOptions = {
49
50
  tsconfig?: string;
50
51
  };
51
52
  export interface AukletConfig {
53
+ debug?: boolean;
52
54
  source?: string;
53
55
  output?: string;
54
56
  modules?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auklet",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "author": "chentao.arthur",
6
6
  "description": "Build utilities for TypeScript packages and module CSS output.",