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 #550

Merged
merged 12 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
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,7 +1,8 @@
{
"require": "ts-node/register,source-map-support/register",
"require": ["ts-node/register"],
"watch-extensions": "ts",
"recursive": true,
"reporter": "spec",
"timeout": 20000
"timeout": 20000,
"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: 0 additions & 4 deletions messages/doctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ Check http://status.salesforce.com for general Salesforce availability and perfo

Must first initialize a new SfDoctor.

# doctorAlreadyInitializedError

SfDoctor has already been initialized.

# pluginNotInstalledError

Specified plugin [%s] isn't installed. Install it, correct the name, or choose another plugin.
84 changes: 31 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,67 @@
"version": "2.6.51",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"main": "lib/index.js",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.7.1",
"@salesforce/core": "^5.3.1",
"@salesforce/kit": "^3.0.14",
"@salesforce/sf-plugins-core": "^3.1.28",
"got": "^11.8.6",
"@salesforce/sf-plugins-core": "^4",
"got": "^13.0.0",
"marked": "^4.3.0",
"marked-terminal": "^4.2.0",
"open": "^8.4.2",
"proxy-agent": "^6.3.1",
"semver": "^7.5.4",
"tslib": "^2"
"semver": "^7.5.4"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.14",
"@salesforce/cli-plugins-testkit": "^4.4.10",
"@salesforce/dev-config": "^4.0.1",
"@salesforce/dev-scripts": "^5.12.2",
"@salesforce/plugin-command-reference": "^3.0.45",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "^1.4.19",
"@swc/core": "1.3.39",
"@oclif/plugin-command-snapshot": "^5",
"@salesforce/cli-plugins-testkit": "^5.0.0-dev.1",
"@salesforce/dev-scripts": "^6.0.1",
"@salesforce/plugin-command-reference": "^3.0.33",
"@salesforce/ts-sinon": "^1.4.18",
"@types/fs-extra": "^9.0.13",
"@types/marked": "^4.0.8",
"@types/marked-terminal": "^3.1.3",
"@types/semver": "^7.5.4",
"@types/sinon-chai": "^3.2.11",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.62.0",
"chai": "^4.3.10",
"eslint": "^8.52.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.28.1",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-sf-plugin": "^1.16.10",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.17.2",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.0",
"oclif": "^4.0.3",
"shx": "0.3.4",
"sinon": "^11.1.1",
"sinon-chai": "^3.7.0",
"ts-node": "^10.4.0",
"typescript": "^5.2.2",
"wireit": "^0.14.1"
"typescript": "^5.2.2"
},
"config": {},
"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-info",
"keywords": [
"force",
"salesforce",
"sfdx",
"salesforcedx",
"sfdx-plugin"
"sf-plugin",
"sf",
"sfdx-plugin",
"sfdx"
],
"license": "BSD-3-Clause",
"oclif": {
"commands": "./lib/commands",
"additionalHelpFlags": [
"-h"
],
"bin": "sfdx",
"bin": "sf",
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-command-snapshot",
"@salesforce/plugin-command-reference"
],
"hooks": {
"init": [
"./lib/hooks/init/init_doctor.js"
]
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this hook removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed because we can initialize the Doctor class at the beginning of the doctor command execution. Also hooks are fairly expensive in terms of performance, especially the init hooks since they'll run on every single command execution, even --help and --version

"topics": {
"info": {
"description": "Access Salesforce CLI information from the command line.",
Expand All @@ -103,25 +77,27 @@
"doctor": {
"description": "Tools for diagnosing problems with Salesforce CLI."
}
}
},
"flexibleTaxonomy": true,
"topicSeparator": " "
},
"repository": "salesforcecli/plugin-info",
"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",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"test:only": "wireit",
"version": "oclif-dev readme"
"version": "oclif readme"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -202,7 +178,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 @@ -213,7 +189,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -223,12 +199,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"
}
36 changes: 19 additions & 17 deletions src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as os from 'node:os';
import * as path from 'node:path';
import { EOL } from 'node:os';
import { dirname, resolve as pathResolve, join } from 'node:path';
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SfError } from '@salesforce/core';
import * as open from 'open';
import open from 'open';
import got from 'got';
import { ProxyAgent } from 'proxy-agent';
import { Doctor as SFDoctor, SfDoctor, SfDoctorDiagnosis } from '../doctor';
import { DiagnosticStatus } from '../diagnostics';
import { Doctor as SFDoctor, SfDoctor, SfDoctorDiagnosis } from '../doctor.js';
import { DiagnosticStatus } from '../diagnostics.js';

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

