aberlaas-precommit 2.18.1 → 2.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,28 @@
1
- const readmeCommands = [
2
- 'yarn run aberlaas readme',
3
- 'git add ./README.md ./lib/README.md',
4
- ];
1
+ export const commands = {
2
+ lintCss: 'yarn run lint:fix --css',
3
+ lintYml: 'yarn run lint:fix --yml',
4
+ lintCircleci: 'yarn run lint --circleci',
5
+ lintJson: 'yarn run lint:fix --json',
6
+ lintJs: 'yarn run lint:fix --js',
7
+ testJs: 'yarn run test --failFast --related',
8
+ compressPng: 'yarn run compress --png',
9
+ readme: 'yarn run aberlaas readme --add-to-git',
10
+ };
5
11
 
6
12
  export default {
7
13
  // Lint
8
- '*.css': ['yarn run lint:fix --css'],
9
- '*.{yml,yaml}': ['yarn run lint:fix --yml'],
10
- '.circleci/config.yml': ['yarn run lint --circleci'],
11
- '*.json': ['yarn run lint:fix --json'],
12
- '*.js': ['yarn run lint:fix --js'],
14
+ '**/*.css': [commands.lintCss],
15
+ '**/*.{yml,yaml}': [commands.lintYml],
16
+ '.circleci/config.yml': [commands.lintCircleci],
17
+ '**/*.json': [commands.lintJson],
18
+ '**/*.js': [commands.lintJs],
13
19
 
14
20
  // Test
15
- './lib/**/*.js': ['FORCE_COLOR=1 yarn run test --failFast --related'],
21
+ '**/lib/**/*.js': [commands.testJs],
16
22
 
17
23
  // Compress
18
- '*.png': ['yarn run compress --png'],
24
+ '**/*.png': [commands.compressPng],
19
25
 
20
26
  // Documentation
21
- // Update the README whenever the documentation, or the README template
22
- // changes
23
- 'docs/src/**/*.md': readmeCommands,
24
- '.github/README.template.md': readmeCommands,
27
+ '**/*.md': [commands.readme],
25
28
  };
package/lib/main.js CHANGED
@@ -1,33 +1,70 @@
1
+ import { consoleInfo, consoleWarn, firostError } from 'firost';
2
+ import { getConfig } from 'aberlaas-helper';
1
3
  import lintStaged from 'lint-staged';
2
- import { firostError } from 'firost';
3
- import helper from 'aberlaas-helper';
4
4
  import lintStagedConfig from '../configs/lintstaged.js';
5
5
 
