WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Summary

Modernizes FileWriter to use Node.js built-in node:fs module instead of the fs-extra dependency, removing lazy-loading overhead and simplifying the implementation.

Details

Replaced fs-extra with node:fs:

  • Removed Import.lazy('fs-extra', require) pattern in favor of import * as fs from 'node:fs'
  • All file operations (openSync, writeSync, closeSync, fstatSync) now use native fs APIs directly

Refactored flag conversion helper:

  • Moved _convertFlagsForNode from private static method to module-level function convertFlagsForNode
  • Replaced array join with template literal: `${flags.append ? 'a' : 'w'}${flags.exclusive ? 'x' : ''}`
  • Added explicit NodeFileFlags type annotation to satisfy lint requirements

Import reordering:

  • Node.js built-in imports now precede local imports with blank line separation

Added Rush change file:

  • Created change file for changelog generation with patch-level bump

No breaking changes. Public API (FileWriter class, IFileWriterFlags interface) remains unchanged.

How it was tested

Verified that all 237 existing unit tests pass, including tests in LockFile.test.ts that exercise FileWriter.open() with various flag combinations.

Impacted documentation

None. FileWriter JSDoc already references fs.openSync() and other native fs methods.

Original prompt

Make the following changes to libraries/node-core-library/src/FileWriter.ts:

  1. Replace the lazy-loaded fs-extra usage and Import.lazy pattern with the built-in node:fs module.

    • Remove the import of Import and any Import.lazy calls.
    • Add import * as fs from 'node:fs'; and ensure all fs-extra usage is replaced with fs equivalents (openSync, writeSync, closeSync, fstatSync).
  2. Move the private static method _convertFlagsForNode out of the FileWriter class and make it a module-level free function named convertFlagsForNode with the same behavior.

    • Use a template string for concatenation instead of array join or manual concatenation.
    • Add an explicit type annotation : NodeFileFlags to the result variable to satisfy lint rules (no implicit any/implicit typedefs).
  3. Reorder imports so that import * as fs from 'node:fs'; appears before the typed local import with a single blank line between them, i.e.:

    import * as fs from 'node:fs';

    import type { FileSystemStats } from './FileSystem';

  4. Update all call sites in the file to use fs (e.g. fs.openSync(...), fs.writeSync(...), fs.closeSync(...), fs.fstatSync(...)) and remove the fsx identifier.

  5. Preserve existing JSDoc and comments and ensure API, types, and exported symbols remain unchanged.

Commit message: "Replace fs-extra with node:fs and move flag conversion helper to module scope"

Create a pull request that applies these changes. Base branch: leave default (do not set base_ref). Include unit tests if necessary (not required).

This pull request was created as a result of the following prompt from Copilot chat.

Make the following changes to libraries/node-core-library/src/FileWriter.ts:

  1. Replace the lazy-loaded fs-extra usage and Import.lazy pattern with the built-in node:fs module.

    • Remove the import of Import and any Import.lazy calls.
    • Add import * as fs from 'node:fs'; and ensure all fs-extra usage is replaced with fs equivalents (openSync, writeSync, closeSync, fstatSync).
  2. Move the private static method _convertFlagsForNode out of the FileWriter class and make it a module-level free function named convertFlagsForNode with the same behavior.

    • Use a template string for concatenation instead of array join or manual concatenation.
    • Add an explicit type annotation : NodeFileFlags to the result variable to satisfy lint rules (no implicit any/implicit typedefs).
  3. Reorder imports so that import * as fs from 'node:fs'; appears before the typed local import with a single blank line between them, i.e.:

    import * as fs from 'node:fs';

    import type { FileSystemStats } from './FileSystem';

  4. Update all call sites in the file to use fs (e.g. fs.openSync(...), fs.writeSync(...), fs.closeSync(...), fs.fstatSync(...)) and remove the fsx identifier.

  5. Preserve existing JSDoc and comments and ensure API, types, and exported symbols remain unchanged.

Commit message: "Replace fs-extra with node:fs and move flag conversion helper to module scope"

Create a pull request that applies these changes. Base branch: leave default (do not set base_ref). Include unit tests if necessary (not required).


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Replace fs-extra with built-in node:fs module [node-core-library] Replace fs-extra with node:fs in FileWriter Dec 4, 2025
Copilot AI requested a review from dmichon-msft December 4, 2025 22:41
@dmichon-msft
Copy link
Contributor

@copilot Run rush change --no-fetch --bump-type patch --message "${description of change}" to create the needed change file for the PR

Copy link
Contributor Author

Copilot AI commented Dec 4, 2025

@copilot Run rush change --no-fetch --bump-type patch --message "${description of change}" to create the needed change file for the PR

Created the Rush change file in commit 11c0379.

@dmichon-msft dmichon-msft marked this pull request as ready for review December 4, 2025 23:57
@dmichon-msft
Copy link
Contributor

Motivation for this change is that the Import.lazy call to fs-extra makes the code bundler-unfriendly and adds next to no value over using the underlying fs module directly.

@dmichon-msft dmichon-msft merged commit 51c0310 into main Dec 5, 2025
12 checks passed
@dmichon-msft dmichon-msft deleted the copilot/replace-fs-extra-with-node-fs branch December 5, 2025 21:57
@github-project-automation github-project-automation bot moved this from Needs triage to Closed in Bug Triage Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

3 participants