auklet 0.0.3 → 0.0.4

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 (79) hide show
  1. package/README.md +81 -42
  2. package/bin/entry.cjs +33 -11
  3. package/dist/build/runTsdown.js +2 -3
  4. package/dist/build/tsdownConfig.d.ts +138 -2
  5. package/dist/build/tsdownConfig.js +108 -63
  6. package/dist/config.d.ts +38 -6
  7. package/dist/config.js +43 -7
  8. package/dist/configLoader.js +1 -2
  9. package/dist/css/config.d.ts +2 -0
  10. package/dist/css/config.js +10 -0
  11. package/dist/css/constants.d.ts +6 -0
  12. package/dist/css/constants.js +6 -0
  13. package/dist/css/core/moduleGraph.d.ts +55 -0
  14. package/dist/css/core/moduleGraph.js +362 -0
  15. package/dist/css/core/moduleGraphRequestCache.d.ts +80 -0
  16. package/dist/css/core/moduleGraphRequestCache.js +92 -0
  17. package/dist/css/core/moduleStyleImportCollector.d.ts +5 -3
  18. package/dist/css/core/moduleStyleImportCollector.js +27 -45
  19. package/dist/css/core/style/dependencies.d.ts +20 -0
  20. package/dist/css/core/style/dependencies.js +55 -0
  21. package/dist/css/core/style/files.d.ts +8 -0
  22. package/dist/css/core/style/files.js +19 -0
  23. package/dist/css/core/style/plan.d.ts +59 -0
  24. package/dist/css/core/style/plan.js +27 -0
  25. package/dist/css/core/style/specifier.d.ts +14 -0
  26. package/dist/css/core/style/specifier.js +27 -0
  27. package/dist/css/core/styleModuleEntryPlanner.d.ts +29 -0
  28. package/dist/css/core/styleModuleEntryPlanner.js +66 -0
  29. package/dist/css/core/stylePackageContext.d.ts +27 -0
  30. package/dist/css/core/stylePackageContext.js +57 -0
  31. package/dist/css/core/styleProcessor.d.ts +3 -3
  32. package/dist/css/core/styleProcessor.js +18 -35
  33. package/dist/css/core/workspaceStyleResolver.d.ts +4 -5
  34. package/dist/css/core/workspaceStyleResolver.js +12 -28
  35. package/dist/css/production/builder.d.ts +18 -0
  36. package/dist/css/production/builder.js +68 -0
  37. package/dist/css/production/format/componentWriter.d.ts +12 -0
  38. package/dist/css/production/format/componentWriter.js +67 -0
  39. package/dist/css/production/format/entryWriter.d.ts +12 -0
  40. package/dist/css/production/format/entryWriter.js +54 -0
  41. package/dist/css/production/format/externalWriter.d.ts +9 -0
  42. package/dist/css/production/format/externalWriter.js +39 -0
  43. package/dist/css/production/format/moduleWriter.d.ts +8 -0
  44. package/dist/css/production/format/moduleWriter.js +31 -0
  45. package/dist/css/production/format/shared.d.ts +20 -0
  46. package/dist/css/production/format/shared.js +8 -0
  47. package/dist/css/production/format/sourceWriter.d.ts +6 -0
  48. package/dist/css/production/format/sourceWriter.js +16 -0
  49. package/dist/css/production/format/themeWriter.d.ts +16 -0
  50. package/dist/css/production/format/themeWriter.js +80 -0
  51. package/dist/css/production/moduleOutputWriter.d.ts +26 -0
  52. package/dist/css/production/moduleOutputWriter.js +83 -0
  53. package/dist/css/production/packageEntryWriter.d.ts +20 -0
  54. package/dist/css/production/packageEntryWriter.js +55 -0
  55. package/dist/css/vite/hmr.d.ts +4 -4
  56. package/dist/css/vite/hmr.js +14 -27
  57. package/dist/css/vite/vitePlugin.d.ts +5 -5
  58. package/dist/css/vite/vitePlugin.js +21 -30
  59. package/dist/css/watch/{moduleCssWatcher.d.ts → watcher.d.ts} +7 -4
  60. package/dist/css/watch/watcher.js +82 -0
  61. package/dist/index.d.ts +15 -12
  62. package/dist/index.js +6 -5
  63. package/dist/types.d.ts +40 -20
  64. package/dist/utils.d.ts +5 -1
  65. package/dist/utils.js +37 -12
  66. package/package.json +19 -14
  67. package/dist/css/core/config.d.ts +0 -2
  68. package/dist/css/core/config.js +0 -11
  69. package/dist/css/core/constants.d.ts +0 -3
  70. package/dist/css/core/constants.js +0 -3
  71. package/dist/css/core/moduleCssGraph.d.ts +0 -51
  72. package/dist/css/core/moduleCssGraph.js +0 -416
  73. package/dist/css/core/path.d.ts +0 -4
  74. package/dist/css/core/path.js +0 -26
  75. package/dist/css/core/styleEntry.d.ts +0 -45
  76. package/dist/css/core/styleEntry.js +0 -108
  77. package/dist/css/production/moduleCssBuilder.d.ts +0 -33
  78. package/dist/css/production/moduleCssBuilder.js +0 -445
  79. package/dist/css/watch/moduleCssWatcher.js +0 -106
@@ -1,445 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { moduleCssBuildConfig } from '#auklet/css/core/config';
4
- import { aukletDefaultCssOptions } from '#auklet/config';
5
- import { StyleProcessor } from '#auklet/css/core/styleProcessor';
6
- import { ModuleStyleImportCollector } from '#auklet/css/core/moduleStyleImportCollector';
7
- import {
8
- THEMES_DIR,
9
- createStyleFileKey,
10
- createStyleFileKeySet,
11
- groupStyleFilesByDir,
12
- getExternalStyleDependencies,
13
- getGlobalStyleDependencies,
14
- getThemeStyleDependencies,
15
- resolveThemeStyleFiles,
16
- } from '#auklet/css/core/styleEntry';
17
- import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
18
- import { fileWalker, getSourceModuleDir, toPosixPath } from '#auklet/utils';
19
- const EMPTY_MODULE_STYLE_ENTRY_COMMENT =
20
- '/* Empty style entry kept so automated tooling can resolve this module CSS path. */\n';
21
- export class ModuleCssBuilder {
22
- constructor(context = {}, config = moduleCssBuildConfig) {
23
- this.config = config;
24
- this.context = {
25
- packageRoot: process.cwd(),
26
- sourceDir: context.sourceDir,
27
- outputDir: context.outputDir,
28
- ...context,
29
- };
30
- this.logger = context.logger;
31
- this.applyContext(this.createBuildContext({}));
32
- }
33
- async build(options = {}) {
34
- var _a, _b, _c, _d, _e, _f;
35
- const cssOptions =
36
- (_b =
37
- (_a = options.aukletConfig) !== null && _a !== void 0
38
- ? _a
39
- : this.context.aukletConfig) !== null && _b !== void 0
40
- ? _b
41
- : {};
42
- const logger =
43
- (_c = options.logger) !== null && _c !== void 0 ? _c : this.logger;
44
- const context = this.createBuildContext(cssOptions);
45
- this.applyContext(context);
46
- (_d = logger === null || logger === void 0 ? void 0 : logger.log) ===
47
- null || _d === void 0
48
- ? void 0
49
- : _d.call(
50
- logger,
51
- `[auklet:css] build ${path.basename(context.packageRoot)}`,
52
- );
53
- const sourceFiles = fileWalker(this.srcRoot);
54
- const themeFiles = resolveThemeStyleFiles(cssOptions, context.packageRoot);
55
- const themeFileKeys = createStyleFileKeySet(themeFiles.values());
56
- const styleFiles = this.getStyleFiles(sourceFiles).filter(
57
- (styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)),
58
- );
59
- const moduleStyleImports = this.importCollector.collect(
60
- sourceFiles,
61
- cssOptions,
62
- );
63
- const outputs = [];
64
- const packageStyle = this.writePackageStyles(
65
- styleFiles,
66
- themeFiles,
67
- cssOptions,
68
- context,
69
- );
70
- if (packageStyle) outputs.push(packageStyle);
71
- for (const format of this.config.output.outputFormats) {
72
- const outRoot = path.join(context.packageRoot, context.outputDir, format);
73
- this.cleanThemeStyles(outRoot);
74
- this.copyStyleFiles(styleFiles, outRoot);
75
- const themeStyles = this.writeThemeStyles(themeFiles, outRoot);
76
- const themeEntries = this.writeThemeEntries(
77
- themeStyles,
78
- outRoot,
79
- cssOptions,
80
- );
81
- const externalStyle = this.writeExternalStyle(outRoot, cssOptions);
82
- const moduleStyle = this.writeModuleStyle(styleFiles, outRoot);
83
- const entryStyle = this.writeEntryStyle(
84
- outRoot,
85
- cssOptions,
86
- themeStyles.map((themeStyle) => themeStyle.file),
87
- moduleStyle,
88
- );
89
- outputs.push(...themeStyles.map((themeStyle) => themeStyle.file));
90
- outputs.push(...themeEntries);
91
- if (externalStyle) outputs.push(externalStyle);
92
- if (moduleStyle) outputs.push(moduleStyle);
93
- if (entryStyle) outputs.push(entryStyle);
94
- outputs.push(
95
- ...this.writeComponentStyleEntries(
96
- sourceFiles,
97
- styleFiles,
98
- outRoot,
99
- moduleStyleImports,
100
- ),
101
- );
102
- }
103
- (_e = logger === null || logger === void 0 ? void 0 : logger.log) ===
104
- null || _e === void 0
105
- ? void 0
106
- : _e.call(
107
- logger,
108
- `[auklet:css] ${styleFiles.length} source style file(s), ${outputs.length} output entry file(s)`,
109
- );
110
- for (const output of outputs) {
111
- (_f = logger === null || logger === void 0 ? void 0 : logger.log) ===
112
- null || _f === void 0
113
- ? void 0
114
- : _f.call(
115
- logger,
116
- `[auklet:css] + ${toPosixPath(
117
- path.relative(context.packageRoot, output),
118
- )}`,
119
- );
120
- }
121
- }
122
- getStyleFiles(files) {
123
- return files.filter((file) =>
124
- this.config.styleExtensions.includes(path.extname(file)),
125
- );
126
- }
127
- createBuildContext(cssOptions) {
128
- var _a, _b, _c, _d;
129
- return {
130
- packageRoot: this.context.packageRoot,
131
- sourceDir:
132
- (_b =
133
- (_a = cssOptions.sourceDir) !== null && _a !== void 0
134
- ? _a
135
- : this.context.sourceDir) !== null && _b !== void 0
136
- ? _b
137
- : aukletDefaultCssOptions.sourceDir,
138
- outputDir:
139
- (_d =
140
- (_c = cssOptions.outputDir) !== null && _c !== void 0
141
- ? _c
142
- : this.context.outputDir) !== null && _d !== void 0
143
- ? _d
144
- : aukletDefaultCssOptions.outputDir,
145
- };
146
- }
147
- applyContext(context) {
148
- this.srcRoot = path.join(context.packageRoot, context.sourceDir);
149
- this.resolver = new WorkspaceStyleResolver(this.config, context);
150
- this.styleProcessor = new StyleProcessor(this.config, this.resolver);
151
- this.importCollector = new ModuleStyleImportCollector(
152
- this.srcRoot,
153
- context.packageRoot,
154
- this.resolver,
155
- this.config.styleExtensions,
156
- );
157
- }
158
- copyStyleFiles(files, outRoot) {
159
- for (const sourceFile of files) {
160
- const relative = path.relative(this.srcRoot, sourceFile);
161
- const target = path.join(outRoot, relative);
162
- fs.mkdirSync(path.dirname(target), { recursive: true });
163
- fs.copyFileSync(sourceFile, target);
164
- }
165
- }
166
- writePackageStyles(styleFiles, themeFiles, buildConfig, context) {
167
- var _a;
168
- const seen = new Set();
169
- const root = this.styleProcessor.createRoot();
170
- for (const cssPath of themeFiles.values()) {
171
- const content = this.styleProcessor.readStyleFile(cssPath, seen);
172
- if (content.trim()) {
173
- this.styleProcessor.appendStyleContent(root, content, cssPath);
174
- }
175
- }
176
- for (const specifier of getGlobalStyleDependencies(buildConfig)) {
177
- const cssPath = this.resolver.resolveStyleDependency(specifier);
178
- if (!cssPath) continue;
179
- const content = this.styleProcessor.readStyleFile(cssPath, seen);
180
- if (content.trim()) {
181
- this.styleProcessor.appendStyleContent(root, content, cssPath);
182
- }
183
- }
184
- for (const styleFile of styleFiles) {
185
- const content = this.styleProcessor.readStyleFile(styleFile, seen);
186
- if (content.trim()) {
187
- this.styleProcessor.appendStyleContent(root, content, styleFile);
188
- }
189
- }
190
- if (!((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length))
191
- return null;
192
- fs.mkdirSync(path.join(context.packageRoot, context.outputDir), {
193
- recursive: true,
194
- });
195
- const target = path.join(
196
- context.packageRoot,
197
- context.outputDir,
198
- this.config.output.indexCssFile,
199
- );
200
- fs.writeFileSync(target, this.styleProcessor.stringify(root));
201
- return target;
202
- }
203
- writeEntryStyle(outRoot, buildConfig, themeStyles, moduleStyle) {
204
- var _a;
205
- const target = path.join(
206
- outRoot,
207
- this.config.output.styleDir,
208
- this.config.output.indexCssFile,
209
- );
210
- const root = this.styleProcessor.createRoot();
211
- const styleDir = path.dirname(target);
212
- for (const specifier of getGlobalStyleDependencies(buildConfig)) {
213
- this.styleProcessor.appendImportRule(root, specifier);
214
- }
215
- for (const style of [...themeStyles, moduleStyle]) {
216
- if (!style) continue;
217
- this.styleProcessor.appendImportRule(
218
- root,
219
- this.toRelativeImportSpecifier(styleDir, style),
220
- );
221
- }
222
- if (!((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length))
223
- return null;
224
- fs.mkdirSync(path.dirname(target), { recursive: true });
225
- fs.writeFileSync(target, this.styleProcessor.stringify(root));
226
- return target;
227
- }
228
- writeThemeStyles(themeFiles, outRoot) {
229
- var _a;
230
- const outputs = [];
231
- const themesDir = path.join(
232
- outRoot,
233
- this.config.output.styleDir,
234
- THEMES_DIR,
235
- );
236
- for (const [themeName, cssPath] of themeFiles) {
237
- const root = this.styleProcessor.createRoot();
238
- const content = this.styleProcessor.readStyleFile(cssPath);
239
- if (content.trim()) {
240
- this.styleProcessor.appendStyleContent(root, content, cssPath);
241
- }
242
- const target = path.join(themesDir, `${themeName}.css`);
243
- fs.mkdirSync(path.dirname(target), { recursive: true });
244
- fs.writeFileSync(
245
- target,
246
- ((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
247
- ? this.styleProcessor.stringify(root)
248
- : '',
249
- );
250
- outputs.push({ themeName, file: target });
251
- }
252
- return outputs;
253
- }
254
- writeThemeEntries(themeStyles, outRoot, buildConfig) {
255
- const outputs = [];
256
- const themesDir = path.join(outRoot, THEMES_DIR);
257
- for (const { themeName, file } of themeStyles) {
258
- const target = path.join(themesDir, `${themeName}.css`);
259
- const root = this.styleProcessor.createRoot();
260
- const targetDir = path.dirname(target);
261
- for (const specifier of getThemeStyleDependencies(
262
- buildConfig,
263
- themeName,
264
- )) {
265
- this.styleProcessor.appendImportRule(root, specifier);
266
- }
267
- this.styleProcessor.appendImportRule(
268
- root,
269
- this.toRelativeImportSpecifier(targetDir, file),
270
- );
271
- fs.mkdirSync(targetDir, { recursive: true });
272
- fs.writeFileSync(target, this.styleProcessor.stringify(root));
273
- outputs.push(target);
274
- }
275
- return outputs;
276
- }
277
- cleanThemeStyles(outRoot) {
278
- fs.rmSync(path.join(outRoot, THEMES_DIR), {
279
- recursive: true,
280
- force: true,
281
- });
282
- fs.rmSync(path.join(outRoot, this.config.output.styleDir, THEMES_DIR), {
283
- recursive: true,
284
- force: true,
285
- });
286
- }
287
- writeModuleStyle(styleFiles, outRoot) {
288
- var _a;
289
- const target = path.join(
290
- outRoot,
291
- this.config.output.styleDir,
292
- this.config.output.moduleCssFile,
293
- );
294
- const seen = new Set();
295
- const root = this.styleProcessor.createRoot();
296
- for (const styleFile of styleFiles) {
297
- const content = this.styleProcessor.readStyleFile(styleFile, seen);
298
- if (content.trim()) {
299
- this.styleProcessor.appendStyleContent(root, content, styleFile);
300
- }
301
- }
302
- if (!((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length))
303
- return null;
304
- fs.mkdirSync(path.dirname(target), { recursive: true });
305
- fs.writeFileSync(target, this.styleProcessor.stringify(root));
306
- return target;
307
- }
308
- writeExternalStyle(outRoot, buildConfig) {
309
- var _a;
310
- const target = path.join(
311
- outRoot,
312
- this.config.output.styleDir,
313
- this.config.output.externalCssFile,
314
- );
315
- const root = this.styleProcessor.createRoot();
316
- for (const specifier of getExternalStyleDependencies(buildConfig)) {
317
- this.styleProcessor.appendImportRule(
318
- root,
319
- this.resolver.toExternalStyleSpecifier(specifier, outRoot),
320
- );
321
- }
322
- fs.mkdirSync(path.dirname(target), { recursive: true });
323
- fs.writeFileSync(
324
- target,
325
- ((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
326
- ? this.styleProcessor.stringify(root)
327
- : '',
328
- );
329
- return target;
330
- }
331
- writeComponentStyleEntries(
332
- sourceFiles,
333
- styleFiles,
334
- outRoot,
335
- moduleStyleImports,
336
- ) {
337
- var _a, _b, _c;
338
- const styleFilesByDir = groupStyleFilesByDir(this.srcRoot, styleFiles);
339
- const importedStyleFiles =
340
- this.styleProcessor.collectImportedStyleFiles(styleFiles);
341
- const sourceModuleDirs = this.getSourceModuleDirs(sourceFiles);
342
- const ownStyleDirs = this.getOwnStyleDirs(
343
- styleFilesByDir,
344
- importedStyleFiles,
345
- );
346
- const sourceDirs = Array.from(
347
- new Set([
348
- ...sourceModuleDirs,
349
- ...ownStyleDirs,
350
- ...moduleStyleImports.keys(),
351
- ]),
352
- );
353
- const outputs = [];
354
- for (const sourceDir of sourceDirs) {
355
- if (sourceDir === '.') continue;
356
- const dirStyleFiles =
357
- (_a = styleFilesByDir.get(sourceDir)) !== null && _a !== void 0
358
- ? _a
359
- : [];
360
- const styleDir = path.join(
361
- outRoot,
362
- sourceDir,
363
- this.config.output.styleDir,
364
- );
365
- const target = path.join(styleDir, this.config.output.indexCssFile);
366
- const moduleStyleSpecifiers = this.getModuleStyleSpecifiers(
367
- (_b = moduleStyleImports.get(sourceDir)) !== null && _b !== void 0
368
- ? _b
369
- : [],
370
- styleDir,
371
- );
372
- const dirStyleSpecifiers = this.getDirStyleSpecifiers(
373
- dirStyleFiles,
374
- importedStyleFiles,
375
- styleDir,
376
- outRoot,
377
- );
378
- const sourceStyleSpecifiers = [
379
- ...moduleStyleSpecifiers,
380
- ...dirStyleSpecifiers,
381
- ];
382
- const root = this.styleProcessor.createRoot();
383
- const seen = new Set();
384
- for (const specifier of sourceStyleSpecifiers) {
385
- if (seen.has(specifier)) continue;
386
- seen.add(specifier);
387
- this.styleProcessor.appendImportRule(
388
- root,
389
- this.resolver.toOutputStyleSpecifier(specifier, outRoot),
390
- );
391
- }
392
- fs.mkdirSync(styleDir, { recursive: true });
393
- fs.writeFileSync(
394
- target,
395
- ((_c = root.nodes) === null || _c === void 0 ? void 0 : _c.length)
396
- ? this.styleProcessor.stringify(root)
397
- : EMPTY_MODULE_STYLE_ENTRY_COMMENT,
398
- );
399
- outputs.push(target);
400
- }
401
- return outputs;
402
- }
403
- getSourceModuleDirs(sourceFiles) {
404
- return sourceFiles
405
- .filter((sourceFile) => sourceFile.endsWith('.tsx'))
406
- .map((sourceFile) => {
407
- return getSourceModuleDir(path.relative(this.srcRoot, sourceFile));
408
- })
409
- .filter((sourceModuleDir) => {
410
- return toPosixPath(sourceModuleDir).split('/').length === 2;
411
- });
412
- }
413
- getOwnStyleDirs(styleFilesByDir, importedStyleFiles) {
414
- return Array.from(styleFilesByDir.entries())
415
- .filter(([, dirStyleFiles]) =>
416
- dirStyleFiles.some(
417
- (styleFile) => !importedStyleFiles.has(path.resolve(styleFile)),
418
- ),
419
- )
420
- .map(([sourceDir]) => sourceDir);
421
- }
422
- getModuleStyleSpecifiers(specifiers, styleDir) {
423
- return specifiers.map((specifier) => {
424
- if (specifier.startsWith('.')) return specifier;
425
- if (!path.isAbsolute(specifier)) return specifier;
426
- return toPosixPath(path.relative(styleDir, specifier));
427
- });
428
- }
429
- getDirStyleSpecifiers(dirStyleFiles, importedStyleFiles, styleDir, outRoot) {
430
- return dirStyleFiles
431
- .filter((styleFile) => !importedStyleFiles.has(path.resolve(styleFile)))
432
- .map((styleFile) =>
433
- toPosixPath(
434
- path.relative(
435
- styleDir,
436
- path.join(outRoot, path.relative(this.srcRoot, styleFile)),
437
- ),
438
- ),
439
- );
440
- }
441
- toRelativeImportSpecifier(fromDir, file) {
442
- const relative = toPosixPath(path.relative(fromDir, file));
443
- return relative.startsWith('.') ? relative : `./${relative}`;
444
- }
445
- }
@@ -1,106 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import chokidar from 'chokidar';
4
- import { aukletConfigFile, aukletDefaultCssOptions } 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
- : aukletDefaultCssOptions.sourceDir;
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
- }