Skip to content

Commit 0e153f0

Browse files
authored
Update to working open, switch to ESM (#499)
1 parent e3d57d5 commit 0e153f0

File tree

5 files changed

+151
-52
lines changed

5 files changed

+151
-52
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ jobs:
1515
node-version: [18.x, 20.x]
1616

1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
1919
- name: Use Node.js ${{ matrix.node-version }}
20-
uses: actions/setup-node@v1
20+
uses: actions/setup-node@v4
2121
with:
2222
node-version: ${{ matrix.node-version }}
2323
- run: npm install
2424
- run: npm test
2525
env:
2626
CI: true
27-
27+
- name: Try CLI
28+
run: node bin/cli.mjs -v
2829
- name: Coveralls Parallel
29-
uses: coverallsapp/github-action@master
30+
uses: coverallsapp/github-action@v2
3031
with:
3132
github-token: ${{ secrets.github_token }}
3233
flag-name: run-${{ matrix.node-version }}
@@ -37,7 +38,7 @@ jobs:
3738
runs-on: ubuntu-latest
3839
steps:
3940
- name: Coveralls Finished
40-
uses: coverallsapp/github-action@master
41+
uses: coverallsapp/github-action@v2
4142
with:
4243
github-token: ${{ secrets.github_token }}
4344
parallel-finished: true

README-ADMINS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ cd /var/folders/l0/qtd9z14973s2tw81vmzwkyp00000gp/T/speedscope-test-installation
2121

2222
Run this command, to switch to the test directory.
2323

24-
Inside of here, run `bin/cli.js`. This should open a copy of speedscope in browser.
24+
Inside of here, run `bin/cli.mjs`. This should open a copy of speedscope in browser.
2525
Try importing a profile from disk via the browse button and make sure it works.
2626

27-
Next, try running `bin/cli.js dist/release/perf-vertx*`. This should immediately open
27+
Next, try running `bin/cli.mjs dist/release/perf-vertx*`. This should immediately open
2828
speedscope in browser, and the perf-vertx file should load immediately.
2929

3030
## Create & publish the new release

bin/cli.js renamed to bin/cli.mjs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/usr/bin/env node
2-
const path = require('path')
3-
const fs = require('fs')
4-
const os = require('os')
5-
const stream = require('stream')
2+
import path from 'node:path'
3+
import fs from 'node:fs'
4+
import os from 'node:os'
5+
import stream from 'node:stream'
6+
import { fileURLToPath } from 'node:url'
67

7-
const open = require('open')
8+
import open from 'open'
9+
10+
const __filename = fileURLToPath(import.meta.url)
11+
const __dirname = path.dirname(__filename)
812

913
const helpString = `Usage: speedscope [filepath]
1014
@@ -52,7 +56,9 @@ async function main() {
5256
}
5357

5458
if (process.argv.includes('--version') || process.argv.includes('-v')) {
55-
console.log('v' + require('../package.json').version)
59+
const json = fs.readFileSync(path.resolve(__dirname, '../package.json'), { encoding: 'utf-8' })
60+
const { version } = JSON.parse(json)
61+
console.log(`v${version}`)
5662
return
5763
}
5864

@@ -87,14 +93,16 @@ async function main() {
8793
fs.writeFileSync(jsPath, jsSource)
8894
urlToOpen += `#localProfilePath=${jsPath}`
8995

90-
// For some silly reason, the OS X open command ignores any query parameters or hash parameters
96+
// For some silly reason, the macOS `open` and Windows `start` commands ignore hash parameters
9197
// passed as part of the URL. To get around this weird issue, we'll create a local HTML file
9298
// that just redirects.
93-
const htmlPath = path.join(os.tmpdir(), `${filePrefix}.html`)
94-
console.log(`Creating temp file ${htmlPath}`)
95-
fs.writeFileSync(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)
99+
if (process.platform === 'darwin' || process.platform === 'win32') {
100+
const htmlPath = path.join(os.tmpdir(), `${filePrefix}.html`)
101+
console.log(`Creating temp file ${htmlPath}`)
102+
fs.writeFileSync(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)
96103

97-
urlToOpen = `file://${htmlPath}`
104+
urlToOpen = `file://${htmlPath}`
105+
}
98106
}
99107

100108
console.log('Opening', urlToOpen, 'in your default browser')

package-lock.json

Lines changed: 121 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": "jlfwong/speedscope",
66
"main": "index.js",
77
"bin": {
8-
"speedscope": "./bin/cli.js"
8+
"speedscope": "./bin/cli.mjs"
99
},
1010
"scripts": {
1111
"deploy": "./scripts/deploy.sh",
@@ -19,7 +19,7 @@
1919
"serve": "tsx scripts/dev-server.ts"
2020
},
2121
"files": [
22-
"bin/cli.js",
22+
"bin/cli.mjs",
2323
"dist/release/**",
2424
"!*.map"
2525
],
@@ -78,6 +78,6 @@
7878
]
7979
},
8080
"dependencies": {
81-
"open": "7.2.0"
81+
"open": "10.1.0"
8282
}
8383
}

0 commit comments

Comments
 (0)