@travetto/manifest 3.0.0-rc.11 → 3.0.0-rc.13

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 CHANGED
@@ -101,16 +101,19 @@ 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,
107
- mainModule,
109
+ mainModule: mainModule ?? 'untitled', // When root package.json is missing a name
108
110
  mainFolder,
109
111
  workspacePath,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/manifest",
3
- "version": "3.0.0-rc.11",
3
+ "version": "3.0.0-rc.13",
4
4
  "description": "Manifest support",
5
5
  "keywords": [
6
6
  "path",
@@ -305,6 +305,7 @@ export class ManifestIndex {
305
305
  return this.getLocalModules().flatMap(x =>
306
306
  ((!this.manifest.monoRepo || x.sourcePath !== this.manifest.workspacePath) ?
307
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
308
309
  ).map(f => [f, path.resolve(x.sourceFolder)] as [string, string])
309
310
  );
310
311
  }
package/src/package.ts CHANGED
@@ -91,10 +91,14 @@ export class PackageUtil {
91
91
  if (forceRead) {
92
92
  delete this.#cache[modulePath];
93
93
  }
94
- return this.#cache[modulePath] ??= JSON.parse(readFileSync(
94
+ const res = this.#cache[modulePath] ??= JSON.parse(readFileSync(
95
95
  modulePath.endsWith('.json') ? modulePath : path.resolve(modulePath, 'package.json'),
96
96
  'utf8'
97
97
  ));
98
+
99
+ res.name ??= 'untitled'; // If a package.json (root-only) is missing a name, allows for npx execution
100
+
101
+ return res;
98
102
  }
99
103
 
100
104
  /**
@@ -179,9 +183,25 @@ export class PackageUtil {
179
183
  try {
180
184
  return JSON.parse(await fs.readFile(cache, 'utf8'));
181
185
  } catch {
182
- const text = execSync('npm query .workspace', { cwd: rootPath, encoding: 'utf8', env: { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH } });
183
- const res: { location: string, name: string }[] = JSON.parse(text);
184
- const out = this.#workspaces[rootPath] = res.map(d => ({ sourcePath: d.location, name: d.name }));
186
+ let out: PackageWorkspaceEntry[];
187
+ switch (ctx.packageManager) {
188
+ case 'npm': {
189
+ const text = execSync('npm query .workspace', { cwd: rootPath, encoding: 'utf8', env: { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH } });
190
+ out = JSON.parse(text)
191
+ .map((d: { location: string, name: string }) => ({ sourcePath: d.location, name: d.name }));
192
+ break;
193
+ }
194
+ case 'yarn': {
195
+ const text = execSync('yarn -s workspaces info', { cwd: rootPath, encoding: 'utf8', env: { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH } });
196
+ out = Object.entries<{ location: string }>(JSON.parse(text))
197
+ .map(([name, { location }]) => ({ sourcePath: location, name }));
198
+ break;
199
+ }
200
+ default: throw new Error(`Unknown package manager: ${ctx.packageManager}`);
201
+ }
202
+
203
+ this.#workspaces[rootPath] = out;
204
+
185
205
  await fs.writeFile(cache, JSON.stringify(out), 'utf8');
186
206
  }
187
207
  }
package/src/types.ts CHANGED
@@ -34,6 +34,7 @@ export type ManifestContext = {
34
34
  compilerFolder: string;
35
35
  monoRepo?: boolean;
36
36
  moduleType: 'module' | 'commonjs';
37
+ packageManager: 'yarn' | 'npm';
37
38
  };
38
39
 
39
40
  export type ManifestRoot = ManifestContext & {
package/src/watch.ts CHANGED
@@ -22,7 +22,11 @@ async function getWatcher(): Promise<typeof import('@parcel/watcher')> {
22
22
  * @param onEvent
23
23
  * @private
24
24
  */
25
- export async function watchFolders(folders: string[] | [folder: string, targetFolder: string][], onEvent: WatchEventListener, config: WatchConfig = {}): Promise<() => Promise<void>> {
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
32
  const validFolders = new Set(folders.map(x => typeof x === 'string' ? x : x[0]));