@servicetitan/startup 22.19.0 → 22.20.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/build.d.ts +1 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +1 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/bundle-package.d.ts +5 -3
- package/dist/cli/commands/bundle-package.d.ts.map +1 -1
- package/dist/cli/commands/bundle-package.js +7 -2
- package/dist/cli/commands/bundle-package.js.map +1 -1
- package/dist/cli/commands/start.d.ts +5 -4
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +3 -0
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/utils/bundle.d.ts +2 -0
- package/dist/cli/utils/bundle.d.ts.map +1 -1
- package/dist/cli/utils/bundle.js +14 -7
- package/dist/cli/utils/bundle.js.map +1 -1
- package/dist/webpack/configs/plugins/provide-react-plugin.d.ts +1 -1
- package/dist/webpack/configs/plugins/provide-react-plugin.d.ts.map +1 -1
- package/dist/webpack/configs/plugins/provide-react-plugin.js +2 -2
- package/dist/webpack/configs/plugins/provide-react-plugin.js.map +1 -1
- package/dist/webpack/configs/rules/tsx-rules.d.ts +1 -1
- package/dist/webpack/configs/rules/tsx-rules.d.ts.map +1 -1
- package/dist/webpack/configs/rules/tsx-rules.js +27 -7
- package/dist/webpack/configs/rules/tsx-rules.js.map +1 -1
- package/dist/webpack/configs/types.d.ts +1 -0
- package/dist/webpack/configs/types.d.ts.map +1 -1
- package/dist/webpack/create-webpack-config.d.ts.map +1 -1
- package/dist/webpack/create-webpack-config.js +2 -1
- package/dist/webpack/create-webpack-config.js.map +1 -1
- package/dist/webpack/types.d.ts +2 -0
- package/dist/webpack/types.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/cli/commands/__tests__/build.test.ts +14 -0
- package/src/cli/commands/__tests__/bundle-package.test.ts +8 -4
- package/src/cli/commands/__tests__/init.test.ts +5 -4
- package/src/cli/commands/__tests__/mfe-package-clean.test.ts +4 -3
- package/src/cli/commands/__tests__/mfe-package-publish.test.ts +5 -4
- package/src/cli/commands/__tests__/mfe-publish.test.ts +4 -3
- package/src/cli/commands/__tests__/start.test.ts +14 -0
- package/src/cli/commands/__tests__/styles-check.test.ts +12 -11
- package/src/cli/commands/build.ts +2 -0
- package/src/cli/commands/bundle-package.ts +13 -5
- package/src/cli/commands/start.ts +8 -4
- package/src/cli/utils/__tests__/bundle.test.ts +15 -14
- package/src/cli/utils/__tests__/eslint.test.ts +11 -4
- package/src/cli/utils/__tests__/get-module-type.test.ts +10 -15
- package/src/cli/utils/__tests__/is-module-installed.test.ts +6 -7
- package/src/cli/utils/__tests__/tcm.test.ts +6 -5
- package/src/cli/utils/__tests__/tsc.test.ts +6 -7
- package/src/cli/utils/bundle.ts +25 -7
- package/src/utils/__tests__/get-configuration.test.ts +20 -14
- package/src/utils/__tests__/get-destination-folders.test.ts +11 -13
- package/src/utils/__tests__/get-folders.test.ts +8 -6
- package/src/utils/__tests__/get-tsconfig.test.ts +6 -4
- package/src/utils/__tests__/read-json.test.ts +12 -16
- package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +6 -5
- package/src/webpack/__tests__/create-webpack-config.test.ts +48 -9
- package/src/webpack/configs/plugins/provide-react-plugin.ts +2 -2
- package/src/webpack/configs/rules/tsx-rules.ts +32 -10
- package/src/webpack/configs/types.ts +1 -0
- package/src/webpack/configs/utils/__tests__/generate-metadata.test.ts +9 -12
- package/src/webpack/configs/utils/__tests__/get-startup-version.test.ts +6 -10
- package/src/webpack/create-webpack-config.ts +3 -1
- package/src/webpack/types.ts +2 -0
- package/template/.gitignore +4 -0
|
@@ -89,6 +89,20 @@ describe(`[startup] ${Start.name}`, () => {
|
|
|
89
89
|
});
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
+
describe('with "experimental-bundlers"', () => {
|
|
93
|
+
beforeEach(() => (args['experimental-bundlers'] = true));
|
|
94
|
+
|
|
95
|
+
test('enables swc-loader', async () => {
|
|
96
|
+
await subject();
|
|
97
|
+
|
|
98
|
+
expect(exec).toHaveBeenCalledWith(
|
|
99
|
+
expect.objectContaining({
|
|
100
|
+
'--': ['--watch', '--experimental-bundlers'],
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
92
106
|
describe('with "config"', () => {
|
|
93
107
|
beforeEach(() => (args.config = 'foo.config.js'));
|
|
94
108
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fs, vol } from 'memfs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import {
|
|
4
4
|
getFolders,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
|
|
12
12
|
import { StylesCheck } from '../styles-check';
|
|
13
13
|
|
|
14
|
+
jest.mock('fs', () => fs);
|
|
14
15
|
jest.mock('../../../utils', () => ({
|
|
15
16
|
...jest.requireActual('../../../utils'),
|
|
16
17
|
getFolders: jest.fn(),
|
|
@@ -30,7 +31,7 @@ describe(`[startup] ${StylesCheck.name}`, () => {
|
|
|
30
31
|
jest.mocked(getFolders).mockReturnValue({ source: 'src', destination: 'dist' });
|
|
31
32
|
});
|
|
32
33
|
|
|
33
|
-
afterEach(() =>
|
|
34
|
+
afterEach(() => vol.reset());
|
|
34
35
|
|
|
35
36
|
test("warns that application doesn't have design-system.css", async () => {
|
|
36
37
|
await subject();
|
|
@@ -70,13 +71,11 @@ describe(`[startup] ${StylesCheck.name}`, () => {
|
|
|
70
71
|
const systemMinCss = "@import '~@servicetitan/design-system/dist/system.min.css';";
|
|
71
72
|
|
|
72
73
|
beforeEach(() => {
|
|
73
|
-
|
|
74
|
-
src:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
'styles': { 'baz.css': `${systemMinCss}\r\n` },
|
|
79
|
-
},
|
|
74
|
+
vol.fromJSON({
|
|
75
|
+
'src/design-system.css': [tokenCss, anvilFontsCss, systemMinCss].join('\r\n'),
|
|
76
|
+
'src/foo.css': `${tokenCss}\r\n`,
|
|
77
|
+
'src/bar.less': `${anvilFontsCss}\r\n`,
|
|
78
|
+
'src/styles/baz.css': `${systemMinCss}\r\n`,
|
|
80
79
|
});
|
|
81
80
|
});
|
|
82
81
|
|
|
@@ -89,13 +88,15 @@ describe(`[startup] ${StylesCheck.name}`, () => {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
const errors = jest.mocked(log.error).mock.calls[0][0].split('\n');
|
|
92
|
-
|
|
91
|
+
const expectedErrors = [
|
|
93
92
|
expect.stringMatching(/style check error/i),
|
|
94
93
|
expect.stringMatching(/style check failed/i),
|
|
95
94
|
`file bar.less contains link to "${anvilFontsCss}"`,
|
|
96
95
|
`file foo.css contains link to "${tokenCss}"`,
|
|
97
96
|
`file ${path.join('styles', 'baz.css')} contains link to "${systemMinCss}"`,
|
|
98
|
-
]
|
|
97
|
+
];
|
|
98
|
+
expect(errors).toEqual(expect.arrayContaining(expectedErrors));
|
|
99
|
+
expect(errors.length).toEqual(expectedErrors.length);
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
|
|
@@ -8,6 +8,7 @@ interface Args {
|
|
|
8
8
|
'cdn-path'?: string;
|
|
9
9
|
'config'?: string;
|
|
10
10
|
'esbuild'?: boolean;
|
|
11
|
+
'experimental-bundlers'?: boolean;
|
|
11
12
|
'ignore'?: string | string[];
|
|
12
13
|
'scope'?: string | string[];
|
|
13
14
|
'stat'?: boolean;
|
|
@@ -51,6 +52,7 @@ export class Build implements Command {
|
|
|
51
52
|
'--': [
|
|
52
53
|
...[this.args.config ? `--config "${this.args.config}"` : undefined],
|
|
53
54
|
...[this.args.esbuild ? '--esbuild' : undefined],
|
|
55
|
+
...[this.args['experimental-bundlers'] ? '--experimental-bundlers' : undefined],
|
|
54
56
|
...[this.args.stat ? '--stat' : undefined],
|
|
55
57
|
].filter(item => item),
|
|
56
58
|
});
|
|
@@ -5,9 +5,11 @@ import { bundle, bundleWatch, getModuleType } from '../utils';
|
|
|
5
5
|
import { Command } from '.';
|
|
6
6
|
|
|
7
7
|
interface Args {
|
|
8
|
-
config?: string;
|
|
9
|
-
stat?: boolean;
|
|
10
|
-
watch?: boolean;
|
|
8
|
+
'config'?: string;
|
|
9
|
+
'stat'?: boolean;
|
|
10
|
+
'watch'?: boolean;
|
|
11
|
+
'esbuild'?: boolean;
|
|
12
|
+
'experimental-bundlers'?: boolean;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export class BundlePackage implements Command {
|
|
@@ -25,10 +27,16 @@ export class BundlePackage implements Command {
|
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
const options = {
|
|
31
|
+
config,
|
|
32
|
+
esbuild: this.args.esbuild,
|
|
33
|
+
experimentalBundlers: this.args['experimental-bundlers'],
|
|
34
|
+
};
|
|
35
|
+
|
|
28
36
|
if (!watch) {
|
|
29
|
-
await bundle({ buildStat: stat,
|
|
37
|
+
await bundle({ buildStat: stat, ...options });
|
|
30
38
|
} else {
|
|
31
|
-
await bundleWatch(
|
|
39
|
+
await bundleWatch(options);
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
}
|
|
@@ -5,10 +5,11 @@ import { tsc, tscWatch } from '../utils';
|
|
|
5
5
|
import { Command } from '.';
|
|
6
6
|
|
|
7
7
|
interface Args {
|
|
8
|
-
config?: string;
|
|
9
|
-
esbuild?: boolean;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
'config'?: string;
|
|
9
|
+
'esbuild'?: boolean;
|
|
10
|
+
'experimental-bundlers'?: boolean;
|
|
11
|
+
'ignore'?: string | string[];
|
|
12
|
+
'scope'?: string | string[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export class Start implements Command {
|
|
@@ -60,6 +61,9 @@ export class Start implements Command {
|
|
|
60
61
|
'--watch',
|
|
61
62
|
this.args.config ? `--config "${this.args.config}"` : undefined,
|
|
62
63
|
this.args.esbuild ? '--esbuild' : undefined,
|
|
64
|
+
this.args['experimental-bundlers']
|
|
65
|
+
? '--experimental-bundlers'
|
|
66
|
+
: undefined,
|
|
63
67
|
].filter(item => item),
|
|
64
68
|
}),
|
|
65
69
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fs, vol } from 'memfs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import webpack from 'webpack';
|
|
4
4
|
import WebpackDevServer from 'webpack-dev-server';
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
webpackProdConfigFileName,
|
|
14
14
|
} from '../bundle';
|
|
15
15
|
|
|
16
|
+
jest.mock('fs', () => fs);
|
|
16
17
|
jest.mock('webpack', () => jest.fn());
|
|
17
18
|
jest.mock('webpack-dev-server');
|
|
18
19
|
jest.mock('../../../utils', () => ({
|
|
@@ -36,7 +37,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
36
37
|
compiler = { close: jest.fn(callback => callback()) };
|
|
37
38
|
});
|
|
38
39
|
|
|
39
|
-
afterEach(() =>
|
|
40
|
+
afterEach(() => vol.reset());
|
|
40
41
|
|
|
41
42
|
function expectPackageName() {
|
|
42
43
|
const name = pkg.name.replace(/\//g, '-').replace(/[^\w-]/g, '');
|
|
@@ -61,7 +62,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
61
62
|
let stdoutSpy: jest.SpyInstance;
|
|
62
63
|
|
|
63
64
|
beforeEach(() => {
|
|
64
|
-
|
|
65
|
+
vol.fromJSON(packageFS());
|
|
65
66
|
options = { buildStat: false };
|
|
66
67
|
stdoutSpy = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
|
|
67
68
|
compiler.run = jest.fn(callback => callback(null, stats as any));
|
|
@@ -138,14 +139,14 @@ describe('[startup] Cli Utils', () => {
|
|
|
138
139
|
describe(`with ${webpackProdConfigFileName} config`, () => {
|
|
139
140
|
const FS = { ...packageFS(), [webpackProdConfigFileName]: '' };
|
|
140
141
|
|
|
141
|
-
beforeEach(() =>
|
|
142
|
+
beforeEach(() => vol.fromJSON(FS));
|
|
142
143
|
|
|
143
144
|
itUsesConfig({ name: webpackProdConfigFileName, config: () => prodConfig });
|
|
144
145
|
|
|
145
146
|
describe('with custom config', () => {
|
|
146
147
|
beforeEach(() => {
|
|
147
148
|
options = { config: customConfigFileName };
|
|
148
|
-
|
|
149
|
+
vol.fromJSON({ ...FS, [customConfigFileName]: '' });
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
itUsesConfig({ name: 'custom config', config: () => customConfig });
|
|
@@ -165,7 +166,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
165
166
|
const sharedDependencies = { react: 'SharedDependencies.React' };
|
|
166
167
|
|
|
167
168
|
beforeEach(() => {
|
|
168
|
-
|
|
169
|
+
vol.fromJSON(webComponentFS());
|
|
169
170
|
jest.mocked(getFolders).mockReturnValue({ source, destination });
|
|
170
171
|
jest.mocked(getPackageData).mockReturnValue({ dependencies });
|
|
171
172
|
jest.mocked(loadSharedDependencies).mockReturnValue(sharedDependencies);
|
|
@@ -210,14 +211,14 @@ describe('[startup] Cli Utils', () => {
|
|
|
210
211
|
describe(`with ${webpackProdConfigFileName} config`, () => {
|
|
211
212
|
const FS = { ...webComponentFS(), [webpackProdConfigFileName]: '' };
|
|
212
213
|
|
|
213
|
-
beforeEach(() =>
|
|
214
|
+
beforeEach(() => vol.fromJSON(FS));
|
|
214
215
|
|
|
215
216
|
itUsesConfig({ name: webpackProdConfigFileName, config: () => prodConfig });
|
|
216
217
|
|
|
217
218
|
describe('with custom config', () => {
|
|
218
219
|
beforeEach(() => {
|
|
219
220
|
options = { config: customConfigFileName };
|
|
220
|
-
|
|
221
|
+
vol.fromJSON({ ...FS, [customConfigFileName]: '' });
|
|
221
222
|
});
|
|
222
223
|
|
|
223
224
|
itUsesConfig({ name: 'custom config', config: () => customConfig });
|
|
@@ -252,7 +253,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
252
253
|
|
|
253
254
|
beforeEach(() => {
|
|
254
255
|
options = undefined;
|
|
255
|
-
|
|
256
|
+
vol.fromJSON(packageFS());
|
|
256
257
|
jest.mocked(WebpackDevServer).mockImplementation((): any => ({
|
|
257
258
|
listen: jest.fn((_0: number, _1: string, callback?: (error?: Error) => void) =>
|
|
258
259
|
stopWatching(callback)
|
|
@@ -297,14 +298,14 @@ describe('[startup] Cli Utils', () => {
|
|
|
297
298
|
describe(`with ${webpackDevConfigFileName} config`, () => {
|
|
298
299
|
const FS = { ...packageFS(), [webpackDevConfigFileName]: '' };
|
|
299
300
|
|
|
300
|
-
beforeEach(() =>
|
|
301
|
+
beforeEach(() => vol.fromJSON(FS));
|
|
301
302
|
|
|
302
303
|
itUsesConfig({ name: webpackDevConfigFileName, config: () => devConfig });
|
|
303
304
|
|
|
304
305
|
describe('with custom config', () => {
|
|
305
306
|
beforeEach(() => {
|
|
306
307
|
options = { config: customConfigFileName };
|
|
307
|
-
|
|
308
|
+
vol.fromJSON({ ...FS, [customConfigFileName]: '' });
|
|
308
309
|
});
|
|
309
310
|
|
|
310
311
|
itUsesConfig({ name: 'custom config', config: () => customConfig });
|
|
@@ -324,7 +325,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
324
325
|
const sharedDependencies = { react: 'SharedDependencies.React' };
|
|
325
326
|
|
|
326
327
|
beforeEach(() => {
|
|
327
|
-
|
|
328
|
+
vol.fromJSON(webComponentFS());
|
|
328
329
|
jest.mocked(getFolders).mockReturnValue({ source, destination });
|
|
329
330
|
jest.mocked(getPackageData).mockReturnValue({ dependencies });
|
|
330
331
|
jest.mocked(loadSharedDependencies).mockReturnValue(sharedDependencies);
|
|
@@ -368,14 +369,14 @@ describe('[startup] Cli Utils', () => {
|
|
|
368
369
|
describe(`with ${webpackDevConfigFileName} config`, () => {
|
|
369
370
|
const FS = { ...webComponentFS(), [webpackDevConfigFileName]: '' };
|
|
370
371
|
|
|
371
|
-
beforeEach(() =>
|
|
372
|
+
beforeEach(() => vol.fromJSON(FS));
|
|
372
373
|
|
|
373
374
|
itUsesConfig({ name: webpackDevConfigFileName, config: () => devConfig });
|
|
374
375
|
|
|
375
376
|
describe('with custom config', () => {
|
|
376
377
|
beforeEach(() => {
|
|
377
378
|
options = { config: customConfigFileName };
|
|
378
|
-
|
|
379
|
+
vol.fromJSON({ ...FS, [customConfigFileName]: '' });
|
|
379
380
|
});
|
|
380
381
|
|
|
381
382
|
itUsesConfig({ name: 'custom config', config: () => customConfig });
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fs, vol } from 'memfs';
|
|
2
2
|
import { ESLint } from 'eslint';
|
|
3
3
|
|
|
4
4
|
import { eslint } from '../eslint';
|
|
5
5
|
|
|
6
|
+
jest.mock('fs', () => fs);
|
|
6
7
|
jest.mock('eslint');
|
|
8
|
+
jest.mock('../../../utils/get-destination-folders', () => ({
|
|
9
|
+
getDestinationFolders: () => [],
|
|
10
|
+
}));
|
|
7
11
|
|
|
8
12
|
describe(`[startup] utils:${eslint.name}`, () => {
|
|
9
13
|
const mockResult = { filePath: 'foo' } as ESLint.LintResult;
|
|
@@ -13,7 +17,11 @@ describe(`[startup] utils:${eslint.name}`, () => {
|
|
|
13
17
|
let eslintResults: ESLint.LintResult[];
|
|
14
18
|
let eslintErrors: ESLint.LintResult[];
|
|
15
19
|
|
|
16
|
-
beforeEach(() =>
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.resetAllMocks();
|
|
22
|
+
vol.fromJSON({ 'package.json': JSON.stringify({}) });
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => vol.reset());
|
|
17
25
|
|
|
18
26
|
beforeEach(() => {
|
|
19
27
|
mockESLint = {
|
|
@@ -79,8 +87,7 @@ describe(`[startup] utils:${eslint.name}`, () => {
|
|
|
79
87
|
cli: { lint: { eslint: { disabled: true } } },
|
|
80
88
|
});
|
|
81
89
|
|
|
82
|
-
beforeEach(() =>
|
|
83
|
-
afterEach(() => mockFS.restore());
|
|
90
|
+
beforeEach(() => vol.fromJSON({ 'package.json': config }));
|
|
84
91
|
|
|
85
92
|
test('does nothing', async () => {
|
|
86
93
|
await subject();
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fs, vol } from 'memfs';
|
|
2
2
|
import { getModuleType } from '../get-module-type';
|
|
3
3
|
|
|
4
|
+
jest.mock('fs', () => fs);
|
|
5
|
+
|
|
4
6
|
describe('[startup] Cli Utils', () => {
|
|
5
7
|
describe(`${getModuleType.name}`, () => {
|
|
6
8
|
const tsconfig = 'tsconfig.json';
|
|
7
9
|
|
|
8
|
-
beforeEach(() =>
|
|
10
|
+
beforeEach(() => vol.fromJSON({ [tsconfig]: JSON.stringify({}) }));
|
|
9
11
|
|
|
10
|
-
afterEach(() =>
|
|
12
|
+
afterEach(() => vol.reset());
|
|
11
13
|
|
|
12
14
|
const subject = (configPath?: string) => getModuleType(configPath ?? `./${tsconfig}`);
|
|
13
15
|
|
|
@@ -19,7 +21,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
19
21
|
const module = 'foo';
|
|
20
22
|
|
|
21
23
|
beforeEach(() => {
|
|
22
|
-
|
|
24
|
+
vol.fromJSON({ [tsconfig]: JSON.stringify({ compilerOptions: { module } }) });
|
|
23
25
|
});
|
|
24
26
|
|
|
25
27
|
test('returns configured module', () => {
|
|
@@ -31,20 +33,13 @@ describe('[startup] Cli Utils', () => {
|
|
|
31
33
|
const module = 'bar';
|
|
32
34
|
|
|
33
35
|
beforeEach(() => {
|
|
34
|
-
|
|
36
|
+
vol.fromJSON({
|
|
35
37
|
'tsconfig.json': JSON.stringify({
|
|
36
38
|
extends: '@servicetitan/startup/tsconfig/base',
|
|
37
39
|
}),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
startup: {
|
|
42
|
-
tsconfig: {
|
|
43
|
-
'base.json': JSON.stringify({ compilerOptions: { module } }),
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
40
|
+
'packages/startup/tsconfig/base.json': JSON.stringify({
|
|
41
|
+
compilerOptions: { module },
|
|
42
|
+
}),
|
|
48
43
|
});
|
|
49
44
|
});
|
|
50
45
|
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import mockFS from 'mock-fs';
|
|
2
|
-
|
|
3
1
|
import { isModuleInstalled } from '../is-module-installed';
|
|
4
2
|
|
|
5
3
|
describe(`[startup] Cli Utils`, () => {
|
|
6
4
|
describe(`${isModuleInstalled.name}`, () => {
|
|
7
|
-
afterEach(() => mockFS.restore());
|
|
8
|
-
|
|
9
5
|
const subject = (name: string) => isModuleInstalled(name);
|
|
10
6
|
|
|
11
7
|
test('returns false', () => {
|
|
@@ -13,11 +9,14 @@ describe(`[startup] Cli Utils`, () => {
|
|
|
13
9
|
});
|
|
14
10
|
|
|
15
11
|
describe('when module exists', () => {
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
/*
|
|
13
|
+
* Have to choose a module that really exists, because we are unable
|
|
14
|
+
* to mock require.resolve()
|
|
15
|
+
*/
|
|
16
|
+
const moduleName = 'fs';
|
|
18
17
|
|
|
19
18
|
test('returns true', () => {
|
|
20
|
-
expect(subject(
|
|
19
|
+
expect(subject(moduleName)).toBe(true);
|
|
21
20
|
});
|
|
22
21
|
});
|
|
23
22
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { fs, vol } from 'memfs';
|
|
1
2
|
import chokidar from 'chokidar';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import mockFS from 'mock-fs';
|
|
4
3
|
|
|
5
4
|
import { getFolders, log } from '../../../utils';
|
|
6
5
|
import * as sassModule from '../compile-sass';
|
|
@@ -8,6 +7,7 @@ import * as sassModule from '../compile-sass';
|
|
|
8
7
|
import { styleExtensions } from '..';
|
|
9
8
|
import { tcm, tcmWatch } from '../tcm';
|
|
10
9
|
|
|
10
|
+
jest.mock('fs', () => fs);
|
|
11
11
|
jest.mock('../../../utils', () => ({
|
|
12
12
|
...jest.requireActual('../../../utils'),
|
|
13
13
|
getFolders: jest.fn(),
|
|
@@ -22,10 +22,11 @@ describe('[startup] Cli Utils', () => {
|
|
|
22
22
|
jest.mocked(getFolders).mockReturnValue({ source, destination: undefined });
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
afterEach(() =>
|
|
25
|
+
afterEach(() => vol.reset());
|
|
26
26
|
|
|
27
27
|
function mockStylesModule(module: string, id = 'foo') {
|
|
28
|
-
|
|
28
|
+
const content = `.${id} { display: none; }`;
|
|
29
|
+
vol.fromJSON({ [`${source}/${module}`]: content });
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
function expectTypeDefinitions(module: string, id = 'foo') {
|
|
@@ -77,7 +78,7 @@ describe('[startup] Cli Utils', () => {
|
|
|
77
78
|
beforeEach(() => {
|
|
78
79
|
fsWatcher = { on: jest.fn() };
|
|
79
80
|
watchSpy = jest.spyOn(chokidar, 'watch').mockReturnValue(fsWatcher as any);
|
|
80
|
-
|
|
81
|
+
vol.fromJSON({ [`${source}/foo.bar`]: '' });
|
|
81
82
|
});
|
|
82
83
|
|
|
83
84
|
const subject = () => tcmWatch();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import execa from 'execa';
|
|
2
|
-
import
|
|
2
|
+
import { fs, vol } from 'memfs';
|
|
3
3
|
import { Package, getPackagesGraph, getTsConfig } from '../../../utils';
|
|
4
4
|
import { createPackage } from '../../../__mocks__';
|
|
5
5
|
|
|
6
6
|
import { tsc, tscWatch } from '../tsc';
|
|
7
7
|
|
|
8
|
+
jest.mock('fs', () => fs);
|
|
8
9
|
jest.mock('execa', () => jest.fn());
|
|
9
10
|
jest.mock('../../../utils', () => ({
|
|
10
11
|
...jest.requireActual('../../../utils'),
|
|
@@ -22,15 +23,13 @@ describe('[startup] Cli Utils', () => {
|
|
|
22
23
|
createPackage({ name: 'foo', location: 'packages/foo' }),
|
|
23
24
|
createPackage({ name: 'bar', location: 'packages/bar' }),
|
|
24
25
|
];
|
|
25
|
-
|
|
26
|
-
packages: {
|
|
27
|
-
|
|
28
|
-
bar: { 'tsconfig.json': JSON.stringify({}) },
|
|
29
|
-
},
|
|
26
|
+
vol.fromJSON({
|
|
27
|
+
'packages/foo/tsconfig.json': JSON.stringify({}),
|
|
28
|
+
'packages/bar/tsconfig.json': JSON.stringify({}),
|
|
30
29
|
});
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
afterEach(() =>
|
|
32
|
+
afterEach(() => vol.reset());
|
|
34
33
|
|
|
35
34
|
describe(`${tsc.name}`, () => {
|
|
36
35
|
const subject = async () => tsc(packages);
|
package/src/cli/utils/bundle.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { Overrides, createWebpackConfig } from '../../webpack';
|
|
|
12
12
|
interface Options {
|
|
13
13
|
buildStat?: boolean;
|
|
14
14
|
config?: string;
|
|
15
|
+
esbuild?: boolean;
|
|
16
|
+
experimentalBundlers?: boolean;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
function getName() {
|
|
@@ -33,7 +35,7 @@ export async function bundle(options: Options = {}) {
|
|
|
33
35
|
const mode = 'production';
|
|
34
36
|
const fallback = `./${webpackProdConfigFileName}`;
|
|
35
37
|
const config = readWebpackConfig({ ...options, fallback });
|
|
36
|
-
const { buildStat } = options;
|
|
38
|
+
const { buildStat, esbuild, experimentalBundlers } = options;
|
|
37
39
|
|
|
38
40
|
const run = async (config: Configuration) => {
|
|
39
41
|
const compiler = webpack(config);
|
|
@@ -55,6 +57,8 @@ export async function bundle(options: Options = {}) {
|
|
|
55
57
|
process.stdout.write(stats.toString(config.stats) + '\n');
|
|
56
58
|
};
|
|
57
59
|
|
|
60
|
+
const webpackOptions = { name, buildStat, esbuild, experimentalBundlers };
|
|
61
|
+
|
|
58
62
|
if (isWebComponent()) {
|
|
59
63
|
const webpackConfig: Overrides = {
|
|
60
64
|
configuration: { ...config?.configuration, mode },
|
|
@@ -62,12 +66,12 @@ export async function bundle(options: Options = {}) {
|
|
|
62
66
|
};
|
|
63
67
|
|
|
64
68
|
return Promise.all([
|
|
65
|
-
run(createWebpackConfig(webpackConfig, { embed: true,
|
|
66
|
-
run(createWebpackConfig(webpackConfig,
|
|
69
|
+
run(createWebpackConfig(webpackConfig, { embed: true, ...webpackOptions })),
|
|
70
|
+
run(createWebpackConfig(webpackConfig, webpackOptions)),
|
|
67
71
|
]);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
return run(config ?? createWebpackConfig({ configuration: { mode } },
|
|
74
|
+
return run(config ?? createWebpackConfig({ configuration: { mode } }, webpackOptions));
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
export async function bundleWatch(options: Options = {}) {
|
|
@@ -76,6 +80,7 @@ export async function bundleWatch(options: Options = {}) {
|
|
|
76
80
|
const name = getName();
|
|
77
81
|
const mode = 'development';
|
|
78
82
|
const config = readWebpackConfig({ ...options, fallback: `./${webpackDevConfigFileName}` });
|
|
83
|
+
const { esbuild, experimentalBundlers } = options;
|
|
79
84
|
|
|
80
85
|
const runServe = async ({ devServer = {}, ...config }: Configuration) => {
|
|
81
86
|
const compiler = webpack(config);
|
|
@@ -118,12 +123,25 @@ export async function bundleWatch(options: Options = {}) {
|
|
|
118
123
|
};
|
|
119
124
|
|
|
120
125
|
return Promise.all([
|
|
121
|
-
run(
|
|
122
|
-
|
|
126
|
+
run(
|
|
127
|
+
createWebpackConfig(webpackConfig, {
|
|
128
|
+
embed: true,
|
|
129
|
+
name,
|
|
130
|
+
esbuild,
|
|
131
|
+
experimentalBundlers,
|
|
132
|
+
})
|
|
133
|
+
),
|
|
134
|
+
runServe(createWebpackConfig(webpackConfig, { name, esbuild, experimentalBundlers })),
|
|
123
135
|
]);
|
|
124
136
|
}
|
|
125
137
|
|
|
126
|
-
return runServe(
|
|
138
|
+
return runServe(
|
|
139
|
+
config ??
|
|
140
|
+
createWebpackConfig(
|
|
141
|
+
{ configuration: { mode } },
|
|
142
|
+
{ name, esbuild, experimentalBundlers }
|
|
143
|
+
)
|
|
144
|
+
);
|
|
127
145
|
}
|
|
128
146
|
|
|
129
147
|
function readWebpackConfig({ config, fallback }: Options & { fallback: string }) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fs, vol } from 'memfs';
|
|
2
|
+
import WebpackDevServer from 'webpack-dev-server';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
2
5
|
import {
|
|
3
6
|
getConfiguration,
|
|
4
7
|
getConfigurationSafe,
|
|
@@ -13,7 +16,8 @@ import {
|
|
|
13
16
|
isStyleCheckDisabled,
|
|
14
17
|
isWebComponent,
|
|
15
18
|
} from '../get-configuration';
|
|
16
|
-
|
|
19
|
+
|
|
20
|
+
jest.mock('fs', () => fs);
|
|
17
21
|
|
|
18
22
|
describe('[startup] Utils', () => {
|
|
19
23
|
const packageJson = 'package.json';
|
|
@@ -23,7 +27,7 @@ describe('[startup] Utils', () => {
|
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
function mockPackageJson(content: Record<string, any> = {}) {
|
|
26
|
-
|
|
30
|
+
vol.fromJSON(packageJsonFS(content));
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
function itReturns(subject: Function, value: any) {
|
|
@@ -32,7 +36,7 @@ describe('[startup] Utils', () => {
|
|
|
32
36
|
|
|
33
37
|
beforeEach(() => mockPackageJson());
|
|
34
38
|
|
|
35
|
-
afterEach(() =>
|
|
39
|
+
afterEach(() => jest.resetAllMocks());
|
|
36
40
|
|
|
37
41
|
describe(`${getConfiguration.name}`, () => {
|
|
38
42
|
let location: string | undefined;
|
|
@@ -56,7 +60,7 @@ describe('[startup] Utils', () => {
|
|
|
56
60
|
|
|
57
61
|
beforeEach(() => {
|
|
58
62
|
location = 'packages/foo';
|
|
59
|
-
|
|
63
|
+
vol.fromJSON({ [`packages/foo/${packageJson}`]: JSON.stringify({ cli }) });
|
|
60
64
|
});
|
|
61
65
|
|
|
62
66
|
test("returns location's cli", () => {
|
|
@@ -65,7 +69,7 @@ describe('[startup] Utils', () => {
|
|
|
65
69
|
});
|
|
66
70
|
|
|
67
71
|
describe('with no package.json', () => {
|
|
68
|
-
beforeEach(() =>
|
|
72
|
+
beforeEach(() => vol.reset());
|
|
69
73
|
|
|
70
74
|
test('throws error', () => {
|
|
71
75
|
expect(subject).toThrowError();
|
|
@@ -95,7 +99,7 @@ describe('[startup] Utils', () => {
|
|
|
95
99
|
|
|
96
100
|
beforeEach(() => {
|
|
97
101
|
location = 'packages/foo';
|
|
98
|
-
|
|
102
|
+
vol.fromJSON({ [`packages/foo/${packageJson}`]: JSON.stringify({ cli }) });
|
|
99
103
|
});
|
|
100
104
|
|
|
101
105
|
test("returns location's cli", () => {
|
|
@@ -104,7 +108,7 @@ describe('[startup] Utils', () => {
|
|
|
104
108
|
});
|
|
105
109
|
|
|
106
110
|
describe('with no package.json', () => {
|
|
107
|
-
beforeEach(() =>
|
|
111
|
+
beforeEach(() => vol.reset());
|
|
108
112
|
|
|
109
113
|
itReturns(subject, {});
|
|
110
114
|
});
|
|
@@ -135,7 +139,7 @@ describe('[startup] Utils', () => {
|
|
|
135
139
|
});
|
|
136
140
|
|
|
137
141
|
describe('when "cli.webpack.proxy" is a path', () => {
|
|
138
|
-
const proxy = 'proxy.
|
|
142
|
+
const proxy = 'proxy.js';
|
|
139
143
|
const proxyConfig = { cli: { webpack: { ...webpack, proxy } } };
|
|
140
144
|
|
|
141
145
|
beforeEach(() => mockPackageJson(proxyConfig));
|
|
@@ -148,12 +152,14 @@ describe('[startup] Utils', () => {
|
|
|
148
152
|
|
|
149
153
|
describe('when file exists', () => {
|
|
150
154
|
beforeEach(() => {
|
|
151
|
-
|
|
155
|
+
vol.fromJSON({
|
|
152
156
|
...packageJsonFS(proxyConfig),
|
|
153
157
|
[proxy]: JSON.stringify(webpack.proxy),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Have to mock proxy.js because our fs is virtual, but require() is not
|
|
161
|
+
jest.doMock(path.resolve('proxy.js'), () => webpack.proxy, {
|
|
162
|
+
virtual: true,
|
|
157
163
|
});
|
|
158
164
|
});
|
|
159
165
|
|
|
@@ -265,7 +271,7 @@ describe('[startup] Utils', () => {
|
|
|
265
271
|
describe('with a location', () => {
|
|
266
272
|
beforeEach(() => {
|
|
267
273
|
location = 'packages/foo';
|
|
268
|
-
|
|
274
|
+
vol.fromJSON({ [`packages/foo/${packageJson}`]: JSON.stringify(trigger) });
|
|
269
275
|
});
|
|
270
276
|
|
|
271
277
|
test("returns location's status", () => {
|