Skip to content

Commit

Permalink
🚨 Lint against extraneous dependencies (#670)
Browse files Browse the repository at this point in the history
In all circumstances where it matters in this repo, the extraneous dependencies are guaranteed to be
present and resolve to their expected versions. However, to better support Yarn 2+ and any other
potential node loaders that might block on this, this eslint rule will help ensure that packages
only import from their specific dependencies.
  • Loading branch information
Wil Wilsman authored Dec 14, 2021
1 parent 0c1942c commit 07c56d9
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rules:
prefer-const: off
no-unused-expressions: off
babel/no-unused-expressions: warn
import/no-extraneous-dependencies: error
node/no-callback-literal: off
promise/param-names: off
semi: [error, always]
Expand Down
1 change: 0 additions & 1 deletion packages/cli-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"@percy/cli-command": "1.0.0-beta.71",
"@percy/client": "1.0.0-beta.71",
"@percy/env": "1.0.0-beta.71",
"@percy/logger": "1.0.0-beta.71"
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-build/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
1 change: 1 addition & 0 deletions packages/cli-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.0",
"@percy/core": "1.0.0-beta.71",
"@percy/config": "1.0.0-beta.71",
"@percy/logger": "1.0.0-beta.71"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-command/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
2 changes: 2 additions & 0 deletions packages/cli-config/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
2 changes: 1 addition & 1 deletion packages/cli-exec/src/commands/exec/ping.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Command, { flags } from '@percy/cli-command';
import request from '@percy/client/dist/request';
import { request } from '@percy/core/dist/utils';
import logger from '@percy/logger';
import execFlags from '../../flags';

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-exec/src/commands/exec/stop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Command, { flags } from '@percy/cli-command';
import request from '@percy/client/dist/request';
import { request } from '@percy/core/dist/utils';
import logger from '@percy/logger';
import execFlags from '../../flags';

Expand Down
1 change: 1 addition & 0 deletions packages/cli-exec/src/hooks/init.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import PercyConfig from '@percy/config';
import * as CoreConfig from '@percy/core/dist/config';

Expand Down
2 changes: 2 additions & 0 deletions packages/cli-exec/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
5 changes: 1 addition & 4 deletions packages/cli-exec/test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logger from '@percy/logger/test/helpers';
import mockAPI from '@percy/client/test/helpers';
import { logger, mockAPI } from '@percy/core/test/helpers';

beforeEach(() => {
process.env.PERCY_TOKEN = '<<PERCY_TOKEN>>';
mockAPI.start();
logger.mock();
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-exec/test/start.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import request from '@percy/client/dist/request';
import { request } from '@percy/core/dist/utils';
import { logger } from './helpers';
import { Start } from '../src/commands/exec/start';
import { Stop } from '../src/commands/exec/stop';
Expand Down
1 change: 0 additions & 1 deletion packages/cli-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@percy/cli-command": "1.0.0-beta.71",
"@percy/config": "1.0.0-beta.71",
"@percy/core": "1.0.0-beta.71",
"@percy/dom": "1.0.0-beta.71",
"@percy/logger": "1.0.0-beta.71",
"globby": "^11.0.4",
"path-to-regexp": "^6.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-snapshot/src/commands/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'fs';
import path from 'path';
import PercyConfig from '@percy/config';
import Command, { flags } from '@percy/cli-command';
import request from '@percy/client/dist/request';
import Percy from '@percy/core';
import { request } from '@percy/core/dist/utils';
import logger from '@percy/logger';
import globby from 'globby';
import YAML from 'yaml';
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-snapshot/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
3 changes: 1 addition & 2 deletions packages/cli-snapshot/test/directory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';
import PercyConfig from '@percy/config';
import mockAPI from '@percy/client/test/helpers';
import logger from '@percy/logger/test/helpers';
import { logger, mockAPI } from '@percy/core/test/helpers';
import { Snapshot } from '../src/commands/snapshot';

describe('percy snapshot <directory>', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/cli-snapshot/test/file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import fs from 'fs';
import path from 'path';
import { inspect } from 'util';
import rimraf from 'rimraf';
import mockAPI from '@percy/client/test/helpers';
import logger from '@percy/logger/test/helpers';
import { createTestServer } from '@percy/core/test/helpers';
import { logger, mockAPI, createTestServer } from '@percy/core/test/helpers';
import { Snapshot } from '../src/commands/snapshot';

describe('percy snapshot <file>', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/cli-snapshot/test/sitemap.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';
import mockAPI from '@percy/client/test/helpers';
import logger from '@percy/logger/test/helpers';
import { createTestServer } from '@percy/core/test/helpers';
import { logger, mockAPI, createTestServer } from '@percy/core/test/helpers';
import { Snapshot } from '../src/commands/snapshot';

describe('percy snapshot <sitemap>', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/cli-upload/src/commands/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import logger from '@percy/logger';
import globby from 'globby';
import imageSize from 'image-size';
import PercyClient from '@percy/client';

// eslint-disable-next-line import/no-extraneous-dependencies
import Queue from '@percy/core/dist/queue';

import createImageResources from '../resources';
import { schema } from '../config';
import pkg from '../../package.json';
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-upload/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
]
},
"dependencies": {
"@oclif/command": "^1.8.0",
"@oclif/plugin-help": "^3.2.0",
"@percy/cli-build": "1.0.0-beta.71",
"@percy/cli-config": "1.0.0-beta.71",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
2 changes: 2 additions & 0 deletions packages/client/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
2 changes: 2 additions & 0 deletions packages/config/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
1 change: 1 addition & 0 deletions packages/core/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
no-return-assign: off
no-sequences: off
2 changes: 2 additions & 0 deletions packages/dom/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
2 changes: 2 additions & 0 deletions packages/env/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
2 changes: 2 additions & 0 deletions packages/logger/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
9 changes: 5 additions & 4 deletions packages/sdk-utils/src/percy-enabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import request from './request';

// Create a socket to connect to a remote logger
async function connectRemoteLogger() {
await logger.remote(() => {
await logger.remote(async () => {
let url = percy.address.replace('http', 'ws');

if (process.env.__PERCY_BROWSERIFIED__) {
return new window.WebSocket(url);
} else {
let socket = new (require('ws'))(url);
/* eslint-disable-next-line import/no-extraneous-dependencies */
let { default: WebSocket } = await import('ws');
let ws = new WebSocket(url);
// allow node to exit with an active connection
socket.once('open', () => socket._socket.unref());
return socket;
return ws.once('open', () => ws._socket.unref());
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk-utils/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
env:
jasmine: true
rules:
import/no-extraneous-dependencies: off
3 changes: 2 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
const cwd = process.cwd();
const path = require('path');
const colors = require('colors');
const colors = require('colors/safe');

process.env.NODE_ENV = 'production';

Expand Down
1 change: 1 addition & 0 deletions scripts/test-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env jasmine */
/* eslint-disable import/no-extraneous-dependencies */

beforeAll(() => {
// default timeout to 10s
Expand Down
1 change: 1 addition & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
const cwd = process.cwd();
const path = require('path');
const colors = require('colors/safe');
Expand Down
3 changes: 2 additions & 1 deletion scripts/watch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const { readFileSync } = require('fs');
const colors = require('colors');
const colors = require('colors/safe');
const gaze = require('gaze');

// executes the callback when files within the current working directory have been modified
Expand Down

0 comments on commit 07c56d9

Please sign in to comment.