@jdeighan/coffee-utils 7.0.19 → 7.0.20

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.19",
4
+ "version": "7.0.20",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -342,46 +342,37 @@ export shortenPath = (path) ->
342
342
  export parseSource = (source) ->
343
343
  # --- returns {
344
344
  # dir
345
- # filename # only this is guaranteed to be set
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
- filename: 'unit test'
354
- stub: 'unit test'
362
+ dir
363
+ fullpath: mkpath(dir, hInfo.base)
364
+ filename: hInfo.base
365
+ stub: hInfo.name
366
+ ext: hInfo.ext
355
367
  }
356
- debug "return from parseSource()", hSourceInfo
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: source
380
- stub: source
381
- error: err.message
370
+ filename: hInfo.base
371
+ stub: hInfo.name
372
+ ext: hInfo.ext
382
373
  }
383
- debug "return '#{err.message} from parseSource()", hSourceInfo
384
- return hSourceInfo
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, err, hInfo, hSourceInfo;
404
+ var dir, hInfo, hSourceInfo;
405
405
  // --- returns {
406
406
  // dir
407
- // filename # only this is guaranteed to be set
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
- filename: 'unit test',
415
- stub: 'unit test'
424
+ dir,
425
+ fullpath: mkpath(dir, hInfo.base),
426
+ filename: hInfo.base,
427
+ stub: hInfo.name,
428
+ ext: hInfo.ext
416
429
  };
417
- debug("return from parseSource()", hSourceInfo);
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: source,
444
- stub: source,
445
- error: err.message
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
  // ---------------------------------------------------------------------------