Skip to content

Commit

Permalink
Fix imports in profile.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Dec 16, 2024
1 parent f32eda5 commit cf5bf4a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/theme/src/cli/services/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs/promises'
import * as path from 'path'
import * as os from 'os'
import {writeFile} from 'fs/promises'
import {join, resolve, dirname} from 'path'

Check failure on line 2 in packages/theme/src/cli/services/profile.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/theme/src/cli/services/profile.ts#L2

[no-restricted-imports] 'path' import is restricted from being used. Please use: import { joinPath } from '@shopify/cli-kit/node/path'
import {tmpdir} from 'os'
import {fileURLToPath} from 'url'
import {openURL} from '@shopify/cli-kit/node/system'

Check failure on line 5 in packages/theme/src/cli/services/profile.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/theme/src/cli/services/profile.ts#L5

[import/order] `@shopify/cli-kit/node/system` import should occur before import of `fs/promises`

Expand All @@ -22,23 +22,23 @@ export async function profile(storeUrl: string, asJson: boolean) {
async function openProfile(profileJson: string) {
// Adapted from https://github.com/jlfwong/speedscope/blob/146477a8508a6d2da697cb0ea0a426ba81b3e8dc/bin/cli.js#L63
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
let urlToOpen = 'file://' + path.resolve(__dirname, '../../../node_modules/speedscope/dist/release/index.html')
const __dirname = dirname(__filename)
let urlToOpen = 'file://' + resolve(__dirname, '../../../node_modules/speedscope/dist/release/index.html')

Check failure on line 26 in packages/theme/src/cli/services/profile.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/theme/src/cli/services/profile.ts#L26

[prefer-template] Unexpected string concatenation.
const filename = 'liquid-profile'

const sourceBase64 = Buffer.from(profileJson).toString('base64')
const jsSource = `speedscope.loadFileFromBase64(${JSON.stringify(filename)}, ${JSON.stringify(sourceBase64)})`

const filePrefix = `speedscope-${+new Date()}-${process.pid}`

Check failure on line 32 in packages/theme/src/cli/services/profile.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/theme/src/cli/services/profile.ts#L32

[no-implicit-coercion] use `Number(new Date())` instead.
const jsPath = path.join(os.tmpdir(), `${filePrefix}.js`)
await fs.writeFile(jsPath, jsSource)
const jsPath = join(tmpdir(), `${filePrefix}.js`)
await writeFile(jsPath, jsSource)
urlToOpen += `#localProfilePath=${jsPath}`

// For some silly reason, the OS X open command ignores any query parameters or hash parameters
// passed as part of the URL. To get around this weird issue, we'll create a local HTML file
// that just redirects.
const htmlPath = path.join(os.tmpdir(), `${filePrefix}.html`)
await fs.writeFile(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)
const htmlPath = join(tmpdir(), `${filePrefix}.html`)
await writeFile(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)

urlToOpen = `file://${htmlPath}`
await openURL(urlToOpen)
Expand Down

0 comments on commit cf5bf4a

Please sign in to comment.