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

preconstruct doesn't make files for paths, containing curly braces #439

Open
MurzNN opened this issue Jan 13, 2022 · 5 comments · May be fixed by #442
Open

preconstruct doesn't make files for paths, containing curly braces #439

MurzNN opened this issue Jan 13, 2022 · 5 comments · May be fixed by #442

Comments

@MurzNN
Copy link

MurzNN commented Jan 13, 2022

By what reason preconstruct command can not make files for paths, containing curly braces? Here is example of line from packages/keystone/package.json from keystone project:

      "___internal-do-not-use-will-break-in-patch/admin-ui/{next-config.ts,id-field-view.tsx}",

But it doesn't produce the node_modules/@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config/dist/keystone-6-core-___internal-do-not-use-will-break-in-patch-admin-ui-next-config.cjs.js file.

But if I expose braces to separate lines like this:

      "___internal-do-not-use-will-break-in-patch/admin-ui/next-config.ts",
      "___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx",

it starts working well!

Via preconstruct validate I even can see that it catch those files:

$ npx preconstruct validate | grep next-config
🎁 info @keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config a valid entry point exists.
🎁 info @keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config main field is valid
🎁 info @keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config module field is valid

but with curly braces - not:

$ npx preconstruct validate | grep next-config
<empty output>

The version is @preconstruct/cli@2.1.5, but interesting thing that on other project same version works well with curly braces!

Is there any debug mode exists to understand what happening in this situation?

@MurzNN
Copy link
Author

MurzNN commented Jan 14, 2022

Here is how to reproduce the issue:

Failure:

  1. Initialize empty project, create package json like this:
{
  "name": "ks-preconstruct",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true,
  "preconstruct": {
    "packages": [
      "keystone_core/packages/*",
      "keystone_core/design-system/packages/*",
      "keystone_core/prisma-utils"
    ]
  },
  "workspaces": {
    "packages": [
      "keystone_core/packages/*",
      "keystone_core/design-system/packages/*",
      "keystone_core/prisma-utils"
    ],
    "nohoist": [
      "**/cypress-multi-reporters"
    ]
  },
  "dependencies": {
    "@preconstruct/cli": "2.1.5"
  }
}
  1. Download keystone to the subfolder keystone_core:
git clone https://github.com/keystonejs/keystone.git keystone_core
  1. Run yarn install
  2. Run the preconstruct validate process with grepping by next-config and see empty output:
$ npx preconstruct validate | grep next-config
<empty output>

Success:

  1. Clone keystone project to empty directory:
git clone https://github.com/keystonejs/keystone.git && cd keystone
  1. Run yarn install
  2. Run the preconstruct validate process with grepping by next-config and see that those files are caught successfully:
$ npx preconstruct validate | grep next-config
🎁 info @keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config a valid entry point exists.
🎁 info @keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config main field is valid
🎁 info @keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config module field is valid

So, where can be the source of that issue?

@MurzNN
Copy link
Author

MurzNN commented Jan 14, 2022

Seems this is an issue with fast-glob function, here is code to reproduce the problem:

const fg = require('fast-glob');

let entries;

entries = fg.sync([
  "keystone_core/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/{next-config.ts,id-field-view.tsx}",
  "keystone_core/packages/keystone/src/artifacts.ts"
], { dot: true });

console.log('expansions', entries);

entries = fg.sync([
  "keystone_core/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx",
  "keystone_core/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/next-config.ts",
  "keystone_core/packages/keystone/src/artifacts.ts"
], { dot: true });

console.log('direct', entries);

and the output:

expansions [ 'keystone_core/packages/keystone/src/artifacts.ts' ]
direct [
  'keystone_core/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx',
  'keystone_core/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/next-config.ts',
  'keystone_core/packages/keystone/src/artifacts.ts'
]

@MurzNN
Copy link
Author

MurzNN commented Jan 14, 2022

I've figured out the source of this problem, here is the issue: mrmlnc/fast-glob#351
Before it is solved, maybe good to lock it's version in preconstruct? Here is my PR with this #441

And here https://github.com/Murz-forks/preconstruct-cli-build is my compiled version of @preconstruct/cli with that fix, which can be installed quickly via:

  "dependencies": {
    "@preconstruct/cli": "Murz-forks/preconstruct-cli-build",
  }

@MurzNN
Copy link
Author

MurzNN commented Jan 15, 2022

This issue is fixed in fast-glob 3.2.11, so we should bump version.

@MurzNN
Copy link
Author

MurzNN commented Jan 17, 2022

I've found an easier way to force set deep dependency version - add to package.json this:

  "resolutions": {
    "@preconstruct/cli/fast-glob": "^3.2.11"
  }

Documentation is here https://classic.yarnpkg.com/en/docs/selective-version-resolutions/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant