Skip to content

Commit ab6cd95

Browse files
committed
[New] add --entrypoints-legacy CLI command
1 parent 8d66a58 commit ab6cd95

File tree

9 files changed

+160
-3
lines changed

9 files changed

+160
-3
lines changed

.changeset/violet-bananas-own.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@arethetypeswrong/cli": minor
3+
"@arethetypeswrong/core": minor
4+
---
5+
6+
add `--entrypoints-legacy` option

packages/cli/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ In the config file, `format` can be a string value.
132132

133133
#### Entrypoints
134134

135-
`attw` automatically discovers package entrypoints by looking at package.json `exports` and subdirectories with additional package.json files. This automatic discovery process can be overridden with the `--entrypoints` option, or altered with the `--include-entrypoints` and `--exclude-entrypoints` options:
135+
`attw` automatically discovers package entrypoints by looking at package.json `exports` and subdirectories with additional package.json files. In a package lacking `exports`, providing the `--entrypoints-legacy` option will include all published code files. This automatic discovery process can be overridden with the `--entrypoints` option, or altered with the `--include-entrypoints` and `--exclude-entrypoints` options:
136136

137137
```shell
138138
attw --pack . --entrypoints . one two three # Just ".", "./one", "./two", "./three"
139139
attw --pack . --include-entrypoints added # Auto-discovered entyrpoints plus "./added"
140140
attw --pack . --exclude-entrypoints styles.css # Auto-discovered entrypoints except "./styles.css"
141+
attw --pack . --entrypoints-legacy # All published code files
141142
```
142143

143144
#### Ignore Rules

packages/cli/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface Opts extends render.RenderOptions {
3737
entrypoints?: string[];
3838
includeEntrypoints?: string[];
3939
excludeEntrypoints?: string[];
40+
entrypointsLegacy?: boolean;
4041
}
4142

