diff options
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/package.json | 4 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/globals.d.ts | 19 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/test_installation.ts | 57 | ||||
-rw-r--r-- | packages/monorepo-scripts/tsconfig.json | 2 |
4 files changed, 81 insertions, 1 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index a8f4918ca..5333e6cad 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -25,6 +25,8 @@ "@0xproject/tslint-config": "0.4.8", "@types/glob": "^5.0.33", "@types/node": "^8.0.53", + "@types/rimraf": "^2.0.2", + "lerna-get-packages": "^1.0.0", "shx": "^0.2.2", "tslint": "5.8.0", "typescript": "2.7.1" @@ -35,7 +37,9 @@ "es6-promisify": "^5.0.0", "glob": "^7.1.2", "lodash": "^4.17.4", + "promisify-child-process": "^1.0.5", "publish-release": "0xproject/publish-release", + "rimraf": "^2.6.2", "semver-sort": "^0.0.4" }, "publishConfig": { diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index 757ae4097..1d49559f2 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -6,3 +6,22 @@ declare module 'es6-promisify'; declare module 'semver-sort' { const desc: (versions: string[]) => string[]; } + +declare interface LernaPackage { + location: string; + package: { + private?: boolean; + name: string; + main?: string; + config?: { + additionalTsTypings?: string[]; + }; + }; +} +declare function lernaGetPackages(path: string): LernaPackage[]; +// lerna-get-packages declarations +declare module 'lerna-get-packages' { + export = lernaGetPackages; +} + +declare module 'promisify-child-process'; diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts new file mode 100644 index 000000000..116b70f3a --- /dev/null +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +import * as fs from 'fs'; +import lernaGetPackages = require('lerna-get-packages'); +import * as _ from 'lodash'; +import * as path from 'path'; +import { exec as execAsync } from 'promisify-child-process'; +import * as rimraf from 'rimraf'; + +import { utils } from './utils'; + +(async () => { + const monorepoRootPath = path.join(__dirname, '../../..'); + const lernaPackages = lernaGetPackages(monorepoRootPath); + const installablePackages = _.filter( + lernaPackages, + lernaPackage => + !lernaPackage.package.private && + !_.isUndefined(lernaPackage.package.main) && + lernaPackage.package.main.endsWith('.js'), + ); + for (const installableLernaPackage of installablePackages) { + const packagePath = installableLernaPackage.location; + const packageName = installableLernaPackage.package.name; + utils.log(`Testing ${packageName}`); + let result = await execAsync('npm pack', { cwd: packagePath }); + const packedPackageFileName = result.stdout.trim(); + const testDirectory = path.join(monorepoRootPath, '../test-env'); + fs.mkdirSync(testDirectory); + result = await execAsync('yarn init --yes', { cwd: testDirectory }); + utils.log(`Installing ${packedPackageFileName}`); + result = await execAsync(`yarn add ${packagePath}/${packedPackageFileName}`, { cwd: testDirectory }); + const indexFilePath = path.join(testDirectory, 'index.ts'); + fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}'`); + const tsConfig = { + compilerOptions: { + module: 'commonjs', + target: 'es5', + lib: ['es2017', 'dom'], + declaration: true, + noImplicitReturns: true, + pretty: true, + strict: true, + }, + include: ['index.ts'], + }; + const tsconfigFilePath = path.join(testDirectory, 'tsconfig.json'); + fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, 4)); + utils.log(`Compiling ${packageName}`); + await execAsync('../node_modules/typescript/bin/tsc', { cwd: testDirectory }); + utils.log(`Successfully compiled with ${packageName} as a dependency`); + rimraf.sync(testDirectory); + } +})().catch(err => { + utils.log(err.stdout); + process.exit(1); +}); diff --git a/packages/monorepo-scripts/tsconfig.json b/packages/monorepo-scripts/tsconfig.json index 3d967d05f..c56d255d5 100644 --- a/packages/monorepo-scripts/tsconfig.json +++ b/packages/monorepo-scripts/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "lib" }, - "include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] + "include": ["./src/**/*"] } |