Skip to content

Commit

Permalink
Merge pull request #751 from salesforcecli/mdonnalley/esm
Browse files Browse the repository at this point in the history
feat!: migrate to ESM
  • Loading branch information
WillieRuemmele authored Nov 8, 2023
2 parents 7340e36 + 3a05817 commit fd415e9
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 264 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 @@ -45,3 +45,5 @@ node_modules

oclif.manifest.json
oclif.lock

oclif.lock
3 changes: 3 additions & 0 deletions .lintstagedrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'**/*.{js,json,md}?(x)': () => 'npm run reformat',
};
3 changes: 0 additions & 3 deletions .lintstagedrc.js

This file was deleted.

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",
"recursive": true,
"reporter": "spec",
"timeout": 5000,
"watch-files": ["src/**/*.ts", "test/**/*.ts"]
"watch-files": ["src/**/*.ts", "test/**/*.ts"],
"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.
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
{
"name": "@salesforce/plugin-env",
"description": "An sf plugin for logging into and interacting with different Salesforce environments.",
"version": "2.2.9",
"version": "3.0.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.10.6",
"@salesforce/core": "^5.3.15",
"@salesforce/sf-plugins-core": "^3.1.28",
"@salesforce/sf-plugins-core": "^4.0.0",
"change-case": "^4.1.2",
"open": "^8.4.2",
"tslib": "^2"
"open": "^8.4.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.16",
"@oclif/test": "^2.5.6",
"@salesforce/cli-plugins-testkit": "^4.4.12",
"@oclif/plugin-command-snapshot": "^5.0.1",
"@oclif/test": "^3.1.1",
"@salesforce/cli-plugins-testkit": "^5.0.2",
"@salesforce/dev-scripts": "^6.0.3",
"@salesforce/plugin-command-reference": "^3.0.45",
"@salesforce/plugin-functions": "^1.22.8",
"@salesforce/ts-sinon": "1.4.18",
"@swc/core": "^1.3.29",
"@types/shelljs": "^0.8.13",
"eslint-plugin-sf-plugin": "^1.16.14",
"oclif": "^3.17.2",
"oclif": "^4.0.3",
"shelljs": "^0.8.5",
"shx": "0.3.4",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"config": {},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
Expand All @@ -45,7 +43,8 @@
"force",
"salesforce",
"sf",
"sf env"
"sf env",
"sf-plugin"
],
"license": "BSD-3-Clause",
"oclif": {
Expand All @@ -62,19 +61,20 @@
"env": {
"description": "Commands to manage your environments, such as orgs and compute environments."
}
}
},
"flexibleTaxonomy": true
},
"repository": "salesforcecli/plugin-env",
"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",
"test": "wireit",
Expand All @@ -85,7 +85,6 @@
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"wireit": {
"build": {
"dependencies": [
Expand Down Expand Up @@ -162,7 +161,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 @@ -173,7 +172,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -183,12 +182,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/commands/env/display.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 { Messages } from '@salesforce/core';
import { SfCommand, SfHook, JsonObject, Flags } from '@salesforce/sf-plugins-core';
import { toKey, toValue } from '../../utils';
import { toKey, toValue } from '../../utils.js';

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

export default class EnvDisplay extends SfCommand<JsonObject> {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/env/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* 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 { Interfaces } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Flags, SfCommand, JsonObject, SfHook, EnvList as Env } from '@salesforce/sf-plugins-core';
import { toKey, toValue } from '../../utils';
import { toKey, toValue } from '../../utils.js';

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

const envTypeValues = Object.keys(Env.EnvType);
Expand Down
6 changes: 4 additions & 2 deletions src/commands/env/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
*/

import { URL } from 'node:url';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Logger, Messages, Org, SfError } from '@salesforce/core';
import * as open from 'open';
import open from 'open';

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

export type OpenResult = { url: string };
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

export = {};
export default {};
72 changes: 26 additions & 46 deletions test/commands/env/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { expect, test } from '@oclif/test';
import { AuthInfo, Connection, Org, OrgAuthorization } from '@salesforce/core';

import { assert } from 'chai';
import EnvOpen, { OpenResult } from '../../../src/commands/env/open';
import EnvOpen, { OpenResult } from '../../../src/commands/env/open.js';

// we can't make this "readonly" or "as const" because OrgAuthorization includes a Nullable in is props
const expectedSfOrgs: Array<Partial<OrgAuthorization>> = [
Expand All @@ -26,32 +26,21 @@ const expectedSfOrgs: Array<Partial<OrgAuthorization>> = [
describe('open unit tests', () => {
assert(expectedSfOrgs[0].username);
test
.stub(Connection.prototype, 'getAuthInfo', (): AuthInfo => ({} as AuthInfo))
.stub(
AuthInfo.prototype,
'listAllAuthorizations',
async (): Promise<Array<Partial<OrgAuthorization>>> => expectedSfOrgs
.stub(Connection.prototype, 'getAuthInfo', (stub) => stub.returns({}))
.stub(AuthInfo, 'listAllAuthorizations', (stub) => stub.resolves(expectedSfOrgs))
.stub(AuthInfo.prototype, 'getOrgFrontDoorUrl', (stub) =>
stub.returns(`${expectedSfOrgs[0].instanceUrl}?sid=${expectedSfOrgs[0].accessToken}`)
)
.stub(
AuthInfo.prototype,
'getOrgFrontDoorUrl',
(): string => `${expectedSfOrgs[0].instanceUrl}?sid=${expectedSfOrgs[0].accessToken}`
.stub(Org.prototype, 'getConnection', (stub) =>
stub.callsFake(() => {
const getAuthInfo = (): AuthInfo => new AuthInfo();
const conn = { getAuthInfo } as Connection;
return conn;
})
)
.stub(Org.prototype, 'getConnection', (): Connection => {
const getAuthInfo = (): AuthInfo => new AuthInfo();
const conn = { getAuthInfo } as Connection;
return conn;
})
.stub(Org.prototype, 'refreshAuth', async (): Promise<void> => {})
.stub(
Org,
'create',
async (): Promise<Org> =>
new Org({
aliasOrUsername: expectedSfOrgs[0].username,
} as Org.Options)
)
.stub(EnvOpen.prototype, 'open', async (): Promise<void> => {})
.stub(Org.prototype, 'refreshAuth', (stub) => stub.resolves())
.stub(Org, 'create', (stub) => stub.resolves(new Org({ aliasOrUsername: expectedSfOrgs[0].username })))
.stub(EnvOpen.prototype, 'open', (stub) => stub.resolves())
.stdout()
.command([
'env:open',
Expand All @@ -71,28 +60,19 @@ describe('open unit tests', () => {
expect(result.url).match(urlEndRegEx);
});
test
.stub(Connection.prototype, 'getAuthInfo', (): AuthInfo => ({} as AuthInfo))
.stub(
AuthInfo.prototype,
'listAllAuthorizations',
async (): Promise<Array<Partial<OrgAuthorization>>> => expectedSfOrgs
)
.stub(AuthInfo.prototype, 'getOrgFrontDoorUrl', (): string => expectedSfOrgs[0].instanceUrl as string)
.stub(Org.prototype, 'getConnection', (): Connection => {
const getAuthInfo = (): AuthInfo => new AuthInfo();
const conn = { getAuthInfo } as Connection;
return conn;
})
.stub(Org.prototype, 'refreshAuth', async (): Promise<void> => {})
.stub(
Org,
'create',
async (): Promise<Org> =>
new Org({
aliasOrUsername: expectedSfOrgs[0].username,
} as Org.Options)
.stub(Connection.prototype, 'getAuthInfo', (stub) => stub.returns({}))
.stub(AuthInfo, 'listAllAuthorizations', (stub) => stub.resolves(expectedSfOrgs))
.stub(AuthInfo.prototype, 'getOrgFrontDoorUrl', (stub) => stub.returns(expectedSfOrgs[0].instanceUrl))
.stub(Org.prototype, 'getConnection', (stub) =>
stub.callsFake(() => {
const getAuthInfo = (): AuthInfo => new AuthInfo();
const conn = { getAuthInfo } as Connection;
return conn;
})
)
.stub(EnvOpen.prototype, 'open', async (): Promise<void> => {})
.stub(Org.prototype, 'refreshAuth', (stub) => stub.resolves())
.stub(Org, 'create', (stub) => stub.resolves(new Org({ aliasOrUsername: expectedSfOrgs[0].username })))
.stub(EnvOpen.prototype, 'open', (stub) => stub.resolves())
.stdout()
.command(['env:open', '--target-env', expectedSfOrgs[0].username, '--url-only', '--json'])
.it('should open requested environment', (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@salesforce/dev-config/tsconfig-test-strict",
"extends": "@salesforce/dev-config/tsconfig-test-strict-esm",
"include": ["./**/*.ts"],
"compilerOptions": {
"target": "es2021",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@salesforce/dev-config/tsconfig-strict",
"extends": "@salesforce/dev-config/tsconfig-strict-esm",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
Expand Down
Loading

0 comments on commit fd415e9

Please sign in to comment.