Skip to content

Commit 5749812

Browse files
committed
test esm changes
1 parent 5edacc8 commit 5749812

21 files changed

+143
-135
lines changed

examples/favorites.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ux} from '@oclif/core'
22

3-
import {Command} from '../src'
3+
import {Command} from '../src/index.js'
44

55
type Favorite = {
66
id: string;

examples/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Command, flags} from '../src'
1+
import {Command, flags} from '../src/index.js'
22

33
class LoginCommand extends Command {
44
static flags = {

examples/logout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Command} from '../src'
1+
import {Command} from '../src/index.js'
22

33
class LogoutCommand extends Command {
44
async run() {

examples/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ if [ ! -f "examples/$COMMAND.ts" ]; then
1313
exit 1
1414
fi
1515

16-
./node_modules/.bin/ts-node "examples/$COMMAND.ts" "$@"
16+
node --loader ts-node/esm "examples/$COMMAND.ts" "$@"

examples/status.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
console.log('Starting status example')
12
import {HTTP} from '@heroku/http-call'
23
import {ux} from '@oclif/core'
34

4-
import {Command} from '../src'
5+
import {Command} from '../src/command.js'
56

67
class StatusCommand extends Command {
78
async run() {
@@ -26,4 +27,7 @@ class StatusCommand extends Command {
2627
}
2728

2829
(StatusCommand.run([]) as any)
29-
.catch(require('@oclif/core').Errors.handle)
30+
.catch((err: any) => {
31+
console.error('Caught error:', err);
32+
require('@oclif/core').Errors.handle(err);
33+
});

examples/whoami.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Heroku from '@heroku-cli/schema'
22
import {ux} from '@oclif/core'
33

4-
import {Command} from '../src'
4+
import {Command} from '../src/index.js'
55

66
class StatusCommand extends Command {
77
notloggedin() {

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"devDependencies": {
1919
"@heroku-cli/schema": "^1.0.25",
2020
"@types/chai": "^5.2.2",
21+
"@types/debug": "^4.1.2",
2122
"@types/inquirer": "^8.2.11",
2223
"@types/mocha": "^10.0.6",
2324
"@types/node": "22.15.21",
@@ -80,5 +81,6 @@
8081
"changelog": "conventional-changelog -p conventionalcommits -i CHANGELOG.md -s",
8182
"example": "sh examples/run.sh"
8283
},
84+
"type": "module",
8385
"types": "./lib/index.d.ts"
8486
}

src/api-client.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {HTTP, HTTPError, HTTPRequestOptions} from '@heroku/http-call'
22
import {Errors, Interfaces} from '@oclif/core'
3+
import debug from 'debug'
34
import inquirer from 'inquirer'
4-
import Netrc from 'netrc-parser'
55
import * as url from 'node:url'
6-
7-
import deps from './deps'
8-
import {Login} from './login'
9-
import {Mutex} from './mutex'
10-
import {IDelinquencyConfig, IDelinquencyInfo, ParticleboardClient} from './particleboard-client'
11-
import {RequestId, requestIdHeader} from './request-id'
12-
import {vars} from './vars'
13-
14-
const debug = require('debug')
15-
6+
import {Login} from './login.js'
7+
import {Mutex} from './mutex.js'
8+
import {IDelinquencyConfig, IDelinquencyInfo, ParticleboardClient} from './particleboard-client.js'
9+
import {RequestId, requestIdHeader} from './request-id.js'
10+
import {vars} from './vars.js'
11+
import {yubikey} from './yubikey.js'
12+
13+
// Use top-level await for dynamic import
14+
const Netrc = (await import('netrc-parser')).default;
15+
const netrc = new (Netrc as any)();
1616
// eslint-disable-next-line @typescript-eslint/no-namespace
1717
export namespace APIClient {
1818
export interface Options extends HTTPRequestOptions {
@@ -86,7 +86,7 @@ export class APIClient {
8686
protocol: apiUrl.protocol,
8787
}
8888
const delinquencyConfig: IDelinquencyConfig = {fetch_delinquency: false, warning_shown: false}
89-
this.http = class APIHTTPClient<T> extends deps.HTTP.HTTP.create(opts)<T> {
89+
this.http = class APIHTTPClient<T> extends HTTP.create(opts)<T> {
9090
static configDelinquency(url: string, opts: APIClient.Options): void {
9191
if (opts.method?.toUpperCase() !== 'GET' || (opts.hostname && opts.hostname !== apiUrl.hostname)) {
9292
delinquencyConfig.fetch_delinquency = false
@@ -193,7 +193,7 @@ export class APIClient {
193193
this.showWarnings<T>(response)
194194
return response
195195
} catch (error) {
196-
if (!(error instanceof deps.HTTP.HTTPError)) throw error
196+
if (!(error instanceof HTTPError)) throw error
197197
if (retries > 0) {
198198
if (opts.retryAuth !== false && error.http.statusCode === 401 && error.body.id === 'unauthorized') {
199199
if (process.env.HEROKU_API_KEY) {
@@ -258,11 +258,11 @@ export class APIClient {
258258

259259
get auth(): string | undefined {
260260
if (!this._auth) {
261-
if (process.env.HEROKU_API_TOKEN && !process.env.HEROKU_API_KEY) deps.cli.warn('HEROKU_API_TOKEN is set but you probably meant HEROKU_API_KEY')
261+
if (process.env.HEROKU_API_TOKEN && !process.env.HEROKU_API_KEY) Errors.warn('HEROKU_API_TOKEN is set but you probably meant HEROKU_API_KEY')
262262
this._auth = process.env.HEROKU_API_KEY
263263
if (!this._auth) {
264-
deps.netrc.loadSync()
265-
this._auth = deps.netrc.machines[vars.apiHost] && deps.netrc.machines[vars.apiHost].password
264+
netrc.loadSync()
265+
this._auth = netrc.machines[vars.apiHost] && netrc.machines[vars.apiHost].password
266266
}
267267
}
268268

@@ -280,13 +280,13 @@ export class APIClient {
280280

281281
get particleboard(): ParticleboardClient {
282282
if (this._particleboard) return this._particleboard
283-
this._particleboard = new deps.ParticleboardClient(this.config)
283+
this._particleboard = new ParticleboardClient(this.config)
284284
return this._particleboard
285285
}
286286

287287
get twoFactorMutex(): Mutex<string> {
288288
if (!this._twoFactorMutex) {
289-
this._twoFactorMutex = new deps.Mutex()
289+
this._twoFactorMutex = new Mutex()
290290
}
291291

292292
return this._twoFactorMutex
@@ -311,9 +311,9 @@ export class APIClient {
311311
if (error instanceof Errors.CLIError) Errors.warn(error)
312312
}
313313

314-
delete Netrc.machines['api.heroku.com']
315-
delete Netrc.machines['git.heroku.com']
316-
await Netrc.save()
314+
delete netrc.machines['api.heroku.com']
315+
delete netrc.machines['git.heroku.com']
316+
await netrc.save()
317317
}
318318

319319
patch<T>(url: string, options: APIClient.Options = {}) {
@@ -343,7 +343,7 @@ export class APIClient {
343343
}
344344

345345
twoFactorPrompt() {
346-
deps.yubikey.enable()
346+
yubikey.enable()
347347
return this.twoFactorMutex.synchronize(async () => {
348348
try {
349349
const {factor} = await inquirer.prompt([{
@@ -352,10 +352,10 @@ export class APIClient {
352352
name: 'factor',
353353
type: 'password',
354354
}])
355-
deps.yubikey.disable()
355+
yubikey.disable()
356356
return factor
357357
} catch (error) {
358-
deps.yubikey.disable()
358+
yubikey.disable()
359359
throw error
360360
}
361361
})

src/command.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import {Command as Base} from '@oclif/core'
2-
import {
2+
import type {
33
ArgOutput,
44
FlagOutput,
55
Input,
66
ParserOutput,
7-
} from '@oclif/core/lib/interfaces/parser'
8-
import {NonExistentFlagsError} from '@oclif/core/lib/parser/errors'
7+
} from '@oclif/core/lib/interfaces/parser.js'
8+
import {NonExistentFlagsError} from '@oclif/core/lib/parser/errors.js'
9+
import * as fs from 'node:fs'
10+
import path from 'node:path'
11+
import {fileURLToPath} from 'node:url'
912
import parser from 'yargs-parser'
1013
import unparser from 'yargs-unparser'
1114

12-
const pjson = require('../package.json')
15+
import {APIClient, IOptions} from './api-client.js'
1316

14-
import {APIClient, IOptions} from './api-client'
15-
import deps from './deps'
17+
const __filename = fileURLToPath(import.meta.url)
18+
const __dirname = path.dirname(__filename)
19+
const packageJsonPath = path.resolve(__dirname, '../../../package.json')
20+
const pjson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
1621

1722
export abstract class Command extends Base {
1823
allowArbitraryFlags: boolean = false
@@ -25,7 +30,7 @@ export abstract class Command extends Base {
2530
debug: process.env.HEROKU_DEBUG === '1' || process.env.HEROKU_DEBUG?.toUpperCase() === 'TRUE',
2631
debugHeaders: process.env.HEROKU_DEBUG_HEADERS === '1' || process.env.HEROKU_DEBUG_HEADERS?.toUpperCase() === 'TRUE',
2732
}
28-
this._heroku = new deps.APIClient(this.config, options)
33+
this._heroku = new APIClient(this.config, options)
2934
return this._heroku
3035
}
3136

src/completions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {Errors, Interfaces} from '@oclif/core'
22
import * as path from 'node:path'
3-
4-
import deps from './deps'
5-
import {configRemote, getGitRemotes} from './git'
3+
import {APIClient} from './api-client.js'
4+
import * as file from './file.js'
5+
import {configRemote, getGitRemotes} from './git.js'
66

77
export const oneDay = 60 * 60 * 24
88

99
export const herokuGet = async (resource: string, ctx: {config: Interfaces.Config}): Promise<string[]> => {
10-
const heroku = new deps.APIClient(ctx.config)
10+
const heroku = new APIClient(ctx.config)
1111
let {body: resources} = await heroku.get<any>(`/${resource}`)
1212
if (typeof resources === 'string') resources = JSON.parse(resources)
1313
return resources.map((a: any) => a.name).sort()
@@ -71,7 +71,7 @@ export const DynoSizeCompletion = {
7171

7272
export const FileCompletion = {
7373
async options() {
74-
const files = await deps.file.readdir(process.cwd())
74+
const files = await file.readdir(process.cwd())
7575
return files
7676
},
7777

@@ -91,7 +91,7 @@ export const ProcessTypeCompletion = {
9191
let types: string[] = []
9292
const procfile = path.join(process.cwd(), 'Procfile')
9393
try {
94-
const buff = await deps.file.readFile(procfile)
94+
const buff = await file.readFile(procfile)
9595
types = buff
9696
.toString()
9797
.split('\n')

src/deps.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/file.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import * as fs from 'fs'
2-
import {promisify} from 'util'
1+
import * as fs from 'node:fs'
2+
import {promisify} from 'node:util'
3+
import debugModule from 'debug'
34

45
let _debug: any
56
function debug(...args: any[]) {
6-
if (_debug) _debug = require('debug')('@heroku-cli/command:file')
7+
if (!_debug) _debug = debugModule('@heroku-cli/command:file')
78
_debug(...args)
89
}
910

src/flags/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Errors, Flags} from '@oclif/core'
22

3-
import {IGitRemotes, configRemote, getGitRemotes} from '../git'
3+
import {IGitRemotes, configRemote, getGitRemotes} from '../git.js'
44

55
class MultipleRemotesError extends Errors.CLIError {
66
constructor(gitRemotes: IGitRemotes[]) {

src/flags/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {Flags} from '@oclif/core'
22

3-
export {app, remote} from './app'
4-
export {org} from './org'
5-
export {pipeline} from './pipeline'
6-
export {team} from './team'
3+
export {app, remote} from './app.js'
4+
export {org} from './org.js'
5+
export {pipeline} from './pipeline.js'
6+
export {team} from './team.js'
77

88
// Explicitly export oclif flag types using object destructuring, sorted alphabetically
99
export const {boolean, custom, directory, file, integer, option, string, url} = Flags

0 commit comments

Comments
 (0)