|
1 | 1 | // @ts-check |
2 | | - |
3 | | -/// PNPM Typedefs. |
4 | | -// From <https://github.com/pnpm/pnpm/blob/eeb76cd1d0a3133d71d96de5646e305f34474652/hooks/pnpmfile/src/Hooks.ts> & <https://github.com/pnpm/pnpm/blob/d500d9f12e8819bf2659abece126938fb3a9ac87/packages/types/src/package.ts>. |
5 | | - |
6 | | -const VERBOSE = false; |
7 | | - |
8 | | -/** |
9 | | - * A local `package.json` or a remote manifest from a registry as deserialized JSON. |
10 | | - * |
11 | | - * @typedef {Object} Pkg |
12 | | - * @property {string?} name |
13 | | - * @property {string?} version |
14 | | - * @property {Record<string, string>?} dependencies |
15 | | - */ |
16 | | - |
17 | | -/** |
18 | | - * A context object passed to hooks. |
19 | | - * Currently contains naught but a logger. |
20 | | - * |
21 | | - * @typedef {Object} HookContext |
22 | | - * @property {(message: string) => void} log |
23 | | - */ |
24 | | - |
25 | | -/// Ported code from the Yarn plugin. |
26 | | - |
27 | | -/** |
28 | | - * A full list of nolyfilled packages. |
29 | | - * |
30 | | - * Based on <https://github.com/wojtekmaj/yarn-plugin-nolyfill/blob/main/src/index.ts>. |
31 | | - * Keep in sync with <https://github.com/SukkaW/nolyfill/blob/master/packages/tools/cli/src/all-packages.ts>. |
32 | | - * Do note that nolyfill doesn't use CD, so check that the versions listed there have been published. |
33 | | - * |
34 | | - * @type {string[]} |
35 | | - */ |
36 | | -const allPackages = [ |
37 | | - "abab", |
38 | | - "array-buffer-byte-length", |
39 | | - "array-flatten", |
40 | | - "array-includes", |
41 | | - "array.from", |
42 | | - "array.of", |
43 | | - "array.prototype.at", |
44 | | - "array.prototype.every", |
45 | | - "array.prototype.find", |
46 | | - "array.prototype.findlast", |
47 | | - "array.prototype.findlastindex", |
48 | | - "array.prototype.flat", |
49 | | - "array.prototype.flatmap", |
50 | | - "array.prototype.flatmap", |
51 | | - "array.prototype.foreach", |
52 | | - "array.prototype.reduce", |
53 | | - "array.prototype.toreversed", |
54 | | - "array.prototype.tosorted", |
55 | | - "arraybuffer.prototype.slice", |
56 | | - "assert", |
57 | | - "asynciterator.prototype", |
58 | | - "available-typed-arrays", |
59 | | - "deep-equal", |
60 | | - "deep-equal-json", |
61 | | - "define-properties", |
62 | | - "es-aggregate-error", |
63 | | - "es-iterator-helpers", |
64 | | - "es-set-tostringtag", |
65 | | - "es6-object-assign", |
66 | | - "function-bind", |
67 | | - "function.prototype.name", |
68 | | - "get-symbol-description", |
69 | | - "globalthis", |
70 | | - "gopd", |
71 | | - "harmony-reflect", |
72 | | - "has", |
73 | | - "has-property-descriptors", |
74 | | - "has-proto", |
75 | | - "has-symbols", |
76 | | - "has-tostringtag", |
77 | | - "hasown", |
78 | | - "internal-slot", |
79 | | - "is-arguments", |
80 | | - "is-array-buffer", |
81 | | - "is-core-module", |
82 | | - "is-date-object", |
83 | | - "is-generator-function", |
84 | | - "is-nan", |
85 | | - "is-regex", |
86 | | - "is-shared-array-buffer", |
87 | | - "is-string", |
88 | | - "is-symbol", |
89 | | - "is-typed-array", |
90 | | - "is-weakref", |
91 | | - "isarray", |
92 | | - "iterator.prototype", |
93 | | - "json-stable-stringify", |
94 | | - "jsonify", |
95 | | - "number-is-nan", |
96 | | - "object-is", |
97 | | - "object-keys", |
98 | | - "object.assign", |
99 | | - "object.entries", |
100 | | - "object.fromentries", |
101 | | - "object.getownpropertydescriptors", |
102 | | - "object.groupby", |
103 | | - "object.hasown", |
104 | | - "object.values", |
105 | | - "promise.allsettled", |
106 | | - "promise.any", |
107 | | - "reflect.getprototypeof", |
108 | | - "reflect.ownkeys", |
109 | | - "regexp.prototype.flags", |
110 | | - "safe-array-concat", |
111 | | - "safe-buffer", |
112 | | - "safe-regex-test", |
113 | | - "safer-buffer", |
114 | | - "set-function-length", |
115 | | - "side-channel", |
116 | | - "string.prototype.at", |
117 | | - "string.prototype.codepointat", |
118 | | - "string.prototype.includes", |
119 | | - "string.prototype.matchall", |
120 | | - "string.prototype.padend", |
121 | | - "string.prototype.padstart", |
122 | | - "string.prototype.repeat", |
123 | | - "string.prototype.replaceall", |
124 | | - "string.prototype.split", |
125 | | - "string.prototype.startswith", |
126 | | - "string.prototype.trim", |
127 | | - "string.prototype.trimend", |
128 | | - "string.prototype.trimleft", |
129 | | - "string.prototype.trimright", |
130 | | - "string.prototype.trimstart", |
131 | | - "typed-array-buffer", |
132 | | - "typed-array-byte-length", |
133 | | - "typed-array-byte-offset", |
134 | | - "typed-array-length", |
135 | | - "typedarray", |
136 | | - "typedarray.prototype.slice", |
137 | | - "unbox-primitive", |
138 | | - "util.promisify", |
139 | | - "which-boxed-primitive", |
140 | | - "which-typed-array", |
141 | | -]; |
142 | | - |
143 | | -/** |
144 | | - * A map of all nolyfilled packages. |
145 | | - * The keys are the original package names, the values are the nolyfilled package names. |
146 | | - * |
147 | | - * @type {Map<string, string>} |
148 | | - */ |
149 | | -const PATCHES = new Map(allPackages.map((name) => [name, `@nolyfill/${name}`])); |
150 | | - |
151 | | -/// Wiring code (pnpm specific) |
152 | | - |
153 | | -/** |
154 | | - * @param {Pkg} pkg - The package read. |
155 | | - * @param {HookContext} context - The context of the hook. |
156 | | - * @returns {Pkg} - The package to use. |
157 | | - */ |
158 | | -function readPackage(pkg, context) { |
159 | | - // Not really necessary, but I prefer to keep the original package unmodified. |
160 | | - const newPkg = { ...pkg }; |
161 | | - |
162 | | - // If the package has dependencies, check if any of them need to be nolyfilled. |
163 | | - if (newPkg.dependencies) { |
164 | | - // Iterate over all dependencies. |
165 | | - for (const name of Object.keys(newPkg.dependencies)) { |
166 | | - // Get the possible nolyfill package name. |
167 | | - const nolyfill = PATCHES.get(name); |
168 | | - |
169 | | - // Check if there is nolyfill for the package. |
170 | | - if (nolyfill !== undefined) { |
171 | | - // Replace the original package with the nolyfill. |
172 | | - newPkg.dependencies[name] = `npm:${nolyfill}@^1`; |
173 | | - |
174 | | - if (VERBOSE) { |
175 | | - // Tell the user that the package has been nolyfilled. |
176 | | - context.log(`${name} => ${nolyfill}`); |
177 | | - } |
178 | | - } |
179 | | - } |
180 | | - } |
181 | | - |
182 | | - // Return the (possibly modified) package. |
183 | | - return newPkg; |
184 | | -} |
185 | | - |
186 | | -/// Exports |
187 | | - |
188 | | -/** |
189 | | - * A pnpmfile allows you to use hooks to modify the behavior of pnpm. |
190 | | - * |
191 | | - * From <https://pnpm.io/pnpmfile>. |
192 | | - */ |
193 | | -module.exports = { |
194 | | - hooks: { |
195 | | - readPackage, |
196 | | - }, |
197 | | -}; |
| 2 | +module.exports = require("./node_modules/.pnpm-config/@pnpmfiles/nolyfill/.pnpmfile.cjs"); |
0 commit comments