@travetto/manifest 3.0.0-rc.7 → 3.0.0-rc.8
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/context.js +21 -0
- package/package.json +1 -1
package/bin/context.js
CHANGED
|
@@ -22,6 +22,23 @@ async function $getPkg(inputFolder) {
|
|
|
22
22
|
|
|
23
23
|
const WS_ROOT = {};
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Get module name from a given file
|
|
27
|
+
* @param {string} file
|
|
28
|
+
* @return {Promise<string|void>}
|
|
29
|
+
*/
|
|
30
|
+
async function $getModuleFromFile(file) {
|
|
31
|
+
let dir = path.dirname(file);
|
|
32
|
+
let prev;
|
|
33
|
+
while (dir !== prev && !(await fs.stat(path.resolve(dir, 'package.json')).catch(() => false))) {
|
|
34
|
+
prev = dir;
|
|
35
|
+
dir = path.dirname(dir);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
return (await $getPkg(dir)).name;
|
|
39
|
+
} catch { }
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
/**
|
|
26
43
|
* Get workspace root
|
|
27
44
|
* @return {Promise<string>}
|
|
@@ -60,6 +77,10 @@ export async function getManifestContext(folder) {
|
|
|
60
77
|
|
|
61
78
|
// If manifest specified via env var, and is a package name
|
|
62
79
|
if (!folder && process.env.TRV_MODULE) {
|
|
80
|
+
// If module is actually a file, try to detect
|
|
81
|
+
if (/[.](t|j)s$/.test(process.env.TRV_MODULE)) {
|
|
82
|
+
process.env.TRV_MODULE = await $getModuleFromFile(process.env.TRV_MODULE) ?? process.env.TRV_MODULE;
|
|
83
|
+
}
|
|
63
84
|
const req = createRequire(`${workspacePath}/node_modules`);
|
|
64
85
|
try {
|
|
65
86
|
folder = path.dirname(req.resolve(`${process.env.TRV_MODULE}/package.json`));
|