auklet 0.0.16 → 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 (95) hide show
  1. package/dist/build/bundleConfig.d.ts +1 -4
  2. package/dist/build/bundleConfig.js +59 -71
  3. package/dist/build/cleanOutput.d.ts +2 -8
  4. package/dist/build/cleanOutput.js +7 -7
  5. package/dist/build/moduleConfig.d.ts +1 -3
  6. package/dist/build/moduleConfig.js +21 -40
  7. package/dist/build/runTsdown.d.ts +2 -5
  8. package/dist/build/runTsdown.js +18 -23
  9. package/dist/build/tsdown/common.d.ts +17 -28
  10. package/dist/build/tsdown/common.js +22 -25
  11. package/dist/build/tsdown/context.d.ts +16 -20
  12. package/dist/build/tsdown/context.js +41 -45
  13. package/dist/build/tsdown/define.d.ts +2 -7
  14. package/dist/build/tsdown/define.js +13 -22
  15. package/dist/build/tsdown/dependencies.d.ts +4 -12
  16. package/dist/build/tsdown/dependencies.js +47 -51
  17. package/dist/build/tsdown/entries.d.ts +4 -6
  18. package/dist/build/tsdown/entries.js +39 -38
  19. package/dist/build/tsdown/parseModuleId.d.ts +4 -4
  20. package/dist/build/tsdown/parseModuleId.js +92 -77
  21. package/dist/build/tsdown/types.d.ts +24 -31
  22. package/dist/build/tsdownConfig.js +1 -4
  23. package/dist/config.d.ts +37 -37
  24. package/dist/config.js +38 -41
  25. package/dist/configLoader.d.ts +2 -7
  26. package/dist/configLoader.js +59 -64
  27. package/dist/css/config.js +8 -8
  28. package/dist/css/constants.d.ts +6 -6
  29. package/dist/css/core/resolvers/packageImports.d.ts +1 -5
  30. package/dist/css/core/resolvers/packageImports.js +35 -40
  31. package/dist/css/core/resolvers/relative.d.ts +1 -4
  32. package/dist/css/core/resolvers/relative.js +3 -2
  33. package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
  34. package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
  35. package/dist/css/core/style/dependencies.d.ts +6 -16
  36. package/dist/css/core/style/dependencies.js +35 -38
  37. package/dist/css/core/style/entries.d.ts +35 -58
  38. package/dist/css/core/style/entries.js +20 -31
  39. package/dist/css/core/style/files.d.ts +2 -7
  40. package/dist/css/core/style/files.js +11 -11
  41. package/dist/css/core/style/specifier.d.ts +5 -8
  42. package/dist/css/core/style/specifier.js +21 -18
  43. package/dist/css/core/styleImports/collector.d.ts +17 -25
  44. package/dist/css/core/styleImports/collector.js +162 -201
  45. package/dist/css/core/styleImports/sourceReference.d.ts +8 -16
  46. package/dist/css/core/styleImports/sourceReference.js +153 -173
  47. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  48. package/dist/css/core/styleModuleEntryPlanner.js +44 -61
  49. package/dist/css/core/stylePackageContext.d.ts +16 -20
  50. package/dist/css/core/stylePackageContext.js +33 -49
  51. package/dist/css/core/styleProcessor.js +105 -104
  52. package/dist/css/core/workspaceStyleResolver.d.ts +9 -15
  53. package/dist/css/core/workspaceStyleResolver.js +62 -72
  54. package/dist/css/production/builder.d.ts +9 -16
  55. package/dist/css/production/builder.js +51 -57
  56. package/dist/css/production/format/componentWriter.js +45 -66
  57. package/dist/css/production/format/entryWriter.js +36 -49
  58. package/dist/css/production/format/externalWriter.js +21 -33
  59. package/dist/css/production/format/moduleWriter.js +23 -26
  60. package/dist/css/production/format/shared.d.ts +8 -15
  61. package/dist/css/production/format/shared.js +5 -6
  62. package/dist/css/production/format/sourceWriter.js +11 -11
  63. package/dist/css/production/format/themeWriter.js +56 -71
  64. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  65. package/dist/css/production/moduleOutputWriter.js +56 -65
  66. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  67. package/dist/css/production/packageEntryWriter.js +42 -45
  68. package/dist/css/vite/hmr.d.ts +11 -11
  69. package/dist/css/vite/hmr.js +93 -109
  70. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  71. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  72. package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
  73. package/dist/css/vite/moduleGraph/graph.js +46 -49
  74. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  75. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  76. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +4 -6
  77. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +59 -64
  78. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
  79. package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
  80. package/dist/css/vite/moduleGraph/requestCache.js +53 -51
  81. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  82. package/dist/css/vite/moduleGraph/styleCodeFactory.js +182 -263
  83. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  84. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  85. package/dist/css/vite/moduleGraph/types.d.ts +11 -14
  86. package/dist/css/vite/vitePlugin.d.ts +16 -20
  87. package/dist/css/vite/vitePlugin.js +110 -109
  88. package/dist/css/watch/watcher.d.ts +15 -21
  89. package/dist/css/watch/watcher.js +83 -80
  90. package/dist/index.d.ts +3 -25
  91. package/dist/index.js +2 -9
  92. package/dist/types.d.ts +59 -62
  93. package/dist/utils.d.ts +3 -7
  94. package/dist/utils.js +50 -47
  95. package/package.json +31 -33
