@jdeighan/coffee-utils 7.0.2 → 7.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.2",
4
+ "version": "7.0.3",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -49,7 +49,7 @@
49
49
  "js-yaml": "^4.1.0",
50
50
  "n-readlines": "^1.0.1",
51
51
  "readline-sync": "^1.4.10",
52
- "svelte": "^3.46.4"
52
+ "svelte": "^3.46.6"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@jdeighan/unit-tester": "^1.0.5"
@@ -239,21 +239,26 @@ export pathTo = (fname, dir, direction="down") ->
239
239
 
240
240
  debug "enter pathTo('#{fname}','#{dir}','#{direction}')"
241
241
  assert fs.existsSync(dir), "Directory #{dir} does not exist"
242
- if fs.existsSync("#{dir}/#{fname}")
243
- debug "return from pathTo: #{dir}/#{fname} - file exists"
244
- return mkpath("#{dir}/#{fname}")
242
+ filepath = mkpath(dir, fname)
243
+ if fs.existsSync(filepath)
244
+ debug "return from pathTo: #{filepath} - file exists"
245
+ return filepath
245
246
  else if (direction == 'down')
246
247
  # --- Search all directories in this directory
248
+ # getSubDirs() returns dirs sorted alphabetically
247
249
  for subdir in getSubDirs(dir)
248
- if fpath = pathTo(fname, "#{dir}/#{subdir}")
250
+ dirpath = mkpath(dir, subdir)
251
+ debug "check #{dirpath}"
252
+ if fpath = pathTo(fname, dirpath)
249
253
  debug "return from pathTo: #{fpath}"
250
254
  return fpath
251
255
  else if (direction == 'up')
252
- while dir = getParentDir(dir)
253
- debug "check #{dir}"
254
- if fs.existsSync("#{dir}/#{fname}")
255
- debug "return from pathTo(): #{dir}/#{fname}"
256
- return "#{dir}/#{fname}"
256
+ while dirpath = getParentDir(dir)
257
+ debug "check #{dirpath}"
258
+ filepath = mkpath(dirpath, fname)
259
+ if fs.existsSync(filepath)
260
+ debug "return from pathTo(): #{filepath}"
261
+ return filepath
257
262
  else
258
263
  error "pathTo(): Invalid direction '#{direction}'"
259
264
  debug "return undef from pathTo - file not found"
package/src/fs_utils.js CHANGED
@@ -281,28 +281,33 @@ export var forEachFile = function(dir, cb, filt = undef, level = 0) {
281
281
 
282
282
  // ---------------------------------------------------------------------------
283
283
  export var pathTo = function(fname, dir, direction = "down") {
284
- var fpath, i, len, ref, subdir;
284
+ var dirpath, filepath, fpath, i, len, ref, subdir;
285
285
  debug(`enter pathTo('${fname}','${dir}','${direction}')`);
286
286
  assert(fs.existsSync(dir), `Directory ${dir} does not exist`);
287
- if (fs.existsSync(`${dir}/${fname}`)) {
288
- debug(`return from pathTo: ${dir}/${fname} - file exists`);
289
- return mkpath(`${dir}/${fname}`);
287
+ filepath = mkpath(dir, fname);
288
+ if (fs.existsSync(filepath)) {
289
+ debug(`return from pathTo: ${filepath} - file exists`);
290
+ return filepath;
290
291
  } else if (direction === 'down') {
291
292
  ref = getSubDirs(dir);
292
293
  // --- Search all directories in this directory
294
+ // getSubDirs() returns dirs sorted alphabetically
293
295
  for (i = 0, len = ref.length; i < len; i++) {
294
296
  subdir = ref[i];
295
- if (fpath = pathTo(fname, `${dir}/${subdir}`)) {
297
+ dirpath = mkpath(dir, subdir);
298
+ debug(`check ${dirpath}`);
299
+ if (fpath = pathTo(fname, dirpath)) {
296
300
  debug(`return from pathTo: ${fpath}`);
297
301
  return fpath;
298
302
  }
299
303
  }
300
304
  } else if (direction === 'up') {
301
- while (dir = getParentDir(dir)) {
302
- debug(`check ${dir}`);
303
- if (fs.existsSync(`${dir}/${fname}`)) {
304
- debug(`return from pathTo(): ${dir}/${fname}`);
305
- return `${dir}/${fname}`;
305
+ while (dirpath = getParentDir(dir)) {
306
+ debug(`check ${dirpath}`);
307
+ filepath = mkpath(dirpath, fname);
308
+ if (fs.existsSync(filepath)) {
309
+ debug(`return from pathTo(): ${filepath}`);
310
+ return filepath;
306
311
  }
307
312
  }
308
313
  } else {