From 3f46a65d698b4196cbeb1fa5210b46970339f2f7 Mon Sep 17 00:00:00 2001 From: Nebulis Date: Fri, 20 Nov 2020 15:10:40 +0800 Subject: [PATCH] fix: cjs + esm + umd module --- package-lock.json | 105 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 11 ++++- rollup.config.js | 12 ++++++ tsconfig.prod.json | 6 +++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 rollup.config.js create mode 100644 tsconfig.prod.json diff --git a/package-lock.json b/package-lock.json index cd8e6c8..705d9a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1140,6 +1140,26 @@ "@types/node": ">= 8" } }, + "@rollup/plugin-json": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", + "integrity": "sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8" + } + }, + "@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + } + }, "@semantic-release/commit-analyzer": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-8.0.1.tgz", @@ -1635,6 +1655,12 @@ "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", "dev": true }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/istanbul-lib-coverage": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", @@ -4423,6 +4449,12 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -5869,6 +5901,15 @@ "isobject": "^3.0.1" } }, + "is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "requires": { + "@types/estree": "*" + } + }, "is-regex": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", @@ -12756,6 +12797,64 @@ "glob": "^7.1.3" } }, + "rollup": { + "version": "1.32.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz", + "integrity": "sha512-/2HA0Ec70TvQnXdzynFffkjA6XN+1e2pEv/uKS5Ulca40g2L7KuOE3riasHoNVHOsFD5KKZgDsMk1CP3Tw9s+A==", + "dev": true, + "requires": { + "@types/estree": "*", + "@types/node": "*", + "acorn": "^7.1.0" + } + }, + "rollup-plugin-commonjs": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz", + "integrity": "sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1", + "is-reference": "^1.1.2", + "magic-string": "^0.25.2", + "resolve": "^1.11.0", + "rollup-pluginutils": "^2.8.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, + "magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + } + } + }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + } + } + }, "rsvp": { "version": "4.8.5", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz", @@ -13504,6 +13603,12 @@ "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=", "dev": true }, + "sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "dev": true + }, "spawn-error-forwarder": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/spawn-error-forwarder/-/spawn-error-forwarder-1.0.0.tgz", diff --git a/package.json b/package.json index fec874f..f920d72 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,16 @@ "name": "@govtechsg/oa-schemata", "version": "0.0.0-development", "description": "Repository for schemata created by open-attestation", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "browser": "dist/index.umd.js", "types": "dist/types/index.d.ts", "scripts": { - "build": "npm run clean && npm run build:type", + "build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:type", + "build:cjs": "tsc --module commonjs --outDir dist/cjs --project ./tsconfig.prod.json", + "build:esm": "tsc --module es2015 --outDir dist/esm --project ./tsconfig.prod.json", "build:type": "tsc -d --emitDeclarationOnly --outDir dist/types", + "build:umd": "rollup -c", "clean": "rm -rf dist/", "dev": "cd app && npm run dev", "test": "jest", @@ -21,6 +27,7 @@ "@commitlint/config-conventional": "8.3.3", "@commitlint/prompt": "8.3.3", "@ls-age/commitlint-circle": "1.0.0", + "@rollup/plugin-json": "^4.0.0", "@types/jest": "^24.0.23", "@types/lodash": "^4.14.162", "@typescript-eslint/eslint-plugin": "^2.8.0", @@ -41,6 +48,8 @@ "prettier": "^1.19.1", "prettier-plugin-svelte": "^1.4.1", "quicktype": "^15.0.258", + "rollup": "^1.27.3", + "rollup-plugin-commonjs": "^10.1.0", "semantic-release": "^17.2.1", "svelte": "^3.29.4", "ts-jest": "^24.1.0", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..6edcc79 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,12 @@ +import commonjs from "rollup-plugin-commonjs"; +import json from "@rollup/plugin-json"; + +export default { + input: "./dist/esm/index.js", // umd will run from esm build to produce a single bundled file, any better idea ? + output: { + file: "./dist/index.umd.js", + format: "umd", + name: "openAttestation" + }, + plugins: [commonjs(), json()] +}; diff --git a/tsconfig.prod.json b/tsconfig.prod.json new file mode 100644 index 0000000..3c45519 --- /dev/null +++ b/tsconfig.prod.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig", + "exclude": [ + "**/*.test.ts" + ] +}