Skip to content

Commit

Permalink
Merge branch 'master' into support-version-apply-exact
Browse files Browse the repository at this point in the history
  • Loading branch information
snowystinger authored Jan 13, 2025
2 parents a07cd9b + 93a5664 commit 6d53d5b
Show file tree
Hide file tree
Showing 16 changed files with 701 additions and 614 deletions.
24 changes: 13 additions & 11 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@ describe(`Commands`, () => {
expect(xfs.existsSync(`${path}/.yarn/cache`)).toEqual(false);
expect(xfs.existsSync(`${path}/.yarn/global/cache`)).toEqual(false);
}));

test(`it should follow the enableCacheClean configuration`, makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, {
enableCacheClean: false,
}, async ({path, run, source}) => {
await run(`install`);
await expect(run(`cache`, `clean`)).rejects.toThrowError();
}));
});
});
62 changes: 60 additions & 2 deletions packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ describe(`Plug'n'Play - ESM`, () => {
),
);

test(
// @ts-expect-error - Missing types
(process.features.require_module ? it.skip : it)(
`it should throw ERR_REQUIRE_ESM when requiring a file with type=module`,
makeTemporaryEnv(
{
Expand Down Expand Up @@ -643,7 +644,36 @@ describe(`Plug'n'Play - ESM`, () => {
),
);

test(
// @ts-expect-error - Missing types
(process.features.require_module ? it : it.skip)(
`it should not throw ERR_REQUIRE_ESM when requiring a file with type=module`,
makeTemporaryEnv(
{
dependencies: {
'no-deps-esm': `1.0.0`,
},
},
{
pnpEnableEsmLoader: true,
},
async ({path, run, source}) => {
await run(`install`);

await xfs.writeFilePromise(ppath.join(path, `index.js`), `
require('no-deps-esm')
console.log('ESM required')
`);

await expect(run(`node`, `index.js`)).resolves.toMatchObject({
code: 0,
stdout: `ESM required\n`,
});
},
),
);

// @ts-expect-error - Missing types
(process.features.require_module ? it.skip : it)(
`it should throw ERR_REQUIRE_ESM when requiring a .mjs file`,
makeTemporaryEnv(
{
Expand Down Expand Up @@ -673,6 +703,34 @@ describe(`Plug'n'Play - ESM`, () => {
),
);

// @ts-expect-error - Missing types
(process.features.require_module ? it : it.skip)(
`it should not throw ERR_REQUIRE_ESM when requiring a .mjs file`,
makeTemporaryEnv(
{
dependencies: {
'no-deps-mjs': `1.0.0`,
},
},
{
pnpEnableEsmLoader: true,
},
async ({path, run, source}) => {
await run(`install`);

await xfs.writeFilePromise(ppath.join(path, `index.js`), `
require('no-deps-mjs/index.mjs')
console.log('ESM required')
`);

await expect(run(`node`, `index.js`)).resolves.toMatchObject({
code: 0,
stdout: `ESM required\n`,
});
},
),
);

test(
`it should throw ERR_MODULE_NOT_FOUND when statically importing a nonexistent file`,
makeTemporaryEnv(
Expand Down
574 changes: 287 additions & 287 deletions packages/berry-cli/bin/berry.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/plugin-essentials/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yarnpkg/plugin-essentials",
"version": "4.2.2",
"version": "4.3.0",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
Expand Down Expand Up @@ -54,5 +54,5 @@
"engines": {
"node": ">=18.12.0"
},
"stableVersion": "4.2.2"
"stableVersion": "4.3.0"
}
6 changes: 5 additions & 1 deletion packages/plugin-essentials/sources/commands/cache/clean.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Cache, StreamReport, Hooks} from '@yarnpkg/core';
import {xfs} from '@yarnpkg/fslib';
import {Command, Option, Usage} from 'clipanion';
import {Command, Option, Usage, UsageError} from 'clipanion';

// eslint-disable-next-line arca/no-default-export
export default class CacheCleanCommand extends BaseCommand {
Expand Down Expand Up @@ -34,6 +34,10 @@ export default class CacheCleanCommand extends BaseCommand {

async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

if (!configuration.get(`enableCacheClean`))
throw new UsageError(`Cache cleaning is currently disabled. To enable it, set \`enableCacheClean: true\` in your configuration file. Note: Cache cleaning is typically not required and should be avoided when using Zero-Installs.`);

const cache = await Cache.find(configuration);

const report = await StreamReport.start({
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-pnp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yarnpkg/plugin-pnp",
"version": "4.0.5",
"version": "4.0.6",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
Expand Down Expand Up @@ -46,5 +46,5 @@
"engines": {
"node": ">=18.12.0"
},
"stableVersion": "4.0.5"
"stableVersion": "4.0.6"
}
4 changes: 2 additions & 2 deletions packages/plugin-workspace-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yarnpkg/plugin-workspace-tools",
"version": "4.1.1",
"version": "4.1.2",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
Expand Down Expand Up @@ -50,5 +50,5 @@
"engines": {
"node": ">=18.12.0"
},
"stableVersion": "4.1.1"
"stableVersion": "4.1.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
}

if (this.exclude.length > 0 && (micromatch.isMatch(structUtils.stringifyIdent(workspace.anchoredLocator), this.exclude) || micromatch.isMatch(workspace.relativeCwd, this.exclude))) {
log(`Excluding ${workspace.relativeCwd} because it matches the --include filter`);
log(`Excluding ${workspace.relativeCwd} because it matches the --exclude filter`);
continue;
}

Expand Down
574 changes: 287 additions & 287 deletions packages/yarnpkg-cli/bin/yarn.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/yarnpkg-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yarnpkg/cli",
"version": "4.5.3",
"version": "4.6.0",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
Expand Down Expand Up @@ -110,5 +110,5 @@
"engines": {
"node": ">=18.12.0"
},
"stableVersion": "4.5.3"
"stableVersion": "4.6.0"
}
8 changes: 6 additions & 2 deletions packages/yarnpkg-core/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@yarnpkg/core",
"version": "4.1.6",
"version": "4.2.0",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
".": "./sources/index.ts",
"./structUtils": "./sources/structUtils.ts",
"./semverUtils": "./sources/semverUtils.ts",
"./package.json": "./package.json"
},
"sideEffects": false,
Expand Down Expand Up @@ -69,6 +71,8 @@
"main": "./lib/index.js",
"exports": {
".": "./lib/index.js",
"./structUtils": "./lib/structUtils.js",
"./semverUtils": "./lib/semverUtils.js",
"./package.json": "./package.json"
}
},
Expand All @@ -83,5 +87,5 @@
"engines": {
"node": ">=18.12.0"
},
"stableVersion": "4.1.6"
"stableVersion": "4.2.0"
}
5 changes: 5 additions & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
type: SettingsType.BOOLEAN,
default: false,
},
enableCacheClean: {
description: `If false, disallows the \`cache clean\` command`,
type: SettingsType.BOOLEAN,
default: true,
},
checksumBehavior: {
description: `Enumeration defining what to do when a checksum doesn't match expectations`,
type: SettingsType.STRING,
Expand Down
4 changes: 2 additions & 2 deletions packages/yarnpkg-pnp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yarnpkg/pnp",
"version": "4.0.7",
"version": "4.0.8",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
Expand Down Expand Up @@ -51,5 +51,5 @@
"engines": {
"node": ">=18.12.0"
},
"stableVersion": "4.0.7"
"stableVersion": "4.0.8"
}
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions packages/yarnpkg-pnp/sources/loader/applyPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,23 @@ export function applyPatch(pnpapi: PnpApi, opts: ApplyPatchOptions) {
return false;
};

// https://github.com/nodejs/node/blob/3743406b0a44e13de491c8590386a964dbe327bb/lib/internal/modules/cjs/loader.js#L1110-L1154
const originalExtensionJSFunction = Module._extensions[`.js`] as (module: NodeModule, filename: string) => void;
Module._extensions[`.js`] = function (module: NodeModule, filename: string) {
if (filename.endsWith(`.js`)) {
const pkg = nodeUtils.readPackageScope(filename);
if (pkg && pkg.data?.type === `module`) {
const err = nodeUtils.ERR_REQUIRE_ESM(filename, module.parent?.filename);
Error.captureStackTrace(err);
throw err;
// @ts-expect-error - Missing types
if (!process.features.require_module) {
// https://github.com/nodejs/node/blob/3743406b0a44e13de491c8590386a964dbe327bb/lib/internal/modules/cjs/loader.js#L1110-L1154
const originalExtensionJSFunction = Module._extensions[`.js`] as (module: NodeModule, filename: string) => void;
Module._extensions[`.js`] = function (module: NodeModule, filename: string) {
if (filename.endsWith(`.js`)) {
const pkg = nodeUtils.readPackageScope(filename);
if (pkg && pkg.data?.type === `module`) {
const err = nodeUtils.ERR_REQUIRE_ESM(filename, module.parent?.filename);
Error.captureStackTrace(err);
throw err;
}
}
}

originalExtensionJSFunction.call(this, module, filename);
};
originalExtensionJSFunction.call(this, module, filename);
};
}

const originalDlopen = process.dlopen;
process.dlopen = function (...args) {
Expand Down

0 comments on commit 6d53d5b

Please sign in to comment.