Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: migrate to ESM #854

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cjs/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ node_modules
.idea

oclif.manifest.json

oclif.lock
File renamed without changes.
5 changes: 3 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"require": "ts-node/register,source-map-support/register",
"require": ["ts-node/register"],
"watch-extensions": "ts",
"watch-files": ["src", "test"],
"recursive": true,
"reporter": "spec",
"timeout": 10000
"timeout": 10000,
"node-option": ["loader=ts-node/esm"]
}
21 changes: 0 additions & 21 deletions bin/dev

This file was deleted.

2 changes: 1 addition & 1 deletion bin/dev.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off

node "%~dp0\dev" %*
node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
8 changes: 8 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line node/shebang
async function main() {
const {execute} = await import('@oclif/core')
await execute({development: true, dir: import.meta.url})
}

await main()
3 changes: 0 additions & 3 deletions bin/run

This file was deleted.

9 changes: 9 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

// eslint-disable-next-line node/shebang
async function main() {
const {execute} = await import('@oclif/core')
await execute({dir: import.meta.url})
}

await main()
File renamed without changes.
52 changes: 27 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
{
"name": "@salesforce/plugin-auth",
"description": "plugin for sfdx auth commands",
"version": "2.8.26",
"description": "plugin for sf auth commands",
"version": "3.0.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"main": "lib/index.js",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.10.2",
"@salesforce/core": "^5.3.17",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^3.1.28",
"@salesforce/sf-plugins-core": "^4.1.0",
"@salesforce/ts-types": "^2.0.9",
"chalk": "^4.1.2",
"inquirer": "^8.2.6",
"open": "^8.2.1",
"tslib": "^2"
"chalk": "^5.3.0",
"open": "^9.1.0"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.14",
"@salesforce/cli-plugins-testkit": "^4.4.12",
"@oclif/plugin-command-snapshot": "^5.0.1",
"@salesforce/cli-plugins-testkit": "^5.0.2",
"@salesforce/dev-scripts": "^6.0.3",
"@salesforce/plugin-command-reference": "^3.0.42",
"@salesforce/ts-sinon": "^1.4.19",
"@swc/core": "1.3.39",
"@types/inquirer": "^8.2.0",
"eslint-plugin-sf-plugin": "^1.16.11",
"oclif": "^3.17.2",
"oclif": "^4.0.3",
"shx": "0.3.4",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
"/messages",
"/oclif.manifest.json"
"/oclif.manifest.json",
"/oclif.lock"
],
"homepage": "https://github.com/salesforcecli/plugin-auth",
"keywords": [
"force",
"salesforce",
"sfdx",
"salesforcedx",
"sf",
"sf-plugin",
"sfdx",
"sfdx-plugin"
],
"license": "BSD-3-Clause",
Expand All @@ -52,7 +50,7 @@
"additionalHelpFlags": [
"-h"
],
"bin": "sfdx",
"bin": "sf",
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-command-snapshot",
Expand Down Expand Up @@ -88,19 +86,21 @@
}
}
}
}
},
"flexibleTaxonomy": true,
"topicSeparator": " "
},
"repository": "salesforcecli/plugin-auth",
"scripts": {
"build": "wireit",
"clean": "sf-clean",
"clean-all": "sf-clean all",
"clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json",
"clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json oclif.lock",
"compile": "wireit",
"docs": "sf-docs",
"format": "wireit",
"lint": "wireit",
"postpack": "shx rm -f oclif.manifest.json",
"postpack": "shx rm -f oclif.manifest.json oclif.lock",
"prepack": "sf-prepack",
"prepare": "sf-install",
"reformat": "prettier --config .prettierrc --write './*.{js,json,md}' './**/*.{ts,json,md}'",
Expand Down Expand Up @@ -188,7 +188,7 @@
"output": []
},
"test:command-reference": {
"command": "\"./bin/dev\" commandreference:generate --erroronwarnings",
"command": "ts-node \"./bin/dev.js\" commandreference:generate --erroronwarnings",
"files": [
"src/**/*.ts",
"messages/**",
Expand All @@ -199,7 +199,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -209,12 +209,14 @@
]
},
"test:json-schema": {
"command": "\"./bin/dev\" schema:compare",
"command": "ts-node \"./bin/dev.js\" schema:compare",
"files": [
"src/**/*.ts",
"schemas"
],
"output": []
}
}
},
"exports": "./lib/index.js",
"type": "module"
}
6 changes: 4 additions & 2 deletions src/authBaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Messages, Global, Mode } from '@salesforce/core';
import * as chalk from 'chalk';
import chalk from 'chalk';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { Config } from '@oclif/core';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

