Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-dancers-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arethetypeswrong/cli": minor
---

Report relevant build tools detected in package.json `devDependencies`
5 changes: 5 additions & 0 deletions .changeset/thin-moles-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arethetypeswrong/core": minor
---

Add `buildTools` property to `Analysis` (a pick of `devDependencies`)
23 changes: 17 additions & 6 deletions packages/cli/src/render/typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ export async function typed(analysis: core.Analysis, opts: Opts) {
headerIds: false,
});

console.log(`${analysis.packageName} v${analysis.packageVersion}`);
if (analysis.types.kind === "@types") {
console.log(`${analysis.types.packageName} v${analysis.types.packageVersion}`);
}
console.log();
if (Object.keys(analysis.buildTools).length) {
console.log("Build tools:");
console.log(
Object.entries(analysis.buildTools)
.map(([tool, version]) => {
return `- ${tool}@${version}`;
})
.join("\n")
);
console.log();
}

if (opts.ignoreRules && opts.ignoreRules.length) {
console.log(
chalk.gray(
Expand All @@ -31,12 +48,6 @@ export async function typed(analysis: core.Analysis, opts: Opts) {
);
}

console.log(`${analysis.packageName} v${analysis.packageVersion}`);
if (analysis.types.kind === "@types") {
console.log(`${analysis.types.packageName} v${analysis.types.packageVersion}`);
}
console.log();

if (opts.summary) {
const defaultSummary = marked(!opts.emoji ? " No problems found" : " No problems found 🌟");
const summaryTexts = Object.keys(grouped).map((kind) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/test/snapshots/@apollo__client-3.7.16.tgz.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ $ attw @apollo__client-3.7.16.tgz -f table-flipped

@apollo/client v3.7.16

Build tools:
- [email protected]
- [email protected]

👺 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

⚠️ 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
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/test/snapshots/@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ $ attw @[email protected] -f table-flipped

@ice/app v3.2.6

Build tools:
- webpack@^5.86.0
- esbuild@^0.17.16

⚠️ 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

💀 Import failed to resolve to type declarations or JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/test/snapshots/@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ $ attw @[email protected] -f table-flipped

@reduxjs/toolkit v2.0.0-beta.0

Build tools:
- typescript@~4.9
- @microsoft/api-extractor@^7.13.2

🎭 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

🥴 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
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/test/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ $ attw [email protected] -f table-flipped

ajv v8.12.0

Build tools:
- typescript@^4.8.0
- rollup@^2.44.0
- @rollup/plugin-typescript@^10.0.1

No problems found 🌟


Expand Down
4 changes: 4 additions & 0 deletions packages/cli/test/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ $ attw [email protected] -f table-flipped

axios v1.4.0

Build tools:
- typescript@^4.8.4
- rollup@^2.67.0

❓ Wildcard subpaths cannot yet be analyzed by this tool. https://github.com/arethetypeswrong/arethetypeswrong.github.io/issues/40

💀 Import failed to resolve to type declarations or JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/test/snapshots/[email protected] -f table.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ $ attw [email protected] -f table

commander v10.0.1

Build tools:
- typescript@^4.9.4

🎭 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

❌ Import resolved to JavaScript files, but no type declarations were found. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/test/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ $ attw [email protected] -f table-flipped

node-html-parser v6.1.5

Build tools:
- typescript@latest

🤨 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


Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/checkPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type { Package } from "./createPackage.js";
import { createCompilerHosts, type CompilerHosts, CompilerHostWrapper } from "./multiCompilerHost.js";
import type {
AnalysisTypes,
BuildTool,
CheckResult,
EntrypointInfo,
EntrypointResolutionAnalysis,
Resolution,
ResolutionKind,
} from "./types.js";
import { allBuildTools } from "./utils.js";

export interface CheckPackageOptions {
/**
Expand Down Expand Up @@ -56,6 +58,7 @@ export async function checkPackage(pkg: Package, options?: CheckPackageOptions):
packageName,
packageVersion,
types,
buildTools: getBuildTools(JSON.parse(pkg.readFile(`/node_modules/${packageName}/package.json`))),
entrypoints: entrypointResolutions,
problems: [...entrypointResolutionProblems, ...resolutionBasedFileProblems, ...fileProblems],
};
Expand Down Expand Up @@ -221,3 +224,16 @@ function getEntrypointResolution(
function unique<T>(array: readonly T[]): T[] {
return array.filter((value, index) => array.indexOf(value) === index);
}

function getBuildTools(packageJson: any): Partial<Record<BuildTool, string>> {
if (!packageJson.devDependencies) {
return {};
}
const result: Partial<Record<BuildTool, string>> = {};
for (const buildTool of allBuildTools) {
if (buildTool in packageJson.devDependencies) {
result[buildTool] = packageJson.devDependencies[buildTool];
}
}
return result;
}
16 changes: 16 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@ export interface TypesPackage {
}
export type AnalysisTypes = IncludedTypes | TypesPackage;

export type BuildTool =
| "@arethetypeswrong/cli"
| "typescript"
| "rollup"
| "@rollup/plugin-typescript"
| "@rollup/plugin-typescript2"
| "webpack"
| "esbuild"
| "parcel-bundler"
| "@preconstruct/cli"
| "vite"
| "snowpack"
| "microbundle"
| "@microsoft/api-extractor";

export interface Analysis {
packageName: string;
packageVersion: string;
buildTools: Partial<Record<BuildTool, string>>;
types: AnalysisTypes;
entrypoints: Record<string, EntrypointInfo>;
problems: Problem[];
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import validatePackgeName from "validate-npm-package-name";
import { valid, validRange } from "semver";
import type {
BuildTool,
EntrypointInfo,
EntrypointResolutionAnalysis,
EntrypointResolutionProblem,
Expand Down Expand Up @@ -199,3 +200,19 @@ export function parsePackageSpec(input: string): Failable<ParsedPackageSpec> {
data: { versionKind: "tag", name, version },
};
}

export const allBuildTools = Object.keys({
"@arethetypeswrong/cli": true,
typescript: true,
rollup: true,
"@rollup/plugin-typescript": true,
"@rollup/plugin-typescript2": true,
webpack: true,
esbuild: true,
"parcel-bundler": true,
"@preconstruct/cli": true,
vite: true,
snowpack: true,
microbundle: true,
"@microsoft/api-extractor": true,
} satisfies Record<BuildTool, any>) as BuildTool[];
12 changes: 2 additions & 10 deletions packages/core/test/snapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,8 @@ describe("snapshots", async () => {
const analysis = await checkPackage(
typesTarball ? pkg.mergedWithTypes(createPackageFromTarballData(typesTarball)) : pkg
);
const snapshotURL = new URL(`../snapshots/${fixture}.md`, import.meta.url);
const expectedSnapshot = [
`# ${fixture}`,
"",
"## Problems",
"",
"```json",
JSON.stringify(analysis.types ? analysis.problems : [], null, 2),
"```",
].join("\n");
const snapshotURL = new URL(`../snapshots/${fixture}.json`, import.meta.url);
const expectedSnapshot = JSON.stringify(analysis, null, 2) + "\n";

if (
await access(snapshotURL)
Expand Down
Loading