1 | import fixturify from 'fixturify';
|
2 | import { PackageJson as PackageJson$1 } from 'type-fest';
|
3 |
|
4 | type PackageJson = PackageJson$1 & Record<string, any>;
|
5 | type ProjectCallback = (project: Project) => void;
|
6 | interface ReadDirOpts {
|
7 | linkDeps?: boolean;
|
8 | linkDevDeps?: boolean;
|
9 | }
|
10 | interface ProjectArgs {
|
11 | name?: string;
|
12 | version?: string;
|
13 | files?: fixturify.DirJSON;
|
14 | requestedRange?: string;
|
15 | }
|
16 | declare class Project {
|
17 | pkg: PackageJson;
|
18 | files: fixturify.DirJSON;
|
19 | readonly isDependency = true;
|
20 | private _dependencies;
|
21 | private _devDependencies;
|
22 | private _baseDir;
|
23 | private _tmp;
|
24 | private requestedRange;
|
25 | private dependencyLinks;
|
26 | private linkIsDevDependency;
|
27 | private usingHardLinks;
|
28 | private resolutionCache;
|
29 | constructor(name?: string, version?: string, args?: Omit<ProjectArgs, 'name' | 'version'>, projectCallback?: ProjectCallback);
|
30 | constructor(name?: string, version?: string, args?: Omit<ProjectArgs, 'name' | 'version'>);
|
31 | constructor(name?: string, version?: string, projectCallback?: ProjectCallback);
|
32 | constructor(name?: string, args?: Omit<ProjectArgs, 'name'>, projectCallback?: ProjectCallback);
|
33 | constructor(args?: ProjectArgs, projectCallback?: ProjectCallback);
|
34 | /**
|
35 | * Sets the base directory of the project.
|
36 | *
|
37 | * @memberof Project
|
38 | * @param dir - The directory path.
|
39 | */
|
40 | set baseDir(dir: string);
|
41 | /**
|
42 | * Gets the base directory path, usually a tmp directory unless a baseDir has been explicitly set.
|
43 | *
|
44 | * @readonly
|
45 | * @memberof Project
|
46 | */
|
47 | get baseDir(): string;
|
48 | /**
|
49 | * Gets the package name from the package.json.
|
50 | *
|
51 | * @type {string}
|
52 | * @memberof Project
|
53 | */
|
54 | get name(): string;
|
55 | /**
|
56 | * Sets the package name in the package.json.
|
57 | *
|
58 | * @memberof Project
|
59 | */
|
60 | set name(value: string);
|
61 | /**
|
62 | * Gets the version number from the package.json.
|
63 | *
|
64 | * @type {string}
|
65 | * @memberof Project
|
66 | */
|
67 | get version(): string;
|
68 | /**
|
69 | * Sets the version number in the package.json.
|
70 | *
|
71 | * @memberof Project
|
72 | */
|
73 | set version(value: string);
|
74 | /**
|
75 | * Reads an existing project from the specified base dir.
|
76 | *
|
77 | * @param baseDir - The base directory to read the project from.
|
78 | * @param opts - An options object.
|
79 | * @param opts.linkDeps - Include linking dependencies from the Project's node_modules.
|
80 | * @param opts.linkDevDeps - Include linking devDependencies from the Project's node_modules.
|
81 | * @returns - The deserialized Project.
|
82 | */
|
83 | static fromDir(baseDir: string, opts?: ReadDirOpts): Project;
|
84 | /**
|
85 | * Merges an object containing a directory represention with the existing files.
|
86 | *
|
87 | * @param dirJSON - An object containing a directory representation to merge.
|
88 | */
|
89 | mergeFiles(dirJSON: fixturify.DirJSON): void;
|
90 | /**
|
91 | * Writes the existing files property containing a directory representation to the tmp directory.
|
92 | *
|
93 | * @param dirJSON? - An optional object containing a directory representation to write.
|
94 | */
|
95 | write(dirJSON?: fixturify.DirJSON): Promise<void>;
|
96 | addDependency(name?: string, version?: string, args?: Omit<ProjectArgs, 'name' | 'version'>, projectCallback?: ProjectCallback): Project;
|
97 | addDependency(name?: string, version?: string, projectCallback?: ProjectCallback): Project;
|
98 | addDependency(name?: string, args?: Omit<ProjectArgs, 'name'>, projectCallback?: ProjectCallback): Project;
|
99 | addDependency(args?: ProjectArgs, projectCallback?: ProjectCallback): Project;
|
100 | addDependency(args?: Project, projectCallback?: ProjectCallback): Project;
|
101 | /**
|
102 | * Adds a devDependency to the Project's package.json.
|
103 | *
|
104 | * @returns - The Project instance.
|
105 | */
|
106 | addDevDependency(name?: string, version?: string, args?: Omit<ProjectArgs, 'name' | 'version'>, projectCallback?: ProjectCallback): Project;
|
107 | addDevDependency(name?: string, version?: string, projectCallback?: ProjectCallback): Project;
|
108 | addDevDependency(name?: string, args?: Omit<ProjectArgs, 'name'>, projectCallback?: ProjectCallback): Project;
|
109 | addDevDependency(args?: ProjectArgs, projectCallback?: ProjectCallback): Project;
|
110 | addDevDependency(args?: Project, projectCallback?: ProjectCallback): Project;
|
111 | /**
|
112 | * Removes a dependency to the Project's package.json.
|
113 | *
|
114 | * @param name - The name of the dependency to remove.
|
115 | */
|
116 | removeDependency(name: string): void;
|
117 | /**
|
118 | * Removes a devDependency.
|
119 | *
|
120 | * @param name - The name of the devDependency to remove.
|
121 | */
|
122 | removeDevDependency(name: string): void;
|
123 | /**
|
124 | * Links a dependency.
|
125 | *
|
126 | * @param name - The name of the dependency to link.
|
127 | */
|
128 | linkDependency(name: string, opts: LinkParams): void;
|
129 | /**
|
130 | * Links a devDependency.
|
131 | *
|
132 | * @param name - The name of the dependency to link.
|
133 | */
|
134 | linkDevDependency(name: string, opts: LinkParams): void;
|
135 | /**
|
136 | * @returns - An array of the dependencies for this Projct.
|
137 | */
|
138 | dependencyProjects(): Project[];
|
139 | /**
|
140 | * @returns - An array of the devDependencies for this Projct.
|
141 | */
|
142 | devDependencyProjects(): Project[];
|
143 | /**
|
144 | * @returns - The cloned Project.
|
145 | */
|
146 | clone(): Project;
|
147 | /**
|
148 | * Disposes of the tmp directory that the Project is stored in.
|
149 | */
|
150 | dispose(): void;
|
151 | private writeProject;
|
152 | private assignBaseDirs;
|
153 | private writeFiles;
|
154 | private finalizeWrite;
|
155 | private resolveLinks;
|
156 | private binLinks;
|
157 | private transitivePeersCache;
|
158 | private transitivePeers;
|
159 | private writeLinkedPackage;
|
160 | private knownWorkspaces;
|
161 | private discoverWorkspaces;
|
162 | private publishedPackageContents;
|
163 | private hardLinkContents;
|
164 | private hardLinkFile;
|
165 | private readSync;
|
166 | private addDep;
|
167 | private pkgJSONWithDeps;
|
168 | private depsToObject;
|
169 | }
|
170 | type LinkParams = {
|
171 | baseDir: string;
|
172 | resolveName?: string;
|
173 | requestedRange?: string;
|
174 | } | {
|
175 | target: string;
|
176 | requestedRange?: string;
|
177 | } | {
|
178 | project: Project;
|
179 | requestedRange?: string;
|
180 | };
|
181 |
|
182 | export { LinkParams, Project, ProjectArgs };
|