Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
feat: add eslint and use it in all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Jul 9, 2020
1 parent 0c1bf43 commit 0165cc8
Show file tree
Hide file tree
Showing 106 changed files with 3,954 additions and 2,231 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/packages/dev-scripts/utils/standardize-pjson.js",
"outFiles": ["${workspaceFolder}/**/*.js"]
},
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node"
}
]
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "root",
"name": "dev-config",
"private": true,
"scripts": {
"bootstrap": "lerna bootstrap",
Expand All @@ -16,12 +16,15 @@
"lint-fix": "lerna run lint -- --fix",
"postclean-all": "yarn sfdx-clean all",
"prepack": "lerna run prepack",
"test": "lerna run test"
"test": "lerna run test",
"undefined": "lerna run undefined"
},
"devDependencies": {
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.3.1",
"lerna": "^3.15.0"
"husky": "^4.2.5",
"lerna": "^3.15.0",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1"
},
"config": {
"commitizen": {
Expand Down
3 changes: 3 additions & 0 deletions packages/dev-config/.sfdevrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"only-scripts": ["clean", "clean-all"]
}
3 changes: 0 additions & 3 deletions packages/dev-config/.sfdx-dev.json

This file was deleted.

4 changes: 1 addition & 3 deletions packages/dev-config/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const path = require('path');
const tslint = require(path.join(__dirname, 'tslint'));
const tsconfig = require(path.join(__dirname, 'tsconfig'));

module.exports = {
tslint,
tsconfig
tsconfig,
};
9 changes: 2 additions & 7 deletions packages/dev-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/dev-config",
"version": "1.5.0",
"version": "2.0.0",
"description": "A set of standard typescript config and tslint options for Salesforce projects.",
"repository": "https://github.com/forcedotcom/sfdx-dev-packages",
"main": "index.js",
Expand All @@ -22,16 +22,11 @@
"/nyc.json",
"/typedoc.js"
],
"dependencies": {
"tslint": "^5.18.0",
"tslint-microsoft-contrib": "^5.2.1",
"typescript": "~3.1.6"
},
"scripts": {
"clean-all": "shx rm -rf node_modules"
},
"devDependencies": {
"commitizen": "^3.1.1",
"commitizen": "^4.1.2",
"shx": "^0.3.2"
}
}
18 changes: 9 additions & 9 deletions packages/dev-scripts/bin/sfdx-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const defaultDirs = ['lib', '*coverage', '.nyc_output'];
const defaultFiles = ['*xunit.xml', '*checkstyle.xml', 'yarn-error.log'];

const packageRoot = require('../utils/package-path');
const Config = require('../utils/sfdx-dev-config');
const config = new Config(packageRoot);
const clean = config.get('clean');
const { resolveConfig } = require('../utils/sfdx-dev-config');
const config = resolveConfig(packageRoot);
const clean = config.clean;

const cleanAll = process.argv[2] === 'all';

