Skip to content

Commit

Permalink
feat!: migrate to ESM (#651)
Browse files Browse the repository at this point in the history
* feat!: migrate to ESM

BREAKING CHANGES: ESM and node 18 minimum

* chore: dep cleanup

* refactor: drop ts-types

* style: typos

* fix: remove unspecified kit dependency

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
mdonnalley and mshanemc authored Nov 14, 2023
1 parent 5c331a5 commit a406c7a
Show file tree
Hide file tree
Showing 33 changed files with 321 additions and 393 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cjs/
5 changes: 3 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"require": ["test/helpers/init.js", "ts-node/register", "source-map-support/register"],
"require": ["ts-node/register"],
"recursive": true,
"watch-extensions": ["ts"],
"watch-files": ["src/**/*.ts", "test/**/*.ts"],
"timeout": 5000
"timeout": 5000,
"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();
5 changes: 0 additions & 5 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.
49 changes: 26 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/plugin-custom-metadata",
"description": "Tools for working with custom metadata types and their records.",
"version": "2.2.13",
"version": "3.0.0",
"contributors": [
{
"name": "Carolyn Grabill",
Expand Down Expand Up @@ -42,30 +42,26 @@
],
"bugs": "https://github.com/salesforcecli/plugin-custom-metadata/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.11.0",
"@salesforce/core": "^5.3.20",
"@salesforce/sf-plugins-core": "^3.1.22",
"@salesforce/ts-types": "^2.0.6",
"@salesforce/sf-plugins-core": "^4.1.2",
"csv-parse": "^5.5.2",
"fast-xml-parser": "^4.3.2",
"tslib": "^2"
"fast-xml-parser": "^4.3.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.16",
"@salesforce/cli-plugins-testkit": "^4.4.12",
"@salesforce/dev-scripts": "^6.0.3",
"@oclif/plugin-command-snapshot": "^5.0.2",
"@salesforce/cli-plugins-testkit": "^5.0.4",
"@salesforce/dev-scripts": "^6.0.4",
"@salesforce/plugin-command-reference": "^3.0.46",
"@salesforce/ts-sinon": "^1.4.19",
"@swc/core": "^1.3.37",
"eslint-plugin-sf-plugin": "^1.16.14",
"jsforce": "^2.0.0-beta.22",
"oclif": "^3.17.2",
"eslint-plugin-sf-plugin": "^1.16.15",
"jsforce": "^2.0.0-beta.28",
"oclif": "^4.0.3",
"shx": "0.2.2",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
Expand All @@ -76,12 +72,14 @@
],
"homepage": "https://github.com/salesforcecli/plugin-custom-metadata",
"keywords": [
"sf",
"sf-plugin",
"sfdx-plugin"
],
"license": "BSD-3-Clause",
"oclif": {
"commands": "./lib/commands",
"bin": "sfdx",
"bin": "sf",
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-command-snapshot",
Expand All @@ -99,19 +97,21 @@
}
}
}
}
},
"flexibleTaxonomy": true,
"topicSeparator": " "
},
"repository": "github:salesforcecli/plugin-custom-metadata",
"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",
Expand Down Expand Up @@ -199,7 +199,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 @@ -210,7 +210,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -220,12 +220,15 @@
]
},
"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",
"author": "Salesforce"
}
12 changes: 7 additions & 5 deletions src/commands/cmdt/generate/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
* 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 fs from 'node:fs';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { arrayWithDeprecation, Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages, SfError } from '@salesforce/core';
import { writeFieldFile } from '../../../shared/helpers/fileWriter';
import { validateAPIName } from '../../../shared/helpers/validationUtil';
import { createDefaultTypeStructure, createFieldXML } from '../../../shared/templates/templates';
import { writeFieldFile } from '../../../shared/helpers/fileWriter.js';
import { validateAPIName } from '../../../shared/helpers/validationUtil.js';
import { createDefaultTypeStructure, createFieldXML } from '../../../shared/templates/templates.js';

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

export interface CmdtFieldCreateResponse {
Expand Down
20 changes: 10 additions & 10 deletions src/commands/cmdt/generate/fromorg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* 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 from 'node:path';
import { fileURLToPath } from 'node:url';
import {
Flags,
loglevel,
Expand All @@ -14,19 +15,18 @@ import {
SfCommand,
} from '@salesforce/sf-plugins-core';
import { SfError, Messages } from '@salesforce/core';
import { isEmpty } from '@salesforce/kit';
import { CustomField, CustomObject } from 'jsforce/api/metadata';
import { createRecord, getFileData } from '../../../shared/helpers/createUtil';
import { writeTypeFile, writeFieldFile } from '../../../shared/helpers/fileWriter';
import { describeObjFields, cleanQueryResponse, validCustomSettingType } from '../../../shared/helpers/metadataUtil';
import { createRecord, getFileData } from '../../../shared/helpers/createUtil.js';
import { writeTypeFile, writeFieldFile } from '../../../shared/helpers/fileWriter.js';
import { describeObjFields, cleanQueryResponse, validCustomSettingType } from '../../../shared/helpers/metadataUtil.js';
import {
validateAPIName,
validateMetadataTypeName,
isValidMetadataRecordName,
} from '../../../shared/helpers/validationUtil';
import { canConvert, createObjectXML, createFieldXML } from '../../../shared/templates/templates';
} from '../../../shared/helpers/validationUtil.js';
import { canConvert, createObjectXML, createFieldXML } from '../../../shared/templates/templates.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(path.dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-custom-metadata', 'fromorg');

