@@ -2,7 +2,7 @@ import * as fs from "fs";
2
2
import * as path from "path" ;
3
3
import * as os from "os" ;
4
4
import * as process from "process" ;
5
- import { spawnSync } from "child_process " ;
5
+ import * as spawn from "cross-spawn " ;
6
6
import findUp from "find-up" ;
7
7
8
8
import * as lambda from "@aws-cdk/aws-lambda" ;
@@ -123,15 +123,17 @@ export class NodejsFunction extends lambda.Function {
123
123
} ;
124
124
} , { } ) ;
125
125
126
+ const nodeifyPath = ( path : string ) => path . replace ( / \\ / g, '\\\\' ) ;
127
+
126
128
const webpackConfiguration = `
127
129
const { builtinModules } = require("module");
128
130
const { NormalModuleReplacementPlugin } = require("${
129
- pluginsPaths [ "webpack" ]
131
+ nodeifyPath ( pluginsPaths [ "webpack" ] )
130
132
} ");
131
133
132
134
module.exports = {
133
135
mode: "none",
134
- entry: "${ entryFullPath } ",
136
+ entry: "${ nodeifyPath ( entryFullPath ) } ",
135
137
target: "node",
136
138
resolve: {
137
139
modules: ["node_modules", "."],
@@ -144,12 +146,12 @@ export class NodejsFunction extends lambda.Function {
144
146
test: /\\.js$/,
145
147
exclude: /node_modules/,
146
148
use: {
147
- loader: "${ pluginsPaths [ "babel-loader" ] } ",
149
+ loader: "${ nodeifyPath ( pluginsPaths [ "babel-loader" ] ) } ",
148
150
options: {
149
151
cacheDirectory: true,
150
152
presets: [
151
153
[
152
- "${ pluginsPaths [ "@babel/preset-env" ] } ",
154
+ "${ nodeifyPath ( pluginsPaths [ "@babel/preset-env" ] ) } ",
153
155
{
154
156
"targets": {
155
157
"node": "${
@@ -162,8 +164,8 @@ export class NodejsFunction extends lambda.Function {
162
164
]
163
165
],
164
166
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" ] ) } "
167
169
]
168
170
}
169
171
}
@@ -178,15 +180,15 @@ export class NodejsFunction extends lambda.Function {
178
180
externals: [...builtinModules, "aws-sdk"],
179
181
output: {
180
182
filename: "[name].js",
181
- path: "${ outputDir } ",
183
+ path: "${ nodeifyPath ( outputDir ) } ",
182
184
libraryTarget: "commonjs2",
183
185
},
184
186
${ ( props . modulesToIgnore &&
185
187
`
186
188
plugins: [
187
189
new NormalModuleReplacementPlugin(
188
- /${ props . modulesToIgnore . join ( "|" ) } /,
189
- "${ pluginsPaths [ "noop2" ] } ",
190
+ /${ nodeifyPath ( props . modulesToIgnore . join ( "|" ) ) } /,
191
+ "${ nodeifyPath ( pluginsPaths [ "noop2" ] ) } ",
190
192
),
191
193
]
192
194
` ) ||
@@ -196,12 +198,12 @@ export class NodejsFunction extends lambda.Function {
196
198
fs . writeFileSync ( webpackConfigPath , webpackConfiguration ) ;
197
199
198
200
// 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 ] , {
200
202
cwd : process . cwd ( ) ,
201
203
} ) ;
202
204
203
205
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 } ` ) ;
205
207
console . error (
206
208
webpack ?. output ?. map ( out => {
207
209
return out ?. toString ( ) ;
0 commit comments