Skip to content

Commit

Permalink
Change build scripts (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Nov 4, 2020
1 parent 83ef058 commit 4318354
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "Repair broken JSON documents",
"type": "module",
"main": "lib/cjs/index-commonjs.js",
"main": "lib/umd/jsonRepair.js",
"module": "lib/esm/json-repair.js",
"types": "lib/esm/json-repair.d.ts",
"keywords": [
Expand All @@ -13,7 +13,12 @@
"scripts": {
"test": "mocha",
"test:lib": "mocha test-lib/*.test.*",
"build": "del-cli lib && tsc -p tsconfig.json && tsc -p tsconfig-esm.json && cp-cli tools/cjs lib/cjs",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"clean": "del-cli lib",
"build:esm": "tsc --module es2015 --target es5 --outDir lib/esm",
"build:cjs": "tsc --module commonjs --target es5 --outDir lib/cjs && cp-cli tools/cjs lib/cjs",
"build:umd": "rollup lib/esm/json-repair.js --format umd --name 'jsonRepair' --sourcemap --output.file lib/umd/jsonRepair.js",
"build:umd:min": "uglifyjs --compress --mangle --source-map --comments --output lib/umd/jsonRepair.min.js -- lib/umd/jsonRepair.js",
"link": "npm run build",
"lint": "eslint src/**/*.ts",
"prepublishOnly": "npm run build && npm run test:lib && npm run lint"
Expand All @@ -37,8 +42,10 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"mocha": "8.2.0",
"rollup": "2.33.1",
"ts-node": "9.0.0",
"tslib": "2.0.3",
"typescript": "4.0.5"
"typescript": "4.0.5",
"uglify-js": "3.11.5"
}
}
2 changes: 1 addition & 1 deletion src/json-repair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
normalizeQuote,
normalizeWhitespace,
stripLastOccurrence
} from './stringUtils.js'
} from './stringUtils'

// token types enumeration
const DELIMITER = 0
Expand Down
2 changes: 1 addition & 1 deletion test-lib/apps/cjsApp.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const repair = require('../..')
const repair = require('../../lib/umd/jsonRepair.js')

console.log(repair('{name: \'John\'}'))
15 changes: 15 additions & 0 deletions test-lib/apps/esmBrowserApp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSON Repair</title>
</head>
<body>
<script type="module">
import jsonRepair from '../../lib/esm/json-repair.js'

document.write(jsonRepair('{name: \'John\'}'))
</script>

</body>
</html>
14 changes: 14 additions & 0 deletions test-lib/apps/umdBrowserApp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSON Repair</title>
<script src="../../lib/umd/jsonRepair.js"></script>
</head>
<body>
<script>
document.write(jsonRepair('{name: \'John\'}'))
</script>

</body>
</html>
12 changes: 6 additions & 6 deletions test-lib/lib.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path')

describe('lib', () => {
it('should load the library using ESM', (done) => {
const filename = path.join(__dirname, 'apps/cjsApp.cjs')
const filename = path.join(__dirname, 'apps/cjsApp.cjs')

cp.exec(`node ${filename}`, function (error, result) {
strictEqual(error, null)
strictEqual(result, '{"name": "John"}\n')
done()
})
cp.exec(`node ${filename}`, function (error, result) {
strictEqual(error, null)
strictEqual(result, '{"name": "John"}\n')
done()
})
})

it('should load the library using CJS', (done) => {
Expand Down

0 comments on commit 4318354

Please sign in to comment.