Skip to content

Commit

Permalink
Success checkpoint -2
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelsky committed Apr 3, 2022
1 parent a016686 commit 0a6b1db
Show file tree
Hide file tree
Showing 55 changed files with 5,987 additions and 6,552 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ yarn-error.log
# Serverless directories
.serverless
cache
tsconfig.tsbuildinfo
logs
version-packs.sh
1 change: 1 addition & 0 deletions .idea/package-build-stats.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 0 additions & 37 deletions .parcelrc

This file was deleted.

Binary file modified .yarn/install-state.gz
Binary file not shown.
550 changes: 550 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-version.cjs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .yarn/versions/1518cd58.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
undecided:
- package-build-stats-monorepo
- package-build-stats-cli
- parcel-reporter-package-build-stats
- parcel-resolver-package-build-stats
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ plugins:
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: "@yarnpkg/plugin-constraints"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"

yarnPath: .yarn/releases/yarn-3.2.0.cjs
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ server({ port: PORT }, [
const result = await getPackageExportSizes(packageString, {
debug: !!ctx.query.debug,
minifier: ctx.query.minifier,
client: ctx.query.client,
})
return json(result)
} catch (err) {
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}
37 changes: 10 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
"devDependencies": {
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@npmcli/package-json": "^1.0.1",
"@parcel/reporter-bundle-analyzer": "^2.4.1",
"@types/autoprefixer": "9.7.2",
"@types/babel__traverse": "^7.14.2",
"@types/chance": "^1.1.3",
"@types/enhanced-resolve": "^3.0.7",
"@types/lodash": "^4.14.179",
"@types/memory-fs": "^0.3.3",
"@types/mini-css-extract-plugin": "^2.5.1",
"@types/mkdirp": "^1",
"@types/node": "^14.18.12",
"@types/rimraf": "^3.0.2",
"@types/shortid": "^0.0.29",
Expand All @@ -50,7 +53,7 @@
"@types/write-file-webpack-plugin": "^4.5.2",
"dotenv": "^8.6.0",
"husky": "^4.3.8",
"jest": "^24.9.0",
"jest": "^27.5.1",
"p-series": "^2.1.0",
"prettier": "^2.5.1",
"pretty-quick": "^3.1.3",
Expand All @@ -77,53 +80,33 @@
"@parcel/transformer-vue": "^2.4.1",
"@parcel/types": "^2.4.1",
"@parcel/utils": "^2.4.1",
"@types/jest": "^27.4.1",
"autoprefixer": "^9.8.8",
"axios": "^0.24.0",
"babel-eslint": "^10.1.0",
"builtin-modules": "^3.2.0",
"chance": "^1.1.8",
"commander": "^9.1.0",
"css-loader": "^4.3.0",
"cssnano": "^4.1.11",
"csso-webpack-plugin": "^2.0.0-beta.3",
"debug": "^4.3.3",
"enhanced-resolve": "^5.9.1",
"escape-string-regexp": "^2.0.0",
"fast-safe-stringify": "^2.1.1",
"file-loader": "^6.2.0",
"is-valid-npm-name": "^0.0.5",
"less": "^4.1.2",
"less-loader": "^8.1.1",
"lodash": "^4.17.21",
"memfs": "^3.4.1",
"memoizee": "^0.4.15",
"memory-fs": "^0.5.0",
"mini-css-extract-plugin": "^1.6.2",
"mitt": "^2.1.0",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.7",
"node-sass": "^6.0.1",
"np": "^7.6.0",
"optimize-css-assets-webpack-plugin": "^5.0.8",
"parcel": "^2.4.1",
"performance-now": "^2.1.0",
"pify": "^5.0.0",
"postcss-loader": "^3.0.0",
"rimraf": "^3.0.2",
"sanitize-filename": "^1.6.3",
"sass-loader": "^8.0.2",
"server": "^1.0.37",
"shortid": "^2.2.16",
"source-map-explorer": "^2.5.2",
"stats-lite": "^2.2.0",
"string-replace-loader": "^3.1.0",
"svelte": "^3.46.3",
"svelte-loader": "^3.1.2",
"terser": "^5.10.0",
"terser-webpack-plugin": "^5.3.0",
"vm2": "^3.9.5",
"vue-loader": "^15.9.8",
"vue-template-compiler": "^2.6.14",
"webpack": "^5.67.0",
"webpack-bundle-analyzer": "^4.5.0",
"write-file-webpack-plugin": "^4.5.1"
"ts-jest": "^27.1.4",
"vm2": "^3.9.5"
},
"packageManager": "yarn@3.2.0"
}
17 changes: 17 additions & 0 deletions packages/package-build-stats-cli/bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

