@@ -123,17 +123,20 @@ export class NodejsFunction extends lambda.Function {
123123 } ;
124124 } , { } ) ;
125125
126- const nodeifyPath = ( path : string ) => path . replace ( / \\ / g, '\\\\' ) ;
126+ // NodeJs reserves '\' as an escape char; but pluginsPaths etc are inlined directly in the
127+ // TemplateString below, so will contain this escape character on paths computed when running
128+ // the Construct on a Windows machine, and so we need to escape these chars before writing them
129+ const escapePathForNodeJs = ( path : string ) => path . replace ( / \\ / g, '\\\\' ) ;
127130
128131 const webpackConfiguration = `
129132 const { builtinModules } = require("module");
130133 const { NormalModuleReplacementPlugin } = require("${
131- nodeifyPath ( pluginsPaths [ "webpack" ] )
134+ escapePathForNodeJs ( pluginsPaths [ "webpack" ] )
132135 } ");
133136
134137 module.exports = {
135138 mode: "none",
136- entry: "${ nodeifyPath ( entryFullPath ) } ",
139+ entry: "${ escapePathForNodeJs ( entryFullPath ) } ",
137140 target: "node",
138141 resolve: {
139142 modules: ["node_modules", "."],
@@ -146,12 +149,12 @@ export class NodejsFunction extends lambda.Function {
146149 test: /\\.js$/,
147150 exclude: /node_modules/,
148151 use: {
149- loader: "${ nodeifyPath ( pluginsPaths [ "babel-loader" ] ) } ",
152+ loader: "${ escapePathForNodeJs ( pluginsPaths [ "babel-loader" ] ) } ",
150153 options: {
151154 cacheDirectory: true,
152155 presets: [
153156 [
154- "${ nodeifyPath ( pluginsPaths [ "@babel/preset-env" ] ) } ",
157+ "${ escapePathForNodeJs ( pluginsPaths [ "@babel/preset-env" ] ) } ",
155158 {
156159 "targets": {
157160 "node": "${
@@ -164,8 +167,8 @@ export class NodejsFunction extends lambda.Function {
164167 ]
165168 ],
166169 plugins: [
167- "${ nodeifyPath ( pluginsPaths [ "@babel/plugin-transform-runtime" ] ) } ",
168- "${ nodeifyPath ( pluginsPaths [ "babel-plugin-source-map-support" ] ) } "
170+ "${ escapePathForNodeJs ( pluginsPaths [ "@babel/plugin-transform-runtime" ] ) } ",
171+ "${ escapePathForNodeJs ( pluginsPaths [ "babel-plugin-source-map-support" ] ) } "
169172 ]
170173 }
171174 }
@@ -180,15 +183,15 @@ export class NodejsFunction extends lambda.Function {
180183 externals: [...builtinModules, "aws-sdk"],
181184 output: {
182185 filename: "[name].js",
183- path: "${ nodeifyPath ( outputDir ) } ",
186+ path: "${ escapePathForNodeJs ( outputDir ) } ",
184187 libraryTarget: "commonjs2",
185188 },
186189 ${ ( props . modulesToIgnore &&
187190 `
188191 plugins: [
189192 new NormalModuleReplacementPlugin(
190- /${ nodeifyPath ( props . modulesToIgnore . join ( "|" ) ) } /,
191- "${ nodeifyPath ( pluginsPaths [ "noop2" ] ) } ",
193+ /${ escapePathForNodeJs ( props . modulesToIgnore . join ( "|" ) ) } /,
194+ "${ escapePathForNodeJs ( pluginsPaths [ "noop2" ] ) } ",
192195 ),
193196 ]
194197 ` ) ||
0 commit comments