Skip to content

fix(gaxios): exclude compiled tests and .tsbuildinfo from published tarball - #9612

Merged
quirogas merged 1 commit into
googleapis:mainfrom
quirogas:fix/gaxios-tarball-exclude-tests
Oct 14, 2026
Merged

quirogas merged 1 commit into
googleapis:mainfrom
quirogas:fix/gaxios-tarball-exclude-tests

Conversation

@quirogas

Copy link
Copy Markdown
Contributor

Description

This change updates the files allowlist in core/packages/gaxios/package.json from ["build/"] to ["build/cjs/src", "build/esm/src", "build/esm/package.json", "!build/**/*.map"] so that compiled test artifacts, .tsbuildinfo incremental caches, and source maps are excluded from the published npm tarball (b/572989218).

Impact

Reduces the published gaxios tarball from 78 files (738.4 kB unpacked / 109.8 kB compressed) to 28 files (161.5 kB unpacked / 26.1 kB compressed) by eliminating ~488 kB (66.1%) of compiled test/, browser-test/, system-test/, and .tsbuildinfo build-cache bloat across all downstream Google Cloud Node.js installs.

Changes

  • core/packages/gaxios/package.json: Replace "files": ["build/"] with ["build/cjs/src", "build/esm/src", "build/esm/package.json", "!build/**/*.map"].
  • core/packages/gaxios/test/test.getch.ts: Add a unit test verifying that package.json files includes build/cjs/src, build/esm/src, and build/esm/package.json and does not include build/ as a wildcard.

Testing

  • Executed npm test and JS_RUNTIME=bun npm test in core/packages/gaxios (135 passing in both runtimes).
  • Verified npm pack --dry-run in core/packages/gaxios packs 28 files (build/cjs/src/*, build/esm/src/*, build/esm/package.json, package.json, README.md, LICENSE) with zero test/, browser-test/, system-test/, or .tsbuildinfo files.
  • Verified GIT_DIFF_ARG=origin/main node ./bin/linter.mjs --strict passes.

Alternatives

  • Leaving "files": ["build/"] in core/packages/gaxios/package.json was rejected because tsconfig.base.json compiles test/*.ts, browser-test/*.ts, and system-test/*.ts during prepare, causing every gaxios consumer to download compiled test suites and .tsbuildinfo files.

…arball

## Description

This change updates the `files` allowlist in `core/packages/gaxios/package.json` from `["build/"]` to `["build/cjs/src", "build/esm/src", "build/esm/package.json", "!build/**/*.map"]` so that compiled test artifacts, `.tsbuildinfo` incremental caches, and source maps are excluded from the published npm tarball (b/572989218).

## Impact

Reduces the published `gaxios` tarball from 78 files (`738.4 kB` unpacked / `109.8 kB` compressed) to 28 files (`161.5 kB` unpacked / `26.1 kB` compressed) by eliminating `~488 kB` (66.1%) of compiled `test/`, `browser-test/`, `system-test/`, and `.tsbuildinfo` build-cache bloat across all downstream Google Cloud Node.js installs.

## Changes

- `core/packages/gaxios/package.json`: Replace `"files": ["build/"]` with `["build/cjs/src", "build/esm/src", "build/esm/package.json", "!build/**/*.map"]`.
- `core/packages/gaxios/test/test.getch.ts`: Add a unit test verifying that `package.json` `files` includes `build/cjs/src`, `build/esm/src`, and `build/esm/package.json` and does not include `build/` as a wildcard.

## Testing

- Executed `npm test` and `JS_RUNTIME=bun npm test` in `core/packages/gaxios` (135 passing in both runtimes).
- Verified `npm pack --dry-run` in `core/packages/gaxios` packs 28 files (`build/cjs/src/*`, `build/esm/src/*`, `build/esm/package.json`, `package.json`, `README.md`, `LICENSE`) with zero `test/`, `browser-test/`, `system-test/`, or `.tsbuildinfo` files.
- Verified `GIT_DIFF_ARG=origin/main node ./bin/linter.mjs --strict` passes.

## Alternatives

- Leaving `"files": ["build/"]` in `core/packages/gaxios/package.json` was rejected because `tsconfig.base.json` compiles `test/*.ts`, `browser-test/*.ts`, and `system-test/*.ts` during `prepare`, causing every `gaxios` consumer to download compiled test suites and `.tsbuildinfo` files.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the files field in package.json to restrict the published files to specific build directories and exclude map files, and adds a corresponding test to verify this allowlist. The review feedback suggests making the test less brittle by asserting the inclusion of specific paths rather than asserting exact array equality.

Comment on lines +1990 to +1996
assert.deepStrictEqual(pkgFiles, [
'build/cjs/src',
'build/esm/src',
'build/esm/package.json',
'!build/**/*.map',
]);
assert.strictEqual(pkgFiles?.includes('build/'), false);

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.

medium

Asserting the exact array equality for package.json files makes the test brittle to future additions of other files or assets to the allowlist. It is more robust to assert the presence of the required build directories and the absence of the wildcard build/ directory individually.

    assert.ok(pkgFiles?.includes('build/cjs/src'));
    assert.ok(pkgFiles?.includes('build/esm/src'));
    assert.ok(pkgFiles?.includes('build/esm/package.json'));
    assert.ok(pkgFiles?.includes('!build/**/*.map'));
    assert.strictEqual(pkgFiles?.includes('build/'), false);

@quirogas
quirogas marked this pull request as ready for review October 14, 2026 17:47
@quirogas
quirogas requested a review from a team as a code owner October 14, 2026 17:47
@github-actions
github-actions Bot requested a review from danieljbruce October 14, 2026 17:47
@quirogas
quirogas merged commit 7394a38 into googleapis:main Oct 14, 2026
47 checks passed
@release-please release-please Bot mentioned this pull request Oct 14, 2026
quirogas added a commit that referenced this pull request Oct 14, 2026
…tEqual (#9626)

## Description

Replaces the `assert.deepStrictEqual(pkgFiles, [...])` assertion in
`core/packages/gaxios/test/test.getch.ts` (added in #9612) with a
minimal per-entry `pkgFiles?.includes(file)` check.

## Impact

Avoids coupling the test to the exact array ordering or disallowing
future additions to `package.json` `"files"`, while keeping the test
minimal (+4/-2 lines), self-contained, and aligned with the existing
assertion style in `test.getch.ts`.

## Changes

- `core/packages/gaxios/test/test.getch.ts`:
- Replace `assert.deepStrictEqual(pkgFiles, [...])` with a `for (const
file of [...])` loop asserting
`assert.strictEqual(pkgFiles?.includes(file), true)` for each required
entry alongside `assert.strictEqual(pkgFiles?.includes('build/'),
false)`.

## Testing

- `npm test` in `core/packages/gaxios` (Node.js)
- `JS_RUNTIME=bun npm test` in `core/packages/gaxios` (Bun)
- `GIT_DIFF_ARG=origin/main node ./bin/linter.mjs --strict`

## Alternatives

- Keeping `assert.deepStrictEqual(pkgFiles, [...])` was rejected because
it couples the assertion to exact array ordering and length.
- Shelling out to `npm pack --dry-run` with regex path matching was
rejected as overengineered for a fast unit test.
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.

2 participants