Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

coolyuantao
Copy link

@coolyuantao coolyuantao commented Mar 30, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of file paths containing spaces or special characters by ensuring command-line arguments are correctly quoted.
    • Enhanced the processing of module import commands to ensure reliable command execution.
  • New Features

    • Introduced new test suites and cases to validate functionality with paths containing spaces.
    • Added new example applications and scripts to demonstrate functionality in paths with spaces.
    • Created new TypeScript declaration files for improved type support in projects.
  • Chores

    • Updated .gitignore to allow tracking of specific node_modules directories.
    • Added new package.json files for various example projects to specify configurations.

Copy link

vercel bot commented Mar 30, 2025

@coolyuantao is attempting to deploy a commit to the no-veronica Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Mar 30, 2025

Walkthrough

This update adds double quotes around file path arguments in several command execution calls to ensure that spaces and special characters in paths are handled as a single argument. Both the runScript calls in the post-install script and the base command, as well as the module import formatting, have been updated. Additionally, the module import processing in the Dev command has been refactored to extract module paths accurately and prevent unintended splitting of arguments. New test cases have been introduced to validate functionality with paths containing spaces.

Changes

File(s) Summary
scripts/postinstall.mjs, src/baseCommand.ts Updated runScript calls by wrapping the file path variable in double quotes to ensure paths with spaces or special characters are handled correctly.
src/baseCommand.ts Modified formatImportModule to return module paths enclosed in double quotes for both ESM and CommonJS formats, with additional handling for Windows paths.
src/commands/dev.ts Refactored the Dev.run method to extract module paths from import strings more precisely, avoiding unwanted splitting by spaces.
.gitignore Added exceptions for specific node_modules directories to be tracked by version control.
test/commands/dev.test.ts, test/commands/test.test.ts Introduced new test suites and cases to validate functionality with paths containing spaces.
Various package.json files in test/fixtures/test path with space Created new package.json files for multiple example projects, specifying names and dependencies.
New test and script files in test/fixtures/test path with space Added new test files and scripts to validate functionality involving spaces in paths.
test/postinstall.test.ts Introduced a test file for the post-installation script to verify execution and output in specified working directories.
test/fixtures/test-postinstall/typings/app/index.d.ts, plugin.d.ts Created TypeScript declaration files to support the Egg framework, including re-exports and interface declarations.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as DevCommand
    participant Formatter as ModuleFormatter
    participant Runner as ScriptRunner

    Dev->>Formatter: Call formatImportModule(module)
    Formatter-->>Dev: Return formatted "--import \"modulePath\""
    Dev->>Dev: Extract module path up to first space
    Dev->>Runner: Invoke runScript with "node \"modulePath\""
Loading

Possibly related PRs

  • fix: enable postinstall #285: Modifies the resolved path of etsBinFile in scripts/postinstall.mjs by explicitly adding the .js extension, related to handling the etsBinFile path but addressing different aspects than this PR.

Poem

I'm a bunny with a clever hop,
Updating code that just won't stop.
Quotes now guard my precious path,
Protecting spaces from coding wrath.
With whiskered cheer, I celebrate,
A change that makes our scripts first-rate!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/baseCommand.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

src/commands/dev.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a9eccc and 34a42eb.

📒 Files selected for processing (2)
  • src/baseCommand.ts (3 hunks)
  • src/commands/dev.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/commands/dev.ts
  • src/baseCommand.ts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fengmk2 fengmk2 requested a review from Copilot March 31, 2025 02:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issues with file path quoting to correctly handle paths containing spaces or special characters in various command-line executions.

  • Updates the module import formatting to properly handle quoted paths.
  • Adds quotes around file paths when executing node scripts.
  • Adjusts quoting in both dev and postinstall scripts for improved reliability.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/commands/dev.ts Refactored module import parsing to correctly split and quote paths.
src/baseCommand.ts Updated command and module import formatting by adding quotes.
scripts/postinstall.mjs Fixed quoting around the ETS script path in postinstall script.

