@konomi-app/k2 1.6.1 → 1.7.1

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,11 +1,12 @@
1
+ import chokidar from 'chokidar';
1
2
  import cssnanoPlugin from 'cssnano';
2
3
  import fs from 'fs-extra';
3
4
  import path from 'path';
4
5
  import postcss from 'postcss';
6
+ import { debounce } from 'remeda';
5
7
  import tailwindcss from 'tailwindcss';
6
8
  import invariant from 'tiny-invariant';
7
9
  import { esmImport } from './import.js';
8
- import chokidar from 'chokidar';
9
10
  export const getTailwindConfigFromK2Config = async (k2Config) => {
10
11
  invariant(k2Config?.config, 'tailwind.config is required');
11
12
  const config = (await esmImport(path.resolve(k2Config?.config))).default;
@@ -46,38 +47,51 @@ export const outputCss = async (params) => {
46
47
  };
47
48
  export const watchTailwindCSS = async (params) => {
48
49
  const { input, output, config } = params;
49
- const content = config.content;
50
- if (!content) {
51
- console.warn(`No content is provided in tailwind config. use default content: ['./src/**/*.{ts,tsx}'] and ${input}`);
52
- }
53
- const watcher = chokidar.watch([...(config.content ?? ['./src/**/*.{ts,tsx}']), input], {
50
+ const content = config.content ?? ['./src/**/*.{ts,tsx}'];
51
+ const watcher = chokidar.watch([...content, input], {
54
52
  ignored: /node_modules/,
55
53
  persistent: true,
56
- awaitWriteFinish: {
57
- stabilityThreshold: 2000,
58
- pollInterval: 100,
59
- },
54
+ ignoreInitial: true,
60
55
  });
61
- let initialScanComplete = false;
62
- const listener = async (type, path) => {
56
+ let isInitialized = false;
57
+ const processChanges = async (type) => {
63
58
  try {
64
- if (type === 'add' && !initialScanComplete) {
65
- return;
66
- }
67
59
  await outputCss({ inputPath: input, outputPath: output, config });
68
- if (params.onChanges) {
69
- params.onChanges({ input, output, type });
70
- }
60
+ params.onChanges?.({ input, output, type });
71
61
  }
72
62
  catch (error) {
73
63
  console.error('Error building Tailwind CSS:', error);
74
64
  }
75
65
  };
66
+ const debouncedProcessChanges = debounce(processChanges, { waitMs: 1000 });
76
67
  watcher.on('ready', async () => {
77
- initialScanComplete = true;
78
- await listener('init');
68
+ if (!isInitialized) {
69
+ isInitialized = true;
70
+ await processChanges('init');
71
+ }
72
+ });
73
+ watcher.on('error', (error) => {
74
+ console.error('Error watching Tailwind CSS:', error);
75
+ });
76
+ watcher.on('all', (eventName) => {
77
+ if (!isInitialized) {
78
+ return;
79
+ }
80
+ let type;
81
+ switch (eventName) {
82
+ case 'add':
83
+ type = 'add';
84
+ break;
85
+ case 'change':
86
+ type = 'change';
87
+ break;
88
+ case 'unlink':
89
+ type = 'unlink';
90
+ break;
91
+ default:
92
+ return;
93
+ }
94
+ debouncedProcessChanges.call(type);
79
95
  });
80
- watcher.on('change', (path) => listener('change', path));
81
- watcher.on('add', (path) => listener('add', path));
82
- watcher.on('unlink', () => listener('unlink'));
96
+ return watcher;
83
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "1.6.1",
3
+ "version": "1.7.1",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -47,6 +47,7 @@
47
47
  "html-minifier": "^4",
48
48
  "mini-css-extract-plugin": "^2",
49
49
  "postcss": "^8",
50
+ "remeda": "^2.15.0",
50
51
  "sass": "^1",
51
52
  "sass-loader": "^16",
52
53
  "style-loader": "^4",