orange-orm 5.0.0 → 5.0.1-beta.0
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.
- package/bin/build.js +84 -11
- package/package.json +3 -6
package/bin/build.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
let url = require('url');
|
|
2
2
|
let compile = require('./compile');
|
|
3
|
-
let { glob } = require('glob');
|
|
4
3
|
let path = require('path');
|
|
5
|
-
let findNodeModules = require('findup-sync');
|
|
6
4
|
let fs = require('fs');
|
|
7
5
|
let util = require('util');
|
|
8
6
|
let writeFile = util.promisify(fs.writeFile);
|
|
9
7
|
let ts = require('typescript');
|
|
10
|
-
let moduleDefinition = require('module-definition');
|
|
11
8
|
let getTSDefinition = require('../src/getTSDefinition');
|
|
12
9
|
const _axios = require('axios');
|
|
13
10
|
const axios = _axios.default ? _axios.default.create() : _axios.create();
|
|
@@ -32,7 +29,7 @@ async function runSingle(schemaTs) {
|
|
|
32
29
|
}
|
|
33
30
|
console.log(`Orange: found schema ${schemaTs}`);
|
|
34
31
|
if (!schemaJsPath) {
|
|
35
|
-
let nodeModules =
|
|
32
|
+
let nodeModules = findClosestNodeModules(schemaTs);
|
|
36
33
|
outDir = path.join(nodeModules, '/.rdb', '/' + new Date().getUTCMilliseconds());
|
|
37
34
|
schemaJsPath = compile(schemaTs, { outDir });
|
|
38
35
|
}
|
|
@@ -73,18 +70,72 @@ async function runSingle(schemaTs) {
|
|
|
73
70
|
async function writeIndexJs(schemaJsPath) {
|
|
74
71
|
const schema = path.basename(schemaJsPath);
|
|
75
72
|
const indexJs = path.join(path.dirname(schemaJsPath), '/index' + path.extname(schemaJsPath));
|
|
76
|
-
if (
|
|
73
|
+
if (detectModuleFormat(schemaJsPath) === 'commonjs')
|
|
77
74
|
await writeFile(indexJs, `module.exports = require('./${schema}');`);
|
|
78
75
|
else
|
|
79
76
|
await writeFile(indexJs, `export {default} from './${schema}';`);
|
|
80
77
|
}
|
|
81
78
|
|
|
79
|
+
function detectModuleFormat(filePath) {
|
|
80
|
+
const extension = path.extname(filePath);
|
|
81
|
+
if (extension === '.mjs')
|
|
82
|
+
return 'module';
|
|
83
|
+
if (extension === '.cjs')
|
|
84
|
+
return 'commonjs';
|
|
85
|
+
|
|
86
|
+
const pkg = findClosestPackageJson(path.dirname(filePath));
|
|
87
|
+
if (pkg && pkg.type === 'module')
|
|
88
|
+
return 'module';
|
|
89
|
+
|
|
90
|
+
return 'commonjs';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function findClosestPackageJson(startDir) {
|
|
94
|
+
let currentDir = startDir;
|
|
95
|
+
while (currentDir) {
|
|
96
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
97
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const parentDir = path.dirname(currentDir);
|
|
107
|
+
if (parentDir === currentDir)
|
|
108
|
+
return null;
|
|
109
|
+
currentDir = parentDir;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function findClosestNodeModules(startPath) {
|
|
115
|
+
const startDir = fs.statSync(startPath).isDirectory() ? startPath : path.dirname(startPath);
|
|
116
|
+
let currentDir = startDir;
|
|
117
|
+
while (true) {
|
|
118
|
+
const nodeModulesPath = path.join(currentDir, 'node_modules');
|
|
119
|
+
if (fs.existsSync(nodeModulesPath))
|
|
120
|
+
return nodeModulesPath;
|
|
121
|
+
|
|
122
|
+
const parentDir = path.dirname(currentDir);
|
|
123
|
+
if (parentDir === currentDir)
|
|
124
|
+
return path.join(startDir, 'node_modules');
|
|
125
|
+
currentDir = parentDir;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
82
129
|
async function findSchemaJs(cwd) {
|
|
83
|
-
let
|
|
84
|
-
|
|
85
|
-
|
|
130
|
+
let ignoredDirNames = {
|
|
131
|
+
node_modules: true,
|
|
132
|
+
dist: true,
|
|
133
|
+
dev: true,
|
|
134
|
+
deploy: true,
|
|
135
|
+
build: true
|
|
86
136
|
};
|
|
87
|
-
let files =
|
|
137
|
+
let files = [];
|
|
138
|
+
scanForSchemaFiles(cwd, ignoredDirNames, files);
|
|
88
139
|
files.sort((a, b) => {
|
|
89
140
|
const aIsTs = a.substring(a.length - 2) === 'ts';
|
|
90
141
|
const bIsTs = b.substring(b.length - 2) === 'ts';
|
|
@@ -97,7 +148,29 @@ async function findSchemaJs(cwd) {
|
|
|
97
148
|
else
|
|
98
149
|
return 0;
|
|
99
150
|
});
|
|
100
|
-
return files
|
|
151
|
+
return files;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function scanForSchemaFiles(currentDir, ignoredDirNames, results) {
|
|
155
|
+
for (let entry of fs.readdirSync(currentDir)) {
|
|
156
|
+
const fullPath = path.join(currentDir, entry);
|
|
157
|
+
let stat;
|
|
158
|
+
try {
|
|
159
|
+
stat = fs.statSync(fullPath);
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (stat.isDirectory()) {
|
|
165
|
+
if (ignoredDirNames[entry])
|
|
166
|
+
continue;
|
|
167
|
+
scanForSchemaFiles(fullPath, ignoredDirNames, results);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (entry === 'schema.js' || entry === 'schema.mjs' || entry === 'schema.ts')
|
|
172
|
+
results.push(fullPath);
|
|
173
|
+
}
|
|
101
174
|
}
|
|
102
175
|
|
|
103
176
|
function tryDownload(_url, _isNamespace) {
|
|
@@ -124,4 +197,4 @@ async function download(url, isNamespace) {
|
|
|
124
197
|
|
|
125
198
|
module.exports = function(cwd) {
|
|
126
199
|
run(cwd).then(null, console.log);
|
|
127
|
-
};
|
|
200
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orange-orm",
|
|
3
|
-
"version": "5.0.0",
|
|
3
|
+
"version": "5.0.1-beta.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -80,20 +80,17 @@
|
|
|
80
80
|
"ajv": "^8.17.1",
|
|
81
81
|
"axios": "^1.6.2",
|
|
82
82
|
"fast-json-patch": "^3.1.1",
|
|
83
|
-
"findup-sync": "^5.0.0",
|
|
84
|
-
"glob": "^10.3.4 || ^11.0.2",
|
|
85
|
-
"module-definition": "^4.0.0 || ^5.0.0 || || ^6.0.0",
|
|
86
83
|
"rfdc": "^1.2.0",
|
|
87
84
|
"uuid": "^8.3.2 || ^9.0.0 || ^10.0.0 || ^11.1.0"
|
|
88
85
|
},
|
|
89
86
|
"peerDependencies": {
|
|
90
87
|
"@electric-sql/pglite": "^0.3.0",
|
|
88
|
+
"better-sqlite3": "^11.8.1",
|
|
91
89
|
"msnodesqlv8": "^4.1.0 || ^5.0.0",
|
|
92
90
|
"mysql2": "^2.2.5 || ^3.9.4",
|
|
93
91
|
"oracledb": "^6.3.0",
|
|
94
92
|
"pg": "^8.5.1",
|
|
95
93
|
"pg-query-stream": "^3.3.2",
|
|
96
|
-
"better-sqlite3": "^11.8.1",
|
|
97
94
|
"tedious": "^15.1.2 || ^16.0.0 || ^18.1.0 || || ^19.0.0"
|
|
98
95
|
},
|
|
99
96
|
"peerDependenciesMeta": {
|
|
@@ -133,6 +130,7 @@
|
|
|
133
130
|
"@typescript-eslint/eslint-plugin": "^6.x",
|
|
134
131
|
"@typescript-eslint/parser": "^6.x",
|
|
135
132
|
"@vitest/coverage-v8": "^3.2.4",
|
|
133
|
+
"better-sqlite3": "^11.8.1",
|
|
136
134
|
"cors": "^2.8.5",
|
|
137
135
|
"eslint": "^8.57.0",
|
|
138
136
|
"eslint-plugin-jest": "^27.1.7",
|
|
@@ -144,7 +142,6 @@
|
|
|
144
142
|
"pg": "^8.5.1",
|
|
145
143
|
"pg-query-stream": "^3.3.2",
|
|
146
144
|
"rollup": "^2.52.7",
|
|
147
|
-
"better-sqlite3": "^11.8.1",
|
|
148
145
|
"tedious": "^19.0.0",
|
|
149
146
|
"typescript": "^5.4.5",
|
|
150
147
|
"vitest": "^3.2.4"
|