4243
program
@@ -71,6 +72,11 @@ particularly ESM-related module resolution issues.`,
7172
"Specify entrypoints to check in addition to automatically discovered ones.",
7273
)
7374
.option("--exclude-entrypoints <entrypoints...>", "Specify entrypoints to exclude from checking.")
75+
.option(
76+
"--entrypoints-legacy",
77+
'In packages without the `exports` field, every file is an entry point. Specifying this option ' +
78+
'only takes effect when no entrypoints are automatically detected, or explicitly provided with other options.'
79+
)
7480
.addOption(
7581
new Option("--ignore-rules <rules...>", "Specify rules to ignore").choices(Object.values(problemFlags)).default([]),
7682
)
@@ -127,6 +133,7 @@ particularly ESM-related module resolution issues.`,
127133
entrypoints: opts.entrypoints,
128134
includeEntrypoints: opts.includeEntrypoints,
129135
excludeEntrypoints: opts.excludeEntrypoints,
136+
entrypointsLegacy: opts.entrypointsLegacy,
130137
});
131138
}
132139
} catch (error) {
@@ -189,6 +196,7 @@ particularly ESM-related module resolution issues.`,
189196
entrypoints: opts.entrypoints,
190197
includeEntrypoints: opts.includeEntrypoints,
191198
excludeEntrypoints: opts.excludeEntrypoints,
199+
entrypointsLegacy: opts.entrypointsLegacy,
192200
});
193201
} catch (error) {
194202
handleError(error, "checking file");

packages/cli/test/snapshots.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const tests = [
4040
4141
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
4242
],
43+
44+
["[email protected]", "--entrypoints-legacy --ignore-rules=cjs-only-exports-default"],
4345
];
4446

4547
const defaultOpts = "-f table-flipped";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# [email protected] --entrypoints-legacy --ignore-rules=cjs-only-exports-default
2+
3+
```
4+
$ attw [email protected] --entrypoints-legacy --ignore-rules=cjs-only-exports-default
5+
6+
7+
eslint-module-utils v2.8.1
8+
9+
Build tools:
10+
- typescript@next
11+
12+
(ignoring rules: 'cjs-only-exports-default')
13+
14+
No problems found 🌟
15+
16+
17+
┌─────────────────────────────────────────┬────────┬───────────────────┬───────────────────┬─────────┐
18+
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
19+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
20+
│ "eslint-module-utils/declaredScope.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
21+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
22+
│ "eslint-module-utils/hash.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
23+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
24+
│ "eslint-module-utils/ignore.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
25+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
26+
│ "eslint-module-utils/module-require.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
27+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
28+
│ "eslint-module-utils/ModuleCache.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
29+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
30+
│ "eslint-module-utils/moduleVisitor.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
31+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
32+
│ "eslint-module-utils/parse.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
33+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
34+
│ "eslint-module-utils/pkgDir.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
35+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
36+
│ "eslint-module-utils/pkgUp.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
37+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
38+
│ "eslint-module-utils/readPkgUp.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
39+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
40+
│ "eslint-module-utils/resolve.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
41+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
42+
│ "eslint-module-utils/unambiguous.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
43+
├─────────────────────────────────────────┼────────┼───────────────────┼───────────────────┼─────────┤
44+
│ "eslint-module-utils/visit.js" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
45+
└─────────────────────────────────────────┴────────┴───────────────────┴───────────────────┴─────────┘
46+
47+
48+
```
49+
50+
Exit code: 0

packages/core/src/checkPackage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export interface CheckPackageOptions {
2828
* Entrypoints to exclude from checking.
2929
*/
3030
excludeEntrypoints?: (string | RegExp)[];
31+
32+
/**
33+
* Whether to automatically consider all published files as entrypoints
34+
* in the absence of any other detected or configured entrypoints.
35+
*/
36+
entrypointsLegacy?: boolean;
3137
}
3238

3339
export async function checkPackage(pkg: Package, options?: CheckPackageOptions): Promise<CheckResult> {

packages/core/src/internal/getEntrypointInfo.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ import type {
1313
import { allBuildTools, getResolutionKinds } from "../utils.js";
1414
import type { CheckPackageOptions } from "../checkPackage.js";
1515

16-
function getEntrypoints(fs: Package, exportsObject: any, options: CheckPackageOptions | undefined): string[] {
16+
const extensions = new Set([".jsx", ".tsx", ".js", ".ts", ".mjs", ".cjs", ".mts", ".cjs"]);
17+
18+
function getEntrypoints(fs: Package, exportsObject: unknown, options: CheckPackageOptions | undefined): string[] {
1719
if (options?.entrypoints) {
1820
return options.entrypoints.map((e) => formatEntrypointString(e, fs.packageName));
1921
}
2022
if (exportsObject === undefined && fs) {
21-
const proxies = getProxyDirectories(`/node_modules/${fs.packageName}`, fs);
23+
const rootDir = `/node_modules/${fs.packageName}`;
24+
const proxies = getProxyDirectories(rootDir, fs);
2225
if (proxies.length === 0) {
26+
if (options?.entrypointsLegacy) {
27+
return fs.listFiles()
28+
.filter(f => !ts.isDeclarationFileName(f) && extensions.has(f.slice(f.lastIndexOf("."))))
29+
.map(f => "." + f.slice(rootDir.length));
30+
}
2331
return ["."];
2432
}
2533
return proxies;
15.2 KB
Binary file not shown.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"packageName": "eslint-module-utils",
3+
"packageVersion": "2.8.1",
4+
"types": {
5+
"kind": "included"
6+
},
7+
"buildTools": {
8+
"typescript": "next"
9+
},
10+
"entrypoints": {
11+
".": {
12+
"subpath": ".",
13+
"resolutions": {
14+
"node10": {
15+
"name": ".",
16+
"resolutionKind": "node10",
17+
"visibleProblems": [
18+
0
19+
]
20+
},
21+
"node16-cjs": {
22+
"name": ".",
23+
"resolutionKind": "node16-cjs",
24+
"visibleProblems": [
25+
1
26+
]
27+
},
28+
"node16-esm": {
29+
"name": ".",
30+
"resolutionKind": "node16-esm",
31+
"visibleProblems": [
32+
2
33+
]
34+
},
35+
"bundler": {
36+
"name": ".",
37+
"resolutionKind": "bundler",
38+
"visibleProblems": [
39+
3
40+
]
41+
}
42+
},
43+
"hasTypes": false,
44+
"isWildcard": false
45+
}
46+
},
47+
"programInfo": {
48+
"node10": {},
49+
"node16": {
50+
"moduleKinds": {}
51+
},
52+
"bundler": {}
53+
},
54+
"problems": [
55+
{
56+
"kind": "NoResolution",
57+
"entrypoint": ".",
58+
"resolutionKind": "node10"
59+
},
60+
{
61+
"kind": "NoResolution",
62+
"entrypoint": ".",
63+
"resolutionKind": "node16-cjs"
64+
},
65+
{
66+
"kind": "NoResolution",
67+
"entrypoint": ".",
68+
"resolutionKind": "node16-esm"
69+
},
70+
{
71+
"kind": "NoResolution",
72+
"entrypoint": ".",
73+
"resolutionKind": "bundler"
74+
}
75+
]
76+
}

0 commit comments

Comments
 (0)