Skip to content

Commit

Permalink
Fix broken UTC plugin due to rollup (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloisklink committed May 26, 2021
1 parent 52e2e59 commit 0914706
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
22 changes: 13 additions & 9 deletions build/index.js
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
@@ -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
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
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
@@ -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

0 comments on commit 0914706

Please sign in to comment.