Skip to content

Commit

Permalink
feat: migrate to esm (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 5, 2021
1 parent 43cf87e commit 7ee5c73
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 196 deletions.
48 changes: 12 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,22 @@ name: ci
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
test-ci:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [12]
ci:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-node@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- name: checkout
uses: actions/checkout@v2

- name: cache node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}

- name: install
if: steps.cache.outputs.cache-hit != 'true'
run: yarn --check-files --frozen-lockfile --non-interactive

- name: lint
run: yarn lint

- name: build
run: yarn build

- name: test
run: yarn jest

- name: coverage
uses: codecov/codecov-action@v1
node-version: '14'
cache: yarn
- run: yarn install
- run: yarn lint
- run: yarn prepack
- run: yarn jest
12 changes: 12 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
declaration: true,
emitCJS: false,
entries: [
'src/index'
],
externals: [
'webpack'
]
})
2 changes: 1 addition & 1 deletion demo/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const WebpackBar = require('jiti')(__dirname)('../src/webpackbar')
const WebpackBar = require('../index.cjs')

// let lastProgress;

Expand Down
1 change: 1 addition & 0 deletions index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('jiti')(__dirname)('./src/index').default
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
"description": "Elegant ProgressBar and Profiler for Webpack",
"repository": "unjs/webpackbar",
"license": "MIT",
"main": "dist/webpackbar.js",
"types": "dist/webpackbar.d.ts",
"main": "./dist/index.mjs",
"exports": {
"import": "./dist/index.mjs"
},
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"prebuild": "yarn clean",
"build": "siroc build",
"clean": "rimraf dist",
"demo": "webpack-cli --config demo/webpack.config.js",
"dev": "webpack-cli --config demo/webpack.config.js",
"lint": "eslint --ext .ts src test",
"release": "yarn build && yarn test && standard-version && npm publish && git push --follow-tags",
"start": "yarn build -- -w",
"test": "yarn lint && yarn build && jest"
"prepack": "unbuild",
"release": "yarn test && standard-version && npm publish && git push --follow-tags",
"test": "yarn lint && jest"
},
"dependencies": {
"ansi-escapes": "^4.3.1",
"ansi-escapes": "^5.0.0",
"chalk": "^4.1.0",
"consola": "^2.15.3",
"figures": "^3.2.0",
"markdown-table": "^2.0.0",
"figures": "^4.0.0",
"markdown-table": "^3.0.1",
"pretty-time": "^1.1.0",
"std-env": "^3.0.0",
"wrap-ansi": "^7.0.0"
"wrap-ansi": "^8.0.1"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
Expand All @@ -38,18 +38,17 @@
"jest": "latest",
"jiti": "latest",
"memory-fs": "latest",
"rimraf": "latest",
"siroc": "latest",
"standard-version": "latest",
"ts-jest": "latest",
"typescript": "latest",
"unbuild": "latest",
"webpack": "latest",
"webpack-cli": "latest"
},
"peerDependencies": {
"webpack": "3 || 4 || 5"
},
"engines": {
"node": ">=10"
"node": ">=14"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Stats } from 'webpack'
import WebpackBar from './webpackbar'
import WebpackBar from '.'

type ReporterContextFunc<T = any> = (context: WebpackBar, opts: T) => void

Expand Down
2 changes: 1 addition & 1 deletion src/utils/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk'
import _consola from 'consola'
import markdownTable from 'markdown-table'
import { markdownTable } from 'markdown-table'

import { BLOCK_CHAR, BLOCK_CHAR2, BAR_LENGTH } from './consts'

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/basic/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import type { Configuration } from 'webpack'
import WebpackBar from '../../../src/webpackbar'

const WebpackBar = require('../../../index.cjs')

export function getConfig (options: any) {
return {
Expand Down
Loading

0 comments on commit 7ee5c73

Please sign in to comment.