Skip to content

Commit

Permalink
Renames yarn.config.js -> yarn.config.cjs (#5733)
Browse files Browse the repository at this point in the history
**What's the problem this PR addresses?**

The `yarn.config.cjs` file doesn't work with projects using `type:
"module"`.

Fixes #5720

**How did you fix it?**

Renames the file into `yarn.config.cjs`. Since it never got released in
a stable release, it should be acceptable to do so without backward
compatibility.

**Checklist**
<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
  • Loading branch information
arcanis authored Sep 13, 2023
1 parent 752bb99 commit d5431bd
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 64 deletions.
34 changes: 34 additions & 0 deletions .yarn/versions/3a69f2b3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": major
"@yarnpkg/core": major

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
2 changes: 1 addition & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
%
% Check this other file in this same repository to see the new way to write constraints, using JS/TS:
%
% yarn.config.js
% yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ exports[`Commands constraints test (empty project / gen_enforced_dependency (amb
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -126,8 +126,8 @@ exports[`Commands constraints test (empty project / gen_enforced_field (ambiguou
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -278,18 +278,18 @@ exports[`Commands constraints test (multiple workspaces / gen_enforced_dependenc
"stderr": "",
"stdout": "├─ root-workspace-0b6124@workspace:.
│ └─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
├─ workspace-a@workspace:packages/workspace-a
│ └─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
└─ workspace-b@workspace:packages/workspace-b
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -354,19 +354,19 @@ exports[`Commands constraints test (multiple workspaces / gen_enforced_dependenc
"stderr": "",
"stdout": "├─ workspace-a@workspace:packages/workspace-a
│ ├─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
│ │ ├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
│ │ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
│ │ ├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
│ │ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
│ └─ Conflict detected in constraint targeting devDependencies["no-deps"]; conflicting values are:
│ ├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
│ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
│ ├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
│ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
└─ workspace-b@workspace:packages/workspace-b
├─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
│ ├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
│ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
│ ├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
│ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
└─ Conflict detected in constraint targeting devDependencies["no-deps"]; conflicting values are:
├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
",
}
`;
Expand Down Expand Up @@ -472,18 +472,18 @@ exports[`Commands constraints test (multiple workspaces / gen_enforced_field (am
"stderr": "",
"stdout": "├─ root-workspace-0b6124@workspace:.
│ └─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
├─ workspace-a@workspace:packages/workspace-a
│ └─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
│ ├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
│ └─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
└─ workspace-b@workspace:packages/workspace-b
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -696,8 +696,8 @@ exports[`Commands constraints test (one regular dependency / gen_enforced_depend
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -744,8 +744,8 @@ exports[`Commands constraints test (one regular dependency / gen_enforced_depend
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
",
}
`;
Expand Down Expand Up @@ -812,8 +812,8 @@ exports[`Commands constraints test (one regular dependency / gen_enforced_field
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -972,8 +972,8 @@ exports[`Commands constraints test (two development dependencies / gen_enforced_
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1016,8 +1016,8 @@ exports[`Commands constraints test (two development dependencies / gen_enforced_
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting devDependencies["no-deps"]; conflicting values are:
├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
",
}
`;
Expand Down Expand Up @@ -1084,8 +1084,8 @@ exports[`Commands constraints test (two development dependencies / gen_enforced_
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1236,8 +1236,8 @@ exports[`Commands constraints test (two regular dependencies / gen_enforced_depe
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1284,8 +1284,8 @@ exports[`Commands constraints test (two regular dependencies / gen_enforced_depe
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
",
}
`;
Expand Down Expand Up @@ -1352,8 +1352,8 @@ exports[`Commands constraints test (two regular dependencies / gen_enforced_fiel
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1512,8 +1512,8 @@ exports[`Commands constraints test (two regular dependencies, two development de
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1561,11 +1561,11 @@ exports[`Commands constraints test (two regular dependencies, two development de
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
├─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
│ ├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
│ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
│ ├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
│ └─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
└─ Conflict detected in constraint targeting devDependencies["no-deps"]; conflicting values are:
├─ undefined at exports.constraints (/path/to/yarn.config.js:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:4:82)
├─ undefined at exports.constraints (/path/to/yarn.config.cjs:3:72)
└─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:82)
",
}
`;
Expand Down Expand Up @@ -1632,8 +1632,8 @@ exports[`Commands constraints test (two regular dependencies, two development de
"stderr": "",
"stdout": "└─ root-workspace-0b6124@workspace:.
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1792,8 +1792,8 @@ exports[`Commands constraints test (various field types / gen_enforced_dependenc
"stderr": "",
"stdout": "└─ foo@workspace:.
└─ Conflict detected in constraint targeting dependencies["no-deps"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down Expand Up @@ -1896,8 +1896,8 @@ exports[`Commands constraints test (various field types / gen_enforced_field (am
"stderr": "",
"stdout": "└─ foo@workspace:.
└─ Conflict detected in constraint targeting dependencies["a-new-dep"]; conflicting values are:
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.js:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.js:4:46)
├─ '1.0.0' at exports.constraints (/path/to/yarn.config.cjs:3:46)
└─ '2.0.0' at exports.constraints (/path/to/yarn.config.cjs:4:46)
",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {

const scriptNames = {
prolog: `constraints.pro`,
js: `yarn.config.js`,
js: `yarn.config.cjs`,
};

const constraints = {
Expand Down Expand Up @@ -98,7 +98,7 @@ describe(`Commands`, () => {
it(`should report custom errors`, makeTemporaryEnv({}, async ({path, run, source}) => {
await run(`install`);

await writeFile(ppath.join(path, `yarn.config.js`), `
await writeFile(ppath.join(path, `yarn.config.cjs`), `
exports.constraints = ({Yarn}) => {
Yarn.workspace().error('This should fail');
};
Expand Down Expand Up @@ -128,7 +128,7 @@ describe(`Commands`, () => {
}

// TODO: Use .replaceAll when we drop support for Node.js v14
stdout = stdout.split(npath.join(npath.fromPortablePath(path), `yarn.config.js`)).join(`/path/to/yarn.config.js`);
stdout = stdout.split(npath.join(npath.fromPortablePath(path), `yarn.config.cjs`)).join(`/path/to/yarn.config.cjs`);
stdout = stdout.replace(/(Module|Object)\.(exports\.)/g, `$2`);

expect({code, stdout, stderr}).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe(`Features`, () => {
makeTemporaryEnv({}, {
enableConstraintsChecks: true,
}, async ({path, run}) => {
await xfs.writeFilePromise(ppath.join(path, `yarn.config.js`), [
await xfs.writeFilePromise(ppath.join(path, `yarn.config.cjs`), [
`exports.constraints = ({ Yarn }) => {\n`,
` for (const workspace of Yarn.workspaces()) {\n`,
` workspace.set('foo', 'bar')\n`,
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus/docs/features/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ It currently doesn't support the following, but might in the future (PRs welcome

## Creating a constraint

Constraints are created by adding a `yarn.config.js` file at the root of your project (repository). This file should export an object with a `constraints` method. This method will be called by the constraints engine, and must define the rules to enforce on the project, using the provided API.
Constraints are created by adding a `yarn.config.cjs` file at the root of your project (repository). This file should export an object with a `constraints` method. This method will be called by the constraints engine, and must define the rules to enforce on the project, using the provided API.

For example, the following `yarn.config.js` will enforce that all `react` dependencies are set to `18.0.0`.
For example, the following `yarn.config.cjs` will enforce that all `react` dependencies are set to `18.0.0`.

```ts
module.exports = {
Expand Down Expand Up @@ -80,7 +80,7 @@ Yarn ships types that make it easier to write constraints. To use them, add the
$ yarn add @yarnpkg/types
```

Then, in your `yarn.config.js` file, import the types, in particular the `defineConfig` function which automatically type the configuration methods:
Then, in your `yarn.config.cjs` file, import the types, in particular the `defineConfig` function which automatically type the configuration methods:

```ts
/** @type {import('@yarnpkg/types')} */
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/static/configuration/yarnrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"constraintsPath": {
"_package": "@yarnpkg/plugin-constraints",
"title": "Path of the constraints file.",
"description": "This only matters for Prolog constraints, which are being deprecated. JavaScript constraints will always be read from the `yarn.config.js` file.",
"description": "This only matters for Prolog constraints, which are being deprecated. JavaScript constraints will always be read from the `yarn.config.cjs` file.",
"type": "string",
"format": "uri-reference",
"default": "./constraints.pro"
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ export class Project {
}

async loadUserConfig() {
const configPath = ppath.join(this.cwd, `yarn.config.js`);
const configPath = ppath.join(this.cwd, `yarn.config.cjs`);
if (!await xfs.existsPromise(configPath))
return null;

Expand Down
File renamed without changes.

0 comments on commit d5431bd

Please sign in to comment.