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.
- 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.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.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.js +45 -66
- package/dist/css/production/format/entryWriter.js +36 -49
- package/dist/css/production/format/externalWriter.js +21 -33
- 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.js +11 -11
- 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 -23
- package/dist/css/vite/moduleGraph/graph.js +46 -49
- 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 +4 -6
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +59 -64
- package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
- package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
- package/dist/css/vite/moduleGraph/requestCache.js +53 -51
- 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 -14
- package/dist/css/vite/vitePlugin.d.ts +16 -20
- package/dist/css/vite/vitePlugin.js +110 -109
- 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 -33
|
@@ -2,117 +2,118 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import postcss from 'postcss';
|
|
4
4
|
export class StyleProcessor {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
createRoot() {
|
|
12
|
-
return postcss.root();
|
|
13
|
-
}
|
|
14
|
-
appendImportRule(root, specifier) {
|
|
15
|
-
const rule = postcss.atRule({
|
|
16
|
-
name: 'import',
|
|
17
|
-
params: `"${specifier}"`,
|
|
18
|
-
});
|
|
19
|
-
if (root.nodes?.length) rule.raws.before = '\n';
|
|
20
|
-
root.append(rule);
|
|
21
|
-
root.raws.semicolon = true;
|
|
22
|
-
}
|
|
23
|
-
stringify(root) {
|
|
24
|
-
root.raws.semicolon = true;
|
|
25
|
-
return `${root}\n`;
|
|
26
|
-
}
|
|
27
|
-
appendStyleContent(target, content, from) {
|
|
28
|
-
const root = this.parse(content, from);
|
|
29
|
-
if (target.nodes?.length && root.nodes?.[0]) {
|
|
30
|
-
root.nodes[0].raws.before = '\n';
|
|
5
|
+
config;
|
|
6
|
+
resolver;
|
|
7
|
+
constructor(config, resolver) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.resolver = resolver;
|
|
31
10
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
readStyleFile(stylePath, seen = new Set()) {
|
|
35
|
-
if (!fs.existsSync(stylePath)) {
|
|
36
|
-
return '';
|
|
11
|
+
createRoot() {
|
|
12
|
+
return postcss.root();
|
|
37
13
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
for (const { rule, specifier } of imports) {
|
|
49
|
-
const importedPath = this.resolver.resolveStyleDependency(
|
|
50
|
-
specifier,
|
|
51
|
-
path.dirname(stylePath),
|
|
52
|
-
);
|
|
53
|
-
if (!importedPath) continue;
|
|
54
|
-
const content = this.readStyleFile(importedPath, seen);
|
|
55
|
-
if (!content.trim()) {
|
|
56
|
-
rule.remove();
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
rule.replaceWith(...(this.parse(content, importedPath).nodes ?? []));
|
|
14
|
+
appendImportRule(root, specifier) {
|
|
15
|
+
const rule = postcss.atRule({
|
|
16
|
+
name: 'import',
|
|
17
|
+
params: `"${specifier}"`,
|
|
18
|
+
});
|
|
19
|
+
if (root.nodes?.length)
|
|
20
|
+
rule.raws.before = '\n';
|
|
21
|
+
root.append(rule);
|
|
22
|
+
root.raws.semicolon = true;
|
|
60
23
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const specifier = this.parseImportSpecifier(rule.params);
|
|
70
|
-
if (
|
|
71
|
-
!specifier?.startsWith('.') ||
|
|
72
|
-
!this.config.styleExtensions.includes(path.extname(specifier))
|
|
73
|
-
) {
|
|
74
|
-
return;
|
|
24
|
+
stringify(root) {
|
|
25
|
+
root.raws.semicolon = true;
|
|
26
|
+
return `${root}\n`;
|
|
27
|
+
}
|
|
28
|
+
appendStyleContent(target, content, from) {
|
|
29
|
+
const root = this.parse(content, from);
|
|
30
|
+
if (target.nodes?.length && root.nodes?.[0]) {
|
|
31
|
+
root.nodes[0].raws.before = '\n';
|
|
75
32
|
}
|
|
76
|
-
|
|
77
|
-
});
|
|
33
|
+
target.append(...(root.nodes ?? []));
|
|
78
34
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
35
|
+
readStyleFile(stylePath, seen = new Set()) {
|
|
36
|
+
if (!fs.existsSync(stylePath)) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
const normalizedPath = path.resolve(stylePath);
|
|
40
|
+
if (seen.has(normalizedPath))
|
|
41
|
+
return '';
|
|
42
|
+
seen.add(normalizedPath);
|
|
43
|
+
const css = fs.readFileSync(stylePath, 'utf8');
|
|
44
|
+
const root = this.parse(css, stylePath);
|
|
45
|
+
const imports = [];
|
|
46
|
+
root.walkAtRules('import', (rule) => {
|
|
47
|
+
const specifier = this.parseImportSpecifier(rule.params);
|
|
48
|
+
if (specifier)
|
|
49
|
+
imports.push({ rule, specifier });
|
|
50
|
+
});
|
|
51
|
+
for (const { rule, specifier } of imports) {
|
|
52
|
+
const importedPath = this.resolver.resolveStyleDependency(specifier, path.dirname(stylePath));
|
|
53
|
+
if (!importedPath)
|
|
54
|
+
continue;
|
|
55
|
+
const content = this.readStyleFile(importedPath, seen);
|
|
56
|
+
if (!content.trim()) {
|
|
57
|
+
rule.remove();
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
rule.replaceWith(...(this.parse(content, importedPath).nodes ?? []));
|
|
61
|
+
}
|
|
62
|
+
return root.toString();
|
|
90
63
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
64
|
+
collectImportedStyleFiles(styleFiles) {
|
|
65
|
+
const imported = new Set();
|
|
66
|
+
for (const styleFile of styleFiles) {
|
|
67
|
+
const css = fs.readFileSync(styleFile, 'utf8');
|
|
68
|
+
const root = this.parse(css, styleFile);
|
|
69
|
+
root.walkAtRules('import', (rule) => {
|
|
70
|
+
const specifier = this.parseImportSpecifier(rule.params);
|
|
71
|
+
if (!specifier?.startsWith('.') ||
|
|
72
|
+
!this.config.styleExtensions.includes(path.extname(specifier))) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
imported.add(path.resolve(path.dirname(styleFile), specifier));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return imported;
|
|
104
79
|
}
|
|
105
|
-
|
|
106
|
-
|
|
80
|
+
collectStyleImportSpecifiers(styleFiles) {
|
|
81
|
+
const specifiers = new Set();
|
|
82
|
+
for (const styleFile of styleFiles) {
|
|
83
|
+
const css = fs.readFileSync(styleFile, 'utf8');
|
|
84
|
+
const root = this.parse(css, styleFile);
|
|
85
|
+
root.walkAtRules('import', (rule) => {
|
|
86
|
+
const specifier = this.parseImportSpecifier(rule.params);
|
|
87
|
+
if (specifier)
|
|
88
|
+
specifiers.add(specifier);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return specifiers;
|
|
107
92
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
parse(code, from) {
|
|
94
|
+
// Keep parsing behind one method so future style languages can transform
|
|
95
|
+
// to CSS before PostCSS reads the final stylesheet.
|
|
96
|
+
return postcss.parse(code, { from });
|
|
97
|
+
}
|
|
98
|
+
parseImportSpecifier(params) {
|
|
99
|
+
const value = params.trim();
|
|
100
|
+
const first = value[0];
|
|
101
|
+
if (first === '"' || first === "'") {
|
|
102
|
+
const end = value.indexOf(first, 1);
|
|
103
|
+
return end > 0 ? value.slice(1, end) : null;
|
|
104
|
+
}
|
|
105
|
+
if (!value.startsWith('url(')) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const end = value.indexOf(')', 4);
|
|
109
|
+
if (end < 0)
|
|
110
|
+
return null;
|
|
111
|
+
const url = value.slice(4, end).trim();
|
|
112
|
+
const quote = url[0];
|
|
113
|
+
if (quote === '"' || quote === "'") {
|
|
114
|
+
const quoteEnd = url.indexOf(quote, 1);
|
|
115
|
+
return quoteEnd > 0 ? url.slice(1, quoteEnd) : null;
|
|
116
|
+
}
|
|
117
|
+
return url || null;
|
|
115
118
|
}
|
|
116
|
-
return url || null;
|
|
117
|
-
}
|
|
118
119
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ModuleStyleBuildConfig,
|
|
3
|
-
ResolvedModuleStyleBuildContext,
|
|
4
|
-
} from '#auklet/types';
|
|
1
|
+
import type { ModuleStyleBuildConfig, ResolvedModuleStyleBuildContext } from '#auklet/types';
|
|
5
2
|
export declare class WorkspaceStyleResolver {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
toOutputStyleSpecifier(specifier: string, outRoot: string): string;
|
|
15
|
-
toExternalStyleSpecifier(specifier: string, outRoot: string): string;
|
|
16
|
-
private getStylePathOutputFormat;
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly context;
|
|
5
|
+
private readonly require;
|
|
6
|
+
constructor(config: ModuleStyleBuildConfig, context: ResolvedModuleStyleBuildContext);
|
|
7
|
+
resolveStyleDependency(specifier: string, fromDir?: string): string;
|
|
8
|
+
toOutputStyleSpecifier(specifier: string, outRoot: string): string;
|
|
9
|
+
toExternalStyleSpecifier(specifier: string, outRoot: string): string;
|
|
10
|
+
private getStylePathOutputFormat;
|
|
17
11
|
}
|
|
@@ -4,81 +4,71 @@ import { NODE_MODULES_DIR, STYLE_ENTRY } from '#auklet/css/constants';
|
|
|
4
4
|
import { POSIX_SEPARATOR } from '#auklet/utils';
|
|
5
5
|
import { parsePackageStyleSpecifier } from '#auklet/css/core/style/specifier';
|
|
6
6
|
export class WorkspaceStyleResolver {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
path.join(this.context.packageRoot, 'package.json'),
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
resolveStyleDependency(specifier, fromDir = this.context.packageRoot) {
|
|
18
|
-
if (specifier.startsWith('.')) {
|
|
19
|
-
return path.resolve(fromDir, specifier);
|
|
7
|
+
config;
|
|
8
|
+
context;
|
|
9
|
+
require;
|
|
10
|
+
constructor(config, context) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.require = createRequire(path.join(this.context.packageRoot, 'package.json'));
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
resolveStyleDependency(specifier, fromDir = this.context.packageRoot) {
|
|
16
|
+
if (specifier.startsWith('.')) {
|
|
17
|
+
return path.resolve(fromDir, specifier);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return this.require.resolve(specifier, {
|
|
21
|
+
paths: [this.context.packageRoot],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return path.resolve(this.context.packageRoot, NODE_MODULES_DIR, specifier);
|
|
26
|
+
}
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
toOutputStyleSpecifier(specifier, outRoot) {
|
|
29
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
30
|
+
if (!parsed)
|
|
31
|
+
return specifier;
|
|
32
|
+
const { packageName, stylePath } = parsed;
|
|
33
|
+
const currentOutputFormat = path.basename(outRoot);
|
|
34
|
+
const outputFormat = this.getStylePathOutputFormat(stylePath);
|
|
35
|
+
if (outputFormat) {
|
|
36
|
+
return [packageName, currentOutputFormat, outputFormat.path].join(POSIX_SEPARATOR);
|
|
37
|
+
}
|
|
38
|
+
return specifier;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
toExternalStyleSpecifier(specifier, outRoot) {
|
|
41
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
42
|
+
if (!parsed)
|
|
43
|
+
return specifier;
|
|
44
|
+
const { packageName, stylePath } = parsed;
|
|
45
|
+
const currentOutputFormat = path.basename(outRoot);
|
|
46
|
+
const outputFormat = this.getStylePathOutputFormat(stylePath);
|
|
47
|
+
if (stylePath === STYLE_ENTRY) {
|
|
48
|
+
return [packageName, this.config.output.externalStyleFile].join(POSIX_SEPARATOR);
|
|
49
|
+
}
|
|
50
|
+
if (outputFormat &&
|
|
51
|
+
outputFormat.path ===
|
|
52
|
+
[this.config.output.styleDir, this.config.output.indexStyleFile].join(POSIX_SEPARATOR)) {
|
|
53
|
+
return [
|
|
54
|
+
packageName,
|
|
55
|
+
currentOutputFormat,
|
|
56
|
+
this.config.output.styleDir,
|
|
57
|
+
this.config.output.externalStyleFile,
|
|
58
|
+
].join(POSIX_SEPARATOR);
|
|
59
|
+
}
|
|
60
|
+
return specifier;
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.config.output.externalStyleFile,
|
|
69
|
-
].join(POSIX_SEPARATOR);
|
|
62
|
+
getStylePathOutputFormat(stylePath) {
|
|
63
|
+
for (const format of this.config.output.outputFormats) {
|
|
64
|
+
const prefix = `${format}${POSIX_SEPARATOR}`;
|
|
65
|
+
if (!stylePath.startsWith(prefix))
|
|
66
|
+
continue;
|
|
67
|
+
return {
|
|
68
|
+
format,
|
|
69
|
+
path: stylePath.slice(prefix.length),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
70
73
|
}
|
|
71
|
-
return specifier;
|
|
72
|
-
}
|
|
73
|
-
getStylePathOutputFormat(stylePath) {
|
|
74
|
-
for (const format of this.config.output.outputFormats) {
|
|
75
|
-
const prefix = `${format}${POSIX_SEPARATOR}`;
|
|
76
|
-
if (!stylePath.startsWith(prefix)) continue;
|
|
77
|
-
return {
|
|
78
|
-
format,
|
|
79
|
-
path: stylePath.slice(prefix.length),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
74
|
}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ModuleStyleBuildConfig,
|
|
3
|
-
ModuleStyleBuildContext,
|
|
4
|
-
ModuleStyleBuildOptions,
|
|
5
|
-
} from '#auklet/types';
|
|
1
|
+
import type { ModuleStyleBuildConfig, ModuleStyleBuildContext, ModuleStyleBuildOptions } from '#auklet/types';
|
|
6
2
|
export declare class ModuleStyleBuilder {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private logOutputs;
|
|
16
|
-
private createBuildContext;
|
|
17
|
-
private createPackageContext;
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly context;
|
|
5
|
+
private readonly logger?;
|
|
6
|
+
constructor(context?: ModuleStyleBuildContext, config?: ModuleStyleBuildConfig);
|
|
7
|
+
build(options?: ModuleStyleBuildOptions): Promise<void>;
|
|
8
|
+
private logOutputs;
|
|
9
|
+
private createBuildContext;
|
|
10
|
+
private createPackageContext;
|
|
18
11
|
}
|
|
@@ -6,63 +6,57 @@ import { ModuleStyleOutputWriter } from '#auklet/css/production/moduleOutputWrit
|
|
|
6
6
|
import { PackageStyleEntryWriter } from '#auklet/css/production/packageEntryWriter';
|
|
7
7
|
import { toPosixPath } from '#auklet/utils';
|
|
8
8
|
export class ModuleStyleBuilder {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
async build(options = {}) {
|
|
23
|
-
const rawConfig = options.aukletConfig ?? this.context.aukletConfig ?? {};
|
|
24
|
-
const normalizedConfig = normalizeAukletConfig(rawConfig);
|
|
25
|
-
const logger = options.logger ?? this.logger;
|
|
26
|
-
const context = this.createBuildContext(normalizedConfig);
|
|
27
|
-
const packageContext = this.createPackageContext(context, normalizedConfig);
|
|
28
|
-
const writerOptions = {
|
|
29
|
-
config: this.config,
|
|
30
|
-
context,
|
|
31
|
-
packageContext,
|
|
32
|
-
};
|
|
33
|
-
const packageWriter = new PackageStyleEntryWriter(writerOptions);
|
|
34
|
-
const packageOutput = packageWriter.write();
|
|
35
|
-
const outputs = packageOutput ? [packageOutput] : [];
|
|
36
|
-
logger?.log?.(`[auklet:css] build ${path.basename(context.packageRoot)}`);
|
|
37
|
-
if (normalizedConfig.modules) {
|
|
38
|
-
outputs.push(...new ModuleStyleOutputWriter(writerOptions).write());
|
|
9
|
+
config;
|
|
10
|
+
context;
|
|
11
|
+
logger;
|
|
12
|
+
constructor(context = {}, config = moduleStyleBuildConfig) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.context = {
|
|
15
|
+
packageRoot: process.cwd(),
|
|
16
|
+
source: context.source,
|
|
17
|
+
output: context.output,
|
|
18
|
+
...context,
|
|
19
|
+
};
|
|
20
|
+
this.logger = context.logger;
|
|
39
21
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
22
|
+
async build(options = {}) {
|
|
23
|
+
const rawConfig = options.aukletConfig ?? this.context.aukletConfig ?? {};
|
|
24
|
+
const normalizedConfig = normalizeAukletConfig(rawConfig);
|
|
25
|
+
const logger = options.logger ?? this.logger;
|
|
26
|
+
const context = this.createBuildContext(normalizedConfig);
|
|
27
|
+
const packageContext = this.createPackageContext(context, normalizedConfig);
|
|
28
|
+
const writerOptions = {
|
|
29
|
+
config: this.config,
|
|
30
|
+
context,
|
|
31
|
+
packageContext,
|
|
32
|
+
};
|
|
33
|
+
const packageWriter = new PackageStyleEntryWriter(writerOptions);
|
|
34
|
+
const packageOutput = packageWriter.write();
|
|
35
|
+
const outputs = packageOutput ? [packageOutput] : [];
|
|
36
|
+
logger?.log?.(`[auklet:css] build ${path.basename(context.packageRoot)}`);
|
|
37
|
+
if (normalizedConfig.modules) {
|
|
38
|
+
outputs.push(...new ModuleStyleOutputWriter(writerOptions).write());
|
|
39
|
+
}
|
|
40
|
+
this.logOutputs(context, packageContext.styleFiles, outputs, logger);
|
|
41
|
+
}
|
|
42
|
+
logOutputs(context, styleFiles, outputs, logger) {
|
|
43
|
+
logger?.log?.(`[auklet:css] ${styleFiles.length} source style file(s), ${outputs.length} output entry file(s)`);
|
|
44
|
+
for (const output of outputs) {
|
|
45
|
+
logger?.log?.(`[auklet:css] + ${toPosixPath(path.relative(context.packageRoot, output))}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
createBuildContext(config) {
|
|
49
|
+
return {
|
|
50
|
+
packageRoot: this.context.packageRoot,
|
|
51
|
+
sourceDir: this.context.source ?? config.source,
|
|
52
|
+
outputDir: this.context.output ?? config.output,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
createPackageContext(context, normalizedConfig) {
|
|
56
|
+
return new StylePackageContext({
|
|
57
|
+
config: this.config,
|
|
58
|
+
context,
|
|
59
|
+
normalizedConfig,
|
|
60
|
+
});
|
|
52
61
|
}
|
|
53
|
-
}
|
|
54
|
-
createBuildContext(config) {
|
|
55
|
-
return {
|
|
56
|
-
packageRoot: this.context.packageRoot,
|
|
57
|
-
sourceDir: this.context.source ?? config.source,
|
|
58
|
-
outputDir: this.context.output ?? config.output,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
createPackageContext(context, normalizedConfig) {
|
|
62
|
-
return new StylePackageContext({
|
|
63
|
-
config: this.config,
|
|
64
|
-
context,
|
|
65
|
-
normalizedConfig,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
62
|
}
|
|
@@ -1,71 +1,50 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { writeStyleFile } from '#auklet/css/production/format/shared';
|
|
2
|
+
import { writeStyleFile, } from '#auklet/css/production/format/shared';
|
|
3
3
|
import { toPosixPath } from '#auklet/utils';
|
|
4
4
|
export class ComponentStyleEntryWriter {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
outputs.push(target);
|
|
5
|
+
config;
|
|
6
|
+
sourceRoot;
|
|
7
|
+
resolver;
|
|
8
|
+
styleProcessor;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.config = options.config;
|
|
11
|
+
this.sourceRoot = options.packageContext.sourceRoot;
|
|
12
|
+
this.resolver = options.packageContext.resolver;
|
|
13
|
+
this.styleProcessor = options.packageContext.styleProcessor;
|
|
14
|
+
}
|
|
15
|
+
write(outRoot, entries) {
|
|
16
|
+
const outputs = [];
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const styleDir = path.join(outRoot, entry.sourceDir, this.config.output.styleDir);
|
|
19
|
+
const target = path.join(styleDir, this.config.output.indexStyleFile);
|
|
20
|
+
const ownImports = this.styleProcessor.collectStyleImportSpecifiers(entry.ownStyleFiles);
|
|
21
|
+
const sourceStyleSpecifiers = [
|
|
22
|
+
...this.getModuleStyleSpecifiers(entry.moduleStyleImports.filter((specifier) => !ownImports.has(specifier)), styleDir),
|
|
23
|
+
...this.getOwnStyleSpecifiers(entry.ownStyleFiles, styleDir, outRoot),
|
|
24
|
+
];
|
|
25
|
+
const root = this.styleProcessor.createRoot();
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const specifier of sourceStyleSpecifiers) {
|
|
28
|
+
if (seen.has(specifier))
|
|
29
|
+
continue;
|
|
30
|
+
seen.add(specifier);
|
|
31
|
+
this.styleProcessor.appendImportRule(root, this.resolver.toOutputStyleSpecifier(specifier, outRoot));
|
|
32
|
+
}
|
|
33
|
+
writeStyleFile(target, root.nodes?.length ? this.styleProcessor.stringify(root) : '');
|
|
34
|
+
outputs.push(target);
|
|
35
|
+
}
|
|
36
|
+
return outputs;
|
|
37
|
+
}
|
|
38
|
+
getModuleStyleSpecifiers(specifiers, styleDir) {
|
|
39
|
+
return specifiers.map((specifier) => {
|
|
40
|
+
if (specifier.startsWith('.'))
|
|
41
|
+
return specifier;
|
|
42
|
+
if (!path.isAbsolute(specifier))
|
|
43
|
+
return specifier;
|
|
44
|
+
return toPosixPath(path.relative(styleDir, specifier));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getOwnStyleSpecifiers(ownStyleFiles, styleDir, outRoot) {
|
|
48
|
+
return ownStyleFiles.map((styleFile) => toPosixPath(path.relative(styleDir, path.join(outRoot, path.relative(this.sourceRoot, styleFile)))));
|
|
51
49
|
}
|
|
52
|
-
return outputs;
|
|
53
|
-
}
|
|
54
|
-
getModuleStyleSpecifiers(specifiers, styleDir) {
|
|
55
|
-
return specifiers.map((specifier) => {
|
|
56
|
-
if (specifier.startsWith('.')) return specifier;
|
|
57
|
-
if (!path.isAbsolute(specifier)) return specifier;
|
|
58
|
-
return toPosixPath(path.relative(styleDir, specifier));
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
getOwnStyleSpecifiers(ownStyleFiles, styleDir, outRoot) {
|
|
62
|
-
return ownStyleFiles.map((styleFile) =>
|
|
63
|
-
toPosixPath(
|
|
64
|
-
path.relative(
|
|
65
|
-
styleDir,
|
|
66
|
-
path.join(outRoot, path.relative(this.sourceRoot, styleFile)),
|
|
67
|
-
),
|
|
68
|
-
),
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
50
|
}
|