Skip to content

Commit 620c270

Browse files
authored
Fix UMD packaging. (#52)
1 parent 7ab2de6 commit 620c270

5 files changed

Lines changed: 127 additions & 37 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
_Updates limited to IANA tzdb updates omitted._
22

3+
### 3.10.3
4+
5+
* Fix UMD packaging.
6+
37
### 3.10.2
48

59
* Fixed a very edge-case bug where `getSecondsInDay()` and `getMinutesInDay()` might return 0 for the very last Julian calendar date before a transition to the Gregorian calendar.

package-lock.json

Lines changed: 52 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tubular/time",
3-
"version": "3.10.2",
3+
"version": "3.10.3",
44
"description": "Date/time, IANA timezones, leap seconds, TAI/UTC conversions, calendar with settable Julian/Gregorian switchover",
55
"module": "dist/index.min.mjs",
66
"main": "dist/index.min.cjs",
@@ -63,6 +63,7 @@
6363
"json-z": "^6.0.0"
6464
},
6565
"devDependencies": {
66+
"@rollup/plugin-node-resolve": "^16.0.1",
6667
"@rollup/plugin-terser": "^0.4.4",
6768
"@rollup/plugin-typescript": "^12.1.2",
6869
"@stylistic/eslint-plugin": "^4.4.1",

rollup.config.js

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
1+
const nodeResolve = require('@rollup/plugin-node-resolve');
12
const sourcemaps = require('rollup-plugin-sourcemaps');
23
const terser = require('@rollup/plugin-terser');
34
const typescript = require('@rollup/plugin-typescript');
45
const pkg = require('./package.json');
56

6-
// noinspection JSUnusedGlobalSymbols
7-
module.exports = [{
8-
external: ['by-request', 'json-z', '@tubular/math', '@tubular/util'],
9-
input: 'src/index.ts',
10-
output: [
11-
{
7+
function trimUmd() {
8+
// noinspection JSUnusedGlobalSymbols
9+
return {
10+
name: 'mixExports',
11+
renderChunk(code, _chunk, options) {
12+
if (options.format === 'umd') {
13+
// Strip out dynamic import() so it doesn't generate warnings.
14+
code = code.replace(/return import\(.*?\/\* webpackIgnore: true \*\/.*?tseuqer-yb.*?\.join\(''\)\)/s, 'return null');
15+
// Strip out large and large-alt timezone definitions from UMD build.
16+
code = code.replace(/(?<!timezoneSmall = )\/\* trim-file-start \*\/.*?\/\* trim-file-end \*\//sg, 'null');
17+
}
18+
19+
return { code, map: null };
20+
}
21+
};
22+
}
23+
24+
const plugins = [
25+
nodeResolve(),
26+
typescript({ inlineSources: true }),
27+
trimUmd(),
28+
sourcemaps(),
29+
terser({
30+
output: {
31+
comments: (node, comment) => {
32+
return comment.type === 'comment2' && /\b(webpackIgnore|vite-ignore)\b/.test(comment.value);
33+
},
34+
max_line_len: 511
35+
},
36+
sourceMap: { includeSources: true }
37+
})
38+
];
39+
40+
const onwarn = (code, defaultHandler) => {
41+
if (code.code !== 'MIXED_EXPORTS')
42+
defaultHandler(code);
43+
};
44+
45+
// noinspection JSUnusedGlobalSymbols,CommaExpressionJS
46+
module.exports = [
47+
{
48+
input: 'src/index.ts',
49+
output: {
1250
file: pkg.browser,
1351
sourcemap: true,
1452
format: 'umd',
@@ -20,32 +58,25 @@ module.exports = [{
2058
'by-request': '_by_request_' // Never used, only specified to suppress warning
2159
}
2260
},
23-
{
24-
file: pkg.main,
25-
sourcemap: true,
26-
format: 'cjs'
27-
},
28-
{
29-
file: pkg.module,
30-
sourcemap: true,
31-
format: 'esm'
32-
}
33-
],
34-
plugins: [
35-
typescript({ inlineSources: true }),
36-
sourcemaps(),
37-
terser({
38-
output: {
39-
comments: (node, comment) => {
40-
return comment.type === 'comment2' && /\b(webpackIgnore|vite-ignore)\b/.test(comment.value);
41-
},
42-
max_line_len: 511
61+
plugins,
62+
onwarn
63+
},
64+
{
65+
external: ['by-request', 'json-z', '@tubular/math', '@tubular/util'],
66+
input: 'src/index.ts',
67+
output: [
68+
{
69+
file: pkg.main,
70+
sourcemap: true,
71+
format: 'cjs'
4372
},
44-
sourceMap: { includeSources: true }
45-
})
46-
],
47-
onwarn(code, defaultHandler) {
48-
if (code.code !== 'MIXED_EXPORTS')
49-
defaultHandler(code);
73+
{
74+
file: pkg.module,
75+
sourcemap: true,
76+
format: 'esm'
77+
}
78+
],
79+
plugins: (plugins.slice(0).splice(0, 1).splice(2, 1), plugins),
80+
onwarn
5081
}
51-
}];
82+
];

test.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Browser Check</title>
6-
<script src="dist/umd/index.js"></script>
6+
<script src="dist/index.min.js"></script>
77
</head>
88
<body>
99
<script>
@@ -31,6 +31,10 @@
3131

3232
document.write('<br><br>\n');
3333
}
34+
35+
const zones = tbTime.Timezone.getAvailableTimezones().join('<br>\n');
36+
37+
document.write(zones + '<br><br>\n');
3438
</script>
3539
</body>
3640
</html>

0 commit comments

Comments
 (0)