Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
unsafe-disable-integrity-migration "false"
--run.silent true
21 changes: 21 additions & 0 deletions bin/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This is a script which can be run with or without --fix.
// It will run prettier with the right flags.

const { spawnSync } = require('child_process');

const PRETTIER_FLAGS = [
'--cache',
...['--cache-strategy', 'content'],
...['--cache-location', '.prettiercache'],
...['--log-level', 'warn'],
];

const shouldFix = process.argv.includes('--fix');
const writeOrCheck = shouldFix ? '--write' : '--check';
const args = [writeOrCheck, '.', ...PRETTIER_FLAGS];
const result = spawnSync('prettier', args, { stdio: 'inherit' });
process.exitCode = result.status;
10 changes: 10 additions & 0 deletions bin/lint-or-lint-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const { spawnSync } = require('child_process');

const shouldFix = process.argv.includes('--fix');
const scriptToRun = shouldFix ? 'lint-fix' : 'lint-internal';
const result = spawnSync('yarn', [scriptToRun], { stdio: 'inherit' });
process.exitCode = result.status;
40 changes: 0 additions & 40 deletions bin/output-fixing-commands.js

This file was deleted.

25 changes: 25 additions & 0 deletions bin/suggest-fixing-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This file runs before linting commands and intercept errors so that more
// friendly errors can be output.

const cp = require('child_process');

const scriptToRun = process.argv[2];
const scriptToSuggest = process.argv[3];
const extraArgs = process.argv.slice(4);

const result = cp.spawnSync('yarn', [scriptToRun, ...extraArgs], {
stdio: 'inherit',
});

if (result.status !== 0) {
process.exitCode = result.status;
console.log(
'💡 You might be able to fix the error by running `yarn ' +
scriptToSuggest +
'`'
);
}
31 changes: 19 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
"build-photon": "webpack --config res/photon/webpack.config.js",
"build-symbolicator-cli": "yarn build-symbolicator-cli:quiet --progress",
"build-symbolicator-cli:quiet": "yarn build:clean && cross-env NODE_ENV=production webpack --config src/symbolicator-cli/webpack.config.js",
"lint": "node bin/output-fixing-commands.js run-p lint-js lint-css prettier-run",
"lint-fix": "run-p lint-fix-js lint-fix-css prettier-fix",
"lint-js": "node bin/output-fixing-commands.js eslint *.js bin src --report-unused-disable-directives --cache --cache-strategy content",
"lint-fix-js": "yarn lint-js --fix",
"lint-css": "node bin/output-fixing-commands.js stylelint \"src/**/*.css\" \"res/**/*.css\"",
"lint-fix-css": "yarn lint-css --fix",
"prettier-run": "node bin/output-fixing-commands.js prettier --check . --cache --cache-strategy content --cache-location .prettiercache",
"prettier-fix": "prettier --write . --cache --cache-strategy content --cache-location .prettiercache",
"lint": "node bin/suggest-fixing-command.js lint-or-lint-fix-internal 'lint --fix'",
"lint-js": "node bin/suggest-fixing-command.js lint-internal:js 'lint-js --fix'",
"lint-css": "node bin/suggest-fixing-command.js lint-internal:css 'lint-css --fix'",
"prettier-run": "node bin/suggest-fixing-command.js lint-internal:format fmt",
"fmt": "yarn lint-fix:format",
"lint-or-lint-fix-internal": "node bin/lint-or-lint-fix.js",
"lint-internal": "run-p lint-internal:**",
"lint-internal:js": "eslint *.js bin src --report-unused-disable-directives --cache --cache-strategy content",
"lint-internal:css": "stylelint \"src/**/*.css\" \"res/**/*.css\"",
"lint-internal:format": "node bin/format.js",
"lint-fix": "run-p lint-fix:**",
"lint-fix:js": "yarn lint-internal:js --fix",
"lint-fix:css": "yarn lint-internal:css --fix",
"lint-fix:format": "yarn lint-internal:format --fix",
"ts": "tsc",
"protoc": "npx -p protobufjs-cli pbjs -t static-module -w commonjs -o ./src/profile-logic/import/proto/simpleperf_report.js ./src/profile-logic/import/proto/simpleperf_report.proto && npx -p protobufjs-cli pbts -o ./src/profile-logic/import/proto/simpleperf_report.d.ts ./src/profile-logic/import/proto/simpleperf_report.js",
"license-check": "devtools-license-check",
Expand All @@ -42,11 +48,12 @@
"start-examples": "ws -d examples/ -s index.html -p 4244",
"start-docs": "ws -d docs-user/ -p 3000",
"start-photon": "node res/photon/server",
"test": "node bin/output-fixing-commands.js cross-env LC_ALL=C TZ=UTC NODE_ENV=test jest",
"test": "node bin/suggest-fixing-command.js test-internal 'test -u'",
"test-internal": "cross-env LC_ALL=C TZ=UTC NODE_ENV=test jest",
"test-all": "run-p --max-parallel 4 ts license-check lint test test-alex test-lockfile",
"test-build-coverage": "yarn test --coverage --coverageReporters=html",
"test-serve-coverage": "ws -d coverage/ -p 4343",
"test-coverage": "run-s test-build-coverage test-serve-coverage",
"test-coverage": "run-s test-coverage:**",
"test-coverage:build": "yarn test --coverage --coverageReporters=html",
"test-coverage:serve": "ws -d coverage/ -p 4343",
"test-alex": "alex ./docs-* CODE_OF_CONDUCT.md CONTRIBUTING.md README.md",
"test-lockfile": "lockfile-lint --path yarn.lock --allowed-hosts yarn --validate-https",
"test-debug": "cross-env LC_ALL=C TZ=UTC NODE_ENV=test node --inspect-brk node_modules/.bin/jest --runInBand",
Expand Down