Skip to content

Commit 4392d8c

Browse files
Use Yarn 2 (babel#11167)
* Update husky * Update Makefile * Update CI config * Update e2e and utils bash scripts * Patch lerna * Directly spawn node. This won't work with PnP * Don't make lerna ignore codemods and eslint packages * Add yarn.lock * Use process.execPath * Updates the e2e upgrade * Updates build * Update e2e old babel * Fix e2e babel old * Simplify e2e old babel script * Update lockfile * Update preset-env fixtures * Remove nested lock files * Fix codesandbox
1 parent d45d4c9 commit 4392d8c

File tree

35 files changed

+28322
-18787
lines changed

35 files changed

+28322
-18787
lines changed

.circleci/config.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
version: 2.1
22

33
aliases:
4-
- &restore-node-modules-cache
5-
keys:
6-
- v1-yarn-deps-{{ checksum "yarn.lock" }}
7-
84
- &restore-yarn-cache
9-
keys:
10-
- v1-yarn-cache
11-
12-
- &save-node-modules-cache
13-
paths:
14-
- node_modules
15-
key: v1-yarn-deps-{{ checksum "yarn.lock" }}
5+
key: v2-yarn-cache-{{ checksum "yarn.lock" }}
166

177
- &save-yarn-cache
188
paths:
19-
- ~/.yarn-cache
20-
key: v1-yarn-cache
9+
- .yarn/cache
10+
key: v2-yarn-cache-{{ checksum "yarn.lock" }}
2111

2212
- &artifact_babel
2313
path: ~/babel/packages/babel-standalone/babel.js
@@ -54,7 +44,6 @@ jobs:
5444
steps:
5545
- checkout
5646
- restore_cache: *restore-yarn-cache
57-
- restore_cache: *restore-node-modules-cache
5847
# Builds babel-standalone with the regular Babel config
5948
# test-ci-coverage doesn't test babel-standalone, as trying to gather coverage
6049
- run: IS_PUBLISH=true make -j build-standalone-ci
@@ -63,7 +52,6 @@ jobs:
6352
- run: yarn jest "\-standalone/test"
6453
- store_artifacts: *artifact_babel
6554
- store_artifacts: *artifact_babel_min
66-
- save_cache: *save-node-modules-cache
6755
- save_cache: *save-yarn-cache
6856

6957
test262:
@@ -79,7 +67,6 @@ jobs:
7967
git checkout -qf FETCH_HEAD
8068
fi
8169
- restore_cache: *restore-yarn-cache
82-
- restore_cache: *restore-node-modules-cache
8370
- run:
8471
name: Build Babel
8572
command: BABEL_ENV=test make bootstrap
@@ -119,20 +106,20 @@ jobs:
119106
cat ~/diff.tap | $(npm bin)/tap-merge | $(npm bin)/tap-mocha-reporter xunit | tee ~/test-results/test262/results.xml
120107
<<: *test262_workdir
121108
- store_test_results: *artifact_test262_xunit
122-
- save_cache: *save-node-modules-cache
123109
- save_cache: *save-yarn-cache
124110

125111
publish-verdaccio:
126112
executor: node-executor
127113
steps:
128114
- checkout
129-
- run: yarn install
115+
- restore_cache: *restore-yarn-cache
130116
- run: ./scripts/integration-tests/publish-local.sh
131117
- persist_to_workspace:
132118
root: /tmp/verdaccio-workspace
133119
paths:
134120
- storage
135121
- htpasswd
122+
- save_cache: *save-yarn-cache
136123

137124
e2e-babel:
138125
executor: node-executor

.codesandbox/ci.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"installCommand": "codesandbox",
3-
"buildCommand": false,
2+
"buildCommand": "codesandbox:build",
43
"sandboxes": ["7s08o", "vhm64"],
54
"packages": ["packages/*"]
65
}

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
git:
22
depth: 5
33
language: node_js
4+
45
cache:
5-
yarn: true
6+
npm: false
7+
directories:
8+
- .yarn/cache
69

710
os: linux
811

912
env:
1013
global:
11-
- PATH=$HOME/.yarn/bin:$PATH
1214
- JOB=test
1315

