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

Fix broken UTC plugin due to rollup #1453

Merged
merged 3 commits into from
May 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,27 @@ async function listLocaleJson(localeArr) {

(async () => {
try {
/* eslint-disable no-restricted-syntax, no-await-in-loop */
// We use await-in-loop to make rollup run sequentially to save on RAM
const locales = await promisifyReadDir(localePath)
locales.forEach((l) => {
build(configFactory({
for (const l of locales) {
// run builds sequentially to limit RAM usage
await build(configFactory({
input: `./src/locale/${l}`,
fileName: `./locale/${l}`,
name: `dayjs_locale_${formatName(l)}`
}))
})
}

const plugins = await promisifyReadDir(path.join(__dirname, '../src/plugin'))
plugins.forEach((l) => {
build(configFactory({
input: `./src/plugin/${l}/index`,
fileName: `./plugin/${l}.js`,
name: `dayjs_plugin_${formatName(l)}`
for (const plugin of plugins) {
// run builds sequentially to limit RAM usage
await build(configFactory({
input: `./src/plugin/${plugin}/index`,
fileName: `./plugin/${plugin}.js`,
name: `dayjs_plugin_${formatName(plugin)}`
}))
})
}

build(configFactory({
input: './src/index.js',
Expand Down
7 changes: 4 additions & 3 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const babel = require('rollup-plugin-babel')
const uglify = require('rollup-plugin-uglify')
const { terser } = require('rollup-plugin-terser')

module.exports = (config) => {
const { input, fileName, name } = config
Expand All @@ -13,7 +13,7 @@ module.exports = (config) => {
babel({
exclude: 'node_modules/**'
}),
uglify()
terser()
]
},
output: {
Expand All @@ -22,7 +22,8 @@ module.exports = (config) => {
name: name || 'dayjs',
globals: {
dayjs: 'dayjs'
}
},
compact: true
}
}
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@
"ncp": "^2.0.0",
"pre-commit": "^1.2.2",
"prettier": "^1.16.1",
"rollup": "^0.57.1",
"rollup-plugin-babel": "^4.0.0-beta.4",
"rollup-plugin-uglify": "^3.0.0",
"rollup": "^2.45.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^7.0.2",
"size-limit": "^0.18.0",
"typescript": "^2.8.3"
},
"dependencies": {}
}
}
4 changes: 4 additions & 0 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ export const INVALID_DATE_STRING = 'Invalid Date'
// regex
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g

// used by plugins/utc
export const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g
export const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g
5 changes: 1 addition & 4 deletions src/plugin/utc/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { MILLISECONDS_A_MINUTE, MIN } from '../../constant'

export const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g
export const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g
import { MILLISECONDS_A_MINUTE, MIN, REGEX_VALID_OFFSET_FORMAT, REGEX_OFFSET_HOURS_MINUTES_FORMAT } from '../../constant'

function offsetFromString(value = '') {
const offset = value.match(REGEX_VALID_OFFSET_FORMAT)
Expand Down