Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed hardcoded package manager names #83

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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 @@ -34,15 +34,15 @@
"lint": "pnpm --filter '*' lint",
"lint:fix": "pnpm --filter '*' lint:fix",
"prepare": "pnpm build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'pnpm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "pnpm --filter <%= options.packages.addon.name %> start",
"start:test-app": "pnpm --filter <%= options.packages.testApp.name %> start",
"test": "pnpm --filter '*' test"
},
"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 All @@ -58,7 +58,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace <%= options.packages.addon.name %> run start",
"start:test-app": "yarn workspace <%= options.packages.testApp.name %> run start",
"test": "yarn workspaces run test"
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
18 changes: 12 additions & 6 deletions src/steps/update-addon-package-json/update-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function updateScripts(
packageJson: PackageJson,
options: Options,
): void {
const { locations, packages } = options;
const { locations, packageManager, packages } = options;

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

Expand All @@ -16,8 +16,14 @@ export function updateScripts(
*/
scripts.clear();

scripts.set('lint', "concurrently 'npm:lint:*(!fix)' --names 'lint:'");
scripts.set('lint:fix', "concurrently 'npm:lint:*:fix' --names 'fix:'");
scripts.set(
'lint',
`concurrently '${packageManager}:lint:*(!fix)' --names 'lint:'`,
);
scripts.set(
'lint:fix',
`concurrently '${packageManager}:lint:*:fix' --names 'fix:'`,
);
scripts.set(
'lint:hbs',
'ember-template-lint . --no-error-on-unmatched-pattern',
Expand All @@ -34,11 +40,11 @@ export function updateScripts(
);

if (packages.addon.hasTypeScript) {
scripts.set('build', 'concurrently "npm:build:*"');
scripts.set('build', `concurrently '${packageManager}:build:*'`);
scripts.set('build:js', 'rollup --config');
scripts.delete('postpack');
scripts.set('prepack', "concurrently 'npm:build:*'");
scripts.set('start', 'concurrently "npm:start:*"');
scripts.set('prepack', `concurrently '${packageManager}:build:*'`);
scripts.set('start', `concurrently '${packageManager}:start:*'`);
scripts.set('start:js', 'rollup --config --watch --no-watch.clearScreen');

if (packages.addon.hasGlint) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace ember-container-query run start",
"start:test-app": "yarn workspace demo-app-for-ember-container-query run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
"test": "tests"
},
"scripts": {
"build": "concurrently \"npm:build:*\"",
"build": "concurrently 'yarn:build:*'",
"build:js": "rollup --config",
"build:types": "glint --declaration",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "glint",
"prepack": "concurrently 'npm:build:*'",
"start": "concurrently \"npm:start:*\"",
"prepack": "concurrently 'yarn:build:*'",
"start": "concurrently 'yarn:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "glint --declaration --watch",
"test": "echo 'A v2 addon does not have tests, run tests in demo-app'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
"test": "tests"
},
"scripts": {
"build": "concurrently \"npm:build:*\"",
"build": "concurrently 'yarn:build:*'",
"build:js": "rollup --config",
"build:types": "glint --declaration",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "glint",
"prepack": "concurrently 'npm:build:*'",
"start": "concurrently \"npm:start:*\"",
"prepack": "concurrently 'yarn:build:*'",
"start": "concurrently 'yarn:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "glint --declaration --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace ember-container-query run start",
"start:test-app": "yarn workspace test-app run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"scripts": {
"build": "rollup --config",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace ember-container-query run start",
"start:test-app": "yarn workspace test-app run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
"test": "tests"
},
"scripts": {
"build": "concurrently \"npm:build:*\"",
"build": "concurrently 'yarn:build:*'",
"build:js": "rollup --config",
"build:types": "glint --declaration",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "glint",
"prepack": "concurrently 'npm:build:*'",
"start": "concurrently \"npm:start:*\"",
"prepack": "concurrently 'yarn:build:*'",
"start": "concurrently 'yarn:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "glint --declaration --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace @ijlee2/ember-container-query run start",
"start:test-app": "yarn workspace test-app run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
"test": "tests"
},
"scripts": {
"build": "concurrently \"npm:build:*\"",
"build": "concurrently 'yarn:build:*'",
"build:js": "rollup --config",
"build:types": "tsc",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "tsc --emitDeclarationOnly false --noEmit",
"prepack": "concurrently 'npm:build:*'",
"start": "concurrently \"npm:start:*\"",
"prepack": "concurrently 'yarn:build:*'",
"start": "concurrently 'yarn:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "tsc --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace ember-container-query run start",
"start:test-app": "yarn workspace test-app run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace new-v1-addon run start",
"start:test-app": "yarn workspace demo-app-for-new-v1-addon run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
"test": "tests"
},
"scripts": {
"build": "concurrently \"npm:build:*\"",
"build": "concurrently 'yarn:build:*'",
"build:js": "rollup --config",
"build:types": "tsc",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "tsc --emitDeclarationOnly false --noEmit",
"prepack": "concurrently 'npm:build:*'",
"start": "concurrently \"npm:start:*\"",
"prepack": "concurrently 'yarn:build:*'",
"start": "concurrently 'yarn:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "tsc --watch",
"test": "echo 'A v2 addon does not have tests, run tests in demo-app'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"scripts": {
"build": "rollup --config",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/new-v1-addon-javascript/output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"prepare": "yarn build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "yarn workspace new-v1-addon run start",
"start:test-app": "yarn workspace test-app run start",
"test": "yarn workspaces run test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"scripts": {
"build": "rollup --config",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/new-v1-addon-pnpm/output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "pnpm --filter '*' lint",
"lint:fix": "pnpm --filter '*' lint:fix",
"prepare": "pnpm build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start": "concurrently 'pnpm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:addon": "pnpm --filter new-v1-addon start",
"start:test-app": "pnpm --filter test-app start",
"test": "pnpm --filter '*' test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
"test": "tests"
},
"scripts": {
"build": "concurrently \"npm:build:*\"",
"build": "concurrently 'yarn:build:*'",
"build:js": "rollup --config",
"build:types": "tsc",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'yarn:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'yarn:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "tsc --emitDeclarationOnly false --noEmit",
"prepack": "concurrently 'npm:build:*'",
"start": "concurrently \"npm:start:*\"",
"prepack": "concurrently 'yarn:build:*'",
"start": "concurrently 'yarn:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "tsc --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
Expand Down
Loading