@bscotch/project
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -32,5 +32,5 @@ import { PackageJson, TsConfig, type DependencyVersion, type PackageJsonDependencyType, type PackageJsonFindOptions, type PackageName, type PackageNameConstructable } from '@bscotch/config'; | ||
get packageJson(): PackageJson<PackageJsonExtension>; | ||
get workspaceProjects(): Project[]; | ||
get name(): PackageName; | ||
get version(): DependencyVersion | undefined; | ||
get centralizedPackageJson(): PackageJson<undefined> | undefined; | ||
srcDir(): Promise<Pathy<unknown>>; | ||
@@ -46,5 +46,3 @@ outDir(): Promise<Pathy<unknown>>; | ||
prepublishOnly?: string | undefined; | ||
prepack?: string | undefined; /** | ||
* The scripts defined in the project's package.json | ||
*/ | ||
prepack?: string | undefined; | ||
postpack?: string | undefined; | ||
@@ -60,6 +58,3 @@ publish?: string | undefined; | ||
preversion?: string | undefined; | ||
version?: string | undefined; /** | ||
* Move this project to another location on disk. | ||
* Moves *all* files, including any npm/gitignored ones. | ||
*/ | ||
version?: string | undefined; | ||
postversion?: string | undefined; | ||
@@ -263,5 +258,3 @@ pretest?: string | undefined; | ||
*/ | ||
updateDependencyListing(dep: string, depType: PackageJsonDependencyType, options: (ProjectBuildOptions & { | ||
onlyUpdateCentral?: boolean; | ||
}) | undefined): Promise<"updated" | "added" | undefined>; | ||
updateDependencyListing(dep: string, depType: PackageJsonDependencyType, options: ProjectBuildOptions | undefined): Promise<"updated" | "added" | undefined>; | ||
/** | ||
@@ -268,0 +261,0 @@ * List all source files found in the project, |
@@ -29,14 +29,4 @@ import type { PackageJsonDependencyType, PackageNameConstructable } from '@bscotch/config'; | ||
* and ensure that's true in all appropriate files (if possible). | ||
* | ||
* Priority order to set: | ||
* 1. If found in options?.localPackages | ||
* 2. If centralizedPackageJson, the version there | ||
* - If that is a local path, follow it to get the version | ||
* - Otherwise use the version directly | ||
* - If not found, throw an error (after updating the current project) | ||
* 3. If none of the above, the version in the current project | ||
*/ | ||
export declare function updateProjectDependencyListing(project: Project, dep: string, depType: PackageJsonDependencyType, options: (ProjectBuildOptions & { | ||
onlyUpdateCentral?: boolean; | ||
}) | undefined): Promise<"updated" | "added" | undefined>; | ||
export declare function updateProjectDependencyListing(project: Project, dep: string, depType: PackageJsonDependencyType, options: ProjectBuildOptions | undefined): Promise<"updated" | "added" | undefined>; | ||
export declare function inferProjectDependencies(project: Project): Promise<ProjectDependencies>; | ||
@@ -43,0 +33,0 @@ /** |
@@ -43,5 +43,17 @@ import { PackageName } from '@bscotch/config'; | ||
...protectFromPruning, | ||
// Ensure that any paired DefinitelyTyped dependencies are kept | ||
...[...includedDeps, ...protectFromPruning].map((d) => `@types/${d}`), | ||
'@bscotch/trebuchet', // This very package! | ||
], | ||
}); | ||
// Ensure `@types/` deps are listed in devDeps | ||
const allDeps = project.packageJson.flattenedDependencies(); | ||
for (const [dep, def] of Object.entries(allDeps)) { | ||
if (dep.startsWith('@types/') && def.type !== 'devDependencies') { | ||
await project.packageJson.addDependency(dep, { | ||
...def, | ||
type: 'devDependencies', | ||
}); | ||
} | ||
} | ||
} | ||
@@ -51,14 +63,5 @@ /** | ||
* and ensure that's true in all appropriate files (if possible). | ||
* | ||
* Priority order to set: | ||
* 1. If found in options?.localPackages | ||
* 2. If centralizedPackageJson, the version there | ||
* - If that is a local path, follow it to get the version | ||
* - Otherwise use the version directly | ||
* - If not found, throw an error (after updating the current project) | ||
* 3. If none of the above, the version in the current project | ||
*/ | ||
export async function updateProjectDependencyListing(project, dep, depType, options) { | ||
const currentVersion = project.packageJson.findDependency(dep); | ||
let version = undefined; | ||
let version = project.packageJson.findDependency(dep)?.version.toString(); | ||
// Check any provided local packages | ||
@@ -70,42 +73,21 @@ if (options?.localPackages) { | ||
ok(!localMatch || localMatchVersion, `No version found for ${dep}`); | ||
version = localMatchVersion ? `^${localMatchVersion}` : undefined; | ||
} | ||
// If no local match, check the centralized package.json | ||
// This dependency *must* be listed there if the centralized | ||
// package.json is used. | ||
if (!version && project.options?.centralizedPackageJson) { | ||
// Does it exist as a local package to resolve? | ||
const localPkg = await project.options.centralizedPackageJson.loadIfLocalDependency(dep); | ||
project.trace(`updateDependencyListing: checking centralizedPackageJson for local dep %s: is local? %o`, dep, !!localPkg); | ||
if (localPkg) { | ||
ok(localPkg.version, `No version found for ${dep} in ${localPkg.path}`); | ||
project.trace(`updateDependencyListing: using centralizedPackageJson for dep %s: %o`, dep, !!localPkg); | ||
version = `^${localPkg.version}`; | ||
if (localMatch && project.packageJson.packageManager === 'npm') { | ||
version = localMatchVersion ? `^${localMatchVersion}` : undefined; | ||
} | ||
else { | ||
// Then it's 3rd party. If the central package doesn't | ||
// list it at all, then we need to add it if we have a valid | ||
// version. | ||
const centralVersion = project.options.centralizedPackageJson.findDependency(dep)?.version; | ||
if (!centralVersion && currentVersion) { | ||
await project.options.centralizedPackageJson.addDependency(dep, { | ||
version: currentVersion.version, | ||
}); | ||
} | ||
else if (centralVersion) { | ||
// Don't need to add the ^ prefix, since the version | ||
// string could be of any type except `file:` | ||
version = centralVersion.toString(); | ||
} | ||
else { | ||
throw new Error(`No version found for ${dep} in ${project.options.centralizedPackageJson.path}`); | ||
} | ||
else if (localMatch) { | ||
version = 'workspace:^'; | ||
} | ||
} | ||
// Finally, if still no version found the version is whatever | ||
// we have in the current project's package.json | ||
version ||= currentVersion?.version.toString(); | ||
// If we don't have a version yet, check workspace | ||
// projects (if they exist) for a matching dep and | ||
// use that version. | ||
for (const otherProject of project.workspaceProjects) { | ||
if (version || otherProject.name.toString() === project.name.toString()) { | ||
continue; | ||
} | ||
version = otherProject.packageJson.findDependency(dep)?.version.toString(); | ||
} | ||
// WHEW. If we don't have a version after all of that, then | ||
// this dependency is not listed ANYWHERE. | ||
ok(version, `No version found for ${dep} in any provided or discovered project`); | ||
ok(version, `No version found for ${dep}.`); | ||
// Ensure that the current project has this same version | ||
@@ -112,0 +94,0 @@ return await project.packageJson.addDependency(dep, { |
@@ -1,2 +0,1 @@ | ||
import { DependencyVersion } from '@bscotch/config'; | ||
import { Pathy } from '@bscotch/pathy'; | ||
@@ -197,9 +196,4 @@ import '@bscotch/utility'; | ||
dir: newProjectDir, | ||
centralizedPackageJson: sourceProject.centralizedPackageJson, | ||
}); | ||
await newProject.updateDependencyListings(); | ||
await sourceProject.centralizedPackageJson?.addDependency(newProject.packageJson, { | ||
version: DependencyVersion.fromLocalPath(newProject.dir.relativeFrom(sourceProject.centralizedPackageJson.dir)), | ||
}); | ||
// await sourceProject.centralizedPackageJson?.install(newProject.packageJson); | ||
await newProject.updateDependencyListings(); | ||
@@ -206,0 +200,0 @@ await sourceProject.packageJson.addDependency(newProject.name, { |
@@ -11,3 +11,6 @@ import { Pathy } from '@bscotch/pathy'; | ||
export async function fixProjectSourceFiles(project, options) { | ||
const pkgJsonFixWait = options.packageJson && project.updateDependencyListings(); | ||
const pkgJsonFixWait = options.packageJson && | ||
project.updateDependencyListings({ | ||
localPackages: project.workspaceProjects, | ||
}); | ||
const morpher = await project.codeMorpher(); | ||
@@ -14,0 +17,0 @@ for (let sourceFile of morpher.getSourceFiles()) { |
@@ -45,2 +45,5 @@ var Project_1; | ||
} | ||
get workspaceProjects() { | ||
return this.options?.workspaceProjects || []; | ||
} | ||
get name() { | ||
@@ -52,5 +55,2 @@ return this.packageJson.name; | ||
} | ||
get centralizedPackageJson() { | ||
return this.options?.centralizedPackageJson; | ||
} | ||
async srcDir() { | ||
@@ -310,11 +310,4 @@ return await (await this.tsconfig()).srcDir(); | ||
__decorate([ | ||
trace, | ||
memoize, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [Object]), | ||
__metadata("design:returntype", Promise) | ||
], Project.prototype, "updateDependencyListings", null); | ||
__decorate([ | ||
memoize, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
@@ -321,0 +314,0 @@ __metadata("design:returntype", Promise) |
@@ -10,17 +10,7 @@ import type { PackageJson, PackageJsonData } from '@bscotch/config'; | ||
/** | ||
* A `package.json` file that isn't directly used by this | ||
* project, but that should include the same dependencies | ||
* and dependency versions as this project. It may also | ||
* contain *other* dependencies not included in this project. | ||
* | ||
* Any dependencies found in the current project will be added | ||
* to the shared `package.json` file if missing. Any dependencies | ||
* found in both will have their versions forced to match the shared | ||
* `package.json`'s version. | ||
* | ||
* Useful for monorepo cases, where a root `package.json` file | ||
* provides a cumulative dependency list and sets the common versions | ||
* across projects. | ||
* The names of other projects sharing | ||
* a workspace with this one. Used for | ||
* resolving dependencies. | ||
*/ | ||
centralizedPackageJson?: PackageJson; | ||
workspaceProjects?: Project[]; | ||
} | ||
@@ -63,6 +53,2 @@ /** | ||
* determine the appropriate version to specify. | ||
* | ||
* This is optional if {@link centralizedPackageJson} is provided, | ||
* and if that `PackageJson` file lists the local dependencies | ||
* using filepath versions. | ||
*/ | ||
@@ -69,0 +55,0 @@ localPackages?: Project[]; |
{ | ||
"name": "@bscotch/project", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"type": "module", | ||
@@ -19,6 +19,6 @@ "exports": { | ||
"dependencies": { | ||
"@bscotch/config": "^0.5.1", | ||
"@bscotch/pathy": "^2.1.0", | ||
"@bscotch/utility": "^6.1.1", | ||
"@bscotch/validation": "^0.2.0", | ||
"@bscotch/config": "workspace:^", | ||
"@bscotch/pathy": "workspace:^", | ||
"@bscotch/utility": "workspace:^", | ||
"@bscotch/validation": "workspace:^", | ||
"chalk": "^5.0.1", | ||
@@ -34,2 +34,5 @@ "dependency-graph": "^0.11.0", | ||
"devDependencies": { | ||
"@types/diff": "^5.0.2", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/source-map-support": "^0.5.4", | ||
"type-fest": "^2.16.0", | ||
@@ -36,0 +39,0 @@ "typescript": "^4.8.0-beta" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
135137
5
2174
- Removed@bscotch/config@0.5.1(transitive)
- Removed@bscotch/emitter@0.2.0(transitive)
- Removed@bscotch/pathy@2.12.1(transitive)
- Removed@bscotch/utility@6.8.47.2.0(transitive)
- Removed@bscotch/validation@0.2.5(transitive)
- Removed@types/glob@7.2.0(transitive)
- Removed@types/minimatch@5.1.2(transitive)
- Removed@types/node@22.13.5(transitive)
- Removedajv@8.12.0(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedassertion-error@1.1.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcamel-case@4.1.2(transitive)
- Removedcapital-case@1.0.4(transitive)
- Removedchai@4.5.0(transitive)
- Removedchalk@5.2.0(transitive)
- Removedchange-case@4.1.2(transitive)
- Removedcheck-error@1.0.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconstant-case@3.0.4(transitive)
- Removeddebug@4.3.4(transitive)
- Removeddeep-eql@4.1.4(transitive)
- Removeddetect-indent@6.1.0(transitive)
- Removeddetect-newline@3.1.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removeddot-case@3.0.4(transitive)
- Removedeventemitter2@6.4.9(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfs-extra@11.1.1(transitive)
- Removedget-func-name@2.0.2(transitive)
- Removedgit-hooks-list@1.0.3(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobby@10.0.013.2.2(transitive)
- Removedheader-case@2.0.4(transitive)
- Removedignore@5.3.2(transitive)
- Removedignore-walk@5.0.1(transitive)
- Removedjson-schema-traverse@1.0.0(transitive)
- Removedjson5@2.2.3(transitive)
- Removedloupe@2.3.7(transitive)
- Removedlower-case@2.0.2(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedms@2.1.2(transitive)
- Removedno-case@3.0.4(transitive)
- Removednpm-bundled@2.0.1(transitive)
- Removednpm-normalize-package-bin@2.0.0(transitive)
- Removednpm-packlist@5.1.3(transitive)
- Removedparam-case@3.0.4(transitive)
- Removedpascal-case@3.1.2(transitive)
- Removedpath-case@3.0.4(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpathval@1.1.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedrequire-from-string@2.0.2(transitive)
- Removedsemver@7.7.1(transitive)
- Removedsentence-case@3.0.4(transitive)
- Removedslash@3.0.04.0.0(transitive)
- Removedsnake-case@3.0.4(transitive)
- Removedsort-object-keys@1.1.3(transitive)
- Removedsort-package-json@1.57.0(transitive)
- Removedtype-detect@4.1.0(transitive)
- Removedtype-fest@2.19.0(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedupper-case@2.0.2(transitive)
- Removedupper-case-first@2.0.2(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedyaml@2.3.2(transitive)
Updated@bscotch/config@workspace:^
Updated@bscotch/pathy@workspace:^
Updated@bscotch/utility@workspace:^