auklet 0.0.3 → 0.0.5
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/README.md +99 -42
- package/bin/entry.cjs +33 -11
- package/dist/build/runTsdown.js +2 -3
- package/dist/build/tsdownConfig.d.ts +138 -2
- package/dist/build/tsdownConfig.js +108 -63
- package/dist/config.d.ts +38 -6
- package/dist/config.js +43 -7
- package/dist/configLoader.js +1 -2
- package/dist/css/config.d.ts +2 -0
- package/dist/css/config.js +10 -0
- package/dist/css/constants.d.ts +7 -0
- package/dist/css/constants.js +7 -0
- package/dist/css/core/moduleGraph.d.ts +55 -0
- package/dist/css/core/moduleGraph.js +363 -0
- package/dist/css/core/moduleGraphRequestCache.d.ts +80 -0
- package/dist/css/core/moduleGraphRequestCache.js +92 -0
- package/dist/css/core/style/dependencies.d.ts +20 -0
- package/dist/css/core/style/dependencies.js +55 -0
- package/dist/css/core/style/files.d.ts +8 -0
- package/dist/css/core/style/files.js +19 -0
- package/dist/css/core/style/plan.d.ts +59 -0
- package/dist/css/core/style/plan.js +27 -0
- package/dist/css/core/style/specifier.d.ts +14 -0
- package/dist/css/core/style/specifier.js +27 -0
- package/dist/css/core/{moduleStyleImportCollector.d.ts → styleImports/collector.d.ts} +5 -5
- package/dist/css/core/{moduleStyleImportCollector.js → styleImports/collector.js} +36 -99
- package/dist/css/core/styleImports/sourceReference.d.ts +19 -0
- package/dist/css/core/styleImports/sourceReference.js +193 -0
- package/dist/css/core/styleModuleEntryPlanner.d.ts +29 -0
- package/dist/css/core/styleModuleEntryPlanner.js +67 -0
- package/dist/css/core/stylePackageContext.d.ts +27 -0
- package/dist/css/core/stylePackageContext.js +57 -0
- package/dist/css/core/styleProcessor.d.ts +3 -3
- package/dist/css/core/styleProcessor.js +18 -35
- package/dist/css/core/workspaceStyleResolver.d.ts +4 -5
- package/dist/css/core/workspaceStyleResolver.js +12 -28
- package/dist/css/production/builder.d.ts +18 -0
- package/dist/css/production/builder.js +68 -0
- package/dist/css/production/format/componentWriter.d.ts +12 -0
- package/dist/css/production/format/componentWriter.js +67 -0
- package/dist/css/production/format/entryWriter.d.ts +12 -0
- package/dist/css/production/format/entryWriter.js +54 -0
- package/dist/css/production/format/externalWriter.d.ts +9 -0
- package/dist/css/production/format/externalWriter.js +39 -0
- package/dist/css/production/format/moduleWriter.d.ts +8 -0
- package/dist/css/production/format/moduleWriter.js +31 -0
- package/dist/css/production/format/shared.d.ts +20 -0
- package/dist/css/production/format/shared.js +8 -0
- package/dist/css/production/format/sourceWriter.d.ts +6 -0
- package/dist/css/production/format/sourceWriter.js +16 -0
- package/dist/css/production/format/themeWriter.d.ts +16 -0
- package/dist/css/production/format/themeWriter.js +80 -0
- package/dist/css/production/moduleOutputWriter.d.ts +26 -0
- package/dist/css/production/moduleOutputWriter.js +83 -0
- package/dist/css/production/packageEntryWriter.d.ts +20 -0
- package/dist/css/production/packageEntryWriter.js +55 -0
- package/dist/css/vite/hmr.d.ts +4 -4
- package/dist/css/vite/hmr.js +14 -27
- package/dist/css/vite/vitePlugin.d.ts +5 -5
- package/dist/css/vite/vitePlugin.js +21 -30
- package/dist/css/watch/{moduleCssWatcher.d.ts → watcher.d.ts} +8 -4
- package/dist/css/watch/watcher.js +91 -0
- package/dist/index.d.ts +15 -12
- package/dist/index.js +6 -5
- package/dist/types.d.ts +40 -20
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +37 -12
- package/package.json +19 -14
- package/dist/css/core/config.d.ts +0 -2
- package/dist/css/core/config.js +0 -11
- package/dist/css/core/constants.d.ts +0 -3
- package/dist/css/core/constants.js +0 -3
- package/dist/css/core/moduleCssGraph.d.ts +0 -51
- package/dist/css/core/moduleCssGraph.js +0 -416
- package/dist/css/core/path.d.ts +0 -4
- package/dist/css/core/path.js +0 -26
- package/dist/css/core/styleEntry.d.ts +0 -45
- package/dist/css/core/styleEntry.js +0 -108
- package/dist/css/production/moduleCssBuilder.d.ts +0 -33
- package/dist/css/production/moduleCssBuilder.js +0 -445
- package/dist/css/watch/moduleCssWatcher.js +0 -106
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ModuleStyleImportCollector } from '#auklet/css/core/styleImports/collector';
|
|
4
|
+
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
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';
|
|
14
|
+
import { fileWalker } from '#auklet/utils';
|
|
15
|
+
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
|
+
}
|
|
57
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import postcss, { type Root } from 'postcss';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModuleStyleBuildConfig } from '#auklet/types';
|
|
3
3
|
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
4
4
|
export declare class StyleProcessor {
|
|
5
5
|
private readonly config;
|
|
6
6
|
private readonly resolver;
|
|
7
|
-
constructor(config:
|
|
7
|
+
constructor(config: ModuleStyleBuildConfig, resolver: WorkspaceStyleResolver);
|
|
8
8
|
createRoot(): postcss.Root;
|
|
9
9
|
appendImportRule(root: Root, specifier: string): void;
|
|
10
10
|
stringify(root: Root): string;
|
|
11
11
|
appendStyleContent(target: Root, content: string, from: string): void;
|
|
12
|
-
readStyleFile(
|
|
12
|
+
readStyleFile(stylePath: string, seen?: Set<string>): string;
|
|
13
13
|
collectImportedStyleFiles(styleFiles: Array<string>): Set<string>;
|
|
14
14
|
private parse;
|
|
15
15
|
private parseImportSpecifier;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import postcss from 'postcss';
|
|
4
|
-
import {
|
|
5
|
-
IMPORT_AT_RULE,
|
|
6
|
-
LINE_SEPARATOR,
|
|
7
|
-
RELATIVE_IMPORT_PREFIX,
|
|
8
|
-
} from '#auklet/css/core/constants';
|
|
9
4
|
export class StyleProcessor {
|
|
5
|
+
config;
|
|
6
|
+
resolver;
|
|
10
7
|
constructor(config, resolver) {
|
|
11
8
|
this.config = config;
|
|
12
9
|
this.resolver = resolver;
|
|
@@ -15,50 +12,43 @@ export class StyleProcessor {
|
|
|
15
12
|
return postcss.root();
|
|
16
13
|
}
|
|
17
14
|
appendImportRule(root, specifier) {
|
|
18
|
-
var _a;
|
|
19
15
|
const rule = postcss.atRule({
|
|
20
|
-
name:
|
|
16
|
+
name: 'import',
|
|
21
17
|
params: `"${specifier}"`,
|
|
22
18
|
});
|
|
23
|
-
if (
|
|
24
|
-
rule.raws.before = LINE_SEPARATOR;
|
|
19
|
+
if (root.nodes?.length) rule.raws.before = '\n';
|
|
25
20
|
root.append(rule);
|
|
26
21
|
root.raws.semicolon = true;
|
|
27
22
|
}
|
|
28
23
|
stringify(root) {
|
|
29
24
|
root.raws.semicolon = true;
|
|
30
|
-
return `${root}
|
|
25
|
+
return `${root}\n`;
|
|
31
26
|
}
|
|
32
27
|
appendStyleContent(target, content, from) {
|
|
33
|
-
var _a, _b, _c;
|
|
34
28
|
const root = this.parse(content, from);
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
((_b = root.nodes) === null || _b === void 0 ? void 0 : _b[0])
|
|
38
|
-
) {
|
|
39
|
-
root.nodes[0].raws.before = LINE_SEPARATOR;
|
|
29
|
+
if (target.nodes?.length && root.nodes?.[0]) {
|
|
30
|
+
root.nodes[0].raws.before = '\n';
|
|
40
31
|
}
|
|
41
|
-
target.append(...(
|
|
32
|
+
target.append(...(root.nodes ?? []));
|
|
42
33
|
}
|
|
43
|
-
readStyleFile(
|
|
44
|
-
|
|
45
|
-
if (!fs.existsSync(cssPath)) {
|
|
34
|
+
readStyleFile(stylePath, seen = new Set()) {
|
|
35
|
+
if (!fs.existsSync(stylePath)) {
|
|
46
36
|
return '';
|
|
47
37
|
}
|
|
48
|
-
const normalizedPath = path.resolve(
|
|
38
|
+
const normalizedPath = path.resolve(stylePath);
|
|
49
39
|
if (seen.has(normalizedPath)) return '';
|
|
50
40
|
seen.add(normalizedPath);
|
|
51
|
-
const css = fs.readFileSync(
|
|
52
|
-
const root = this.parse(css,
|
|
41
|
+
const css = fs.readFileSync(stylePath, 'utf8');
|
|
42
|
+
const root = this.parse(css, stylePath);
|
|
53
43
|
const imports = [];
|
|
54
|
-
root.walkAtRules(
|
|
44
|
+
root.walkAtRules('import', (rule) => {
|
|
55
45
|
const specifier = this.parseImportSpecifier(rule.params);
|
|
56
46
|
if (specifier) imports.push({ rule, specifier });
|
|
57
47
|
});
|
|
58
48
|
for (const { rule, specifier } of imports) {
|
|
59
49
|
const importedPath = this.resolver.resolveStyleDependency(
|
|
60
50
|
specifier,
|
|
61
|
-
path.dirname(
|
|
51
|
+
path.dirname(stylePath),
|
|
62
52
|
);
|
|
63
53
|
if (!importedPath) continue;
|
|
64
54
|
const content = this.readStyleFile(importedPath, seen);
|
|
@@ -66,12 +56,7 @@ export class StyleProcessor {
|
|
|
66
56
|
rule.remove();
|
|
67
57
|
continue;
|
|
68
58
|
}
|
|
69
|
-
rule.replaceWith(
|
|
70
|
-
...((_a = this.parse(content, importedPath).nodes) !== null &&
|
|
71
|
-
_a !== void 0
|
|
72
|
-
? _a
|
|
73
|
-
: []),
|
|
74
|
-
);
|
|
59
|
+
rule.replaceWith(...(this.parse(content, importedPath).nodes ?? []));
|
|
75
60
|
}
|
|
76
61
|
return root.toString();
|
|
77
62
|
}
|
|
@@ -80,12 +65,10 @@ export class StyleProcessor {
|
|
|
80
65
|
for (const styleFile of styleFiles) {
|
|
81
66
|
const css = fs.readFileSync(styleFile, 'utf8');
|
|
82
67
|
const root = this.parse(css, styleFile);
|
|
83
|
-
root.walkAtRules(
|
|
68
|
+
root.walkAtRules('import', (rule) => {
|
|
84
69
|
const specifier = this.parseImportSpecifier(rule.params);
|
|
85
70
|
if (
|
|
86
|
-
!(
|
|
87
|
-
? void 0
|
|
88
|
-
: specifier.startsWith(RELATIVE_IMPORT_PREFIX)) ||
|
|
71
|
+
!specifier?.startsWith('.') ||
|
|
89
72
|
!this.config.styleExtensions.includes(path.extname(specifier))
|
|
90
73
|
) {
|
|
91
74
|
return;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
ModuleStyleBuildConfig,
|
|
3
|
+
ResolvedModuleStyleBuildContext,
|
|
4
4
|
} from '#auklet/types';
|
|
5
5
|
export declare class WorkspaceStyleResolver {
|
|
6
6
|
private readonly config;
|
|
7
7
|
private readonly context;
|
|
8
8
|
private readonly require;
|
|
9
9
|
constructor(
|
|
10
|
-
config:
|
|
11
|
-
context:
|
|
10
|
+
config: ModuleStyleBuildConfig,
|
|
11
|
+
context: ResolvedModuleStyleBuildContext,
|
|
12
12
|
);
|
|
13
13
|
resolveStyleDependency(specifier: string, fromDir?: string): string;
|
|
14
14
|
toOutputStyleSpecifier(specifier: string, outRoot: string): string;
|
|
15
15
|
toExternalStyleSpecifier(specifier: string, outRoot: string): string;
|
|
16
16
|
private getStylePathOutputFormat;
|
|
17
|
-
private parsePackageStyleSpecifier;
|
|
18
17
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
+
import { NODE_MODULES_DIR, STYLE_ENTRY } from '#auklet/css/constants';
|
|
3
4
|
import { POSIX_SEPARATOR } from '#auklet/utils';
|
|
4
|
-
|
|
5
|
-
const PACKAGE_STYLE_FILE = 'style.css';
|
|
5
|
+
import { parsePackageStyleSpecifier } from '#auklet/css/core/style/specifier';
|
|
6
6
|
export class WorkspaceStyleResolver {
|
|
7
|
+
config;
|
|
8
|
+
context;
|
|
9
|
+
require;
|
|
7
10
|
constructor(config, context) {
|
|
8
11
|
this.config = config;
|
|
9
12
|
this.context = context;
|
|
@@ -19,7 +22,7 @@ export class WorkspaceStyleResolver {
|
|
|
19
22
|
return this.require.resolve(specifier, {
|
|
20
23
|
paths: [this.context.packageRoot],
|
|
21
24
|
});
|
|
22
|
-
} catch
|
|
25
|
+
} catch {
|
|
23
26
|
return path.resolve(
|
|
24
27
|
this.context.packageRoot,
|
|
25
28
|
NODE_MODULES_DIR,
|
|
@@ -28,7 +31,7 @@ export class WorkspaceStyleResolver {
|
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
toOutputStyleSpecifier(specifier, outRoot) {
|
|
31
|
-
const parsed =
|
|
34
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
32
35
|
if (!parsed) return specifier;
|
|
33
36
|
const { packageName, stylePath } = parsed;
|
|
34
37
|
const currentOutputFormat = path.basename(outRoot);
|
|
@@ -41,20 +44,20 @@ export class WorkspaceStyleResolver {
|
|
|
41
44
|
return specifier;
|
|
42
45
|
}
|
|
43
46
|
toExternalStyleSpecifier(specifier, outRoot) {
|
|
44
|
-
const parsed =
|
|
47
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
45
48
|
if (!parsed) return specifier;
|
|
46
49
|
const { packageName, stylePath } = parsed;
|
|
47
50
|
const currentOutputFormat = path.basename(outRoot);
|
|
48
51
|
const outputFormat = this.getStylePathOutputFormat(stylePath);
|
|
49
|
-
if (stylePath ===
|
|
50
|
-
return [packageName, this.config.output.
|
|
52
|
+
if (stylePath === STYLE_ENTRY) {
|
|
53
|
+
return [packageName, this.config.output.externalStyleFile].join(
|
|
51
54
|
POSIX_SEPARATOR,
|
|
52
55
|
);
|
|
53
56
|
}
|
|
54
57
|
if (
|
|
55
58
|
outputFormat &&
|
|
56
59
|
outputFormat.path ===
|
|
57
|
-
[this.config.output.styleDir, this.config.output.
|
|
60
|
+
[this.config.output.styleDir, this.config.output.indexStyleFile].join(
|
|
58
61
|
POSIX_SEPARATOR,
|
|
59
62
|
)
|
|
60
63
|
) {
|
|
@@ -62,7 +65,7 @@ export class WorkspaceStyleResolver {
|
|
|
62
65
|
packageName,
|
|
63
66
|
currentOutputFormat,
|
|
64
67
|
this.config.output.styleDir,
|
|
65
|
-
this.config.output.
|
|
68
|
+
this.config.output.externalStyleFile,
|
|
66
69
|
].join(POSIX_SEPARATOR);
|
|
67
70
|
}
|
|
68
71
|
return specifier;
|
|
@@ -78,23 +81,4 @@ export class WorkspaceStyleResolver {
|
|
|
78
81
|
}
|
|
79
82
|
return null;
|
|
80
83
|
}
|
|
81
|
-
parsePackageStyleSpecifier(specifier) {
|
|
82
|
-
var _a, _b, _c;
|
|
83
|
-
if (specifier.startsWith('.')) return null;
|
|
84
|
-
const parts = specifier.split(POSIX_SEPARATOR);
|
|
85
|
-
const packageName = specifier.startsWith('@')
|
|
86
|
-
? `${
|
|
87
|
-
(_a = parts.shift()) !== null && _a !== void 0 ? _a : ''
|
|
88
|
-
}${POSIX_SEPARATOR}${
|
|
89
|
-
(_b = parts.shift()) !== null && _b !== void 0 ? _b : ''
|
|
90
|
-
}`
|
|
91
|
-
: (_c = parts.shift()) !== null && _c !== void 0
|
|
92
|
-
? _c
|
|
93
|
-
: '';
|
|
94
|
-
if (!packageName) return null;
|
|
95
|
-
return {
|
|
96
|
-
packageName,
|
|
97
|
-
stylePath: parts.join(POSIX_SEPARATOR),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
84
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModuleStyleBuildConfig,
|
|
3
|
+
ModuleStyleBuildContext,
|
|
4
|
+
ModuleStyleBuildOptions,
|
|
5
|
+
} from '#auklet/types';
|
|
6
|
+
export declare class ModuleStyleBuilder {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly context;
|
|
9
|
+
private readonly logger?;
|
|
10
|
+
constructor(
|
|
11
|
+
context?: ModuleStyleBuildContext,
|
|
12
|
+
config?: ModuleStyleBuildConfig,
|
|
13
|
+
);
|
|
14
|
+
build(options?: ModuleStyleBuildOptions): Promise<void>;
|
|
15
|
+
private logOutputs;
|
|
16
|
+
private createBuildContext;
|
|
17
|
+
private createPackageContext;
|
|
18
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizeAukletConfig } from '#auklet/config';
|
|
3
|
+
import { moduleStyleBuildConfig } from '#auklet/css/config';
|
|
4
|
+
import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
5
|
+
import { ModuleStyleOutputWriter } from '#auklet/css/production/moduleOutputWriter';
|
|
6
|
+
import { PackageStyleEntryWriter } from '#auklet/css/production/packageEntryWriter';
|
|
7
|
+
import { toPosixPath } from '#auklet/utils';
|
|
8
|
+
export class ModuleStyleBuilder {
|
|
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;
|
|
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());
|
|
39
|
+
}
|
|
40
|
+
this.logOutputs(context, packageContext.styleFiles, outputs, logger);
|
|
41
|
+
}
|
|
42
|
+
logOutputs(context, styleFiles, outputs, logger) {
|
|
43
|
+
logger?.log?.(
|
|
44
|
+
`[auklet:css] ${styleFiles.length} source style file(s), ${outputs.length} output entry file(s)`,
|
|
45
|
+
);
|
|
46
|
+
for (const output of outputs) {
|
|
47
|
+
logger?.log?.(
|
|
48
|
+
`[auklet:css] + ${toPosixPath(
|
|
49
|
+
path.relative(context.packageRoot, output),
|
|
50
|
+
)}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ModuleStyleEntryPlan } from '#auklet/css/core/styleModuleEntryPlanner';
|
|
2
|
+
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
3
|
+
export declare class ComponentStyleEntryWriter {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly sourceRoot;
|
|
6
|
+
private readonly resolver;
|
|
7
|
+
private readonly styleProcessor;
|
|
8
|
+
constructor(options: FormatWriterOptions);
|
|
9
|
+
write(outRoot: string, entries: Array<ModuleStyleEntryPlan>): string[];
|
|
10
|
+
private getModuleStyleSpecifiers;
|
|
11
|
+
private getOwnStyleSpecifiers;
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { emptyModuleEntryComment } from '#auklet/css/production/format/shared';
|
|
4
|
+
import { toPosixPath } from '#auklet/utils';
|
|
5
|
+
export class ComponentStyleEntryWriter {
|
|
6
|
+
config;
|
|
7
|
+
sourceRoot;
|
|
8
|
+
resolver;
|
|
9
|
+
styleProcessor;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.config = options.config;
|
|
12
|
+
this.sourceRoot = options.packageContext.sourceRoot;
|
|
13
|
+
this.resolver = options.packageContext.resolver;
|
|
14
|
+
this.styleProcessor = options.packageContext.styleProcessor;
|
|
15
|
+
}
|
|
16
|
+
write(outRoot, entries) {
|
|
17
|
+
const outputs = [];
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
const styleDir = path.join(
|
|
20
|
+
outRoot,
|
|
21
|
+
entry.sourceDir,
|
|
22
|
+
this.config.output.styleDir,
|
|
23
|
+
);
|
|
24
|
+
const target = path.join(styleDir, this.config.output.indexStyleFile);
|
|
25
|
+
const sourceStyleSpecifiers = [
|
|
26
|
+
...this.getModuleStyleSpecifiers(entry.moduleStyleImports, styleDir),
|
|
27
|
+
...this.getOwnStyleSpecifiers(entry.ownStyleFiles, styleDir, outRoot),
|
|
28
|
+
];
|
|
29
|
+
const root = this.styleProcessor.createRoot();
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (const specifier of sourceStyleSpecifiers) {
|
|
32
|
+
if (seen.has(specifier)) continue;
|
|
33
|
+
seen.add(specifier);
|
|
34
|
+
this.styleProcessor.appendImportRule(
|
|
35
|
+
root,
|
|
36
|
+
this.resolver.toOutputStyleSpecifier(specifier, outRoot),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
fs.mkdirSync(styleDir, { recursive: true });
|
|
40
|
+
fs.writeFileSync(
|
|
41
|
+
target,
|
|
42
|
+
root.nodes?.length
|
|
43
|
+
? this.styleProcessor.stringify(root)
|
|
44
|
+
: emptyModuleEntryComment,
|
|
45
|
+
);
|
|
46
|
+
outputs.push(target);
|
|
47
|
+
}
|
|
48
|
+
return outputs;
|
|
49
|
+
}
|
|
50
|
+
getModuleStyleSpecifiers(specifiers, styleDir) {
|
|
51
|
+
return specifiers.map((specifier) => {
|
|
52
|
+
if (specifier.startsWith('.')) return specifier;
|
|
53
|
+
if (!path.isAbsolute(specifier)) return specifier;
|
|
54
|
+
return toPosixPath(path.relative(styleDir, specifier));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getOwnStyleSpecifiers(ownStyleFiles, styleDir, outRoot) {
|
|
58
|
+
return ownStyleFiles.map((styleFile) =>
|
|
59
|
+
toPosixPath(
|
|
60
|
+
path.relative(
|
|
61
|
+
styleDir,
|
|
62
|
+
path.join(outRoot, path.relative(this.sourceRoot, styleFile)),
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
|
+
export declare class StyleEntryWriter {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly packageContext;
|
|
5
|
+
private readonly styleProcessor;
|
|
6
|
+
constructor(options: FormatWriterOptions);
|
|
7
|
+
write(
|
|
8
|
+
outRoot: string,
|
|
9
|
+
themeStyles: Map<string, string>,
|
|
10
|
+
moduleStyle: string | null,
|
|
11
|
+
): string | null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createStyleEntryParts } from '#auklet/css/core/style/plan';
|
|
4
|
+
import { toRelativeImportSpecifier } from '#auklet/css/production/format/shared';
|
|
5
|
+
export class StyleEntryWriter {
|
|
6
|
+
config;
|
|
7
|
+
packageContext;
|
|
8
|
+
styleProcessor;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.config = options.config;
|
|
11
|
+
this.packageContext = options.packageContext;
|
|
12
|
+
this.styleProcessor = options.packageContext.styleProcessor;
|
|
13
|
+
}
|
|
14
|
+
write(outRoot, themeStyles, moduleStyle) {
|
|
15
|
+
const target = path.join(
|
|
16
|
+
outRoot,
|
|
17
|
+
this.config.output.styleDir,
|
|
18
|
+
this.config.output.indexStyleFile,
|
|
19
|
+
);
|
|
20
|
+
const root = this.styleProcessor.createRoot();
|
|
21
|
+
const styleDir = path.dirname(target);
|
|
22
|
+
for (const part of createStyleEntryParts(
|
|
23
|
+
this.packageContext.normalizedConfig,
|
|
24
|
+
)) {
|
|
25
|
+
if (part.type === 'dependencies') {
|
|
26
|
+
for (const specifier of part.specifiers) {
|
|
27
|
+
this.styleProcessor.appendImportRule(root, specifier);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (part.type === 'themes') {
|
|
32
|
+
for (const themeName of part.themeNames) {
|
|
33
|
+
const themeStyle = themeStyles.get(themeName);
|
|
34
|
+
if (!themeStyle) continue;
|
|
35
|
+
this.styleProcessor.appendImportRule(
|
|
36
|
+
root,
|
|
37
|
+
toRelativeImportSpecifier(styleDir, themeStyle),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (moduleStyle) {
|
|
43
|
+
this.styleProcessor.appendImportRule(
|
|
44
|
+
root,
|
|
45
|
+
toRelativeImportSpecifier(styleDir, moduleStyle),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!root.nodes?.length) return null;
|
|
50
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
51
|
+
fs.writeFileSync(target, this.styleProcessor.stringify(root));
|
|
52
|
+
return target;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
|
+
export declare class ExternalStyleWriter {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly packageContext;
|
|
5
|
+
private readonly resolver;
|
|
6
|
+
private readonly styleProcessor;
|
|
7
|
+
constructor(options: FormatWriterOptions);
|
|
8
|
+
write(outRoot: string): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createExternalEntryParts } from '#auklet/css/core/style/plan';
|
|
4
|
+
export class ExternalStyleWriter {
|
|
5
|
+
config;
|
|
6
|
+
packageContext;
|
|
7
|
+
resolver;
|
|
8
|
+
styleProcessor;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.config = options.config;
|
|
11
|
+
this.packageContext = options.packageContext;
|
|
12
|
+
this.resolver = options.packageContext.resolver;
|
|
13
|
+
this.styleProcessor = options.packageContext.styleProcessor;
|
|
14
|
+
}
|
|
15
|
+
write(outRoot) {
|
|
16
|
+
const target = path.join(
|
|
17
|
+
outRoot,
|
|
18
|
+
this.config.output.styleDir,
|
|
19
|
+
this.config.output.externalStyleFile,
|
|
20
|
+
);
|
|
21
|
+
const root = this.styleProcessor.createRoot();
|
|
22
|
+
for (const part of createExternalEntryParts(
|
|
23
|
+
this.packageContext.normalizedConfig,
|
|
24
|
+
)) {
|
|
25
|
+
for (const specifier of part.specifiers) {
|
|
26
|
+
this.styleProcessor.appendImportRule(
|
|
27
|
+
root,
|
|
28
|
+
this.resolver.toExternalStyleSpecifier(specifier, outRoot),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
33
|
+
fs.writeFileSync(
|
|
34
|
+
target,
|
|
35
|
+
root.nodes?.length ? this.styleProcessor.stringify(root) : '',
|
|
36
|
+
);
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
|
+
export declare class ModuleStyleWriter {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly packageContext;
|
|
5
|
+
private readonly styleProcessor;
|
|
6
|
+
constructor(options: FormatWriterOptions);
|
|
7
|
+
write(outRoot: string): string | null;
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export class ModuleStyleWriter {
|
|
4
|
+
config;
|
|
5
|
+
packageContext;
|
|
6
|
+
styleProcessor;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.config = options.config;
|
|
9
|
+
this.packageContext = options.packageContext;
|
|
10
|
+
this.styleProcessor = options.packageContext.styleProcessor;
|
|
11
|
+
}
|
|
12
|
+
write(outRoot) {
|
|
13
|
+
const target = path.join(
|
|
14
|
+
outRoot,
|
|
15
|
+
this.config.output.styleDir,
|
|
16
|
+
this.config.output.moduleStyleFile,
|
|
17
|
+
);
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
const root = this.styleProcessor.createRoot();
|
|
20
|
+
for (const styleFile of this.packageContext.styleFiles) {
|
|
21
|
+
const content = this.styleProcessor.readStyleFile(styleFile, seen);
|
|
22
|
+
if (content.trim()) {
|
|
23
|
+
this.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!root.nodes?.length) return null;
|
|
27
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
28
|
+
fs.writeFileSync(target, this.styleProcessor.stringify(root));
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
2
|
+
import type {
|
|
3
|
+
ModuleStyleBuildConfig,
|
|
4
|
+
ResolvedModuleStyleBuildContext,
|
|
5
|
+
} from '#auklet/types';
|
|
6
|
+
export declare const emptyModuleEntryComment =
|
|
7
|
+
'/* Empty style entry kept so automated tooling can resolve this module CSS path. */\n';
|
|
8
|
+
export type FormatWriterOptions = {
|
|
9
|
+
config: ModuleStyleBuildConfig;
|
|
10
|
+
context: ResolvedModuleStyleBuildContext;
|
|
11
|
+
packageContext: StylePackageContext;
|
|
12
|
+
};
|
|
13
|
+
export type ThemeStyleOutput = {
|
|
14
|
+
themeName: string;
|
|
15
|
+
file: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function toRelativeImportSpecifier(
|
|
18
|
+
fromDir: string,
|
|
19
|
+
file: string,
|
|
20
|
+
): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { toPosixPath } from '#auklet/utils';
|
|
3
|
+
export const emptyModuleEntryComment =
|
|
4
|
+
'/* Empty style entry kept so automated tooling can resolve this module CSS path. */\n';
|
|
5
|
+
export function toRelativeImportSpecifier(fromDir, file) {
|
|
6
|
+
const relative = toPosixPath(path.relative(fromDir, file));
|
|
7
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
8
|
+
}
|