mirror of
https://github.com/desktop/desktop
synced 2024-09-29 21:03:35 +00:00
Merge pull request #14055 from desktop/if-it-smells-like-a-bundle-and-looks-like-a-bundle
Replace file-metadata with custom execFile implementatation
This commit is contained in:
commit
cb181f9ae2
|
@ -34,7 +34,6 @@
|
|||
"dugite": "^1.104.0",
|
||||
"electron-window-state": "^5.0.3",
|
||||
"event-kit": "^2.0.0",
|
||||
"file-metadata": "^1.0.0",
|
||||
"focus-trap-react": "^8.1.0",
|
||||
"fs-admin": "^0.19.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
|
|
6
app/src/lib/globals.d.ts
vendored
6
app/src/lib/globals.d.ts
vendored
|
@ -154,12 +154,6 @@ declare namespace Electron {
|
|||
}
|
||||
}
|
||||
|
||||
declare module 'file-metadata' {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
function fileMetadata(path: string): Promise<plist.PlistObject>
|
||||
export = fileMetadata
|
||||
}
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/21568#issuecomment-362473070
|
||||
interface Window {
|
||||
Element: typeof Element
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
/**
|
||||
* Hack: The file-metadata plugin has substantial dependencies
|
||||
* (plist, DOMParser, etc) and it's only applicable on macOS.
|
||||
*
|
||||
* Therefore, when compiling on other platforms, we replace it
|
||||
* with this tiny shim. See webpack.common.ts.
|
||||
*/
|
||||
module.exports = () => Promise.resolve({})
|
|
@ -1,4 +1,4 @@
|
|||
import getFileMetadata from 'file-metadata'
|
||||
import { execFile } from './exec-file'
|
||||
|
||||
/**
|
||||
* Attempts to determine if the provided path is an application bundle or not.
|
||||
|
@ -18,24 +18,30 @@ export async function isApplicationBundle(path: string): Promise<boolean> {
|
|||
return false
|
||||
}
|
||||
|
||||
const metadata = await getFileMetadata(path)
|
||||
// Expected output for an application bundle:
|
||||
// $ mdls -name kMDItemContentType -name kMDItemContentTypeTree /Applications/GitHub\ Desktop.app
|
||||
// kMDItemContentType = "com.apple.application-bundle"
|
||||
// kMDItemContentTypeTree = (
|
||||
// "com.apple.application-bundle",
|
||||
// "com.apple.application",
|
||||
// "public.executable",
|
||||
// "com.apple.localizable-name-bundle",
|
||||
// "com.apple.bundle",
|
||||
// "public.directory",
|
||||
// "public.item",
|
||||
// "com.apple.package"
|
||||
// )
|
||||
const { stdout } = await execFile('mdls', [
|
||||
...['-name', 'kMDItemContentType'],
|
||||
...['-name', 'kMDItemContentTypeTree'],
|
||||
path,
|
||||
])
|
||||
|
||||
if (metadata['contentType'] === 'com.apple.application-bundle') {
|
||||
return true
|
||||
}
|
||||
const probableBundleIdentifiers = [
|
||||
'com.apple.application-bundle',
|
||||
'com.apple.application',
|
||||
'public.executable',
|
||||
]
|
||||
|
||||
const contentTypeTree = metadata['contentTypeTree']
|
||||
|
||||
if (Array.isArray(contentTypeTree)) {
|
||||
for (const contentType of contentTypeTree) {
|
||||
switch (contentType) {
|
||||
case 'com.apple.application-bundle':
|
||||
case 'com.apple.application':
|
||||
case 'public.executable':
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return probableBundleIdentifiers.some(id => stdout.includes(`"${id}"`))
|
||||
}
|
||||
|
|
|
@ -66,41 +66,17 @@ const commonConfig: webpack.Configuration = {
|
|||
},
|
||||
}
|
||||
|
||||
// Hack: The file-metadata plugin has substantial dependencies
|
||||
// (plist, DOMParser, etc) and it's only applicable on macOS.
|
||||
//
|
||||
// Therefore, when compiling on other platforms, we replace it
|
||||
// with a tiny shim instead.
|
||||
const shimFileMetadata = {
|
||||
resolve: {
|
||||
alias: {
|
||||
'file-metadata': path.resolve(
|
||||
__dirname,
|
||||
'src',
|
||||
'lib',
|
||||
'helpers',
|
||||
'file-metadata.js'
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const main = merge(
|
||||
{},
|
||||
commonConfig,
|
||||
{
|
||||
entry: { main: path.resolve(__dirname, 'src/main-process/main') },
|
||||
target: 'electron-main',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin(
|
||||
Object.assign({}, replacements, {
|
||||
__PROCESS_KIND__: JSON.stringify('main'),
|
||||
})
|
||||
),
|
||||
],
|
||||
},
|
||||
process.platform !== 'darwin' ? shimFileMetadata : {}
|
||||
)
|
||||
export const main = merge({}, commonConfig, {
|
||||
entry: { main: path.resolve(__dirname, 'src/main-process/main') },
|
||||
target: 'electron-main',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin(
|
||||
Object.assign({}, replacements, {
|
||||
__PROCESS_KIND__: JSON.stringify('main'),
|
||||
})
|
||||
),
|
||||
],
|
||||
})
|
||||
|
||||
export const renderer = merge({}, commonConfig, {
|
||||
entry: { renderer: path.resolve(__dirname, 'src/ui/index') },
|
||||
|
|
|
@ -140,11 +140,6 @@ balanced-match@^1.0.0:
|
|||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
|
||||
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
|
||||
|
||||
base64-js@1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1"
|
||||
integrity sha1-o5mS1yNYSBGYK+XikLtqU9hnAPE=
|
||||
|
||||
bl@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/bl/-/bl-3.0.1.tgz#1cbb439299609e419b5a74d7fce2f8b37d8e5c6f"
|
||||
|
@ -583,13 +578,6 @@ fecha@^4.2.0:
|
|||
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.1.tgz#0a83ad8f86ef62a091e22bb5a039cd03d23eecce"
|
||||
integrity sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q==
|
||||
|
||||
file-metadata@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/file-metadata/-/file-metadata-1.0.0.tgz#fb3f063667d1fa80e9b6594a9c0b6557d1a0c015"
|
||||
integrity sha512-ipgdCeX/rx+ar60f3lMYy6dPDaxhYou442tEXn0OrHxX23vD8ABvVUjKal6+h9bBHkgjFMs57Cmc68O0zGAtKQ==
|
||||
dependencies:
|
||||
plist "^2.1.0"
|
||||
|
||||
file-stream-rotator@^0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz#007019e735b262bb6c6f0197e58e5c87cb96cec3"
|
||||
|
@ -1255,15 +1243,6 @@ path-key@^2.0.0, path-key@^2.0.1:
|
|||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
|
||||
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
|
||||
|
||||
plist@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/plist/-/plist-2.1.0.tgz#57ccdb7a0821df21831217a3cad54e3e146a1025"
|
||||
integrity sha1-V8zbeggh3yGDEhejytVOPhRqECU=
|
||||
dependencies:
|
||||
base64-js "1.2.0"
|
||||
xmlbuilder "8.2.2"
|
||||
xmldom "0.1.x"
|
||||
|
||||
prebuild-install@^5.3.5:
|
||||
version "5.3.5"
|
||||
resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-5.3.5.tgz#e7e71e425298785ea9d22d4f958dbaccf8bb0e1b"
|
||||
|
@ -1982,16 +1961,6 @@ wrappy@1:
|
|||
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
|
||||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
||||
|
||||
xmlbuilder@8.2.2:
|
||||
version "8.2.2"
|
||||
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"
|
||||
integrity sha1-aSSGc0ELS6QuGmE2VR0pIjNap3M=
|
||||
|
||||
xmldom@0.1.x:
|
||||
version "0.1.31"
|
||||
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
|
||||
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==
|
||||
|
||||
yaku@^0.16.6:
|
||||
version "0.16.7"
|
||||
resolved "https://registry.yarnpkg.com/yaku/-/yaku-0.16.7.tgz#1d195c78aa9b5bf8479c895b9504fd4f0847984e"
|
||||
|
|
Loading…
Reference in a new issue