       #}
       #console.log code
       pirates?.settings = @settings
-      @load require(filename).default ? {}
+      @module = runWithMapping @, -> require filename
+      @load @module.default ? {}
       @walkDeps filename
     else
       ## But if file has been explicitly loaded (e.g. in browser),

      #@load eval code
      func = new Function \
        'exports', '__filename', '__dirname', 'svgtiler', 'preact', code
      func exports, _filename, _dirname, svgtiler,
        (if code.includes 'preact' then require 'preact')
      @load exports.default
  walkDeps: (filename) ->
    deps = new Set
    recurse = (modname) =>

class Styles extends ArrayWrapper
  @itemClass: Style

currentMapping = null
getMapping = ->
  ## Returns current `Mapping` object,
  ## when used at top level of a JS/CS mapping file.
  currentMapping
runWithMapping = (mapping, fn) ->
  ## Runs the specified function `fn` as if it were called
  ## at the top level of the specified mapping.
  oldMapping = currentMapping
  currentMapping = mapping
  try
    fn()
  finally
    currentMapping = oldMapping

class Mapping extends Input
  constructor: (...args) ->
    super ...args
