@jdeighan/coffee-utils 7.0.19 → 7.0.20
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/fs_utils.coffee +21 -30
- package/src/fs_utils.js +23 -34
package/package.json
CHANGED
package/src/fs_utils.coffee
CHANGED
@@ -342,46 +342,37 @@ export shortenPath = (path) ->
|
|
342
342
|
export parseSource = (source) ->
|
343
343
|
# --- returns {
|
344
344
|
# dir
|
345
|
-
# filename
|
345
|
+
# filename
|
346
346
|
# stub
|
347
347
|
# ext
|
348
348
|
# }
|
349
|
+
# --- NOTE: source may be a file URL, e.g. import.meta.url
|
349
350
|
|
350
351
|
debug "enter parseSource()"
|
352
|
+
assert isString(source), "parseSource(): source not a string"
|
351
353
|
if source == 'unit test'
|
354
|
+
croak "A source of 'unit test' is deprecated"
|
355
|
+
if source.match(/^file\:\/\//)
|
356
|
+
source = urllib.fileURLToPath(source)
|
357
|
+
|
358
|
+
hInfo = pathlib.parse(source)
|
359
|
+
if hInfo.dir
|
360
|
+
dir = mkpath(hInfo.dir) # change \ to /
|
352
361
|
hSourceInfo = {
|
353
|
-
|
354
|
-
|
362
|
+
dir
|
363
|
+
fullpath: mkpath(dir, hInfo.base)
|
364
|
+
filename: hInfo.base
|
365
|
+
stub: hInfo.name
|
366
|
+
ext: hInfo.ext
|
355
367
|
}
|
356
|
-
|
357
|
-
return hSourceInfo
|
358
|
-
try
|
359
|
-
hInfo = pathlib.parse(source)
|
360
|
-
if hInfo.dir
|
361
|
-
dir = mkpath(hInfo.dir) # change \ to /
|
362
|
-
hSourceInfo = {
|
363
|
-
dir
|
364
|
-
fullpath: mkpath(dir, hInfo.base)
|
365
|
-
filename: hInfo.base
|
366
|
-
stub: hInfo.name
|
367
|
-
ext: hInfo.ext
|
368
|
-
}
|
369
|
-
else
|
370
|
-
hSourceInfo = {
|
371
|
-
filename: hInfo.base
|
372
|
-
stub: hInfo.name
|
373
|
-
ext: hInfo.ext
|
374
|
-
}
|
375
|
-
debug "return from parseSource()", hSourceInfo
|
376
|
-
return hSourceInfo
|
377
|
-
catch err
|
368
|
+
else
|
378
369
|
hSourceInfo = {
|
379
|
-
filename:
|
380
|
-
stub:
|
381
|
-
|
370
|
+
filename: hInfo.base
|
371
|
+
stub: hInfo.name
|
372
|
+
ext: hInfo.ext
|
382
373
|
}
|
383
|
-
|
384
|
-
|
374
|
+
debug "return from parseSource()", hSourceInfo
|
375
|
+
return hSourceInfo
|
385
376
|
|
386
377
|
# ---------------------------------------------------------------------------
|
387
378
|
# backup - back up a file
|
package/src/fs_utils.js
CHANGED
@@ -401,52 +401,41 @@ export var shortenPath = function(path) {
|
|
401
401
|
|
402
402
|
// ---------------------------------------------------------------------------
|
403
403
|
export var parseSource = function(source) {
|
404
|
-
var dir,
|
404
|
+
var dir, hInfo, hSourceInfo;
|
405
405
|
// --- returns {
|
406
406
|
// dir
|
407
|
-
// filename
|
407
|
+
// filename
|
408
408
|
// stub
|
409
409
|
// ext
|
410
410
|
// }
|
411
|
+
// --- NOTE: source may be a file URL, e.g. import.meta.url
|
411
412
|
debug("enter parseSource()");
|
413
|
+
assert(isString(source), "parseSource(): source not a string");
|
412
414
|
if (source === 'unit test') {
|
415
|
+
croak("A source of 'unit test' is deprecated");
|
416
|
+
}
|
417
|
+
if (source.match(/^file\:\/\//)) {
|
418
|
+
source = urllib.fileURLToPath(source);
|
419
|
+
}
|
420
|
+
hInfo = pathlib.parse(source);
|
421
|
+
if (hInfo.dir) {
|
422
|
+
dir = mkpath(hInfo.dir); // change \ to /
|
413
423
|
hSourceInfo = {
|
414
|
-
|
415
|
-
|
424
|
+
dir,
|
425
|
+
fullpath: mkpath(dir, hInfo.base),
|
426
|
+
filename: hInfo.base,
|
427
|
+
stub: hInfo.name,
|
428
|
+
ext: hInfo.ext
|
416
429
|
};
|
417
|
-
|
418
|
-
return hSourceInfo;
|
419
|
-
}
|
420
|
-
try {
|
421
|
-
hInfo = pathlib.parse(source);
|
422
|
-
if (hInfo.dir) {
|
423
|
-
dir = mkpath(hInfo.dir); // change \ to /
|
424
|
-
hSourceInfo = {
|
425
|
-
dir,
|
426
|
-
fullpath: mkpath(dir, hInfo.base),
|
427
|
-
filename: hInfo.base,
|
428
|
-
stub: hInfo.name,
|
429
|
-
ext: hInfo.ext
|
430
|
-
};
|
431
|
-
} else {
|
432
|
-
hSourceInfo = {
|
433
|
-
filename: hInfo.base,
|
434
|
-
stub: hInfo.name,
|
435
|
-
ext: hInfo.ext
|
436
|
-
};
|
437
|
-
}
|
438
|
-
debug("return from parseSource()", hSourceInfo);
|
439
|
-
return hSourceInfo;
|
440
|
-
} catch (error1) {
|
441
|
-
err = error1;
|
430
|
+
} else {
|
442
431
|
hSourceInfo = {
|
443
|
-
filename:
|
444
|
-
stub:
|
445
|
-
|
432
|
+
filename: hInfo.base,
|
433
|
+
stub: hInfo.name,
|
434
|
+
ext: hInfo.ext
|
446
435
|
};
|
447
|
-
debug(`return '${err.message} from parseSource()`, hSourceInfo);
|
448
|
-
return hSourceInfo;
|
449
436
|
}
|
437
|
+
debug("return from parseSource()", hSourceInfo);
|
438
|
+
return hSourceInfo;
|
450
439
|
};
|
451
440
|
|
452
441
|
// ---------------------------------------------------------------------------
|