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