Skip to content

Commit 2cd8cba

Browse files
authored
feat!: esm (#811)
* 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
1 parent e20edc8 commit 2cd8cba

File tree

118 files changed

+720
-690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+720
-690
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.cjs/

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ oclif.manifest.json
4747

4848
# ignore generated nut tests
4949
test/nuts/generated/
50+
51+
oclif.lock

.lintstagedrc.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'**/*.{js,json,md}?(x)': () => 'npm run reformat',
3+
};

.lintstagedrc.js

-3
This file was deleted.

.mocharc.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"require": "ts-node/register,source-map-support/register",
2+
"require": ["ts-node/register"],
33
"watch-extensions": "ts",
44
"watch-files": ["src", "test"],
55
"recursive": true,
66
"reporter": "spec",
7-
"timeout": 10000
7+
"timeout": 10000,
8+
"node-option": ["loader=ts-node/esm"]
89
}

DEVELOPING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
1. Build and lint the code: `yarn build`
3030
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.
3131
1. Make code changes and build: `yarn build`
32-
1. Run changed commands: `./bin/dev project:deploy:start --help`
32+
1. Run changed commands: `./bin/dev.js project:deploy:start --help`
3333
1. Write tests and run: `yarn test` (unit) and/or `yarn test:nuts` (NUTs)
3434
1. Show all changed files: `git status`
3535
1. Add all files to staging: `git add .`
@@ -93,7 +93,7 @@ If there are conflict errors in the tests then we need to make a similar modific
9393

9494
## Running Commands
9595

96-
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.
96+
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.
9797

9898
```bash
9999
# Run using local dev file.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ yarn install
4444
yarn build
4545
```
4646

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

4949
```bash
5050
# Run using local run file.
51-
./bin/dev deploy
51+
./bin/dev.js deploy
5252
```
5353

5454
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.

bin/dev

-21
This file was deleted.

bin/dev.cmd

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@echo off
2-
set NODE_ENV=development
3-
node "%~dp0\dev" %*
2+
3+
node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*

bin/dev.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
2+
// eslint-disable-next-line node/shebang
3+
async function main() {
4+
const { execute } = await import('@oclif/core');
5+
await execute({ development: true, dir: import.meta.url });
6+
}
7+
8+
await main();

bin/run

-5
This file was deleted.

bin/run.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
3+
// eslint-disable-next-line node/shebang
4+
async function main() {
5+
const { execute } = await import('@oclif/core');
6+
await execute({ dir: import.meta.url });
7+
}
8+
9+
await main();
File renamed without changes.

package.json

