Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.

Commit ab871f0

Browse files
authored
Enable typescript strict mode (#122)
* change tsconfig.json "strict" settings to be true * remove unused code from package-json.ts * update ramda * fix some tsc errors * automatically ignore tsc errors
2 parents 01eef57 + 623ede4 commit ab871f0

File tree

18 files changed

+91
-161
lines changed

18 files changed

+91
-161
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"object-assign": "^4.1.1",
6363
"ora": "^1.2.0",
6464
"parents": "^1.0.1",
65-
"ramda": "^0.22.1",
65+
"ramda": "^0.26.1",
6666
"regenerator-runtime": "^0.10.5",
6767
"resolve": "^1.5.0",
6868
"resolve-dependency-path": "^2.0.0",

src/cli/command-registrar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function logAndExit(str) {
3535
function start() {
3636
program.version(pkg.version).description('bit driver for javascript');
3737
commands.forEach(c => {
38+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3839
const currentCommand = program.command(c.name).description(c.description);
3940

4041
if (c.options && Array.isArray(c.options)) {
@@ -48,6 +49,7 @@ function start() {
4849
c.action(args, options)
4950
.then(c.report)
5051
.then(logAndExit)
52+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
5153
.catch(c.handleError || errorHandler);
5254
});
5355
});

src/cli/loader/loader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ const off = (): Loader | null | undefined => {
4646

4747
const loader: Loader = {
4848
on,
49+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
4950
off,
51+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
5052
stop,
53+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
5154
start,
55+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
5256
setText,
57+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
5358
get
5459
};
5560

src/dependency-builder/build-tree.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ describe('buildTree', () => {
2121
expect(results).to.deep.equal({ tree: {} });
2222
});
2323
it('when unsupported files are passed should return them with no dependencies', async () => {
24+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2425
dependencyTreeParams.filePaths = [`${fixtures}/unsupported-file.pdf`];
2526
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2627
const results = await buildTree.getDependencyTree(dependencyTreeParams);
2728
expect(results.tree).to.deep.equal({ 'fixtures/unsupported-file.pdf': {} });
2829
});
2930
it('when supported and unsupported files are passed should return them all', async () => {
31+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
32+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3033
dependencyTreeParams.filePaths = [`${fixtures}/unsupported-file.pdf`, `${precinctFixtures}/es6.js`];
3134
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3235
const results = await buildTree.getDependencyTree(dependencyTreeParams);
3336
expect(results.tree).to.have.property('fixtures/unsupported-file.pdf');
3437
expect(results.tree).to.have.property('fixtures/precinct/es6.js');
3538
});
3639
it('when a js file has parsing error it should add the file to the tree with the error instance', async () => {
40+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3741
dependencyTreeParams.filePaths = [`${precinctFixtures}/unparseable.js`];
3842
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3943
const results = await buildTree.getDependencyTree(dependencyTreeParams);
@@ -43,6 +47,7 @@ describe('buildTree', () => {
4347
expect(results.tree[unParsedFile].error).to.be.instanceof(Error);
4448
});
4549
it('when a js file has parsing error and it retrieved from the cache it should add the file to the tree with the error instance', async () => {
50+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
4651
dependencyTreeParams.filePaths = [`${precinctFixtures}/unparseable.js`];
4752
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
4853
dependencyTreeParams.visited = {};
@@ -61,6 +66,7 @@ describe('buildTree', () => {
6166
expect(resultsCached.tree[unParsedFile].error).to.be.instanceof(Error);
6267
});
6368
it.skip('when a css file has parsing error it should add the file to the tree with the error instance', async () => {
69+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
6470
dependencyTreeParams.filePaths = [`${buildTreeFixtures}/unparsed.css`];
6571
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
6672
const results = await buildTree.getDependencyTree(dependencyTreeParams);
@@ -72,6 +78,8 @@ describe('buildTree', () => {
7278
describe('when a dependency of dependency has parsing error', () => {
7379
let results;
7480
before(async () => {
81+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
82+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
7583
dependencyTreeParams.filePaths = [`${buildTreeFixtures}/a.js`, `${buildTreeFixtures}/b.js`];
7684
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
7785
results = await buildTree.getDependencyTree(dependencyTreeParams);
@@ -94,6 +102,7 @@ describe('buildTree', () => {
94102
let results;
95103
const missingDepsFile = 'fixtures/missing-deps.js';
96104
before(async () => {
105+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
97106
dependencyTreeParams.filePaths = [`${fixtures}/missing-deps.js`];
98107
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
99108
results = await buildTree.getDependencyTree(dependencyTreeParams);
@@ -113,6 +122,7 @@ describe('buildTree', () => {
113122
describe('when a file imports from itself', () => {
114123
let results;
115124
before(async () => {
125+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
116126
dependencyTreeParams.filePaths = [`${buildTreeFixtures}/tree-shaking-cycle/self-cycle.js`];
117127
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
118128
results = await buildTree.getDependencyTree(dependencyTreeParams);
@@ -125,6 +135,7 @@ describe('buildTree', () => {
125135
describe('cycle with multiple files', () => {
126136
let results;
127137
before(async () => {
138+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
128139
dependencyTreeParams.filePaths = [`${buildTreeFixtures}/tree-shaking-cycle/foo.js`];
129140
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
130141
results = await buildTree.getDependencyTree(dependencyTreeParams);
@@ -144,6 +155,7 @@ describe('buildTree', () => {
144155
describe('fileA imports varX from fileB, fileB imports varX from fileC but not export it', () => {
145156
let results;
146157
before(async () => {
158+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
147159
dependencyTreeParams.filePaths = [`${buildTreeFixtures}/not-link-file/file-a.js`];
148160
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
149161
results = await buildTree.getDependencyTree(dependencyTreeParams);

src/dependency-builder/build-tree.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ export function resolveNodePackage(cwd: string, packageFullPath: string): Record
8282
// if you have 2 authored component which one dependet on the other
8383
// we will look for the package.json on the dependency but won't find it
8484
// if we propagate we will take the version from the root's package json which has nothing with the component version
85-
const packageInfo = PackageJson.loadSync(packageDir, false);
85+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
86+
const packageInfo = PackageJson.loadSync(packageDir);
8687

8788
// when running 'bitjs get-dependencies' command, packageInfo is sometimes empty
8889
// or when using custom-module-resolution it may be empty or the name/version are empty
90+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
8991
if (!packageInfo || !packageInfo.name || !packageInfo.version) return null;
92+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
9093
result[packageInfo.name] = packageInfo.version;
9194
return result;
9295
}
@@ -129,6 +132,7 @@ function groupDependencyList(list, cwd, bindingPrefix) {
129132
groups.packages.forEach(packagePath => {
130133
const packageWithVersion = resolveNodePackage(cwd, path.join(cwd, packagePath));
131134
if (packageWithVersion) Object.assign(packages, packageWithVersion);
135+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
132136
else unidentifiedPackages.push(packagePath);
133137
});
134138
groups.packages = packages;
@@ -259,6 +263,7 @@ function groupMissing(missing, cwd, consumerPath, bindingPrefix) {
259263
if (R.contains(packageName, missingPackages)) return;
260264
const resolvedPath = resolveModulePath(packageName, cwd, consumerPath);
261265
if (!resolvedPath) {
266+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
262267
missingPackages.push(packageName);
263268
return;
264269
}
@@ -413,6 +418,7 @@ export async function getDependencyTree({
413418
resolveConfig: resolveConfigAbsolute,
414419
cacheProjectAst
415420
};
421+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
416422
const { madgeTree, skipped, pathMap, errors } = generateTree(filePaths, config);
417423
const tree: Tree = groupDependencyTree(madgeTree, baseDir, bindingPrefix);
418424
const { missingGroups, foundPackages } = groupMissing(skipped, baseDir, consumerPath, bindingPrefix);

src/dependency-builder/dependency-tree/Config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,58 @@ const debug = require('debug')('tree');
99

1010
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1111
function Config(options) {
12+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1213
this.filename = options.filename;
14+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1315
this.directory = options.directory || options.root;
16+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1417
this.visited = options.visited || {};
18+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1519
this.errors = options.errors || {};
20+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1621
this.nonExistent = options.nonExistent || [];
22+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1723
this.isListForm = options.isListForm;
24+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1825
this.requireConfig = options.config || options.requireConfig;
26+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
1927
this.webpackConfig = options.webpackConfig;
28+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2029
this.detectiveConfig = options.detective || options.detectiveConfig || {};
30+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2131
this.pathMap = options.pathMap || [];
32+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2233
this.resolveConfig = options.resolveConfig;
34+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2335
this.cacheProjectAst = options.cacheProjectAst;
2436

37+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2538
this.filter = options.filter;
2639

40+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2741
if (!this.filename) {
2842
throw new Error('filename not given');
2943
}
44+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3045
if (!this.directory) {
3146
throw new Error('directory not given');
3247
}
48+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
49+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3350
if (this.filter && typeof this.filter !== 'function') {
3451
throw new Error('filter must be a function');
3552
}
3653

54+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3755
debug(`given filename: ${this.filename}`);
3856

57+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
58+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
3959
this.filename = path.resolve(process.cwd(), this.filename);
4060

61+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
4162
debug(`resolved filename: ${this.filename}`);
63+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
4264
debug('visited: ', this.visited);
4365
}
4466

src/dependency-builder/dependency-tree/index.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,11 @@ describe('dependencyTree', function() {
963963
resolveConfig: { aliases: { something: 'anything' } }
964964
};
965965
dependencyTree(config);
966+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
966967
const pathMapRecord = config.pathMap.find(f => f.file === filename);
968+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
967969
expect(pathMapRecord.dependencies).to.have.lengthOf(1);
970+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
968971
const dependency = pathMapRecord.dependencies[0];
969972
expect(dependency).to.not.have.property('isCustomResolveUsed');
970973
});
@@ -988,8 +991,11 @@ describe('dependencyTree', function() {
988991
resolveConfig: { aliases: { something: 'anything' } }
989992
};
990993
dependencyTree(config);
994+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
991995
const pathMapRecord = config.pathMap.find(f => f.file === filename);
996+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
992997
expect(pathMapRecord.dependencies).to.have.lengthOf(1);
998+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
993999
const dependency = pathMapRecord.dependencies[0];
9941000
expect(dependency).to.not.have.property('isCustomResolveUsed');
9951001
});

src/dependency-builder/dependency-tree/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ module.exports._getDependencies = function(config) {
147147
pathMap.isCustomResolveUsed = true;
148148
}
149149

150+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
150151
pathMapDependencies.push(pathMap);
151152

153+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
152154
resolvedDependencies.push(result);
153155
}
154156
function addToNonExistent(dependency) {
@@ -195,6 +197,7 @@ function traverse(config) {
195197
debug(`number of dependencies after filtering: ${dependencies.length}`);
196198
}
197199
debug('cabinet-resolved all dependencies: ', dependencies);
200+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
198201
tree[dependency] = dependencies;
199202
const filePathMap = config.pathMap.find(pathMapEntry => pathMapEntry.file === dependency);
200203
if (!filePathMap) throw new Error(`file ${dependency} is missing from PathMap`);
@@ -222,6 +225,7 @@ function traverse(config) {
222225
}
223226
debug(`found ${dependency} in the cache`);
224227
const dependencies = config.visited[dependency].pathMap.dependencies.map(d => d.resolvedDep);
228+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
225229
tree[dependency] = dependencies;
226230
config.pathMap.push(config.visited[dependency].pathMap);
227231
if (config.visited[dependency].missing) {

src/dependency-builder/detectives/detective-css-and-preprocessors/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function detective(fileContent, syntax) {
2424

2525
const ast = csstree.parse(fileContent, {
2626
onParseError(error) {
27-
// @ts-ignore FIXME
27+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
2828
handleError(error);
2929
}
3030
});

src/dependency-builder/filing-cabinet/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ describe('filing-cabinet', () => {
211211
});
212212

213213
assert.ok(
214+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
214215
require.main.paths.some(function(p) {
215216
return p.indexOf(path.normalize(directory)) !== -1;
216217
})

src/dependency-builder/generate-tree-madge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export default function generateTree(files = [], config) {
147147
});
148148
Object.assign(depTree, dependencyTreeResult);
149149
} catch (err) {
150+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
150151
errors[file] = err;
151152
}
152153
});

src/dependency-builder/path-map.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ function getDependenciesFromLinkFileIfExists(
130130

131131
const dependencies = dependency.importSpecifiers.map((specifier: Specifier) => {
132132
const realDep = findTheRealDependency(pathMap, dependencyPathMap, specifier);
133-
// $FlowFixMe
134133
if (!realDep) return null;
135-
// $FlowFixMe importSpecifiers do exist
134+
// @ts-ignore
136135
const depImportSpecifier = realDep.importSpecifiers.find(depSpecifier => depSpecifier.name === specifier.name);
137136
const importSpecifier: ImportSpecifier = {
138137
mainFile: specifier,
@@ -146,11 +145,16 @@ function getDependenciesFromLinkFileIfExists(
146145
return null;
147146
}
148147
const linkFiles = [];
148+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
149149
dependencies.forEach((dep: { file: string; importSpecifier: ImportSpecifier }) => {
150+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
150151
const existingFile = linkFiles.find(linkFile => linkFile.file === dep.file);
151152
if (existingFile) {
153+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
152154
existingFile.importSpecifiers.push(dep.importSpecifier);
153155
} else {
156+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
157+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
154158
linkFiles.push({ file: dep.file, importSpecifiers: [dep.importSpecifier] });
155159
}
156160
});

src/exceptions/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/exceptions/package-json-already-exists.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/exceptions/package-json-not-found.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)