@servicetitan/startup 31.2.0 → 31.3.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/dist/cli/tasks/swc-compile-package.d.ts +1 -0
- package/dist/cli/tasks/swc-compile-package.d.ts.map +1 -1
- package/dist/cli/tasks/swc-compile-package.js +70 -53
- package/dist/cli/tasks/swc-compile-package.js.map +1 -1
- package/package.json +9 -5
- package/src/cli/tasks/__tests__/swc-compile-package.test.ts +36 -6
- package/src/cli/tasks/swc-compile-package.ts +76 -54
- package/dist/cli/tasks/swc-cli.d.js +0 -3
- package/dist/cli/tasks/swc-cli.d.js.map +0 -1
- package/dist/cli/types/cpx2.d.js +0 -3
- package/dist/cli/types/cpx2.d.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swc-compile-package.d.ts","sourceRoot":"","sources":["../../../src/cli/tasks/swc-compile-package.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"swc-compile-package.d.ts","sourceRoot":"","sources":["../../../src/cli/tasks/swc-compile-package.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,UAAU,IAAI;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAQD,qBAAa,iBAAkB,SAAQ,IAAI;gBAC3B,EAAE,KAAK,EAAE,EAAE,IAAI;IAIrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqC9B,OAAO,CAAC,SAAS;CAyDpB"}
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "SwcCompilePackage", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _cli = require("@swc/cli");
|
|
12
|
+
const _debounce = /*#__PURE__*/ _interop_require_default(require("debounce"));
|
|
12
13
|
const _deepmerge = /*#__PURE__*/ _interop_require_default(require("deepmerge"));
|
|
13
14
|
const _utils = require("../../utils");
|
|
14
15
|
const _utils1 = require("../utils");
|
|
@@ -21,8 +22,40 @@ function _interop_require_default(obj) {
|
|
|
21
22
|
function overwriteMerge(_destinationArray, sourceArray) {
|
|
22
23
|
return sourceArray;
|
|
23
24
|
}
|
|
25
|
+
const typedefsPattern = '**/*.d.ts';
|
|
24
26
|
class SwcCompilePackage extends _task.Task {
|
|
25
27
|
async execute() {
|
|
28
|
+
const config = this.getConfig();
|
|
29
|
+
/* istanbul ignore next: debug only */ _utils.log.debug('swc-compile-package:config', ()=>JSON.stringify(config, null, 2));
|
|
30
|
+
/*
|
|
31
|
+
* @swc/cli@0.5.0 doesn't implement "ignore" in watch mode so debounce
|
|
32
|
+
* noisy output. See https://servicetitan.atlassian.net/browse/FAR-1592
|
|
33
|
+
* and DEVELOPER_NOTES in file://./../../../package.json
|
|
34
|
+
*/ const logSuccessResults = this.watch ? (0, _debounce.default)(this.logCompletionResults.bind(this), 200) : this.logCompletionResults.bind(this);
|
|
35
|
+
return new Promise((resolve, reject)=>{
|
|
36
|
+
(0, _cli.swcDir)({
|
|
37
|
+
...config,
|
|
38
|
+
callbacks: {
|
|
39
|
+
onSuccess: (e)=>{
|
|
40
|
+
logSuccessResults(this.taskTimer.add(e.duration));
|
|
41
|
+
if (!this.watch) {
|
|
42
|
+
resolve();
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
onFail: (e)=>{
|
|
46
|
+
_utils.log.text([
|
|
47
|
+
...e.reasons.values()
|
|
48
|
+
][0]);
|
|
49
|
+
this.logCompletionResults(this.taskTimer.add(e.duration));
|
|
50
|
+
if (!this.watch) {
|
|
51
|
+
reject(new Error('Compilation failed'));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
getConfig() {
|
|
26
59
|
var _tsConfig_getValue;
|
|
27
60
|
const { source, destination } = (0, _utils.getFolders)();
|
|
28
61
|
const packageConfig = (0, _utils.getSwcCompilePackageConfiguration)();
|
|
@@ -39,63 +72,47 @@ class SwcCompilePackage extends _task.Task {
|
|
|
39
72
|
'**/__mocks__/*',
|
|
40
73
|
'**/*.stories.*'
|
|
41
74
|
]);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
transform: {
|
|
66
|
-
legacyDecorator,
|
|
67
|
-
decoratorMetadata,
|
|
68
|
-
react: {
|
|
69
|
-
runtime: 'automatic'
|
|
70
|
-
}
|
|
71
|
-
}
|
|
75
|
+
if (!ignore.includes(typedefsPattern)) {
|
|
76
|
+
ignore.push(typedefsPattern);
|
|
77
|
+
}
|
|
78
|
+
return (0, _deepmerge.default)({
|
|
79
|
+
cliOptions: {
|
|
80
|
+
watch: this.watch,
|
|
81
|
+
outDir: destination,
|
|
82
|
+
stripLeadingPaths: true,
|
|
83
|
+
extensions: [
|
|
84
|
+
'.ts',
|
|
85
|
+
'.tsx'
|
|
86
|
+
],
|
|
87
|
+
filenames: [
|
|
88
|
+
source
|
|
89
|
+
],
|
|
90
|
+
ignore
|
|
91
|
+
},
|
|
92
|
+
swcOptions: {
|
|
93
|
+
jsc: {
|
|
94
|
+
parser: {
|
|
95
|
+
syntax: 'typescript',
|
|
96
|
+
tsx: true,
|
|
97
|
+
decorators: true
|
|
72
98
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onSuccess: (e)=>{
|
|
80
|
-
this.logCompletionResults(this.taskTimer.add(e.duration));
|
|
81
|
-
if (!this.watch) {
|
|
82
|
-
resolve();
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
onFail: (e)=>{
|
|
86
|
-
_utils.log.text([
|
|
87
|
-
...e.reasons.values()
|
|
88
|
-
][0]);
|
|
89
|
-
this.logCompletionResults(this.taskTimer.add(e.duration));
|
|
90
|
-
if (!this.watch) {
|
|
91
|
-
reject(new Error('Compilation failed'));
|
|
99
|
+
target,
|
|
100
|
+
transform: {
|
|
101
|
+
legacyDecorator,
|
|
102
|
+
decoratorMetadata,
|
|
103
|
+
react: {
|
|
104
|
+
runtime: 'automatic'
|
|
92
105
|
}
|
|
93
106
|
}
|
|
107
|
+
},
|
|
108
|
+
sourceMaps,
|
|
109
|
+
module: {
|
|
110
|
+
type: module === 'commonjs' || module === 'nodenext' ? 'commonjs' : 'es6'
|
|
94
111
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
}
|
|
113
|
+
}, packageConfig, {
|
|
114
|
+
arrayMerge: overwriteMerge,
|
|
115
|
+
clone: false
|
|
99
116
|
});
|
|
100
117
|
}
|
|
101
118
|
constructor({ watch }){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/tasks/swc-compile-package.ts"],"sourcesContent":["import { swcDir } from '@swc/cli';\nimport deepmerge from 'deepmerge';\n\nimport { getFolders, getSwcCompilePackageConfiguration, getTsConfig, log } from '../../utils';\nimport { TSConfig } from '../utils';\nimport { Task } from './task';\n\ninterface Args {\n [key: string]: unknown;\n watch?: boolean;\n}\n\nfunction overwriteMerge(_destinationArray: unknown[], sourceArray: unknown[]) {\n return sourceArray;\n}\n\nexport class SwcCompilePackage extends Task {\n constructor({ watch }: Args) {\n super({ name: 'swc-compile-package', global: false, watch });\n }\n\n async execute(): Promise<void> {\n const { source, destination } = getFolders();\n const packageConfig = getSwcCompilePackageConfiguration();\n const tsConfig = new TSConfig(getTsConfig());\n const target = tsConfig.getValue('compilerOptions.target');\n const legacyDecorator = tsConfig.getValue('compilerOptions.experimentalDecorators');\n const decoratorMetadata = tsConfig.getValue('compilerOptions.emitDecoratorMetadata');\n const sourceMaps = tsConfig.getValue('compilerOptions.sourceMap');\n const module = tsConfig.getValue<string>('compilerOptions.module')?.toLowerCase();\n const ignore = tsConfig.getValue('exclude', [\n '**/*.d.ts',\n '**/__tests__/*',\n '**/*.test.*',\n '**/__mocks__/*',\n '**/*.stories.*',\n ]);\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/cli/tasks/swc-compile-package.ts"],"sourcesContent":["import { Options, swcDir } from '@swc/cli';\nimport debounce from 'debounce';\nimport deepmerge from 'deepmerge';\n\nimport { getFolders, getSwcCompilePackageConfiguration, getTsConfig, log } from '../../utils';\nimport { TSConfig } from '../utils';\nimport { Task } from './task';\n\ninterface Args {\n [key: string]: unknown;\n watch?: boolean;\n}\n\nfunction overwriteMerge(_destinationArray: unknown[], sourceArray: unknown[]) {\n return sourceArray;\n}\n\nconst typedefsPattern = '**/*.d.ts';\n\nexport class SwcCompilePackage extends Task {\n constructor({ watch }: Args) {\n super({ name: 'swc-compile-package', global: false, watch });\n }\n\n async execute(): Promise<void> {\n const config = this.getConfig();\n\n /* istanbul ignore next: debug only */\n log.debug('swc-compile-package:config', () => JSON.stringify(config, null, 2));\n\n /*\n * @swc/cli@0.5.0 doesn't implement \"ignore\" in watch mode so debounce\n * noisy output. See https://servicetitan.atlassian.net/browse/FAR-1592\n * and DEVELOPER_NOTES in file://./../../../package.json\n */\n const logSuccessResults = this.watch\n ? debounce(this.logCompletionResults.bind(this), 200)\n : this.logCompletionResults.bind(this);\n\n return new Promise((resolve, reject) => {\n swcDir({\n ...config,\n callbacks: {\n onSuccess: (e: { duration: number }) => {\n logSuccessResults(this.taskTimer.add(e.duration));\n if (!this.watch) {\n resolve();\n }\n },\n onFail: (e: { duration: number; reasons: Map<string, string> }) => {\n log.text([...e.reasons.values()][0]);\n this.logCompletionResults(this.taskTimer.add(e.duration));\n if (!this.watch) {\n reject(new Error('Compilation failed'));\n }\n },\n },\n });\n });\n }\n\n private getConfig(): Options {\n const { source, destination } = getFolders();\n const packageConfig = getSwcCompilePackageConfiguration();\n const tsConfig = new TSConfig(getTsConfig());\n const target = tsConfig.getValue('compilerOptions.target');\n const legacyDecorator = tsConfig.getValue('compilerOptions.experimentalDecorators');\n const decoratorMetadata = tsConfig.getValue('compilerOptions.emitDecoratorMetadata');\n const sourceMaps = tsConfig.getValue('compilerOptions.sourceMap');\n const module = tsConfig.getValue<string>('compilerOptions.module')?.toLowerCase();\n const ignore = tsConfig.getValue('exclude', [\n '**/*.d.ts',\n '**/__tests__/*',\n '**/*.test.*',\n '**/__mocks__/*',\n '**/*.stories.*',\n ]);\n\n if (!ignore.includes(typedefsPattern)) {\n ignore.push(typedefsPattern);\n }\n\n return deepmerge(\n {\n cliOptions: {\n watch: this.watch,\n outDir: destination,\n stripLeadingPaths: true,\n extensions: ['.ts', '.tsx'],\n filenames: [source],\n ignore,\n },\n swcOptions: {\n jsc: {\n parser: {\n syntax: 'typescript',\n tsx: true,\n decorators: true,\n },\n target,\n transform: {\n legacyDecorator,\n decoratorMetadata,\n react: {\n runtime: 'automatic',\n },\n },\n },\n sourceMaps,\n module: {\n type: module === 'commonjs' || module === 'nodenext' ? 'commonjs' : 'es6',\n },\n },\n },\n packageConfig,\n { arrayMerge: overwriteMerge, clone: false }\n );\n }\n}\n"],"names":["SwcCompilePackage","overwriteMerge","_destinationArray","sourceArray","typedefsPattern","Task","execute","config","getConfig","log","debug","JSON","stringify","logSuccessResults","watch","debounce","logCompletionResults","bind","Promise","resolve","reject","swcDir","callbacks","onSuccess","e","taskTimer","add","duration","onFail","text","reasons","values","Error","tsConfig","source","destination","getFolders","packageConfig","getSwcCompilePackageConfiguration","TSConfig","getTsConfig","target","getValue","legacyDecorator","decoratorMetadata","sourceMaps","module","toLowerCase","ignore","includes","push","deepmerge","cliOptions","outDir","stripLeadingPaths","extensions","filenames","swcOptions","jsc","parser","syntax","tsx","decorators","transform","react","runtime","type","arrayMerge","clone","constructor","name","global"],"mappings":";;;;+BAmBaA;;;eAAAA;;;qBAnBmB;iEACX;kEACC;uBAE0D;wBACvD;sBACJ;;;;;;AAOrB,SAASC,eAAeC,iBAA4B,EAAEC,WAAsB;IACxE,OAAOA;AACX;AAEA,MAAMC,kBAAkB;AAEjB,MAAMJ,0BAA0BK,UAAI;IAKvC,MAAMC,UAAyB;QAC3B,MAAMC,SAAS,IAAI,CAACC,SAAS;QAE7B,oCAAoC,GACpCC,UAAG,CAACC,KAAK,CAAC,8BAA8B,IAAMC,KAAKC,SAAS,CAACL,QAAQ,MAAM;QAE3E;;;;SAIC,GACD,MAAMM,oBAAoB,IAAI,CAACC,KAAK,GAC9BC,IAAAA,iBAAQ,EAAC,IAAI,CAACC,oBAAoB,CAACC,IAAI,CAAC,IAAI,GAAG,OAC/C,IAAI,CAACD,oBAAoB,CAACC,IAAI,CAAC,IAAI;QAEzC,OAAO,IAAIC,QAAQ,CAACC,SAASC;YACzBC,IAAAA,WAAM,EAAC;gBACH,GAAGd,MAAM;gBACTe,WAAW;oBACPC,WAAW,CAACC;wBACRX,kBAAkB,IAAI,CAACY,SAAS,CAACC,GAAG,CAACF,EAAEG,QAAQ;wBAC/C,IAAI,CAAC,IAAI,CAACb,KAAK,EAAE;4BACbK;wBACJ;oBACJ;oBACAS,QAAQ,CAACJ;wBACLf,UAAG,CAACoB,IAAI,CAAC;+BAAIL,EAAEM,OAAO,CAACC,MAAM;yBAAG,CAAC,EAAE;wBACnC,IAAI,CAACf,oBAAoB,CAAC,IAAI,CAACS,SAAS,CAACC,GAAG,CAACF,EAAEG,QAAQ;wBACvD,IAAI,CAAC,IAAI,CAACb,KAAK,EAAE;4BACbM,OAAO,IAAIY,MAAM;wBACrB;oBACJ;gBACJ;YACJ;QACJ;IACJ;IAEQxB,YAAqB;YAQVyB;QAPf,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGC,IAAAA,iBAAU;QAC1C,MAAMC,gBAAgBC,IAAAA,wCAAiC;QACvD,MAAML,WAAW,IAAIM,gBAAQ,CAACC,IAAAA,kBAAW;QACzC,MAAMC,SAASR,SAASS,QAAQ,CAAC;QACjC,MAAMC,kBAAkBV,SAASS,QAAQ,CAAC;QAC1C,MAAME,oBAAoBX,SAASS,QAAQ,CAAC;QAC5C,MAAMG,aAAaZ,SAASS,QAAQ,CAAC;QACrC,MAAMI,UAASb,qBAAAA,SAASS,QAAQ,CAAS,uCAA1BT,yCAAAA,mBAAqDc,WAAW;QAC/E,MAAMC,SAASf,SAASS,QAAQ,CAAC,WAAW;YACxC;YACA;YACA;YACA;YACA;SACH;QAED,IAAI,CAACM,OAAOC,QAAQ,CAAC7C,kBAAkB;YACnC4C,OAAOE,IAAI,CAAC9C;QAChB;QAEA,OAAO+C,IAAAA,kBAAS,EACZ;YACIC,YAAY;gBACRtC,OAAO,IAAI,CAACA,KAAK;gBACjBuC,QAAQlB;gBACRmB,mBAAmB;gBACnBC,YAAY;oBAAC;oBAAO;iBAAO;gBAC3BC,WAAW;oBAACtB;iBAAO;gBACnBc;YACJ;YACAS,YAAY;gBACRC,KAAK;oBACDC,QAAQ;wBACJC,QAAQ;wBACRC,KAAK;wBACLC,YAAY;oBAChB;oBACArB;oBACAsB,WAAW;wBACPpB;wBACAC;wBACAoB,OAAO;4BACHC,SAAS;wBACb;oBACJ;gBACJ;gBACApB;gBACAC,QAAQ;oBACJoB,MAAMpB,WAAW,cAAcA,WAAW,aAAa,aAAa;gBACxE;YACJ;QACJ,GACAT,eACA;YAAE8B,YAAYlE;YAAgBmE,OAAO;QAAM;IAEnD;IAjGAC,YAAY,EAAEvD,KAAK,EAAQ,CAAE;QACzB,KAAK,CAAC;YAAEwD,MAAM;YAAuBC,QAAQ;YAAOzD;QAAM;IAC9D;AAgGJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/startup",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/startup",
|
|
6
6
|
"repository": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@jest/core": "~29.7.0",
|
|
38
38
|
"@jest/types": "~29.6.3",
|
|
39
39
|
"@jsdevtools/coverage-istanbul-loader": "^3.0.5",
|
|
40
|
-
"@servicetitan/eslint-config": "31.
|
|
41
|
-
"@servicetitan/stylelint-config": "31.
|
|
40
|
+
"@servicetitan/eslint-config": "31.3.1",
|
|
41
|
+
"@servicetitan/stylelint-config": "31.3.1",
|
|
42
42
|
"@svgr/webpack": "^8.1.0",
|
|
43
43
|
"@swc/cli": "^0.5.0",
|
|
44
44
|
"@swc/core": "1.11.29",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"cpx2": "8.0.0",
|
|
49
49
|
"css-loader": "~7.1.2",
|
|
50
50
|
"css-minimizer-webpack-plugin": "^7.0.2",
|
|
51
|
+
"debounce": "^2.2.0",
|
|
51
52
|
"debug": "^4.4.1",
|
|
52
53
|
"deepmerge": "~4.3.1",
|
|
53
54
|
"eslint": "~9.30.1",
|
|
@@ -104,7 +105,10 @@
|
|
|
104
105
|
}
|
|
105
106
|
},
|
|
106
107
|
"DEVELOPER_NOTES": {
|
|
107
|
-
"@swc/cli":
|
|
108
|
+
"@swc/cli": [
|
|
109
|
+
"Update when https://github.com/swc-project/swc/issues/10535 is resolved",
|
|
110
|
+
"See also SwcCompilePackage.execute in file://./src/cli/tasks/swc-compile-package.ts"
|
|
111
|
+
]
|
|
108
112
|
},
|
|
109
113
|
"publishConfig": {
|
|
110
114
|
"access": "public"
|
|
@@ -112,5 +116,5 @@
|
|
|
112
116
|
"cli": {
|
|
113
117
|
"webpack": false
|
|
114
118
|
},
|
|
115
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "0f6ee09cfe2f5d12a17f42c5aea40d93db9ae6e9"
|
|
116
120
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { fs, vol } from 'memfs';
|
|
2
1
|
import { swcDir } from '@swc/cli';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
import debounce from 'debounce';
|
|
4
|
+
import { fs, vol } from 'memfs';
|
|
3
5
|
import { getSwcCompilePackageConfiguration, log } from '../../../utils';
|
|
4
6
|
import { SwcCompilePackage } from '../swc-compile-package';
|
|
5
|
-
import deepmerge from 'deepmerge';
|
|
6
7
|
|
|
8
|
+
jest.mock('debounce', () => jest.fn());
|
|
7
9
|
jest.mock('fs', () => fs);
|
|
8
10
|
jest.mock('@swc/cli', () => ({
|
|
9
11
|
swcDir: jest.fn(),
|
|
@@ -15,7 +17,7 @@ jest.mock('../../../utils', () => ({
|
|
|
15
17
|
source: 'src',
|
|
16
18
|
destination: 'dist',
|
|
17
19
|
}),
|
|
18
|
-
log: { info: jest.fn(), text: jest.fn() },
|
|
20
|
+
log: { debug: jest.fn(), info: jest.fn(), text: jest.fn() },
|
|
19
21
|
getSwcCompilePackageConfiguration: jest.fn(),
|
|
20
22
|
}));
|
|
21
23
|
|
|
@@ -129,8 +131,8 @@ describe(`[startup] ${SwcCompilePackage.name} task`, () => {
|
|
|
129
131
|
itCallsSwcDir(overrides);
|
|
130
132
|
});
|
|
131
133
|
|
|
132
|
-
describe('when tsconfig contains "exclude"', () => {
|
|
133
|
-
const exclude = ['**/
|
|
134
|
+
describe('when tsconfig contains "exclude" with "**/*.d.ts"', () => {
|
|
135
|
+
const exclude = ['**/*.d.ts', '**/__tests__/*', '**/__mocks__/*'];
|
|
134
136
|
|
|
135
137
|
beforeEach(() => {
|
|
136
138
|
volumeFromJSON({
|
|
@@ -150,6 +152,29 @@ describe(`[startup] ${SwcCompilePackage.name} task`, () => {
|
|
|
150
152
|
});
|
|
151
153
|
});
|
|
152
154
|
|
|
155
|
+
describe('when tsconfig contains "exclude" without "**/*.d.ts"', () => {
|
|
156
|
+
const exclude = ['**/__tests__/*', '**/__mocks__/*'];
|
|
157
|
+
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
volumeFromJSON({
|
|
160
|
+
'base.json': { exclude },
|
|
161
|
+
'tsconfig.build.json': { extends: './base' },
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('adds "**/*.d.ts" to exclude config', () => {
|
|
166
|
+
subject();
|
|
167
|
+
|
|
168
|
+
expect(swcDir).toHaveBeenCalledWith(
|
|
169
|
+
expect.objectContaining({
|
|
170
|
+
cliOptions: expect.objectContaining({
|
|
171
|
+
ignore: [...exclude, '**/*.d.ts'],
|
|
172
|
+
}),
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
153
178
|
describe.each(
|
|
154
179
|
Object.entries({
|
|
155
180
|
target: 'jsc.target',
|
|
@@ -229,7 +254,12 @@ describe(`[startup] ${SwcCompilePackage.name} task`, () => {
|
|
|
229
254
|
});
|
|
230
255
|
|
|
231
256
|
describe('in watch mode', () => {
|
|
232
|
-
beforeEach(() =>
|
|
257
|
+
beforeEach(() => {
|
|
258
|
+
watch = true;
|
|
259
|
+
jest.mocked(debounce).mockImplementation((fn: Function) => {
|
|
260
|
+
return ((...args: any[]) => fn(...args)) as any;
|
|
261
|
+
});
|
|
262
|
+
});
|
|
233
263
|
|
|
234
264
|
test('calls swcDir with watch=true', () => {
|
|
235
265
|
subject();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { swcDir } from '@swc/cli';
|
|
1
|
+
import { Options, swcDir } from '@swc/cli';
|
|
2
|
+
import debounce from 'debounce';
|
|
2
3
|
import deepmerge from 'deepmerge';
|
|
3
4
|
|
|
4
5
|
import { getFolders, getSwcCompilePackageConfiguration, getTsConfig, log } from '../../utils';
|
|
@@ -14,12 +15,51 @@ function overwriteMerge(_destinationArray: unknown[], sourceArray: unknown[]) {
|
|
|
14
15
|
return sourceArray;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
const typedefsPattern = '**/*.d.ts';
|
|
19
|
+
|
|
17
20
|
export class SwcCompilePackage extends Task {
|
|
18
21
|
constructor({ watch }: Args) {
|
|
19
22
|
super({ name: 'swc-compile-package', global: false, watch });
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
async execute(): Promise<void> {
|
|
26
|
+
const config = this.getConfig();
|
|
27
|
+
|
|
28
|
+
/* istanbul ignore next: debug only */
|
|
29
|
+
log.debug('swc-compile-package:config', () => JSON.stringify(config, null, 2));
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* @swc/cli@0.5.0 doesn't implement "ignore" in watch mode so debounce
|
|
33
|
+
* noisy output. See https://servicetitan.atlassian.net/browse/FAR-1592
|
|
34
|
+
* and DEVELOPER_NOTES in file://./../../../package.json
|
|
35
|
+
*/
|
|
36
|
+
const logSuccessResults = this.watch
|
|
37
|
+
? debounce(this.logCompletionResults.bind(this), 200)
|
|
38
|
+
: this.logCompletionResults.bind(this);
|
|
39
|
+
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
swcDir({
|
|
42
|
+
...config,
|
|
43
|
+
callbacks: {
|
|
44
|
+
onSuccess: (e: { duration: number }) => {
|
|
45
|
+
logSuccessResults(this.taskTimer.add(e.duration));
|
|
46
|
+
if (!this.watch) {
|
|
47
|
+
resolve();
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
onFail: (e: { duration: number; reasons: Map<string, string> }) => {
|
|
51
|
+
log.text([...e.reasons.values()][0]);
|
|
52
|
+
this.logCompletionResults(this.taskTimer.add(e.duration));
|
|
53
|
+
if (!this.watch) {
|
|
54
|
+
reject(new Error('Compilation failed'));
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private getConfig(): Options {
|
|
23
63
|
const { source, destination } = getFolders();
|
|
24
64
|
const packageConfig = getSwcCompilePackageConfiguration();
|
|
25
65
|
const tsConfig = new TSConfig(getTsConfig());
|
|
@@ -36,62 +76,44 @@ export class SwcCompilePackage extends Task {
|
|
|
36
76
|
'**/*.stories.*',
|
|
37
77
|
]);
|
|
38
78
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
transform: {
|
|
60
|
-
legacyDecorator,
|
|
61
|
-
decoratorMetadata,
|
|
62
|
-
react: {
|
|
63
|
-
runtime: 'automatic',
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
sourceMaps,
|
|
68
|
-
module: {
|
|
69
|
-
type:
|
|
70
|
-
module === 'commonjs' || module === 'nodenext'
|
|
71
|
-
? 'commonjs'
|
|
72
|
-
: 'es6',
|
|
73
|
-
},
|
|
79
|
+
if (!ignore.includes(typedefsPattern)) {
|
|
80
|
+
ignore.push(typedefsPattern);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return deepmerge(
|
|
84
|
+
{
|
|
85
|
+
cliOptions: {
|
|
86
|
+
watch: this.watch,
|
|
87
|
+
outDir: destination,
|
|
88
|
+
stripLeadingPaths: true,
|
|
89
|
+
extensions: ['.ts', '.tsx'],
|
|
90
|
+
filenames: [source],
|
|
91
|
+
ignore,
|
|
92
|
+
},
|
|
93
|
+
swcOptions: {
|
|
94
|
+
jsc: {
|
|
95
|
+
parser: {
|
|
96
|
+
syntax: 'typescript',
|
|
97
|
+
tsx: true,
|
|
98
|
+
decorators: true,
|
|
74
99
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
onFail: (e: { duration: number; reasons: Map<string, string> }) => {
|
|
83
|
-
log.text([...e.reasons.values()][0]);
|
|
84
|
-
this.logCompletionResults(this.taskTimer.add(e.duration));
|
|
85
|
-
if (!this.watch) {
|
|
86
|
-
reject(new Error('Compilation failed'));
|
|
87
|
-
}
|
|
100
|
+
target,
|
|
101
|
+
transform: {
|
|
102
|
+
legacyDecorator,
|
|
103
|
+
decoratorMetadata,
|
|
104
|
+
react: {
|
|
105
|
+
runtime: 'automatic',
|
|
88
106
|
},
|
|
89
107
|
},
|
|
90
108
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
sourceMaps,
|
|
110
|
+
module: {
|
|
111
|
+
type: module === 'commonjs' || module === 'nodenext' ? 'commonjs' : 'es6',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
packageConfig,
|
|
116
|
+
{ arrayMerge: overwriteMerge, clone: false }
|
|
117
|
+
);
|
|
96
118
|
}
|
|
97
119
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/tasks/swc-cli.d.ts"],"names":[],"mappings":""}
|
package/dist/cli/types/cpx2.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/types/cpx2.d.ts"],"names":[],"mappings":""}
|