Skip to content

Commit c5d36ce

Browse files
authored
chore: upgrade build infrastructure (#171)
1 parent c44c0cb commit c5d36ce

File tree

11 files changed

+1862
-3021
lines changed

11 files changed

+1862
-3021
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ com_crashlytics_export_strings.xml
114114
crashlytics.properties
115115
crashlytics-build.properties
116116
fabric.properties
117+
test/e2e/dist/

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
22
preset: 'ts-jest',
3+
testEnvironment: 'jsdom'
34
};

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"clean": "rimraf dist",
55
"lint": "yarn eslint 'src/**/*.{ts,tsx}'",
66
"start": "cross-env NODE_ENV=development webpack --watch",
7-
"e2e-build": "tsc --project tsconfig.e2e.json && yarn run e2e-copy",
7+
"e2e-build": "mkdir -p ./test/e2e/dist/ && cp ./dist/leanplum.js ./test/e2e/dist/leanplum.js && tsc --project tsconfig.e2e.json && yarn run e2e-copy",
88
"e2e-copy": "cp ./test/e2e/*.html ./dist/e2e/ && cp ./dist/*.js ./dist/e2e/ && cp ./dist/sw/*.js ./dist/e2e/",
99
"e2e-deploy": "yarn run e2e-build && now deploy dist/e2e --confirm --local-config vercel.json",
1010
"e2e-serve": "yarn run e2e-build && http-server dist/e2e -p 8989 -a localhost",
@@ -19,7 +19,7 @@
1919
"@types/jest": "^25.2.1",
2020
"@types/jquery": "^3.3.38",
2121
"@types/node": "^13.13.4",
22-
"@types/webpack": "^4.41.12",
22+
"@types/webpack": "^5",
2323
"@typescript-eslint/eslint-plugin": "^2.29.0",
2424
"@typescript-eslint/parser": "^2.29.0",
2525
"chai": "^3.5.0",
@@ -29,21 +29,21 @@
2929
"eslint-loader": "^4.0.0",
3030
"fork-ts-checker-webpack-plugin": "^4.1.3",
3131
"http-server": "^0.12.1",
32-
"jest": "^25.4.0",
33-
"jsdom": "^9.12.0",
32+
"jest": "^29",
33+
"jest-environment-jsdom": "^29.3.1",
34+
"jsdom": "^20.0.3",
3435
"lodash.isequal": "^4.5.0",
3536
"lodash.merge": "^4.6.2",
3637
"mock-local-storage": "^1.0.2",
3738
"rimraf": "^3.0.2",
3839
"semantic-release": "^19.0.2",
3940
"sinon": "^2.1.0",
40-
"ts-jest": "^25.4.0",
41-
"ts-loader": "^7.0.1",
42-
"ts-node": "^8.9.1",
43-
"typescript": "^3.8.3",
44-
"uglifyjs-webpack-plugin": "^2.2.0",
45-
"webpack": "^4.43.0",
46-
"webpack-cli": "^3.3.11"
41+
"ts-jest": "^29",
42+
"ts-loader": "^9",
43+
"ts-node": "^10",
44+
"typescript": "^4",
45+
"webpack": "^5",
46+
"webpack-cli": "^5"
4747
},
4848
"name": "leanplum-sdk",
4949
"description": "The JavaScript SDK for Leanplum allows developers to integrate the Leanplum platform with applications that use JavaScript and HTML5. Leanplum is an customer engagement platform that provides mobile A/B testing, messaging, and personalization features for websites and web applications.",

