Skip to content

Commit

Permalink
feat!: migrate to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Oct 31, 2023
1 parent 4bf95e9 commit 65b0486
Show file tree
Hide file tree
Showing 32 changed files with 2,294 additions and 1,717 deletions.
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
File renamed without changes.
16 changes: 12 additions & 4 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"require": "ts-node/register,source-map-support/register",
"require": [
"ts-node/register"
],
"watch-extensions": "ts",
"watch-files": ["src/**/*.ts", "test/**/*.ts"],
"watch-files": [
"src/**/*.ts",
"test/**/*.ts"
],
"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.

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.
69 changes: 25 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,54 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.9.2",
"@salesforce/core": "^5.3.9",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^3.1.22",
"@salesforce/sf-plugins-core": "^4.0.0",
"change-case": "^4.1.2",
"fast-glob": "^3.3.1",
"fast-xml-parser": "^4.3.2",
"inquirer": "^8.2.6",
"js2xmlparser": "^4.0.2",
"tslib": "^2"
"inquirer": "^9.2.11",
"js2xmlparser": "^4.0.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.14",
"@oclif/test": "^2.5.6",
"@salesforce/cli-plugins-testkit": "^4.4.10",
"@salesforce/dev-config": "^4.0.1",
"@salesforce/dev-scripts": "^5.12.2",
"@oclif/plugin-command-snapshot": "^5.0.1",
"@oclif/test": "^3.0.4",
"@salesforce/cli-plugins-testkit": "^5.0.0-dev.1",
"@salesforce/dev-scripts": "^6.0.3",
"@salesforce/plugin-command-reference": "^3.0.44",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "1.4.18",
"@swc/core": "^1.3.37",
"@types/inquirer": "^8.2.0",
"@types/shelljs": "^0.8.13",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.61.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.12",
"husky": "^7.0.4",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"oclif": "^3.17.1",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"oclif": "^4.0.3",
"shelljs": "^0.8.4",
"shx": "0.3.4",
"sinon": "10.0.0",
"ts-node": "^10.9.1",
"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",
"/schemas"
"/schemas",
"/oclif.lock"
],
"homepage": "https://github.com/salesforcecli/plugin-sobject",
"keywords": [
"force",
"salesforce",
"sfdx",
"salesforcedx",
"sfdx-plugin",
"sf",
"sf-plugin",
"sf"
"sfdx",
"sfdx-plugin"
],
"license": "BSD-3-Clause",
"main": "lib/index.js",
"oclif": {
"commands": "./lib/commands",
"bin": "sf",
Expand All @@ -94,14 +72,15 @@
}
}
}
}
},
"flexibleTaxonomy": true
},
"repository": "salesforcecli/plugin-sobject",
"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",
Expand Down Expand Up @@ -193,7 +172,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 @@ -204,7 +183,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -214,12 +193,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"
}
15 changes: 8 additions & 7 deletions src/commands/schema/generate/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
* 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 * as fs from 'node:fs';
import * as path from 'node:path';
import fs from 'node:fs';
import path, {dirname} from 'node:path';
import { fileURLToPath } from 'node:url';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import { CustomField } from 'jsforce/api/metadata';
import { convertJsonToXml } from '../../../shared/convert';
import { convertJsonToXml } from '../../../shared/convert.js';
import {
descriptionPrompt,
apiNamePrompt,
objectPrompt,
integerValidation,
picklistPrompts,
} from '../../../shared/prompts/prompts';
import { relationshipFieldPrompts } from '../../../shared/prompts/relationshipField';
import { isObjectsFolder, labelValidation } from '../../../shared/flags';
} from '../../../shared/prompts/prompts.js';
import { relationshipFieldPrompts } from '../../../shared/prompts/relationshipField.js';
import { isObjectsFolder, labelValidation } from '../../../shared/flags.js';

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

