auklet 0.0.15 → 0.0.17

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 (105) hide show
  1. package/bin/entry.cjs +4 -6
  2. package/dist/build/bundleConfig.d.ts +1 -4
  3. package/dist/build/bundleConfig.js +59 -71
  4. package/dist/build/cleanOutput.d.ts +2 -8
  5. package/dist/build/cleanOutput.js +7 -7
  6. package/dist/build/moduleConfig.d.ts +1 -3
  7. package/dist/build/moduleConfig.js +21 -40
  8. package/dist/build/runTsdown.d.ts +2 -5
  9. package/dist/build/runTsdown.js +18 -23
  10. package/dist/build/tsdown/common.d.ts +17 -28
  11. package/dist/build/tsdown/common.js +22 -25
  12. package/dist/build/tsdown/context.d.ts +16 -20
  13. package/dist/build/tsdown/context.js +41 -45
  14. package/dist/build/tsdown/define.d.ts +2 -7
  15. package/dist/build/tsdown/define.js +13 -22
  16. package/dist/build/tsdown/dependencies.d.ts +4 -12
  17. package/dist/build/tsdown/dependencies.js +47 -51
  18. package/dist/build/tsdown/entries.d.ts +4 -6
  19. package/dist/build/tsdown/entries.js +39 -38
  20. package/dist/build/tsdown/parseModuleId.d.ts +4 -4
  21. package/dist/build/tsdown/parseModuleId.js +92 -77
  22. package/dist/build/tsdown/types.d.ts +24 -31
  23. package/dist/build/tsdownConfig.d.ts +2 -6
  24. package/dist/build/tsdownConfig.js +1 -4
  25. package/dist/config.d.ts +37 -37
  26. package/dist/config.js +38 -41
  27. package/dist/configLoader.d.ts +2 -7
  28. package/dist/configLoader.js +59 -64
  29. package/dist/css/config.js +8 -8
  30. package/dist/css/constants.d.ts +6 -6
  31. package/dist/css/core/resolvers/packageImports.d.ts +1 -5
  32. package/dist/css/core/resolvers/packageImports.js +35 -40
  33. package/dist/css/core/resolvers/relative.d.ts +1 -4
  34. package/dist/css/core/resolvers/relative.js +3 -2
  35. package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
  36. package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
  37. package/dist/css/core/style/dependencies.d.ts +6 -16
  38. package/dist/css/core/style/dependencies.js +35 -38
  39. package/dist/css/core/style/entries.d.ts +35 -58
  40. package/dist/css/core/style/entries.js +20 -31
  41. package/dist/css/core/style/files.d.ts +2 -7
  42. package/dist/css/core/style/files.js +11 -11
  43. package/dist/css/core/style/specifier.d.ts +5 -8
  44. package/dist/css/core/style/specifier.js +21 -18
  45. package/dist/css/core/styleImports/collector.d.ts +17 -25
  46. package/dist/css/core/styleImports/collector.js +162 -201
  47. package/dist/css/core/styleImports/sourceReference.d.ts +8 -16
  48. package/dist/css/core/styleImports/sourceReference.js +153 -173
  49. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  50. package/dist/css/core/styleModuleEntryPlanner.js +44 -61
  51. package/dist/css/core/stylePackageContext.d.ts +16 -20
  52. package/dist/css/core/stylePackageContext.js +33 -49
  53. package/dist/css/core/styleProcessor.d.ts +12 -12
  54. package/dist/css/core/styleProcessor.js +105 -104
  55. package/dist/css/core/workspaceStyleResolver.d.ts +9 -15
  56. package/dist/css/core/workspaceStyleResolver.js +62 -72
  57. package/dist/css/production/builder.d.ts +9 -16
  58. package/dist/css/production/builder.js +51 -57
  59. package/dist/css/production/format/componentWriter.d.ts +8 -8
  60. package/dist/css/production/format/componentWriter.js +45 -66
  61. package/dist/css/production/format/entryWriter.d.ts +5 -9
  62. package/dist/css/production/format/entryWriter.js +36 -49
  63. package/dist/css/production/format/externalWriter.d.ts +6 -6
  64. package/dist/css/production/format/externalWriter.js +21 -33
  65. package/dist/css/production/format/moduleWriter.d.ts +5 -5
  66. package/dist/css/production/format/moduleWriter.js +23 -26
  67. package/dist/css/production/format/shared.d.ts +8 -15
  68. package/dist/css/production/format/shared.js +5 -6
  69. package/dist/css/production/format/sourceWriter.d.ts +3 -3
  70. package/dist/css/production/format/sourceWriter.js +11 -11
  71. package/dist/css/production/format/themeWriter.d.ts +8 -14
  72. package/dist/css/production/format/themeWriter.js +56 -71
  73. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  74. package/dist/css/production/moduleOutputWriter.js +56 -65
  75. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  76. package/dist/css/production/packageEntryWriter.js +42 -45
  77. package/dist/css/vite/hmr.d.ts +11 -11
  78. package/dist/css/vite/hmr.js +93 -109
  79. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  80. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  81. package/dist/css/vite/moduleGraph/graph.d.ts +20 -24
  82. package/dist/css/vite/moduleGraph/graph.js +49 -64
  83. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  84. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  85. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +7 -0
  86. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +72 -0
  87. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +11 -0
  88. package/dist/css/vite/moduleGraph/packageSource/types.js +0 -0
  89. package/dist/css/vite/moduleGraph/requestCache.d.ts +47 -61
  90. package/dist/css/vite/moduleGraph/requestCache.js +51 -84
  91. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  92. package/dist/css/vite/moduleGraph/styleCodeFactory.js +182 -263
  93. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  94. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  95. package/dist/css/vite/moduleGraph/types.d.ts +11 -13
  96. package/dist/css/vite/vitePlugin.d.ts +16 -20
  97. package/dist/css/vite/vitePlugin.js +111 -110
  98. package/dist/css/watch/watcher.d.ts +15 -21
  99. package/dist/css/watch/watcher.js +83 -80
  100. package/dist/index.d.ts +3 -25
  101. package/dist/index.js +2 -9
  102. package/dist/types.d.ts +59 -62
  103. package/dist/utils.d.ts +3 -7
  104. package/dist/utils.js +50 -47
  105. package/package.json +31 -32
