Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --experimental-transform-types #194

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v2
with:
version: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v2
with:
version: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version-or-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v2
with:
version: latest
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
"build": "pnpm tsc && pnpm -r build",
"format": "prettier --write \"**/*.{ts,json,css}\"",
"test": "pnpm -r test",
"test-js": "pnpm tsc && pnpm -r test-js",
"check-dts": "tsc -p tsconfig.check-dts.json",
"start": "pnpm --filter @arethetypeswrong/web start",
"version": "changeset version && pnpm install --lockfile-only"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"prettier": "^3.0.3",
"typescript": "5.6.1-rc"
"typescript": "npm:@typescript-deploys/[email protected]"
},
"engines": {
"node": ">=18",
"node": ">=22",
"pnpm": ">=8"
}
}
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"tsc": "tsc -b",
"local:install": "npm install -g .",
"local:uninstall": "npm uninstall -g @arethetypeswrong/cli",
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
"test": "node --experimental-transform-types --conditions=@arethetypeswrong/source --test 'test/**/*.test.ts'",
"test-js": "node --experimental-transform-types --test 'test/**/*.test.ts'",
"prepack": "pnpm tsc"
},
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/getExitCode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CheckResult } from "@arethetypeswrong/core";
import { problemFlags } from "./problemUtils.js";
import type { RenderOptions } from "./render/index.js";
import { problemFlags } from "./problemUtils.ts";
import type { RenderOptions } from "./render/index.ts";