const MAX_LONG_TEXT_LENGTH = 131072;
Expand Down
12 changes: 7 additions & 5 deletions src/commands/schema/generate/platformevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
* 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 } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import { apiNamePrompt, descriptionPrompt, directoryPrompt, pluralPrompt } from '../../../shared/prompts/prompts';
import { writeObjectFile } from '../../../shared/fs';
import { SaveablePlatformEvent } from '../../../shared/types';
import { labelValidation } from '../../../shared/flags';
import { apiNamePrompt, descriptionPrompt, directoryPrompt, pluralPrompt } from '../../../shared/prompts/prompts.js';
import { writeObjectFile } from '../../../shared/fs.js';
import { SaveablePlatformEvent } from '../../../shared/types.js';
import { labelValidation } from '../../../shared/flags.js';

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

export type PlatformEventGenerateResult = {
Expand Down
11 changes: 6 additions & 5 deletions src/commands/schema/generate/sobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 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, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
Expand All @@ -15,12 +16,12 @@ import {
pluralPrompt,
apiNamePrompt,
namePrompts,
} from '../../../shared/prompts/prompts';
import { writeObjectFile } from '../../../shared/fs';
import { SaveableCustomObject, NameFieldResponse } from '../../../shared/types';
import { labelValidation } from '../../../shared/flags';
} from '../../../shared/prompts/prompts.js';
import { writeObjectFile } from '../../../shared/fs.js';
import { SaveableCustomObject, NameFieldResponse } from '../../../shared/types.js';
import { labelValidation } from '../../../shared/flags.js';

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

export type CustomObjectGenerateResult = {
Expand Down
11 changes: 6 additions & 5 deletions src/commands/schema/generate/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as fs from 'node:fs';
import * as path from 'node:path';
import fs from 'node:fs';
import path, {dirname} from 'node:path';
import {fileURLToPath} from 'node:url';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { CustomTab } from 'jsforce/api/metadata';
import { isTabsFolder } from '../../../shared/flags';
import { convertJsonToXml } from '../../../shared/convert';
import { isTabsFolder } from '../../../shared/flags.js';
import { convertJsonToXml } from '../../../shared/convert.js';

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

export type GenerateTabResult = {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

export = {};
export default {};
2 changes: 1 addition & 1 deletion src/shared/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as jsToXml from 'js2xmlparser';
import { XMLParser } from 'fast-xml-parser';
import { IOptions } from 'js2xmlparser/lib/options';
import { IOptions } from 'js2xmlparser/lib/options.js';
import { CustomObject, CustomField } from 'jsforce/api/metadata';
import { JsonMap } from '@salesforce/ts-types';

Expand Down
6 changes: 4 additions & 2 deletions src/shared/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { sep, resolve } from 'node:path';
import {sep, resolve, dirname} from 'node:path';
import { fileURLToPath } from 'node:url';
import { Messages, SfError } from '@salesforce/core';

Messages.importMessagesDirectory(__dirname);

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

// eslint-disable-next-line @typescript-eslint/require-await
Expand Down
10 changes: 5 additions & 5 deletions src/shared/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* 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 * as path from 'node:path';
import * as fs from 'node:fs';
import * as fg from 'fast-glob';
import path from 'node:path';
import fs from 'node:fs';
import fg from 'fast-glob';
import { CustomObject } from 'jsforce/api/metadata';
import { convertJsonToXml, parseXml } from './convert';
import { SaveableCustomObject, SaveablePlatformEvent } from './types';
import { convertJsonToXml, parseXml } from './convert.js';
import { SaveableCustomObject, SaveablePlatformEvent } from './types.js';

const getObjectXmlByPathAsJson = async (objectFilePath: string): Promise<CustomObject> => {
const xml = await fs.promises.readFile(objectFilePath, 'utf8');
Expand Down
8 changes: 5 additions & 3 deletions src/shared/prompts/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* 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 { NamedPackageDir } from '@salesforce/core';
import { prompt, Question, ListQuestion } from 'inquirer';
import { ValueSet, CustomValue } from 'jsforce/api/metadata';
import { Messages } from '@salesforce/core';
import { getDirectoriesThatContainObjects, getObjectDirectories } from '../fs';
import {ListQuestion, prompt, Question} from 'inquirer';
import { getDirectoriesThatContainObjects, getObjectDirectories } from '../fs.js';

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

export const makeNameApiCompatible = (input: string): string =>
Expand Down
Loading

0 comments on commit 65b0486

Please sign in to comment.