Skip to content
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
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"@types/node": "^8.5.9",
"coveralls": "^3.0.0",
"cz-conventional-changelog": "^2.1.0",
"lerna": "^2.5.1",
"mocha": "^5.0.0",
"source-map-support": "^0.5.2"
"lerna": "^2.8.0"
},
"scripts": {
"bootstrap": "npm i && lerna bootstrap",
Expand All @@ -41,7 +39,7 @@
"build:full": "npm run clean:full && npm run bootstrap && npm run build && npm run mocha && npm run lint",
"pretest": "npm run clean && npm run build:current",
"test": "node packages/build/bin/run-nyc npm run mocha",
"mocha": "node packages/build/bin/select-dist mocha --opts packages/build/mocha.ts.opts \"packages/*/DIST/test/**/*.js\" \"packages/cli/test/*.js\"",
"mocha": "node packages/build/bin/run-mocha \"packages/*/DIST/test/**/*.js\" \"packages/cli/test/*.js\"",
"posttest": "npm run lint"
},
"config": {
Expand Down
8 changes: 4 additions & 4 deletions packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
"node": ">=6"
},
"scripts": {
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
"build:dist6": "lb-tsc es2015",
"build:apidocs": "lb-apidocs",
"clean": "lb-clean loopback-authentication*.tgz dist dist6 package api-docs",
"integration": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/integration/**/*.js'",
"integration": "lb-mocha \"DIST/test/integration/**/*.js\"",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/integration/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-authentication*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down
19 changes: 12 additions & 7 deletions packages/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
This module contains a set of common scripts and default configurations to build LoopBack 4 or other TypeScript modules, including:

- lb-tsc: Use [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to compile typescript files
- lb-dist: Detect the correct distribution target: `dist` => ES2017, `dist6` => ES2015
- lb-tslint: Run [`tslint`](https://github.com/palantir/tslint)
- lb-prettier: Run [`prettier`](https://github.com/prettier/prettier)
- lb-mocha: Run [`mocha`](https://mochajs.org/) to execute test cases
- lb-nyc: Run [`nyc`](https://github.com/istanbuljs/nyc)
- lb-dist: Detect the correct distribution target: `dist` => ES2017, `dist6` => ES2015.
The command is deprecated as `lb-mocha` detects the distribution target now.

These scripts first try to locate the CLI from target project dependencies and fall back to bundled ones in `@loopback/build`.

Expand All @@ -19,6 +21,7 @@ To use `@loopback/build` for your package:
`npm i @loopback/build --save-dev`

2. Configure your project package.json as follows:

```json
"scripts": {
"build": "npm run build:dist && npm run build:dist6",
Expand All @@ -33,17 +36,19 @@ To use `@loopback/build` for your package:
"prettier:fix": "npm run prettier:cli -- --write",
"lint": "npm run prettier:check && npm run tslint",
"lint:fix": "npm run prettier:fix && npm run tslint:fix",
"clean": "lb-clean loopback-grpc*.tgz dist*",
"clean": "lb-clean your-module-name*.tgz dist* api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'",
"integration": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/integration/**/*.js'",
"test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'",
"verify": "npm pack && tar xf loopback-grpc*.tgz && tree package && npm run clean"
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"integration": "lb-mocha \"DIST/test/integration/**/*.js\"",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/integration/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf your-module-name*.tgz && tree package && npm run clean"
},
```

Please remember to replace `your-module-name` with the name of your module.

Now you run the scripts, such as:

- `npm run build` - Compile TypeScript files
Expand Down
46 changes: 46 additions & 0 deletions packages/build/bin/run-mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/build
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/*
========

Usage:
node ./bin/run-mocha

========
*/

'use strict';

function run(argv, dryRun) {
const utils = require('./utils');
const path = require('path');

// Substitute the DIST variable with the dist folder
const dist = utils.getDistribution();
const mochaOpts = argv.slice(2).map(a => a.replace(/\bDIST\b/g, dist));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this has effectively inlined select-dist script, I think we can remove select-dist entirely? Just make sure to mention that removal in the commit message as a BREAKING CHANGE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to leave lb-dist there to keep backward compatibility as projects generated from previous versions of our CLI reference lb-dist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

To me, this is another argument against using.alpha.X prereleases for so long. If we were versioning non-core modules as 0.x.y, then we could treat semver-patch release as backwards compatible and semver-minor releases as breaking. This works great with the carrot operator as implemented by npm's semver (https://www.npmjs.com/package/semver#caret-ranges-123-025-004):

this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the versioning. Is it too late to fix it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the versioning.

👍

Is it too late to fix it?

I don't know. Let's open a new issue and try to find out what the implications of such change would be & how much work this change would require:

#954


// Add default options
if (mochaOpts.indexOf('--opts') === -1) {
const optsPath = require.resolve('../mocha.opts');
mochaOpts.unshift('--opts', optsPath);
}

// Add source map support
if (mochaOpts.indexOf('source-map-support/register') === -1) {
// Resolve source-map-support so that the path can be used by mocha
const sourceMapRegisterPath = require.resolve(
'source-map-support/register'
);
mochaOpts.unshift('--require', sourceMapRegisterPath);
}
const args = [...mochaOpts];

return utils.runCLI('mocha/bin/mocha', args, dryRun);
}

module.exports = run;
if (require.main === module) run(process.argv);
1 change: 1 addition & 0 deletions packages/build/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"bin/generate-apidocs.js",
"bin/run-clean.js",
"bin/run-nyc.js",
"bin/run-mocha.js",
"bin/run-prettier.js",
"bin/run-tslint.js",
"bin/select-dist.js",
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions packages/build/mocha.ts.opts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"mocha": "^5.0.0",
"nyc": "^11.4.1",
"prettier": "^1.10.2",
"source-map-support": "^0.5.3",
"strong-docs": "^1.6.0",
"tslint": "^5.9.1",
"typescript": "^2.6.2"
Expand All @@ -28,6 +29,7 @@
"lb-tsc": "./bin/compile-package.js",
"lb-tslint": "./bin/run-tslint.js",
"lb-prettier": "./bin/run-prettier.js",
"lb-mocha": "./bin/run-mocha.js",
"lb-nyc": "./bin/run-nyc.js",
"lb-dist": "./bin/select-dist.js",
"lb-apidocs": "./bin/generate-apidocs.js",
Expand All @@ -40,7 +42,7 @@
"prettier:check": "npm run prettier:cli -- -l",
"prettier:fix": "npm run prettier:cli -- --write",
"test": "npm run mocha",
"mocha": "node bin/select-dist mocha --opts mocha.js.opts --timeout 30000 \"test/integration/*.js\"",
"mocha": "node bin/run-mocha --timeout 30000 \"test/integration/*.js\"",
"posttest": "npm run lint"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generators/project/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<% } -%>
"pretest": "npm run clean && npm run build",
<% if (project.mocha) { -%>
"test": "lb-dist mocha DIST/test",
"test": "lb-mocha \"DIST/test\"",
<% } -%>
<% if (project.prettier || project.tslint) { -%>
"posttest": "npm run lint",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"yeoman-generator"
],
"devDependencies": {
"@loopback/build": "^4.0.0-alpha.9",
"@loopback/testlab": "^4.0.0-alpha.19",
"eslint-config-google": "^0.9.1",
"glob": "^7.1.2",
Expand Down Expand Up @@ -54,7 +55,7 @@
},
"scripts": {
"prepublishOnly": "nsp check",
"test": "mocha --opts node_modules/@loopback/build/mocha.js.opts \"test/*.js\""
"test": "lb-mocha \"test/*.js\""
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/clone-example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('cloneExampleFromGitHub', function() {
return Promise.all([
glob('**', {
cwd: path.join(__dirname, `../../example-${VALID_EXAMPLE}`),
ignore: '@(node_modules|dist*)/**',
ignore: '@(node_modules|dist*|api-docs)/**',
}),
glob('**', {
cwd: outDir,
Expand Down
6 changes: 3 additions & 3 deletions packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"node": ">=6"
},
"scripts": {
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
Expand All @@ -15,8 +15,8 @@
"clean": "lb-clean loopback-context*.tgz dist dist6 package api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-context*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"node": ">=6"
},
"scripts": {
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
Expand All @@ -15,9 +15,9 @@
"clean": "lb-clean loopback-core*.tgz dist dist6 package api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"integration": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/integration/**/*.js'",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"integration": "lb-mocha \"DIST/test/integration/**/*.js\"",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/integration/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-core*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down
8 changes: 4 additions & 4 deletions packages/example-getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": ">=8"
},
"scripts": {
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
Expand All @@ -17,9 +17,9 @@
"clean": "lb-clean *example-getting-started*.tgz dist dist6 package api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"verify": "npm pack && tar xf *example-getting-started*.tgz && tree package && npm run clean",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-getting-started*.tgz && tree package && npm run clean",
"start": "npm run build && node ."
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/example-log-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"tslint:fix": "npm run tslint -- --fix",
"prepare": "npm run build",
"pretest": "npm run clean && npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"test": "lb-dist mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"posttest": "npm run lint",
"verify": "npm pack && tar xf *example-log-extension*.tgz && tree package && npm run clean"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"node": ">=6"
},
"scripts": {
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
Expand All @@ -15,8 +15,8 @@
"clean": "lb-clean loopback-metadata*.tgz dist dist6 package api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-metadata*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down
11 changes: 11 additions & 0 deletions packages/metadata/test/unit/inspector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ describe('Inspector for design time metadata', () => {

@propertyDecorator() myArray: string[];

@propertyDecorator() myUnionType: string | number;

@methodDecorator()
myMethod(x: string, y: number): boolean {
return false;
Expand Down Expand Up @@ -631,6 +633,15 @@ describe('Inspector for design time metadata', () => {
expect(meta).to.eql(MyClass);
});

it('inspects design time type for properties with union type', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like unrelated changes to me. @raymondfeng could you please check these changes were intended?

const meta = MetadataInspector.getDesignTypeForProperty(
MyController.prototype,
'myUnionType',
);
// Union type is recorded as Object
expect(meta).to.eql(Object);
});

it('inspects design time type for static properties', () => {
const meta = MetadataInspector.getDesignTypeForProperty(
MyController,
Expand Down
4 changes: 3 additions & 1 deletion packages/openapi-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@loopback/openapi-spec-builder": "^4.0.0-alpha.17",
"@loopback/repository": "^4.0.0-alpha.23",
"@loopback/testlab": "^4.0.0-alpha.19",
"@types/debug": "0.0.30",
"@types/lodash": "^4.14.96"
},
"scripts": {
Expand All @@ -21,7 +22,7 @@
"clean": "lb-clean loopback-openapi-v2*.tgz dist* package",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"test": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-openapi-v2*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down Expand Up @@ -52,6 +53,7 @@
"@loopback/context": "^4.0.0-alpha.26",
"@loopback/openapi-spec": "^4.0.0-alpha.20",
"@loopback/repository-json-schema": "^4.0.0-alpha.1",
"debug": "^3.1.0",
"lodash": "^4.17.4"
}
}
2 changes: 1 addition & 1 deletion packages/repository-json-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"clean": "lb-clean loopback-json-schema*.tgz dist dist6 package api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'dist/test/unit/**/*.js' 'dist/test/integration/**/*.js' 'dist/test/acceptance/**/*.js'",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/integration/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"verify": "npm pack && tar xf loopback-json-schema*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down
6 changes: 3 additions & 3 deletions packages/repository/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"main": "index",
"scripts": {
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"",
"build": "npm run build:dist && npm run build:dist6",
"build:current": "lb-tsc",
"build:dist": "lb-tsc es2017",
Expand All @@ -16,8 +16,8 @@
"clean": "lb-clean loopback-repository*.tgz dist dist6 package api-docs",
"prepare": "npm run build && npm run build:apidocs",
"pretest": "npm run build:current",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"",
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"",
"verify": "npm pack && tar xf loopback-juggler*.tgz && tree package && npm run clean"
},
"author": "IBM",
Expand Down
Loading