             try pkgfile = resolve.sync path.join(mfile, 'package.json'),
                 basedir:dirname
             catch err # nothing
-        if pkgfile and not @files[pkgfile]
-            if path.existsSync(pkgfile)
-                pkgbody = "module.exports=" + fs.readFileSync(pkgfile, 'utf-8')
-                @append(pkgfile, pkgbody, {dirname})
-            else pkgfile = null
+        if pkgfile
+            if @files[pkgfile]
+                pkgname = @files[pkgfile].name
+            else
+                unless path.existsSync(pkgfile)
+                    pkgfile = null
+                else
+                    pkgbody = fs.readFileSync(pkgfile, 'utf-8')
+                    try
+                        npmpkg = JSON.parse(pkgbody)
+                        pkgname = npmpkg?.name
+                    catch err #  ignore broken package.jsons just like node
+                    pkgbody = "module.exports=#{pkgbody}"
+                    pkgjson = @append(pkgfile, pkgbody, {dirname})
+                    pkgjson.name = pkgname ? opts.name
 
         body = opts.body ? @readFile(opts.file)
 

            @emit('error', "no size for #{file}") unless opts.size?
        stream.props = size:opts.size
        @_push (done) ->
            @emit('append', stream)
            @tarball.append(stream, done)
            content or= fs.createReadStream(file)
            if typeof content is 'string'


        entry = @append(opts.file, body, {dirname})
        entry.target = opts.target
        entry.name = pkgname ? opts.name

        for req in nub(required.strings)
            params = {dirname, name:entry.name, fromFile:entry.file}
            if opts.target and /^[.\/]/.test(req)
                # not a real directory on the filesystem; just using the path
                # module to get rid of the filename.