@@ -1,193 +1,173 @@
1
1
  import ts from 'typescript';
2
2
  export function collectModuleStyleSourceReferences(file, code) {
3
- const imports = [];
4
- const importBindings = new Map();
5
- const localDeclarations = new Set();
6
- const sourceFile = ts.createSourceFile(
7
- file,
8
- code,
9
- ts.ScriptTarget.Latest,
10
- false,
11
- file.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
12
- );
13
- sourceFile.forEachChild((node) => {
14
- collectLocalDeclarationNames(node, localDeclarations);
15
- if (ts.isImportDeclaration(node)) {
16
- collectImportBindings(node, importBindings);
17
- }
18
- });
19
- sourceFile.forEachChild((node) => {
20
- if (ts.isImportDeclaration(node)) {
21
- if (!ts.isStringLiteral(node.moduleSpecifier)) {
22
- return;
23
- }
24
- imports.push({
25
- importPath: node.moduleSpecifier.text,
26
- importClause: node.importClause,
27
- });
28
- return;
29
- }
30
- if (ts.isExportDeclaration(node)) {
31
- collectExportDeclaration(
32
- file,
33
- node,
34
- imports,
35
- importBindings,
36
- localDeclarations,
37
- );
38
- }
39
- });
40
- return imports;
3
+ const imports = [];
4
+ const importBindings = new Map();
5
+ const localDeclarations = new Set();
6
+ const sourceFile = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, false, file.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
7
+ sourceFile.forEachChild((node) => {
8
+ collectLocalDeclarationNames(node, localDeclarations);
9
+ if (ts.isImportDeclaration(node)) {
10
+ collectImportBindings(node, importBindings);
11
+ }
12
+ });
13
+ sourceFile.forEachChild((node) => {
14
+ if (ts.isImportDeclaration(node)) {
15
+ if (!ts.isStringLiteral(node.moduleSpecifier)) {
16
+ return;
17
+ }
18
+ imports.push({
19
+ importPath: node.moduleSpecifier.text,
20
+ importClause: node.importClause,
21
+ });
22
+ return;
23
+ }
24
+ if (ts.isExportDeclaration(node)) {
25
+ collectExportDeclaration(file, node, imports, importBindings, localDeclarations);
26
+ }
27
+ });
28
+ return imports;
41
29
  }
42
30
  export function isTypeOnlySourceReference(item) {
43
- return isTypeOnlyImportClause(item.importClause) || item.isTypeOnly;
31
+ return isTypeOnlyImportClause(item.importClause) || item.isTypeOnly;
44
32
  }
