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

Merged
merged 24 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ node_modules
.idea

oclif.manifest.json

oclif.lock
Copy link
Contributor

Choose a reason for hiding this comment

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

multiple oclif.locks here


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": 10000,
"exclude": "node_modules/**/*"
"exclude": "node_modules/**/*",
"node-option": ["loader=ts-node/esm"]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ yarn install
yarn build
```

To use your plugin, run using the local `./bin/dev` or `./bin/dev.cmd` file.
To use your plugin, run using the local `./bin/dev.js` or `./bin/dev.cmd` file.

```bash
# Run using local run file.
Expand Down
21 changes: 0 additions & 21 deletions bin/dev

This file was deleted.

4 changes: 2 additions & 2 deletions bin/dev.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
set NODE_ENV=development
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.
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.9.0",
"@salesforce/core": "^5.3.14",
"@salesforce/sf-plugins-core": "^3.1.25",
"fast-levenshtein": "^3.0.0",
"tslib": "^2"
"@salesforce/sf-plugins-core": "^4.0.0",
"fast-levenshtein": "^3.0.0"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.14",
"@oclif/test": "^2.5.6",
"@salesforce/cli-plugins-testkit": "^4.4.7",
"@oclif/plugin-command-snapshot": "^5.0.1",
"@oclif/test": "^3.0.3",
"@salesforce/cli-plugins-testkit": "^5.0.0-dev.1",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/dev-scripts": "^5.12.2",
"@salesforce/kit": "^3.0.11",
Expand All @@ -23,7 +22,6 @@
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "^1.4.17",
"@salesforce/ts-types": "^2.0.9",
"@swc/core": "^1.3.27",
"@types/fast-levenshtein": "^0.0.3",
"@types/fs-extra": "^9.0.13",
"@types/shelljs": "^0.8.14",
Expand All @@ -43,7 +41,7 @@
"husky": "^7.0.4",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"oclif": "^3.17.2",
"oclif": "^4.0.3",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"shelljs": "^0.8.5",
Expand All @@ -55,13 +53,15 @@
},
"config": {},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
"/messages",
"/oclif.manifest.json",
"/schemas"
"/schemas",
"/oclif.lock",
"/oclif.lock"
Copy link
Contributor

Choose a reason for hiding this comment

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

multiple oclif.locks

],
"homepage": "https://github.com/salesforcecli/plugin-settings",
"keywords": [
Expand All @@ -74,7 +74,6 @@
"sf"
],
"license": "BSD-3-Clause",
"main": "lib/index.js",
"oclif": {
"commands": "./lib/commands",
"bin": "sf",
Expand All @@ -97,7 +96,8 @@
"alias": {
"description": "Use the alias commands to manage your aliases."
}
}
},
"flexibleTaxonomy": true
},
"repository": "salesforcecli/plugin-settings",
"scripts": {
Expand Down Expand Up @@ -198,7 +198,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 @@ -209,7 +209,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -219,12 +219,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/alias/list.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 { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { StateAggregator, Messages } from '@salesforce/core';
import { loglevel } from '@salesforce/sf-plugins-core';
import { AliasCommand, AliasResults } from '../../alias';
import { AliasCommand, AliasResults } from '../../alias.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'alias.list');
export default class AliasList extends AliasCommand<AliasResults> {
public static summary = messages.getMessage('summary');
Expand Down
6 changes: 4 additions & 2 deletions src/commands/alias/set.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 { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { loglevel, parseVarArgs } from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages } from '@salesforce/core';
import { AliasCommand, AliasResults } from '../../alias';
import { AliasCommand, AliasResults } from '../../alias.js';

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

export default class AliasSet extends AliasCommand<AliasResults> {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/alias/unset.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 { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages } from '@salesforce/core';
import { AliasCommand, AliasResults } from '../../alias';
import { AliasCommand, AliasResults } from '../../alias.js';

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

export default class AliasUnset extends AliasCommand<AliasResults> {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/config/get.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 { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigAggregator, Messages } from '@salesforce/core';
import {
Expand All @@ -13,9 +15,9 @@ import {
buildSuccessMsg,
output,
ConfigResponses,
} from '../../config';
} from '../../config.js';

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

export class Get extends SfCommand<ConfigResponses> {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/config/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* 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 { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { ConfigAggregator, Messages } from '@salesforce/core';
import { loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigResponses, buildSuccessMsg, output } from '../../config';
import { ConfigResponses, buildSuccessMsg, output } from '../../config.js';

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

export default class List extends SfCommand<ConfigResponses> {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
* 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 { parseVarArgs, Flags, loglevel, Ux, SfCommand } from '@salesforce/sf-plugins-core';
import { Config, Messages, Org, SfError, OrgConfigProperties } from '@salesforce/core';
import { CONFIG_HELP_SECTION, Msg, buildFailureMsg, calculateSuggestion, output } from '../../config';
import { HelpSection } from '@oclif/core';
import { CONFIG_HELP_SECTION, Msg, buildFailureMsg, calculateSuggestion, output } from '../../config.js';

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

export type SetOrUnsetConfigCommandResult = { successes: Msg[]; failures: Msg[] };
Expand All @@ -29,7 +32,7 @@ export class Set extends SfCommand<SetOrUnsetConfigCommandResult> {
}),
};

public static configurationVariablesSection = CONFIG_HELP_SECTION;
public static configurationVariablesSection: HelpSection = CONFIG_HELP_SECTION;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? I removed it locally and typescript didn't mind


public async run(): Promise<SetOrUnsetConfigCommandResult> {
const { args, argv, flags } = await this.parse(Set);
Expand Down
8 changes: 5 additions & 3 deletions src/commands/config/unset.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 { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Config, Messages } from '@salesforce/core';
import { CONFIG_HELP_SECTION, buildFailureMsg, calculateSuggestion, output } from '../../config';
import { SetOrUnsetConfigCommandResult } from './set';
import { CONFIG_HELP_SECTION, buildFailureMsg, calculateSuggestion, output } from '../../config.js';
import { SetOrUnsetConfigCommandResult } from './set.js';

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

export class UnSet extends SfCommand<SetOrUnsetConfigCommandResult> {
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import { Ux } from '@salesforce/sf-plugins-core';
import { ConfigInfo, SfError, Config } from '@salesforce/core';
import { toHelpSection } from '@salesforce/sf-plugins-core';
import * as Levenshtein from 'fast-levenshtein';
import Levenshtein from 'fast-levenshtein';
import { isJsonMap } from '@salesforce/ts-types';
import { HelpSection } from '@oclif/core';

export type Msg = {
name: string;
Expand All @@ -27,7 +28,7 @@ export type Msg = {
};
export type ConfigResponses = Msg[];

export const CONFIG_HELP_SECTION = toHelpSection(
export const CONFIG_HELP_SECTION: HelpSection = toHelpSection(
'CONFIGURATION VARIABLES',
...new Set(Config.getAllowedProperties().map((k) => k.newKey ?? k.key))
);
Expand Down
Loading
Loading