masterrecord 0.2.21 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/context.js +32 -14
  2. package/package.json +1 -1
package/context.js CHANGED
@@ -98,19 +98,21 @@ class context {
98
98
  let currentRoot = root;
99
99
  const maxHops = 12;
100
100
  for(let i = 0; i < maxHops; i++){
101
- const rootFolder = path.isAbsolute(rootFolderLocation) ? rootFolderLocation : `${currentRoot}/${rootFolderLocation}`;
101
+ const rootFolder = path.isAbsolute(rootFolderLocation) ? rootFolderLocation : path.join(currentRoot, rootFolderLocation);
102
102
  // Support both env.development.json and development.json naming
103
103
  const searchA = `${rootFolder}/**/*env.${envType}.json`;
104
104
  const searchB = `${rootFolder}/**/*${envType}.json`;
105
- let files = globSearch.sync(searchA, currentRoot);
105
+ let files = globSearch.sync(searchA, { cwd: currentRoot, dot: true, nocase: true, windowsPathsNoEscape: true });
106
106
  if(!files || files.length === 0){
107
- files = globSearch.sync(searchB, currentRoot);
107
+ files = globSearch.sync(searchB, { cwd: currentRoot, dot: true, nocase: true, windowsPathsNoEscape: true });
108
108
  }
109
- const file = files && files[0];
110
- if(file){
111
- return { file: file, rootFolder: currentRoot };
109
+ const rel = files && files[0];
110
+ if(rel){
111
+ // Ensure absolute path for require()
112
+ const abs = path.isAbsolute(rel) ? rel : path.resolve(currentRoot, rel);
113
+ return { file: abs, rootFolder: currentRoot };
112
114
  }
113
- const parent = tools.removeBackwardSlashSection(currentRoot, 1, "/");
115
+ const parent = path.dirname(currentRoot);
114
116
  if(parent === currentRoot || parent === ""){
115
117
  break;
116
118
  }
@@ -151,7 +153,9 @@ class context {
151
153
  throw new Error(`Environment config not found for '${envType}' under '${rootFolderLocation}'.`);
152
154
  }
153
155
 
154
- const settings = require(file.file);
156
+ // Always require absolute file path to avoid module root ambiguity on global installs/Windows
157
+ const settingsPath = path.isAbsolute(file.file) ? file.file : path.resolve(file.rootFolder, file.file);
158
+ const settings = require(settingsPath);
155
159
  const options = settings[contextName];
156
160
  if(options === undefined){
157
161
  console.log("settings missing context name settings");
@@ -162,11 +166,15 @@ class context {
162
166
 
163
167
  if(type === 'sqlite' || type === 'better-sqlite3'){
164
168
  this.isSQLite = true; this.isMySQL = false;
165
- // Back-compat: treat leading '/' as project-root relative, not filesystem root
169
+ // Treat leading project-style paths ('/components/...') as project-root relative across OSes
166
170
  let dbPath = options.connection || '';
167
171
  if(dbPath){
168
- if(dbPath.startsWith(path.sep) || !path.isAbsolute(dbPath)){
169
- dbPath = path.join(file.rootFolder, dbPath);
172
+ const looksProjectRootRelative = dbPath.startsWith('/') || dbPath.startsWith('\\');
173
+ const isAbsoluteFsPath = path.isAbsolute(dbPath);
174
+ if(looksProjectRootRelative || !isAbsoluteFsPath){
175
+ // Normalize leading separators to avoid duplicating separators on Windows
176
+ const trimmed = dbPath.replace(/^[/\\]+/, '');
177
+ dbPath = path.join(file.rootFolder, trimmed);
170
178
  }
171
179
  }
172
180
  const dbDir = path.dirname(dbPath);
@@ -210,11 +218,21 @@ class context {
210
218
  }
211
219
 
212
220
  this.validateSQLiteOptions(options);
213
- options.completeConnection = `${file.rootFolder}${options.connection}`;
214
- var dbDirectory = options.completeConnection.substr(0, options.completeConnection.lastIndexOf("\/"));
221
+ // Build DB path similarly to env(): project-root relative on leading slash
222
+ let dbPath = options.connection || '';
223
+ if(dbPath){
224
+ const looksProjectRootRelative = dbPath.startsWith('/') || dbPath.startsWith('\\');
225
+ const isAbsoluteFsPath = path.isAbsolute(dbPath);
226
+ if(looksProjectRootRelative || !isAbsoluteFsPath){
227
+ const trimmed = dbPath.replace(/^[/\\]+/, '');
228
+ dbPath = path.join(file.rootFolder, trimmed);
229
+ }
230
+ }
231
+ options.completeConnection = dbPath;
232
+ var dbDirectory = path.dirname(options.completeConnection);
215
233
 
216
234
  if (!fs.existsSync(dbDirectory)){
217
- fs.mkdirSync(dbDirectory);
235
+ fs.mkdirSync(dbDirectory, { recursive: true });
218
236
  }
219
237
 
220
238
  this.db = this.__SQLiteInit(options, "better-sqlite3");
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "app-root-path": "^3.1.0",
10
10
  "better-sqlite3": "^12.4.1"
11
11
  },
12
- "version": "0.2.21",
12
+ "version": "0.2.23",
13
13
  "description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
14
14
  "homepage": "https://github.com/Tailor/MasterRecord#readme",
15
15
  "repository": {