auklet 0.0.16 → 0.0.18

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/README.md +37 -1
  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.js +1 -4
  24. package/dist/config.d.ts +37 -37
  25. package/dist/config.js +38 -41
  26. package/dist/configLoader.d.ts +2 -7
  27. package/dist/configLoader.js +59 -64
  28. package/dist/css/config.js +8 -8
  29. package/dist/css/constants.d.ts +7 -7
  30. package/dist/css/constants.js +1 -1
  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 +22 -33
  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 +41 -8
  44. package/dist/css/core/style/specifier.js +107 -18
  45. package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
  46. package/dist/css/core/styleImports/autoImportRules.js +68 -0
  47. package/dist/css/core/styleImports/collector.d.ts +12 -25
  48. package/dist/css/core/styleImports/collector.js +101 -206
  49. package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
  50. package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
  51. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  52. package/dist/css/core/styleModuleEntryPlanner.js +45 -62
  53. package/dist/css/core/stylePackageContext.d.ts +16 -20
  54. package/dist/css/core/stylePackageContext.js +33 -49
  55. package/dist/css/core/styleProcessor.js +105 -104
  56. package/dist/css/core/workspaceStyleResolver.d.ts +8 -15
  57. package/dist/css/core/workspaceStyleResolver.js +34 -76
  58. package/dist/css/production/builder.d.ts +9 -16
  59. package/dist/css/production/builder.js +51 -57
  60. package/dist/css/production/format/entryWriter.js +36 -49
  61. package/dist/css/production/format/externalWriter.js +21 -33
  62. package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
  63. package/dist/css/production/format/moduleEntryWriter.js +48 -0
  64. package/dist/css/production/format/moduleWriter.js +23 -26
  65. package/dist/css/production/format/shared.d.ts +8 -15
  66. package/dist/css/production/format/shared.js +4 -9
  67. package/dist/css/production/format/sourceWriter.js +11 -11
  68. package/dist/css/production/format/themeWriter.js +56 -71
  69. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  70. package/dist/css/production/moduleOutputWriter.js +58 -67
  71. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  72. package/dist/css/production/packageEntryWriter.js +42 -45
  73. package/dist/css/vite/hmr.d.ts +11 -11
  74. package/dist/css/vite/hmr.js +93 -109
  75. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  76. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  77. package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
  78. package/dist/css/vite/moduleGraph/graph.js +51 -50
  79. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  80. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  81. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +16 -7
  82. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
  83. package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
  84. package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
  85. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
  86. package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
  87. package/dist/css/vite/moduleGraph/requestCache.js +53 -51
  88. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  89. package/dist/css/vite/moduleGraph/styleCodeFactory.js +173 -264
  90. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  91. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  92. package/dist/css/vite/moduleGraph/types.d.ts +11 -14
  93. package/dist/css/vite/vitePlugin.d.ts +16 -20
  94. package/dist/css/vite/vitePlugin.js +117 -109
  95. package/dist/css/watch/watcher.d.ts +15 -21
  96. package/dist/css/watch/watcher.js +84 -81
  97. package/dist/index.d.ts +3 -25
  98. package/dist/index.js +2 -9
  99. package/dist/types.d.ts +59 -62
  100. package/dist/utils.d.ts +3 -7
  101. package/dist/utils.js +50 -47
  102. package/package.json +31 -33
  103. package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
  104. package/dist/css/core/styleImports/sourceReference.js +0 -193
  105. package/dist/css/production/format/componentWriter.js +0 -71
@@ -1,225 +1,120 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { isArray } from 'aidly';
4
- import { SOURCE_COMPONENT_MODULE_RE } from '#auklet/css/constants';
5
- import { joinDependencySpecifier } from '#auklet/css/core/style/specifier';
6
- import {
7
- appendUniqueMapValue,
8
- getSourceModuleDir,
9
- POSIX_SEPARATOR,
10
- } from '#auklet/utils';
11
- import {
12
- collectModuleStyleSourceReferences,
13
- getSourceReferenceImportedNames,
14
- isTypeOnlySourceReference,
15
- } from '#auklet/css/core/styleImports/sourceReference';
3
+ import { SOURCE_MODULE_RE } from '#auklet/css/constants';
4
+ import { appendUniqueMapValue, getSourceModuleDir } from '#auklet/utils';
5
+ import { isTypeOnlyModuleReference, collectModuleImportReferences, getModuleReferenceImportedNames, } from '#auklet/css/core/styleImports/sourceImportExportAnalyzer';
16
6
  import { resolveRelativeSourceImport } from '#auklet/css/core/resolvers/relative';
