     /// The path of the package.
     private let packagePath: AbsolutePath
 
+    /// The filesystem package builder will run on.
+    private let fileSystem: FileSystem
+
     /// Create a builder for the given manifest and package `path`.
     ///
     /// - Parameters:
     ///   - path: The root path of the package.
-    public init(manifest: Manifest, path: AbsolutePath) {
+    public init(manifest: Manifest, path: AbsolutePath, fileSystem: FileSystem = localFileSystem) {
         self.manifest = manifest
         self.packagePath = path
+        self.fileSystem = fileSystem
     }
     
     /// Build a new package following the conventions.

        let srcroot = try sourceRoot()

        if srcroot != packagePath {
            let invalidRootFiles = try walk(packagePath, recursively: false).filter(isValidSource)
            guard invalidRootFiles.isEmpty else {
                throw ModuleError.invalidLayout(.invalidLayout(invalidRootFiles.map{ $0.asString }))
            }
        }

        let maybeModules = try walk(srcroot, recursively: false).filter(shouldConsiderDirectory)

        if maybeModules.count == 1 && maybeModules[0] != srcroot {
            let invalidModuleFiles = try walk(srcroot, recursively: false).filter(isValidSource)
            guard invalidModuleFiles.isEmpty else {
                throw ModuleError.invalidLayout(.invalidLayout(invalidModuleFiles.map{ $0.asString }))
            }

        if base.hasPrefix(".") { return false }  // eg .git
        if excludedPaths.contains(path) { return false }
        if path == packagesDirectory { return false }
        if !fileSystem.isDirectory(path) { return false }
        return true
    }

