Skip to content

Refuse to load npm package.json files - #3136

Merged
Geod24 merged 5 commits into
dlang:masterfrom
AMDphreak:fix/3118-refuse-npm-package-json
Nov 6, 2026
Merged

Geod24 merged 5 commits into
dlang:masterfrom
AMDphreak:fix/3118-refuse-npm-package-json

Conversation

@AMDphreak

Copy link
Copy Markdown
Contributor

Summary

  • Refuse to parse a file named package.json when it contains npm-only top-level keys (packageManager, scripts, devDependencies, workspaces, private), matching the proposal in Refuse to load npm package.json files #3118.
  • Keep loading legacy Dub recipes that still use the package.json filename (no npm sentinel keys).
  • Add unit tests, an integration .fail_build case, and a changelog entry.

Test plan

  • CI unit tests for source/dub/recipe/io.d (npm refuse + legacy allow)
  • CI integration: test/issue3118-npm-package-json fails to build as expected
  • CI integration: test/1-exec-simple-package-json still builds
  • Manual: in a repo with only an npm package.json, dub build prints a clear refusal instead of unknown-key warnings

Fixes #3118

@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

✅ PR OK, no changes in deprecations or warnings

Total deprecations: 0

Total warnings: 0

Build statistics:

 statistics (-before, +after)
-executable size=5688688 bin/dub
-rough build time=57s
+executable size=5688824 bin/dub
+rough build time=58s
Full build output
DUB version 1.42.0, built on Aug 30 2026
LDC - the LLVM D compiler (1.43.0):
  based on DMD v2.113.0 and LLVM 22.1.8
  built with LDC - the LLVM D compiler (1.43.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver4
  https://dlang.org - https://wiki.dlang.org/LDC


  Registered Targets:
    aarch64     - AArch64 (little endian)
    aarch64_32  - AArch64 (little endian ILP32)
    aarch64_be  - AArch64 (big endian)
    amdgcn      - AMD GCN GPUs
    arm         - ARM
    arm64       - ARM64 (little endian)
    arm64_32    - ARM64 (little endian ILP32)
    armeb       - ARM (big endian)
    avr         - Atmel AVR Microcontroller
    bpf         - BPF (host endian)
    bpfeb       - BPF (big endian)
    bpfel       - BPF (little endian)
    hexagon     - Hexagon
    lanai       - Lanai
    loongarch32 - 32-bit LoongArch
    loongarch64 - 64-bit LoongArch
    mips        - MIPS (32-bit big endian)
    mips64      - MIPS (64-bit big endian)
    mips64el    - MIPS (64-bit little endian)
    mipsel      - MIPS (32-bit little endian)
    msp430      - MSP430 [experimental]
    nvptx       - NVIDIA PTX 32-bit
    nvptx64     - NVIDIA PTX 64-bit
    ppc32       - PowerPC 32
    ppc32le     - PowerPC 32 LE
    ppc64       - PowerPC 64
    ppc64le     - PowerPC 64 LE
    r600        - AMD GPUs HD2XXX-HD6XXX
    riscv32     - 32-bit RISC-V
    riscv32be   - 32-bit big endian RISC-V
    riscv64     - 64-bit RISC-V
    riscv64be   - 64-bit big endian RISC-V
    sparc       - Sparc
    sparcel     - Sparc LE
    sparcv9     - Sparc V9
    spirv       - SPIR-V Logical
    spirv32     - SPIR-V 32-bit
    spirv64     - SPIR-V 64-bit
    systemz     - SystemZ
    thumb       - Thumb
    thumbeb     - Thumb (big endian)
    ve          - VE
    wasm32      - WebAssembly 32-bit
    wasm64      - WebAssembly 64-bit
    x86         - 32-bit X86: Pentium-Pro and above
    x86-64      - 64-bit X86: EM64T and AMD64
    xcore       - XCore
    xtensa      - Xtensa 32
   Upgrading project in /home/runner/work/dub/dub/
    Starting Performing "release" build using /opt/hostedtoolcache/ldc2/1.43.0/x64/ldc2-1.43.0-linux-x86_64/bin/ldc2 for x86_64.
    Building dub 1.42.0-beta.1+commit.46.gecb9b4f9: building configuration [application]
     Linking dub
STAT:statistics (-before, +after)
STAT:executable size=5688824 bin/dub
STAT:rough build time=58s

@Geod24

Geod24 commented Nov 5, 2026

Copy link
Copy Markdown
Member

Thank you!

@Geod24 Geod24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you mind rebasing on master to please the CI ? Ideally we'd also convert the test to the new framework (see source/dub/test/base.d), but not a blocker.

AMDphreak and others added 3 commits November 5, 2026 23:42
When Dub finds a package.json with npm-only top-level keys
(packageManager, scripts, devDependencies, workspaces, private),
raise a hard error instead of parsing it as a Dub recipe.

Fixes dlang#3118

Co-authored-by: Cursor <[email protected]>
Force-track package.json under test/ (gitignore only allowlists dub.json)
and allowlist package.json test fixtures going forward.

Co-authored-by: Cursor <[email protected]>
Replace the test/issue3118-npm-package-json integration fixture with
source/dub/test/npm_package_json.d, which uses TestDub to check that an
npm package.json is refused and a legacy Dub package.json still loads.
Drop the now-unneeded .gitignore exception for test/*/package.json.
@AMDphreak
AMDphreak force-pushed the fix/3118-refuse-npm-package-json branch from 24a9383 to 0450e1e Compare November 6, 2026 05:44

@thewilsonator thewilsonator 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.

otherwise looks good

Comment thread source/dub/test/npm_package_json.d Outdated
});
dub.loadPackage();
assert(dub.project.rootPackage.name == "legacy");
} No newline at end of file

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.

newline at end of file

@Geod24
Geod24 merged commit f359765 into dlang:master Nov 6, 2026
37 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.

Refuse to load npm package.json files

3 participants