function dimMessage(message: string): string {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/org/list/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { AuthInfo, Messages, OrgAuthorization } from '@salesforce/core';
type AuthListResult = Omit<OrgAuthorization, 'aliases'> & { alias: string };
export type AuthListResults = AuthListResult[];
Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'list');

export default class ListAuth extends SfCommand<AuthListResults> {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/org/login/access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, Messages, matchesAccessToken, SfError, StateAggregator } from '@salesforce/core';
import { env } from '@salesforce/kit';
import { Interfaces } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand';
import { AuthBaseCommand } from '../../../authBaseCommand.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'accesstoken.store');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

Expand Down
10 changes: 6 additions & 4 deletions src/commands/org/login/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { AuthFields, AuthInfo, DeviceOauthService, Messages, OAuth2Config } from '@salesforce/core';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { DeviceCodeResponse } from '@salesforce/core/lib/deviceOauthService';
import { DeviceCodeResponse } from '@salesforce/core/lib/deviceOauthService.js';
import { ux } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand';
import { Common } from '../../../common';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import { Common } from '../../../common.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'device.login');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

Expand Down
8 changes: 5 additions & 3 deletions src/commands/org/login/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, AuthRemover, Logger, Messages, SfError } from '@salesforce/core';
import { Interfaces } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand';
import { Common } from '../../../common';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import { Common } from '../../../common.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'jwt.grant');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

Expand Down
14 changes: 9 additions & 5 deletions src/commands/org/login/sfdx-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { readFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'node:fs/promises';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import { parseJson } from '@salesforce/kit';
import { AuthBaseCommand } from '../../../authBaseCommand';
import { AuthBaseCommand } from '../../../authBaseCommand.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'sfdxurl.store');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

Expand Down Expand Up @@ -71,7 +73,9 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {

const authFile = flags['sfdx-url-file'];

const sfdxAuthUrl = authFile.endsWith('.json') ? await getUrlFromJson(authFile) : await readFile(authFile, 'utf8');
const sfdxAuthUrl = authFile.endsWith('.json')
? await getUrlFromJson(authFile)
: await fs.readFile(authFile, 'utf8');

if (!sfdxAuthUrl) {
throw new Error(
Expand Down Expand Up @@ -101,7 +105,7 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {
}

const getUrlFromJson = async (authFile: string): Promise<string> => {
const jsonContents = await readFile(authFile, 'utf8');
const jsonContents = await fs.readFile(authFile, 'utf8');
const authFileJson = parseJson(jsonContents) as AuthJson;
return authFileJson.result?.sfdxAuthUrl ?? authFileJson.sfdxAuthUrl;
};
16 changes: 8 additions & 8 deletions src/commands/org/login/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as open from 'open';

import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import open, { apps, AppName } from 'open';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { AuthFields, AuthInfo, Logger, Messages, OAuth2Config, SfError, WebOAuthServer } from '@salesforce/core';
import { Env } from '@salesforce/kit';
import { Interfaces } from '@oclif/core';
import { AuthBaseCommand } from '../../../authBaseCommand';
import { Common } from '../../../common';
import { AuthBaseCommand } from '../../../authBaseCommand.js';
import { Common } from '../../../common.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'web.login');
const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

Expand Down Expand Up @@ -128,9 +129,8 @@ export default class LoginWeb extends AuthBaseCommand<AuthFields> {
private async executeLoginFlow(oauthConfig: OAuth2Config): Promise<AuthInfo> {
const oauthServer = await WebOAuthServer.create({ oauthConfig });
await oauthServer.start();
const app =
this.flags.browser && this.flags.browser in open.apps ? (this.flags.browser as open.AppName) : undefined;
const openOptions = app ? { app: { name: open.apps[app] }, wait: false } : { wait: false };
const app = this.flags.browser && this.flags.browser in apps ? (this.flags.browser as AppName) : undefined;
const openOptions = app ? { app: { name: apps[app] }, wait: false } : { wait: false };
await open(oauthServer.getAuthorizationUrl(), openOptions);
return oauthServer.authorizeAndSave();
}
Expand Down
Loading