diff --git a/.gitignore b/.gitignore index 4843d1fa..9b08d8e3 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ node_modules oclif.manifest.json oclif.lock + +oclif.lock diff --git a/.lintstagedrc.cjs b/.lintstagedrc.cjs new file mode 100644 index 00000000..9a99d41c --- /dev/null +++ b/.lintstagedrc.cjs @@ -0,0 +1,3 @@ +module.exports = { + '**/*.{js,json,md}?(x)': () => 'npm run reformat', +}; diff --git a/.lintstagedrc.js b/.lintstagedrc.js deleted file mode 100644 index d7fab80d..00000000 --- a/.lintstagedrc.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - '**/*.{js,json,md}?(x)': () => 'npm run reformat' -}; diff --git a/bin/dev.cmd b/bin/dev.cmd old mode 100644 new mode 100755 index 8ae2b12c..cec553be --- a/bin/dev.cmd +++ b/bin/dev.cmd @@ -1,3 +1,3 @@ @echo off -node "%~dp0\dev" %* +node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %* diff --git a/bin/dev.js b/bin/dev.js index 7df65142..89a549a7 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -1,4 +1,4 @@ -#!/usr/bin/env ts-node +#!/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'); diff --git a/bin/run.js b/bin/run.js index 07987471..cf13fb93 100755 --- a/bin/run.js +++ b/bin/run.js @@ -1,5 +1,6 @@ #!/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 }); diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 100% rename from commitlint.config.js rename to commitlint.config.cjs diff --git a/package.json b/package.json index 8f3b696b..d77051da 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "bugs": "https://github.com/forcedotcom/cli/issues", "dependencies": { - "@oclif/core": "^3.8.0", + "@oclif/core": "^3.9.0", "@salesforce/core": "^5.3.10", "@salesforce/sf-plugins-core": "^4.0.0", "got": "^13.0.0", @@ -36,7 +36,7 @@ "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-dev.1", + "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", @@ -63,6 +63,7 @@ "/lib", "/messages", "/oclif.manifest.json", + "/oclif.lock", "/oclif.lock" ], "homepage": "https://github.com/salesforcecli/plugin-trust", diff --git a/src/commands/plugins/trust/verify.ts b/src/commands/plugins/trust/verify.ts index 56e0150f..96e2e03d 100644 --- a/src/commands/plugins/trust/verify.ts +++ b/src/commands/plugins/trust/verify.ts @@ -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 { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; import { SfCommand, Flags, loglevel } from '@salesforce/sf-plugins-core'; import { Messages, SfError, Logger } from '@salesforce/core'; import { @@ -15,7 +17,7 @@ import { import { NpmName } from '../../../shared/NpmName.js'; import { setErrorName } from '../../../shared/errors.js'; -Messages.importMessagesDirectory(__dirname); +Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url))); const messages = Messages.loadMessages('@salesforce/plugin-trust', 'verify'); export interface VerifyResponse { diff --git a/src/shared/installationVerification.ts b/src/shared/installationVerification.ts index 44381086..ddbcdf76 100644 --- a/src/shared/installationVerification.ts +++ b/src/shared/installationVerification.ts @@ -11,6 +11,8 @@ import { URL } from 'node:url'; import * as crypto from 'node:crypto'; import * as fs from 'node:fs'; import { mkdir } from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; import { Logger, SfError, Messages } from '@salesforce/core'; import got from 'got'; import { ProxyAgent } from 'proxy-agent'; @@ -19,11 +21,10 @@ import { ux } from '@oclif/core'; import { NpmModule, NpmMeta } from './npmCommand.js'; import { NpmName } from './NpmName.js'; import { setErrorName } from './errors.js'; - const CRYPTO_LEVEL = 'RSA-SHA256'; const ALLOW_LIST_FILENAME = 'unsignedPluginAllowList.json'; export const DEFAULT_REGISTRY = 'https://registry.npmjs.org/'; -Messages.importMessagesDirectory(__dirname); +Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url))); export interface ConfigContext { configDir?: string; diff --git a/test/nuts/plugin-install.nut.ts b/test/nuts/plugin-install.nut.ts index 21ff92da..32e979e8 100644 --- a/test/nuts/plugin-install.nut.ts +++ b/test/nuts/plugin-install.nut.ts @@ -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 * as path from 'node:path'; -import * as fs from 'node:fs'; -import * as os from 'node:os'; +import path from 'node:path'; +import fs from 'node:fs'; +import os from 'node:os'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; import { expect, config } from 'chai'; import { TestSession, execCmd, execInteractiveCmd, Interaction } from '@salesforce/cli-plugins-testkit'; import { Messages } from '@salesforce/core'; -Messages.importMessagesDirectory(__dirname); +Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url))); const messages = Messages.loadMessages('@salesforce/plugin-trust', 'verify'); config.truncateThreshold = 0; diff --git a/test/shared/installationVerification.test.ts b/test/shared/installationVerification.test.ts index 50b69f06..c493c829 100644 --- a/test/shared/installationVerification.test.ts +++ b/test/shared/installationVerification.test.ts @@ -6,6 +6,8 @@ */ import { Readable } from 'node:stream'; import * as fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; import { assert, expect } from 'chai'; import got from 'got'; import { OptionsOfTextResponseBody } from 'got'; @@ -130,7 +132,7 @@ describe('InstallationVerification Tests', () => { return 'configDir'; }, get cliRoot() { - return __dirname; + return dirname(fileURLToPath(import.meta.url)); }, }; const currentRegistry = process.env.SFDX_NPM_REGISTRY; diff --git a/test/shared/npmCommand.test.ts b/test/shared/npmCommand.test.ts index f803485b..618d4b73 100644 --- a/test/shared/npmCommand.test.ts +++ b/test/shared/npmCommand.test.ts @@ -8,6 +8,8 @@ import { fail } from 'node:assert'; import * as os from 'node:os'; import * as fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; import { expect, assert } from 'chai'; import * as Sinon from 'sinon'; import * as shelljs from 'shelljs'; @@ -100,7 +102,9 @@ describe('should run npm commands', () => { }); it('Runs the show command', () => { - const npmMetadata = new NpmModule(MODULE_NAME, undefined, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, undefined, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(shelljsExecStub).to.have.been.calledOnce; expect(shelljsExecStub.firstCall.args[0]).to.include(`show ${MODULE_NAME}@latest`); expect(shelljsExecStub.firstCall.args[0]).to.include(`--registry=${DEFAULT_REGISTRY}`); @@ -108,7 +112,9 @@ describe('should run npm commands', () => { }); it('Runs the show command with specified version', () => { - const npmMetadata = new NpmModule(MODULE_NAME, MODULE_VERSION, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, MODULE_VERSION, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(shelljsExecStub).to.have.been.calledOnce; expect(shelljsExecStub.firstCall.args[0]).to.include(`show ${MODULE_NAME}@${MODULE_VERSION}`); expect(shelljsExecStub.firstCall.args[0]).to.include(`--registry=${DEFAULT_REGISTRY}`); @@ -116,7 +122,9 @@ describe('should run npm commands', () => { }); it('Runs the pack command', () => { - new NpmModule(MODULE_NAME, MODULE_VERSION, __dirname).pack(DEFAULT_REGISTRY, { cwd: CACHE_PATH }); + new NpmModule(MODULE_NAME, MODULE_VERSION, dirname(fileURLToPath(import.meta.url))).pack(DEFAULT_REGISTRY, { + cwd: CACHE_PATH, + }); expect(shelljsExecStub).to.have.been.calledOnce; expect(shelljsExecStub.firstCall.args[0]).to.include(`pack ${MODULE_NAME}@${MODULE_VERSION}`); expect(shelljsExecStub.firstCall.args[0]).to.include(`--registry=${DEFAULT_REGISTRY}`); @@ -185,7 +193,9 @@ describe('should find the node executable', () => { }); it('finds node binary inside sfdx bin folder and runs npm show command', () => { - const npmMetadata = new NpmModule(MODULE_NAME, undefined, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, undefined, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(accessSyncStub).to.have.been.calledOnce; expect(existsSyncStub).to.have.been.calledTwice; expect(osTypeStub).to.have.been.calledOnce; @@ -202,7 +212,9 @@ describe('should find the node executable', () => { shelljsFindStub.returns(['C:\\Program Files\\sfdx\\client\\bin\\node.exe']); osTypeStub.returns('Windows_NT'); - const npmMetadata = new NpmModule(MODULE_NAME, undefined, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, undefined, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(accessSyncStub).to.not.have.been.called; expect(existsSyncStub).to.have.been.calledTwice; expect(osTypeStub).to.have.been.calledOnce; @@ -228,7 +240,9 @@ describe('should find the node executable', () => { code: 0, } as shelljs.ShellString; }); - const npmMetadata = new NpmModule(MODULE_NAME, undefined, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, undefined, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(existsSyncStub).to.have.been.calledTwice; expect(shelljsFindStub).to.not.have.been.called; expect(realpathSyncStub).to.not.have.been.called; @@ -252,7 +266,9 @@ describe('should find the node executable', () => { return null; }); try { - const npmMetadata = new NpmModule(MODULE_NAME, undefined, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, undefined, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(npmMetadata).to.be.undefined; fail('Error'); } catch (error) { @@ -304,7 +320,9 @@ describe('should run npm commands with execution errors', () => { it('show command throws error', () => { try { - const npmMetadata = new NpmModule(MODULE_NAME, undefined, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, undefined, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(npmMetadata).to.be.undefined; fail('Error'); } catch (error) { @@ -315,7 +333,9 @@ describe('should run npm commands with execution errors', () => { it('Runs the pack command', () => { try { - new NpmModule(MODULE_NAME, MODULE_VERSION, __dirname).pack(DEFAULT_REGISTRY, { cwd: CACHE_PATH }); + new NpmModule(MODULE_NAME, MODULE_VERSION, dirname(fileURLToPath(import.meta.url))).pack(DEFAULT_REGISTRY, { + cwd: CACHE_PATH, + }); fail('Error'); } catch (error) { assert(error instanceof SfError); @@ -363,7 +383,9 @@ describe('should run npm commands with parse errors', () => { it('show command throws error', () => { try { - const npmMetadata = new NpmModule(MODULE_NAME, MODULE_VERSION, __dirname).show(DEFAULT_REGISTRY); + const npmMetadata = new NpmModule(MODULE_NAME, MODULE_VERSION, dirname(fileURLToPath(import.meta.url))).show( + DEFAULT_REGISTRY + ); expect(npmMetadata).to.be.undefined; fail('Error'); } catch (error) { @@ -402,7 +424,7 @@ describe('should run npm commands with npm errors', () => { it('show command throws error', () => { try { - new NpmModule(MODULE_NAME, MODULE_VERSION, __dirname).show(DEFAULT_REGISTRY); + new NpmModule(MODULE_NAME, MODULE_VERSION, dirname(fileURLToPath(import.meta.url))).show(DEFAULT_REGISTRY); } catch (error) { assert(error instanceof SfError); expect(error.code).to.equal('NpmError'); @@ -412,7 +434,7 @@ describe('should run npm commands with npm errors', () => { it('pack command throws error', () => { try { - new NpmModule(MODULE_NAME, MODULE_VERSION, __dirname).pack(DEFAULT_REGISTRY); + new NpmModule(MODULE_NAME, MODULE_VERSION, dirname(fileURLToPath(import.meta.url))).pack(DEFAULT_REGISTRY); } catch (error) { assert(error instanceof SfError); expect(error.code).to.equal('NpmError'); diff --git a/yarn.lock b/yarn.lock index 270e818a..26f3881e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -966,10 +966,10 @@ wordwrap "^1.0.0" wrap-ansi "^7.0.0" -"@oclif/core@^3.0.0", "@oclif/core@^3.0.4", "@oclif/core@^3.3.1", "@oclif/core@^3.5.0", "@oclif/core@^3.8.0": - version "3.8.0" - resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.8.0.tgz#45f5f630b3b593c3486e7835953ad6fb2af01bcb" - integrity sha512-fKqg9QzjIflDcYljZkZEeY6zoRyk4AZ5e2V4LUIsSOR7+B78qpqNqDPJFTI8TvrEU3+Q+ssELntOL2VA3SMsqQ== +"@oclif/core@^3.0.0", "@oclif/core@^3.0.4", "@oclif/core@^3.3.1", "@oclif/core@^3.5.0", "@oclif/core@^3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.9.0.tgz#51c53ea4eafd3d643a55a37477f3e7c9d2cc2942" + integrity sha512-9UT0ySJgaUvERUQwDFh0u9Q5cfoBttfyaJ1sorSms6H5AELIjQ2Yvu2QfzPmnAit2rod+hdcDZ+O1Hia5Zcz+Q== dependencies: ansi-escapes "^4.3.2" ansi-styles "^4.3.0" @@ -3551,7 +3551,7 @@ eslint-config-salesforce-license@^0.2.0: resolved "https://registry.yarnpkg.com/eslint-config-salesforce-license/-/eslint-config-salesforce-license-0.2.0.tgz#323193f1aa15dd33fbf108d25fc1210afc11065e" integrity sha512-DJdBvgj82Erum82YMe+YvG/o6ukna3UA++lRl0HSTldj0VlBl3Q8hzCp97nRXZHra6JH1I912yievZzklXDw6w== -eslint-config-salesforce-typescript@^2.0.0, eslint-config-salesforce-typescript@^2.0.0-dev.1: +eslint-config-salesforce-typescript@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/eslint-config-salesforce-typescript/-/eslint-config-salesforce-typescript-2.0.0.tgz#df6cd54c7d5254158e0c175a8a3526d3f9510b56" integrity sha512-1gq4ChEamP3VaDXoMJdEUX92fOdNMjX9/xOfByOO5AsQJnakRE/P4LWQrw5QqQQGWU8YnnM/OADFI9otD002aQ==