45
33
  export function getSourceReferenceImportedNames(file, item) {
46
- if (item.importedNames) {
47
- if (item.isTypeOnly) return [];
48
- if (item.hasNamespaceImport) {
49
- throw createNamespaceImportError(file, item.importPath);
50
- }
51
- return item.importedNames;
52
- }
53
- const importClause = item.importClause;
54
- if (!importClause || isTypeOnlyImportClause(importClause)) {
55
- return [];
56
- }
57
- const names = [];
58
- if (importClause.name) {
59
- names.push(importClause.name.text);
60
- }
61
- const namedBindings = importClause.namedBindings;
62
- if (!namedBindings) {
34
+ if (item.importedNames) {
35
+ if (item.isTypeOnly)
36
+ return [];
37
+ if (item.hasNamespaceImport) {
38
+ throw createNamespaceImportError(file, item.importPath);
39
+ }
40
+ return item.importedNames;
41
+ }
42
+ const importClause = item.importClause;
43
+ if (!importClause || isTypeOnlyImportClause(importClause)) {
44
+ return [];
45
+ }
46
+ const names = [];
47
+ if (importClause.name) {
48
+ names.push(importClause.name.text);
49
+ }
50
+ const namedBindings = importClause.namedBindings;
51
+ if (!namedBindings) {
52
+ return names;
53
+ }
54
+ if (ts.isNamespaceImport(namedBindings)) {
55
+ throw createNamespaceImportError(file, item.importPath);
56
+ }
57
+ for (const element of namedBindings.elements) {
58
+ if (element.isTypeOnly)
59
+ continue;
60
+ names.push((element.propertyName ?? element.name).text);
61
+ }
63
62
  return names;
64
- }
65
- if (ts.isNamespaceImport(namedBindings)) {
66
- throw createNamespaceImportError(file, item.importPath);
67
- }
68
- for (const element of namedBindings.elements) {
69
- if (element.isTypeOnly) continue;
70
- names.push((element.propertyName ?? element.name).text);
71
- }
72
- return names;
73
63
  }
74
64
  const collectLocalDeclarationNames = (node, localDeclarations) => {
75
- if (
76
- (ts.isFunctionDeclaration(node) ||
77
- ts.isClassDeclaration(node) ||
78
- ts.isInterfaceDeclaration(node) ||
79
- ts.isTypeAliasDeclaration(node) ||
80
- ts.isEnumDeclaration(node)) &&
81
- node.name
82
- ) {
83
- localDeclarations.add(node.name.text);
84
- return;
85
- }
86
- if (!ts.isVariableStatement(node)) return;
87
- for (const declaration of node.declarationList.declarations) {
88
- if (ts.isIdentifier(declaration.name)) {
89
- localDeclarations.add(declaration.name.text);
90
- }
91
- }
65
+ if ((ts.isFunctionDeclaration(node) ||
66
+ ts.isClassDeclaration(node) ||
67
+ ts.isInterfaceDeclaration(node) ||
68
+ ts.isTypeAliasDeclaration(node) ||
69
+ ts.isEnumDeclaration(node)) &&
70
+ node.name) {
71
+ localDeclarations.add(node.name.text);
72
+ return;
73
+ }
74
+ if (!ts.isVariableStatement(node))
75
+ return;
76
+ for (const declaration of node.declarationList.declarations) {
77
+ if (ts.isIdentifier(declaration.name)) {
78
+ localDeclarations.add(declaration.name.text);
79
+ }
80
+ }
92
81
  };
