Skip to content

Commit

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

* test: generated nuts vs. ts-node

* chore: __filename

* test: nut fixes for esm

* chore: dep bumps

* test: none of that experimental stuff

* chore: bump deps for testkit windows hangs
  • Loading branch information
mshanemc authored Nov 14, 2023
1 parent e20edc8 commit 2cd8cba
Show file tree
Hide file tree
Showing 118 changed files with 720 additions and 690 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 @@ -47,3 +47,5 @@ oclif.manifest.json

# ignore generated nut tests
test/nuts/generated/

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",
"watch-files": ["src", "test"],
"recursive": true,
"reporter": "spec",
"timeout": 10000
"timeout": 10000,
"node-option": ["loader=ts-node/esm"]
}
4 changes: 2 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
1. Build and lint the code: `yarn build`
1. Create a branch off main for new work: `git checkout -b <branch_name>` _Suggestion: use branch_name format of initials/work-title_. For external contributors, please fork the main branch of the repo instead and PR the fork to the main branch.
1. Make code changes and build: `yarn build`
1. Run changed commands: `./bin/dev project:deploy:start --help`
1. Run changed commands: `./bin/dev.js project:deploy:start --help`
1. Write tests and run: `yarn test` (unit) and/or `yarn test:nuts` (NUTs)
1. Show all changed files: `git status`
1. Add all files to staging: `git add .`
Expand Down Expand Up @@ -93,7 +93,7 @@ If there are conflict errors in the tests then we need to make a similar modific

## Running Commands

To run your modified plugin commands locally, use `./bin/dev` or `./bin/dev.cmd` file, which uses ts-node to execute the plugin's TypeScript commands.
To run your modified plugin commands locally, use `./bin/dev.js` or `./bin/dev.cmd` file, which uses ts-node to execute the plugin's TypeScript commands.

```bash
# Run using local dev file.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ 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.
./bin/dev deploy
./bin/dev.js deploy
```

