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

Validation for unused dependencies not required by index.js #756

Merged
merged 1 commit into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion packages/turf-concave/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
},
"dependencies": {
"@turf/distance": "^4.3.0",
"@turf/meta": "^4.3.0",
"@turf/tin": "^4.3.0",
"@turf/union": "^4.3.0"
}
Expand Down
1 change: 0 additions & 1 deletion packages/turf-dissolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"dependencies": {
"@turf/bbox": "^4.3.0",
"@turf/helpers": "^4.3.0",
"@turf/union": "^4.3.0",
"geojson-utils": "^1.1.0",
"get-closest": "^0.0.4",
Expand Down
8 changes: 5 additions & 3 deletions packages/turf-great-circle/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ GreatCircle.prototype.Arc = function (npoints, options) {
return arc;
};

module.exports.Coord = Coord;
module.exports.Arc = Arc;
module.exports.GreatCircle = GreatCircle;
module.exports = {
Coord: Coord,
Arc: Arc,
GreatCircle: GreatCircle
};
3 changes: 1 addition & 2 deletions packages/turf-great-circle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"write-json-file": "^2.0.0"
},
"dependencies": {
"@turf/invariant": "^4.3.0",
"arc": "^0.1.0"
"@turf/invariant": "^4.3.0"
}
}
8 changes: 5 additions & 3 deletions packages/turf-hex-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
],
"author": "Turf Authors",
"contributors": [
"jseppi",
"jvail",
"James Seppi <@jseppi>",
"Morgan Herlocker <@morganherlocker>",
"Tom MacWright <@tmcw>",
"Jan Vaillant <@jvail>",
"Lyzi Diamond <@lyzidiamond>",
"Tom MacWright <@tmcw>"
"Denis Carriere <@DenisCarriere>"
],
"license": "MIT",
"bugs": {
Expand Down
1 change: 0 additions & 1 deletion packages/turf-idw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@turf/bbox": "^4.3.0",
"@turf/centroid": "^4.3.0",
"@turf/distance": "^4.3.0",
"@turf/helpers": "^4.3.0",
"@turf/square-grid": "^4.3.0"
}
}
3 changes: 1 addition & 2 deletions packages/turf-line-arc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"dependencies": {
"@turf/circle": "^4.3.0",
"@turf/destination": "^4.3.0",
"@turf/helpers": "^4.3.0",
"@turf/meta": "^4.3.0"
"@turf/helpers": "^4.3.0"
}
}
3 changes: 1 addition & 2 deletions packages/turf-midpoint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"dependencies": {
"@turf/bearing": "^4.3.0",
"@turf/destination": "^4.3.0",
"@turf/distance": "^4.3.0",
"@turf/invariant": "^4.3.0"
"@turf/distance": "^4.3.0"
}
}
3 changes: 1 addition & 2 deletions packages/turf-square/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"tape": "^4.6.3"
},
"dependencies": {
"@turf/distance": "^4.3.0",
"@turf/helpers": "^4.3.0"
"@turf/distance": "^4.3.0"
}
}
4 changes: 3 additions & 1 deletion packages/turf-tesselate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
],
"author": "Turf Authors",
"contributors": [
"Abel Vázquez <@AbelVM>",
"Morgan Herlocker <@morganherlocker>",
"Abel Vázquez"
"Tom MacWright <@tmcw>",
"Vladimir Agafonkin <@mourner>"
],
"license": "MIT",
"bugs": {
Expand Down
44 changes: 25 additions & 19 deletions packages/turf/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ test('turf - required files', t => {
for (const filename of ['test.js', 'bench.js', 'index.js', 'index.d.ts', 'LICENSE', 'README.md']) {
if (!fs.existsSync(path.join(dir, filename))) t.fail(`${name} ${filename} is required`);
}
// ENABLE "types.ts" WHEN COMPLETELY ADDED
// if (!fs.existsSync(path.join(dir, 'types.ts'))) t.fail(`${name} types.ts is required`);
}
t.skip('add "types.ts" to all packages');
t.end();
});

Expand All @@ -32,9 +32,9 @@ test('turf - invalid dependencies', t => {
if (dependencies[invalidDependency]) t.fail(`${name} ${invalidDependency} should be defined as devDependencies`);
}
if (devDependencies['eslint'] || devDependencies['eslint-config-mourner']) t.fail(`${name} eslint is handled at the root level`);
// ENABLE "mkdirp"" WHEN COMPLETELY REMOVED
// if (devDependencies['mkdirp']) t.fail(`${name} tests should not have to create folders`);
}
t.skip('remove "mkdirp" from testing');
t.end();
});