Expand All @@ -27,40 +27,40 @@ if (cleanAll) {

if (!clean || clean.skipDefaults !== true) {
log(`cleaning default directories: ${defaultDirs.join()}`);
defaultDirs.forEach(dir => {
defaultDirs.forEach((dir) => {
shell.rm('-rf', join(packageRoot, dir));
});
log(`cleaning default files: ${defaultFiles.join()}`);
defaultFiles.forEach(file => {
defaultFiles.forEach((file) => {
shell.rm('-f', join(packageRoot, file));
});
}

if (clean && clean.dirs) {
log(`cleaning config directories: ${clean.dirs.join()}`);
clean.dirs.forEach(dir => {
clean.dirs.forEach((dir) => {
shell.rm('-rf', join(packageRoot, dir));
});
}

if (clean && clean.files) {
log(`cleaning config files: ${clean.files.join()}`);
clean.files.forEach(file => {
clean.files.forEach((file) => {
shell.rm('-f', join(packageRoot, file));
});
}

if (cleanAll) {
if (clean && clean.allDirs) {
log(`cleaning all directories: ${clean.allDirs.join()}`);
clean.allDirs.forEach(dir => {
clean.allDirs.forEach((dir) => {
shell.rm('-rf', join(packageRoot, dir));
});
}

if (clean && clean.allFiles) {
log(`cleaning all files: ${clean.allFiles.join()}`);
clean.allFiles.forEach(file => {
clean.allFiles.forEach((file) => {
shell.rm('-f', join(packageRoot, file));
});
}
Expand Down
11 changes: 5 additions & 6 deletions packages/dev-scripts/bin/sfdx-lerna-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
let chalk = require('chalk');
const log = require('../utils/log');
const writeDeps = require('../utils/write-dependencies');
const packageRoot = require('../utils/package-path');

let changed = false;
log(`Writing dependencies for the lerna project`);
changed = changed || writeDeps();
changed = changed || writeDeps(packageRoot);

// Run it for all packages in the lerna project
changed =
changed || require('../utils/run-in-lerna-packages')('preinstall', writeDeps);
changed = changed || require('../utils/run-in-lerna-packages')('preinstall', writeDeps);

if (changed) {
const errorHeader = chalk.red('ERROR: ');
const errorMsg =
"Dependencies have changed and saved to package.json. Rerun 'yarn install' to finish the install";
const errorMsg = "Dependencies have changed and saved to package.json. Rerun 'yarn install' to finish the install";
console.error(chalk.bold(`\n${errorHeader}${errorMsg}\n`));
process.exitCode = 1;
} else {
Expand All @@ -37,7 +36,7 @@ if (changed) {
standardizePjson(packagePath, inLernaProject);
};

runAll();
runAll(packageRoot);

// Run it for all packages in the lerna project
require('../utils/run-in-lerna-packages')('postinstall', runAll);
Expand Down
12 changes: 6 additions & 6 deletions packages/dev-scripts/bin/sfdx-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const shell = require('../utils/shelljs');
const exists = require('../utils/exists');
const packageRoot = require('../utils/package-path');

const lint = require.resolve('tslint/bin/tslint');
const lint = require.resolve('eslint/bin/eslint');

const extras = process.argv.slice(2).join(' ');

shell.exec(`${lint} -p . -t stylish ${extras}`, {
cwd: packageRoot
console.log(`${lint} ${extras} ./src/**/*.ts`);
shell.exec(`${lint} ${extras} ./src/**/*.ts`, {
cwd: packageRoot,
});

if (exists('./test')) {
shell.exec(`${lint} -p ./test -t stylish ${extras}`, {
cwd: packageRoot
shell.exec(`${lint} ${extras} ./test/**/*.ts`, {
cwd: packageRoot,
});
}
11 changes: 5 additions & 6 deletions packages/dev-scripts/bin/sfdx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@
const shell = require('../utils/shelljs');

const packageRoot = require('../utils/package-path');
const SfdxDevConfig = require('../utils/sfdx-dev-config');
const { resolveConfig } = require('../utils/sfdx-dev-config');

const nyc = require.resolve('nyc/bin/nyc');

const config = new SfdxDevConfig(packageRoot);
const testConfig = config.get('test') || {};
const config = resolveConfig(packageRoot);
const testConfig = config.test || {};

let command = `${nyc} mocha`;

if (!testConfig.mochaOpts) {
command +=
' --require ts-node/register --require source-map-support/register';
command += ' --require ts-node/register --require source-map-support/register';
}

const includes = testConfig.testsPath || '**/*.test.ts';
command += ` --recursive "${includes}"`;

try {
shell.exec(command, {
cwd: packageRoot
cwd: packageRoot,
});
} catch (err) {
process.exitCode = 1;
Expand Down
46 changes: 26 additions & 20 deletions packages/dev-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/dev-scripts",
"version": "0.4.2",
"description": "A set of standard package.json scripts for Salesforce projects.",
"version": "1.0.0",
"description": "Standardize package.json scripts and config files for Salesforce projects.",
"repository": "https://github.com/forcedotcom/sfdx-dev-packages",
"bin": {
"sfdx-build": "bin/sfdx-build.js",
Expand Down Expand Up @@ -33,29 +33,35 @@
"utils"
],
"dependencies": {
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^7.6.0",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@salesforce/dev-config": "^1.5.0",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.7",
"@types/node": "^10.14.12",
"@types/sinon": "^4.3.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/node": "^12.12.6",
"@types/sinon": "^9.0.4",
"chai": "^4.2.0",
"chalk": "2.4.2",
"mocha": "^5.2.0",
"nyc": "^13.3.0",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.1",
"shelljs": "~0.8.3",
"sinon": "^5.1.1",
"source-map-support": "~0.5.12",
"ts-node": "^7.0.1",
"tslint": "^5.18.0",
"typedoc": "~0.15.0",
"typedoc-plugin-external-module-name": "~1.1.3",
"chalk": "^4.0.0",
"config": "^3.3.1",
"cosmiconfig": "^6.0.0",
"eslint-config-salesforce-typescript": "1.0.0",
"mocha": "^7.2.0",
"nyc": "^15.1.0",
"shelljs": "~0.8.4",
"sinon": "^9.0.2",
"source-map-support": "~0.5.19",
"ts-node": "^8.10.2",
"typedoc": "~0.17.7",
"typedoc-plugin-external-module-name": "~4.0.0",
"typescript": "^3.9.3",
"xunit-file": "^1.0.0"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"husky": "^4.2.5",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1"
}
}
8 changes: 6 additions & 2 deletions packages/dev-scripts/utils/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PackageJson {
this.pjsonPath = join(packageRoot, 'package.json');
this.contents = require(this.pjsonPath);
this.originalContents = this.stringify();
this.actions = [];
}

stringify() {
Expand All @@ -33,10 +34,13 @@ class PackageJson {
write() {
const pjson = this.stringify();
if (this.originalContents !== pjson) {
log(`Found changes for ${this.contents.name}`);
for (const action of this.actions) {
log(action, 2);
}

writeFileSync(this.pjsonPath, pjson);
log(`wrote changes to ${this.pjsonPath}`, 1);
} else {
log('package.json not changed; skipping write', 2);
}
}

Expand Down
36 changes: 16 additions & 20 deletions packages/dev-scripts/utils/run-in-lerna-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@ const packageRoot = require('./package-path');

module.exports = (name, script) => {
// Only get lerna packages that require @salesforce/dev-scripts
const packageList = readdirSync(join(packageRoot, 'packages')).filter(
name => {
try {
const pjson = require(join(
packageRoot,
'packages',
name,
'package.json'
));
return (
pjson.dependencies['@salesforce/dev-scripts'] ||
pjson.devDependencies['@salesforce/dev-scripts']
);
} catch (e) {}
return false;
const packageList = readdirSync(join(packageRoot, 'packages')).filter((packageName) => {
try {
const pjson = require(join(packageRoot, 'packages', packageName, 'package.json'));
// TODO should inner packages even depend on this? Maybe it should be at the lerna level only
return (
(pjson.dependencies && pjson.dependencies['@salesforce/dev-scripts']) ||
(pjson.devDependencies && pjson.devDependencies['@salesforce/dev-scripts'])
);
} catch (e) {
console.warn(`Skipping ${packageName} because ${e.message}`);
}
);
return false;
});

log(`Running ${name} for packages ${packageList.join(', ')}`);

let changed = false;
try {
packageList.forEach(dir => {
// Run against the packages root
changed = changed || script(join(packageRoot, 'packages', dir), true);
});
for (const dir of packageList) {
// Run against all packages to update all package.json at once (don't short circuit).
changed = script(join(packageRoot, 'packages', dir), true) || changed;
}
} catch (err) {
console.error(err);
process.exitCode = 1;
Expand Down
Loading

0 comments on commit 0165cc8

Please sign in to comment.