positron.js 1.0.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/extensions.js ADDED
@@ -0,0 +1,42 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { info } = require("./logs");
4
+
5
+
6
+ class PositronRegistry {
7
+
8
+ /**
9
+ * PositronRegistry is responsible for discovering native extensions in a Positron application.
10
+ * @internal
11
+ */
12
+ constructor(appRoot) {
13
+ this.appRoot = appRoot;
14
+ this.nativeExtensions = [];
15
+ }
16
+
17
+ discover() {
18
+ const rootPackagePath = path.join(this.appRoot, "package.json");
19
+ if (!fs.existsSync(rootPackagePath)) return;
20
+
21
+ const rootPackage = JSON.parse(fs.readFileSync(rootPackagePath, "utf8"));
22
+ const dependencies = Object.keys(rootPackage.dependencies || {});
23
+
24
+ for (const dep of dependencies) {
25
+ const depPackagePath = path.join(this.appRoot, "node_modules", dep, "package.json");
26
+
27
+ if (fs.existsSync(depPackagePath)) {
28
+ const depPackage = JSON.parse(fs.readFileSync(depPackagePath, "utf8"));
29
+
30
+ if (depPackage.positron) {
31
+ const depDir = path.dirname(depPackagePath);
32
+ this.nativeExtensions.push({
33
+ name: depPackage.positron.command,
34
+ sourceFile: path.join(depDir, depPackage.positron.platforms[process.platform])
35
+ });
36
+ }
37
+ }
38
+ }
39
+
40
+ info(`Discovered ${this.nativeExtensions.length} native Positron extensions.`);
41
+ }
42
+ }
package/findpackage.js ADDED
@@ -0,0 +1,34 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function findNearestPackageJson(startDir = process.cwd()) {
5
+ let currentDir = path.resolve(startDir);
6
+ const root = path.parse(currentDir).root;
7
+
8
+ while (true) {
9
+ const pkgPath = path.join(currentDir, 'package.json');
10
+
11
+ if (fs.existsSync(pkgPath)) {
12
+ try {
13
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
14
+
15
+ return {
16
+ path: pkgPath,
17
+ dir: currentDir,
18
+ packageJson: pkg,
19
+ };
20
+ } catch (err) {
21
+ throw new Error(`Invalid package.json at ${pkgPath}`);
22
+ }
23
+ }
24
+
25
+ if (currentDir === root) {
26
+ return null;
27
+ }
28
+
29
+ currentDir = path.dirname(currentDir);
30
+ }
31
+ }
32
+
33
+
34
+ module.exports = findNearestPackageJson;