@servicetitan/startup 28.5.0 → 30.0.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/bin/index.js +1 -1
- package/dist/cli/commands/convert-eslint-config.d.ts +21 -0
- package/dist/cli/commands/convert-eslint-config.d.ts.map +1 -0
- package/dist/cli/commands/convert-eslint-config.js +235 -0
- package/dist/cli/commands/convert-eslint-config.js.map +1 -0
- package/dist/cli/commands/get-command.d.ts.map +1 -1
- package/dist/cli/commands/get-command.js +6 -0
- package/dist/cli/commands/get-command.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +4 -3
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/lint.d.ts +1 -1
- package/dist/cli/commands/lint.js +2 -2
- package/dist/cli/commands/mfe-package-clean.d.ts +5 -1
- package/dist/cli/commands/mfe-package-clean.d.ts.map +1 -1
- package/dist/cli/commands/mfe-package-clean.js +46 -36
- package/dist/cli/commands/mfe-package-clean.js.map +1 -1
- package/dist/cli/commands/mfe-package-publish.d.ts +1 -1
- package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
- package/dist/cli/commands/mfe-package-publish.js +3 -13
- package/dist/cli/commands/mfe-package-publish.js.map +1 -1
- package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
- package/dist/cli/commands/mfe-publish.js +6 -5
- package/dist/cli/commands/mfe-publish.js.map +1 -1
- package/dist/cli/commands/run-task.d.ts +13 -0
- package/dist/cli/commands/run-task.d.ts.map +1 -0
- package/dist/cli/commands/run-task.js +53 -0
- package/dist/cli/commands/run-task.js.map +1 -0
- package/dist/cli/index.js +13 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/tasks/cli-task.d.ts +16 -0
- package/dist/cli/tasks/cli-task.d.ts.map +1 -0
- package/dist/cli/tasks/cli-task.js +58 -0
- package/dist/cli/tasks/cli-task.js.map +1 -0
- package/dist/cli/tasks/swc-compile-package.d.ts +12 -0
- package/dist/cli/tasks/swc-compile-package.d.ts.map +1 -0
- package/dist/cli/tasks/swc-compile-package.js +66 -0
- package/dist/cli/tasks/swc-compile-package.js.map +1 -0
- package/dist/cli/tasks/task.d.ts +42 -0
- package/dist/cli/tasks/task.d.ts.map +1 -0
- package/dist/cli/tasks/task.js +113 -0
- package/dist/cli/tasks/task.js.map +1 -0
- package/dist/cli/tasks/tsc-compile-package.d.ts +12 -0
- package/dist/cli/tasks/tsc-compile-package.d.ts.map +1 -0
- package/dist/cli/tasks/tsc-compile-package.js +42 -0
- package/dist/cli/tasks/tsc-compile-package.js.map +1 -0
- package/dist/cli/tasks/tsc-compile.d.ts +16 -0
- package/dist/cli/tasks/tsc-compile.d.ts.map +1 -0
- package/dist/cli/tasks/tsc-compile.js +48 -0
- package/dist/cli/tasks/tsc-compile.js.map +1 -0
- package/dist/cli/utils/bundle.js +1 -1
- package/dist/cli/utils/bundle.js.map +1 -1
- package/dist/cli/utils/cli-npm.d.ts +10 -3
- package/dist/cli/utils/cli-npm.d.ts.map +1 -1
- package/dist/cli/utils/cli-npm.js +13 -15
- package/dist/cli/utils/cli-npm.js.map +1 -1
- package/dist/cli/utils/cli-os.d.ts.map +1 -1
- package/dist/cli/utils/cli-os.js +2 -2
- package/dist/cli/utils/cli-os.js.map +1 -1
- package/dist/cli/utils/eslint.d.ts.map +1 -1
- package/dist/cli/utils/eslint.js +13 -12
- package/dist/cli/utils/eslint.js.map +1 -1
- package/dist/cli/utils/is-module-installed.js +1 -1
- package/dist/cli/utils/is-module-installed.js.map +1 -1
- package/dist/cli/utils/publish.d.ts.map +1 -1
- package/dist/cli/utils/tsc.d.ts +3 -2
- package/dist/cli/utils/tsc.d.ts.map +1 -1
- package/dist/cli/utils/tsc.js +20 -16
- package/dist/cli/utils/tsc.js.map +1 -1
- package/dist/utils/get-configuration.d.ts +3 -1
- package/dist/utils/get-configuration.d.ts.map +1 -1
- package/dist/utils/get-configuration.js +2 -0
- package/dist/utils/get-configuration.js.map +1 -1
- package/dist/utils/get-destination-folders.d.ts.map +1 -1
- package/dist/utils/get-destination-folders.js +9 -13
- package/dist/utils/get-destination-folders.js.map +1 -1
- package/dist/utils/get-folders.js +2 -2
- package/dist/utils/get-folders.js.map +1 -1
- package/dist/utils/get-jest-config.d.ts.map +1 -1
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/log.d.ts.map +1 -1
- package/dist/utils/log.js +3 -0
- package/dist/utils/log.js.map +1 -1
- package/dist/webpack/configs/plugins/ignore-plugin/check-resource.d.ts.map +1 -1
- package/dist/webpack/configs/plugins/ignore-plugin/check-resource.js +1 -1
- package/dist/webpack/configs/plugins/ignore-plugin/check-resource.js.map +1 -1
- package/dist/webpack/utils/hash-mod.d.ts.map +1 -1
- package/dist/webpack/utils/testing/execute.d.ts.map +1 -1
- package/dist/webpack/utils/testing/get-compiler.d.ts.map +1 -1
- package/package.json +28 -24
- package/src/cli/commands/__tests__/convert-eslint-config.test.ts +455 -0
- package/src/cli/commands/__tests__/lint.test.ts +2 -2
- package/src/cli/commands/__tests__/mfe-package-clean.test.ts +143 -73
- package/src/cli/commands/__tests__/mfe-package-publish.test.ts +27 -20
- package/src/cli/commands/__tests__/mfe-publish.test.ts +18 -7
- package/src/cli/commands/convert-eslint-config.ts +289 -0
- package/src/cli/commands/get-command.ts +6 -0
- package/src/cli/commands/init.ts +4 -3
- package/src/cli/commands/lint.ts +3 -3
- package/src/cli/commands/mfe-package-clean.ts +53 -52
- package/src/cli/commands/mfe-package-publish.ts +7 -21
- package/src/cli/commands/mfe-publish.ts +6 -5
- package/src/cli/commands/run-task.ts +41 -0
- package/src/cli/index.ts +16 -4
- package/src/cli/tasks/__tests__/cli-task.test.ts +115 -0
- package/src/cli/tasks/__tests__/swc-compile.test.ts +192 -0
- package/src/cli/tasks/__tests__/task.test.ts +88 -0
- package/src/cli/tasks/__tests__/tsc-compile-package.test.ts +72 -0
- package/src/cli/tasks/__tests__/tsc-compile.test.ts +156 -0
- package/src/cli/tasks/cli-task.ts +64 -0
- package/src/cli/tasks/swc-cli.d.ts +3 -0
- package/src/cli/tasks/swc-compile-package.ts +70 -0
- package/src/cli/tasks/task.ts +112 -0
- package/src/cli/tasks/tsc-compile-package.ts +47 -0
- package/src/cli/tasks/tsc-compile.ts +64 -0
- package/src/cli/utils/__tests__/assets-copy.test.ts +1 -1
- package/src/cli/utils/__tests__/bundle.test.ts +1 -1
- package/src/cli/utils/__tests__/cli-npm.test.ts +39 -26
- package/src/cli/utils/__tests__/cli-os.test.ts +2 -2
- package/src/cli/utils/__tests__/eslint.test.ts +37 -8
- package/src/cli/utils/__tests__/styles-copy.test.ts +1 -1
- package/src/cli/utils/__tests__/tsc.test.ts +34 -55
- package/src/cli/utils/bundle.ts +1 -1
- package/src/cli/utils/cli-npm.ts +25 -16
- package/src/cli/utils/cli-os.ts +2 -2
- package/src/cli/utils/eslint.ts +16 -13
- package/src/cli/utils/is-module-installed.ts +1 -1
- package/src/cli/utils/tsc.ts +25 -20
- package/src/utils/__tests__/get-destination-folders.test.ts +1 -1
- package/src/utils/__tests__/get-folders.test.ts +6 -18
- package/src/utils/__tests__/log.test.ts +6 -0
- package/src/utils/get-configuration.ts +2 -0
- package/src/utils/get-destination-folders.ts +11 -17
- package/src/utils/get-folders.ts +2 -2
- package/src/utils/log.ts +4 -0
- package/src/webpack/configs/plugins/ignore-plugin/check-resource.ts +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { log, logErrors } from '../../utils';
|
|
2
|
+
import { Command } from './types';
|
|
3
|
+
import { SwcCompilePackage } from '../tasks/swc-compile-package';
|
|
4
|
+
import { TscCompilePackage } from '../tasks/tsc-compile-package';
|
|
5
|
+
import { TscCompile } from '../tasks/tsc-compile';
|
|
6
|
+
import { Task } from '../tasks/task';
|
|
7
|
+
|
|
8
|
+
interface Args {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
+
_: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const tasks: Record<string, new (args: Args) => Task> = {
|
|
15
|
+
'tsc-compile-package': TscCompilePackage,
|
|
16
|
+
'swc-compile-package': SwcCompilePackage,
|
|
17
|
+
'tsc-compile': TscCompile,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export class RunTask implements Command {
|
|
21
|
+
constructor(private readonly args: Args) {}
|
|
22
|
+
|
|
23
|
+
description() {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@logErrors
|
|
28
|
+
async execute() {
|
|
29
|
+
const taskName = this.args._[0];
|
|
30
|
+
|
|
31
|
+
if (taskName in tasks) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
33
|
+
const trimArgs = { ...this.args, _: this.args._.slice(1) };
|
|
34
|
+
await new tasks[taskName](trimArgs).execute();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
log.error(`Unknown task: "${taskName}"`);
|
|
39
|
+
log.text(`\nSupported tasks: "${Object.keys(tasks).join('", "')}"`);
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import execa from 'execa';
|
|
2
|
+
import path from 'path';
|
|
2
3
|
import { argv, Arguments } from 'yargs';
|
|
3
4
|
import { CommandName, getStartupVersion, log } from '../utils';
|
|
4
5
|
import { getCommand, getUserCommands } from './commands';
|
|
@@ -20,6 +21,7 @@ if (!Command) {
|
|
|
20
21
|
process.exit(127);
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
checkNodeVersion();
|
|
23
25
|
maybeCreateGitFolder(Command);
|
|
24
26
|
|
|
25
27
|
if (setNodeOptions(name)) {
|
|
@@ -36,15 +38,25 @@ if (setNodeOptions(name)) {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
function usage() {
|
|
39
|
-
|
|
41
|
+
log.text('\nUsage:');
|
|
40
42
|
|
|
41
43
|
const commands = getUserCommands().filter(({ name }) => !!name);
|
|
42
44
|
const maxNameLength = commands.reduce((result, { name }) => Math.max(result, name.length), 0);
|
|
43
45
|
commands.forEach(({ name, description }) => {
|
|
44
|
-
|
|
46
|
+
log.text(`startup ${name.padEnd(maxNameLength, ' ')} ${description}`);
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
+
function checkNodeVersion() {
|
|
51
|
+
const nodeVersion = Number(process.versions.node.split('.')[0]);
|
|
52
|
+
if (nodeVersion % 2 === 0 || process.env.SKIP_NODE_VERSION_CHECK) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { engines } = require(path.join(__dirname, '../../package.json'));
|
|
57
|
+
log.error(
|
|
58
|
+
`error: node v${nodeVersion} detected, only even-numbered LTS versions ${engines.node} are supported`
|
|
59
|
+
);
|
|
60
|
+
log.text('See https://nodejs.org/en/download for LTS versions');
|
|
61
|
+
process.exit(127);
|
|
50
62
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import execa from 'execa';
|
|
2
|
+
import { log } from '../../../utils';
|
|
3
|
+
import { CliTask, Indicators } from '../cli-task';
|
|
4
|
+
|
|
5
|
+
jest.mock('execa', () =>
|
|
6
|
+
jest.fn().mockReturnValue(
|
|
7
|
+
Object.assign(Promise.resolve(), {
|
|
8
|
+
stdout: {
|
|
9
|
+
on: jest.fn(),
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
jest.mock('../../../utils', () => ({
|
|
16
|
+
getFolders: jest.fn().mockReturnValue({
|
|
17
|
+
source: 'src',
|
|
18
|
+
destination: 'dist',
|
|
19
|
+
}),
|
|
20
|
+
log: { info: jest.fn() },
|
|
21
|
+
readJsonSafe: jest.fn().mockReturnValue({}),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const taskName = 'cli-task-impl';
|
|
25
|
+
const indicators: Required<Indicators> = {
|
|
26
|
+
end: 'Watching for file changes.',
|
|
27
|
+
watchStart: 'Starting incremental compilation.',
|
|
28
|
+
watchEnd: 'Watching changes.',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class CliTaskImpl extends CliTask {
|
|
32
|
+
constructor({ watch }: { watch: boolean }) {
|
|
33
|
+
super({ name: taskName, global: false, watch, indicators });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
description() {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async execute(): Promise<void> {
|
|
41
|
+
await this.runChildProcess('', []);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe(`[startup] ${CliTask.name} task`, () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
globalThis.performance.clearMarks();
|
|
48
|
+
globalThis.performance.clearMeasures();
|
|
49
|
+
jest.clearAllMocks();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
let watch = false;
|
|
53
|
+
|
|
54
|
+
const subject = () => new CliTaskImpl({ watch }).execute();
|
|
55
|
+
|
|
56
|
+
test('logs completion message', async () => {
|
|
57
|
+
await subject();
|
|
58
|
+
|
|
59
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
60
|
+
expect.stringContaining(`${taskName} task completed in`)
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('in watch mode', () => {
|
|
65
|
+
beforeEach(() => (watch = true));
|
|
66
|
+
|
|
67
|
+
describe('onData handler', () => {
|
|
68
|
+
beforeEach(() => subject());
|
|
69
|
+
|
|
70
|
+
const onDataHandler = (data: string) => {
|
|
71
|
+
jest.mocked(jest.mocked(execa).mock.results[0].value.stdout.on).mock.calls[0][1](
|
|
72
|
+
data
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function itLogsInitialBuild(event: keyof Indicators) {
|
|
77
|
+
test('logs duration of initial build', () => {
|
|
78
|
+
onDataHandler(indicators[event]);
|
|
79
|
+
|
|
80
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
81
|
+
expect.stringContaining(`Initial ${taskName} task completed in`)
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function itLogsSubsequentBuild(event: keyof Indicators) {
|
|
87
|
+
test('logs duration of subsequent build', () => {
|
|
88
|
+
onDataHandler(indicators[event]!);
|
|
89
|
+
|
|
90
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
91
|
+
expect.stringContaining(`Subsequent ${taskName} task completed in`)
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
itLogsInitialBuild('end');
|
|
97
|
+
|
|
98
|
+
describe('when subsequent build starts after initial build ends', () => {
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
onDataHandler(indicators.end);
|
|
101
|
+
onDataHandler(indicators.watchStart);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
itLogsSubsequentBuild('end');
|
|
105
|
+
itLogsSubsequentBuild('watchEnd');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('when subsequent build starts before initial build ends', () => {
|
|
109
|
+
beforeEach(() => onDataHandler(indicators.watchStart));
|
|
110
|
+
|
|
111
|
+
itLogsSubsequentBuild('watchEnd');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { swcDir } from '@swc/cli';
|
|
2
|
+
import { log, readJson } from '../../../utils';
|
|
3
|
+
import { SwcCompilePackage } from '../swc-compile-package';
|
|
4
|
+
import { compilerOptions } from '../../../../tsconfig/base.json';
|
|
5
|
+
|
|
6
|
+
jest.mock('@swc/cli', () => ({
|
|
7
|
+
swcDir: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('../../../utils', () => ({
|
|
11
|
+
getFolders: jest.fn().mockReturnValue({
|
|
12
|
+
source: 'src',
|
|
13
|
+
destination: 'dist',
|
|
14
|
+
}),
|
|
15
|
+
log: { info: jest.fn(), text: jest.fn() },
|
|
16
|
+
readJsonSafe: jest.fn().mockReturnValue({}),
|
|
17
|
+
readJson: jest.fn().mockReturnValue({}),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
describe(`[startup] ${SwcCompilePackage.name} task`, () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
globalThis.performance.clearMarks();
|
|
23
|
+
globalThis.performance.clearMeasures();
|
|
24
|
+
jest.clearAllMocks();
|
|
25
|
+
jest.restoreAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let watch = false;
|
|
29
|
+
|
|
30
|
+
const subject = () => new SwcCompilePackage({ watch }).execute();
|
|
31
|
+
|
|
32
|
+
const onSuccessHandlerParams = {
|
|
33
|
+
duration: 10,
|
|
34
|
+
};
|
|
35
|
+
const callOnSuccessHandler = (parameters: { duration: number }) => {
|
|
36
|
+
jest.mocked(swcDir).mock.calls[0][0].callbacks.onSuccess(parameters);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const onFailHandlerParams = {
|
|
40
|
+
duration: 10,
|
|
41
|
+
reasons: new Map([['index.js', 'Syntax error']]),
|
|
42
|
+
};
|
|
43
|
+
const callOnFailHandler = (parameters: { duration: number; reasons: Map<string, string> }) => {
|
|
44
|
+
jest.mocked(swcDir).mock.calls[0][0].callbacks.onFail(parameters);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
test('calls swcDir', () => {
|
|
48
|
+
subject();
|
|
49
|
+
|
|
50
|
+
expect(swcDir).toHaveBeenCalledWith({
|
|
51
|
+
cliOptions: {
|
|
52
|
+
watch: false,
|
|
53
|
+
outDir: 'dist',
|
|
54
|
+
stripLeadingPaths: true,
|
|
55
|
+
extensions: ['.ts', '.tsx'],
|
|
56
|
+
filenames: ['src'],
|
|
57
|
+
},
|
|
58
|
+
swcOptions: {
|
|
59
|
+
jsc: {
|
|
60
|
+
parser: {
|
|
61
|
+
syntax: 'typescript',
|
|
62
|
+
tsx: true,
|
|
63
|
+
decorators: true,
|
|
64
|
+
},
|
|
65
|
+
target: compilerOptions.target,
|
|
66
|
+
transform: {
|
|
67
|
+
legacyDecorator: compilerOptions.experimentalDecorators,
|
|
68
|
+
decoratorMetadata: compilerOptions.emitDecoratorMetadata,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
sourceMaps: compilerOptions.sourceMap,
|
|
72
|
+
module: {
|
|
73
|
+
type: 'es6',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
callbacks: {
|
|
77
|
+
onSuccess: expect.any(Function),
|
|
78
|
+
onFail: expect.any(Function),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('when package is commonjs', () => {
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
jest.mocked(readJson).mockReturnValueOnce({
|
|
86
|
+
compilerOptions: { module: 'commonjs' },
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('swc module type is commonjs', () => {
|
|
91
|
+
subject();
|
|
92
|
+
|
|
93
|
+
expect(swcDir).toHaveBeenCalledWith(
|
|
94
|
+
expect.objectContaining({
|
|
95
|
+
swcOptions: expect.objectContaining({
|
|
96
|
+
module: { type: 'commonjs' },
|
|
97
|
+
}),
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('onSuccess handler completes task and logs completion message', async () => {
|
|
104
|
+
const task = subject();
|
|
105
|
+
|
|
106
|
+
callOnSuccessHandler(onSuccessHandlerParams);
|
|
107
|
+
|
|
108
|
+
await task;
|
|
109
|
+
|
|
110
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
111
|
+
expect.stringMatching(
|
|
112
|
+
`swc-compile-package task completed in ${onSuccessHandlerParams.duration}ms`
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('onFail handler fails task and logs completion message', async () => {
|
|
118
|
+
const task = subject();
|
|
119
|
+
|
|
120
|
+
callOnFailHandler(onFailHandlerParams);
|
|
121
|
+
|
|
122
|
+
await expect(task).rejects.toThrow('Compilation failed');
|
|
123
|
+
|
|
124
|
+
expect(log.text).toHaveBeenCalledWith('Syntax error');
|
|
125
|
+
|
|
126
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
127
|
+
expect.stringMatching(
|
|
128
|
+
`swc-compile-package task completed in ${onFailHandlerParams.duration}ms`
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('in watch mode', () => {
|
|
134
|
+
beforeEach(() => (watch = true));
|
|
135
|
+
|
|
136
|
+
test('calls swcDir with watch=true', () => {
|
|
137
|
+
subject();
|
|
138
|
+
|
|
139
|
+
expect(swcDir).toHaveBeenCalledWith(
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
cliOptions: expect.objectContaining({
|
|
142
|
+
watch: true,
|
|
143
|
+
}),
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('onSuccess handler logs completion messages', () => {
|
|
149
|
+
subject();
|
|
150
|
+
|
|
151
|
+
callOnSuccessHandler(onSuccessHandlerParams);
|
|
152
|
+
|
|
153
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
154
|
+
expect.stringMatching(
|
|
155
|
+
`Initial swc-compile-package task completed in ${onSuccessHandlerParams.duration}ms`
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
callOnSuccessHandler(onSuccessHandlerParams);
|
|
160
|
+
|
|
161
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
162
|
+
expect.stringMatching(
|
|
163
|
+
`Subsequent swc-compile-package task completed in ${onSuccessHandlerParams.duration}ms`
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('onFail handler logs completion message', () => {
|
|
169
|
+
subject();
|
|
170
|
+
|
|
171
|
+
callOnFailHandler(onFailHandlerParams);
|
|
172
|
+
|
|
173
|
+
expect(log.text).toHaveBeenCalledWith('Syntax error');
|
|
174
|
+
|
|
175
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
176
|
+
expect.stringMatching(
|
|
177
|
+
`Initial swc-compile-package task completed in ${onFailHandlerParams.duration}ms`
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
callOnFailHandler(onFailHandlerParams);
|
|
182
|
+
|
|
183
|
+
expect(log.text).toHaveBeenCalledWith('Syntax error');
|
|
184
|
+
|
|
185
|
+
expect(log.info).toHaveBeenCalledWith(
|
|
186
|
+
expect.stringMatching(
|
|
187
|
+
`Subsequent swc-compile-package task completed in ${onFailHandlerParams.duration}ms`
|
|
188
|
+
)
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { readJsonSafe } from '../../../utils';
|
|
2
|
+
import { Task } from '../task';
|
|
3
|
+
|
|
4
|
+
jest.mock('../../../utils', () => ({
|
|
5
|
+
readJsonSafe: jest.fn().mockReturnValue({}),
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
class GlobalTask extends Task {
|
|
9
|
+
constructor() {
|
|
10
|
+
super({ name: 'GlobalTask', watch: false, global: true });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
description() {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
execute() {
|
|
18
|
+
return Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class PackageTask extends Task {
|
|
23
|
+
constructor() {
|
|
24
|
+
super({ name: 'PackageTask', watch: false, global: false });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
description() {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
execute() {
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe(`[startup] ${Task.name} entity`, () => {
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
globalThis.performance.clearMarks();
|
|
39
|
+
globalThis.performance.clearMeasures();
|
|
40
|
+
jest.clearAllMocks();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('Global task', () => {
|
|
44
|
+
const subject = () => new GlobalTask();
|
|
45
|
+
|
|
46
|
+
test('runs from the workspace root directory', () => {
|
|
47
|
+
jest.mocked(readJsonSafe).mockReturnValueOnce({
|
|
48
|
+
workspaces: ['packages/*'],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(subject).not.toThrow();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("doesn't run from the package directory", () => {
|
|
55
|
+
jest.mocked(readJsonSafe).mockReturnValueOnce({});
|
|
56
|
+
|
|
57
|
+
expect(subject).toThrow();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("doesn't run from the arbitrary directory", () => {
|
|
61
|
+
jest.mocked(readJsonSafe).mockReturnValueOnce(undefined);
|
|
62
|
+
|
|
63
|
+
expect(subject).toThrow();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('Package task', () => {
|
|
68
|
+
const subject = () => new PackageTask();
|
|
69
|
+
|
|
70
|
+
test('runs from the package directory', () => {
|
|
71
|
+
jest.mocked(readJsonSafe).mockReturnValueOnce({});
|
|
72
|
+
|
|
73
|
+
expect(subject).not.toThrow();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("doesn't run from the workspace root directory", () => {
|
|
77
|
+
jest.mocked(readJsonSafe).mockReturnValueOnce({ workspaces: ['packages/*'] });
|
|
78
|
+
|
|
79
|
+
expect(subject).toThrow();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("doesn't run from arbitrary directory", () => {
|
|
83
|
+
jest.mocked(readJsonSafe).mockReturnValueOnce(undefined);
|
|
84
|
+
|
|
85
|
+
expect(subject).toThrow();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import execa from 'execa';
|
|
2
|
+
import { TscCompilePackage } from '../tsc-compile-package';
|
|
3
|
+
|
|
4
|
+
jest.mock('execa', () =>
|
|
5
|
+
jest.fn().mockReturnValue(
|
|
6
|
+
Object.assign(Promise.resolve(), {
|
|
7
|
+
stdout: {
|
|
8
|
+
on: jest.fn(),
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const tsConfig = 'tsconfig.build.json';
|
|
15
|
+
|
|
16
|
+
const tscOptions = [
|
|
17
|
+
'--pretty',
|
|
18
|
+
'--preserveWatchOutput',
|
|
19
|
+
'--noCheck',
|
|
20
|
+
'--composite',
|
|
21
|
+
'false',
|
|
22
|
+
'--declaration',
|
|
23
|
+
'false',
|
|
24
|
+
'--declarationMap',
|
|
25
|
+
'false',
|
|
26
|
+
'--tsBuildInfoFile',
|
|
27
|
+
'tsconfig.compile.tsbuildinfo',
|
|
28
|
+
'--project',
|
|
29
|
+
tsConfig,
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
jest.mock('../../../utils', () => ({
|
|
33
|
+
getFolders: jest.fn().mockReturnValue({
|
|
34
|
+
source: 'src',
|
|
35
|
+
destination: 'dist',
|
|
36
|
+
}),
|
|
37
|
+
log: { info: jest.fn() },
|
|
38
|
+
readJsonSafe: jest.fn().mockReturnValue({}),
|
|
39
|
+
getTsConfig: () => tsConfig,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
describe(`[startup] ${TscCompilePackage.name} task`, () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
globalThis.performance.clearMarks();
|
|
45
|
+
globalThis.performance.clearMeasures();
|
|
46
|
+
jest.clearAllMocks();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
let watch = false;
|
|
50
|
+
|
|
51
|
+
const subject = () => new TscCompilePackage({ watch }).execute();
|
|
52
|
+
|
|
53
|
+
test('calls execa', () => {
|
|
54
|
+
subject();
|
|
55
|
+
|
|
56
|
+
expect(execa).toHaveBeenCalledWith('tsc', tscOptions, {
|
|
57
|
+
stdio: 'inherit',
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('in watch mode', () => {
|
|
62
|
+
beforeEach(() => (watch = true));
|
|
63
|
+
|
|
64
|
+
test('calls execa', () => {
|
|
65
|
+
subject();
|
|
66
|
+
|
|
67
|
+
expect(execa).toHaveBeenCalledWith('tsc', ['-w', ...tscOptions], {
|
|
68
|
+
stdio: ['inherit', 'pipe', 'inherit'],
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|