ngc-webpack
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "ngc-webpack", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -77,2 +77,14 @@ # Angular Template Compiler Wrapper for Webpack | ||
In addition there are 2 callbacks invoked when the process ends: | ||
- onCompilationSuccess: () => void | ||
Fires then the compilation ended with no errors. | ||
- onCompilationError?: (error: Error) => void | ||
Fires then the compilation ended with an error. | ||
If you throw from these callbacks the process will exit with failure and print the error message. | ||
This allows some validation for `pathTransformer`, to check the state one finished and conclude about the result. | ||
> Throwing from `onCompilationError` is like re-throw with a new error. | ||
Currently it's not possible to suppress an error. | ||
Example (webpack.config module) | ||
@@ -79,0 +91,0 @@ ```js |
@@ -8,15 +8,7 @@ #!/usr/bin/env node | ||
var compiler_cli_1 = require('@angular/compiler-cli'); | ||
var webpack_wrapper_1 = require('./webpack-wrapper'); | ||
var webpack_chain_module_resolution_host_adapter_1 = require('./webpack-chain-module-resolution-host-adapter'); | ||
function codeGenFactory(args, consoleError) { | ||
var webpackConfigPath = Path.join(process.cwd(), args.webpack || './webpack.config.js'); | ||
var config; | ||
try { | ||
config = require(webpackConfigPath); | ||
} | ||
catch (err) { | ||
consoleError("Invalid webpack configuration. Please set a valid --webpack argument.\n" + err.message); | ||
throw err; | ||
} | ||
function codeGenFactory(webpackWrapper) { | ||
return function (ngOptions, cliOptions, program, host) { | ||
var hostContext = new webpack_chain_module_resolution_host_adapter_1.WebpackChainModuleResolutionHostAdapter(host, config); | ||
var hostContext = new webpack_chain_module_resolution_host_adapter_1.WebpackChainModuleResolutionHostAdapter(host, webpackWrapper); | ||
return compiler_cli_1.CodeGenerator.create(ngOptions, cliOptions, program, host, hostContext).codegen(); | ||
@@ -29,5 +21,10 @@ }; | ||
var cliOptions = new tsc_wrapped_1.NgcCliOptions(args); | ||
return tsc_wrapped_1.main(project, cliOptions, codeGenFactory(args, consoleError)) | ||
var webpack = new webpack_wrapper_1.WebpackWrapper(Path.join(process.cwd(), args.webpack || './webpack.config.js')); | ||
return Promise.resolve() | ||
.then(function () { return webpack.init(); }) | ||
.then(function () { return tsc_wrapped_1.main(project, cliOptions, codeGenFactory(webpack)); }) | ||
.then(function () { return webpack.emitOnCompilationSuccess(); }) | ||
.then(function () { return 0; }) | ||
.catch(function (e) { | ||
webpack.emitOnCompilationError(e); | ||
if (e instanceof tsc_wrapped_1.UserError || e instanceof compiler_1.SyntaxError) { | ||
@@ -34,0 +31,0 @@ consoleError(e.message); |
@@ -0,4 +1,9 @@ | ||
/// <reference types="node" /> | ||
export declare type PathTransformer = (path: string) => string; | ||
export declare type OnCompilationSuccess = () => void; | ||
export declare type OnCompilationError = (err: Error) => void; | ||
export interface NgcWebpackPluginOptions { | ||
pathTransformer?: PathTransformer; | ||
onCompilationSuccess?: OnCompilationSuccess; | ||
onCompilationError?: OnCompilationError; | ||
} | ||
@@ -5,0 +10,0 @@ export declare class NgcWebpackPlugin { |
import { ModuleResolutionHost } from 'typescript'; | ||
import { ModuleResolutionHostAdapter } from '@angular/compiler-cli'; | ||
import { WebpackWrapper } from './webpack-wrapper'; | ||
export declare class WebpackChainModuleResolutionHostAdapter extends ModuleResolutionHostAdapter { | ||
compiler: any; | ||
webpackWrapper: WebpackWrapper; | ||
private _loader; | ||
private _pathTransformer; | ||
constructor(host: ModuleResolutionHost, webpackConfig: any); | ||
constructor(host: ModuleResolutionHost, webpackWrapper: WebpackWrapper); | ||
readResource(path: string): Promise<string>; | ||
} |
@@ -7,14 +7,11 @@ "use strict"; | ||
}; | ||
var webpack = require('webpack'); | ||
var compiler_cli_1 = require('@angular/compiler-cli'); | ||
var webpack_resource_loader_1 = require('./webpack-resource-loader'); | ||
var plugin_1 = require('./plugin'); | ||
var WebpackChainModuleResolutionHostAdapter = (function (_super) { | ||
__extends(WebpackChainModuleResolutionHostAdapter, _super); | ||
function WebpackChainModuleResolutionHostAdapter(host, webpackConfig) { | ||
function WebpackChainModuleResolutionHostAdapter(host, webpackWrapper) { | ||
_super.call(this, host); | ||
this.compiler = webpack(webpackConfig()); | ||
this._loader = new webpack_resource_loader_1.WebpackResourceLoader(this.compiler.createCompilation()); | ||
var plugin = this.compiler.options.plugins | ||
.filter(function (p) { return p instanceof plugin_1.NgcWebpackPlugin; })[0]; | ||
this.webpackWrapper = webpackWrapper; | ||
this._loader = new webpack_resource_loader_1.WebpackResourceLoader(this.webpackWrapper.compiler.createCompilation()); | ||
var plugin = this.webpackWrapper.plugin; | ||
if (plugin && typeof plugin.options.pathTransformer === 'function') { | ||
@@ -21,0 +18,0 @@ this._pathTransformer = plugin.options.pathTransformer; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
36655
20
273
125