ember-codemod-v1-to-v2 0.1.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 (36) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +129 -0
  3. package/bin/ember-codemod-v1-to-v2.js +42 -0
  4. package/package.json +67 -0
  5. package/src/blueprints/ember-addon/.prettierignore +25 -0
  6. package/src/blueprints/ember-addon/.prettierrc.js +5 -0
  7. package/src/blueprints/ember-addon/__addonLocation__/.eslintignore +8 -0
  8. package/src/blueprints/ember-addon/__addonLocation__/addon-main.js +5 -0
  9. package/src/blueprints/ember-addon/__addonLocation__/babel.config.json +8 -0
  10. package/src/blueprints/ember-addon/__addonLocation__/rollup.config.js +58 -0
  11. package/src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs +55 -0
  12. package/src/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts +13 -0
  13. package/src/blueprints/ember-addon/__testAppLocation__/ember-cli-build.js +16 -0
  14. package/src/blueprints/ember-addon/__testAppLocation__/types/global.d.ts +7 -0
  15. package/src/blueprints/ember-addon/package.json +76 -0
  16. package/src/blueprints/ember-addon/pnpm-workspace.yaml +3 -0
  17. package/src/index.js +5 -0
  18. package/src/migration/ember-addon/index.js +41 -0
  19. package/src/migration/ember-addon/steps/analyze-addon.js +30 -0
  20. package/src/migration/ember-addon/steps/augment-options.js +111 -0
  21. package/src/migration/ember-addon/steps/create-files-from-blueprint.js +68 -0
  22. package/src/migration/ember-addon/steps/index.js +11 -0
  23. package/src/migration/ember-addon/steps/move-addon-files.js +79 -0
  24. package/src/migration/ember-addon/steps/move-project-root-files.js +126 -0
  25. package/src/migration/ember-addon/steps/move-test-app-files.js +103 -0
  26. package/src/migration/ember-addon/steps/update-addon-package-json.js +130 -0
  27. package/src/migration/ember-addon/steps/update-addon-tsconfig-json.js +42 -0
  28. package/src/migration/ember-addon/steps/update-test-app-package-json.js +85 -0
  29. package/src/migration/ember-addon/steps/update-test-app-tsconfig-json.js +47 -0
  30. package/src/migration/ember-addon/steps/use-relative-paths.js +88 -0
  31. package/src/migration/index.js +1 -0
  32. package/src/utils/convert-json-object.js +9 -0
  33. package/src/utils/decide-version.js +24 -0
  34. package/src/utils/files.js +88 -0
  35. package/src/utils/map-file-paths.js +20 -0
  36. package/src/utils/process-template.js +12 -0
