Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@angularclass/hmr
Advanced tools
Angular-HMR Hot Module Reloading for Webpack and Angular. All versions of Angular and Webpack will work with this module
npm install @angularclass/hmr
main.browser.ts
import { removeNgStyles, createNewHosts, bootloader } from '@angularclass/hmr';
@NgModule({
bootstrap: [ App ],
declarations: [ App ],
imports: [
// Angular 2
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([], {
useHash: true
}),
// app
appModule
// vendors
],
providers: []
})
class MainModule {
constructor(public appRef: ApplicationRef) {}
hmrOnInit(store) {
if (!store || !store.state) return;
console.log('HMR store', store);
console.log('store.state.data:', store.state.data)
// inject AppStore here and update it
// this.AppStore.update(store.state)
if ('restoreInputValues' in store) {
store.restoreInputValues();
}
// change detection
this.appRef.tick();
delete store.state;
delete store.restoreInputValues;
}
hmrOnDestroy(store) {
var cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
// recreate elements
store.disposeOldHosts = createNewHosts(cmpLocation)
// inject your AppStore and grab state then set it on store
// var appState = this.AppStore.get()
store.state = {data: 'yolo'};
// store.state = Object.assign({}, appState)
// save input values
store.restoreInputValues = createInputTransfer();
// remove styles
removeNgStyles();
}
hmrAfterDestroy(store) {
// display new elements
store.disposeOldHosts()
delete store.disposeOldHosts;
// anything you need done the component is removed
}
}
export function main() {
return platformBrowserDynamic().bootstrapModule(MainModule)
// use `hmrModule` or the "@angularclass/hmr-loader"
.then((ngModuleRef: any) => {
// `module` global ref for webpackhmr
// Don't run this in Prod
return hmrModule(ngModuleRef, module);
});
}
// boot on document ready
bootloader(main);
bootloader
is only needed to detect that the dom is ready before bootstraping otherwise bootstrap. This is needed because that dom is already ready during reloading.
In production you only need bootloader which just does this:
export function bootloader(main) {
if (document.readyState === 'complete') {
main()
} else {
document.addEventListener('DOMContentLoaded', main);
}
}
You would bootstrap your app the normal way, in production, after dom is ready. Also, in production, you should remove the loader:
To hook into NGRX 4 you simply need to supply a reducer to set the state, and include it in your development metaReducers.
// make sure you export for AoT
export function stateSetter(reducer: ActionReducer<any>): ActionReducer<any> {
return function(state: any, action: any) {
if (action.type === 'SET_ROOT_STATE') {
return action.payload;
}
return reducer(state, action);
};
}
In your root reducer you can do something like this to include it in your metaReducers
.
You should access your environment here and only include this in development.
/**
* By default, @ngrx/store uses combineReducers with the reducer map to compose
* the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers
* that will be composed to form the root meta-reducer.
*/
export const metaReducers: ActionReducer<any, any>[] = [stateSetter]
Simply supply the metaReducer to the StoreModule
and your hmr is hooked in.
StoreModule.forRoot(reducers, { metaReducers }),
enjoy — PatrickJS
FAQs
angular-hmr: Hot Module Replacement for Webpack and Angular
The npm package @angularclass/hmr receives a total of 50,202 weekly downloads. As such, @angularclass/hmr popularity was classified as popular.
We found that @angularclass/hmr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.