Skip to content

Commit

Permalink
chore: make type checking faster, type check entire repo at once
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Oct 24, 2018
1 parent 22549d9 commit 00c5769
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ packages/publisher/**/README.md
packages/plugin/**/README.md
!packages/**/base/README.md
!/README.md
packages/*/*/index.ts
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ README.md
test
ci
docs
/index.ts
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
}
},
"scripts": {
"clean": "bolt ws exec -- rimraf dist",
"prebuild": "bolt clean && ts-node tools/link-ts.ts && ts-node tools/copy-shared-types.ts && bolt ws exec -- node_modules/.bin/tsc --emitDeclarationOnly",
"clean": "rimraf dist && bolt ws exec -- rimraf dist",
"prebuild": "bolt clean && ts-node tools/link-ts.ts && ts-node tools/copy-shared-types.ts && tsc --project ./tsconfig.packages.json --emitDeclarationOnly && ts-node tools/copy-types.ts",
"build": "yarn build:quick",
"build:quick": "bolt ws exec -- node_modules/.bin/babel src -d dist --quiet --extensions \".ts\" --config-file ../../../.babelrc",
"postbuild": "ts-node tools/test-dist",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/cli/src/util/check-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os from 'os';
import path from 'path';
import semver from 'semver';

import { hasYarn, yarnOrNpmSpawn } from '@electron-forge/core/dist/util/yarn-or-npm';
import { utils as forgeUtils } from '@electron-forge/core';
import { OraImpl } from '@electron-forge/async-ora';

const d = debug('electron-forge:check-system');
Expand Down Expand Up @@ -55,10 +55,10 @@ The known versions that work with Electron Forge are: ${versions}`);
}

async function checkPackageManagerVersion(ora: OraImpl) {
return yarnOrNpmSpawn(['--version'])
return forgeUtils.yarnOrNpmSpawn(['--version'])
.then((version) => {
const versionString = version.toString();
if (hasYarn()) {
if (forgeUtils.hasYarn()) {
warnIfPackageManagerIsntAKnownGoodVersion('Yarn', versionString, YARN_WHITELISTED_VERSIONS, ora);
} else {
warnIfPackageManagerIsntAKnownGoodVersion('NPM', versionString, NPM_WHITELISTED_VERSIONS, ora);
Expand Down
4 changes: 4 additions & 0 deletions packages/api/core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import publish, { PublishOptions } from './publish';
import start, { StartOptions } from './start';

import { fromBuildIdentifier } from '../util/forge-config';
import { hasYarn, yarnOrNpmSpawn } from '../util/yarn-or-npm';

export class ForgeAPI {
/**
Expand Down Expand Up @@ -85,6 +86,9 @@ export class ForgeUtils {
fromBuildIdentifier<T>(map: { [key: string]: T | undefined }) {
return fromBuildIdentifier(map);
}

hasYarn = hasYarn;
yarnOrNpmSpawn = yarnOrNpmSpawn;
}

const api = new ForgeAPI();
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { asyncOra } from '@electron-forge/async-ora';
import PluginBase from '@electron-forge/plugin-base';
import { ForgeConfig } from '@electron-forge/shared-types';
import Logger from '@electron-forge/web-multi-logger';
import Tab from '@electron-forge/web-multi-logger/dist/Tab';
import Logger, { Tab } from '@electron-forge/web-multi-logger';
import { ChildProcess } from 'child_process';
import debug from 'debug';
import fs from 'fs-extra';
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/web-multi-logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import http from 'http';

import Tab from './Tab';

export { Tab };

export default class Logger {
private app = express();
private ws!: ews.Instance;
Expand Down
22 changes: 22 additions & 0 deletions tools/copy-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as fs from 'fs-extra';
import * as path from 'path';

const BASE_DIR = path.resolve(__dirname, '..');
const DIST_DIR = path.resolve(BASE_DIR, 'dist');
const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');

(async () => {
const dirsToLink = [];

for (const subDir of await fs.readdir(PACKAGES_DIR)) {
for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
dirsToLink.push(path.join(subDir, packageDir));
}
}

for (const dir of dirsToLink) {
const targetDir = path.resolve(BASE_DIR, 'packages', dir, 'dist');
await fs.mkdirp(targetDir);
await fs.copy(path.resolve(DIST_DIR, dir, 'src'), targetDir);
}
})();
12 changes: 12 additions & 0 deletions tools/link-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');
await fs.copy(path.resolve(BASE_DIR, 'tsconfig.json'), path.resolve(dir, 'tsconfig.json'));
await fs.copy(path.resolve(BASE_DIR, 'tslint.json'), path.resolve(dir, 'tslint.json'));
await fs.copy(path.resolve(BASE_DIR, '.npmignore'), path.resolve(dir, '.npmignore'));
const pj = await fs.readJson(path.resolve(dir, 'package.json'));
if (pj.main) {
const mainFile = pj.main.replace('dist', 'src').replace('.js', '.ts');
const importableFile = mainFile.replace('.ts', '');
const hasDefault = (await fs.readFile(path.resolve(dir, mainFile), 'utf8')).includes('export default');

if (hasDefault) {
await fs.writeFile(path.resolve(dir, 'index.ts'), `import d from './${importableFile}';\nexport default d;\nexport * from './${importableFile}';\n`);
} else {
await fs.writeFile(path.resolve(dir, 'index.ts'), `export * from './${importableFile}';\n`);
}
}
}
})();
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"exclude": [
"node_modules",
"dist",
"test"
"test",
"index.ts"
]
}
17 changes: 17 additions & 0 deletions tsconfig.packages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "packages"
},
"exclude": [
"dist",
"node_modules",
"ci",
"tools",
"**/dist",
"**/node_modules",
"**/test",
"packages/installer/**/typings/ambient.d.ts",
"packages/maker/wix/typings/ambient.d.ts",
]
}

0 comments on commit 00c5769

Please sign in to comment.