auklet 0.0.13 → 0.0.15

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.
@@ -1,4 +1,4 @@
1
- import { parseModuleId } from 'conditional-export';
1
+ import { parseModuleId } from '#auklet/build/tsdown/parseModuleId';
2
2
  const getExternal = (names) => {
3
3
  const external = new Set();
4
4
  for (const name of names) {
@@ -0,0 +1,6 @@
1
+ export declare function parseModuleId(moduleId: string): {
2
+ name: string;
3
+ path: string;
4
+ version: string;
5
+ raw: string;
6
+ };
@@ -0,0 +1,85 @@
1
+ export function parseModuleId(moduleId) {
2
+ let name = '';
3
+ let path = '';
4
+ let version = '';
5
+ let buf = '';
6
+ let slash = 0;
7
+ let isScope = false;
8
+ const set = (type) => {
9
+ if (type === 'path') path = buf;
10
+ if (type === 'name') name = buf;
11
+ if (type === 'version') version = buf;
12
+ buf = '';
13
+ };
14
+ const setValueBySlash = (char) => {
15
+ if (!name) {
16
+ set('name');
17
+ } else if (!version) {
18
+ set('version');
19
+ } else {
20
+ buf += char;
21
+ }
22
+ };
23
+ for (let i = 0, l = moduleId.length; i < l; i++) {
24
+ const char = moduleId[i];
25
+ if (char === '@') {
26
+ if (i === 0) {
27
+ buf += char;
28
+ isScope = true;
29
+ } else if (!name) {
30
+ if (isScope) {
31
+ if (slash === 1 && buf[buf.length - 1] !== '/') {
32
+ set('name');
33
+ } else {
34
+ buf += char;
35
+ }
36
+ } else {
37
+ set('name');
38
+ }
39
+ } else {
40
+ buf += char;
41
+ }
42
+ } else if (char === '/') {
43
+ if (slash === 0) {
44
+ if (!isScope) {
45
+ setValueBySlash(char);
46
+ }
47
+ buf += char;
48
+ } else if (slash === 1) {
49
+ if (isScope) {
50
+ setValueBySlash(char);
51
+ }
52
+ buf += char;
53
+ } else {
54
+ buf += char;
55
+ }
56
+ slash++;
57
+ } else {
58
+ buf += char;
59
+ }
60
+ }
61
+ if (!name) {
62
+ set('name');
63
+ } else if (!version) {
64
+ moduleId[name.length] === '@' ? set('version') : set('path');
65
+ } else if (!path) {
66
+ set('path');
67
+ }
68
+ if (path) {
69
+ path = `.${path}`;
70
+ }
71
+ // `@vue` -> ''
72
+ // `@vue/` -> ''
73
+ // `@vue//` -> ''
74
+ if (isScope && (slash === 0 || name[name.length - 1] === '/')) {
75
+ name = '';
76
+ path = '';
77
+ version = '';
78
+ }
79
+ return {
80
+ name,
81
+ path,
82
+ version,
83
+ raw: moduleId,
84
+ };
85
+ }
@@ -11,6 +11,7 @@ export declare class StyleProcessor {
11
11
  appendStyleContent(target: Root, content: string, from: string): void;
12
12
  readStyleFile(stylePath: string, seen?: Set<string>): string;
13
13
  collectImportedStyleFiles(styleFiles: Array<string>): Set<string>;
14
+ collectStyleImportSpecifiers(styleFiles: Array<string>): Set<string>;
14
15
  private parse;
15
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.
@@ -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(entry.moduleStyleImports, styleDir),
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auklet",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "author": "chentao.arthur",
6
6
  "packageManager": "pnpm@10.27.0",