1
1
const chmodr = require ( 'chmodr' ) ;
2
2
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
3
3
const path = require ( 'node:path' ) ;
4
+ const fs = require ( 'node:fs/promises' ) ;
4
5
const resolvePackagePath = require ( 'resolve-package-path' ) ;
5
6
const webpack = require ( 'webpack' ) ;
6
7
const frontend = require ( './gen-webpack.config' ) ;
7
8
const backend = require ( './gen-webpack.node.config' ) ;
8
9
10
+ const isWindows = process . platform === 'win32' ;
11
+ const isMacOS = process . platform === 'darwin' ;
12
+
9
13
// https://github.com/browserify/node-util/issues/57#issuecomment-764436352
10
14
const mainWindowConfig = frontend [ 0 ] ;
11
15
mainWindowConfig . resolve . extensions . push ( '.ts' ) ;
@@ -37,7 +41,19 @@ class PermissionsPlugin {
37
41
*/
38
42
apply ( compiler ) {
39
43
compiler . hooks . afterEmit . tap ( 'PermissionsPlugin' , ( ) => {
40
- return new Promise ( ( resolve , reject ) => {
44
+ return new Promise ( async ( resolve , reject ) => {
45
+ let trashBinaryFilename = undefined ;
46
+ if ( isWindows ) {
47
+ trashBinaryFilename = 'windows-trash.exe' ;
48
+ } else if ( isMacOS ) {
49
+ trashBinaryFilename = 'macos-trash' ;
50
+ }
51
+ if ( trashBinaryFilename ) {
52
+ await fs . chmod (
53
+ path . join ( __dirname , 'lib' , 'backend' , trashBinaryFilename ) ,
54
+ 0o755
55
+ ) ;
56
+ }
41
57
chmodr (
42
58
path . join ( __dirname , 'lib' , 'backend' , 'resources' ) ,
43
59
0o755 ,
@@ -48,42 +64,64 @@ class PermissionsPlugin {
48
64
}
49
65
}
50
66
67
+ const trashBinariesPath = path . join (
68
+ resolvePackagePath ( 'trash' , __dirname ) ,
69
+ '..' ,
70
+ 'lib'
71
+ ) ;
72
+
73
+ const copyOptions = {
74
+ patterns : [
75
+ // binaries
76
+ {
77
+ from : path . join (
78
+ resolvePackagePath ( 'arduino-ide-extension' , __dirname ) ,
79
+ '..' ,
80
+ 'src' ,
81
+ 'node' ,
82
+ 'resources'
83
+ ) ,
84
+ to : path . resolve ( __dirname , 'lib' , 'backend' , 'resources' ) ,
85
+ globOptions : {
86
+ ignore : [ '**/i18n/**' ] ,
87
+ } ,
88
+ } ,
89
+ // plotter app
90
+ {
91
+ from : path . join (
92
+ resolvePackagePath ( 'arduino-serial-plotter-webapp' , __dirname ) ,
93
+ '..' ,
94
+ 'build'
95
+ ) ,
96
+ to : path . resolve (
97
+ __dirname ,
98
+ 'lib' ,
99
+ 'backend' ,
100
+ 'resources' ,
101
+ 'arduino-serial-plotter-webapp'
102
+ ) ,
103
+ } ,
104
+ ] ,
105
+ } ;
106
+
107
+ // workaround for https://github.com/eclipse-theia/theia/issues/12780
108
+ // copy the Windows (`windows-trash.exe`) and macOS (`macos-trash`) executables for `trash`
109
+ if ( isWindows ) {
110
+ copyOptions . patterns . push ( {
111
+ from : path . join ( trashBinariesPath , 'windows-trash.exe' ) ,
112
+ to : path . resolve ( __dirname , 'lib' , 'backend' ) ,
113
+ } ) ;
114
+ } else if ( isMacOS ) {
115
+ copyOptions . patterns . push ( {
116
+ from : path . join ( trashBinariesPath , 'macos-trash' ) ,
117
+ to : path . resolve ( __dirname , 'lib' , 'backend' ) ,
118
+ } ) ;
119
+ }
120
+
51
121
// Copy all the IDE2 binaries and the plotter web app.
52
122
// XXX: For whatever reason it is important to use `unshift` instead of `push`, and execute the additional webpack plugins before the Theia contributed ones kick in. Otherwise ours do not work.
53
123
backend . config . plugins . unshift (
54
- new CopyWebpackPlugin ( {
55
- patterns : [
56
- // binaries
57
- {
58
- from : path . join (
59
- resolvePackagePath ( 'arduino-ide-extension' , __dirname ) ,
60
- '..' ,
61
- 'src' ,
62
- 'node' ,
63
- 'resources'
64
- ) ,
65
- to : path . resolve ( __dirname , 'lib' , 'backend' , 'resources' ) ,
66
- globOptions : {
67
- ignore : [ '**/i18n/**' ] ,
68
- } ,
69
- } ,
70
- // plotter app
71
- {
72
- from : path . join (
73
- resolvePackagePath ( 'arduino-serial-plotter-webapp' , __dirname ) ,
74
- '..' ,
75
- 'build'
76
- ) ,
77
- to : path . resolve (
78
- __dirname ,
79
- 'lib' ,
80
- 'backend' ,
81
- 'resources' ,
82
- 'arduino-serial-plotter-webapp'
83
- ) ,
84
- } ,
85
- ] ,
86
- } ) ,
124
+ new CopyWebpackPlugin ( copyOptions ) ,
87
125
new PermissionsPlugin ( )
88
126
) ;
89
127
0 commit comments