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

ISSUE-65: use 'files' field instead of '.npmignore' file #67

Merged
merged 3 commits into from
Jun 4, 2021
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
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node_version: [8, 10, 12, 14, 15]
node_version: [8, 10, 12, 14, 16]
os:
- ubuntu-latest
- macos-latest
Expand All @@ -54,5 +54,9 @@ jobs:
if: ${{ matrix.node_version != 8 }}
- name: Run dependencies checks
run: npm run lint:dependencies
- name: Run size limit check
run: npm run lint:size
env:
TOOLS_SIZE_LIMIT_SKIP: '1'
- name: Run unit tests
run: npm run test
28 changes: 0 additions & 28 deletions .npmignore

This file was deleted.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"node": ">= 8"
},
"scripts": {
"preversion": "npm run lint:size",
"clean": "lerna run --parallel clean",
"lint": "lerna run --parallel lint",
"lint:dependencies": "depend --lerna . --bail --hint --strategy=conservative",
"lint:size": "lerna exec tools.size-limit --no-private --parallel",
"compile": "tsc -b ./packages --verbose",
"test": "lerna run --parallel test",
"build": "npm run clean && npm run compile && npm run lint && npm run test",
Expand All @@ -20,6 +22,7 @@
},
"devDependencies": {
"@nodelib-internal/tools.typedoc": "file:tools/typedoc",
"@nodelib-internal/tools.size-limit": "file:tools/size-limit",
"@times-components/depend": "2.1.15",
"@types/mocha": "^7.0.2",
"@types/node": "^12.20.12",
Expand Down
1 change: 0 additions & 1 deletion packages/fs/fs.macchiato/.npmignore

This file was deleted.

5 changes: 5 additions & 0 deletions packages/fs/fs.macchiato/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"engines": {
"node": ">= 8"
},
"files": [
"out/*",
"!out/*.map",
"!out/*.spec.*"
],
"main": "out/index.js",
"typings": "out/index.d.ts",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/fs/fs.scandir/.npmignore

This file was deleted.

5 changes: 5 additions & 0 deletions packages/fs/fs.scandir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"engines": {
"node": ">= 8"
},
"files": [
"out/**",
"!out/**/*.map",
"!out/**/*.spec.*"
],
"main": "out/index.js",
"typings": "out/index.d.ts",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/fs/fs.stat/.npmignore

This file was deleted.

5 changes: 5 additions & 0 deletions packages/fs/fs.stat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"engines": {
"node": ">= 8"
},
"files": [
"out/**",
"!out/**/*.map",
"!out/**/*.spec.*"
],
"main": "out/index.js",
"typings": "out/index.d.ts",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/fs/fs.walk/.npmignore

This file was deleted.

6 changes: 6 additions & 0 deletions packages/fs/fs.walk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"engines": {
"node": ">= 8"
},
"files": [
"out/**",
"!out/**/*.map",
"!out/**/*.spec.*",
"!out/**/tests/**"
],
"main": "out/index.js",
"typings": "out/index.d.ts",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions tools/size-limit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"name": "@nodelib-internal/tools.size-limit",
"version": "0.0.0",
"bin": {
"tools.size-limit": "size-limit.js"
},
"dependencies": {
"chalk": "4.1.1",
"pretty-bytes": "5.6.0"
}
}
89 changes: 89 additions & 0 deletions tools/size-limit/size-limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env node

const cp = require('child_process');
const util = require('util');

const prettyBytes = require('pretty-bytes');
const chalk = require('chalk');

chalk.level = 1;

const executeCommand = util.promisify(cp.exec);

const RATIO_LIMIT = 10;
const LERNA_PACKAGE_NAME = process.env.LERNA_PACKAGE_NAME;
const TOOLS_SIZE_LIMIT_SKIP = process.env.TOOLS_SIZE_LIMIT_SKIP;

async function main() {
const remote = await getPackageSize(`${LERNA_PACKAGE_NAME}@latest`);
const local = await getPackageSize('.');

// How much the current value is greater than the previous one.
const sizeRatio = (local.size - remote.size) / remote.size * 100;
const unpackedSizeRatio = (local.unpackedSize - remote.unpackedSize) / remote.unpackedSize * 100;
const entryCountRatio = (local.entryCount - remote.entryCount) / remote.entryCount * 100;

/** @type {string[]} */
const lines = [];

if (sizeRatio > RATIO_LIMIT) {
const current = prettyBytes(local.size);
const previous = prettyBytes(remote.size);

lines.push(`The size of the new version is ${chalk.red(current)} which is ${chalk.yellow(`${sizeRatio.toFixed(2)}%`)} more than the previous version (${chalk.green(previous)}).`);
}

if (unpackedSizeRatio > RATIO_LIMIT) {
const current = prettyBytes(local.unpackedSize);
const previous = prettyBytes(remote.unpackedSize);

lines.push(`The unpacked size of the new version is ${chalk.red(current)} which is ${chalk.yellow(`${unpackedSizeRatio.toFixed(2)}%`)} more than the previous version (${chalk.green(previous)}).`);
}

if (entryCountRatio > RATIO_LIMIT) {
lines.push(`The number of files in the new version is ${chalk.red(local.entryCount)} which is ${chalk.yellow(`${entryCountRatio.toFixed(2)}%`)} more than the previous version (${chalk.green(remote.entryCount)}).`);
}

if (lines.length > 0) {
console.log(lines.join('\n'));

if (TOOLS_SIZE_LIMIT_SKIP) {
console.log('The size limit is reached, but the checker is disabled.');
} else {
throw new Error('The size limit is reached.');
}
}
}

/**
* @param {string} name
* @returns {Promise<PackageInfo>}
*/
async function getPackageSize(name) {
const { stdout } = await executeCommand(`npm pack ${name} --dry --json`);

const data = JSON.parse(stdout);

return {
size: data[0].size,
unpackedSize: data[0].unpackedSize,
entryCount: data[0].entryCount
};
}

(async () => {
try {
await main();
console.log(chalk.green('success'));
} catch (error) {
console.log(chalk.red(error.message));
process.exit(1);
}
})();

/**
* @typedef {Object} PackageInfo
* @property {number} size
* @property {number} unpackedSize
* @property {number} entryCount
*/