diff --git a/.gitignore b/.gitignore index 4f572cc4..14795f20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ coverage node_modules -out -build .DS_Store -repc src/wasm -docs \ No newline at end of file +docs +out \ No newline at end of file diff --git a/package.json b/package.json index 804a1999..f2a41f3d 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,13 @@ "check-format": "prettier --check '{src,sample,perf}/**/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{js,jsx,json,ts,tsx,html,css,md}'", "lint": "eslint --ext .ts,.tsx,.js,.jsx src/ perf/", "doc": "typedoc src/mod.ts", - "build": "rollup --config rollup.config.js", - "build-dev": "DEV=1 rollup --config rollup.config.js", + "build": "rollup --config rollup.config.js && CJS=1 rollup --config rollup.config.js ", "build:watch": "rollup --config rollup.config.js --watch", - "postinstall": "rm -f node_modules/fetch-mock/esm/client.d.ts && tool/get-deps.sh", - "prepublishOnly": "npm run lint && npm run get-repc && npm run test && rm -rf out && npm run build && npm run build-dev", + "postinstall": "rm -f node_modules/fetch-mock/esm/client.d.ts", + "prepublishOnly": "npm run lint && tool/get-deps.sh && npm run test && rm -rf out && npm run build", "prepack": "npm run prepublishOnly", - "perf": "node perf/runner.js", - "get-repc": "tool/get-deps.sh" + "prepare": "tool/get-deps.sh", + "perf": "node perf/runner.js" }, "devDependencies": { "@esm-bundle/chai": "^4.3.0", @@ -46,15 +45,12 @@ "typedoc-plugin-sourcefile-url": "^1.0.6", "typescript": "^4.2.3" }, - "type": "module", - "module": "out/replicache.js", - "types": "out/replicache.js", + "main": "out/replicache.js", + "types": "out/replicache.d.js", "files": [ - "out", - "tool/get-deps.sh" - ], - "exports": { - ".": "./out/replicache.js", - "./dev": "./out/replicache.dev.js" - } + "out/replicache.js", + "out/replicache.mjs", + "out/replicache.wasm", + "out/replicache.dev.wasm" + ] } diff --git a/perf/package.json b/perf/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/perf/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/perf/perf.js b/perf/perf.js index 0c17ddd5..165f0f6d 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -3,7 +3,7 @@ /* eslint-env browser, es2020 */ -import {Replicache} from '../out/replicache.js'; +import {Replicache} from '../out/replicache.mjs'; console.assert = console.debug = console.error = console.info = console.log = console.warn = () => void 0; diff --git a/rollup.config.js b/rollup.config.js index 825647bf..0d0e630a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,47 +1,42 @@ import typescript from '@wessberg/rollup-plugin-ts'; import replace from '@rollup/plugin-replace'; -import alias from '@rollup/plugin-alias'; import copy from 'rollup-plugin-copy'; /* eslint-env node */ -const dev = !!process.env.DEV; -const part = dev ? '.dev' : ''; -const variant = dev ? 'debug' : 'release'; +const dir = 'out'; +const cjs = process.env.CJS !== undefined; +const format = cjs ? 'cjs' : 'es'; +const ext = cjs ? 'js' : 'mjs'; export default { input: 'src/mod.ts', output: { - file: `out/replicache${part}.js`, - format: 'esm', + file: `./${dir}/replicache.${ext}`, + format, }, plugins: [ - // When building dev version use wasm/debug/ instead of wasm/relese/ - alias({ - entries: [ - { - find: /wasm\/release\/replicache_client\.js$/, - replacement: `wasm/${variant}/replicache_client.js`, - }, - ], - }), - - // Use replicache.wasm in same directory as out/replicache.js + // Use replicache.wasm in same directory as replicache.js replace({ - ['./wasm/release/replicache_client_bg.wasm']: `'./replicache${part}.wasm'`, + ['./wasm/release/replicache_client_bg.wasm']: `'./replicache.wasm'`, delimiters: [`'`, `'`], include: 'src/repm-invoker.ts', }), typescript(), - // Copy wasm file to out directory + // Copy wasm files to out directory copy({ targets: [ { - src: `src/wasm/${variant}/replicache_client_bg.wasm`, - dest: `out`, - rename: `replicache${part}.wasm`, + src: `src/wasm/release/replicache_client_bg.wasm`, + dest: `./${dir}/`, + rename: `replicache.wasm`, + }, + { + src: `src/wasm/debug/replicache_client_bg.wasm`, + dest: `./${dir}/`, + rename: `replicache.dev.wasm`, }, ], }), diff --git a/src/replicache.test.ts b/src/replicache.test.ts index 520675f9..dfea9775 100644 --- a/src/replicache.test.ts +++ b/src/replicache.test.ts @@ -1483,7 +1483,7 @@ testWithBothStores('onSync', async () => { patch: [], }); rep.pull(); - await tickAFewTimes(10); + await tickAFewTimes(15); expect(onSync.callCount).to.eq(2); expect(onSync.getCall(0).args[0]).to.be.true;