93
82
  const collectImportBindings = (node, importBindings) => {
94
- if (!ts.isStringLiteral(node.moduleSpecifier) || !node.importClause) {
95
- return;
96
- }
97
- const importPath = node.moduleSpecifier.text;
98
- const isTypeOnly = isTypeOnlyImportClause(node.importClause);
99
- if (node.importClause.name) {
100
- const importedName = node.importClause.name.text;
101
- importBindings.set(importedName, {
102
- importPath,
103
- importedName,
104
- isTypeOnly,
105
- hasNamespaceImport: false,
106
- });
107
- }
108
- const namedBindings = node.importClause.namedBindings;
109
- if (!namedBindings) return;
110
- if (ts.isNamespaceImport(namedBindings)) {
111
- importBindings.set(namedBindings.name.text, {
112
- importPath,
113
- importedName: namedBindings.name.text,
114
- isTypeOnly,
115
- hasNamespaceImport: true,
116
- });
117
- return;
118
- }
119
- for (const element of namedBindings.elements) {
120
- const importedName = (element.propertyName ?? element.name).text;
121
- importBindings.set(element.name.text, {
122
- importPath,
123
- importedName,
124
- isTypeOnly: isTypeOnly || element.isTypeOnly,
125
- hasNamespaceImport: false,
126
- });
127
- }
83
+ if (!ts.isStringLiteral(node.moduleSpecifier) || !node.importClause) {
84
+ return;
85
+ }
86
+ const importPath = node.moduleSpecifier.text;
87
+ const isTypeOnly = isTypeOnlyImportClause(node.importClause);
88
+ if (node.importClause.name) {
89
+ const importedName = node.importClause.name.text;
90
+ importBindings.set(importedName, {
91
+ importPath,
92
+ importedName,
93
+ isTypeOnly,
94
+ hasNamespaceImport: false,
95
+ });
96
+ }
97
+ const namedBindings = node.importClause.namedBindings;
98
+ if (!namedBindings)
99
+ return;
100
+ if (ts.isNamespaceImport(namedBindings)) {
101
+ importBindings.set(namedBindings.name.text, {
102
+ importPath,
103
+ importedName: namedBindings.name.text,
104
+ isTypeOnly,
105
+ hasNamespaceImport: true,
106
+ });
107
+ return;
108
+ }
109
+ for (const element of namedBindings.elements) {
110
+ const importedName = (element.propertyName ?? element.name).text;
111
+ importBindings.set(element.name.text, {
112
+ importPath,
113
+ importedName,
114
+ isTypeOnly: isTypeOnly || element.isTypeOnly,
115
+ hasNamespaceImport: false,
116
+ });
117
+ }
128
118
  };
129
- const collectExportDeclaration = (
130
- file,
131
- node,
132
- imports,
133
- importBindings,
134
- localDeclarations,
135
- ) => {
136
- if (node.moduleSpecifier) {
137
- if (!ts.isStringLiteral(node.moduleSpecifier)) return;
119
+ const collectExportDeclaration = (file, node, imports, importBindings, localDeclarations) => {
120
+ if (node.moduleSpecifier) {
121
+ if (!ts.isStringLiteral(node.moduleSpecifier))
122
+ return;
123
+ if (!node.exportClause || !ts.isNamedExports(node.exportClause)) {
124
+ throw new Error(`[auklet:css] Export-all declarations are not supported for CSS auto import: ${node.moduleSpecifier.text}\n` +
125
+ `Use named exports instead, for example: export { Component } from '${node.moduleSpecifier.text}'.\n` +
126
+ `File: ${file}`);
127
+ }
128
+ imports.push({
129
+ importPath: node.moduleSpecifier.text,
130
+ importedNames: getExportedNames(node),
131
+ isTypeOnly: node.isTypeOnly,
132
+ });
133
+ return;
134
+ }
138
135
  if (!node.exportClause || !ts.isNamedExports(node.exportClause)) {
139
- throw new Error(
140
- `[auklet:css] Export-all declarations are not supported for CSS auto import: ${node.moduleSpecifier.text}\n` +
141
- `Use named exports instead, for example: export { Component } from '${node.moduleSpecifier.text}'.\n` +
142
- `File: ${file}`,
143
- );
144
- }
145
- imports.push({
146
- importPath: node.moduleSpecifier.text,
147
- importedNames: getExportedNames(node),
148
- isTypeOnly: node.isTypeOnly,
149
- });
150
- return;
151
- }
152
- if (!node.exportClause || !ts.isNamedExports(node.exportClause)) {
153
- return;
154
- }
155
- for (const element of node.exportClause.elements) {
156
- if (node.isTypeOnly || element.isTypeOnly) continue;
157
- const localName = (element.propertyName ?? element.name).text;
158
- const binding = importBindings.get(localName);
159
- if (binding) {
160
- imports.push({
161
- importPath: binding.importPath,
162
- importedNames: [binding.importedName],
163
- isTypeOnly: binding.isTypeOnly,
164
- hasNamespaceImport: binding.hasNamespaceImport,
165
- });
166
- continue;
167
- }
168
- if (!localDeclarations.has(localName)) {
169
- throw new Error(
170
- `[auklet:css] Unable to resolve exported symbol "${localName}" for CSS auto import.\n` +
171
- `File: ${file}`,
172
- );
173
- }
174
- }
136
+ return;
137
+ }
138
+ for (const element of node.exportClause.elements) {
139
+ if (node.isTypeOnly || element.isTypeOnly)
140
+ continue;
141
+ const localName = (element.propertyName ?? element.name).text;
142
+ const binding = importBindings.get(localName);
143
+ if (binding) {
144
+ imports.push({
145
+ importPath: binding.importPath,
146
+ importedNames: [binding.importedName],
147
+ isTypeOnly: binding.isTypeOnly,
148
+ hasNamespaceImport: binding.hasNamespaceImport,
149
+ });
150
+ continue;
151
+ }
152
+ if (!localDeclarations.has(localName)) {
153
+ throw new Error(`[auklet:css] Unable to resolve exported symbol "${localName}" for CSS auto import.\n` +
154
+ `File: ${file}`);
155
+ }
156
+ }
175
157
  };
