From 0b49badd43435f5ce5259f03a5d913b74e384e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 2 Oct 2017 15:33:06 +0200 Subject: [PATCH] build: remove ts-node dev-dependency Refactor project infrastructure to transpile test files together with production code and then run the tests from plain javascript code. Benefits: - consistent error message parseable by VSCode's $tsc problem matcher (compiler errors from test files will show in Problems window now) - earlier feedback about type-related problems in test files, no need to wait for ts-node to load type information from tsc output - slightly faster red-green-refactor cycle, `npm test` takes 27s instead of 32s. - we are opening doors to eventually start using `tsc --watch` once TypeScript adds support for multi-project repositories, see https://github.com/Microsoft/TypeScript/issues/3469 --- .prettierignore | 4 +- bin/compile-package.js | 4 +- bin/select-dist.js | 48 +++++++++++++++++++ package.json | 4 +- packages/authentication/.gitignore | 2 +- packages/authentication/index.d.ts | 2 +- packages/authentication/index.js | 4 +- packages/authentication/package.json | 20 ++++---- packages/authentication/tsconfig.build.json | 6 ++- packages/context/.gitignore | 2 +- packages/context/index.d.ts | 2 +- packages/context/index.js | 4 +- packages/context/package.json | 18 +++---- packages/context/tsconfig.build.json | 6 ++- packages/core/.gitignore | 2 +- packages/core/index.d.ts | 2 +- packages/core/index.js | 4 +- packages/core/package.json | 20 ++++---- packages/core/tsconfig.build.json | 6 ++- packages/example-codehub/package.json | 11 +++-- packages/example-codehub/test/mocha.opts | 2 + packages/openapi-spec-builder/.gitignore | 2 +- packages/openapi-spec-builder/index.d.ts | 2 +- packages/openapi-spec-builder/index.js | 4 +- packages/openapi-spec-builder/package.json | 12 ++--- .../openapi-spec-builder/tsconfig.build.json | 6 ++- packages/openapi-spec/.gitignore | 2 +- packages/openapi-spec/index.d.ts | 2 +- packages/openapi-spec/index.js | 4 +- packages/openapi-spec/package.json | 12 ++--- packages/openapi-spec/tsconfig.build.json | 6 ++- packages/repository/.gitignore | 2 +- packages/repository/index.d.ts | 2 +- packages/repository/index.js | 4 +- packages/repository/package.json | 18 +++---- packages/repository/tsconfig.build.json | 6 ++- packages/rest/.gitignore | 2 +- packages/rest/index.d.ts | 2 +- packages/rest/index.js | 4 +- packages/rest/package.json | 20 ++++---- packages/rest/tsconfig.build.json | 6 ++- packages/testlab/.gitignore | 2 +- packages/testlab/index.d.ts | 2 +- packages/testlab/index.js | 4 +- packages/testlab/package.json | 14 +++--- .../{testlab.smoke.js => testlab.smoke.ts} | 4 +- packages/testlab/tsconfig.build.json | 6 ++- test/mocha.opts | 1 - 48 files changed, 203 insertions(+), 121 deletions(-) create mode 100644 bin/select-dist.js create mode 100644 packages/example-codehub/test/mocha.opts rename packages/testlab/test/{testlab.smoke.js => testlab.smoke.ts} (67%) diff --git a/.prettierignore b/.prettierignore index 92b6a8b7190b..8232af516c3d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,3 @@ -packages/*/lib -packages/*/lib6 +packages/*/dist +packages/*/dist6 packages/*/api-docs diff --git a/bin/compile-package.js b/bin/compile-package.js index 25462a507e99..7da479270faf 100644 --- a/bin/compile-package.js +++ b/bin/compile-package.js @@ -42,10 +42,10 @@ if (!target) { let outDir; switch (target) { case 'es2017': - outDir = 'lib'; + outDir = 'dist'; break; case 'es2015': - outDir = 'lib6'; + outDir = 'dist6'; break; default: console.error('Unknown build target %s. Supported values: es2015, es2017'); diff --git a/bin/select-dist.js b/bin/select-dist.js new file mode 100644 index 000000000000..e11f128ad6c5 --- /dev/null +++ b/bin/select-dist.js @@ -0,0 +1,48 @@ +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: loopback-next +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +/* +======== + +Usage: + node ../../bin/select-dist command [arguments...] + +The script will scan all arguments (including the command) and replace +the string DIST with either dist or dist6, depending on the current +Node.js version. + +Then the provided command is executed with the modified arguments. + +Example usage: + + node ../../bin/select-dist mocha DIST/test + +======== +*/ + +'use strict'; + +const path = require('path'); +const spawn = require('child_process').spawn; + +const nodeMajorVersion = +process.versions.node.split('.')[0]; +const dist = nodeMajorVersion >= 7 ? 'dist' : 'dist6'; + +const args = process.argv.slice(2).map(a => a.replace(/\bDIST\b/g, dist)); +const command = args.shift(); + +console.log(command, args.join(' ')); + +spawn( + command, + args, + { + stdio: 'inherit', + // On Windows, npm creates `.cmd` files instead of symlinks in + // `node_modules/.bin` folder. These files cannot be executed directly, + // only via a shell. + shell: true, + } +).on('close', (number, signal) => (process.exitCode = number)); diff --git a/package.json b/package.json index 09b52228451f..c7469caf2ed2 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "node": ">=6" }, "license": "MIT", + "dependencies": {}, "devDependencies": { "@commitlint/cli": "^3.2.0", "@commitlint/config-angular": "^3.1.1", @@ -26,7 +27,6 @@ "request": "^2.79.0", "request-promise": "^4.1.1", "strong-docs": "^1.4.0", - "ts-node": "^3.3.0", "tslint": "^5.7.0", "typescript": "^2.5.2" }, @@ -47,7 +47,7 @@ "build:current": "lerna run --loglevel=silent build:current", "pretest": "npm run build:current", "test": "nyc npm run mocha", - "mocha": "mocha --opts test/mocha.opts \"packages/*/test/**/*.ts\"", + "mocha": "node bin/select-dist mocha --opts test/mocha.opts \"packages/*/DIST/test/**/*.js\"", "posttest": "npm run lint" }, "nyc": { diff --git a/packages/authentication/.gitignore b/packages/authentication/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/authentication/.gitignore +++ b/packages/authentication/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/authentication/index.d.ts b/packages/authentication/index.d.ts index 1105c61c2888..2e634eac04ba 100644 --- a/packages/authentication/index.d.ts +++ b/packages/authentication/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/authentication/index.js b/packages/authentication/index.js index 1def6e2428ed..f1094cb46f50 100644 --- a/packages/authentication/index.js +++ b/packages/authentication/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/authentication/package.json b/packages/authentication/package.json index ba45464ad385..f49b56245364 100644 --- a/packages/authentication/package.json +++ b/packages/authentication/package.json @@ -6,18 +6,18 @@ "node": ">=6" }, "scripts": { - "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", - "build": "npm run build:lib && npm run build:lib6", + "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-authentication*.tgz lib* package", - "integration": "mocha --opts ../../test/mocha.opts 'test/integration/**/*.ts'", + "clean": "rm -rf loopback-authentication*.tgz dist* package", + "integration": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", - "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'", + "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "node bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-authentication*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -44,8 +44,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/authentication/tsconfig.build.json b/packages/authentication/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/authentication/tsconfig.build.json +++ b/packages/authentication/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/context/.gitignore b/packages/context/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/context/.gitignore +++ b/packages/context/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/context/index.d.ts b/packages/context/index.d.ts index d3a897ade5b3..dc252b89673e 100644 --- a/packages/context/index.d.ts +++ b/packages/context/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/context/index.js b/packages/context/index.js index 6dc0839592cd..83589efea4cc 100644 --- a/packages/context/index.js +++ b/packages/context/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/context/package.json b/packages/context/package.json index 62f58bc73554..909a25e141dc 100644 --- a/packages/context/package.json +++ b/packages/context/package.json @@ -6,17 +6,17 @@ "node": ">=6" }, "scripts": { - "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", - "build": "npm run build:lib && npm run build:lib6", + "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-context*.tgz lib* package", + "clean": "rm -rf loopback-context*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/acceptance/**/*.ts'", - "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'", + "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-context*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -42,8 +42,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/context/tsconfig.build.json b/packages/context/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/context/tsconfig.build.json +++ b/packages/context/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/core/.gitignore b/packages/core/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts index 7eb34b35a307..5fea5a9a76f8 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/core/index.js b/packages/core/index.js index 4062339a10c5..a96d017e9def 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/core/package.json b/packages/core/package.json index b67e143da65a..c3a95b2dfee0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -6,18 +6,18 @@ "node": ">=6" }, "scripts": { - "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", - "build": "npm run build:lib && npm run build:lib6", + "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-core*.tgz lib* package", + "clean": "rm -rf loopback-core*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "integration": "mocha --opts ../../test/mocha.opts 'test/integration/**/*.ts'", - "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", - "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'", + "integration": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", + "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-core*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -33,8 +33,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/core/tsconfig.build.json b/packages/core/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/core/tsconfig.build.json +++ b/packages/core/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/example-codehub/package.json b/packages/example-codehub/package.json index a7f60178f7f9..6d4c68469587 100644 --- a/packages/example-codehub/package.json +++ b/packages/example-codehub/package.json @@ -7,10 +7,10 @@ }, "private": true, "scripts": { - "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", - "integration": "mocha --opts ../../test/mocha.opts 'test/integration/**/*.ts'", - "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", - "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'" + "acceptance": "mocha 'test/acceptance/**/*.ts'", + "integration": "mocha 'test/integration/**/*.ts'", + "test": "mocha 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", + "unit": "mocha 'test/unit/**/*.ts'" }, "author": "IBM", "license": "MIT", @@ -19,6 +19,7 @@ "@loopback/rest": "^4.0.0-alpha.3" }, "devDependencies": { - "@loopback/testlab": "^4.0.0-alpha.9" + "@loopback/testlab": "^4.0.0-alpha.9", + "ts-node": "^3.3.0" } } diff --git a/packages/example-codehub/test/mocha.opts b/packages/example-codehub/test/mocha.opts new file mode 100644 index 000000000000..e6331ca64c27 --- /dev/null +++ b/packages/example-codehub/test/mocha.opts @@ -0,0 +1,2 @@ +--compilers ts:ts-node/register +--recursive diff --git a/packages/openapi-spec-builder/.gitignore b/packages/openapi-spec-builder/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/openapi-spec-builder/.gitignore +++ b/packages/openapi-spec-builder/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/openapi-spec-builder/index.d.ts b/packages/openapi-spec-builder/index.d.ts index 7d00598dadab..0af9fa966911 100644 --- a/packages/openapi-spec-builder/index.d.ts +++ b/packages/openapi-spec-builder/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/openapi-spec-builder/index.js b/packages/openapi-spec-builder/index.js index 6dc0839592cd..83589efea4cc 100644 --- a/packages/openapi-spec-builder/index.js +++ b/packages/openapi-spec-builder/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/openapi-spec-builder/package.json b/packages/openapi-spec-builder/package.json index 1e21eadcc8e7..0ef19d7b97c9 100644 --- a/packages/openapi-spec-builder/package.json +++ b/packages/openapi-spec-builder/package.json @@ -6,12 +6,12 @@ "node": ">=6" }, "scripts": { - "build": "npm run build:lib && npm run build:lib6", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-openapi-spec*.tgz lib* package", + "clean": "rm -rf loopback-openapi-spec*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "verify": "npm pack && tar xf loopback-openapi-spec*.tgz && tree package && npm run clean" }, @@ -31,8 +31,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/openapi-spec-builder/tsconfig.build.json b/packages/openapi-spec-builder/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/openapi-spec-builder/tsconfig.build.json +++ b/packages/openapi-spec-builder/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/openapi-spec/.gitignore b/packages/openapi-spec/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/openapi-spec/.gitignore +++ b/packages/openapi-spec/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/openapi-spec/index.d.ts b/packages/openapi-spec/index.d.ts index 55d111e8410f..06b0595bf1db 100644 --- a/packages/openapi-spec/index.d.ts +++ b/packages/openapi-spec/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/openapi-spec/index.js b/packages/openapi-spec/index.js index 343492a47483..f4eece80d480 100644 --- a/packages/openapi-spec/index.js +++ b/packages/openapi-spec/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/openapi-spec/package.json b/packages/openapi-spec/package.json index 018b87ef8f17..3fca2635b84f 100644 --- a/packages/openapi-spec/package.json +++ b/packages/openapi-spec/package.json @@ -6,12 +6,12 @@ "node": ">=6" }, "scripts": { - "build": "npm run build:lib && npm run build:lib6", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-openapi-spec*.tgz lib* package", + "clean": "rm -rf loopback-openapi-spec*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "verify": "npm pack && tar xf loopback-openapi-spec*.tgz && tree package && npm run clean" }, @@ -27,8 +27,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/openapi-spec/tsconfig.build.json b/packages/openapi-spec/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/openapi-spec/tsconfig.build.json +++ b/packages/openapi-spec/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/repository/.gitignore b/packages/repository/.gitignore index dce0f8a72581..90a8d96cc3ff 100644 --- a/packages/repository/.gitignore +++ b/packages/repository/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib*/ +dist* package diff --git a/packages/repository/index.d.ts b/packages/repository/index.d.ts index 33fd79fd924e..1439c16c90db 100644 --- a/packages/repository/index.d.ts +++ b/packages/repository/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/repository/index.js b/packages/repository/index.js index bc2ffd0c222e..2c0a0c33fcd2 100644 --- a/packages/repository/index.js +++ b/packages/repository/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/repository/package.json b/packages/repository/package.json index fd851192dd0c..ab33c9a77abc 100644 --- a/packages/repository/package.json +++ b/packages/repository/package.json @@ -7,17 +7,17 @@ }, "main": "index", "scripts": { - "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", - "build": "npm run build:lib && npm run build:lib6", + "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-context*.tgz lib* package", + "clean": "rm -rf loopback-context*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/acceptance/**/*.ts'", - "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'", + "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-juggler*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -34,8 +34,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/repository/tsconfig.build.json b/packages/repository/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/repository/tsconfig.build.json +++ b/packages/repository/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/rest/.gitignore b/packages/rest/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/rest/.gitignore +++ b/packages/rest/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/rest/index.d.ts b/packages/rest/index.d.ts index 6fe75632d814..c2a1a6cd6195 100644 --- a/packages/rest/index.d.ts +++ b/packages/rest/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib'; +export * from './dist/src'; diff --git a/packages/rest/index.js b/packages/rest/index.js index b2e325dd10e7..ebfbbdff6edc 100644 --- a/packages/rest/index.js +++ b/packages/rest/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib') : - require('./lib6'); + require('./dist/src') : + require('./dist6/src'); diff --git a/packages/rest/package.json b/packages/rest/package.json index e3d2061821f9..9b518f3ab2d6 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -6,18 +6,18 @@ "node": ">=6" }, "scripts": { - "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", - "build": "npm run build:lib && npm run build:lib6", + "acceptance": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", "build:apidocs": "node ../../bin/generate-apidocs", - "clean": "rm -rf loopback-rest*.tgz lib* package", + "clean": "rm -rf loopback-rest*.tgz dist* package", "prepublish": "npm run build && npm run build:apidocs", "pretest": "npm run build:current", - "integration": "mocha --opts ../../test/mocha.opts 'test/integration/**/*.ts'", - "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", - "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'", + "integration": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'", + "test": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'", + "unit": "node ../../bin/select-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'", "verify": "npm pack && tar xf loopback-rest*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -44,8 +44,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "api-docs" ], "repository": { diff --git a/packages/rest/tsconfig.build.json b/packages/rest/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/rest/tsconfig.build.json +++ b/packages/rest/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/packages/testlab/.gitignore b/packages/testlab/.gitignore index d49d21ed0061..90a8d96cc3ff 100644 --- a/packages/testlab/.gitignore +++ b/packages/testlab/.gitignore @@ -1,3 +1,3 @@ *.tgz -lib* +dist* package diff --git a/packages/testlab/index.d.ts b/packages/testlab/index.d.ts index 377cd5583ecd..7310e29f3c36 100644 --- a/packages/testlab/index.d.ts +++ b/packages/testlab/index.d.ts @@ -3,4 +3,4 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -export * from './lib/testlab'; +export * from './dist/src/testlab'; diff --git a/packages/testlab/index.js b/packages/testlab/index.js index 5aa42b8d1752..de379b2180d1 100644 --- a/packages/testlab/index.js +++ b/packages/testlab/index.js @@ -5,5 +5,5 @@ const nodeMajorVersion = +process.versions.node.split('.')[0]; module.exports = nodeMajorVersion >= 7 ? - require('./lib/testlab') : - require('./lib6/testlab'); + require('./dist/src/testlab') : + require('./dist6/src/testlab'); diff --git a/packages/testlab/package.json b/packages/testlab/package.json index 1f31f7fc1abc..32c202d9b92a 100644 --- a/packages/testlab/package.json +++ b/packages/testlab/package.json @@ -6,14 +6,14 @@ "node": ">=6" }, "scripts": { - "build": "npm run build:lib && npm run build:lib6", + "build": "npm run build:dist && npm run build:dist6", "build:current": "node ../../bin/compile-package", - "build:lib": "node ../../bin/compile-package es2017", - "build:lib6": "node ../../bin/compile-package es2015", - "clean": "rm -rf loopback-testlab*.tgz lib* package", + "build:dist": "node ../../bin/compile-package es2017", + "build:dist6": "node ../../bin/compile-package es2015", + "clean": "rm -rf loopback-testlab*.tgz dist* package", "prepublish": "npm run build", "pretest": "npm run build:current", - "test": "mocha", + "test": "node ../../bin/select-dist mocha --recursive DIST/test", "verify": "npm pack && tar xf loopback-testlab*.tgz && tree package && npm run clean" }, "author": "IBM", @@ -35,8 +35,8 @@ "README.md", "index.js", "index.d.ts", - "lib", - "lib6", + "dist/src", + "dist6/src", "should-as-function.d.ts" ], "repository": { diff --git a/packages/testlab/test/testlab.smoke.js b/packages/testlab/test/testlab.smoke.ts similarity index 67% rename from packages/testlab/test/testlab.smoke.js rename to packages/testlab/test/testlab.smoke.ts index 6f8f20d3ae28..61f8a76ca9c0 100644 --- a/packages/testlab/test/testlab.smoke.js +++ b/packages/testlab/test/testlab.smoke.ts @@ -1,8 +1,8 @@ -const assert = require('assert'); +import * as assert from 'assert'; +import * as testlab from '..'; describe('testlab smoke test', () => { it('exports expect interface', () => { - const testlab = require('..'); assert.equal(typeof testlab.expect, 'function'); }); }); diff --git a/packages/testlab/tsconfig.build.json b/packages/testlab/tsconfig.build.json index 38073c743ab5..dc78331e392e 100644 --- a/packages/testlab/tsconfig.build.json +++ b/packages/testlab/tsconfig.build.json @@ -1,7 +1,11 @@ { "$schema": "http://json.schemastore.org/tsconfig", "extends": "../../tsconfig.common.json", + "compilerOptions": { + "rootDir": "." + }, "include": [ - "src" + "src", + "test" ] } diff --git a/test/mocha.opts b/test/mocha.opts index e6331ca64c27..4a5232017818 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,2 +1 @@ ---compilers ts:ts-node/register --recursive