Skip to content

Commit

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

* chore: building

* test: fix UTs

* chore: merge main, resolve conflicts

* test: replace __filename

* test: fixing NUTs, not running

* chore: bump testkit, use 'dev' cli

* test: fix deb NUTs

* test: set bin to sfdx for SourceTestkit to get correct deploy

* chore: try ts-node --esm

* chore: try node --loader ts-node/esm

* test: fix --source-dir for force:source:deploy

* chore: merge main, resolve conflicts

* chore: fix archiver import

* chore: fix __filename

* chore: actually fix archiver import

* chore: fix DEB NUTs

* chore: try new yarn.lock, all NUTs passed locally

* chore: remove lintstagedrc

* chore: updates

* test: copy type from PDR

* test: remote initProgressBar spy

* test(nuts): use sf for testkit.convert

* chore: remove unused devDeps

* test(nuts): use sf for manifest creation

* test(nuts): use sf

* test(nuts): fix nuts

---------

Co-authored-by: Cristian Dominguez <[email protected]>
  • Loading branch information
WillieRuemmele and cristiand391 authored Nov 24, 2023
1 parent 6e3c762 commit fc3403e
Show file tree
Hide file tree
Showing 113 changed files with 2,770 additions and 2,497 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 @@ -45,3 +45,5 @@ node_modules

# ignore generated nut tests
test/nuts/generated/

oclif.lock
3 changes: 0 additions & 3 deletions .lintstagedrc.js

This file was deleted.

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", "test"],
"watch-files": [
"src",
"test"
],
"recursive": true,
"reporter": "spec",
"timeout": 10000
}
"timeout": 10000,
"node-option": [
"loader=ts-node/esm"
]
}
21 changes: 0 additions & 21 deletions bin/dev

This file was deleted.

