Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are:
"head": true Use the head of the default branch
"prefix": "v" Specify the prefix used in the module version.
"flaky": true Ignore failures
"skip": true Completely skip the module
"skip": true Completely skip the module. May also be a condition (platform, arch, distro, semver range, or an array/object of these, eg "win32" or ["aix", ">=24"]) to skip only when it matches
"expectFail" Expect the module to fail, error if it passes
"repo": "https://github.com/pugjs/jade" - Use a different github repo
"stripAnsi": true Strip ansi data from output stream of npm
Expand All @@ -140,6 +140,8 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are:
"install": ["install", "--param1", "--param2"] - Array of command line parameters passed to `npm` or `yarn` or `pnpm` as install arguments
"maintainers": ["user1", "user2"] - List of module maintainers to be contacted with issues
"scripts": ["script1", "script2"] - List of scripts from package.json to run instead of 'test'
An entry may also be an object, eg `{ "script": "script2", "skip": "win32" }`,
where the optional "skip" takes the same values as the top-level "skip"; if every entry is skipped, use the top-level "skip" instead
"tags": ["tag1", "tag2"] Specify which tags apply to the module
"useGitClone": true Use a shallow git clone instead of downloading the module
"submodules": ["path/to/submodule"] Initialize only the listed submodules when using a git clone
Expand Down
24 changes: 23 additions & 1 deletion lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,29 @@ export function lookup(context) {
`${context.module.name} lookup-scripts`,
rep.scripts
);
context.module.scripts = rep.scripts;
const scripts = rep.scripts
.map((script) => {
if (typeof script === 'string') {
return script;
}
if (
!script ||
typeof script !== 'object' ||
typeof script.script !== 'string'
) {
throw new TypeError(
`${detail.name}: each "scripts" entry must be a string or an object with a string "script" property`
);
}
return defaultMatcher.isMatch(script.skip) ? null : script.script;
})
.filter((script) => script !== null);
if (scripts.length === 0) {
throw new Error(
`${detail.name}: every "scripts" entry is skipped; use the top-level "skip" instead`
);
}
context.module.scripts = scripts;
}
if (rep.tags) {
context.module.tags = rep.tags;
Expand Down
2 changes: 1 addition & 1 deletion lib/lookup.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
"resolve": {
"prefix": "v",
"maintainers": "ljharb",
"scripts": ["tests-only", "posttest"]
"scripts": ["tests-only", { "script": "posttest", "skip": "win32" }]
},
"rewire": {
"prefix": "v",
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/custom-lookup-scripts-skip-all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"omg-i-pass-with-scripts": {
"prefix": "v",
"scripts": [{ "script": "test", "skip": true }]
}
}
6 changes: 6 additions & 0 deletions test/fixtures/custom-lookup-scripts-skip-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"omg-i-pass-with-scripts": {
"prefix": "v",
"scripts": ["test", { "skip": "win32" }]
}
}
12 changes: 12 additions & 0 deletions test/fixtures/custom-lookup-scripts-skip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"omg-i-pass-with-scripts": {
"prefix": "v",
"scripts": [
"test-build",
{ "script": "test" },
{ "script": "test-skipped", "skip": true },
{ "script": "test-not-skipped", "skip": false },
{ "script": "test-skipped-condition", "skip": ">=0" }
]
}
}
73 changes: 73 additions & 0 deletions test/test-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,79 @@ test('lookup: module in table with scripts', (t) => {
t.end();
});

test('lookup: module in table with conditionally skipped scripts', (t) => {
t.plan(1);
const context = {
module: parsePackageArg('omg-i-pass-with-scripts'),
meta: createFakeMeta({
name: 'omg-i-pass-with-scripts',
repository: {
url: 'git+https://github.com/nodejs/citgm'
}
}),
options: {
lookup: 'test/fixtures/custom-lookup-scripts-skip.json'
},
emit: function () {}
};

lookup(context);
t.strictSame(
context.module.scripts,
['test-build', 'test', 'test-not-skipped'],
'lookup should omit scripts whose skip condition matches'
);
t.end();
});

test('lookup: module in table with invalid scripts entry', (t) => {
t.plan(1);
const context = {
module: parsePackageArg('omg-i-pass-with-scripts'),
meta: createFakeMeta({
name: 'omg-i-pass-with-scripts',
repository: {
url: 'git+https://github.com/nodejs/citgm'
}
}),
options: {
lookup: 'test/fixtures/custom-lookup-scripts-skip-invalid.json'
},
emit: function () {}
};

t.throws(
() => lookup(context),
{ name: 'TypeError', message: /must be a string or an object/ },
'lookup should throw on a scripts entry without a string script'
);
t.end();
});

test('lookup: module in table with every script skipped', (t) => {
t.plan(1);
const context = {
module: parsePackageArg('omg-i-pass-with-scripts'),
meta: createFakeMeta({
name: 'omg-i-pass-with-scripts',
repository: {
url: 'git+https://github.com/nodejs/citgm'
}
}),
options: {
lookup: 'test/fixtures/custom-lookup-scripts-skip-all.json'
},
emit: function () {}
};

t.throws(
() => lookup(context),
/every "scripts" entry is skipped/,
'lookup should throw when every script is skipped'
);
t.end();
});

test('lookup: module in table with useGitClone', (t) => {
t.plan(3);
const context = {
Expand Down
Loading