176
158
  const getExportedNames = (node) => {
177
- if (!node.exportClause || !ts.isNamedExports(node.exportClause)) {
178
- return [];
179
- }
180
- return node.exportClause.elements
181
- .filter((element) => !element.isTypeOnly)
182
- .map((element) => (element.propertyName ?? element.name).text);
159
+ if (!node.exportClause || !ts.isNamedExports(node.exportClause)) {
160
+ return [];
161
+ }
162
+ return node.exportClause.elements
163
+ .filter((element) => !element.isTypeOnly)
164
+ .map((element) => (element.propertyName ?? element.name).text);
183
165
  };
184
166
  const isTypeOnlyImportClause = (importClause) => {
185
- return importClause?.phaseModifier === ts.SyntaxKind.TypeKeyword;
167
+ return importClause?.phaseModifier === ts.SyntaxKind.TypeKeyword;
186
168
  };
187
169
  const createNamespaceImportError = (file, importPath) => {
188
- return new Error(
189
- `Namespace import is not supported for CSS auto import: ${importPath}\n` +
190
- `Use named imports instead, for example: import { Component } from '${importPath}'.\n` +
191
- `File: ${file}`,
192
- );
170
+ return new Error(`Namespace import is not supported for CSS auto import: ${importPath}\n` +
171
+ `Use named imports instead, for example: import { Component } from '${importPath}'.\n` +
172
+ `File: ${file}`);
193
173
  };
@@ -1,29 +1,26 @@
1
1
  import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
2
2
  export type ModuleStyleEntryPlan = {
3
- sourceDir: string;
4
- moduleStyleImports: Array<string>;
5
- ownStyleFiles: Array<string>;
3
+ sourceDir: string;
4
+ moduleStyleImports: Array<string>;
5
+ ownStyleFiles: Array<string>;
6
6
  };
