2
2
3
3
/**
4
4
* @import { Configuration, Hooks, Manifest, PackageExtensionData, Plugin } from "@yarnpkg/core";
5
+ * @import { PortablePath } from "@yarnpkg/fslib";
5
6
* @typedef {{ cwd: string; manifest: Manifest["raw"]; } } Workspace;
6
7
*/
7
8
@@ -14,26 +15,29 @@ exports.name = "@rnx-kit/yarn-plugin-dynamic-extensions";
14
15
/** @type {(require: NodeJS.Require) => Plugin<Hooks> } */
15
16
exports . factory = ( require ) => {
16
17
const { Project, SettingsType, structUtils } = require ( "@yarnpkg/core" ) ;
18
+ const { npath } = require ( "@yarnpkg/fslib" ) ;
17
19
18
20
/**
19
21
* @param {Configuration } configuration
20
- * @param {string } projectRoot
22
+ * @param {PortablePath } projectRoot
21
23
* @returns {Promise<((ws: Workspace) => PackageExtensionData | undefined) | void> }
22
24
*/
23
25
async function loadUserExtensions ( configuration , projectRoot ) {
24
26
const packageExtensions = configuration . get ( DYNAMIC_PACKAGE_EXTENSIONS_KEY ) ;
25
- if (
26
- typeof packageExtensions !== "string" ||
27
- packageExtensions === "false"
28
- ) {
27
+ if ( typeof packageExtensions !== "string" ) {
29
28
return ;
30
29
}
31
30
32
31
const path = require ( "node:path" ) ;
33
32
const { pathToFileURL } = require ( "node:url" ) ;
34
33
34
+ // Make sure we resolve user extensions relative to the source config
35
+ const source = configuration . sources . get ( DYNAMIC_PACKAGE_EXTENSIONS_KEY ) ;
36
+ const sourceDir = source ? npath . dirname ( source ) : projectRoot ;
37
+
35
38
// On Windows, import paths must include the `file:` protocol.
36
- const url = pathToFileURL ( path . resolve ( projectRoot , packageExtensions ) ) ;
39
+ const root = npath . fromPortablePath ( sourceDir ) ;
40
+ const url = pathToFileURL ( path . resolve ( root , packageExtensions ) ) ;
37
41
const external = await import ( url . toString ( ) ) ;
38
42
return external ?. default ?? external ;
39
43
}
@@ -57,16 +61,16 @@ exports.factory = (require) => {
57
61
return ;
58
62
}
59
63
60
- const { workspace } = await Project . find ( configuration , projectCwd ) ;
61
- if ( ! workspace ) {
64
+ const getUserExtensions = await loadUserExtensions (
65
+ configuration ,
66
+ projectCwd
67
+ ) ;
68
+ if ( ! getUserExtensions ) {
62
69
return ;
63
70
}
64
71
65
- const { npath } = require ( "@yarnpkg/fslib" ) ;
66
-
67
- const root = npath . fromPortablePath ( projectCwd ) ;
68
- const getUserExtensions = await loadUserExtensions ( configuration , root ) ;
69
- if ( ! getUserExtensions ) {
72
+ const { workspace } = await Project . find ( configuration , projectCwd ) ;
73
+ if ( ! workspace ) {
70
74
return ;
71
75
}
72
76
0 commit comments