Skip to content

Commit

Permalink
Merge pull request #85 from lolmaus/maintenance
Browse files Browse the repository at this point in the history
Bump Node to 16, drop deprecated methods
  • Loading branch information
ef4 committed Aug 3, 2023
2 parents 69d069e + cb5802d commit b330516
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
node: ['14', '16', '18']
node: ['16', '18']
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v2
Expand Down
45 changes: 13 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ project.addDependency('chai', '5.2.0');
project.pkg; // => the contents of package.json for the given project
project.files; // => read or write the set of files further

// if you don't set this, a new temp dir will be made for you when you writeSync()
project.baseDir = 'some/root/';
// if you don't set this, a new temp dir will be made for you when you write()
project.baseDir = 'some/base/dir/';

await project.write();

// after writeSync(), you can read project.baseDir even if you didn't set it
// after write(), you can read project.baseDir even if you didn't set it
expect(fs.existsSync(join(project.baseDir, 'index.js'))).to.eql(true);
```

The above example produces the following files (and most importantly the
appropriate file contents:

```sh
some/root/package.json
some/root/index.js
some/root/node_modules/mocha/package.json
some/root/node_modules/chai/package.json
some/base/dir/package.json
some/base/dir/index.js
some/base/dir/node_modules/mocha/package.json
some/base/dir/node_modules/chai/package.json
```

### Nesting Dependencies
Expand Down Expand Up @@ -136,16 +136,14 @@ appropriate for apps) you can use `linkDevDeps` instead.
- [Linking to real dependencies](#linking-to-real-dependencies)
- [API](#api)
- [Project](#project)
- [~~project.root~~](#projectroot)
- [project.baseDir](#projectbasedir)
- [project.baseDir](#projectbasedir-1)
- [project.name : <code>string</code>](#projectname--string)
- [project.name : string](#projectname--string)
- [project.name](#projectname)
- [project.version : <code>string</code>](#projectversion--string)
- [project.version : string](#projectversion--string)
- [project.version](#projectversion)
- [project.mergeFiles(dirJSON)](#projectmergefilesdirjson)
- [project.write(dirJSON?)](#projectwritedirjson)
- [~~project.writeSync()~~](#projectwritesync)
- [project.addDependency() ⇒](#projectadddependency-)
- [project.addDevDependency() ⇒](#projectadddevdependency-)
- [project.removeDependency(name)](#projectremovedependencyname)
Expand All @@ -156,16 +154,7 @@ appropriate for apps) you can use `linkDevDeps` instead.
- [project.devDependencyProjects() ⇒](#projectdevdependencyprojects-)
- [project.clone() ⇒](#projectclone-)
- [project.dispose()](#projectdispose)
- [Project.fromDir(root, opts) ⇒](#projectfromdirroot-opts-)

<a name="Project+root"></a>

### ~~project.root~~
***Deprecated***

**Kind**: instance property of [<code>Project</code>](#Project)
**Read only**: true
<a name="Project+baseDir"></a>
- [Project.fromDir(baseDir, opts) ⇒](#projectfromdirbasedir-opts-)

### project.baseDir
<p>Sets the base directory of the project.</p>
Expand Down Expand Up @@ -229,14 +218,6 @@ appropriate for apps) you can use `linkDevDeps` instead.
| --- | --- |
| dirJSON? | <p>An optional object containing a directory representation to write.</p> |

<a name="Project+writeSync"></a>

### ~~project.writeSync()~~
***Deprecated***

**Kind**: instance method of [<code>Project</code>](#Project)
<a name="Project+addDependency"></a>

### project.addDependency() ⇒
<p>Adds a dependency to the Project's package.json.</p>

Expand Down Expand Up @@ -326,8 +307,8 @@ appropriate for apps) you can use `linkDevDeps` instead.
**Kind**: instance method of [<code>Project</code>](#Project)
<a name="Project.fromDir"></a>

### Project.fromDir(root, opts) ⇒
<p>Reads an existing project from the specified root.</p>
### Project.fromDir(baseDir, opts) ⇒
<p>Reads an existing project from the specified base dir.</p>

**Kind**: static method of [<code>Project</code>](#Project)
**Returns**: <ul>
Expand All @@ -336,7 +317,7 @@ appropriate for apps) you can use `linkDevDeps` instead.

| Param | Description |
| --- | --- |
| root | <p>The base directory to read the project from.</p> |
| baseDir | <p>The base directory to read the project from.</p> |
| opts | <p>An options object.</p> |
| opts.linkDeps | <p>Include linking dependencies from the Project's node_modules.</p> |
| opts.linkDevDeps | <p>Include linking devDependencies from the Project's node_modules.</p> |
Expand Down
39 changes: 8 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import CacheGroup from 'resolve-package-path/lib/cache-group.js';
import binLinks from 'bin-links';
import { PackageJson as BasePackageJson } from 'type-fest';
import walkSync from 'walk-sync';
import { deprecate } from 'util';
import deepmerge from 'deepmerge';
const { entries } = walkSync;

Expand Down Expand Up @@ -134,16 +133,6 @@ export class Project {
}
}

/**
* @deprecated Please use baseDir instead.
*
* @readonly
* @memberof Project
*/
get root() {
throw new Error('.root has been removed, please review the readme but you likely actually want .baseDir now');
}

/**
* Sets the base directory of the project.
*
Expand Down Expand Up @@ -210,17 +199,17 @@ export class Project {
}

/**
* Reads an existing project from the specified root.
* Reads an existing project from the specified base dir.
*
* @param root - The base directory to read the project from.
* @param baseDir - The base directory to read the project from.
* @param opts - An options object.
* @param opts.linkDeps - Include linking dependencies from the Project's node_modules.
* @param opts.linkDevDeps - Include linking devDependencies from the Project's node_modules.
* @returns - The deserialized Project.
*/
static fromDir(root: string, opts?: ReadDirOpts): Project {
static fromDir(baseDir: string, opts?: ReadDirOpts): Project {
let project = new Project();
project.readSync(root, opts);
project.readSync(baseDir, opts);
return project;
}

Expand Down Expand Up @@ -248,13 +237,6 @@ export class Project {
await this.binLinks();
}

/**
* @deprecated Please use `await project.write()` instead.
*/
writeSync() {
this.writeProject();
}

addDependency(
name?: string,
version?: string,
Expand Down Expand Up @@ -571,8 +553,8 @@ export class Project {
fs.copyFileSync(source, destination, fs.constants.COPYFILE_FICLONE | fs.constants.COPYFILE_EXCL);
}

private readSync(root: string, opts?: ReadDirOpts): void {
const files = fixturify.readSync(root, {
private readSync(baseDir: string, opts?: ReadDirOpts): void {
const files = fixturify.readSync(baseDir, {
// when linking deps, we don't need to crawl all of node_modules
ignore: opts?.linkDeps || opts?.linkDevDeps ? ['node_modules'] : [],
});
Expand All @@ -585,12 +567,12 @@ export class Project {
if (opts?.linkDeps || opts?.linkDevDeps) {
if (this.pkg.dependencies) {
for (let dep of Object.keys(this.pkg.dependencies)) {
this.linkDependency(dep, { baseDir: root });
this.linkDependency(dep, { baseDir });
}
}
if (this.pkg.devDependencies && opts.linkDevDeps) {
for (let dep of Object.keys(this.pkg.devDependencies)) {
this.linkDevDependency(dep, { baseDir: root });
this.linkDevDependency(dep, { baseDir });
}
}
} else {
Expand Down Expand Up @@ -819,11 +801,6 @@ function readPackages(modulesPath: string): { pkg: PackageJson; path: string }[]
return pkgs;
}

Project.prototype.writeSync = deprecate(
Project.prototype.writeSync,
'project.writeSync() is deprecated. Use await project.write() instead'
);

export type LinkParams =
| { baseDir: string; resolveName?: string; requestedRange?: string }
| { target: string; requestedRange?: string }
Expand Down

0 comments on commit b330516

Please sign in to comment.