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.
Files changed (105) hide show
  1. package/README.md +37 -1
  2. package/dist/build/bundleConfig.d.ts +1 -4
  3. package/dist/build/bundleConfig.js +59 -71
  4. package/dist/build/cleanOutput.d.ts +2 -8
  5. package/dist/build/cleanOutput.js +7 -7
  6. package/dist/build/moduleConfig.d.ts +1 -3
  7. package/dist/build/moduleConfig.js +21 -40
  8. package/dist/build/runTsdown.d.ts +2 -5
  9. package/dist/build/runTsdown.js +18 -23
  10. package/dist/build/tsdown/common.d.ts +17 -28
  11. package/dist/build/tsdown/common.js +22 -25
  12. package/dist/build/tsdown/context.d.ts +16 -20
  13. package/dist/build/tsdown/context.js +41 -45
  14. package/dist/build/tsdown/define.d.ts +2 -7
  15. package/dist/build/tsdown/define.js +13 -22
  16. package/dist/build/tsdown/dependencies.d.ts +4 -12
  17. package/dist/build/tsdown/dependencies.js +47 -51
  18. package/dist/build/tsdown/entries.d.ts +4 -6
  19. package/dist/build/tsdown/entries.js +39 -38
  20. package/dist/build/tsdown/parseModuleId.d.ts +4 -4
  21. package/dist/build/tsdown/parseModuleId.js +92 -77
  22. package/dist/build/tsdown/types.d.ts +24 -31
  23. package/dist/build/tsdownConfig.js +1 -4
  24. package/dist/config.d.ts +37 -37
  25. package/dist/config.js +38 -41
  26. package/dist/configLoader.d.ts +2 -7
  27. package/dist/configLoader.js +59 -64
  28. package/dist/css/config.js +8 -8
  29. package/dist/css/constants.d.ts +7 -7
  30. package/dist/css/constants.js +1 -1
  31. package/dist/css/core/resolvers/packageImports.d.ts +1 -5
  32. package/dist/css/core/resolvers/packageImports.js +35 -40
  33. package/dist/css/core/resolvers/relative.d.ts +1 -4
  34. package/dist/css/core/resolvers/relative.js +3 -2
  35. package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
  36. package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
  37. package/dist/css/core/style/dependencies.d.ts +6 -16
  38. package/dist/css/core/style/dependencies.js +35 -38
  39. package/dist/css/core/style/entries.d.ts +35 -58
  40. package/dist/css/core/style/entries.js +22 -33
  41. package/dist/css/core/style/files.d.ts +2 -7
  42. package/dist/css/core/style/files.js +11 -11
  43. package/dist/css/core/style/specifier.d.ts +41 -8
  44. package/dist/css/core/style/specifier.js +107 -18
  45. package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
  46. package/dist/css/core/styleImports/autoImportRules.js +68 -0
  47. package/dist/css/core/styleImports/collector.d.ts +12 -25
  48. package/dist/css/core/styleImports/collector.js +101 -206
  49. package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
  50. package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
  51. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  52. package/dist/css/core/styleModuleEntryPlanner.js +45 -62
  53. package/dist/css/core/stylePackageContext.d.ts +16 -20
  54. package/dist/css/core/stylePackageContext.js +33 -49
  55. package/dist/css/core/styleProcessor.js +105 -104
  56. package/dist/css/core/workspaceStyleResolver.d.ts +8 -15
  57. package/dist/css/core/workspaceStyleResolver.js +34 -76
  58. package/dist/css/production/builder.d.ts +9 -16
  59. package/dist/css/production/builder.js +51 -57
  60. package/dist/css/production/format/entryWriter.js +36 -49
  61. package/dist/css/production/format/externalWriter.js +21 -33
  62. package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
  63. package/dist/css/production/format/moduleEntryWriter.js +48 -0
  64. package/dist/css/production/format/moduleWriter.js +23 -26
  65. package/dist/css/production/format/shared.d.ts +8 -15
  66. package/dist/css/production/format/shared.js +4 -9
  67. package/dist/css/production/format/sourceWriter.js +11 -11
  68. package/dist/css/production/format/themeWriter.js +56 -71
  69. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  70. package/dist/css/production/moduleOutputWriter.js +58 -67
  71. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  72. package/dist/css/production/packageEntryWriter.js +42 -45
  73. package/dist/css/vite/hmr.d.ts +11 -11
  74. package/dist/css/vite/hmr.js +93 -109
  75. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  76. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  77. package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
  78. package/dist/css/vite/moduleGraph/graph.js +51 -50
  79. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  80. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  81. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +16 -7
  82. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
  83. package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
  84. package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
  85. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
  86. package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
  87. package/dist/css/vite/moduleGraph/requestCache.js +53 -51
  88. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  89. package/dist/css/vite/moduleGraph/styleCodeFactory.js +173 -264
  90. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  91. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  92. package/dist/css/vite/moduleGraph/types.d.ts +11 -14
  93. package/dist/css/vite/vitePlugin.d.ts +16 -20
  94. package/dist/css/vite/vitePlugin.js +117 -109
  95. package/dist/css/watch/watcher.d.ts +15 -21
  96. package/dist/css/watch/watcher.js +84 -81
  97. package/dist/index.d.ts +3 -25
  98. package/dist/index.js +2 -9
  99. package/dist/types.d.ts +59 -62
  100. package/dist/utils.d.ts +3 -7
  101. package/dist/utils.js +50 -47
  102. package/package.json +31 -33
  103. package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
  104. package/dist/css/core/styleImports/sourceReference.js +0 -193
  105. package/dist/css/production/format/componentWriter.js +0 -71
