-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support package.yaml and package.json5
- Loading branch information
Showing
71 changed files
with
1,745 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017-2019 Zoltan Kochan | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# find-packages | ||
|
||
> Find all packages inside a directory | ||
<!--@shields('npm')--> | ||
[![npm version](https://img.shields.io/npm/v/find-packages.svg)](https://www.npmjs.com/package/find-packages) | ||
<!--/@--> | ||
|
||
## Installation | ||
|
||
```sh | ||
<npm|yarn|pnpm> add find-packages | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
const path = require('path') | ||
const findPkgs = require('find-packages') | ||
|
||
findPkgs(path.join(__dirname, 'test', 'fixture')) | ||
.then(pkgs => console.log(pkgs)) | ||
.catch(err => console.error(err)) | ||
//> [ { path: '/home/zkochan/src/find-packages/test/fixture/pkg', | ||
// manifest: { name: 'foo', version: '1.0.0' }, | ||
// writeImporterManifest: [AsyncFunction] } ] | ||
``` | ||
|
||
## API | ||
|
||
### `findPackages(dir, [opts])` | ||
|
||
#### `dir` | ||
|
||
The directory in which to search for packages. | ||
|
||
#### `opts` | ||
|
||
Parameters normally passed to [glob](https://www.npmjs.com/package/glob) | ||
|
||
#### `opts.patterns` | ||
|
||
Array of globs to use as package locations. For example: `['packages/**', 'utils/**']`. | ||
|
||
#### `opts.ignore` | ||
|
||
Patterns to ignore when searching for packages. By default: `**/node_modules/**`, `**/bower_components/**`, `**/test/**`, `**/tests/**`. | ||
|
||
## License | ||
|
||
[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const path = require('path') | ||
const findPkgs = require('find-packages') | ||
|
||
findPkgs(path.join(__dirname, 'test/fixtures/one-pkg')) | ||
.then(pkgs => console.log(pkgs)) | ||
.catch(err => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "find-packages", | ||
"version": "4.0.1", | ||
"description": "Find all packages inside a directory", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"typings": "lib/index.d.ts", | ||
"scripts": { | ||
"lint": "tslint -c tslint.json src/**/*.ts test/**/*.ts", | ||
"test": "npm run tsc && npm run lint && ts-node test --type-check", | ||
"tsc": "tsc", | ||
"prepublishOnly": "npm run tsc", | ||
"md": "mos" | ||
}, | ||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/find-packages", | ||
"keywords": [ | ||
"find", | ||
"package" | ||
], | ||
"mos": { | ||
"plugins": [ | ||
"readme" | ||
], | ||
"installation": { | ||
"useShortAlias": true | ||
} | ||
}, | ||
"author": { | ||
"name": "Zoltan Kochan", | ||
"email": "z@kochan.io", | ||
"url": "https://www.kochan.io" | ||
}, | ||
"engines": { | ||
"node": ">=8.15" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/pnpm/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/find-packages#readme", | ||
"devDependencies": { | ||
"@pnpm/tslint-config": "0.0.0", | ||
"@types/tape": "^4.2.29", | ||
"find-packages": "link:", | ||
"mos": "^2.0.0-alpha.3", | ||
"mos-plugin-readme": "^1.0.4", | ||
"tape": "^4.6.3", | ||
"ts-node": "^8.0.1", | ||
"tslint": "^5.0.0", | ||
"typescript": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"@pnpm/read-importer-manifest": "0.0.0", | ||
"@types/node": "^10.12.18", | ||
"fast-glob": "^2.0.4", | ||
"p-filter": "^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { readExactImporterManifest } from '@pnpm/read-importer-manifest' | ||
import fastGlob = require('fast-glob') | ||
import pFilter = require('p-filter') | ||
import path = require('path') | ||
|
||
const DEFAULT_IGNORE = [ | ||
'**/node_modules/**', | ||
'**/bower_components/**', | ||
'**/test/**', | ||
'**/tests/**', | ||
] | ||
|
||
async function findPkgs ( | ||
root: string, | ||
opts?: { | ||
ignore?: string[], | ||
patterns?: string[], | ||
}, | ||
) { | ||
opts = opts || {} | ||
const globOpts = { ...opts, cwd: root } | ||
globOpts.ignore = opts.ignore || DEFAULT_IGNORE | ||
globOpts.patterns = opts.patterns | ||
? normalizePatterns(opts.patterns) | ||
: ['**/package.{json,yaml,json5}'] | ||
|
||
const paths: string[] = await fastGlob(globOpts.patterns, globOpts) | ||
|
||
return pFilter( | ||
paths | ||
.sort() | ||
.map((manifestPath) => path.join(root, manifestPath)) | ||
.map(async (manifestPath) => { | ||
try { | ||
return { | ||
path: path.dirname(manifestPath), | ||
...await readExactImporterManifest(manifestPath), | ||
} | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return null | ||
} | ||
throw err | ||
} | ||
}), | ||
Boolean, | ||
) | ||
} | ||
|
||
function normalizePatterns (patterns: string[]) { | ||
return patterns.map((pattern) => pattern.replace(/\/?$/, '/package.{json,yaml,json5}')) | ||
} | ||
|
||
// for backward compatibility | ||
findPkgs['default'] = findPkgs // tslint:disable-line | ||
|
||
export = findPkgs |
2 changes: 2 additions & 0 deletions
2
...test/fixtures/many-pkgs-with-different-manifest-types/components/component-1/package.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: component-1 | ||
version: 1.0.0 |
4 changes: 4 additions & 0 deletions
4
...est/fixtures/many-pkgs-with-different-manifest-types/components/component-2/package.json5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
name: 'component-2', | ||
version: '1.0.0', | ||
} |
4 changes: 4 additions & 0 deletions
4
...find-packages/test/fixtures/many-pkgs-with-different-manifest-types/libs/pkg/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/find-packages/test/fixtures/many-pkgs/components/component-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "component-1", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/find-packages/test/fixtures/many-pkgs/components/component-2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "component-2", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/find-packages/test/fixtures/many-pkgs/libs/pkg/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/find-packages/test/fixtures/one-pkg/pkg/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import findPackages from 'find-packages' | ||
import path = require('path') | ||
import test = require('tape') | ||
|
||
const fixtures = path.join(__dirname, 'fixtures') | ||
|
||
test('finds package', async t => { | ||
const root = path.join(fixtures, 'one-pkg') | ||
const pkgs = await findPackages(root) | ||
|
||
t.equal(pkgs.length, 1) | ||
t.ok(pkgs[0].path) | ||
t.ok(pkgs[0].manifest) | ||
t.end() | ||
}) | ||
|
||
test('finds packages by patterns', async t => { | ||
const root = path.join(fixtures, 'many-pkgs') | ||
const pkgs = await findPackages(root, { patterns: ['components/**'] }) | ||
|
||
t.equal(pkgs.length, 2) | ||
t.ok(pkgs[0].path) | ||
t.ok(pkgs[0].manifest) | ||
t.ok(pkgs[1].path) | ||
t.ok(pkgs[1].manifest) | ||
t.deepEqual([pkgs[0].manifest.name, pkgs[1].manifest.name].sort(), ['component-1', 'component-2']) | ||
t.end() | ||
}) | ||
|
||
test('ignore packages by patterns', async t => { | ||
const root = path.join(fixtures, 'many-pkgs') | ||
const pkgs = await findPackages(root, { patterns: ['**', '!libs/**'] }) | ||
|
||
t.equal(pkgs.length, 2) | ||
t.ok(pkgs[0].path) | ||
t.ok(pkgs[0].manifest) | ||
t.ok(pkgs[1].path) | ||
t.ok(pkgs[1].manifest) | ||
t.deepEqual([pkgs[0].manifest.name, pkgs[1].manifest.name].sort(), ['component-1', 'component-2']) | ||
t.end() | ||
}) | ||
|
||
test('json and yaml manifests are also found', async t => { | ||
const root = path.join(fixtures, 'many-pkgs-with-different-manifest-types') | ||
const pkgs = await findPackages(root) | ||
|
||
t.equal(pkgs.length, 3) | ||
t.ok(pkgs[0].path) | ||
t.equal(pkgs[0].manifest.name, 'component-1') | ||
t.ok(pkgs[1].path) | ||
t.equal(pkgs[1].manifest.name, 'component-2') | ||
t.ok(pkgs[2].path) | ||
t.equal(pkgs[2].manifest.name, 'foo') | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../utils/tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"typings/**/*.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@pnpm/tslint-config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
declare module 'fast-glob' { | ||
const anything: any; | ||
export = anything; | ||
} | ||
|
||
declare module 'read-pkg' { | ||
const anything: any; | ||
export = anything; | ||
} | ||
|
||
declare module 'p-filter' { | ||
const anything: any; | ||
export = anything; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.