Expand All @@ -50,7 +50,7 @@ test('turf - duplicate dependencies', t => {
for (const {name, pckg} of modules) {
const {dependencies, devDependencies} = pckg;
for (const dependency of Object.keys(dependencies)) {
if (devDependencies[dependency]) t.fail(`${name} ${dependency} is duplicated in devDependencies`)
if (devDependencies[dependency]) t.fail(`${name} ${dependency} is duplicated in devDependencies`);
}
}
t.end();
Expand All @@ -59,9 +59,9 @@ test('turf - duplicate dependencies', t => {
test('turf - check if files exists', t => {
for (const {name, dir, pckg} of modules) {
const {files} = pckg;
if (!files || !files.length) t.fail(`${name} (files) must be included in package.json`)
if (!files || !files.length) t.fail(`${name} (files) must be included in package.json`);
for (const file of files) {
if (!fs.existsSync(path.join(dir, file))) t.fail(`${name} missing file ${file} in "files"`)
if (!fs.existsSync(path.join(dir, file))) t.fail(`${name} missing file ${file} in "files"`);
}
}
t.end();
Expand All @@ -78,26 +78,25 @@ test('turf - MIT license', t => {
});

test('turf - contributors', t => {
for (const {name, dir, pckg} of modules) {
for (const {name, pckg} of modules) {
for (const contributor of pckg.contributors || []) {
// ADD WHEN COMPLETED
// if (!contributor.match(/<@.+>/)) t.fail(`${name} ${contributor} (contributors) should resemble "Full Name <@GitHub>"`)
if (!contributor.match(/<@.+>/)) t.fail(`${name} ${contributor} (contributors) should use "Full Name <@GitHub>"`);
}
}
t.end();
});

test('turf - scoped package name', t => {
for (const {name, dir, pckg} of modules) {
const expected = name.replace('turf-', '@turf/')
if (pckg.name !== expected) t.fail(`${name} (name) must use ${expected} in package.json`)
for (const {name, pckg} of modules) {
const expected = name.replace('turf-', '@turf/');
if (pckg.name !== expected) t.fail(`${name} (name) must use ${expected} in package.json`);
}
t.end();
});

test('turf - pre-defined attributes in package.json', t => {
for (const {name, dir, pckg} of modules) {
if (pckg.author !== 'Turf Authors') t.fail(name + ' (author) should be "Turf Authors"')
for (const {name, pckg} of modules) {
if (pckg.author !== 'Turf Authors') t.fail(name + ' (author) should be "Turf Authors"');
if (pckg.main !== 'index.js') t.fail(`${name} (main) must be "index.js" in package.json`);
if (pckg.types !== 'index.d.ts') t.fail(`${name} (types) must be "index.d.ts" in package.json`);
if (!pckg.bugs || pckg.bugs.url !== 'https://github.com/Turfjs/turf/issues') t.fail(`${name} (bugs.url) must be "https://github.com/Turfjs/turf/issues" in package.json`);
Expand All @@ -109,13 +108,20 @@ test('turf - pre-defined attributes in package.json', t => {
test('turf - parsing dependencies from index.js', t => {
for (const {name, dir, pckg} of modules) {
const index = fs.readFileSync(path.join(dir, 'index.js'), 'utf8');
const uniques = {};
for (const dependency of index.match(/require\('[\@\/a-z]+'\)/gi) || []) {
const dependencyName = dependency.match(/require\('([\@\/a-z]+)'\)/)[1];

// Read Depedencies from index.js
const dependencies = new Set();
for (const dependency of index.match(/require\('[\@\/a-z-\d]+'\)/gi) || []) {
const dependencyName = dependency.split(/'/)[1];
if (!pckg.dependencies[dependencyName]) t.fail(`${name} ${dependencyName} is missing from dependencies`);
if (uniques[dependencyName]) t.fail(`${name} ${dependency} is duplicated in index.js`)
uniques[dependencyName] = true;
if (dependencies.has(dependencyName)) t.fail(`${name} ${dependencyName} is duplicated in index.js`);
dependencies.add(dependencyName);
}

// Read Dependencies from package.json
for (const dependencyName of Object.keys(pckg.dependencies)) {
if (!dependencies.has(dependencyName)) t.fail(`${name} ${dependencyName} is not required in index.js`);
}
}
t.end();
});
});