@stackbit/sdk 1.0.20-develop.2 → 1.0.20-staging.1

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.
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const { createRequire } = require('module');
4
+
5
+ // module.exports.dynamicImport = async (absModulePath) => {
6
+ // return await import(absModulePath)
7
+ // }
8
+
9
+ module.exports = async (req) => {
10
+ const { resolve } = createRequire(parentModule());
11
+ const mod = await import(resolve(req));
12
+ return mod;
13
+ };
14
+
15
+ function parentModule(filePath) {
16
+ const stacks = callsites();
17
+
18
+ if (!filePath) {
19
+ return stacks[2].getFileName();
20
+ }
21
+
22
+ let hasSeenValue = false;
23
+
24
+ // Skip the first stack as it's this function
25
+ stacks.shift();
26
+
27
+ for (const stack of stacks) {
28
+ const parentFilePath = stack.getFileName();
29
+
30
+ if (typeof parentFilePath !== 'string') {
31
+ continue;
32
+ }
33
+
34
+ if (parentFilePath === filePath) {
35
+ hasSeenValue = true;
36
+ continue;
37
+ }
38
+
39
+ // Skip native modules
40
+ if (parentFilePath === 'module.js') {
41
+ continue;
42
+ }
43
+
44
+ if (hasSeenValue && parentFilePath !== filePath) {
45
+ return parentFilePath;
46
+ }
47
+ }
48
+ }
49
+
50
+ function callsites() {
51
+ const _prepareStackTrace = Error.prepareStackTrace;
52
+ Error.prepareStackTrace = (_, stack) => stack;
53
+ const stack = new Error().stack.slice(1);
54
+ Error.prepareStackTrace = _prepareStackTrace;
55
+ return stack;
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbit/sdk",
3
- "version": "1.0.20-develop.2",
3
+ "version": "1.0.20-staging.1",
4
4
  "description": "Stackbit SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,8 +35,8 @@
35
35
  "homepage": "https://github.com/stackbit/stackbit-sdk#readme",
36
36
  "dependencies": {
37
37
  "@octokit/rest": "^18.3.5",
38
- "@stackbit/types": "0.11.9-develop.2",
39
- "@stackbit/utils": "0.4.9-develop.2",
38
+ "@stackbit/types": "0.11.9-staging.1",
39
+ "@stackbit/utils": "0.4.9-staging.1",
40
40
  "acorn": "^8.2.4",
41
41
  "chokidar": "^3.5.3",
42
42
  "esbuild": "^0.19.12",
@@ -57,5 +57,5 @@
57
57
  "@types/semver": "^7.3.4",
58
58
  "@types/yargs": "^16.0.0"
59
59
  },
60
- "gitHead": "706448ac139536d5a06d36fd529b7544f3da77a4"
60
+ "gitHead": "3e30561ea41475eb56169316acb8b5605283a8d3"
61
61
  }