Skip to content

Commit 6301da9

Browse files
committed
module-style dependencies?
1 parent acc0363 commit 6301da9

File tree

6 files changed

+37
-83
lines changed

6 files changed

+37
-83
lines changed

.github/workflows/pkg.pr.new.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ jobs:
2727
- run: corepack enable
2828
- run: pnpm install
2929
- run: pnpm build
30-
- run: pnpm add https://pkg.pr.new/mmkal/eslint-plugin-codegen@${{ needs.publish.outputs.hash }}
30+
- name: install pkg-pr-new codegen plugin
31+
run: pnpm add https://pkg.pr.new/mmkal/eslint-plugin-codegen@${{ needs.publish.outputs.hash }}
32+
- name: shim
33+
run: echo 'export * as codegen from "eslint-plugin-codegen"' >> src/index.ts
34+
- run: pnpm build
3135
- name: git
3236
run: |
3337
git config --global user.name "${{ github.actor }}"

src/dependencies.ts

Lines changed: 25 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,30 @@
1-
import * as babelGenerator from '@babel/generator'
2-
import * as babelParser from '@babel/parser'
3-
import * as babelTraverse from '@babel/traverse'
4-
import * as babelTypes from '@babel/types'
5-
import * as cheerio from 'cheerio'
6-
import * as child_process from 'child_process'
7-
import dedent from 'dedent'
8-
import esquery from 'esquery'
1+
export * as babelGenerator from '@babel/generator'
2+
export * as babelParser from '@babel/parser'
3+
export * as babelTraverse from '@babel/traverse'
4+
export * as babelTypes from '@babel/types'
5+
export * as cheerio from 'cheerio'
6+
export * as child_process from 'child_process'
7+
export {default as dedent} from 'dedent'
8+
export {default as esquery} from 'esquery'
99
// eslint-disable-next-line no-restricted-imports
10-
import * as fs from 'fs'
11-
import * as glob from 'glob'
12-
import * as isomorphicGit from 'isomorphic-git'
13-
import * as jsYaml from 'js-yaml'
14-
import lodash from 'lodash'
15-
import * as memfs from 'memfs'
10+
export * as fs from 'fs'
11+
export * as glob from 'glob'
12+
export * as isomorphicGit from 'isomorphic-git'
13+
export * as jsYaml from 'js-yaml'
14+
export {default as lodash} from 'lodash'
15+
16+
export * as memfs from 'memfs'
1617
import * as path from 'path'
17-
import * as readPkgUp from 'read-pkg-up'
18-
import * as recast from 'recast'
19-
import * as unionfs from 'unionfs'
20-
import * as zx from 'zx'
21-
import * as esmModules from './esm-modules'
22-
import {fetchSync} from './fetch-sync'
23-
import {makeSynchronous} from './make-synchronous'
24-
import * as simplify from './simplify'
2518

26-
/*eslint sort-keys: "error"*/
19+
export {default as readPkgUp} from 'read-pkg-up'
20+
export * as recast from 'recast'
21+
export * as unionfs from 'unionfs'
22+
export * as zx from 'zx'
23+
export {arktype} from './esm-modules'
24+
export {fetchSync} from './fetch-sync'
25+
export {makeSynchronous} from './make-synchronous'
2726

28-
export interface PresetDependencies {
29-
arktype: typeof esmModules.arktype
30-
babelGenerator: typeof import('./types/babel-generator')
31-
babelParser: typeof import('@babel/parser')
32-
babelTraverse: typeof import('@babel/traverse')
33-
babelTypes: typeof import('@babel/types')
34-
cheerio: typeof import('cheerio')
35-
child_process: typeof import('child_process')
36-
dedent: typeof import('dedent').default
37-
esquery: typeof import('esquery')
38-
fetchSync: typeof import('./fetch-sync').fetchSync
39-
fs: typeof import('fs')
40-
glob: Pick<typeof import('glob'), 'globSync'>
41-
isomorphicGit: typeof import('isomorphic-git')
42-
jsYaml: typeof import('js-yaml')
43-
lodash: typeof import('lodash')
44-
makeSynchronous: typeof import('./make-synchronous').makeSynchronous
45-
memfs: typeof import('memfs')
46-
path: typeof import('path')
47-
readPkgUp: Pick<typeof import('read-pkg-up'), 'sync'>
48-
recast: typeof import('recast')
49-
/** require an arbitrary module *from eslint-plugin-codegen* - this means you can require dependencies of the plugin even when they're not your dependencies */
50-
require: <T = unknown>(path: string) => T
51-
simplify: typeof import('./simplify')
52-
unionfs: typeof import('unionfs')
53-
zx: typeof import('zx')
54-
}
27+
export * as simplify from './simplify'
5528

56-
export const dependencies: PresetDependencies = {
57-
...esmModules,
58-
babelGenerator: babelGenerator as never,
59-
babelParser,
60-
babelTraverse,
61-
babelTypes,
62-
cheerio,
63-
child_process,
64-
dedent: Object.assign(dedent, {default: dedent}), // backcompat: accidentally used `import * as dedent from 'dedent'` previously
65-
esquery,
66-
fetchSync,
67-
fs,
68-
glob,
69-
isomorphicGit,
70-
jsYaml,
71-
lodash,
72-
makeSynchronous,
73-
memfs,
74-
path,
75-
readPkgUp,
76-
recast,
77-
// eslint-disable-next-line @typescript-eslint/no-require-imports
78-
require: <T>(modulePath: string) => require(modulePath) as T,
79-
simplify,
80-
unionfs,
81-
zx,
82-
}
29+
// eslint-disable-next-line unicorn/prefer-export-from
30+
export {path}

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {codegen} from './rule'
55

66
// idea: codegen/fs rule. type fs.anything and it generates an import for fs. same for path and os.
77

8-
export type {Preset} from './presets'
8+
export type {Preset, PresetDependencies} from './presets'
99
export type {DefinePreset} from './presets/util/standard-schema-preset'
1010

1111
const processor = createProcessor()
@@ -40,3 +40,5 @@ export * from './flat-config'
4040
export * as presets from './presets'
4141

4242
export * as flatConfig from './config'
43+
44+
export * as dependencies from './dependencies'

src/presets/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {StringValue} from 'ms'
2-
import type {PresetDependencies} from '../dependencies'
2+
import * as dependencies from '../dependencies'
33

4-
export type {PresetDependencies} from '../dependencies'
4+
export type PresetDependencies = typeof dependencies
55

66
export type PresetMeta = {
77
sourceCode: string

src/rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ms from 'ms'
88
import * as os from 'os'
99
import * as path from 'path'
1010
import stripAnsi from 'strip-ansi'
11-
import {dependencies} from './dependencies'
11+
import * as dependencies from './dependencies'
1212
import * as presetsModule from './presets'
1313
import {equivalentSimplified} from './simplify'
1414

test/simplify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {test, expect} from 'vitest'
2-
import {dependencies} from '../src/dependencies'
2+
import * as dependencies from '../src/dependencies'
33
import {simplifyCode} from '../src/simplify'
44

55
test('simplifyCode', async () => {

0 commit comments

Comments
 (0)