Skip to content

Commit

Permalink
feat(build): add lodash es imports and lodash types
Browse files Browse the repository at this point in the history
  - added used modules to rollup globals (TODO: NationalBankBelgium#1129)
  - blacklisted `lodash-es` (use submodules instead)
  - added `karma-typescript-es6-transform` for transforming es6 dependencies
    - added workaround for monounity/karma-typescript#320 in `base.spec.ts` (stark-core, stark-ui, showcase, starter)
    - aliased all used lodash modules in karma.conf.js (TODO NationalBankBelgium#1145)
  - minor refactors

ISSUES CLOSED: NationalBankBelgium#150
  • Loading branch information
carlo-nomes committed Mar 27, 2019
1 parent 517df61 commit 1e53d5d
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 50 deletions.
13 changes: 12 additions & 1 deletion packages/rollup.config.common-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const globals = {
"@angular/material/autocomplete": "ngMaterial.autocomplete",
"@angular/material/button": "ngMaterial.button",
"@angular/material/button-toggle": "ngMaterial.buttonToggle",
"@angular/material/card":"ngMaterial.card",
"@angular/material/card": "ngMaterial.card",
"@angular/material/checkbox": "ngMaterial.checkbox",
"@angular/material/core": "ngMaterial.core",
"@angular/material/datepicker": "ngMaterial.datepicker",
Expand Down Expand Up @@ -59,6 +59,17 @@ const globals = {
cerialize: "cerialize",
ibantools: "ibantools",
moment: "moment",
"lodash-es/cloneDeep": "lodash-es.cloneDeep",
"lodash-es/findIndex": "lodash-es.findIndex",
"lodash-es/floor": "lodash-es.floor",
"lodash-es/get": "lodash-es.get",
"lodash-es/isEmpty": "lodash-es.isEmpty",
"lodash-es/isEqual": "lodash-es.isEqual",
"lodash-es/merge": "lodash-es.merge",
"lodash-es/noop": "lodash-es.noop",
"lodash-es/reduce": "lodash-es.reduce",
"lodash-es/sortBy": "lodash-es.sortBy",
"lodash-es/uniqueId": "lodash-es.uniqueId",
nouislider: "nouislider",
"prettier/standalone": "prettier.standalone",
"prettier/parser-babylon": "prettier.parserBabylon",
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-build/config/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
}
],
"no-magic-numbers": false,
"import-blacklist": [true, "@angular/material", "lodash", "rxjs/internal", "rxjs/index", "rxjs/Rx"],
"import-blacklist": [true, "@angular/material", "lodash", "rxjs/internal", "rxjs/index", "rxjs/Rx", "lodash-es"],
"ordered-imports": false,
"max-classes-per-file": false, // [true, 1],
"prefer-for-of": true,
Expand Down
3 changes: 3 additions & 0 deletions packages/stark-core/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "core-js/es7/reflect";
import "core-js/stage/4";

/* tslint:disable:no-import-side-effect */
// FIXME: change when https://github.com/monounity/karma-typescript/issues/320 is resolved
// tslint:disable-next-line:import-blacklist
import "lodash-es"; // see https://github.com/monounity/karma-typescript/issues/150#issuecomment-318620280
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/proxy"; // since zone.js 0.6.15
Expand Down
15 changes: 14 additions & 1 deletion packages/stark-core/karma.conf.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ const starkCoreSpecificConfiguration = Object.assign({}, defaultKarmaCIConfig, {
dir: helpers.root("reports/coverage/packages")
}),
// add missing files due to "@nationalbankbelgium/stark-core" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles]
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles],
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
});

