auklet 0.0.14 → 0.0.16
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/tsdownConfig.d.ts +2 -6
- package/dist/css/core/styleProcessor.d.ts +12 -11
- package/dist/css/core/styleProcessor.js +12 -0
- package/dist/css/production/format/componentWriter.d.ts +8 -8
- package/dist/css/production/format/componentWriter.js +9 -1
- package/dist/css/production/format/entryWriter.d.ts +5 -9
- package/dist/css/production/format/externalWriter.d.ts +6 -6
- package/dist/css/production/format/moduleWriter.d.ts +5 -5
- package/dist/css/production/format/sourceWriter.d.ts +3 -3
- package/dist/css/production/format/themeWriter.d.ts +8 -14
- package/dist/css/vite/hmr.js +2 -2
- package/dist/css/vite/moduleGraph/graph.d.ts +3 -4
- package/dist/css/vite/moduleGraph/graph.js +22 -34
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +9 -0
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +77 -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 +4 -7
- package/dist/css/vite/moduleGraph/requestCache.js +9 -44
- package/dist/css/vite/moduleGraph/styleCodeFactory.js +2 -2
- package/dist/css/vite/moduleGraph/types.d.ts +1 -0
- package/dist/css/vite/vitePlugin.d.ts +1 -1
- package/dist/css/vite/vitePlugin.js +3 -3
- package/package.json +20 -19
package/bin/entry.cjs
CHANGED
|
@@ -45,9 +45,8 @@ const runBuildStyle = async (args, options = {}) => {
|
|
|
45
45
|
return 0;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const { ModuleStyleBuilder } =
|
|
49
|
-
'../dist/css/production/builder.js'
|
|
50
|
-
);
|
|
48
|
+
const { ModuleStyleBuilder } =
|
|
49
|
+
await import('../dist/css/production/builder.js');
|
|
51
50
|
const builder = new ModuleStyleBuilder({ aukletConfig, logger: console });
|
|
52
51
|
await builder.build();
|
|
53
52
|
return 0;
|
|
@@ -60,9 +59,8 @@ const runBuildJs = async (args) => {
|
|
|
60
59
|
|
|
61
60
|
const runBuild = async (args) => {
|
|
62
61
|
const aukletConfig = await loadCurrentAukletConfig();
|
|
63
|
-
const { cleanAukletOutputByConfig } =
|
|
64
|
-
'../dist/build/cleanOutput.js'
|
|
65
|
-
);
|
|
62
|
+
const { cleanAukletOutputByConfig } =
|
|
63
|
+
await import('../dist/build/cleanOutput.js');
|
|
66
64
|
cleanAukletOutputByConfig(process.cwd(), aukletConfig);
|
|
67
65
|
|
|
68
66
|
const jsExitCode = await runBuildJs(args);
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
defineKernelPackageConfigFromFile,
|
|
4
|
-
defineKernelPackageConfigFromOptions,
|
|
5
|
-
} from '#auklet/build/tsdown/define';
|
|
6
|
-
declare const _default: Promise<import('tsdown/config').UserConfig[]>;
|
|
1
|
+
export { type TsdownFormat, defineKernelPackageConfigFromFile, defineKernelPackageConfigFromOptions, } from '#auklet/build/tsdown/define';
|
|
2
|
+
declare const _default: Promise<import("tsdown/config").UserConfig[]>;
|
|
7
3
|
export default _default;
|
|
@@ -2,15 +2,16 @@ import postcss, { type Root } from 'postcss';
|
|
|
2
2
|
import type { ModuleStyleBuildConfig } from '#auklet/types';
|
|
3
3
|
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
4
4
|
export declare class StyleProcessor {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly resolver;
|
|
7
|
+
constructor(config: ModuleStyleBuildConfig, resolver: WorkspaceStyleResolver);
|
|
8
|
+
createRoot(): postcss.Root;
|
|
9
|
+
appendImportRule(root: Root, specifier: string): void;
|
|
10
|
+
stringify(root: Root): string;
|
|
11
|
+
appendStyleContent(target: Root, content: string, from: string): void;
|
|
12
|
+
readStyleFile(stylePath: string, seen?: Set<string>): string;
|
|
13
|
+
collectImportedStyleFiles(styleFiles: Array<string>): Set<string>;
|
|
14
|
+
collectStyleImportSpecifiers(styleFiles: Array<string>): Set<string>;
|
|
15
|
+
private parse;
|
|
16
|
+
private parseImportSpecifier;
|
|
16
17
|
}
|
|
@@ -78,6 +78,18 @@ export class StyleProcessor {
|
|
|
78
78
|
}
|
|
79
79
|
return imported;
|
|
80
80
|
}
|
|
81
|
+
collectStyleImportSpecifiers(styleFiles) {
|
|
82
|
+
const specifiers = new Set();
|
|
83
|
+
for (const styleFile of styleFiles) {
|
|
84
|
+
const css = fs.readFileSync(styleFile, 'utf8');
|
|
85
|
+
const root = this.parse(css, styleFile);
|
|
86
|
+
root.walkAtRules('import', (rule) => {
|
|
87
|
+
const specifier = this.parseImportSpecifier(rule.params);
|
|
88
|
+
if (specifier) specifiers.add(specifier);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return specifiers;
|
|
92
|
+
}
|
|
81
93
|
parse(code, from) {
|
|
82
94
|
// Keep parsing behind one method so future style languages can transform
|
|
83
95
|
// to CSS before PostCSS reads the final stylesheet.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ModuleStyleEntryPlan } from '#auklet/css/core/styleModuleEntryPlanner';
|
|
2
2
|
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
3
3
|
export declare class ComponentStyleEntryWriter {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
12
|
}
|
|
@@ -21,8 +21,16 @@ export class ComponentStyleEntryWriter {
|
|
|
21
21
|
this.config.output.styleDir,
|
|
22
22
|
);
|
|
23
23
|
const target = path.join(styleDir, this.config.output.indexStyleFile);
|
|
24
|
+
const ownImports = this.styleProcessor.collectStyleImportSpecifiers(
|
|
25
|
+
entry.ownStyleFiles,
|
|
26
|
+
);
|
|
24
27
|
const sourceStyleSpecifiers = [
|
|
25
|
-
...this.getModuleStyleSpecifiers(
|
|
28
|
+
...this.getModuleStyleSpecifiers(
|
|
29
|
+
entry.moduleStyleImports.filter(
|
|
30
|
+
(specifier) => !ownImports.has(specifier),
|
|
31
|
+
),
|
|
32
|
+
styleDir,
|
|
33
|
+
),
|
|
26
34
|
...this.getOwnStyleSpecifiers(entry.ownStyleFiles, styleDir, outRoot),
|
|
27
35
|
];
|
|
28
36
|
const root = this.styleProcessor.createRoot();
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
2
|
export declare class StyleEntryWriter {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
outRoot: string,
|
|
9
|
-
themeStyles: Map<string, string>,
|
|
10
|
-
moduleStyle: string | null,
|
|
11
|
-
): string | null;
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly packageContext;
|
|
5
|
+
private readonly styleProcessor;
|
|
6
|
+
constructor(options: FormatWriterOptions);
|
|
7
|
+
write(outRoot: string, themeStyles: Map<string, string>, moduleStyle: string | null): string | null;
|
|
12
8
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
2
|
export declare class ExternalStyleWriter {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
2
|
export declare class ModuleStyleWriter {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly packageContext;
|
|
5
|
+
private readonly styleProcessor;
|
|
6
|
+
constructor(options: FormatWriterOptions);
|
|
7
|
+
write(outRoot: string): string | null;
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FormatWriterOptions } from '#auklet/css/production/format/shared';
|
|
2
2
|
export declare class SourceStyleFileWriter {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
private readonly sourceRoot;
|
|
4
|
+
constructor(options: FormatWriterOptions);
|
|
5
|
+
copy(files: Array<string>, outRoot: string): void;
|
|
6
6
|
}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type FormatWriterOptions,
|
|
3
|
-
type ThemeStyleOutput,
|
|
4
|
-
} from '#auklet/css/production/format/shared';
|
|
1
|
+
import { type FormatWriterOptions, type ThemeStyleOutput } from '#auklet/css/production/format/shared';
|
|
5
2
|
export declare class ThemeStyleWriter {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
themeStyles: Map<string, string>,
|
|
14
|
-
outRoot: string,
|
|
15
|
-
): string[];
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly packageContext;
|
|
5
|
+
private readonly styleProcessor;
|
|
6
|
+
constructor(options: FormatWriterOptions);
|
|
7
|
+
clean(outRoot: string): void;
|
|
8
|
+
writeThemeStyles(outRoot: string): ThemeStyleOutput[];
|
|
9
|
+
writeThemeEntries(themeStyles: Map<string, string>, outRoot: string): string[];
|
|
16
10
|
}
|
package/dist/css/vite/hmr.js
CHANGED
|
@@ -18,7 +18,7 @@ const getRelativeFile = (file) => {
|
|
|
18
18
|
};
|
|
19
19
|
const invalidateVirtualModules = (server, graph) => {
|
|
20
20
|
const modules = [];
|
|
21
|
-
for (const packageName of graph.
|
|
21
|
+
for (const packageName of graph.getPackageNames()) {
|
|
22
22
|
for (const entry of ['style.css', 'external.css', 'module.css']) {
|
|
23
23
|
const module = server.moduleGraph.getModuleById(
|
|
24
24
|
`\0auklet-css:${packageName}/${entry}`,
|
|
@@ -77,7 +77,7 @@ export class AukletStyleHmr {
|
|
|
77
77
|
handleStyleHotUpdate(context) {
|
|
78
78
|
const graph = this.graph();
|
|
79
79
|
if (
|
|
80
|
-
!graph.
|
|
80
|
+
!graph.isSourceGraphFile(context.file) ||
|
|
81
81
|
!graph.isStyleFile(context.file)
|
|
82
82
|
) {
|
|
83
83
|
return;
|
|
@@ -4,8 +4,7 @@ import type {
|
|
|
4
4
|
} from '#auklet/css/vite/moduleGraph/types';
|
|
5
5
|
export declare class ModuleStyleGraph {
|
|
6
6
|
private readonly config;
|
|
7
|
-
private readonly
|
|
8
|
-
private readonly packagesDir;
|
|
7
|
+
private readonly packageSource;
|
|
9
8
|
private readonly styleCodeFactory;
|
|
10
9
|
private readonly loadAukletConfig;
|
|
11
10
|
constructor(options: ModuleStyleGraphOptions);
|
|
@@ -13,10 +12,10 @@ export declare class ModuleStyleGraph {
|
|
|
13
12
|
packageName: string;
|
|
14
13
|
stylePath: string;
|
|
15
14
|
} | null;
|
|
16
|
-
|
|
15
|
+
isSourceGraphFile(file: string): boolean;
|
|
17
16
|
isStyleConfigFile(file: string): boolean;
|
|
18
17
|
isStyleFile(file: string): boolean;
|
|
19
|
-
|
|
18
|
+
getPackageNames(): string[];
|
|
20
19
|
getWatchRoots(): string[];
|
|
21
20
|
createPackageStyleCode(parsed: PackageStyleId): Promise<{
|
|
22
21
|
code: string;
|
|
@@ -2,43 +2,36 @@ import path from 'node:path';
|
|
|
2
2
|
import { aukletConfigFile } from '#auklet/config';
|
|
3
3
|
import { loadAukletConfig } from '#auklet/configLoader';
|
|
4
4
|
import { moduleStyleBuildConfig } from '#auklet/css/config';
|
|
5
|
-
import { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
|
|
6
|
-
import { StyleCodeFactory } from '#auklet/css/vite/moduleGraph/styleCodeFactory';
|
|
7
5
|
import { parsePackageStyleId } from '#auklet/css/vite/moduleGraph/styleId';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
6
|
+
import { StyleCodeFactory } from '#auklet/css/vite/moduleGraph/styleCodeFactory';
|
|
7
|
+
import { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
|
|
8
|
+
import { createMonorepoPackageSource } from '#auklet/css/vite/moduleGraph/packageSource/monorepo';
|
|
9
|
+
import { normalizeFileKey } from '#auklet/utils';
|
|
10
|
+
// package style graph 的对外门面,负责 package source、watch 边界和请求分发。
|
|
11
11
|
export class ModuleStyleGraph {
|
|
12
12
|
config;
|
|
13
|
-
|
|
14
|
-
packagesDir;
|
|
13
|
+
packageSource;
|
|
15
14
|
styleCodeFactory;
|
|
16
15
|
loadAukletConfig;
|
|
17
16
|
constructor(options) {
|
|
18
17
|
this.config = options.config ?? moduleStyleBuildConfig;
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const mode = options.mode ?? 'monorepo';
|
|
19
|
+
if (mode === 'package') {
|
|
20
|
+
throw new Error('[auklet:css] package mode is not supported yet.');
|
|
21
|
+
}
|
|
22
|
+
this.packageSource = createMonorepoPackageSource({
|
|
23
|
+
workspaceRoot: normalizeFileKey(options.workspaceRoot),
|
|
24
|
+
packagesDir: options.packagesDir ?? 'packages',
|
|
25
|
+
styleExtensions: this.config.styleExtensions,
|
|
26
|
+
});
|
|
21
27
|
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
22
28
|
this.styleCodeFactory = new StyleCodeFactory(this.config);
|
|
23
29
|
}
|
|
24
30
|
parsePackageStyleId(id) {
|
|
25
|
-
return parsePackageStyleId(id, this.
|
|
31
|
+
return parsePackageStyleId(id, this.getPackageNames());
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const packagesRoot = normalizeFileKey(
|
|
30
|
-
path.join(this.workspaceRoot, this.packagesDir),
|
|
31
|
-
);
|
|
32
|
-
if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
if (normalizedFile.endsWith(aukletConfigFile)) return true;
|
|
36
|
-
if (SOURCE_COMPONENT_MODULE_RE.test(normalizedFile)) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return this.config.styleExtensions.some((extension) =>
|
|
40
|
-
normalizedFile.endsWith(extension),
|
|
41
|
-
);
|
|
33
|
+
isSourceGraphFile(file) {
|
|
34
|
+
return this.packageSource.isSourceGraphFile(file);
|
|
42
35
|
}
|
|
43
36
|
isStyleConfigFile(file) {
|
|
44
37
|
return normalizeFileKey(file).endsWith(aukletConfigFile);
|
|
@@ -46,15 +39,11 @@ export class ModuleStyleGraph {
|
|
|
46
39
|
isStyleFile(file) {
|
|
47
40
|
return this.config.styleExtensions.includes(path.extname(file));
|
|
48
41
|
}
|
|
49
|
-
|
|
50
|
-
return this.
|
|
42
|
+
getPackageNames() {
|
|
43
|
+
return this.packageSource.getPackageNames();
|
|
51
44
|
}
|
|
52
45
|
getWatchRoots() {
|
|
53
|
-
|
|
54
|
-
return [
|
|
55
|
-
toWatchPath(packagesRoot, '*', 'src'),
|
|
56
|
-
toWatchPath(packagesRoot, '*', aukletConfigFile),
|
|
57
|
-
];
|
|
46
|
+
return this.packageSource.getWatchRoots();
|
|
58
47
|
}
|
|
59
48
|
createPackageStyleCode(parsed) {
|
|
60
49
|
return this.styleCodeFactory.createPackageStyleCode(
|
|
@@ -64,8 +53,7 @@ export class ModuleStyleGraph {
|
|
|
64
53
|
}
|
|
65
54
|
createRequestCache() {
|
|
66
55
|
return new ModuleStyleGraphRequestCache({
|
|
67
|
-
|
|
68
|
-
packagesDir: this.packagesDir,
|
|
56
|
+
packageSource: this.packageSource,
|
|
69
57
|
config: this.config,
|
|
70
58
|
loadAukletConfig: this.loadAukletConfig,
|
|
71
59
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
|
|
2
|
+
export type MonorepoPackageSourceOptions = {
|
|
3
|
+
workspaceRoot: string;
|
|
4
|
+
packagesDir: string;
|
|
5
|
+
styleExtensions: Array<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare function createMonorepoPackageSource(
|
|
8
|
+
options: MonorepoPackageSourceOptions,
|
|
9
|
+
): StylePackageSource;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { aukletConfigFile } from '#auklet/config';
|
|
4
|
+
import { SOURCE_COMPONENT_MODULE_RE } from '#auklet/css/constants';
|
|
5
|
+
import { normalizeFileKey, toWatchPath } from '#auklet/utils';
|
|
6
|
+
export function createMonorepoPackageSource(options) {
|
|
7
|
+
return new MonorepoPackageSource(options);
|
|
8
|
+
}
|
|
9
|
+
class MonorepoPackageSource {
|
|
10
|
+
options;
|
|
11
|
+
packages;
|
|
12
|
+
packageNames;
|
|
13
|
+
workspaceRoot;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.workspaceRoot = normalizeFileKey(options.workspaceRoot);
|
|
17
|
+
}
|
|
18
|
+
getPackages() {
|
|
19
|
+
if (this.packages) return this.packages;
|
|
20
|
+
const packagesRoot = path.join(
|
|
21
|
+
this.workspaceRoot,
|
|
22
|
+
this.options.packagesDir,
|
|
23
|
+
);
|
|
24
|
+
if (!fs.existsSync(packagesRoot)) {
|
|
25
|
+
this.packages = [];
|
|
26
|
+
return this.packages;
|
|
27
|
+
}
|
|
28
|
+
this.packages = fs
|
|
29
|
+
.readdirSync(packagesRoot, { withFileTypes: true })
|
|
30
|
+
.filter((entry) => entry.isDirectory())
|
|
31
|
+
.flatMap((entry) => {
|
|
32
|
+
const packageRoot = path.join(packagesRoot, entry.name);
|
|
33
|
+
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
34
|
+
if (!fs.existsSync(packageJsonPath)) return [];
|
|
35
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
36
|
+
if (!pkg.name) return [];
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
packageName: pkg.name,
|
|
40
|
+
packageRoot,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
});
|
|
44
|
+
return this.packages;
|
|
45
|
+
}
|
|
46
|
+
getPackageNames() {
|
|
47
|
+
this.packageNames ??= this.getPackages().map((item) => item.packageName);
|
|
48
|
+
return this.packageNames;
|
|
49
|
+
}
|
|
50
|
+
isKnownPackageName(packageName) {
|
|
51
|
+
return this.getPackageNames().includes(packageName);
|
|
52
|
+
}
|
|
53
|
+
isSourceGraphFile(file) {
|
|
54
|
+
const normalizedFile = normalizeFileKey(file);
|
|
55
|
+
const packagesRoot = normalizeFileKey(
|
|
56
|
+
path.join(this.workspaceRoot, this.options.packagesDir),
|
|
57
|
+
);
|
|
58
|
+
if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (normalizedFile.endsWith(aukletConfigFile)) return true;
|
|
62
|
+
if (SOURCE_COMPONENT_MODULE_RE.test(normalizedFile)) return true;
|
|
63
|
+
return this.options.styleExtensions.some((extension) =>
|
|
64
|
+
normalizedFile.endsWith(extension),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
getWatchRoots() {
|
|
68
|
+
const packagesRoot = path.join(
|
|
69
|
+
this.workspaceRoot,
|
|
70
|
+
this.options.packagesDir,
|
|
71
|
+
);
|
|
72
|
+
return [
|
|
73
|
+
toWatchPath(packagesRoot, '*', 'src'),
|
|
74
|
+
toWatchPath(packagesRoot, '*', aukletConfigFile),
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type StylePackageInfo = {
|
|
2
|
+
packageName: string;
|
|
3
|
+
packageRoot: string;
|
|
4
|
+
};
|
|
5
|
+
export interface StylePackageSource {
|
|
6
|
+
getPackages(): Array<StylePackageInfo>;
|
|
7
|
+
getPackageNames(): Array<string>;
|
|
8
|
+
isKnownPackageName(packageName: string): boolean;
|
|
9
|
+
isSourceGraphFile(file: string): boolean;
|
|
10
|
+
getWatchRoots(): Array<string>;
|
|
11
|
+
}
|
|
File without changes
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from '#auklet/types';
|
|
7
7
|
import type { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
8
8
|
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
9
|
+
import type { StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
|
|
9
10
|
import type {
|
|
10
11
|
LoadAukletConfig,
|
|
11
12
|
PackageStyleId,
|
|
@@ -21,20 +22,17 @@ export type PackageStyleContext = {
|
|
|
21
22
|
styleProcessor: StyleProcessor;
|
|
22
23
|
};
|
|
23
24
|
export type ModuleStyleGraphRequestCacheOptions = {
|
|
24
|
-
|
|
25
|
-
packagesDir: string;
|
|
25
|
+
packageSource: StylePackageSource;
|
|
26
26
|
config: ModuleStyleBuildConfig;
|
|
27
27
|
loadAukletConfig?: LoadAukletConfig;
|
|
28
28
|
};
|
|
29
29
|
export declare class ModuleStyleGraphRequestCache {
|
|
30
30
|
private readonly options;
|
|
31
|
-
private workspacePackages?;
|
|
32
|
-
private workspacePackageNames?;
|
|
33
31
|
private readonly contexts;
|
|
34
32
|
private readonly loadAukletConfig;
|
|
35
33
|
constructor(options: ModuleStyleGraphRequestCacheOptions);
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
getPackageNames(): string[];
|
|
35
|
+
isKnownPackageName(packageName: string): boolean;
|
|
38
36
|
getContext(parsed: PackageStyleId): Promise<
|
|
39
37
|
| PackageStyleContext
|
|
40
38
|
| {
|
|
@@ -76,5 +74,4 @@ export declare class ModuleStyleGraphRequestCache {
|
|
|
76
74
|
| null
|
|
77
75
|
>;
|
|
78
76
|
private createContext;
|
|
79
|
-
private getWorkspacePackages;
|
|
80
77
|
}
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { aukletConfigFile, normalizeAukletConfig } from '#auklet/config';
|
|
4
3
|
import { loadAukletConfig } from '#auklet/configLoader';
|
|
5
4
|
import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
6
5
|
export class ModuleStyleGraphRequestCache {
|
|
7
6
|
options;
|
|
8
|
-
workspacePackages;
|
|
9
|
-
workspacePackageNames;
|
|
10
7
|
contexts = new Map();
|
|
11
8
|
loadAukletConfig;
|
|
12
9
|
constructor(options) {
|
|
13
10
|
this.options = options;
|
|
14
11
|
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(item) => item.packageName,
|
|
19
|
-
);
|
|
20
|
-
return this.workspacePackageNames;
|
|
13
|
+
getPackageNames() {
|
|
14
|
+
return this.options.packageSource.getPackageNames();
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
return this.
|
|
16
|
+
isKnownPackageName(packageName) {
|
|
17
|
+
return this.options.packageSource.isKnownPackageName(packageName);
|
|
24
18
|
}
|
|
25
19
|
async getContext(parsed) {
|
|
26
20
|
const cachedContext = this.contexts.get(parsed.packageName);
|
|
@@ -30,12 +24,11 @@ export class ModuleStyleGraphRequestCache {
|
|
|
30
24
|
return context;
|
|
31
25
|
}
|
|
32
26
|
async createContext(parsed) {
|
|
33
|
-
const
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
if (!
|
|
37
|
-
const packageRoot =
|
|
38
|
-
if (!fs.existsSync(packageRoot)) return null;
|
|
27
|
+
const stylePackage = this.options.packageSource
|
|
28
|
+
.getPackages()
|
|
29
|
+
.find((item) => item.packageName === parsed.packageName);
|
|
30
|
+
if (!stylePackage) return null;
|
|
31
|
+
const packageRoot = stylePackage.packageRoot;
|
|
39
32
|
const rawConfig = await this.loadAukletConfig(packageRoot, {
|
|
40
33
|
cacheBust: true,
|
|
41
34
|
});
|
|
@@ -61,32 +54,4 @@ export class ModuleStyleGraphRequestCache {
|
|
|
61
54
|
styleProcessor: packageContext.styleProcessor,
|
|
62
55
|
};
|
|
63
56
|
}
|
|
64
|
-
getWorkspacePackages() {
|
|
65
|
-
if (this.workspacePackages) return this.workspacePackages;
|
|
66
|
-
const packagesRoot = path.join(
|
|
67
|
-
this.options.workspaceRoot,
|
|
68
|
-
this.options.packagesDir,
|
|
69
|
-
);
|
|
70
|
-
if (!fs.existsSync(packagesRoot)) {
|
|
71
|
-
this.workspacePackages = [];
|
|
72
|
-
return this.workspacePackages;
|
|
73
|
-
}
|
|
74
|
-
this.workspacePackages = fs
|
|
75
|
-
.readdirSync(packagesRoot, { withFileTypes: true })
|
|
76
|
-
.filter((entry) => entry.isDirectory())
|
|
77
|
-
.flatMap((entry) => {
|
|
78
|
-
const packageRoot = path.join(packagesRoot, entry.name);
|
|
79
|
-
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
80
|
-
if (!fs.existsSync(packageJsonPath)) return [];
|
|
81
|
-
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
82
|
-
if (!pkg.name) return [];
|
|
83
|
-
return [
|
|
84
|
-
{
|
|
85
|
-
packageName: pkg.name,
|
|
86
|
-
packageRoot,
|
|
87
|
-
},
|
|
88
|
-
];
|
|
89
|
-
});
|
|
90
|
-
return this.workspacePackages;
|
|
91
|
-
}
|
|
92
57
|
}
|
|
@@ -263,7 +263,7 @@ export class StyleCodeFactory {
|
|
|
263
263
|
toDevExternalStyleSpecifier(specifier, cache) {
|
|
264
264
|
const parsed = parsePackageStyleSpecifier(specifier);
|
|
265
265
|
if (!parsed) return specifier;
|
|
266
|
-
if (cache.
|
|
266
|
+
if (cache.isKnownPackageName(parsed.packageName)) {
|
|
267
267
|
if (parsed.stylePath === STYLE_ENTRY) {
|
|
268
268
|
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
269
269
|
}
|
|
@@ -279,6 +279,6 @@ export class StyleCodeFactory {
|
|
|
279
279
|
return specifier;
|
|
280
280
|
}
|
|
281
281
|
parsePackageStyleIdInRequest(id, cache) {
|
|
282
|
-
return parsePackageStyleId(id, cache.
|
|
282
|
+
return parsePackageStyleId(id, cache.getPackageNames());
|
|
283
283
|
}
|
|
284
284
|
}
|
|
@@ -2,6 +2,7 @@ import type { AukletConfig, ModuleStyleBuildConfig } from '#auklet/types';
|
|
|
2
2
|
export interface ModuleStyleGraphOptions {
|
|
3
3
|
workspaceRoot: string;
|
|
4
4
|
packagesDir?: string;
|
|
5
|
+
mode?: 'monorepo' | 'package';
|
|
5
6
|
config?: ModuleStyleBuildConfig;
|
|
6
7
|
loadAukletConfig?: LoadAukletConfig;
|
|
7
8
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HotUpdateOptions, ViteDevServer } from 'vite';
|
|
2
2
|
import type { ModuleStyleGraphOptions } from '#auklet/css/vite/moduleGraph/types';
|
|
3
3
|
export type AukletStylePluginOptions = Partial<
|
|
4
|
-
Pick<ModuleStyleGraphOptions, 'workspaceRoot'>
|
|
4
|
+
Pick<ModuleStyleGraphOptions, 'workspaceRoot' | 'mode'>
|
|
5
5
|
> &
|
|
6
6
|
Omit<ModuleStyleGraphOptions, 'workspaceRoot'>;
|
|
7
7
|
export declare function aukletStylePlugin(options?: AukletStylePluginOptions): {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { ModuleStyleGraph } from '#auklet/css/vite/moduleGraph/graph';
|
|
4
3
|
import { AukletStyleHmr } from '#auklet/css/vite/hmr';
|
|
4
|
+
import { ModuleStyleGraph } from '#auklet/css/vite/moduleGraph/graph';
|
|
5
5
|
const WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
6
6
|
const VIRTUAL_ID_PREFIX = 'virtual:auklet-css:';
|
|
7
7
|
const RESOLVED_VIRTUAL_ID_PREFIX = '\0auklet-css:';
|
|
@@ -39,7 +39,7 @@ const createModuleStyleGraph = (options, viteRoot) => {
|
|
|
39
39
|
};
|
|
40
40
|
const invalidateVirtualModules = (server, graph) => {
|
|
41
41
|
const modules = [];
|
|
42
|
-
for (const packageName of graph.
|
|
42
|
+
for (const packageName of graph.getPackageNames()) {
|
|
43
43
|
for (const entry of ['style.css', 'external.css', 'module.css']) {
|
|
44
44
|
const module = server.moduleGraph.getModuleById(
|
|
45
45
|
`${RESOLVED_VIRTUAL_ID_PREFIX}${packageName}/${entry}`,
|
|
@@ -98,7 +98,7 @@ export function aukletStylePlugin(options = {}) {
|
|
|
98
98
|
hmr.installFullReloadGuard(server);
|
|
99
99
|
server.watcher.add(graph.getWatchRoots());
|
|
100
100
|
const invalidateStyleGraph = (file) => {
|
|
101
|
-
if (!graph.
|
|
101
|
+
if (!graph.isSourceGraphFile(file)) return false;
|
|
102
102
|
invalidateVirtualModules(server, graph);
|
|
103
103
|
return true;
|
|
104
104
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auklet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "chentao.arthur",
|
|
6
6
|
"packageManager": "pnpm@10.27.0",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"test:examples": "pnpm build:examples && vitest run examples/__tests__",
|
|
21
21
|
"test:coverage": "vitest run src/__tests__ --coverage",
|
|
22
22
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
23
|
+
"dev:examples": "pnpm --filter './examples/*' --if-present dev",
|
|
23
24
|
"build:examples": "pnpm --filter './examples/*' build",
|
|
24
25
|
"format:md": "prettier --write \"*.md\" \"examples/**/*.md\"",
|
|
25
26
|
"format": "prettier --write \"package.json\" \"pnpm-workspace.yaml\" \"(bin|src|dist|examples)/**/*.{js,mjs,cjs,ts,tsx,json,md,yaml,css}\""
|
|
@@ -63,26 +64,26 @@
|
|
|
63
64
|
"tsdown"
|
|
64
65
|
],
|
|
65
66
|
"dependencies": {
|
|
66
|
-
"unrun": "
|
|
67
|
-
"execa": "
|
|
68
|
-
"aidly": "
|
|
69
|
-
"rimraf": "
|
|
70
|
-
"tsdown": "
|
|
71
|
-
"postcss": "
|
|
72
|
-
"chokidar": "
|
|
73
|
-
"minimist": "
|
|
74
|
-
"typescript": "
|
|
75
|
-
"conditional-export": "
|
|
67
|
+
"unrun": "catalog:",
|
|
68
|
+
"execa": "catalog:",
|
|
69
|
+
"aidly": "catalog:",
|
|
70
|
+
"rimraf": "catalog:",
|
|
71
|
+
"tsdown": "catalog:",
|
|
72
|
+
"postcss": "catalog:",
|
|
73
|
+
"chokidar": "catalog:",
|
|
74
|
+
"minimist": "catalog:",
|
|
75
|
+
"typescript": "catalog:",
|
|
76
|
+
"conditional-export": "catalog:"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
|
-
"@types/node": "
|
|
79
|
-
"@types/minimist": "
|
|
80
|
-
"@vitest/coverage-v8": "
|
|
81
|
-
"husky": "
|
|
82
|
-
"prettier": "
|
|
83
|
-
"lint-staged": "
|
|
84
|
-
"vite": "
|
|
85
|
-
"vitest": "
|
|
79
|
+
"@types/node": "catalog:",
|
|
80
|
+
"@types/minimist": "catalog:",
|
|
81
|
+
"@vitest/coverage-v8": "catalog:",
|
|
82
|
+
"husky": "catalog:",
|
|
83
|
+
"prettier": "catalog:",
|
|
84
|
+
"lint-staged": "catalog:",
|
|
85
|
+
"vite": "catalog:",
|
|
86
|
+
"vitest": "catalog:"
|
|
86
87
|
},
|
|
87
88
|
"lint-staged": {
|
|
88
89
|
"*.js": [
|