@team-supercharge/oasg 17.1.0 → 18.0.0-temp-chore-fix-tanstack-query-version.2eaaff54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +260 -47
  2. package/bin/oasg +23 -4
  3. package/bin/save-lock.js +101 -0
  4. package/bin/target-version.js +84 -0
  5. package/config.schema.yml +15 -0
  6. package/package.json +1 -1
  7. package/targets/android/generate.sh +2 -2
  8. package/targets/android/generator-config.json +2 -1
  9. package/targets/android/publish.sh +1 -1
  10. package/targets/android/templates/build.gradle.mustache +63 -46
  11. package/targets/angular/generate.sh +35 -9
  12. package/targets/angular/publish.sh +1 -1
  13. package/targets/apple-swift/generate.sh +1 -1
  14. package/targets/apple-swift/publish.sh +1 -1
  15. package/targets/common.sh +3 -1
  16. package/targets/contract-testing/generate.sh +1 -1
  17. package/targets/contract-testing/publish.sh +1 -1
  18. package/targets/dependency-lock-utils.sh +290 -0
  19. package/targets/feign/generate.sh +1 -1
  20. package/targets/feign/publish.sh +1 -1
  21. package/targets/feign-kotlin/generate.sh +1 -1
  22. package/targets/feign-kotlin/publish.sh +1 -1
  23. package/targets/flutter/generate.sh +1 -1
  24. package/targets/flutter/publish.sh +1 -1
  25. package/targets/ios/generate.sh +1 -1
  26. package/targets/ios/publish.sh +1 -1
  27. package/targets/kmp/generate.sh +1 -1
  28. package/targets/kmp/publish.sh +1 -1
  29. package/targets/kmp/templates/build.gradle.kts.mustache +17 -13
  30. package/targets/kmp/templates/libraries/multiplatform/api.mustache +2 -0
  31. package/targets/msw/generate.sh +25 -0
  32. package/targets/msw/generator-config.json +28 -0
  33. package/targets/msw/templates/apis.index.mustache +9 -0
  34. package/targets/msw/templates/apis.mustache +178 -0
  35. package/targets/msw/templates/config.mustache +23 -0
  36. package/targets/msw/templates/index.mustache +11 -0
  37. package/targets/msw/templates/modelEnum.mustache +1 -0
  38. package/targets/msw/templates/modelGeneric.mustache +7 -0
  39. package/targets/msw/templates/package.mustache +35 -0
  40. package/targets/msw/templates/prettierrc.mustache +6 -0
  41. package/targets/msw/templates/tsconfig.mustache +18 -0
  42. package/targets/msw/templates/utils.mustache +15 -0
  43. package/targets/nestjs/generate.sh +36 -4
  44. package/targets/nestjs/publish.sh +1 -1
  45. package/targets/nestjs/templates/api.service.mustache +8 -14
  46. package/targets/plain-java/generate.sh +1 -1
  47. package/targets/plain-java/publish.sh +1 -1
  48. package/targets/python/generate.sh +1 -1
  49. package/targets/python/publish.sh +1 -1
  50. package/targets/python-fastapi/generate.sh +1 -1
  51. package/targets/python-fastapi/publish.sh +1 -1
  52. package/targets/python-fastapi-raw-request/generate.sh +1 -1
  53. package/targets/python-fastapi-raw-request/publish.sh +1 -1
  54. package/targets/python-legacy/generate.sh +1 -1
  55. package/targets/python-legacy/publish.sh +1 -1
  56. package/targets/react/generate.sh +17 -5
  57. package/targets/react/publish.sh +1 -1
  58. package/targets/react/templates/hook.mustache +172 -51
  59. package/targets/react/templates/package.mustache +1 -1
  60. package/targets/react/templates/use-api.hook.mustache +2 -0
  61. package/targets/spring/generate.sh +1 -1
  62. package/targets/spring/publish.sh +1 -1
  63. package/targets/spring-kotlin/generate.sh +1 -1
  64. package/targets/spring-kotlin/publish.sh +1 -1
  65. package/targets/stubby/generate.sh +1 -1
  66. package/targets/stubby/publish.sh +1 -1
  67. package/targets/typescript-axios/generate.sh +16 -5
  68. package/targets/typescript-axios/publish.sh +1 -1
  69. package/targets/typescript-fetch/generate.sh +17 -5
  70. package/targets/typescript-fetch/publish.sh +1 -1
  71. package/targets/android/templates/libraries/jvm-retrofit2/api.mustache +0 -157
  72. package/targets/android/templates/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +0 -354
