Skip to content

Commit 487d1e6

Browse files
authored
Makes enableScripts: false the default (#7089)
## What's the problem this PR addresses? <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> I was planning to wait until the next major to land this, but considering the regularity of package compromissions, I think we need to address it sooner than that. ## How did you fix it? <!-- A detailed description of your implementation. --> Disables running scripts by default. ## 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.
1 parent 7469b9c commit 487d1e6

File tree

15 files changed

+126
-9
lines changed

15 files changed

+126
-9
lines changed

.pnp.cjs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/5cc386c8.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/core": minor
4+
"@yarnpkg/doctor": patch
5+
"@yarnpkg/plugin-essentials": minor
6+
7+
declined:
8+
- "@yarnpkg/plugin-catalog"
9+
- "@yarnpkg/plugin-compat"
10+
- "@yarnpkg/plugin-constraints"
11+
- "@yarnpkg/plugin-dlx"
12+
- "@yarnpkg/plugin-exec"
13+
- "@yarnpkg/plugin-file"
14+
- "@yarnpkg/plugin-git"
15+
- "@yarnpkg/plugin-github"
16+
- "@yarnpkg/plugin-http"
17+
- "@yarnpkg/plugin-init"
18+
- "@yarnpkg/plugin-interactive-tools"
19+
- "@yarnpkg/plugin-jsr"
20+
- "@yarnpkg/plugin-link"
21+
- "@yarnpkg/plugin-nm"
22+
- "@yarnpkg/plugin-npm"
23+
- "@yarnpkg/plugin-npm-cli"
24+
- "@yarnpkg/plugin-pack"
25+
- "@yarnpkg/plugin-patch"
26+
- "@yarnpkg/plugin-pnp"
27+
- "@yarnpkg/plugin-pnpm"
28+
- "@yarnpkg/plugin-stage"
29+
- "@yarnpkg/plugin-typescript"
30+
- "@yarnpkg/plugin-version"
31+
- "@yarnpkg/plugin-workspace-tools"
32+
- "@yarnpkg/builder"
33+
- "@yarnpkg/extensions"
34+
- "@yarnpkg/nm"
35+
- "@yarnpkg/pnpify"
36+
- "@yarnpkg/sdks"

packages/acceptance-tests/pkg-tests-specs/sources/commands/install.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,49 @@ describe(`Commands`, () => {
6060
}),
6161
);
6262

