@@ -123,17 +123,20 @@ export class NodejsFunction extends lambda.Function {
123
123
} ;
124
124
} , { } ) ;
125
125
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, '\\\\' ) ;
127
130
128
131
const webpackConfiguration = `
129
132
const { builtinModules } = require("module");
130
133
const { NormalModuleReplacementPlugin } = require("${
131
- nodeifyPath ( pluginsPaths [ "webpack" ] )
134
+ escapePathForNodeJs ( pluginsPaths [ "webpack" ] )
132
135
} ");
133
136
134
137
module.exports = {
135
138
mode: "none",
136
- entry: "${ nodeifyPath ( entryFullPath ) } ",
139
+ entry: "${ escapePathForNodeJs ( entryFullPath ) } ",
137
140
target: "node",
138
141
resolve: {
139
142
modules: ["node_modules", "."],
@@ -146,12 +149,12 @@ export class NodejsFunction extends lambda.Function {
146
149
test: /\\.js$/,
147
150
exclude: /node_modules/,
148
151
use: {
149
- loader: "${ nodeifyPath ( pluginsPaths [ "babel-loader" ] ) } ",
152
+ loader: "${ escapePathForNodeJs ( pluginsPaths [ "babel-loader" ] ) } ",
150
153
options: {
151
154
cacheDirectory: true,
152
155
presets: [
153
156
[
154
- "${ nodeifyPath ( pluginsPaths [ "@babel/preset-env" ] ) } ",
157
+ "${ escapePathForNodeJs ( pluginsPaths [ "@babel/preset-env" ] ) } ",
155
158
{
156
159
"targets": {
157
160
"node": "${
@@ -164,8 +167,8 @@ export class NodejsFunction extends lambda.Function {
164
167
]
165
168
],
166
169
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" ] ) } "
169
172
]
170
173
}
171
174
}
@@ -180,15 +183,15 @@ export class NodejsFunction extends lambda.Function {
180
183
externals: [...builtinModules, "aws-sdk"],
181
184
output: {
182
185
filename: "[name].js",
183
- path: "${ nodeifyPath ( outputDir ) } ",
186
+ path: "${ escapePathForNodeJs ( outputDir ) } ",
184
187
libraryTarget: "commonjs2",
185
188
},
186
189
${ ( props . modulesToIgnore &&
187
190
`
188
191
plugins: [
189
192
new NormalModuleReplacementPlugin(
190
- /${ nodeifyPath ( props . modulesToIgnore . join ( "|" ) ) } /,
191
- "${ nodeifyPath ( pluginsPaths [ "noop2" ] ) } ",
193
+ /${ escapePathForNodeJs ( props . modulesToIgnore . join ( "|" ) ) } /,
194
+ "${ escapePathForNodeJs ( pluginsPaths [ "noop2" ] ) } ",
192
195
),
193
196
]
194
197
` ) ||
0 commit comments