Converted to named export for ES6 module

This commit is contained in:
Ben Ashton 2021-03-14 21:15:26 -07:00
parent 4293e380dd
commit 7501617e1e
7 changed files with 97 additions and 65 deletions

View File

@ -164,6 +164,77 @@ function enableDebug(active) {
/***/ }), /***/ }),
/***/ "./src/pawsqlite.mjs":
/*!***************************!*\
!*** ./src/pawsqlite.mjs ***!
\***************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "PawSQLiteError": () => (/* reexport safe */ _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError),
/* harmony export */ "PawSQLite": () => (/* binding */ PawSQLite)
/* harmony export */ });
/* harmony import */ var _database_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./database.mjs */ "./src/database.mjs");
/* harmony import */ var _adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./adapter_wrapper.mjs */ "./src/adapter_wrapper.mjs");
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
/* harmony import */ var _log_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./log.mjs */ "./src/log.mjs");
const adapters = [];
const PawSQLite = {
open: async function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
let db = new _database_mjs__WEBPACK_IMPORTED_MODULE_0__.Database(dbName, adapter);
await db.open();
return db;
},
delete: function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
return adapter.delete(dbName);
},
registerAdapter: function(adapter) {
if (!adapter) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError("Invalid adapter");
}
const wrapped = (0,_adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__.wrapAdapter)(adapter);
if (getAdapter(wrapped.name, true)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`An adapter with the name: ${ wrapped.name } ` +
`Already exists`);
}
(0,_log_mjs__WEBPACK_IMPORTED_MODULE_3__.log)(`Registered adapter: ${ wrapped.name }`);
adapters.push(wrapped);
},
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_3__.enableDebug
};
function getAdapter(adapterName, silent=false) {
const adapter = adapters.find((a) => a.name === adapterName);
if (!(silent || adapter)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`Unknown Adapter: ${adapterName}`);
}
return adapter;
}
/***/ }),
/***/ "./src/pawsqlite_error.mjs": /***/ "./src/pawsqlite_error.mjs":
/*!*********************************!*\ /*!*********************************!*\
!*** ./src/pawsqlite_error.mjs ***! !*** ./src/pawsqlite_error.mjs ***!
@ -502,70 +573,23 @@ class TransactionManager {
var __webpack_exports__ = {}; var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => { (() => {
/*!***************************!*\ /*!*******************************!*\
!*** ./src/pawsqlite.mjs ***! !*** ./src/pawsqlite_cjs.mjs ***!
\***************************/ \*******************************/
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ }); /* harmony export */ });
/* harmony import */ var _database_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./database.mjs */ "./src/database.mjs"); /* harmony import */ var _pawsqlite_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pawsqlite.mjs */ "./src/pawsqlite.mjs");
/* harmony import */ var _adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./adapter_wrapper.mjs */ "./src/adapter_wrapper.mjs"); /* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
/* harmony import */ var _log_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./log.mjs */ "./src/log.mjs");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Object.create(_pawsqlite_mjs__WEBPACK_IMPORTED_MODULE_0__.PawSQLite, {
Error: {
value: _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__.PawSQLiteError
const adapters = [];
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
open: async function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
let db = new _database_mjs__WEBPACK_IMPORTED_MODULE_0__.Database(dbName, adapter);
await db.open();
return db;
},
delete: function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
return adapter.delete(dbName);
},
registerAdapter: function(adapter) {
if (!adapter) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError("Invalid adapter");
}
const wrapped = (0,_adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__.wrapAdapter)(adapter);
if (getAdapter(wrapped.name, true)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`An adapter with the name: ${ wrapped.name } ` +
`Already exists`);
}
(0,_log_mjs__WEBPACK_IMPORTED_MODULE_3__.log)(`Registered adapter: ${ wrapped.name }`);
adapters.push(wrapped);
},
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_3__.enableDebug,
Error: _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError
});
function getAdapter(adapterName, silent=false) {
const adapter = adapters.find((a) => a.name === adapterName);
if (!(silent || adapter)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`Unknown Adapter: ${adapterName}`);
}
return adapter;
} }
}));
})(); })();
module.exports = __webpack_exports__.default; module.exports = __webpack_exports__.default;

1
cjs/pawsqlite.js.map Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,10 +2,10 @@
"name": "pawsqlite", "name": "pawsqlite",
"version": "1.0.0", "version": "1.0.0",
"description": "An SQLite interface with adapters for Cordova and WebSQL", "description": "An SQLite interface with adapters for Cordova and WebSQL",
"main": "./lib/pawsqlite.js", "main": "./cjs/pawsqlite.js",
"exports": { "exports": {
"import": "./src/pawsqlite.mjs", "import": "./src/pawsqlite.mjs",
"require": "./lib/pawsqlite.js" "require": "./cjs/pawsqlite.js"
}, },
"module": "./src/pawsqlite.mjs", "module": "./src/pawsqlite.mjs",
"scripts": { "scripts": {

View File

@ -3,11 +3,12 @@ import { wrapAdapter } from "./adapter_wrapper.mjs";
import { PawSQLiteError } from "./pawsqlite_error.mjs"; import { PawSQLiteError } from "./pawsqlite_error.mjs";
import { enableDebug, log } from "./log.mjs"; import { enableDebug, log } from "./log.mjs";
export { PawSQLiteError } from "./pawsqlite_error.mjs";
const adapters = []; const adapters = [];
export const PawSQLite = {
export default {
open: async function(dbName, options = {}) { open: async function(dbName, options = {}) {
const adapter = getAdapter(options.adapter); const adapter = getAdapter(options.adapter);
@ -36,8 +37,7 @@ export default {
adapters.push(wrapped); adapters.push(wrapped);
}, },
debug: enableDebug, debug: enableDebug
Error: PawSQLiteError
}; };

8
src/pawsqlite_cjs.mjs Normal file
View File

@ -0,0 +1,8 @@
import { PawSQLite } from "./pawsqlite.mjs";
import { PawSQLiteError } from "./pawsqlite_error.mjs";
export default Object.create(PawSQLite, {
Error: {
value: PawSQLiteError
}
});

View File

@ -4,10 +4,10 @@ var outputFile = libraryName + '.js';
var config = { var config = {
mode: 'development', mode: 'development',
entry: __dirname + '/src/pawsqlite.mjs', entry: __dirname + '/src/pawsqlite_cjs.mjs',
devtool: 'source-map', devtool: 'source-map',
output: { output: {
path: __dirname + '/lib', path: __dirname + '/cjs',
filename: outputFile, filename: outputFile,
libraryExport: 'default', libraryExport: 'default',
libraryTarget: 'commonjs2', libraryTarget: 'commonjs2',