Skip to content

Commit

Permalink
Bag of fixes (yarnpkg#783)
Browse files Browse the repository at this point in the history
* Implements fixes

* Adds the missing plugins

* Adds version file

* Fixes linting

* Improves authentication errors

* Updates the test messages

* Fixes whoami tests

* Fixes snapshots
  • Loading branch information
arcanis authored Jan 27, 2020
1 parent 93c767f commit cdfc813
Show file tree
Hide file tree
Showing 36 changed files with 475 additions and 123 deletions.
19 changes: 19 additions & 0 deletions .vscode/pnpify/eslint/bin/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

// Setup the environment to be able to require eslint/bin/eslint.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real eslint/bin/eslint.js your application uses
module.exports = absRequire(`eslint/bin/eslint.js`);
8 changes: 5 additions & 3 deletions .vscode/pnpify/eslint/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);

Expand All @@ -6,12 +8,12 @@ const relPnpApiPath = "../../../../.pnp.js";
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

// Setup the environment to be able to require eslint
// Setup the environment to be able to require eslint/lib/api.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real eslint your application uses
module.exports = absRequire(`eslint`);
// Defer to the real eslint/lib/api.js your application uses
module.exports = absRequire(`eslint/lib/api.js`);
2 changes: 1 addition & 1 deletion .vscode/pnpify/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eslint",
"version": "5.16.0-pnpify",
"main": "lib/api.js"
"main": "./lib/api.js"
}
19 changes: 19 additions & 0 deletions .vscode/pnpify/typescript/bin/tsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

// Setup the environment to be able to require typescript/bin/tsc
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/bin/tsc your application uses
module.exports = absRequire(`typescript/bin/tsc`);
19 changes: 19 additions & 0 deletions .vscode/pnpify/typescript/bin/tsserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

// Setup the environment to be able to require typescript/bin/tsserver
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/bin/tsserver your application uses
module.exports = absRequire(`typescript/bin/tsserver`);
19 changes: 19 additions & 0 deletions .vscode/pnpify/typescript/lib/tsc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

// Setup the environment to be able to require typescript/lib/tsc.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/lib/tsc.js your application uses
module.exports = absRequire(`typescript/lib/tsc.js`);
8 changes: 5 additions & 3 deletions .vscode/pnpify/typescript/lib/tsserver.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);

Expand All @@ -6,12 +8,12 @@ const relPnpApiPath = "../../../../.pnp.js";
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

// Setup the environment to be able to require typescript/lib/tsserver
// Setup the environment to be able to require typescript/lib/tsserver.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/lib/tsserver your application uses
module.exports = absRequire(`typescript/lib/tsserver`);
// Defer to the real typescript/lib/tsserver.js your application uses
module.exports = absRequire(`typescript/lib/tsserver.js`);
3 changes: 2 additions & 1 deletion .vscode/pnpify/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "typescript",
"version": "3.7.4-pnpify"
"version": "3.7.4-pnpify",
"main": "./lib/typescript.js"
}
33 changes: 33 additions & 0 deletions .yarn/versions/09310360.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
releases:
"@yarnpkg/cli": prerelease
"@yarnpkg/core": prerelease
"@yarnpkg/plugin-essentials": prerelease
"@yarnpkg/plugin-git": prerelease
"@yarnpkg/plugin-github": prerelease
"@yarnpkg/plugin-npm": prerelease
"@yarnpkg/plugin-npm-cli": prerelease
"@yarnpkg/plugin-pnp": prerelease
"@yarnpkg/pnpify": prerelease
"@yarnpkg/shell": prerelease

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/pnp"
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@
"build:plugin-commands": "node ./scripts/gen-plugin-commands.js > packages/plugin-essentials/sources/pluginCommands.ts",
"build:compile": "rm -rf \"$0\"/lib && mkdir -p \"$0\"/lib && rsync -a --exclude '*.ts' --exclude '*.tsx' --include '*.d.ts' \"$0\"/sources/ \"$0\"/lib/ && node scripts/compile \"$@\"",
"build:compile-inline": "find \"$0\"/sources -name '*.js' && babel \"$0\"/sources --out-dir \"$0\"/sources --extensions .ts,.tsx",
"gen-tssdk": "pnpify --sdk scripts",
"release:all": "./scripts/release.sh",
"test:lint": "eslint \"packages/**/@(sources|tests)/**/!(libzip).@(tsx|ts|js)\"",
"test:unit": "jest",
"sleep": "sleep 10",
"typecheck:all": "tsc --noEmit"
},
"sherlock": {
"requireList": [
"scripts/actions/sherlock-prepare.js"
]
},
"nextVersion": {
"nonce": "6668117343518271"
},
"repository": {
"type": "git",
"url": "ssh://[email protected]/yarnpkg/berry.git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe(`Commands`, () => {
TEST_NPM_PASSWORD: `incorrect password`,
},
})
).rejects.toThrowError(/Invalid Authentication/);
).rejects.toThrowError(/Invalid authentication \(attempted as anotherTestUser\)/);
})
);