Comment on lines 48 to 53
const splitIndex = module.indexOf(' ');
if (splitIndex !== -1) {
// --require "path to module"
execArgv.push(module.slice(0, splitIndex), module.slice(splitIndex + 2, -1));
Copy link

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

Relying on hardcoded indices for slicing the module string may be brittle if the format changes. Consider using a regular expression to robustly extract the quoted module path.

Suggested change
const splitIndex = module.indexOf(' ');
if (splitIndex !== -1) {
// --require "path to module"
execArgv.push(module.slice(0, splitIndex), module.slice(splitIndex + 2, -1));
const match = module.match(/--require\s+"([^"]+)"/);
if (match) {
// --require "path to module"
execArgv.push('--require', match[1]);

Copilot uses AI. Check for mistakes.

Copy link

pkg-pr-new bot commented Mar 31, 2025

Open in StackBlitz

npm i https://pkg.pr.new/eggjs/bin/@eggjs/bin@289

commit: 34a42eb

@fengmk2
Copy link
Member

fengmk2 commented Mar 31, 2025

Can you add a test to verify what bug was fixed?

@coolyuantao
Copy link
Author

Can you add a test to verify what bug was fixed?

我补下

@coolyuantao coolyuantao force-pushed the fix/run-script-error branch from 5d8b9cf to 6844a14 Compare April 12, 2025 03:48
Copy link

socket-security bot commented Apr 12, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License

View full report

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)

1-1: Consider removing redundant 'use strict' directive

JavaScript modules are automatically in strict mode, so this directive is not necessary. However, since this is a test file specifically for path handling with spaces, this is a minor stylistic suggestion.

-'use strict';
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8b9cf and 6844a14.

⛔ Files ignored due to path filters (14)
  • test/fixtures/example-ts-error-stack/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-app/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-app/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg-ts-helper/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-egg-require/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-egg-require/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-import-script/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-import-script/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-require-script/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-require-script/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test-postinstall/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test-postinstall/node_modules/egg/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (21)
  • .gitignore (1 hunks)
  • scripts/postinstall.mjs (1 hunks)
  • src/baseCommand.ts (3 hunks)
  • src/commands/dev.ts (1 hunks)
  • test/commands/cov.test.ts (1 hunks)
  • test/commands/dev.test.ts (1 hunks)
  • test/commands/test.test.ts (1 hunks)
  • test/fixtures/test path with space/example-app/app.ts (1 hunks)
  • test/fixtures/test path with space/example-app/package.json (1 hunks)
  • test/fixtures/test path with space/example-declarations/package.json (1 hunks)
  • test/fixtures/test path with space/example-egg-require/package.json (1 hunks)
  • test/fixtures/test path with space/example-import-script/package.json (1 hunks)
  • test/fixtures/test path with space/example-require-script/package.json (1 hunks)
  • test/fixtures/test path with space/require script.cjs (1 hunks)
  • test/fixtures/test path with space/require script.mjs (1 hunks)
  • test/fixtures/test path with space/test-files/package.json (1 hunks)
  • test/fixtures/test path with space/test-files/test/t e s t.test.js (1 hunks)
  • test/fixtures/test-postinstall/package.json (1 hunks)
  • test/fixtures/test-postinstall/typings/app/index.d.ts (1 hunks)
  • test/fixtures/test-postinstall/typings/config/plugin.d.ts (1 hunks)
  • test/postinstall.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (11)
  • test/fixtures/test path with space/require script.mjs
  • test/fixtures/test path with space/example-require-script/package.json
  • test/fixtures/test path with space/test-files/package.json
  • test/fixtures/test path with space/example-declarations/package.json
  • test/fixtures/test path with space/require script.cjs
  • test/fixtures/test-postinstall/typings/app/index.d.ts
  • test/fixtures/test path with space/example-egg-require/package.json
  • test/fixtures/test path with space/example-app/package.json
  • test/fixtures/test path with space/example-import-script/package.json
  • test/fixtures/test-postinstall/typings/config/plugin.d.ts
  • test/fixtures/test-postinstall/package.json
🚧 Files skipped from review as they are similar to previous changes (3)
  • scripts/postinstall.mjs
  • src/commands/dev.ts
  • src/baseCommand.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
test/commands/test.test.ts (1)
test/helper.ts (1)
  • getFixtures (11-13)
test/postinstall.test.ts (1)
test/helper.ts (2)
  • getRootDirname (7-9)
  • getFixtures (11-13)
test/commands/dev.test.ts (1)
test/helper.ts (1)
  • getFixtures (11-13)
🪛 Biome (1.9.4)
test/fixtures/test path with space/test-files/test/t e s t.test.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

🔇 Additional comments (13)
test/fixtures/test path with space/example-app/app.ts (1)

1-4: Simple test fixture function looks good

This new function provides a straightforward test fixture for validating path handling functionality with spaces in the path. The implementation is clean and focuses on the specific test scenario.

test/fixtures/test path with space/test-files/test/t e s t.test.js (1)

3-9: Test case looks good

This simple test case is well-structured for testing path handling with spaces in the filename. The test itself is minimal but sufficient for verifying that the file can be properly loaded and executed.

test/postinstall.test.ts (3)

1-8: Test setup is well-structured

Good job setting up the test environment with proper imports and configuration. The NODE_DEBUG variable is appropriately configured for the postinstall script.


9-23: Baseline test case is properly implemented

This test verifies the basic functionality of the postinstall script in a standard environment. The assertions check for appropriate output and exit code, which is good practice.


25-39: Test case for paths with spaces is exactly what was needed

This test case specifically addresses the PR objective of fixing path quoting by testing with a path that contains spaces. Nice work adding this test as requested by the reviewer.

The test correctly:

  1. Uses a fixture path with spaces
  2. Sets up the proper environment
  3. Verifies the expected output and exit code

This will ensure the path quoting fix works correctly.

.gitignore (1)

23-24: Appropriate .gitignore exceptions for test fixtures

These new exceptions allow tracking of necessary node_modules directories in test fixtures, including those with spaces in their paths. This change supports the new tests and is consistent with the existing pattern of exceptions for test fixtures.

test/commands/cov.test.ts (1)

150-158: Improved error handling for coverage output formatting

The changes correctly handle the variable formatting of coverage reports by removing the strict stderr check and replacing it with informative comments that explain the expected behavior. This makes the test more robust when dealing with different terminal outputs.

test/commands/test.test.ts (1)

398-408: Good test case addition for path handling

This test case properly verifies that the test command works correctly with paths containing spaces, which is essential for the PR's goal of fixing path quoting.

test/commands/dev.test.ts (5)

235-244: Well-structured test for basic path handling

This test correctly verifies that the dev command works with spaces in the path. The test uses appropriate fixtures and assertions.


246-254: Good test for TypeScript declarations with paths containing spaces

This test properly verifies that TypeScript declarations work correctly with paths containing spaces, ensuring that the path quoting fix is applied to this functionality as well.


256-264: Comprehensive test for egg.require with path spaces

The test ensures that egg's require functionality works correctly with paths containing spaces, which is important for module loading in custom environments.


266-274: Good verification of --require option with spaces in paths

This test appropriately checks that the --require option correctly handles paths with spaces, which is essential for properly loading CommonJS modules in environments with complex path structures.


276-284:

❓ Verification inconclusive

Thorough test for --import option with spaces in paths

This test verifies that the --import option correctly handles paths with spaces, ensuring that ESM modules can be properly imported regardless of special characters in paths.


🏁 Script executed:

#!/bin/bash
# Let's verify that the fix is applied to the runScript function that handles path quoting

# Find all files with potential path quoting fixes
rg -p "runScript" --glob "*.ts" | grep -v "test" | grep -A 5 -B 5 "path"

Length of output: 68


Attention: Manual Verification Needed for runScript Function

The test implementation for the --import option with paths containing spaces looks solid and confirms that ESM modules function correctly with such paths. However, the verification command to check for path quoting fixes in the runScript function didn’t return any output. Please manually verify that the runScript function (in relevant source files outside of tests) properly handles quoting for paths. If no modifications are required or the changes are confirmed by other means, please update the test documentation accordingly.

@coolyuantao
Copy link
Author

问题详情

某个目录中带有空格、文件中带有空格,导致拼装路径的逻辑出错:

  1. postinstall 中运行 node 时路径
  2. --require, --import 作为 node 运行时参数时的路径

改动思路

添加引号,防止路径被空格截断。特殊说明:windows 下的 \ 是在引号下是转义字符,需转化成\\

改动前

linux, mac:--require /module/path/a.js
windows:--import D:\module\path\a.js

改动后:

linux, mac:--require "/module/path/a.js"
windows:--import "D:\\module\\path\\a.js"

单测覆盖点

  1. 目录带空格
  2. 文件带空格

@fengmk2 fengmk2 requested a review from Copilot April 13, 2025 07:04
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 28 out of 35 changed files in this pull request and generated no comments.

Files not reviewed (7)
  • test/fixtures/test path with space/example-app/package.json: Language not supported
  • test/fixtures/test path with space/example-declarations/package.json: Language not supported
  • test/fixtures/test path with space/example-egg-require/package.json: Language not supported
  • test/fixtures/test path with space/example-import-script/package.json: Language not supported
  • test/fixtures/test path with space/example-require-script/package.json: Language not supported
  • test/fixtures/test path with space/test-files/package.json: Language not supported
  • test/fixtures/test-postinstall/package.json: Language not supported
Comments suppressed due to low confidence (1)

src/commands/dev.ts:47

  • If no space is found in the module string, nothing is pushed to execArgv, which may result in a missing argument. Consider adding an else branch that pushes the module as-is to ensure all modules are handled.
const module = this.formatImportModule(r);

@coolyuantao coolyuantao force-pushed the fix/run-script-error branch from 6844a14 to 9a9eccc Compare April 14, 2025 01:52
@coolyuantao
Copy link
Author

有个文件提交漏了,现在应该OK了

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)

