@cluerise/tools 4.0.4 → 4.1.0

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.
@@ -11,6 +11,10 @@
11
11
  build/
12
12
  dist/
13
13
 
14
+ # Cloudflare
15
+ .wrangler/
16
+ worker-configuration.d.ts
17
+
14
18
  # Dependencies
15
19
  node_modules/
16
20
 
@@ -2,6 +2,9 @@
2
2
  build/
3
3
  dist/
4
4
 
5
+ # Cloudflare
6
+ .wrangler/
7
+
5
8
  # Dependencies
6
9
  node_modules/
7
10
 
@@ -214,12 +214,21 @@ export default defineConfig([
214
214
  'error',
215
215
  {
216
216
  replacements: {
217
+ acc: false,
217
218
  arg: false,
218
219
  args: false,
219
220
  dist: false,
220
221
  env: false,
221
222
  envs: false,
223
+ param: false,
222
224
  params: false,
225
+ prev: false,
226
+ prop: false,
227
+ props: false,
228
+ ref: false,
229
+ refs: false,
230
+ rel: false,
231
+ temp: false,
223
232
  utils: false
224
233
  }
225
234
  }
@@ -263,21 +272,25 @@ export default defineConfig([
263
272
  '*.tgz',
264
273
 
265
274
  // Build
266
- 'build/',
267
- 'dist/',
275
+ '**/build/',
276
+ '**/dist/',
277
+
278
+ // Cloudflare
279
+ '../.wrangler/',
280
+ '**/worker-configuration.d.ts',
268
281
 
269
282
  // CSS
270
- '*.css',
283
+ '**/*.css',
271
284
 
272
285
  // Dependencies
273
- 'node_modules/',
286
+ '**/node_modules/',
274
287
 
275
288
  // Fonts
276
- '*.ttf',
277
- '*.woff2',
289
+ '**/*.ttf',
290
+ '**/*.woff2',
278
291
 
279
292
  // Generated files
280
- '__generated__/',
293
+ '**/__generated__/',
281
294
  'patches/',
282
295
 
283
296
  // Git
@@ -289,13 +302,13 @@ export default defineConfig([
289
302
  '!hooks/*.ts',
290
303
 
291
304
  // I18n
292
- '*.po',
305
+ '**/*.po',
293
306
 
294
307
  // Images
295
- '*.ico',
296
- '*.png',
297
- '*.svg',
298
- '*.webp',
308
+ '**/*.ico',
309
+ '**/*.png',
310
+ '**/*.svg',
311
+ '**/*.webp',
299
312
 
300
313
  // Lock files
301
314
  'pnpm-lock.yaml',
@@ -303,32 +316,32 @@ export default defineConfig([
303
316
  'yarn.lock',
304
317
 
305
318
  // Lua scripts
306
- '*.lua',
319
+ '**/*.lua',
307
320
 
308
321
  // Misc
309
- 'etc/',
310
- '.DS_Store',
322
+ '**/etc/',
323
+ '**/.DS_Store',
311
324
 
312
325
  // Sample of .env and .envrc files
313
- '.env.example',
314
- '.env.sample',
315
- '.envrc.example',
316
- '.envrc.sample',
326
+ '**/.env.example',
327
+ '**/.env.sample',
328
+ '**/.envrc.example',
329
+ '**/.envrc.sample',
317
330
 
318
331
  // Shell scripts
319
- '*.sh',
332
+ '**/*.sh',
320
333
 
321
334
  // Stryker
322
- '.stryker-tmp/',
335
+ '**/.stryker-tmp/',
323
336
 
324
337
  // Tests coverage
325
- 'coverage/',
338
+ '**/coverage/',
326
339
 
327
340
  // Texts
328
- '*.txt',
341
+ '**/*.txt',
329
342
 
330
343
  // XML
331
- '*.xml'
344
+ '**/*.xml'
332
345
  ]
333
346
  },
334
347
  // Prettier
@@ -1,9 +1,43 @@
1
1
  import FileSystem from 'node:fs';
2
2
  import Path from 'node:path';
3
3
 
4
- const tsconfigPath = '.lint-staged-temp-tsconfig.json';
4
+ const tempConfigName = '.lint-staged-temp-tsconfig.json';
5
5
 
6
- const mapToRelative = (filenames) => filenames.map((filename) => Path.relative('.', filename));
6
+ const mapToRelative = (filenames, root = '.') => filenames.map((filename) => Path.relative(root, filename));
7
+
8
+ const findFileConfig = (filename) => {
9
+ let directory = Path.dirname(filename);
10
+ while (directory !== Path.parse(directory).root) {
11
+ const configPath = Path.join(directory, 'tsconfig.json');
12
+ if (FileSystem.existsSync(configPath)) {
13
+ return configPath;
14
+ }
15
+
16
+ directory = Path.dirname(directory);
17
+ }
18
+
19
+ return null;
20
+ };
21
+
22
+ const groupFilesByConfig = (filenames) => {
23
+ const fileGroups = new Map();
24
+
25
+ for (const filename of filenames) {
26
+ const configPath = findFileConfig(filename);
27
+ if (!configPath) {
28
+ console.warn(`No tsconfig.json found for ${filename}`);
29
+ continue;
30
+ }
31
+
32
+ if (!fileGroups.has(configPath)) {
33
+ fileGroups.set(configPath, []);
34
+ }
35
+
36
+ fileGroups.get(configPath).push(filename);
37
+ }
38
+
39
+ return fileGroups;
40
+ };
7
41
 
8
42
  export default {
9
43
  '**': (filenames) => {
@@ -12,20 +46,26 @@ export default {
12
46
  return [`eslint ${relativeFilenames}`, `prettier --check ${relativeFilenames}`];
13
47
  },
14
48
  '**/*.ts?(x)': (filenames) => {
49
+ const fileGroups = groupFilesByConfig(filenames);
50
+
15
51
  // The lint-staged command runs this function multiple times to prepare
16
52
  // console messages. We want to save the temporary tsconfig.json file only
17
53
  // when this function is run with filenames (that start with a slash)
18
54
  if (filenames.length > 0 && filenames[0].startsWith('/')) {
19
- const relativeFilenames = mapToRelative(filenames);
20
- const tsconfig = {
21
- extends: './tsconfig.json',
22
- files: relativeFilenames
23
- };
24
-
25
- // eslint-disable-next-line no-restricted-globals
26
- FileSystem.writeFileSync(tsconfigPath, JSON.stringify(tsconfig));
55
+ for (const [configPath, filenames] of fileGroups.entries()) {
56
+ const tempConfigPath = Path.join(Path.dirname(configPath), tempConfigName);
57
+
58
+ const relativeFilenames = mapToRelative(filenames, Path.dirname(configPath));
59
+ const tempConfig = {
60
+ extends: './tsconfig.json',
61
+ files: relativeFilenames
62
+ };
63
+
64
+ // eslint-disable-next-line no-restricted-globals
65
+ FileSystem.writeFileSync(tempConfigPath, JSON.stringify(tempConfig));
66
+ }
27
67
  }
28
68
 
29
- return `tsc -p ${tsconfigPath}`;
69
+ return [...fileGroups.keys()].map((configPath) => `tsc -p ${Path.relative('.', configPath)}`);
30
70
  }
31
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cluerise/tools",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Tools for maintaining TypeScript projects.",
5
5
  "author": "Branislav Holý <brano@holy.am>",
6
6
  "repository": "github:cluerise/tools",