@@ -3,8 +3,9 @@
3
3
  "enumPropertyNaming": "original",
4
4
  "dateLibrary": "java8-localdatetime",
5
5
  "useCoroutines": true,
6
- "moshiCodeGen": true,
6
+ "serializationLibrary": "kotlinx_serialization",
7
7
  "omitGradleWrapper": false,
8
+ "useResponseAsReturnType": false,
8
9
  "inlineSchemaOptions": {
9
10
  "ARRAY_ITEM_SUFFIX": "",
10
11
  "MAP_ITEM_SUFFIX": "",
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -3,41 +3,34 @@ version '{{artifactVersion}}'
3
3
  {{^omitGradleWrapper}}
4
4
 
5
5
  wrapper {
6
- gradleVersion = '7.5'
6
+ gradleVersion = '8.14.3'
7
7
  distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
8
8
  }
9
9
  {{/omitGradleWrapper}}
10
10
 
11
11
  buildscript {
12
- ext.kotlin_version = '1.8.10'
12
+ ext.kotlin_version = '2.2.20'
13
13
  {{#jvm-ktor}}
14
- ext.ktor_version = '2.1.3'
14
+ ext.ktor_version = '3.2.3'
15
15
  {{/jvm-ktor}}
16
16
  {{#jvm-retrofit2}}
17
- ext.retrofitVersion = '2.9.0'
17
+ ext.retrofitVersion = '3.0.0'
18
18
  {{/jvm-retrofit2}}
19
- {{#useRxJava}}
20
- ext.rxJavaVersion = '1.3.8'
21
- {{/useRxJava}}
22
- {{#useRxJava2}}
23
- ext.rxJava2Version = '2.2.21'
24
- {{/useRxJava2}}
25
19
  {{#useRxJava3}}
26
- ext.rxJava3Version = '3.0.12'
20
+ ext.rxJava3Version = '3.1.11'
27
21
  {{/useRxJava3}}
28
22
  {{#jvm-vertx}}
29
- ext.vertx_version = "4.3.3"
23
+ ext.vertx_version = "5.0.4"
30
24
  {{/jvm-vertx}}
31
- {{#jvm-spring-webclient}}
25
+ {{#jvm-spring}}
32
26
  {{#useSpringBoot3}}
33
- ext.spring_boot_version = "3.1.0"
27
+ ext.spring_boot_version = "3.5.5"
34
28
  {{/useSpringBoot3}}
35
29
  {{^useSpringBoot3}}
36
- ext.spring_boot_version = "2.7.12"
30
+ ext.spring_boot_version = "2.7.18"
37
31
  {{/useSpringBoot3}}
38
- ext.reactor_version = "3.5.6"
39
- {{/jvm-spring-webclient}}
40
- ext.spotless_version = "6.13.0"
32
+ {{/jvm-spring}}
33
+ ext.spotless_version = "7.2.1"
41
34
 
42
35
  repositories {
43
36
  maven { url "https://repo1.maven.org/maven2" }
@@ -48,12 +41,15 @@ buildscript {
48
41
  classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
49
42
  {{/kotlinx_serialization}}
50
43
  classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version"
44
+ {{#moshiCodeGen}}
45
+ classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:2.2.20-2.0.3"
46
+ {{/moshiCodeGen}}
51
47
  }
52
48
  }
53
49
 
54
50
  apply plugin: 'kotlin'
55
51
  {{#moshiCodeGen}}
56
- apply plugin: 'kotlin-kapt'
52
+ apply plugin: 'com.google.devtools.ksp'
57
53
  {{/moshiCodeGen}}
58
54
  {{#parcelizeModels}}
59
55
  apply plugin: 'kotlin-parcelize'
@@ -106,6 +102,11 @@ idea {
106
102
  }
107
103
  }
108
104
  {{/idea}}
105
+ {{#explicitApi}}
106
+ kotlin {
107
+ explicitApi()
108
+ }
109
+ {{/explicitApi}}
109
110
  {{#jvm-spring-webclient}}{{#useSpringBoot3}}
110
111
  kotlin {
111
112
  jvmToolchain {
@@ -113,35 +114,53 @@ kotlin {
113
114
  }
114
115
  }
115
116
  {{/useSpringBoot3}}{{/jvm-spring-webclient}}
117
+ {{#jvm-spring-restclient}}
118
+ kotlin {
119
+ jvmToolchain {
120
+ languageVersion.set(JavaLanguageVersion.of(17))
121
+ }
122
+ }
123
+ {{/jvm-spring-restclient}}
124
+ {{#kotlinx-datetime}}
125
+ kotlin {
126
+ sourceSets {
127
+ all {
128
+ languageSettings {
129
+ optIn("kotlin.time.ExperimentalTime")
130
+ }
131
+ }
132
+ }
133
+ }
134
+ {{/kotlinx-datetime}}
116
135
  dependencies {
117
136
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
118
137
  {{^doNotUseRxAndCoroutines}}
119
138
  {{#useCoroutines}}
120
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
139
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2"
121
140
  {{/useCoroutines}}
122
141
  {{/doNotUseRxAndCoroutines}}
123
142
  {{#moshi}}
124
143
  {{^moshiCodeGen}}
125
144
  implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
126
- implementation "com.squareup.moshi:moshi-kotlin:1.14.0"
127
- implementation "com.squareup.moshi:moshi-adapters:1.14.0"
145
+ implementation "com.squareup.moshi:moshi-kotlin:1.15.2"
146
+ implementation "com.squareup.moshi:moshi-adapters:1.15.2"
128
147
  {{/moshiCodeGen}}
129
148
  {{#moshiCodeGen}}
130
- implementation "com.squareup.moshi:moshi:1.14.0"
131
- implementation "com.squareup.moshi:moshi-adapters:1.14.0"
132
- kapt "com.squareup.moshi:moshi-kotlin-codegen:1.14.0"
149
+ implementation "com.squareup.moshi:moshi:1.15.2"
150
+ implementation "com.squareup.moshi:moshi-adapters:1.15.2"
151
+ ksp "com.squareup.moshi:moshi-kotlin-codegen:1.15.2"
133
152
  {{/moshiCodeGen}}
134
153
  {{/moshi}}
135
154
  {{#gson}}
136
- implementation "com.google.code.gson:gson:2.9.0"
155
+ implementation "com.google.code.gson:gson:2.13.2"
137
156
  {{/gson}}
138
157
  {{#jackson}}
139
158
  implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
140
- implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.14.3"
141
- implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.3"
159
+ implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.20.0"
160
+ implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.20.0"
142
161
  {{/jackson}}
143
162
  {{#kotlinx_serialization}}
144
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
163
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0"
145
164
  {{/kotlinx_serialization}}
146
165
  {{#jvm-ktor}}
147
166
  implementation "io.ktor:ktor-client-core:$ktor_version"
@@ -155,35 +174,30 @@ dependencies {
155
174
  implementation "io.ktor:ktor-serialization-jackson:$ktor_version"
156
175
  {{/jackson}}
157
176
  {{/jvm-ktor}}
158
- {{#jvm-okhttp3}}
159
- implementation "com.squareup.okhttp3:okhttp:3.12.13"
160
- {{/jvm-okhttp3}}
161
177
  {{#jvm-okhttp4}}
162
- implementation "com.squareup.okhttp3:okhttp:4.11.0"
178
+ implementation "com.squareup.okhttp3:okhttp:5.1.0"
163
179
  {{/jvm-okhttp4}}
164
180
  {{#jvm-spring-webclient}}
165
181
  implementation "org.springframework.boot:spring-boot-starter-webflux:$spring_boot_version"
166
- implementation "io.projectreactor:reactor-core:$reactor_version"
182
+ implementation "io.projectreactor:reactor-core:3.7.11"
167
183
  {{/jvm-spring-webclient}}
184
+ {{#jvm-spring-restclient}}
185
+ implementation "org.springframework.boot:spring-boot-starter-web:$spring_boot_version"
186
+ {{/jvm-spring-restclient}}
168
187
  {{#threetenbp}}
169
- implementation "org.threeten:threetenbp:1.6.8"
188
+ implementation "org.threeten:threetenbp:1.7.2"
170
189
  {{/threetenbp}}
190
+ {{#kotlinx-datetime}}
191
+ implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.7.1"
192
+ {{/kotlinx-datetime}}
171
193
  {{#jvm-retrofit2}}
172
194
  {{#hasOAuthMethods}}
173
195
  implementation "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.2"
174
196
  {{/hasOAuthMethods}}
175
- implementation "com.squareup.okhttp3:logging-interceptor:4.10.0"
176
- {{#useRxJava}}
177
- implementation "io.reactivex:rxjava:$rxJavaVersion"
178
- implementation "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion"
179
- {{/useRxJava}}
180
- {{#useRxJava2}}
181
- implementation "io.reactivex.rxjava2:rxjava:$rxJava2Version"
182
- implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
183
- {{/useRxJava2}}
197
+ implementation "com.squareup.okhttp3:logging-interceptor:5.1.0"
184
198
  {{#useRxJava3}}
185
199
  implementation "io.reactivex.rxjava3:rxjava:$rxJava3Version"
186
- implementation "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
200
+ implementation "com.squareup.retrofit2:adapter-rxjava3:$retrofitVersion"
187
201
  {{/useRxJava3}}
188
202
  implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
189
203
  {{#gson}}
@@ -193,8 +207,11 @@ dependencies {
193
207
  implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion"
194
208
  {{/moshi}}
195
209
  {{#kotlinx_serialization}}
196
- implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
210
+ implementation "com.squareup.retrofit2:converter-kotlinx-serialization:$retrofitVersion"
197
211
  {{/kotlinx_serialization}}
212
+ {{#jackson}}
213
+ implementation "com.squareup.retrofit2:converter-jackson:$retrofitVersion"
214
+ {{/jackson}}
198
215
  implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion"
199
216
  {{/jvm-retrofit2}}
200
217
  testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
@@ -1,6 +1,7 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
+ source $(dirname "$0")/../dependency-lock-utils.sh
4
5
 
5
6
  rm -rf out/$targetId
6
7
  mkdir -p out/$targetId
@@ -13,11 +14,36 @@ java -jar $binary generate \
13
14
  -c $(dirname "$0")/generator-config.json \
14
15
  -p "npmVersion=$version,npmName=$packageName,npmRepository=$repository" $generatorCustomArgs
15
16
 
16
- cd out/$targetId
17
- npm install
18
- # This is a workaround for an issue with the angular generator. Root cause is the missing package-lock.json: https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript-angular
19
- # some of the transitive dependency has @types/node@": "*" in their package.json
20
- # use "npm explain @types/node" in the generated folder (./out/$TARGET) to get more info
21
- npm install --save-dev @types/node@20.17.0
22
- npm run build
23
- cd ../..
17
+ # Extract framework version for dependency locking
18
+ # Priority: 1. generatorCustomArgs override, 2. generator-config.json default
19
+ framework_version=""
20
+
21
+ # First, check if ngVersion is overridden in generatorCustomArgs
22
+ if [ -n "$generatorCustomArgs" ]; then
23
+ # Match patterns: -p ngVersion=X.X.X or -pngVersion=X.X.X
24
+ if [[ "$generatorCustomArgs" =~ -p[[:space:]]*ngVersion=([0-9]+\.[0-9]+\.[0-9]+) ]]; then
25
+ framework_version="${BASH_REMATCH[1]}"
26
+ echo "Using ngVersion from generatorCustomArgs: $framework_version"
27
+ fi
28
+ fi
29
+
30
+ # Fall back to generator-config.json if not found in generatorCustomArgs
31
+ if [ -z "$framework_version" ] && command -v jq &> /dev/null; then
32
+ framework_version=$(jq -r '.ngVersion // empty' $(dirname "$0")/generator-config.json 2>/dev/null)
33
+ if [ -n "$framework_version" ]; then
34
+ echo "Using ngVersion from generator-config.json: $framework_version"
35
+ fi
36
+ fi
37
+
38
+ # Use dependency locking mechanism for build
39
+ echo "Building Angular target with dependency locking support..."
40
+
41
+ install_cmd="npm install"
42
+ build_cmd="npm run build"
43
+
44
+ if build_with_dependency_locking "$targetId" "$framework_version" "out/$targetId" "$install_cmd" "$build_cmd" "$forceLock"; then
45
+ echo "Angular target generation completed successfully!"
46
+ else
47
+ echo "Angular target generation failed!"
48
+ exit 1
49
+ fi
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
package/targets/common.sh CHANGED
@@ -10,6 +10,7 @@
10
10
  # 7. generatorId - openapi-code-generator identifier
11
11
  # 8. preRelease - building/publishing a pre-release
12
12
  # 9. templateDir - directory for merged templates
13
+ # 10. forceLock - force usage of saved package-lock.json (true/false)
13
14
 
14
15
  version=$1
15
16
  binary=$2
@@ -20,8 +21,9 @@ formatterBinary=$6
20
21
  generatorId=$7
21
22
  preRelease=$8
22
23
  templateDir=$9
24
+ forceLock=${10:-false}
23
25
 
24
- echo -e "\n=====\n version:\t$version\n binary:\t$binary\n configFile:\t$configFile\n targetId:\t$targetId\n generatorId:\t$generatorId\n openApiFile:\t$openApiFile\n formatter:\t$formatterBinary\n preRelease:\t$preRelease\n templateDir:\t$templateDir\n ---"
26
+ echo -e "\n=====\n version:\t$version\n binary:\t$binary\n configFile:\t$configFile\n targetId:\t$targetId\n generatorId:\t$generatorId\n openApiFile:\t$openApiFile\n formatter:\t$formatterBinary\n preRelease:\t$preRelease\n templateDir:\t$templateDir\n forceLock:\t$forceLock\n ---"
25
27
 
26
28
  blacklist='.id, .type, .source, .generator, .generatorId, .templateDir'
27
29
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -0,0 +1,290 @@
1
+ #!/bin/bash
2
+
3
+ # Dependency Lock Utilities
4
+ # This script provides functions to manage package-lock.json files for Node.js-based targets
5
+
6
+ # Global variables
7
+ LOCKS_DIR=".oasg"
8
+ CURRENT_DIR=$(pwd)
9
+
10
+ # Create locks directory if it doesn't exist
11
+ create_locks_dir() {
12
+ local target_id=$1
13
+ local version=$2
14
+
15
+ if [ -n "$version" ]; then
16
+ local lock_dir="$CURRENT_DIR/$LOCKS_DIR/${target_id}-${version}"
17
+ else
18
+ local lock_dir="$CURRENT_DIR/$LOCKS_DIR/${target_id}"
19
+ fi
20
+
21
+ mkdir -p "$lock_dir"
22
+ echo "$lock_dir"
23
+ }
24
+
25
+ # Check if saved package-lock.json exists for target
26
+ saved_lock_exists() {
27
+ local target_id=$1
28
+ local version=$2
29
+
30
+ if [ -n "$version" ]; then
31
+ local lock_file="$CURRENT_DIR/$LOCKS_DIR/${target_id}-${version}/package-lock.json"
32
+ else
33
+ local lock_file="$CURRENT_DIR/$LOCKS_DIR/${target_id}/package-lock.json"
34
+ fi
35
+
36
+ if [ -f "$lock_file" ]; then
37
+ echo "true"
38
+ else
39
+ echo "false"
40
+ fi
41
+ }
42
+
43
+ # Get path to saved package-lock.json
44
+ get_saved_lock_path() {
45
+ local target_id=$1
46
+ local version=$2
47
+
48
+ if [ -n "$version" ]; then
49
+ echo "$CURRENT_DIR/$LOCKS_DIR/${target_id}-${version}/package-lock.json"
50
+ else
51
+ echo "$CURRENT_DIR/$LOCKS_DIR/${target_id}/package-lock.json"
52
+ fi
53
+ }
54
+
55
+ # Compare two package-lock.json files
56
+ compare_package_locks() {
57
+ local current_lock=$1
58
+ local saved_lock=$2
59
+
60
+ if [ ! -f "$current_lock" ]; then
61
+ echo "false"
62
+ return
63
+ fi
64
+
65
+ if [ ! -f "$saved_lock" ]; then
66
+ echo "false"
67
+ return
68
+ fi
69
+
70
+ # Create temporary files for normalized JSON
71
+ local temp_dir="/tmp"
72
+ local temp_current="$temp_dir/oasg_current_$$.json"
73
+ local temp_saved="$temp_dir/oasg_saved_$$.json"
74
+
75
+ # Normalize JSON files
76
+ if ! jq -S . "$current_lock" > "$temp_current" 2>/dev/null; then
77
+ rm -f "$temp_current" "$temp_saved"
78
+ echo "false"
79
+ return
80
+ fi
81
+
82
+ if ! jq -S . "$saved_lock" > "$temp_saved" 2>/dev/null; then
83
+ rm -f "$temp_current" "$temp_saved"
84
+ echo "false"
85
+ return
86
+ fi
87
+
88
+ # Compare using cmp for binary comparison
89
+ if cmp -s "$temp_current" "$temp_saved"; then
90
+ rm -f "$temp_current" "$temp_saved"
91
+ echo "true"
92
+ else
93
+ rm -f "$temp_current" "$temp_saved"
94
+ echo "false"
95
+ fi
96
+ }
97
+
98
+ # Copy current package-lock.json to saved location
99
+ save_current_lock() {
100
+ local target_id=$1
101
+ local version=$2
102
+ local current_lock=$3
103
+ local lock_dir=$(create_locks_dir "$target_id" "$version")
104
+
105
+ if [ -f "$current_lock" ]; then
106
+ cp "$current_lock" "$lock_dir/package-lock.json"
107
+ echo "Package-lock.json saved to $lock_dir/package-lock.json"
108
+ return 0
109
+ else
110
+ echo "Error: Current package-lock.json not found at $current_lock"
111
+ return 1
112
+ fi
113
+ }
114
+
115
+ # Restore saved package-lock.json to current location
116
+ restore_saved_lock() {
117
+ local target_id=$1
118
+ local version=$2
119
+ local target_lock=$3
120
+ local saved_lock=$(get_saved_lock_path "$target_id" "$version")
121
+
122
+ if [ -f "$saved_lock" ]; then
123
+ cp "$saved_lock" "$target_lock"
124
+ echo "Saved package-lock.json restored to $target_lock"
125
+ return 0
126
+ else
127
+ echo "Error: Saved package-lock.json not found at $saved_lock"
128
+ return 1
129
+ fi
130
+ }
131
+
132
+ # Prompt user to save package-lock.json
133
+ prompt_save_lock() {
134
+ local target_id=$1
135
+ local version=$2
136
+
137
+ echo ""
138
+ echo "============================================="
139
+ echo "DEPENDENCY LOCK MANAGEMENT"
140
+ echo "============================================="
141
+ echo "A new package-lock.json has been generated for $target_id."
142
+ echo "To save this working configuration for future use, run:"
143
+ echo ""
144
+ echo " oasg save-lock $target_id"
145
+ echo ""
146
+ echo "This will help prevent future dependency-related build failures."
147
+ echo "============================================="
148
+ echo ""
149
+ }
150
+
151
+ # Prompt user to update saved package-lock.json
152
+ prompt_update_lock() {
153
+ local target_id=$1
154
+ local version=$2
155
+ local saved_lock=$(get_saved_lock_path "$target_id" "$version")
156
+
157
+ echo ""
158
+ echo "============================================="
159
+ echo "DEPENDENCY LOCK UPDATE REQUIRED"
160
+ echo "============================================="
161
+ echo "The package-lock.json for $target_id has changed."
162
+ echo "This may include security patches or minor updates."
163
+ echo "To update the saved lock file, run:"
164
+ echo ""
165
+ echo " oasg save-lock $target_id"
166
+ echo ""
167
+ echo "Then commit the updated lock file: $saved_lock"
168
+ echo "============================================="
169
+ echo ""
170
+ }
171
+
172
+ # Build with dependency locking support
173
+ build_with_dependency_locking() {
174
+ local target_id=$1
175
+ local version=$2
176
+ local build_dir=$3
177
+ local install_cmd=${4:-"npm install"}
178
+ local build_cmd=${5:-"npm run build"}
179
+ local force_lock=${6:-false}
180
+
181
+ echo "Building $target_id with dependency locking support..."
182
+
183
+ # If force-lock is enabled, skip normal install and use saved lock immediately
184
+ if [ "$force_lock" = "true" ]; then
185
+ echo "Force-lock enabled: using saved package-lock.json immediately..."
186
+ local saved_exists=$(saved_lock_exists "$target_id" "$version")
187
+
188
+ if [ "$saved_exists" = "false" ]; then
189
+ echo "Error: --force-lock specified but no saved package-lock.json found for $target_id"
190
+ cd "$CURRENT_DIR"
191
+ return 1
192
+ fi
193
+
194
+ cd "$CURRENT_DIR"
195
+ restore_saved_lock "$target_id" "$version" "$build_dir/package-lock.json"
196
+
197
+ cd "$build_dir"
198
+ local forced_install_cmd="npm ci"
199
+ echo "Running: $forced_install_cmd"
200
+ if eval "$forced_install_cmd"; then
201
+ echo "Running: $build_cmd"
202
+ if eval "$build_cmd"; then
203
+ echo "Build successful with forced saved package-lock.json!"
204
+ cd "$CURRENT_DIR"
205
+ return 0
206
+ else
207
+ echo "Build failed even with forced saved package-lock.json!"
208
+ cd "$CURRENT_DIR"
209
+ return 1
210
+ fi
211
+ else
212
+ echo "Install failed even with forced saved package-lock.json!"
213
+ cd "$CURRENT_DIR"
214
+ return 1
215
+ fi
216
+ fi
217
+
218
+ # Try normal build first
219
+ cd "$build_dir"
220
+ echo "Running: $install_cmd"
221
+ if eval "$install_cmd"; then
222
+ echo "Running: $build_cmd"
223
+ if eval "$build_cmd"; then
224
+ echo "Build successful!"
225
+
226
+ # Check if we need to manage package-lock.json
227
+ if [ -f "package-lock.json" ]; then
228
+ local saved_exists=$(saved_lock_exists "$target_id" "$version")
229
+
230
+ if [ "$saved_exists" = "true" ]; then
231
+ local saved_lock_full_path=$(get_saved_lock_path "$target_id" "$version")
232
+ local current_lock_full_path="$CURRENT_DIR/$build_dir/package-lock.json"
233
+ local locks_identical=$(compare_package_locks "$current_lock_full_path" "$saved_lock_full_path")
234
+
235
+ if [ "$locks_identical" = "false" ]; then
236
+ cd "$CURRENT_DIR"
237
+ prompt_update_lock "$target_id" "$version"
238
+ else
239
+ echo "Package-lock.json unchanged from saved version."
240
+ fi
241
+ else
242
+ cd "$CURRENT_DIR"
243
+ prompt_save_lock "$target_id" "$version"
244
+ fi
245
+ fi
246
+
247
+ cd "$CURRENT_DIR"
248
+ return 0
249
+ else
250
+ echo "Build failed, attempting to use saved package-lock.json..."
251
+ fi
252
+ else
253
+ echo "Install failed, attempting to use saved package-lock.json..."
254
+ fi
255
+
256
+ # Try with saved package-lock.json
257
+ local saved_exists=$(saved_lock_exists "$target_id" "$version")
258
+ if [ "$saved_exists" = "true" ]; then
259
+ echo "Restoring saved package-lock.json..."
260
+ cd "$CURRENT_DIR"
261
+ restore_saved_lock "$target_id" "$version" "$build_dir/package-lock.json"
262
+
263
+ cd "$build_dir"
264
+ echo "Retrying with saved package-lock.json..."
265
+ # Use npm ci when restoring from saved package-lock.json to ensure exact versions
266
+ local fallback_install_cmd="npm ci"
267
+ echo "Running: $fallback_install_cmd"
268
+ if eval "$fallback_install_cmd"; then
269
+ echo "Running: $build_cmd"
270
+ if eval "$build_cmd"; then
271
+ echo "Build successful with saved package-lock.json!"
272
+ cd "$CURRENT_DIR"
273
+ return 0
274
+ else
275
+ echo "Build failed even with saved package-lock.json!"
276
+ cd "$CURRENT_DIR"
277
+ return 1
278
+ fi
279
+ else
280
+ echo "Install failed even with saved package-lock.json!"
281
+ cd "$CURRENT_DIR"
282
+ return 1
283
+ fi
284
+ else
285
+ echo "No saved package-lock.json found for $target_id"
286
+ echo "Build failed and no fallback available."
287
+ cd "$CURRENT_DIR"
288
+ return 1
289
+ fi
290
+ }
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4
 
@@ -1,4 +1,4 @@
1
- #/bin/bash
1
+ #!/bin/bash
2
2
 
3
3
  source $(dirname "$0")/../common.sh
4
4