@toptal/davinci-engine 10.5.5 → 10.5.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 +13 -0
- package/bin/davinci-engine.js +2 -21
- package/package.json +3 -3
- package/src/commands/__snapshots__/analyze.test.js.snap +44 -6
- package/src/commands/__snapshots__/build.test.js.snap +122 -23
- package/src/commands/__snapshots__/compile-package.test.js.snap +89 -16
- package/src/commands/__snapshots__/publish-package.test.js.snap +94 -17
- package/src/commands/__snapshots__/release-package.test.js.snap +94 -17
- package/src/commands/__snapshots__/sentry-upload-sourcemaps.test.js.snap +54 -9
- package/src/commands/__snapshots__/size.test.js.snap +64 -11
- package/src/commands/analyze.js +10 -15
- package/src/commands/analyze.test.js +21 -4
- package/src/commands/build.js +50 -66
- package/src/commands/build.test.js +11 -5
- package/src/commands/compile-package.js +58 -69
- package/src/commands/compile-package.test.js +21 -4
- package/src/commands/publish-package.js +44 -63
- package/src/commands/publish-package.test.js +15 -4
- package/src/commands/release-package.js +35 -41
- package/src/commands/release-package.test.js +20 -4
- package/src/commands/sentry-upload-sourcemaps.js +12 -25
- package/src/commands/sentry-upload-sourcemaps.test.js +23 -4
- package/src/commands/size.js +15 -33
- package/src/commands/size.test.js +21 -4
- package/src/index.js +14 -14
|
@@ -1,15 +1,60 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
4
|
-
{
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
3
|
+
exports[`createSentryUploadSourceMapsCommand creates a command with the correct parameters 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 1,
|
|
7
|
+
"commands": [],
|
|
8
8
|
"options": [
|
|
9
9
|
{
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
10
|
+
"flags": "--url-prefix <prefix>",
|
|
11
|
+
"description": "This sets URL prefix in front of all files. This defaults to the path where your production build is set e.g. '~/static/js' inside \`dist\` directory. This is also useful if your files are stored in a sub folder when deployed. eg: --url-prefix '~/blackfish/ui'.",
|
|
12
|
+
"required": true,
|
|
13
|
+
"optional": false,
|
|
14
|
+
"variadic": false,
|
|
15
|
+
"mandatory": false,
|
|
16
|
+
"long": "--url-prefix",
|
|
17
|
+
"negate": false,
|
|
18
|
+
"hidden": false,
|
|
19
|
+
"conflictsWith": []
|
|
20
|
+
}
|
|
13
21
|
],
|
|
14
|
-
|
|
22
|
+
"parent": null,
|
|
23
|
+
"_allowUnknownOption": false,
|
|
24
|
+
"_allowExcessArguments": true,
|
|
25
|
+
"_args": [],
|
|
26
|
+
"args": [],
|
|
27
|
+
"rawArgs": [],
|
|
28
|
+
"processedArgs": [],
|
|
29
|
+
"_scriptPath": null,
|
|
30
|
+
"_name": "sentry-upload-source-maps",
|
|
31
|
+
"_optionValues": {},
|
|
32
|
+
"_optionValueSources": {},
|
|
33
|
+
"_storeOptionsAsProperties": false,
|
|
34
|
+
"_executableHandler": false,
|
|
35
|
+
"_executableFile": null,
|
|
36
|
+
"_executableDir": null,
|
|
37
|
+
"_defaultCommandName": null,
|
|
38
|
+
"_exitCallback": null,
|
|
39
|
+
"_aliases": [],
|
|
40
|
+
"_combineFlagAndOptionalValue": true,
|
|
41
|
+
"_description": "Upload source maps to Sentry",
|
|
42
|
+
"_summary": "",
|
|
43
|
+
"_enablePositionalOptions": false,
|
|
44
|
+
"_passThroughOptions": false,
|
|
45
|
+
"_lifeCycleHooks": {},
|
|
46
|
+
"_showHelpAfterError": false,
|
|
47
|
+
"_showSuggestionAfterError": true,
|
|
48
|
+
"_outputConfiguration": {},
|
|
49
|
+
"_hidden": false,
|
|
50
|
+
"_hasHelpOption": true,
|
|
51
|
+
"_helpFlags": "-h, --help",
|
|
52
|
+
"_helpDescription": "display help for command",
|
|
53
|
+
"_helpShortFlag": "-h",
|
|
54
|
+
"_helpLongFlag": "--help",
|
|
55
|
+
"_helpCommandName": "help",
|
|
56
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
57
|
+
"_helpCommandDescription": "display help for command",
|
|
58
|
+
"_helpConfiguration": {}
|
|
59
|
+
}"
|
|
15
60
|
`;
|
|
@@ -1,19 +1,72 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
4
|
-
{
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
3
|
+
exports[`createSizeCommand creates a command with the correct parameters 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 2,
|
|
7
|
+
"commands": [],
|
|
8
8
|
"options": [
|
|
9
9
|
{
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"flags": "--limit <limit>",
|
|
11
|
+
"description": "limit to check the size against: 2.5Mb, 1337Kb, etc",
|
|
12
|
+
"required": true,
|
|
13
|
+
"optional": false,
|
|
14
|
+
"variadic": false,
|
|
15
|
+
"mandatory": false,
|
|
16
|
+
"long": "--limit",
|
|
17
|
+
"negate": false,
|
|
18
|
+
"hidden": false,
|
|
19
|
+
"conflictsWith": []
|
|
12
20
|
},
|
|
13
21
|
{
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
22
|
+
"flags": "--maxChunkSize <maxChunkSize>",
|
|
23
|
+
"description": "max allowed chunk size: 100Kb, 1Mb, etc",
|
|
24
|
+
"required": true,
|
|
25
|
+
"optional": false,
|
|
26
|
+
"variadic": false,
|
|
27
|
+
"mandatory": false,
|
|
28
|
+
"long": "--maxChunkSize",
|
|
29
|
+
"negate": false,
|
|
30
|
+
"hidden": false,
|
|
31
|
+
"conflictsWith": []
|
|
32
|
+
}
|
|
17
33
|
],
|
|
18
|
-
|
|
34
|
+
"parent": null,
|
|
35
|
+
"_allowUnknownOption": false,
|
|
36
|
+
"_allowExcessArguments": true,
|
|
37
|
+
"_args": [],
|
|
38
|
+
"args": [],
|
|
39
|
+
"rawArgs": [],
|
|
40
|
+
"processedArgs": [],
|
|
41
|
+
"_scriptPath": null,
|
|
42
|
+
"_name": "size",
|
|
43
|
+
"_optionValues": {},
|
|
44
|
+
"_optionValueSources": {},
|
|
45
|
+
"_storeOptionsAsProperties": false,
|
|
46
|
+
"_executableHandler": false,
|
|
47
|
+
"_executableFile": null,
|
|
48
|
+
"_executableDir": null,
|
|
49
|
+
"_defaultCommandName": null,
|
|
50
|
+
"_exitCallback": null,
|
|
51
|
+
"_aliases": [],
|
|
52
|
+
"_combineFlagAndOptionalValue": true,
|
|
53
|
+
"_description": "Checks the bundle size against provided limit — fails if limit is exceeded.",
|
|
54
|
+
"_summary": "",
|
|
55
|
+
"_enablePositionalOptions": false,
|
|
56
|
+
"_passThroughOptions": false,
|
|
57
|
+
"_lifeCycleHooks": {},
|
|
58
|
+
"_showHelpAfterError": false,
|
|
59
|
+
"_showSuggestionAfterError": true,
|
|
60
|
+
"_outputConfiguration": {},
|
|
61
|
+
"_hidden": false,
|
|
62
|
+
"_hasHelpOption": true,
|
|
63
|
+
"_helpFlags": "-h, --help",
|
|
64
|
+
"_helpDescription": "display help for command",
|
|
65
|
+
"_helpShortFlag": "-h",
|
|
66
|
+
"_helpLongFlag": "--help",
|
|
67
|
+
"_helpCommandName": "help",
|
|
68
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
69
|
+
"_helpCommandDescription": "display help for command",
|
|
70
|
+
"_helpConfiguration": {}
|
|
71
|
+
}"
|
|
19
72
|
`;
|
package/src/commands/analyze.js
CHANGED
|
@@ -3,19 +3,15 @@ import { print } from '@toptal/davinci-cli-shared'
|
|
|
3
3
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
4
4
|
|
|
5
5
|
import { getWebpackConfig } from '../utils/index.js'
|
|
6
|
-
|
|
7
6
|
const printError = err => {
|
|
8
7
|
print.red(err.stack || err)
|
|
9
|
-
|
|
10
8
|
if (err.details) {
|
|
11
9
|
print.red(err.details)
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
const analyze = async () => {
|
|
16
13
|
process.env.BABEL_ENV = 'production'
|
|
17
14
|
process.env.NODE_ENV = 'production'
|
|
18
|
-
|
|
19
15
|
const config = await getWebpackConfig({
|
|
20
16
|
webpackEnv: 'production',
|
|
21
17
|
})
|
|
@@ -31,9 +27,11 @@ const analyze = async () => {
|
|
|
31
27
|
|
|
32
28
|
return reject(err)
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
console.log(
|
|
31
|
+
stats.toString({
|
|
32
|
+
colors: true,
|
|
33
|
+
})
|
|
34
|
+
)
|
|
37
35
|
compiler.close(closeErr => {
|
|
38
36
|
if (closeErr) {
|
|
39
37
|
printError(closeErr)
|
|
@@ -44,10 +42,8 @@ const analyze = async () => {
|
|
|
44
42
|
})
|
|
45
43
|
})
|
|
46
44
|
}
|
|
47
|
-
|
|
48
45
|
const analyzeCommand = async () => {
|
|
49
46
|
print.header('Creating a production build with bundle analysis')
|
|
50
|
-
|
|
51
47
|
try {
|
|
52
48
|
await analyze()
|
|
53
49
|
} catch (e) {
|
|
@@ -55,10 +51,9 @@ const analyzeCommand = async () => {
|
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
export const createAnalyzeCommand = program => {
|
|
55
|
+
return program
|
|
56
|
+
.createCommand('analyze')
|
|
57
|
+
.description('analyze webpack bundle and show the installed dependencies')
|
|
58
|
+
.action(analyzeCommand)
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
export default analyzeCommandCreator
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { jest } from '@jest/globals'
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
+
import { Command } from 'commander'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
const { createAnalyzeCommand } = await import('./analyze.js')
|
|
7
|
+
|
|
8
|
+
describe('createAnalyzeCommand', () => {
|
|
9
|
+
let program
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
program = new Command()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.clearAllMocks()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('creates a command with the correct parameters', () => {
|
|
20
|
+
const command = createAnalyzeCommand(program)
|
|
21
|
+
|
|
22
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
6
23
|
})
|
|
7
24
|
})
|
package/src/commands/build.js
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
printStarting,
|
|
15
15
|
printSuccess,
|
|
16
16
|
} from '../utils/build/print.js'
|
|
17
|
-
|
|
18
17
|
const ERROR_EXIT_CODE = 1
|
|
19
18
|
const PROGRESS_BAR_TYPE = process.stdin.isTTY ? 'fancy' : 'basic'
|
|
20
19
|
|
|
@@ -23,14 +22,12 @@ export const buildCommand = async ({
|
|
|
23
22
|
...buildOptions
|
|
24
23
|
}) => {
|
|
25
24
|
printStarting()
|
|
26
|
-
|
|
27
25
|
const { isProgressiveWebApp, serviceWorkerFileName } = getServiceWorkersInfo()
|
|
28
26
|
|
|
29
27
|
try {
|
|
30
28
|
const previousFileSizes = await measureInitialFileSizes()
|
|
31
29
|
|
|
32
30
|
cleanDistFolder()
|
|
33
|
-
|
|
34
31
|
const { stats, warnings } = await build({
|
|
35
32
|
...buildOptions,
|
|
36
33
|
isProgressiveWebApp,
|
|
@@ -40,79 +37,66 @@ export const buildCommand = async ({
|
|
|
40
37
|
printBuildResultMessage(warnings)
|
|
41
38
|
|
|
42
39
|
// use safety workers if necessary
|
|
43
|
-
applySafetyWorkers({
|
|
40
|
+
applySafetyWorkers({
|
|
41
|
+
emergencySafetyWorker,
|
|
42
|
+
})
|
|
44
43
|
|
|
45
44
|
// Merge with the public folder
|
|
46
45
|
copyPublicFolder()
|
|
47
|
-
|
|
48
46
|
printFileSizes(stats, previousFileSizes)
|
|
49
|
-
|
|
50
47
|
printSuccess()
|
|
51
48
|
} catch (e) {
|
|
52
49
|
printError(e)
|
|
53
|
-
|
|
54
50
|
process.exit(ERROR_EXIT_CODE)
|
|
55
51
|
}
|
|
56
52
|
}
|
|
53
|
+
export const createBuildCommand = program => {
|
|
54
|
+
return program
|
|
55
|
+
.createCommand('build')
|
|
56
|
+
.description('Build project for release')
|
|
57
|
+
.action(options => {
|
|
58
|
+
const {
|
|
59
|
+
dotenv,
|
|
60
|
+
disableSourceMaps,
|
|
61
|
+
emergencySafetyWorker,
|
|
62
|
+
disableCloudflareHandler,
|
|
63
|
+
skipTypeChecking,
|
|
64
|
+
progressBar,
|
|
65
|
+
compiler,
|
|
66
|
+
} = options
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
compiler,
|
|
68
|
-
} = options
|
|
69
|
-
|
|
70
|
-
return buildCommand({
|
|
71
|
-
dotenv,
|
|
72
|
-
isSourceMapEnabled: !disableSourceMaps,
|
|
73
|
-
emergencySafetyWorker,
|
|
74
|
-
disableCloudflareHandler,
|
|
75
|
-
skipTypeChecking,
|
|
76
|
-
progressBar,
|
|
77
|
-
compiler,
|
|
68
|
+
return buildCommand({
|
|
69
|
+
dotenv,
|
|
70
|
+
isSourceMapEnabled: !disableSourceMaps,
|
|
71
|
+
emergencySafetyWorker,
|
|
72
|
+
disableCloudflareHandler,
|
|
73
|
+
skipTypeChecking,
|
|
74
|
+
progressBar,
|
|
75
|
+
compiler,
|
|
76
|
+
})
|
|
78
77
|
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
name: '--skip-type-checking',
|
|
104
|
-
label: 'skip type checking in webpack',
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: '--progress-bar [basic | fancy]',
|
|
108
|
-
label: 'progress bar type for webpack build process',
|
|
109
|
-
default: PROGRESS_BAR_TYPE,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: '--compiler <compiler>',
|
|
113
|
-
label: 'Compiler to use: babel, swc (default: babel)',
|
|
114
|
-
},
|
|
115
|
-
],
|
|
78
|
+
.option(
|
|
79
|
+
'--dotenv <dotenv>',
|
|
80
|
+
".env file to use as source of env variables; values: 'none', 'auto' or path to dotenv file",
|
|
81
|
+
DOTENV_NONE
|
|
82
|
+
)
|
|
83
|
+
.option('--disable-source-maps', 'disable source maps generation')
|
|
84
|
+
.option(
|
|
85
|
+
'--emergency-safety-worker',
|
|
86
|
+
'replace progressive web app service worker with safety-worker.js content (https://toptal-core.atlassian.net/wiki/spaces/FE/pages/2059796590/Davinci+-+How+to+deal+with+progressive+web+app+PWA#Service-Worker-Safety)'
|
|
87
|
+
)
|
|
88
|
+
.option(
|
|
89
|
+
'--disable-cloudflare-handler',
|
|
90
|
+
'disable Cloudflare fetch handler override'
|
|
91
|
+
)
|
|
92
|
+
.option('--skip-type-checking', 'skip type checking in webpack')
|
|
93
|
+
.option(
|
|
94
|
+
'--progress-bar [basic | fancy]',
|
|
95
|
+
'progress bar type for webpack build process',
|
|
96
|
+
PROGRESS_BAR_TYPE
|
|
97
|
+
)
|
|
98
|
+
.option(
|
|
99
|
+
'--compiler <compiler>',
|
|
100
|
+
'Compiler to use: babel, swc (default: babel)'
|
|
101
|
+
)
|
|
116
102
|
}
|
|
117
|
-
|
|
118
|
-
export default buildCommandCreator
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { jest } from '@jest/globals'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import { Command } from 'commander'
|
|
2
4
|
|
|
3
5
|
jest.unstable_mockModule('../utils/build/build.js', () => ({
|
|
4
6
|
build: jest.fn(),
|
|
@@ -31,9 +33,7 @@ const {
|
|
|
31
33
|
const { printBuildResultMessage, printFileSizes, printSuccess } = await import(
|
|
32
34
|
'../utils/build/print.js'
|
|
33
35
|
)
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const { buildCommand } = buildCommandCreator
|
|
36
|
+
const { createBuildCommand, buildCommand } = await import('./build.js')
|
|
37
37
|
|
|
38
38
|
const buildOptions = {
|
|
39
39
|
option1: 123,
|
|
@@ -43,7 +43,9 @@ const warnings = ['warning1', 'warning2']
|
|
|
43
43
|
const previousFileSizes = [1, 2, 3]
|
|
44
44
|
const originalProcessExit = process.exit
|
|
45
45
|
|
|
46
|
-
describe('
|
|
46
|
+
describe('createBuildCommand', () => {
|
|
47
|
+
let program
|
|
48
|
+
|
|
47
49
|
beforeEach(() => {
|
|
48
50
|
getServiceWorkersInfo.mockReturnValue({
|
|
49
51
|
isProgressiveWebApp: true,
|
|
@@ -58,6 +60,8 @@ describe('buildCommandCreator', () => {
|
|
|
58
60
|
})
|
|
59
61
|
|
|
60
62
|
process.exit = jest.fn()
|
|
63
|
+
|
|
64
|
+
program = new Command()
|
|
61
65
|
})
|
|
62
66
|
|
|
63
67
|
afterEach(() => {
|
|
@@ -75,7 +79,9 @@ describe('buildCommandCreator', () => {
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
it('has the correct command structure', () => {
|
|
78
|
-
|
|
82
|
+
const command = createBuildCommand(program)
|
|
83
|
+
|
|
84
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
79
85
|
})
|
|
80
86
|
|
|
81
87
|
describe('when build is successful', () => {
|
|
@@ -8,7 +8,6 @@ import { getEnvVariables } from '../utils/index.js'
|
|
|
8
8
|
import { copyPackageJson } from '../utils/copy-package-json.js'
|
|
9
9
|
import { copyFileIfExists } from '../utils/copy-file.js'
|
|
10
10
|
import { DOTENV_NONE, DIST_PACKAGE_PATH } from '../constants.cjs'
|
|
11
|
-
|
|
12
11
|
const SOURCE_FOLDER_NAME = 'src'
|
|
13
12
|
const PACKAGE_ENTRY_FILE = `./${SOURCE_FOLDER_NAME}/index.package.js`
|
|
14
13
|
const DEFAULT_TSCONFIG_PATH = './tsconfig.json'
|
|
@@ -20,16 +19,13 @@ const TEST_FILES_PATTERNS = [
|
|
|
20
19
|
'*.storyshot',
|
|
21
20
|
'*.snap',
|
|
22
21
|
]
|
|
23
|
-
|
|
24
22
|
const getTsConfigValue = (tsConfigPath, prop) => {
|
|
25
23
|
const projectTsConfigContent = fs.readJsonSync(tsConfigPath)
|
|
26
|
-
|
|
27
24
|
const extendsTsConfigPath = projectTsConfigContent.extends
|
|
28
25
|
|
|
29
26
|
if (!extendsTsConfigPath) {
|
|
30
27
|
return dotProp.get(projectTsConfigContent, prop)
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
const extendsTsConfigContent = fs.readJsonSync(
|
|
34
30
|
path.resolve(extendsTsConfigPath)
|
|
35
31
|
)
|
|
@@ -39,20 +35,18 @@ const getTsConfigValue = (tsConfigPath, prop) => {
|
|
|
39
35
|
dotProp.get(extendsTsConfigContent, prop)
|
|
40
36
|
)
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
const cleanFolder = outputDir => {
|
|
44
39
|
print.green('Cleaning up the folder... \n')
|
|
45
|
-
|
|
46
40
|
const absoluteOutputDirPath = path.resolve(outputDir)
|
|
47
41
|
|
|
48
|
-
fs.rmSync(absoluteOutputDirPath, {
|
|
42
|
+
fs.rmSync(absoluteOutputDirPath, {
|
|
43
|
+
force: true,
|
|
44
|
+
recursive: true,
|
|
45
|
+
})
|
|
49
46
|
}
|
|
50
|
-
|
|
51
47
|
const emitTypeDeclarations = ({ tsConfigPath, outputDir }) => {
|
|
52
48
|
print.green('Preparing type definitions... \n')
|
|
53
|
-
|
|
54
49
|
const declarationDirPath = path.resolve(outputDir, SOURCE_FOLDER_NAME)
|
|
55
|
-
|
|
56
50
|
const tscArgs = [
|
|
57
51
|
'tsc',
|
|
58
52
|
'--emitDeclarationOnly',
|
|
@@ -65,24 +59,22 @@ const emitTypeDeclarations = ({ tsConfigPath, outputDir }) => {
|
|
|
65
59
|
]
|
|
66
60
|
|
|
67
61
|
runSync('yarn', tscArgs)
|
|
68
|
-
replaceTscAliasPaths({
|
|
62
|
+
replaceTscAliasPaths({
|
|
63
|
+
configFile: tsConfigPath,
|
|
64
|
+
})
|
|
69
65
|
}
|
|
70
|
-
|
|
71
66
|
const getPathsToIgnoreDuringTranspilation = () =>
|
|
72
67
|
[...TEST_FILES_PATTERNS]
|
|
73
68
|
.map(pattern => `${SOURCE_FOLDER_NAME}/**/${pattern}`)
|
|
74
69
|
.join()
|
|
75
|
-
|
|
76
70
|
const transpileSourceCode = ({ outputDir, envVariables, babelConfigPath }) => {
|
|
77
71
|
const defaultBabelConfigPath = files.getPackageFilePath(
|
|
78
72
|
'@toptal/davinci-engine',
|
|
79
73
|
'src/configs/babel/babel-package-config.json'
|
|
80
74
|
)
|
|
81
|
-
|
|
82
75
|
const babelConfigAbsolutePath = babelConfigPath
|
|
83
76
|
? path.resolve(babelConfigPath)
|
|
84
77
|
: defaultBabelConfigPath
|
|
85
|
-
|
|
86
78
|
const pathsToIgnore = getPathsToIgnoreDuringTranspilation()
|
|
87
79
|
|
|
88
80
|
runSync(
|
|
@@ -109,17 +101,14 @@ const transpileSourceCode = ({ outputDir, envVariables, babelConfigPath }) => {
|
|
|
109
101
|
}
|
|
110
102
|
)
|
|
111
103
|
}
|
|
112
|
-
|
|
113
104
|
const copySupportiveFiles = ({ outputDir, entry = PACKAGE_ENTRY_FILE }) => {
|
|
114
105
|
const entryBaseName = path.basename(entry, path.extname(entry))
|
|
115
106
|
const dirEntry = path.dirname(entry)
|
|
116
|
-
|
|
117
107
|
const compiledEntry = path.format({
|
|
118
108
|
dir: dirEntry,
|
|
119
109
|
ext: '.js',
|
|
120
110
|
name: entryBaseName,
|
|
121
111
|
})
|
|
122
|
-
|
|
123
112
|
const typesPath = path.format({
|
|
124
113
|
dir: dirEntry,
|
|
125
114
|
ext: '.d.ts',
|
|
@@ -155,7 +144,6 @@ const copySupportiveFiles = ({ outputDir, entry = PACKAGE_ENTRY_FILE }) => {
|
|
|
155
144
|
to: path.join(outputDir, './.gitignore'),
|
|
156
145
|
})
|
|
157
146
|
}
|
|
158
|
-
|
|
159
147
|
const compilePackageCommand = async ({
|
|
160
148
|
dotenv,
|
|
161
149
|
babelConfigPath,
|
|
@@ -163,7 +151,6 @@ const compilePackageCommand = async ({
|
|
|
163
151
|
entry,
|
|
164
152
|
}) => {
|
|
165
153
|
print.header('Compiling a package')
|
|
166
|
-
|
|
167
154
|
const packageJson = fs.readJsonSync(path.resolve('./package.json'))
|
|
168
155
|
|
|
169
156
|
if (!('sideEffects' in packageJson)) {
|
|
@@ -171,7 +158,6 @@ const compilePackageCommand = async ({
|
|
|
171
158
|
'sideEffects property is not added to the package.json file. The tree-shaking functionality would not be working for your package. [https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects]'
|
|
172
159
|
)
|
|
173
160
|
}
|
|
174
|
-
|
|
175
161
|
const projectTsConfigPath = path.resolve(
|
|
176
162
|
tsConfigPath || DEFAULT_TSCONFIG_PATH
|
|
177
163
|
)
|
|
@@ -186,58 +172,61 @@ const compilePackageCommand = async ({
|
|
|
186
172
|
|
|
187
173
|
print.grey('Output dir: ', outputDir)
|
|
188
174
|
print.grey('')
|
|
189
|
-
|
|
190
|
-
|
|
175
|
+
const envVariables = getEnvVariables({
|
|
176
|
+
dotenv,
|
|
177
|
+
})
|
|
191
178
|
|
|
192
179
|
cleanFolder(outputDir)
|
|
193
|
-
emitTypeDeclarations({
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
180
|
+
emitTypeDeclarations({
|
|
181
|
+
outputDir,
|
|
182
|
+
tsConfigPath: projectTsConfigPath,
|
|
183
|
+
})
|
|
184
|
+
transpileSourceCode({
|
|
185
|
+
babelConfigPath,
|
|
186
|
+
envVariables,
|
|
187
|
+
outputDir,
|
|
188
|
+
})
|
|
189
|
+
copySupportiveFiles({
|
|
190
|
+
entry,
|
|
191
|
+
outputDir,
|
|
192
|
+
})
|
|
197
193
|
print.success('Done!')
|
|
198
194
|
}
|
|
199
195
|
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
196
|
+
export const createCompilePackageCommand = program => {
|
|
197
|
+
return program
|
|
198
|
+
.createCommand('compile-package')
|
|
199
|
+
.description('Compile package to publish to npm')
|
|
200
|
+
.action(options => {
|
|
201
|
+
const {
|
|
202
|
+
dotenv,
|
|
203
|
+
babelConfig: babelConfigPath,
|
|
204
|
+
tsConfig: tsConfigPath,
|
|
205
|
+
entry,
|
|
206
|
+
} = options
|
|
207
|
+
|
|
208
|
+
return compilePackageCommand({
|
|
209
|
+
babelConfigPath,
|
|
210
|
+
dotenv,
|
|
211
|
+
entry,
|
|
212
|
+
tsConfigPath,
|
|
213
|
+
})
|
|
214
214
|
})
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
'path to a custom tsconfig file; values: path to a custom tsconfig file',
|
|
233
|
-
name: '--tsConfig <tsConfig>',
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
label:
|
|
237
|
-
'path to a custom entry index file; values: path to a custom entry index file',
|
|
238
|
-
name: '--entry <entry>',
|
|
239
|
-
},
|
|
240
|
-
],
|
|
215
|
+
.option(
|
|
216
|
+
'--dotenv <dotenv>',
|
|
217
|
+
".env file to use as source of env variables; values: 'none', 'auto' or path to dotenv file",
|
|
218
|
+
DOTENV_NONE
|
|
219
|
+
)
|
|
220
|
+
.option(
|
|
221
|
+
'--babelConfig <babelConfig>',
|
|
222
|
+
'path to a custom Babel config file; values: path to a Babel config file'
|
|
223
|
+
)
|
|
224
|
+
.option(
|
|
225
|
+
'--tsConfig <tsConfig>',
|
|
226
|
+
'path to a custom tsconfig file; values: path to a custom tsconfig file'
|
|
227
|
+
)
|
|
228
|
+
.option(
|
|
229
|
+
'--entry <entry>',
|
|
230
|
+
'path to a custom entry index file; values: path to a custom entry index file'
|
|
231
|
+
)
|
|
241
232
|
}
|
|
242
|
-
|
|
243
|
-
export default compilePackageCommandCreator
|