Skip to content

Commit

Permalink
feat!: migrate to ESM (#435)
Browse files Browse the repository at this point in the history
* feat!: migrate to ESM

BREAKING CHANGES: ESM and node 18 minimum

* fix: compilation error

* perf: defer message loading

* refactor: dep cleanup

* chore: bump to change-case5 (esm)

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
mdonnalley and mshanemc authored Nov 14, 2023
1 parent 56e2b8b commit 6ac84f4
Show file tree
Hide file tree
Showing 32 changed files with 579 additions and 752 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cjs/
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,9 +1,10 @@
{
"require": "ts-node/register,source-map-support/register",
"require": ["ts-node/register"],
"watch-extensions": "ts",
"extensions": [".ts", ".js", ".json"],
"watch-files": ["src", "test"],
"recursive": true,
"reporter": "spec",
"timeout": 5000
"timeout": 5000,
"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.
4 changes: 4 additions & 0 deletions messages/messages.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# errorWithOrg

Org: %s: %s

# noAuthFound

No authenticated orgs found.
86 changes: 33 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,37 @@
{
"name": "@salesforce/plugin-signups",
"description": "Commands to interact with org shapes",
"version": "1.5.6",
"version": "2.0.0",
"author": "Salesforce",
"main": "lib/index.js",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"@salesforce/core": "^5.3.14",
"@salesforce/kit": "^3.0.13",
"@salesforce/sf-plugins-core": "^3.1.28",
"chalk": "^4.1.2",
"change-case": "^4.1.2",
"tslib": "^2"
"@oclif/core": "^3.11.0",
"@salesforce/core": "^5.3.20",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^4.1.2",
"chalk": "^5.3.0",
"change-case": "^5.1.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.16",
"@salesforce/cli-plugins-testkit": "^4.4.7",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/dev-scripts": "^5.12.2",
"@salesforce/plugin-command-reference": "^3.0.44",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "^1.4.19",
"@salesforce/ts-types": "^2.0.6",
"@swc/core": "^1.3.39",
"@oclif/plugin-command-snapshot": "^5.0.2",
"@salesforce/cli-plugins-testkit": "^5.0.4",
"@salesforce/dev-scripts": "^6.0.4",
"@salesforce/plugin-command-reference": "^3.0.46",
"@salesforce/ts-types": "^2.0.9",
"@types/chai-as-promised": "^7.1.7",
"@types/chai-string": "^1.4.3",
"@types/inquirer": "^9.0.6",
"@types/shelljs": "^0.8.14",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"chai": "^4.3.10",
"chai-as-promised": "7.1.1",
"chai-string": "^1.5.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-salesforce": "^2.0.2",
"eslint-config-salesforce-license": "^0.2.0",
"eslint-config-salesforce-typescript": "^2.0.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-sf-plugin": "^1.16.12",
"husky": "^7.0.4",
"jsforce": "^2.0.0-beta.27",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.17.2",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.0",
"eslint-plugin-sf-plugin": "^1.16.15",
"jsforce": "^2.0.0-beta.28",
"oclif": "^4.0.3",
"shx": "0.3.4",
"sinon": "^11.1.1",
"ts-node": "^10.2.1",
"typescript": "^5.2.2",
"wireit": "^0.14.1"
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"config": {},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
Expand All @@ -69,14 +43,16 @@
"keywords": [
"force",
"salesforce",
"sfdx",
"salesforcedx",
"sf",
"sf-plugin",
"sfdx",
"sfdx-plugin"
],
"license": "BSD-3-Clause",
"oclif": {
"commands": "./lib/commands",
"bin": "sfdx",
"bin": "sf",
"devPlugins": [
"@oclif/plugin-command-snapshot",
"@salesforce/plugin-command-reference"
Expand Down Expand Up @@ -136,19 +112,21 @@
}
}
}
}
},
"flexibleTaxonomy": true,
"topicSeparator": " "
},
"repository": "salesforcecli/plugin-signups",
"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 Down Expand Up @@ -236,7 +214,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 @@ -247,7 +225,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -257,12 +235,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/org/create/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 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 {
SfCommand,
requiredOrgFlagWithDeprecations,
Expand All @@ -13,9 +15,9 @@ import {
} from '@salesforce/sf-plugins-core';
import { Messages, Connection, Logger } from '@salesforce/core';
import type { SaveResult } from 'jsforce';
import { isShapeEnabled, JsForceError } from '../../../shared/orgShapeListUtils';
import { isShapeEnabled, JsForceError } from '../../../shared/orgShapeListUtils.js';

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