7
7
  export declare class StyleModuleEntryPlanner {
8
- private readonly packageContext;
9
- private readonly styleFilesByDir;
10
- private readonly importedStyleFiles;
11
- constructor(packageContext: StylePackageContext);
12
- createEntries(moduleStyleImports: Map<string, Array<string>>): {
13
- sourceDir: string;
14
- moduleStyleImports: string[];
15
- ownStyleFiles: string[];
16
- }[];
17
- createEntry(
18
- sourceDir: string,
19
- moduleStyleImports: Map<string, Array<string>>,
20
- ): {
21
- sourceDir: string;
22
- moduleStyleImports: string[];
23
- ownStyleFiles: string[];
24
- };
25
- private getSourceDirs;
26
- private getSourceModuleDirs;
27
- private getOwnStyleDirs;
28
- private getOwnStyleFiles;
8
+ private readonly packageContext;
9
+ private readonly styleFilesByDir;
10
+ private readonly importedStyleFiles;
11
+ constructor(packageContext: StylePackageContext);
12
+ createEntries(moduleStyleImports: Map<string, Array<string>>): {
13
+ sourceDir: string;
14
+ moduleStyleImports: string[];
15
+ ownStyleFiles: string[];
16
+ }[];
17
+ createEntry(sourceDir: string, moduleStyleImports: Map<string, Array<string>>): {
18
+ sourceDir: string;
19
+ moduleStyleImports: string[];
20
+ ownStyleFiles: string[];
21
+ };
22
+ private getSourceDirs;
23
+ private getSourceModuleDirs;
24
+ private getOwnStyleDirs;
25
+ private getOwnStyleFiles;
29
26
  }
@@ -3,65 +3,48 @@ import { SOURCE_COMPONENT_MODULE_RE } from '#auklet/css/constants';
3
3
  import { groupStyleFilesByDir } from '#auklet/css/core/style/files';
4
4
  import { getSourceModuleDir, toPosixPath } from '#auklet/utils';
5
5
  export class StyleModuleEntryPlanner {
6
- packageContext;
7
- styleFilesByDir;
8
- importedStyleFiles;
9
- constructor(packageContext) {
10
- this.packageContext = packageContext;
11
- this.styleFilesByDir = groupStyleFilesByDir(
12
- this.packageContext.sourceRoot,
13
- this.packageContext.styleFiles,
14
- );
15
- this.importedStyleFiles =
16
- this.packageContext.styleProcessor.collectImportedStyleFiles(
17
- this.packageContext.styleFiles,
18
- );
19
- }
20
- createEntries(moduleStyleImports) {
21
- return this.getSourceDirs(moduleStyleImports).map((sourceDir) =>
22
- this.createEntry(sourceDir, moduleStyleImports),
23
- );
24
- }
25
- createEntry(sourceDir, moduleStyleImports) {
26
- return {
27
- sourceDir,
28
- moduleStyleImports: moduleStyleImports.get(sourceDir) ?? [],
29
- ownStyleFiles: this.getOwnStyleFiles(sourceDir),
30
- };
31
- }
32
- getSourceDirs(moduleStyleImports) {
33
- return Array.from(
34
- new Set([
35
- ...this.getSourceModuleDirs(),
36
- ...this.getOwnStyleDirs(),
37
- ...moduleStyleImports.keys(),
38
- ]),
39
- ).filter((sourceDir) => sourceDir !== '.');
40
- }
41
- getSourceModuleDirs() {
42
- return this.packageContext.sourceFiles
43
- .filter((sourceFile) => SOURCE_COMPONENT_MODULE_RE.test(sourceFile))
44
- .map((sourceFile) => {
45
- return getSourceModuleDir(
46
- path.relative(this.packageContext.sourceRoot, sourceFile),
47
- );
48
- })
49
- .filter((sourceModuleDir) => {
50
- return toPosixPath(sourceModuleDir).split('/').length === 2;
51
- });
52
- }
53
- getOwnStyleDirs() {
54
- return Array.from(this.styleFilesByDir.entries())
55
- .filter(([, dirStyleFiles]) =>
56
- dirStyleFiles.some(
57
- (styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)),
58
- ),
59
- )
60
- .map(([sourceDir]) => sourceDir);
61
- }
62
- getOwnStyleFiles(sourceDir) {
63
- return (this.styleFilesByDir.get(sourceDir) ?? []).filter(
64
- (styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)),
65
- );
66
- }
6
+ packageContext;
7
+ styleFilesByDir;
8
+ importedStyleFiles;
9
+ constructor(packageContext) {
10
+ this.packageContext = packageContext;
11
+ this.styleFilesByDir = groupStyleFilesByDir(this.packageContext.sourceRoot, this.packageContext.styleFiles);
12
+ this.importedStyleFiles =
13
+ this.packageContext.styleProcessor.collectImportedStyleFiles(this.packageContext.styleFiles);
14
+ }
15
+ createEntries(moduleStyleImports) {
16
+ return this.getSourceDirs(moduleStyleImports).map((sourceDir) => this.createEntry(sourceDir, moduleStyleImports));
17
+ }
18
+ createEntry(sourceDir, moduleStyleImports) {
19
+ return {
20
+ sourceDir,
21
+ moduleStyleImports: moduleStyleImports.get(sourceDir) ?? [],
22
+ ownStyleFiles: this.getOwnStyleFiles(sourceDir),
23
+ };
24
+ }
25
+ getSourceDirs(moduleStyleImports) {
26
+ return Array.from(new Set([
27
+ ...this.getSourceModuleDirs(),
28
+ ...this.getOwnStyleDirs(),
29
+ ...moduleStyleImports.keys(),
30
+ ])).filter((sourceDir) => sourceDir !== '.');
31
+ }
32
+ getSourceModuleDirs() {
33
+ return this.packageContext.sourceFiles
34
+ .filter((sourceFile) => SOURCE_COMPONENT_MODULE_RE.test(sourceFile))
35
+ .map((sourceFile) => {
36
+ return getSourceModuleDir(path.relative(this.packageContext.sourceRoot, sourceFile));
37
+ })
38
+ .filter((sourceModuleDir) => {
39
+ return toPosixPath(sourceModuleDir).split('/').length === 2;
40
+ });
41
+ }
42
+ getOwnStyleDirs() {
43
+ return Array.from(this.styleFilesByDir.entries())
44
+ .filter(([, dirStyleFiles]) => dirStyleFiles.some((styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile))))
45
+ .map(([sourceDir]) => sourceDir);
46
+ }
47
+ getOwnStyleFiles(sourceDir) {
48
+ return (this.styleFilesByDir.get(sourceDir) ?? []).filter((styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)));
49
+ }
67
50
  }
