Skip to content

Emulate some CJS and ESM projects as unit test not to break user projects#1605

Open
Yang-33 wants to merge 7 commits into
masterfrom
dual-package-test-2026-05-08
Open

Emulate some CJS and ESM projects as unit test not to break user projects#1605
Yang-33 wants to merge 7 commits into
masterfrom
dual-package-test-2026-05-08

Conversation

@Yang-33
Copy link
Copy Markdown
Contributor

@Yang-33 Yang-33 commented May 9, 2026

resolve #1585

We need to keep the dual package for another 2 to 3 years.

Therefore, we need to prevent regressions in ESM and CJS support caused by TypeScript config changes or publishing changes.

This change adds tests for that. The local execution time increases by about 30 seconds, which I think is acceptable.

@Yang-33 Yang-33 marked this pull request as ready for review May 9, 2026 04:05
@Yang-33 Yang-33 requested a review from a team May 9, 2026 04:05
Copy link
Copy Markdown
Contributor

@mokuzon mokuzon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost LGTM.

const repoRoot = process.cwd();
const tempDirs: string[] = [];
let tarballPath = "";
const TS5_VERSION = "5.9.3";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use a semver range like ~5.9 here (and ^6.0 in the ts6 spec) instead of pinning the exact patch?

Since these tests aim to emulate real consumer projects, automatically picking up patch/minor TS updates would let us catch breakages of the shipped .d.ts against future TS releases earlier. The min-release-age=7 in .npmrc already mitigates zero-day supply-chain risk.

If CI determinism is the priority, pinning is also reasonable — just sharing a thought.

Copy link
Copy Markdown
Contributor Author

@Yang-33 Yang-33 May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specific version is better to make build stable?

}

afterAll(async () => {
await Promise.all(tempDirs.map(dir => removeDir(dir)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] Using Promise.allSettled here (and in the other spec files that share the same pattern) would ensure the remaining temp dirs are still cleaned up even if one removal fails.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkdtemp creates a temporary directory, so I think it should be removed automatically, but your point makes sense. I fixed it.

Comment on lines +23 to +48
interface TsLaneConfig {
readonly fixtureName: string;
readonly packageTemplateFile: "package.module.json" | "package.commonjs.json";
readonly tsconfigTemplateFile:
| "tsconfig.nodenext.json"
| "tsconfig.node16.json"
| "tsconfig.bundler.json";
readonly withRuntime: boolean;
}

async function runTsLane(config: TsLaneConfig): Promise<void> {
const fixtureDir = await prepareFixtureDir(config.fixtureName);
await materializeTsFixture({
repoRoot,
outDir: fixtureDir,
packageTemplateFile: config.packageTemplateFile,
tsconfigTemplateFile: config.tsconfigTemplateFile,
tsVersion: TS6_VERSION,
});

installSdkTarball(fixtureDir, tarballPath);
runCommand(fixtureDir, "npm", ["run", "build"]);
if (config.withRuntime) {
runCommand(fixtureDir, "npm", ["run", "run:resolution"]);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] TsLaneConfig / runTsLane are nearly identical between this file and consumer-contract-ts5.spec.ts. Extracting a shared helper could make adding future TS major versions (ts7, ...) easier.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I created a common for the common parts! 😄 323676e

@Yang-33 Yang-33 requested a review from mokuzon May 19, 2026 06:55
@Yang-33
Copy link
Copy Markdown
Contributor Author

Yang-33 commented May 19, 2026

PTAL~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emulate some CJS and ESM projects as unit test not to break user projects

3 participants