@servicetitan/startup 32.3.2 → 32.5.0
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/dist/cli/commands/get-command.d.ts.map +1 -1
- package/dist/cli/commands/get-command.js +2 -0
- package/dist/cli/commands/get-command.js.map +1 -1
- package/dist/cli/commands/init.d.ts +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +6 -5
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/install.d.ts +1 -4
- package/dist/cli/commands/install.d.ts.map +1 -1
- package/dist/cli/commands/install.js +12 -118
- package/dist/cli/commands/install.js.map +1 -1
- package/dist/cli/commands/lint.d.ts.map +1 -1
- package/dist/cli/commands/lint.js +7 -55
- package/dist/cli/commands/lint.js.map +1 -1
- package/dist/cli/commands/mfe-list.d.ts.map +1 -1
- package/dist/cli/commands/mfe-list.js +2 -1
- package/dist/cli/commands/mfe-list.js.map +1 -1
- package/dist/cli/commands/review/rules/index.d.ts.map +1 -1
- package/dist/cli/commands/review/rules/index.js +2 -0
- package/dist/cli/commands/review/rules/index.js.map +1 -1
- package/dist/cli/commands/review/rules/no-deprecated-startup-install.d.ts +7 -0
- package/dist/cli/commands/review/rules/no-deprecated-startup-install.d.ts.map +1 -0
- package/dist/cli/commands/review/rules/no-deprecated-startup-install.js +38 -0
- package/dist/cli/commands/review/rules/no-deprecated-startup-install.js.map +1 -0
- package/dist/cli/commands/review/types.d.ts +1 -0
- package/dist/cli/commands/review/types.d.ts.map +1 -1
- package/dist/cli/commands/review/types.js.map +1 -1
- package/dist/cli/commands/stylelint.d.ts +17 -0
- package/dist/cli/commands/stylelint.d.ts.map +1 -0
- package/dist/cli/commands/stylelint.js +63 -0
- package/dist/cli/commands/stylelint.js.map +1 -0
- package/dist/cli/commands/upload-sourcemaps.d.ts.map +1 -1
- package/dist/cli/commands/upload-sourcemaps.js +2 -1
- package/dist/cli/commands/upload-sourcemaps.js.map +1 -1
- package/dist/cli/utils/cli-git.d.ts +0 -9
- package/dist/cli/utils/cli-git.d.ts.map +1 -1
- package/dist/cli/utils/cli-git.js +0 -59
- package/dist/cli/utils/cli-git.js.map +1 -1
- package/dist/cli/utils/cli-npm.d.ts +0 -3
- package/dist/cli/utils/cli-npm.d.ts.map +1 -1
- package/dist/cli/utils/cli-npm.js +0 -22
- package/dist/cli/utils/cli-npm.js.map +1 -1
- package/dist/cli/utils/index.d.ts +0 -1
- package/dist/cli/utils/index.d.ts.map +1 -1
- package/dist/cli/utils/index.js +0 -1
- package/dist/cli/utils/index.js.map +1 -1
- package/dist/cli/utils/lerna-exec.d.ts.map +1 -1
- package/dist/cli/utils/lerna-exec.js +2 -2
- package/dist/cli/utils/lerna-exec.js.map +1 -1
- package/dist/cli/utils/stylelint.d.ts +8 -0
- package/dist/cli/utils/stylelint.d.ts.map +1 -0
- package/dist/cli/utils/stylelint.js +67 -0
- package/dist/cli/utils/stylelint.js.map +1 -0
- package/dist/utils/get-configuration.d.ts +1 -0
- package/dist/utils/get-configuration.d.ts.map +1 -1
- package/dist/utils/get-configuration.js +1 -0
- package/dist/utils/get-configuration.js.map +1 -1
- package/package.json +8 -9
- package/src/cli/commands/__tests__/init.test.ts +11 -14
- package/src/cli/commands/__tests__/install.test.ts +19 -224
- package/src/cli/commands/__tests__/lint.test.ts +52 -10
- package/src/cli/commands/__tests__/mfe-list.test.ts +5 -4
- package/src/cli/commands/__tests__/stylelint.test.ts +32 -0
- package/src/cli/commands/__tests__/upload-sourcemaps.test.ts +4 -7
- package/src/cli/commands/get-command.ts +2 -0
- package/src/cli/commands/init.ts +6 -4
- package/src/cli/commands/install.ts +13 -116
- package/src/cli/commands/lint.ts +5 -57
- package/src/cli/commands/mfe-list.ts +2 -1
- package/src/cli/commands/review/rules/__tests__/no-deprecated-startup-install.test.ts +81 -0
- package/src/cli/commands/review/rules/index.ts +2 -0
- package/src/cli/commands/review/rules/no-deprecated-startup-install.ts +30 -0
- package/src/cli/commands/review/types.ts +1 -0
- package/src/cli/commands/stylelint.ts +26 -0
- package/src/cli/commands/upload-sourcemaps.ts +2 -1
- package/src/cli/utils/__tests__/cli-git.test.ts +4 -140
- package/src/cli/utils/__tests__/cli-npm.test.ts +0 -43
- package/src/cli/utils/__tests__/lerna-exec.test.ts +2 -2
- package/src/cli/utils/__tests__/stylelint.test.ts +164 -0
- package/src/cli/utils/cli-git.ts +1 -52
- package/src/cli/utils/cli-npm.ts +0 -12
- package/src/cli/utils/index.ts +1 -1
- package/src/cli/utils/lerna-exec.ts +1 -1
- package/src/cli/utils/stylelint.ts +55 -0
- package/src/utils/get-configuration.ts +1 -0
- package/dist/cli/utils/is-ci.d.ts +0 -2
- package/dist/cli/utils/is-ci.d.ts.map +0 -1
- package/dist/cli/utils/is-ci.js +0 -15
- package/dist/cli/utils/is-ci.js.map +0 -1
- package/src/cli/utils/__tests__/is-ci.test.ts +0 -40
- package/src/cli/utils/is-ci.ts +0 -3
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runCommandOutput } from '../cli-os';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { isCI } from '../is-ci';
|
|
3
|
+
import { gitGetBranch, gitGetCommitHash } from '../cli-git';
|
|
5
4
|
|
|
6
|
-
jest.mock('../
|
|
7
|
-
jest.mock('../cli-os', () => ({ runCommand: jest.fn(), runCommandOutput: jest.fn() }));
|
|
5
|
+
jest.mock('../cli-os', () => ({ runCommandOutput: jest.fn() }));
|
|
8
6
|
|
|
9
7
|
describe('[startup] Cli Utils (Git)', () => {
|
|
10
8
|
beforeEach(() => {
|
|
11
|
-
jest.
|
|
12
|
-
jest.mocked(isCI).mockReturnValue(false);
|
|
9
|
+
jest.clearAllMocks();
|
|
13
10
|
});
|
|
14
11
|
|
|
15
12
|
function itRunsCommand(subject: Function, command: string) {
|
|
@@ -30,137 +27,4 @@ describe('[startup] Cli Utils (Git)', () => {
|
|
|
30
27
|
describe(gitGetCommitHash.name, () => {
|
|
31
28
|
itRunsCommand(gitGetCommitHash, 'git rev-parse --short HEAD');
|
|
32
29
|
});
|
|
33
|
-
|
|
34
|
-
describe(gitCloneRepo.name, () => {
|
|
35
|
-
const destination = 'foo';
|
|
36
|
-
const name = '{name}';
|
|
37
|
-
|
|
38
|
-
const webUrl = `https://github.com/servicetitan/${name}.git`;
|
|
39
|
-
const sshUrl = `git@github.com:servicetitan/${name}.git`;
|
|
40
|
-
|
|
41
|
-
let params: Parameters<typeof gitCloneRepo>[0];
|
|
42
|
-
|
|
43
|
-
beforeEach(() => (params = { destination, name }));
|
|
44
|
-
|
|
45
|
-
const subject = () => gitCloneRepo(params);
|
|
46
|
-
|
|
47
|
-
function itReturns(value: boolean) {
|
|
48
|
-
test(`it returns ${value}`, async () => {
|
|
49
|
-
expect(await subject()).toBe(value);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
test(`clones ${sshUrl} to destination directory`, async () => {
|
|
54
|
-
await subject();
|
|
55
|
-
|
|
56
|
-
expect(runCommand).toHaveBeenCalledWith(
|
|
57
|
-
`git clone -q ${sshUrl} ${destination}`,
|
|
58
|
-
expect.anything()
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
itReturns(true);
|
|
63
|
-
|
|
64
|
-
describe(`when cloning ${sshUrl} fails`, () => {
|
|
65
|
-
beforeEach(() => jest.mocked(runCommand).mockRejectedValueOnce('Nope!'));
|
|
66
|
-
|
|
67
|
-
test(`clones ${webUrl} to destination directory`, async () => {
|
|
68
|
-
await subject();
|
|
69
|
-
|
|
70
|
-
expect(runCommand).toHaveBeenCalledWith(`git clone -q ${webUrl} ${destination}`, {
|
|
71
|
-
quiet: true,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
73
|
-
env: expect.objectContaining({ GIT_TERMINAL_PROMPT: '0' }),
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
itReturns(true);
|
|
78
|
-
|
|
79
|
-
describe(`when cloning ${webUrl} also fails`, () => {
|
|
80
|
-
beforeEach(() => {
|
|
81
|
-
jest.mocked(runCommand).mockRejectedValue('Nope!');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
itReturns(false);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('when running in CI environment with GITHUB_TOKEN', () => {
|
|
89
|
-
const originalEnv = process.env;
|
|
90
|
-
const token = 'foo-bar';
|
|
91
|
-
|
|
92
|
-
beforeEach(() => {
|
|
93
|
-
jest.mocked(isCI).mockReturnValue(true);
|
|
94
|
-
process.env.GITHUB_TOKEN = token;
|
|
95
|
-
});
|
|
96
|
-
afterEach(() => (process.env = originalEnv));
|
|
97
|
-
|
|
98
|
-
test(`clones ${webUrl} with token to destination directory`, async () => {
|
|
99
|
-
await subject();
|
|
100
|
-
|
|
101
|
-
const urlWithToken = webUrl.replace('github.com', `oauth2:${token}@github.com`);
|
|
102
|
-
expect(runCommand).toHaveBeenCalledWith(
|
|
103
|
-
`git clone -q ${urlWithToken} ${destination}`,
|
|
104
|
-
expect.anything()
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe(gitIsReachable.name, () => {
|
|
111
|
-
const name = '{name}';
|
|
112
|
-
|
|
113
|
-
let params: Parameters<typeof gitIsReachable>[0];
|
|
114
|
-
|
|
115
|
-
beforeEach(() => (params = { name }));
|
|
116
|
-
|
|
117
|
-
const subject = () => gitIsReachable(params);
|
|
118
|
-
|
|
119
|
-
function itReturns(value: boolean) {
|
|
120
|
-
test(`it returns ${value}`, () => {
|
|
121
|
-
expect(subject()).toBe(value);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const webUrl = `https://github.com/servicetitan/${name}.git`;
|
|
126
|
-
const sshUrl = `git@github.com:servicetitan/${name}.git`;
|
|
127
|
-
|
|
128
|
-
test(`checks if ${sshUrl} is reachable`, () => {
|
|
129
|
-
subject();
|
|
130
|
-
|
|
131
|
-
expect(runCommandOutput).toHaveBeenCalledWith(`git ls-remote -qt ${sshUrl}`, {
|
|
132
|
-
quiet: true,
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
itReturns(true);
|
|
137
|
-
|
|
138
|
-
describe(`when ${sshUrl} is not reachable`, () => {
|
|
139
|
-
beforeEach(() => {
|
|
140
|
-
jest.mocked(runCommandOutput).mockImplementationOnce(() => {
|
|
141
|
-
throw new Error('Oops!');
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test(`checks if ${webUrl} is reachable`, () => {
|
|
146
|
-
subject();
|
|
147
|
-
|
|
148
|
-
expect(runCommandOutput).toHaveBeenCalledWith(`git ls-remote -qt ${webUrl}`, {
|
|
149
|
-
quiet: true,
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
itReturns(true);
|
|
154
|
-
|
|
155
|
-
describe(`when ${webUrl} is also unreachable`, () => {
|
|
156
|
-
beforeEach(() =>
|
|
157
|
-
jest.mocked(runCommandOutput).mockImplementation(() => {
|
|
158
|
-
throw new Error('Oops');
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
itReturns(false);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
30
|
});
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
npmTagVersion,
|
|
9
9
|
npmUnpublish,
|
|
10
10
|
npmView,
|
|
11
|
-
npmWhoAmI,
|
|
12
11
|
} from '../cli-npm';
|
|
13
12
|
|
|
14
13
|
jest.mock('../cli-os', () => ({
|
|
@@ -249,46 +248,4 @@ describe('[startup] Cli Utils (Npm)', () => {
|
|
|
249
248
|
});
|
|
250
249
|
});
|
|
251
250
|
});
|
|
252
|
-
|
|
253
|
-
describe(npmWhoAmI.name, () => {
|
|
254
|
-
const username = 'Foo\n';
|
|
255
|
-
let args: Parameters<typeof npmWhoAmI>[0];
|
|
256
|
-
|
|
257
|
-
beforeEach(() => {
|
|
258
|
-
args = undefined;
|
|
259
|
-
jest.mocked(runCommandOutput).mockReturnValue(username);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
const subject = () => npmWhoAmI(args);
|
|
263
|
-
|
|
264
|
-
itRunsCommandOutput(subject, 'npm whoami', {
|
|
265
|
-
quiet: true,
|
|
266
|
-
stdio: ['pipe', 'pipe', 'ignore'],
|
|
267
|
-
timeout: 10000,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
test('returns trimmed username ', () => {
|
|
271
|
-
expect(subject()).toEqual(username.trim());
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
describe('with registry', () => {
|
|
275
|
-
beforeEach(() => (args = { registry: '{registry}' }));
|
|
276
|
-
|
|
277
|
-
itRunsCommandOutput(subject, 'npm whoami --registry={registry}', expect.anything());
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
describe('when command fails', () => {
|
|
281
|
-
const error = new Error('Oops');
|
|
282
|
-
|
|
283
|
-
beforeEach(() => {
|
|
284
|
-
jest.mocked(runCommandOutput).mockImplementation(() => {
|
|
285
|
-
throw error;
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
test('ignores error and returns undefined', () => {
|
|
290
|
-
expect(subject()).toBeUndefined();
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
251
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { isCI } from '@servicetitan/install';
|
|
1
2
|
import execa from 'execa';
|
|
2
3
|
|
|
3
4
|
import { log } from '../../../utils';
|
|
4
|
-
import { isCI } from '../is-ci';
|
|
5
5
|
import { maybeCreateGitFolder } from '../maybe-create-git-folder';
|
|
6
6
|
import { lernaExec } from '../lerna-exec';
|
|
7
7
|
|
|
8
|
+
jest.mock('@servicetitan/install');
|
|
8
9
|
jest.mock('execa');
|
|
9
|
-
jest.mock('../is-ci', () => ({ isCI: jest.fn() }));
|
|
10
10
|
jest.mock('../maybe-create-git-folder', () => ({ maybeCreateGitFolder: jest.fn() }));
|
|
11
11
|
|
|
12
12
|
const AVAILABLE_PARALLELISM = 2;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { lint } from 'stylelint';
|
|
2
|
+
import { stylelint } from '../stylelint';
|
|
3
|
+
import { getDestinationFolders, getStylelintConfiguration } from '../../../utils';
|
|
4
|
+
|
|
5
|
+
jest.mock('stylelint', () => ({ lint: jest.fn() }));
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../utils', () => ({
|
|
8
|
+
...jest.requireActual('../../../utils'),
|
|
9
|
+
getDestinationFolders: jest.fn(),
|
|
10
|
+
getStylelintConfiguration: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe(`[startup] utils:${stylelint.name}`, () => {
|
|
14
|
+
const defaultFiles = '**/*.{css,scss,less}';
|
|
15
|
+
let args: Parameters<typeof stylelint>[0];
|
|
16
|
+
let linterResult: Partial<Awaited<ReturnType<typeof lint>>>;
|
|
17
|
+
let writeSpy: jest.SpyInstance;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
args = {};
|
|
21
|
+
linterResult = { report: 'report' };
|
|
22
|
+
|
|
23
|
+
jest.clearAllMocks();
|
|
24
|
+
jest.mocked(getDestinationFolders).mockReturnValue([]);
|
|
25
|
+
jest.mocked(getStylelintConfiguration).mockReturnValue({});
|
|
26
|
+
jest.mocked(lint).mockImplementation(() => Promise.resolve(linterResult) as any);
|
|
27
|
+
writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const subject = async () => stylelint(args);
|
|
31
|
+
|
|
32
|
+
test('runs linter', async () => {
|
|
33
|
+
await subject();
|
|
34
|
+
|
|
35
|
+
expect(lint).toHaveBeenCalledWith(
|
|
36
|
+
expect.objectContaining({
|
|
37
|
+
files: [defaultFiles],
|
|
38
|
+
formatter: 'string',
|
|
39
|
+
ignorePattern: ['node_modules'],
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('outputs report', async () => {
|
|
45
|
+
await subject();
|
|
46
|
+
|
|
47
|
+
expect(writeSpy).toHaveBeenCalledWith(linterResult.report);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('with output folders', () => {
|
|
51
|
+
const outputFolders = ['../foo/out/', 'dist/', 'packages/bar/out/', 'packages/foo/dist/'];
|
|
52
|
+
|
|
53
|
+
beforeEach(() => jest.mocked(getDestinationFolders).mockReturnValue(outputFolders));
|
|
54
|
+
|
|
55
|
+
test('ignores output folders', async () => {
|
|
56
|
+
await subject();
|
|
57
|
+
|
|
58
|
+
expect(lint).toHaveBeenCalledWith(
|
|
59
|
+
expect.objectContaining({
|
|
60
|
+
ignorePattern: ['node_modules', ...outputFolders],
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('with {fix: true}', () => {
|
|
67
|
+
beforeEach(() => (args.fix = true));
|
|
68
|
+
|
|
69
|
+
test('applies fixes', async () => {
|
|
70
|
+
await subject();
|
|
71
|
+
|
|
72
|
+
expect(lint).toHaveBeenCalledWith(expect.objectContaining({ fix: true }));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('with directory paths', () => {
|
|
77
|
+
beforeEach(() => (args.paths = ['packages/foo', 'packages/bar']));
|
|
78
|
+
|
|
79
|
+
test('appends glob pattern to path', async () => {
|
|
80
|
+
await subject();
|
|
81
|
+
|
|
82
|
+
expect(lint).toHaveBeenCalledWith(
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
files: args.paths!.map(path => `${path}/${defaultFiles}`),
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('with file paths', () => {
|
|
91
|
+
const allowedPaths = ['foo.css', 'bar.scss', 'baz.less'];
|
|
92
|
+
|
|
93
|
+
beforeEach(() => (args.paths = allowedPaths));
|
|
94
|
+
|
|
95
|
+
test('passes paths to linter', async () => {
|
|
96
|
+
await subject();
|
|
97
|
+
|
|
98
|
+
expect(lint).toHaveBeenCalledWith(expect.objectContaining({ files: args.paths }));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('with disallowed paths', () => {
|
|
102
|
+
const disallowedPaths = ['foo.txt', 'bar.*'];
|
|
103
|
+
|
|
104
|
+
beforeEach(() => (args.paths = [...allowedPaths, ...disallowedPaths]));
|
|
105
|
+
|
|
106
|
+
test('ignores disallowed paths', async () => {
|
|
107
|
+
await subject();
|
|
108
|
+
|
|
109
|
+
expect(lint).toHaveBeenCalledWith(expect.objectContaining({ files: allowedPaths }));
|
|
110
|
+
});
|
|
111
|
+
describe('with only disallowed paths', () => {
|
|
112
|
+
beforeEach(() => (args.paths = disallowedPaths));
|
|
113
|
+
|
|
114
|
+
test('ignores paths', async () => {
|
|
115
|
+
await subject();
|
|
116
|
+
|
|
117
|
+
expect(lint).toHaveBeenCalledWith(
|
|
118
|
+
expect.objectContaining({ files: [defaultFiles] })
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('when there are errors', () => {
|
|
126
|
+
const exitCode = process.exitCode;
|
|
127
|
+
|
|
128
|
+
beforeEach(() => (linterResult.errored = true));
|
|
129
|
+
|
|
130
|
+
afterAll(() => (process.exitCode = exitCode));
|
|
131
|
+
|
|
132
|
+
test('sets process.exitCode', async () => {
|
|
133
|
+
await subject();
|
|
134
|
+
|
|
135
|
+
expect(process.exitCode).toBeGreaterThan(0);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('when disabled', () => {
|
|
140
|
+
beforeEach(() => {
|
|
141
|
+
jest.mocked(getStylelintConfiguration).mockReturnValue({ disabled: true });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('does nothing', async () => {
|
|
145
|
+
await subject();
|
|
146
|
+
|
|
147
|
+
expect(lint).not.toHaveBeenCalled();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('with custom config', () => {
|
|
152
|
+
const config: ReturnType<typeof getStylelintConfiguration> = { ignorePath: 'foo' };
|
|
153
|
+
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
jest.mocked(getStylelintConfiguration).mockReturnValue(config);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('passes config to linter', async () => {
|
|
159
|
+
await subject();
|
|
160
|
+
|
|
161
|
+
expect(lint).toHaveBeenCalledWith(expect.objectContaining(config));
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
package/src/cli/utils/cli-git.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { runCommand, runCommandOutput } from './cli-os';
|
|
3
|
-
import { isCI } from './is-ci';
|
|
1
|
+
import { runCommandOutput } from './cli-os';
|
|
4
2
|
|
|
5
3
|
export function gitGetBranch(): string {
|
|
6
4
|
return runCommandOutput('git rev-parse --abbrev-ref HEAD').trim();
|
|
@@ -9,52 +7,3 @@ export function gitGetBranch(): string {
|
|
|
9
7
|
export function gitGetCommitHash(): string {
|
|
10
8
|
return runCommandOutput('git rev-parse --short HEAD').trim();
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
interface Repo {
|
|
14
|
-
owner?: string;
|
|
15
|
-
name: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function gitCloneRepo(params: Repo & { destination: string }) {
|
|
19
|
-
const { destination, name, owner = 'servicetitan' } = params;
|
|
20
|
-
const gitUrls = getGitUrls({ owner, name });
|
|
21
|
-
|
|
22
|
-
for (const url of gitUrls) {
|
|
23
|
-
try {
|
|
24
|
-
const command = `git clone -q ${url} ${destination}`;
|
|
25
|
-
log.debug('git:clone-repo', `running ${command}`);
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line no-await-in-loop
|
|
28
|
-
await runCommand(command, {
|
|
29
|
-
quiet: true,
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
31
|
-
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
32
|
-
});
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
// ignore error
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function gitIsReachable({ owner = 'servicetitan', name }: Repo) {
|
|
43
|
-
return getGitUrls({ owner, name }).some(url => {
|
|
44
|
-
try {
|
|
45
|
-
runCommandOutput(`git ls-remote -qt ${url}`, { quiet: true });
|
|
46
|
-
return true;
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getGitUrls({ owner, name }: Repo) {
|
|
54
|
-
const webUrl = `https://github.com/${owner}/${name}.git`;
|
|
55
|
-
const sshUrl = `git@github.com:${owner}/${name}.git`;
|
|
56
|
-
|
|
57
|
-
return isCI() && !!process.env.GITHUB_TOKEN
|
|
58
|
-
? [webUrl.replace('github.com', `oauth2:${process.env.GITHUB_TOKEN}@github.com`)]
|
|
59
|
-
: [sshUrl, webUrl];
|
|
60
|
-
}
|
package/src/cli/utils/cli-npm.ts
CHANGED
|
@@ -95,15 +95,3 @@ export function npmView({ packageName, registry }: { packageName: string; regist
|
|
|
95
95
|
// ignore
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
export function npmWhoAmI({ registry }: { registry?: string } = {}) {
|
|
100
|
-
try {
|
|
101
|
-
return runCommandOutput(['npm', 'whoami', registry ? `--registry=${registry}` : ''], {
|
|
102
|
-
quiet: true,
|
|
103
|
-
stdio: ['pipe', 'pipe', 'ignore'],
|
|
104
|
-
timeout: NPM_TIMEOUT,
|
|
105
|
-
}).trim();
|
|
106
|
-
} catch {
|
|
107
|
-
// ignore
|
|
108
|
-
}
|
|
109
|
-
}
|
package/src/cli/utils/index.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * from './compile-sass';
|
|
|
9
9
|
export * from './copy-files';
|
|
10
10
|
export * from './eslint';
|
|
11
11
|
export * from './get-module-type';
|
|
12
|
-
export * from './is-ci';
|
|
13
12
|
export * from './is-module-installed';
|
|
14
13
|
export * from './is-tty';
|
|
15
14
|
export * from './lerna-exec';
|
|
@@ -18,6 +17,7 @@ export * from './pipe-stdout';
|
|
|
18
17
|
export * from './process-tree';
|
|
19
18
|
export * from './publish';
|
|
20
19
|
export * from './set-node-options';
|
|
20
|
+
// Don't export ./stylelint, it breaks tests using the default "jsdom" environment
|
|
21
21
|
export * from './ts-config';
|
|
22
22
|
export * from './type-check';
|
|
23
23
|
export * from './watch-stdout';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { isCI } from '@servicetitan/install';
|
|
1
2
|
import execa, { StdioOption } from 'execa';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
|
|
4
5
|
import { log } from '../../utils';
|
|
5
|
-
import { isCI } from './is-ci';
|
|
6
6
|
import { maybeCreateGitFolder } from './maybe-create-git-folder';
|
|
7
7
|
|
|
8
8
|
interface Args {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { lint } from 'stylelint';
|
|
3
|
+
import { CommandArgs } from '../commands';
|
|
4
|
+
import { getDestinationFolders, getStylelintConfiguration, log } from '../../utils';
|
|
5
|
+
|
|
6
|
+
interface Args extends CommandArgs {
|
|
7
|
+
fix?: boolean;
|
|
8
|
+
paths?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const allowedExtensions = ['css', 'scss', 'less'];
|
|
12
|
+
const glob = `**/*.{${allowedExtensions.join(',')}}`;
|
|
13
|
+
|
|
14
|
+
export async function stylelint({ fix, paths = [] }: Args) {
|
|
15
|
+
const { disabled, ...config } = getStylelintConfiguration();
|
|
16
|
+
if (disabled) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const files = paths.reduce<string[]>((result, file) => {
|
|
21
|
+
const extension = path.parse(file).ext.slice(1); // drop leading dot
|
|
22
|
+
if (extension) {
|
|
23
|
+
if (allowedExtensions.includes(extension.toLowerCase())) {
|
|
24
|
+
result.push(file);
|
|
25
|
+
} else {
|
|
26
|
+
log.debug('stylelint', `ignoring ${file}`);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
result.push(pathUniJoin(file, glob));
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
const options: Parameters<typeof lint>[0] = {
|
|
35
|
+
files: files.length ? files : [glob],
|
|
36
|
+
ignorePattern: ['node_modules', ...getDestinationFolders()],
|
|
37
|
+
formatter: 'string',
|
|
38
|
+
fix,
|
|
39
|
+
quietDeprecationWarnings: true,
|
|
40
|
+
...config,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/* istanbul ignore next: debug only */
|
|
44
|
+
log.debug('stylelint', () => JSON.stringify(options, null, 2));
|
|
45
|
+
|
|
46
|
+
const { report, errored } = await lint(options);
|
|
47
|
+
process.stdout.write(report);
|
|
48
|
+
if (errored) {
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function pathUniJoin(...chunks: string[]) {
|
|
54
|
+
return path.join(...chunks).replace(/\\/g, '/');
|
|
55
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-ci.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/is-ci.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,YAEnB"}
|
package/dist/cli/utils/is-ci.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "isCI", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return isCI;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function isCI() {
|
|
12
|
-
return !!process.env.CI || !!process.env.TEAMCITY_VERSION;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=is-ci.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/utils/is-ci.ts"],"sourcesContent":["export function isCI() {\n return !!process.env.CI || !!process.env.TEAMCITY_VERSION;\n}\n"],"names":["isCI","process","env","CI","TEAMCITY_VERSION"],"mappings":";;;;+BAAgBA;;;eAAAA;;;AAAT,SAASA;IACZ,OAAO,CAAC,CAACC,QAAQC,GAAG,CAACC,EAAE,IAAI,CAAC,CAACF,QAAQC,GAAG,CAACE,gBAAgB;AAC7D"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { isCI } from '../is-ci';
|
|
2
|
-
|
|
3
|
-
describe(`[startup] Utils ${isCI.name}`, () => {
|
|
4
|
-
const originalCI = process.env.CI;
|
|
5
|
-
|
|
6
|
-
beforeAll(() => delete process.env.CI);
|
|
7
|
-
afterAll(() => (process.env.CI = originalCI));
|
|
8
|
-
|
|
9
|
-
const subject = () => isCI();
|
|
10
|
-
|
|
11
|
-
function itReturns(value: boolean) {
|
|
12
|
-
test(`returns ${value}`, () => {
|
|
13
|
-
expect(subject()).toBe(value);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
itReturns(false);
|
|
18
|
-
|
|
19
|
-
describe.each([
|
|
20
|
-
{ value: '', result: false },
|
|
21
|
-
{ value: '1', result: true },
|
|
22
|
-
])('when process.env.CI is "$value"', ({ value, result }) => {
|
|
23
|
-
beforeEach(() => (process.env.CI = value));
|
|
24
|
-
|
|
25
|
-
afterEach(() => delete process.env.CI);
|
|
26
|
-
|
|
27
|
-
itReturns(result);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe.each([
|
|
31
|
-
{ value: '', result: false },
|
|
32
|
-
{ value: '1', result: true },
|
|
33
|
-
])('when process.env.TEAMCITY_VERSION is "$value"', ({ value, result }) => {
|
|
34
|
-
beforeEach(() => (process.env.TEAMCITY_VERSION = value));
|
|
35
|
-
|
|
36
|
-
afterEach(() => delete process.env.TEAMCITY_VERSION);
|
|
37
|
-
|
|
38
|
-
itReturns(result);
|
|
39
|
-
});
|
|
40
|
-
});
|
package/src/cli/utils/is-ci.ts
DELETED