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

Support Yarn backward compatibility mode (node-modules) for Yarn version 2.x or higher #86

Merged
merged 3 commits into from
Nov 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 82 additions & 4 deletions __test__/after-task.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ansiColors.inverse = ansiColors;
ansiColors.underline = ansiColors;
ansiColors.bold = ansiColors;

const isAvailable = bin => bin === 'yarn';
const isAvailable = bin => bin === 'yarn' || bin === 'pnpm';

test('"after" task only prints summary in unattended mode', async t => {
const prompts = {
Expand Down Expand Up @@ -79,10 +79,49 @@ test('"after" task only prints summary in unattended mode and here mode', async
);
});

test('"after" task installs deps, and prints summary', async t => {
test('"after" task installs deps with npm, and prints summary', async t => {
const prompts = {
select(opts) {
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn']);
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn', 'pnpm']);
return 'npm';
}
};

function run(cmd, args) {
t.is(cmd, 'npm');
t.deepEqual(args, ['install']);
}

let printOut = '';
await after({
unattended: false,
here: false,
prompts,
run,
properties: {name: 'my-app'},
features: ['a', 'b'],
notDefaultFeatures: ['a', 'b-c'],
ansiColors
}, {
_isAvailable: isAvailable,
_log(m) {
printOut += m + '\n';
}
});

t.is(printOut,
'\nNext time, you can try to create similar project in silent mode:\n' +
' npx makes aurelia new-project-name -s a,b-c \n\n' +
'Get Started\n' +
'cd my-app\n' +
'npm start\n\n'
);
});

test('"after" task installs deps with yarn, and prints summary', async t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please duplicate this test case, one to cover npm, one for yarn.

const prompts = {
select(opts) {
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn', 'pnpm']);
return 'yarn';
}
};
Expand Down Expand Up @@ -114,7 +153,46 @@ test('"after" task installs deps, and prints summary', async t => {
' npx makes aurelia new-project-name -s a,b-c \n\n' +
'Get Started\n' +
'cd my-app\n' +
'npm start\n\n'
'yarn start\n\n'
);
});

test('"after" task installs deps with pnpm, and prints summary', async t => {
const prompts = {
select(opts) {
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn', 'pnpm']);
return 'pnpm';
}
};

function run(cmd, args) {
t.is(cmd, 'pnpm');
t.deepEqual(args, ['install']);
}

let printOut = '';
await after({
unattended: false,
here: false,
prompts,
run,
properties: {name: 'my-app'},
features: ['a', 'b'],
notDefaultFeatures: ['a', 'b-c'],
ansiColors
}, {
_isAvailable: isAvailable,
_log(m) {
printOut += m + '\n';
}
});

t.is(printOut,
'\nNext time, you can try to create similar project in silent mode:\n' +
' npx makes aurelia new-project-name -s a,b-c \n\n' +
'Get Started\n' +
'cd my-app\n' +
'pnpm start\n\n'
);
});

Expand Down
19 changes: 13 additions & 6 deletions after.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = async function({
} = {}) {
const c = ansiColors;
let depsInstalled = false;
let packageManager = undefined;

if (!unattended) {
const choices = [
Expand All @@ -28,22 +29,27 @@ module.exports = async function({
];

if (_isAvailable('yarn')) {
choices.push({value: 'yarn', title: 'Yes, use yarn'});
choices.push({value: 'yarn', title: 'Yes, use yarn (node-modules)'});
}

if (_isAvailable('pnpm')) {
choices.push({value: 'pnpm', title: 'Yes, use pnpm'});
}

const result = await prompts.select({
packageManager = await prompts.select({
message: 'Do you want to install npm dependencies now?',
choices
});

if (result) {
await run(result, ['install']);
if (packageManager) {
await run(packageManager, ['install']);

if (features.includes('playwright')) {
await run('npx', ['playwright', 'install', '--with-deps']);
if (packageManager === 'npm') {
await run('npx', ['playwright', 'install', '--with-deps']);
} else {
await run(packageManager, ['dlx', 'playwright', 'install', '--with-deps']);
3cp marked this conversation as resolved.
Show resolved Hide resolved
}
}
depsInstalled = true;
}
Expand All @@ -54,9 +60,10 @@ module.exports = async function({

_log(`\n${c.underline.bold('Get Started')}`);
if (!here) _log('cd ' + properties.name);

if (!depsInstalled) {
_log('npm install');
if (features.includes('playwright')) _log('npx playwright install --with-deps');
}
_log('npm start\n');
_log((packageManager ?? 'npm') + ' start\n');
};
1 change: 1 addition & 0 deletions common/.npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# for pnpm, use flat node_modules
shamefully-hoist=true
strict-peer-dependencies=false
5 changes: 2 additions & 3 deletions common/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# For compatibility in yarn 2
pnpMode: loose
pnpFallbackMode: all
# For compatibility in yarn 2+
nodeLinker: node-modules