@@ -1,27 +1,23 @@
1
1
  import { ModuleStyleImportCollector } from '#auklet/css/core/styleImports/collector';
2
2
  import { StyleProcessor } from '#auklet/css/core/styleProcessor';
3
3
  import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
4
- import type {
5
- ModuleStyleBuildConfig,
6
- NormalizedAukletConfig,
7
- ResolvedModuleStyleBuildContext,
8
- } from '#auklet/types';
4
+ import type { ModuleStyleBuildConfig, NormalizedAukletConfig, ResolvedModuleStyleBuildContext } from '#auklet/types';
9
5
  export type StylePackageContextOptions = {
10
- config: ModuleStyleBuildConfig;
11
- context: ResolvedModuleStyleBuildContext;
12
- normalizedConfig: NormalizedAukletConfig;
6
+ config: ModuleStyleBuildConfig;
7
+ context: ResolvedModuleStyleBuildContext;
8
+ normalizedConfig: NormalizedAukletConfig;
13
9
  };
14
10
  export declare class StylePackageContext {
15
- private readonly options;
16
- readonly normalizedConfig: NormalizedAukletConfig;
17
- readonly sourceRoot: string;
18
- readonly resolver: WorkspaceStyleResolver;
19
- readonly styleProcessor: StyleProcessor;
20
- readonly importCollector: ModuleStyleImportCollector;
21
- readonly sourceFiles: Array<string>;
22
- readonly themeFiles: Map<string, string>;
23
- readonly themeNames: Array<string>;
24
- readonly styleFiles: Array<string>;
25
- constructor(options: StylePackageContextOptions);
26
- getStyleFiles(files: Array<string>): string[];
11
+ private readonly options;
12
+ readonly normalizedConfig: NormalizedAukletConfig;
13
+ readonly sourceRoot: string;
14
+ readonly resolver: WorkspaceStyleResolver;
15
+ readonly styleProcessor: StyleProcessor;
16
+ readonly importCollector: ModuleStyleImportCollector;
17
+ readonly sourceFiles: Array<string>;
18
+ readonly themeFiles: Map<string, string>;
19
+ readonly themeNames: Array<string>;
20
+ readonly styleFiles: Array<string>;
21
+ constructor(options: StylePackageContextOptions);
22
+ getStyleFiles(files: Array<string>): string[];
27
23
  }
