anchor.diff:      }
     }
   
  -  String _moduleForLibrary(Source source) {
  +  String _moduleForLibrary(String moduleRoot, Source source) {
       if (source is InSummarySource) {
  -      return path.basenameWithoutExtension(source.summaryPath);
  +      var summaryPath = source.summaryPath;
  +      if (path.isWithin(moduleRoot, summaryPath)) {
  +        return path
  +            .withoutExtension(path.relative(summaryPath, from: moduleRoot));
  +      }
  +
  +      throw usageException(
  +          'Imported file ${source.uri} is not within the module root '
  +          'directory $moduleRoot');
       }
   
       throw usageException(
  
positive.code:     } else {
        buildRoot = Directory.current.path;
      }
      var unit = new BuildUnit(path.basenameWithoutExtension(outPath), buildRoot,
          argResults.rest, _moduleForLibrary);
  
      JSModuleFile module = compiler.compile(unit, compilerOptions);
      module.errors.forEach(messageHandler);
  
negative.code:   CompileCommand({MessageHandler messageHandler})
        : this.messageHandler = messageHandler ?? print {
      argParser.addOption('out', abbr: 'o', help: 'Output file (required)');
      argParser.addOption('module-root',
          help: 'Root module directory. '
              'Generated module paths are relative to this root.');
      argParser.addOption('build-root',
          help: 'Root of source files. '
              'Generated library names are relative to this root.');
      CompilerOptions.addArguments(argParser);
      AnalyzerOptions.addArguments(argParser);
    }
  