-
-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc(generator): allow local paths to generators
- Loading branch information
1 parent
4cf5e17
commit 0f0fe3e
Showing
8 changed files
with
165 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require("fs"); | ||
const npmPackagesExists = require("./npm-packages-exists"); | ||
|
||
jest.mock("fs"); | ||
jest.mock("./npm-exists"); | ||
jest.mock("./resolve-packages"); | ||
|
||
const mockResolvePackages = require("./resolve-packages").resolvePackages; | ||
|
||
describe("npmPackagesExists", () => { | ||
test("resolves packages when they are available on the local filesystem", () => { | ||
fs.existsSync.mockReturnValueOnce(true); | ||
npmPackagesExists(["./testpkg"]); | ||
expect(mockResolvePackages.mock.calls[mockResolvePackages.mock.calls.length - 1][0]).toEqual(["./testpkg"]); | ||
}); | ||
|
||
test("throws a TypeError when an npm package name doesn't include the prefix", () => { | ||
fs.existsSync.mockReturnValueOnce(false); | ||
expect(() => npmPackagesExists(["my-webpack-addon"])).toThrowError(TypeError); | ||
}); | ||
|
||
test("resolves packages when they are available on npm", done => { | ||
fs.existsSync.mockReturnValueOnce(false); | ||
require("./npm-exists").mockImplementation(() => Promise.resolve(true)); | ||
npmPackagesExists(["webpack-addons-foobar"]); | ||
setTimeout(() => { | ||
expect(mockResolvePackages.mock.calls[mockResolvePackages.mock.calls.length - 1][0]).toEqual(["webpack-addons-foobar"]); | ||
done(); | ||
}, 10); | ||
}); | ||
}); |
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,22 @@ | ||
"use strict"; | ||
|
||
const fs = require("fs"); | ||
const npmExists = require("./npm-exists"); | ||
|
||
/** | ||
* | ||
* Checks whether a package exists locally or on npm | ||
* | ||
* @param {String} pkg - Name or location of package | ||
* @returns {Promise} exists - Returns true or false, | ||
* based on if it exists or not | ||
*/ | ||
|
||
module.exports = function packageExists(pkg) { | ||
const isValidLocalPath = fs.existsSync(pkg); | ||
if (isValidLocalPath) { | ||
return Promise.resolve(true); | ||
} | ||
|
||
return npmExists(pkg); | ||
}; |
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