export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
Expand Down Expand Up @@ -57,10 +58,11 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {

public async run(): Promise<SfDoctorDiagnosis> {
const { flags } = await this.parse(Doctor);
this.doctor = SFDoctor.getInstance();
// this.doctor = SFDoctor.getInstance();
this.doctor = SFDoctor.init(this.config);
const lifecycle = Lifecycle.getInstance();

this.outputDir = path.resolve(flags['output-dir'] ?? process.cwd());
this.outputDir = pathResolve(flags['output-dir'] ?? process.cwd());

lifecycle.on<DiagnosticStatus>('Doctor:diagnostic', async (data) => {
this.log(`${data.status} - ${data.testName}`);
Expand Down Expand Up @@ -102,7 +104,7 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {

const diagnosis = this.doctor.getDiagnosis();
const diagnosisLocation = this.doctor.writeFileSync(
path.join(this.outputDir, 'diagnosis.json'),
join(this.outputDir, 'diagnosis.json'),
JSON.stringify(diagnosis, null, 2)
);
this.filesWrittenMsgs.push(`Wrote doctor diagnosis to: ${diagnosisLocation}`);
Expand Down Expand Up @@ -155,14 +157,14 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
const info = `
\`\`\`
${diagnosis.cliConfig.userAgent}
${(diagnosis.versionDetail.pluginVersions ?? []).join(os.EOL)}
${(diagnosis.versionDetail.pluginVersions ?? []).join(EOL)}
\`\`\`
${
diagnosis.sfdxEnvVars.length
? `
\`\`\`
SFDX ENV. VARS.
${diagnosis.sfdxEnvVars.join(os.EOL)}
${diagnosis.sfdxEnvVars.join(EOL)}
\`\`\`
`
: ''
Expand All @@ -173,7 +175,7 @@ ${
? `
\`\`\`
SF ENV. VARS.
${diagnosis.sfEnvVars.join(os.EOL)}
${diagnosis.sfEnvVars.join(EOL)}
\`\`\`
`
: ''
Expand All @@ -191,11 +193,11 @@ ${this.doctor
.diagnosticResults.map(
(res) => `${res.status === 'pass' ? ':white_check_mark:' : ':x:'} ${res.status} - ${res.testName}`
)
.join(os.EOL)}
.join(EOL)}
`;
return body
.replace(new RegExp(`---(.|${os.EOL})*---${os.EOL}${os.EOL}`), '')
.replace(new RegExp(`${os.EOL}- Which shell/terminal (.|${os.EOL})*- Paste the output here`), info);
.replace(new RegExp(`---(.|${EOL})*---${EOL}${EOL}`), '')
.replace(new RegExp(`${EOL}- Which shell/terminal (.|${EOL})*- Paste the output here`), info);
}

// Takes the command flag and:
Expand Down Expand Up @@ -225,8 +227,8 @@ ${this.doctor
this.doctor.addCommandName(cmdString);

const execPromise = new Promise<void>((resolve) => {
const stdoutLogLocation = this.doctor.getDoctoredFilePath(path.join(this.outputDir, 'command-stdout.log'));
const debugLogLocation = this.doctor.getDoctoredFilePath(path.join(this.outputDir, 'command-debug.log'));
const stdoutLogLocation = this.doctor.getDoctoredFilePath(join(this.outputDir, 'command-stdout.log'));
const debugLogLocation = this.doctor.getDoctoredFilePath(join(this.outputDir, 'command-debug.log'));
this.doctor.createStdoutWriteStream(stdoutLogLocation);
this.doctor.createStderrWriteStream(debugLogLocation);
const cp = spawn(cmdString, [], { shell: true, env: Object.assign({}, process.env) });
Expand Down
Loading