Skip to content

Commit

Permalink
feat: use get-monorepo-packages (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed Jan 5, 2018
1 parent dc6466d commit ed7a88a
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 114 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"eslint-module-utils": "^2.1.1",
"get-monorepo-packages": "^1.0.0",
"globby": "^7.1.1",
"load-json-file": "^4.0.0",
"minimatch": "^3.0.4",
Expand Down
48 changes: 0 additions & 48 deletions src/get-packages.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/rules/no-internal-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import moduleVisitor, {
makeOptionsSchema,
} from 'eslint-module-utils/moduleVisitor';
import parse from 'parse-package-name';
import getPackages from '../get-packages';
import getPackages from 'get-monorepo-packages';

export const meta = {
schema: [makeOptionsSchema({})],
Expand All @@ -14,7 +14,7 @@ export const create = context => {

return moduleVisitor(node => {
const { name, path: internalPath } = tryParse(node.value);
if (internalPath && packages.find(pkg => pkg.name === name)) {
if (internalPath && packages.find(pkg => pkg.package.name === name)) {
context.report({
node,
message: `Import for monorepo package '${name}' is internal.`,
Expand Down
18 changes: 11 additions & 7 deletions src/rules/no-relative-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moduleVisitor, {
import isInside from 'path-is-inside';
import minimatch from 'minimatch';
import path from 'path';
import getPackages from '../get-packages';
import getPackages from 'get-monorepo-packages';

export const meta = {
schema: [makeOptionsSchema({})],
Expand All @@ -25,19 +25,23 @@ export const create = context => {
return;
}

const pkg = packages.find(pkg => isInside(resolvedPath, pkg.fsPath));
const pkg = packages.find(pkg => isInside(resolvedPath, pkg.location));
if (!pkg) {
return;
}

const subPackagePath = path.relative(pkg.fsPath, resolvedPath);
const subPackagePath = path.relative(pkg.location, resolvedPath);
context.report({
node,
message: `Import for monorepo package '${pkg.name}' should be absolute.`,
message: `Import for monorepo package '${
pkg.package.name
}' should be absolute.`,
fix: fixer => {
fixer.replaceText(
node,
`${pkg.name}${subPackagePath !== '.' ? '/' + subPackagePath : ''}`
`${pkg.package.name}${
subPackagePath !== '.' ? '/' + subPackagePath : ''
}`
);
},
});
Expand All @@ -46,9 +50,9 @@ export const create = context => {

const getPackageDir = (filePath, packages) => {
const match = packages.find(pkg =>
minimatch(filePath, path.join(pkg.fsPath, '**'))
minimatch(filePath, path.join(pkg.location, '**'))
);
if (match) {
return match.fsPath;
return match.location;
}
};
27 changes: 0 additions & 27 deletions test/__snapshots__/get-packages.test.js.snap

This file was deleted.

4 changes: 3 additions & 1 deletion test/fixture/yarn/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"workspaces": ["packages/*"]
"name": "@azz/workspace",
"workspaces": ["packages/*"],
"private": true
}
3 changes: 2 additions & 1 deletion test/fixture/yarn/packages/bar/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "bar"
"name": "bar",
"version": "0.0.0"
}
3 changes: 2 additions & 1 deletion test/fixture/yarn/packages/foo/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "foo"
"name": "foo",
"version": "0.0.0"
}
27 changes: 0 additions & 27 deletions test/get-packages.test.js

This file was deleted.

7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,13 @@ get-caller-file@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"

get-monorepo-packages@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/get-monorepo-packages/-/get-monorepo-packages-1.0.0.tgz#7deec63b9b14fab11ba2bd09c020f54ad9a761ea"
dependencies:
globby "^7.1.1"
load-json-file "^4.0.0"

get-pkg-repo@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/get-pkg-repo/-/get-pkg-repo-1.4.0.tgz#c73b489c06d80cc5536c2c853f9e05232056972d"
Expand Down

0 comments on commit ed7a88a

Please sign in to comment.