Skip to content

Commit

Permalink
feat: make esm
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 1, 2023
1 parent 2a2377e commit 858bab3
Show file tree
Hide file tree
Showing 26 changed files with 565 additions and 694 deletions.
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ docs
oclif.manifest.json

# -- CLEAN ALL
*.tsbuildinfo
.eslintcache
.wireit
node_modules

# --
Expand Down
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,
"exclude": "node_modules/**/*"
"exclude": "node_modules/**/*",
"node-option": ["loader=ts-node/esm"]
}
13 changes: 0 additions & 13 deletions bin/dev

This file was deleted.

7 changes: 7 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

void (async () => {
const oclif = await import('@oclif/core');
oclif.settings.performanceEnabled = true;
await oclif.execute({ development: true, dir: import.meta.url });
})();
25 changes: 0 additions & 25 deletions bin/run

This file was deleted.

30 changes: 30 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node

void (async () => {
// Since the CLI is a single process, we can have a larger amount of max listeners since
// the process gets shut down. Don't set it to 0 (no limit) since we should still be aware
// of rouge event listeners
process.setMaxListeners(parseInt(process.env.SF_MAX_EVENT_LISTENERS, 10) || 1000);

// Don't let other plugins override the CLI specified max listener count
process.setMaxListeners = () => {};

// Pre-process/prune flags before creating or running the actual CLI
(await import('../dist/flags.js')).preprocessCliFlags(process);

const oclif = await import('@oclif/core');
const { createRequire } = await import('module');
const pjson = createRequire(import.meta.url)('../package.json');

const cli = await import('../dist/cli.js');

cli
.create({ version: pjson.version, bin: pjson.oclif.bin, channel: 'stable' })
.run()
.then(async () => {
await oclif.flush();
})
.catch(async (err) => {
await oclif.handle(err);
});
})();
File renamed without changes.
126 changes: 110 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"version": "2.8.2",
"author": "Salesforce",
"bin": {
"sf": "./bin/run",
"sfdx": "./bin/run"
"sf": "./bin/run.js",
"sfdx": "./bin/run.js"
},
"homepage": "https://github.com/salesforcecli/cli",
"bugs": "https://github.com/forcedotcom/cli/issues",
Expand All @@ -27,7 +27,8 @@
"sf"
],
"license": "BSD-3-Clause",
"main": "dist/index.js",
"exports": "./dist/index.js",
"type": "module",
"oclif": {
"bin": "sf",
"binAliases": [
Expand Down Expand Up @@ -119,7 +120,7 @@
]
},
"dependencies": {
"@oclif/core": "2.14.0",
"@oclif/core": "3.0.0-beta.11",
"@oclif/plugin-autocomplete": "2.3.6",
"@oclif/plugin-commands": "2.2.24",
"@oclif/plugin-help": "5.2.18",
Expand Down Expand Up @@ -189,14 +190,14 @@
},
"repository": "salesforcecli/cli",
"scripts": {
"build": "sf-build",
"build": "wireit",
"channel:promote": "sf-release channel:promote",
"clean": "sf-clean",
"clean-all": "sf-clean all",
"compile": "sf-compile",
"compile": "wireit",
"docs": "sf-docs",
"format": "sf-format",
"lint": "eslint \"src/**/*.ts\"",
"format": "wireit",
"lint": "wireit",
"oclif-artifacts": "oclif manifest",
"pack:deb": "oclif pack:deb",
"pack:macos": "oclif pack:macos",
Expand All @@ -211,13 +212,12 @@
"prepare": "sf-install && yarn compile && yarn lint",
"prepublishOnly": "npm shrinkwrap",
"pretarball": "sf-release cli:tarballs:prepare --types",
"pretest": "echo disable # sf-compile-test",
"promote": "oclif promote",
"promote-dist-tags": "./scripts/promote-dist-tags",
"promote:verify": "sf-release cli:versions:inspect --channels stable --locations archive --cli sf",
"promote:verify-rc": "sf-release cli:versions:inspect --channels stable-rc --locations archive --cli sf",
"test": "sf-test",
"test:deprecation-policy": "sf-release cli:artifacts:compare",
"test": "wireit",
"test:only": "wireit",
"test:smoke-unix": "sf-release cli:tarballs:smoke --cli sf",
"upload:deb": "oclif upload:deb",
"upload:macos": "oclif upload:macos",
Expand All @@ -227,9 +227,9 @@
},
"types": "dist/index.d.ts",
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.3.0",
"@oclif/plugin-command-snapshot": "^4.0.2",
"@salesforce/dev-config": "^4.0.1",
"@salesforce/dev-scripts": "^3.1.1",
"@salesforce/dev-scripts": "^5.8.0",
"@salesforce/plugin-release-management": "^4.1.19",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "^1.4.15",
Expand All @@ -239,7 +239,7 @@
"aws-sdk": "^2.1446.0",
"chai": "^4.3.8",
"eslint": "^8.48.0",
"eslint-config-oclif": "^3.1",
"eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^0.2.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-salesforce": "^2.0.2",
Expand All @@ -255,8 +255,102 @@
"oclif": "^3.11.3",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"sinon": "^11.1.2",
"sinon": "^15.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"wireit": "^0.9.5"
},
"wireit": {
"build": {
"dependencies": [
"compile",
"lint"
]
},
"compile": {
"command": "tsc -p . --pretty --incremental",
"files": [
"src/**/*.ts",
"**/tsconfig.json",
"messages/**"
],
"output": [
"lib/**",
"*.tsbuildinfo"
],
"clean": "if-file-deleted"
},
"format": {
"command": "prettier --write \"+(src|test|schemas)/**/*.+(ts|js|json)|command-snapshot.json\"",
"files": [
"src/**/*.ts",
"test/**/*.ts",
"schemas/**/*.json",
"command-snapshot.json",
".prettier*"
],
"output": []
},
"lint": {
"command": "eslint src test --color --cache --cache-location .eslintcache",
"files": [
"src/**/*.ts",
"test/**/*.ts",
"messages/**",
"**/.eslint*",
"**/tsconfig.json"
],
"output": []
},
"test:compile": {
"command": "tsc -p \"./test\" --pretty",
"files": [
"test/**/*.ts",
"**/tsconfig.json"
],
"output": []
},
"test": {
"dependencies": [
"test:compile",
"test:only",
"lint"
]
},
"test:only": {
"command": "nyc mocha \"test/**/*.test.ts\"",
"env": {
"FORCE_COLOR": "2"
},
"files": [
"test/**/*.ts",
"src/**/*.ts",
"**/tsconfig.json",
".mocha*",
"!*.nut.ts",
".nycrc"
],
"output": []
},
"test:deprecation-policy": {
"command": "sf-release cli:artifacts:compare",
"files": [
"src/**/*.ts"
],
"output": [],
"dependencies": [
"compile"
]
},
"test:smoke-unix": {
"command": "sf-release cli:tarballs:smoke --cli sf",
"files": [
"src/**/*.ts"
],
"output": [],
"dependencies": [
"compile"
]
}
}
}
77 changes: 40 additions & 37 deletions scripts/post-install-release-notes.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
#!/usr/bin/env node

