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

allow scripts related checks. #70

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28,178 changes: 28,178 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"execa": "^5.1.1",
"lodash": "^4.17.21",
"superstruct": "^1.0.3",
"yaml": "^2.4.1",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
152 changes: 130 additions & 22 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import execa from 'execa';
import path from 'path';
import { MockWritable } from 'stdio-mock';
import stripAnsi from 'strip-ansi';
import { stringify } from 'yaml';

import { main } from './main';
import { FakeOutputLogger } from '../tests/fake-output-logger';
Expand Down Expand Up @@ -61,10 +62,6 @@ describe('main', () => {
await ensureDirectoryStructureExists(
path.join(repository.directoryPath, 'src'),
);
await writeFile(
path.join(repository.directoryPath, '.yarnrc.yml'),
'',
);
await writeFile(
path.join(
repository.directoryPath,
Expand Down Expand Up @@ -96,6 +93,8 @@ describe('main', () => {
typescript: '1.0.0',
typedoc: '1.0.0',
'@metamask/auto-changelog': '1.0.0',
'@lavamoat/allow-scripts': '1.0.0',
'@lavamoat/preinstall-always-fail': '1.0.0',
},
scripts: {
test: 'test script',
Expand All @@ -109,6 +108,12 @@ describe('main', () => {
repository: {
url: 'https://github.com/MetaMask/module-lint.git',
},
lavamoat: {
allowScripts: {
'tsup>esbuild': true,
'@lavamoat/preinstall-always-fail': false,
},
},
}),
);
await writeFile(
Expand Down Expand Up @@ -155,6 +160,25 @@ describe('main', () => {
path.join(repository.directoryPath, '.gitignore'),
'content for .gitignore',
);
await writeFile(
path.join(repository.directoryPath, '.yarnrc.yml'),
stringify({
enableScripts: false,
plugins: [
{
path: '.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs',
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js',
},
],
}),
);
await writeFile(
path.join(
repository.directoryPath,
'.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs',
),
'test scripts',
);
}
const outputLogger = new FakeOutputLogger();

Expand Down Expand Up @@ -193,6 +217,8 @@ repo-1
- Do the typedoc-related \`scripts\` in \`package.json\` conform? ✅
- Do the changelog-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the changelog-related \`scripts\` in \`package.json\` conform? ✅
- Do the lavamoat-related \`devDependencies\` in \`package.json\` conform? ✅
- Does lavamoat lists \`@lavamoat/preinstall-always-fail: false\` in allow scripts? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -210,8 +236,10 @@ repo-1
- Is \`.editorconfig\` present, and does it conform? ✅
- Is \`.gitattributes\` present, and does it conform? ✅
- Is \`.gitignore\` present, and does it conform? ✅
- Does allow scripts conforms to yarn? ✅
- Does yarn plugins conforms to allow scripts? ✅

Results: 36 passed, 0 failed, 36 total
Results: 40 passed, 0 failed, 40 total
Elapsed time: 0 ms


Expand All @@ -237,6 +265,8 @@ repo-2
- Do the typedoc-related \`scripts\` in \`package.json\` conform? ✅
- Do the changelog-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the changelog-related \`scripts\` in \`package.json\` conform? ✅
- Do the lavamoat-related \`devDependencies\` in \`package.json\` conform? ✅
- Does lavamoat lists \`@lavamoat/preinstall-always-fail: false\` in allow scripts? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -254,8 +284,10 @@ repo-2
- Is \`.editorconfig\` present, and does it conform? ✅
- Is \`.gitattributes\` present, and does it conform? ✅
- Is \`.gitignore\` present, and does it conform? ✅
- Does allow scripts conforms to yarn? ✅
- Does yarn plugins conforms to allow scripts? ✅

Results: 36 passed, 0 failed, 36 total
Results: 40 passed, 0 failed, 40 total
Elapsed time: 0 ms

`,
Expand All @@ -282,6 +314,20 @@ Elapsed time: 0 ms
for (const repository of repositories.slice(1)) {
await writeFile(path.join(repository.directoryPath, '.yarnrc'), '');
}
for (const repository of repositories) {
await writeFile(
path.join(repository.directoryPath, '.yarnrc.yml'),
stringify({
enableScripts: true,
plugins: [
{
path: '.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs',
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js',
},
],
}),
);
}
const outputLogger = new FakeOutputLogger();

await main({
Expand All @@ -307,7 +353,6 @@ repo-1
- Is \`README.md\` present? ❌
- \`README.md\` does not exist in this project.
- Are all of the files for Yarn Modern present, and do they conform? ❌
- \`.yarnrc.yml\` does not exist in this project.
- \`.yarn/releases/\` does not exist in this project.
- \`.yarn/plugins/\` does not exist in this project.
- Does the \`src/\` directory exist? ❌
Expand All @@ -332,8 +377,12 @@ repo-1
- \`.gitattributes\` does not exist in this project.
- Is \`.gitignore\` present, and does it conform? ❌
- \`.gitignore\` does not exist in this project.
- Does allow scripts conforms to yarn? ❌
- \`.yarnrc.yml\` should list \`'enableScripts': false\`, but does not.
- Does yarn plugins conforms to allow scripts? ❌
- \`.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs\` does not exist in this project.

Results: 0 passed, 15 failed, 15 total
Results: 0 passed, 17 failed, 17 total
Elapsed time: 0 ms


Expand All @@ -347,7 +396,6 @@ repo-2
- Is \`README.md\` present? ❌
- \`README.md\` does not exist in this project.
- Are all of the files for Yarn Modern present, and do they conform? ❌
- \`.yarnrc.yml\` does not exist in this project.
- \`.yarn/releases/\` does not exist in this project.
- \`.yarn/plugins/\` does not exist in this project.
- Does the \`src/\` directory exist? ❌
Expand All @@ -372,8 +420,12 @@ repo-2
- \`.gitattributes\` does not exist in this project.
- Is \`.gitignore\` present, and does it conform? ❌
- \`.gitignore\` does not exist in this project.
- Does allow scripts conforms to yarn? ❌
- \`.yarnrc.yml\` should list \`'enableScripts': false\`, but does not.
- Does yarn plugins conforms to allow scripts? ❌
- \`.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs\` does not exist in this project.

Results: 0 passed, 15 failed, 15 total
Results: 0 passed, 17 failed, 17 total
Elapsed time: 0 ms

`,
Expand Down Expand Up @@ -456,8 +508,10 @@ repo-2
- \`.gitattributes\` does not exist in this project.
- Is \`.gitignore\` present, and does it conform? ❌
- \`.gitignore\` does not exist in this project.
- Does allow scripts conforms to yarn? ✅
- Does yarn plugins conforms to allow scripts? ✅

Results: 1 passed, 14 failed, 15 total
Results: 3 passed, 14 failed, 17 total
Elapsed time: 0 ms

`.trimStart(),
Expand Down Expand Up @@ -486,10 +540,6 @@ Elapsed time: 0 ms
await ensureDirectoryStructureExists(
path.join(repository.directoryPath, 'src'),
);
await writeFile(
path.join(repository.directoryPath, '.yarnrc.yml'),
'',
);
await writeFile(
path.join(
repository.directoryPath,
Expand Down Expand Up @@ -521,6 +571,8 @@ Elapsed time: 0 ms
typescript: '1.0.0',
typedoc: '1.0.0',
'@metamask/auto-changelog': '1.0.0',
'@lavamoat/allow-scripts': '1.0.0',
'@lavamoat/preinstall-always-fail': '1.0.0',
},
scripts: {
test: 'test script',
Expand All @@ -534,6 +586,12 @@ Elapsed time: 0 ms
repository: {
url: 'https://github.com/MetaMask/module-lint.git',
},
lavamoat: {
allowScripts: {
'tsup>esbuild': true,
'@lavamoat/preinstall-always-fail': false,
},
},
}),
);
await writeFile(
Expand Down Expand Up @@ -580,6 +638,26 @@ Elapsed time: 0 ms
path.join(repository.directoryPath, '.gitignore'),
'content for .gitignore',
);
await writeFile(
path.join(repository.directoryPath, '.yarnrc.yml'),
stringify({
enableScripts: false,
plugins: [
{
path: '.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs',
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js',
},
],
}),
);

await writeFile(
path.join(
repository.directoryPath,
'.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs',
),
'test scripts',
);
}
const outputLogger = new FakeOutputLogger();

Expand Down Expand Up @@ -618,6 +696,8 @@ repo-1
- Do the typedoc-related \`scripts\` in \`package.json\` conform? ✅
- Do the changelog-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the changelog-related \`scripts\` in \`package.json\` conform? ✅
- Do the lavamoat-related \`devDependencies\` in \`package.json\` conform? ✅
- Does lavamoat lists \`@lavamoat/preinstall-always-fail: false\` in allow scripts? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -635,8 +715,10 @@ repo-1
- Is \`.editorconfig\` present, and does it conform? ✅
- Is \`.gitattributes\` present, and does it conform? ✅
- Is \`.gitignore\` present, and does it conform? ✅
- Does allow scripts conforms to yarn? ✅
- Does yarn plugins conforms to allow scripts? ✅

Results: 36 passed, 0 failed, 36 total
Results: 40 passed, 0 failed, 40 total
Elapsed time: 0 ms


Expand All @@ -662,6 +744,8 @@ repo-2
- Do the typedoc-related \`scripts\` in \`package.json\` conform? ✅
- Do the changelog-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the changelog-related \`scripts\` in \`package.json\` conform? ✅
- Do the lavamoat-related \`devDependencies\` in \`package.json\` conform? ✅
- Does lavamoat lists \`@lavamoat/preinstall-always-fail: false\` in allow scripts? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -679,8 +763,10 @@ repo-2
- Is \`.editorconfig\` present, and does it conform? ✅
- Is \`.gitattributes\` present, and does it conform? ✅
- Is \`.gitignore\` present, and does it conform? ✅
- Does allow scripts conforms to yarn? ✅
- Does yarn plugins conforms to allow scripts? ✅

Results: 36 passed, 0 failed, 36 total
Results: 40 passed, 0 failed, 40 total
Elapsed time: 0 ms

`,
Expand All @@ -707,6 +793,20 @@ Elapsed time: 0 ms
for (const repository of repositories.slice(1)) {
await writeFile(path.join(repository.directoryPath, '.yarnrc'), '');
}
for (const repository of repositories) {
await writeFile(
path.join(repository.directoryPath, '.yarnrc.yml'),
stringify({
enableScripts: true,
plugins: [
{
path: '.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs',
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js',
},
],
}),
);
}
const outputLogger = new FakeOutputLogger();

await main({
Expand All @@ -732,7 +832,6 @@ repo-1
- Is \`README.md\` present? ❌
- \`README.md\` does not exist in this project.
- Are all of the files for Yarn Modern present, and do they conform? ❌
- \`.yarnrc.yml\` does not exist in this project.
- \`.yarn/releases/\` does not exist in this project.
- \`.yarn/plugins/\` does not exist in this project.
- Does the \`src/\` directory exist? ❌
Expand All @@ -757,8 +856,12 @@ repo-1
- \`.gitattributes\` does not exist in this project.
- Is \`.gitignore\` present, and does it conform? ❌
- \`.gitignore\` does not exist in this project.
- Does allow scripts conforms to yarn? ❌
- \`.yarnrc.yml\` should list \`'enableScripts': false\`, but does not.
- Does yarn plugins conforms to allow scripts? ❌
- \`.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs\` does not exist in this project.

Results: 0 passed, 15 failed, 15 total
Results: 0 passed, 17 failed, 17 total
Elapsed time: 0 ms


Expand All @@ -772,7 +875,6 @@ repo-2
- Is \`README.md\` present? ❌
- \`README.md\` does not exist in this project.
- Are all of the files for Yarn Modern present, and do they conform? ❌
- \`.yarnrc.yml\` does not exist in this project.
- \`.yarn/releases/\` does not exist in this project.
- \`.yarn/plugins/\` does not exist in this project.
- Does the \`src/\` directory exist? ❌
Expand All @@ -797,8 +899,12 @@ repo-2
- \`.gitattributes\` does not exist in this project.
- Is \`.gitignore\` present, and does it conform? ❌
- \`.gitignore\` does not exist in this project.
- Does allow scripts conforms to yarn? ❌
- \`.yarnrc.yml\` should list \`'enableScripts': false\`, but does not.
- Does yarn plugins conforms to allow scripts? ❌
- \`.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs\` does not exist in this project.

Results: 0 passed, 15 failed, 15 total
Results: 0 passed, 17 failed, 17 total
Elapsed time: 0 ms

`,
Expand Down Expand Up @@ -880,8 +986,10 @@ repo-2
- \`.gitattributes\` does not exist in this project.
- Is \`.gitignore\` present, and does it conform? ❌
- \`.gitignore\` does not exist in this project.
- Does allow scripts conforms to yarn? ✅
- Does yarn plugins conforms to allow scripts? ✅

Results: 1 passed, 14 failed, 15 total
Results: 3 passed, 14 failed, 17 total
Elapsed time: 0 ms

`,
Expand Down
Loading
Loading