Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*.html
*.yml
*.yaml
*.css
*.scss
*.md
*.markdown

package/lib

.well-known
android
ios
vendor
package.json
package-lock.json

# The GH actions don't seem to compile and verify themselves well when Prettier is applied to them
.github/actions/javascript/**/index.js

9 changes: 9 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
quoteProps: 'consistent',
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
useTabs: false,
singleAttributePerLine: true,
semi: false,
}
2 changes: 1 addition & 1 deletion .watchmanconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
39 changes: 15 additions & 24 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
module.exports = {
root: true,
ignorePatterns: [
"**/node_modules",
"**/lib",
"**/.eslintrc.js",
"**/.prettierrc.js",
"**/jest.config.js",
"**/babel.config.js",
"**/metro.config.js",
"**/react-native.config.js",
"**/tsconfig.json"
'**/node_modules',
'**/lib',
'**/.eslintrc.js',
'**/.prettierrc.js',
'**/jest.config.js',
'**/babel.config.js',
'**/metro.config.js',
'**/react-native.config.js',
'**/tsconfig.json',
],
extends: ['@react-native','plugin:prettier/recommended'],
plugins: ['@typescript-eslint', 'prettier'],
extends: [
'@react-native',
'plugin:prettier/recommended',
'plugin:@typescript-eslint/recommended',
],
plugins: ['@typescript-eslint', 'jest'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
Expand All @@ -23,17 +27,4 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
'prettier/prettier': [
'warn',
{
quoteProps: 'consistent',
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
semi: false,
},
],
},
}
2 changes: 1 addition & 1 deletion example/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ module.exports = {
project: true,
tsconfigRootDir: __dirname,
},
};
}
2 changes: 1 addition & 1 deletion example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
10 changes: 5 additions & 5 deletions example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const pak = require('../package/package.json');
const path = require('path')
const pak = require('../package/package.json')

module.exports = {
presets: ['module:@react-native/babel-preset'],
Expand All @@ -10,12 +10,12 @@ module.exports = {
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
[pak.name]: path.join(__dirname, '../package', pak.source),
stream: 'stream-browserify',
'stream': 'stream-browserify',
'react-native-sqlite-storage': 'react-native-nitro-sqlite',
},
},
],
'babel-plugin-transform-typescript-metadata',
['@babel/plugin-proposal-decorators', {legacy: true}],
['@babel/plugin-proposal-decorators', { legacy: true }],
],
};
}
53 changes: 27 additions & 26 deletions example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
const fs = require('fs');
const path = require('path');
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const escape = require('escape-string-regexp');
const fs = require('fs')
const path = require('path')
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
const exclusionList = require('metro-config/src/defaults/exclusionList')
const escape = require('escape-string-regexp')

const root = path.resolve(__dirname, '..');
const rootNodeModulesPath = path.join(root, 'node_modules');
const exampleNodeModulesPath = path.join(__dirname, 'node_modules');
const root = path.resolve(__dirname, '..')
const rootNodeModulesPath = path.join(root, 'node_modules')
const exampleNodeModulesPath = path.join(__dirname, 'node_modules')

function getPackageNames(nodeModulesPath) {
if (!fs.existsSync(nodeModulesPath)) {
return [];
return []
}

const allFiles = fs.readdirSync(nodeModulesPath);
const allFiles = fs.readdirSync(nodeModulesPath)

// Filter out only directories (package names)
const packageNames = allFiles.filter(file => {
const filePath = path.join(nodeModulesPath, file);
return fs.statSync(filePath).isDirectory();
});
const packageNames = allFiles.filter((file) => {
const filePath = path.join(nodeModulesPath, file)
return fs.statSync(filePath).isDirectory()
})

// Handle scoped packages (e.g., @scope/package)
const scopedPackages = packageNames
.filter(pkg => pkg.startsWith('@'))
.flatMap(scope => {
const scopePath = path.join(nodeModulesPath, scope);
const scopedFiles = fs.readdirSync(scopePath);
return scopedFiles.map(scopedFile => `${scope}/${scopedFile}`);
});
.filter((pkg) => pkg.startsWith('@'))
.flatMap((scope) => {
const scopePath = path.join(nodeModulesPath, scope)
const scopedFiles = fs.readdirSync(scopePath)
return scopedFiles.map((scopedFile) => `${scope}/${scopedFile}`)
})

// Return both regular and scoped package names
return packageNames
.filter(pkg => !pkg.startsWith('@'))
.concat(scopedPackages);
.filter((pkg) => !pkg.startsWith('@'))
.concat(scopedPackages)
}

const exampleNodeModules = getPackageNames(exampleNodeModulesPath);
const exampleNodeModules = getPackageNames(exampleNodeModulesPath)

