@hubspot/npm-scripts 0.1.0-beta.0 → 0.1.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.
- package/package.json +5 -3
- package/src/constants/release.d.ts +2 -1
- package/src/constants/release.js +7 -1
- package/src/constants/repo-sync.d.ts +2 -1
- package/src/constants/repo-sync.js +2 -1
- package/src/release.js +55 -19
- package/src/repo-sync.d.ts +1 -1
- package/src/repo-sync.js +15 -15
- package/src/types.d.ts +6 -1
- package/src/utils/__tests__/filesystem.test.d.ts +1 -0
- package/src/utils/__tests__/filesystem.test.js +154 -0
- package/src/utils/__tests__/git.test.d.ts +1 -0
- package/src/utils/__tests__/git.test.js +267 -0
- package/src/utils/__tests__/logging.test.d.ts +1 -0
- package/src/utils/__tests__/logging.test.js +64 -0
- package/src/utils/__tests__/npm.test.d.ts +1 -0
- package/src/utils/__tests__/npm.test.js +266 -0
- package/src/utils/__tests__/process.test.d.ts +1 -0
- package/src/utils/__tests__/process.test.js +12 -0
- package/src/utils/__tests__/prompting.test.d.ts +1 -0
- package/src/utils/__tests__/prompting.test.js +100 -0
- package/src/utils/npm.d.ts +3 -1
- package/src/utils/npm.js +17 -8
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { confirm, input, checkbox } from '../prompting.js';
|
|
3
|
+
import { logger } from '../logging.js';
|
|
4
|
+
import _confirm from '@inquirer/confirm';
|
|
5
|
+
import _input from '@inquirer/input';
|
|
6
|
+
import _checkbox from '@inquirer/checkbox';
|
|
7
|
+
vi.mock('@inquirer/confirm', () => ({
|
|
8
|
+
default: vi.fn(),
|
|
9
|
+
}));
|
|
10
|
+
vi.mock('@inquirer/input', () => ({
|
|
11
|
+
default: vi.fn(),
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('@inquirer/checkbox', () => ({
|
|
14
|
+
default: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('../logging.js', () => ({
|
|
17
|
+
logger: {
|
|
18
|
+
log: vi.fn(),
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
describe('prompting', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
vi.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
describe('confirm', () => {
|
|
26
|
+
it('should return the result from inquirer confirm', async () => {
|
|
27
|
+
const mockConfirmFn = vi.mocked(_confirm);
|
|
28
|
+
mockConfirmFn.mockResolvedValue(true);
|
|
29
|
+
const result = await confirm({ message: 'Are you sure?' });
|
|
30
|
+
expect(result).toBe(true);
|
|
31
|
+
expect(mockConfirmFn).toHaveBeenCalledWith({ message: 'Are you sure?' });
|
|
32
|
+
});
|
|
33
|
+
it('should exit on ExitPromptError', async () => {
|
|
34
|
+
const mockConfirmFn = vi.mocked(_confirm);
|
|
35
|
+
const exitError = new Error('User exited');
|
|
36
|
+
exitError.name = 'ExitPromptError';
|
|
37
|
+
mockConfirmFn.mockRejectedValue(exitError);
|
|
38
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
|
|
39
|
+
throw new Error('process.exit called');
|
|
40
|
+
});
|
|
41
|
+
await expect(confirm({ message: 'Test' })).rejects.toThrow('process.exit called');
|
|
42
|
+
expect(vi.mocked(logger.log)).toHaveBeenCalledWith('Exiting...');
|
|
43
|
+
exitSpy.mockRestore();
|
|
44
|
+
});
|
|
45
|
+
it('should rethrow non-ExitPromptError', async () => {
|
|
46
|
+
const mockConfirmFn = vi.mocked(_confirm);
|
|
47
|
+
const otherError = new Error('Other error');
|
|
48
|
+
mockConfirmFn.mockRejectedValue(otherError);
|
|
49
|
+
await expect(confirm({ message: 'Test' })).rejects.toThrow('Other error');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('input', () => {
|
|
53
|
+
it('should return the result from inquirer input', async () => {
|
|
54
|
+
const mockInputFn = vi.mocked(_input);
|
|
55
|
+
mockInputFn.mockResolvedValue('test input');
|
|
56
|
+
const result = await input({ message: 'Enter value:' });
|
|
57
|
+
expect(result).toBe('test input');
|
|
58
|
+
expect(mockInputFn).toHaveBeenCalledWith({ message: 'Enter value:' });
|
|
59
|
+
});
|
|
60
|
+
it('should exit on ExitPromptError', async () => {
|
|
61
|
+
const mockInputFn = vi.mocked(_input);
|
|
62
|
+
const exitError = new Error('User exited');
|
|
63
|
+
exitError.name = 'ExitPromptError';
|
|
64
|
+
mockInputFn.mockRejectedValue(exitError);
|
|
65
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
|
|
66
|
+
throw new Error('process.exit called');
|
|
67
|
+
});
|
|
68
|
+
await expect(input({ message: 'Test' })).rejects.toThrow('process.exit called');
|
|
69
|
+
expect(vi.mocked(logger.log)).toHaveBeenCalledWith('Exiting...');
|
|
70
|
+
exitSpy.mockRestore();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('checkbox', () => {
|
|
74
|
+
it('should return the result from inquirer checkbox', async () => {
|
|
75
|
+
const mockCheckboxFn = vi.mocked(_checkbox);
|
|
76
|
+
mockCheckboxFn.mockResolvedValue(['option1', 'option2']);
|
|
77
|
+
const result = await checkbox({
|
|
78
|
+
message: 'Select options:',
|
|
79
|
+
choices: [{ value: 'option1' }, { value: 'option2' }],
|
|
80
|
+
});
|
|
81
|
+
expect(result).toEqual(['option1', 'option2']);
|
|
82
|
+
expect(mockCheckboxFn).toHaveBeenCalledWith({
|
|
83
|
+
message: 'Select options:',
|
|
84
|
+
choices: [{ value: 'option1' }, { value: 'option2' }],
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should exit on ExitPromptError', async () => {
|
|
88
|
+
const mockCheckboxFn = vi.mocked(_checkbox);
|
|
89
|
+
const exitError = new Error('User exited');
|
|
90
|
+
exitError.name = 'ExitPromptError';
|
|
91
|
+
mockCheckboxFn.mockRejectedValue(exitError);
|
|
92
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
|
|
93
|
+
throw new Error('process.exit called');
|
|
94
|
+
});
|
|
95
|
+
await expect(checkbox({ message: 'Test', choices: [{ value: 'option1' }] })).rejects.toThrow('process.exit called');
|
|
96
|
+
expect(vi.mocked(logger.log)).toHaveBeenCalledWith('Exiting...');
|
|
97
|
+
exitSpy.mockRestore();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
package/src/utils/npm.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DistTags, Tag } from '../types.js';
|
|
2
2
|
export declare function getDistTags(packageName: string): Promise<DistTags>;
|
|
3
|
-
export declare function publish(tag: Tag, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
3
|
+
export declare function publish(tag: Tag, otp: string, isDryRun: boolean, ignoreScripts: boolean, registry: string): Promise<void>;
|
|
4
|
+
export declare function updateDistTag(packageName: string, version: string, tag: string, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
4
5
|
export declare function updateNextTag(packageName: string, newVersion: string, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
|
6
|
+
export declare function updatePreviousTag(packageName: string, oldLatestVersion: string, otp: string, isDryRun: boolean, registry: string): Promise<void>;
|
package/src/utils/npm.js
CHANGED
|
@@ -9,7 +9,7 @@ export async function getDistTags(packageName) {
|
|
|
9
9
|
const distTags = stdout.trim();
|
|
10
10
|
return JSON.parse(distTags);
|
|
11
11
|
}
|
|
12
|
-
export async function publish(tag, otp, isDryRun, registry) {
|
|
12
|
+
export async function publish(tag, otp, isDryRun, ignoreScripts, registry) {
|
|
13
13
|
logger.log(`\nPublishing to ${tag}...`);
|
|
14
14
|
logger.log('-'.repeat(50));
|
|
15
15
|
logger.log('\n');
|
|
@@ -25,6 +25,9 @@ export async function publish(tag, otp, isDryRun, registry) {
|
|
|
25
25
|
if (isDryRun) {
|
|
26
26
|
commandArgs.push('--dry-run');
|
|
27
27
|
}
|
|
28
|
+
if (ignoreScripts) {
|
|
29
|
+
commandArgs.push('--ignore-scripts');
|
|
30
|
+
}
|
|
28
31
|
return new Promise((resolve, reject) => {
|
|
29
32
|
const childProcess = spawn('npm', commandArgs, {
|
|
30
33
|
stdio: 'inherit',
|
|
@@ -32,7 +35,7 @@ export async function publish(tag, otp, isDryRun, registry) {
|
|
|
32
35
|
});
|
|
33
36
|
childProcess.on('close', code => {
|
|
34
37
|
if (code !== EXIT_CODES.SUCCESS) {
|
|
35
|
-
reject();
|
|
38
|
+
reject(new Error(`npm publish failed with exit code ${code}`));
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
38
41
|
resolve();
|
|
@@ -40,14 +43,14 @@ export async function publish(tag, otp, isDryRun, registry) {
|
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
|
-
export async function
|
|
46
|
+
export async function updateDistTag(packageName, version, tag, otp, isDryRun, registry) {
|
|
44
47
|
logger.log();
|
|
45
|
-
logger.log(`Updating ${
|
|
48
|
+
logger.log(`Updating ${tag} tag to ${version}...`);
|
|
46
49
|
const commandArgs = [
|
|
47
50
|
'dist-tag',
|
|
48
51
|
'add',
|
|
49
|
-
`${packageName}@${
|
|
50
|
-
|
|
52
|
+
`${packageName}@${version}`,
|
|
53
|
+
tag,
|
|
51
54
|
'--registry',
|
|
52
55
|
registry,
|
|
53
56
|
'--otp',
|
|
@@ -63,13 +66,19 @@ export async function updateNextTag(packageName, newVersion, otp, isDryRun, regi
|
|
|
63
66
|
const childProcess = spawn('npm', commandArgs, { stdio: 'inherit' });
|
|
64
67
|
childProcess.on('close', code => {
|
|
65
68
|
if (code !== EXIT_CODES.SUCCESS) {
|
|
66
|
-
reject();
|
|
69
|
+
reject(new Error(`npm dist-tag add failed with exit code ${code}`));
|
|
67
70
|
}
|
|
68
71
|
else {
|
|
69
|
-
logger.success(`${
|
|
72
|
+
logger.success(`${tag} tag updated successfully`);
|
|
70
73
|
resolve();
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
78
|
}
|
|
79
|
+
export async function updateNextTag(packageName, newVersion, otp, isDryRun, registry) {
|
|
80
|
+
return updateDistTag(packageName, newVersion, TAG.NEXT, otp, isDryRun, registry);
|
|
81
|
+
}
|
|
82
|
+
export async function updatePreviousTag(packageName, oldLatestVersion, otp, isDryRun, registry) {
|
|
83
|
+
return updateDistTag(packageName, oldLatestVersion, TAG.PREVIOUS, otp, isDryRun, registry);
|
|
84
|
+
}
|