Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore glob on Copy Assets Handler doesn't work on Windows #23050

Closed
1 of 4 tasks
sjoholma opened this issue Apr 27, 2024 · 0 comments · Fixed by #23065
Closed
1 of 4 tasks

Ignore glob on Copy Assets Handler doesn't work on Windows #23050

sjoholma opened this issue Apr 27, 2024 · 0 comments · Fixed by #23065

Comments

@sjoholma
Copy link

sjoholma commented Apr 27, 2024

Current Behavior

Copy Assets Handler ignore glob doesn't work on Windows due to path.join changing glob forward slashes to backslashes.

Let's suppose I have the following three files in my src folder:

  • index.ts
  • index.test.ts
  • assets.json

And I would want to copy only the assets.json to my target folder.

Now using the configuration produces the expected result on OS'ses using forward slash, but not on Windows as it uses backslash.

"build": {
  "executor": "@nx/js:tsc",
  "options": {
    // shortened...
    "assets": [
      {
        "input": "./src",
        "glob": "**/*",
        "output": "./src",
        "ignore": ['**/*.ts']
      }
    ]
  }
}

On Windows the ignore glob is turned into src\\**\\*.ts which doesn't match any of the files and thus all files are copied over.

Expected Behavior

Only assets.json should be copied over as index.ts and index.test.ts should match the ignore glob.

GitHub Repo

No response

Steps to Reproduce

  1. See description in current behaviour

Nx Report

Node   : 20.12.1
OS     : win32-x64
npm    : 10.5.0

nx             : 18.3.4
@nx/js         : 18.3.4
@nx/jest       : 18.3.4
@nx/linter     : 18.3.4
@nx/eslint     : 18.3.4
@nx/workspace  : 18.3.4
@nx/devkit     : 18.3.4
@nrwl/tao      : 18.3.4
typescript     : 5.4.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Copy Assets Handler uses minimatch here:

!ag.ignore?.some((ig) => minimatch(pathFromRoot, ig)) &&

And here:

!assetGlob.ignore?.some((ig) => minimatch(src, ig)) &&

Minimatch instructs to use only forward slashes on Windows as I have done:
https://github.com/isaacs/minimatch/blob/main/README.md#windows

But the problem seems to be here where the glob is joined with input path:

if (f.ignore) ignore = f.ignore.map((ig) => path.join(f.input, ig));

Changing that to this should fix the issue:

// minimatch only supports Unix paths
if (f.ignore) ignore = f.ignore.map((ig) => path.join(f.input, ig).replace(/\\/g, '/'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants