auklet 0.1.7 → 0.1.8
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.
|
@@ -9,11 +9,11 @@ export async function resolveWorkspaceScriptTargets(cwd, filters, envContext, op
|
|
|
9
9
|
excludeRoot: true,
|
|
10
10
|
env: envContext.normalizedValues,
|
|
11
11
|
scope: options.scope ?? 'workspace',
|
|
12
|
-
emptyTargetMessage: options.emptyTargetMessage ?? '[workspace] no workspace package found.',
|
|
13
12
|
includePrivate: options.includePrivate,
|
|
14
13
|
readPackageJson: readWorkspaceScriptPackageJson,
|
|
15
14
|
getDependencies: getWorkspaceScriptDependencies,
|
|
16
15
|
includeDependencies: options.includeDependencies,
|
|
16
|
+
emptyTargetMessage: options.emptyTargetMessage ?? '[workspace] no workspace package found.',
|
|
17
17
|
createTarget: (item, packageJson) => ({
|
|
18
18
|
packageRoot: item.path,
|
|
19
19
|
packageName: item.name,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
2
2
|
export type ModuleStyleEntryPlan = {
|
|
3
3
|
sourceDir: string;
|
|
4
|
-
moduleStyleImports: Array<string>;
|
|
5
4
|
ownStyleFiles: Array<string>;
|
|
5
|
+
moduleStyleImports: Array<string>;
|
|
6
6
|
};
|
|
7
7
|
export declare class StyleModuleEntryPlanner {
|
|
8
8
|
private readonly packageContext;
|
|
@@ -23,4 +23,7 @@ export declare class StyleModuleEntryPlanner {
|
|
|
23
23
|
private getSourceModuleDirs;
|
|
24
24
|
private getOwnStyleDirs;
|
|
25
25
|
private getOwnStyleFiles;
|
|
26
|
+
private rejectCrossModuleStyleImports;
|
|
27
|
+
private getStyleFileModuleDir;
|
|
28
|
+
private toRelativeSourceFile;
|
|
26
29
|
}
|
|
@@ -11,6 +11,7 @@ export class StyleModuleEntryPlanner {
|
|
|
11
11
|
this.styleFilesByDir = groupStyleFilesByDir(this.packageContext.sourceRoot, this.packageContext.styleFiles);
|
|
12
12
|
this.importedStyleFiles =
|
|
13
13
|
this.packageContext.styleProcessor.collectImportedStyleFiles(this.packageContext.styleFiles);
|
|
14
|
+
this.rejectCrossModuleStyleImports();
|
|
14
15
|
}
|
|
15
16
|
createEntries(moduleStyleImports) {
|
|
16
17
|
return this.getSourceDirs(moduleStyleImports).map((sourceDir) => this.createEntry(sourceDir, moduleStyleImports));
|
|
@@ -47,4 +48,38 @@ export class StyleModuleEntryPlanner {
|
|
|
47
48
|
getOwnStyleFiles(sourceDir) {
|
|
48
49
|
return (this.styleFilesByDir.get(sourceDir) ?? []).filter((styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)));
|
|
49
50
|
}
|
|
51
|
+
rejectCrossModuleStyleImports() {
|
|
52
|
+
if (!this.packageContext.normalizedConfig.modules)
|
|
53
|
+
return;
|
|
54
|
+
const styleFileKeys = new Set(this.packageContext.styleFiles.map((file) => path.resolve(file)));
|
|
55
|
+
const imports = this.packageContext.styleProcessor.collectImportedStyleFileReferences(this.packageContext.styleFiles);
|
|
56
|
+
for (const item of imports) {
|
|
57
|
+
if (!styleFileKeys.has(item.imported))
|
|
58
|
+
continue;
|
|
59
|
+
const importerModuleDir = this.getStyleFileModuleDir(item.importer);
|
|
60
|
+
const importedModuleDir = this.getStyleFileModuleDir(item.imported);
|
|
61
|
+
if (!importerModuleDir ||
|
|
62
|
+
!importedModuleDir ||
|
|
63
|
+
importerModuleDir === importedModuleDir) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const importer = this.toRelativeSourceFile(item.importer);
|
|
67
|
+
const imported = this.toRelativeSourceFile(item.imported);
|
|
68
|
+
throw new Error(`[css] cross-component CSS import detected: ${importer} imports ${imported}. ` +
|
|
69
|
+
'Use TSX imports to express component dependencies so auklet can ' +
|
|
70
|
+
'generate module CSS entries correctly.');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getStyleFileModuleDir(file) {
|
|
74
|
+
const sourceRelative = toPosixPath(path.relative(this.packageContext.sourceRoot, file));
|
|
75
|
+
const parts = sourceRelative.split('/');
|
|
76
|
+
if (parts.length < 2)
|
|
77
|
+
return null;
|
|
78
|
+
if (parts.length === 2)
|
|
79
|
+
return getSourceModuleDir(sourceRelative);
|
|
80
|
+
return parts.slice(0, 2).join('/');
|
|
81
|
+
}
|
|
82
|
+
toRelativeSourceFile(file) {
|
|
83
|
+
return toPosixPath(path.relative(this.packageContext.sourceRoot, file));
|
|
84
|
+
}
|
|
50
85
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
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
|
+
export type StyleFileImportReference = {
|
|
5
|
+
importer: string;
|
|
6
|
+
imported: string;
|
|
7
|
+
};
|
|
4
8
|
export declare class StyleProcessor {
|
|
5
9
|
private readonly config;
|
|
6
10
|
private readonly resolver;
|
|
@@ -11,6 +15,7 @@ export declare class StyleProcessor {
|
|
|
11
15
|
appendStyleContent(target: Root, content: string, from: string): void;
|
|
12
16
|
readStyleFile(stylePath: string, seen?: Set<string>): string;
|
|
13
17
|
collectImportedStyleFiles(styleFiles: Array<string>): Set<string>;
|
|
18
|
+
collectImportedStyleFileReferences(styleFiles: Array<string>): StyleFileImportReference[];
|
|
14
19
|
collectStyleImportSpecifiers(styleFiles: Array<string>): Set<string>;
|
|
15
20
|
private parse;
|
|
16
21
|
private parseImportSpecifier;
|
|
@@ -62,7 +62,10 @@ export class StyleProcessor {
|
|
|
62
62
|
return root.toString();
|
|
63
63
|
}
|
|
64
64
|
collectImportedStyleFiles(styleFiles) {
|
|
65
|
-
|
|
65
|
+
return new Set(this.collectImportedStyleFileReferences(styleFiles).map((item) => item.imported));
|
|
66
|
+
}
|
|
67
|
+
collectImportedStyleFileReferences(styleFiles) {
|
|
68
|
+
const imports = [];
|
|
66
69
|
for (const styleFile of styleFiles) {
|
|
67
70
|
const css = fs.readFileSync(styleFile, 'utf8');
|
|
68
71
|
const root = this.parse(css, styleFile);
|
|
@@ -72,10 +75,13 @@ export class StyleProcessor {
|
|
|
72
75
|
!this.config.styleExtensions.includes(path.extname(specifier))) {
|
|
73
76
|
return;
|
|
74
77
|
}
|
|
75
|
-
|
|
78
|
+
imports.push({
|
|
79
|
+
importer: path.resolve(styleFile),
|
|
80
|
+
imported: path.resolve(path.dirname(styleFile), specifier),
|
|
81
|
+
});
|
|
76
82
|
});
|
|
77
83
|
}
|
|
78
|
-
return
|
|
84
|
+
return imports;
|
|
79
85
|
}
|
|
80
86
|
collectStyleImportSpecifiers(styleFiles) {
|
|
81
87
|
const specifiers = new Set();
|