@servicetitan/startup 22.18.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.
Files changed (70) hide show
  1. package/dist/cli/commands/build.d.ts +1 -0
  2. package/dist/cli/commands/build.d.ts.map +1 -1
  3. package/dist/cli/commands/build.js +1 -0
  4. package/dist/cli/commands/build.js.map +1 -1
  5. package/dist/cli/commands/bundle-package.d.ts +5 -3
  6. package/dist/cli/commands/bundle-package.d.ts.map +1 -1
  7. package/dist/cli/commands/bundle-package.js +7 -2
  8. package/dist/cli/commands/bundle-package.js.map +1 -1
  9. package/dist/cli/commands/mfe-publish.d.ts +1 -0
  10. package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
  11. package/dist/cli/commands/mfe-publish.js +3 -2
  12. package/dist/cli/commands/mfe-publish.js.map +1 -1
  13. package/dist/cli/commands/start.d.ts +5 -4
  14. package/dist/cli/commands/start.d.ts.map +1 -1
  15. package/dist/cli/commands/start.js +3 -0
  16. package/dist/cli/commands/start.js.map +1 -1
  17. package/dist/cli/utils/bundle.d.ts +2 -0
  18. package/dist/cli/utils/bundle.d.ts.map +1 -1
  19. package/dist/cli/utils/bundle.js +14 -7
  20. package/dist/cli/utils/bundle.js.map +1 -1
  21. package/dist/webpack/configs/plugins/provide-react-plugin.d.ts +1 -1
  22. package/dist/webpack/configs/plugins/provide-react-plugin.d.ts.map +1 -1
  23. package/dist/webpack/configs/plugins/provide-react-plugin.js +2 -2
  24. package/dist/webpack/configs/plugins/provide-react-plugin.js.map +1 -1
  25. package/dist/webpack/configs/rules/tsx-rules.d.ts +1 -1
  26. package/dist/webpack/configs/rules/tsx-rules.d.ts.map +1 -1
  27. package/dist/webpack/configs/rules/tsx-rules.js +27 -7
  28. package/dist/webpack/configs/rules/tsx-rules.js.map +1 -1
  29. package/dist/webpack/configs/types.d.ts +1 -0
  30. package/dist/webpack/configs/types.d.ts.map +1 -1
  31. package/dist/webpack/create-webpack-config.d.ts.map +1 -1
  32. package/dist/webpack/create-webpack-config.js +2 -1
  33. package/dist/webpack/create-webpack-config.js.map +1 -1
  34. package/dist/webpack/types.d.ts +2 -0
  35. package/dist/webpack/types.d.ts.map +1 -1
  36. package/package.json +7 -5
  37. package/src/cli/commands/__tests__/build.test.ts +14 -0
  38. package/src/cli/commands/__tests__/bundle-package.test.ts +8 -4
  39. package/src/cli/commands/__tests__/init.test.ts +5 -4
  40. package/src/cli/commands/__tests__/mfe-package-clean.test.ts +4 -3
  41. package/src/cli/commands/__tests__/mfe-package-publish.test.ts +15 -4
  42. package/src/cli/commands/__tests__/mfe-publish.test.ts +5 -3
  43. package/src/cli/commands/__tests__/start.test.ts +14 -0
  44. package/src/cli/commands/__tests__/styles-check.test.ts +12 -11
  45. package/src/cli/commands/build.ts +2 -0
  46. package/src/cli/commands/bundle-package.ts +13 -5
  47. package/src/cli/commands/mfe-publish.ts +3 -1
  48. package/src/cli/commands/start.ts +8 -4
  49. package/src/cli/utils/__tests__/bundle.test.ts +15 -14
  50. package/src/cli/utils/__tests__/eslint.test.ts +11 -4
  51. package/src/cli/utils/__tests__/get-module-type.test.ts +10 -15
  52. package/src/cli/utils/__tests__/is-module-installed.test.ts +6 -7
  53. package/src/cli/utils/__tests__/tcm.test.ts +6 -5
  54. package/src/cli/utils/__tests__/tsc.test.ts +6 -7
  55. package/src/cli/utils/bundle.ts +25 -7
  56. package/src/utils/__tests__/get-configuration.test.ts +20 -14
  57. package/src/utils/__tests__/get-destination-folders.test.ts +11 -13
  58. package/src/utils/__tests__/get-folders.test.ts +8 -6
  59. package/src/utils/__tests__/get-tsconfig.test.ts +6 -4
  60. package/src/utils/__tests__/read-json.test.ts +12 -16
  61. package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +6 -5
  62. package/src/webpack/__tests__/create-webpack-config.test.ts +48 -9
  63. package/src/webpack/configs/plugins/provide-react-plugin.ts +2 -2
  64. package/src/webpack/configs/rules/tsx-rules.ts +32 -10
  65. package/src/webpack/configs/types.ts +1 -0
  66. package/src/webpack/configs/utils/__tests__/generate-metadata.test.ts +9 -12
  67. package/src/webpack/configs/utils/__tests__/get-startup-version.test.ts +6 -10
  68. package/src/webpack/create-webpack-config.ts +3 -1
  69. package/src/webpack/types.ts +2 -0
  70. package/template/.gitignore +4 -0
