Skip to content

Commit

Permalink
fix(lib): support scoped modules
Browse files Browse the repository at this point in the history
Correct fetch behavior for @scope/name`
  • Loading branch information
azu committed Jan 26, 2018
1 parent 8334e5e commit 7e89a42
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/can-npm-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const checkAlreadyPublish = packagePath => {
return Promise.reject(new Error("This package has not `version`."));
}
// https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#getpackageversion
return fetch(`https://registry.npmjs.com/${encodeURIComponent(name)}`)
// @scope/name => @scope%2Fname
const encodedName = name.replace(/\//g, "%2F");
return fetch(`https://registry.npmjs.com/${encodedName}`)
.then(response => {
if (response.status === 404) {
// not published yet
Expand Down
5 changes: 5 additions & 0 deletions test/can-npm-publish-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe("can-npm-publish", () => {
assert.ok(/is already published/.test(error.message));
});
});
it("should be rejected, it is already published scoped package", () => {
return canNpmPublish(path.join(__dirname, "fixtures/scoped-package.json")).then(shouldNotCalled, error => {
assert.ok(/is already published/.test(error.message));
});
});
it("should be resolve, it is not published yet", () => {
return canNpmPublish(path.join(__dirname, "fixtures/not-published-yet.json"));
});
Expand Down
60 changes: 60 additions & 0 deletions test/fixtures/scoped-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@textlint/fixer-formatter",
"version": "3.0.3",
"description": "textlint output formatter for fixer",
"keywords": [
"AST",
"lint",
"linting",
"markdown",
"plugable",
"text",
"textlint"
],
"homepage": "https://github.com/textlint/textlint#readme",
"bugs": {
"url": "https://github.com/textlint/textlint/issues"
},
"license": "MIT",
"author": "azu",
"files": [
"lib/fixer-formatter",
"src/"
],
"main": "lib/fixer-formatter/src/index.js",
"types": "lib/fixer-formatter/src/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/textlint/textlint.git"
},
"scripts": {
"build": "cross-env NODE_ENV=production tsc -p .",
"clean": "rimraf lib/",
"prepublish": "npm run build",
"test": "mocha \"test/**/*.{js,ts}\""
},
"dependencies": {
"@textlint/kernel": "^2.0.5",
"chalk": "^1.1.3",
"debug": "^2.1.0",
"diff": "^2.2.2",
"interop-require": "^1.0.0",
"is-file": "^1.0.0",
"string-width": "^1.0.1",
"text-table": "^0.2.0",
"try-resolve": "^1.0.1"
},
"devDependencies": {
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.57",
"@types/power-assert": "^1.4.29",
"cross-env": "^5.1.1",
"mocha": "^4.0.1",
"rimraf": "^2.6.2",
"ts-node": "^4.0.1",
"typescript": "^2.6.2"
},
"publishConfig": {
"access": "public"
}
}

0 comments on commit 7e89a42

Please sign in to comment.