// export the configuration function that karma expects and simply return the stark configuration
Expand Down
15 changes: 14 additions & 1 deletion packages/stark-core/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ const karmaTypescriptFiles = [{ pattern: helpers.root("index.ts") }, { pattern:
// start customizing the Karma configuration from stark-testing
const starkCoreSpecificConfiguration = Object.assign({}, defaultKarmaConfig, {
// add missing files due to "@nationalbankbelgium/stark-core" imports used in mock files of the testing sub-package
files: [...defaultKarmaConfig.files, ...karmaTypescriptFiles]
files: [...defaultKarmaConfig.files, ...karmaTypescriptFiles],
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
karmaTypescriptConfig: {
...defaultKarmaConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaConfig.karmaTypescriptConfig.bundlerOptions,
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
});

// export the configuration function that karma expects and simply return the stark configuration
Expand Down
3 changes: 2 additions & 1 deletion packages/stark-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
"@ngrx/store": "^7.1.0",
"@ngrx/store-devtools": "^7.1.0",
"@ngx-translate/core": "^11.0.1",
"@types/lodash-es": "^4.17.1",
"@types/node": "^8.10.37",
"@types/uuid": "^3.4.4",
"@uirouter/angular": "^3.0.0",
"cerialize": "^0.1.18",
"class-validator": "^0.7.3",
"deep-freeze-strict": "^1.1.1",
"ibantools": "^2.0.0",
"lodash": "^4.17.11",
"lodash-es": "^4.17.11",
"moment": "^2.22.2",
"uuid": "^3.3.2"
},
Expand Down
1 change: 0 additions & 1 deletion packages/stark-core/testing/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

"files": ["public_api.ts"],

// Unfortunately, all those options have to be written in every tsconfig file
"angularCompilerOptions": {
"generateCodeForLibraries": true,
"skipMetadataEmit": false,
Expand Down
1 change: 0 additions & 1 deletion packages/stark-core/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

"files": ["public_api.ts"],

// Unfortunately, all those options have to be written in every tsconfig file
"angularCompilerOptions": {
"generateCodeForLibraries": true,
"skipMetadataEmit": false,
Expand Down
5 changes: 4 additions & 1 deletion packages/stark-testing/karma.conf.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const rawKarmaConfig = {
],
resolve: {},
transforms: [
require("karma-typescript-angular2-transform") // see https://github.com/monounity/karma-typescript-angular2-transform
//see https://github.com/monounity/karma-typescript/tree/master/packages/karma-typescript-angular2-transform
require("karma-typescript-angular2-transform"),
//see https://github.com/monounity/karma-typescript/tree/master/packages/karma-typescript-es6-transform
require("karma-typescript-es6-transform")()
]
},
tsconfig: helpers.getAngularCliAppConfig().architect.test.options.tsConfig
Expand Down
7 changes: 6 additions & 1 deletion packages/stark-testing/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ const rawKarmaConfig = {
],
resolve: {},
transforms: [
require("karma-typescript-angular2-transform") // see https://github.com/monounity/karma-typescript-angular2-transform
//see https://github.com/monounity/karma-typescript/tree/master/packages/karma-typescript-angular2-transform
require("karma-typescript-angular2-transform"),
//see https://github.com/monounity/karma-typescript/tree/master/packages/karma-typescript-es6-transform
require("karma-typescript-es6-transform")({
presets: ["babel-preset-env"] // default setting
})
]
},
tsconfig: helpers.getAngularCliAppConfig().architect.test.options.tsConfig
Expand Down
1 change: 1 addition & 0 deletions packages/stark-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-typescript": "^4.0.0",
"karma-typescript-angular2-transform": "^4.0.0",
"karma-typescript-es6-transform": "^4.0.0",
"protractor": "^5.4.2",
"puppeteer": "^1.11.0"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/stark-ui/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ if (window.NodeList && !NodeList.prototype.forEach) {
}

/* tslint:disable:no-import-side-effect */
// FIXME: change when https://github.com/monounity/karma-typescript/issues/320 is resolved
// tslint:disable-next-line:import-blacklist
import "lodash-es"; // see https://github.com/monounity/karma-typescript/issues/150#issuecomment-318620280
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/proxy"; // since zone.js 0.6.15
Expand Down
24 changes: 16 additions & 8 deletions packages/stark-ui/karma.conf.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ const helpers = require("../stark-testing/helpers");
* Load karma config from Stark
*/
const defaultKarmaCIConfig = require("../stark-testing/karma.conf.ci.js").rawKarmaConfig;
const karmaTypescriptBundlerAliasResolution = require("./karma.conf").karmaTypescriptBundlerAliasResolution;
const karmaTypescriptBundlerAlias = require("./karma.conf").karmaTypescriptBundlerAlias;
const karmaTypescriptFiles = require("./karma.conf").karmaTypescriptFiles;

// start customizing the KarmaCI configuration from stark-testing
const starkUiSpecificConfiguration = Object.assign({}, defaultKarmaCIConfig, {
// change the module resolution for the KarmaTypescript bundler
karmaTypescriptConfig: Object.assign(defaultKarmaCIConfig.karmaTypescriptConfig, {
bundlerOptions: Object.assign(defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions, karmaTypescriptBundlerAliasResolution)
}),
// change the path of the report so that Coveralls takes the right path to the source files
coverageIstanbulReporter: Object.assign(defaultKarmaCIConfig.coverageIstanbulReporter, {
dir: helpers.root("reports/coverage/packages")
}),
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
resolve: {
alias: karmaTypescriptBundlerAlias
},
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
},
// add missing files due to "@nationalbankbelgium/stark-ui" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles]
});
Expand Down
75 changes: 48 additions & 27 deletions packages/stark-ui/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,58 @@ const defaultKarmaConfig = require("../stark-testing/karma.conf.js").rawKarmaCon
// entry files of the "@nationalbankbelgium/stark-ui" module imported in mock files
const karmaTypescriptFiles = [{ pattern: helpers.root("index.ts") }, { pattern: helpers.root("public_api.ts") }];

const karmaTypescriptBundlerAliasResolution = {
resolve: {
alias: {
// adapt the resolution of the stark-core module to the UMD module
"@nationalbankbelgium/stark-core": "../../dist/packages-dist/stark-core/bundles/stark-core.umd.js",
"@nationalbankbelgium/stark-core/testing": "../../dist/packages-dist/stark-core/bundles/stark-core-testing.umd.js",
// adapt the resolution of the 3rd party modules used in stark-core
"@angularclass/hmr": "../stark-core/node_modules/@angularclass/hmr/dist/index.js",
"@ng-idle/core": "../stark-core/node_modules/@ng-idle/core/bundles/core.umd.js",
"@ng-idle/keepalive": "../stark-core/node_modules/@ng-idle/keepalive/bundles/keepalive.umd.js",
"@ngrx/store": "../stark-core/node_modules/@ngrx/store/bundles/store.umd.js",
"@ngrx/effects": "../stark-core/node_modules/@ngrx/effects/bundles/effects.umd.js",
"@ngx-translate/core": "../stark-core/node_modules/@ngx-translate/core/bundles/ngx-translate-core.umd.js",
"@uirouter/angular": "../stark-core/node_modules/@uirouter/angular/_bundles/ui-router-ng2.js",
"@uirouter/core": "../stark-core/node_modules/@uirouter/core/lib/index.js",
"@uirouter/rx": "../stark-core/node_modules/@uirouter/rx/lib/index.js",
cerialize: "../stark-core/node_modules/cerialize/index.js",
"class-validator": "../stark-core/node_modules/class-validator/index.js",
"deep-freeze-strict": "../stark-core/node_modules/deep-freeze-strict/index.js",
moment: "../stark-core/node_modules/moment/moment.js",
ibantools: "../stark-core/node_modules/ibantools/build/ibantools.js"
}
}
const karmaTypescriptBundlerAlias = {
// adapt the resolution of the stark-core module to the UMD module
"@nationalbankbelgium/stark-core": "../../dist/packages-dist/stark-core/bundles/stark-core.umd.js",
"@nationalbankbelgium/stark-core/testing": "../../dist/packages-dist/stark-core/bundles/stark-core-testing.umd.js",
// adapt the resolution of the 3rd party modules used in stark-core
"@angularclass/hmr": "../stark-core/node_modules/@angularclass/hmr/dist/index.js",
"@ng-idle/core": "../stark-core/node_modules/@ng-idle/core/bundles/core.umd.js",
"@ng-idle/keepalive": "../stark-core/node_modules/@ng-idle/keepalive/bundles/keepalive.umd.js",
"@ngrx/store": "../stark-core/node_modules/@ngrx/store/bundles/store.umd.js",
"@ngrx/effects": "../stark-core/node_modules/@ngrx/effects/bundles/effects.umd.js",
"@ngx-translate/core": "../stark-core/node_modules/@ngx-translate/core/bundles/ngx-translate-core.umd.js",
"@uirouter/angular": "../stark-core/node_modules/@uirouter/angular/_bundles/ui-router-ng2.js",
"@uirouter/core": "../stark-core/node_modules/@uirouter/core/lib/index.js",
"@uirouter/rx": "../stark-core/node_modules/@uirouter/rx/lib/index.js",
cerialize: "../stark-core/node_modules/cerialize/index.js",
"class-validator": "../stark-core/node_modules/class-validator/index.js",
"deep-freeze-strict": "../stark-core/node_modules/deep-freeze-strict/index.js",
moment: "../stark-core/node_modules/moment/moment.js",
"lodash-es": "../stark-core/node_modules/lodash-es/lodash.js",
"lodash-es/cloneDeep": "../stark-core/node_modules/lodash-es/cloneDeep.js",
"lodash-es/findIndex": "../stark-core/node_modules/lodash-es/findIndex.js",
"lodash-es/floor": "../stark-core/node_modules/lodash-es/floor.js",
"lodash-es/get": "../stark-core/node_modules/lodash-es/get.js",
"lodash-es/isEmpty": "../stark-core/node_modules/lodash-es/isEmpty.js",
"lodash-es/isEqual": "../stark-core/node_modules/lodash-es/isEqual.js",
"lodash-es/merge": "../stark-core/node_modules/lodash-es/merge.js",
"lodash-es/noop": "../stark-core/node_modules/lodash-es/noop.js",
"lodash-es/sortBy": "../stark-core/node_modules/lodash-es/sortBy.js",
"lodash-es/reduce": "../stark-core/node_modules/lodash-es/reduce.js",
"lodash-es/startCase": "../stark-core/node_modules/lodash-es/startCase.js",
"lodash-es/uniqueId": "../stark-core/node_modules/lodash-es/uniqueId.js",
ibantools: "../stark-core/node_modules/ibantools/build/ibantools.js"
};

// start customizing the KarmaCI configuration from stark-testing
const starkUiSpecificConfiguration = Object.assign({}, defaultKarmaConfig, {
// change the module resolution for the KarmaTypescript bundler
karmaTypescriptConfig: Object.assign(defaultKarmaConfig.karmaTypescriptConfig, {
bundlerOptions: Object.assign(defaultKarmaConfig.karmaTypescriptConfig.bundlerOptions, karmaTypescriptBundlerAliasResolution)
}),
karmaTypescriptConfig: {
...defaultKarmaConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaConfig.karmaTypescriptConfig.bundlerOptions,
resolve: {
alias: karmaTypescriptBundlerAlias
},
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
},
// add missing files due to "@nationalbankbelgium/stark-ui" imports used in mock files of the testing sub-package
files: [...defaultKarmaConfig.files, ...karmaTypescriptFiles]
});
Expand All @@ -48,6 +69,6 @@ module.exports = {
default: function(config) {
return config.set(starkUiSpecificConfiguration);
},
karmaTypescriptBundlerAliasResolution: karmaTypescriptBundlerAliasResolution,
karmaTypescriptBundlerAlias,
karmaTypescriptFiles: karmaTypescriptFiles
};
1 change: 1 addition & 0 deletions packages/stark-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@angular/material-moment-adapter": "^7.0.0",
"@mdi/angular-material": "^3.3.92",
"@types/lodash-es": "^4.17.1",
"@types/nouislider": "^9.0.4",
"@types/prismjs": "^1.16.0",
"angular2-text-mask": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-ui/testing/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

"files": ["public_api.ts"],

// Unfortunately, all those options have to be written in every tsconfig file

"angularCompilerOptions": {
"generateCodeForLibraries": true,
"skipMetadataEmit": false,
Expand Down
9 changes: 6 additions & 3 deletions packages/stark-ui/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
"typeRoots": ["./node_modules/@types", "../stark-build/typings", "./typings"],
"typeRoots": [
"./node_modules/@types",
"../stark-build/typings",
"./typings"
],
"lib": ["dom", "dom.iterable", "es2017"],
"paths": {
"@angularclass/hmr": ["../stark-core/node_modules/@angularclass/hmr"],
Expand All @@ -21,7 +25,7 @@
"class-validator": ["../stark-core/node_modules/class-validator"],
"moment": ["../stark-core/node_modules/moment"],
"ibantools": ["../stark-core/node_modules/ibantools"],
"lodash": ["../stark-core/node_modules/lodash"],
"lodash-es/*": ["../stark-core/node_modules/lodash-es/*"],
"rxjs/*": ["../../node_modules/rxjs/*"],
"environments/environment": ["../../dist/packages/stark-core/src/common/environment"],
"@nationalbankbelgium/stark-core": ["../../dist/packages/stark-core"],
Expand All @@ -32,7 +36,6 @@

"files": ["public_api.ts"],

// Unfortunately, all those options have to be written in every tsconfig file
"angularCompilerOptions": {
"generateCodeForLibraries": true,
"skipMetadataEmit": false,
Expand Down
2 changes: 2 additions & 0 deletions packages/stark-ui/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"@ngx-translate/*": ["../stark-core/node_modules/@ngx-translate/*"],
"@uirouter/*": ["../stark-core/node_modules/@uirouter/*"],
"moment": ["../stark-core/node_modules/moment"],
"lodash-es": ["../stark-core/node_modules/lodash-es"],
"lodash-es/*": ["../stark-core/node_modules/lodash-es/*"],
"@nationalbankbelgium/stark-core/testing": ["../../dist/packages/stark-core/testing"],
"@nationalbankbelgium/stark-core": ["../../dist/packages/stark-core"],
"@nationalbankbelgium/stark-ui": ["."]
Expand Down
3 changes: 3 additions & 0 deletions showcase/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ if (window.NodeList && !NodeList.prototype.forEach) {
}

/* tslint:disable:no-import-side-effect */
// FIXME: change when https://github.com/monounity/karma-typescript/issues/320 is resolved
// tslint:disable-next-line:import-blacklist
import "lodash-es"; // see https://github.com/monounity/karma-typescript/issues/150#issuecomment-318620280
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/proxy"; // since zone.js 0.6.15
Expand Down
2 changes: 0 additions & 2 deletions showcase/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class AppComponent implements OnInit {
public breakpointObserver: BreakpointObserver
) {}

/* tslint:disable */
public ngOnInit(): void {
this.logger.debug("app: component loaded");
this.mainMenu = APP_MENU_CONFIG;
Expand All @@ -73,7 +72,6 @@ export class AppComponent implements OnInit {
this.isMenuModeActive = state.matches;
});
}
/* tslint:enable */

public toggleMenu(): void {
this.sidebarService.toggleMenu();
Expand Down
3 changes: 3 additions & 0 deletions starter/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ if (window.NodeList && !NodeList.prototype.forEach) {
}

/* tslint:disable:no-import-side-effect */
// FIXME: change when https://github.com/monounity/karma-typescript/issues/320 is resolved
// tslint:disable-next-line:import-blacklist
import "lodash-es"; // see https://github.com/monounity/karma-typescript/issues/150#issuecomment-318620280
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/proxy"; // since zone.js 0.6.15
Expand Down

0 comments on commit 1e53d5d

Please sign in to comment.