Skip to content

Commit

Permalink
Merge pull request #854 from salesforcecli/mdonnalley/esm
Browse files Browse the repository at this point in the history
feat!: migrate to ESM
  • Loading branch information
mshanemc authored Nov 9, 2023
2 parents db3afaa + f9cc43d commit e02fa18
Show file tree
Hide file tree
Showing 40 changed files with 497 additions and 324 deletions.
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.
5 changes: 5 additions & 0 deletions messages/accesstoken.store.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ To use the command in a CI/CD script, set the SFDX_ACCESS_TOKEN environment vari

The access token isn't in the correct format.
It should follow this pattern: %s.

# overwriteAccessTokenAuthUserFile

A file already exists for user "%s", which is associated with the access token you provided.
Are you sure you want to overwrite the existing file?
5 changes: 0 additions & 5 deletions messages/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,3 @@ Access token of user to use for authentication
# noPrompt

do not prompt for confirmation

# overwriteAccessTokenAuthUserFile

A file already exists for user "%s", which is associated with the access token you provided.
Are you sure you want to overwrite the existing file?
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"
}
21 changes: 4 additions & 17 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 Expand Up @@ -42,26 +44,11 @@ export abstract class AuthBaseCommand<T> extends SfCommand<T> {
}
}

protected async shouldRunCommand(noPrompt?: boolean, message?: string, defaultAnswer = true): Promise<boolean> {
if (Boolean(noPrompt) || Global.getEnvironmentMode() === Mode.DEMO) {
return true;
} else {
const msg = dimMessage(message ?? messages.getMessage('warnAuth', [this.config.bin]));
const answer = await this.confirm(msg, 10000, defaultAnswer);
return answer;
}
}

protected async askForClientSecret(disableMasking = false): Promise<string> {
return this.askForHiddenResponse('clientSecretStdin', disableMasking);
}

protected async askForAccessToken(disableMasking = false): Promise<string> {
return this.askForHiddenResponse('accessTokenStdin', disableMasking);
}

protected async askOverwriteAuthFile(username: string): Promise<boolean> {
const yN = await this.confirm(messages.getMessage('overwriteAccessTokenAuthUserFile', [username]));
return yN;
}
}
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
8 changes: 5 additions & 3 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 Expand Up @@ -107,7 +109,7 @@ export default class LoginAccessToken extends AuthBaseCommand<AuthFields> {
if (!this.flags['no-prompt']) {
const stateAggregator = await StateAggregator.getInstance();
if (await stateAggregator.orgs.exists(username)) {
return this.askOverwriteAuthFile(username);
return this.confirm(messages.getMessage('overwriteAccessTokenAuthUserFile', [username]));
}
}
return true;
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;
};
Loading

0 comments on commit e02fa18

Please sign in to comment.