@servicetitan/startup 25.0.0 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +1 -0
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/utils/bundle.d.ts.map +1 -1
- package/dist/cli/utils/bundle.js +54 -48
- package/dist/cli/utils/bundle.js.map +1 -1
- package/dist/utils/get-configuration.d.ts +3 -2
- package/dist/utils/get-configuration.d.ts.map +1 -1
- package/dist/utils/get-configuration.js +2 -28
- package/dist/utils/get-configuration.js.map +1 -1
- package/dist/utils/get-package-data.d.ts +1 -0
- package/dist/utils/get-package-data.d.ts.map +1 -1
- package/dist/utils/get-package-data.js +1 -0
- package/dist/utils/get-package-data.js.map +1 -1
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/log.js +1 -1
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/pick.d.ts +2 -0
- package/dist/utils/pick.d.ts.map +1 -0
- package/dist/utils/pick.js +13 -0
- package/dist/utils/pick.js.map +1 -0
- package/dist/webpack/configs/dev-server-config.d.ts +1 -1
- package/dist/webpack/configs/dev-server-config.d.ts.map +1 -1
- package/dist/webpack/configs/dev-server-config.js +46 -5
- package/dist/webpack/configs/dev-server-config.js.map +1 -1
- package/dist/webpack/configs/plugins/bundle-analyser-plugin.d.ts +1 -1
- package/dist/webpack/configs/plugins/bundle-analyser-plugin.d.ts.map +1 -1
- package/dist/webpack/configs/plugins/bundle-analyser-plugin.js +28 -3
- package/dist/webpack/configs/plugins/bundle-analyser-plugin.js.map +1 -1
- package/package.json +11 -12
- package/src/cli/commands/__tests__/start.test.ts +5 -5
- package/src/cli/commands/__tests__/styles-check.test.ts +5 -1
- package/src/cli/commands/start.ts +1 -0
- package/src/cli/utils/__tests__/bundle.test.ts +19 -7
- package/src/cli/utils/bundle.ts +54 -55
- package/src/utils/__tests__/get-configuration.test.ts +0 -60
- package/src/utils/__tests__/get-package-data.test.ts +5 -1
- package/src/utils/__tests__/log.test.ts +2 -2
- package/src/utils/get-configuration.ts +3 -34
- package/src/utils/get-package-data.ts +2 -0
- package/src/utils/index.ts +4 -3
- package/src/utils/log.ts +1 -1
- package/src/utils/pick.ts +8 -0
- package/src/webpack/__tests__/create-webpack-config-shared-dependencies.test.ts +5 -1
- package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +5 -1
- package/src/webpack/__tests__/create-webpack-config.test.ts +148 -20
- package/src/webpack/configs/dev-server-config.ts +61 -12
- package/src/webpack/configs/plugins/bundle-analyser-plugin.ts +32 -6
- package/src/webpack/configs/utils/__tests__/generate-metadata.test.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/startup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/startup",
|
|
6
6
|
"repository": {
|
|
@@ -30,15 +30,14 @@
|
|
|
30
30
|
"@types/moment-locales-webpack-plugin": "~1.2.2",
|
|
31
31
|
"@types/sass": "~1.45.0",
|
|
32
32
|
"@types/webpack-assets-manifest": "~5.1.4",
|
|
33
|
-
"@types/webpack-dev-server": "~3.11.5",
|
|
34
33
|
"@types/yargs": "~17.0.24"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"@babel/preset-env": "~7.
|
|
36
|
+
"@babel/preset-env": "~7.25.3",
|
|
38
37
|
"@jest/core": "~29.7.0",
|
|
39
38
|
"@jest/types": "~29.6.3",
|
|
40
|
-
"@servicetitan/eslint-config": "
|
|
41
|
-
"@servicetitan/stylelint-config": "
|
|
39
|
+
"@servicetitan/eslint-config": "26.0.0",
|
|
40
|
+
"@servicetitan/stylelint-config": "26.0.0",
|
|
42
41
|
"@svgr/webpack": "^8.1.0",
|
|
43
42
|
"@swc/core": "1.6.13",
|
|
44
43
|
"@types/debug": "^4.1.12",
|
|
@@ -47,7 +46,7 @@
|
|
|
47
46
|
"chokidar": "~3.6.0",
|
|
48
47
|
"cpx": "~1.5.0",
|
|
49
48
|
"css-loader": "~7.1.2",
|
|
50
|
-
"debug": "^4.3.
|
|
49
|
+
"debug": "^4.3.6",
|
|
51
50
|
"deepmerge": "~4.3.1",
|
|
52
51
|
"esbuild-loader": "~4.2.2",
|
|
53
52
|
"eslint": "~8.57.0",
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
"jest-circus": "~29.7.0",
|
|
61
60
|
"jest-environment-jsdom": "^29.7.0",
|
|
62
61
|
"jest-fetch-mock": "~3.0.3",
|
|
63
|
-
"lerna": "~8.1.
|
|
62
|
+
"lerna": "~8.1.7",
|
|
64
63
|
"less": "~4.2.0",
|
|
65
64
|
"less-loader": "~12.2.0",
|
|
66
65
|
"less-plugin-npm-import": "~2.1.0",
|
|
@@ -70,16 +69,16 @@
|
|
|
70
69
|
"moment-locales-webpack-plugin": "~1.2.0",
|
|
71
70
|
"multimatch": "~5.0.0",
|
|
72
71
|
"portfinder": "~1.0.32",
|
|
73
|
-
"postcss": "~8.4.
|
|
72
|
+
"postcss": "~8.4.40",
|
|
74
73
|
"prettier": "~2.7.1",
|
|
75
74
|
"sass": "~1.77.8",
|
|
76
|
-
"sass-loader": "~
|
|
75
|
+
"sass-loader": "~16.0.0",
|
|
77
76
|
"source-map-loader": "~5.0.0",
|
|
78
77
|
"string-width": "<5.0.0",
|
|
79
78
|
"style-loader": "~4.0.0",
|
|
80
79
|
"stylelint": "~14.16.1",
|
|
81
80
|
"swc-loader": "0.2.6",
|
|
82
|
-
"ts-jest": "~29.
|
|
81
|
+
"ts-jest": "~29.2.3",
|
|
83
82
|
"ts-loader": "~9.5.1",
|
|
84
83
|
"ts-node": "~10.9.2",
|
|
85
84
|
"typed-css-modules": "~0.9.1",
|
|
@@ -88,7 +87,7 @@
|
|
|
88
87
|
"webpack": "~5.93.0",
|
|
89
88
|
"webpack-assets-manifest": "~5.2.1",
|
|
90
89
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
91
|
-
"webpack-dev-server": "~
|
|
90
|
+
"webpack-dev-server": "~5.0.4",
|
|
92
91
|
"webpack-filter-warnings-plugin": "~1.2.1",
|
|
93
92
|
"webpack-merge": "~6.0.1",
|
|
94
93
|
"webpack-virtual-modules": "~0.6.2",
|
|
@@ -105,5 +104,5 @@
|
|
|
105
104
|
"cli": {
|
|
106
105
|
"webpack": false
|
|
107
106
|
},
|
|
108
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "c19b559c2183cbd7f74814b7b913f3343270756a"
|
|
109
108
|
}
|
|
@@ -69,7 +69,7 @@ describe(`[startup] ${Start.name}`, () => {
|
|
|
69
69
|
'scope': packages.map(({ name }) => name),
|
|
70
70
|
'parallel': true,
|
|
71
71
|
'stream': true,
|
|
72
|
-
'--': ['--watch'],
|
|
72
|
+
'--': ['--color', '--watch'],
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -81,7 +81,7 @@ describe(`[startup] ${Start.name}`, () => {
|
|
|
81
81
|
|
|
82
82
|
expect(lernaExec).toHaveBeenCalledWith(
|
|
83
83
|
expect.objectContaining({
|
|
84
|
-
'--': ['--watch', '--code-coverage'],
|
|
84
|
+
'--': ['--color', '--watch', '--code-coverage'],
|
|
85
85
|
})
|
|
86
86
|
);
|
|
87
87
|
});
|
|
@@ -95,7 +95,7 @@ describe(`[startup] ${Start.name}`, () => {
|
|
|
95
95
|
|
|
96
96
|
expect(lernaExec).toHaveBeenCalledWith(
|
|
97
97
|
expect.objectContaining({
|
|
98
|
-
'--': ['--watch', '--esbuild'],
|
|
98
|
+
'--': ['--color', '--watch', '--esbuild'],
|
|
99
99
|
})
|
|
100
100
|
);
|
|
101
101
|
});
|
|
@@ -109,7 +109,7 @@ describe(`[startup] ${Start.name}`, () => {
|
|
|
109
109
|
|
|
110
110
|
expect(lernaExec).toHaveBeenCalledWith(
|
|
111
111
|
expect.objectContaining({
|
|
112
|
-
'--': ['--watch', '--experimental-bundlers'],
|
|
112
|
+
'--': ['--color', '--watch', '--experimental-bundlers'],
|
|
113
113
|
})
|
|
114
114
|
);
|
|
115
115
|
});
|
|
@@ -123,7 +123,7 @@ describe(`[startup] ${Start.name}`, () => {
|
|
|
123
123
|
|
|
124
124
|
expect(lernaExec).toHaveBeenCalledWith(
|
|
125
125
|
expect.objectContaining({
|
|
126
|
-
'--': ['--watch', `--config "${args.config}"`],
|
|
126
|
+
'--': ['--color', '--watch', `--config "${args.config}"`],
|
|
127
127
|
})
|
|
128
128
|
);
|
|
129
129
|
});
|
|
@@ -33,7 +33,11 @@ describe(`[startup] ${StylesCheck.name}`, () => {
|
|
|
33
33
|
jest.resetAllMocks();
|
|
34
34
|
jest.mocked(isBundle).mockReturnValue(true);
|
|
35
35
|
jest.mocked(getFolders).mockReturnValue({ source: 'src', destination: 'dist' });
|
|
36
|
-
jest.mocked(getPackageData).mockReturnValue({
|
|
36
|
+
jest.mocked(getPackageData).mockReturnValue({
|
|
37
|
+
name: '',
|
|
38
|
+
dependencies: {},
|
|
39
|
+
sharedDependencies: {},
|
|
40
|
+
});
|
|
37
41
|
jest.mocked(loadSharedDependencies).mockReturnValue({});
|
|
38
42
|
});
|
|
39
43
|
|
|
@@ -168,7 +168,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
168
168
|
beforeEach(() => {
|
|
169
169
|
vol.fromJSON(webComponentFS());
|
|
170
170
|
jest.mocked(getFolders).mockReturnValue({ source, destination });
|
|
171
|
-
jest.mocked(getPackageData).mockReturnValue({ dependencies });
|
|
171
|
+
jest.mocked(getPackageData).mockReturnValue({ name: '', dependencies });
|
|
172
172
|
jest.mocked(loadSharedDependencies).mockReturnValue(sharedDependencies);
|
|
173
173
|
});
|
|
174
174
|
|
|
@@ -255,10 +255,10 @@ describe('[startup] Cli Utils', () => {
|
|
|
255
255
|
options = undefined;
|
|
256
256
|
vol.fromJSON(packageFS());
|
|
257
257
|
jest.mocked(WebpackDevServer).mockImplementation((): any => ({
|
|
258
|
-
|
|
258
|
+
startCallback: jest.fn((callback?: (error?: Error) => void) =>
|
|
259
259
|
stopWatching(callback)
|
|
260
260
|
),
|
|
261
|
-
|
|
261
|
+
stopCallback: compiler.close,
|
|
262
262
|
}));
|
|
263
263
|
compiler.watch = jest.fn((_, callback): any => {
|
|
264
264
|
stopWatching(callback);
|
|
@@ -281,17 +281,26 @@ describe('[startup] Cli Utils', () => {
|
|
|
281
281
|
{ name: expectPackageName() }
|
|
282
282
|
);
|
|
283
283
|
expect(webpack).toHaveBeenCalledWith(createWebpackResult);
|
|
284
|
-
expect(WebpackDevServer).toHaveBeenCalledWith(
|
|
284
|
+
expect(WebpackDevServer).toHaveBeenCalledWith(
|
|
285
|
+
{ host: 'localhost', port: 8080 },
|
|
286
|
+
compiler
|
|
287
|
+
);
|
|
285
288
|
});
|
|
286
289
|
|
|
287
290
|
function itUsesConfig(params: { name: string; config: () => Record<string, any> }) {
|
|
288
291
|
test(`uses ${params.name}`, async () => {
|
|
289
292
|
const { devServer, ...config } = params.config();
|
|
293
|
+
const host = devServer.host ?? 'localhost';
|
|
294
|
+
const port =
|
|
295
|
+
typeof devServer.port === 'string' ? Number(devServer.port) : devServer.port;
|
|
290
296
|
|
|
291
297
|
await subject();
|
|
292
298
|
|
|
293
299
|
expect(webpack).toHaveBeenCalledWith(config);
|
|
294
|
-
expect(WebpackDevServer).toHaveBeenCalledWith(
|
|
300
|
+
expect(WebpackDevServer).toHaveBeenCalledWith(
|
|
301
|
+
{ ...devServer, host, port },
|
|
302
|
+
compiler
|
|
303
|
+
);
|
|
295
304
|
});
|
|
296
305
|
}
|
|
297
306
|
|
|
@@ -327,7 +336,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
327
336
|
beforeEach(() => {
|
|
328
337
|
vol.fromJSON(webComponentFS());
|
|
329
338
|
jest.mocked(getFolders).mockReturnValue({ source, destination });
|
|
330
|
-
jest.mocked(getPackageData).mockReturnValue({ dependencies });
|
|
339
|
+
jest.mocked(getPackageData).mockReturnValue({ name: '', dependencies });
|
|
331
340
|
jest.mocked(loadSharedDependencies).mockReturnValue(sharedDependencies);
|
|
332
341
|
});
|
|
333
342
|
|
|
@@ -344,7 +353,10 @@ describe('[startup] Cli Utils', () => {
|
|
|
344
353
|
});
|
|
345
354
|
expect(webpack).toHaveBeenCalledWith(createWebpackResult);
|
|
346
355
|
expect(compiler.watch).toHaveBeenCalled();
|
|
347
|
-
expect(WebpackDevServer).toHaveBeenCalledWith(
|
|
356
|
+
expect(WebpackDevServer).toHaveBeenCalledWith(
|
|
357
|
+
{ host: 'localhost', port: 8080 },
|
|
358
|
+
compiler
|
|
359
|
+
);
|
|
348
360
|
});
|
|
349
361
|
|
|
350
362
|
function itUsesConfig(params: { name: string; config: () => Record<string, any> }) {
|
package/src/cli/utils/bundle.ts
CHANGED
|
@@ -38,26 +38,6 @@ export async function bundle(options: Options = {}) {
|
|
|
38
38
|
const config = readWebpackConfig({ ...options, fallback });
|
|
39
39
|
const { buildStat, codeCoverage, esbuild, experimentalBundlers } = options;
|
|
40
40
|
|
|
41
|
-
const run = async (config: Configuration) => {
|
|
42
|
-
const compiler = webpack(config);
|
|
43
|
-
|
|
44
|
-
const stats = await new Promise<webpack.Stats>((resolve, reject) => {
|
|
45
|
-
compiler.run((error, stats) => {
|
|
46
|
-
if (!stats || error) {
|
|
47
|
-
return reject(error ?? new Error('Something went wrong.'));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (stats.hasErrors()) {
|
|
51
|
-
return reject(stats.toString('errors-only'));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
compiler.close(() => resolve(stats));
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
process.stdout.write(stats.toString(config.stats) + '\n');
|
|
59
|
-
};
|
|
60
|
-
|
|
61
41
|
const webpackOptions = { name, buildStat, codeCoverage, esbuild, experimentalBundlers };
|
|
62
42
|
|
|
63
43
|
if (isWebComponent()) {
|
|
@@ -83,40 +63,6 @@ export async function bundleWatch(options: Options = {}) {
|
|
|
83
63
|
const config = readWebpackConfig({ ...options, fallback: `./${webpackDevConfigFileName}` });
|
|
84
64
|
const { codeCoverage, esbuild, experimentalBundlers } = options;
|
|
85
65
|
|
|
86
|
-
const runServe = async ({ devServer = {}, ...config }: Configuration) => {
|
|
87
|
-
const compiler = webpack(config);
|
|
88
|
-
const host = devServer.host ?? 'localhost';
|
|
89
|
-
const port = await getPortPromise({
|
|
90
|
-
port: devServer.port ?? 8080,
|
|
91
|
-
host,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return new Promise<void>((_0, reject) => {
|
|
95
|
-
const server = new WebpackDevServer(compiler, devServer);
|
|
96
|
-
|
|
97
|
-
server.listen(port, host, e => {
|
|
98
|
-
if (e) {
|
|
99
|
-
server.close(() => {
|
|
100
|
-
reject(e);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const run = async (config: Configuration) => {
|
|
108
|
-
const compiler = webpack(config);
|
|
109
|
-
return new Promise<void>((_0, reject) => {
|
|
110
|
-
const watching = compiler.watch({}, e => {
|
|
111
|
-
if (e) {
|
|
112
|
-
watching.close(() => {
|
|
113
|
-
reject(e);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
|
|
120
66
|
if (isWebComponent()) {
|
|
121
67
|
const webpackConfig: Overrides = {
|
|
122
68
|
configuration: { ...config?.configuration, mode },
|
|
@@ -124,7 +70,7 @@ export async function bundleWatch(options: Options = {}) {
|
|
|
124
70
|
};
|
|
125
71
|
|
|
126
72
|
return Promise.all([
|
|
127
|
-
|
|
73
|
+
runWatch(
|
|
128
74
|
createWebpackConfig(webpackConfig, {
|
|
129
75
|
codeCoverage,
|
|
130
76
|
embed: true,
|
|
@@ -162,3 +108,56 @@ function readConfig(relativePath?: string): Record<string, any> | undefined {
|
|
|
162
108
|
return require(path.resolve(relativePath));
|
|
163
109
|
}
|
|
164
110
|
}
|
|
111
|
+
|
|
112
|
+
async function run(config: Configuration) {
|
|
113
|
+
const compiler = webpack(config);
|
|
114
|
+
|
|
115
|
+
const stats = await new Promise<webpack.Stats>((resolve, reject) => {
|
|
116
|
+
compiler.run((error, stats) => {
|
|
117
|
+
if (!stats || error) {
|
|
118
|
+
return reject(error ?? new Error('Something went wrong.'));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (stats.hasErrors()) {
|
|
122
|
+
return reject(stats.toString('errors-only'));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
compiler.close(() => resolve(stats));
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
process.stdout.write(stats.toString(config.stats) + '\n');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function runServe({ devServer = {}, ...config }: Configuration) {
|
|
133
|
+
const compiler = webpack(config);
|
|
134
|
+
const host = devServer.host ?? 'localhost';
|
|
135
|
+
const port = await getPortPromise({
|
|
136
|
+
port: Number(devServer.port) || 8080,
|
|
137
|
+
host,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return new Promise<void>((_0, reject) => {
|
|
141
|
+
const server = new WebpackDevServer({ ...devServer, host, port }, compiler);
|
|
142
|
+
server.startCallback(e => {
|
|
143
|
+
if (e) {
|
|
144
|
+
server.stopCallback(() => {
|
|
145
|
+
reject(e);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function runWatch(config: Configuration) {
|
|
153
|
+
const compiler = webpack(config);
|
|
154
|
+
return new Promise<void>((_0, reject) => {
|
|
155
|
+
const watching = compiler.watch({}, e => {
|
|
156
|
+
if (e) {
|
|
157
|
+
watching.close(() => {
|
|
158
|
+
reject(e);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { fs, vol } from 'memfs';
|
|
2
|
-
import WebpackDevServer from 'webpack-dev-server';
|
|
3
|
-
import path from 'path';
|
|
4
2
|
|
|
5
3
|
import {
|
|
6
4
|
getConfiguration,
|
|
7
5
|
getConfigurationSafe,
|
|
8
|
-
getDevServerConfiguration,
|
|
9
6
|
getESLintConfiguration,
|
|
10
7
|
getJestConfiguration,
|
|
11
8
|
getStylelintConfiguration,
|
|
@@ -137,63 +134,6 @@ describe('[startup] Utils', () => {
|
|
|
137
134
|
});
|
|
138
135
|
});
|
|
139
136
|
|
|
140
|
-
describe(`${getDevServerConfiguration.name}`, () => {
|
|
141
|
-
const subject = () => getDevServerConfiguration();
|
|
142
|
-
|
|
143
|
-
itReturns(subject, undefined);
|
|
144
|
-
|
|
145
|
-
describe('with "cli.webpack"', () => {
|
|
146
|
-
const webpack: WebpackDevServer.Configuration = {
|
|
147
|
-
// allowed options
|
|
148
|
-
contentBase: 'foo',
|
|
149
|
-
headers: { foo: 'bar' },
|
|
150
|
-
port: 9000,
|
|
151
|
-
proxy: { baz: 'qux' },
|
|
152
|
-
// example disallowed options
|
|
153
|
-
compress: true,
|
|
154
|
-
clientLogLevel: 'debug',
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
beforeEach(() => mockPackageJson({ cli: { webpack } }));
|
|
158
|
-
|
|
159
|
-
test('returns allowed options from "cli.webpack', () => {
|
|
160
|
-
const { contentBase, headers, port, proxy } = webpack;
|
|
161
|
-
expect(subject()).toEqual({ contentBase, headers, port, proxy });
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('when "cli.webpack.proxy" is a path', () => {
|
|
165
|
-
const proxy = 'proxy.js';
|
|
166
|
-
const proxyConfig = { cli: { webpack: { ...webpack, proxy } } };
|
|
167
|
-
|
|
168
|
-
beforeEach(() => mockPackageJson(proxyConfig));
|
|
169
|
-
|
|
170
|
-
describe('when file does not exist', () => {
|
|
171
|
-
test('drops the proxy option', () => {
|
|
172
|
-
expect(subject()?.proxy).toBeUndefined();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('when file exists', () => {
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
vol.fromJSON({
|
|
179
|
-
...packageJsonFS(proxyConfig),
|
|
180
|
-
[proxy]: JSON.stringify(webpack.proxy),
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Have to mock proxy.js because our fs is virtual, but require() is not
|
|
184
|
-
jest.doMock(path.resolve('proxy.js'), () => webpack.proxy, {
|
|
185
|
-
virtual: true,
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('loads proxy option from the file', () => {
|
|
190
|
-
expect(subject()?.proxy).toEqual(webpack.proxy);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
137
|
describe(`${getESLintConfiguration.name}`, () => {
|
|
198
138
|
const subject = () => getESLintConfiguration();
|
|
199
139
|
|
|
@@ -13,7 +13,10 @@ describe(`[startup] Utils`, () => {
|
|
|
13
13
|
beforeEach(() => {
|
|
14
14
|
packages = {
|
|
15
15
|
[ancestorPackageJson]: { dependencies: { foo: '1.0.0', bar: '2.0.0' } },
|
|
16
|
-
[packageJson]: {
|
|
16
|
+
[packageJson]: {
|
|
17
|
+
name: 'packageName',
|
|
18
|
+
dependencies: { foo: '1.1.0', baz: '3.0.0' },
|
|
19
|
+
},
|
|
17
20
|
};
|
|
18
21
|
jest.mocked(readJson).mockImplementation(path => packages[path] ?? {});
|
|
19
22
|
});
|
|
@@ -22,6 +25,7 @@ describe(`[startup] Utils`, () => {
|
|
|
22
25
|
|
|
23
26
|
test(`returns merged dependencies from ${packageJson} and ${ancestorPackageJson}`, () => {
|
|
24
27
|
expect(subject()).toEqual({
|
|
28
|
+
name: packages[packageJson].name,
|
|
25
29
|
dependencies: {
|
|
26
30
|
...packages[ancestorPackageJson].dependencies,
|
|
27
31
|
...packages[packageJson].dependencies,
|
|
@@ -26,10 +26,10 @@ describe(`[startup] Utils`, () => {
|
|
|
26
26
|
expect(stdoutSpy).toHaveBeenCalledWith(`${chalk.bold.green(message)}\n`);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
test('warning() writes
|
|
29
|
+
test('warning() writes yellow text', () => {
|
|
30
30
|
log.warning(message);
|
|
31
31
|
|
|
32
|
-
expect(stdoutSpy).toHaveBeenCalledWith(`${chalk.bold.
|
|
32
|
+
expect(stdoutSpy).toHaveBeenCalledWith(`${chalk.bold.yellow(message)}\n`);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('error() writes red text', () => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
|
|
4
3
|
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
|
|
@@ -7,7 +6,7 @@ import { LinterOptions } from 'stylelint';
|
|
|
7
6
|
import { Config } from '@jest/types';
|
|
8
7
|
import { readJson, readJsonSafe } from './read-json';
|
|
9
8
|
|
|
10
|
-
const allowedWebpackDevServerOptions = ['headers', 'port', 'proxy', '
|
|
9
|
+
export const allowedWebpackDevServerOptions = ['headers', 'port', 'proxy', 'static'] as const;
|
|
11
10
|
|
|
12
11
|
type ElementType<T> = T extends readonly (infer ElementType)[] ? ElementType : never;
|
|
13
12
|
|
|
@@ -16,8 +15,10 @@ export interface WebpackConfiguration
|
|
|
16
15
|
Pick<WebpackDevServerConfiguration, ElementType<typeof allowedWebpackDevServerOptions>>,
|
|
17
16
|
'proxy'
|
|
18
17
|
> {
|
|
18
|
+
'contentBase'?: boolean | string | string[] | number; // deprecated 2024-07
|
|
19
19
|
'custom-style-rules'?: boolean;
|
|
20
20
|
'expose-shared-dependencies'?: boolean;
|
|
21
|
+
'devServer'?: WebpackDevServerConfiguration;
|
|
21
22
|
'disable-style-check'?: boolean;
|
|
22
23
|
'proxy'?: WebpackDevServerConfiguration['proxy'] | string;
|
|
23
24
|
}
|
|
@@ -89,29 +90,6 @@ export function getConfigurationSafe(locationOrJson: LocationOrJson = './'): Con
|
|
|
89
90
|
return json?.cli ?? {};
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
export function getDevServerConfiguration() {
|
|
93
|
-
const configuration = getConfiguration();
|
|
94
|
-
|
|
95
|
-
if (typeof configuration.webpack !== 'object') {
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const result = pick(configuration.webpack, allowedWebpackDevServerOptions);
|
|
100
|
-
|
|
101
|
-
if (typeof result.proxy === 'string') {
|
|
102
|
-
if (fs.existsSync(result.proxy)) {
|
|
103
|
-
result.proxy = require(path.resolve(result.proxy));
|
|
104
|
-
} else {
|
|
105
|
-
delete result.proxy;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return result as Pick<
|
|
110
|
-
WebpackDevServerConfiguration,
|
|
111
|
-
ElementType<typeof allowedWebpackDevServerOptions>
|
|
112
|
-
>;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
93
|
export function getESLintConfiguration() {
|
|
116
94
|
return getConfiguration().lint?.eslint ?? {};
|
|
117
95
|
}
|
|
@@ -171,12 +149,3 @@ export function isWebComponent() {
|
|
|
171
149
|
const config = getConfiguration()['web-component'];
|
|
172
150
|
return config === true || typeof config === 'object';
|
|
173
151
|
}
|
|
174
|
-
|
|
175
|
-
function pick<T extends object, K extends keyof T>(target: T, keys: readonly K[]) {
|
|
176
|
-
return keys.reduce((result, key) => {
|
|
177
|
-
if (Object.hasOwn(target, key)) {
|
|
178
|
-
result[key] = target[key];
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
|
-
}, {} as Pick<T, K>);
|
|
182
|
-
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { readJson } from './read-json';
|
|
2
2
|
|
|
3
3
|
export function getPackageData(): {
|
|
4
|
+
name: string;
|
|
4
5
|
dependencies: Record<string, string>;
|
|
5
6
|
sharedDependencies?: Record<string, string>;
|
|
6
7
|
} {
|
|
7
8
|
const packageJson = readJson('./package.json');
|
|
8
9
|
|
|
9
10
|
return {
|
|
11
|
+
name: packageJson.name,
|
|
10
12
|
dependencies: {
|
|
11
13
|
...readJson('../../package.json').dependencies,
|
|
12
14
|
...packageJson.dependencies,
|
package/src/utils/index.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export * from './get-configuration';
|
|
2
2
|
export * from './get-destination-folders';
|
|
3
3
|
export * from './get-folders';
|
|
4
|
+
export * from './get-jest-config';
|
|
5
|
+
export * from './get-package-data';
|
|
4
6
|
export * from './get-package-name';
|
|
5
7
|
export * from './get-packages';
|
|
6
|
-
export * from './get-package-data';
|
|
7
8
|
export * from './get-startup-version';
|
|
8
9
|
export * from './get-tsconfig';
|
|
10
|
+
export * from './load-shared-dependencies';
|
|
9
11
|
export * from './log';
|
|
12
|
+
export * from './pick';
|
|
10
13
|
export * from './read-json';
|
|
11
14
|
export * from './to-array';
|
|
12
|
-
export * from './load-shared-dependencies';
|
|
13
|
-
export * from './get-jest-config';
|
package/src/utils/log.ts
CHANGED
|
@@ -70,7 +70,11 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
|
|
|
70
70
|
|
|
71
71
|
jest.mocked(getFolders).mockReturnValue({ source, destination });
|
|
72
72
|
jest.mocked(getModuleEntryPath).mockImplementation(name => `${name}/entryPath`);
|
|
73
|
-
jest.mocked(getPackageData).mockReturnValue({
|
|
73
|
+
jest.mocked(getPackageData).mockReturnValue({
|
|
74
|
+
name: '',
|
|
75
|
+
dependencies,
|
|
76
|
+
sharedDependencies,
|
|
77
|
+
});
|
|
74
78
|
jest.mocked(getPackageDependencyVersion).mockImplementation(
|
|
75
79
|
(_, defaultVersion) => defaultVersion
|
|
76
80
|
);
|
|
@@ -95,7 +95,11 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
|
|
|
95
95
|
|
|
96
96
|
jest.mocked(getCallerFile).mockReturnValue('');
|
|
97
97
|
jest.mocked(getFolders).mockReturnValue({ source, destination });
|
|
98
|
-
jest.mocked(getPackageData).mockReturnValue({
|
|
98
|
+
jest.mocked(getPackageData).mockReturnValue({
|
|
99
|
+
name: packageName,
|
|
100
|
+
dependencies: {},
|
|
101
|
+
sharedDependencies: {},
|
|
102
|
+
});
|
|
99
103
|
jest.mocked(getPackages).mockReturnValue([]);
|
|
100
104
|
jest.mocked(getTsConfig).mockReturnValue(tsConfig);
|
|
101
105
|
jest.mocked(isLegacyRoot).mockReturnValue(false);
|