@logto/cli 1.30.0-beta.0 → 1.30.1
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.
|
@@ -8,10 +8,29 @@ const currentDirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
8
8
|
const alterationFilenameRegex = /-([\d.]+)-?.*\.js$/;
|
|
9
9
|
export const getTimestampFromFilename = (filename) => {
|
|
10
10
|
const match = alterationFilenameRegex.exec(filename);
|
|
11
|
-
|
|
11
|
+
const timestampPart = match?.[1];
|
|
12
|
+
if (!timestampPart) {
|
|
12
13
|
throw new Error(`Can not get timestamp: ${filename}`);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* We support the timestamp with or without a suffix.
|
|
17
|
+
*
|
|
18
|
+
* - `next-1663923770-a.js`
|
|
19
|
+
* - `next-1663923770.1-c.js`
|
|
20
|
+
*/
|
|
21
|
+
const [baseTimestamp] = timestampPart.split('.');
|
|
22
|
+
/**
|
|
23
|
+
* Validate the baseTimestamp digit length. The timestamp should be formatted in second precision.
|
|
24
|
+
*
|
|
25
|
+
* E.g. Math.ceil(Date.now() / 1000)
|
|
26
|
+
*
|
|
27
|
+
* Should Throw an error if the timestamp is greater than 10 digits.
|
|
28
|
+
* This is to ensure that the timestamp is in seconds, not milliseconds.
|
|
29
|
+
*/
|
|
30
|
+
if (!baseTimestamp || baseTimestamp.length > 10) {
|
|
31
|
+
throw new Error(`Invalid timestamp format in filename: ${filename}`);
|
|
32
|
+
}
|
|
33
|
+
return Number(timestampPart);
|
|
15
34
|
};
|
|
16
35
|
export const getAlterationDirectory = () => getPathInModule('@logto/schemas', 'alterations-js');
|
|
17
36
|
export const getAlterationFiles = async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getTimestampFromFilename } from './utils.js';
|
|
3
|
+
const fileNames = ['1.0.0-1663923770-a.js', '1.0.1-1663923771.1-b.js', 'next-1663923772.12-c.js'];
|
|
4
|
+
const invalidFileNames = [
|
|
5
|
+
'1.0.0-1663923770000-a.js',
|
|
6
|
+
'next-1663923772345-c.js',
|
|
7
|
+
'next-1663923772345.1-c.js',
|
|
8
|
+
];
|
|
9
|
+
describe('getTimestampFromFilename', () => {
|
|
10
|
+
it('should extract timestamp from valid filenames', () => {
|
|
11
|
+
for (const fileName of fileNames) {
|
|
12
|
+
const timestamp = getTimestampFromFilename(fileName);
|
|
13
|
+
expect(timestamp).toBeGreaterThan(0);
|
|
14
|
+
}
|
|
15
|
+
const newTimeStamp = Math.ceil(Date.now() / 1000);
|
|
16
|
+
const newFileName = `next-${newTimeStamp}-c.js`;
|
|
17
|
+
expect(getTimestampFromFilename(newFileName)).toBe(newTimeStamp);
|
|
18
|
+
});
|
|
19
|
+
it('should throw an error for invalid timestamp', () => {
|
|
20
|
+
for (const fileName of invalidFileNames) {
|
|
21
|
+
expect(() => getTimestampFromFilename(fileName)).toThrow(`Invalid timestamp format in filename: ${fileName}`);
|
|
22
|
+
}
|
|
23
|
+
const newTimeStamp = Date.now();
|
|
24
|
+
expect(() => getTimestampFromFilename(`next-${newTimeStamp}-c.js`)).toThrow(`Invalid timestamp format in filename: next-${newTimeStamp}-c.js`);
|
|
25
|
+
});
|
|
26
|
+
});
|
package/lib/package-json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.1",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"tar": "^7.0.0",
|
|
46
46
|
"yargs": "^17.6.0",
|
|
47
47
|
"zod": "3.24.3",
|
|
48
|
-
"@logto/connector-kit": "^4.
|
|
49
|
-
"@logto/core-kit": "^2.6.
|
|
50
|
-
"@logto/
|
|
51
|
-
"@logto/
|
|
48
|
+
"@logto/connector-kit": "^4.4.0",
|
|
49
|
+
"@logto/core-kit": "^2.6.1",
|
|
50
|
+
"@logto/shared": "^3.3.0",
|
|
51
|
+
"@logto/schemas": "1.30.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@silverhand/eslint-config": "6.0.1",
|