Skip to content

Commit

Permalink
unify browser & rn versions for most files
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothée Rebours committed Oct 28, 2021
1 parent cfea45c commit f000cc7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Way data is stored for this database
* For a Node.js/Node Webkit database it's the file system
* For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage)
* For a react-native database, we use @react-native-async-storage/async-storage
*
* This version is the browser version
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For a Node.js/Node Webkit database it's the file system
* For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage)
* For a react-native database, we use @react-native-async-storage/async-storage
*
* This version is the react-native version
*/
const AsyncStorage = require('@react-native-async-storage/async-storage')
Expand Down Expand Up @@ -31,13 +32,13 @@ const rename = (filename, newFilename, callback) => {
}

const writeFile = (filename, contents, options, callback) => {
// Options do not matter in browser setup
// Options do not matter in a react-native setup
if (typeof options === 'function') { callback = options }
AsyncStorage.setItem(filename, contents, callback)
}

const appendFile = (filename, toAppend, options, callback) => {
// Options do not matter in browser setup
// Options do not matter in a react-native setup
if (typeof options === 'function') { callback = options }

// eslint-disable-next-line node/handle-callback-err
Expand All @@ -49,7 +50,7 @@ const appendFile = (filename, toAppend, options, callback) => {
}

const readFile = (filename, options, callback) => {
// Options do not matter in browser setup
// Options do not matter in a react-native setup
if (typeof options === 'function') { callback = options }
// eslint-disable-next-line node/handle-callback-err
AsyncStorage.getItem(filename, (err, contents) => {
Expand All @@ -61,10 +62,10 @@ const unlink = (filename, callback) => {
AsyncStorage.removeItem(filename, callback)
}

// Nothing to do, no directories will be used on the browser
// Nothing to do, no directories will be used on react-native
const mkdir = (dir, options, callback) => callback()

// Nothing to do, no data corruption possible in the browser
// Nothing to do, no data corruption possible on react-native
const ensureDatafileIntegrity = (filename, callback) => callback(null)

const crashSafeWriteFileLines = (filename, lines, callback) => {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.1.0",
"files": [
"lib/**/*.js",
"browser-version/**/*.js",
"platform-specific/**/*.js",
"index.js",
"index.d.ts"
],
Expand Down Expand Up @@ -89,13 +89,13 @@
"main": "index.js",
"browser": {
"./lib/customUtils.js": "./browser-version/lib/customUtils.js",
"./lib/storage.js": "./browser-version/lib/storage.js",
"./lib/storage.js": "./browser-version/lib/storage.browser.js",
"./lib/byline.js": "./browser-version/lib/byline.js"
},
"react-native": {
"./lib/customUtils.js": "./react-native-version/lib/customUtils.js",
"./lib/storage.js": "./react-native-version/lib/storage.js",
"./lib/byline.js": "./react-native-version/lib/byline.js"
"./lib/customUtils.js": "./browser-version/lib/customUtils.js",
"./lib/storage.js": "./browser-version/lib/storage.react-native.js",
"./lib/byline.js": "./browser-version/lib/byline.js"
},
"license": "MIT",
"publishConfig": {
Expand Down
1 change: 0 additions & 1 deletion react-native-version/lib/byline.js

This file was deleted.

66 changes: 0 additions & 66 deletions react-native-version/lib/customUtils.js

This file was deleted.

4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = (env, argv) => {
}
},
plugins: [
new webpack.NormalModuleReplacementPlugin(new RegExp(path.resolve(__dirname, 'lib/storage.js')), path.resolve(__dirname, 'browser-version/lib/storage.js')),
new webpack.NormalModuleReplacementPlugin(new RegExp(path.resolve(__dirname, 'lib/storage.js')), path.resolve(__dirname, 'browser-version/lib/storage.browser.js')),
new webpack.NormalModuleReplacementPlugin(new RegExp(path.resolve(__dirname, 'lib/customUtils.js')), path.resolve(__dirname, 'browser-version/lib/customUtils.js')),
new webpack.NormalModuleReplacementPlugin(/byline/, path.resolve(__dirname, 'browser-version/lib/byline.js')),
new webpack.ProvidePlugin({
Expand All @@ -39,7 +39,7 @@ module.exports = (env, argv) => {
Nedb: path.join(__dirname, 'lib', 'datastore.js')
},
output: {
path: path.join(__dirname, 'browser-version/out'),
path: path.join(__dirname, 'platform-specific/out'),
filename: minimize ? 'nedb.min.js' : 'nedb.js',
libraryTarget: 'window',
library: '[name]'
Expand Down

0 comments on commit f000cc7

Please sign in to comment.