Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional dependencies #3575

Merged
merged 19 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
50 changes: 50 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions .yarn/versions/771de10e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/builder": minor
"@yarnpkg/cli": minor
"@yarnpkg/core": minor
"@yarnpkg/doctor": minor
"@yarnpkg/esbuild-plugin-pnp": minor
"@yarnpkg/nm": minor
"@yarnpkg/plugin-compat": minor
"@yarnpkg/plugin-constraints": minor
"@yarnpkg/plugin-dlx": minor
"@yarnpkg/plugin-essentials": minor
"@yarnpkg/plugin-exec": minor
"@yarnpkg/plugin-file": minor
"@yarnpkg/plugin-git": minor
"@yarnpkg/plugin-github": minor
"@yarnpkg/plugin-http": minor
"@yarnpkg/plugin-init": minor
"@yarnpkg/plugin-interactive-tools": minor
"@yarnpkg/plugin-link": minor
"@yarnpkg/plugin-nm": minor
"@yarnpkg/plugin-npm": minor
"@yarnpkg/plugin-npm-cli": minor
"@yarnpkg/plugin-pack": minor
"@yarnpkg/plugin-patch": minor
"@yarnpkg/plugin-pnp": minor
"@yarnpkg/plugin-pnpm": minor
"@yarnpkg/plugin-stage": minor
"@yarnpkg/plugin-typescript": minor
"@yarnpkg/plugin-version": minor
"@yarnpkg/plugin-workspace-tools": minor
"@yarnpkg/pnp": minor
"@yarnpkg/pnpify": minor
"@yarnpkg/sdks": minor
vscode-zipfs: minor
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ enableGlobalCache: false
immutablePatterns:
- .pnp.*

supportedArchitectures:
os: [darwin, linux, windows]
arcanis marked this conversation as resolved.
Show resolved Hide resolved
cpu: [x64]
arcanis marked this conversation as resolved.
Show resolved Hide resolved

initScope: yarnpkg

npmPublishAccess: public
Expand Down
98 changes: 58 additions & 40 deletions packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,62 @@ export type PackageRunDriver = (
opts: RunDriverOptions,
) => Promise<ExecResult>;

export enum RequestType {
Login = `login`,
PackageInfo = `packageInfo`,
PackageTarball = `packageTarball`,
Whoami = `whoami`,
Repository = `repository`,
Publish = `publish`,
}

export type Request = {
type: RequestType.Login;
username: string,
} | {
type: RequestType.PackageInfo;
scope?: string;
localName: string;
} | {
type: RequestType.PackageTarball;
scope?: string;
localName: string;
version?: string;
} | {
type: RequestType.Whoami;
login: Login
} | {
type: RequestType.Repository;
} | {
type: RequestType.Publish;
scope?: string;
localName: string;
};

export interface Login {
username: string;
password: string;
requiresOtp: boolean;
otp?: string;
npmAuthToken: string;
}

let whitelist = new Map();
let recording: Array<Request> | null = null;

export const startRegistryRecording = async (
fn: () => Promise<void>,
) => {
const currentRecording: Array<Request> = [];
recording = currentRecording;

try {
await fn();
return currentRecording;
} finally {
recording = null;
}
};

export const setPackageWhitelist = async (
packages: Map<string, Set<string>>,
Expand Down Expand Up @@ -184,38 +239,6 @@ export const startPackageServer = ({type}: { type: keyof typeof packageServerUrl
if (serverUrl !== null)
return Promise.resolve(serverUrl);

enum RequestType {
Login = `login`,
PackageInfo = `packageInfo`,
PackageTarball = `packageTarball`,
Whoami = `whoami`,
Repository = `repository`,
Publish = `publish`,
}

type Request = {
type: RequestType.Login;
username: string,
} | {
type: RequestType.PackageInfo;
scope?: string;
localName: string;
} | {
type: RequestType.PackageTarball;
scope?: string;
localName: string;
version?: string;
} | {
type: RequestType.Whoami;
login: Login
} | {
type: RequestType.Repository;
} | {
type: RequestType.Publish;
scope?: string;
localName: string;
};

const processors: {[requestType in RequestType]: (parsedRequest: Request, request: IncomingMessage, response: ServerResponse) => Promise<void>} = {
async [RequestType.PackageInfo](parsedRequest, _, response) {
if (parsedRequest.type !== RequestType.PackageInfo)
Expand Down Expand Up @@ -472,14 +495,6 @@ export const startPackageServer = ({type}: { type: keyof typeof packageServerUrl
}
};

interface Login {
username: string;
password: string;
requiresOtp: boolean;
otp?: string;
npmAuthToken: string;
}

const validLogins: Record<string, Login> = {
testUser: {
username: `testUser`,
Expand Down Expand Up @@ -518,6 +533,9 @@ export const startPackageServer = ({type}: { type: keyof typeof packageServerUrl
return;
}

if (recording !== null)
recording.push(parsedRequest);

const {authorization} = req.headers;
if (authorization != null) {
const auth = validAuthorizations.get(authorization);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "native",
"version": "1.0.0",
"dependencies": {
"native-bar-x64": "1.0.0",
"native-foo-x64": "1.0.0",
"native-foo-x86": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "native-bar-x64",
"version": "1.0.0",
"os": ["bar"],
"cpu": ["x64"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "native-foo-x64",
"version": "1.0.0",
"os": ["foo"],
"cpu": ["x64"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "native-foo-x86",
"version": "1.0.0",
"os": ["foo"],
"cpu": ["x86"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "optional-native",
"version": "1.0.0",
"optionalDependencies": {
"native-bar-x64": "1.0.0",
"native-foo-x64": "1.0.0",
"native-foo-x86": "1.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Features Merge Conflict Resolution it should properly fix merge conflic
# Manual changes might be lost - proceed with caution!

__metadata:
version: 4
version: 5
cacheKey: 0

\\"no-deps@npm:*\\":
Expand Down Expand Up @@ -54,7 +54,7 @@ exports[`Features Merge Conflict Resolution it should properly fix merge conflic
# Manual changes might be lost - proceed with caution!

__metadata:
version: 4
version: 5
cacheKey: 0

<<<<<<< HEAD
Expand Down
Loading