Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/packages/*/build/**
/packages/**/*fixtures*/**
/packages/yarnpkg-libzip/artifacts/**
/packages/plugin-compat/extra/fsevents/fsevents-*.js

# Files generated by Gatsby
/packages/gatsby/public/**
Expand Down
22 changes: 20 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ module.exports = {
require.resolve(`@yarnpkg/eslint-config`),
require.resolve(`@yarnpkg/eslint-config/react`),
],
ignorePatterns: [
`packages/plugin-compat/extra/fsevents/fsevents-*.js`,
overrides: [
{
files: [`!packages/*/sources/{index,Plugin}.ts`],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the correct value would be ['!packages/*/sources/index.ts', '!packages/yarnpkg-core/sources/Plugin.ts'], ESLint seems to still match the files if I put both negated patterns, even though the docs state that:

Override blocks can also specify patterns to exclude from matches. If a file matches any of the excluded patterns, the configuration won't apply.

rules: {
'@typescript-eslint/naming-convention': [`error`, {
selector: `typeLike`,
format: [`PascalCase`],
custom: {
regex: `^Hooks$`,
match: false,
},
}],
},
},
{
files: [`packages/acceptance-tests/pkg-tests-specs/**/*.test.{js,ts}`],
globals: {
makeTemporaryEnv: `readonly`,
},
},
],
};
9 changes: 9 additions & 0 deletions .yarn/versions/36e6a0e0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
releases:
"@yarnpkg/eslint-config": patch
"@yarnpkg/plugin-npm": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/cli"
- "@yarnpkg/core"
6 changes: 0 additions & 6 deletions packages/eslint-config/rules/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,5 @@ module.exports = {
jest: true,
},
},
{
files: [`packages/acceptance-tests/pkg-tests-specs/**/*.test.{js,ts}`],
globals: {
makeTemporaryEnv: `readonly`,
},
},
],
};
8 changes: 0 additions & 8 deletions packages/plugin-npm/sources/Hooks.ts

This file was deleted.

33 changes: 22 additions & 11 deletions packages/plugin-npm/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import {Plugin, SettingsType, miscUtils} from '@yarnpkg/core';
import {Plugin, SettingsType, miscUtils, Configuration, Ident} from '@yarnpkg/core';

import {Hooks} from './Hooks';
import {NpmHttpFetcher} from './NpmHttpFetcher';
import {NpmRemapResolver} from './NpmRemapResolver';
import {NpmSemverFetcher} from './NpmSemverFetcher';
import {NpmSemverResolver} from './NpmSemverResolver';
import {NpmTagResolver} from './NpmTagResolver';
import * as npmConfigUtils from './npmConfigUtils';
import * as npmHttpUtils from './npmHttpUtils';
import * as npmPublishUtils from './npmPublishUtils';
import {NpmHttpFetcher} from './NpmHttpFetcher';
import {NpmRemapResolver} from './NpmRemapResolver';
import {NpmSemverFetcher} from './NpmSemverFetcher';
import {NpmSemverResolver} from './NpmSemverResolver';
import {NpmTagResolver} from './NpmTagResolver';
import * as npmConfigUtils from './npmConfigUtils';
import * as npmHttpUtils from './npmHttpUtils';
import * as npmPublishUtils from './npmPublishUtils';

export {npmConfigUtils};
export {npmHttpUtils};
export {npmPublishUtils};
export type {Hooks};

export interface Hooks {
/**
* Called when getting the authentication header for a request to the npm registry.
* You can use this mechanism to dynamically query a CLI for the credentials for a
* specific registry.
*/
getNpmAuthenticationHeader?: (currentHeader: string | undefined, registry: string, {
configuration,
ident,
}: { configuration: Configuration, ident?: Ident }) => Promise<string | undefined>;
}


const authSettings = {
npmAlwaysAuth: {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-npm/sources/npmHttpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {MessageName, ReportError} from '@yarnpkg/core';
import {prompt} from 'enquirer';
import {URL} from 'url';

import {Hooks} from './Hooks';
import {Hooks} from './index';
import * as npmConfigUtils from './npmConfigUtils';
import {MapLike} from './npmConfigUtils';

Expand Down
7 changes: 7 additions & 0 deletions scripts/extract-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ async function processFile(file: ts.SourceFile) {

const processNode = (node: ts.Node) => {
switch (node.kind) {
case ts.SyntaxKind.TypeAliasDeclaration: {
const typeAliasNode = node as ts.TypeAliasDeclaration;
if (typeAliasNode.name.getText() === `Hooks`) {
throw new UsageError(`Hooks should only be declared using interfaces, not type aliases (in ${file.fileName})`);
}
} break;

case ts.SyntaxKind.InterfaceDeclaration: {
const interfaceNode = node as ts.InterfaceDeclaration;
if (interfaceNode.name.getText() === `Hooks`) {
Expand Down