@@ -2,7 +2,7 @@ import * as fs from "fs";
22import * as path from "path" ;
33import * as os from "os" ;
44import * as process from "process" ;
5- import { spawnSync } from "child_process " ;
5+ import * as spawn from "cross-spawn " ;
66import findUp from "find-up" ;
77
88import * as lambda from "@aws-cdk/aws-lambda" ;
@@ -123,15 +123,17 @@ export class NodejsFunction extends lambda.Function {
123123 } ;
124124 } , { } ) ;
125125
126+ const nodeifyPath = ( path : string ) => path . replace ( / \\ / g, '\\\\' ) ;
127+
126128 const webpackConfiguration = `
127129 const { builtinModules } = require("module");
128130 const { NormalModuleReplacementPlugin } = require("${
129- pluginsPaths [ "webpack" ]
131+ nodeifyPath ( pluginsPaths [ "webpack" ] )
130132 } ");
131133
132134 module.exports = {
133135 mode: "none",
134- entry: "${ entryFullPath } ",
136+ entry: "${ nodeifyPath ( entryFullPath ) } ",
135137 target: "node",
136138 resolve: {
137139 modules: ["node_modules", "."],
@@ -144,12 +146,12 @@ export class NodejsFunction extends lambda.Function {
144146 test: /\\.js$/,
145147 exclude: /node_modules/,
146148 use: {
147- loader: "${ pluginsPaths [ "babel-loader" ] } ",
149+ loader: "${ nodeifyPath ( pluginsPaths [ "babel-loader" ] ) } ",
148150 options: {
149151 cacheDirectory: true,
150152 presets: [
151153 [
152- "${ pluginsPaths [ "@babel/preset-env" ] } ",
154+ "${ nodeifyPath ( pluginsPaths [ "@babel/preset-env" ] ) } ",
153155 {
154156 "targets": {
155157 "node": "${
@@ -162,8 +164,8 @@ export class NodejsFunction extends lambda.Function {
162164 ]
163165 ],
164166 plugins: [
165- "${ pluginsPaths [ "@babel/plugin-transform-runtime" ] } ",
166- "${ pluginsPaths [ "babel-plugin-source-map-support" ] } "
167+ "${ nodeifyPath ( pluginsPaths [ "@babel/plugin-transform-runtime" ] ) } ",
168+ "${ nodeifyPath ( pluginsPaths [ "babel-plugin-source-map-support" ] ) } "
167169 ]
168170 }
169171 }
@@ -178,15 +180,15 @@ export class NodejsFunction extends lambda.Function {
178180 externals: [...builtinModules, "aws-sdk"],
179181 output: {
180182 filename: "[name].js",
181- path: "${ outputDir } ",
183+ path: "${ nodeifyPath ( outputDir ) } ",
182184 libraryTarget: "commonjs2",
183185 },
184186 ${ ( props . modulesToIgnore &&
185187 `
186188 plugins: [
187189 new NormalModuleReplacementPlugin(
188- /${ props . modulesToIgnore . join ( "|" ) } /,
189- "${ pluginsPaths [ "noop2" ] } ",
190+ /${ nodeifyPath ( props . modulesToIgnore . join ( "|" ) ) } /,
191+ "${ nodeifyPath ( pluginsPaths [ "noop2" ] ) } ",
190192 ),
191193 ]
192194 ` ) ||
@@ -196,12 +198,12 @@ export class NodejsFunction extends lambda.Function {
196198 fs . writeFileSync ( webpackConfigPath , webpackConfiguration ) ;
197199
198200 // to implement cache, create a script that uses webpack API, store cache in a file with JSON.stringify, based on entry path key then reuse it
199- const webpack = spawnSync ( webpackBinPath , [ "--config" , webpackConfigPath ] , {
201+ const webpack = spawn . sync ( webpackBinPath , [ "--config" , webpackConfigPath ] , {
200202 cwd : process . cwd ( ) ,
201203 } ) ;
202204
203205 if ( webpack . status !== 0 ) {
204- console . error ( " webpack had an error when bundling." ) ;
206+ console . error ( ` webpack had an error when bundling. Return status was ${ webpack . status } ` ) ;
205207 console . error (
206208 webpack ?. output ?. map ( out => {
207209 return out ?. toString ( ) ;
0 commit comments