63+
test(
64+
`it should migrate old lockfiles by setting enableScripts to true when unset`,
65+
makeTemporaryEnv({
66+
dependencies: {
67+
[`no-deps`]: `1.0.0`,
68+
},
69+
}, async ({path, run}) => {
70+
const lockfilePath = ppath.join(path, Filename.lockfile);
71+
const rcPath = ppath.join(path, Filename.rc);
72+
73+
await run(`install`);
74+
75+
const lockfile = await xfs.readFilePromise(lockfilePath, `utf8`);
76+
const match = lockfile.match(/^__metadata:\r?\n {2}version: (\d+)$/m);
77+
78+
expect(match).not.toBeNull();
79+
const currentVersion = Number(match![1]);
80+
const previousVersion = Math.max(0, currentVersion - 1);
81+
82+
const downgraded = lockfile.replace(
83+
/^(__metadata:\r?\n {2}version: )\d+$/m,
84+
`$1${previousVersion}`,
85+
);
86+
87+
expect(downgraded).not.toEqual(lockfile);
88+
await xfs.writeFilePromise(lockfilePath, downgraded);
89+
90+
await expect(xfs.existsPromise(rcPath)).resolves.toBeFalsy();
91+
92+
await run(`install`);
93+
94+
await expect(xfs.readFilePromise(rcPath, `utf8`)).resolves.toContain(`enableScripts: true`);
95+
}),
96+
);
97+
6398
test(
6499
`it should print the logs to the standard output when using --inline-builds`,
65100
makeTemporaryEnv({
66101
dependencies: {
67102
[`no-deps-scripted`]: `1.0.0`,
68103
},
104+
}, {
105+
enableScripts: true,
69106
}, async ({path, run, source}) => {
70107
const {stdout} = await run(`install`, `--inline-builds`);
71108

@@ -80,6 +117,8 @@ describe(`Commands`, () => {
80117
dependencies: {
81118
[`no-deps-scripted`]: `1.0.0`,
82119
},
120+
}, {
121+
enableScripts: true,
83122
}, async ({path, run, source}) => {
84123
const {stdout} = await run(`install`, `--inline-builds`, `--mode=skip-build`);
85124

@@ -94,6 +133,8 @@ describe(`Commands`, () => {
94133
dependencies: {
95134
[`no-deps-scripted`]: `1.0.0`,
96135
},
136+
}, {
137+
enableScripts: true,
97138
}, async ({path, run, source}) => {
98139
const pnpPath = ppath.join(path, Filename.pnpCjs);
99140

packages/acceptance-tests/pkg-tests-specs/sources/commands/rebuild.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ describe(`Commands`, () => {
77
[`no-deps-scripted`]: `1.0.0`,
88
[`no-deps-scripted-bis`]: `1.0.0`,
99
},
10+
}, {
11+
enableScripts: true,
1012
}, async ({path, run, source}) => {
1113
await run(`install`);
1214

@@ -45,6 +47,8 @@ describe(`Commands`, () => {
4547
[`no-deps-scripted`]: `1.0.0`,
4648
[`no-deps-scripted-bis`]: `1.0.0`,
4749
},
50+
}, {
51+
enableScripts: true,
4852
}, async ({path, run, source}) => {
4953
await run(`install`);
5054

packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ describe(`Dragon tests`, () => {
692692
`pkg-b`,
693693
],
694694
},
695+
{
696+
enableScripts: true,
697+
},
695698
async ({path, run, source}) => {
696699
// This dragon test represents the following scenario:
697700
//

packages/acceptance-tests/pkg-tests-specs/sources/features/installArtifactCleanup.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ describe(`Install Artifact Cleanup`, () => {
7373
[`no-deps-scripted`]: `1.0.0`,
7474
},
7575
}, {
76+
enableScripts: true,
7677
pnpEnableEsmLoader: true,
7778
}, async ({path, run, source}) => {
7879
await run(`install`);

packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe(`Node_Modules`, () => {
105105
},
106106
},
107107
{
108+
enableScripts: true,
108109
nodeLinker: `node-modules`,
109110
},
110111
async ({path, run, source}) => {
@@ -1760,6 +1761,7 @@ describe(`Node_Modules`, () => {
17601761
},
17611762
},
17621763
{
1764+
enableScripts: true,
17631765
nodeLinker: `node-modules`,
17641766
},
17651767
async ({path, run, source}) => {

packages/acceptance-tests/pkg-tests-specs/sources/pnp.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,9 @@ describe(`Plug'n'Play`, () => {
13261326
{
13271327
dependencies: {[`no-deps-scripted`]: `1.0.0`},
13281328
},
1329+
{
1330+
enableScripts: true,
1331+
},
13291332
async ({path, run, source}) => {
13301333
await run(`install`);
13311334

@@ -1389,6 +1392,9 @@ describe(`Plug'n'Play`, () => {
13891392
{
13901393
dependencies: {[`no-deps-scripted`]: `1.0.0`},
13911394
},
1395+
{
1396+
enableScripts: true,
1397+
},
13921398
async ({path, run, source}) => {
13931399
await run(`install`);
13941400

@@ -1953,6 +1959,9 @@ describe(`Plug'n'Play`, () => {
19531959
'no-deps-scripted': `*`,
19541960
},
19551961
},
1962+
{
1963+
enableScripts: true,
1964+
},
19561965
async ({path, run, source}) => {
19571966
await run(`install`);
19581967

packages/acceptance-tests/pkg-tests-specs/sources/script.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ describe(`Scripts tests`, () => {
342342

343343
test(
344344
`it should run install scripts during the install`,
345-
makeTemporaryEnv({dependencies: {[`no-deps-scripted`]: `1.0.0`}}, async ({path, run, source}) => {
345+
makeTemporaryEnv({dependencies: {[`no-deps-scripted`]: `1.0.0`}}, {
346+
enableScripts: true,
347+
}, async ({path, run, source}) => {
346348
await run(`install`);
347349

348350
await expect(source(`require('no-deps-scripted/log.js')`)).resolves.toEqual([
@@ -457,7 +459,9 @@ describe(`Scripts tests`, () => {
457459

458460
test(
459461
`it should abort with an error if a package can't be built`,
460-
makeTemporaryEnv({dependencies: {[`no-deps-scripted-to-fail`]: `1.0.0`}}, async ({path, run, source}) => {
462+
makeTemporaryEnv({dependencies: {[`no-deps-scripted-to-fail`]: `1.0.0`}}, {
463+
enableScripts: true,
464+
}, async ({path, run, source}) => {
461465
await expect(run(`install`)).rejects.toThrow();
462466
}),
463467
);
@@ -522,6 +526,9 @@ describe(`Scripts tests`, () => {
522526
{
523527
dependencies: {[`binding-gyp-scripts`]: `1.0.0`},
524528
},
529+
{
530+
enableScripts: true,
531+
},
525532
async ({path, run, source}) => {
526533
await run(`install`, {env: {}});
527534

@@ -540,6 +547,8 @@ describe(`Scripts tests`, () => {
540547
dependencies: {
541548
[`no-deps-scripted`]: `1.0.0`,
542549
},
550+
}, {
551+
enableScripts: true,
543552
}, async ({path, run, source}) => {
544553
await run(`install`);
545554

packages/docusaurus/docs/features/security.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Our implementation has a couple of differences with the npm one. Like most other
1717
You can exclude your `devDependencies` (and their transitive dependencies) from the report by running the command with `--environment production`.
1818
:::
1919

20+
## Postinstalls
21+
22+
Yarn doesn't run postinstalls by default ever since 4.14. You must either enable them globally by adding `enableScripts: true` to your `.yarnrc.yml`, or on a by-package basis using `dependenciesMeta` in your top-level `package.json`.
23+
24+
## Age gate
25+
26+
Yarn 4.12 introduced `npmMinimalAgeGate` to restrict packages installed on your machine to only packages that got published at least N days prior. The `npmPreapprovedPackages` setting also lets you bypass this check for specific packages.
27+
2028
## Hardened mode
2129

2230
The hardened mode can be set (or disabled) using either the `enableHardenedMode` setting or by defining `YARN_ENABLE_HARDENED_MODE=1|0` in your environment variables, but in most cases you won't even have to think about it - the hardened mode is enabled by default when Yarn detects it runs in a pull request from a public GitHub repository.

0 commit comments

Comments
 (0)