Skip to content

Commit 24370cd

Browse files
authoredJul 29, 2021
Merge pull request #2125 from snyk/chore/use-bin
chore: execute snyk and snyk-protect using bin file
2 parents 1dd610d + 57ffcb1 commit 24370cd

File tree

16 files changed

+24
-26
lines changed

16 files changed

+24
-26
lines changed
 

‎bin/snyk

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('../dist/cli/index.js');

‎package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"files": [
77
"help",
88
"dist",
9+
"bin",
910
"config.default.json",
1011
"SECURITY.md",
1112
"LICENSE",
@@ -18,7 +19,7 @@
1819
"doc": "help/commands-help"
1920
},
2021
"bin": {
21-
"snyk": "dist/cli/index.js"
22+
"snyk": "bin/snyk"
2223
},
2324
"engines": {
2425
"node": ">=10"
@@ -187,7 +188,8 @@
187188
},
188189
"pkg": {
189190
"scripts": [
190-
"dist/**/*.js"
191+
"dist/**/*.js",
192+
"bin/snyk"
191193
],
192194
"assets": [
193195
"config.default.json",

‎packages/snyk-fix/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
"lib": "src",
1616
"test": "test"
1717
},
18-
"bin": {
19-
"snyk-fix": "dist/index.js"
20-
},
2118
"engines": {
2219
"node": ">=10"
2320
},
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('../dist/index.js').protect();

‎packages/snyk-protect/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"files": [
88
"help",
99
"dist",
10+
"bin",
1011
"SECURITY.md",
1112
"LICENSE",
1213
"README.md"
@@ -16,7 +17,7 @@
1617
"test": "test"
1718
},
1819
"bin": {
19-
"snyk-protect": "dist/index.js"
20+
"snyk-protect": "bin/snyk-protect"
2021
},
2122
"engines": {
2223
"node": ">=10"

‎packages/snyk-protect/src/index.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
#!/usr/bin/env node
1+
import protectLib from './lib';
22

3-
import protect from './lib';
4-
5-
async function main() {
3+
export async function protect() {
64
const projectPath = process.cwd();
7-
await protect(projectPath);
8-
}
9-
10-
if (require.main === module) {
11-
main();
5+
await protectLib(projectPath);
126
}

‎packages/snyk-protect/test/acceptance/protect.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('@snyk/protect', () => {
247247

248248
const { code, stdout } = await runCommand(
249249
'node',
250-
[path.resolve(__dirname, '../../dist/index.js'), '--help'],
250+
[path.resolve(__dirname, '../../bin/snyk-protect'), '--help'],
251251
{
252252
cwd: project.path(),
253253
},
@@ -264,7 +264,7 @@ describe('@snyk/protect', () => {
264264

265265
const { code, stdout } = await runCommand(
266266
'node',
267-
[path.resolve(__dirname, '../../dist/index.js'), '--version'],
267+
[path.resolve(__dirname, '../../bin/snyk-protect'), '--version'],
268268
{
269269
cwd: project.path(),
270270
},

‎scripts/run-smoke-tests-locally.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ fi
3838
echo "Installing fixture project with npm install"
3939
npm install --silent --prefix test/fixtures/basic-npm
4040

41-
SNYK_COMMAND="node ${PWD}/dist/cli" REGRESSION_TEST=1 SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER=1 SMOKE_TESTS_SNYK_TOKEN=$SNYK_API_TOKEN shellspec --chdir test/smoke test/smoke/spec/snyk_auth_spec.sh -f d
41+
SNYK_COMMAND="node ${PWD}/bin/snyk" REGRESSION_TEST=1 SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER=1 SMOKE_TESTS_SNYK_TOKEN=$SNYK_API_TOKEN shellspec --chdir test/smoke test/smoke/spec/snyk_auth_spec.sh -f d

‎test/acceptance/cli-protect.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ before('prime config', async (t) => {
5151
t.pass('endpoint removed');
5252
t.end();
5353
});
54-
const main = './dist/cli/index.js'.replace(/\//g, sep);
54+
const main = './bin/snyk'.replace(/\//g, sep);
5555

5656
test('`protect` should not fail for unauthorized users', (t) => {
5757
t.plan(1);

‎test/jest/acceptance/cli-json-file-output.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid';
55
import { fakeServer } from '../../acceptance/fake-server';
66
import cli = require('../../../src/cli/commands');
77

8-
const main = './dist/cli/index.js'.replace(/\//g, sep);
8+
const main = './bin/snyk'.replace(/\//g, sep);
99
const testTimeout = 50000;
1010

1111
describe('test --json-file-output ', () => {

‎test/jest/acceptance/iac/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function run(
5050
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
5151
return new Promise((resolve, reject) => {
5252
const root = join(__dirname, '../../../../');
53-
const main = join(root, 'dist/cli/index.js');
53+
const main = join(root, 'bin/snyk');
5454
const child = exec(
5555
cmd.trim().replace(/^snyk/, `node ${main}`),
5656
{

‎test/jest/acceptance/proxy-behavior.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { exec } from 'child_process';
22
import { sep } from 'path';
3-
const main = './dist/cli/index.js'.replace(/\//g, sep);
3+
const main = './bin/snyk'.replace(/\//g, sep);
44

55
const SNYK_API_HTTPS = 'https://snyk.io/api/v1';
66
const SNYK_API_HTTP = 'http://snyk.io/api/v1';

‎test/jest/system/lib/commands/fix/fix.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import stripAnsi from 'strip-ansi';
55
import { fakeServer } from '../../../../../acceptance/fake-server';
66
import cli = require('../../../../../../src/cli/commands');
77

8-
const main = './dist/cli/index.js'.replace(/\//g, pathLib.sep);
8+
const main = './bin/snyk'.replace(/\//g, pathLib.sep);
99
const testTimeout = 50000;
1010
describe('snyk fix (system tests)', () => {
1111
let oldkey;

‎test/jest/util/runSnykCLI.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const runSnykCLI = async (
77
argsString: string,
88
options?: RunCommandOptions,
99
): Promise<RunCommandResult> => {
10-
const cliPath = path.resolve(cwd, './dist/cli/index.js');
10+
const cliPath = path.resolve(cwd, './bin/snyk');
1111
const args = argsString.split(' ').filter((v) => !!v);
1212
return await runCommand('node', [cliPath, ...args], options);
1313
};

‎test/smoke/setup-alias-for-snyk.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
set -e
33

44
# Force CI to have this built Snyk version available in shell used
5-
echo "node ${PWD}/dist/cli/index.js \"\$@\"" > /usr/local/bin/snyk
5+
echo "node ${PWD}/bin/snyk \"\$@\"" > /usr/local/bin/snyk
66
chmod +x /usr/local/bin/snyk

‎test/smoke/spec/spec_helper.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spec_helper_configure() {
6262
echo "Using this 'snyk' executable:"
6363
echo "${SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}"
6464
echo " "
65-
echo "You may override it with envvar SNYK_COMMAND - e.g. SNYK_COMMAND=\"node ./dist/cli\" to test a local build"
65+
echo "You may override it with envvar SNYK_COMMAND - e.g. SNYK_COMMAND=\"node ./bin/snyk\" to test a local build"
6666
echo " "
6767

6868
snyk() {

0 commit comments

Comments
 (0)
Please sign in to comment.