Skip to content

Commit 0914706

Browse files
authored
Fix broken UTC plugin due to rollup (iamkun#1453)
1 parent 52e2e59 commit 0914706

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

build/index.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,27 @@ async function listLocaleJson(localeArr) {
3535

3636
(async () => {
3737
try {
38+
/* eslint-disable no-restricted-syntax, no-await-in-loop */
39+
// We use await-in-loop to make rollup run sequentially to save on RAM
3840
const locales = await promisifyReadDir(localePath)
39-
locales.forEach((l) => {
40-
build(configFactory({
41+
for (const l of locales) {
42+
// run builds sequentially to limit RAM usage
43+
await build(configFactory({
4144
input: `./src/locale/${l}`,
4245
fileName: `./locale/${l}`,
4346
name: `dayjs_locale_${formatName(l)}`
4447
}))
45-
})
48+
}
4649

4750
const plugins = await promisifyReadDir(path.join(__dirname, '../src/plugin'))
48-
plugins.forEach((l) => {
49-
build(configFactory({
50-
input: `./src/plugin/${l}/index`,
51-
fileName: `./plugin/${l}.js`,
52-
name: `dayjs_plugin_${formatName(l)}`
51+
for (const plugin of plugins) {
52+
// run builds sequentially to limit RAM usage
53+
await build(configFactory({
54+
input: `./src/plugin/${plugin}/index`,
55+
fileName: `./plugin/${plugin}.js`,
56+
name: `dayjs_plugin_${formatName(plugin)}`
5357
}))
54-
})
58+
}
5559

5660
build(configFactory({
5761
input: './src/index.js',

build/rollup.config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const babel = require('rollup-plugin-babel')
2-
const uglify = require('rollup-plugin-uglify')
2+
const { terser } = require('rollup-plugin-terser')
33

44
module.exports = (config) => {
55
const { input, fileName, name } = config
@@ -13,7 +13,7 @@ module.exports = (config) => {
1313
babel({
1414
exclude: 'node_modules/**'
1515
}),
16-
uglify()
16+
terser()
1717
]
1818
},
1919
output: {
@@ -22,7 +22,8 @@ module.exports = (config) => {
2222
name: name || 'dayjs',
2323
globals: {
2424
dayjs: 'dayjs'
25-
}
25+
},
26+
compact: true
2627
}
2728
}
2829
}

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@
9090
"ncp": "^2.0.0",
9191
"pre-commit": "^1.2.2",
9292
"prettier": "^1.16.1",
93-
"rollup": "^0.57.1",
94-
"rollup-plugin-babel": "^4.0.0-beta.4",
95-
"rollup-plugin-uglify": "^3.0.0",
93+
"rollup": "^2.45.1",
94+
"rollup-plugin-babel": "^4.4.0",
95+
"rollup-plugin-terser": "^7.0.2",
9696
"size-limit": "^0.18.0",
9797
"typescript": "^2.8.3"
98-
},
99-
"dependencies": {}
98+
}
10099
}

src/constant.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ export const INVALID_DATE_STRING = 'Invalid Date'
2828
// regex
2929
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
3030
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
31+
32+
// used by plugins/utc
33+
export const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g
34+
export const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g

src/plugin/utc/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { MILLISECONDS_A_MINUTE, MIN } from '../../constant'
2-
3-
export const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g
4-
export const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g
1+
import { MILLISECONDS_A_MINUTE, MIN, REGEX_VALID_OFFSET_FORMAT, REGEX_OFFSET_HOURS_MINUTES_FORMAT } from '../../constant'
52

63
function offsetFromString(value = '') {
74
const offset = value.match(REGEX_VALID_OFFSET_FORMAT)

0 commit comments

Comments
 (0)