@travetto/manifest 7.1.2 → 7.1.3
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/README.md +1 -1
- package/package.json +1 -1
- package/src/context.ts +7 -1
- package/src/package.ts +10 -55
- package/src/types/package.ts +7 -4
package/README.md
CHANGED
|
@@ -134,7 +134,7 @@ The context contains:
|
|
|
134
134
|
* The location where all compiled code will be stored. Defaults to: `.trv_output`. (*Can be overridden in your [Package JSON](https://docs.npmjs.com/cli/v9/configuring-npm/package-json) in 'travetto.outputFolder'*)
|
|
135
135
|
* The location where the intermediate compiler will be created. Defaults to: `.trv_compiler`
|
|
136
136
|
* The location where tooling will be able to write to. Defaults to: `.trv_output`
|
|
137
|
-
* Which package manager is in use [Npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
|
|
137
|
+
* Which package manager is in use [Npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)/[Yarn](https://yarnpkg.com)
|
|
138
138
|
* The main module version
|
|
139
139
|
* The main module description
|
|
140
140
|
* The framework version (based on @travetto/manifest)
|
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -41,11 +41,17 @@ function findPackage(base: string, pred: (_p?: Pkg) => boolean): Pkg {
|
|
|
41
41
|
return pkg;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const WORKSPACE_FILES = PACKAGE_MANAGERS.map(x => x.workspaceFile!).filter(Boolean);
|
|
45
|
+
|
|
44
46
|
/**
|
|
45
47
|
* Gets build context
|
|
46
48
|
*/
|
|
47
49
|
export function getManifestContext(root: string = process.cwd()): ManifestContext {
|
|
48
|
-
const workspace = findPackage(root, pkg =>
|
|
50
|
+
const workspace = findPackage(root, pkg =>
|
|
51
|
+
!!pkg?.workspaces ||
|
|
52
|
+
!!pkg?.travetto?.build?.isolated ||
|
|
53
|
+
(!!pkg && WORKSPACE_FILES.some(file => existsSync(path.resolve(pkg.path, file))))
|
|
54
|
+
);
|
|
49
55
|
if (workspace.type !== 'module') {
|
|
50
56
|
throw new Error('Only ESM modules are supported, package.json must be of type module');
|
|
51
57
|
}
|
package/src/package.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { existsSync } from 'node:fs';
|
|
|
5
5
|
import path from './path.ts';
|
|
6
6
|
import { ManifestFileUtil } from './file.ts';
|
|
7
7
|
|
|
8
|
-
import { PackagePathSymbol, type Package, type PackageWorkspaceEntry
|
|
8
|
+
import { PackagePathSymbol, type Package, type PackageWorkspaceEntry } from './types/package.ts';
|
|
9
9
|
import type { ManifestContext } from './types/context.ts';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -17,12 +17,6 @@ export class PackageUtil {
|
|
|
17
17
|
static #cache: Record<string, Package> = {};
|
|
18
18
|
static #workspaces: Record<string, PackageWorkspaceEntry[]> = {};
|
|
19
19
|
|
|
20
|
-
static #exec<T>(workingDirectory: string, cmd: string): Promise<T> {
|
|
21
|
-
const env = { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH };
|
|
22
|
-
const text = execSync(cmd, { cwd: workingDirectory, encoding: 'utf8', env, stdio: ['pipe', 'pipe'] }).toString().trim();
|
|
23
|
-
return JSON.parse(text);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
20
|
/**
|
|
27
21
|
* Resolve import given a manifest context
|
|
28
22
|
*/
|
|
@@ -101,58 +95,19 @@ export class PackageUtil {
|
|
|
101
95
|
try {
|
|
102
96
|
return this.#workspaces[rootPath] ??= ManifestFileUtil.readAsJsonSync<PackageWorkspaceEntry[]>(cache);
|
|
103
97
|
} catch {
|
|
104
|
-
let
|
|
98
|
+
let args: string[];
|
|
105
99
|
switch (ctx.workspace.manager) {
|
|
106
100
|
case 'yarn':
|
|
107
|
-
case 'npm':
|
|
108
|
-
|
|
109
|
-
out = workspaces.map(module => ({ path: path.resolve(ctx.workspace.path, module.location), name: module.name }));
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
101
|
+
case 'npm': args = ['query', '.workspace']; break;
|
|
102
|
+
case 'pnpm': args = ['ls', '-r', '--depth', '-1', '--json']; break;
|
|
112
103
|
}
|
|
113
|
-
await ManifestFileUtil.bufferedFileWrite(cache, JSON.stringify(out));
|
|
114
|
-
return out;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
104
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
case 'npm': install = `npm install ${production ? '' : '--save-dev '}${pkg}`; break;
|
|
125
|
-
case 'yarn': install = `yarn add ${production ? '' : '--dev '}${pkg}`; break;
|
|
105
|
+
const env = { PATH: process.env.PATH, NODE_PATH: process.env.NODE_PATH };
|
|
106
|
+
const text = execSync(`${ctx.workspace.manager} ${args.join(' ')}`, { cwd: rootPath, encoding: 'utf8', env, stdio: ['pipe', 'pipe'] });
|
|
107
|
+
const out: PackageWorkspaceEntry[] = JSON.parse(text.trim());
|
|
108
|
+
const filtered = out.map(item => ({ name: item.name, path: item.path }));
|
|
109
|
+
await ManifestFileUtil.bufferedFileWrite(cache, JSON.stringify(filtered));
|
|
110
|
+
return filtered;
|
|
126
111
|
}
|
|
127
|
-
return install;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Get an the command for executing a package level binary
|
|
132
|
-
*/
|
|
133
|
-
static getPackageCommand(ctx: { workspace: { manager: NodePackageManager } }, pkg: string, args: string[] = []): string {
|
|
134
|
-
switch (ctx.workspace.manager) {
|
|
135
|
-
case 'npm':
|
|
136
|
-
case 'yarn': return `npx ${pkg} ${args.join(' ')}`.trim();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Get an the command for executing a package level binary
|
|
142
|
-
*/
|
|
143
|
-
static getWorkspaceInitCommand(ctx: { workspace: { manager: NodePackageManager } }): string {
|
|
144
|
-
switch (ctx.workspace.manager) {
|
|
145
|
-
case 'npm': return 'npm init -f';
|
|
146
|
-
case 'yarn': return 'yarn init -y';
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Get install example for a given package
|
|
152
|
-
*/
|
|
153
|
-
static getInstallInstructions(pkg: string, production = false): string {
|
|
154
|
-
return (['npm', 'yarn'] as const)
|
|
155
|
-
.map(cmd => this.getInstallCommand({ workspace: { manager: cmd } }, pkg, production))
|
|
156
|
-
.join('\n\n# or\n\n');
|
|
157
112
|
}
|
|
158
113
|
}
|
package/src/types/package.ts
CHANGED
|
@@ -3,12 +3,15 @@ import type { ManifestContext } from './context.ts';
|
|
|
3
3
|
|
|
4
4
|
export const PackagePathSymbol = Symbol.for('@travetto/manifest:package-path');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
{ lock: '
|
|
8
|
-
{ lock: '
|
|
6
|
+
const ALL_PACKAGE_MANAGERS = [
|
|
7
|
+
{ lock: 'package-lock.json', type: 'npm', title: 'Npm', workspaceFile: undefined, active: true },
|
|
8
|
+
{ lock: 'yarn.lock', type: 'yarn', title: 'Yarn', workspaceFile: undefined, active: true },
|
|
9
|
+
{ lock: 'pnpm-lock.yaml', type: 'pnpm', workspaceFile: 'pnpm-workspace.yaml', title: 'Pnpm', active: false }
|
|
9
10
|
] as const;
|
|
10
11
|
|
|
11
|
-
export type NodePackageManager = (typeof
|
|
12
|
+
export type NodePackageManager = (typeof ALL_PACKAGE_MANAGERS)[number]['type'];
|
|
13
|
+
|
|
14
|
+
export const PACKAGE_MANAGERS = ALL_PACKAGE_MANAGERS.filter(manager => manager.active);
|
|
12
15
|
|
|
13
16
|
export type Package = {
|
|
14
17
|
[PackagePathSymbol]?: string;
|