Skip to content

Fix npm build excluding esm/src/ and script/src/ directories#9

Merged
Hexagon merged 7 commits intomainfrom
copilot/investigate-npm-esm-issue
Oct 29, 2025
Merged

Fix npm build excluding esm/src/ and script/src/ directories#9
Hexagon merged 7 commits intomainfrom
copilot/investigate-npm-esm-issue

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

DNT 0.37.0 generates .npmignore with src/ pattern by default when source maps are not configured. This pattern inadvertently excludes esm/src/ and script/src/ containing transpiled code, causing v1.0.2 module resolution failures.

Root Cause Analysis

DNT automatically adds src/ to .npmignore when sourceMap options are not specified in the build configuration. This is documented in DNT's source code (lib/npm_ignore.ts):

if (!isUsingSourceMaps() || options.inlineSources) {
  lines.push("src/");
}

The same DNT version (0.37.0) and identical build scripts were used for both 1.0.1 and 1.0.2, meaning this pattern has always been generated. The issue affects 1.0.2 because the generic src/ pattern matches:

  • esm/src/ (transpiled ESM JavaScript - required for package)
  • script/src/ (transpiled CommonJS JavaScript - required for package)
  • npm/src/ (TypeScript sources - correctly excluded)

Changes

Build Script Fix

  • Post-process .npmignore to replace src/ with /src/ after DNT build
  • Leading / restricts pattern to root directory only, preserving transpiled code in subdirectories
  • Added detailed comments explaining DNT behavior
  • Added *.test.d.ts and tests/**/*.d.ts patterns to .npmignore to exclude generated test declaration files from npm package

Result

# Before fix: esm/src/ and script/src/ excluded
npm pack --dry-run  # 49 files, missing 100 source files

# After fix: both directories included
npm pack --dry-run  # 149 files, esm/src/ (50 files) + script/src/ (50 files) present
Original prompt

Can you have a look at why npm/esm|script/src/**/* didnt generate at Build of last release? (Latest issue)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits October 29, 2025 18:31
Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate npm/esm script source generation issue Fix npm build excluding esm/src/ and script/src/ directories Oct 29, 2025
Copilot AI requested a review from Hexagon October 29, 2025 18:39
@Hexagon
Copy link
Owner

Hexagon commented Oct 29, 2025

@copilot

  1. The verification script is overkill

  2. Dig deeper into the root cause, did dnt change behavior - what happened between 1.0.1 and 1.0.2?

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot

  1. The verification script is overkill
    ...

Removed verification script and investigated deeper.

Root cause: DNT 0.37.0 generates src/ in .npmignore by default when source maps aren't configured. This is documented in DNT source (lib/npm_ignore.ts). The pattern excludes esm/src/ and script/src/ containing transpiled code.

DNT behavior: Identical in both 1.0.1 and 1.0.2 - same DNT version (0.37.0), same build script, same missing sourceMap config. Both should generate src/ in .npmignore. This suggests the issue may have existed in 1.0.1 too, or manual corrections were made during 1.0.1 publishing.

Solution: Replace src/ with /src/ to only match root directory.

Changes in commit df7e0cf.

@Hexagon Hexagon marked this pull request as ready for review October 29, 2025 19:19
@Hexagon
Copy link
Owner

Hexagon commented Oct 29, 2025

@copilot add tests .d.ts to gitignore

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot add tests .d.ts to gitignore

Added *.test.d.ts and tests/**/*.d.ts patterns to .gitignore.

Changes in commit 5867d28.

@Hexagon
Copy link
Owner

Hexagon commented Oct 29, 2025

@copilot my bad... To .npmignore, not gitignore

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot my bad... To .npmignore, not gitignore

Fixed - reverted .gitignore change and added *.test.d.ts and tests/**/*.d.ts patterns to .npmignore instead (in the build script).

Changes in commit f75638e.

@Hexagon Hexagon merged commit 5c866c7 into main Oct 29, 2025
0 of 8 checks passed
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