Skip to content

Commit

Permalink
chore: switch to node:fs
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Oct 26, 2023
1 parent 4b27582 commit 3b84c22
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 87 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"chai": "^4.3.10",
"eslint": "^8.51.0",
"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": "^1.1.2",
"eslint-config-salesforce-typescript": "^2.0.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^43.0.5",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-sf-plugin": "^1.16.9",
"fs-extra": "^10.1.0",
"husky": "^7.0.4",
Expand All @@ -50,7 +50,7 @@
"sinon": "10.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"wireit": "^0.14.0"
"wireit": "^0.14.1"
},
"config": {},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/alias/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { StateAggregator, Messages } from '@salesforce/core';
import { loglevel } from '@salesforce/sf-plugins-core';
import { AliasCommand, AliasResults } from '../../alias.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/alias/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { loglevel, parseVarArgs } from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages } from '@salesforce/core';
import { AliasCommand, AliasResults } from '../../alias.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/alias/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages } from '@salesforce/core';
import { AliasCommand, AliasResults } from '../../alias.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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 'path';
import { dirname } from 'node:path';
import { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigAggregator, Messages } from '@salesforce/core';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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 'path';
import { dirname } from 'node:path';
import { ConfigAggregator, Messages } from '@salesforce/core';
import { loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigResponses, buildSuccessMsg, output } from '../../config.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { parseVarArgs, Flags, loglevel, Ux, SfCommand } from '@salesforce/sf-plugins-core';
import { Config, Messages, Org, SfError, OrgConfigProperties } from '@salesforce/core';
import { HelpSection } from '@oclif/core';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Config, Messages } from '@salesforce/core';
import { CONFIG_HELP_SECTION, buildFailureMsg, calculateSuggestion, output } from '../../config.js';
Expand Down
26 changes: 14 additions & 12 deletions src/hooks/init/load_config_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,28 @@ async function loadConfigMeta(plugin: Interfaces.Plugin): Promise<ConfigProperty

log.info(x);

return x.default;
return x.default ?? x;
} catch {
return;
}
}

const hook: Hook<'init'> = async ({ config }): Promise<void> => {
const flattenedConfigMetas = (config.getPluginsList() || [])
.flatMap(async (plugin) => {
const configMeta = await loadConfigMeta(plugin);
if (!configMeta) {
log.info(`No config meta found for ${plugin.name}`);
}

return configMeta;
})
.filter<Promise<ConfigPropertyMeta>>(isObject);
const flattenedConfigMetas = (
await Promise.all(
(config.getPluginsList() || []).flatMap(async (plugin) => {
const configMeta = await loadConfigMeta(plugin);
if (!configMeta) {
log.info(`No config meta found for ${plugin.name}`);
}

return configMeta;
})
)
).filter<ConfigPropertyMeta>(isObject);

if (flattenedConfigMetas.length) {
Config.addAllowedProperties(await Promise.all(flattenedConfigMetas));
Config.addAllowedProperties(flattenedConfigMetas);
}
return Promise.resolve();
};
Expand Down
2 changes: 1 addition & 1 deletion test/commands/alias/set.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { getNumber, getString } from '@salesforce/ts-types';
import { expect } from 'chai';
Expand Down
2 changes: 1 addition & 1 deletion test/commands/alias/unset.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { Messages } from '@salesforce/core';
Expand Down
2 changes: 1 addition & 1 deletion test/commands/config/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import path from 'path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { test, expect } from '@oclif/test';
import { ConfigAggregator, OrgConfigProperties } from '@salesforce/core';
Expand Down
2 changes: 1 addition & 1 deletion test/commands/config/set.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'path';
import { dirname } from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { assert, expect } from 'chai';
import { Messages } from '@salesforce/core';
Expand Down
33 changes: 3 additions & 30 deletions test/hooks/load_config_meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import path from 'path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { readFileSync } from 'node:fs';
import { test, expect } from '@oclif/test';
Expand All @@ -15,8 +15,6 @@ import { stubMethod } from '@salesforce/ts-sinon';
import sinon from 'sinon';
import { SinonSandbox, SinonStub } from 'sinon';
import tsSrcConfigMetaMock from '../config-meta-mocks/typescript-src/src/config-meta.js';
// @ts-expect-error because it's js
import jsLibConfigMetaMock from '../config-meta-mocks/javascript-lib/lib/config-meta.js';

process.env.NODE_ENV = 'development';

Expand Down Expand Up @@ -46,39 +44,14 @@ describe('hooks', () => {
})
.hook('init')
.do(() => {
expect(tsSrcConfigMetaMock).to.deep.equal([
expect(tsSrcConfigMetaMock.default).to.deep.equal([
{
key: 'customKey',
},
]);
// modified since devPlugins now includes plugin-deploy-retrieve to exercise a config-meta that it includes.
// see https://github.com/salesforcecli/plugin-deploy-retrieve/blob/main/src/configMeta.ts
expect((Config.addAllowedProperties as SinonStub).firstCall.args[0][1]).to.equal(tsSrcConfigMetaMock);
expect((Config.addAllowedProperties as SinonStub).firstCall.args[0][1]).to.equal(tsSrcConfigMetaMock.default);
})
.it('loads config metas from a ts src directory');

// test
// .stdout()
// .loadConfig()
// .do(async (ctx) => {
// const mockPluginRoot = path.resolve(
// path.dirname(fileURLToPath(import.meta.url)),
// '../config-meta-mocks/javascript-lib'
// );
// ctx.config.plugins.set('sfdx-cli-ts-plugin', {
// root: mockPluginRoot,
// hooks: {},
// pjson: JSON.parse(readFileSync(path.resolve(mockPluginRoot, 'package.json'), 'utf-8')),
// } as unknown as Plugin);
// })
// .hook('init')
// .do(() => {
// expect(jsLibConfigMetaMock).to.deep.equal([
// {
// key: 'customKey',
// },
// ]);
// expect((Config.addAllowedProperties as SinonStub).firstCall.args[0][1]).to.equal(jsLibConfigMetaMock[0]);
// })
// .it('loads config metas from a js lib directory');
});
Loading

0 comments on commit 3b84c22

Please sign in to comment.