17
7
  import { resolvePackageImportsSourceImport } from '#auklet/css/core/resolvers/packageImports';
18
8
  import { resolveTsconfigPathsSourceImport } from '#auklet/css/core/resolvers/tsconfigPaths';
19
- const GLOBSTAR_TOKEN = '**';
9
+ import { matchStyleAutoImportRules, createStyleAutoImportRules, createStyleAutoImportSpecifier, createDirectStyleAutoImportSpecifier, } from '#auklet/css/core/styleImports/autoImportRules';
20
10
  const SOURCE_EXTENSION_RE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
21
11
  const SOURCE_INDEX_RE = new RegExp(`[/\\\\]index${SOURCE_EXTENSION_RE.source}`);
22
12
  export class ModuleStyleImportCollector {
23
- srcRoot;
24
- packageRoot;
25
- resolver;
26
- styleExtensions;
27
- constructor(srcRoot, packageRoot, resolver, styleExtensions = ['.css']) {
28
- this.srcRoot = srcRoot;
29
- this.packageRoot = packageRoot;
30
- this.resolver = resolver;
31
- this.styleExtensions = styleExtensions;
32
- }
33
- collect(files, config) {
34
- const entries = new Map();
35
- const rules = this.createAutoImportRules(config);
36
- for (const file of files) {
37
- if (!SOURCE_COMPONENT_MODULE_RE.test(file)) {
38
- continue;
39
- }
40
- const sourceRelative = path.relative(this.srcRoot, file);
41
- const sourceDir = path.dirname(sourceRelative);
42
- const sourceModuleDir = getSourceModuleDir(sourceRelative);
43
- const code = fs.readFileSync(file, 'utf8');
44
- const imports = collectModuleStyleSourceReferences(file, code);
45
- for (const item of imports) {
46
- this.collectSourceImportStyle(
47
- entries,
48
- sourceDir,
49
- sourceModuleDir,
50
- item,
51
- );
52
- if (isTypeOnlySourceReference(item)) continue;
53
- const importPath = item.importPath;
54
- const ruleMatches = this.matchAutoImportRules(rules, importPath);
55
- if (!ruleMatches.length) continue;
56
- const directSpecifiers = ruleMatches.flatMap((ruleMatch) => {
57
- const specifier = this.createDirectStyleSpecifier(
58
- ruleMatch.rule,
59
- importPath,
60
- );
61
- return specifier ? [specifier] : [];
62
- });
63
- if (directSpecifiers.length) {
64
- for (const specifier of directSpecifiers) {
65
- const cssFile = this.resolver.resolveStyleDependency(specifier);
66
- if (fs.existsSync(cssFile)) {
67
- appendUniqueMapValue(entries, sourceModuleDir, specifier);
13
+ srcRoot;
14
+ packageRoot;
15
+ resolver;
16
+ styleExtensions;
17
+ constructor(srcRoot, packageRoot, resolver, styleExtensions = ['.css']) {
18
+ this.srcRoot = srcRoot;
19
+ this.packageRoot = packageRoot;
20
+ this.resolver = resolver;
21
+ this.styleExtensions = styleExtensions;
22
+ }
23
+ collect(files, config) {
24
+ const entries = new Map();
25
+ const rules = createStyleAutoImportRules(config);
26
+ for (const file of files) {
27
+ if (!SOURCE_MODULE_RE.test(file)) {
28
+ continue;
68
29
  }
69
- }
70
- continue;
71
- }
72
- for (const ruleMatch of ruleMatches) {
73
- const importedNames = getSourceReferenceImportedNames(file, item);
74
- for (const importedName of importedNames) {
75
- const specifier = this.createStyleSpecifier(
76
- ruleMatch.rule,
77
- ruleMatch.values,
78
- importedName,
79
- );
80
- const cssFile = this.resolver.resolveStyleDependency(specifier);
81
- if (!fs.existsSync(cssFile)) {
82
- continue;
30
+ const sourceRelative = path.relative(this.srcRoot, file);
31
+ const sourceDir = path.dirname(sourceRelative);
32
+ const sourceModuleDir = getSourceModuleDir(sourceRelative);
33
+ const code = fs.readFileSync(file, 'utf8');
34
+ const imports = collectModuleImportReferences(file, code);
35
+ for (const item of imports) {
36
+ this.collectSourceImportStyle(entries, sourceDir, sourceModuleDir, item);
37
+ if (isTypeOnlyModuleReference(item))
38
+ continue;
39
+ const importPath = item.importPath;
40
+ const ruleMatches = matchStyleAutoImportRules(rules, importPath);
41
+ if (!ruleMatches.length)
42
+ continue;
43
+ const directSpecifiers = ruleMatches.flatMap((ruleMatch) => {
44
+ const specifier = createDirectStyleAutoImportSpecifier(ruleMatch.rule, importPath);
45
+ return specifier ? [specifier] : [];
46
+ });
47
+ if (directSpecifiers.length) {
48
+ for (const specifier of directSpecifiers) {
49
+ const cssFile = this.resolver.resolveStyleDependency(specifier);
50
+ if (fs.existsSync(cssFile)) {
51
+ appendUniqueMapValue(entries, sourceModuleDir, specifier);
52
+ }
53
+ }
54
+ continue;
55
+ }
56
+ for (const ruleMatch of ruleMatches) {
57
+ const importedNames = getModuleReferenceImportedNames(file, item);
58
+ for (const importedName of importedNames) {
59
+ const specifier = createStyleAutoImportSpecifier(ruleMatch.rule, ruleMatch.values, importedName);
60
+ const cssFile = this.resolver.resolveStyleDependency(specifier);
61
+ if (!fs.existsSync(cssFile)) {
62
+ continue;
63
+ }
64
+ appendUniqueMapValue(entries, sourceModuleDir, specifier);
65
+ }
66
+ }
83
67
  }
84
- appendUniqueMapValue(entries, sourceModuleDir, specifier);
85
- }
86
68
  }
87
- }
69
+ return entries;
88
70
  }
89
- return entries;
90
- }
91
- collectSourceImportStyle(entries, sourceDir, sourceModuleDir, item) {
92
- if (isTypeOnlySourceReference(item)) return;
93
- const importedStyleEntry = this.resolveSourceImportStyleEntry(
94
- sourceDir,
95
- item.importPath,
96
- );
97
- if (!importedStyleEntry) return;
98
- const sourceStyleDir = path.join(this.srcRoot, sourceModuleDir, 'style');
99
- appendUniqueMapValue(
100
- entries,
101
- sourceModuleDir,
102
- this.toRelativeSpecifier(sourceStyleDir, importedStyleEntry),
103
- );
104
- }
105
- resolveSourceImportStyleEntry(sourceDir, importPath) {
106
- const sourceRelativePaths = this.resolveSourceImportPaths(
107
- sourceDir,
108
- importPath,
109
- );
110
- for (const sourceRelativePath of sourceRelativePaths) {
111
- const sourceBase = this.toSourceBase(sourceRelativePath);
112
- if (!this.isInsideSourceRoot(sourceBase)) continue;
113
- const directoryStyleEntry = path.join(sourceBase, 'style', 'index.css');
114
- for (const extension of this.styleExtensions) {
115
- const directorySourceStyle = path.join(sourceBase, `index${extension}`);
116
- if (fs.existsSync(directorySourceStyle)) return directoryStyleEntry;
117
- }
118
- const hasFileSourceStyle = this.styleExtensions.some((extension) =>
119
- fs.existsSync(`${sourceBase}${extension}`),
120
- );
121
- if (hasFileSourceStyle)
122
- return path.join(sourceBase, 'style', 'index.css');
71
+ collectSourceImportStyle(entries, sourceDir, sourceModuleDir, item) {
72
+ if (isTypeOnlyModuleReference(item))
73
+ return;
74
+ const importedStyleEntry = this.resolveSourceImportStyleEntry(sourceDir, item.importPath);
75
+ if (!importedStyleEntry)
76
+ return;
77
+ const sourceStyleDir = path.join(this.srcRoot, sourceModuleDir, 'style');
78
+ appendUniqueMapValue(entries, sourceModuleDir, this.toRelativeSpecifier(sourceStyleDir, importedStyleEntry));
123
79
  }
124
- return null;
125
- }
126
- isInsideSourceRoot(file) {
127
- const relative = path.relative(this.srcRoot, file);
128
- return !relative.startsWith('..') && !path.isAbsolute(relative);
129
- }
130
- resolveSourceImportPaths(sourceDir, importPath) {
131
- return [
132
- ...resolveRelativeSourceImport(sourceDir, importPath),
133
- ...resolvePackageImportsSourceImport(
134
- this.packageRoot,
135
- this.srcRoot,
136
- importPath,
137
- ),
138
- ...resolveTsconfigPathsSourceImport(
139
- this.packageRoot,
140
- this.srcRoot,
141
- importPath,
142
- ),
143
- ];
144
- }
145
- toSourceBase(sourceRelativePath) {
146
- const sourceBase = path.join(this.srcRoot, sourceRelativePath);
147
- if (SOURCE_INDEX_RE.test(sourceBase)) {
148
- return path.dirname(sourceBase);
80
+ resolveSourceImportStyleEntry(sourceDir, importPath) {
81
+ const sourceRelativePaths = this.resolveSourceImportPaths(sourceDir, importPath);
82
+ for (const sourceRelativePath of sourceRelativePaths) {
83
+ const sourceBase = this.toSourceBase(sourceRelativePath);
84
+ if (!this.isInsideSourceRoot(sourceBase))
85
+ continue;
86
+ const directoryStyleEntry = path.join(sourceBase, 'style', 'index.css');
87
+ for (const extension of this.styleExtensions) {
88
+ const directorySourceStyle = path.join(sourceBase, `index${extension}`);
89
+ if (fs.existsSync(directorySourceStyle))
90
+ return directoryStyleEntry;
91
+ }
92
+ const hasFileSourceStyle = this.styleExtensions.some((extension) => fs.existsSync(`${sourceBase}${extension}`));
93
+ if (hasFileSourceStyle)
94
+ return path.join(sourceBase, 'style', 'index.css');
95
+ }
96
+ return null;
149
97
  }
150
- return sourceBase.replace(SOURCE_EXTENSION_RE, '');
151
- }
152
- toRelativeSpecifier(fromDir, file) {
153
- const relative = path.relative(fromDir, file).split(path.sep).join('/');
154
- return relative.startsWith('.') ? relative : `./${relative}`;
155
- }
156
- createAutoImportRules(config) {
157
- const rules = [];
158
- for (const [packageName, dependency] of Object.entries(
159
- config.styles.dependencies,
160
- )) {
161
- const dependencyPaths = isArray(dependency.components)
162
- ? dependency.components
163
- : dependency.components
164
- ? [dependency.components]
165
- : [];
166
- for (const dependencyPath of dependencyPaths) {
167
- rules.push({
168
- packageName,
169
- outputPattern: joinDependencySpecifier(packageName, dependencyPath),
170
- });
171
- }
98
+ isInsideSourceRoot(file) {
99
+ const relative = path.relative(this.srcRoot, file);
100
+ return !relative.startsWith('..') && !path.isAbsolute(relative);
172
101
  }
173
- return rules;
174
- }
175
- matchAutoImportRules(rules, importPath) {
176
- const matches = [];
177
- for (const rule of rules) {
178
- if (
179
- importPath !== rule.packageName &&
180
- !importPath.startsWith(`${rule.packageName}${POSIX_SEPARATOR}`)
181
- ) {
182
- continue;
183
- }
184
- matches.push({
185
- rule,
186
- values: this.getImportPathValues(rule.packageName, importPath),
187
- });
102
+ resolveSourceImportPaths(sourceDir, importPath) {
103
+ return [
104
+ ...resolveRelativeSourceImport(sourceDir, importPath),
105
+ ...resolvePackageImportsSourceImport(this.packageRoot, this.srcRoot, importPath),
106
+ ...resolveTsconfigPathsSourceImport(this.packageRoot, this.srcRoot, importPath),
107
+ ];
188
108
  }
189
- return matches;
190
- }
191
- getImportPathValues(packageName, importPath) {
192
- return importPath
193
- .slice(packageName.length)
194
- .replace(new RegExp(`^${POSIX_SEPARATOR}`), '')
195
- .split(POSIX_SEPARATOR)
196
- .filter(Boolean);
197
- }
198
- createStyleSpecifier(rule, values, importedName) {
199
- const pathValues = [...values];
200
- return rule.outputPattern.replace(/\*\*|\*/g, (token) => {
201
- const matchedValue = pathValues.shift();
202
- if (matchedValue) return matchedValue;
203
- if (token === GLOBSTAR_TOKEN) return importedName;
204
- return matchedValue ?? importedName;
205
- });
206
- }
207
- createDirectStyleSpecifier(rule, importPath) {
208
- const wildcardIndex = rule.outputPattern.indexOf('*');
209
- if (wildcardIndex < 0) {
210
- return null;
109
+ toSourceBase(sourceRelativePath) {
110
+ const sourceBase = path.join(this.srcRoot, sourceRelativePath);
111
+ if (SOURCE_INDEX_RE.test(sourceBase)) {
112
+ return path.dirname(sourceBase);
113
+ }
114
+ return sourceBase.replace(SOURCE_EXTENSION_RE, '');
211
115
  }
212
- const wildcardLength = rule.outputPattern.startsWith(
213
- GLOBSTAR_TOKEN,
214
- wildcardIndex,
215
- )
216
- ? GLOBSTAR_TOKEN.length
217
- : 1;
218
- const prefix = rule.outputPattern.slice(0, wildcardIndex);
219
- const suffix = rule.outputPattern.slice(wildcardIndex + wildcardLength);
220
- if (!importPath.startsWith(prefix)) {
221
- return null;
116
+ toRelativeSpecifier(fromDir, file) {
117
+ const relative = path.relative(fromDir, file).split(path.sep).join('/');
118
+ return relative.startsWith('.') ? relative : `./${relative}`;
222
119
  }
223
- return `${importPath}${suffix}`;
224
- }
225
120
  }
@@ -0,0 +1,11 @@
1
+ import ts from 'typescript';
2
+ export type ModuleImportReference = {
3
+ importPath: string;
4
+ importClause?: ts.ImportClause;
5
+ importedNames?: Array<string>;
6
+ isTypeOnly?: boolean;
7
+ hasNamespaceImport?: boolean;
8
+ };
9
+ export declare function collectModuleImportReferences(file: string, code: string): ModuleImportReference[];
10
+ export declare function isTypeOnlyModuleReference(item: ModuleImportReference): boolean | undefined;
11
+ export declare function getModuleReferenceImportedNames(file: string, item: ModuleImportReference): string[];
@@ -0,0 +1,173 @@
1
+ import ts from 'typescript';
2
+ export function collectModuleImportReferences(file, code) {
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;
29
+ }
30
+ export function isTypeOnlyModuleReference(item) {
31
+ return isTypeOnlyImportClause(item.importClause) || item.isTypeOnly;
32
+ }
33
+ export function getModuleReferenceImportedNames(file, item) {
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
+ }
62
+ return names;
63
+ }
64
+ const collectLocalDeclarationNames = (node, localDeclarations) => {
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
+ }
81
+ };
82
+ const collectImportBindings = (node, importBindings) => {
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
+ }
118
+ };
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
+ }
135
+ if (!node.exportClause || !ts.isNamedExports(node.exportClause)) {
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
+ }
157
+ };
158
+ const getExportedNames = (node) => {
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);
165
+ };
166
+ const isTypeOnlyImportClause = (importClause) => {
167
+ return importClause?.phaseModifier === ts.SyntaxKind.TypeKeyword;
168
+ };
169
+ const createNamespaceImportError = (file, importPath) => {
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}`);
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 importedStyleFiles;
10
+ private readonly styleFilesByDir;
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
  }