require('ts-node').register({project})

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
3 changes: 3 additions & 0 deletions packages/package-build-stats-cli/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
5 changes: 5 additions & 0 deletions packages/package-build-stats-cli/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
3 changes: 3 additions & 0 deletions packages/package-build-stats-cli/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
66 changes: 66 additions & 0 deletions packages/package-build-stats-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "package-build-stats-cli",
"version": "0.0.1",
"description": "Calculate the package size of an npm library",
"author": "Shubham Kanodia @pastelsky",
"bin": "./bin/run",
"homepage": "https://github.com/pastelsky/package-build-stats",
"license": "MIT",
"main": "dist/index.js",
"repository": "https://github.com/pastelsky/package-build-stats",
"files": [
"/bin",
"/dist",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
"dependencies": {
"@oclif/core": "^1",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^2.0.1",
"purdy": "^3.5.1"
},
"devDependencies": {
"@oclif/test": "^2",
"@types/chai": "^4",
"@types/mocha": "^9.0.0",
"@types/node": "^16.9.4",
"@types/purdy": "^3",
"oclif": "^2",
"shx": "^0.3.3",
"ts-node": "^10.2.1",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
},
"oclif": {
"bin": "npmsize ",
"dirname": "npmsize ",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help"
],
"topicSeparator": " ",
"topics": {
"hello": {
"description": "Say hello to the world and others"
}
}
},
"scripts": {
"build": "shx rm -rf dist && tsc -b",
"lint": "eslint . --ext .ts --config .eslintrc",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md"
},
"engines": {
"node": ">=12.0.0"
},
"bugs": "https://github.com/pastelsky/package-build-stats/issues",
"keywords": [
"oclif"
],
"types": "dist/index.d.ts"
}
66 changes: 66 additions & 0 deletions packages/package-build-stats-cli/src/commands/export-sizes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Command, Flags } from '@oclif/core'
import { getPackageExportSizes } from 'package-build-stats'
import Purdy from 'purdy'

export default class ExportSizes extends Command {
static description = 'Get export sizes of a package'

static examples = [`$ npmsize export-sizes package-name`]

static args = [
{
name: 'package',
description: 'Name / Version of the NPM package',
required: true,
},
]

static flags = {
client: Flags.string({
char: 'p',
description: 'Which npm package manager to use',
required: false,
options: ['npm', 'yarn', 'pnpm'],
}),
customImports: Flags.string({
char: 'i',
description: 'Comma separated custom imports',
required: false,
}),
debug: Flags.boolean({
char: 'd',
description: 'Debug builds',
required: false,
}),
limitConcurrency: Flags.boolean({
char: 'c',
description: 'Limit concurrency',
required: false,
}),
networkConcurrency: Flags.integer({
char: 'n',
description: 'Network concurrency',
required: false,
}),
installTimeout: Flags.integer({
char: 't',
description: 'Install timeout in ms',
required: false,
}),
}

async run(): Promise<void> {
const { args, flags } = await this.parse(ExportSizes)
const result = await getPackageExportSizes(args.package, {
// @ts-ignore - convert string to enum
client: flags.client,
limitConcurrency: flags.limitConcurrency,
networkConcurrency: flags.networkConcurrency,
debug: flags.debug,
customImports: flags.customImports?.split(','),
installTimeout: flags.installTimeout,
})

Purdy(result, {})
}
}
60 changes: 60 additions & 0 deletions packages/package-build-stats-cli/src/commands/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Command, Flags } from '@oclif/core'
import { getAllPackageExports } from 'package-build-stats'
import Purdy from 'purdy'

export default class Total extends Command {
static description = 'Total bundled size of an NPM package'

static examples = [`$ npmsize exports package-name`]

static args = [
{
name: 'package',
description: 'Name / Version of the NPM package',
required: true,
},
]

static flags = {
client: Flags.string({
char: 'p',
description: 'Which npm package manager to use',
required: false,
options: ['npm', 'yarn', 'pnpm'],
}),
limitConcurrency: Flags.boolean({
char: 'c',
description: 'Limit concurrency',
required: false,
}),
networkConcurrency: Flags.integer({
char: 'n',
description: 'Network concurrency',
required: false,
}),
local: Flags.boolean({
char: 'l',
description: 'Get exports of a local package',
required: false,
}),
installTimeout: Flags.integer({
char: 't',
description: 'Install timeout in ms',
required: false,
}),
}

async run(): Promise<void> {
const { args, flags } = await this.parse(Total)
const result = await getAllPackageExports(args.package, {
// @ts-ignore - convert string to enum
client: flags.client,
limitConcurrency: flags.limitConcurrency,
networkConcurrency: flags.networkConcurrency,
isLocal: flags.local,
installTimeout: flags.installTimeout,
})

Purdy(result, {})
}
}
Loading

0 comments on commit 0a6b1db

Please sign in to comment.