@@ -2,72 +2,57 @@ import path from 'node:path';
2
2
  import { aukletConfigFile } from '#auklet/config';
3
3
  import { loadAukletConfig } from '#auklet/configLoader';
4
4
  import { moduleStyleBuildConfig } from '#auklet/css/config';
5
- import { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
6
- import { StyleCodeFactory } from '#auklet/css/vite/moduleGraph/styleCodeFactory';
7
5
  import { parsePackageStyleId } from '#auklet/css/vite/moduleGraph/styleId';
8
- import { SOURCE_COMPONENT_MODULE_RE } from '#auklet/css/constants';
9
- import { normalizeFileKey, toWatchPath } from '#auklet/utils';
10
- // package style graph 的对外门面,负责 workspace 发现、watch 边界和请求分发。
6
+ import { StyleCodeFactory } from '#auklet/css/vite/moduleGraph/styleCodeFactory';
7
+ import { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
8
+ import { createMonorepoPackageSource } from '#auklet/css/vite/moduleGraph/packageSource/monorepo';
9
+ import { normalizeFileKey } from '#auklet/utils';
10
+ // package style graph 的对外门面,负责 package source、watch 边界和请求分发。
11
11
  export class ModuleStyleGraph {
12
- config;
13
- workspaceRoot;
14
- packagesDir;
15
- styleCodeFactory;
16
- loadAukletConfig;
17
- constructor(options) {
18
- this.config = options.config ?? moduleStyleBuildConfig;
19
- this.workspaceRoot = normalizeFileKey(options.workspaceRoot);
20
- this.packagesDir = options.packagesDir ?? 'packages';
21
- this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
22
- this.styleCodeFactory = new StyleCodeFactory(this.config);
23
- }
24
- parsePackageStyleId(id) {
25
- return parsePackageStyleId(id, this.getWorkspacePackageNames());
26
- }
27
- isWorkspaceSourceGraphFile(file) {
28
- const normalizedFile = normalizeFileKey(file);
29
- const packagesRoot = normalizeFileKey(
30
- path.join(this.workspaceRoot, this.packagesDir),
31
- );
32
- if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
33
- return false;
12
+ config;
13
+ packageSource;
14
+ styleCodeFactory;
15
+ loadAukletConfig;
16
+ constructor(options) {
17
+ this.config = options.config ?? moduleStyleBuildConfig;
18
+ const mode = options.mode ?? 'monorepo';
19
+ if (mode === 'package') {
20
+ throw new Error('[auklet:css] package mode is not supported yet.');
21
+ }
22
+ this.packageSource = createMonorepoPackageSource({
23
+ workspaceRoot: normalizeFileKey(options.workspaceRoot),
24
+ packagesDir: options.packagesDir ?? 'packages',
25
+ styleExtensions: this.config.styleExtensions,
26
+ });
27
+ this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
28
+ this.styleCodeFactory = new StyleCodeFactory(this.config);
29
+ }
30
+ parsePackageStyleId(id) {
31
+ return parsePackageStyleId(id, this.getPackageNames());
32
+ }
33
+ isSourceGraphFile(file) {
34
+ return this.packageSource.isSourceGraphFile(file);
35
+ }
36
+ isStyleConfigFile(file) {
37
+ return normalizeFileKey(file).endsWith(aukletConfigFile);
38
+ }
39
+ isStyleFile(file) {
40
+ return this.config.styleExtensions.includes(path.extname(file));
41
+ }
42
+ getPackageNames() {
43
+ return this.packageSource.getPackageNames();
44
+ }
45
+ getWatchRoots() {
46
+ return this.packageSource.getWatchRoots();
47
+ }
48
+ createPackageStyleCode(parsed) {
49
+ return this.styleCodeFactory.createPackageStyleCode(parsed, this.createRequestCache());
34
50
  }
35
- if (normalizedFile.endsWith(aukletConfigFile)) return true;
36
- if (SOURCE_COMPONENT_MODULE_RE.test(normalizedFile)) {
37
- return true;
51
+ createRequestCache() {
52
+ return new ModuleStyleGraphRequestCache({
53
+ packageSource: this.packageSource,
54
+ config: this.config,
55
+ loadAukletConfig: this.loadAukletConfig,
56
+ });
38
57
  }
39
- return this.config.styleExtensions.some((extension) =>
40
- normalizedFile.endsWith(extension),
41
- );
42
- }
43
- isStyleConfigFile(file) {
44
- return normalizeFileKey(file).endsWith(aukletConfigFile);
45
- }
46
- isStyleFile(file) {
47
- return this.config.styleExtensions.includes(path.extname(file));
48
- }
49
- getWorkspacePackageNames() {
50
- return this.createRequestCache().getWorkspacePackageNames();
51
- }
52
- getWatchRoots() {
53
- const packagesRoot = path.join(this.workspaceRoot, this.packagesDir);
54
- return [
55
- toWatchPath(packagesRoot, '*', 'src'),
56
- toWatchPath(packagesRoot, '*', aukletConfigFile),
57
- ];
58
- }
59
- createPackageStyleCode(parsed) {
60
- return this.styleCodeFactory.createPackageStyleCode(
61
- parsed,
62
- this.createRequestCache(),
63
- );
64
- }
65
- createRequestCache() {
66
- return new ModuleStyleGraphRequestCache({
67
- workspaceRoot: this.workspaceRoot,
68
- packagesDir: this.packagesDir,
69
- config: this.config,
70
- loadAukletConfig: this.loadAukletConfig,
71
- });
72
- }
73
58
  }
@@ -1,7 +1,5 @@
1
1
  import type { PackageStyleLoadResult } from '#auklet/css/vite/moduleGraph/types';
2
- export declare function mergeLoadResults(
3
- ...results: Array<PackageStyleLoadResult>
4
- ): {
5
- code: string;
6
- watchFiles: string[];
2
+ export declare function mergeLoadResults(...results: Array<PackageStyleLoadResult>): {
3
+ code: string;
4
+ watchFiles: string[];
7
5
  };
@@ -1,12 +1,10 @@
1
1
  // 合并递归 style graph 加载结果,同时保留 CSS 顺序并去重 watch files。
2
2
  export function mergeLoadResults(...results) {
3
- return {
4
- code: results
5
- .map((result) => result.code)
6
- .filter((code) => code.trim())
7
- .join('\n'),
8
- watchFiles: Array.from(
9
- new Set(results.flatMap((result) => result.watchFiles)),
10
- ),
11
- };
3
+ return {
4
+ code: results
5
+ .map((result) => result.code)
6
+ .filter((code) => code.trim())
7
+ .join('\n'),
8
+ watchFiles: Array.from(new Set(results.flatMap((result) => result.watchFiles))),
9
+ };
12
10
  }
@@ -0,0 +1,7 @@
1
+ import type { StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
2
+ export type MonorepoPackageSourceOptions = {
3
+ workspaceRoot: string;
4
+ packagesDir: string;
5
+ styleExtensions: Array<string>;
6
+ };
7
+ export declare function createMonorepoPackageSource(options: MonorepoPackageSourceOptions): StylePackageSource;
@@ -0,0 +1,72 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { aukletConfigFile } from '#auklet/config';
4
+ import { SOURCE_COMPONENT_MODULE_RE } from '#auklet/css/constants';
5
+ import { normalizeFileKey, toWatchPath } from '#auklet/utils';
6
+ export function createMonorepoPackageSource(options) {
7
+ return new MonorepoPackageSource(options);
8
+ }
9
+ class MonorepoPackageSource {
10
+ options;
11
+ packages;
12
+ packageNames;
13
+ workspaceRoot;
14
+ constructor(options) {
15
+ this.options = options;
16
+ this.workspaceRoot = normalizeFileKey(options.workspaceRoot);
17
+ }
18
+ getPackages() {
19
+ if (this.packages)
20
+ return this.packages;
21
+ const packagesRoot = path.join(this.workspaceRoot, this.options.packagesDir);
22
+ if (!fs.existsSync(packagesRoot)) {
23
+ this.packages = [];
24
+ return this.packages;
25
+ }
26
+ this.packages = fs
27
+ .readdirSync(packagesRoot, { withFileTypes: true })
28
+ .filter((entry) => entry.isDirectory())
29
+ .flatMap((entry) => {
30
+ const packageRoot = path.join(packagesRoot, entry.name);
31
+ const packageJsonPath = path.join(packageRoot, 'package.json');
32
+ if (!fs.existsSync(packageJsonPath))
33
+ return [];
34
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
35
+ if (!pkg.name)
36
+ return [];
37
+ return [
38
+ {
39
+ packageName: pkg.name,
40
+ packageRoot,
41
+ },
42
+ ];
43
+ });
44
+ return this.packages;
45
+ }
46
+ getPackageNames() {
47
+ this.packageNames ??= this.getPackages().map((item) => item.packageName);
48
+ return this.packageNames;
49
+ }
50
+ isKnownPackageName(packageName) {
51
+ return this.getPackageNames().includes(packageName);
52
+ }
53
+ isSourceGraphFile(file) {
54
+ const normalizedFile = normalizeFileKey(file);
55
+ const packagesRoot = normalizeFileKey(path.join(this.workspaceRoot, this.options.packagesDir));
56
+ if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
57
+ return false;
58
+ }
59
+ if (normalizedFile.endsWith(aukletConfigFile))
60
+ return true;
61
+ if (SOURCE_COMPONENT_MODULE_RE.test(normalizedFile))
62
+ return true;
63
+ return this.options.styleExtensions.some((extension) => normalizedFile.endsWith(extension));
64
+ }
65
+ getWatchRoots() {
66
+ const packagesRoot = path.join(this.workspaceRoot, this.options.packagesDir);
67
+ return [
68
+ toWatchPath(packagesRoot, '*', 'src'),
69
+ toWatchPath(packagesRoot, '*', aukletConfigFile),
70
+ ];
71
+ }
72
+ }
@@ -0,0 +1,11 @@
1
+ export type StylePackageInfo = {
2
+ packageName: string;
3
+ packageRoot: string;
4
+ };
5
+ export interface StylePackageSource {
6
+ getPackages(): Array<StylePackageInfo>;
7
+ getPackageNames(): Array<string>;
8
+ isKnownPackageName(packageName: string): boolean;
9
+ isSourceGraphFile(file: string): boolean;
10
+ getWatchRoots(): Array<string>;
11
+ }
@@ -1,69 +1,58 @@
1
1
  import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
2
- import type {
3
- ModuleStyleBuildConfig,
4
- NormalizedAukletConfig,
5
- ResolvedModuleStyleBuildContext,
6
- } from '#auklet/types';
2
+ import type { ModuleStyleBuildConfig, NormalizedAukletConfig, ResolvedModuleStyleBuildContext } from '#auklet/types';
7
3
  import type { StyleProcessor } from '#auklet/css/core/styleProcessor';
8
4
  import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
9
- import type {
10
- LoadAukletConfig,
11
- PackageStyleId,
12
- } from '#auklet/css/vite/moduleGraph/types';
5
+ import type { StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
6
+ import type { LoadAukletConfig, PackageStyleId } from '#auklet/css/vite/moduleGraph/types';
13
7
  export type PackageStyleContext = {
14
- normalizedConfig: NormalizedAukletConfig;
15
- context: ResolvedModuleStyleBuildContext;
16
- packageContext: StylePackageContext;
17
- packageName: string;
18
- configPath: string;
19
- resolver: WorkspaceStyleResolver;
20
- sourceRoot: string;
21
- styleProcessor: StyleProcessor;
8
+ normalizedConfig: NormalizedAukletConfig;
9
+ context: ResolvedModuleStyleBuildContext;
10
+ packageContext: StylePackageContext;
11
+ packageName: string;
12
+ configPath: string;
13
+ resolver: WorkspaceStyleResolver;
14
+ sourceRoot: string;
15
+ styleProcessor: StyleProcessor;
22
16
  };
23
17
  export type ModuleStyleGraphRequestCacheOptions = {
24
- workspaceRoot: string;
25
- packagesDir: string;
26
- config: ModuleStyleBuildConfig;
27
- loadAukletConfig?: LoadAukletConfig;
18
+ packageSource: StylePackageSource;
19
+ config: ModuleStyleBuildConfig;
20
+ loadAukletConfig?: LoadAukletConfig;
28
21
  };
29
22
  export declare class ModuleStyleGraphRequestCache {
30
- private readonly options;
31
- private workspacePackages?;
32
- private workspacePackageNames?;
33
- private readonly contexts;
34
- private readonly loadAukletConfig;
35
- constructor(options: ModuleStyleGraphRequestCacheOptions);
36
- getWorkspacePackageNames(): string[];
37
- isWorkspacePackageName(packageName: string): boolean;
38
- getContext(parsed: PackageStyleId): Promise<
39
- | PackageStyleContext
40
- | {
23
+ private readonly options;
24
+ private readonly contexts;
25
+ private readonly loadAukletConfig;
26
+ constructor(options: ModuleStyleGraphRequestCacheOptions);
27
+ getPackageNames(): string[];
28
+ isKnownPackageName(packageName: string): boolean;
29
+ getContext(parsed: PackageStyleId): Promise<PackageStyleContext | {
41
30
  normalizedConfig: {
42
- source: string;
43
- output: string;
44
- modules: boolean;
45
- build: {
46
- formats: Array<import('#auklet/types').PackageBuildFormat>;
47
- target: import('#auklet/types').PackageBuildTarget;
48
- platform: import('#auklet/types').PackageBuildPlatform;
49
- banner?: string;
50
- externals?: Array<string>;
51
- alias?: Record<string, string>;
52
- mainFields?: Array<string>;
53
- globals?: Record<string, string>;
54
- configureTsdown?: import('#auklet/types').ConfigureTsdown;
55
- tsconfig?: string;
56
- };
57
- styles: {
58
- themes: {};
59
- dependencies: {
60
- [k: string]: {
61
- entry: string | string[] | undefined;
62
- themes: Record<string, string> | undefined;
63
- components: string | string[] | undefined;
64
- };
31
+ source: string;
32
+ output: string;
33
+ modules: boolean;
34
+ build: {
35
+ formats: Array<import("#auklet/types").PackageBuildFormat>;
36
+ target: import("#auklet/types").PackageBuildTarget;
37
+ platform: import("#auklet/types").PackageBuildPlatform;
38
+ banner?: string;
39
+ externals?: Array<string>;
40
+ alias?: Record<string, string>;
41
+ mainFields?: Array<string>;
42
+ globals?: Record<string, string>;
43
+ configureTsdown?: import("#auklet/types").ConfigureTsdown;
44
+ tsconfig?: string;
45
+ };
46
+ styles: {
47
+ themes: {};
48
+ dependencies: {
49
+ [k: string]: {
50
+ entry: string | string[] | undefined;
51
+ themes: Record<string, string> | undefined;
52
+ components: string | string[] | undefined;
53
+ };
54
+ };
65
55
  };
66
- };
67
56
  };
68
57
  context: ResolvedModuleStyleBuildContext;
69
58
  packageContext: StylePackageContext;
@@ -72,9 +61,6 @@ export declare class ModuleStyleGraphRequestCache {
72
61
  resolver: WorkspaceStyleResolver;
73
62
  sourceRoot: string;
74
63
  styleProcessor: StyleProcessor;
75
- }
76
- | null
77
- >;
78
- private createContext;
79
- private getWorkspacePackages;
64
+ } | null>;
65
+ private createContext;
80
66
  }
@@ -1,92 +1,59 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
3
2
  import { aukletConfigFile, normalizeAukletConfig } from '#auklet/config';
4
3
  import { loadAukletConfig } from '#auklet/configLoader';
5
4
  import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
6
5
  export class ModuleStyleGraphRequestCache {
7
- options;
8
- workspacePackages;
9
- workspacePackageNames;
10
- contexts = new Map();
11
- loadAukletConfig;
12
- constructor(options) {
13
- this.options = options;
14
- this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
15
- }
16
- getWorkspacePackageNames() {
17
- this.workspacePackageNames ??= this.getWorkspacePackages().map(
18
- (item) => item.packageName,
19
- );
20
- return this.workspacePackageNames;
21
- }
22
- isWorkspacePackageName(packageName) {
23
- return this.getWorkspacePackageNames().includes(packageName);
24
- }
25
- async getContext(parsed) {
26
- const cachedContext = this.contexts.get(parsed.packageName);
27
- if (cachedContext) return cachedContext;
28
- const context = this.createContext(parsed);
29
- this.contexts.set(parsed.packageName, context);
30
- return context;
31
- }
32
- async createContext(parsed) {
33
- const workspacePackage = this.getWorkspacePackages().find(
34
- (item) => item.packageName === parsed.packageName,
35
- );
36
- if (!workspacePackage) return null;
37
- const packageRoot = workspacePackage.packageRoot;
38
- if (!fs.existsSync(packageRoot)) return null;
39
- const rawConfig = await this.loadAukletConfig(packageRoot, {
40
- cacheBust: true,
41
- });
42
- const normalizedConfig = normalizeAukletConfig(rawConfig);
43
- const context = {
44
- packageRoot,
45
- sourceDir: normalizedConfig.source,
46
- outputDir: normalizedConfig.output,
47
- };
48
- const packageContext = new StylePackageContext({
49
- config: this.options.config,
50
- context,
51
- normalizedConfig,
52
- });
53
- return {
54
- normalizedConfig,
55
- context,
56
- packageContext,
57
- packageName: parsed.packageName,
58
- configPath: path.join(packageRoot, aukletConfigFile),
59
- resolver: packageContext.resolver,
60
- sourceRoot: packageContext.sourceRoot,
61
- styleProcessor: packageContext.styleProcessor,
62
- };
63
- }
64
- getWorkspacePackages() {
65
- if (this.workspacePackages) return this.workspacePackages;
66
- const packagesRoot = path.join(
67
- this.options.workspaceRoot,
68
- this.options.packagesDir,
69
- );
70
- if (!fs.existsSync(packagesRoot)) {
71
- this.workspacePackages = [];
72
- return this.workspacePackages;
6
+ options;
7
+ contexts = new Map();
8
+ loadAukletConfig;
9
+ constructor(options) {
10
+ this.options = options;
11
+ this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
73
12
  }
74
- this.workspacePackages = fs
75
- .readdirSync(packagesRoot, { withFileTypes: true })
76
- .filter((entry) => entry.isDirectory())
77
- .flatMap((entry) => {
78
- const packageRoot = path.join(packagesRoot, entry.name);
79
- const packageJsonPath = path.join(packageRoot, 'package.json');
80
- if (!fs.existsSync(packageJsonPath)) return [];
81
- const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
82
- if (!pkg.name) return [];
83
- return [
84
- {
85
- packageName: pkg.name,
13
+ getPackageNames() {
14
+ return this.options.packageSource.getPackageNames();
15
+ }
16
+ isKnownPackageName(packageName) {
17
+ return this.options.packageSource.isKnownPackageName(packageName);
18
+ }
19
+ async getContext(parsed) {
20
+ const cachedContext = this.contexts.get(parsed.packageName);
21
+ if (cachedContext)
22
+ return cachedContext;
23
+ const context = this.createContext(parsed);
24
+ this.contexts.set(parsed.packageName, context);
25
+ return context;
26
+ }
27
+ async createContext(parsed) {
28
+ const stylePackage = this.options.packageSource
29
+ .getPackages()
30
+ .find((item) => item.packageName === parsed.packageName);
31
+ if (!stylePackage)
32
+ return null;
33
+ const packageRoot = stylePackage.packageRoot;
34
+ const rawConfig = await this.loadAukletConfig(packageRoot, {
35
+ cacheBust: true,
36
+ });
37
+ const normalizedConfig = normalizeAukletConfig(rawConfig);
38
+ const context = {
86
39
  packageRoot,
87
- },
88
- ];
89
- });
90
- return this.workspacePackages;
91
- }
40
+ sourceDir: normalizedConfig.source,
41
+ outputDir: normalizedConfig.output,
42
+ };
43
+ const packageContext = new StylePackageContext({
44
+ config: this.options.config,
45
+ context,
46
+ normalizedConfig,
47
+ });
48
+ return {
49
+ normalizedConfig,
50
+ context,
51
+ packageContext,
52
+ packageName: parsed.packageName,
53
+ configPath: path.join(packageRoot, aukletConfigFile),
54
+ resolver: packageContext.resolver,
55
+ sourceRoot: packageContext.sourceRoot,
56
+ styleProcessor: packageContext.styleProcessor,
57
+ };
58
+ }
92
59
  }
@@ -2,22 +2,19 @@ import type { ModuleStyleBuildConfig } from '#auklet/types';
2
2
  import type { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
3
3
  import type { PackageStyleId } from '#auklet/css/vite/moduleGraph/types';
4
4
  export declare class StyleCodeFactory {
5
- private readonly config;
6
- constructor(config: ModuleStyleBuildConfig);
7
- createPackageStyleCode(
8
- parsed: PackageStyleId,
9
- cache: ModuleStyleGraphRequestCache,
10
- ): Promise<{
11
- code: string;
12
- watchFiles: string[];
13
- }>;
14
- private createStyleCode;
15
- private createDependencyStyleCode;
16
- private createExternalStyleCode;
17
- private createThemeStyleCode;
18
- private createModuleStyleCode;
19
- private createSourceModuleStyleCode;
20
- private toDevModuleImportSpecifier;
21
- private toDevExternalStyleSpecifier;
22
- private parsePackageStyleIdInRequest;
5
+ private readonly config;
6
+ constructor(config: ModuleStyleBuildConfig);
7
+ createPackageStyleCode(parsed: PackageStyleId, cache: ModuleStyleGraphRequestCache): Promise<{
8
+ code: string;
9
+ watchFiles: string[];
10
+ }>;
11
+ private createStyleCode;
12
+ private createDependencyStyleCode;
13
+ private createExternalStyleCode;
14
+ private createThemeStyleCode;
15
+ private createModuleStyleCode;
16
+ private createSourceModuleStyleCode;
17
+ private toDevModuleImportSpecifier;
18
+ private toDevExternalStyleSpecifier;
19
+ private parsePackageStyleIdInRequest;
23
20
  }