Skip to content

Commit

Permalink
chore: remove opener
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Apr 2, 2024
1 parent 6d5412d commit c2f67ff
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import Components from 'unplugin-vue-components/vite'
import { analyzer } from 'vite-bundle-analyzer'

export default defineConfig({
plugins: [vue(), Components({ resolvers: [VarletUIResolver()] }), analyzer({ analyzerMode: 'server', openAnalyzer: false })]
plugins: [vue(), Components({ resolvers: [VarletUIResolver()] }), analyzer({ analyzerMode: 'server', openAnalyzer: true })]
})
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@geist-ui/icons": "^1.0.2",
"@stylexjs/stylex": "^0.5.1",
"@types/node": "^20.7.0",
"@types/opener": "^1.4.3",
"@types/react": "^18.2.31",
"@types/react-dom": "18.2.7",
"@vitejs/plugin-react": "^4.2.1",
Expand Down Expand Up @@ -113,7 +112,6 @@
"esbuild-minify-templates@^0.11.0": "patch:esbuild-minify-templates@npm%3A0.11.0#./.yarn/patches/esbuild-minify-templates-npm-0.11.0-458ab522a4.patch"
},
"dependencies": {
"opener": "^1.5.2",
"picocolors": "^1.0.0",
"source-map": "^0.7.4"
},
Expand Down
4 changes: 2 additions & 2 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path'
import fsp from 'fs/promises'
import opener from 'opener'
import type { Logger, Plugin } from 'vite'
import colors from 'picocolors'
import { name } from '../../package.json'
import { opener } from './opener'
import { renderView } from './render'
import { searchForWorkspaceRoot } from './search-root'
import type { AnalyzerPluginOptions, AnalyzerStore, OutputAsset, OutputBundle, OutputChunk } from './interface'
Expand All @@ -14,7 +14,7 @@ import { convertBytes } from './shared'
const isCI = !!process.env.CI

function openBrowser(address: string) {
opener(address)
opener([address])
}

const formatNumber = (number: number | string) => colors.dim(colors.bold(number))
Expand Down
33 changes: 33 additions & 0 deletions src/server/opener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os from 'os'
import child_process from 'child_process'

const MS = 'microsoft'

function ensureCommander(platform: NodeJS.Platform): [NodeJS.Platform, string] {
switch (platform) {
case 'linux': {
if (os.release().toLocaleLowerCase().indexOf(MS) !== -1) {
return ['win32', 'cmd.exe']
}
return ['linux', 'xdg-open']
}
case 'win32':
return ['win32', 'cmd.exe']
case 'darwin':
return ['darwin', 'open']
default:
return [platform, 'xdg-open']
}
}

export function opener(argvs: string[]) {
const [platform, command] = ensureCommander(os.platform())

// https://stackoverflow.com/questions/154075/using-the-start-command-with-parameters-passed-to-the-started-program/154090#154090
if (platform === 'win32') {
argvs = argvs.map((arg) => arg.replace(/[&^]/g, '^$&'))
argvs = ['/c', 'start', '""'].concat(argvs)
}

return child_process.spawn(command, argvs)
}
36 changes: 0 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1218,15 +1218,6 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:*":
version: 20.11.30
resolution: "@types/node@npm:20.11.30"
dependencies:
undici-types: ~5.26.4
checksum: 7597767aa3e44b0f1bf62efa522dd17741135f283c11de6a20ead8bb7016fb4999cc30adcd8f2bb29ebb216906c92894346ccd187de170927dc1e212d2c07c81
languageName: node
linkType: hard

"@types/node@npm:^20.7.0":
version: 20.8.6
resolution: "@types/node@npm:20.8.6"
Expand All @@ -1236,15 +1227,6 @@ __metadata:
languageName: node
linkType: hard

"@types/opener@npm:^1.4.3":
version: 1.4.3
resolution: "@types/opener@npm:1.4.3"
dependencies:
"@types/node": "*"
checksum: 9a41f86b73f86b7f44d5bcbdd35330565c01df00183d00a45bbb509c3508d0f2cdcb4670f8620097b8b928912bc4fc5b58a46990fad915b91a4c680dc6c0efbd
languageName: node
linkType: hard

"@types/prop-types@npm:*":
version: 15.7.8
resolution: "@types/prop-types@npm:15.7.8"
Expand Down Expand Up @@ -4453,15 +4435,6 @@ __metadata:
languageName: node
linkType: hard

"opener@npm:^1.5.2":
version: 1.5.2
resolution: "opener@npm:1.5.2"
bin:
opener: bin/opener-bin.js
checksum: 33b620c0d53d5b883f2abc6687dd1c5fd394d270dbe33a6356f2d71e0a2ec85b100d5bac94694198ccf5c30d592da863b2292c5539009c715a9c80c697b4f6cc
languageName: node
linkType: hard

"optionator@npm:^0.9.3":
version: 0.9.3
resolution: "optionator@npm:0.9.3"
Expand Down Expand Up @@ -5630,13 +5603,6 @@ __metadata:
languageName: node
linkType: hard

"undici-types@npm:~5.26.4":
version: 5.26.5
resolution: "undici-types@npm:5.26.5"
checksum: 3192ef6f3fd5df652f2dc1cd782b49d6ff14dc98e5dced492aa8a8c65425227da5da6aafe22523c67f035a272c599bb89cfe803c1db6311e44bed3042fc25487
languageName: node
linkType: hard

"unique-filename@npm:^3.0.0":
version: 3.0.0
resolution: "unique-filename@npm:3.0.0"
Expand Down Expand Up @@ -5752,7 +5718,6 @@ __metadata:
"@geist-ui/icons": ^1.0.2
"@stylexjs/stylex": ^0.5.1
"@types/node": ^20.7.0
"@types/opener": ^1.4.3
"@types/react": ^18.2.31
"@types/react-dom": 18.2.7
"@vitejs/plugin-react": ^4.2.1
Expand All @@ -5762,7 +5727,6 @@ __metadata:
eslint: ^8.49.0
eslint-config-kagura: ^2.1.1
foxact: ^0.2.29
opener: ^1.5.2
picocolors: ^1.0.0
preact: ^10.19.2
react: ^18.2.0
Expand Down

0 comments on commit c2f67ff

Please sign in to comment.