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

Use Yarn 2 #11962

Merged
merged 17 commits into from Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 5 additions & 20 deletions .circleci/config.yml
@@ -1,25 +1,13 @@
version: 2.1

aliases:
- &restore-node-modules-cache
keys:
- v1-yarn-deps-{{ checksum "yarn.lock" }}
- v1-yarn-deps-

- &restore-yarn-cache
keys:
- v1-1-yarn-cache-{{ checksum "yarn.lock" }}
- v1-1-yarn-cache-

- &save-node-modules-cache
paths:
- node_modules
key: v1-yarn-deps-{{ checksum "yarn.lock" }}
key: v2-yarn-cache-{{ checksum "yarn.lock" }}

- &save-yarn-cache
paths:
- ~/.cache/yarn
key: v1-1-yarn-cache-{{ checksum "yarn.lock" }}
- ~/.yarn/berry/cache
key: v2-yarn-cache-{{ checksum "yarn.lock" }}

- &artifact_babel
path: ~/babel/packages/babel-standalone/babel.js
Expand Down Expand Up @@ -56,7 +44,6 @@ jobs:
steps:
- checkout
- restore_cache: *restore-yarn-cache
- restore_cache: *restore-node-modules-cache
# Builds babel-standalone with the regular Babel config
# test-ci-coverage doesn't test babel-standalone, as trying to gather coverage
- run: IS_PUBLISH=true make -j build-standalone-ci
Expand All @@ -65,7 +52,6 @@ jobs:
- run: yarn jest "\-standalone/test"
- store_artifacts: *artifact_babel
- store_artifacts: *artifact_babel_min
- save_cache: *save-node-modules-cache
- save_cache: *save-yarn-cache

test262:
Expand All @@ -81,7 +67,6 @@ jobs:
git checkout -qf FETCH_HEAD
fi
- restore_cache: *restore-yarn-cache
- restore_cache: *restore-node-modules-cache
- run:
name: Build Babel
command: BABEL_ENV=test make bootstrap
Expand Down Expand Up @@ -121,20 +106,20 @@ jobs:
cat ~/diff.tap | $(npm bin)/tap-merge | $(npm bin)/tap-mocha-reporter xunit | tee ~/test-results/test262/results.xml
<<: *test262_workdir
- store_test_results: *artifact_test262_xunit
- save_cache: *save-yarn-cache

publish-verdaccio:
executor: node-executor
steps:
- checkout
- restore_cache: *restore-yarn-cache
- restore_cache: *restore-node-modules-cache
- run: yarn install
- run: ./scripts/integration-tests/publish-local.sh
- persist_to_workspace:
root: /tmp/verdaccio-workspace
paths:
- storage
- htpasswd
- save_cache: *save-yarn-cache

e2e-babel:
executor: node-executor
Expand Down
3 changes: 1 addition & 2 deletions .codesandbox/ci.json
@@ -1,6 +1,5 @@
{
"installCommand": "codesandbox",
"buildCommand": false,
"buildCommand": "codesandbox:build",
"sandboxes": ["7s08o", "vhm64"],
"packages": ["packages/*"]
}
10 changes: 6 additions & 4 deletions .travis.yml
@@ -1,14 +1,16 @@
git:
depth: 5
language: node_js

cache:
yarn: true
npm: false
directories:
- ~/.yarn/berry/cache

os: linux

env:
global:
- PATH=$HOME/.yarn/bin:$PATH
- JOB=test

install: skip
Expand Down Expand Up @@ -37,13 +39,13 @@ matrix:
# https://travis-ci.community/t/build-doesnt-finish-after-completing-tests/288/9
- YARN_GPG=no
cache:
yarn: true
npm: false
directories:
- $HOME/AppData/Local/Temp/chocolatey
- $HOME/AppData/Local/Yarn/Berry/cache
# Continue node_js matrix
- node_js: "12"
- node_js: "10"
# Node.js 6 and 8 are tested on GitHub actions
- node_js: "node"
env: JOB=babel-parser-flow-tests
- node_js: "node"
Expand Down
31 changes: 31 additions & 0 deletions .yarn-patches/@lerna/npm-publish.patch
@@ -0,0 +1,31 @@
diff --git a/npm-publish.js b/npm-publish.js
index ee6ad133e..6a31d1775 100644
--- a/npm-publish.js
+++ b/npm-publish.js
@@ -32,6 +32,15 @@ const PublishConfig = figgyPudding(
}
);