6
- export default {
7
- async run(cliArgs) {
8
- // Config
9
- const config = await helper.getConfig(
6
+ export let __;
7
+ let additionalOptions = {};
8
+
9
+ /**
10
+ * Runs precommit linting using lint-staged with the provided configuration
11
+ * @param {object} cliArgs - Command line arguments object
12
+ * @param {string} [cliArgs.config] - Path to custom configuration file
13
+ * @returns {boolean} True on success
14
+ */
15
+ export async function run(cliArgs = {}) {
16
+ const options = await __.getOptions(cliArgs);
17
+
18
+ // Grab all errors output by lint-staged, to display later
19
+ const errors = [];
20
+ const logger = {
21
+ log: consoleInfo,
22
+ warn: consoleWarn,
23
+ error(error) {
24
+ errors.push(error);
25
+ },
26
+ };
27
+
28
+ const canCommit = await __.lintStaged(options, logger);
29
+
30
+ // Stop if can commit
31
+ if (canCommit) {
32
+ return true;
33
+ }
34
+
35
+ // Throw error if can't commit
36
+ throw __.firostError('ABERLAAS_PRECOMMIT_LINT_FAILED', errors);
37
+ }
38
+
39
+ __ = {
40
+ /**
41
+ * Retrieves configuration options for lint-staged execution
42
+ * @param {object} cliArgs - Command line arguments object
43
+ * @param {string} [cliArgs.config] - Path to custom configuration file
44
+ * @returns {object} configuration options object with config, additional options, and shell set to true
45
+ */
46
+ async getOptions(cliArgs) {
47
+ // Find the most relevant config
48
+ const config = await getConfig(
10
49
  cliArgs.config,
11
50
  'lintstaged.config.js',
12
51
  lintStagedConfig,
13
52
  );
14
53
 
15
- try {
16
- const result = await lintStaged({
17
- config,
18
- // Allow use extended shell syntax in config, like pipes, redirects or
19
- // env variables
20
- shell: true,
21
- });
22
- // Linting failed
23
- if (!result) {
24
- throw firostError(
25
- 'ERROR_PRECOMMIT_LINT_FAILED',
26
- 'Precommit linting failed',
27
- );
28
- }
29
- } catch (_error) {
30
- throw firostError('ERROR_PRECOMMIT', 'Precommit failed');
31
- }
54
+ return {
55
+ config,
56
+ ...additionalOptions, // Additional overrides from tests
57
+ };
58
+ },
59
+ lintStaged,
60
+ firostError,
61
+ // Internal methods to pass additional options to lint-staged, for tests
62
+ addOption(key, value) {
63
+ additionalOptions[key] = value;
64
+ },
65
+ clearOptions() {
66
+ additionalOptions = {};
32
67
  },
33
68
  };
69
+
70
+ export default { run };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "aberlaas-precommit",
3
3
  "type": "module",
4
+ "sideEffects": false,
4
5
  "description": "aberlaas precommit helper: Sanitize and cleanup on commit",
5
- "version": "2.18.1",
6
+ "version": "2.20.1",
6
7
  "repository": "pixelastic/aberlaas",
7
8
  "homepage": "https://projects.pixelastic.com/aberlaas/",
8
9
  "author": "Tim Carry (@pixelastic)",
@@ -19,25 +20,27 @@
19
20
  "engines": {
20
21
  "node": ">=18.18.0"
21
22
  },
22
- "scripts": {
23
- "build": "../../scripts/local/build",
24
- "build:prod": "../../scripts/local/build-prod",
25
- "cms": "../../scripts/local/cms",
26
- "serve": "../../scripts/local/serve",
27
- "ci": "../../scripts/local/ci",
28
- "release": "../../scripts/local/release",
29
- "update-dependencies": "node ../../scripts/meta/update-dependencies.js",
30
- "test:meta": "../../scripts/local/test-meta",
31
- "test": "../../scripts/local/test",
32
- "test:watch": "../../scripts/local/test-watch",
33
- "compress": "../../scripts/local/compress",
34
- "lint": "../../scripts/local/lint",
35
- "lint:fix": "../../scripts/local/lint-fix"
36
- },
37
23
  "dependencies": {
38
- "aberlaas-helper": "^2.18.1",
39
- "firost": "5.2.1",
40
- "lint-staged": "15.2.10"
24
+ "aberlaas-helper": "workspace:*",
25
+ "firost": "5.5.1",
26
+ "lint-staged": "16.2.7"
27
+ },
28
+ "scripts": {
29
+ "build": "cd ../docs && yarn run build",
30
+ "build:prod": "cd ../docs && yarn run build:prod",
31
+ "cms": "cd ../docs && yarn run cms",
32
+ "serve": "cd ../docs && yarn run serve",
33
+ "release": "cd ../.. && ./scripts/release",
34
+ "test:meta": "cd ../.. && ./scripts/test-meta",
35
+ "test": "cd ../.. && ./scripts/test",
36
+ "test:watch": "cd ../.. && ./scripts/test-watch",
37
+ "compress": "cd ../.. && ./scripts/compress",
38
+ "lint": "cd ../.. && ./scripts/lint",
39
+ "lint:fix": "cd ../.. && ./scripts/lint-fix"
41
40
  },
42
- "gitHead": "00b60dcf9aebab442a809ccc81942005d87d1b5c"
41
+ "devDependencies": {
42
+ "gilmore": "1.2.0",
43
+ "golgoth": "3.0.0",
44
+ "micromatch": "4.0.8"
45
+ }
43
46
  }