1416
install: skip
@@ -37,9 +39,10 @@ matrix:
3739
# https://travis-ci.community/t/build-doesnt-finish-after-completing-tests/288/9
3840
- YARN_GPG=no
3941
cache:
40-
yarn: true
42+
npm: false
4143
directories:
4244
- $HOME/AppData/Local/Temp/chocolatey
45+
- .yarn/cache
4346
# Continue node_js matrix
4447
- node_js: "12"
4548
- node_js: "10"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
diff --git a/npm-publish.js b/npm-publish.js
2+
index ee6ad133e..6a31d1775 100644
3+
--- a/npm-publish.js
4+
+++ b/npm-publish.js
5+
@@ -32,6 +32,15 @@ const PublishConfig = figgyPudding(
6+
}
7+
);
8+
9+
+function stripWorkspaceProtocolFromDeps(deps) {
10+
+ if (!deps) return;
11+
+ for (const [name, version] of Object.entries(deps)) {
12+
+ if (version.startsWith("workspace:")) {
13+
+ deps[name] = version.slice(10);
14+
+ }
15+
+ }
16+
+}
17+
+
18+
function npmPublish(pkg, tarFilePath, _opts, otpCache) {
19+
const { scope } = npa(pkg.name);
20+
// pass only the package scope to libnpmpublish
21+
@@ -67,6 +76,10 @@ function npmPublish(pkg, tarFilePath, _opts, otpCache) {
22+
manifest.publishConfig.tag = opts.tag;
23+
}
24+
25+
+ stripWorkspaceProtocolFromDeps(manifest.dependencies);
26+
+ stripWorkspaceProtocolFromDeps(manifest.peerDependencies);
27+
+ stripWorkspaceProtocolFromDeps(manifest.devDependencies);
28+
+
29+
return otplease(innerOpts => publish(manifest, tarData, innerOpts), opts, otpCache).catch(err => {
30+
opts.log.silly("", err);
31+
opts.log.error(err.code, (err.body && err.body.error) || err.message);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
diff --git a/lib/pack-directory.js b/lib/pack-directory.js
2+
index d46069c78..2ba6bfea1 100644
3+
--- a/lib/pack-directory.js
4+
+++ b/lib/pack-directory.js
5+
@@ -2,13 +2,13 @@
6+
7+
const path = require("path");
8+
const figgyPudding = require("figgy-pudding");
9+
-const packlist = require("npm-packlist");
10+
const log = require("npmlog");
11+
-const tar = require("tar");
12+
const tempWrite = require("temp-write");
13+
const getPacked = require("@lerna/get-packed");
14+
const Package = require("@lerna/package");
15+
const runLifecycle = require("@lerna/run-lifecycle");
16+
+const util = require("util");
17+
+const exec = util.promisify(require('child_process').exec);
18+
19+
module.exports = packDirectory;
20+
21+
@@ -40,34 +40,23 @@ function packDirectory(_pkg, dir, _opts) {
22+
chain = chain.then(() => pkg.refresh());
23+
}
24+
25+
- chain = chain.then(() => runLifecycle(pkg, "prepack", opts));
26+
- chain = chain.then(() => pkg.refresh());
27+
- chain = chain.then(() => packlist({ path: pkg.contents }));
28+
- chain = chain.then(files =>
29+
- tar.create(
30+
- {
31+
- cwd: pkg.contents,
32+
- prefix: "package/",
33+
- portable: true,
34+
- // Provide a specific date in the 1980s for the benefit of zip,
35+
- // which is confounded by files dated at the Unix epoch 0.
36+
- mtime: new Date("1985-10-26T08:15:00.000Z"),
37+
- gzip: true,
38+
- },
39+
- // NOTE: node-tar does some Magic Stuff depending on prefixes for files
40+
- // specifically with @ signs, so we just neutralize that one
41+
- // and any such future "features" by prepending `./`
42+
- files.map(f => `./${f}`)
43+
- )
44+
+ // We need to call "yarn pack" to remove the "workspace:" protocol from
45+
+ // package.json before publishing
46+
+ chain = chain.then(() => tempWrite("", getTarballName(pkg)));
47+
+ chain = chain.then(tarFilePath =>
48+
+ exec("yarn pack --out " + tarFilePath, { cwd: pkg.location })
49+
+ .then(({ stdout, stderr }) => {
50+
+ const err = stderr.toString();
51+
+ if (err) console.log(err);
52+
+ })
53+
+ .then(() => tarFilePath)
54+
);
55+
- chain = chain.then(stream => tempWrite(stream, getTarballName(pkg)));
56+
chain = chain.then(tarFilePath =>
57+
- getPacked(pkg, tarFilePath).then(packed =>
58+
- Promise.resolve()
59+
- .then(() => runLifecycle(pkg, "postpack", opts))
60+
- .then(() => packed)
61+
- )
62+
+ Promise.resolve()
63+
+ .then(() => pkg.refresh())
64+
+ .then(() => tarFilePath)
65+
);
66+
+ chain = chain.then(tarFilePath => getPacked(pkg, tarFilePath));
67+
68+
return chain;
69+
}
70+
@@ -81,3 +70,7 @@ function getTarballName(pkg) {
71+
72+
return `${name}-${pkg.version}.tgz`;
73+
}
74+
+
75+
+function tap(fn) {
76+
+ return arg => Promise.resolve(fn(arg)).then(() => arg);
77+
+}
78+
\ No newline at end of file
79+
diff --git a/package.json b/package.json
80+
index e00ac73ff..953512b2c 100644
81+
--- a/package.json
82+
+++ b/package.json
83+
@@ -31,9 +31,7 @@
84+
"@lerna/package": "3.16.0",
85+
"@lerna/run-lifecycle": "3.16.2",
86+
"figgy-pudding": "^3.5.1",
87+
- "npm-packlist": "^1.4.4",
88+
"npmlog": "^4.1.2",
89+
- "tar": "^4.4.10",
90+
"temp-write": "^3.4.0"
91+
},
92+
"gitHead": "bb048cb306b5cfcb039aa98f667cf3751cf0ad20"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/index.js b/index.js
2+
index f860af4d2..27c4ce21d 100644
3+
--- a/index.js
4+
+++ b/index.js
5+
@@ -57,8 +57,18 @@ class PackageGraph extends Map {
6+
// Yarn decided to ignore https://github.com/npm/npm/pull/15900 and implemented "link:"
7+
// As they apparently have no intention of being compatible, we have to do it for them.
8+
// @see https://github.com/yarnpkg/yarn/issues/4212
9+
- const spec = graphDependencies[depName].replace(/^link:/, "file:");
10+
+ let spec = graphDependencies[depName].replace(/^link:/, "file:");
11+
+
12+
+ // npa doesn't support the explicit workspace: protocol, supported by
13+
+ // pnpm and Yarn.
14+
+ // https://github.com/lerna/lerna/pull/2450
15+
+ const explicitWorkspace = /^workspace:/.test(spec);
16+
+ if (explicitWorkspace) {
17+
+ spec = spec.replace(/^workspace:/, "");
18+
+ }
19+
+
20+
const resolved = npa.resolve(depName, spec, currentNode.location);
21+
+ resolved.explicitWorkspace = explicitWorkspace;
22+
23+
if (!depNode) {
24+
// it's an external dependency, store the resolution and bail

.yarn-patches/@lerna/package.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/index.js b/index.js
2+
index 67b997073..6e2912e9e 100644
3+
--- a/index.js
4+
+++ b/index.js
5+
@@ -209,6 +209,11 @@ class Package {
6+
if (resolved.registry || resolved.type === "directory") {
7+
// a version (1.2.3) OR range (^1.2.3) OR directory (file:../foo-pkg)
8+
depCollection[depName] = `${savePrefix}${depVersion}`;
9+
+
10+
+ // https://github.com/lerna/lerna/pull/2450
11+
+ if (resolved.explicitWorkspace) {
12+
+ depCollection[depName] = `workspace:${depCollection[depName]}`;
13+
+ }
14+
} else if (resolved.gitCommittish) {
15+
// a git url with matching committish (#v1.2.3 or #1.2.3)
16+
const [tagPrefix] = /^\D*/.exec(resolved.gitCommittish);

.yarn-patches/@lerna/version.patch

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/command.js b/command.js
2+
index 4109ff1db..86349e057 100644
3+
--- a/command.js
4+
+++ b/command.js
5+
@@ -12,6 +12,12 @@ exports.describe = "Bump version of packages changed since the last release.";
6+
7+
exports.builder = (yargs, composed) => {
8+
const opts = {
9+
+ // THIS IS ONLY USED BY BABEL
10+
+ "exclude-dependents": {
11+
+ describe: "Exclude all transitive dependents.",
12+
+ type: "boolean"
13+
+ },
14+
+
15+
"allow-branch": {
16+
describe: "Specify which branches to allow versioning from.",
17+
type: "array",

0 commit comments

Comments
 (0)