export interface ShapeCreateResult {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/org/create/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* 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 {
Flags,
SfCommand,
Expand All @@ -12,9 +14,9 @@ import {
requiredHubFlagWithDeprecations,
} from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages, SfError } from '@salesforce/core';
import { OrgSnapshot, queryByNameOrId, printSingleRecordTable } from '../../../shared/snapshot';
import { OrgSnapshot, queryByNameOrId, printSingleRecordTable } from '../../../shared/snapshot.js';

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

export class SnapshotCreate extends SfCommand<OrgSnapshot> {
Expand Down
76 changes: 7 additions & 69 deletions src/commands/org/delete/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,22 @@
* 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,
SfCommand,
requiredOrgFlagWithDeprecations,
orgApiVersionFlagWithDeprecations,
loglevel,
} from '@salesforce/sf-plugins-core';
import { Messages, Connection, SfError } from '@salesforce/core';
import { isShapeEnabled, JsForceError } from '../../../shared/orgShapeListUtils';
import { Messages, SfError } from '@salesforce/core';
import { isShapeEnabled } from '../../../shared/orgShapeListUtils.js';
import utils, { DeleteAllResult } from '../../../shared/deleteUtils.js';

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

interface ShapeRepresentation {
Id: string;
Status: string;
Edition: string;
Features: string;
Settings: string;
CreatedDate: string;
Description: string;
}

type FailureMsg = {
shapeId: string;
message: string;
};

type DeleteAllResult = {
shapeIds: string[];
failures: FailureMsg[];
};

export interface OrgShapeDeleteResult extends DeleteAllResult {
orgId: string;
}
Expand Down Expand Up @@ -78,7 +61,7 @@ export class OrgShapeDeleteCommand extends SfCommand<OrgShapeDeleteResult | unde
throw messages.createError('noAccess', [username]);
}

const deleteRes = await deleteAll(conn, username);
const deleteRes = await utils.deleteAll(conn, username);

if (deleteRes.shapeIds.length === 0) {
this.info(messages.getMessage('noShapesHumanSuccess', [orgId]));
Expand Down Expand Up @@ -112,51 +95,6 @@ export class OrgShapeDeleteCommand extends SfCommand<OrgShapeDeleteResult | unde
}
}

/**
* Delete all ShapeRepresentation records for the shapeOrg.
*
* @return List of SR IDs that were deleted
*/
export const deleteAll = async (conn: Connection, username: string): Promise<DeleteAllResult> => {
let shapeIds: string[] = [];
const deleteAllResult: DeleteAllResult = {
shapeIds: [],
failures: [],
};
try {
const result = await conn.query<ShapeRepresentation>('SELECT Id FROM ShapeRepresentation');
if (result.totalSize === 0) {
return deleteAllResult;
}
shapeIds = result.records.map((shape) => shape.Id);
} catch (err) {
const JsForceErr = err as JsForceError;
if (JsForceErr.errorCode && JsForceErr.errorCode === 'INVALID_TYPE') {
// ShapeExportPref is not enabled, or user does not have CRUD access
throw messages.createError('noAccess', [username]);
}
// non-access error
throw JsForceErr;
}

await Promise.all(
shapeIds.map(async (id) => {
try {
const delResult = await conn.sobject('ShapeRepresentation').delete(id);
if (delResult.success) {
deleteAllResult.shapeIds.push(id);
}
} catch (err) {
deleteAllResult.failures.push({
shapeId: id,
message: err instanceof Error ? err.message : 'error contained no message',
});
}
})
);

return deleteAllResult;
};
const setExitCode = (code: number): void => {
process.exitCode = code;
};
Loading

0 comments on commit 6ac84f4

Please sign in to comment.