+36-34
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
{
22
"name": "@salesforce/plugin-deploy-retrieve",
33
"description": "deploy and retrieve commands for sf",
4-
"version": "1.20.3",
4+
"version": "2.0.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
8-
"@oclif/core": "^2.15.0",
8+
"@oclif/core": "^3.11.0",
99
"@salesforce/apex-node": "^2.1.2",
10-
"@salesforce/core": "^5.3.18",
10+
"@salesforce/core": "^5.3.20",
1111
"@salesforce/kit": "^3.0.15",
12-
"@salesforce/sf-plugins-core": "^3.1.22",
13-
"@salesforce/source-deploy-retrieve": "^9.8.4",
14-
"@salesforce/source-tracking": "^4.3.0",
15-
"chalk": "^4.1.2",
16-
"tslib": "^2"
12+
"@salesforce/sf-plugins-core": "^4.1.2",
13+
"@salesforce/source-deploy-retrieve": "^9.8.6",
14+
"@salesforce/source-tracking": "^4.4.3",
15+
"chalk": "^5.3.0"
1716
},
1817
"devDependencies": {
19-
"@oclif/plugin-command-snapshot": "^4.0.16",
20-
"@salesforce/cli-plugins-testkit": "^5.0.2",
21-
"@salesforce/dev-scripts": "^6.0.3",
18+
"@oclif/plugin-command-snapshot": "^5.0.2",
19+
"@salesforce/cli-plugins-testkit": "^5.0.4",
20+
"@salesforce/dev-scripts": "^6.0.4",
2221
"@salesforce/plugin-command-reference": "^3.0.46",
23-
"@salesforce/plugin-source": "^2.11.0",
24-
"@salesforce/source-testkit": "^2.1.62",
25-
"@salesforce/ts-sinon": "1.4.19",
26-
"@salesforce/ts-types": "^2.0.8",
27-
"@swc/core": "1.3.39",
22+
"@salesforce/plugin-source": "^2.11.3",
23+
"@salesforce/source-testkit": "^2.1.65",
24+
"@salesforce/ts-sinon": "^1.4.19",
25+
"@salesforce/ts-types": "^2.0.9",
2826
"cross-env": "^7.0.3",
29-
"eslint-plugin-sf-plugin": "^1.16.14",
30-
"oclif": "^3.16.0",
27+
"eslint-plugin-sf-plugin": "^1.16.15",
28+
"oclif": "^4.0.3",
3129
"shx": "0.3.4",
3230
"ts-node": "^10.9.1",
3331
"typescript": "^5.2.2"
3432
},
3533
"config": {},
3634
"engines": {
37-
"node": ">=16.0.0"
35+
"node": ">=18.0.0"
3836
},
3937
"files": [
4038
"/lib",
4139
"/messages",
4240
"/oclif.manifest.json",
43-
"/schemas"
41+
"/schemas",
42+
"/oclif.lock"
4443
],
4544
"homepage": "https://github.com/salesforcecli/plugin-deploy-retrieve",
4645
"keywords": [
4746
"force",
4847
"salesforce",
49-
"sfdx",
5048
"sf",
49+
"sf deploy",
5150
"sf retrieve",
52-
"sf deploy"
51+
"sf-plugin",
52+
"sfdx"
5353
],
5454
"license": "BSD-3-Clause",
5555
"oclif": {
@@ -93,7 +93,8 @@
9393
}
9494
}
9595
}
96-
}
96+
},
97+
"flexibleTaxonomy": true
9798
},
9899
"repository": "salesforcecli/plugin-deploy-retrieve",
99100
"scripts": {
@@ -109,16 +110,16 @@
109110
"prepack": "sf-prepack",
110111
"prepare": "sf-install",
111112
"test": "wireit",
112-
"test:nuts": "ts-node ./test/nuts/generateNuts.ts && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 10",
113+
"test:nuts": "node --loader ts-node/esm ./test/nuts/generateNuts.ts && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 10",
113114
"test:nuts:convert": "nyc mocha \"test/nuts/convert/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
114115
"test:nuts:deb": "nyc mocha \"test/nuts/digitalExperienceBundle/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
115116
"test:nuts:delete": "nyc mocha \"test/nuts/delete/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
116117
"test:nuts:deploy": "nyc mocha \"test/nuts/deploy/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
117-
"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",
118-
"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",
119-
"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",
120-
"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",
121-
"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",
118+
"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",
119+
"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",
120+
"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",
121+
"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",
122+
"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",
122123
"test:nuts:destructive": "nyc mocha \"test/nuts/destructive/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
123124
"test:nuts:manifest": "nyc mocha \"test/nuts/manifest/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
124125
"test:nuts:retrieve": "nyc mocha \"test/nuts/retrieve/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
@@ -132,7 +133,6 @@
132133
"publishConfig": {
133134
"access": "public"
134135
},
135-
"main": "lib/index.js",
136136
"wireit": {
137137
"build": {
138138
"dependencies": [
@@ -209,7 +209,7 @@
209209
"output": []
210210
},
211211
"test:command-reference": {
212-
"command": "\"./bin/dev\" commandreference:generate --erroronwarnings",
212+
"command": "ts-node \"./bin/dev.js\" commandreference:generate --erroronwarnings",
213213
"files": [
214214
"src/**/*.ts",
215215
"messages/**",
@@ -220,7 +220,7 @@
220220
]
221221
},
222222
"test:deprecation-policy": {
223-
"command": "\"./bin/dev\" snapshot:compare",
223+
"command": "ts-node \"./bin/dev.js\" snapshot:compare",
224224
"files": [
225225
"src/**/*.ts"
226226
],
@@ -230,12 +230,14 @@
230230
]
231231
},
232232
"test:json-schema": {
233-
"command": "\"./bin/dev\" schema:compare",
233+
"command": "ts-node \"./bin/dev.js\" schema:compare",
234234
"files": [
235235
"src/**/*.ts",
236236
"schemas"
237237
],
238238
"output": []
239239
}
240-
}
240+
},
241+
"exports": "./lib/index.js",
242+
"type": "module"
241243
}

schemas/project-retrieve-start.json