const config = {
projectRoot: __dirname,
Expand All @@ -48,7 +48,8 @@ const config = {
unstable_enableSymlinks: true,
blockList: exclusionList(
exampleNodeModules.map(
m => new RegExp(`^${escape(path.join(rootNodeModulesPath, m))}\\/.*$`),
(m) =>
new RegExp(`^${escape(path.join(rootNodeModulesPath, m))}\\/.*$`),
),
),

Expand All @@ -70,6 +71,6 @@ const config = {
},
}),
},
};
}

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = mergeConfig(getDefaultConfig(__dirname), config)
6 changes: 3 additions & 3 deletions example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path');
const pak = require('../package/package.json');
const path = require('path')
const pak = require('../package/package.json')

module.exports = {
dependencies: {
[pak.name]: {
root: path.join(__dirname, '../package'),
},
},
};
}
15 changes: 12 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ export default function App() {
return (
<NavigationContainer>
<RootStack.Navigator initialRouteName="NitroSQLite Example">
<RootStack.Screen name="NitroSQLite Example" component={HomeScreen} />
<RootStack.Screen name="Unit Tests" component={UnitTestScreen} />
<RootStack.Screen name="Benchmarks" component={BenchmarkScreen} />
<RootStack.Screen
name="NitroSQLite Example"
component={HomeScreen}
/>
<RootStack.Screen
name="Unit Tests"
component={UnitTestScreen}
/>
<RootStack.Screen
name="Benchmarks"
component={BenchmarkScreen}
/>
</RootStack.Navigator>

<StatusBar style="auto" />
Expand Down
3 changes: 2 additions & 1 deletion example/src/initGlobals.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer'

declare global {
// eslint-disable-next-line no-var
var Buffer: typeof CraftzdogBuffer
}

if (!globalThis.process) {
// @ts-expect-error
// @ts-expect-error - if process is not defined, we need to set it to an empty object
globalThis.process = {}
}

Expand Down
11 changes: 7 additions & 4 deletions example/src/screens/BenchmarkScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const benchmarks: Benchmark[] = [
resetTestDb()
testDb?.execute('DROP TABLE IF EXISTS User;')
testDb?.execute(
'CREATE TABLE User ( id REAL PRIMARY KEY, name TEXT NOT NULL, age REAL, networth REAL) STRICT;'
'CREATE TABLE User ( id REAL PRIMARY KEY, name TEXT NOT NULL, age REAL, networth REAL) STRICT;',
)
},
run: (i) => {
testDb?.execute(
'INSERT INTO User (id, name, age, networth) VALUES(?, ?, ?, ?)',
[ids[i], stringValue, integerValue, doubleValue]
[ids[i], stringValue, integerValue, doubleValue],
)
},
},
Expand Down Expand Up @@ -126,7 +126,10 @@ export function BenchmarkScreen() {
benchmarks.map(({ description }, index) => {
const time = results[description]
return (
<View style={{ paddingBottom: 10 }} key={index}>
<View
style={{ paddingBottom: 10 }}
key={index}
>
<View
style={{
flexDirection: 'row',
Expand Down Expand Up @@ -159,7 +162,7 @@ export function BenchmarkScreen() {
</View>
)
}),
[results]
[results],
)

return (
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/UnitTestScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function UnitTestScreen() {
useEffect(() => {
setResults([])
runTests(
registerUnitTests
registerUnitTests,
// registerTypeORMTests
).then(setResults)
}, [])
Expand Down
4 changes: 2 additions & 2 deletions example/src/tests/MochaRNAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const clearTests = () => {

export const it = (
name: string,
f: MochaTypes.Func | MochaTypes.AsyncFunc
f: MochaTypes.Func | MochaTypes.AsyncFunc,
): void => {
if (!only) {
const test = new Mocha.Test(name, f)
Expand All @@ -26,7 +26,7 @@ export const it = (

export const itOnly = (
name: string,
f: MochaTypes.Func | MochaTypes.AsyncFunc
f: MochaTypes.Func | MochaTypes.AsyncFunc,
): void => {
clearTests()
const test = new Mocha.Test(name, f)
Expand Down
2 changes: 1 addition & 1 deletion example/src/tests/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function resetLargeDb() {
})

largeDb.execute(
'CREATE TABLE Test ( id INT PRIMARY KEY, v1 TEXT, v2 TEXT, v3 TEXT, v4 TEXT, v5 TEXT, v6 INT, v7 INT, v8 INT, v9 INT, v10 INT, v11 REAL, v12 REAL, v13 REAL, v14 REAL) STRICT;'
'CREATE TABLE Test ( id INT PRIMARY KEY, v1 TEXT, v2 TEXT, v3 TEXT, v4 TEXT, v5 TEXT, v6 INT, v7 INT, v8 INT, v9 INT, v10 INT, v11 REAL, v12 REAL, v13 REAL, v14 REAL) STRICT;',
)

largeDb.execute('PRAGMA mmap_size=268435456')
Expand Down
Loading
Loading