6-6: Minor grammar issue in test name

The test name "should success" is grammatically incorrect. Consider changing to "should succeed" for better readability.

-    it('should success', () => {
+    it('should succeed', () => {
test/commands/dev.test.ts (1)

238-239: Test could benefit from validating error scenarios

The tests validate that the fix works for successful execution, but consider adding tests that verify error scenarios are handled properly when paths with spaces are involved.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6844a14 and 9a9eccc.

⛔ Files ignored due to path filters (15)
  • test/fixtures/example-ts-error-stack/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-app/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-app/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg-ts-helper/dist/bin.js is excluded by !**/dist/**, !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg-ts-helper/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-declarations/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-egg-require/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-egg-require/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-import-script/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-import-script/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-require-script/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test path with space/example-require-script/node_modules/egg/package.json is excluded by !**/node_modules/**
  • test/fixtures/test-postinstall/node_modules/egg/index.js is excluded by !**/node_modules/**
  • test/fixtures/test-postinstall/node_modules/egg/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (21)
  • .gitignore (2 hunks)
  • scripts/postinstall.mjs (1 hunks)
  • src/baseCommand.ts (3 hunks)
  • src/commands/dev.ts (1 hunks)
  • test/commands/cov.test.ts (1 hunks)
  • test/commands/dev.test.ts (1 hunks)
  • test/commands/test.test.ts (1 hunks)
  • test/fixtures/test path with space/example-app/app.ts (1 hunks)
  • test/fixtures/test path with space/example-app/package.json (1 hunks)
  • test/fixtures/test path with space/example-declarations/package.json (1 hunks)
  • test/fixtures/test path with space/example-egg-require/package.json (1 hunks)
  • test/fixtures/test path with space/example-import-script/package.json (1 hunks)
  • test/fixtures/test path with space/example-require-script/package.json (1 hunks)
  • test/fixtures/test path with space/require script.cjs (1 hunks)
  • test/fixtures/test path with space/require script.mjs (1 hunks)
  • test/fixtures/test path with space/test-files/package.json (1 hunks)
  • test/fixtures/test path with space/test-files/test/t e s t.test.js (1 hunks)
  • test/fixtures/test-postinstall/package.json (1 hunks)
  • test/fixtures/test-postinstall/typings/app/index.d.ts (1 hunks)
  • test/fixtures/test-postinstall/typings/config/plugin.d.ts (1 hunks)
  • test/postinstall.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (19)
  • test/fixtures/test path with space/example-import-script/package.json
  • test/fixtures/test path with space/example-app/app.ts
  • test/fixtures/test path with space/example-require-script/package.json
  • test/fixtures/test path with space/example-declarations/package.json
  • test/fixtures/test-postinstall/package.json
  • test/postinstall.test.ts
  • scripts/postinstall.mjs
  • test/commands/test.test.ts
  • test/fixtures/test path with space/test-files/package.json
  • test/fixtures/test path with space/require script.mjs
  • test/commands/cov.test.ts
  • test/fixtures/test path with space/require script.cjs
  • .gitignore
  • src/baseCommand.ts
  • test/fixtures/test path with space/example-egg-require/package.json
  • src/commands/dev.ts
  • test/fixtures/test-postinstall/typings/config/plugin.d.ts
  • test/fixtures/test path with space/example-app/package.json
  • test/fixtures/test-postinstall/typings/app/index.d.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/commands/dev.test.ts (1)
test/helper.ts (1)
  • getFixtures (11-13)
🪛 Biome (1.9.4)
test/fixtures/test path with space/test-files/test/t e s t.test.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

🔇 Additional comments (3)
test/fixtures/test path with space/test-files/test/t e s t.test.js (1)

1-9: Well-constructed test file with spaces in the path

This test file's path explicitly contains spaces to validate the fix for handling paths with spaces in directories or files, which aligns perfectly with the PR objectives. The simple test ensures that basic functionality works in the space-containing environment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

test/commands/dev.test.ts (2)

235-286: Comprehensive test coverage for paths with spaces

These tests effectively validate the fix for handling paths with spaces in various scenarios:

  • Basic application execution
  • TypeScript declarations support
  • Egg require functionality
  • Module imports with --require and --import flags

The tests are well-structured and provide excellent coverage for the issue mentioned in the PR objectives.


267-267:

✅ Verification successful

Verify path handling consistency across environments

The test uses a space in the script filename ('require script.cjs'). This is good for testing but ensure that the path handling logic in the implementation properly quotes and escapes these paths on all operating systems.


🏁 Script executed:

#!/bin/bash
# Check how spaces in paths are handled in the implementation

# Search for relevant path handling code
rg "formatImportModule|runScript" -A 5 -B 5

Length of output: 8329


Path Quoting Verification Passed

The implementation has been reviewed, and the path handling logic appears to be robust across environments. In particular:

  • In src/baseCommand.ts, the formatImportModule function correctly distinguishes between ESM and non-ESM modes. For ESM, it uses pathToFileURL to safely convert file paths, while on Windows it applies path.win32.normalize along with appropriate escaping.
  • Multiple uses of runScript (e.g., in both src/baseCommand.ts and scripts/postinstall.mjs) confirm that command strings are wrapped in quotes, ensuring that paths with spaces (like "require script.cjs") are handled correctly.

Based on these findings, there is no further action required regarding path quoting.

@fengmk2
Copy link
Member

fengmk2 commented Apr 14, 2025

感谢,ci 过了就合并发布

Copy link

codecov bot commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 43.75000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 90.70%. Comparing base (2e2e3cf) to head (9a9eccc).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/commands/dev.ts 0.00% 8 Missing ⚠️
src/baseCommand.ts 85.71% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (2e2e3cf) and HEAD (9a9eccc). Click for more details.

HEAD has 16 uploads less than BASE
Flag BASE (2e2e3cf) HEAD (9a9eccc)
18 2
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
- Coverage   95.85%   90.70%   -5.15%     
==========================================
  Files          22       18       -4     
  Lines        1085     1108      +23     
  Branches      172      153      -19     
==========================================
- Hits         1040     1005      -35     
- Misses         45      103      +58     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 merged commit dcff9ac into eggjs:master Apr 19, 2025
24 of 25 checks passed
@fengmk2
Copy link
Member

fengmk2 commented Apr 19, 2025

@coolyuantao 感谢参与开源❤️

fengmk2 pushed a commit that referenced this pull request Apr 19, 2025
[skip ci]

## [7.3.1](v7.3.0...v7.3.1) (2025-04-19)

### Bug Fixes

* properly quote paths ([#289](#289)) ([dcff9ac](dcff9ac))
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