Expand All @@ -103,7 +103,7 @@ describe(`Commands`, () => {
TEST_NPM_2FA_TOKEN: `incorrect OTP`,
},
})
).rejects.toThrowError(/Invalid Authentication/);
).rejects.toThrowError(/Invalid authentication \(attempted as testUser\)/);
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ describe(`Commands`, () => {
`it should throw an error when config has an invalid npmAuthToken`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc.yml`, `npmAuthToken: "${INVALID_AUTH_TOKEN}"\n`);
await expect(run(`npm`, `whoami`)).rejects.toThrowError(/Authentication failed/);
await expect(run(`npm`, `whoami`)).rejects.toThrowError(/Invalid authentication \(as an unknown user\)/);
})
);

test(
`it should throw an error when config has an invalid npmAuthIdent`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc.yml`, `npmAuthIdent: "${INVALID_AUTH_IDENT}"\n`);
await expect(run(`npm`, `whoami`)).rejects.toThrowError(/Authentication failed/);
await expect(run(`npm`, `whoami`)).rejects.toThrowError(/Invalid authentication \(as an unknown user\)/);
})
);

Expand All @@ -114,8 +114,8 @@ describe(`Commands`, () => {
` npmAuthToken: ${INVALID_AUTH_TOKEN}`,
].join(``));

await expect(run(`npm`, `whoami`, `--scope`, `testScope`)).rejects.toThrowError(/Authentication failed/);
await expect(run(`npm`, `whoami`)).rejects.toThrowError(/Authentication failed/);
await expect(run(`npm`, `whoami`, `--scope`, `testScope`)).rejects.toThrowError(/Invalid authentication \(as an unknown user\)/);
await expect(run(`npm`, `whoami`)).rejects.toThrowError(/Invalid authentication \(as an unknown user\)/);
})
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {xfs, ppath} from '@yarnpkg/fslib';
import {xfs} from '@yarnpkg/fslib';

