@zohodesk/codestandard-validator 1.4.1-window-fix → 1.4.3

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.
@@ -198,4 +198,233 @@ FileResolver.prototype.collectSourceFiles = function (srcDir) {
198
198
  FileResolver.prototype.collectTestFiles = function (testDir) {
199
199
  return this.collectFiles(testDir, '**/*.{test,spec}.{js,ts,jsx,tsx}');
200
200
  };
201
- module.exports = FileResolver;
201
+ module.exports = FileResolver;
202
+
203
+ // "use strict";
204
+
205
+ // const path = require('path');
206
+ // const fs = require('fs');
207
+ // const glob = require('glob');
208
+ // const {
209
+ // getRootDirectory
210
+ // } = require('../utils/General/RootDirectoryUtils/getRootDirectory');
211
+
212
+ // /**
213
+ // * FileResolver — resolves source ↔ test file pairs.
214
+ // *
215
+ // * Uses heuristic strategies (co-located, __tests__/, mirrored dirs)
216
+ // * to find a test file for every source file and vice versa.
217
+ // *
218
+ // * Compatible with Node 16+.
219
+ // */
220
+ // function FileResolver(options) {
221
+ // options = options || {};
222
+ // this._rootdir = getRootDirectory();
223
+ // this._cwd = options.cwd || process.cwd();
224
+ // this._testSuffixes = options.testSuffixes || ['.test.js', '.test.ts', '.test.jsx', '.test.tsx'];
225
+ // this._sourceExtensions = options.sourceExtensions || ['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs'];
226
+ // }
227
+
228
+ // /* ------------------------------------------------------------------ */
229
+ // /* Source → Test */
230
+ // /* ------------------------------------------------------------------ */
231
+
232
+ // FileResolver.prototype.findTestForSource = function (sourceFile) {
233
+ // var parsed = path.parse(sourceFile);
234
+ // var dir = parsed.dir;
235
+ // var name = parsed.name;
236
+ // var candidate, i, j, k;
237
+
238
+ // // Strategy 1: co-located (src/foo.js → src/foo.test.js)
239
+ // for (i = 0; i < this._testSuffixes.length; i++) {
240
+ // candidate = path.join(dir, name + this._testSuffixes[i]);
241
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
242
+ // return candidate;
243
+ // }
244
+ // }
245
+
246
+ // // Strategy 2: __tests__ subdir (src/foo.js → src/__tests__/foo.test.js)
247
+ // // Also walks up ancestor directories (e.g., src/a/b/foo.js → src/a/__tests__/foo.test.js)
248
+ // var ancestorDir = dir;
249
+ // while (ancestorDir && ancestorDir !== '.') {
250
+ // for (i = 0; i < this._testSuffixes.length; i++) {
251
+ // candidate = path.join(ancestorDir, '__tests__', name + this._testSuffixes[i]);
252
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
253
+ // return candidate;
254
+ // }
255
+ // }
256
+ // var parentOfAncestor = path.dirname(ancestorDir);
257
+ // if (parentOfAncestor === ancestorDir) break;
258
+ // ancestorDir = parentOfAncestor;
259
+ // }
260
+
261
+ // // Strategy 3: mirror structure (src/x/foo.js → test/x/foo.test.js)
262
+ // var testDirs = ['test', 'tests', '__tests__'];
263
+ // var srcDirs = ['src', 'lib'];
264
+ // for (i = 0; i < srcDirs.length; i++) {
265
+ // var srcIdx = dir.indexOf(srcDirs[i] + '/');
266
+ // if (srcIdx !== -1) {
267
+ // var relativePath = dir.substring(srcIdx + srcDirs[i].length);
268
+ // var prefix = dir.substring(0, srcIdx);
269
+ // for (j = 0; j < testDirs.length; j++) {
270
+ // for (k = 0; k < this._testSuffixes.length; k++) {
271
+ // candidate = path.join(prefix, testDirs[j], relativePath, name + this._testSuffixes[k]);
272
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
273
+ // return candidate;
274
+ // }
275
+ // }
276
+ // }
277
+ // }
278
+ // }
279
+ // return null;
280
+ // };
281
+
282
+ // /* ------------------------------------------------------------------ */
283
+ // /* Test → Source */
284
+ // /* ------------------------------------------------------------------ */
285
+
286
+ // FileResolver.prototype.findSourceForTest = function (testFile) {
287
+ // var parsed = path.parse(testFile);
288
+ // var dir = parsed.dir;
289
+ // var name = parsed.name;
290
+ // var candidate, i, j, k;
291
+
292
+ // // Strip .test / .spec suffix
293
+ // var suffixes = ['.test', '.spec'];
294
+ // for (i = 0; i < suffixes.length; i++) {
295
+ // if (name.slice(-suffixes[i].length) === suffixes[i]) {
296
+ // name = name.slice(0, -suffixes[i].length);
297
+ // break;
298
+ // }
299
+ // }
300
+
301
+ // // Strategy 1: co-located
302
+ // for (i = 0; i < this._sourceExtensions.length; i++) {
303
+ // candidate = path.join(dir, name + this._sourceExtensions[i]);
304
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
305
+ // return candidate;
306
+ // }
307
+ // }
308
+
309
+ // // Strategy 2: parent of __tests__
310
+ // // Walk up from __tests__ checking parent dirs and their subdirs
311
+ // if (dir.indexOf('__tests__') !== -1) {
312
+ // var parentDir = dir.replace(/__tests__\/?.*$/, '');
313
+ // // Check direct parent
314
+ // for (i = 0; i < this._sourceExtensions.length; i++) {
315
+ // candidate = path.join(parentDir, name + this._sourceExtensions[i]);
316
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
317
+ // return candidate;
318
+ // }
319
+ // }
320
+ // // Check subdirs of parent (e.g., _store/__tests__/foo.test.js → _store/helpers/foo.js)
321
+ // var subDirs = [];
322
+ // try {
323
+ // var entries = fs.readdirSync(path.resolve(this._rootdir, parentDir), { withFileTypes: true });
324
+ // subDirs = entries.filter(function(e) { return e.isDirectory() && e.name !== '__tests__'; }).map(function(e) { return e.name; });
325
+ // } catch (e) { /* ignore */ }
326
+ // for (i = 0; i < subDirs.length; i++) {
327
+ // for (j = 0; j < this._sourceExtensions.length; j++) {
328
+ // candidate = path.join(parentDir, subDirs[i], name + this._sourceExtensions[j]);
329
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
330
+ // return candidate;
331
+ // }
332
+ // }
333
+ // }
334
+ // }
335
+
336
+ // // Strategy 3: mirror test → src/lib
337
+ // var testDirs = ['test', 'tests', '__tests__'];
338
+ // var srcDirs = ['src', 'lib'];
339
+ // for (i = 0; i < testDirs.length; i++) {
340
+ // var testIdx = dir.indexOf(testDirs[i] + '/');
341
+ // if (testIdx !== -1) {
342
+ // var relativePath = dir.substring(testIdx + testDirs[i].length);
343
+ // var prefix = dir.substring(0, testIdx);
344
+ // for (j = 0; j < srcDirs.length; j++) {
345
+ // for (k = 0; k < this._sourceExtensions.length; k++) {
346
+ // candidate = path.join(prefix, srcDirs[j], relativePath, name + this._sourceExtensions[k]);
347
+ // if (fs.existsSync(path.resolve(this._rootdir, candidate))) {
348
+ // return candidate;
349
+ // }
350
+ // }
351
+ // }
352
+ // }
353
+ // }
354
+ // return null;
355
+ // };
356
+
357
+ // /* ------------------------------------------------------------------ */
358
+ // /* Pair resolution */
359
+ // /* ------------------------------------------------------------------ */
360
+
361
+ // FileResolver.prototype.resolveSourceTestPairs = function (sourceFiles, testFiles) {
362
+ // var pairs = [];
363
+ // var resolvedSources = {};
364
+ // var resolvedTests = {};
365
+ // var i, normalizedSource, normalizedTest, test, source;
366
+
367
+ // // Map source → test
368
+ // for (i = 0; i < sourceFiles.length; i++) {
369
+ // normalizedSource = sourceFiles[i].replace(/\\/g, '/');
370
+ // test = this.findTestForSource(normalizedSource);
371
+ // if (test) {
372
+ // normalizedTest = test.replace(/\\/g, '/');
373
+ // pairs.push({
374
+ // source: normalizedSource,
375
+ // test: normalizedTest
376
+ // });
377
+ // resolvedSources[normalizedSource] = true;
378
+ // resolvedTests[normalizedTest] = true;
379
+ // } else {
380
+ // pairs.push({
381
+ // source: normalizedSource,
382
+ // test: null
383
+ // });
384
+ // resolvedSources[normalizedSource] = true;
385
+ // }
386
+ // }
387
+
388
+ // // Map remaining test → source
389
+ // for (i = 0; i < testFiles.length; i++) {
390
+ // normalizedTest = testFiles[i].replace(/\\/g, '/');
391
+ // if (resolvedTests[normalizedTest]) continue;
392
+ // source = this.findSourceForTest(normalizedTest);
393
+ // if (source && !resolvedSources[source.replace(/\\/g, '/')]) {
394
+ // pairs.push({
395
+ // source: source.replace(/\\/g, '/'),
396
+ // test: normalizedTest
397
+ // });
398
+ // resolvedSources[source.replace(/\\/g, '/')] = true;
399
+ // }
400
+ // resolvedTests[normalizedTest] = true;
401
+ // }
402
+ // return pairs;
403
+ // };
404
+
405
+ // /* ------------------------------------------------------------------ */
406
+ // /* File collectors (glob-based) */
407
+ // /* ------------------------------------------------------------------ */
408
+
409
+ // FileResolver.prototype.collectFiles = function (directory, pattern) {
410
+ // var fullPattern = path.join(directory, pattern || '**/*.{js,ts,jsx,tsx}').replace(/\\/g, '/');
411
+ // try {
412
+ // return glob.sync(fullPattern, {
413
+ // cwd: this._rootdir,
414
+ // nodir: true
415
+ // });
416
+ // } catch (err) {
417
+ // throw new Error("Failed to collect files from '" + directory + "': " + err.message);
418
+ // }
419
+ // };
420
+ // FileResolver.prototype.collectSourceFiles = function (srcDir) {
421
+ // var allFiles = this.collectFiles(srcDir, '**/*.{js,ts,jsx,tsx,mjs,cjs}');
422
+ // var testPattern = /\.(test|spec)\.(js|ts|jsx|tsx|mjs|cjs)$/;
423
+ // return allFiles.filter(function (f) {
424
+ // return !testPattern.test(f);
425
+ // });
426
+ // };
427
+ // FileResolver.prototype.collectTestFiles = function (testDir) {
428
+ // return this.collectFiles(testDir, '**/*.{test,spec}.{js,ts,jsx,tsx}');
429
+ // };
430
+ // module.exports = FileResolver;
@@ -29,7 +29,7 @@ async function installPlugins(pluginsToBeInstalled) {
29
29
  Logger.log(Logger.INFO_TYPE, `Install command being executed: npm ${args.join(' ')}`);
30
30
  const result = spawnSync('npm', args, {
31
31
  cwd: getNodeModulesPath(),
32
- shell: false,
32
+ shell: true,
33
33
  encoding: 'utf8'
34
34
  });
35
35
  if (result.stdout) {
package/changeLog.md CHANGED
@@ -72,3 +72,14 @@
72
72
  4. Add `.feature` file support in `getSupportedLanguage()` and include feature files in pre-commit hook linting
73
73
  5. Update `@zohodesk/codestandard-analytics` dependency to `1.1.6-node-18`
74
74
  6. Update unit tests for mutation modules to match refactored API
75
+
76
+ # 1.4.1 - Windows Path and Pre-commit Stability Fixes
77
+
78
+ 1. Fix plugin discovery path handling for scoped packages by resolving `package.json` directly, preventing malformed module paths on Windows.
79
+ 2. Improve plugin version parsing and error handling to avoid hard failures during plugin validation when metadata is unavailable.
80
+ 3. Harden pre-commit initialization flow by adding deterministic async ordering and centralized startup error handling.
81
+ 4. Add timeout protection for remote commit-hash fetch to prevent long blocking in hook execution.
82
+ 5. Improve fsUtils update safety using temporary file write + rename to reduce partial-write risk.
83
+ 6. Derive project root from install path suffix instead of fixed directory traversal for cross-platform compatibility.
84
+ 7. Normalize ESLint config and plugin resolution paths in pre-commit lint flows for Windows/macOS/Linux parity.
85
+ 8. Add and update unit tests for plugin checks, install-path derivation, JSON update flow, and ESLint path resolution.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.4.1-window-fix",
3
+ "version": "1.4.3",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {