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

ESM Support #2066

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
51 changes: 18 additions & 33 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "airbnb-base",
"plugins": [
"jest"
],
"extends": ["@sxzz/eslint-config-ts", "@sxzz/eslint-config-prettier"],
"plugins": ["jest"],
"env": {
"jest/globals": true
},
Expand All @@ -11,34 +9,21 @@
"dayjs": true
},
"rules": {
"semi": [
2,
"never"
],
"comma-dangle": [
"error",
"never"
],
"no-param-reassign": [
0
],
"func-names": [
0
],
"import/no-extraneous-dependencies": [
0
],
"import/no-unresolved": [
2,
{
"ignore": [
"dayjs"
]
"unicorn/better-regex": "off",
"eslint-comments/no-unlimited-disable": "off",
"@typescript-eslint/triple-slash-reference": "off",
"unicorn/prefer-node-protocol": "off"
},
"overrides": [
{
"files": ["src/**"],
"rules": {
"unicorn/prefer-includes": "off",
"unicorn/no-for-loop": "off",
"unicorn/prefer-number-properties": "off",
"unicorn/no-instanceof-array": "off",
"unicorn/explicit-length-check": "off"
}
],
"import/extensions": [
2,
"never"
]
}
}
]
}
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/--bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
Expand All @@ -14,7 +13,8 @@ A clear and concise description of what the bug is.
A clear and concise description of what you expected to happen.

**Information**
- Day.js Version [e.g. v1.0.0]
- OS: [e.g. iOS]
- Browser [e.g. chrome 62]
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]

- Day.js Version [e.g. v1.0.0]
- OS: [e.g. iOS]
- Browser [e.g. chrome 62]
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]
40 changes: 25 additions & 15 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
name: Lint & Unit Test
on:
push:
branches: [ master, dev ]
branches: [master, dev]
pull_request:
branches: [dev]
jobs:
check:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node: [ 12, 14, 16, 18 ]
node: [14.19, 16, 18]

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm install -g codecov && npm install
- name: Run Lint
run: npm run lint
- name: Run tests
run: npm test && codecov
- name: Checkout
uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
name: Install pnpm

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install dependencies
run: pnpm install -g codecov && pnpm install

- name: Run Lint
run: pnpm run lint

- name: Run tests
run: pnpm test && codecov
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ yarn.lock
coverage

# build
/locale
/plugin
/dayjs.min.js
/esm
/index.d.ts
locale.json
dist

#dev
demo.js
.eslintcache
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist = true
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
pnpm-lock.yaml
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ script:
- codecov
after_success:
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
npx travis-deploy-once --pro && npm run build && npm run babel && npm install -g @semantic-release/changelog @semantic-release/git semantic-release && semantic-release && echo release success && curl ${TriggerUrl} && npm run test:sauce;
npx travis-deploy-once --pro && npm run build && npm run babel && npm install -g @semantic-release/changelog @semantic-release/git semantic-release && semantic-release && echo release success && curl ${TriggerUrl} && npm run test:sauce;
fi
branches:
only:
only:
- master
786 changes: 357 additions & 429 deletions CHANGELOG.md

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Our open source community strives to be nice, welcoming and professional. Instan

## Style

* Day.js is written in ES6.
* We use ESLint to check our code. You can use `npm run lint` before submitting a pull request.
* Please use semantic commit message.
- Day.js is written in ES6.
- We use ESLint to check our code. You can use `npm run lint` before submitting a pull request.
- Please use semantic commit message.

## Bugs

* Before submitting a bug report, search the issues for similar tickets. Your issue may have already been discussed and resolved.
* Feel free to add a comment to an existing issue, even if it's closed.
* Be thorough in your title and report, don't leave out important details.
* English, please.
- Before submitting a bug report, search the issues for similar tickets. Your issue may have already been discussed and resolved.
- Feel free to add a comment to an existing issue, even if it's closed.
- Be thorough in your title and report, don't leave out important details.
- English, please.

## Tests

* Feel free to create a new `test/*.test.js` file if none of the existing test files suits your test case.
* Help us keeping 100% test coverage :D.
* You can use `npm run test` before submitting a pull request.
- Feel free to create a new `test/*.test.js` file if none of the existing test files suits your test case.
- Help us keeping 100% test coverage :D.
- You can use `npm run test` before submitting a pull request.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/R
alt="Day.js"></a></p>
<p align="center">Fast <b>2kB</b> alternative to Moment.js with the same modern API</p>
<p align="center">
<a href="https://unpkg.com/dayjs/dayjs.min.js"><img
src="https://img.badgesize.io/https://unpkg.com/dayjs/dayjs.min.js?compression=gzip&style=flat-square"
<a href="https://unpkg.com/dayjs"><img
src="https://img.badgesize.io/dayjs?compression=gzip&style=flat-square"
alt="Gzip Size"></a>
<a href="https://www.npmjs.com/package/dayjs"><img src="https://img.shields.io/npm/v/dayjs.svg?style=flat-square&colorB=51C838"
alt="NPM Version"></a>
Expand All @@ -25,15 +25,19 @@ English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/R
> Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.

```js
dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
dayjs()
.startOf('month')
.add(1, 'day')
.set('year', 2018)
.format('YYYY-MM-DD HH:mm:ss')
```

* 🕒 Familiar Moment.js API & patterns
* 💪 Immutable
* 🔥 Chainable
* 🌐 I18n support
* 📦 2kb mini library
* 👫 All browsers supported
- 🕒 Familiar Moment.js API & patterns
- 💪 Immutable
- 🔥 Chainable
- 🌐 I18n support
- 📦 2kb mini library
- 👫 All browsers supported

---

Expand Down Expand Up @@ -82,6 +86,7 @@ dayjs.locale('es') // use Spanish locale globally

dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in a specific instance
```

📚[Internationalization](https://day.js.org/docs/en/i18n/i18n)

### Plugin
Expand All @@ -100,7 +105,7 @@ dayjs().format('Q Do k kk X x') // more available formats

## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

[[Become a sponsor via Github](https://github.com/sponsors/iamkun/)] [[Become a sponsor via OpenCollective](https://opencollective.com/dayjs#sponsor)]

Expand Down
16 changes: 7 additions & 9 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module.exports = {
env: {
test: {
presets: [
'@babel/preset-env'
]
presets: ['@babel/preset-env'],
},
build: {
presets: [
[
'@babel/preset-env',
{
modules: false,
loose: true
}
]
]
}
}
loose: true,
},
],
],
},
},
}
44 changes: 0 additions & 44 deletions build/esm.js

This file was deleted.

46 changes: 46 additions & 0 deletions build/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { resolve } from 'path'
import { fileURLToPath } from 'url'
import { rollup } from 'rollup'
import fg from 'fast-glob'
import Alias from '@rollup/plugin-alias'
import NodeResolve from '@rollup/plugin-node-resolve'

const pathRoot = resolve(fileURLToPath(import.meta.url), '../..')
const pathSrc = resolve(pathRoot, 'src')
;(async () => {
const entries = await fg(['index.js', 'locale/*.js', 'plugin/*/*.js'], {
cwd: pathSrc,
absolute: true,
})
const bundle = await rollup({
input: entries,
plugins: [
Alias({
entries: {
dayjs: resolve(pathSrc, 'index.js'),
},
}),
NodeResolve(),
],
})
await bundle.write({
dir: resolve(pathRoot, 'dist'),
entryFileNames(chunk) {
if (chunk.facadeModuleId) {
const pluginMatches = chunk.facadeModuleId.match(
/src\/plugin\/(.+?)\/index\.js/
)
if (pluginMatches && pluginMatches[1]) {
return `plugin/${pluginMatches[1]}.mjs`
}

if (/src\/locale\/(.+?)\.js/.test(chunk.facadeModuleId)) {
return 'locale/[name].mjs'
}
}

return '[name].mjs'
},
chunkFileNames: '[name].mjs',
})
})()
Loading