src/Messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export default class Messages {
372372
if ('srcdoc' in iframe) {
373373
iframe.srcdoc = content
374374
} else {
375-
const doc = iframe.contentWindow.document
375+
const doc = (iframe as HTMLIFrameElement).contentWindow.document
376376
doc.open()
377377
doc.write(content)
378378
doc.close()

test/e2e/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
declare const Leanplum: typeof import('../../dist/leanplum').default
2-
import { RenderOptions } from '../../dist/leanplum'
1+
import Leanplum from './dist/leanplum'
32

43
const isProdKey = (accessKey: string): boolean => /^prod_/.test(accessKey)
54

@@ -257,7 +256,7 @@ function renderAppInbox(): void {
257256

258257
// register handler for in-app messages
259258
Leanplum.enableRichInAppMessages(true)
260-
Leanplum.on('showMessage', (args: RenderOptions) => {
259+
Leanplum.on('showMessage', (args) => {
261260
const { message, context } = args
262261
let title, body
263262
const buttons = []

test/specs/Leanplum.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Object.keys(testModes).forEach((mode) => {
316316
})
317317

318318
describe('Test variable changed callback after forceContentUpdate.', () => {
319-
it('test setVariable forceContentUpdate', async (done) => {
319+
it('test setVariable forceContentUpdate', (done) => {
320320
interceptRequest((request) => {
321321
const methodName = getAction(request)
322322
if (methodName == 'getVars'){

test/specs/LeanplumIntegration.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('Integration Tests', () => {
9494
})
9595
})
9696

97-
it('pushes notification token when registering with LP', async (done) => {
97+
it('pushes notification token when registering with LP', (done) => {
9898
mockNextResponse(migrationResponses.DUPLICATE)
9999
mockNextResponse(startResponse)
100100

@@ -106,7 +106,6 @@ describe('Integration Tests', () => {
106106

107107
done()
108108
})
109-
110109
})
111110

112111
it('pushes previously registered notification token', (done) => {

test/specs/Messages.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe(Messages, () => {
1212
let getFileUrl: jest.Mock
1313

1414
beforeEach(() => {
15-
localStorage.clear()
15+
window.localStorage.clear()
1616
Network.prototype.ajax = jest.fn()
1717
events = new EventEmitter()
1818
createRequest = jest.fn().mockImplementation((_, __, options) => options?.response())
@@ -1194,7 +1194,7 @@ describe(Messages, () => {
11941194

11951195
events.emit('track', { eventName: 'Add to cart' })
11961196

1197-
await (new Promise(resolve => setImmediate(resolve)));
1197+
await (new Promise(resolve => setTimeout(resolve, 0)));
11981198
const messageVars = JSON.stringify({ messageId: "12345", ...vars })
11991199
expect(iframe.srcdoc).toEqual(
12001200
`<body><script>window.messageId='12345'</script>${messageVars}</body>`

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"allowJs": true,
44
"allowSyntheticDefaultImports": true,
5+
"declaration": true,
56
"esModuleInterop": true,
67
"lib": [
78
"dom",

webpack.config.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
44
import fs from 'fs'
55
import merge from 'lodash.merge'
66
import path from 'path'
7-
import UglifyJS from 'uglifyjs-webpack-plugin'
7+
import TerserPlugin from 'terser-webpack-plugin';
88
import webpack from 'webpack'
99

1010
let configuration = null
@@ -16,8 +16,9 @@ class DtsBundlePlugin {
1616

1717
apply(compiler: webpack.Compiler): void {
1818
compiler.hooks.done.tap('DtsBundlePlugin', (stats) => {
19+
return;
1920
// Do not bundle TypeScript declaration files if there are errors.
20-
if (stats.compilation.errors?.length) {
21+
if (stats.hasErrors()) {
2122
return
2223
}
2324

@@ -59,24 +60,19 @@ class DtsBundlePlugin {
5960
}
6061
}
6162

62-
const optimization: webpack.Options.Optimization = {
63+
const optimization = {
6364
minimize: true,
6465
minimizer: [
65-
new UglifyJS({
66-
cache: true,
66+
new TerserPlugin({
6767
parallel: true,
68-
uglifyOptions: {
68+
terserOptions: {
69+
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
6970
ecma: 5,
7071
mangle: true,
71-
output: {
72-
beautify: false,
73-
comments: false,
74-
},
75-
warnings: false,
7672
},
7773
}),
7874
],
79-
noEmitOnErrors: true,
75+
emitOnErrors: false,
8076
sideEffects: true,
8177
usedExports: true,
8278
}

0 commit comments

Comments
 (0)