Skip to content

Fix Node Protocol plugin to handle node-only modules correctly#483

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-node-protocol-module-handling
Closed

Fix Node Protocol plugin to handle node-only modules correctly#483
Copilot wants to merge 2 commits intomainfrom
copilot/fix-node-protocol-module-handling

Conversation

Copy link
Contributor

Copilot AI commented Sep 9, 2025

The Node Protocol plugin was incorrectly handling modules that require the node: prefix and modules that already have the prefix. This caused two main issues:

  1. Double prefixing: When nodeProtocol: true was used, modules that already had the node: prefix would get another prefix added, resulting in node:node:path instead of node:path.

  2. Stripping required prefixes: When nodeProtocol: 'strip' was used, modules that REQUIRE the node: prefix (like node:test, node:sqlite, node:sea, node:test/reporters) would have their prefix stripped, making them invalid.

Example of the problem:

// Before fix - with nodeProtocol: true
import fs from 'fs'
import { join } from 'node:path'
// Would output: import fs from "node:fs"; import { join } from "node:node:path";

// Before fix - with nodeProtocol: 'strip'  
import test from 'node:test'
import sqlite from 'node:sqlite'
// Would output: import test from "test"; import sqlite from "sqlite"; (invalid!)

Solution:

  • For adding mode (nodeProtocol: true): Check if modules already have the node: prefix and preserve them as-is instead of adding another prefix.

  • **For stripping mode (nodeProtocol: 'strip')**: Identify modules that require the node: prefix (node:sea, node:sqlite, node:test, node:test/reporters`) and preserve their prefix even in strip mode.

After fix:

// With nodeProtocol: true
import fs from 'fs'
import { join } from 'node:path'
// Correctly outputs: import fs from "node:fs"; import { join } from "node:path";

// With nodeProtocol: 'strip'
import test from 'node:test'
import sqlite from 'node:sqlite'  
// Correctly outputs: import test from "node:test"; import sqlite from "node:sqlite";

The fix includes comprehensive test cases to validate both scenarios and maintains backward compatibility with existing functionality.

Fixes #482.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI assigned Copilot and sxzz Sep 9, 2025
Copy link
Contributor Author

Copilot AI commented Sep 9, 2025

@sxzz 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@netlify
Copy link

netlify bot commented Sep 9, 2025

Deploy Preview for tsdown ready!

Name Link
🔨 Latest commit 1a8b52e
🔍 Latest deploy log https://app.netlify.com/projects/tsdown/deploys/68c01508608c390008ee6ece
😎 Deploy Preview https://deploy-preview-483--tsdown.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-authored-by: sxzz <6481596+sxzz@users.noreply.github.com>
Copilot AI changed the title [WIP] Node Protocol plugin needs to handle Node Protocol only modules Fix Node Protocol plugin to handle node-only modules correctly Sep 9, 2025
Copilot AI requested a review from sxzz September 9, 2025 11:55
@sxzz sxzz closed this in a480fba Sep 9, 2025
sxzz added a commit that referenced this pull request Sep 9, 2025
@sxzz sxzz deleted the copilot/fix-node-protocol-module-handling branch November 28, 2025 19:57
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.

Node Protocol plugin needs to handle Node Protocol only modules

2 participants