3 changes: 1 addition & 2 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@@ -0,0 +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()
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.
73 changes: 40 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "@salesforce/plugin-source",
"description": "Commands to interact with source formatted metadata",
"version": "2.11.4",
"version": "3.0.0",
"author": "Salesforce",
"main": "lib/index.js",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^3.11.0",
Expand All @@ -13,47 +12,48 @@
"@salesforce/sf-plugins-core": "^5.0.1",
"@salesforce/source-deploy-retrieve": "^10.0.0",
"@salesforce/source-tracking": "^5.0.0",
"chalk": "^4.1.2",
"got": "^11.8.6",
"proxy-agent": "^6.3.1",
"tslib": "^2"
"chalk": "^5.3.0",
"got": "^13.0.0",
"proxy-agent": "^6.3.1"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.16",
"@oclif/plugin-help": "^5.2.20",
"@oclif/plugin-command-snapshot": "^5.0.1",
"@oclif/plugin-help": "^6.0.5",
"@salesforce/cli-plugins-testkit": "^5.0.2",
"@salesforce/dev-scripts": "^7.1.1",
"@salesforce/plugin-command-reference": "^3.0.46",
"@salesforce/plugin-deploy-retrieve": "^2.1.2",
"@salesforce/plugin-info": "^2.6.51",
"@salesforce/source-testkit": "^2.1.65",
"@salesforce/plugin-info": "^2.6.50",
"@salesforce/source-testkit": "^2.1.62",
"@salesforce/ts-sinon": "1.4.19",
"@swc/core": "1.3.96",
"@types/archiver": "^5.3.2",
"archiver": "^5.3.2",
"chai-each": "^0.0.1",
"cross-env": "^7.0.3",
"eslint-plugin-sf-plugin": "^1.16.15",
"oclif": "^3.16.0",
"fast-glob": "^3.3.1",
"oclif": "^4.0.3",
"shx": "0.3.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.2.2"
},
"config": {},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
"/messages",
"/oclif.manifest.json"
"/oclif.manifest.json",
"/oclif.lock"
],
"homepage": "https://github.com/salesforcecli/plugin-source",
"keywords": [
"force",
"salesforce",
"sfdx",
"salesforcedx",
"sf",
"sf-plugin",
"sfdx",
"sfdx-plugin"
],
"license": "BSD-3-Clause",
Expand All @@ -64,7 +64,10 @@
"@oclif/plugin-command-snapshot",
"@oclif/plugin-help",
"@salesforce/plugin-command-reference",
"@salesforce/plugin-deploy-retrieve"
"@salesforce/plugin-deploy-retrieve",
"@salesforce/plugin-templates",
"@salesforce/plugin-settings",
"@salesforce/plugin-user"
],
"topics": {
"force": {
Expand Down Expand Up @@ -95,7 +98,9 @@
},
"hooks": {
"sf-doctor-@salesforce/plugin-source": "./lib/hooks/diagnostics"
}
},
"flexibleTaxonomy": true,
"topicSeparator": " "
},
"repository": "salesforcecli/plugin-source",
"scripts": {
Expand All @@ -111,20 +116,20 @@
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
"test:nuts": "ts-node ./test/nuts/generateNuts.ts && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0",
"test:nuts": "node --loader ts-node/esm ./test/nuts/generateNuts.ts && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0",
"test:nuts:deb": "mocha \"test/nuts/digitalExperienceBundle/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy PLUGIN_SOURCE_SEED_EXCLUDE=async ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:async": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.async ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy PLUGIN_SOURCE_SEED_EXCLUDE=async node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:async": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.async node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:destructive": "mocha \"test/nuts/deployDestructive.nut.ts\" --slow 3000 --timeout 1200000 --retries 0 --jobs 20",
"test:nuts:deploy:manifest": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.manifest ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:metadata": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.metadata ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:quick": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.quick ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:manifest": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.manifest node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:metadata": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.metadata node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:quick": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.quick node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:rest": "mocha \"test/nuts/REST/*.nut.ts\" --slow 3000 --timeout 1200000 --retries 0 --parallel --jobs 20",
"test:nuts:deploy:sourcepath": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.sourcepath ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:testlevel": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.testlevel ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:sourcepath": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.sourcepath node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:testlevel": "cross-env PLUGIN_SOURCE_SEED_FILTER=deploy.testlevel node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:mdapi": "mocha \"test/nuts/mdapi.nut.ts\" --slow 3000 --timeout 1200000 --retries 0 --jobs 20",
"test:nuts:retrieve": "cross-env PLUGIN_SOURCE_SEED_FILTER=retrieve ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:retrieve:metadata": "cross-env PLUGIN_SOURCE_SEED_FILTER=retrieve.metadata ts-node ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:retrieve": "cross-env PLUGIN_SOURCE_SEED_FILTER=retrieve node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:retrieve:metadata": "cross-env PLUGIN_SOURCE_SEED_FILTER=retrieve.metadata node --loader ts-node/esm ./test/nuts/generateNuts.ts && mocha \"test/nuts/generated/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:specialTypes": "mocha \"test/nuts/territory2.nut.ts\" \"test/nuts/folderTypes.nut.ts\" \"test/nuts/translation.nut.ts\" \"test/nuts/nestedLwc.nut.ts\" \"test/nuts/partialBundleDelete.nut.ts\" --slow 4500 --timeout 1200000 --retries 0 --parallel --jobs 20",
"test:nuts:specialTypes:folders": "mocha \"test/nuts/folderTypes.nut.ts\" --slow 4500 --timeout 1200000 --jobs 20",
"test:nuts:specialTypes:nestedLwc": "mocha \"test/nuts/nestedLwc.nut.ts\" --slow 3000 --timeout 1200000 --retries 0 --jobs 20 ",
Expand Down Expand Up @@ -221,7 +226,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 @@ -232,7 +237,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -242,12 +247,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"
}
48 changes: 27 additions & 21 deletions schemas/force-source-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@
"type": "object",
"properties": {
"state": {
"type": "string",
"enum": [
"Local Deleted",
"Local Add",
"Local Changed",
"Local Unchanged",
"Remote Deleted",
"Remote Add",
"Remote Changed",
"Remote Unchanged",
"Local Deleted (Conflict)",
"Local Add (Conflict)",
"Local Changed (Conflict)",
"Local Unchanged (Conflict)",
"Remote Deleted (Conflict)",
"Remote Add (Conflict)",
"Remote Changed (Conflict)",
"Remote Unchanged (Conflict)"
]
"$ref": "#/definitions/StatusStateString"
},
"fullName": {
"type": "string"
Expand All @@ -52,12 +34,36 @@
"enum": ["Deleted", "Add", "Changed", "Unchanged"]
},
"origin": {
"type": "string",
"enum": ["Local", "Remote"]
"$ref": "#/definitions/StatusOrigin"
}
},
"required": ["state", "fullName", "type", "origin"],
"additionalProperties": false
},
"StatusStateString": {
"type": "string",
"enum": [
"Local Deleted",
"Local Add",
"Local Changed",
"Local Unchanged",
"Remote Deleted",
"Remote Add",
"Remote Changed",
"Remote Unchanged",
"Local Deleted (Conflict)",
"Local Add (Conflict)",
"Local Changed (Conflict)",
"Local Unchanged (Conflict)",
"Remote Deleted (Conflict)",
"Remote Add (Conflict)",
"Remote Changed (Conflict)",
"Remote Unchanged (Conflict)"
]
},
"StatusOrigin": {
"type": "string",
"enum": ["Local", "Remote"]
}
}
}
32 changes: 17 additions & 15 deletions src/commands/force/mdapi/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* 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 { Duration, env } from '@salesforce/kit';
import { Lifecycle, Messages, Org } from '@salesforce/core';
import { DeployVersionData, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { AsyncResult, DeployVersionData, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import {
arrayWithDeprecation,
Flags,
Expand All @@ -21,16 +23,16 @@ import {
reportsFormatters,
targetUsernameFlag,
TestLevel,
} from '../../../deployCommand';
import { DeployCommandAsyncResult } from '../../../formatters/source/deployAsyncResultFormatter';
import { MdDeployResult, MdDeployResultFormatter } from '../../../formatters/mdapi/mdDeployResultFormatter';
import { ProgressFormatter } from '../../../formatters/progressFormatter';
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter';
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter';
import { MdDeployAsyncResultFormatter } from '../../../formatters/mdapi/mdDeployAsyncResultFormatter';
import { ResultFormatterOptions } from '../../../formatters/resultFormatter';
} from '../../../deployCommand.js';
import { DeployCommandAsyncResult } from '../../../formatters/source/deployAsyncResultFormatter.js';
import { MdDeployResult, MdDeployResultFormatter } from '../../../formatters/mdapi/mdDeployResultFormatter.js';
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
import { MdDeployAsyncResultFormatter } from '../../../formatters/mdapi/mdDeployAsyncResultFormatter.js';
import { ResultFormatterOptions } from '../../../formatters/resultFormatter.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-source', 'md.deploy');
const deployMessages = Messages.loadMessages('@salesforce/plugin-source', 'deployCommand');

Expand Down Expand Up @@ -135,8 +137,8 @@ export class Deploy extends DeployCommand {
junit: Flags.boolean({ summary: messages.getMessage('flags.junit.summary') }),
};

private flags: Interfaces.InferredFlags<typeof Deploy.flags>;
private org: Org;
private flags!: Interfaces.InferredFlags<typeof Deploy.flags>;
private org!: Org;

public async run(): Promise<DeployResult> {
this.flags = (await this.parse(Deploy)).flags;
Expand Down Expand Up @@ -165,7 +167,7 @@ export class Deploy extends DeployCommand {
const deploymentOptions = this.flags.zipfile
? { zipPath: this.flags.zipfile }
: { mdapiPath: this.flags.deploydir };
const username = this.org.getUsername();
const username = this.org.getUsername() as string;

// still here? we need to deploy a zip file then
const deploy = new MetadataApiDeploy({
Expand Down Expand Up @@ -198,7 +200,7 @@ export class Deploy extends DeployCommand {
this.log(deployMessages.getMessage('apiVersionMsgBasic', [username, apiData.apiVersion, apiData.webService]));
});
await deploy.start();
this.asyncDeployResult = { id: deploy.id };
this.asyncDeployResult = deploy.id ? { id: deploy.id } : undefined;
this.updateDeployId(deploy.id);

if (!this.isAsync) {
Expand Down Expand Up @@ -235,7 +237,7 @@ export class Deploy extends DeployCommand {
? new MdDeployAsyncResultFormatter(
new Ux({ jsonEnabled: this.jsonEnabled() }),
formatterOptions,
this.asyncDeployResult
this.asyncDeployResult as AsyncResult
)
: new MdDeployResultFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }), formatterOptions, this.deployResult);

Expand Down
Loading

0 comments on commit fc3403e

Please sign in to comment.