@@ -0,0 +1,111 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import glob from 'glob';
5
+
6
+ function analyzePackageJson(options) {
7
+ const { projectRoot } = options;
8
+
9
+ try {
10
+ const packageJsonFile = readFileSync(
11
+ join(projectRoot, 'package.json'),
12
+ 'utf8'
13
+ );
14
+
15
+ const {
16
+ dependencies,
17
+ devDependencies,
18
+ 'ember-addon': emberAddon,
19
+ name,
20
+ version,
21
+ } = JSON.parse(packageJsonFile);
22
+
23
+ const projectDependencies = new Map([
24
+ ...Object.entries(dependencies ?? {}),
25
+ ...Object.entries(devDependencies ?? {}),
26
+ ]);
27
+
28
+ return {
29
+ dependencies: projectDependencies,
30
+ hasGlint: projectDependencies.has('@glint/core'),
31
+ hasTypeScript: projectDependencies.has('typescript'),
32
+ isV1Addon: Boolean(emberAddon),
33
+ name,
34
+ version,
35
+ };
36
+ } catch (e) {
37
+ throw new SyntaxError(
38
+ `ERROR: package.json is missing or is not a valid JSON. (${e.message})\n`
39
+ );
40
+ }
41
+ }
42
+
43
+ function analyzePackageManager(options) {
44
+ const { projectRoot } = options;
45
+
46
+ const lockFiles = glob.sync('{package-lock.json,pnpm-lock.yaml,yarn.lock}', {
47
+ cwd: projectRoot,
48
+ });
49
+
50
+ if (lockFiles.length !== 1) {
51
+ console.warn('WARNING: Package manager is unknown. Yarn will be assumed.');
52
+
53
+ return {
54
+ isNpm: false,
55
+ isPnpm: false,
56
+ isYarn: true,
57
+ };
58
+ }
59
+
60
+ const [lockFile] = lockFiles;
61
+
62
+ return {
63
+ isNpm: lockFile === 'package-lock.json',
64
+ isPnpm: lockFile === 'pnpm-lock.yaml',
65
+ isYarn: lockFile === 'yarn.lock',
66
+ };
67
+ }
68
+
69
+ function deriveAddonLocation(addonPackage) {
70
+ if (!addonPackage.name) {
71
+ throw new RangeError(
72
+ `ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
73
+ );
74
+ }
75
+
76
+ // Package is scoped
77
+ if (addonPackage.name.includes('/')) {
78
+ // eslint-disable-next-line no-unused-vars
79
+ const [scope, packageName] = addonPackage.name.split('/');
80
+
81
+ if (!packageName) {
82
+ throw new SyntaxError(
83
+ `ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
84
+ );
85
+ }
86
+
87
+ return packageName;
88
+ }
89
+
90
+ return addonPackage.name;
91
+ }
92
+
93
+ export function augmentOptions(options) {
94
+ const addonPackage = analyzePackageJson(options);
95
+ const packageManager = analyzePackageManager(options);
96
+
97
+ return {
98
+ locations: {
99
+ addon: options.addonLocation ?? deriveAddonLocation(addonPackage),
100
+ testApp: options.testAppLocation ?? 'test-app',
101
+ },
102
+ packageManager,
103
+ packages: {
104
+ addon: addonPackage,
105
+ testApp: {
106
+ name: options.testAppName ?? 'test-app',
107
+ },
108
+ },
109
+ projectRoot: options.projectRoot,
110
+ };
111
+ }
@@ -0,0 +1,68 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import glob from 'glob';
5
+
6
+ import { createFiles } from '../../../utils/files.js';
7
+ import { processTemplate } from '../../../utils/process-template.js';
8
+
9
+ function getFilePath(blueprintFilePath, options) {
10
+ const { locations } = options;
11
+
12
+ return blueprintFilePath
13
+ .replace('__addonLocation__', locations.addon)
14
+ .replace('__testAppLocation__', locations.testApp);
15
+ }
16
+
17
+ function getFilesToSkip(options) {
18
+ const { packageManager, packages } = options;
19
+
20
+ const files = new Set();
21
+
22
+ if (packages.addon.hasTypeScript) {
23
+ files.add('__addonLocation__/rollup.config.js');
24
+ } else {
25
+ files.add('__addonLocation__/rollup.config.mjs');
26
+ files.add('__addonLocation__/unpublished-development-types/index.d.ts');
27
+ files.add('__testAppLocation__/types/global.d.ts');
28
+ }
29
+
30
+ if (!packageManager.isPnpm) {
31
+ files.add('pnpm-workspace.yaml');
32
+ }
33
+
34
+ return [...files];
35
+ }
36
+
37
+ export function createFilesFromBlueprint(context, options) {
38
+ const blueprintRoot = 'src/blueprints/ember-addon';
39
+
40
+ const filesToSkip = getFilesToSkip(options);
41
+
42
+ const blueprintFilePaths = glob.sync('**/*', {
43
+ cwd: blueprintRoot,
44
+ dot: true,
45
+ ignore: filesToSkip,
46
+ nodir: true,
47
+ });
48
+
49
+ const fileMapping = new Map(
50
+ blueprintFilePaths.map((blueprintFilePath) => {
51
+ const filePath = getFilePath(blueprintFilePath, options);
52
+
53
+ const blueprintFile = readFileSync(
54
+ join(blueprintRoot, blueprintFilePath),
55
+ 'utf8'
56
+ );
57
+
58
+ const file = processTemplate(blueprintFile, {
59
+ context,
60
+ options,
61
+ });
62
+
63
+ return [filePath, file];
64
+ })
65
+ );
66
+
67
+ createFiles(fileMapping, options);
68
+ }
@@ -0,0 +1,11 @@
1
+ export * from './analyze-addon.js';
2
+ export * from './augment-options.js';
3
+ export * from './create-files-from-blueprint.js';
4
+ export * from './move-addon-files.js';
5
+ export * from './move-project-root-files.js';
6
+ export * from './move-test-app-files.js';
7
+ export * from './update-addon-package-json.js';
8
+ export * from './update-addon-tsconfig-json.js';
9
+ export * from './update-test-app-package-json.js';
10
+ export * from './update-test-app-tsconfig-json.js';
11
+ export * from './use-relative-paths.js';
@@ -0,0 +1,79 @@
1
+ import glob from 'glob';
2
+
3
+ import { moveFiles, removeFiles } from '../../../utils/files.js';
4
+ import { mapFilePaths } from '../../../utils/map-file-paths.js';
5
+
6
+ function moveAddonFolder(options) {
7
+ const { locations, projectRoot } = options;
8
+
9
+ const filePaths = glob.sync('addon/**/*', {
10
+ cwd: projectRoot,
11
+ dot: true,
12
+ nodir: true,
13
+ });
14
+
15
+ const pathMapping = mapFilePaths(filePaths, {
16
+ from: 'addon',
17
+ to: `${locations.addon}/src`,
18
+ });
19
+
20
+ moveFiles(pathMapping, options);
21
+ }
22
+
23
+ function moveAddonTestSupportFolder(options) {
24
+ const { locations, projectRoot } = options;
25
+
26
+ const filePaths = glob.sync('addon-test-support/**/*', {
27
+ cwd: projectRoot,
28
+ dot: true,
29
+ nodir: true,
30
+ });
31
+
32
+ const pathMapping = mapFilePaths(filePaths, {
33
+ from: 'addon-test-support',
34
+ to: `${locations.addon}/src/test-support`,
35
+ });
36
+
37
+ moveFiles(pathMapping, options);
38
+ }
39
+
40
+ function moveBlueprintsFolder(options) {
41
+ const { locations, projectRoot } = options;
42
+
43
+ const filePaths = glob.sync('blueprints/**/*', {
44
+ cwd: projectRoot,
45
+ dot: true,
46
+ nodir: true,
47
+ });
48
+
49
+ const pathMapping = mapFilePaths(filePaths, {
50
+ from: 'blueprints',
51
+ to: `${locations.addon}/blueprints`,
52
+ });
53
+
54
+ moveFiles(pathMapping, options);
55
+ }
56
+
57
+ function removeAppFolder(options) {
58
+ const { projectRoot } = options;
59
+
60
+ const filePaths = glob.sync('app/**/*', {
61
+ cwd: projectRoot,
62
+ dot: true,
63
+ nodir: true,
64
+ });
65
+
66
+ const pathMapping = mapFilePaths(filePaths, {
67
+ from: 'app',
68
+ to: 'app',
69
+ });
70
+
71
+ removeFiles(pathMapping, options);
72
+ }
73
+
74
+ export function moveAddonFiles(options) {
75
+ moveAddonFolder(options);
76
+ moveAddonTestSupportFolder(options);
77
+ moveBlueprintsFolder(options);
78
+ removeAppFolder(options);
79
+ }
@@ -0,0 +1,126 @@
1
+ import glob from 'glob';
2
+
3
+ import { copyFiles, moveFiles, removeFiles } from '../../../utils/files.js';
4
+ import { mapFilePaths } from '../../../utils/map-file-paths.js';
5
+
6
+ function globPattern(files) {
7
+ if (files.length <= 1) {
8
+ return files.join(',');
9
+ }
10
+
11
+ return `{${files.join(',')}}`;
12
+ }
13
+
14
+ function copyToAddon(options) {
15
+ const { locations, projectRoot } = options;
16
+
17
+ const files = ['LICENSE.md', 'README.md'];
18
+
19
+ const filePaths = glob.sync(globPattern(files), {
20
+ cwd: projectRoot,
21
+ });
22
+
23
+ const pathMapping = mapFilePaths(filePaths, {
24
+ from: '',
25
+ to: locations.addon,
26
+ });
27
+
28
+ copyFiles(pathMapping, options);
29
+ }
30
+
31
+ function moveToAddonAndTestApp(options) {
32
+ const { locations, packages, projectRoot } = options;
33
+
34
+ const files = packages.addon.hasTypeScript
35
+ ? [
36
+ '.eslintrc.js',
37
+ '.gitignore',
38
+ '.prettierignore',
39
+ '.prettierrc.js',
40
+ '.stylelintrc.js',
41
+ '.template-lintrc.js',
42
+ 'package.json',
43
+ 'tsconfig.json',
44
+ ]
45
+ : [
46
+ '.eslintrc.js',
47
+ '.gitignore',
48
+ '.prettierignore',
49
+ '.prettierrc.js',
50
+ '.stylelintrc.js',
51
+ '.template-lintrc.js',
52
+ 'package.json',
53
+ ];
54
+
55
+ const filePaths = glob.sync(globPattern(files), {
56
+ cwd: projectRoot,
57
+ });
58
+
59
+ let pathMapping = mapFilePaths(filePaths, {
60
+ from: '',
61
+ to: locations.addon,
62
+ });
63
+
64
+ copyFiles(pathMapping, options);
65
+
66
+ pathMapping = mapFilePaths(filePaths, {
67
+ from: '',
68
+ to: locations.testApp,
69
+ });
70
+
71
+ copyFiles(pathMapping, options);
72
+
73
+ pathMapping = mapFilePaths(filePaths, {
74
+ from: '',
75
+ to: '',
76
+ });
77
+
78
+ removeFiles(pathMapping, options);
79
+ }
80
+
81
+ function moveToTestApp(options) {
82
+ const { locations, projectRoot } = options;
83
+
84
+ const files = [
85
+ '.ember-cli',
86
+ '.eslintignore',
87
+ '.watchmanconfig',
88
+ 'ember-cli-build.js',
89
+ 'testem.js',
90
+ ];
91
+
92
+ const filePaths = glob.sync(globPattern(files), {
93
+ cwd: projectRoot,
94
+ });
95
+
96
+ const pathMapping = mapFilePaths(filePaths, {
97
+ from: '',
98
+ to: locations.testApp,
99
+ });
100
+
101
+ moveFiles(pathMapping, options);
102
+ }
103
+
104
+ function removeFromProjectRoot(options) {
105
+ const { projectRoot } = options;
106
+
107
+ const files = ['.npmignore', 'index.js'];
108
+
109
+ const filePaths = glob.sync(globPattern(files), {
110
+ cwd: projectRoot,
111
+ });
112
+
113
+ const pathMapping = mapFilePaths(filePaths, {
114
+ from: '',
115
+ to: '',
116
+ });
117
+
118
+ removeFiles(pathMapping, options);
119
+ }
120
+
121
+ export function moveProjectRootFiles(options) {
122
+ copyToAddon(options);
123
+ moveToAddonAndTestApp(options);
124
+ moveToTestApp(options);
125
+ removeFromProjectRoot(options);
126
+ }
@@ -0,0 +1,103 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import glob from 'glob';
5
+
6
+ import { moveFiles } from '../../../utils/files.js';
7
+ import { mapFilePaths } from '../../../utils/map-file-paths.js';
8
+
9
+ function moveTestsFolder(options) {
10
+ const { locations, projectRoot } = options;
11
+
12
+ let filePaths = glob.sync('tests/dummy/**/*', {
13
+ cwd: projectRoot,
14
+ dot: true,
15
+ nodir: true,
16
+ });
17
+
18
+ let pathMapping = mapFilePaths(filePaths, {
19
+ from: 'tests/dummy',
20
+ to: locations.testApp,
21
+ });
22
+
23
+ moveFiles(pathMapping, options);
24
+
25
+ filePaths = glob.sync('tests/**/*', {
26
+ cwd: projectRoot,
27
+ dot: true,
28
+ ignore: 'tests/dummy/**/*',
29
+ nodir: true,
30
+ });
31
+
32
+ pathMapping = mapFilePaths(filePaths, {
33
+ from: 'tests',
34
+ to: `${locations.testApp}/tests`,
35
+ });
36
+
37
+ moveFiles(pathMapping, options);
38
+ }
39
+
40
+ function moveTypesFolder(options) {
41
+ const { locations, packages, projectRoot } = options;
42
+
43
+ if (!packages.addon.hasTypeScript) {
44
+ return;
45
+ }
46
+
47
+ let filePaths = glob.sync('types/dummy/**/*', {
48
+ cwd: projectRoot,
49
+ dot: true,
50
+ nodir: true,
51
+ });
52
+
53
+ let pathMapping = mapFilePaths(filePaths, {
54
+ from: 'types/dummy',
55
+ to: `${locations.testApp}/types/${packages.testApp.name}`,
56
+ });
57
+
58
+ moveFiles(pathMapping, options);
59
+
60
+ filePaths = glob.sync('types/**/*', {
61
+ cwd: projectRoot,
62
+ dot: true,
63
+ ignore: 'types/dummy/**/*',
64
+ nodir: true,
65
+ });
66
+
67
+ pathMapping = mapFilePaths(filePaths, {
68
+ from: 'types',
69
+ to: `${locations.testApp}/types`,
70
+ });
71
+
72
+ moveFiles(pathMapping, options);
73
+ }
74
+
75
+ function renameDummy(options) {
76
+ const { locations, packages, projectRoot } = options;
77
+
78
+ // File extensions had been specified, partly to encode assumptions
79
+ // about Ember, and partly to avoid corrupting non-text files
80
+ const filePaths = glob.sync(`${locations.testApp}/**/*.{d.ts,html,js,ts}`, {
81
+ cwd: projectRoot,
82
+ dot: true,
83
+ nodir: true,
84
+ });
85
+
86
+ filePaths.forEach((filePath) => {
87
+ const oldPath = join(projectRoot, filePath);
88
+ const oldFile = readFileSync(oldPath, 'utf8');
89
+
90
+ const newFile = oldFile.replace(
91
+ new RegExp('dummy', 'g'),
92
+ packages.testApp.name
93
+ );
94
+
95
+ writeFileSync(oldPath, newFile, 'utf8');
96
+ });
97
+ }
98
+
99
+ export function moveTestAppFiles(options) {
100
+ moveTestsFolder(options);
101
+ moveTypesFolder(options);
102
+ renameDummy(options);
103
+ }
@@ -0,0 +1,130 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import {
5
+ convertToMap,
6
+ convertToObject,
7
+ } from '../../../utils/convert-json-object.js';
8
+ import { decideVersion } from '../../../utils/decide-version.js';
9
+
10
+ function updateDependencies(packageJson) {
11
+ const dependencies = convertToMap(packageJson['dependencies']);
12
+
13
+ const packagesToDelete = [
14
+ '@embroider/macros',
15
+ 'ember-auto-import',
16
+ 'ember-cli-babel',
17
+ 'ember-cli-htmlbars',
18
+ ];
19
+
20
+ const packagesToInstall = ['@embroider/addon-shim'];
21
+
22
+ packagesToDelete.forEach((packageName) => {
23
+ dependencies.delete(packageName);
24
+ });
25
+
26
+ packagesToInstall.forEach((packageName) => {
27
+ const version = decideVersion(packageName, dependencies);
28
+
29
+ dependencies.set(packageName, version);
30
+ });
31
+
32
+ packageJson['dependencies'] = convertToObject(dependencies);
33
+ }
34
+
35
+ function updateDevDependencies(packageJson, options) {
36
+ const { packages } = options;
37
+
38
+ const devDependencies = convertToMap(packageJson['devDependencies']);
39
+
40
+ const packagesToDelete = [
41
+ '@embroider/macros',
42
+ 'ember-auto-import',
43
+ 'ember-cli-babel',
44
+ 'ember-cli-htmlbars',
45
+ ];
46
+
47
+ const packagesToInstall = packages.addon.hasTypeScript
48
+ ? [
49
+ '@babel/core',
50
+ '@babel/plugin-proposal-class-properties',
51
+ '@babel/plugin-proposal-decorators',
52
+ '@babel/preset-typescript',
53
+ '@embroider/addon-dev',
54
+ 'rollup',
55
+ 'rollup-plugin-copy',
56
+ 'rollup-plugin-ts',
57
+ ]
58
+ : [
59
+ '@babel/core',
60
+ '@babel/plugin-proposal-class-properties',
61
+ '@babel/plugin-proposal-decorators',
62
+ '@embroider/addon-dev',
63
+ '@rollup/plugin-babel',
64
+ 'rollup',
65
+ 'rollup-plugin-copy',
66
+ ];
67
+
68
+ // May be easier to start over and add missing dependencies
69
+ devDependencies.clear();
70
+
71
+ packagesToDelete.forEach((packageName) => {
72
+ devDependencies.delete(packageName);
73
+ });
74
+
75
+ packagesToInstall.forEach((packageName) => {
76
+ const version = decideVersion(packageName, devDependencies);
77
+
78
+ devDependencies.set(packageName, version);
79
+ });
80
+
81
+ packageJson['devDependencies'] = convertToObject(devDependencies);
82
+ }
83
+
84
+ function updateOtherFields(packageJson) {
85
+ packageJson['ember-addon'] = {
86
+ 'app-js': {},
87
+ main: 'addon-main.js',
88
+ type: 'addon',
89
+ version: 2,
90
+ };
91
+
92
+ packageJson['exports'] = {
93
+ '.': './dist/index.js',
94
+ './*': './dist/*.js',
95
+ './addon-main.js': './addon-main.js',
96
+ };
97
+
98
+ packageJson['files'] = ['addon-main.js', 'dist'];
99
+ }
100
+
101
+ function updateScripts(packageJson) {
102
+ const scripts = convertToMap(packageJson.scripts);
103
+
104
+ scripts.set('build', 'rollup --config');
105
+ scripts.set('prepack', 'rollup --config');
106
+ scripts.set('start', 'rollup --config --watch');
107
+ scripts.set(
108
+ 'test',
109
+ "echo 'A v2 addon does not have tests, run tests in test-app'"
110
+ );
111
+
112
+ packageJson['scripts'] = convertToObject(scripts);
113
+ }
114
+
115
+ export function updateAddonPackageJson(options) {
116
+ const { locations, projectRoot } = options;
117
+
118
+ const oldPath = join(projectRoot, locations.addon, 'package.json');
119
+ const oldFile = readFileSync(oldPath, 'utf8');
120
+ const packageJson = JSON.parse(oldFile);
121
+
122
+ updateDependencies(packageJson);
123
+ updateDevDependencies(packageJson, options);
124
+ updateScripts(packageJson);
125
+ updateOtherFields(packageJson);
126
+
127
+ const newFile = JSON.stringify(packageJson, null, 2) + '\n';
128
+
129
+ writeFileSync(oldPath, newFile, 'utf8');
130
+ }
@@ -0,0 +1,42 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import {
5
+ convertToMap,
6
+ convertToObject,
7
+ } from '../../../utils/convert-json-object.js';
8
+
9
+ function updateCompilerOptions(tsconfigJson) {
10
+ const compilerOptions = convertToMap(tsconfigJson['compilerOptions']);
11
+
12
+ compilerOptions.delete('baseUrl');
13
+ compilerOptions.delete('paths');
14
+
15
+ tsconfigJson['compilerOptions'] = convertToObject(compilerOptions);
16
+ }
17
+
18
+ function updateInclude(tsconfigJson) {
19
+ tsconfigJson['include'] = ['src/**/*', 'unpublished-development-types/**/*'];
20
+ }
21
+
22
+ export function updateAddonTsconfigJson(options) {
23
+ const { locations, packages, projectRoot } = options;
24
+
25
+ if (!packages.addon.hasTypeScript) {
26
+ return;
27
+ }
28
+
29
+ const oldPath = join(projectRoot, locations.addon, 'tsconfig.json');
30
+ const oldFile = readFileSync(oldPath, 'utf8');
31
+ const tsconfigJson = JSON.parse(
32
+ // Remove comments
33
+ oldFile.replace(new RegExp('//.*', 'mg'), '')
34
+ );
35
+
36
+ updateCompilerOptions(tsconfigJson);
37
+ updateInclude(tsconfigJson);
38
+
39
+ const newFile = JSON.stringify(tsconfigJson, null, 2) + '\n';
40
+
41
+ writeFileSync(oldPath, newFile, 'utf8');
42
+ }