@dynamic-labs/assert-package-version 4.0.0-alpha.6
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/CHANGELOG.md +4204 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/package.json +32 -0
- package/src/index.cjs +10 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
- package/src/lib/assertPackageVersion/assertPackageVersion.cjs +77 -0
- package/src/lib/assertPackageVersion/assertPackageVersion.d.ts +16 -0
- package/src/lib/assertPackageVersion/assertPackageVersion.js +72 -0
- package/src/lib/assertPackageVersion/index.d.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/assert-package-version",
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
7
|
+
"directory": "packages/assert-package-version"
|
|
8
|
+
},
|
|
9
|
+
"description": "Utility to assert package versions",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/dynamic-labs/DynamicAuth/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/dynamic-labs/DynamicAuth/main/packages/assert-package-version#readme",
|
|
14
|
+
"author": "Dynamic Labs, Inc.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "./src/index.cjs",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"import": "./src/index.js",
|
|
24
|
+
"require": "./src/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@dynamic-labs/logger": "4.0.0-alpha.6"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {}
|
|
32
|
+
}
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('./lib/assertPackageVersion/assertPackageVersion.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.assertPackageVersion = assertPackageVersion.assertPackageVersion;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { assertPackageVersion } from './lib/assertPackageVersion';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A mapping of package names to their versions.
|
|
10
|
+
*/
|
|
11
|
+
let packageVersions = {};
|
|
12
|
+
const logger = new logger$1.Logger('@dynamic-labs/assert-package-version');
|
|
13
|
+
/**
|
|
14
|
+
* Timeout ID for batching version checks.
|
|
15
|
+
*/
|
|
16
|
+
exports.versionCheckTimeout = null;
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that all `@dynamic-labs` packages are on the same version.
|
|
19
|
+
* Throws an error with instructions if versions mismatch.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} packageName - The name of the package to assert.
|
|
22
|
+
* @param {string} version - The version of the package.
|
|
23
|
+
*/
|
|
24
|
+
const assertPackageVersion = (packageName, version) => {
|
|
25
|
+
// Update the package version mapping
|
|
26
|
+
packageVersions[packageName] = version;
|
|
27
|
+
// Clear any existing timeout
|
|
28
|
+
if (exports.versionCheckTimeout) {
|
|
29
|
+
clearTimeout(exports.versionCheckTimeout);
|
|
30
|
+
exports.versionCheckTimeout = null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Timeout is set to 100ms to ensure the following:
|
|
34
|
+
* - All package versions have been imported and registered.
|
|
35
|
+
* - The environmentId is set in the logger so the error can be captured in DD
|
|
36
|
+
*/
|
|
37
|
+
const timeout = 100;
|
|
38
|
+
/**
|
|
39
|
+
* Set a timeout to batch the version check.
|
|
40
|
+
* This ensures that the check is executed after all package versions have been imported
|
|
41
|
+
* and registered.
|
|
42
|
+
*/
|
|
43
|
+
exports.versionCheckTimeout = setTimeout(() => {
|
|
44
|
+
const versions = Object.values(packageVersions);
|
|
45
|
+
const [firstVersion] = versions;
|
|
46
|
+
const allSameVersion = versions.every((v) => v === firstVersion);
|
|
47
|
+
if (!allSameVersion) {
|
|
48
|
+
// Determine the required (target) version
|
|
49
|
+
const targetVersion = packageVersions['@dynamic-labs/sdk-react-core'] || firstVersion;
|
|
50
|
+
const errorMessage = getErrorMessage(targetVersion);
|
|
51
|
+
logger.error(new Error(errorMessage));
|
|
52
|
+
}
|
|
53
|
+
exports.versionCheckTimeout = null;
|
|
54
|
+
}, timeout);
|
|
55
|
+
};
|
|
56
|
+
const getErrorMessage = (targetVersion) => {
|
|
57
|
+
// Identify packages with mismatched versions
|
|
58
|
+
const affectedPackages = Object.entries(packageVersions)
|
|
59
|
+
.filter(([, v]) => v !== targetVersion)
|
|
60
|
+
.map(([pkgName, installedVersion]) => `- \`${pkgName}\` (installed: **${installedVersion}**, required: **${targetVersion}**)`)
|
|
61
|
+
.join('\n');
|
|
62
|
+
// Error message template
|
|
63
|
+
const errorMessage = `
|
|
64
|
+
🚨 Version Mismatch Error
|
|
65
|
+
|
|
66
|
+
One or more \`@dynamic-labs\` packages are installed with mismatched versions. All \`@dynamic-labs\` packages must be on the same version to work correctly.
|
|
67
|
+
|
|
68
|
+
Affected Packages:
|
|
69
|
+
${affectedPackages}
|
|
70
|
+
|
|
71
|
+
💡 To fix this issue, update all @dynamic/* packages to version \`${targetVersion}\` in your package.json
|
|
72
|
+
`;
|
|
73
|
+
return errorMessage.trim();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
exports.assertPackageVersion = assertPackageVersion;
|
|
77
|
+
exports.logger = logger;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
3
|
+
export declare const logger: Logger;
|
|
4
|
+
/**
|
|
5
|
+
* Timeout ID for batching version checks.
|
|
6
|
+
*/
|
|
7
|
+
export declare let versionCheckTimeout: NodeJS.Timeout | null;
|
|
8
|
+
/**
|
|
9
|
+
* Asserts that all `@dynamic-labs` packages are on the same version.
|
|
10
|
+
* Throws an error with instructions if versions mismatch.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} packageName - The name of the package to assert.
|
|
13
|
+
* @param {string} version - The version of the package.
|
|
14
|
+
*/
|
|
15
|
+
export declare const assertPackageVersion: (packageName: string, version: string) => void;
|
|
16
|
+
export declare const clearPackageVersionState: () => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A mapping of package names to their versions.
|
|
6
|
+
*/
|
|
7
|
+
let packageVersions = {};
|
|
8
|
+
const logger = new Logger('@dynamic-labs/assert-package-version');
|
|
9
|
+
/**
|
|
10
|
+
* Timeout ID for batching version checks.
|
|
11
|
+
*/
|
|
12
|
+
let versionCheckTimeout = null;
|
|
13
|
+
/**
|
|
14
|
+
* Asserts that all `@dynamic-labs` packages are on the same version.
|
|
15
|
+
* Throws an error with instructions if versions mismatch.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} packageName - The name of the package to assert.
|
|
18
|
+
* @param {string} version - The version of the package.
|
|
19
|
+
*/
|
|
20
|
+
const assertPackageVersion = (packageName, version) => {
|
|
21
|
+
// Update the package version mapping
|
|
22
|
+
packageVersions[packageName] = version;
|
|
23
|
+
// Clear any existing timeout
|
|
24
|
+
if (versionCheckTimeout) {
|
|
25
|
+
clearTimeout(versionCheckTimeout);
|
|
26
|
+
versionCheckTimeout = null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Timeout is set to 100ms to ensure the following:
|
|
30
|
+
* - All package versions have been imported and registered.
|
|
31
|
+
* - The environmentId is set in the logger so the error can be captured in DD
|
|
32
|
+
*/
|
|
33
|
+
const timeout = 100;
|
|
34
|
+
/**
|
|
35
|
+
* Set a timeout to batch the version check.
|
|
36
|
+
* This ensures that the check is executed after all package versions have been imported
|
|
37
|
+
* and registered.
|
|
38
|
+
*/
|
|
39
|
+
versionCheckTimeout = setTimeout(() => {
|
|
40
|
+
const versions = Object.values(packageVersions);
|
|
41
|
+
const [firstVersion] = versions;
|
|
42
|
+
const allSameVersion = versions.every((v) => v === firstVersion);
|
|
43
|
+
if (!allSameVersion) {
|
|
44
|
+
// Determine the required (target) version
|
|
45
|
+
const targetVersion = packageVersions['@dynamic-labs/sdk-react-core'] || firstVersion;
|
|
46
|
+
const errorMessage = getErrorMessage(targetVersion);
|
|
47
|
+
logger.error(new Error(errorMessage));
|
|
48
|
+
}
|
|
49
|
+
versionCheckTimeout = null;
|
|
50
|
+
}, timeout);
|
|
51
|
+
};
|
|
52
|
+
const getErrorMessage = (targetVersion) => {
|
|
53
|
+
// Identify packages with mismatched versions
|
|
54
|
+
const affectedPackages = Object.entries(packageVersions)
|
|
55
|
+
.filter(([, v]) => v !== targetVersion)
|
|
56
|
+
.map(([pkgName, installedVersion]) => `- \`${pkgName}\` (installed: **${installedVersion}**, required: **${targetVersion}**)`)
|
|
57
|
+
.join('\n');
|
|
58
|
+
// Error message template
|
|
59
|
+
const errorMessage = `
|
|
60
|
+
🚨 Version Mismatch Error
|
|
61
|
+
|
|
62
|
+
One or more \`@dynamic-labs\` packages are installed with mismatched versions. All \`@dynamic-labs\` packages must be on the same version to work correctly.
|
|
63
|
+
|
|
64
|
+
Affected Packages:
|
|
65
|
+
${affectedPackages}
|
|
66
|
+
|
|
67
|
+
💡 To fix this issue, update all @dynamic/* packages to version \`${targetVersion}\` in your package.json
|
|
68
|
+
`;
|
|
69
|
+
return errorMessage.trim();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { assertPackageVersion, logger, versionCheckTimeout };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { assertPackageVersion } from './assertPackageVersion';
|