@@ -3,55 +3,39 @@ 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 {
7
- createStyleFileKey,
8
- createStyleFileKeySet,
9
- } from '#auklet/css/core/style/files';
10
- import {
11
- getThemeNames,
12
- resolveThemeStyleFiles,
13
- } from '#auklet/css/core/style/dependencies';
6
+ import { createStyleFileKey, createStyleFileKeySet, } from '#auklet/css/core/style/files';
7
+ import { getThemeNames, resolveThemeStyleFiles, } from '#auklet/css/core/style/dependencies';
14
8
  import { fileWalker } from '#auklet/utils';
15
9
  export class StylePackageContext {
16
- options;
17
- normalizedConfig;
18
- sourceRoot;
19
- resolver;
20
- styleProcessor;
21
- importCollector;
22
- sourceFiles;
23
- themeFiles;
24
- themeNames;
25
- styleFiles;
26
- constructor(options) {
27
- this.options = options;
28
- const { config, context, normalizedConfig } = this.options;
29
- this.normalizedConfig = normalizedConfig;
30
- this.sourceRoot = path.join(context.packageRoot, context.sourceDir);
31
- this.resolver = new WorkspaceStyleResolver(config, context);
32
- this.styleProcessor = new StyleProcessor(config, this.resolver);
33
- this.importCollector = new ModuleStyleImportCollector(
34
- this.sourceRoot,
35
- context.packageRoot,
36
- this.resolver,
37
- config.styleExtensions,
38
- );
39
- this.sourceFiles = fs.existsSync(this.sourceRoot)
40
- ? fileWalker(this.sourceRoot)
41
- : [];
42
- this.themeFiles = resolveThemeStyleFiles(
43
- normalizedConfig,
44
- context.packageRoot,
45
- );
46
- this.themeNames = getThemeNames(normalizedConfig);
47
- this.styleFiles = this.getStyleFiles(this.sourceFiles);
48
- }
49
- getStyleFiles(files) {
50
- const themeFileKeys = createStyleFileKeySet(this.themeFiles.values());
51
- return files
52
- .filter((file) =>
53
- this.options.config.styleExtensions.includes(path.extname(file)),
54
- )
55
- .filter((styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)));
56
- }
10
+ options;
11
+ normalizedConfig;
12
+ sourceRoot;
13
+ resolver;
14
+ styleProcessor;
15
+ importCollector;
16
+ sourceFiles;
17
+ themeFiles;
18
+ themeNames;
19
+ styleFiles;
20
+ constructor(options) {
21
+ this.options = options;
22
+ const { config, context, normalizedConfig } = this.options;
23
+ this.normalizedConfig = normalizedConfig;
24
+ this.sourceRoot = path.join(context.packageRoot, context.sourceDir);
25
+ this.resolver = new WorkspaceStyleResolver(config, context);
26
+ this.styleProcessor = new StyleProcessor(config, this.resolver);
27
+ this.importCollector = new ModuleStyleImportCollector(this.sourceRoot, context.packageRoot, this.resolver, config.styleExtensions);
28
+ this.sourceFiles = fs.existsSync(this.sourceRoot)
29
+ ? fileWalker(this.sourceRoot)
30
+ : [];
31
+ this.themeFiles = resolveThemeStyleFiles(normalizedConfig, context.packageRoot);
32
+ this.themeNames = getThemeNames(normalizedConfig);
33
+ this.styleFiles = this.getStyleFiles(this.sourceFiles);
34
+ }
35
+ getStyleFiles(files) {
36
+ const themeFileKeys = createStyleFileKeySet(this.themeFiles.values());
37
+ return files
38
+ .filter((file) => this.options.config.styleExtensions.includes(path.extname(file)))
39
+ .filter((styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)));
40
+ }
57
41
  }