@servicetitan/startup 31.1.0 → 31.3.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 CHANGED
@@ -8,6 +8,14 @@ try {
8
8
  if (startupPath && (startupPath.includes('node_modules') || startupPath.includes('.yalc'))) {
9
9
  require('../dist/cli/index.js');
10
10
  } else {
11
+ /*
12
+ * Workaround to prevent sporadic ReadSingleBytecodeData errors inside V8
13
+ * ts-node is using v8-compile-cache-lib to cache require statements
14
+ * See: https://github.com/nodejs/node/issues/51555
15
+ */
16
+ if (process.env.CI) {
17
+ process.env.DISABLE_V8_COMPILE_CACHE = '1';
18
+ }
11
19
  require('ts-node').register({
12
20
  project: require.resolve('../tsconfig.json'),
13
21
  transpileOnly: true,
@@ -6,6 +6,7 @@ interface Args {
6
6
  export declare class SwcCompilePackage extends Task {
7
7
  constructor({ watch }: Args);
8
8
  execute(): Promise<void>;
9
+ private getConfig;
9
10
  }
10
11
  export {};
11
12
  //# sourceMappingURL=swc-compile-package.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"swc-compile-package.d.ts","sourceRoot":"","sources":["../../../src/cli/tasks/swc-compile-package.ts"],"names":[],"mappings":"AAKA,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;AAMD,qBAAa,iBAAkB,SAAQ,IAAI;gBAC3B,EAAE,KAAK,EAAE,EAAE,IAAI;IAIrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA2EjC"}
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
- return new Promise((resolve, reject)=>{
43
- (0, _cli.swcDir)((0, _deepmerge.default)({
44
- cliOptions: {
45
- watch: this.watch,
46
- outDir: destination,
47
- stripLeadingPaths: true,
48
- extensions: [
49
- '.ts',
50
- '.tsx'
51
- ],
52
- filenames: [
53
- source
54
- ],
55
- ignore
56
- },
57
- swcOptions: {
58
- jsc: {
59
- parser: {
60
- syntax: 'typescript',
61
- tsx: true,
62
- decorators: true
63
- },
64
- target,
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
- sourceMaps,
74
- module: {
75
- type: module === 'commonjs' || module === 'nodenext' ? 'commonjs' : 'es6'
76
- }
77
- },
78
- callbacks: {
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
- }, packageConfig, {
96
- arrayMerge: overwriteMerge,
97
- clone: false
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 return new Promise((resolve, reject) => {\n swcDir(\n 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:\n module === 'commonjs' || module === 'nodenext'\n ? 'commonjs'\n : 'es6',\n },\n },\n callbacks: {\n onSuccess: (e: { duration: number }) => {\n this.logCompletionResults(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 packageConfig,\n { arrayMerge: overwriteMerge, clone: false }\n )\n );\n });\n }\n}\n"],"names":["SwcCompilePackage","overwriteMerge","_destinationArray","sourceArray","Task","execute","tsConfig","source","destination","getFolders","packageConfig","getSwcCompilePackageConfiguration","TSConfig","getTsConfig","target","getValue","legacyDecorator","decoratorMetadata","sourceMaps","module","toLowerCase","ignore","Promise","resolve","reject","swcDir","deepmerge","cliOptions","watch","outDir","stripLeadingPaths","extensions","filenames","swcOptions","jsc","parser","syntax","tsx","decorators","transform","react","runtime","type","callbacks","onSuccess","e","logCompletionResults","taskTimer","add","duration","onFail","log","text","reasons","values","Error","arrayMerge","clone","constructor","name","global"],"mappings":";;;;+BAgBaA;;;eAAAA;;;qBAhBU;kEACD;uBAE0D;wBACvD;sBACJ;;;;;;AAOrB,SAASC,eAAeC,iBAA4B,EAAEC,WAAsB;IACxE,OAAOA;AACX;AAEO,MAAMH,0BAA0BI,UAAI;IAKvC,MAAMC,UAAyB;YAQZC;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,OAAO,IAAIO,QAAQ,CAACC,SAASC;YACzBC,IAAAA,WAAM,EACFC,IAAAA,kBAAS,EACL;gBACIC,YAAY;oBACRC,OAAO,IAAI,CAACA,KAAK;oBACjBC,QAAQrB;oBACRsB,mBAAmB;oBACnBC,YAAY;wBAAC;wBAAO;qBAAO;oBAC3BC,WAAW;wBAACzB;qBAAO;oBACnBc;gBACJ;gBACAY,YAAY;oBACRC,KAAK;wBACDC,QAAQ;4BACJC,QAAQ;4BACRC,KAAK;4BACLC,YAAY;wBAChB;wBACAxB;wBACAyB,WAAW;4BACPvB;4BACAC;4BACAuB,OAAO;gCACHC,SAAS;4BACb;wBACJ;oBACJ;oBACAvB;oBACAC,QAAQ;wBACJuB,MACIvB,WAAW,cAAcA,WAAW,aAC9B,aACA;oBACd;gBACJ;gBACAwB,WAAW;oBACPC,WAAW,CAACC;wBACR,IAAI,CAACC,oBAAoB,CAAC,IAAI,CAACC,SAAS,CAACC,GAAG,CAACH,EAAEI,QAAQ;wBACvD,IAAI,CAAC,IAAI,CAACrB,KAAK,EAAE;4BACbL;wBACJ;oBACJ;oBACA2B,QAAQ,CAACL;wBACLM,UAAG,CAACC,IAAI,CAAC;+BAAIP,EAAEQ,OAAO,CAACC,MAAM;yBAAG,CAAC,EAAE;wBACnC,IAAI,CAACR,oBAAoB,CAAC,IAAI,CAACC,SAAS,CAACC,GAAG,CAACH,EAAEI,QAAQ;wBACvD,IAAI,CAAC,IAAI,CAACrB,KAAK,EAAE;4BACbJ,OAAO,IAAI+B,MAAM;wBACrB;oBACJ;gBACJ;YACJ,GACA7C,eACA;gBAAE8C,YAAYvD;gBAAgBwD,OAAO;YAAM;QAGvD;IACJ;IA9EAC,YAAY,EAAE9B,KAAK,EAAQ,CAAE;QACzB,KAAK,CAAC;YAAE+B,MAAM;YAAuBC,QAAQ;YAAOhC;QAAM;IAC9D;AA6EJ"}
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"}
@@ -1,6 +1,7 @@
1
1
  declare class Log {
2
2
  private readonly debugMap;
3
3
  constructor();
4
+ get timestamp(): string;
4
5
  text(...text: string[]): void;
5
6
  info(...text: string[]): void;
6
7
  success(...text: string[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAKA,cAAM,GAAG;IACL,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;;IAMjD,IAAI,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAItB,IAAI,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAItB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAIzB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAIzB,KAAK,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAIvB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;;;CAY1C;AAED,eAAO,MAAM,GAAG,KAAY,CAAC"}
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAKA,cAAM,GAAG;IACL,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;;IAMjD,IAAI,SAAS,WAQZ;IAED,IAAI,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAItB,IAAI,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAItB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAIzB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAIzB,KAAK,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAIvB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;;;CAY1C;AAED,eAAO,MAAM,GAAG,KAAY,CAAC"}
package/dist/utils/log.js CHANGED
@@ -29,6 +29,15 @@ function _interop_require_default(obj) {
29
29
  };
30
30
  }
31
31
  class Log {
32
+ get timestamp() {
33
+ return new Date().toLocaleTimeString(undefined, {
34
+ hour12: false,
35
+ hour: '2-digit',
36
+ minute: '2-digit',
37
+ second: '2-digit',
38
+ fractionalSecondDigits: 3
39
+ });
40
+ }
32
41
  text(...text) {
33
42
  process.stdout.write((0, _chalk.default)(...text) + '\n');
34
43
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/log.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { createDebug } from './debug';\n\ntype Debugger = ReturnType<typeof createDebug>;\n\nclass Log {\n private readonly debugMap: Map<string, Debugger>;\n\n constructor() {\n this.debugMap = new Map<string, Debugger>();\n }\n\n text(...text: string[]) {\n process.stdout.write(chalk(...text) + '\\n');\n }\n\n info(...text: string[]) {\n process.stdout.write(chalk.bold.cyan(...text) + '\\n');\n }\n\n success(...text: string[]) {\n process.stdout.write(chalk.bold.green(...text) + '\\n');\n }\n\n warning(...text: string[]) {\n process.stdout.write(chalk.bold.yellow(...text) + '\\n');\n }\n\n error(...text: string[]) {\n process.stdout.write(chalk.bold.red(...text) + '\\n');\n }\n\n debug(namespace: string, ...text: any[]) {\n let dbg = this.debugMap.get(namespace);\n if (!dbg) {\n dbg = createDebug(namespace);\n this.debugMap.set(namespace, dbg);\n }\n if (dbg.enabled && text.length) {\n const [formatter, ...args] = text.map(str => (typeof str === 'function' ? str() : str));\n dbg(formatter, ...args);\n }\n return dbg;\n }\n}\n\nexport const log = new Log();\n"],"names":["log","Log","text","process","stdout","write","chalk","info","bold","cyan","success","green","warning","yellow","error","red","debug","namespace","dbg","debugMap","get","createDebug","set","enabled","length","formatter","args","map","str","constructor","Map"],"mappings":";;;;+BA8CaA;;;eAAAA;;;8DA9CK;uBACU;;;;;;;;;;;;;;;;;;;AAI5B,MAAMC;IAOFC,KAAK,GAAGA,IAAc,EAAE;QACpBC,QAAQC,MAAM,CAACC,KAAK,CAACC,IAAAA,cAAK,KAAIJ,QAAQ;IAC1C;IAEAK,KAAK,GAAGL,IAAc,EAAE;QACpBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACC,IAAI,IAAIP,QAAQ;IACpD;IAEAQ,QAAQ,GAAGR,IAAc,EAAE;QACvBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACG,KAAK,IAAIT,QAAQ;IACrD;IAEAU,QAAQ,GAAGV,IAAc,EAAE;QACvBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACK,MAAM,IAAIX,QAAQ;IACtD;IAEAY,MAAM,GAAGZ,IAAc,EAAE;QACrBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACO,GAAG,IAAIb,QAAQ;IACnD;IAEAc,MAAMC,SAAiB,EAAE,GAAGf,IAAW,EAAE;QACrC,IAAIgB,MAAM,IAAI,CAACC,QAAQ,CAACC,GAAG,CAACH;QAC5B,IAAI,CAACC,KAAK;YACNA,MAAMG,IAAAA,kBAAW,EAACJ;YAClB,IAAI,CAACE,QAAQ,CAACG,GAAG,CAACL,WAAWC;QACjC;QACA,IAAIA,IAAIK,OAAO,IAAIrB,KAAKsB,MAAM,EAAE;YAC5B,MAAM,CAACC,WAAW,GAAGC,KAAK,GAAGxB,KAAKyB,GAAG,CAACC,CAAAA,MAAQ,OAAOA,QAAQ,aAAaA,QAAQA;YAClFV,IAAIO,cAAcC;QACtB;QACA,OAAOR;IACX;IAnCAW,aAAc;QAFd,uBAAiBV,YAAjB,KAAA;QAGI,IAAI,CAACA,QAAQ,GAAG,IAAIW;IACxB;AAkCJ;AAEO,MAAM9B,MAAM,IAAIC"}
1
+ {"version":3,"sources":["../../src/utils/log.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { createDebug } from './debug';\n\ntype Debugger = ReturnType<typeof createDebug>;\n\nclass Log {\n private readonly debugMap: Map<string, Debugger>;\n\n constructor() {\n this.debugMap = new Map<string, Debugger>();\n }\n\n get timestamp() {\n return new Date().toLocaleTimeString(undefined, {\n hour12: false,\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n fractionalSecondDigits: 3,\n });\n }\n\n text(...text: string[]) {\n process.stdout.write(chalk(...text) + '\\n');\n }\n\n info(...text: string[]) {\n process.stdout.write(chalk.bold.cyan(...text) + '\\n');\n }\n\n success(...text: string[]) {\n process.stdout.write(chalk.bold.green(...text) + '\\n');\n }\n\n warning(...text: string[]) {\n process.stdout.write(chalk.bold.yellow(...text) + '\\n');\n }\n\n error(...text: string[]) {\n process.stdout.write(chalk.bold.red(...text) + '\\n');\n }\n\n debug(namespace: string, ...text: any[]) {\n let dbg = this.debugMap.get(namespace);\n if (!dbg) {\n dbg = createDebug(namespace);\n this.debugMap.set(namespace, dbg);\n }\n if (dbg.enabled && text.length) {\n const [formatter, ...args] = text.map(str => (typeof str === 'function' ? str() : str));\n dbg(formatter, ...args);\n }\n return dbg;\n }\n}\n\nexport const log = new Log();\n"],"names":["log","Log","timestamp","Date","toLocaleTimeString","undefined","hour12","hour","minute","second","fractionalSecondDigits","text","process","stdout","write","chalk","info","bold","cyan","success","green","warning","yellow","error","red","debug","namespace","dbg","debugMap","get","createDebug","set","enabled","length","formatter","args","map","str","constructor","Map"],"mappings":";;;;+BAwDaA;;;eAAAA;;;8DAxDK;uBACU;;;;;;;;;;;;;;;;;;;AAI5B,MAAMC;IAOF,IAAIC,YAAY;QACZ,OAAO,IAAIC,OAAOC,kBAAkB,CAACC,WAAW;YAC5CC,QAAQ;YACRC,MAAM;YACNC,QAAQ;YACRC,QAAQ;YACRC,wBAAwB;QAC5B;IACJ;IAEAC,KAAK,GAAGA,IAAc,EAAE;QACpBC,QAAQC,MAAM,CAACC,KAAK,CAACC,IAAAA,cAAK,KAAIJ,QAAQ;IAC1C;IAEAK,KAAK,GAAGL,IAAc,EAAE;QACpBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACC,IAAI,IAAIP,QAAQ;IACpD;IAEAQ,QAAQ,GAAGR,IAAc,EAAE;QACvBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACG,KAAK,IAAIT,QAAQ;IACrD;IAEAU,QAAQ,GAAGV,IAAc,EAAE;QACvBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACK,MAAM,IAAIX,QAAQ;IACtD;IAEAY,MAAM,GAAGZ,IAAc,EAAE;QACrBC,QAAQC,MAAM,CAACC,KAAK,CAACC,cAAK,CAACE,IAAI,CAACO,GAAG,IAAIb,QAAQ;IACnD;IAEAc,MAAMC,SAAiB,EAAE,GAAGf,IAAW,EAAE;QACrC,IAAIgB,MAAM,IAAI,CAACC,QAAQ,CAACC,GAAG,CAACH;QAC5B,IAAI,CAACC,KAAK;YACNA,MAAMG,IAAAA,kBAAW,EAACJ;YAClB,IAAI,CAACE,QAAQ,CAACG,GAAG,CAACL,WAAWC;QACjC;QACA,IAAIA,IAAIK,OAAO,IAAIrB,KAAKsB,MAAM,EAAE;YAC5B,MAAM,CAACC,WAAW,GAAGC,KAAK,GAAGxB,KAAKyB,GAAG,CAACC,CAAAA,MAAQ,OAAOA,QAAQ,aAAaA,QAAQA;YAClFV,IAAIO,cAAcC;QACtB;QACA,OAAOR;IACX;IA7CAW,aAAc;QAFd,uBAAiBV,YAAjB,KAAA;QAGI,IAAI,CAACA,QAAQ,GAAG,IAAIW;IACxB;AA4CJ;AAEO,MAAMvC,MAAM,IAAIC"}
@@ -1 +1 @@
1
- {"version":3,"file":"dev-server-config.d.ts","sourceRoot":"","sources":["../../../src/webpack/configs/dev-server-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AASxC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAG7C,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC;AAE3D,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAoB9E"}
1
+ {"version":3,"file":"dev-server-config.d.ts","sourceRoot":"","sources":["../../../src/webpack/configs/dev-server-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AASxC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAG7C,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC;AAE3D,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAgC9E"}
@@ -33,6 +33,17 @@ function devServerConfig(context, overrides) {
33
33
  'Access-Control-Allow-Origin': '*',
34
34
  'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
35
35
  },
36
+ setupMiddlewares: (middlewares, devServer)=>{
37
+ if (devServer.app) {
38
+ devServer.app.use((request, _, next)=>{
39
+ _utils.log.info(`[${_utils.log.timestamp}]: ${request.method} ${request.url}`);
40
+ next();
41
+ });
42
+ } else {
43
+ _utils.log.warning('webpack-dev-server app is not defined');
44
+ }
45
+ return middlewares;
46
+ },
36
47
  ...getDevServerConfig()
37
48
  };
38
49
  /* istanbul ignore next: debug only */ _utils.log.debug('dev-server-config', ()=>JSON.stringify({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/webpack/configs/dev-server-config.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { Configuration } from 'webpack';\nimport {\n allowedWebpackDevServerOptions,\n getWebpackConfiguration,\n isDevServerDisabled,\n log,\n pick,\n} from '../../utils';\nimport { statsConfig } from './stats-config';\nimport { Context, Overrides } from './types';\n\ntype DevServerConfig = NonNullable<Configuration['devServer']>;\ntype Result = Pick<Configuration, 'devServer'> | undefined;\n\nexport function devServerConfig(context: Context, overrides: Overrides): Result {\n if (context.isProduction || isDevServerDisabled()) {\n return;\n }\n\n const devServer = {\n hot: false,\n port: 8080,\n historyApiFallback: true,\n devMiddleware: { writeToDisk: true, ...statsConfig(context, overrides) },\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',\n },\n ...getDevServerConfig(),\n };\n\n /* istanbul ignore next: debug only */\n log.debug('dev-server-config', () => JSON.stringify({ devServer }, null, 2));\n return { devServer };\n}\n\nfunction getDevServerConfig() {\n const webpack = getWebpackConfiguration();\n /* istanbul ignore next: debug only */\n log.debug('dev-server-config', () => JSON.stringify({ webpack }, null, 2));\n\n const result = pick(webpack, allowedWebpackDevServerOptions);\n if (typeof result.proxy === 'string') {\n if (fs.existsSync(result.proxy)) {\n result.proxy = require(path.resolve(result.proxy));\n } else {\n delete result.proxy;\n }\n }\n\n if (result.static === undefined) {\n const contentBase = webpack.contentBase;\n if (contentBase !== undefined) {\n log.warning(CONTENT_BASE_DEPRECATION_WARNING);\n if (typeof contentBase !== 'number') {\n result.static = contentBase;\n }\n } else {\n result.static = '.';\n }\n }\n\n return { ...result, ...webpack.devServer } as Partial<DevServerConfig>;\n}\n\nconst CONTENT_BASE_DEPRECATION_WARNING = `\n DEPRECATION WARNING: webpack.contentBase in package.json is deprecated.\n Use webpack.static instead.\n`\n .replace(/\\n\\s*/g, ' ')\n .trim();\n"],"names":["devServerConfig","context","overrides","isProduction","isDevServerDisabled","devServer","hot","port","historyApiFallback","devMiddleware","writeToDisk","statsConfig","headers","getDevServerConfig","log","debug","JSON","stringify","webpack","getWebpackConfiguration","result","pick","allowedWebpackDevServerOptions","proxy","fs","existsSync","require","path","resolve","static","undefined","contentBase","warning","CONTENT_BASE_DEPRECATION_WARNING","replace","trim"],"mappings":";;;;+BAgBgBA;;;eAAAA;;;2DAhBD;6DACE;uBAQV;6BACqB;;;;;;AAMrB,SAASA,gBAAgBC,OAAgB,EAAEC,SAAoB;IAClE,IAAID,QAAQE,YAAY,IAAIC,IAAAA,0BAAmB,KAAI;QAC/C;IACJ;IAEA,MAAMC,YAAY;QACdC,KAAK;QACLC,MAAM;QACNC,oBAAoB;QACpBC,eAAe;YAAEC,aAAa;YAAM,GAAGC,IAAAA,wBAAW,EAACV,SAASC,UAAU;QAAC;QACvEU,SAAS;YACL,+BAA+B;YAC/B,gCAAgC;QACpC;QACA,GAAGC,oBAAoB;IAC3B;IAEA,oCAAoC,GACpCC,UAAG,CAACC,KAAK,CAAC,qBAAqB,IAAMC,KAAKC,SAAS,CAAC;YAAEZ;QAAU,GAAG,MAAM;IACzE,OAAO;QAAEA;IAAU;AACvB;AAEA,SAASQ;IACL,MAAMK,UAAUC,IAAAA,8BAAuB;IACvC,oCAAoC,GACpCL,UAAG,CAACC,KAAK,CAAC,qBAAqB,IAAMC,KAAKC,SAAS,CAAC;YAAEC;QAAQ,GAAG,MAAM;IAEvE,MAAME,SAASC,IAAAA,WAAI,EAACH,SAASI,qCAA8B;IAC3D,IAAI,OAAOF,OAAOG,KAAK,KAAK,UAAU;QAClC,IAAIC,WAAE,CAACC,UAAU,CAACL,OAAOG,KAAK,GAAG;YAC7BH,OAAOG,KAAK,GAAGG,QAAQC,aAAI,CAACC,OAAO,CAACR,OAAOG,KAAK;QACpD,OAAO;YACH,OAAOH,OAAOG,KAAK;QACvB;IACJ;IAEA,IAAIH,OAAOS,MAAM,KAAKC,WAAW;QAC7B,MAAMC,cAAcb,QAAQa,WAAW;QACvC,IAAIA,gBAAgBD,WAAW;YAC3BhB,UAAG,CAACkB,OAAO,CAACC;YACZ,IAAI,OAAOF,gBAAgB,UAAU;gBACjCX,OAAOS,MAAM,GAAGE;YACpB;QACJ,OAAO;YACHX,OAAOS,MAAM,GAAG;QACpB;IACJ;IAEA,OAAO;QAAE,GAAGT,MAAM;QAAE,GAAGF,QAAQb,SAAS;IAAC;AAC7C;AAEA,MAAM4B,mCAAmC,CAAC;;;AAG1C,CAAC,CACIC,OAAO,CAAC,UAAU,KAClBC,IAAI"}
1
+ {"version":3,"sources":["../../../src/webpack/configs/dev-server-config.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { Configuration } from 'webpack';\nimport {\n allowedWebpackDevServerOptions,\n getWebpackConfiguration,\n isDevServerDisabled,\n log,\n pick,\n} from '../../utils';\nimport { statsConfig } from './stats-config';\nimport { Context, Overrides } from './types';\n\ntype DevServerConfig = NonNullable<Configuration['devServer']>;\ntype Result = Pick<Configuration, 'devServer'> | undefined;\n\nexport function devServerConfig(context: Context, overrides: Overrides): Result {\n if (context.isProduction || isDevServerDisabled()) {\n return;\n }\n\n const devServer: DevServerConfig = {\n hot: false,\n port: 8080,\n historyApiFallback: true,\n devMiddleware: { writeToDisk: true, ...statsConfig(context, overrides) },\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',\n },\n setupMiddlewares: (middlewares, devServer) => {\n if (devServer.app) {\n devServer.app.use((request, _, next) => {\n log.info(`[${log.timestamp}]: ${request.method} ${request.url}`);\n next();\n });\n } else {\n log.warning('webpack-dev-server app is not defined');\n }\n\n return middlewares;\n },\n ...getDevServerConfig(),\n };\n\n /* istanbul ignore next: debug only */\n log.debug('dev-server-config', () => JSON.stringify({ devServer }, null, 2));\n return { devServer };\n}\n\nfunction getDevServerConfig() {\n const webpack = getWebpackConfiguration();\n /* istanbul ignore next: debug only */\n log.debug('dev-server-config', () => JSON.stringify({ webpack }, null, 2));\n\n const result = pick(webpack, allowedWebpackDevServerOptions);\n if (typeof result.proxy === 'string') {\n if (fs.existsSync(result.proxy)) {\n result.proxy = require(path.resolve(result.proxy));\n } else {\n delete result.proxy;\n }\n }\n\n if (result.static === undefined) {\n const contentBase = webpack.contentBase;\n if (contentBase !== undefined) {\n log.warning(CONTENT_BASE_DEPRECATION_WARNING);\n if (typeof contentBase !== 'number') {\n result.static = contentBase;\n }\n } else {\n result.static = '.';\n }\n }\n\n return { ...result, ...webpack.devServer } as Partial<DevServerConfig>;\n}\n\nconst CONTENT_BASE_DEPRECATION_WARNING = `\n DEPRECATION WARNING: webpack.contentBase in package.json is deprecated.\n Use webpack.static instead.\n`\n .replace(/\\n\\s*/g, ' ')\n .trim();\n"],"names":["devServerConfig","context","overrides","isProduction","isDevServerDisabled","devServer","hot","port","historyApiFallback","devMiddleware","writeToDisk","statsConfig","headers","setupMiddlewares","middlewares","app","use","request","_","next","log","info","timestamp","method","url","warning","getDevServerConfig","debug","JSON","stringify","webpack","getWebpackConfiguration","result","pick","allowedWebpackDevServerOptions","proxy","fs","existsSync","require","path","resolve","static","undefined","contentBase","CONTENT_BASE_DEPRECATION_WARNING","replace","trim"],"mappings":";;;;+BAgBgBA;;;eAAAA;;;2DAhBD;6DACE;uBAQV;6BACqB;;;;;;AAMrB,SAASA,gBAAgBC,OAAgB,EAAEC,SAAoB;IAClE,IAAID,QAAQE,YAAY,IAAIC,IAAAA,0BAAmB,KAAI;QAC/C;IACJ;IAEA,MAAMC,YAA6B;QAC/BC,KAAK;QACLC,MAAM;QACNC,oBAAoB;QACpBC,eAAe;YAAEC,aAAa;YAAM,GAAGC,IAAAA,wBAAW,EAACV,SAASC,UAAU;QAAC;QACvEU,SAAS;YACL,+BAA+B;YAC/B,gCAAgC;QACpC;QACAC,kBAAkB,CAACC,aAAaT;YAC5B,IAAIA,UAAUU,GAAG,EAAE;gBACfV,UAAUU,GAAG,CAACC,GAAG,CAAC,CAACC,SAASC,GAAGC;oBAC3BC,UAAG,CAACC,IAAI,CAAC,CAAC,CAAC,EAAED,UAAG,CAACE,SAAS,CAAC,GAAG,EAAEL,QAAQM,MAAM,CAAC,CAAC,EAAEN,QAAQO,GAAG,EAAE;oBAC/DL;gBACJ;YACJ,OAAO;gBACHC,UAAG,CAACK,OAAO,CAAC;YAChB;YAEA,OAAOX;QACX;QACA,GAAGY,oBAAoB;IAC3B;IAEA,oCAAoC,GACpCN,UAAG,CAACO,KAAK,CAAC,qBAAqB,IAAMC,KAAKC,SAAS,CAAC;YAAExB;QAAU,GAAG,MAAM;IACzE,OAAO;QAAEA;IAAU;AACvB;AAEA,SAASqB;IACL,MAAMI,UAAUC,IAAAA,8BAAuB;IACvC,oCAAoC,GACpCX,UAAG,CAACO,KAAK,CAAC,qBAAqB,IAAMC,KAAKC,SAAS,CAAC;YAAEC;QAAQ,GAAG,MAAM;IAEvE,MAAME,SAASC,IAAAA,WAAI,EAACH,SAASI,qCAA8B;IAC3D,IAAI,OAAOF,OAAOG,KAAK,KAAK,UAAU;QAClC,IAAIC,WAAE,CAACC,UAAU,CAACL,OAAOG,KAAK,GAAG;YAC7BH,OAAOG,KAAK,GAAGG,QAAQC,aAAI,CAACC,OAAO,CAACR,OAAOG,KAAK;QACpD,OAAO;YACH,OAAOH,OAAOG,KAAK;QACvB;IACJ;IAEA,IAAIH,OAAOS,MAAM,KAAKC,WAAW;QAC7B,MAAMC,cAAcb,QAAQa,WAAW;QACvC,IAAIA,gBAAgBD,WAAW;YAC3BtB,UAAG,CAACK,OAAO,CAACmB;YACZ,IAAI,OAAOD,gBAAgB,UAAU;gBACjCX,OAAOS,MAAM,GAAGE;YACpB;QACJ,OAAO;YACHX,OAAOS,MAAM,GAAG;QACpB;IACJ;IAEA,OAAO;QAAE,GAAGT,MAAM;QAAE,GAAGF,QAAQzB,SAAS;IAAC;AAC7C;AAEA,MAAMuC,mCAAmC,CAAC;;;AAG1C,CAAC,CACIC,OAAO,CAAC,UAAU,KAClBC,IAAI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/startup",
3
- "version": "31.1.0",
3
+ "version": "31.3.0",
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.1.0",
41
- "@servicetitan/stylelint-config": "31.1.0",
40
+ "@servicetitan/eslint-config": "31.3.0",
41
+ "@servicetitan/stylelint-config": "31.3.0",
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": "Update when https://github.com/swc-project/swc/issues/10535 is resolved"
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": "d01cfe32c50461245ce52c911710e8eb879290e9"
119
+ "gitHead": "697267506bd18238072f19c6f8669c0385c5197b"
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 = ['**/stories.*'];
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(() => (watch = true));
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
- return new Promise((resolve, reject) => {
40
- swcDir(
41
- deepmerge(
42
- {
43
- cliOptions: {
44
- watch: this.watch,
45
- outDir: destination,
46
- stripLeadingPaths: true,
47
- extensions: ['.ts', '.tsx'],
48
- filenames: [source],
49
- ignore,
50
- },
51
- swcOptions: {
52
- jsc: {
53
- parser: {
54
- syntax: 'typescript',
55
- tsx: true,
56
- decorators: true,
57
- },
58
- target,
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
- callbacks: {
76
- onSuccess: (e: { duration: number }) => {
77
- this.logCompletionResults(this.taskTimer.add(e.duration));
78
- if (!this.watch) {
79
- resolve();
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
- packageConfig,
92
- { arrayMerge: overwriteMerge, clone: false }
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
  }
@@ -14,6 +14,14 @@ describe(`[startup] Utils`, () => {
14
14
  stdoutSpy = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
15
15
  });
16
16
 
17
+ test('timestamp() returns the current time in the HH:MM:SS.SSS format', () => {
18
+ jest.useFakeTimers({
19
+ now: new Date('2024-05-14 10:40:00.050'),
20
+ });
21
+
22
+ expect(log.timestamp).toBe('10:40:00.050');
23
+ });
24
+
17
25
  test('text() writes default text', () => {
18
26
  log.text(message);
19
27
 
package/src/utils/log.ts CHANGED
@@ -10,6 +10,16 @@ class Log {
10
10
  this.debugMap = new Map<string, Debugger>();
11
11
  }
12
12
 
13
+ get timestamp() {
14
+ return new Date().toLocaleTimeString(undefined, {
15
+ hour12: false,
16
+ hour: '2-digit',
17
+ minute: '2-digit',
18
+ second: '2-digit',
19
+ fractionalSecondDigits: 3,
20
+ });
21
+ }
22
+
13
23
  text(...text: string[]) {
14
24
  process.stdout.write(chalk(...text) + '\n');
15
25
  }
@@ -65,7 +65,12 @@ jest.mock('../../utils', () => ({
65
65
  isExposeSharedDependencies: jest.fn(),
66
66
  isWebComponent: jest.fn(),
67
67
  loadSharedDependencies: jest.fn(),
68
- log: { debug: jest.fn(), info: jest.fn(), warning: jest.fn() },
68
+ log: {
69
+ debug: jest.fn(),
70
+ info: jest.fn(),
71
+ warning: jest.fn(),
72
+ timestamp: '10:40:00.000',
73
+ },
69
74
  }));
70
75
 
71
76
  describe(`[startup] ${createWebpackConfig.name}`, () => {
@@ -151,6 +156,15 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
151
156
 
152
157
  const subject = () => createWebpackConfig(overrides, options);
153
158
 
159
+ function expectDevServerToBe(devServer: WebpackDevServer.Configuration) {
160
+ expect(subject().devServer).toEqual(
161
+ expect.objectContaining({
162
+ ...devServer,
163
+ setupMiddlewares: expect.any(Function),
164
+ })
165
+ );
166
+ }
167
+
154
168
  test('configures "entry"', () => {
155
169
  expect(subject().entry).toEqual({ main: [`./${destination}/index`] });
156
170
  });
@@ -208,7 +222,75 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
208
222
  };
209
223
 
210
224
  test('configures "devServer"', () => {
211
- expect(subject().devServer).toEqual(defaultDefServerConfig);
225
+ expectDevServerToBe(defaultDefServerConfig);
226
+ });
227
+
228
+ describe('devServer.setupMiddlewares', () => {
229
+ const middlewares: WebpackDevServer.Middleware[] = [];
230
+ let mockDevServer: any;
231
+
232
+ const setupMiddlewaresSubject = () => {
233
+ const { devServer } = subject();
234
+
235
+ return devServer?.setupMiddlewares?.(middlewares, mockDevServer);
236
+ };
237
+
238
+ describe('when devServer.app is defined', () => {
239
+ beforeEach(() => {
240
+ mockDevServer = { app: { use: jest.fn() } };
241
+ });
242
+
243
+ test('calls app.use once to add logging middleware', () => {
244
+ setupMiddlewaresSubject();
245
+ expect(mockDevServer.app.use).toHaveBeenCalledTimes(1);
246
+ });
247
+
248
+ test('returns the original middlewares array', () => {
249
+ expect(setupMiddlewaresSubject()).toBe(middlewares);
250
+ });
251
+
252
+ describe('when request is handled', () => {
253
+ const request = { method: 'GET', url: '/test' };
254
+ const nextMockFn = jest.fn();
255
+
256
+ const simulateRequest = () => {
257
+ const middlewareFn = mockDevServer.app.use.mock.calls[0][0];
258
+
259
+ middlewareFn(request, {}, nextMockFn);
260
+ };
261
+
262
+ beforeEach(() => {
263
+ setupMiddlewaresSubject();
264
+ simulateRequest();
265
+ });
266
+
267
+ test('logs the request with expected format', () => {
268
+ expect(log.info).toHaveBeenCalledWith(
269
+ `[${log.timestamp}]: ${request.method} ${request.url}`
270
+ );
271
+ });
272
+
273
+ test('calls next middleware', () => {
274
+ expect(nextMockFn).toHaveBeenCalled();
275
+ });
276
+ });
277
+ });
278
+
279
+ describe('when devServer.app is not defined', () => {
280
+ beforeEach(() => {
281
+ mockDevServer = { app: undefined };
282
+ });
283
+
284
+ test('logs a warning that webpack-dev-server is not defined', () => {
285
+ setupMiddlewaresSubject();
286
+
287
+ expect(log.warning).toHaveBeenCalledWith('webpack-dev-server app is not defined');
288
+ });
289
+
290
+ test('returns the original middlewares array', () => {
291
+ expect(setupMiddlewaresSubject()).toBe(middlewares);
292
+ });
293
+ });
212
294
  });
213
295
 
214
296
  describe('when "devServer" is disabled', () => {
@@ -234,7 +316,7 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
234
316
  beforeEach(() => (configuration = { webpack: options }));
235
317
 
236
318
  test('adds allowed options to "devServer" configuration', () => {
237
- expect(subject().devServer).toEqual({
319
+ expectDevServerToBe({
238
320
  ...defaultDefServerConfig,
239
321
  headers: options.headers,
240
322
  port: options.port,
@@ -247,7 +329,7 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
247
329
  beforeEach(() => (configuration.webpack = { devServer: options }));
248
330
 
249
331
  test('adds all options to "devServer" configuration', () => {
250
- expect(subject().devServer).toEqual({
332
+ expectDevServerToBe({
251
333
  ...defaultDefServerConfig,
252
334
  ...options,
253
335
  });
@@ -19,7 +19,7 @@ export function devServerConfig(context: Context, overrides: Overrides): Result
19
19
  return;
20
20
  }
21
21
 
22
- const devServer = {
22
+ const devServer: DevServerConfig = {
23
23
  hot: false,
24
24
  port: 8080,
25
25
  historyApiFallback: true,
@@ -28,6 +28,18 @@ export function devServerConfig(context: Context, overrides: Overrides): Result
28
28
  'Access-Control-Allow-Origin': '*',
29
29
  'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
30
30
  },
31
+ setupMiddlewares: (middlewares, devServer) => {
32
+ if (devServer.app) {
33
+ devServer.app.use((request, _, next) => {
34
+ log.info(`[${log.timestamp}]: ${request.method} ${request.url}`);
35
+ next();
36
+ });
37
+ } else {
38
+ log.warning('webpack-dev-server app is not defined');
39
+ }
40
+
41
+ return middlewares;
42
+ },
31
43
  ...getDevServerConfig(),
32
44
  };
33
45
 
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- //# sourceMappingURL=swc-cli.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/cli/tasks/swc-cli.d.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- //# sourceMappingURL=cpx2.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/cli/types/cpx2.d.ts"],"names":[],"mappings":""}