Skip to content

Commit

Permalink
Merge pull request #156 from pustovalov/yarn2
Browse files Browse the repository at this point in the history
Yarn 2 support
  • Loading branch information
ai committed Jan 31, 2020
2 parents 91a9dc5 + 10f74ae commit ad7dbd3
Show file tree
Hide file tree
Showing 38 changed files with 191 additions and 50 deletions.
16 changes: 8 additions & 8 deletions packages/size-limit/create-help.js
Expand Up @@ -71,7 +71,7 @@ module.exports = process => {
}

function showMigrationGuide (pkg) {
let { add, rm } = npmCommands(pkg)
let { add } = npmCommands(pkg)
printError(
chalk.red('Install Size Limit preset depends on type of the project'),
'',
Expand All @@ -81,24 +81,24 @@ module.exports = process => {
' ' + y(add + '@size-limit/preset-big-lib'),
'For small (< 10 KB) libraries',
' ' + y(add + '@size-limit/preset-small-lib'),
'Check out docs for more comlicated cases',
'Check out docs for more complicated cases',
' ' + y('https://github.com/ai/size-limit/')
)
let devDependencies = pkg.packageJson.devDependencies
if (devDependencies && devDependencies['size-limit']) {
if (devDependencies && !devDependencies['size-limit']) {
printError(
'',
`You can remove size-limit dependency: ${ y(rm + 'size-limit') }`
`You need to add size-limit dependency: ${ y(add + 'size-limit') }`
)
}
}

function warnAboutDep (pkg) {
let { rm } = npmCommands(pkg)
let { add } = npmCommands(pkg)
printError(
chalk.bgYellow.black(' WARN ') + ' You can remove size-limit dependency',
' All plugins and presets already contain it as own dependency',
' ' + y(rm + 'size-limit'),
chalk.bgYellow.black(' WARN ') + ' You need to add size-limit dependency',
' In order for the plugins to work correctly',
' ' + y(add + 'size-limit'),
''
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/run.js
Expand Up @@ -44,7 +44,7 @@ module.exports = async process => {
return process.exit(1)
}

if (devDeps(pkg)['size-limit'] && !hasArg('--json')) {
if (!devDeps(pkg)['size-limit'] && !hasArg('--json')) {
help.warnAboutDep(pkg)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/size-limit/size-limit-error.js
@@ -1,10 +1,10 @@
const MESSAGES = {
noPackage: () => (
'Size Limit did’t find *package.json*. ' +
'Size Limit didn’t find *package.json*. ' +
'Create npm package and run Size Limit there.'
),
unknownArg: arg => (
`Uknown argument *${ arg }*. Check command for typo and read docs.`
`Unknown argument *${ arg }*. Check command for typo and read docs.`
),
argWithoutWebpack: arg => (
`Argument *--${ arg }* works only with *@size-limit/webpack* plugin` +
Expand Down
66 changes: 53 additions & 13 deletions packages/size-limit/test/__snapshots__/run.test.js.snap
Expand Up @@ -139,7 +139,7 @@ exports[`shows debug on error 1`] = `
{
\\"limit\\": \\"200 s\\",
\\"path\\": [
\\"/packages/size-limit/test/fixtures/interal-error/index.js\\"
\\"/packages/size-limit/test/fixtures/internal-error/index.js\\"
],
\\"name\\": \\"index.js\\",
\\"timeLimit\\": 200
Expand All @@ -151,7 +151,7 @@ exports[`shows debug on error 1`] = `
`;

exports[`shows error on missed package.json 1`] = `
"[41m[30m ERROR [39m[49m [31mSize Limit did’t find [33mpackage.json[39m[31m.[39m
"[41m[30m ERROR [39m[49m [31mSize Limit didn’t find [33mpackage.json[39m[31m.[39m
 Create npm package and run Size Limit there.
"
`;
Expand Down Expand Up @@ -197,11 +197,35 @@ For frameworks, components and big libraries
npm install --save-dev @size-limit/preset-big-lib
For small (< 10 KB) libraries
npm install --save-dev @size-limit/preset-small-lib
Check out docs for more comlicated cases
Check out docs for more complicated cases
https://github.com/ai/size-limit/
"
`;

exports[`shows migration guide for npm users: config 1, dep 0 1`] = `
"Install Size Limit preset depends on type of the project
For application, where you send JS bundle directly to users
npm install --save-dev @size-limit/preset-app
For frameworks, components and big libraries
npm install --save-dev @size-limit/preset-big-lib
For small (< 10 KB) libraries
npm install --save-dev @size-limit/preset-small-lib
Check out docs for more complicated cases
https://github.com/ai/size-limit/
You need to add size-limit dependency: npm install --save-dev size-limit
"
`;

exports[`shows migration guide for npm users: without sl dev dep 1`] = `
" WARN  You need to add size-limit dependency
In order for the plugins to work correctly
npm install --save-dev size-limit
"
`;

exports[`shows migration guide for yarn users 1`] = `
"Install Size Limit preset depends on type of the project
Expand All @@ -211,21 +235,37 @@ For frameworks, components and big libraries
yarn add --dev @size-limit/preset-big-lib
For small (< 10 KB) libraries
yarn add --dev @size-limit/preset-small-lib
Check out docs for more comlicated cases
Check out docs for more complicated cases
https://github.com/ai/size-limit/
"
`;

You can remove size-limit dependency: yarn remove size-limit
exports[`shows migration guide for yarn users: config 1, dep 0 1`] = `
"Install Size Limit preset depends on type of the project
For application, where you send JS bundle directly to users
yarn add --dev @size-limit/preset-app
For frameworks, components and big libraries
yarn add --dev @size-limit/preset-big-lib
For small (< 10 KB) libraries
yarn add --dev @size-limit/preset-small-lib
Check out docs for more complicated cases
https://github.com/ai/size-limit/
You need to add size-limit dependency: yarn add --dev size-limit
"
`;

exports[`shows size-limit dependency warning 1`] = `
"[43m[30m WARN [39m[49m You can remove size-limit dependency
All plugins and presets already contain it as own dependency
[33mnpm remove size-limit[39m
exports[`shows migration guide for yarn users: without sl dev dep 1`] = `
"[43m[30m WARN [39m[49m You need to add size-limit dependency
In order for the plugins to work correctly
[33myarn add --dev size-limit[39m
"
`;

exports[`shows size-limit dependency warning 1`] = `""`;

exports[`shows webpack-related help 1`] = `
"size-limit [OPTION]… [FILE]…
Check the real performance cost of your front-end project to users
Expand Down Expand Up @@ -343,7 +383,7 @@ exports[`throws on time limit without time plugin 1`] = `
`;
exports[`throws on unknown argument 1`] = `
"[41m[30m ERROR [39m[49m [31mUknown argument [33m--unknown[39m[31m.[39m
"[41m[30m ERROR [39m[49m [31mUnknown argument [33m--unknown[39m[31m.[39m
 Check command for typo and read docs.
"
`;
Expand Down Expand Up @@ -394,7 +434,7 @@ Check the real performance cost of your front-end project to users
"
`;
exports[`works in intergration test with JSON 1`] = `
exports[`works in integration test with JSON 1`] = `
"[
{
\\"name\\": \\"index.js\\",
Expand All @@ -407,7 +447,7 @@ exports[`works in intergration test with JSON 1`] = `
"
`;
exports[`works in intergration test with size 1`] = `
exports[`works in integration test with size 1`] = `
"
Size limit: 200 B
Size: 31 B  with all dependencies, minified and gzipped
Expand All @@ -418,7 +458,7 @@ exports[`works in intergration test with size 1`] = `
"
`;
exports[`works in intergration test with time 1`] = `
exports[`works in integration test with time 1`] = `
"
Time limit: 2 s
Size: 31 B  with all dependencies, minified and gzipped
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/empty/package.json
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": []
}
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/file/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "file",
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/globby/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "file",
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/integration/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "intergration",
"private": true,
"devDependencies": {
"@size-limit/preset-big-lib": ">= 0.0.0"
"@size-limit/preset-big-lib": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
Expand Up @@ -2,7 +2,8 @@
"name": "intergration",
"private": true,
"devDependencies": {
"@size-limit/time": ">= 0.0.0"
"@size-limit/time": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/non-array/package.json
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": { }
}
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/non-gzip/package.json
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/time": ">= 0.0.0"
"@size-limit/time": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/non-object/package.json
@@ -1,6 +1,7 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
}
}
@@ -1,6 +1,7 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/non-string/package.json
@@ -1,6 +1,7 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/non-time/package.json
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/non-webpack/package.json
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
Empty file.
@@ -0,0 +1,12 @@
{
"name": "file",
"private": true,
"devDependencies": {},
"size-limit": [
{
"path": "index.js",
"limit": "1 KB",
"running": false
}
]
}
Empty file.
14 changes: 14 additions & 0 deletions packages/size-limit/test/fixtures/npm-without-dev-dep/package.json
@@ -0,0 +1,14 @@
{
"name": "file",
"private": true,
"devDependencies": {
"@size-limit/preset-big-lib": ">= 0.0.0"
},
"size-limit": [
{
"path": "index.js",
"limit": "1 KB",
"running": false
}
]
}
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/peer/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "file",
"private": true,
"devDependencies": {
"@size-limit/webpack": ">= 0.0.0"
"@size-limit/webpack": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"peerDependencies": {
"a": ">= 0.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/simple/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "file",
"private": true,
"devDependencies": {
"@size-limit/file": ">= 0.0.0"
"@size-limit/file": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/fixtures/time/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "file",
"private": true,
"devDependencies": {
"@size-limit/time": ">= 0.0.0"
"@size-limit/time": ">= 0.0.0",
"size-limit": ">= 0.0.0"
},
"size-limit": [
{
Expand Down

0 comments on commit ad7dbd3

Please sign in to comment.