auklet 0.0.17 → 0.0.19
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 +436 -107
- package/dist/css/constants.d.ts +1 -1
- package/dist/css/constants.js +1 -1
- package/dist/css/core/style/entries.d.ts +2 -2
- package/dist/css/core/style/entries.js +2 -2
- package/dist/css/core/style/specifier.d.ts +36 -0
- package/dist/css/core/style/specifier.js +86 -0
- 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 +0 -5
- package/dist/css/core/styleImports/collector.js +13 -79
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
- package/dist/css/core/styleImports/{sourceReference.js → sourceImportExportAnalyzer.js} +3 -3
- package/dist/css/core/styleModuleEntryPlanner.d.ts +1 -1
- package/dist/css/core/styleModuleEntryPlanner.js +3 -3
- package/dist/css/core/workspaceStyleResolver.d.ts +0 -1
- package/dist/css/core/workspaceStyleResolver.js +13 -45
- package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
- package/dist/css/production/format/{componentWriter.js → moduleEntryWriter.js} +8 -10
- package/dist/css/production/format/shared.d.ts +1 -1
- package/dist/css/production/format/shared.js +1 -5
- package/dist/css/production/moduleOutputWriter.d.ts +2 -2
- package/dist/css/production/moduleOutputWriter.js +11 -11
- package/dist/css/vite/moduleGraph/graph.d.ts +1 -1
- package/dist/css/vite/moduleGraph/graph.js +15 -11
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +14 -3
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +9 -12
- 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 +1 -1
- package/dist/css/vite/moduleGraph/styleCodeFactory.js +19 -29
- package/dist/css/vite/moduleGraph/types.d.ts +1 -1
- package/dist/css/vite/vitePlugin.d.ts +2 -2
- package/dist/css/vite/vitePlugin.js +11 -4
- package/dist/css/watch/watcher.js +2 -2
- package/package.json +1 -1
- package/dist/css/core/styleImports/sourceReference.d.ts +0 -11
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createModuleStyleEntryPlans } from '#auklet/css/core/style/entries';
|
|
3
|
+
import { ModuleStyleEntryWriter } from '#auklet/css/production/format/moduleEntryWriter';
|
|
4
4
|
import { StyleEntryWriter } from '#auklet/css/production/format/entryWriter';
|
|
5
5
|
import { ExternalStyleWriter } from '#auklet/css/production/format/externalWriter';
|
|
6
6
|
import { ModuleStyleWriter } from '#auklet/css/production/format/moduleWriter';
|
|
@@ -16,7 +16,7 @@ export class ModuleStyleOutputWriter {
|
|
|
16
16
|
externalWriter;
|
|
17
17
|
moduleWriter;
|
|
18
18
|
entryWriter;
|
|
19
|
-
|
|
19
|
+
moduleEntryWriter;
|
|
20
20
|
constructor(options) {
|
|
21
21
|
this.config = options.config;
|
|
22
22
|
this.context = options.context;
|
|
@@ -26,23 +26,23 @@ export class ModuleStyleOutputWriter {
|
|
|
26
26
|
this.externalWriter = new ExternalStyleWriter(options);
|
|
27
27
|
this.moduleWriter = new ModuleStyleWriter(options);
|
|
28
28
|
this.entryWriter = new StyleEntryWriter(options);
|
|
29
|
-
this.
|
|
29
|
+
this.moduleEntryWriter = new ModuleStyleEntryWriter(options);
|
|
30
30
|
}
|
|
31
31
|
write() {
|
|
32
|
-
const
|
|
32
|
+
const moduleEntries = this.createModuleEntries();
|
|
33
33
|
const outputs = [];
|
|
34
34
|
for (const format of this.config.output.outputFormats) {
|
|
35
|
-
outputs.push(...this.writeFormat(format,
|
|
35
|
+
outputs.push(...this.writeFormat(format, moduleEntries));
|
|
36
36
|
}
|
|
37
37
|
return outputs;
|
|
38
38
|
}
|
|
39
39
|
get outputRoot() {
|
|
40
40
|
return path.join(this.context.packageRoot, this.context.outputDir);
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
return
|
|
42
|
+
createModuleEntries() {
|
|
43
|
+
return createModuleStyleEntryPlans(this.packageContext);
|
|
44
44
|
}
|
|
45
|
-
writeFormat(format,
|
|
45
|
+
writeFormat(format, moduleEntries) {
|
|
46
46
|
const outRoot = path.join(this.outputRoot, format);
|
|
47
47
|
const outputs = [];
|
|
48
48
|
this.themeWriter.clean(outRoot);
|
|
@@ -53,7 +53,7 @@ export class ModuleStyleOutputWriter {
|
|
|
53
53
|
const externalStyle = this.externalWriter.write(outRoot);
|
|
54
54
|
const moduleStyle = this.moduleWriter.write(outRoot);
|
|
55
55
|
const entryStyle = this.entryWriter.write(outRoot, themeStyleMap, moduleStyle);
|
|
56
|
-
const
|
|
56
|
+
const moduleStyleEntries = this.moduleEntryWriter.write(outRoot, moduleEntries);
|
|
57
57
|
outputs.push(...themeStyles.map((themeStyle) => themeStyle.file));
|
|
58
58
|
outputs.push(...themeEntries);
|
|
59
59
|
if (externalStyle)
|
|
@@ -62,7 +62,7 @@ export class ModuleStyleOutputWriter {
|
|
|
62
62
|
outputs.push(moduleStyle);
|
|
63
63
|
if (entryStyle)
|
|
64
64
|
outputs.push(entryStyle);
|
|
65
|
-
outputs.push(...
|
|
65
|
+
outputs.push(...moduleStyleEntries);
|
|
66
66
|
return outputs;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -13,7 +13,7 @@ export declare class ModuleStyleGraph {
|
|
|
13
13
|
isStyleConfigFile(file: string): boolean;
|
|
14
14
|
isStyleFile(file: string): boolean;
|
|
15
15
|
getPackageNames(): string[];
|
|
16
|
-
getWatchRoots(): string[]
|
|
16
|
+
getWatchRoots(): Promise<string[]>;
|
|
17
17
|
createPackageStyleCode(parsed: PackageStyleId): Promise<{
|
|
18
18
|
code: string;
|
|
19
19
|
watchFiles: string[];
|
|
@@ -5,7 +5,8 @@ import { moduleStyleBuildConfig } from '#auklet/css/config';
|
|
|
5
5
|
import { parsePackageStyleId } from '#auklet/css/vite/moduleGraph/styleId';
|
|
6
6
|
import { StyleCodeFactory } from '#auklet/css/vite/moduleGraph/styleCodeFactory';
|
|
7
7
|
import { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
|
|
8
|
-
import {
|
|
8
|
+
import { MonorepoPackageSource } from '#auklet/css/vite/moduleGraph/packageSource/monorepo';
|
|
9
|
+
import { SinglePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/singlePackage';
|
|
9
10
|
import { normalizeFileKey } from '#auklet/utils';
|
|
10
11
|
// package style graph 的对外门面,负责 package source、watch 边界和请求分发。
|
|
11
12
|
export class ModuleStyleGraph {
|
|
@@ -15,17 +16,20 @@ export class ModuleStyleGraph {
|
|
|
15
16
|
loadAukletConfig;
|
|
16
17
|
constructor(options) {
|
|
17
18
|
this.config = options.config ?? moduleStyleBuildConfig;
|
|
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
|
-
});
|
|
27
|
-
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
28
19
|
this.styleCodeFactory = new StyleCodeFactory(this.config);
|
|
20
|
+
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
21
|
+
this.packageSource =
|
|
22
|
+
(options.mode ?? 'package') === 'monorepo'
|
|
23
|
+
? new MonorepoPackageSource({
|
|
24
|
+
root: normalizeFileKey(options.root),
|
|
25
|
+
packagesDir: options.packagesDir ?? 'packages',
|
|
26
|
+
styleExtensions: this.config.styleExtensions,
|
|
27
|
+
})
|
|
28
|
+
: new SinglePackageSource({
|
|
29
|
+
root: normalizeFileKey(options.root),
|
|
30
|
+
styleExtensions: this.config.styleExtensions,
|
|
31
|
+
loadAukletConfig: this.loadAukletConfig,
|
|
32
|
+
});
|
|
29
33
|
}
|
|
30
34
|
parsePackageStyleId(id) {
|
|
31
35
|
return parsePackageStyleId(id, this.getPackageNames());
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import type { StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
|
|
1
|
+
import type { StylePackageInfo, StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
|
|
2
2
|
export type MonorepoPackageSourceOptions = {
|
|
3
|
-
|
|
3
|
+
root: string;
|
|
4
4
|
packagesDir: string;
|
|
5
5
|
styleExtensions: Array<string>;
|
|
6
6
|
};
|
|
7
|
-
export declare
|
|
7
|
+
export declare class MonorepoPackageSource implements StylePackageSource {
|
|
8
|
+
private readonly options;
|
|
9
|
+
private packages?;
|
|
10
|
+
private packageNames?;
|
|
11
|
+
private readonly root;
|
|
12
|
+
constructor(options: MonorepoPackageSourceOptions);
|
|
13
|
+
getPackages(): StylePackageInfo[];
|
|
14
|
+
getPackageNames(): string[];
|
|
15
|
+
isKnownPackageName(packageName: string): boolean;
|
|
16
|
+
isSourceGraphFile(file: string): boolean;
|
|
17
|
+
getWatchRoots(): Promise<string[]>;
|
|
18
|
+
}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { aukletConfigFile } from '#auklet/config';
|
|
4
|
-
import {
|
|
4
|
+
import { SOURCE_MODULE_RE } from '#auklet/css/constants';
|
|
5
5
|
import { normalizeFileKey, toWatchPath } from '#auklet/utils';
|
|
6
|
-
export
|
|
7
|
-
return new MonorepoPackageSource(options);
|
|
8
|
-
}
|
|
9
|
-
class MonorepoPackageSource {
|
|
6
|
+
export class MonorepoPackageSource {
|
|
10
7
|
options;
|
|
11
8
|
packages;
|
|
12
9
|
packageNames;
|
|
13
|
-
|
|
10
|
+
root;
|
|
14
11
|
constructor(options) {
|
|
15
12
|
this.options = options;
|
|
16
|
-
this.
|
|
13
|
+
this.root = normalizeFileKey(options.root);
|
|
17
14
|
}
|
|
18
15
|
getPackages() {
|
|
19
16
|
if (this.packages)
|
|
20
17
|
return this.packages;
|
|
21
|
-
const packagesRoot = path.join(this.
|
|
18
|
+
const packagesRoot = path.join(this.root, this.options.packagesDir);
|
|
22
19
|
if (!fs.existsSync(packagesRoot)) {
|
|
23
20
|
this.packages = [];
|
|
24
21
|
return this.packages;
|
|
@@ -52,18 +49,18 @@ class MonorepoPackageSource {
|
|
|
52
49
|
}
|
|
53
50
|
isSourceGraphFile(file) {
|
|
54
51
|
const normalizedFile = normalizeFileKey(file);
|
|
55
|
-
const packagesRoot = normalizeFileKey(path.join(this.
|
|
52
|
+
const packagesRoot = normalizeFileKey(path.join(this.root, this.options.packagesDir));
|
|
56
53
|
if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
|
|
57
54
|
return false;
|
|
58
55
|
}
|
|
59
56
|
if (normalizedFile.endsWith(aukletConfigFile))
|
|
60
57
|
return true;
|
|
61
|
-
if (
|
|
58
|
+
if (SOURCE_MODULE_RE.test(normalizedFile))
|
|
62
59
|
return true;
|
|
63
60
|
return this.options.styleExtensions.some((extension) => normalizedFile.endsWith(extension));
|
|
64
61
|
}
|
|
65
|
-
getWatchRoots() {
|
|
66
|
-
const packagesRoot = path.join(this.
|
|
62
|
+
async getWatchRoots() {
|
|
63
|
+
const packagesRoot = path.join(this.root, this.options.packagesDir);
|
|
67
64
|
return [
|
|
68
65
|
toWatchPath(packagesRoot, '*', 'src'),
|
|
69
66
|
toWatchPath(packagesRoot, '*', aukletConfigFile),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { StylePackageInfo, StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
|
|
2
|
+
import type { LoadAukletConfig } from '#auklet/css/vite/moduleGraph/types';
|
|
3
|
+
export type SinglePackageSourceOptions = {
|
|
4
|
+
root: string;
|
|
5
|
+
styleExtensions: Array<string>;
|
|
6
|
+
loadAukletConfig?: LoadAukletConfig;
|
|
7
|
+
};
|
|
8
|
+
export declare class SinglePackageSource implements StylePackageSource {
|
|
9
|
+
private readonly options;
|
|
10
|
+
private packageInfo?;
|
|
11
|
+
private readonly root;
|
|
12
|
+
private readonly loadAukletConfig;
|
|
13
|
+
constructor(options: SinglePackageSourceOptions);
|
|
14
|
+
getPackages(): StylePackageInfo[];
|
|
15
|
+
getPackageNames(): string[];
|
|
16
|
+
isKnownPackageName(packageName: string): boolean;
|
|
17
|
+
isSourceGraphFile(file: string): boolean;
|
|
18
|
+
getWatchRoots(): Promise<string[]>;
|
|
19
|
+
private getPackageInfo;
|
|
20
|
+
private isInsidePackage;
|
|
21
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { aukletConfigFile, normalizeAukletConfig } from '#auklet/config';
|
|
4
|
+
import { loadAukletConfig } from '#auklet/configLoader';
|
|
5
|
+
import { SOURCE_MODULE_RE } from '#auklet/css/constants';
|
|
6
|
+
import { normalizeFileKey, toWatchPath } from '#auklet/utils';
|
|
7
|
+
export class SinglePackageSource {
|
|
8
|
+
options;
|
|
9
|
+
packageInfo;
|
|
10
|
+
root;
|
|
11
|
+
loadAukletConfig;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.root = normalizeFileKey(options.root);
|
|
15
|
+
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
16
|
+
}
|
|
17
|
+
getPackages() {
|
|
18
|
+
return [this.getPackageInfo()];
|
|
19
|
+
}
|
|
20
|
+
getPackageNames() {
|
|
21
|
+
return [this.getPackageInfo().packageName];
|
|
22
|
+
}
|
|
23
|
+
isKnownPackageName(packageName) {
|
|
24
|
+
return packageName === this.getPackageInfo().packageName;
|
|
25
|
+
}
|
|
26
|
+
isSourceGraphFile(file) {
|
|
27
|
+
const normalizedFile = normalizeFileKey(file);
|
|
28
|
+
if (!this.isInsidePackage(normalizedFile))
|
|
29
|
+
return false;
|
|
30
|
+
if (normalizedFile.endsWith(aukletConfigFile))
|
|
31
|
+
return true;
|
|
32
|
+
if (SOURCE_MODULE_RE.test(normalizedFile))
|
|
33
|
+
return true;
|
|
34
|
+
return this.options.styleExtensions.some((extension) => normalizedFile.endsWith(extension));
|
|
35
|
+
}
|
|
36
|
+
async getWatchRoots() {
|
|
37
|
+
const normalizedConfig = normalizeAukletConfig(await this.loadAukletConfig(this.root, { cacheBust: true }));
|
|
38
|
+
return [
|
|
39
|
+
toWatchPath(this.root, normalizedConfig.source),
|
|
40
|
+
toWatchPath(this.root, aukletConfigFile),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
getPackageInfo() {
|
|
44
|
+
if (this.packageInfo)
|
|
45
|
+
return this.packageInfo;
|
|
46
|
+
const packageJsonPath = path.join(this.root, 'package.json');
|
|
47
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
48
|
+
throw new Error(`[auklet:css] package mode requires a package.json at ${this.root}.`);
|
|
49
|
+
}
|
|
50
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
51
|
+
if (!pkg.name) {
|
|
52
|
+
throw new Error(`[auklet:css] package mode requires package.json#name at ${this.root}.`);
|
|
53
|
+
}
|
|
54
|
+
this.packageInfo = {
|
|
55
|
+
packageName: pkg.name,
|
|
56
|
+
packageRoot: this.root,
|
|
57
|
+
};
|
|
58
|
+
return this.packageInfo;
|
|
59
|
+
}
|
|
60
|
+
isInsidePackage(file) {
|
|
61
|
+
return file === this.root || file.startsWith(`${this.root}/`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -3,9 +3,8 @@ import { mergeLoadResults } from '#auklet/css/vite/moduleGraph/loadResult';
|
|
|
3
3
|
import { parsePackageStyleId } from '#auklet/css/vite/moduleGraph/styleId';
|
|
4
4
|
import { toDevDependencyImportSpecifier } from '#auklet/css/vite/moduleGraph/devDependency';
|
|
5
5
|
import { EXTERNAL_ENTRY, MODULE_ENTRY, STYLE_ENTRY, THEMES_ENTRY_PREFIX, } from '#auklet/css/constants';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { toFsSpecifier, toPosixPath } from '#auklet/utils';
|
|
6
|
+
import { createModuleStyleEntryPlan, createExternalEntryParts, createStyleEntryParts, createThemeEntryParts, } from '#auklet/css/core/style/entries';
|
|
7
|
+
import { createDevExternalStyleSpecifier, createDevModuleStyleSpecifier, createImportCode, removeStyleExtension, } from '#auklet/css/core/style/specifier';
|
|
9
8
|
// 生成 Vite/dev 虚拟 CSS;production writer 共享入口语义,但写入真实文件。
|
|
10
9
|
export class StyleCodeFactory {
|
|
11
10
|
config;
|
|
@@ -129,13 +128,13 @@ export class StyleCodeFactory {
|
|
|
129
128
|
async createSourceModuleStyleCode(context, cache, stylePath) {
|
|
130
129
|
const sourceModuleDir = removeStyleExtension(stylePath);
|
|
131
130
|
const { styleFiles, sourceFiles } = context.packageContext;
|
|
132
|
-
const entry =
|
|
131
|
+
const entry = createModuleStyleEntryPlan(context.packageContext, sourceModuleDir);
|
|
133
132
|
const sourceStyleDir = path.join(context.sourceRoot, sourceModuleDir, this.config.output.styleDir);
|
|
134
133
|
const moduleStyleResults = [];
|
|
135
134
|
const moduleStyleSpecifiers = [];
|
|
136
135
|
const moduleStyleWatchFiles = [];
|
|
137
136
|
for (const specifier of entry.moduleStyleImports) {
|
|
138
|
-
const result = this.toDevModuleImportSpecifier(context, cache, sourceStyleDir
|
|
137
|
+
const result = this.toDevModuleImportSpecifier(specifier, context, cache, sourceStyleDir);
|
|
139
138
|
const parsed = this.parsePackageStyleIdInRequest(result, cache);
|
|
140
139
|
if (parsed) {
|
|
141
140
|
moduleStyleResults.push(await this.createPackageStyleCode(parsed, cache));
|
|
@@ -170,32 +169,23 @@ export class StyleCodeFactory {
|
|
|
170
169
|
],
|
|
171
170
|
});
|
|
172
171
|
}
|
|
173
|
-
toDevModuleImportSpecifier(context, cache, sourceStyleDir
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
const sourceModuleDir = path.relative(context.sourceRoot, outputStyleEntry.slice(0, -styleEntrySuffix.length));
|
|
183
|
-
return `${context.packageName}/${toPosixPath(sourceModuleDir)}.css`;
|
|
172
|
+
toDevModuleImportSpecifier(specifier, context, cache, sourceStyleDir) {
|
|
173
|
+
return createDevModuleStyleSpecifier(specifier, {
|
|
174
|
+
sourceStyleDir,
|
|
175
|
+
sourceRoot: context.sourceRoot,
|
|
176
|
+
packageName: context.packageName,
|
|
177
|
+
styleDir: this.config.output.styleDir,
|
|
178
|
+
indexStyleFile: this.config.output.indexStyleFile,
|
|
179
|
+
mapExternalSpecifier: (externalSpecifier) => this.toDevExternalStyleSpecifier(externalSpecifier, cache),
|
|
180
|
+
});
|
|
184
181
|
}
|
|
185
182
|
toDevExternalStyleSpecifier(specifier, cache) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
if (parsed.stylePath ===
|
|
194
|
-
[this.config.output.styleDir, this.config.output.indexStyleFile].join('/')) {
|
|
195
|
-
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return specifier;
|
|
183
|
+
return createDevExternalStyleSpecifier(specifier, {
|
|
184
|
+
isKnownPackageName: (packageName) => cache.isKnownPackageName(packageName),
|
|
185
|
+
styleDir: this.config.output.styleDir,
|
|
186
|
+
indexStyleFile: this.config.output.indexStyleFile,
|
|
187
|
+
externalStyleFile: EXTERNAL_ENTRY,
|
|
188
|
+
});
|
|
199
189
|
}
|
|
200
190
|
parsePackageStyleIdInRequest(id, cache) {
|
|
201
191
|
return parsePackageStyleId(id, cache.getPackageNames());
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HotUpdateOptions, ViteDevServer } from 'vite';
|
|
2
2
|
import type { ModuleStyleGraphOptions } from '#auklet/css/vite/moduleGraph/types';
|
|
3
|
-
export type AukletStylePluginOptions = Partial<Pick<ModuleStyleGraphOptions, '
|
|
3
|
+
export type AukletStylePluginOptions = Partial<Pick<ModuleStyleGraphOptions, 'root' | 'mode'>> & Omit<ModuleStyleGraphOptions, 'root'>;
|
|
4
4
|
export declare function aukletStylePlugin(options?: AukletStylePluginOptions): {
|
|
5
5
|
name: string;
|
|
6
6
|
apply: "serve";
|
|
@@ -12,7 +12,7 @@ export declare function aukletStylePlugin(options?: AukletStylePluginOptions): {
|
|
|
12
12
|
load(this: {
|
|
13
13
|
addWatchFile?: (file: string) => void;
|
|
14
14
|
}, id: string): Promise<string | null>;
|
|
15
|
-
configureServer(server: ViteDevServer): void
|
|
15
|
+
configureServer(server: ViteDevServer): Promise<void>;
|
|
16
16
|
hotUpdate: {
|
|
17
17
|
order: "pre";
|
|
18
18
|
handler(context: HotUpdateOptions): never[] | undefined;
|
|
@@ -29,12 +29,19 @@ const findWorkspaceRoot = (startDir) => {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
const createModuleStyleGraph = (options, viteRoot) => {
|
|
32
|
-
const
|
|
32
|
+
const mode = options.mode ?? 'package';
|
|
33
|
+
const root = options.root ?? resolveGraphRoot(mode, viteRoot);
|
|
33
34
|
return new ModuleStyleGraph({
|
|
34
35
|
...options,
|
|
35
|
-
|
|
36
|
+
mode,
|
|
37
|
+
root,
|
|
36
38
|
});
|
|
37
39
|
};
|
|
40
|
+
const resolveGraphRoot = (mode, viteRoot) => {
|
|
41
|
+
if (mode === 'monorepo')
|
|
42
|
+
return findWorkspaceRoot(viteRoot) ?? process.cwd();
|
|
43
|
+
return viteRoot;
|
|
44
|
+
};
|
|
38
45
|
const invalidateVirtualModules = (server, graph) => {
|
|
39
46
|
const modules = [];
|
|
40
47
|
for (const packageName of graph.getPackageNames()) {
|
|
@@ -92,10 +99,10 @@ export function aukletStylePlugin(options = {}) {
|
|
|
92
99
|
}
|
|
93
100
|
return result.code;
|
|
94
101
|
},
|
|
95
|
-
configureServer(server) {
|
|
102
|
+
async configureServer(server) {
|
|
96
103
|
const graph = getGraph();
|
|
97
104
|
hmr.installFullReloadGuard(server);
|
|
98
|
-
server.watcher.add(graph.getWatchRoots());
|
|
105
|
+
server.watcher.add(await graph.getWatchRoots());
|
|
99
106
|
const invalidateStyleGraph = (file) => {
|
|
100
107
|
if (!graph.isSourceGraphFile(file))
|
|
101
108
|
return false;
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import chokidar from 'chokidar';
|
|
4
4
|
import { aukletConfigFile, aukletDefaultOptions } from '#auklet/config';
|
|
5
5
|
import { moduleStyleBuildConfig } from '#auklet/css/config';
|
|
6
|
-
import {
|
|
6
|
+
import { SOURCE_MODULE_RE } from '#auklet/css/constants';
|
|
7
7
|
import { ModuleStyleBuilder } from '#auklet/css/production/builder';
|
|
8
8
|
export class ModuleStyleWatcher {
|
|
9
9
|
config;
|
|
@@ -82,7 +82,7 @@ export class ModuleStyleWatcher {
|
|
|
82
82
|
shouldRebuildForFile(file) {
|
|
83
83
|
if (path.basename(file) === aukletConfigFile)
|
|
84
84
|
return true;
|
|
85
|
-
if (
|
|
85
|
+
if (SOURCE_MODULE_RE.test(file))
|
|
86
86
|
return true;
|
|
87
87
|
return this.config.styleExtensions.includes(path.extname(file));
|
|
88
88
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
export type ModuleStyleSourceReference = {
|
|
3
|
-
importPath: string;
|
|
4
|
-
importClause?: ts.ImportClause;
|
|
5
|
-
importedNames?: Array<string>;
|
|
6
|
-
isTypeOnly?: boolean;
|
|
7
|
-
hasNamespaceImport?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare function collectModuleStyleSourceReferences(file: string, code: string): ModuleStyleSourceReference[];
|
|
10
|
-
export declare function isTypeOnlySourceReference(item: ModuleStyleSourceReference): boolean | undefined;
|
|
11
|
-
export declare function getSourceReferenceImportedNames(file: string, item: ModuleStyleSourceReference): string[];
|