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

feat: update #63

Draft
wants to merge 24 commits into
base: rei-yarn
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "yarn",
"installationMethod": "unknown",
"version": "1.22.10",
"version": "1.22.22",
"packageManager": "[email protected]",
"license": "BSD-2-Clause",
"preferGlobal": true,
"description": "📦🐈 Fast, reliable, and secure dependency management.",
Expand Down Expand Up @@ -39,6 +40,7 @@
"object-path": "^0.11.2",
"proper-lockfile": "^2.0.0",
"puka": "^1.0.0",
"punycode": "1.4.1",
"read": "^1.0.7",
"request": "^2.87.0",
"request-capture-har": "^1.2.2",
Expand Down
71 changes: 23 additions & 48 deletions scripts/build-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,22 @@ const resolve = require('resolve');
const util = require('util');
const fs = require('fs');

const version = require('../package.json').version;
const basedir = path.join(__dirname, '../');
const babelRc = JSON.parse(fs.readFileSync(path.join(basedir, '.babelrc'), 'utf8'));

var PnpResolver = {
apply: function(resolver) {
resolver.plugin('resolve', function(request, callback) {
if (request.context.issuer === undefined) {
return callback();
}

let basedir;
let resolved;
// Otherwise Webpack 4 will be "helpful" and automatically mark the `punycode` package as external,
// despite us wanting to bundle it since it will be removed from future Node.js versions.
const binding = process.binding;
process.binding = name => {
let ret = binding(name);

if (!request.context.issuer) {
basedir = request.path;
} else if (request.context.issuer.startsWith('/')) {
basedir = path.dirname(request.context.issuer);
} else {
throw 42;
}

try {
resolved = resolve.sync(request.request, {basedir});
} catch (error) {
// TODO This is not good! But the `debug` package tries to require `supports-color` without declaring it in its
// package.json, and Webpack accepts this because it's in a try/catch, so we need to do it as well.
resolved = false;
}

this.doResolve(['resolved'], Object.assign({}, request, {
path: resolved,
}), '', callback);
});
if (name === `natives`) {
delete ret.punycode;
}

return ret;
};

const pnpOptions = fs.existsSync(`${__dirname}/../.pnp.js`) ? {
resolve: {
plugins: [
PnpResolver,
]
},
resolveLoader: {
plugins: [
PnpResolver,
]
}
} : {};
const version = require('../package.json').version;
const basedir = path.join(__dirname, '../');
const babelRc = JSON.parse(fs.readFileSync(path.join(basedir, '.babelrc'), 'utf8'));

// Use the real node __dirname and __filename in order to get Yarn's source
// files on the user's system. See constants.js
Expand All @@ -74,6 +41,11 @@ const compiler = webpack({
[`artifacts/yarn-${version}.js`]: path.join(basedir, 'src/cli/index.js'),
'packages/lockfile/index.js': path.join(basedir, 'src/lockfile/index.js'),
},
resolve: {
alias: {
punycode: require.resolve(`punycode/`),
},
},
module: {
rules: [
{
Expand Down Expand Up @@ -110,13 +82,12 @@ const compiler = webpack({
},
target: 'node',
node: nodeOptions,
... pnpOptions,
});

compiler.run((err, stats) => {
const fileDependencies = stats.compilation.fileDependencies;
const filenames = fileDependencies.map(x => x.replace(basedir, ''));
console.log(util.inspect(filenames, {maxArrayLength: null}));
//console.log(util.inspect(filenames, {maxArrayLength: null}));
});

//
Expand All @@ -126,6 +97,11 @@ compiler.run((err, stats) => {
const compilerLegacy = webpack({
// devtool: 'inline-source-map',
entry: path.join(basedir, 'src/cli/index.js'),
resolve: {
alias: {
punycode: require.resolve(`punycode/`),
},
},
module: {
rules: [
{
Expand Down Expand Up @@ -157,7 +133,6 @@ const compilerLegacy = webpack({
},
target: 'node',
node: nodeOptions,
... pnpOptions,
});

compilerLegacy.run((err, stats) => {
Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
[
path.join(process.env.COREPACK_ROOT, 'dist/corepack.js'),
`yarn@${flags.install || `stable`}`,
`yarn`,
`init`,
...forwardedArgs,
`--install=self`,
Expand Down
100 changes: 91 additions & 9 deletions src/cli/commands/policies.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/* @flow */
/* eslint-disable max-len */

import type {Reporter} from '../../reporters/index.js';
import type Config from '../../config.js';
import {version} from '../../util/yarn-version.js';
import * as child from '../../util/child.js';
import buildSubCommands from './_build-sub-commands.js';
import {getRcConfigForFolder} from '../../rc.js';
import * as fs from '../../util/fs.js';
import {stringify} from '../../lockfile';
import {satisfiesWithPrereleases} from '../../util/semver.js';
import {NODE_BIN_PATH} from '../../constants';

const V2_NAMES = ['berry', 'stable', 'canary', 'v2', '2'];

const isLocalFile = (version: string) => version.match(/^\.{0,2}[\\/]/) || path.isAbsolute(version);
const isV2Version = (version: string) => satisfiesWithPrereleases(version, '>=2.0.0');

const chalk = require('chalk');
const invariant = require('invariant');
Expand Down Expand Up @@ -49,6 +59,7 @@ async function fetchReleases(
): Promise<Array<Release>> {
const token = process.env.GITHUB_TOKEN;
const tokenUrlParameter = token ? `?access_token=${token}` : '';

const request: Array<Release> = await config.requestManager.request({
url: `https://api.github.com/repos/yarnpkg/yarn/releases${tokenUrlParameter}`,
json: true,
Expand Down Expand Up @@ -98,32 +109,103 @@ export function hasWrapper(flags: Object, args: Array<string>): boolean {

const {run, setFlags, examples} = buildSubCommands('policies', {
async setVersion(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
let range = args[0] || 'latest';
let allowRc = flags.rc;
const initialRange = args[0] || 'latest';
let range = initialRange;

reporter.log(`Resolving ${chalk.yellow(range)} to a url...`);
let allowRc = flags.rc;

if (range === 'rc') {
range = 'latest';
reporter.log(
`${chalk.yellow(
`Warning:`,
)} Your current Yarn binary is currently Yarn ${version}; to avoid potential breaking changes, 'set version rc' won't receive upgrades past the 1.22.x branch.\n To upgrade to the latest versions, run ${chalk.cyan(
`yarn set version`,
)} ${chalk.yellow.underline(`canary`)} instead. Sorry for the inconvenience.\n`,
);

range = '*';
allowRc = true;
}

if (range === 'latest') {
reporter.log(
`${chalk.yellow(
`Warning:`,
)} Your current Yarn binary is currently Yarn ${version}; to avoid potential breaking changes, 'set version latest' won't receive upgrades past the 1.22.x branch.\n To upgrade to the latest versions, run ${chalk.cyan(
`yarn set version`,
)} ${chalk.yellow.underline(`stable`)} instead. Sorry for the inconvenience.\n`,
);

range = '*';
}

if (range === 'classic') {
range = '*';
}

let bundleUrl;
let bundleVersion;
let isV2 = false;
const isV2 = false;

if (range === 'nightly' || range === 'nightlies') {
reporter.log(
`${chalk.yellow(
`Warning:`,
)} Nightlies only exist for Yarn 1.x; starting from 2.x onwards, you should use 'canary' instead`,
);

bundleUrl = 'https://nightly.yarnpkg.com/latest.js';
bundleVersion = 'nightly';
} else if (range === 'berry' || range === 'v2' || range === '2') {
bundleUrl = 'https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js';
bundleVersion = 'berry';
isV2 = true;
} else if (V2_NAMES.includes(range) || isLocalFile(range) || isV2Version(range)) {
const normalizedRange = isV2Version(range) ? range : range === `canary` ? `canary` : `stable`;

if (process.env.COREPACK_ROOT) {
await child.spawn(
NODE_BIN_PATH,
[
path.join(process.env.COREPACK_ROOT, 'dist/corepack.js'),
`yarn@${normalizedRange}`,
`set`,
`version`,
normalizedRange,
],
{
stdio: 'inherit',
cwd: config.cwd,
},
);

return;
} else {
const bundle = await fetchBundle(
config,
'https://github.com/yarnpkg/berry/raw/master/packages/yarnpkg-cli/bin/yarn.js',
);

const yarnPath = path.resolve(config.lockfileFolder, `.yarn/releases/yarn-stable-temp.cjs`);
await fs.mkdirp(path.dirname(yarnPath));
await fs.writeFile(yarnPath, bundle);
await fs.chmod(yarnPath, 0o755);

try {
await child.spawn(NODE_BIN_PATH, [yarnPath, 'set', 'version', range], {
stdio: 'inherit',
cwd: config.lockfileFolder,
env: {
...process.env,
YARN_IGNORE_PATH: `1`,
},
});
} catch (err) {
// eslint-disable-next-line no-process-exit
process.exit(1);
}

return;
}
} else {
reporter.log(`Resolving ${chalk.yellow(initialRange)} to a url...`);

let releases = [];

try {
Expand Down
Loading