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.
- package/README.md +37 -1
- 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 +7 -7
- package/dist/css/constants.js +1 -1
- 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 +22 -33
- 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 +41 -8
- package/dist/css/core/style/specifier.js +107 -18
- package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
- package/dist/css/core/styleImports/autoImportRules.js +68 -0
- package/dist/css/core/styleImports/collector.d.ts +12 -25
- package/dist/css/core/styleImports/collector.js +101 -206
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
- package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
- package/dist/css/core/styleModuleEntryPlanner.js +45 -62
- 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 +8 -15
- package/dist/css/core/workspaceStyleResolver.js +34 -76
- package/dist/css/production/builder.d.ts +9 -16
- package/dist/css/production/builder.js +51 -57
- package/dist/css/production/format/entryWriter.js +36 -49
- package/dist/css/production/format/externalWriter.js +21 -33
- package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
- package/dist/css/production/format/moduleEntryWriter.js +48 -0
- 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 +4 -9
- 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 +58 -67
- 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 +51 -50
- 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 +16 -7
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
- 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 +173 -264
- 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 +117 -109
- package/dist/css/watch/watcher.d.ts +15 -21
- package/dist/css/watch/watcher.js +84 -81
- 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
- package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
- package/dist/css/core/styleImports/sourceReference.js +0 -193
- package/dist/css/production/format/componentWriter.js +0 -71
|
@@ -1,67 +1,50 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { SOURCE_MODULE_RE } from '#auklet/css/constants';
|
|
3
3
|
import { groupStyleFilesByDir } from '#auklet/css/core/style/files';
|
|
4
4
|
import { getSourceModuleDir, toPosixPath } from '#auklet/utils';
|
|
5
5
|
export class StyleModuleEntryPlanner {
|
|
6
|
-
|
|
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
|
-
return toPosixPath(sourceModuleDir).split('/').length === 2;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
getOwnStyleDirs() {
|
|
54
|
-
return Array.from(this.styleFilesByDir.entries())
|
|
55
|
-
.filter(([, dirStyleFiles]) =>
|
|
56
|
-
dirStyleFiles.some(
|
|
57
|
-
(styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)),
|
|
58
|
-
),
|
|
59
|
-
)
|
|
60
|
-
.map(([sourceDir]) => sourceDir);
|
|
61
|
-
}
|
|
62
|
-
getOwnStyleFiles(sourceDir) {
|
|
63
|
-
return (this.styleFilesByDir.get(sourceDir) ?? []).filter(
|
|
64
|
-
(styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)),
|
|
65
|
-
);
|
|
66
|
-
}
|
|
6
|
+
packageContext;
|
|
7
|
+
importedStyleFiles;
|
|
8
|
+
styleFilesByDir;
|
|
9
|
+
constructor(packageContext) {
|
|
10
|
+
this.packageContext = packageContext;
|
|
11
|
+
this.styleFilesByDir = groupStyleFilesByDir(this.packageContext.sourceRoot, this.packageContext.styleFiles);
|
|
12
|
+
this.importedStyleFiles =
|
|
13
|
+
this.packageContext.styleProcessor.collectImportedStyleFiles(this.packageContext.styleFiles);
|
|
14
|
+
}
|
|
15
|
+
createEntries(moduleStyleImports) {
|
|
16
|
+
return this.getSourceDirs(moduleStyleImports).map((sourceDir) => this.createEntry(sourceDir, moduleStyleImports));
|
|
17
|
+
}
|
|
18
|
+
createEntry(sourceDir, moduleStyleImports) {
|
|
19
|
+
return {
|
|
20
|
+
sourceDir,
|
|
21
|
+
moduleStyleImports: moduleStyleImports.get(sourceDir) ?? [],
|
|
22
|
+
ownStyleFiles: this.getOwnStyleFiles(sourceDir),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
getSourceDirs(moduleStyleImports) {
|
|
26
|
+
return Array.from(new Set([
|
|
27
|
+
...this.getSourceModuleDirs(),
|
|
28
|
+
...this.getOwnStyleDirs(),
|
|
29
|
+
...moduleStyleImports.keys(),
|
|
30
|
+
])).filter((sourceDir) => sourceDir !== '.');
|
|
31
|
+
}
|
|
32
|
+
getSourceModuleDirs() {
|
|
33
|
+
return this.packageContext.sourceFiles
|
|
34
|
+
.filter((sourceFile) => SOURCE_MODULE_RE.test(sourceFile))
|
|
35
|
+
.map((sourceFile) => {
|
|
36
|
+
return getSourceModuleDir(path.relative(this.packageContext.sourceRoot, sourceFile));
|
|
37
|
+
})
|
|
38
|
+
.filter((sourceModuleDir) => {
|
|
39
|
+
return toPosixPath(sourceModuleDir).split('/').length === 2;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getOwnStyleDirs() {
|
|
43
|
+
return Array.from(this.styleFilesByDir.entries())
|
|
44
|
+
.filter(([, dirStyleFiles]) => dirStyleFiles.some((styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile))))
|
|
45
|
+
.map(([sourceDir]) => sourceDir);
|
|
46
|
+
}
|
|
47
|
+
getOwnStyleFiles(sourceDir) {
|
|
48
|
+
return (this.styleFilesByDir.get(sourceDir) ?? []).filter((styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)));
|
|
49
|
+
}
|
|
67
50
|
}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { ModuleStyleImportCollector } from '#auklet/css/core/styleImports/collector';
|
|
2
2
|
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
3
3
|
import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
4
|
-
import type {
|
|
5
|
-
ModuleStyleBuildConfig,
|
|
6
|
-
NormalizedAukletConfig,
|
|
7
|
-
ResolvedModuleStyleBuildContext,
|
|
8
|
-
} from '#auklet/types';
|
|
4
|
+
import type { ModuleStyleBuildConfig, NormalizedAukletConfig, ResolvedModuleStyleBuildContext } from '#auklet/types';
|
|
9
5
|
export type StylePackageContextOptions = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
config: ModuleStyleBuildConfig;
|
|
7
|
+
context: ResolvedModuleStyleBuildContext;
|
|
8
|
+
normalizedConfig: NormalizedAukletConfig;
|
|
13
9
|
};
|
|
14
10
|
export declare class StylePackageContext {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
private readonly options;
|
|
12
|
+
readonly normalizedConfig: NormalizedAukletConfig;
|
|
13
|
+
readonly sourceRoot: string;
|
|
14
|
+
readonly resolver: WorkspaceStyleResolver;
|
|
15
|
+
readonly styleProcessor: StyleProcessor;
|
|
16
|
+
readonly importCollector: ModuleStyleImportCollector;
|
|
17
|
+
readonly sourceFiles: Array<string>;
|
|
18
|
+
readonly themeFiles: Map<string, string>;
|
|
19
|
+
readonly themeNames: Array<string>;
|
|
20
|
+
readonly styleFiles: Array<string>;
|
|
21
|
+
constructor(options: StylePackageContextOptions);
|
|
22
|
+
getStyleFiles(files: Array<string>): string[];
|
|
27
23
|
}
|
|
@@ -3,55 +3,39 @@ import path from 'node:path';
|
|
|
3
3
|
import { ModuleStyleImportCollector } from '#auklet/css/core/styleImports/collector';
|
|
4
4
|
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
5
5
|
import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
createStyleFileKeySet,
|
|
9
|
-
} from '#auklet/css/core/style/files';
|
|
10
|
-
import {
|
|
11
|
-
getThemeNames,
|
|
12
|
-
resolveThemeStyleFiles,
|
|
13
|
-
} from '#auklet/css/core/style/dependencies';
|
|
6
|
+
import { createStyleFileKey, createStyleFileKeySet, } from '#auklet/css/core/style/files';
|
|
7
|
+
import { getThemeNames, resolveThemeStyleFiles, } from '#auklet/css/core/style/dependencies';
|
|
14
8
|
import { fileWalker } from '#auklet/utils';
|
|
15
9
|
export class StylePackageContext {
|
|
16
|
-
|
|
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
|
-
this.styleFiles = this.getStyleFiles(this.sourceFiles);
|
|
48
|
-
}
|
|
49
|
-
getStyleFiles(files) {
|
|
50
|
-
const themeFileKeys = createStyleFileKeySet(this.themeFiles.values());
|
|
51
|
-
return files
|
|
52
|
-
.filter((file) =>
|
|
53
|
-
this.options.config.styleExtensions.includes(path.extname(file)),
|
|
54
|
-
)
|
|
55
|
-
.filter((styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)));
|
|
56
|
-
}
|
|
10
|
+
options;
|
|
11
|
+
normalizedConfig;
|
|
12
|
+
sourceRoot;
|
|
13
|
+
resolver;
|
|
14
|
+
styleProcessor;
|
|
15
|
+
importCollector;
|
|
16
|
+
sourceFiles;
|
|
17
|
+
themeFiles;
|
|
18
|
+
themeNames;
|
|
19
|
+
styleFiles;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
const { config, context, normalizedConfig } = this.options;
|
|
23
|
+
this.normalizedConfig = normalizedConfig;
|
|
24
|
+
this.sourceRoot = path.join(context.packageRoot, context.sourceDir);
|
|
25
|
+
this.resolver = new WorkspaceStyleResolver(config, context);
|
|
26
|
+
this.styleProcessor = new StyleProcessor(config, this.resolver);
|
|
27
|
+
this.importCollector = new ModuleStyleImportCollector(this.sourceRoot, context.packageRoot, this.resolver, config.styleExtensions);
|
|
28
|
+
this.sourceFiles = fs.existsSync(this.sourceRoot)
|
|
29
|
+
? fileWalker(this.sourceRoot)
|
|
30
|
+
: [];
|
|
31
|
+
this.themeFiles = resolveThemeStyleFiles(normalizedConfig, context.packageRoot);
|
|
32
|
+
this.themeNames = getThemeNames(normalizedConfig);
|
|
33
|
+
this.styleFiles = this.getStyleFiles(this.sourceFiles);
|
|
34
|
+
}
|
|
35
|
+
getStyleFiles(files) {
|
|
36
|
+
const themeFileKeys = createStyleFileKeySet(this.themeFiles.values());
|
|
37
|
+
return files
|
|
38
|
+
.filter((file) => this.options.config.styleExtensions.includes(path.extname(file)))
|
|
39
|
+
.filter((styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)));
|
|
40
|
+
}
|
|
57
41
|
}
|
|
@@ -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,10 @@
|
|
|
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
|
-
resolveStyleDependency(specifier: string, fromDir?: string): string;
|
|
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;
|
|
17
10
|
}
|
|
@@ -1,84 +1,42 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { NODE_MODULES_DIR
|
|
4
|
-
import {
|
|
5
|
-
import { parsePackageStyleSpecifier } from '#auklet/css/core/style/specifier';
|
|
3
|
+
import { NODE_MODULES_DIR } from '#auklet/css/constants';
|
|
4
|
+
import { createExternalStyleSpecifier, createOutputStyleSpecifier, } from '#auklet/css/core/style/specifier';
|
|
6
5
|
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);
|
|
6
|
+
config;
|
|
7
|
+
context;
|
|
8
|
+
require;
|
|
9
|
+
constructor(config, context) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.require = createRequire(path.join(this.context.packageRoot, 'package.json'));
|
|
20
13
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
resolveStyleDependency(specifier, fromDir = this.context.packageRoot) {
|
|
15
|
+
if (specifier.startsWith('.')) {
|
|
16
|
+
return path.resolve(fromDir, specifier);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return this.require.resolve(specifier, {
|
|
20
|
+
paths: [this.context.packageRoot],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return path.resolve(this.context.packageRoot, NODE_MODULES_DIR, specifier);
|
|
25
|
+
}
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const currentOutputFormat = path.basename(outRoot);
|
|
38
|
-
const outputFormat = this.getStylePathOutputFormat(stylePath);
|
|
39
|
-
if (outputFormat) {
|
|
40
|
-
return [packageName, currentOutputFormat, outputFormat.path].join(
|
|
41
|
-
POSIX_SEPARATOR,
|
|
42
|
-
);
|
|
27
|
+
toOutputStyleSpecifier(specifier, outRoot) {
|
|
28
|
+
return createOutputStyleSpecifier(specifier, {
|
|
29
|
+
currentOutputFormat: path.basename(outRoot),
|
|
30
|
+
outputFormats: this.config.output.outputFormats,
|
|
31
|
+
});
|
|
43
32
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (stylePath === STYLE_ENTRY) {
|
|
53
|
-
return [packageName, this.config.output.externalStyleFile].join(
|
|
54
|
-
POSIX_SEPARATOR,
|
|
55
|
-
);
|
|
33
|
+
toExternalStyleSpecifier(specifier, outRoot) {
|
|
34
|
+
return createExternalStyleSpecifier(specifier, {
|
|
35
|
+
currentOutputFormat: path.basename(outRoot),
|
|
36
|
+
outputFormats: this.config.output.outputFormats,
|
|
37
|
+
styleDir: this.config.output.styleDir,
|
|
38
|
+
indexStyleFile: this.config.output.indexStyleFile,
|
|
39
|
+
externalStyleFile: this.config.output.externalStyleFile,
|
|
40
|
+
});
|
|
56
41
|
}
|
|
57
|
-
if (
|
|
58
|
-
outputFormat &&
|
|
59
|
-
outputFormat.path ===
|
|
60
|
-
[this.config.output.styleDir, this.config.output.indexStyleFile].join(
|
|
61
|
-
POSIX_SEPARATOR,
|
|
62
|
-
)
|
|
63
|
-
) {
|
|
64
|
-
return [
|
|
65
|
-
packageName,
|
|
66
|
-
currentOutputFormat,
|
|
67
|
-
this.config.output.styleDir,
|
|
68
|
-
this.config.output.externalStyleFile,
|
|
69
|
-
].join(POSIX_SEPARATOR);
|
|
70
|
-
}
|
|
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
42
|
}
|
|
@@ -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
|
}
|