export function getExitCode(analysis: CheckResult, opts?: RenderOptions): number {
if (!analysis.types) {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { readFile, stat, unlink } from "fs/promises";
import { createRequire } from "module";
import path from "path";
import readline from "readline";
import { problemFlags } from "./problemUtils.js";
import { readConfig } from "./readConfig.js";
import * as render from "./render/index.js";
import { problemFlags } from "./problemUtils.ts";
import { readConfig } from "./readConfig.ts";
import * as render from "./render/index.ts";
import { major, minor } from "semver";
import { getExitCode } from "./getExitCode.js";
import { getExitCode } from "./getExitCode.ts";

const packageJson = createRequire(import.meta.url)("../package.json");
const version = packageJson.version;
Expand Down Expand Up @@ -74,8 +74,8 @@ particularly ESM-related module resolution issues.`,
.option("--exclude-entrypoints <entrypoints...>", "Specify entrypoints to exclude from checking.")
.option(
"--entrypoints-legacy",
'In packages without the `exports` field, every file is an entry point. Specifying this option ' +
'only takes effect when no entrypoints are automatically detected, or explicitly provided with other options.'
"In packages without the `exports` field, every file is an entry point. Specifying this option " +
"only takes effect when no entrypoints are automatically detected, or explicitly provided with other options.",
)
.addOption(
new Option("--ignore-rules <rules...>", "Specify rules to ignore").choices(Object.values(problemFlags)).default([]),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/readConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from "commander";
import { readFile } from "fs/promises";
import { problemFlags } from "./problemUtils.js";
import { problemFlags } from "./problemUtils.ts";

export async function readConfig(program: Command, alternate = ".attw.json") {
try {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/render/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { problemFlags } from "../problemUtils.js";
import type { problemFlags } from "../problemUtils.ts";

export type Format = "auto" | "table" | "table-flipped" | "ascii" | "json";
export interface RenderOptions {
Expand All @@ -9,5 +9,5 @@ export interface RenderOptions {
emoji?: boolean;
}

export * from "./typed.js";
export * from "./untyped.js";
export * from "./typed.ts";
export * from "./untyped.ts";
6 changes: 3 additions & 3 deletions packages/cli/src/render/typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import chalk from "chalk";
import Table, { type GenericTable, type HorizontalTableRow } from "cli-table3";
import { marked } from "marked";
import TerminalRenderer from "marked-terminal";
import { moduleKinds, problemFlags, resolutionKinds } from "../problemUtils.js";
import { asciiTable } from "./asciiTable.js";
import type { RenderOptions } from "./index.js";
import { moduleKinds, problemFlags, resolutionKinds } from "../problemUtils.ts";
import { asciiTable } from "./asciiTable.ts";
import type { RenderOptions } from "./index.ts";

export async function typed(
analysis: core.Analysis,
Expand Down
41 changes: 21 additions & 20 deletions packages/cli/test/snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { access, readFile, writeFile } from "fs/promises";
import { execSync, type SpawnSyncReturns } from "child_process";
import assert from "node:assert";
import { spawnSync } from "node:child_process";
import { access, readFile, writeFile } from "node:fs/promises";
import { after, describe, test } from "node:test";

const attw = `node ${new URL("../../dist/index.js", import.meta.url).pathname}`;
const attw = new URL("../src/index.ts", import.meta.url).pathname;
const updateSnapshots = process.env.UPDATE_SNAPSHOTS || process.env.U;
const testFilter = (process.env.TEST_FILTER || process.env.T)?.toLowerCase();

Expand Down Expand Up @@ -34,11 +34,11 @@ const tests = [

[
"[email protected]",
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
`--definitely-typed ${new URL("../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
],
[
"[email protected]",
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
`--definitely-typed ${new URL("../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
],

["[email protected]", "--entrypoints-legacy --ignore-rules=cjs-only-exports-default"],
Expand Down Expand Up @@ -68,21 +68,22 @@ describe("snapshots", async () => {
}

test(fixture, async () => {
const tarballPath = new URL(`../../../core/test/fixtures/${tarball}`, import.meta.url).pathname;
let stdout;
let stderr = "";
let exitCode = 0;
try {
stdout = execSync(`${attw} ${tarballPath} ${options ?? defaultOpts}`, {
const tarballPath = new URL(`../../core/test/fixtures/${tarball}`, import.meta.url).pathname;
const {
stdout,
stderr,
status = 1,
} = spawnSync(
process.execPath,
[...process.execArgv, attw, tarballPath, ...(options ?? defaultOpts).split(" ")],
{
encoding: "utf8",
env: { ...process.env, FORCE_COLOR: "0" },
});
} catch (error) {
stdout = (error as SpawnSyncReturns<string>).stdout;
stderr = (error as SpawnSyncReturns<string>).stderr;
exitCode = (error as SpawnSyncReturns<string>).status ?? 1;
}
const snapshotURL = new URL(`../snapshots/${fixture}.md`, import.meta.url);
stdio: "pipe",
env: { ...process.env, FORCE_COLOR: "0", NODE_OPTIONS: "--no-warnings" },
},
);

const snapshotURL = new URL(`snapshots/${fixture}.md`, import.meta.url);
// prettier-ignore
const expectedSnapshot = [
`# ${fixture}`,
Expand All @@ -94,7 +95,7 @@ describe("snapshots", async () => {
"",
"```",
"",
`Exit code: ${exitCode}`,
`Exit code: ${status}`,
].join("\n");

if (
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"lib": ["es2019"],
"module": "nodenext",
"outDir": "dist",
"types": ["node"]
},
"extends": "../../../tsconfig.test.json",
"references": [
{
"path": ".."
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "nodenext",
"rewriteRelativeImportExtensions": true,
"rootDir": "src",
"types": ["node", "ts-expose-internals"],
"outDir": "./dist",
Expand Down
16 changes: 10 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@
},
"scripts": {
"tsc": "tsc",
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
"test": "node --experimental-transform-types --conditions=@arethetypeswrong/source --test 'test/**/*.test.ts'",
"test-js": "node --experimental-transform-types --test 'test/**/*.test.ts'",
"snapshot": "node scripts/createSnapshotFixture.js",
"prepack": "pnpm tsc"
},
"type": "module",
"imports": {
"#internal/*": "./dist/internal/*"
"#internal/*": {
"@arethetypeswrong/source": "./src/internal/*.ts",
"default": "./dist/internal/*.js"
}
},
"exports": {
".": {
"development": "./src/index.ts",
"@arethetypeswrong/source": "./src/index.ts",
"default": "./dist/index.js"
},
"./types": {
"development": "./src/types.ts",
"@arethetypeswrong/source": "./src/types.ts",
"default": "./dist/types.js"
},
"./utils": {
"development": "./src/utils.ts",
"@arethetypeswrong/source": "./src/utils.ts",
"default": "./dist/utils.js"
},
"./problems": {
"development": "./src/problems.ts",
"@arethetypeswrong/source": "./src/problems.ts",
"default": "./dist/problems.js"
},
"./versions": {
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/checkPackage.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { Package } from "./createPackage.js";
import checks from "./internal/checks/index.js";
import type { AnyCheck, CheckDependenciesContext } from "./internal/defineCheck.js";
import { createCompilerHosts } from "./internal/multiCompilerHost.js";
import type { Package } from "./createPackage.ts";
import checks from "./internal/checks/index.ts";
import type { AnyCheck, CheckDependenciesContext } from "./internal/defineCheck.ts";
import { createCompilerHosts } from "./internal/multiCompilerHost.ts";
import type {
AnalysisTypes,
CheckResult,
EntrypointResolutionAnalysis,
Problem,
ProgramInfo,
ResolutionOption,
} from "./types.js";
import { getResolutionOption, visitResolutions } from "./utils.js";
import { getEntrypointInfo, getModuleKinds, getBuildTools } from "./internal/getEntrypointInfo.js";
} from "./types.ts";
import { getResolutionOption, visitResolutions } from "./utils.ts";
import { getEntrypointInfo, getModuleKinds, getBuildTools } from "./internal/getEntrypointInfo.ts";

export interface CheckPackageOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/createPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { untar } from "@andrewbranch/untar.js";
import { Gunzip } from "fflate";
import { major, maxSatisfying, minor, valid, validRange } from "semver";
import ts from "typescript";
import { parsePackageSpec, type ParsedPackageSpec } from "./utils.js";
import { parsePackageSpec, type ParsedPackageSpec } from "./utils.ts";

export class Package {
#files: Record<string, string | Uint8Array> = {};
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./checkPackage.js";
export * from "./createPackage.js";
export type * from "./types.js";
export * from "./checkPackage.ts";
export * from "./createPackage.ts";
export type * from "./types.ts";
2 changes: 1 addition & 1 deletion packages/core/src/internal/checks/cjsOnlyExportsDefault.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from "typescript";
import { defineCheck } from "../defineCheck.js";
import { defineCheck } from "../defineCheck.ts";

export default defineCheck({
name: "CJSOnlyExportsDefault",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/internal/checks/entrypointResolutions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ts from "typescript";
import type { Problem } from "../../types.js";
import { resolvedThroughFallback } from "../../utils.js";
import { defineCheck } from "../defineCheck.js";
import type { Problem } from "../../types.ts";
import { resolvedThroughFallback } from "../../utils.ts";
import { defineCheck } from "../defineCheck.ts";

export default defineCheck({
name: "EntrypointResolutions",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ts from "typescript";
import { defineCheck } from "../defineCheck.js";
import { getProbableExports, type Export } from "../getProbableExports.js";
import { getResolutionOption } from "../../utils.js";
import { defineCheck } from "../defineCheck.ts";
import { getProbableExports, type Export } from "../getProbableExports.ts";
import { getResolutionOption } from "../../utils.ts";

const bindOptions: ts.CompilerOptions = {
target: ts.ScriptTarget.Latest,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/internal/checks/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cjsOnlyExportsDefault from "./cjsOnlyExportsDefault.js";
import entrypointResolutions from "./entrypointResolutions.js";
import exportDefaultDisagreement from "./exportDefaultDisagreement.js";
import internalResolutionError from "./internalResolutionError.js";
import moduleKindDisagreement from "./moduleKindDisagreement.js";
import unexpectedModuleSyntax from "./unexpectedModuleSyntax.js";
import cjsOnlyExportsDefault from "./cjsOnlyExportsDefault.ts";
import entrypointResolutions from "./entrypointResolutions.ts";
import exportDefaultDisagreement from "./exportDefaultDisagreement.ts";
import internalResolutionError from "./internalResolutionError.ts";
import moduleKindDisagreement from "./moduleKindDisagreement.ts";
import unexpectedModuleSyntax from "./unexpectedModuleSyntax.ts";

export default [
entrypointResolutions,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/internal/checks/internalResolutionError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";
import { defineCheck } from "../defineCheck.js";
import type { InternalResolutionErrorProblem } from "../../types.js";
import { defineCheck } from "../defineCheck.ts";
import type { InternalResolutionErrorProblem } from "../../types.ts";

export default defineCheck({
name: "InternalResolutionError",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from "typescript";
import { defineCheck } from "../defineCheck.js";
import { defineCheck } from "../defineCheck.ts";

export default defineCheck({
name: "ModuleKindDisagreement",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from "typescript";
import { defineCheck } from "../defineCheck.js";
import { defineCheck } from "../defineCheck.ts";

export default defineCheck({
name: "UnexpectedModuleSyntax",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/internal/defineCheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Package } from "../createPackage.js";
import type { CompilerHosts } from "./multiCompilerHost.js";
import type { Analysis, Problem, ResolutionKind, ResolutionOption } from "../types.js";
import type { Package } from "../createPackage.ts";
import type { CompilerHosts } from "./multiCompilerHost.ts";
import type { Analysis, Problem, ResolutionKind, ResolutionOption } from "../types.ts";

export interface CheckDependenciesContext<EnumerateFiles extends boolean = false> extends CheckExecutionContext {
subpath: string;
Expand Down
Loading
Loading