@servicetitan/startup 31.1.0 → 31.2.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 +8 -0
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/log.d.ts.map +1 -1
- package/dist/utils/log.js +9 -0
- package/dist/utils/log.js.map +1 -1
- package/dist/webpack/configs/dev-server-config.d.ts.map +1 -1
- package/dist/webpack/configs/dev-server-config.js +11 -0
- package/dist/webpack/configs/dev-server-config.js.map +1 -1
- package/package.json +4 -4
- package/src/utils/__tests__/log.test.ts +8 -0
- package/src/utils/log.ts +10 -0
- package/src/webpack/__tests__/create-webpack-config.test.ts +86 -4
- package/src/webpack/configs/dev-server-config.ts +13 -1
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,
|
package/dist/utils/log.d.ts
CHANGED
package/dist/utils/log.d.ts.map
CHANGED
|
@@ -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
|
}
|
package/dist/utils/log.js.map
CHANGED
|
@@ -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":";;;;+
|
|
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,
|
|
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","
|
|
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.
|
|
3
|
+
"version": "31.2.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.
|
|
41
|
-
"@servicetitan/stylelint-config": "31.
|
|
40
|
+
"@servicetitan/eslint-config": "31.2.0",
|
|
41
|
+
"@servicetitan/stylelint-config": "31.2.0",
|
|
42
42
|
"@svgr/webpack": "^8.1.0",
|
|
43
43
|
"@swc/cli": "^0.5.0",
|
|
44
44
|
"@swc/core": "1.11.29",
|
|
@@ -112,5 +112,5 @@
|
|
|
112
112
|
"cli": {
|
|
113
113
|
"webpack": false
|
|
114
114
|
},
|
|
115
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "a12efe0333352598f98e5f8772458c8b8d64aa74"
|
|
116
116
|
}
|
|
@@ -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: {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|