@travetto/eslint 3.4.2 → 4.0.0-rc.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/README.md CHANGED
@@ -32,11 +32,14 @@ This is the file the linter will use, and any other tooling (e.g. IDEs).
32
32
  **Code: Sample configuration**
33
33
  ```javascript
34
34
  process.env.TRV_MANIFEST = './.trv/output/node_modules/@travetto/eslint';
35
+
35
36
  const { buildConfig } = require('./.trv/output/node_modules/@travetto/eslint/support/bin/eslint-config.js');
36
- const { RootIndex } = require('./.trv/output/node_modules/@travetto/manifest/__index__.js');
37
- const pluginFiles = RootIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
37
+ const { RuntimeIndex } = require('./.trv/output/node_modules/@travetto/manifest/__index__.js');
38
+
39
+ const pluginFiles = RuntimeIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
38
40
  const plugins = pluginFiles.map(x => require(x.outputFile));
39
41
  const config = buildConfig(plugins);
42
+
40
43
  module.exports = config;
41
44
  ```
42
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/eslint",
3
- "version": "3.4.2",
3
+ "version": "4.0.0-rc.0",
4
4
  "description": "ES Linting Rules",
5
5
  "keywords": [
6
6
  "eslint",
@@ -16,6 +16,7 @@
16
16
  "main": "__index__.ts",
17
17
  "files": [
18
18
  "support",
19
+ "resources",
19
20
  "__index__.ts"
20
21
  ],
21
22
  "repository": {
@@ -24,16 +25,16 @@
24
25
  },
25
26
  "dependencies": {
26
27
  "@eslint/js": "^8.52.0",
27
- "@travetto/manifest": "^3.4.0",
28
- "@types/eslint": "^8.44.7",
28
+ "@travetto/manifest": "^4.0.0-rc.0",
29
+ "@types/eslint": "^8.44.8",
29
30
  "@types/eslint__js": "^8.42.3",
30
- "@typescript-eslint/eslint-plugin": "^6.11.0",
31
- "@typescript-eslint/parser": "^6.11.0",
32
- "eslint": "^8.54.0",
31
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
32
+ "@typescript-eslint/parser": "^6.13.2",
33
+ "eslint": "^8.55.0",
33
34
  "eslint-plugin-unused-imports": "^3.0.0"
34
35
  },
35
36
  "peerDependencies": {
36
- "@travetto/cli": "^3.4.3"
37
+ "@travetto/cli": "^4.0.0-rc.0"
37
38
  },
38
39
  "peerDependenciesMeta": {
39
40
  "@travetto/cli": {
@@ -0,0 +1,10 @@
1
+ process.env.TRV_MANIFEST = '%MANIFEST_FILE%';
2
+
3
+ const { buildConfig } = require('@travetto/eslint/support/bin/eslint-config');
4
+ const { RuntimeIndex } = require('@travetto/manifest/__index__');
5
+
6
+ const pluginFiles = RuntimeIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
7
+ const plugins = pluginFiles.map(x => require(x.outputFile));
8
+ const config = buildConfig(plugins);
9
+
10
+ module.exports = config;
@@ -0,0 +1,10 @@
1
+ process.env.TRV_MANIFEST = '%MANIFEST_FILE%';
2
+
3
+ const { buildConfig } = await import('@travetto/eslint/support/bin/eslint-config');
4
+ const { RuntimeIndex } = await import('@travetto/manifest/__index__');
5
+
6
+ const pluginFiles = RuntimeIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
7
+ const plugins = await Promise.all(pluginFiles.map(x => import(x.outputFile)))
8
+ const config = buildConfig(plugins);
9
+
10
+ export default config;
@@ -1,11 +1,11 @@
1
1
  import * as parser from '@typescript-eslint/parser';
2
2
 
3
- import { RootIndex } from '@travetto/manifest';
3
+ import { RuntimeContext } from '@travetto/manifest';
4
4
 
5
5
  export const RULE_COMMON = {
6
6
  languageOptions: {
7
7
  ecmaVersion: 'latest',
8
- sourceType: RootIndex.manifest.moduleType,
8
+ sourceType: RuntimeContext.workspace.type,
9
9
  globals: {
10
10
  AbortController: false,
11
11
  AbortSignal: false,
@@ -1,39 +1,13 @@
1
- import path from 'path';
1
+ import fs from 'node:fs/promises';
2
2
 
3
- import { RootIndex } from '@travetto/manifest';
3
+ import { RuntimeContext, RuntimeIndex, path } from '@travetto/manifest';
4
4
 
5
- export function buildEslintConfig(): string {
6
- const rulesImp = RootIndex.resolveFileImport('@travetto/eslint/support/bin/eslint-config.ts');
7
- const manifestImp = RootIndex.resolveFileImport('@travetto/manifest/__index__.ts');
8
- const manifestFile = RootIndex.mainModule.outputPath;
5
+ export async function buildEslintConfig(): Promise<string> {
6
+ const root = RuntimeIndex.getModule('@travetto/eslint')!.sourcePath;
7
+ const ext = RuntimeContext.workspace.type === 'commonjs' ? '.cjs' : '.mjs';
8
+ const tpl = await fs.readFile(path.resolve(root, 'resources', `eslint-config-file${ext}`), 'utf8');
9
9
 
10
- const common = {
11
- manifest: `process.env.TRV_MANIFEST = '${path.resolve(manifestFile)}'`,
12
- pluginFiles: "const pluginFiles = RootIndex.find({ folder: f => f === 'support', file: f => /support\\/eslint[.]/.test(f) })",
13
- build: 'const config = buildConfig(plugins)',
14
- };
15
-
16
- const lines = RootIndex.manifest.moduleType === 'commonjs' ?
17
- [
18
- common.manifest,
19
- `const { buildConfig } = require('${rulesImp}')`,
20
- `const { RootIndex } = require('${manifestImp}')`,
21
- common.pluginFiles,
22
- 'const plugins = pluginFiles.map(x => require(x.outputFile))',
23
- common.build,
24
- 'module.exports = config',
25
- ''
26
- ] :
27
- [
28
- common.manifest,
29
- `const { buildConfig } = await import('${rulesImp}')`,
30
- `const { RootIndex } = await import('${manifestImp}')`,
31
- common.pluginFiles,
32
- 'const plugins = await Promise.all(pluginFiles.map(x => import(x.outputFile)))',
33
- common.build,
34
- 'export default config',
35
- ''
36
- ];
37
-
38
- return lines.join(';\n');
10
+ return tpl
11
+ .replace(/'(@travetto\/[^']+)'/g, (_, v) => `'${RuntimeIndex.resolveFileImport(v)}'`)
12
+ .replace('%MANIFEST_FILE%', RuntimeIndex.mainModule.outputPath);
39
13
  }
@@ -1,10 +1,11 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+
1
3
  // @ts-expect-error
2
4
  import * as unused from 'eslint-plugin-unused-imports';
3
5
  import { configs } from '@eslint/js';
4
6
  import * as tsEslintPlugin from '@typescript-eslint/eslint-plugin';
5
- import { existsSync, readFileSync } from 'fs';
6
7
 
7
- import { path, RootIndex } from '@travetto/manifest';
8
+ import { RuntimeContext } from '@travetto/manifest';
8
9
 
9
10
  import { IGNORES, RULE_COMMON } from './eslint-common';
10
11
  import { STD_RULES } from './eslint-std-rules';
@@ -19,7 +20,7 @@ export function buildConfig(pluginMaps: Record<string, TrvEslintPlugin>[]): read
19
20
  }
20
21
  }
21
22
 
22
- const overrides = path.resolve(RootIndex.manifest.workspacePath, 'eslint-overrides.json');
23
+ const overrides = RuntimeContext.workspaceRelative('eslint-overrides.json');
23
24
 
24
25
  const extra: (typeof STD_RULES)[] = existsSync(overrides) ? JSON.parse(readFileSync(overrides, 'utf8')) : [];
25
26
 
@@ -1,5 +1,5 @@
1
- import { RootIndex } from '@travetto/manifest';
2
- import { ExecUtil, EnvInit } from '@travetto/base';
1
+ import { RuntimeContext } from '@travetto/manifest';
2
+ import { Env, ExecUtil } from '@travetto/base';
3
3
  import { CliCommandShape, CliCommand, CliModuleUtil, CliScmUtil } from '@travetto/cli';
4
4
 
5
5
  /**
@@ -17,8 +17,8 @@ export class LintCommand implements CliCommandShape {
17
17
  /** Since a specific git commit */
18
18
  since?: string;
19
19
 
20
- envInit(): EnvInit {
21
- return { debug: false };
20
+ preMain(): void {
21
+ Env.DEBUG.set(false);
22
22
  }
23
23
 
24
24
  async main(): Promise<void> {
@@ -37,7 +37,7 @@ export class LintCommand implements CliCommandShape {
37
37
  ...(this.format ? ['--format', this.format] : []),
38
38
  ...files
39
39
  ], {
40
- cwd: RootIndex.manifest.workspacePath,
40
+ cwd: RuntimeContext.workspace.path,
41
41
  stdio: 'inherit',
42
42
  catchAsResult: true
43
43
  }).result;
@@ -1,7 +1,7 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
3
  import { CliCommandShape, CliCommand } from '@travetto/cli';
4
- import { path, RootIndex } from '@travetto/manifest';
4
+ import { RuntimeContext } from '@travetto/manifest';
5
5
 
6
6
  import { buildEslintConfig } from './bin/eslint-config-file';
7
7
 
@@ -12,9 +12,9 @@ import { buildEslintConfig } from './bin/eslint-config-file';
12
12
  export class LintConfigureCommand implements CliCommandShape {
13
13
 
14
14
  async main(): Promise<void> {
15
- const content = buildEslintConfig();
16
- const output = path.resolve(RootIndex.manifest.workspacePath, 'eslint.config.js');
17
- await fs.writeFile(output, content.replaceAll(RootIndex.manifest.workspacePath, '.').trim());
15
+ const content = await buildEslintConfig();
16
+ const output = RuntimeContext.workspaceRelative('eslint.config.js');
17
+ await fs.writeFile(output, content.replaceAll(RuntimeContext.workspace.path, '.').trim());
18
18
 
19
19
  console.log(`Wrote eslint config to ${output}`);
20
20
  }