@@ -1,9 +1,10 @@
1
- import mockFS from 'mock-fs';
1
+ import { fs, vol } from 'memfs';
2
2
  import { isWebComponent, log } from '../../../utils';
3
3
  import { npmGetPackageVersionDates, npmUnpublish } from '../../utils/cli-npm';
4
4
 
5
5
  import { MFEPackageClean } from '../mfe-publish';
6
6
 
7
+ jest.mock('fs', () => fs);
7
8
  jest.mock('../../../utils', () => ({
8
9
  ...jest.requireActual('../../../utils'),
9
10
  isWebComponent: jest.fn(),
@@ -34,10 +35,10 @@ describe(`[startup] ${MFEPackageClean.name}`, () => {
34
35
  jest.resetAllMocks();
35
36
  jest.mocked(isWebComponent).mockReturnValue(true);
36
37
  jest.mocked(npmGetPackageVersionDates).mockImplementation(() => Object.entries(versions));
37
- mockFS({ 'package.json': JSON.stringify({ name: packageName }) });
38
+ vol.fromJSON({ 'package.json': JSON.stringify({ name: packageName }) });
38
39
  });
39
40
 
40
- afterEach(() => mockFS.restore());
41
+ afterEach(() => vol.reset());
41
42
 
42
43
  const subject = async () => new MFEPackageClean(args).execute();
43
44
 
@@ -1,4 +1,4 @@
1
- import mockFS from 'mock-fs';
1
+ import { fs, vol } from 'memfs';
2
2
  import { isWebComponent, log } from '../../../utils';
3
3
  import { gitGetBranch, gitGetCommitHash } from '../../utils/cli-git';
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  } from '../../utils/cli-npm';
10
10
  import { MFEPackagePublish } from '../mfe-publish';
11
11
 
12
+ jest.mock('fs', () => fs);
12
13
  jest.mock('../../../utils', () => ({
13
14
  ...jest.requireActual('../../../utils'),
14
15
  isWebComponent: jest.fn(),
@@ -40,10 +41,10 @@ describe(`[startup] ${MFEPackagePublish.name}`, () => {
40
41
  jest.mocked(gitGetBranch).mockReturnValue(branch);
41
42
  jest.mocked(gitGetCommitHash).mockReturnValue(commitHash);
42
43
  jest.mocked(npmGetPackageVersions).mockReturnValue([]);
43
- mockFS({ 'package.json': JSON.stringify({ name: packageName, files: [] }) });
44
+ vol.fromJSON({ 'package.json': JSON.stringify({ name: packageName, files: [] }) });
44
45
  });
45
46
 
46
- afterEach(() => mockFS.restore());
47
+ afterEach(() => vol.reset());
47
48
 
48
49
  const subject = async () => new MFEPackagePublish(args).execute();
49
50
 
@@ -62,6 +63,16 @@ describe(`[startup] ${MFEPackagePublish.name}`, () => {
62
63
  );
63
64
  });
64
65
 
66
+ describe('with "registry" argument', () => {
67
+ beforeEach(() => (args.registry = 'https://foo'));
68
+
69
+ test('sets package registry to specified value', async () => {
70
+ await subject();
71
+
72
+ expect(npmPackageSet).toHaveBeenCalledWith('publishConfig.registry', args.registry);
73
+ });
74
+ });
75
+
65
76
  test('publishes package and logs message', async () => {
66
77
  await subject();
67
78
 
@@ -133,7 +144,7 @@ describe(`[startup] ${MFEPackagePublish.name}`, () => {
133
144
  });
134
145
 
135
146
  describe('when package has no files', () => {
136
- beforeEach(() => mockFS({ 'package.json': JSON.stringify({ name: packageName }) }));
147
+ beforeEach(() => vol.fromJSON({ 'package.json': JSON.stringify({ name: packageName }) }));
137
148
 
138
149
  test('sets package files to "package.json"', async () => {
139
150
  await subject();
@@ -1,10 +1,11 @@
1
1
  const exec = require('@lerna/exec');
2
- import mockFS from 'mock-fs';
2
+ import { fs, vol } from 'memfs';
3
3
  import { Package, PackageType, getPackages } from '../../../utils';
4
4
  import { createPackage } from '../../../__mocks__';
5
5
 
6
6
  import { MFEPublish } from '../mfe-publish';
7
7
 
8
+ jest.mock('fs', () => fs);
8
9
  jest.mock('@lerna/exec', () => jest.fn());
9
10
  jest.mock('../../../utils', () => ({
10
11
  ...jest.requireActual('../../../utils'),
@@ -22,7 +23,7 @@ describe(`[startup] ${MFEPublish.name}`, () => {
22
23
  jest.mocked(getPackages).mockReturnValue(packages);
23
24
  });
24
25
 
25
- afterEach(() => mockFS.restore());
26
+ afterEach(() => vol.reset());
26
27
 
27
28
  const subject = async () => new MFEPublish(args).execute();
28
29
 
@@ -49,7 +50,7 @@ describe(`[startup] ${MFEPublish.name}`, () => {
49
50
  packages: Package[],
50
51
  json: Record<string, any> = { cli: { 'web-component': true } }
51
52
  ) {
52
- mockFS(
53
+ vol.fromJSON(
53
54
  packages.reduce(
54
55
  (result, { location }) => ({
55
56
  ...result,
@@ -102,6 +103,7 @@ describe(`[startup] ${MFEPublish.name}`, () => {
102
103
  { name: 'tag', value: false, expected: '--no-tag' },
103
104
  { name: 'dry', value: true, expected: '--dry' },
104
105
  { name: 'force', value: true, expected: '--force' },
106
+ { name: 'registry', value: 'https://foo' },
105
107
  { name: 'count', value: 42 },
106
108
  ];
107
109
 
@@ -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 mockFS from 'mock-fs';
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(() => mockFS.restore());
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
- mockFS({
74
- src: {
75
- 'design-system.css': [tokenCss, anvilFontsCss, systemMinCss].join('\r\n'),
76
- 'foo.css': `${tokenCss}\r\n`,
77
- 'bar.less': `${anvilFontsCss}\r\n`,
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
- expect(errors).toEqual([
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, config });
37
+ await bundle({ buildStat: stat, ...options });
30
38
  } else {
31
- await bundleWatch({ config });
39
+ await bundleWatch(options);
32
40
  }
33
41
  }
34
42
  }
@@ -29,6 +29,7 @@ interface ArgsPackagePublish {
29
29
  branch?: string;
30
30
  tag?: string | false;
31
31
  noTag?: string;
32
+ registry?: string;
32
33
  }
33
34
 
34
35
  interface ArgsPackageClean {
@@ -76,6 +77,7 @@ export class MFEPublish implements Command {
76
77
  ...[this.args.dry ? '--dry' : undefined],
77
78
  ...[this.args.force ? '--force' : undefined],
78
79
  ...[this.args.count ? `--count ${this.args.count}` : undefined],
80
+ ...[this.args.registry ? `--registry ${this.args.registry}` : undefined],
79
81
  ].filter(item => item),
80
82
  });
81
83
  }
@@ -171,7 +173,7 @@ export class MFEPackagePublish implements Command {
171
173
  tag = branchConfig?.tag ?? '';
172
174
  }
173
175
 
174
- const registry = 'https://verdaccio.servicetitan.com';
176
+ const registry = cli.registry ?? 'https://verdaccio.servicetitan.com';
175
177
 
176
178
  return {
177
179
  tag,
@@ -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
- ignore?: string | string[];
11
- scope?: string | string[];
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 mockFS from 'mock-fs';
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(() => mockFS.restore());
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
- mockFS(packageFS());
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(() => mockFS(FS));
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
- mockFS({ ...FS, [customConfigFileName]: '' });
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
- mockFS(webComponentFS());
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(() => mockFS(FS));
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
- mockFS({ ...FS, [customConfigFileName]: '' });
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
- mockFS(packageFS());
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(() => mockFS(FS));
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
- mockFS({ ...FS, [customConfigFileName]: '' });
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
- mockFS(webComponentFS());
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(() => mockFS(FS));
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
- mockFS({ ...FS, [customConfigFileName]: '' });
379
+ vol.fromJSON({ ...FS, [customConfigFileName]: '' });
379
380
  });
380
381
 
381
382
  itUsesConfig({ name: 'custom config', config: () => customConfig });
@@ -1,9 +1,13 @@
1
- import mockFS from 'mock-fs';
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(() => jest.resetAllMocks());
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(() => mockFS({ 'package.json': config }));
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 mockFS from 'mock-fs';
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(() => mockFS({ [tsconfig]: JSON.stringify({}) }));
10
+ beforeEach(() => vol.fromJSON({ [tsconfig]: JSON.stringify({}) }));
9
11
 
10
- afterEach(() => mockFS.restore());
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
- mockFS({ [tsconfig]: JSON.stringify({ compilerOptions: { module } }) });
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
- mockFS({
36
+ vol.fromJSON({
35
37
  'tsconfig.json': JSON.stringify({
36
38
  extends: '@servicetitan/startup/tsconfig/base',
37
39
  }),
38
- // eslint-disable-next-line @typescript-eslint/naming-convention
39
- 'node_modules': {
40
- '@servicetitan': {
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
- // eslint-disable-next-line @typescript-eslint/naming-convention
17
- beforeEach(() => mockFS({ node_modules: { bar: { 'index.js': '' } } }));
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('bar')).toBe(true);
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(() => mockFS.restore());
25
+ afterEach(() => vol.reset());
26
26
 
27
27
  function mockStylesModule(module: string, id = 'foo') {
28
- mockFS({ [source]: { [module]: `.${id} { display: none; }` } });
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
- mockFS({ [source]: {} });
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 mockFS from 'mock-fs';
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
- mockFS({
26
- packages: {
27
- foo: { 'tsconfig.json': JSON.stringify({}) },
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(() => mockFS.restore());
32
+ afterEach(() => vol.reset());
34
33
 
35
34
  describe(`${tsc.name}`, () => {
36
35
  const subject = async () => tsc(packages);