@@ -33,6 +33,9 @@ const CLIENT_DIR = 'client';
33
33
const EXPORT_PREFIX = `./${ API_DIR } /` ;
34
34
const TYPE_PREFIX = `${ API_DIR } /` ;
35
35
36
+ const toPosixPath = ( p : string ) => p . replace ( / \\ / g, '/' ) ;
37
+ const posixJoin = ( ...args : string [ ] ) => toPosixPath ( path . join ( ...args ) ) ;
38
+
36
39
export async function readDirectoryFiles (
37
40
appDirectory : string ,
38
41
directory : string ,
@@ -55,7 +58,7 @@ export async function readDirectoryFiles(
55
58
const relativePath = path . relative ( directory , resourcePath ) ;
56
59
const parsedPath = path . parse ( relativePath ) ;
57
60
58
- const targetDir = path . join (
61
+ const targetDir = posixJoin (
59
62
`./${ relativeDistPath } /${ CLIENT_DIR } ` ,
60
63
parsedPath . dir ,
61
64
`${ parsedPath . name } .js` ,
@@ -66,13 +69,13 @@ export async function readDirectoryFiles(
66
69
appDirectory ,
67
70
currentPath ,
68
71
) ;
69
- const typesFilePath = path . join (
72
+ const typesFilePath = posixJoin (
70
73
`./${ relativeDistPath } ` ,
71
74
relativePathFromAppDirectory ,
72
75
`${ name } .d.ts` ,
73
76
) ;
74
77
const relativeTargetDistDir = `./${ typesFilePath } ` ;
75
- const exportKey = path . join ( parsedPath . dir , name ) ;
78
+ const exportKey = toPosixPath ( path . join ( parsedPath . dir , name ) ) ;
76
79
77
80
filesList . push ( {
78
81
resourcePath,
@@ -136,48 +139,55 @@ async function setPackage(
136
139
const packageJson = JSON . parse ( packageContent ) ;
137
140
138
141
const addFiles = [
139
- ` ${ relativeDistPath } / ${ CLIENT_DIR } /**/*` ,
140
- ` ${ relativeDistPath } / ${ RUNTIME_DIR } /**/*` ,
141
- ` ${ relativeDistPath } / ${ PLUGIN_DIR } /**/*` ,
142
+ posixJoin ( relativeDistPath , CLIENT_DIR , '**' , '*' ) ,
143
+ posixJoin ( relativeDistPath , RUNTIME_DIR , '**' , '*' ) ,
144
+ posixJoin ( relativeDistPath , PLUGIN_DIR , '**' , '*' ) ,
142
145
] ;
143
146
144
147
const typesVersions = {
145
148
'*' : files . reduce (
146
149
( acc , file ) => {
147
- const typeFilePath = `./${ file . targetDir } ` . replace ( 'js' , 'd.ts' ) ;
150
+ const typeFilePath = toPosixPath ( `./${ file . targetDir } ` ) . replace (
151
+ 'js' ,
152
+ 'd.ts' ,
153
+ ) ;
148
154
return {
149
155
...acc ,
150
- [ `${ TYPE_PREFIX } ${ file . exportKey } ` ] : [ typeFilePath ] ,
156
+ [ toPosixPath ( `${ TYPE_PREFIX } ${ file . exportKey } ` ) ] : [ typeFilePath ] ,
151
157
} ;
152
158
} ,
153
159
{
154
- [ RUNTIME_DIR ] : [ `./${ relativeDistPath } /${ RUNTIME_DIR } /index.d.ts` ] ,
155
- [ PLUGIN_DIR ] : [ `./${ relativeDistPath } /${ PLUGIN_DIR } /index.d.ts` ] ,
160
+ [ RUNTIME_DIR ] : [
161
+ toPosixPath ( `./${ relativeDistPath } /${ RUNTIME_DIR } /index.d.ts` ) ,
162
+ ] ,
163
+ [ PLUGIN_DIR ] : [
164
+ toPosixPath ( `./${ relativeDistPath } /${ PLUGIN_DIR } /index.d.ts` ) ,
165
+ ] ,
156
166
} ,
157
167
) ,
158
168
} ;
159
169
160
170
const exports = files . reduce (
161
171
( acc , file ) => {
162
172
const exportKey = `${ EXPORT_PREFIX } ${ file . exportKey } ` ;
163
- const jsFilePath = `./${ file . targetDir } ` ;
173
+ const jsFilePath = toPosixPath ( `./${ file . targetDir } ` ) ;
164
174
165
175
return {
166
176
...acc ,
167
- [ exportKey ] : {
177
+ [ toPosixPath ( exportKey ) ] : {
168
178
import : jsFilePath ,
169
- types : jsFilePath . replace ( / \. j s $ / , '.d.ts' ) ,
179
+ types : toPosixPath ( jsFilePath . replace ( / \. j s $ / , '.d.ts' ) ) ,
170
180
} ,
171
181
} ;
172
182
} ,
173
183
{
174
- [ `./${ PLUGIN_DIR } ` ] : {
175
- require : `./${ relativeDistPath } /${ PLUGIN_DIR } /index.js` ,
176
- types : `./${ relativeDistPath } /${ PLUGIN_DIR } /index.d.ts` ,
184
+ [ toPosixPath ( `./${ PLUGIN_DIR } ` ) ] : {
185
+ require : toPosixPath ( `./${ relativeDistPath } /${ PLUGIN_DIR } /index.js` ) ,
186
+ types : toPosixPath ( `./${ relativeDistPath } /${ PLUGIN_DIR } /index.d.ts` ) ,
177
187
} ,
178
- [ `./${ RUNTIME_DIR } ` ] : {
179
- import : `./${ relativeDistPath } /${ RUNTIME_DIR } /index.js` ,
180
- types : `./${ relativeDistPath } /${ RUNTIME_DIR } /index.d.ts` ,
188
+ [ toPosixPath ( `./${ RUNTIME_DIR } ` ) ] : {
189
+ import : toPosixPath ( `./${ relativeDistPath } /${ RUNTIME_DIR } /index.js` ) ,
190
+ types : toPosixPath ( `./${ relativeDistPath } /${ RUNTIME_DIR } /index.d.ts` ) ,
181
191
} ,
182
192
} ,
183
193
) ;
@@ -195,7 +205,7 @@ async function setPackage(
195
205
196
206
export async function copyFiles ( from : string , to : string ) {
197
207
if ( await fs . pathExists ( from ) ) {
198
- await fs . copy ( from , to ) ;
208
+ await fs . copy ( toPosixPath ( from ) , toPosixPath ( to ) ) ;
199
209
}
200
210
}
201
211
0 commit comments