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

Use Chosen Package Manager (Catalog) #1044

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions .changeset/wise-queens-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
"@gasket/plugin-dynamic-plugins": patch
"@gasket/plugin-service-worker": patch
"@gasket/plugin-docs-graphs": patch
"@gasket/plugin-elastic-apm": patch
"@gasket/plugin-https-proxy": patch
"@gasket/plugin-docusaurus": patch
"@gasket/plugin-middleware": patch
"@gasket/plugin-typescript": patch
"@gasket/plugin-happyfeet": patch
"@gasket/typescript-tests": patch
"@gasket/plugin-manifest": patch
"@gasket/plugin-metadata": patch
"@gasket/plugin-analyze": patch
"@gasket/plugin-command": patch
"@gasket/plugin-cypress": patch
"@gasket/plugin-express": patch
"@gasket/plugin-fastify": patch
"@gasket/plugin-swagger": patch
"@gasket/plugin-webpack": patch
"@gasket/plugin-winston": patch
"@gasket/plugin-workbox": patch
"@gasket/plugin-logger": patch
"@gasket/plugin-morgan": patch
"@gasket/plugin-nextjs": patch
"@gasket/preset-nextjs": patch
"@gasket/plugin-https": patch
"@gasket/plugin-mocha": patch
"@gasket/plugin-redux": patch
"@gasket/plugin-data": patch
"@gasket/plugin-docs": patch
"@gasket/plugin-intl": patch
"@gasket/plugin-jest": patch
"@gasket/plugin-lint": patch
"generate-docs-index": patch
"create-gasket-app": patch
"@gasket/plugin-git": patch
"@gasket/preset-api": patch
"@gasket/react-intl": patch
"@gasket/request": patch
"@gasket/assets": patch
"@gasket/nextjs": patch
"@gasket/fetch": patch
"@gasket/redux": patch
"@gasket/utils": patch
"@gasket/core": patch
"@gasket/data": patch
"@gasket/intl": patch
---

Updates to use user-selected package manager. Update all packages to use catalog dep versions.
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
registry=https://registry.npmjs.org/
package-manager=pnpm@latest
link-workspace-packages=true
strict-peer-dependencies=true
strict-dependencies=true
auto-install-peers=true
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ async function choosePackageManager(context, prompt) {
{ name: 'npm' },
{ name: 'pnpm' },
{ name: 'yarn' }
]
],
default: 'npm'
}
])
).packageManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@ import { runShellCommand } from '@gasket/utils';
* @type {import('../../internal').postCreateHooks}
*/
async function postCreateHooks({ gasket, context }) {
const { dest } = context;
const { dest, packageManager } = context;

/**
* Run an npm script in the context of the created application
* @param {string} script name of script
* @returns {Promise} A promise represents if npm succeeds or fails.
* Determines the correct command for running scripts based on the package manager.
* @param {string} script - The name of the script to run.
* @returns {Promise} A promise that resolves if the script runs successfully.
*/
async function runScript(script) {
return await runShellCommand('pnpm', ['run', script], { cwd: dest });
let cmd;

switch (packageManager) {
case 'yarn':
cmd = 'yarn';
break;
case 'pnpm':
cmd = 'pnpm';
break;
case 'npm':
default:
cmd = 'npm';
break;
}

return await runShellCommand(cmd, ['run', script], { cwd: dest });
}

/**
* An object with one value for now, so adding more utilities
* in future is easy.
* An object with one value for now, so adding more utilities in future is easy.
*/
const utils = { runScript };
await gasket.exec('postCreate', context, utils);
Expand Down
1 change: 1 addition & 0 deletions packages/create-gasket-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
},
"devDependencies": {
"@gasket/request": "^7.3.0",
"@jest/globals": "^29.7.0",
"@types/inquirer": "^9.0.7",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@swc/cli": "^0.3.14",
"@swc/cli": "^0.6.0",
"@swc/core": "^1.10.18",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"devDependencies": {
"@gasket/plugin-data": "^7.3.0",
"@jest/globals": "^29.7.0",
"@swc/cli": "^0.3.14",
"@swc/cli": "^0.6.0",
"@swc/core": "^1.10.18",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"jest": "^29.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"start-server-and-test": "^1.15.4",
"start-server-and-test": "^2.0.10",
"typescript": "^5.7.3"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-https-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-unicorn": "^55.0.0",
"typescript": "^5.7.3",
"vitest": "^2.1.9"
"vitest": "^3.0.7"
},
"eslintConfig": {
"extends": [
Expand Down
6 changes: 3 additions & 3 deletions packages/gasket-plugin-lint/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ function makeGatherDevDeps() {
/**
* Creates a function to generate the correct package script execution command.
*
* This function returns a script command formatted for either npm or yarn, depending
* This function returns a script command formatted for npm, yarn, or pnpm, depending
* on the package manager used in the given context.
* @type {import('./internal').makeRunScriptStr}
*/
function makeRunScriptStr(context) {
var runCmd = context.packageManager === 'npm' ? 'npm run' : context.packageManager;
let runCmd = `${context.packageManager} run`;

/**
* Formats the script command for execution.
Expand All @@ -85,7 +85,7 @@ function makeRunScriptStr(context) {
throw new TypeError('Script name must be a non-empty string.');
}

return runCmd === 'yarn' ? (runCmd + ' ' + script).replace(' -- ', ' ') : runCmd + ' ' + script;
return runCmd.includes('npm') ? `${runCmd} ${script}` : (`${runCmd} ${script}`).replace(' -- ', ' ');
}

return runScriptStr;
Expand Down
4 changes: 2 additions & 2 deletions packages/gasket-plugin-lint/test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ describe('utils', () => {

it('[yarn] returns command', () => {
const results = forYarn('test-script');
expect(results).toEqual('yarn test-script');
expect(results).toEqual('yarn run test-script');
});

it('[yarn] returns command with flags (removes "--")', () => {
const results = forYarn('test-script -- --extra');
expect(results).toEqual('yarn test-script --extra');
expect(results).toEqual('yarn run test-script --extra');
});

it('throws TypeError for an invalid script name', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-unicorn": "^55.0.0",
"typescript": "^5.7.3",
"vitest": "^2.1.9"
"vitest": "^3.0.7"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"devDependencies": {
"@gasket/core": "^7.3.0",
"@jest/globals": "^29.7.0",
"@swc/cli": "^0.3.14",
"@swc/cli": "^0.6.0",
"@swc/core": "^1.10.18",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.19",
Expand Down
Loading
Loading