+function stripWorkspaceProtocolFromDeps(deps) {
+ if (!deps) return;
+ for (const [name, version] of Object.entries(deps)) {
+ if (version.startsWith("workspace:")) {
+ deps[name] = version.slice(10);
+ }
+ }
+}
+
function npmPublish(pkg, tarFilePath, _opts, otpCache) {
const { scope } = npa(pkg.name);
// pass only the package scope to libnpmpublish
@@ -67,6 +76,10 @@ function npmPublish(pkg, tarFilePath, _opts, otpCache) {
manifest.publishConfig.tag = opts.tag;
}

+ stripWorkspaceProtocolFromDeps(manifest.dependencies);
+ stripWorkspaceProtocolFromDeps(manifest.peerDependencies);
+ stripWorkspaceProtocolFromDeps(manifest.devDependencies);
+
return otplease(innerOpts => publish(manifest, tarData, innerOpts), opts, otpCache).catch(err => {
opts.log.silly("", err);
opts.log.error(err.code, (err.body && err.body.error) || err.message);
92 changes: 92 additions & 0 deletions .yarn-patches/@lerna/pack-directory.patch
@@ -0,0 +1,92 @@
diff --git a/lib/pack-directory.js b/lib/pack-directory.js
index d46069c78..2ba6bfea1 100644
--- a/lib/pack-directory.js
+++ b/lib/pack-directory.js
@@ -2,13 +2,13 @@

const path = require("path");
const figgyPudding = require("figgy-pudding");
-const packlist = require("npm-packlist");
const log = require("npmlog");
-const tar = require("tar");
const tempWrite = require("temp-write");
const getPacked = require("@lerna/get-packed");
const Package = require("@lerna/package");
const runLifecycle = require("@lerna/run-lifecycle");
+const util = require("util");
+const exec = util.promisify(require('child_process').exec);

module.exports = packDirectory;

@@ -40,34 +40,23 @@ function packDirectory(_pkg, dir, _opts) {
chain = chain.then(() => pkg.refresh());
}

- chain = chain.then(() => runLifecycle(pkg, "prepack", opts));
- chain = chain.then(() => pkg.refresh());
- chain = chain.then(() => packlist({ path: pkg.contents }));
- chain = chain.then(files =>
- tar.create(
- {
- cwd: pkg.contents,
- prefix: "package/",
- portable: true,
- // Provide a specific date in the 1980s for the benefit of zip,
- // which is confounded by files dated at the Unix epoch 0.
- mtime: new Date("1985-10-26T08:15:00.000Z"),
- gzip: true,
- },
- // NOTE: node-tar does some Magic Stuff depending on prefixes for files
- // specifically with @ signs, so we just neutralize that one
- // and any such future "features" by prepending `./`
- files.map(f => `./${f}`)
- )
+ // We need to call "yarn pack" to remove the "workspace:" protocol from
+ // package.json before publishing
+ chain = chain.then(() => tempWrite("", getTarballName(pkg)));
+ chain = chain.then(tarFilePath =>
+ exec("yarn pack --out " + tarFilePath, { cwd: pkg.location })
+ .then(({ stdout, stderr }) => {
+ const err = stderr.toString();
+ if (err) console.log(err);
+ })
+ .then(() => tarFilePath)
);
- chain = chain.then(stream => tempWrite(stream, getTarballName(pkg)));
chain = chain.then(tarFilePath =>
- getPacked(pkg, tarFilePath).then(packed =>
- Promise.resolve()
- .then(() => runLifecycle(pkg, "postpack", opts))
- .then(() => packed)
- )
+ Promise.resolve()
+ .then(() => pkg.refresh())
+ .then(() => tarFilePath)
);
+ chain = chain.then(tarFilePath => getPacked(pkg, tarFilePath));

return chain;
}
@@ -81,3 +70,7 @@ function getTarballName(pkg) {

return `${name}-${pkg.version}.tgz`;
}
+
+function tap(fn) {
+ return arg => Promise.resolve(fn(arg)).then(() => arg);
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index e00ac73ff..953512b2c 100644
--- a/package.json
+++ b/package.json
@@ -31,9 +31,7 @@
"@lerna/package": "3.16.0",
"@lerna/run-lifecycle": "3.16.2",
"figgy-pudding": "^3.5.1",
- "npm-packlist": "^1.4.4",
"npmlog": "^4.1.2",
- "tar": "^4.4.10",
"temp-write": "^3.4.0"
},
"gitHead": "bb048cb306b5cfcb039aa98f667cf3751cf0ad20"
24 changes: 24 additions & 0 deletions .yarn-patches/@lerna/package-graph.patch
@@ -0,0 +1,24 @@
diff --git a/index.js b/index.js
index f860af4d2..27c4ce21d 100644
--- a/index.js
+++ b/index.js
@@ -57,8 +57,18 @@ class PackageGraph extends Map {
// Yarn decided to ignore https://github.com/npm/npm/pull/15900 and implemented "link:"
// As they apparently have no intention of being compatible, we have to do it for them.
// @see https://github.com/yarnpkg/yarn/issues/4212
- const spec = graphDependencies[depName].replace(/^link:/, "file:");
+ let spec = graphDependencies[depName].replace(/^link:/, "file:");
+
+ // npa doesn't support the explicit workspace: protocol, supported by
+ // pnpm and Yarn.
+ // https://github.com/lerna/lerna/pull/2450
+ const explicitWorkspace = /^workspace:/.test(spec);
+ if (explicitWorkspace) {
+ spec = spec.replace(/^workspace:/, "");
+ }
+
const resolved = npa.resolve(depName, spec, currentNode.location);
+ resolved.explicitWorkspace = explicitWorkspace;

if (!depNode) {
// it's an external dependency, store the resolution and bail
16 changes: 16 additions & 0 deletions .yarn-patches/@lerna/package.patch
@@ -0,0 +1,16 @@
diff --git a/index.js b/index.js
index 67b997073..6e2912e9e 100644
--- a/index.js
+++ b/index.js
@@ -209,6 +209,11 @@ class Package {
if (resolved.registry || resolved.type === "directory") {
// a version (1.2.3) OR range (^1.2.3) OR directory (file:../foo-pkg)
depCollection[depName] = `${savePrefix}${depVersion}`;
+
+ // https://github.com/lerna/lerna/pull/2450
+ if (resolved.explicitWorkspace) {
+ depCollection[depName] = `workspace:${depCollection[depName]}`;
+ }
} else if (resolved.gitCommittish) {
// a git url with matching committish (#v1.2.3 or #1.2.3)
const [tagPrefix] = /^\D*/.exec(resolved.gitCommittish);
17 changes: 17 additions & 0 deletions .yarn-patches/@lerna/version.patch
@@ -0,0 +1,17 @@
diff --git a/command.js b/command.js
index 4109ff1db..86349e057 100644
--- a/command.js
+++ b/command.js
@@ -12,6 +12,12 @@ exports.describe = "Bump version of packages changed since the last release.";

exports.builder = (yargs, composed) => {
const opts = {
+ // THIS IS ONLY USED BY BABEL
+ "exclude-dependents": {
+ describe: "Exclude all transitive dependents.",
+ type: "boolean"
+ },
+
"allow-branch": {
describe: "Specify which branches to allow versioning from.",
type: "array",
11 changes: 11 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-deduplicate.cjs
@@ -0,0 +1,11 @@
/* eslint-disable */
module.exports = {
name: "@yarnpkg/plugin-deduplicate",
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
factory: function (require) {
var plugin;plugin=(()=>{"use strict";var e={587:(e,t,r)=>{r.r(t),r.d(t,{default:()=>d});var o=r(594),s=r(966),a=r(42),n=r(513),i=function(e,t,r,o){var s,a=arguments.length,n=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,o);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(n=(a<3?s(n):a>3?s(t,r,n):s(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n};class c extends o.BaseCommand{async execute(){const e=await s.Configuration.find(this.context.cwd,this.context.plugins),{project:t}=await s.Project.find(e,this.context.cwd);await t.restoreInstallState();const r=await s.StreamReport.start({configuration:e,stdout:this.context.stdout,includeFooter:!1},async e=>{e.startTimerSync("deduplication step",()=>{!function(e,t){const r=new Map;for(const[t,o]of e.storedResolutions.entries()){const s=o,a=e.storedDescriptors.get(t).identHash,n=r.get(a);void 0===n?r.set(a,new Set([s])):r.set(a,n.add(s))}for(const o of e.storedResolutions.keys()){const a=e.storedDescriptors.get(o),i=r.get(a.identHash),c=a.range.match(/^npm:(.*)$/);if(null!==c&&(void 0!==i&&i.size>1)){const r=Array.from(i).map(t=>{const r=e.storedPackages.get(t);if(void 0===r)throw new TypeError(`Can't find package for locator hash '${t}'`);if(s.structUtils.isVirtualLocator(r)){const t=s.structUtils.devirtualizeLocator(r);return e.storedPackages.get(t.locatorHash)}return r}).filter(e=>null!==e.version&&n.satisfies(e.version,c[1])).sort((e,t)=>n.gt(e.version,t.version)?-1:1);if(r.length>1){const n=r[0].locatorHash,i=e.storedResolutions.get(o),c=e.storedPackages.get(n),d=e.storedPackages.get(i);!1===s.structUtils.areLocatorsEqual(d,c)&&(t.reportInfo(s.MessageName.UNNAMED,`${s.structUtils.stringifyDescriptor(a)} can be deduplicated from ${d.name}@${d.version} to ${c.name}@${c.version}`),e.storedResolutions.set(o,n))}}}}
/**
* @license MIT
*/(t,e)})});if(r.hasErrors())return r.exitCode();const o=await s.Cache.find(e);return(await s.StreamReport.start({configuration:e,stdout:this.context.stdout,includeLogs:!0},async e=>{await t.install({cache:o,report:e})})).exitCode()}}c.usage=a.Command.Usage({category:"Workspace-related commands",description:"Reduces dependencies with overlapping ranges to a smaller set of packages",details:"https://github.com/atlassian/yarn-deduplicate for yarn v2",examples:[]}),i([a.Command.Path("deduplicate")],c.prototype,"execute",null);const d={commands:[c]}},594:e=>{e.exports=require("@yarnpkg/cli")},966:e=>{e.exports=require("@yarnpkg/core")},42:e=>{e.exports=require("clipanion")},513:e=>{e.exports=require("semver")}},t={};function r(o){if(t[o])return t[o].exports;var s=t[o]={exports:{}};return e[o](s,s.exports,r),s.exports}return r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(587)})();
return plugin;
}
};
86 changes: 86 additions & 0 deletions .yarn/releases/yarn-2.1.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc
@@ -0,0 +1,3 @@
# Use Yarn 2
# This path should always match the one in .yarnrc.yml
yarn-path ".yarn/releases/yarn-2.1.1.cjs"
14 changes: 14 additions & 0 deletions .yarnrc.yml
@@ -0,0 +1,14 @@
enableGlobalCache: true

enableTransparentWorkspaces: false

nodeLinker: node-modules
JLHwung marked this conversation as resolved.
Show resolved Hide resolved

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-deduplicate.cjs
spec: "https://raw.githubusercontent.com/eps1lon/yarn-plugin-deduplicate/latest/bin/%40yarnpkg/plugin-deduplicate.js"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we will remove this plugin and use built-in yarn dedupe (PR) which is expected to ship in Yarn 2.2.0.


unsafeHttpWhitelist:
- localhost

yarnPath: .yarn/releases/yarn-2.1.1.cjs
12 changes: 2 additions & 10 deletions Gulpfile.js
Expand Up @@ -140,17 +140,9 @@ function buildRollup(packages) {
rollupNodeResolve({
browser: nodeResolveBrowser,
preferBuiltins: true,
//todo: When Yarn workspaces is enabled, remove `dedupe` option
//todo: remove when semver and source-map are bumped to latest versions
dedupe(importee) {
return (
importee.startsWith("lodash/") ||
[
"babel-plugin-dynamic-import-node/utils",
"esutils",
"semver",
"source-map",
].includes(importee)
);
return ["semver", "source-map"].includes(importee);
},
}),
rollupCommonJs({
Expand Down