@opencrvs/toolkit 2.0.0-rc.d846143 → 2.0.0-rc.d86d00f
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.
- package/create-countryconfig/index.js +73 -0
- package/create-countryconfig/package.json +21 -0
- package/dist/application-config/index.js +259 -96
- package/dist/cli.js +1952 -347
- package/dist/commons/api/router.d.ts +3328 -255
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +1 -0
- package/dist/commons/events/ActionInput.d.ts +108 -0
- package/dist/commons/events/Draft.d.ts +4 -2
- package/dist/commons/events/EventIndex.d.ts +0 -3
- package/dist/commons/events/EventMetadata.d.ts +0 -7
- package/dist/commons/events/FieldConfig.d.ts +10 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +150 -150
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locations.d.ts +38 -1
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/commons/events/state/index.d.ts +0 -4
- package/dist/commons/events/state/utils.d.ts +0 -2
- package/dist/commons/events/utils.d.ts +1 -1
- package/dist/conditionals/index.js +40 -8
- package/dist/events/index.js +799 -154
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +17 -14
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
- package/dist/migrations/v2.0/create-events-index.js +1 -2
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
- package/dist/migrations/v2.0/index.d.ts +10 -4
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +1920 -344
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +55 -32
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +143 -63
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-api-paths.js +3 -4
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
- package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
- package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
- package/dist/migrations/v2.0/update-package-json.js +105 -0
- package/dist/notification/index.js +689 -124
- package/dist/scopes/index.d.ts +87 -10
- package/dist/scopes/index.js +46 -9
- package/opencrvs-toolkit-2.0.0-rc.d86d00f.tgz +0 -0
- package/package.json +5 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.d846143.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"AAodA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -41,11 +41,14 @@ exports.main = main;
|
|
|
41
41
|
* - Removes the `deduplication` property from those objects
|
|
42
42
|
* - Replaces `review: { fields: <value> }` with `form: <value>`, or
|
|
43
43
|
* `review: <expr>` with `form: <expr>.fields` when the value is not an inline object
|
|
44
|
+
* - Adds the top-level `validated` flag definition and `{ id: 'validated',
|
|
45
|
+
* operation: 'add' }` to the (now custom) validate action
|
|
46
|
+
* - Adds `{ id: 'validated', operation: 'remove' }` to every `REGISTER` action
|
|
47
|
+
* in the same config, closing the flag's lifecycle when registration happens
|
|
44
48
|
* - Saves the modified files in-place
|
|
45
49
|
*/
|
|
46
50
|
const ts_morph_1 = require("ts-morph");
|
|
47
51
|
const path_1 = __importDefault(require("path"));
|
|
48
|
-
const _1 = require(".");
|
|
49
52
|
const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
|
|
50
53
|
const REQUIRED_SYMBOLS = [
|
|
51
54
|
'ConditionalType',
|
|
@@ -75,6 +78,8 @@ function ensureImports(sourceFile) {
|
|
|
75
78
|
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
76
79
|
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
77
80
|
const TYPE_PROPERTY_NAME = 'type';
|
|
81
|
+
const ID_PROPERTY_NAME = 'id';
|
|
82
|
+
const FLAGS_PROPERTY_NAME = 'flags';
|
|
78
83
|
const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
|
|
79
84
|
const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
|
|
80
85
|
const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
|
|
@@ -84,9 +89,12 @@ const FORM_PROPERTY_NAME = 'form';
|
|
|
84
89
|
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
85
90
|
const VALIDATE_MEMBER_NAME = 'VALIDATE';
|
|
86
91
|
const CUSTOM_MEMBER_NAME = 'CUSTOM';
|
|
92
|
+
const REGISTER_MEMBER_NAME = 'REGISTER';
|
|
87
93
|
const VALIDATE_STRING_LITERAL = 'VALIDATE';
|
|
88
94
|
const CUSTOM_STRING_LITERAL = 'CUSTOM';
|
|
95
|
+
const REGISTER_STRING_LITERAL = 'REGISTER';
|
|
89
96
|
const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
|
|
97
|
+
const VALIDATED_FLAG_VALUE = 'validated';
|
|
90
98
|
function isValidateType(typeInitializer) {
|
|
91
99
|
// Matches: ActionType.VALIDATE
|
|
92
100
|
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
@@ -231,6 +239,72 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
231
239
|
}
|
|
232
240
|
return true;
|
|
233
241
|
}
|
|
242
|
+
function isRegisterAction(action) {
|
|
243
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
244
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
245
|
+
return false;
|
|
246
|
+
const typeInit = typeProperty.getInitializer();
|
|
247
|
+
if (!typeInit)
|
|
248
|
+
return false;
|
|
249
|
+
// Matches: ActionType.REGISTER
|
|
250
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
|
|
251
|
+
const enumExpr = typeInit.getExpression();
|
|
252
|
+
return (ts_morph_1.Node.isIdentifier(enumExpr) &&
|
|
253
|
+
enumExpr.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
254
|
+
typeInit.getName() === REGISTER_MEMBER_NAME);
|
|
255
|
+
}
|
|
256
|
+
// Matches: "REGISTER"
|
|
257
|
+
if (ts_morph_1.Node.isStringLiteral(typeInit)) {
|
|
258
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL;
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
264
|
+
*/
|
|
265
|
+
function arrayHasElementWithId(array, id) {
|
|
266
|
+
for (const el of array.getElements()) {
|
|
267
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(el))
|
|
268
|
+
continue;
|
|
269
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
270
|
+
if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
|
|
271
|
+
continue;
|
|
272
|
+
const idInit = idProp.getInitializer();
|
|
273
|
+
if (idInit &&
|
|
274
|
+
ts_morph_1.Node.isStringLiteral(idInit) &&
|
|
275
|
+
idInit.getLiteralValue() === id) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Adds `{ id: 'validated', operation: 'remove' }` to a REGISTER action's
|
|
283
|
+
* `flags` array. Skips if any `validated` flag entry is already present —
|
|
284
|
+
* this keeps the codemod idempotent and avoids stomping on an intentional
|
|
285
|
+
* `add` op a maintainer may have authored manually.
|
|
286
|
+
*
|
|
287
|
+
* Returns true if a change was made.
|
|
288
|
+
*/
|
|
289
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
290
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
291
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
292
|
+
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
293
|
+
const flagsInit = flagsProp.getInitializer();
|
|
294
|
+
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
295
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE))
|
|
296
|
+
return false;
|
|
297
|
+
flagsInit.addElement(entry);
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
action.addPropertyAssignment({
|
|
303
|
+
name: FLAGS_PROPERTY_NAME,
|
|
304
|
+
initializer: `[${entry}]`
|
|
305
|
+
});
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
234
308
|
function processFile(filePath, project) {
|
|
235
309
|
const sourceFile = project.getSourceFile(filePath);
|
|
236
310
|
if (!sourceFile)
|
|
@@ -263,7 +337,7 @@ function processFile(filePath, project) {
|
|
|
263
337
|
// Resolve the root event type for use in the auditHistoryLabel id
|
|
264
338
|
const eventType = resolveEventType(configArg);
|
|
265
339
|
if (!eventType) {
|
|
266
|
-
console.warn(` [${path_1.default.relative(
|
|
340
|
+
console.warn(` [${path_1.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig — skipping auditHistoryLabel id generation`);
|
|
267
341
|
}
|
|
268
342
|
// Iterate over every element in the `actions` array
|
|
269
343
|
let fileNeedsImports = false;
|
|
@@ -276,7 +350,7 @@ function processFile(filePath, project) {
|
|
|
276
350
|
transformedCount++;
|
|
277
351
|
fileNeedsImports = true;
|
|
278
352
|
configHadValidateAction = true;
|
|
279
|
-
console.log(` [${path_1.default.relative(
|
|
353
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`);
|
|
280
354
|
}
|
|
281
355
|
}
|
|
282
356
|
// Add top-level flags array to the config object if a VALIDATE action was found
|
|
@@ -296,7 +370,21 @@ function processFile(filePath, project) {
|
|
|
296
370
|
}
|
|
297
371
|
]`
|
|
298
372
|
});
|
|
299
|
-
console.log(` [${path_1.default.relative(
|
|
373
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
|
|
374
|
+
}
|
|
375
|
+
// Close the `validated` flag's lifecycle: when the validate action adds the
|
|
376
|
+
// flag, the matching REGISTER action(s) must remove it on registration.
|
|
377
|
+
if (configHadValidateAction) {
|
|
378
|
+
for (const element of actionsInitializer.getElements()) {
|
|
379
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
380
|
+
continue;
|
|
381
|
+
if (!isRegisterAction(element))
|
|
382
|
+
continue;
|
|
383
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
384
|
+
transformedCount++;
|
|
385
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
300
388
|
}
|
|
301
389
|
if (fileNeedsImports) {
|
|
302
390
|
ensureImports(sourceFile);
|
|
@@ -306,7 +394,7 @@ function processFile(filePath, project) {
|
|
|
306
394
|
}
|
|
307
395
|
function main() {
|
|
308
396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
-
const srcDir = path_1.default.join(
|
|
397
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
310
398
|
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
311
399
|
const project = new ts_morph_1.Project({
|
|
312
400
|
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
@@ -337,8 +425,8 @@ function main() {
|
|
|
337
425
|
for (const filePath of modifiedFiles) {
|
|
338
426
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
339
427
|
yield sourceFile.save();
|
|
340
|
-
console.log(` Saved: ${path_1.default.relative(
|
|
428
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
341
429
|
}
|
|
342
|
-
console.log(`\nDone.
|
|
430
|
+
console.log(`\nDone. Applied ${totalTransformed} change(s): VALIDATE → CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`);
|
|
343
431
|
});
|
|
344
432
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface MergeInfrastructureOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Top-level subdirectories of `infrastructure/` to scope the merge to.
|
|
4
|
+
* When omitted or empty, the entire `infrastructure/` tree is merged
|
|
5
|
+
* (legacy behavior). Each name is relative to `infrastructure/` —
|
|
6
|
+
* e.g. `['postgres', 'metabase']` merges only
|
|
7
|
+
* `infrastructure/postgres/` and `infrastructure/metabase/`.
|
|
8
|
+
*/
|
|
9
|
+
subdirs?: string[];
|
|
10
|
+
}
|
|
11
|
+
declare function main({ subdirs }?: MergeInfrastructureOptions): Promise<void>;
|
|
12
|
+
export { main };
|
|
13
|
+
//# sourceMappingURL=merge-infrastructure-directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,UAAU,0BAA0B;IAClC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAID,iBAAe,IAAI,CAAC,EAClB,OAAY,EACb,GAAE,0BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAoIjD;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.main = main;
|
|
23
|
+
/**
|
|
24
|
+
* Codemod: Merge upstream changes into the local `infrastructure/` directory
|
|
25
|
+
* (or selected subdirectories of it) from opencrvs/opencrvs-countryconfig.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
29
|
+
*
|
|
30
|
+
* What it does:
|
|
31
|
+
* 1. Registers a temporary git remote that points at the canonical
|
|
32
|
+
* opencrvs-countryconfig repository and fetches both:
|
|
33
|
+
* - the upstream "theirs" branch (v2.0) → `UPSTREAM_BRANCH`
|
|
34
|
+
* - the synthetic merge-base branch (latest 1.9 release line)
|
|
35
|
+
* → `BASE_BRANCH`
|
|
36
|
+
* 2. For every file under `infrastructure/` on upstream "theirs" (or, when
|
|
37
|
+
* `subdirs` is provided, only files under
|
|
38
|
+
* `infrastructure/<subdir>/` for each requested subdir), performs a
|
|
39
|
+
* file-scoped 3-way merge:
|
|
40
|
+
* - new file on upstream → checked out and staged
|
|
41
|
+
* - existing file → 3-way merged in place via `git merge-file`,
|
|
42
|
+
* using the BASE_BRANCH version of the file
|
|
43
|
+
* as the ancestor (or an empty file if the
|
|
44
|
+
* base doesn't have it)
|
|
45
|
+
* Files local to the country config that don't exist on upstream are
|
|
46
|
+
* left untouched.
|
|
47
|
+
* 3. Cleanly merged files are staged. Files with conflicts are left in the
|
|
48
|
+
* working tree with standard <<<<<<< / ======= / >>>>>>> markers and
|
|
49
|
+
* MUST be resolved manually by the developer.
|
|
50
|
+
* 4. Removes the temporary remote in all cases (success, failure, or
|
|
51
|
+
* unexpected error) via a `finally` block.
|
|
52
|
+
*
|
|
53
|
+
* Why a content-based synthetic merge-base instead of `git merge-base`:
|
|
54
|
+
* - Country config repos rarely share git history with
|
|
55
|
+
* opencrvs-countryconfig (squashed forks, template-cloned repos, etc.),
|
|
56
|
+
* so `git merge-base HEAD upstream/develop` typically returns nothing.
|
|
57
|
+
* - With no merge-base, a 3-way merge degenerates to a 2-way diff against
|
|
58
|
+
* an empty file — every line that differs becomes a conflict.
|
|
59
|
+
* - `release-v1.9` is the latest 1.9.x release line on upstream and is a
|
|
60
|
+
* near-perfect representation of "what `infrastructure/` looked like
|
|
61
|
+
* before v2.0", regardless of whether the fork's git history reaches it.
|
|
62
|
+
* - For files the country config never modified relative to that baseline,
|
|
63
|
+
* `git merge-file` resolves cleanly to upstream's v2.0 version. Conflicts
|
|
64
|
+
* are produced only where local edits genuinely overlap with v1.9 → v2.0
|
|
65
|
+
* upstream edits — which is what the developer needs to review anyway.
|
|
66
|
+
*
|
|
67
|
+
* Why per-file merge instead of a real `git merge`:
|
|
68
|
+
* - Limits the blast radius to `infrastructure/` only — no other paths
|
|
69
|
+
* are touched.
|
|
70
|
+
* - Doesn't put the repository into an in-progress merge state
|
|
71
|
+
* (no MERGE_HEAD), so subsequent codemods/commands behave normally.
|
|
72
|
+
* - Works regardless of whether the local repo shares history with
|
|
73
|
+
* opencrvs-countryconfig.
|
|
74
|
+
*
|
|
75
|
+
* Caveats:
|
|
76
|
+
* - Local edits to merged files may be overwritten where they overlap
|
|
77
|
+
* with upstream changes. Run on a clean working tree.
|
|
78
|
+
* - Requires git to be installed and network access to github.com.
|
|
79
|
+
* - Requires the country config working directory to be a git repo.
|
|
80
|
+
* - Binary files in `infrastructure/` are not merged textually; if both
|
|
81
|
+
* sides changed a binary file, the result will be invalid and a warning
|
|
82
|
+
* is printed.
|
|
83
|
+
* - Forks that are on a much older 1.9.x and never merged later 1.9 patches
|
|
84
|
+
* may see a few extra conflicts on files where 1.9.x → release-v1.9
|
|
85
|
+
* patches and v1.9 → v2.0 changes textually overlap.
|
|
86
|
+
*/
|
|
87
|
+
const child_process_1 = require("child_process");
|
|
88
|
+
const fs_1 = require("fs");
|
|
89
|
+
const os_1 = require("os");
|
|
90
|
+
const path_1 = require("path");
|
|
91
|
+
const checkout_upstream_files_1 = require("./checkout-upstream-files");
|
|
92
|
+
// Distinct from the remote used by `checkout-upstream-files` so that a stale
|
|
93
|
+
// remote left behind by an aborted run of one codemod doesn't trip up the
|
|
94
|
+
// other.
|
|
95
|
+
const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod-merge-infra';
|
|
96
|
+
const INFRASTRUCTURE_DIR = 'infrastructure';
|
|
97
|
+
// Synthetic merge-base: the tip of upstream's latest 1.9.x release line.
|
|
98
|
+
// We use this branch's content as the "common ancestor" for every file,
|
|
99
|
+
// since most country forks don't share git history with upstream.
|
|
100
|
+
const BASE_BRANCH = 'release-v1.9';
|
|
101
|
+
/**
|
|
102
|
+
* Reads `git show <ref>:<path>` as a Uint8Array (binary-safe).
|
|
103
|
+
* Returns `null` if the path doesn't exist at that ref.
|
|
104
|
+
*/
|
|
105
|
+
function gitShowBytes(ref, path) {
|
|
106
|
+
try {
|
|
107
|
+
const buf = (0, child_process_1.execFileSync)('git', ['show', `${ref}:${path}`], {
|
|
108
|
+
cwd: process.cwd(),
|
|
109
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
110
|
+
});
|
|
111
|
+
// Return a plain Uint8Array view to satisfy strict typings of `fs`
|
|
112
|
+
// (which want `ArrayBufferView`, not Node's `Buffer` subtype).
|
|
113
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
114
|
+
}
|
|
115
|
+
catch (_a) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
120
|
+
function main() {
|
|
121
|
+
return __awaiter(this, arguments, void 0, function* ({ subdirs = [] } = {}) {
|
|
122
|
+
// Build the pathspec list passed to `git ls-tree`. Trailing slashes make
|
|
123
|
+
// git treat them as tree paths (recurse into them).
|
|
124
|
+
const pathspecs = subdirs.length > 0
|
|
125
|
+
? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`)
|
|
126
|
+
: [`${INFRASTRUCTURE_DIR}/`];
|
|
127
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(', ');
|
|
128
|
+
console.log(`Merging ${scopeLabel} from ${checkout_upstream_files_1.UPSTREAM_URL}@${checkout_upstream_files_1.UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...\n`);
|
|
129
|
+
(0, checkout_upstream_files_1.assertIsGitRepo)();
|
|
130
|
+
// Best-effort cleanup of a stale temp remote from a previous aborted run.
|
|
131
|
+
(0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE]);
|
|
132
|
+
try {
|
|
133
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${checkout_upstream_files_1.UPSTREAM_URL}`);
|
|
134
|
+
(0, checkout_upstream_files_1.runGit)(['remote', 'add', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_URL], { silent: true });
|
|
135
|
+
// Fetch both branches at depth=1 — we only need their tip contents,
|
|
136
|
+
// not their history (the merge is content-based, not history-based).
|
|
137
|
+
console.log(` Fetching ${TEMP_REMOTE}/{${checkout_upstream_files_1.UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`);
|
|
138
|
+
(0, checkout_upstream_files_1.runGit)(['fetch', '--depth=1', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
139
|
+
const ref = `${TEMP_REMOTE}/${checkout_upstream_files_1.UPSTREAM_BRANCH}`;
|
|
140
|
+
const baseRef = `${TEMP_REMOTE}/${BASE_BRANCH}`;
|
|
141
|
+
// -z gives NUL-separated paths so filenames with spaces or newlines
|
|
142
|
+
// survive the round-trip. Multiple pathspecs after `--` are unioned
|
|
143
|
+
// by git, which scopes the listing to the requested subdirectories.
|
|
144
|
+
const upstreamFiles = (0, checkout_upstream_files_1.runGit)(['ls-tree', '-r', '--name-only', '-z', ref, '--', ...pathspecs], { silent: true })
|
|
145
|
+
.split('\0')
|
|
146
|
+
.filter(Boolean);
|
|
147
|
+
if (upstreamFiles.length === 0) {
|
|
148
|
+
console.log(` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const tmpDir = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'opencrvs-merge-infra-'));
|
|
152
|
+
const baseTmp = (0, path_1.join)(tmpDir, 'base');
|
|
153
|
+
const theirsTmp = (0, path_1.join)(tmpDir, 'theirs');
|
|
154
|
+
let added = 0;
|
|
155
|
+
let merged = 0;
|
|
156
|
+
const conflictedFiles = [];
|
|
157
|
+
for (const file of upstreamFiles) {
|
|
158
|
+
const fullPath = (0, path_1.join)(process.cwd(), file);
|
|
159
|
+
if (!(0, fs_1.existsSync)(fullPath)) {
|
|
160
|
+
// New upstream file — `git checkout` handles binary correctly and
|
|
161
|
+
// stages the result, matching the UX of `checkout-upstream-files`.
|
|
162
|
+
if ((0, checkout_upstream_files_1.tryGit)(['checkout', ref, '--', file])) {
|
|
163
|
+
console.log(` + ${file} (new from upstream)`);
|
|
164
|
+
added++;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
168
|
+
}
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const theirContents = gitShowBytes(ref, file);
|
|
172
|
+
if (theirContents === null) {
|
|
173
|
+
// Shouldn't happen — `ls-tree` just told us the file is there.
|
|
174
|
+
console.warn(` [warn] could not read ${file} from ${ref} — skipping.`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
(0, fs_1.writeFileSync)(theirsTmp, theirContents);
|
|
178
|
+
// Pull the base version from upstream's latest 1.9 release line. If
|
|
179
|
+
// the file didn't exist there yet (added in v2.0), fall back to an
|
|
180
|
+
// empty base — `git merge-file` will then treat any local content as
|
|
181
|
+
// a local addition.
|
|
182
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
183
|
+
(0, fs_1.writeFileSync)(baseTmp, baseContents !== null && baseContents !== void 0 ? baseContents : new Uint8Array(0));
|
|
184
|
+
// `git merge-file` does an in-place 3-way merge. Exit codes:
|
|
185
|
+
// 0 → clean merge
|
|
186
|
+
// 1..N → that many conflicts; markers written into the file
|
|
187
|
+
// <0/127 → error (e.g. binary file rejected)
|
|
188
|
+
try {
|
|
189
|
+
(0, child_process_1.execFileSync)('git', ['merge-file', fullPath, baseTmp, theirsTmp], {
|
|
190
|
+
cwd: process.cwd(),
|
|
191
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
192
|
+
});
|
|
193
|
+
(0, checkout_upstream_files_1.runGit)(['add', '--', file], { silent: true });
|
|
194
|
+
merged++;
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
const status = err.status;
|
|
198
|
+
if (typeof status === 'number' && status > 0) {
|
|
199
|
+
conflictedFiles.push(file);
|
|
200
|
+
console.warn(` ! ${file} (${status} conflict${status > 1 ? 's' : ''})`);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
conflictedFiles.push(file);
|
|
204
|
+
console.warn(` [warn] merge failed for ${file} (likely binary or unreadable) — left untouched.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
console.log(`\n Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`);
|
|
209
|
+
if (conflictedFiles.length > 0) {
|
|
210
|
+
console.warn(`\n NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.\n` +
|
|
211
|
+
` Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:\n` +
|
|
212
|
+
conflictedFiles.map((f) => ` - ${f}`).join('\n') +
|
|
213
|
+
`\n After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
if ((0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE])) {
|
|
218
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-application-config-url.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-application-config-url.ts"],"names":[],"mappings":"AAwUA,iBAAe,IAAI,kBAqElB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|