export interface CmdtGenerateResponse {
Expand Down Expand Up @@ -103,7 +103,7 @@ export default class Generate extends SfCommand<CmdtGenerateResponse> {
const describeObj = await conn.metadata.read('CustomObject', flags.sobject);

// throw error if the object doesnot exist(empty json as response from the describe call.)
if (isEmpty(describeObj.fields)) {
if (describeObj.fields.length === 0) {
const errMsg = messages.getMessage('sobjectnameNoResultError', [flags.sobject]);
throw new SfError(errMsg, 'sobjectnameNoResultError');
}
Expand Down
12 changes: 7 additions & 5 deletions src/commands/cmdt/generate/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
* 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 fs from 'node:fs';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { writeTypeFile } from '../../../shared/helpers/fileWriter';
import { validateMetadataTypeName, validateLessThanForty } from '../../../shared/helpers/validationUtil';
import { createObjectXML } from '../../../shared/templates/templates';
import { writeTypeFile } from '../../../shared/helpers/fileWriter.js';
import { validateMetadataTypeName, validateLessThanForty } from '../../../shared/helpers/validationUtil.js';
import { createObjectXML } from '../../../shared/templates/templates.js';

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

export interface CmdtCreateResponse {
Expand Down
11 changes: 6 additions & 5 deletions src/commands/cmdt/generate/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
* 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 from 'node:path';
import { fileURLToPath } from 'node:url';
import { Flags, loglevel, parseVarArgs, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { CustomField } from 'jsforce/api/metadata';
import { appendDirectorySuffix, createRecord, getFileData } from '../../../shared/helpers/createUtil';
import { appendDirectorySuffix, createRecord, getFileData } from '../../../shared/helpers/createUtil.js';
import {
validateMetadataRecordName,
validateMetadataTypeName,
validateLessThanForty,
} from '../../../shared/helpers/validationUtil';
} from '../../../shared/helpers/validationUtil.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(path.dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-custom-metadata', 'record');

export interface CmdtRecordCreateResponse {
Expand Down
11 changes: 6 additions & 5 deletions src/commands/cmdt/generate/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
* 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 from 'node:path';
import { fileURLToPath } from 'node:url';
import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages, SfError } from '@salesforce/core';
import { Record } from 'jsforce';
import { parse } from 'csv-parse/sync';
import { getFieldNames, appendDirectorySuffix, createRecord, getFileData } from '../../../shared/helpers/createUtil';
import { CreateConfig, CreateConfigs } from '../../../shared/interfaces/createConfig';
import { getFieldNames, appendDirectorySuffix, createRecord, getFileData } from '../../../shared/helpers/createUtil.js';
import { CreateConfig, CreateConfigs } from '../../../shared/interfaces/createConfig.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(path.dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-custom-metadata', 'records');

export default class Insert extends SfCommand<CreateConfigs> {
Expand Down
15 changes: 7 additions & 8 deletions src/shared/helpers/createUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +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 fs from 'node:fs';
import * as path from 'node:path';
import fs from 'node:fs';
import path from 'node:path';
import { CustomField } from 'jsforce/api/metadata';
import { XMLParser } from 'fast-xml-parser';
import { isString } from '@salesforce/ts-types';
import { CreateConfig } from '../interfaces/createConfig';
import { canConvert } from '../templates/templates';
import { CreateConfig } from '../interfaces/createConfig.js';
import { canConvert } from '../templates/templates.js';

interface CustomFieldFile {
CustomField: CustomField;
Expand Down Expand Up @@ -110,15 +109,15 @@ export const appendDirectorySuffix = (typename: string): string =>
typename.endsWith('__mdt') ? typename : `${typename}__mdt`;

/**
* Goes through the file data that has been genreated and gets all of the field names and adds the
* Goes through the file data that has been generated and gets all of the field names and adds the
* name of the field that is used as the label for metadata record
*
* @param fileData Array of objects based on metadata type xml
* @param nameField name of the column that is going to be used for the name of the metadata record
* @return [] Array of field names
*/
export const getFieldNames = (fileData: CustomField[], nameField: string): string[] => [
...fileData.map((file) => file.fullName).filter(isString),
...fileData.map((file) => file.fullName).filter((f): f is string => typeof f === 'string'),
nameField,
];

Expand All @@ -139,7 +138,7 @@ const buildCustomFieldXml = (
for (const fieldName of Object.keys(cliParams)) {
const type = getFieldPrimitiveType(fileData, fieldName);
const dataType = getFieldDataType(fileData, fieldName);
// Added functionality to handle the igonre fields scenario.
// Added functionality to handle the ignore fields scenario.
if (canConvert(dataType) || !ignoreFields) {
ret += getFieldTemplate(fieldName, cliParams[fieldName], type);
}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/helpers/fileWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 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 from 'node:path';

interface FileWriterResult {
dir: string;
Expand Down
Loading

0 comments on commit a406c7a

Please sign in to comment.