Skip to content

Commit c66461f

Browse files
authored
Merge pull request #82 from arethetypeswrong/build-tools
Report build tools detected in package.json
2 parents a27200e + b2a3251 commit c66461f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+40096
-4717
lines changed

.changeset/moody-dancers-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/cli": minor
3+
---
4+
5+
Report relevant build tools detected in package.json `devDependencies`

.changeset/thin-moles-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": minor
3+
---
4+
5+
Add `buildTools` property to `Analysis` (a pick of `devDependencies`)

packages/cli/src/render/typed.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ export async function typed(analysis: core.Analysis, opts: Opts) {
2121
headerIds: false,
2222
});
2323

24+
console.log(`${analysis.packageName} v${analysis.packageVersion}`);
25+
if (analysis.types.kind === "@types") {
26+
console.log(`${analysis.types.packageName} v${analysis.types.packageVersion}`);
27+
}
28+
console.log();
29+
if (Object.keys(analysis.buildTools).length) {
30+
console.log("Build tools:");
31+
console.log(
32+
Object.entries(analysis.buildTools)
33+
.map(([tool, version]) => {
34+
return `- ${tool}@${version}`;
35+
})
36+
.join("\n")
37+
);
38+
console.log();
39+
}
40+
2441
if (opts.ignoreRules && opts.ignoreRules.length) {
2542
console.log(
2643
chalk.gray(
@@ -31,12 +48,6 @@ export async function typed(analysis: core.Analysis, opts: Opts) {
3148
);
3249
}
3350

34-
console.log(`${analysis.packageName} v${analysis.packageVersion}`);
35-
if (analysis.types.kind === "@types") {
36-
console.log(`${analysis.types.packageName} v${analysis.types.packageVersion}`);
37-
}
38-
console.log();
39-
4051
if (opts.summary) {
4152
const defaultSummary = marked(!opts.emoji ? " No problems found" : " No problems found 🌟");
4253
const summaryTexts = Object.keys(grouped).map((kind) => {

packages/cli/test/snapshots/@apollo__client-3.7.16.tgz.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ $ attw @apollo__client-3.7.16.tgz -f table-flipped
66
77
@apollo/client v3.7.16
88
9+
Build tools:
10+
11+
12+
913
👺 Import resolved to an ESM type declaration file, but a CommonJS JavaScript file. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md
1014
1115
⚠️ A require call resolved to an ESM JavaScript file, which is an error in Node and some bundlers. CommonJS consumers will need to use a dynamic import. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSResolvesToESM.md

packages/cli/test/snapshots/@[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ $ attw @[email protected] -f table-flipped
66
77
@ice/app v3.2.6
88
9+
Build tools:
10+
- webpack@^5.86.0
11+
- esbuild@^0.17.16
12+
913
⚠️ A require call resolved to an ESM JavaScript file, which is an error in Node and some bundlers. CommonJS consumers will need to use a dynamic import. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSResolvesToESM.md
1014
1115
💀 Import failed to resolve to type declarations or JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md

packages/cli/test/snapshots/@[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ $ attw @[email protected] -f table-flipped
66
77
@reduxjs/toolkit v2.0.0-beta.0
88
9+
Build tools:
10+
- typescript@~4.9
11+
- @microsoft/api-extractor@^7.13.2
12+
913
🎭 Import resolved to a CommonJS type declaration file, but an ESM JavaScript file. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md
1014
1115
🥴 Import found in a type declaration file failed to resolve. Either this indicates that runtime resolution errors will occur, or (more likely) the types misrepresent the contents of the JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/InternalResolutionError.md

packages/cli/test/snapshots/[email protected]

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ $ attw [email protected] -f table-flipped
66
77
ajv v8.12.0
88
9+
Build tools:
10+
- typescript@^4.8.0
11+
- rollup@^2.44.0
12+
- @rollup/plugin-typescript@^10.0.1
13+
914
No problems found 🌟
1015
1116

packages/cli/test/snapshots/[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ $ attw [email protected] -f table-flipped
66
77
axios v1.4.0
88
9+
Build tools:
10+
- typescript@^4.8.4
11+
- rollup@^2.67.0
12+
913
❓ Wildcard subpaths cannot yet be analyzed by this tool. https://github.com/arethetypeswrong/arethetypeswrong.github.io/issues/40
1014
1115
💀 Import failed to resolve to type declarations or JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md

packages/cli/test/snapshots/[email protected] -f table.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ $ attw [email protected] -f table
66
77
commander v10.0.1
88
9+
Build tools:
10+
- typescript@^4.9.4
11+
912
🎭 Import resolved to a CommonJS type declaration file, but an ESM JavaScript file. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md
1013
1114
❌ Import resolved to JavaScript files, but no type declarations were found. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md

packages/cli/test/snapshots/[email protected]

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ $ attw [email protected] -f table-flipped
66
77
node-html-parser v6.1.5
88
9+
Build tools:
10+
- typescript@latest
11+
912
🤨 CommonJS module simulates a default export with exports.default and exports.__esModule, but does not also set module.exports for compatibility with Node. Node, and some bundlers under certain conditions (https://andrewbranch.github.io/interop-test/#synthesizing-default-exports-for-cjs-modules), do not respect the __esModule marker, so accessing the intended default export will require a .default property access on the default import. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSOnlyExportsDefault.md
1013
1114

packages/core/src/checkPackage.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import type { Package } from "./createPackage.js";
66
import { createCompilerHosts, type CompilerHosts, CompilerHostWrapper } from "./multiCompilerHost.js";
77
import type {
88
AnalysisTypes,
9+
BuildTool,
910
CheckResult,
1011
EntrypointInfo,
1112
EntrypointResolutionAnalysis,
1213
Resolution,
1314
ResolutionKind,
1415
} from "./types.js";
16+
import { allBuildTools } from "./utils.js";
1517

1618
export interface CheckPackageOptions {
1719
/**
@@ -56,6 +58,7 @@ export async function checkPackage(pkg: Package, options?: CheckPackageOptions):
5658
packageName,
5759
packageVersion,
5860
types,
61+
buildTools: getBuildTools(JSON.parse(pkg.readFile(`/node_modules/${packageName}/package.json`))),
5962
entrypoints: entrypointResolutions,
6063
problems: [...entrypointResolutionProblems, ...resolutionBasedFileProblems, ...fileProblems],
6164
};
@@ -221,3 +224,16 @@ function getEntrypointResolution(
221224
function unique<T>(array: readonly T[]): T[] {
222225
return array.filter((value, index) => array.indexOf(value) === index);
223226
}
227+
228+
function getBuildTools(packageJson: any): Partial<Record<BuildTool, string>> {
229+
if (!packageJson.devDependencies) {
230+
return {};
231+
}
232+
const result: Partial<Record<BuildTool, string>> = {};
233+
for (const buildTool of allBuildTools) {
234+
if (buildTool in packageJson.devDependencies) {
235+
result[buildTool] = packageJson.devDependencies[buildTool];
236+
}
237+
}
238+
return result;
239+
}

packages/core/src/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,25 @@ export interface TypesPackage {
2020
}
2121
export type AnalysisTypes = IncludedTypes | TypesPackage;
2222

23+
export type BuildTool =
24+
| "@arethetypeswrong/cli"
25+
| "typescript"
26+
| "rollup"
27+
| "@rollup/plugin-typescript"
28+
| "@rollup/plugin-typescript2"
29+
| "webpack"
30+
| "esbuild"
31+
| "parcel-bundler"
32+
| "@preconstruct/cli"
33+
| "vite"
34+
| "snowpack"
35+
| "microbundle"
36+
| "@microsoft/api-extractor";
37+
2338
export interface Analysis {
2439
packageName: string;
2540
packageVersion: string;
41+
buildTools: Partial<Record<BuildTool, string>>;
2642
types: AnalysisTypes;
2743
entrypoints: Record<string, EntrypointInfo>;
2844
problems: Problem[];

packages/core/src/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import validatePackgeName from "validate-npm-package-name";
22
import { valid, validRange } from "semver";
33
import type {
4+
BuildTool,
45
EntrypointInfo,
56
EntrypointResolutionAnalysis,
67
EntrypointResolutionProblem,
@@ -199,3 +200,19 @@ export function parsePackageSpec(input: string): Failable<ParsedPackageSpec> {
199200
data: { versionKind: "tag", name, version },
200201
};
201202
}
203+
204+
export const allBuildTools = Object.keys({
205+
"@arethetypeswrong/cli": true,
206+
typescript: true,
207+
rollup: true,
208+
"@rollup/plugin-typescript": true,
209+
"@rollup/plugin-typescript2": true,
210+
webpack: true,
211+
esbuild: true,
212+
"parcel-bundler": true,
213+
"@preconstruct/cli": true,
214+
vite: true,
215+
snowpack: true,
216+
microbundle: true,
217+
"@microsoft/api-extractor": true,
218+
} satisfies Record<BuildTool, any>) as BuildTool[];

packages/core/test/snapshots.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ describe("snapshots", async () => {
3939
const analysis = await checkPackage(
4040
typesTarball ? pkg.mergedWithTypes(createPackageFromTarballData(typesTarball)) : pkg
4141
);
42-
const snapshotURL = new URL(`../snapshots/${fixture}.md`, import.meta.url);
43-
const expectedSnapshot = [
44-
`# ${fixture}`,
45-
"",
46-
"## Problems",
47-
"",
48-
"```json",
49-
JSON.stringify(analysis.types ? analysis.problems : [], null, 2),
50-
"```",
51-
].join("\n");
42+
const snapshotURL = new URL(`../snapshots/${fixture}.json`, import.meta.url);
43+
const expectedSnapshot = JSON.stringify(analysis, null, 2) + "\n";
5244

5345
if (
5446
await access(snapshotURL)

0 commit comments

Comments
 (0)