@companion-module/tools 1.5.1 → 2.0.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.0](https://github.com/bitfocus/companion-module-tools/compare/v1.5.1...v2.0.0) (2024-08-25)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * remove eslint and prettier as dependencies, modules should install these directly ([#43](https://github.com/bitfocus/companion-module-tools/issues/43))
9
+
10
+ ### Features
11
+
12
+ * remove eslint and prettier as dependencies, modules should install these directly ([#43](https://github.com/bitfocus/companion-module-tools/issues/43)) ([45615fc](https://github.com/bitfocus/companion-module-tools/commit/45615fc3d5448d32ea37b9023e9476ca4893c407))
13
+
3
14
  ## [1.5.1](https://github.com/bitfocus/companion-module-tools/compare/v1.5.0...v1.5.1) (2024-06-20)
4
15
 
5
16
 
package/README.md CHANGED
@@ -13,3 +13,58 @@ More information on this command is available [on the wiki](https://github.com/b
13
13
  ### companion-generate-manifest
14
14
 
15
15
  Generate the new format manifest from an old package.json
16
+
17
+
18
+ ## Upgrading from v1.x to v2.0
19
+
20
+ v2.0 of this library includes some breaking changes to how eslint and prettier handled.
21
+ Instead of it being installed as a dependency, and being directly usable by modules it has to be explicitly installed by modules.
22
+
23
+ This change was done for two reasons:
24
+ 1) Very few modules use eslint, making this extra weight for them for no gain
25
+ 2) Recent versions of yarn do not expose these binaries in a way which is easily callable by modules, requiring tricks to be able to execute them.
26
+
27
+ To resolve this, you will need to do a `yarn add --dev eslint prettier` in your modules to install the dependencies, and update any scripts to remove the invocation hacks.
28
+
29
+ This also allows for eslint to be updated to v9, which requires a new config format. This unfortonately means that your config file needs to be replaced.
30
+
31
+ A new basic config should be called `eslint.config.mjs` (remove any existing `.eslintrc.json` or `.eslintrc.cjs`), and could contain:
32
+ ```js
33
+ import { generateEslintConfig } from '@companion-module/tools/eslint/config.mjs'
34
+
35
+ export default generateEslintConfig({})
36
+ ```
37
+
38
+ If using typescript, you should specify a `typescriprRoot`
39
+
40
+ ```js
41
+ import { generateEslintConfig } from '@companion-module/tools/eslint/config.mjs'
42
+
43
+ export default generateEslintConfig({
44
+ enableTypescript: true,
45
+ })
46
+ ```
47
+
48
+ You can easily override rules in this setup with:
49
+ ```js
50
+ import { generateEslintConfig } from '@companion-module/tools/eslint/config.mjs'
51
+
52
+ const baseConfig = await generateEslintConfig({
53
+ enableTypescript: true,
54
+ })
55
+
56
+ const customConfig = [
57
+ ...baseConfig,
58
+
59
+ {
60
+ rules: {
61
+ 'n/no-missing-import': 'off',
62
+ 'node/no-unpublished-import': 'off',
63
+ },
64
+ },
65
+ ]
66
+
67
+ export default customConfig
68
+ ```
69
+
70
+ More options are available for the `generateEslintConfig` function, check the wiki or the method signature to see what is available.
@@ -0,0 +1,139 @@
1
+ // @ts-check
2
+
3
+ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
4
+ import eslint from '@eslint/js'
5
+ import neslint from 'eslint-plugin-n'
6
+
7
+ /**
8
+ *
9
+ * @template T
10
+ * @param {Record<string, T | null | undefined>} obj
11
+ * @returns {Record<string, T>}
12
+ */
13
+ function compactObj(obj) {
14
+ /** @type {Record<string, T>} */
15
+ const result = {}
16
+
17
+ for (const [key, value] of Object.entries(obj)) {
18
+ if (value) result[key] = value
19
+ }
20
+
21
+ return result
22
+ }
23
+
24
+ /***
25
+ * @param {{ enableJest?: boolean, enableTypescript?: boolean, ignores?: string[] }} [options={}] - Options to customize the config
26
+ * @returns {Promise<import('eslint').Linter.Config[]>}
27
+ */
28
+ export async function generateEslintConfig(options = {}) {
29
+ const tseslint = options.enableTypescript ? await import('typescript-eslint') : null
30
+
31
+ /** @type {import('eslint').Linter.Config} */
32
+ const result = {
33
+ // extends: commonExtends,
34
+ plugins: compactObj({
35
+ '@typescript-eslint': tseslint ? tseslint.plugin : null,
36
+ }),
37
+ rules: {
38
+ // Default rules to be applied everywhere
39
+ 'prettier/prettier': 'error',
40
+
41
+ ...eslint.configs.recommended.rules,
42
+
43
+ 'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' }],
44
+ 'no-extra-semi': 'off',
45
+ // 'n/no-unsupported-features/es-syntax': ['error', { ignores: ['modules'] }],
46
+ 'no-use-before-define': 'off',
47
+ 'no-warning-comments': ['error', { terms: ['nocommit', '@nocommit', '@no-commit'] }],
48
+ // 'jest/no-mocks-import': 'off',
49
+ },
50
+ }
51
+
52
+ return [
53
+ // setup the parser first
54
+ tseslint
55
+ ? {
56
+ languageOptions: {
57
+ parser: tseslint.parser,
58
+ parserOptions: {
59
+ project: true,
60
+ },
61
+ },
62
+ }
63
+ : null,
64
+
65
+ neslint.configs['flat/recommended-script'],
66
+ result,
67
+ ...(tseslint ? tseslint.configs.recommendedTypeChecked : []),
68
+ {
69
+ // disable type-aware linting on JS files
70
+ files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
71
+ ...(tseslint ? tseslint.configs.disableTypeChecked : {}),
72
+ },
73
+ tseslint
74
+ ? {
75
+ files: ['**/*.ts', '**/*.cts', '**/*.mts'],
76
+ rules: {
77
+ '@typescript-eslint/no-explicit-any': 'off',
78
+ '@typescript-eslint/interface-name-prefix': 'off',
79
+ '@typescript-eslint/no-unused-vars': [
80
+ 'error',
81
+ { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' },
82
+ ],
83
+ '@typescript-eslint/no-floating-promises': 'error',
84
+ '@typescript-eslint/explicit-module-boundary-types': ['error'],
85
+ '@typescript-eslint/promise-function-async': 'error',
86
+ '@typescript-eslint/require-await': 'off', // conflicts with 'promise-function-async'
87
+
88
+ /** Disable some annoyingly strict rules from the 'recommended-requiring-type-checking' pack */
89
+ '@typescript-eslint/no-unsafe-assignment': 0,
90
+ '@typescript-eslint/no-unsafe-member-access': 0,
91
+ '@typescript-eslint/no-unsafe-argument': 0,
92
+ '@typescript-eslint/no-unsafe-return': 0,
93
+ '@typescript-eslint/no-unsafe-call': 0,
94
+ '@typescript-eslint/restrict-template-expressions': 0,
95
+ '@typescript-eslint/restrict-plus-operands': 0,
96
+ '@typescript-eslint/no-redundant-type-constituents': 0,
97
+ /** End 'recommended-requiring-type-checking' overrides */
98
+ },
99
+ }
100
+ : null,
101
+ tseslint
102
+ ? {
103
+ files: ['**/__tests__/**/*', 'test/**/*'],
104
+ rules: {
105
+ '@typescript-eslint/ban-ts-ignore': 'off',
106
+ '@typescript-eslint/ban-ts-comment': 'off',
107
+ },
108
+ }
109
+ : null,
110
+ {
111
+ // disable type-aware linting on JS files
112
+ files: [
113
+ 'examples/**/*.js',
114
+ 'examples/**/*.cjs',
115
+ 'examples/**/*.mjs',
116
+ 'examples/**/*.ts',
117
+ 'examples/**/*.cts',
118
+ 'examples/**/*.mts',
119
+ ],
120
+ rules: {
121
+ 'no-process-exit': 'off',
122
+ 'n/no-missing-import': 'off',
123
+ },
124
+ },
125
+
126
+ // Add prettier at the end to give it final say on formatting
127
+ eslintPluginPrettierRecommended,
128
+ {
129
+ // But lastly, ensure that we ignore certain paths
130
+ ignores: ['**/dist/*', '/dist', '**/pkg/*', '**/docs/*', '**/generated/*', ...(options.ignores || [])],
131
+ },
132
+ {
133
+ files: ['eslint.config.*'],
134
+ rules: {
135
+ 'n/no-unpublished-import': 'off',
136
+ },
137
+ },
138
+ ].filter((v) => !!v)
139
+ }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@companion-module/tools",
3
- "version": "1.5.1",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "repository": "https://github.com/bitfocus/companion-module-tools",
8
8
  "bin": {
9
+ "companion-generate-manifest": "scripts/generate-manifest.js",
9
10
  "companion-module-build": "scripts/build.js",
10
- "companion-module-check": "scripts/check.js",
11
- "companion-generate-manifest": "scripts/generate-manifest.js"
11
+ "companion-module-check": "scripts/check.js"
12
12
  },
13
13
  "engines": {
14
- "node": "^18.12"
14
+ "node": "^18.18"
15
15
  },
16
16
  "files": [
17
17
  "eslint",
@@ -23,21 +23,39 @@
23
23
  "webpack.*"
24
24
  ],
25
25
  "dependencies": {
26
- "@typescript-eslint/eslint-plugin": "^5.59.9",
27
- "@typescript-eslint/parser": "^5.59.9",
28
- "eslint": "^8.56.0",
29
- "eslint-config-prettier": "^8.8.0",
30
- "eslint-plugin-n": "^16.6.2",
31
- "eslint-plugin-prettier": "^4.2.1",
26
+ "@eslint/js": "^9.9.1",
27
+ "eslint-config-prettier": "^9.1.0",
28
+ "eslint-plugin-n": "^17.10.2",
29
+ "eslint-plugin-prettier": "^5.2.1",
32
30
  "find-up": "^7.0.0",
33
31
  "parse-author": "^2.0.0",
34
- "prettier": "^2.8.8",
35
- "tar": "^6.2.1",
36
- "webpack": "^5.90.0",
32
+ "tar": "^7.4.3",
33
+ "webpack": "^5.94.0",
37
34
  "webpack-cli": "^5.1.4",
38
35
  "zx": "^7.2.3"
39
36
  },
40
37
  "peerDependencies": {
41
- "@companion-module/base": "^1.4.1"
42
- }
38
+ "@companion-module/base": "^1.7.1",
39
+ "eslint": "^9.0.0",
40
+ "prettier": "^3.0.0",
41
+ "typescript-eslint": "^8.2.0"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "eslint": {
45
+ "optional": true
46
+ },
47
+ "prettier": {
48
+ "optional": true
49
+ },
50
+ "typescript-eslint": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "@types/eslint": "^9.6.0",
56
+ "eslint": "^9.9.1",
57
+ "prettier": "^3.3.3",
58
+ "typescript-eslint": "^8.2.0"
59
+ },
60
+ "packageManager": "yarn@4.4.1"
43
61
  }