There should be no differences when running via the Salesforce CLI or using the local run file. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.
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();
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.
70 changes: 36 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
{
"name": "@salesforce/plugin-deploy-retrieve",
"description": "deploy and retrieve commands for sf",
"version": "1.20.3",
"version": "2.0.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.11.0",
"@salesforce/apex-node": "^2.1.2",
"@salesforce/core": "^5.3.18",
"@salesforce/core": "^5.3.20",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^3.1.22",
"@salesforce/source-deploy-retrieve": "^9.8.4",
"@salesforce/source-tracking": "^4.3.0",
"chalk": "^4.1.2",
"tslib": "^2"
"@salesforce/sf-plugins-core": "^4.1.2",
"@salesforce/source-deploy-retrieve": "^9.8.6",
"@salesforce/source-tracking": "^4.4.3",
"chalk": "^5.3.0"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.16",
"@salesforce/cli-plugins-testkit": "^5.0.2",
"@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/plugin-source": "^2.11.0",
"@salesforce/source-testkit": "^2.1.62",
"@salesforce/ts-sinon": "1.4.19",
"@salesforce/ts-types": "^2.0.8",
"@swc/core": "1.3.39",
"@salesforce/plugin-source": "^2.11.3",
"@salesforce/source-testkit": "^2.1.65",
"@salesforce/ts-sinon": "^1.4.19",
"@salesforce/ts-types": "^2.0.9",
"cross-env": "^7.0.3",
"eslint-plugin-sf-plugin": "^1.16.14",
"oclif": "^3.16.0",
"eslint-plugin-sf-plugin": "^1.16.15",
"oclif": "^4.0.3",
"shx": "0.3.4",
"ts-node": "^10.9.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-deploy-retrieve",
"keywords": [
"force",
"salesforce",
"sfdx",
"sf",
"sf deploy",
"sf retrieve",
"sf deploy"
"sf-plugin",
"sfdx"
],
"license": "BSD-3-Clause",
"oclif": {
Expand Down Expand Up @@ -93,7 +93,8 @@
}
}
}
}
},
"flexibleTaxonomy": true
},
"repository": "salesforcecli/plugin-deploy-retrieve",
"scripts": {
Expand All @@ -109,16 +110,16 @@
"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 --jobs 10",
"test:nuts": "node --loader ts-node/esm ./test/nuts/generateNuts.ts && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 10",
"test:nuts:convert": "nyc mocha \"test/nuts/convert/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deb": "nyc mocha \"test/nuts/digitalExperienceBundle/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:delete": "nyc mocha \"test/nuts/delete/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy": "nyc mocha \"test/nuts/deploy/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:deploy:metadata:manifest": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.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:metadata": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.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:metadata:metadata-dir": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.metadata-dir 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:source-dir": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.source-dir 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:test-level": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.test-level 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:manifest": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.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:metadata": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.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:metadata:metadata-dir": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.metadata-dir 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:source-dir": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.source-dir 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:test-level": "cross-env PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER=deploy.metadata.test-level 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:destructive": "nyc mocha \"test/nuts/destructive/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:manifest": "nyc mocha \"test/nuts/manifest/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:retrieve": "nyc mocha \"test/nuts/retrieve/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
Expand All @@ -132,7 +133,6 @@
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"wireit": {
"build": {
"dependencies": [
Expand Down Expand Up @@ -209,7 +209,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 @@ -220,7 +220,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -230,12 +230,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"
}
25 changes: 14 additions & 11 deletions schemas/project-retrieve-start.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,7 @@
"type": "string"
},
"manageableState": {
"type": "string",
"enum": [
"beta",
"deleted",
"deprecated",
"deprecatedEditable",
"installed",
"installedEditable",
"released",
"unmanaged"
]
"$ref": "#/definitions/ManageableState"
},
"namespacePrefix": {
"type": "string"
Expand All @@ -187,6 +177,19 @@
],
"additionalProperties": false
},
"ManageableState": {
"type": "string",
"enum": [
"beta",
"deleted",
"deprecated",
"deprecatedEditable",
"installed",
"installedEditable",
"released",
"unmanaged"
]
},
"RequestStatus": {
"type": "string",
"enum": ["Pending", "InProgress", "Succeeded", "SucceededPartial", "Failed", "Canceling", "Canceled"]
Expand Down
7 changes: 5 additions & 2 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { EOL } from 'node:os';
import { writeFile, readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { exec } from 'node:child_process';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Hook } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Env, parseJsonMap } from '@salesforce/kit';
Expand All @@ -22,8 +24,9 @@ import {
SfHook,
Flags,
} from '@salesforce/sf-plugins-core';
import { DeployerResult } from '@salesforce/sf-plugins-core/lib/deployer';
Messages.importMessagesDirectory(__dirname);
import { DeployerResult } from '@salesforce/sf-plugins-core/lib/deployer.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));

const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy');

Expand Down
9 changes: 5 additions & 4 deletions src/commands/project/convert/mdapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { dirname, resolve } from 'node:path';
import * as fs from 'node:fs';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { Messages, SfError } from '@salesforce/core';
import {
ComponentSet,
Expand All @@ -22,10 +23,10 @@ import {
SfCommand,
} from '@salesforce/sf-plugins-core';
import { Interfaces } from '@oclif/core';
import { ConvertMdapiJson } from '../../../utils/types';
import { MetadataConvertResultFormatter } from '../../../formatters/metadataConvertResultFormatter';
import { ConvertMdapiJson } from '../../../utils/types.js';
import { MetadataConvertResultFormatter } from '../../../formatters/metadataConvertResultFormatter.js';

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'convert.mdapi');

export interface EnsureFsFlagOptions {
Expand Down
17 changes: 8 additions & 9 deletions src/commands/project/convert/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { resolve } from 'node:path';
import * as fs from 'node:fs';

import { resolve, dirname } from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { Messages } from '@salesforce/core';
import {
ComponentSet,
ComponentSetBuilder,
ConvertResult,
MetadataConverter,
} from '@salesforce/source-deploy-retrieve';
import { getString } from '@salesforce/ts-types';
import {
arrayWithDeprecation,
Flags,
Expand All @@ -24,11 +23,11 @@ import {
SfCommand,
} from '@salesforce/sf-plugins-core';
import { Interfaces } from '@oclif/core';
import { getPackageDirs, getSourceApiVersion } from '../../../utils/project';
import { SourceConvertResultFormatter } from '../../../formatters/sourceConvertResultFormatter';
import { ConvertResultJson } from '../../../utils/types';
import { getPackageDirs, getSourceApiVersion } from '../../../utils/project.js';
import { SourceConvertResultFormatter } from '../../../formatters/sourceConvertResultFormatter.js';
import { ConvertResultJson } from '../../../utils/types.js';

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

export class Source extends SfCommand<ConvertResultJson> {
Expand Down Expand Up @@ -153,7 +152,7 @@ export class Source extends SfCommand<ConvertResultJson> {
}

protected resolveSuccess(): void {
if (!getString(this.convertResult, 'packagePath')) {
if (!this.convertResult.packagePath) {
process.exitCode = 1;
}
}
Expand Down
Loading

0 comments on commit 2cd8cba

Please sign in to comment.