Skip to content

Commit

Permalink
refactor: Simplified Options['packageManager']
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlee2 committed Apr 26, 2024
1 parent 28d104f commit b102ca0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/blueprints/ember-addon/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if (options.packageManager.isNpm) { %>{
<% if (options.packageManager === 'npm') { %>{
"name": "workspace-root",
"version": "<%= options.packages.addon.version %>",
"private": true,
Expand All @@ -22,7 +22,7 @@
"devDependencies": {
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
}
}<% } else if (options.packageManager.isPnpm) { %>{
}<% } else if (options.packageManager === 'pnpm') { %>{
"name": "workspace-root",
"version": "<%= options.packages.addon.version %>",
"private": true,
Expand All @@ -42,7 +42,7 @@
"devDependencies": {
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
}
}<% } else if (options.packageManager.isYarn) { %>{
}<% } else if (options.packageManager === 'yarn') { %>{
"name": "workspace-root",
"version": "<%= options.packages.addon.version %>",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion src/steps/create-files-from-blueprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getFilesToSkip(options: Options): string[] {
files.add('__testAppLocation__/types/global.d.ts');
}

if (!packageManager.isPnpm) {
if (packageManager !== 'pnpm') {
files.add('pnpm-workspace.yaml');
}

Expand Down
26 changes: 9 additions & 17 deletions src/steps/create-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ function analyzePackageJson(codemodOptions: CodemodOptions): AddonPackage {
function analyzePackageManager(codemodOptions: CodemodOptions): PackageManager {
const { projectRoot } = codemodOptions;

const mapping = new Map([
['package-lock.json', 'npm'],
['pnpm-lock.yaml', 'pnpm'],
['yarn.lock', 'yarn'],
]);
const mapping = {
'package-lock.json': 'npm',
'pnpm-lock.yaml': 'pnpm',
'yarn.lock': 'yarn',
} as const;

const lockFiles = Array.from(mapping.keys());
const lockFiles = Object.keys(mapping);

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

return {
isNpm: false,
isPnpm: false,
isYarn: true,
};
return 'yarn';
}

const packageManager = mapping.get(filePaths[0]!);
const lockfile = filePaths[0] as keyof typeof mapping;

return {
isNpm: packageManager === 'npm',
isPnpm: packageManager === 'pnpm',
isYarn: packageManager === 'yarn',
};
return mapping[lockfile];
}

function deriveAddonLocation(addonPackage: AddonPackage): string {
Expand Down
6 changes: 1 addition & 5 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ type Options = {
addon: string;
testApp: string;
};
packageManager: {
isNpm: boolean;
isPnpm: boolean;
isYarn: boolean;
};
packageManager: 'npm' | 'pnpm' | 'yarn';
packages: {
addon: {
dependencies: Map<string, string>;
Expand Down

0 comments on commit b102ca0

Please sign in to comment.