@@ -6,7 +6,7 @@ import { readFile } from 'fs/promises'
6
6
import { delimiter , dirname } from 'path'
7
7
import { ZipFile } from 'yauzl'
8
8
import { InstallLibraryTask , InstallSideOption , LibraryOptions } from './minecraft'
9
- import { checksum , errorToString , SpawnJavaOptions , waitProcess } from './utils'
9
+ import { checksum , errorToString , missing , SpawnJavaOptions , waitProcess } from './utils'
10
10
11
11
export interface PostProcessor {
12
12
/**
@@ -82,13 +82,17 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
82
82
}
83
83
return val
84
84
}
85
- function normalizeVariable ( val : string ) {
86
- if ( val && val . match ( / ^ { .+ } $ / g) ) { // match sth like {MAPPINGS}
87
- const key = val . substring ( 1 , val . length - 1 )
88
- return variables [ key ] [ side ]
89
- }
90
- return val
85
+
86
+ const normalizeVariable = ( val : string ) => {
87
+ if ( ! val ) return val
88
+ // replace "{A}/{B}, which the value of A and B are from varaiables
89
+ // for example, variables = { A: "a", B: "b" }
90
+ // "{A}/{B}" => "a/b"
91
+ // The key variable name can be any alphabet characters and number other special characters
92
+ // Another example, "{A}" => "a"
93
+ return val . replace ( / { ( [ A - Z a - z 0 - 9 _ - ] + ) } / g, ( _ , key ) => variables [ key ] ?. [ side ] ?? '' )
91
94
}
95
+
92
96
// store the mapping of {VARIABLE_NAME} -> real path in disk
93
97
const variables : Record < string , { client : string ; server : string } > = {
94
98
SIDE : {
@@ -99,6 +103,18 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
99
103
client : minecraft . getVersionJar ( installProfile . minecraft ) ,
100
104
server : minecraft . getVersionJar ( installProfile . minecraft , 'server' ) ,
101
105
} ,
106
+ ROOT : {
107
+ client : minecraft . root ,
108
+ server : minecraft . root ,
109
+ } ,
110
+ MINECRAFT_VERSION : {
111
+ client : installProfile . minecraft ,
112
+ server : installProfile . minecraft ,
113
+ } ,
114
+ LIBRARY_DIR : {
115
+ client : minecraft . libraries ,
116
+ server : minecraft . libraries ,
117
+ } ,
102
118
}
103
119
if ( installProfile . data ) {
104
120
for ( const key in installProfile . data ) {
@@ -109,12 +125,6 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
109
125
}
110
126
}
111
127
}
112
- if ( variables . INSTALLER ) {
113
- variables . ROOT = {
114
- client : dirname ( variables . INSTALLER . client ) ,
115
- server : dirname ( variables . INSTALLER . server ) ,
116
- }
117
- }
118
128
119
129
const resolveOutputs = ( proc : PostProcessor , args : string [ ] ) => {
120
130
const original = proc . outputs
@@ -269,6 +279,9 @@ export class PostProcessingTask extends AbortableTask<void> {
269
279
270
280
protected async isInvalid ( outputs : Required < PostProcessor > [ 'outputs' ] ) {
271
281
for ( const [ file , expect ] of Object . entries ( outputs ) ) {
282
+ if ( ! expect ) {
283
+ return missing ( file )
284
+ }
272
285
const sha1 = await checksum ( file , 'sha1' ) . catch ( ( e ) => '' )
273
286
if ( ! sha1 ) return true // if file not exist, the file is not generated
274
287
if ( ! expect ) return false // if expect is empty, we just need file exists
0 commit comments