Skip to content

Commit 2fdeced

Browse files
targosMylesBorins
authored andcommitted
lookup: deprecate and rename "master" field to "head" (#848)
Patch the lookup object in memory for backwards-compatibility.
1 parent b23b086 commit 2fdeced

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are:
127127

128128
```
129129
"npm": true Download the module from npm instead of github
130-
"master": true Use the master branch
130+
"head": true Use the head of the default branch
131131
"prefix": "v" Specify the prefix used in the module version.
132132
"flaky": true Ignore failures
133133
"skip": true Completely skip the module

lib/lookup.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function makeUrl(repo, spec, tags, prefix, sha) {
1212
let version;
1313
if (!spec)
1414
// Spec should already have defaulted to latest.
15-
version = 'master';
15+
version = 'HEAD';
1616
else if (tags[spec]) version = tags[spec];
1717
// Matches npm tags like 'latest' or 'next'.
1818
// `spec` must match one of `meta.versions` as npm info call passed.
@@ -30,7 +30,7 @@ function makeUrl(repo, spec, tags, prefix, sha) {
3030

3131
function makeClone(repo, spec, tags, prefix) {
3232
let version;
33-
if (!spec) version = 'master';
33+
if (!spec) version = 'HEAD';
3434
else version = (prefix || '') + tags[spec];
3535
return {
3636
url: `${repo}.git`,
@@ -56,7 +56,27 @@ function getLookupTable(options) {
5656
if (typeof options.lookup === 'string') {
5757
name = path.resolve(process.cwd(), options.lookup);
5858
}
59-
return require(name);
59+
const lookup = require(name);
60+
61+
// Backwards-compatibility: replace "master" key with "head".
62+
let warningEmitted = false;
63+
for (const moduleName of Object.keys(lookup)) {
64+
const moduleConfig = lookup[moduleName];
65+
if (moduleConfig.master !== undefined) {
66+
if (!warningEmitted) {
67+
process.emitWarning(
68+
'The "master" key in lookup entries is deprecated. Use "head" instead. ' +
69+
`Found in "${name}" for module "${moduleName}".`,
70+
'DeprecationWarning'
71+
);
72+
warningEmitted = true;
73+
}
74+
moduleConfig.head = moduleConfig.master;
75+
delete moduleConfig.master;
76+
}
77+
}
78+
79+
return lookup;
6080
} catch (err) {
6181
return undefined;
6282
}
@@ -107,7 +127,7 @@ function resolve(context) {
107127
if (rep.useGitClone) {
108128
const { url, ref } = makeClone(
109129
getRepo(rep.repo, meta),
110-
rep.master ? null : detail.fetchSpec,
130+
rep.head ? null : detail.fetchSpec,
111131
meta['dist-tags'],
112132
rep.prefix
113133
);
@@ -121,12 +141,12 @@ function resolve(context) {
121141
context.module.raw = url;
122142
context.module.ref = ref;
123143
} else {
124-
const gitHead = rep.master || rep.ignoreGitHead ? null : meta.gitHead;
144+
const gitHead = rep.head || rep.ignoreGitHead ? null : meta.gitHead;
125145
const url = makeUrl(
126146
getRepo(rep.repo, meta),
127-
rep.master ? null : detail.fetchSpec,
147+
rep.head ? null : detail.fetchSpec,
128148
meta['dist-tags'],
129-
rep.master ? null : rep.prefix,
149+
rep.head ? null : rep.prefix,
130150
context.options.sha || rep.sha || gitHead
131151
);
132152
context.emit(

lib/lookup.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
},
8585
"cheerio": {
8686
"skip": "win32",
87-
"master": true,
87+
"head": true,
8888
"maintainers": ["matthewmueller", "jugglinmike"]
8989
},
9090
"clinic": {
@@ -136,7 +136,7 @@
136136
"envVar": { "YARN_IGNORE_ENGINES": "true" },
137137
"prefix": "v",
138138
"flaky": ["win32", "rhel", "sles"],
139-
"master": true,
139+
"head": true,
140140
"expectFail": "fips",
141141
"maintainers": ["stefanpenner", "rwjblue", "Turbo87", "kellyselden"]
142142
},
@@ -300,7 +300,7 @@
300300
"maintainers": "substack"
301301
},
302302
"mkdirp": {
303-
"master": true,
303+
"head": true,
304304
"skip": true,
305305
"maintainers": "substack"
306306
},
@@ -447,7 +447,7 @@
447447
},
448448
"socket.io": {
449449
"maintainers": "rauchg",
450-
"master": true
450+
"head": true
451451
},
452452
"spawn-wrap": {
453453
"prefix": "v",
@@ -470,7 +470,7 @@
470470
"split2": {
471471
"prefix": "v",
472472
"maintainers": "mcollina",
473-
"master": true
473+
"head": true
474474
},
475475
"sqlite3": {
476476
"prefix": "v",
@@ -542,7 +542,7 @@
542542
},
543543
"vinyl-fs": {
544544
"prefix": "v",
545-
"master": true,
545+
"head": true,
546546
"maintainers": ["contra", "phated"],
547547
"skip": true
548548
},

test/fixtures/custom-lookup-log.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"omg-i-pass": {
33
"install": ["--extra-param"],
4-
"master": true,
4+
"head": true,
55
"replace": true,
66
"repo": "https://github.com/nodejs/citgm"
77
}

test/test-lookup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ test('lookup: makeUrl', (t) => {
2020

2121
const sha = 'abc123';
2222

23-
let expected = `${repo}/archive/master.tar.gz`;
23+
let expected = `${repo}/archive/HEAD.tar.gz`;
2424
let url = makeUrl(repo);
25-
t.equal(url, expected, 'by default makeUrl should give a link to master');
25+
t.equal(url, expected, 'by default makeUrl should give a link to HEAD');
2626

2727
expected = `${repo}/archive/${tags.latest}.tar.gz`;
2828
url = makeUrl(repo, 'latest', tags);
@@ -171,7 +171,7 @@ test('lookup: module in table', (t) => {
171171
lookup(context);
172172
t.equals(
173173
context.module.raw,
174-
'https://github.com/lodash/lodash/archive/master.tar.gz',
174+
'https://github.com/lodash/lodash/archive/HEAD.tar.gz',
175175
'raw should be truthy if the module was in the list'
176176
);
177177
t.end();
@@ -404,7 +404,7 @@ test('lookup: logging', (t) => {
404404
{
405405
type: 'info',
406406
key: 'omg-i-pass lookup-replace',
407-
msg: 'https://github.com/nodejs/citgm/archive/master.tar.gz'
407+
msg: 'https://github.com/nodejs/citgm/archive/HEAD.tar.gz'
408408
},
409409
{
410410
type: 'verbose',

0 commit comments

Comments
 (0)