Skip to content

Commit 51836f9

Browse files
authored
Removed hardcoded package manager names (#83)
* refactor: Simplified Options['packageManager'] * chore: Updated tests * bugfix: Removed hardcoded package manager names * chore: Used single quotation marks for consistency * chore: Updated fixtures --------- Co-authored-by: ijlee2 <[email protected]>
1 parent 28d104f commit 51836f9

File tree

58 files changed

+140
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+140
-206
lines changed

src/blueprints/ember-addon/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if (options.packageManager.isNpm) { %>{
1+
<% if (options.packageManager === 'npm') { %>{
22
"name": "workspace-root",
33
"version": "<%= options.packages.addon.version %>",
44
"private": true,
@@ -22,7 +22,7 @@
2222
"devDependencies": {
2323
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
2424
}
25-
}<% } else if (options.packageManager.isPnpm) { %>{
25+
}<% } else if (options.packageManager === 'pnpm') { %>{
2626
"name": "workspace-root",
2727
"version": "<%= options.packages.addon.version %>",
2828
"private": true,
@@ -34,15 +34,15 @@
3434
"lint": "pnpm --filter '*' lint",
3535
"lint:fix": "pnpm --filter '*' lint:fix",
3636
"prepare": "pnpm build",
37-
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
37+
"start": "concurrently 'pnpm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
3838
"start:addon": "pnpm --filter <%= options.packages.addon.name %> start",
3939
"start:test-app": "pnpm --filter <%= options.packages.testApp.name %> start",
4040
"test": "pnpm --filter '*' test"
4141
},
4242
"devDependencies": {
4343
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
4444
}
45-
}<% } else if (options.packageManager.isYarn) { %>{
45+
}<% } else if (options.packageManager === 'yarn') { %>{
4646
"name": "workspace-root",
4747
"version": "<%= options.packages.addon.version %>",
4848
"private": true,
@@ -58,7 +58,7 @@
5858
"lint": "yarn workspaces run lint",
5959
"lint:fix": "yarn workspaces run lint:fix",
6060
"prepare": "yarn build",
61-
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
61+
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
6262
"start:addon": "yarn workspace <%= options.packages.addon.name %> run start",
6363
"start:test-app": "yarn workspace <%= options.packages.testApp.name %> run start",
6464
"test": "yarn workspaces run test"

src/steps/create-files-from-blueprints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getFilesToSkip(options: Options): string[] {
1818
files.add('__testAppLocation__/types/global.d.ts');
1919
}
2020

21-
if (!packageManager.isPnpm) {
21+
if (packageManager !== 'pnpm') {
2222
files.add('pnpm-workspace.yaml');
2323
}
2424

src/steps/create-options.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ function analyzePackageJson(codemodOptions: CodemodOptions): AddonPackage {
3939
function analyzePackageManager(codemodOptions: CodemodOptions): PackageManager {
4040
const { projectRoot } = codemodOptions;
4141

42-
const mapping = new Map([
43-
['package-lock.json', 'npm'],
44-
['pnpm-lock.yaml', 'pnpm'],
45-
['yarn.lock', 'yarn'],
46-
]);
42+
const mapping = {
43+
'package-lock.json': 'npm',
44+
'pnpm-lock.yaml': 'pnpm',
45+
'yarn.lock': 'yarn',
46+
} as const;
4747

48-
const lockFiles = Array.from(mapping.keys());
48+
const lockFiles = Object.keys(mapping);
4949

5050
const filePaths = findFiles(lockFiles, {
5151
projectRoot,
@@ -54,20 +54,12 @@ function analyzePackageManager(codemodOptions: CodemodOptions): PackageManager {
5454
if (filePaths.length !== 1) {
5555
console.warn('WARNING: Package manager is unknown. Yarn will be assumed.');
5656

57-
return {
58-
isNpm: false,
59-
isPnpm: false,
60-
isYarn: true,
61-
};
57+
return 'yarn';
6258
}
6359

64-
const packageManager = mapping.get(filePaths[0]!);
60+
const lockfile = filePaths[0] as keyof typeof mapping;
6561

66-
return {
67-
isNpm: packageManager === 'npm',
68-
isPnpm: packageManager === 'pnpm',
69-
isYarn: packageManager === 'yarn',
70-
};
62+
return mapping[lockfile];
7163
}
7264

7365
function deriveAddonLocation(addonPackage: AddonPackage): string {

src/steps/update-addon-package-json/update-scripts.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function updateScripts(
66
packageJson: PackageJson,
77
options: Options,
88
): void {
9-
const { locations, packages } = options;
9+
const { locations, packageManager, packages } = options;
1010

1111
const scripts = convertToMap(packageJson['scripts']);
1212

@@ -16,8 +16,14 @@ export function updateScripts(
1616
*/
1717
scripts.clear();
1818

19-
scripts.set('lint', "concurrently 'npm:lint:*(!fix)' --names 'lint:'");
20-
scripts.set('lint:fix', "concurrently 'npm:lint:*:fix' --names 'fix:'");
19+
scripts.set(
20+
'lint',
21+
`concurrently '${packageManager}:lint:*(!fix)' --names 'lint:'`,
22+
);
23+
scripts.set(
24+
'lint:fix',
25+
`concurrently '${packageManager}:lint:*:fix' --names 'fix:'`,
26+
);
2127
scripts.set(
2228
'lint:hbs',
2329
'ember-template-lint . --no-error-on-unmatched-pattern',
@@ -34,11 +40,11 @@ export function updateScripts(
3440
);
3541

3642
if (packages.addon.hasTypeScript) {
37-
scripts.set('build', 'concurrently "npm:build:*"');
43+
scripts.set('build', `concurrently '${packageManager}:build:*'`);
3844
scripts.set('build:js', 'rollup --config');
3945
scripts.delete('postpack');
40-
scripts.set('prepack', "concurrently 'npm:build:*'");
41-
scripts.set('start', 'concurrently "npm:start:*"');
46+
scripts.set('prepack', `concurrently '${packageManager}:build:*'`);
47+
scripts.set('start', `concurrently '${packageManager}:start:*'`);
4248
scripts.set('start:js', 'rollup --config --watch --no-watch.clearScreen');
4349

4450
if (packages.addon.hasGlint) {

src/types/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ type Options = {
2222
addon: string;
2323
testApp: string;
2424
};
25-
packageManager: {
26-
isNpm: boolean;
27-
isPnpm: boolean;
28-
isYarn: boolean;
29-
};
25+
packageManager: 'npm' | 'pnpm' | 'yarn';
3026
packages: {
3127
addon: {
3228
dependencies: Map<string, string>;

tests/fixtures/ember-container-query-customizations/output/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "yarn workspaces run lint",
1515
"lint:fix": "yarn workspaces run lint:fix",
1616
"prepare": "yarn build",
17-
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
17+
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
1818
"start:addon": "yarn workspace ember-container-query run start",
1919
"start:test-app": "yarn workspace demo-app-for-ember-container-query run start",
2020
"test": "yarn workspaces run test"

tests/fixtures/ember-container-query-customizations/output/packages/ember-container-query/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
"test": "tests"
2525
},
2626
"scripts": {
27-
"build": "concurrently \"npm:build:*\"",
27+
"build": "concurrently 'yarn:build:*'",
2828
"build:js": "rollup --config",
2929
"build:types": "glint --declaration",
30-
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
31-
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
30+
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
31+
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
3232
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
3333
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
3434
"lint:js": "eslint . --cache",
3535
"lint:js:fix": "eslint . --fix",
3636
"lint:types": "glint",
37-
"prepack": "concurrently 'npm:build:*'",
38-
"start": "concurrently \"npm:start:*\"",
37+
"prepack": "concurrently 'yarn:build:*'",
38+
"start": "concurrently 'yarn:start:*'",
3939
"start:js": "rollup --config --watch --no-watch.clearScreen",
4040
"start:types": "glint --declaration --watch",
4141
"test": "echo 'A v2 addon does not have tests, run tests in demo-app'"

tests/fixtures/ember-container-query-glint/output/ember-container-query/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
"test": "tests"
2525
},
2626
"scripts": {
27-
"build": "concurrently \"npm:build:*\"",
27+
"build": "concurrently 'yarn:build:*'",
2828
"build:js": "rollup --config",
2929
"build:types": "glint --declaration",
30-
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
31-
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
30+
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
31+
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
3232
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
3333
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
3434
"lint:js": "eslint . --cache",
3535
"lint:js:fix": "eslint . --fix",
3636
"lint:types": "glint",
37-
"prepack": "concurrently 'npm:build:*'",
38-
"start": "concurrently \"npm:start:*\"",
37+
"prepack": "concurrently 'yarn:build:*'",
38+
"start": "concurrently 'yarn:start:*'",
3939
"start:js": "rollup --config --watch --no-watch.clearScreen",
4040
"start:types": "glint --declaration --watch",
4141
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"

tests/fixtures/ember-container-query-glint/output/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "yarn workspaces run lint",
1515
"lint:fix": "yarn workspaces run lint:fix",
1616
"prepare": "yarn build",
17-
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
17+
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
1818
"start:addon": "yarn workspace ember-container-query run start",
1919
"start:test-app": "yarn workspace test-app run start",
2020
"test": "yarn workspaces run test"

tests/fixtures/ember-container-query-javascript/output/ember-container-query/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
},
2626
"scripts": {
2727
"build": "rollup --config",
28-
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
29-
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
28+
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
29+
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
3030
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
3131
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
3232
"lint:js": "eslint . --cache",

0 commit comments

Comments
 (0)