@@ -1,62 +0,0 @@
1
- function compact(arr) {
2
- return arr.filter((v) => v !== undefined && v !== null)
3
- }
4
-
5
- module.exports = function createFragments(enableJest) {
6
- return {
7
- commonPlugins: compact(['prettier', enableJest ? 'jest' : null]),
8
- tsPlugins: compact(['@typescript-eslint', 'prettier', enableJest ? 'jest' : null]),
9
-
10
- commonExtends: ['eslint:recommended', 'plugin:n/recommended', 'plugin:prettier/recommended'],
11
- tsExtends: compact([
12
- 'eslint:recommended',
13
- 'plugin:@typescript-eslint/eslint-recommended',
14
- 'plugin:@typescript-eslint/recommended',
15
- 'plugin:@typescript-eslint/recommended-requiring-type-checking',
16
- 'plugin:n/recommended',
17
- enableJest ? 'plugin:jest/recommended' : null,
18
- 'prettier',
19
- 'plugin:prettier/recommended',
20
- ]),
21
-
22
- commonRules: {
23
- 'prettier/prettier': 'error',
24
- 'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' }],
25
- 'no-extra-semi': 'off',
26
- 'n/no-unsupported-features/es-syntax': ['error', { ignores: ['modules'] }],
27
- 'no-use-before-define': 'off',
28
- 'no-warning-comments': ['error', { terms: ['nocommit', '@nocommit', '@no-commit'] }],
29
- 'jest/no-mocks-import': 'off',
30
- },
31
- tsRules: {
32
- 'no-unused-vars': 'off',
33
- '@typescript-eslint/no-explicit-any': 'off',
34
- '@typescript-eslint/interface-name-prefix': 'off',
35
- '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' }],
36
- '@typescript-eslint/no-floating-promises': 'error',
37
- '@typescript-eslint/explicit-module-boundary-types': ['error'],
38
- '@typescript-eslint/promise-function-async': 'error',
39
- '@typescript-eslint/require-await': 'off', // conflicts with 'promise-function-async'
40
-
41
- /** Disable some annoyingly strict rules from the 'recommended-requiring-type-checking' pack */
42
- '@typescript-eslint/no-unsafe-assignment': 0,
43
- '@typescript-eslint/no-unsafe-member-access': 0,
44
- '@typescript-eslint/no-unsafe-argument': 0,
45
- '@typescript-eslint/no-unsafe-return': 0,
46
- '@typescript-eslint/no-unsafe-call': 0,
47
- '@typescript-eslint/restrict-template-expressions': 0,
48
- '@typescript-eslint/restrict-plus-operands': 0,
49
- /** End 'recommended-requiring-type-checking' overrides */
50
- },
51
-
52
- tsParser: {
53
- parser: '@typescript-eslint/parser',
54
- parserOptions: { project: './tsconfig.json' },
55
- settings: {
56
- node: {
57
- tryExtensions: ['.js', '.json', '.node', '.ts', '.d.ts'],
58
- },
59
- },
60
- },
61
- }
62
- }
package/eslint/index.cjs DELETED
@@ -1,96 +0,0 @@
1
- const createFragments = require('./fragments.cjs')
2
-
3
- module.exports = function generateEslintConfig(options = {}) {
4
- const { commonPlugins, tsPlugins, commonExtends, tsExtends, commonRules, tsRules, tsParser } = createFragments(
5
- options.enableJest
6
- )
7
-
8
- const disableJest = options.enableJest
9
- ? {
10
- 'jest/globals': false, // Block jest from this
11
- }
12
- : {}
13
- const allowJest = options.enableJest
14
- ? {
15
- 'jest/globals': true,
16
- jest: true,
17
- }
18
- : {}
19
-
20
- const result = {
21
- extends: commonExtends,
22
- plugins: commonPlugins,
23
- rules: {
24
- 'prettier/prettier': 'error',
25
- },
26
- env: { es2017: true },
27
- parserOptions: { sourceType: 'module', ecmaVersion: 2022 },
28
- overrides: [
29
- // Note: the overrides replace the values defined above, so make sure to extend them if they are needed
30
- {
31
- files: ['*.js', '*.cjs', '*.mjs'],
32
- settings: {
33
- node: {
34
- tryExtensions: ['.js', '.json', '.node', '.ts'],
35
- },
36
- },
37
- env: {
38
- ...disableJest,
39
- },
40
- rules: {
41
- ...commonRules,
42
- },
43
- },
44
- ],
45
- }
46
-
47
- if (options.enableTypescript) {
48
- result.overrides.push(
49
- {
50
- files: ['*.ts'],
51
- extends: tsExtends,
52
- plugins: tsPlugins,
53
- ...tsParser,
54
- env: {
55
- ...disableJest,
56
- },
57
- rules: {
58
- ...commonRules,
59
- ...tsRules,
60
- },
61
- },
62
- {
63
- files: ['src/**/__tests__/**/*.ts'],
64
- extends: tsExtends,
65
- plugins: tsPlugins,
66
- ...tsParser,
67
- env: {
68
- ...allowJest,
69
- },
70
- rules: {
71
- ...commonRules,
72
- ...tsRules,
73
- '@typescript-eslint/ban-ts-ignore': 'off',
74
- '@typescript-eslint/ban-ts-comment': 'off',
75
- },
76
- },
77
- {
78
- files: ['examples/**/*.ts'],
79
- extends: tsExtends,
80
- plugins: tsPlugins,
81
- ...tsParser,
82
- env: {
83
- ...disableJest,
84
- },
85
- rules: {
86
- ...commonRules,
87
- ...tsRules,
88
- 'no-process-exit': 'off',
89
- 'n/no-missing-import': 'off',
90
- },
91
- }
92
- )
93
- }
94
-
95
- return result
96
- }
package/eslint/main.cjs DELETED
@@ -1,6 +0,0 @@
1
- const generateEslintConfig = require('./index.cjs')
2
-
3
- /**
4
- * @deprecated use the line like below to generate your own config
5
- */
6
- module.exports = generateEslintConfig({ enableTypescript: true })