@multiplatform.one/utils 10.1.3 → 10.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/dev.cjs CHANGED
@@ -197,10 +197,29 @@ function importsBinding(file, binding) {
197
197
  }
198
198
  return new RegExp(`(?:import|require)[^;]*\\b${binding}\\b[^;]*['"]react-native['"]`, "s").test(source);
199
199
  }
200
- /** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`. */
200
+ /** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`, else from the installed package. */
201
201
  function stubFile(name) {
202
202
  const here = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
203
- return [node_path.default.resolve(here, "shims", name), node_path.default.resolve(here, "../src/shims", name)].find((candidate) => node_fs.default.existsSync(candidate));
203
+ const installed = installedShimsDir();
204
+ return [
205
+ node_path.default.resolve(here, "shims", name),
206
+ node_path.default.resolve(here, "../src/shims", name),
207
+ ...installed ? [node_path.default.join(installed, name)] : []
208
+ ].find((candidate) => node_fs.default.existsSync(candidate));
209
+ }
210
+ /**
211
+ * `src/shims` of the installed `@multiplatform.one/utils`. config's tsdown
212
+ * inlines this module into its own `lib`, where neither path relative to
213
+ * `import.meta.url` exists, so the stub went missing there and the dev
214
+ * dep-optimizer lost its plugin without a word (FZ-11764).
215
+ */
216
+ function installedShimsDir() {
217
+ try {
218
+ const manifest = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("@multiplatform.one/utils/package.json");
219
+ return node_path.default.join(node_path.default.dirname(manifest), "src", "shims");
220
+ } catch {
221
+ return;
222
+ }
204
223
  }
205
224
  function resolvePackageDir(pkgName, root, requireFrom) {
206
225
  try {
package/lib/dev.mjs CHANGED
@@ -165,10 +165,29 @@ function importsBinding(file, binding) {
165
165
  }
166
166
  return new RegExp(`(?:import|require)[^;]*\\b${binding}\\b[^;]*['"]react-native['"]`, "s").test(source);
167
167
  }
168
- /** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`. */
168
+ /** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`, else from the installed package. */
169
169
  function stubFile(name) {
170
170
  const here = path.dirname(fileURLToPath(import.meta.url));
171
- return [path.resolve(here, "shims", name), path.resolve(here, "../src/shims", name)].find((candidate) => fs.existsSync(candidate));
171
+ const installed = installedShimsDir();
172
+ return [
173
+ path.resolve(here, "shims", name),
174
+ path.resolve(here, "../src/shims", name),
175
+ ...installed ? [path.join(installed, name)] : []
176
+ ].find((candidate) => fs.existsSync(candidate));
177
+ }
178
+ /**
179
+ * `src/shims` of the installed `@multiplatform.one/utils`. config's tsdown
180
+ * inlines this module into its own `lib`, where neither path relative to
181
+ * `import.meta.url` exists, so the stub went missing there and the dev
182
+ * dep-optimizer lost its plugin without a word (FZ-11764).
183
+ */
184
+ function installedShimsDir() {
185
+ try {
186
+ const manifest = createRequire(import.meta.url).resolve("@multiplatform.one/utils/package.json");
187
+ return path.join(path.dirname(manifest), "src", "shims");
188
+ } catch {
189
+ return;
190
+ }
172
191
  }
173
192
  function resolvePackageDir(pkgName, root, requireFrom) {
174
193
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/utils",
3
- "version": "10.1.3",
3
+ "version": "10.1.4",
4
4
  "description": "utilities for multiplatform.one",
5
5
  "keywords": [
6
6
  "multiplatform.one",
@@ -193,12 +193,32 @@ function importsBinding(file: string, binding: string): boolean {
193
193
  );
194
194
  }
195
195
 
196
- /** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`. */
196
+ /** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`, else from the installed package. */
197
197
  function stubFile(name: string): string | undefined {
198
198
  const here = path.dirname(fileURLToPath(import.meta.url));
199
- return [path.resolve(here, "shims", name), path.resolve(here, "../src/shims", name)].find(
200
- (candidate) => fs.existsSync(candidate),
201
- );
199
+ const installed = installedShimsDir();
200
+ return [
201
+ path.resolve(here, "shims", name),
202
+ path.resolve(here, "../src/shims", name),
203
+ ...(installed ? [path.join(installed, name)] : []),
204
+ ].find((candidate) => fs.existsSync(candidate));
205
+ }
206
+
207
+ /**
208
+ * `src/shims` of the installed `@multiplatform.one/utils`. config's tsdown
209
+ * inlines this module into its own `lib`, where neither path relative to
210
+ * `import.meta.url` exists, so the stub went missing there and the dev
211
+ * dep-optimizer lost its plugin without a word (FZ-11764).
212
+ */
213
+ function installedShimsDir(): string | undefined {
214
+ try {
215
+ const manifest = createRequire(import.meta.url).resolve(
216
+ "@multiplatform.one/utils/package.json",
217
+ );
218
+ return path.join(path.dirname(manifest), "src", "shims");
219
+ } catch {
220
+ return undefined;
221
+ }
202
222
  }
203
223
 
204
224
  function resolvePackageDir(