const { spawn } = require('child_process');
const { join } = require('path');

if (process.env.SF_HIDE_RELEASE_NOTES === 'true') process.exit(0);

const logAndExit = (msg) => {
console.log('NOTE: This error can be ignored in CI and may be silenced in the future');
console.log('- Set the SF_HIDE_RELEASE_NOTES env var to "true" to skip this script\n');
console.log(msg.toString());

process.exit(0);
};

/*
* NOTE: Please read "Notes about the hook scripts" in this PR before making changes:
* https://github.com/salesforcecli/sfdx-cli/pull/407
*/

var executable = process.platform === 'win32' ? 'run.cmd' : 'run';

var cmd = spawn(join(__dirname, '..', 'bin', executable), ['whatsnew', '--hook'], {
stdio: ['ignore', 'inherit', 'pipe'],
timeout: 10000,
});

cmd.stderr.on('data', (error) => {
logAndExit(error);
});

cmd.on('error', (error) => {
logAndExit(error);
});

// 'exit' fires whether or not the stream are finished
cmd.on('exit', (code) => {
process.exit(0);
});
void (async () => {
const { spawn } = await import('node:child_process');
const { join } = await import('node:path');
const { fileURLToPath } = await import('node:url');

if (process.env.SF_HIDE_RELEASE_NOTES === 'true') process.exit(0);

const logAndExit = (msg) => {
console.log('NOTE: This error can be ignored in CI and may be silenced in the future');
console.log('- Set the SF_HIDE_RELEASE_NOTES env var to "true" to skip this script\n');
console.log(msg.toString());

process.exit(0);
};

/*
* NOTE: Please read "Notes about the hook scripts" in this PR before making changes:
* https://github.com/salesforcecli/sfdx-cli/pull/407
*/

const executable = process.platform === 'win32' ? 'run.cmd' : 'run.js';

const cmd = spawn(join(fileURLToPath(import.meta.url), '..', '..', 'bin', executable), ['whatsnew', '--hook'], {
stdio: ['ignore', 'inherit', 'pipe'],
timeout: 10000,
});

cmd.stderr.on('data', (error) => {
logAndExit(error);
});

cmd.on('error', (error) => {
logAndExit(error);
});

// 'exit' fires whether or not the stream are finished
cmd.on('exit', (code) => {
process.exit(0);
});
})();
9 changes: 5 additions & 4 deletions scripts/preinstall.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { execSync } = require('child_process');

(() => {
void (async () => {
const { execSync } = await import('node:child_process');
const testCliNotVersion = (cli, version) => {
try {
return execSync(`${cli} --version`).toString('utf-8').includes(version);
Expand All @@ -11,6 +10,8 @@ const { execSync } = require('child_process');
};
// test sfdx is installed
if (testCliNotVersion('sfdx', 'sfdx-cli/7.')) {
throw Error('"[email protected]" has a bin alias for "sfdx", please uninstall sfdx-cli first. See https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_move_to_sf_v2.htm for more information');
throw Error(
'"[email protected]" has a bin alias for "sfdx", please uninstall sfdx-cli first. See https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_move_to_sf_v2.htm for more information'
);
}
})();
Loading

0 comments on commit 858bab3

Please sign in to comment.