auklet 0.0.1 → 0.0.2
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 +207 -0
- package/bin/entry.cjs +136 -0
- package/dist/build/runTsdown.d.ts +8 -0
- package/dist/build/runTsdown.js +36 -0
- package/dist/build/tsdownConfig.d.ts +12 -0
- package/dist/build/tsdownConfig.js +223 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +9 -0
- package/dist/configLoader.d.ts +8 -0
- package/dist/configLoader.js +85 -0
- package/dist/css/core/config.d.ts +2 -0
- package/dist/css/core/config.js +18 -0
- package/dist/css/core/constants.d.ts +3 -0
- package/dist/css/core/constants.js +3 -0
- package/dist/css/core/moduleCssGraph.d.ts +51 -0
- package/dist/css/core/moduleCssGraph.js +412 -0
- package/dist/css/core/moduleStyleImportCollector.d.ts +29 -0
- package/dist/css/core/moduleStyleImportCollector.js +285 -0
- package/dist/css/core/path.d.ts +4 -0
- package/dist/css/core/path.js +26 -0
- package/dist/css/core/styleEntry.d.ts +45 -0
- package/dist/css/core/styleEntry.js +108 -0
- package/dist/css/core/styleProcessor.d.ts +16 -0
- package/dist/css/core/styleProcessor.js +126 -0
- package/dist/css/core/workspaceStyleResolver.d.ts +18 -0
- package/dist/css/core/workspaceStyleResolver.js +100 -0
- package/dist/css/production/moduleCssBuilder.d.ts +33 -0
- package/dist/css/production/moduleCssBuilder.js +444 -0
- package/dist/css/vite/hmr.d.ts +15 -0
- package/dist/css/vite/hmr.js +153 -0
- package/dist/css/vite/vitePlugin.d.ts +24 -0
- package/dist/css/vite/vitePlugin.js +140 -0
- package/dist/css/watch/moduleCssWatcher.d.ts +19 -0
- package/dist/css/watch/moduleCssWatcher.js +106 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +9 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +59 -0
- package/package.json +80 -6
- package/index.js +0 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizeCssFileKey } from '#auklet/css/core/path';
|
|
3
|
+
// package CSS 的 HMR 不能直接走 Vite 原生 CSS 文件链路:
|
|
4
|
+
// - 浏览器 import 的是 auklet-css:* 虚拟 CSS 模块,不是真实的
|
|
5
|
+
// packages/*/src/**/*.css 文件,所以真实 CSS 变化时 Vite 的 modules 可能为空。
|
|
6
|
+
// - Vite dev 会把 CSS 转成自接受的 JS 模块,重新执行模块里的 updateStyle()
|
|
7
|
+
// 才能更新样式,因此这里手动发送 js-update,而不是 css-update。
|
|
8
|
+
// - @tailwindcss/vite 会在相关 CSS 变化时主动发 full-reload。package CSS 已由
|
|
9
|
+
// 这个插件接管 HMR 时,需要在一个很短的窗口内吞掉这次 reload。
|
|
10
|
+
const HMR_LOG_PREFIX = '[auklet:css:vite]';
|
|
11
|
+
const FULL_RELOAD_SUPPRESS_MS = 100;
|
|
12
|
+
const DUPLICATE_UPDATE_IGNORE_MS = 500;
|
|
13
|
+
const toBrowserVirtualPath = (id) => {
|
|
14
|
+
return `/@id/${id.replace('\0', '__x00__')}`;
|
|
15
|
+
};
|
|
16
|
+
const getRelativeFile = (file) => {
|
|
17
|
+
return path.relative(process.cwd(), file);
|
|
18
|
+
};
|
|
19
|
+
const invalidateVirtualModules = (server, graph) => {
|
|
20
|
+
const modules = [];
|
|
21
|
+
for (const packageName of graph.getWorkspacePackageNames()) {
|
|
22
|
+
for (const entry of ['style.css', 'external.css', 'module.css']) {
|
|
23
|
+
const module = server.moduleGraph.getModuleById(
|
|
24
|
+
`\0auklet-css:${packageName}/${entry}`,
|
|
25
|
+
);
|
|
26
|
+
if (!module) continue;
|
|
27
|
+
server.moduleGraph.invalidateModule(module);
|
|
28
|
+
modules.push(module);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return modules;
|
|
32
|
+
};
|
|
33
|
+
const addVirtualCssDependency = (virtualIdsByDependency, file, virtualId) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const normalizedFile = normalizeCssFileKey(file);
|
|
36
|
+
const values =
|
|
37
|
+
(_a = virtualIdsByDependency.get(normalizedFile)) !== null && _a !== void 0
|
|
38
|
+
? _a
|
|
39
|
+
: new Set();
|
|
40
|
+
values.add(virtualId);
|
|
41
|
+
virtualIdsByDependency.set(normalizedFile, values);
|
|
42
|
+
};
|
|
43
|
+
const getDependencyVirtualIds = (virtualIdsByDependency, file) => {
|
|
44
|
+
var _a;
|
|
45
|
+
return Array.from(
|
|
46
|
+
(_a = virtualIdsByDependency.get(normalizeCssFileKey(file))) !== null &&
|
|
47
|
+
_a !== void 0
|
|
48
|
+
? _a
|
|
49
|
+
: [],
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
const getDependencyVirtualModules = (virtualIdsByDependency, server, file) => {
|
|
53
|
+
return getDependencyVirtualIds(virtualIdsByDependency, file).flatMap((id) => {
|
|
54
|
+
const module = server.moduleGraph.getModuleById(id);
|
|
55
|
+
return module ? [module] : [];
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
export class AukletCssHmr {
|
|
59
|
+
constructor(graph) {
|
|
60
|
+
this.graph = graph;
|
|
61
|
+
this.lastUpdateTimes = new Map();
|
|
62
|
+
this.suppressFullReloadUntil = 0;
|
|
63
|
+
this.virtualIdsByDependency = new Map();
|
|
64
|
+
}
|
|
65
|
+
trackVirtualCssDependency(file, virtualId) {
|
|
66
|
+
addVirtualCssDependency(this.virtualIdsByDependency, file, virtualId);
|
|
67
|
+
}
|
|
68
|
+
installFullReloadGuard(server) {
|
|
69
|
+
const send = server.ws.send.bind(server.ws);
|
|
70
|
+
server.ws.send = (payload, data) => {
|
|
71
|
+
if (
|
|
72
|
+
typeof payload !== 'string' &&
|
|
73
|
+
payload.type === 'full-reload' &&
|
|
74
|
+
this.shouldSuppressFullReload()
|
|
75
|
+
) {
|
|
76
|
+
console.info(`${HMR_LOG_PREFIX} suppressed package css full-reload`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof payload === 'string') {
|
|
80
|
+
send(payload, data);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
send(payload);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
handleStyleHotUpdate(context) {
|
|
87
|
+
const graph = this.graph();
|
|
88
|
+
if (
|
|
89
|
+
!graph.isWorkspaceSourceGraphFile(context.file) ||
|
|
90
|
+
!graph.isStyleFile(context.file)
|
|
91
|
+
) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (this.isDuplicateUpdate(context.file)) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
this.suppressFullReload();
|
|
98
|
+
const virtualIds = getDependencyVirtualIds(
|
|
99
|
+
this.virtualIdsByDependency,
|
|
100
|
+
context.file,
|
|
101
|
+
);
|
|
102
|
+
const modules = getDependencyVirtualModules(
|
|
103
|
+
this.virtualIdsByDependency,
|
|
104
|
+
context.server,
|
|
105
|
+
context.file,
|
|
106
|
+
);
|
|
107
|
+
for (const module of modules) {
|
|
108
|
+
context.server.moduleGraph.invalidateModule(module);
|
|
109
|
+
}
|
|
110
|
+
invalidateVirtualModules(context.server, graph);
|
|
111
|
+
const updates = virtualIds.map((id) => {
|
|
112
|
+
const browserPath = toBrowserVirtualPath(id);
|
|
113
|
+
return {
|
|
114
|
+
type: 'js-update',
|
|
115
|
+
path: browserPath,
|
|
116
|
+
acceptedPath: browserPath,
|
|
117
|
+
timestamp: context.timestamp,
|
|
118
|
+
explicitImportRequired: false,
|
|
119
|
+
isWithinCircularImport: false,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
console.info(
|
|
123
|
+
`${HMR_LOG_PREFIX} package css hmr ${getRelativeFile(
|
|
124
|
+
context.file,
|
|
125
|
+
)} tracked=${virtualIds.length} updates=${updates.length}`,
|
|
126
|
+
);
|
|
127
|
+
if (updates.length) {
|
|
128
|
+
context.server.ws.send({
|
|
129
|
+
type: 'update',
|
|
130
|
+
updates,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
suppressFullReload() {
|
|
136
|
+
this.suppressFullReloadUntil = Date.now() + FULL_RELOAD_SUPPRESS_MS;
|
|
137
|
+
}
|
|
138
|
+
shouldSuppressFullReload() {
|
|
139
|
+
return Date.now() <= this.suppressFullReloadUntil;
|
|
140
|
+
}
|
|
141
|
+
isDuplicateUpdate(file) {
|
|
142
|
+
var _a;
|
|
143
|
+
const now = Date.now();
|
|
144
|
+
const normalizedFile = normalizeCssFileKey(file);
|
|
145
|
+
const lastUpdateTime =
|
|
146
|
+
(_a = this.lastUpdateTimes.get(normalizedFile)) !== null && _a !== void 0
|
|
147
|
+
? _a
|
|
148
|
+
: 0;
|
|
149
|
+
const isDuplicate = now - lastUpdateTime < DUPLICATE_UPDATE_IGNORE_MS;
|
|
150
|
+
this.lastUpdateTimes.set(normalizedFile, now);
|
|
151
|
+
return isDuplicate;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HotUpdateOptions, ViteDevServer } from 'vite';
|
|
2
|
+
import { type ModuleCssGraphOptions } from '#auklet/css/core/moduleCssGraph';
|
|
3
|
+
export type AukletCssPluginOptions = Partial<
|
|
4
|
+
Pick<ModuleCssGraphOptions, 'workspaceRoot'>
|
|
5
|
+
> &
|
|
6
|
+
Omit<ModuleCssGraphOptions, 'workspaceRoot'>;
|
|
7
|
+
export declare function aukletCssPlugin(options?: AukletCssPluginOptions): {
|
|
8
|
+
name: string;
|
|
9
|
+
apply: 'serve';
|
|
10
|
+
enforce: 'pre';
|
|
11
|
+
configResolved(config: { root: string }): void;
|
|
12
|
+
resolveId(id: string): string | null;
|
|
13
|
+
load(
|
|
14
|
+
this: {
|
|
15
|
+
addWatchFile?: (file: string) => void;
|
|
16
|
+
},
|
|
17
|
+
id: string,
|
|
18
|
+
): Promise<string | null>;
|
|
19
|
+
configureServer(server: ViteDevServer): void;
|
|
20
|
+
hotUpdate: {
|
|
21
|
+
order: 'pre';
|
|
22
|
+
handler(context: HotUpdateOptions): never[] | undefined;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ModuleCssGraph } from '#auklet/css/core/moduleCssGraph';
|
|
4
|
+
import { AukletCssHmr } from '#auklet/css/vite/hmr';
|
|
5
|
+
const WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
6
|
+
const VIRTUAL_ID_PREFIX = 'virtual:auklet-css:';
|
|
7
|
+
const RESOLVED_VIRTUAL_ID_PREFIX = '\0auklet-css:';
|
|
8
|
+
const BROWSER_VIRTUAL_ID_PREFIX = 'auklet-css:';
|
|
9
|
+
const stripQuery = (id) => id.split('?')[0];
|
|
10
|
+
const toResolvedVirtualId = (id) => {
|
|
11
|
+
if (id.startsWith(RESOLVED_VIRTUAL_ID_PREFIX)) {
|
|
12
|
+
return id;
|
|
13
|
+
}
|
|
14
|
+
if (id.startsWith(BROWSER_VIRTUAL_ID_PREFIX)) {
|
|
15
|
+
return `${RESOLVED_VIRTUAL_ID_PREFIX}${id.slice(
|
|
16
|
+
BROWSER_VIRTUAL_ID_PREFIX.length,
|
|
17
|
+
)}`;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
const findWorkspaceRoot = (startDir) => {
|
|
22
|
+
let current = path.resolve(startDir);
|
|
23
|
+
while (true) {
|
|
24
|
+
if (fs.existsSync(path.join(current, WORKSPACE_FILE))) {
|
|
25
|
+
return current;
|
|
26
|
+
}
|
|
27
|
+
const parent = path.dirname(current);
|
|
28
|
+
if (parent === current) return null;
|
|
29
|
+
current = parent;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const createModuleCssGraph = (options, viteRoot) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const workspaceRoot =
|
|
35
|
+
(_b =
|
|
36
|
+
(_a = options.workspaceRoot) !== null && _a !== void 0
|
|
37
|
+
? _a
|
|
38
|
+
: findWorkspaceRoot(viteRoot)) !== null && _b !== void 0
|
|
39
|
+
? _b
|
|
40
|
+
: process.cwd();
|
|
41
|
+
return new ModuleCssGraph({
|
|
42
|
+
...options,
|
|
43
|
+
workspaceRoot,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const invalidateVirtualModules = (server, graph) => {
|
|
47
|
+
const modules = [];
|
|
48
|
+
for (const packageName of graph.getWorkspacePackageNames()) {
|
|
49
|
+
for (const entry of ['style.css', 'external.css', 'module.css']) {
|
|
50
|
+
const module = server.moduleGraph.getModuleById(
|
|
51
|
+
`${RESOLVED_VIRTUAL_ID_PREFIX}${packageName}/${entry}`,
|
|
52
|
+
);
|
|
53
|
+
if (!module) continue;
|
|
54
|
+
server.moduleGraph.invalidateModule(module);
|
|
55
|
+
modules.push(module);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return modules;
|
|
59
|
+
};
|
|
60
|
+
export function aukletCssPlugin(options = {}) {
|
|
61
|
+
let graph = null;
|
|
62
|
+
const getGraph = () => {
|
|
63
|
+
if (!graph) {
|
|
64
|
+
graph = createModuleCssGraph(options, process.cwd());
|
|
65
|
+
}
|
|
66
|
+
return graph;
|
|
67
|
+
};
|
|
68
|
+
const hmr = new AukletCssHmr(getGraph);
|
|
69
|
+
return {
|
|
70
|
+
name: 'auklet-css',
|
|
71
|
+
apply: 'serve',
|
|
72
|
+
enforce: 'pre',
|
|
73
|
+
configResolved(config) {
|
|
74
|
+
graph = createModuleCssGraph(options, config.root);
|
|
75
|
+
},
|
|
76
|
+
resolveId(id) {
|
|
77
|
+
const graph = getGraph();
|
|
78
|
+
const cleanId = stripQuery(id);
|
|
79
|
+
const resolvedVirtualId = toResolvedVirtualId(cleanId);
|
|
80
|
+
if (resolvedVirtualId) return resolvedVirtualId;
|
|
81
|
+
if (cleanId.startsWith(VIRTUAL_ID_PREFIX)) {
|
|
82
|
+
return `${RESOLVED_VIRTUAL_ID_PREFIX}${cleanId.slice(
|
|
83
|
+
VIRTUAL_ID_PREFIX.length,
|
|
84
|
+
)}`;
|
|
85
|
+
}
|
|
86
|
+
if (!graph.parsePackageCssId(cleanId)) return null;
|
|
87
|
+
return `${RESOLVED_VIRTUAL_ID_PREFIX}${cleanId}`;
|
|
88
|
+
},
|
|
89
|
+
async load(id) {
|
|
90
|
+
var _a;
|
|
91
|
+
if (!id.startsWith(RESOLVED_VIRTUAL_ID_PREFIX)) return null;
|
|
92
|
+
const originalId = id.slice(RESOLVED_VIRTUAL_ID_PREFIX.length);
|
|
93
|
+
const graph = getGraph();
|
|
94
|
+
const parsed = graph.parsePackageCssId(originalId);
|
|
95
|
+
if (!parsed) return null;
|
|
96
|
+
const result = await graph.createPackageCssCode(parsed);
|
|
97
|
+
for (const file of result.watchFiles) {
|
|
98
|
+
hmr.trackVirtualCssDependency(file, id);
|
|
99
|
+
(_a = this.addWatchFile) === null || _a === void 0
|
|
100
|
+
? void 0
|
|
101
|
+
: _a.call(this, file);
|
|
102
|
+
}
|
|
103
|
+
return result.code;
|
|
104
|
+
},
|
|
105
|
+
configureServer(server) {
|
|
106
|
+
const graph = getGraph();
|
|
107
|
+
hmr.installFullReloadGuard(server);
|
|
108
|
+
server.watcher.add(graph.getWatchRoots());
|
|
109
|
+
const invalidateCssGraph = (file) => {
|
|
110
|
+
if (!graph.isWorkspaceSourceGraphFile(file)) return false;
|
|
111
|
+
invalidateVirtualModules(server, graph);
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
const reloadCssGraph = (file) => {
|
|
115
|
+
if (!invalidateCssGraph(file)) return;
|
|
116
|
+
server.ws.send({ type: 'full-reload' });
|
|
117
|
+
};
|
|
118
|
+
const handleSourceAddOrUnlink = (file) => {
|
|
119
|
+
if (graph.isStyleFile(file)) {
|
|
120
|
+
invalidateCssGraph(file);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
reloadCssGraph(file);
|
|
124
|
+
};
|
|
125
|
+
server.watcher.on('add', handleSourceAddOrUnlink);
|
|
126
|
+
server.watcher.on('unlink', handleSourceAddOrUnlink);
|
|
127
|
+
server.watcher.on('change', (file) => {
|
|
128
|
+
if (graph.isCssConfigFile(file)) {
|
|
129
|
+
reloadCssGraph(file);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
hotUpdate: {
|
|
134
|
+
order: 'pre',
|
|
135
|
+
handler(context) {
|
|
136
|
+
return hmr.handleStyleHotUpdate(context);
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModuleCssBuildConfig,
|
|
3
|
+
ModuleCssBuildContext,
|
|
4
|
+
} from '#auklet/types';
|
|
5
|
+
export declare class ModuleCssWatcher {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private readonly context;
|
|
8
|
+
private readonly logger?;
|
|
9
|
+
private timer;
|
|
10
|
+
private isBuilding;
|
|
11
|
+
private shouldRebuild;
|
|
12
|
+
private watcher;
|
|
13
|
+
constructor(context?: ModuleCssBuildContext, config?: ModuleCssBuildConfig);
|
|
14
|
+
watch(): Promise<void>;
|
|
15
|
+
private rebuild;
|
|
16
|
+
private refreshWatcher;
|
|
17
|
+
private scheduleBuild;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import chokidar from 'chokidar';
|
|
4
|
+
import { aukletConfigFile } from '#auklet/config';
|
|
5
|
+
import { moduleCssBuildConfig } from '#auklet/css/core/config';
|
|
6
|
+
import { ModuleCssBuilder } from '#auklet/css/production/moduleCssBuilder';
|
|
7
|
+
export class ModuleCssWatcher {
|
|
8
|
+
constructor(context = {}, config = moduleCssBuildConfig) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.timer = null;
|
|
11
|
+
this.isBuilding = false;
|
|
12
|
+
this.shouldRebuild = false;
|
|
13
|
+
this.watcher = null;
|
|
14
|
+
this.context = {
|
|
15
|
+
packageRoot: process.cwd(),
|
|
16
|
+
...context,
|
|
17
|
+
};
|
|
18
|
+
this.logger = context.logger;
|
|
19
|
+
}
|
|
20
|
+
async watch() {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
await this.rebuild();
|
|
23
|
+
(_b = (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log) ===
|
|
24
|
+
null || _b === void 0
|
|
25
|
+
? void 0
|
|
26
|
+
: _b.call(_a, '[auklet:css] watch mode ready');
|
|
27
|
+
}
|
|
28
|
+
async rebuild() {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
if (this.isBuilding) {
|
|
31
|
+
this.shouldRebuild = true;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.isBuilding = true;
|
|
35
|
+
try {
|
|
36
|
+
const builder = new ModuleCssBuilder(this.context, this.config);
|
|
37
|
+
await builder.build();
|
|
38
|
+
await this.refreshWatcher();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
(_b =
|
|
41
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error) ===
|
|
42
|
+
null || _b === void 0
|
|
43
|
+
? void 0
|
|
44
|
+
: _b.call(_a, error);
|
|
45
|
+
} finally {
|
|
46
|
+
this.isBuilding = false;
|
|
47
|
+
if (this.shouldRebuild) {
|
|
48
|
+
this.shouldRebuild = false;
|
|
49
|
+
this.scheduleBuild();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async refreshWatcher() {
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
|
+
const cssOptions =
|
|
56
|
+
(_a = this.context.aukletConfig) !== null && _a !== void 0 ? _a : {};
|
|
57
|
+
const sourceDir =
|
|
58
|
+
(_c =
|
|
59
|
+
(_b = cssOptions.sourceDir) !== null && _b !== void 0
|
|
60
|
+
? _b
|
|
61
|
+
: this.context.sourceDir) !== null && _c !== void 0
|
|
62
|
+
? _c
|
|
63
|
+
: 'src';
|
|
64
|
+
const sourceRoot = path.join(this.context.packageRoot, sourceDir);
|
|
65
|
+
const configPath = path.join(this.context.packageRoot, aukletConfigFile);
|
|
66
|
+
const watchPaths = [sourceRoot, configPath].filter((file) =>
|
|
67
|
+
fs.existsSync(file),
|
|
68
|
+
);
|
|
69
|
+
await ((_d = this.watcher) === null || _d === void 0 ? void 0 : _d.close());
|
|
70
|
+
this.watcher = chokidar.watch(watchPaths, {
|
|
71
|
+
ignoreInitial: true,
|
|
72
|
+
interval: 300,
|
|
73
|
+
usePolling: true,
|
|
74
|
+
});
|
|
75
|
+
this.watcher.on('all', () => {
|
|
76
|
+
this.scheduleBuild();
|
|
77
|
+
});
|
|
78
|
+
this.watcher.on('error', (error) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
(_b =
|
|
81
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error) ===
|
|
82
|
+
null || _b === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _b.call(_a, error);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
scheduleBuild() {
|
|
88
|
+
if (this.timer) clearTimeout(this.timer);
|
|
89
|
+
this.timer = setTimeout(() => {
|
|
90
|
+
this.timer = null;
|
|
91
|
+
this.rebuild().catch((error) => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
(_b =
|
|
94
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error) ===
|
|
95
|
+
null || _b === void 0
|
|
96
|
+
? void 0
|
|
97
|
+
: _b.call(_a, error);
|
|
98
|
+
});
|
|
99
|
+
}, 80);
|
|
100
|
+
}
|
|
101
|
+
async close() {
|
|
102
|
+
var _a;
|
|
103
|
+
if (this.timer) clearTimeout(this.timer);
|
|
104
|
+
await ((_a = this.watcher) === null || _a === void 0 ? void 0 : _a.close());
|
|
105
|
+
}
|
|
106
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
CssOptions,
|
|
3
|
+
CssDependencyGroup,
|
|
4
|
+
AukletConfig,
|
|
5
|
+
LoadAukletConfigOptions,
|
|
6
|
+
ModuleCssBuildConfig,
|
|
7
|
+
ModuleCssBuildContext,
|
|
8
|
+
ModuleCssBuildOptions,
|
|
9
|
+
PackageBuildFormat,
|
|
10
|
+
PackageBuildOptions,
|
|
11
|
+
ResolvedModuleCssBuildContext,
|
|
12
|
+
StyleLanguage,
|
|
13
|
+
} from '#auklet/types';
|
|
14
|
+
export type { RunTsdownOptions } from '#auklet/build/runTsdown';
|
|
15
|
+
export type { AukletCssPluginOptions } from '#auklet/css/vite/vitePlugin';
|
|
16
|
+
export { aukletDefaultCssDependencyConfig } from '#auklet/config';
|
|
17
|
+
export {
|
|
18
|
+
loadAukletConfig,
|
|
19
|
+
resolveAukletConfigModule,
|
|
20
|
+
} from '#auklet/configLoader';
|
|
21
|
+
export { aukletCssPlugin } from '#auklet/css/vite/vitePlugin';
|
|
22
|
+
export { createTsdownArgs, runTsdown } from '#auklet/build/runTsdown';
|
|
23
|
+
export { ModuleCssWatcher } from '#auklet/css/watch/moduleCssWatcher';
|
|
24
|
+
export { ModuleCssBuilder } from '#auklet/css/production/moduleCssBuilder';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { aukletDefaultCssDependencyConfig } from '#auklet/config';
|
|
2
|
+
export {
|
|
3
|
+
loadAukletConfig,
|
|
4
|
+
resolveAukletConfigModule,
|
|
5
|
+
} from '#auklet/configLoader';
|
|
6
|
+
export { aukletCssPlugin } from '#auklet/css/vite/vitePlugin';
|
|
7
|
+
export { createTsdownArgs, runTsdown } from '#auklet/build/runTsdown';
|
|
8
|
+
export { ModuleCssWatcher } from '#auklet/css/watch/moduleCssWatcher';
|
|
9
|
+
export { ModuleCssBuilder } from '#auklet/css/production/moduleCssBuilder';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type CssDependencyGroup = {
|
|
2
|
+
global?: string | Array<string>;
|
|
3
|
+
themes?: Record<string, string>;
|
|
4
|
+
component?: string | Array<string>;
|
|
5
|
+
};
|
|
6
|
+
export interface CssOptions {
|
|
7
|
+
cssDependencies?: Record<string, CssDependencyGroup>;
|
|
8
|
+
themes?: Record<string, string>;
|
|
9
|
+
sourceDir?: string;
|
|
10
|
+
outputDir?: string;
|
|
11
|
+
}
|
|
12
|
+
export type PackageBuildFormat = 'cjs' | 'esm' | 'iife';
|
|
13
|
+
export type PackageBuildOptions = {
|
|
14
|
+
formats?: Array<PackageBuildFormat>;
|
|
15
|
+
banner?: string;
|
|
16
|
+
externals?: Array<string>;
|
|
17
|
+
modules?: boolean;
|
|
18
|
+
tsconfig?: string;
|
|
19
|
+
};
|
|
20
|
+
export interface AukletConfig extends CssOptions {
|
|
21
|
+
build?: PackageBuildOptions;
|
|
22
|
+
}
|
|
23
|
+
export type AukletLogger = {
|
|
24
|
+
log?: (...args: Array<unknown>) => void;
|
|
25
|
+
info?: (...args: Array<unknown>) => void;
|
|
26
|
+
error?: (...args: Array<unknown>) => void;
|
|
27
|
+
};
|
|
28
|
+
export type LoadAukletConfigOptions = {
|
|
29
|
+
configFile?: string;
|
|
30
|
+
cacheBust?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type StyleLanguage = 'css' | 'less';
|
|
33
|
+
export interface ModuleCssBuildContext {
|
|
34
|
+
packageRoot?: string;
|
|
35
|
+
aukletConfig?: AukletConfig;
|
|
36
|
+
logger?: AukletLogger;
|
|
37
|
+
sourceDir?: string;
|
|
38
|
+
outputDir?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ResolvedModuleCssBuildContext {
|
|
41
|
+
packageRoot: string;
|
|
42
|
+
sourceDir: string;
|
|
43
|
+
outputDir: string;
|
|
44
|
+
}
|
|
45
|
+
export type ModuleCssBuildOptions = {
|
|
46
|
+
aukletConfig?: AukletConfig;
|
|
47
|
+
logger?: AukletLogger;
|
|
48
|
+
};
|
|
49
|
+
export interface ModuleCssBuildOutputConfig {
|
|
50
|
+
outputFormats: Array<string>;
|
|
51
|
+
styleDir: string;
|
|
52
|
+
indexCssFile: string;
|
|
53
|
+
externalCssFile: string;
|
|
54
|
+
moduleCssFile: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ModuleCssBuildConfig {
|
|
57
|
+
output: ModuleCssBuildOutputConfig;
|
|
58
|
+
styleExtensions: Record<string, StyleLanguage>;
|
|
59
|
+
lessLanguage: StyleLanguage;
|
|
60
|
+
}
|
package/dist/types.js
ADDED
|
File without changes
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const POSIX_SEPARATOR = '/';
|
|
2
|
+
export declare const IMPORT_LIST_SEPARATOR = ',';
|
|
3
|
+
export declare const TEST_DIR_NAMES: Set<string>;
|
|
4
|
+
export declare const SOURCE_TEST_RE: RegExp;
|
|
5
|
+
export declare const SOURCE_MODULE_RE: RegExp;
|
|
6
|
+
export declare const SOURCE_DECLARATION_RE: RegExp;
|
|
7
|
+
export declare const TYPE_IMPORT_PREFIX: RegExp;
|
|
8
|
+
export declare const IMPORT_ALIAS_SEPARATOR: RegExp;
|
|
9
|
+
export declare function isTestDir(name: string): boolean;
|
|
10
|
+
export declare function isTestFile(name: string): boolean;
|
|
11
|
+
export declare function fileWalker(dir: string): Array<string>;
|
|
12
|
+
export declare function toPosixPath(value: string): string;
|
|
13
|
+
export declare function removeExtension(file: string): string;
|
|
14
|
+
export declare function getSourceModuleDir(file: string): string;
|
|
15
|
+
export declare function escapeRegExp(value: string): string;
|
|
16
|
+
export declare function appendUniqueMapValue<K, V>(
|
|
17
|
+
map: Map<K, Array<V>>,
|
|
18
|
+
key: K,
|
|
19
|
+
value: V,
|
|
20
|
+
): void;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { slash } from 'aidly';
|
|
4
|
+
export const POSIX_SEPARATOR = '/';
|
|
5
|
+
export const IMPORT_LIST_SEPARATOR = ',';
|
|
6
|
+
export const TEST_DIR_NAMES = new Set([
|
|
7
|
+
'__test__',
|
|
8
|
+
'__tests__',
|
|
9
|
+
'test',
|
|
10
|
+
'tests',
|
|
11
|
+
]);
|
|
12
|
+
export const SOURCE_TEST_RE = /\.(spec|test)\.[cm]?(ts|tsx|js|jsx)$/;
|
|
13
|
+
export const SOURCE_MODULE_RE = /\.(ts|tsx)$/;
|
|
14
|
+
export const SOURCE_DECLARATION_RE = /\.d\.[cm]?ts$/;
|
|
15
|
+
export const TYPE_IMPORT_PREFIX = /^type\s+/;
|
|
16
|
+
export const IMPORT_ALIAS_SEPARATOR = /\s+as\s+/;
|
|
17
|
+
export function isTestDir(name) {
|
|
18
|
+
return TEST_DIR_NAMES.has(name);
|
|
19
|
+
}
|
|
20
|
+
export function isTestFile(name) {
|
|
21
|
+
return SOURCE_TEST_RE.test(name);
|
|
22
|
+
}
|
|
23
|
+
export function fileWalker(dir) {
|
|
24
|
+
const files = [];
|
|
25
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (entry.isDirectory() && isTestDir(entry.name)) continue;
|
|
28
|
+
const fullPath = path.join(dir, entry.name);
|
|
29
|
+
if (entry.isDirectory()) {
|
|
30
|
+
files.push(...fileWalker(fullPath));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (isTestFile(entry.name)) continue;
|
|
34
|
+
files.push(fullPath);
|
|
35
|
+
}
|
|
36
|
+
return files;
|
|
37
|
+
}
|
|
38
|
+
export function toPosixPath(value) {
|
|
39
|
+
return slash(value);
|
|
40
|
+
}
|
|
41
|
+
export function removeExtension(file) {
|
|
42
|
+
return file.slice(0, -path.extname(file).length);
|
|
43
|
+
}
|
|
44
|
+
export function getSourceModuleDir(file) {
|
|
45
|
+
const filename = path.basename(file);
|
|
46
|
+
if (filename.startsWith('index.')) {
|
|
47
|
+
return path.dirname(file);
|
|
48
|
+
}
|
|
49
|
+
return removeExtension(file);
|
|
50
|
+
}
|
|
51
|
+
export function escapeRegExp(value) {
|
|
52
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
53
|
+
}
|
|
54
|
+
export function appendUniqueMapValue(map, key, value) {
|
|
55
|
+
var _a;
|
|
56
|
+
const values = (_a = map.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
57
|
+
if (!values.includes(value)) values.push(value);
|
|
58
|
+
map.set(key, values);
|
|
59
|
+
}
|