@@ -1,67 +1,50 @@
1
1
  import path from 'node:path';
2
- import { SOURCE_COMPONENT_MODULE_RE } from '#auklet/css/constants';
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
- packageContext;
7
- styleFilesByDir;
8
- importedStyleFiles;
9
- constructor(packageContext) {
10
- this.packageContext = packageContext;
11
- this.styleFilesByDir = groupStyleFilesByDir(
12
- this.packageContext.sourceRoot,
13
- this.packageContext.styleFiles,
14
- );
15
- this.importedStyleFiles =
16
- this.packageContext.styleProcessor.collectImportedStyleFiles(
17
- this.packageContext.styleFiles,
18
- );
19
- }
20
- createEntries(moduleStyleImports) {
21
- return this.getSourceDirs(moduleStyleImports).map((sourceDir) =>
22
- this.createEntry(sourceDir, moduleStyleImports),
23
- );
24
- }
25
- createEntry(sourceDir, moduleStyleImports) {
26
- return {
27
- sourceDir,
28
- moduleStyleImports: moduleStyleImports.get(sourceDir) ?? [],
29
- ownStyleFiles: this.getOwnStyleFiles(sourceDir),
30
- };
31
- }
32
- getSourceDirs(moduleStyleImports) {
33
- return Array.from(
34
- new Set([
35
- ...this.getSourceModuleDirs(),
36
- ...this.getOwnStyleDirs(),
37
- ...moduleStyleImports.keys(),
38
- ]),
39
- ).filter((sourceDir) => sourceDir !== '.');
40
- }
41
- getSourceModuleDirs() {
42
- return this.packageContext.sourceFiles
43
- .filter((sourceFile) => SOURCE_COMPONENT_MODULE_RE.test(sourceFile))
44
- .map((sourceFile) => {
45
- return getSourceModuleDir(
46
- path.relative(this.packageContext.sourceRoot, sourceFile),
47
- );
48
- })
49
- .filter((sourceModuleDir) => {
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
- config: ModuleStyleBuildConfig;
11
- context: ResolvedModuleStyleBuildContext;
12
- normalizedConfig: NormalizedAukletConfig;
6
+ config: ModuleStyleBuildConfig;
7
+ context: ResolvedModuleStyleBuildContext;
8
+ normalizedConfig: NormalizedAukletConfig;
13
9
  };
14
10
  export declare class StylePackageContext {
15
- private readonly options;
16
- readonly normalizedConfig: NormalizedAukletConfig;
17
- readonly sourceRoot: string;
18
- readonly resolver: WorkspaceStyleResolver;
19
- readonly styleProcessor: StyleProcessor;
20
- readonly importCollector: ModuleStyleImportCollector;
21
- readonly sourceFiles: Array<string>;
22
- readonly themeFiles: Map<string, string>;
23
- readonly themeNames: Array<string>;
24
- readonly styleFiles: Array<string>;
25
- constructor(options: StylePackageContextOptions);
26
- getStyleFiles(files: Array<string>): string[];
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
- createStyleFileKey,
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
- 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
- }
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
- config;
6
- resolver;
7
- constructor(config, resolver) {
8
- this.config = config;
9
- this.resolver = resolver;
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
- target.append(...(root.nodes ?? []));
33
- }
34
- readStyleFile(stylePath, seen = new Set()) {
35
- if (!fs.existsSync(stylePath)) {
36
- return '';
11
+ createRoot() {
12
+ return postcss.root();
37
13
  }
38
- const normalizedPath = path.resolve(stylePath);
39
- if (seen.has(normalizedPath)) return '';
40
- seen.add(normalizedPath);
41
- const css = fs.readFileSync(stylePath, 'utf8');
42
- const root = this.parse(css, stylePath);
43
- const imports = [];
44
- root.walkAtRules('import', (rule) => {
45
- const specifier = this.parseImportSpecifier(rule.params);
46
- if (specifier) imports.push({ rule, specifier });
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
- return root.toString();
62
- }
63
- collectImportedStyleFiles(styleFiles) {
64
- const imported = new Set();
65
- for (const styleFile of styleFiles) {
66
- const css = fs.readFileSync(styleFile, 'utf8');
67
- const root = this.parse(css, styleFile);
68
- root.walkAtRules('import', (rule) => {
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
- imported.add(path.resolve(path.dirname(styleFile), specifier));
77
- });
33
+ target.append(...(root.nodes ?? []));
78
34
  }
79
- return imported;
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
- });
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
- return specifiers;
92
- }
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;
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
- if (!value.startsWith('url(')) {
106
- return null;
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
- const end = value.indexOf(')', 4);
109
- if (end < 0) return null;
110
- const url = value.slice(4, end).trim();
111
- const quote = url[0];
112
- if (quote === '"' || quote === "'") {
113
- const quoteEnd = url.indexOf(quote, 1);
114
- return quoteEnd > 0 ? url.slice(1, quoteEnd) : null;
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
- private readonly config;
7
- private readonly context;
8
- private readonly require;
9
- constructor(
10
- config: ModuleStyleBuildConfig,
11
- context: ResolvedModuleStyleBuildContext,
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, STYLE_ENTRY } from '#auklet/css/constants';
4
- import { POSIX_SEPARATOR } from '#auklet/utils';
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
- config;
8
- context;
9
- require;
10
- constructor(config, context) {
11
- this.config = config;
12
- this.context = context;
13
- this.require = createRequire(
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
- try {
22
- return this.require.resolve(specifier, {
23
- paths: [this.context.packageRoot],
24
- });
25
- } catch {
26
- return path.resolve(
27
- this.context.packageRoot,
28
- NODE_MODULES_DIR,
29
- specifier,
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
- toOutputStyleSpecifier(specifier, outRoot) {
34
- const parsed = parsePackageStyleSpecifier(specifier);
35
- if (!parsed) return specifier;
36
- const { packageName, stylePath } = parsed;
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
- return specifier;
45
- }
46
- toExternalStyleSpecifier(specifier, outRoot) {
47
- const parsed = parsePackageStyleSpecifier(specifier);
48
- if (!parsed) return specifier;
49
- const { packageName, stylePath } = parsed;
50
- const currentOutputFormat = path.basename(outRoot);
51
- const outputFormat = this.getStylePathOutputFormat(stylePath);
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
- 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;
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
  }