@travetto/manifest 3.0.0-rc.10 → 3.0.0-rc.12
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 +4 -1
- package/package.json +1 -1
- package/src/manifest-index.ts +7 -6
- package/src/package.ts +19 -3
- package/src/types.ts +1 -0
- package/src/watch.ts +11 -4
package/bin/context.js
CHANGED
|
@@ -101,6 +101,8 @@ export async function getManifestContext(folder) {
|
|
|
101
101
|
|
|
102
102
|
const moduleType = (await $getPkg(workspacePath)).type ?? 'commonjs';
|
|
103
103
|
const mainFolder = mainPath === workspacePath ? '' : mainPath.replace(`${workspacePath}/`, '');
|
|
104
|
+
/** @type {'yarn'|'npm'} */
|
|
105
|
+
const packageManager = await fs.stat(path.resolve(workspacePath, 'yarn.lock')).then(() => 'yarn', () => 'npm');
|
|
104
106
|
|
|
105
107
|
const res = {
|
|
106
108
|
moduleType,
|
|
@@ -110,7 +112,8 @@ export async function getManifestContext(folder) {
|
|
|
110
112
|
monoRepo,
|
|
111
113
|
outputFolder,
|
|
112
114
|
toolFolder: '.trv_build',
|
|
113
|
-
compilerFolder: '.trv_compiler'
|
|
115
|
+
compilerFolder: '.trv_compiler',
|
|
116
|
+
packageManager
|
|
114
117
|
};
|
|
115
118
|
return res;
|
|
116
119
|
}
|
package/package.json
CHANGED
package/src/manifest-index.ts
CHANGED
|
@@ -301,12 +301,13 @@ export class ManifestIndex {
|
|
|
301
301
|
/**
|
|
302
302
|
* Get local folders that represent the user's controlled input
|
|
303
303
|
*/
|
|
304
|
-
|
|
305
|
-
return this.getLocalModules()
|
|
306
|
-
.
|
|
307
|
-
(!
|
|
308
|
-
|
|
309
|
-
)
|
|
304
|
+
getLocalInputFolderMapping(): [folder: string, moduleSourceRoot: string][] {
|
|
305
|
+
return this.getLocalModules().flatMap(x =>
|
|
306
|
+
((!this.manifest.monoRepo || x.sourcePath !== this.manifest.workspacePath) ?
|
|
307
|
+
[x.sourcePath] : [...Object.keys(x.files)].filter(y => !y.startsWith('$')).map(y => path.resolve(x.sourcePath, y))
|
|
308
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
309
|
+
).map(f => [f, path.resolve(x.sourceFolder)] as [string, string])
|
|
310
|
+
);
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
/**
|
package/src/package.ts
CHANGED
|
@@ -179,9 +179,25 @@ export class PackageUtil {
|
|
|
179
179
|
try {
|
|
180
180
|
return JSON.parse(await fs.readFile(cache, 'utf8'));
|
|
181
181
|
} catch {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
let out: PackageWorkspaceEntry[];
|
|
183
|
+
switch (ctx.packageManager) {
|
|
184
|
+
case 'npm': {
|
|
185
|
+
const text = execSync('npm query .workspace', { cwd: rootPath, encoding: 'utf8', env: { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH } });
|
|
186
|
+
out = JSON.parse(text)
|
|
187
|
+
.map((d: { location: string, name: string }) => ({ sourcePath: d.location, name: d.name }));
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 'yarn': {
|
|
191
|
+
const text = execSync('yarn -s workspaces info', { cwd: rootPath, encoding: 'utf8', env: { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH } });
|
|
192
|
+
out = Object.entries<{ location: string }>(JSON.parse(text))
|
|
193
|
+
.map(([name, { location }]) => ({ sourcePath: location, name }));
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
default: throw new Error(`Unknown package manager: ${ctx.packageManager}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.#workspaces[rootPath] = out;
|
|
200
|
+
|
|
185
201
|
await fs.writeFile(cache, JSON.stringify(out), 'utf8');
|
|
186
202
|
}
|
|
187
203
|
}
|
package/src/types.ts
CHANGED
package/src/watch.ts
CHANGED
|
@@ -22,12 +22,19 @@ async function getWatcher(): Promise<typeof import('@parcel/watcher')> {
|
|
|
22
22
|
* @param onEvent
|
|
23
23
|
* @private
|
|
24
24
|
*/
|
|
25
|
-
export async function watchFolders(
|
|
25
|
+
export async function watchFolders(
|
|
26
|
+
folders: string[] | [folder: string, targetFolder: string][],
|
|
27
|
+
onEvent: WatchEventListener,
|
|
28
|
+
config: WatchConfig = {}
|
|
29
|
+
): Promise<() => Promise<void>> {
|
|
26
30
|
const lib = await getWatcher();
|
|
27
31
|
const createMissing = config.createMissing ?? false;
|
|
28
|
-
const validFolders = new Set(folders);
|
|
32
|
+
const validFolders = new Set(folders.map(x => typeof x === 'string' ? x : x[0]));
|
|
33
|
+
|
|
34
|
+
const subs = await Promise.all(folders.map(async value => {
|
|
35
|
+
const folder = typeof value === 'string' ? value : value[0];
|
|
36
|
+
const targetFolder = typeof value === 'string' ? value : value[1];
|
|
29
37
|
|
|
30
|
-
const subs = await Promise.all(folders.map(async folder => {
|
|
31
38
|
if (await fs.stat(folder).then(() => true, () => createMissing)) {
|
|
32
39
|
await fs.mkdir(folder, { recursive: true });
|
|
33
40
|
const ignore = (await fs.readdir(folder)).filter(x => x.startsWith('.') && x.length > 2);
|
|
@@ -38,7 +45,7 @@ export async function watchFolders(folders: string[], onEvent: WatchEventListene
|
|
|
38
45
|
}
|
|
39
46
|
const finalEv = { action: ev.type, file: ev.path };
|
|
40
47
|
if (!config.filter || config.filter(finalEv)) {
|
|
41
|
-
onEvent(finalEv,
|
|
48
|
+
onEvent(finalEv, targetFolder);
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
}, { ignore: [...ignore, ...config.ignore ?? []] });
|