+14-11
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,7 @@
154154
"type": "string"
155155
},
156156
"manageableState": {
157-
"type": "string",
158-
"enum": [
159-
"beta",
160-
"deleted",
161-
"deprecated",
162-
"deprecatedEditable",
163-
"installed",
164-
"installedEditable",
165-
"released",
166-
"unmanaged"
167-
]
157+
"$ref": "#/definitions/ManageableState"
168158
},
169159
"namespacePrefix": {
170160
"type": "string"
@@ -187,6 +177,19 @@
187177
],
188178
"additionalProperties": false
189179
},
180+
"ManageableState": {
181+
"type": "string",
182+
"enum": [
183+
"beta",
184+
"deleted",
185+
"deprecated",
186+
"deprecatedEditable",
187+
"installed",
188+
"installedEditable",
189+
"released",
190+
"unmanaged"
191+
]
192+
},
190193
"RequestStatus": {
191194
"type": "string",
192195
"enum": ["Pending", "InProgress", "Succeeded", "SucceededPartial", "Failed", "Canceling", "Canceled"]

src/commands/deploy.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { EOL } from 'node:os';
1010
import { writeFile, readFile } from 'node:fs/promises';
1111
import { existsSync } from 'node:fs';
1212
import { exec } from 'node:child_process';
13+
import { dirname } from 'node:path';
14+
import { fileURLToPath } from 'node:url';
1315
import { Hook } from '@oclif/core';
1416
import { Messages } from '@salesforce/core';
1517
import { Env, parseJsonMap } from '@salesforce/kit';
@@ -22,8 +24,9 @@ import {
2224
SfHook,
2325
Flags,
2426
} from '@salesforce/sf-plugins-core';
25-
import { DeployerResult } from '@salesforce/sf-plugins-core/lib/deployer';
26-
Messages.importMessagesDirectory(__dirname);
27+
import { DeployerResult } from '@salesforce/sf-plugins-core/lib/deployer.js';
28+
29+
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
2730

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

src/commands/project/convert/mdapi.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { dirname, resolve } from 'node:path';
9-
import * as fs from 'node:fs';
9+
import fs from 'node:fs';
10+
import { fileURLToPath } from 'node:url';
1011
import { Messages, SfError } from '@salesforce/core';
1112
import {
1213
ComponentSet,
@@ -22,10 +23,10 @@ import {
2223
SfCommand,
2324
} from '@salesforce/sf-plugins-core';
2425
import { Interfaces } from '@oclif/core';
25-
import { ConvertMdapiJson } from '../../../utils/types';
26-
import { MetadataConvertResultFormatter } from '../../../formatters/metadataConvertResultFormatter';
26+
import { ConvertMdapiJson } from '../../../utils/types.js';
27+
import { MetadataConvertResultFormatter } from '../../../formatters/metadataConvertResultFormatter.js';
2728

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

3132
export interface EnsureFsFlagOptions {

src/commands/project/convert/source.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { resolve } from 'node:path';
9-
import * as fs from 'node:fs';
10-
8+
import { resolve, dirname } from 'node:path';
9+
import fs from 'node:fs';
10+
import { fileURLToPath } from 'node:url';
1111
import { Messages } from '@salesforce/core';
1212
import {
1313
ComponentSet,
1414
ComponentSetBuilder,
1515
ConvertResult,
1616
MetadataConverter,
1717
} from '@salesforce/source-deploy-retrieve';
18-
import { getString } from '@salesforce/ts-types';
1918
import {
2019
arrayWithDeprecation,
2120
Flags,
@@ -24,11 +23,11 @@ import {
2423
SfCommand,
2524
} from '@salesforce/sf-plugins-core';
2625
import { Interfaces } from '@oclif/core';
27-
import { getPackageDirs, getSourceApiVersion } from '../../../utils/project';
28-
import { SourceConvertResultFormatter } from '../../../formatters/sourceConvertResultFormatter';
29-
import { ConvertResultJson } from '../../../utils/types';
26+
import { getPackageDirs, getSourceApiVersion } from '../../../utils/project.js';
27+
import { SourceConvertResultFormatter } from '../../../formatters/sourceConvertResultFormatter.js';
28+
import { ConvertResultJson } from '../../../utils/types.js';
3029

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

3433
export class Source extends SfCommand<ConvertResultJson> {
@@ -153,7 +152,7 @@ export class Source extends SfCommand<ConvertResultJson> {
153152
}
154153

155154
protected resolveSuccess(): void {
156-
if (!getString(this.convertResult, 'packagePath')) {
155+
if (!this.convertResult.packagePath) {
157156
process.exitCode = 1;
158157
}
159158
}

0 commit comments

Comments
 (0)