Skip to content

Commit 2c58dea

Browse files
committed
feat(yarn-plugin-ignore): Yarn plugin implementing the ignore: protocol
1 parent c77d02d commit 2c58dea

File tree

22 files changed

+585
-52
lines changed

22 files changed

+585
-52
lines changed

.changeset/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"access": "public",
77
"baseBranch": "origin/main",
88
"ignore": [
9-
"@rnx-kit/ignore",
109
"@rnx-kit/template",
1110
"@rnx-kit/test-app",
1211
"@rnx-kit/test-app-macos",

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ plugins:
6363
spec: "@yarnpkg/plugin-compat"
6464
- path: incubator/yarn-plugin-dynamic-extensions/index.js
6565
- path: incubator/yarn-plugin-external-workspaces/dist/external-workspaces.cjs
66+
- path: incubator/yarn-plugin-ignore/dist/yarn-plugin-ignore.cjs
6667
- path: incubator/yarn-plugin-install-to/dist/yarn-plugin-install-to.cjs
6768

6869
tsEnableAutoTypes: false

docsite/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"typescript": "catalog:"
3434
},
3535
"resolutions": {
36-
"@algolia/autocomplete-core": "link:../incubator/ignore",
37-
"@docsearch/react": "link:../incubator/ignore",
36+
"@algolia/autocomplete-core": "ignore:",
37+
"@docsearch/react": "ignore:",
3838
"@pnpm/network.ca-file/graceful-fs": "^4.2.10",
39-
"algoliasearch": "link:../incubator/ignore",
40-
"algoliasearch-helper": "link:../incubator/ignore",
41-
"node-gyp": "link:../incubator/ignore"
39+
"algoliasearch": "ignore:",
40+
"algoliasearch-helper": "ignore:",
41+
"node-gyp": "ignore:"
4242
},
4343
"browserslist": {
4444
"production": [

docsite/yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ __metadata:
55
version: 8
66
cacheKey: 10c0
77

8-
"@algolia/autocomplete-core@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
8+
"@algolia/autocomplete-core@ignore:::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
99
version: 0.0.0-use.local
10-
resolution: "@algolia/autocomplete-core@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A."
10+
resolution: "@algolia/autocomplete-core@ignore:"
1111
languageName: node
1212
linkType: soft
1313

@@ -1800,9 +1800,9 @@ __metadata:
18001800
languageName: node
18011801
linkType: hard
18021802

1803-
"@docsearch/react@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
1803+
"@docsearch/react@ignore:::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
18041804
version: 0.0.0-use.local
1805-
resolution: "@docsearch/react@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A."
1805+
resolution: "@docsearch/react@ignore:"
18061806
languageName: node
18071807
linkType: soft
18081808

@@ -4381,15 +4381,15 @@ __metadata:
43814381
languageName: node
43824382
linkType: hard
43834383

4384-
"algoliasearch-helper@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
4384+
"algoliasearch-helper@ignore:::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
43854385
version: 0.0.0-use.local
4386-
resolution: "algoliasearch-helper@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A."
4386+
resolution: "algoliasearch-helper@ignore:"
43874387
languageName: node
43884388
linkType: soft
43894389

4390-
"algoliasearch@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
4390+
"algoliasearch@ignore:::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
43914391
version: 0.0.0-use.local
4392-
resolution: "algoliasearch@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A."
4392+
resolution: "algoliasearch@ignore:"
43934393
languageName: node
43944394
linkType: soft
43954395

@@ -9344,9 +9344,9 @@ __metadata:
93449344
languageName: node
93459345
linkType: hard
93469346

9347-
"node-gyp@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
9347+
"node-gyp@ignore:::locator=%40rnx-kit%2Fdocsite%40workspace%3A.":
93489348
version: 0.0.0-use.local
9349-
resolution: "node-gyp@link:../incubator/ignore::locator=%40rnx-kit%2Fdocsite%40workspace%3A."
9349+
resolution: "node-gyp@ignore:"
93509350
languageName: node
93519351
linkType: soft
93529352

incubator/ignore/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

incubator/ignore/package.json

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!dist/
2+
dist/*.map
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# @rnx-kit/yarn-plugin-ignore
2+
3+
[![Build](https://github.com/microsoft/rnx-kit/actions/workflows/build.yml/badge.svg)](https://github.com/microsoft/rnx-kit/actions/workflows/build.yml)
4+
[![npm version](https://img.shields.io/npm/v/@rnx-kit/yarn-plugin-ignore)](https://www.npmjs.com/package/@rnx-kit/yarn-plugin-ignore)
5+
6+
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
7+
8+
### THIS TOOL IS EXPERIMENTAL — USE WITH CAUTION
9+
10+
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
11+
12+
A Yarn plugin for excluding packages from being installed.
13+
14+
## Installation
15+
16+
```sh
17+
yarn plugin import https://raw.githubusercontent.com/microsoft/rnx-kit/main/incubator/yarn-plugin-ignore/dist/yarn-plugin-ignore.cjs
18+
```
19+
20+
## Usage
21+
22+
In the root `package.json`, add a `resolutions` section and use the `ignore:`
23+
protocol to exclude packages. For example, to exclude `node-gyp`:
24+
25+
```diff
26+
+ "resolutions": {
27+
+ "node-gyp": "ignore:"
28+
+ },
29+
```
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/* eslint-disable */
2+
//prettier-ignore
3+
module.exports = {
4+
name: "@rnx-kit/yarn-plugin-ignore",
5+
factory: function (require) {
6+
"use strict";
7+
var plugin = (() => {
8+
var __create = Object.create;
9+
var __defProp = Object.defineProperty;
10+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11+
var __getOwnPropNames = Object.getOwnPropertyNames;
12+
var __getProtoOf = Object.getPrototypeOf;
13+
var __hasOwnProp = Object.prototype.hasOwnProperty;
14+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
15+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
16+
}) : x)(function(x) {
17+
if (typeof require !== "undefined") return require.apply(this, arguments);
18+
throw Error('Dynamic require of "' + x + '" is not supported');
19+
});
20+
var __export = (target, all) => {
21+
for (var name in all)
22+
__defProp(target, name, { get: all[name], enumerable: true });
23+
};
24+
var __copyProps = (to, from, except, desc) => {
25+
if (from && typeof from === "object" || typeof from === "function") {
26+
for (let key of __getOwnPropNames(from))
27+
if (!__hasOwnProp.call(to, key) && key !== except)
28+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29+
}
30+
return to;
31+
};
32+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33+
// If the importer is in node compatibility mode or this is not an ESM
34+
// file that has been converted to a CommonJS file using a Babel-
35+
// compatible transform (i.e. "__esModule" has not been set), then set
36+
// "default" to the CommonJS "module.exports" for node compatibility.
37+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38+
mod
39+
));
40+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41+
42+
// src/index.ts
43+
var index_exports = {};
44+
__export(index_exports, {
45+
IgnoreFetcher: () => IgnoreFetcher,
46+
IgnoreResolver: () => IgnoreResolver,
47+
default: () => index_default
48+
});
49+
50+
// src/IgnoreFetcher.ts
51+
var import_fslib = __require("@yarnpkg/fslib");
52+
var fs = __toESM(__require("fs"), 1);
53+
54+
// src/constants.ts
55+
var IGNORE_PROTOCOL = "ignore:";
56+
var STUB_MODULE = `module.exports = {};
57+
`;
58+
var STUB_PACKAGE = `{
59+
"name": "@rnx-kit/yarn-plugin-ignore/stub",
60+
"version": "0.0.0",
61+
"description": "Stub package for '@rnx-kit/yarn-plugin-ignore'",
62+
"main": "index.js"
63+
}
64+
`;
65+
66+
// src/IgnoreFetcher.ts
67+
var IgnoreFetcher = class {
68+
supports(locator) {
69+
return locator.reference.startsWith(IGNORE_PROTOCOL);
70+
}
71+
getLocalPath() {
72+
return null;
73+
}
74+
async fetch(_locator, opts) {
75+
const base = opts.project.cwd;
76+
const sourceFs = new import_fslib.CwdFS(base);
77+
const localPath = import_fslib.ppath.resolve(
78+
base,
79+
"node_modules",
80+
".generated",
81+
"@rnx-kit",
82+
"yarn-plugin-ignore-stub"
83+
);
84+
const nativePath = import_fslib.npath.fromPortablePath(localPath);
85+
if (!fs.existsSync(nativePath)) {
86+
fs.mkdirSync(nativePath, { recursive: true, mode: 493 });
87+
fs.writeFileSync(import_fslib.npath.join(nativePath, "package.json"), STUB_PACKAGE);
88+
fs.writeFileSync(import_fslib.npath.join(nativePath, "index.js"), STUB_MODULE);
89+
}
90+
return {
91+
packageFs: new import_fslib.CwdFS(localPath, { baseFs: sourceFs }),
92+
prefixPath: import_fslib.PortablePath.dot,
93+
discardFromLookup: true,
94+
localPath
95+
};
96+
}
97+
};
98+
99+
// src/IgnoreResolver.ts
100+
var import_core = __require("@yarnpkg/core");
101+
var IgnoreResolver = class {
102+
supportsDescriptor(descriptor) {
103+
return descriptor.range.startsWith(IGNORE_PROTOCOL);
104+
}
105+
supportsLocator(locator) {
106+
return locator.reference.startsWith(IGNORE_PROTOCOL);
107+
}
108+
shouldPersistResolution() {
109+
return false;
110+
}
111+
bindDescriptor(descriptor, fromLocator) {
112+
return import_core.structUtils.bindDescriptor(descriptor, {
113+
locator: import_core.structUtils.stringifyLocator(fromLocator)
114+
});
115+
}
116+
getResolutionDependencies() {
117+
return {};
118+
}
119+
async getCandidates(descriptor, _dependencies, _opts) {
120+
return [import_core.structUtils.makeLocator(descriptor, IGNORE_PROTOCOL)];
121+
}
122+
async getSatisfying(descriptor, dependencies, locators, opts) {
123+
const [locator] = await this.getCandidates(descriptor, dependencies, opts);
124+
return {
125+
locators: locators.filter(
126+
(candidate) => candidate.locatorHash === locator.locatorHash
127+
),
128+
sorted: false
129+
};
130+
}
131+
async resolve(locator, opts) {
132+
return {
133+
...locator,
134+
version: "0.0.0",
135+
languageName: opts.project.configuration.get("defaultLanguageName"),
136+
linkType: import_core.LinkType.SOFT,
137+
conditions: null,
138+
dependencies: /* @__PURE__ */ new Map(),
139+
peerDependencies: /* @__PURE__ */ new Map(),
140+
dependenciesMeta: /* @__PURE__ */ new Map(),
141+
peerDependenciesMeta: /* @__PURE__ */ new Map(),
142+
bin: /* @__PURE__ */ new Map()
143+
};
144+
}
145+
};
146+
147+
// src/index.ts
148+
var plugin = {
149+
fetchers: [IgnoreFetcher],
150+
resolvers: [IgnoreResolver]
151+
};
152+
var index_default = plugin;
153+
return __toCommonJS(index_exports);
154+
})();
155+
return plugin;
156+
}
157+
};
158+
//# sourceMappingURL=yarn-plugin-ignore.cjs.map
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@rnx-kit/yarn-plugin-ignore",
3+
"version": "0.0.1",
4+
"private": true,
5+
"description": "EXPERIMENTAL - USE WITH CAUTION - yarn-plugin-ignore",
6+
"homepage": "https://github.com/microsoft/rnx-kit/tree/main/incubator/yarn-plugin-ignore#readme",
7+
"license": "MIT",
8+
"author": {
9+
"name": "Microsoft Open Source",
10+
"email": "microsoftopensource@users.noreply.github.com"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/microsoft/rnx-kit",
15+
"directory": "incubator/yarn-plugin-ignore"
16+
},
17+
"files": [
18+
"dist/yarn-plugin-ignore.cjs"
19+
],
20+
"type": "module",
21+
"main": "dist/yarn-plugin-ignore.cjs",
22+
"scripts": {
23+
"build": "rnx-kit-scripts build",
24+
"bundle": "rnx-kit-scripts bundle --platform yarn --sourceMap",
25+
"format": "rnx-kit-scripts format",
26+
"lint": "rnx-kit-scripts lint",
27+
"test": "rnx-kit-scripts test"
28+
},
29+
"devDependencies": {
30+
"@rnx-kit/scripts": "*",
31+
"@rnx-kit/tsconfig": "*",
32+
"@yarnpkg/core": "^4.2.0",
33+
"@yarnpkg/fslib": "^3.1.1"
34+
},
35+
"engines": {
36+
"node": ">=18.12",
37+
"yarn": ">=4.0"
38+
},
39+
"experimental": true
40+
}

0 commit comments

Comments
 (0)