const {
fs: {createTemporaryFolder, writeJson},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class PluginDlCommand extends BaseCommand {
pluginSpec = ppath.relative(project.cwd, candidatePath);
pluginBuffer = await xfs.readFilePromise(candidatePath);
} else {
let pluginUrl;
let pluginUrl: string;
if (this.name.match(/^https?:/)) {
try {
// @ts-ignore We don't want to add the dom to the TS env just for this line
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-git/sources/__snapshots__/gitUtils.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`gitUtils should properly normalize GitHubOrg/foo-bar.js 1`] = `"https://github.com/GitHubOrg/foo-bar.js.git"`;

exports[`gitUtils should properly normalize GitHubOrg/foo-bar.js#hash 1`] = `"https://github.com/GitHubOrg/foo-bar.js.git#hash"`;

exports[`gitUtils should properly normalize git+ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1 1`] = `"git+ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1"`;

exports[`gitUtils should properly normalize git://github.com/TooTallNate/util-deprecate.git#v1.0.1 1`] = `"git://github.com/TooTallNate/util-deprecate.git#v1.0.1"`;

exports[`gitUtils should properly normalize github:GitHubOrg/foo-bar.js 1`] = `"https://github.com/GitHubOrg/foo-bar.js.git"`;

exports[`gitUtils should properly normalize github:GitHubOrg/foo-bar.js#hash 1`] = `"https://github.com/GitHubOrg/foo-bar.js.git#hash"`;

exports[`gitUtils should properly normalize https://github.com/TooTallNate/util-deprecate.git#b3562c2798507869edb767da869cd7b85487726d 1`] = `"https://github.com/TooTallNate/util-deprecate.git#b3562c2798507869edb767da869cd7b85487726d"`;

exports[`gitUtils should properly normalize https://github.com/TooTallNate/util-deprecate.git#master 1`] = `"https://github.com/TooTallNate/util-deprecate.git#master"`;

exports[`gitUtils should properly normalize https://github.com/TooTallNate/util-deprecate.git#v1.0.0 1`] = `"https://github.com/TooTallNate/util-deprecate.git#v1.0.0"`;
38 changes: 38 additions & 0 deletions packages/plugin-git/sources/gitUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as gitUtils from './gitUtils';

const VALID_PATTERNS = [
`GitHubOrg/foo-bar.js`,
`GitHubOrg/foo-bar.js#hash`,
`github:GitHubOrg/foo-bar.js`,
`github:GitHubOrg/foo-bar.js#hash`,
`https://github.com/TooTallNate/util-deprecate.git#v1.0.0`,
`https://github.com/TooTallNate/util-deprecate.git#master`,
`https://github.com/TooTallNate/util-deprecate.git#b3562c2798507869edb767da869cd7b85487726d`,
`git://github.com/TooTallNate/util-deprecate.git#v1.0.1`,
`git+ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1`,
];

const INVALID_PATTERNS = [
`./.`,
`../..`,
];

describe(`gitUtils`, () => {
for (const pattern of VALID_PATTERNS) {
it(`should detect ${pattern} as a valid Git url`, () => {
expect(gitUtils.isGitUrl(pattern)).toEqual(true);
});
}

for (const pattern of INVALID_PATTERNS) {
it(`shouldn't detect ${pattern} as a valid Git url`, () => {
expect(gitUtils.isGitUrl(pattern)).toEqual(false);
});
}

for (const pattern of VALID_PATTERNS) {
it(`should properly normalize ${pattern}`, () => {
expect(gitUtils.normalizeRepoUrl(pattern)).toMatchSnapshot();
});
}
});
4 changes: 2 additions & 2 deletions packages/plugin-git/sources/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const gitPatterns = [
/^git(?:\+ssh)?:/,
/^(?:git\+)?https?:[^#]+\/[^#]+\.git(?:#.*)?$/,
/^git@[^#]+\/[^#]+\.git(?:#.*)?$/,
/^(?:github:|https:\/\/github\.com\/)?([a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d]))+)\/([a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d]))+)(?:#.*)?$/,
/^(?:github:|https:\/\/github\.com\/)?(?!\.{1,2}\/)([a-zA-Z._-]+)\/(?!\.{1,2}(?:#|$))([a-zA-Z._-]+?)(?:\.git)?(?:#.*)?$/,
];

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ export function normalizeRepoUrl(url: string) {
url = url.replace(/^git\+https:/, `https:`);

// We support this as an alias to Github repositories
url = url.replace(/^(?:github:|https:\/\/github\.com\/)?([a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d]))+)\/([a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d]))+)(#.*)?$/, `https://github.com/$1/$2.git$3`);
url = url.replace(/^(?:github:|https:\/\/github\.com\/)?(?!\.{1,2}\/)([a-zA-Z._-]+)\/(?!\.{1,2}(?:#|$))([a-zA-Z._-]+?)(?:\.git)?(#.*)?$/, `https://github.com/$1/$2.git$3`);

return url;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-git/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {FetchOptions, FetchResult, Locator, Plugin} from '@yarnpkg/core';

import {GitFetcher} from './GitFetcher';
import {GitResolver} from './GitResolver';
import * as gitUtils from './gitUtils';

export interface Hooks {
fetchHostedRepository?: (
Expand All @@ -20,5 +21,7 @@ const plugin: Plugin = {
],
};

export {gitUtils};

// eslint-disable-next-line arca/no-default-export
export default plugin;
18 changes: 18 additions & 0 deletions packages/plugin-github/sources/githubUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {gitUtils} from '@yarnpkg/plugin-git';

import * as githubUtils from './githubUtils';

const VALID_PATTERNS = [
`GitHubOrg/foo-bar.js`,
`GitHubOrg/foo-bar.js#hash`,
`github:GitHubOrg/foo-bar.js`,
`github:GitHubOrg/foo-bar.js#hash`,
];

describe(`gitUtils`, () => {
for (const pattern of VALID_PATTERNS) {
it(`should detect ${pattern} as a valid Git url`, () => {
expect(githubUtils.isGithubUrl(gitUtils.normalizeRepoUrl(pattern))).toEqual(true);
});
}
});
Loading

0 comments on commit cdfc813

Please sign in to comment.