diff --git a/.gitignore b/.gitignore index 7564a43..5f1777a 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ typings/ build/ data/ packages/*/lib +packages/*/esm diff --git a/Buildfile b/Buildfile index a24f059..f6d8aa5 100644 --- a/Buildfile +++ b/Buildfile @@ -11,5 +11,8 @@ add: clean: rm -rf packages/*/lib +sync-esm-config: + node scripts/sync-esm-config.js + test: jest diff --git a/package-lock.json b/package-lock.json index bcd7fb6..b639c00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5427,9 +5427,8 @@ } }, "esmify": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/esmify/-/esmify-2.1.1.tgz", - "integrity": "sha512-GyOVgjG7sNyYB5Mbo15Ll4aGrcXZzZ3LI22rbLOjCI7L/wYelzQpBHRZkZkqbPNZ/QIRilcaHqzgNCLcEsi1lQ==", + "version": "git+https://github.com/jeremija/esmify.git#f98b2c83898283cb01346635ef457e33795d7060", + "from": "git+https://github.com/jeremija/esmify.git", "dev": true, "requires": { "@babel/core": "^7.2.2", diff --git a/package.json b/package.json index c956dd8..0516f5d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "cookie-parser": "^1.4.4", "date-fns": "^2.0.0-alpha.27", "deep-object-diff": "^1.1.0", - "esmify": "^2.1.1", + "esmify": "git+https://github.com/jeremija/esmify.git", "history": "^4.9.0", "jest": "^24.5.0", "lerna": "^3.13.1", @@ -60,13 +60,12 @@ "react-dom": "^16.7.0", "react-icons": "^3.5.0", "react-redux": "^6.0.0", - "react-router-dom": "^4.4.0", + "react-router-dom": "^4.3.1", "redux": "^4.0.1", "sanitize-html": "^1.20.0", "sourceify": "git+https://github.com/jeremija/sourceify.git#sources-content", "std-mocks": "^1.0.1", "supertest": "^3.3.0", - "terser": "^3.14.1", "ts-jest": "^24.0.0", "ts-node": "^7.0.1", "ts-node-dev": "^1.0.0-pre.32", diff --git a/packages/client/package.json b/packages/client/package.json index 1b9b8c5..b0d3bc1 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -9,5 +9,6 @@ "redux": "^4.0.1" }, "main": "lib/index.js", - "types": "lib/index.d.ts" + "types": "lib/index.d.ts", + "module": "esm/index.js" } diff --git a/packages/client/tsconfig.esm.json b/packages/client/tsconfig.esm.json new file mode 100644 index 0000000..a55f888 --- /dev/null +++ b/packages/client/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "esm" + }, + "references": [ + { + "path": "../common/tsconfig.esm.json" + } + ] +} \ No newline at end of file diff --git a/packages/common/package.json b/packages/common/package.json index 817fcd3..b5b7839 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -2,5 +2,6 @@ "name": "@rondo/common", "private": true, "main": "lib/index.js", + "module": "esm/index.js", "types": "lib/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/common/tsconfig.esm.json b/packages/common/tsconfig.esm.json new file mode 100644 index 0000000..d54bfbf --- /dev/null +++ b/packages/common/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "esm" + }, + "references": [] +} \ No newline at end of file diff --git a/packages/server/package.json b/packages/server/package.json index 08e2092..ade6f4c 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -34,5 +34,6 @@ "winston": "^3.1.0" }, "main": "lib/index.js", - "types": "lib/index.d.ts" -} + "types": "lib/index.d.ts", + "module": "esm/index.js" +} \ No newline at end of file diff --git a/packages/server/tsconfig.esm.json b/packages/server/tsconfig.esm.json new file mode 100644 index 0000000..a55f888 --- /dev/null +++ b/packages/server/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "esm" + }, + "references": [ + { + "path": "../common/tsconfig.esm.json" + } + ] +} \ No newline at end of file diff --git a/scripts/sync-esm-config.js b/scripts/sync-esm-config.js new file mode 100755 index 0000000..fab3587 --- /dev/null +++ b/scripts/sync-esm-config.js @@ -0,0 +1,47 @@ +#!/usr/bin/env node +const fs = require('fs') +const path = require('path') + +const TSCONFIG_FILENAME = 'tsconfig.json' +const TSCONFIG_ESM_FILENAME = 'tsconfig.esm.json' +const PKG_DIRNAME = 'packages' + +const projectRoot = path.relative( + process.cwd(), path.resolve(__dirname, '..')) +const pkgDir = path.join(projectRoot, PKG_DIRNAME) + +const projects = fs.readdirSync(pkgDir) +.filter(file => { + const stat = fs.lstatSync(path.join(pkgDir, file)) + return stat.isDirectory() +}) +.map(file => path.join(pkgDir, file, TSCONFIG_FILENAME)) +.filter(file => fs.existsSync(file)) +.forEach(file => { + const tsconfig = JSON.parse(fs.readFileSync(file, 'utf8')) + const references = (tsconfig.references || []) + .map(ref => ({ + ...ref, + path: path.join(ref.path, TSCONFIG_ESM_FILENAME), + })) + + const tsconfigEsm = { + extends: `./${TSCONFIG_FILENAME}`, + compilerOptions: { + "outDir": "esm", + }, + references, + } + + const dirname = path.dirname(file) + const esmFile = path.join(dirname, TSCONFIG_ESM_FILENAME) + console.log('Writing %s', esmFile) + fs.writeFileSync(esmFile, JSON.stringify(tsconfigEsm, null, ' ')) + + const pkgFile = path.join(dirname, 'package.json') + const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8')) + pkg.module = 'lib/index.js' + pkg.module = pkg.main ? pkg.main.replace(/^lib/, 'esm') : 'lib/index.js' + console.log('Writing %s', pkgFile) + fs.writeFileSync(pkgFile, JSON.stringify(pkg, null, ' ')) +})