Skip to content

Commit

Permalink
--offline avoids github tests (no internet); clone depth 1
Browse files Browse the repository at this point in the history
  • Loading branch information
WillForan committed Dec 30, 2023
1 parent c3c8ee3 commit d9ce2dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ const cli = meow(`
Options
--reporter, -r Use a custom reporter
--offline
`, {
importMeta: import.meta,
flags: {
reporter: {
type: 'string',
shortFlag: 'r',
},
offline: {
type: 'boolean',
},
},
});

Expand All @@ -39,6 +43,7 @@ const input = cli.input[0];
const options = {};

options.filename = input ?? findReadmeFile(process.cwd());
options.offline = cli.flags.offline ?? false;

const reporterName = cli.flags.reporter;
if (reporterName) {
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const lint = options => {
filename: options.filename ?? 'readme.md',
};

// 'awesome' and 'awesome-list' topic search will fail after timeout w/o connectivity
// see rules/github.js
if (options.offline) {
options.config = options.config.filter(x => !/remark-lint:awesome-github/.test(x.name));
}

const readmeFile = globbySync(options.filename.replaceAll('\\', '/'), {caseSensitiveMatch: false})[0];

if (!readmeFile) {
Expand Down Expand Up @@ -62,12 +68,16 @@ lint._report = async (options, spinner) => {
let temporary = null;

if (isUrl(options.filename)) {
if (options.offline) {
throw new Error('Attempting to lint url while offline!');
}

if (!isGithubUrl(options.filename, {repository: true})) {
throw new Error(`Invalid GitHub repo URL: ${options.filename}`);
}

temporary = temporaryDirectory();
await execa('git', ['clone', '--', options.filename, temporary]);
await execa('git', ['clone', '--depth', 1, '--', options.filename, temporary]);

const readme = findReadmeFile(temporary);
if (!readme) {
Expand Down

0 comments on commit d9ce2dd

Please sign in to comment.