@travetto/manifest 3.0.0-rc.7 → 3.0.0-rc.9
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/src/package.ts +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`));
|
package/package.json
CHANGED
package/src/package.ts
CHANGED
|
@@ -171,7 +171,7 @@ export class PackageUtil {
|
|
|
171
171
|
try {
|
|
172
172
|
return JSON.parse(await fs.readFile(cache, 'utf8'));
|
|
173
173
|
} catch {
|
|
174
|
-
const text = execSync('npm query .workspace', { cwd: rootPath, encoding: 'utf8', env: {} });
|
|
174
|
+
const text = execSync('npm query .workspace', { cwd: rootPath, encoding: 'utf8', env: { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH } });
|
|
175
175
|
const res: { location: string, name: string }[] = JSON.parse(text);
|
|
176
176
|
const out = this.#workspaces[rootPath] = res.map(d => ({ sourcePath: d.location, name: d.name }));
|
|
177
177
|
await fs.writeFile(cache, JSON.stringify(out), 'utf8');
|