@ms-cloudpack/package-utilities 5.0.2 → 5.1.1
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/PackageDefinitions.d.ts +6 -4
- package/lib/PackageDefinitions.d.ts.map +1 -1
- package/lib/PackageDefinitions.js +32 -16
- package/lib/PackageDefinitions.js.map +1 -1
- package/lib/addExportsMapEntry.d.ts.map +1 -1
- package/lib/addExportsMapEntry.js +20 -12
- package/lib/addExportsMapEntry.js.map +1 -1
- package/lib/createExportsMap.d.ts +1 -0
- package/lib/createExportsMap.d.ts.map +1 -1
- package/lib/createExportsMap.js +1 -1
- package/lib/createExportsMap.js.map +1 -1
- package/lib/createResolveMap/convertToResolveMap.js +1 -1
- package/lib/createResolveMap/convertToResolveMap.js.map +1 -1
- package/lib/createResolveMap/createResolveMap.d.ts +1 -0
- package/lib/createResolveMap/createResolveMap.d.ts.map +1 -1
- package/lib/createResolveMap/createResolveMap.js +1 -2
- package/lib/createResolveMap/createResolveMap.js.map +1 -1
- package/lib/createResolveMap/detachEntry.d.ts.map +1 -1
- package/lib/createResolveMap/detachEntry.js +2 -2
- package/lib/createResolveMap/detachEntry.js.map +1 -1
- package/lib/createResolveMap/findPackagesFromPath.d.ts +2 -8
- package/lib/createResolveMap/findPackagesFromPath.d.ts.map +1 -1
- package/lib/createResolveMap/findPackagesFromPath.js +2 -3
- package/lib/createResolveMap/findPackagesFromPath.js.map +1 -1
- package/lib/findPackagePath.d.ts +1 -7
- package/lib/findPackagePath.d.ts.map +1 -1
- package/lib/findPackagePath.js +3 -9
- package/lib/findPackagePath.js.map +1 -1
- package/lib/getExportsMap.d.ts +1 -0
- package/lib/getExportsMap.d.ts.map +1 -1
- package/lib/getExportsMap.js +1 -1
- package/lib/getExportsMap.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { PackageJson, PackageDefinitionTransform, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
2
|
export declare class PackageDefinitions implements PackageDefinitionsCache {
|
|
3
|
-
private
|
|
3
|
+
private _definitions;
|
|
4
|
+
private _transformedDefinitions;
|
|
4
5
|
private _config;
|
|
5
6
|
private _transforms;
|
|
6
7
|
private _transformFactories;
|
|
7
8
|
/**
|
|
8
9
|
* Constructor for PackageDefinitions.
|
|
9
|
-
* @param
|
|
10
|
+
* @param definitionCache - The map of package paths to package definitions, used mainly for testing.
|
|
10
11
|
* @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the
|
|
11
12
|
* transforms will be re-created using the new config.
|
|
12
13
|
*/
|
|
13
|
-
constructor(
|
|
14
|
+
constructor(definitionCache?: Record<string, PackageJson>, config?: unknown);
|
|
14
15
|
get(packagePath: string, options?: {
|
|
15
|
-
refresh
|
|
16
|
+
refresh?: boolean;
|
|
17
|
+
disableTransforms?: boolean;
|
|
16
18
|
}): Promise<PackageJson | undefined>;
|
|
17
19
|
/**
|
|
18
20
|
* Registers a transform factory function, which will be called on initialization, and when reset, to re-generate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEpH,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEpH,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,mBAAmB,CAAuD;IAElF;;;;;OAKG;gBACS,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAQzE,GAAG,CACP,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3D,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAwCnC;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,0BAA0B;IAO3E;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE;CAWxC"}
|
|
@@ -4,33 +4,48 @@ import { readJson } from '@ms-cloudpack/json-utilities';
|
|
|
4
4
|
export class PackageDefinitions {
|
|
5
5
|
/**
|
|
6
6
|
* Constructor for PackageDefinitions.
|
|
7
|
-
* @param
|
|
7
|
+
* @param definitionCache - The map of package paths to package definitions, used mainly for testing.
|
|
8
8
|
* @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the
|
|
9
9
|
* transforms will be re-created using the new config.
|
|
10
10
|
*/
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(definitionCache = {}, config) {
|
|
12
12
|
this._transforms = [];
|
|
13
|
-
this.
|
|
13
|
+
this._definitions = definitionCache;
|
|
14
|
+
this._transformedDefinitions = {};
|
|
14
15
|
this._config = config;
|
|
15
16
|
this._transforms = [applyOverrides];
|
|
16
17
|
this._transformFactories = [];
|
|
17
18
|
}
|
|
18
19
|
async get(packagePath, options) {
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
existingDefinition = this._cache[packagePath] = this._transforms.reduce((def, transform) => transform(def) || def, definition);
|
|
27
|
-
}
|
|
20
|
+
let definition = this._definitions[packagePath];
|
|
21
|
+
let transformedDefinition = this._transformedDefinitions[packagePath];
|
|
22
|
+
const { refresh, disableTransforms } = options || {};
|
|
23
|
+
// If we already have the answer they need, return immediately.
|
|
24
|
+
if (!refresh) {
|
|
25
|
+
if (disableTransforms && definition) {
|
|
26
|
+
return definition;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (!disableTransforms && transformedDefinition) {
|
|
29
|
+
return transformedDefinition;
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
// If we don't have the definition, try to load it.
|
|
33
|
+
if (!definition || refresh) {
|
|
34
|
+
definition = await readJson(path.join(packagePath, 'package.json'));
|
|
35
|
+
if (!definition) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
this._definitions[packagePath] = definition;
|
|
39
|
+
}
|
|
40
|
+
// If we don't want to skip the transform, transform the definition.
|
|
41
|
+
if (!disableTransforms && (!transformedDefinition || refresh)) {
|
|
42
|
+
for (const transform of this._transforms) {
|
|
43
|
+
transformedDefinition =
|
|
44
|
+
(await transform(transformedDefinition || definition, packagePath, this)) || transformedDefinition;
|
|
45
|
+
}
|
|
46
|
+
this._transformedDefinitions[packagePath] = transformedDefinition;
|
|
47
|
+
}
|
|
48
|
+
return (!disableTransforms && transformedDefinition) || definition;
|
|
34
49
|
}
|
|
35
50
|
/**
|
|
36
51
|
* Registers a transform factory function, which will be called on initialization, and when reset, to re-generate
|
|
@@ -46,7 +61,8 @@ export class PackageDefinitions {
|
|
|
46
61
|
* Resets the cache of package definitions. This is useful when testing, to ensure that the cache is empty.
|
|
47
62
|
*/
|
|
48
63
|
reset(options) {
|
|
49
|
-
this.
|
|
64
|
+
this._definitions = {};
|
|
65
|
+
this._transformedDefinitions = {};
|
|
50
66
|
const { newConfig } = options || {};
|
|
51
67
|
if (newConfig) {
|
|
52
68
|
this._config = newConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,MAAM,OAAO,kBAAkB;
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,MAAM,OAAO,kBAAkB;IAO7B;;;;;OAKG;IACH,YAAY,kBAA+C,EAAE,EAAE,MAAgB;QATvE,gBAAW,GAAiC,EAAE,CAAC;QAUrD,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC;QACpC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,CAAC,CAAC;QACpC,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,WAAmB,EACnB,OAA4D;QAE5D,IAAI,UAAU,GAA4B,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACzE,IAAI,qBAAqB,GAA4B,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAC/F,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAErD,+DAA+D;QAC/D,IAAI,CAAC,OAAO,EAAE;YACZ,IAAI,iBAAiB,IAAI,UAAU,EAAE;gBACnC,OAAO,UAAU,CAAC;aACnB;YAED,IAAI,CAAC,i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IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SACvG;IACH,CAAC;CACF","sourcesContent":["import path from 'path';\nimport { applyOverrides } from '@ms-cloudpack/package-overrides';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport type { PackageJson, PackageDefinitionTransform, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _definitions: Record<string, PackageJson>;\n private _transformedDefinitions: Record<string, PackageJson>;\n private _config: unknown;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: ((config?: unknown) => PackageDefinitionTransform)[];\n\n /**\n * Constructor for PackageDefinitions.\n * @param definitionCache - The map of package paths to package definitions, used mainly for testing.\n * @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the\n * transforms will be re-created using the new config.\n */\n constructor(definitionCache: Record<string, PackageJson> = {}, config?: unknown) {\n this._definitions = definitionCache;\n this._transformedDefinitions = {};\n this._config = config;\n this._transforms = [applyOverrides];\n this._transformFactories = [];\n }\n\n async get(\n packagePath: string,\n options?: { refresh?: boolean; disableTransforms?: boolean },\n ): Promise<PackageJson | undefined> {\n let definition: PackageJson | undefined = this._definitions[packagePath];\n let transformedDefinition: PackageJson | undefined = this._transformedDefinitions[packagePath];\n const { refresh, disableTransforms } = options || {};\n\n // If we already have the answer they need, return immediately.\n if (!refresh) {\n if (disableTransforms && definition) {\n return definition;\n }\n\n if (!disableTransforms && transformedDefinition) {\n return transformedDefinition;\n }\n }\n\n // If we don't have the definition, try to load it.\n if (!definition || refresh) {\n definition = await readJson(path.join(packagePath, 'package.json'));\n\n if (!definition) {\n return undefined;\n }\n\n this._definitions[packagePath] = definition;\n }\n\n // If we don't want to skip the transform, transform the definition.\n if (!disableTransforms && (!transformedDefinition || refresh)) {\n for (const transform of this._transforms) {\n transformedDefinition =\n (await transform(transformedDefinition || definition, packagePath, this)) || transformedDefinition;\n }\n\n this._transformedDefinitions[packagePath] = transformedDefinition;\n }\n\n return (!disableTransforms && transformedDefinition) || definition;\n }\n\n /**\n * Registers a transform factory function, which will be called on initialization, and when reset, to re-generate\n * the transform function. Transform functions are called only when the package definition hasn't been loaded before,\n * and the result will be cached. Calling `reset` will reset the cache.\n */\n registerTransform(factory: (config?: unknown) => PackageDefinitionTransform) {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n /**\n * Resets the cache of package definitions. This is useful when testing, to ensure that the cache is empty.\n */\n reset(options?: { newConfig?: unknown }) {\n this._definitions = {};\n this._transformedDefinitions = {};\n\n const { newConfig } = options || {};\n\n if (newConfig) {\n this._config = newConfig;\n this._transforms = [applyOverrides, ...this._transformFactories.map((factory) => factory(newConfig))];\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,CAkDlB"}
|
|
@@ -11,23 +11,31 @@ export async function addExportsMapEntry(options, context) {
|
|
|
11
11
|
filePath: options.filePath || options.importPath || '',
|
|
12
12
|
}, context);
|
|
13
13
|
// Create a local for casting.
|
|
14
|
-
// TODO: this is potentially clobbering or not correctly handling certain existing structures
|
|
15
14
|
const localExports = exports;
|
|
16
15
|
// Only do work if a file path was provided.
|
|
17
16
|
if (filePath) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// If this is the only entry we're adding, set it to a string to minimize the exports map.
|
|
18
|
+
if (!typesPath &&
|
|
19
|
+
!sourcePath &&
|
|
20
|
+
condition === 'default' &&
|
|
21
|
+
(!localExports[importPath] || typeof localExports[importPath] === 'string')) {
|
|
22
|
+
localExports[importPath] = filePath;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
exportsEntry[
|
|
24
|
+
else {
|
|
25
|
+
let exportsEntry = (localExports[importPath] ??= {});
|
|
26
|
+
// Promote string-based exports into objects with default conditions.
|
|
27
|
+
if (typeof exportsEntry === 'string') {
|
|
28
|
+
exportsEntry = exports[importPath] = { default: exportsEntry };
|
|
29
|
+
}
|
|
30
|
+
if (typesPath) {
|
|
31
|
+
exportsEntry['types'] = typesPath;
|
|
32
|
+
}
|
|
33
|
+
if (sourcePath) {
|
|
34
|
+
exportsEntry['source'] = sourcePath;
|
|
35
|
+
}
|
|
36
|
+
// Add the entry for the condition.
|
|
37
|
+
exportsEntry[condition] = filePath;
|
|
25
38
|
}
|
|
26
|
-
if (sourcePath) {
|
|
27
|
-
exportsEntry['source'] = sourcePath;
|
|
28
|
-
}
|
|
29
|
-
// Add the entry for the condition.
|
|
30
|
-
exportsEntry[condition] = filePath;
|
|
31
39
|
}
|
|
32
40
|
return !!filePath;
|
|
33
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAyCrE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAA8C;IAE9C,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IAChE,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,GAChF,GAAG,MAAM,iBAA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AY,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;YAErD,qEAAqE;YACrE,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;gBACpC,YAAY,GAAI,OAAkD,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;aAC5G;YAED,IAAI,SAAS,EAAE;gBACb,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;aACnC;YAED,IAAI,UAAU,EAAE;gBACd,YAAY,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;aACrC;YAED,mCAAmC;YACnC,YAAY,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC;SACpC;KACF;IAED,OAAO,CAAC,CAAC,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,GAAG,EAAE;QACrC,OAAO,GAAG,CAAC;KACZ;IAED,4CAA4C;IAC5C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;KAClB;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { findFileInPackage } from './findFileInPackage.js';\nimport type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * Optional types path. If not provided, types will be discovered for internal packages that have source files.\n * This is useful mainly when converting the default import from a package.json that has explicit typings listed.\n */\n typesPath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\", \"browser\", \"types\") Defaults to \"default\"\n */\n condition?: string;\n}\n\n/**\n * Given an exports map and details about an import path, adds the entry.\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = makeSafeImportKey(options.importPath || '.');\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? safeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string>>;\n\n // Only do work if a file path was provided.\n if (filePath) {\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (\n !typesPath &&\n !sourcePath &&\n condition === 'default' &&\n (!localExports[importPath] || typeof localExports[importPath] === 'string')\n ) {\n localExports[importPath] = filePath;\n } else {\n let exportsEntry = (localExports[importPath] ??= {});\n\n // Promote string-based exports into objects with default conditions.\n if (typeof exportsEntry === 'string') {\n exportsEntry = (exports as Record<string, Record<string, string>>)[importPath] = { default: exportsEntry };\n }\n\n if (typesPath) {\n exportsEntry['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportsEntry['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportsEntry[condition] = filePath;\n }\n }\n\n return !!filePath;\n}\n\nfunction makeSafeImportKey(key: string) {\n if (!key || key === '' || key === '.') {\n return '.';\n }\n\n // if the key starts with a slash, add a dot\n if (key.startsWith('/')) {\n key = '.' + key;\n }\n\n // if the key doesn't start with \"./\", add it\n if (!key.startsWith('./')) {\n key = './' + key;\n }\n\n return key;\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import type { PackageJsonExports, PackageDefinitionsCache } from '@ms-cloudpack/
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function createExportsMap(options: {
|
|
6
6
|
packagePath: string;
|
|
7
|
+
disableTransforms?: boolean;
|
|
7
8
|
}, context: {
|
|
8
9
|
packages: PackageDefinitionsCache;
|
|
9
10
|
}): Promise<PackageJsonExports>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI/F;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI/F;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAoF7B"}
|
package/lib/createExportsMap.js
CHANGED
|
@@ -6,7 +6,7 @@ import { safeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
|
6
6
|
export async function createExportsMap(options, context) {
|
|
7
7
|
const { packagePath } = options;
|
|
8
8
|
const { packages } = context;
|
|
9
|
-
const definition = await packages.get(packagePath);
|
|
9
|
+
const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });
|
|
10
10
|
if (!definition) {
|
|
11
11
|
throw new Error(`Package definition not found for ${packagePath}`);
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,
|
|
1
|
+
{"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAGC,EACD,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAErG,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,oCAAoC,WAAW,EAAE,CAAC,CAAC;KACpE;IAED,qEAAqE;IACrE,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB,OAAO,UAAU,CAAC,OAAO,CAAC;KAC3B;IAED,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IACnE,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,MAAM,SAAS,GAAG,KAAK,IAAI,OAAO,CAAC;IAEnC,MAAM,kBAAkB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C;oBAEpD,IAAI,CAAC,eAAe,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;wBAC3C,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;qBAC5C;oBAED,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;wBACpC,MAAM,kBAAkB,CACtB;4BACE,OAAO;4BACP,WAAW;4BACX,UAAU;4BACV,QAAQ,EAAE,KAAK;4BACf,SAAS,EAAE,SAAS;yBACrB,EACD,OAAO,CACR,CAAC;qBACH;iBACF;aACF;SACF;KACF;IAED,qEAAqE;IACrE,+CAA+C;IAC/C,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACrC,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;YACvF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,CAAC,CAAC;YACxF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;KACzF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PackageJsonExports, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Given a package path, generates an export map for the package.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n },\n context: { packages: PackageDefinitionsCache },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });\n\n if (!definition) {\n throw new Error(`Package definition not found for ${packagePath}`);\n }\n\n // Don't create an exports map for a definition that already has one.\n if (definition.exports) {\n return definition.exports;\n }\n\n const { browser, main, module, types, typings, type } = definition;\n const exports = {};\n const typesPath = types || typings;\n\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: 'index.js',\n typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n );\n main &&\n (await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n ),\n context);\n module &&\n (await addExportsMapEntry({ exports, packagePath, filePath: module, typesPath, condition: 'import' }, context));\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, condition: 'browser' }, context);\n } else if (typeof definition.browser === 'object') {\n for (const [key, value] of Object.entries(definition.browser)) {\n if (value && typeof value === 'string') {\n const isDefaultImport = safeRelativePath(module || main) === safeRelativePath(key);\n\n const importPaths = isDefaultImport ? ['.'] : [key];\n\n if (!isDefaultImport && key.endsWith('.js')) {\n importPaths.push(key.replace(/\\.js$/, ''));\n }\n\n for (const importPath of importPaths) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n importPath,\n filePath: value,\n condition: 'browser',\n },\n context,\n );\n }\n }\n }\n }\n }\n\n // If we couldn't infer the exports map shape from existing metadata,\n // formulate based off inferred file structure.\n // Note: CRA defaults to src/index.js, Vite defaults to src/main.js\n if (Object.keys(exports).length === 0) {\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js' }, context));\n }\n\n return exports;\n}\n"]}
|
|
@@ -16,7 +16,7 @@ export function convertToResolveMap(options) {
|
|
|
16
16
|
const entry = (resolveMap[packageName] = sortedPackageEntries[0]);
|
|
17
17
|
// Update scoped versions (version to resolve map entry)
|
|
18
18
|
if (sortedPackageEntries.length > 1) {
|
|
19
|
-
entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((
|
|
19
|
+
entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((e) => [e.version, e]));
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertToResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/convertToResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgD;IAClF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAClE,6EAA6E;QAC7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;aACvD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;aAC7E,IAAI,CAAC,WAAW,CAAC,CAAC;QACrB,wFAAwF;QACxF,2EAA2E;QAC3E,IAAI,oBAAoB,CAAC,MAAM,EAAE;YAC/B,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;YAElE,wDAAwD;YACxD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"convertToResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/convertToResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgD;IAClF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAClE,6EAA6E;QAC7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;aACvD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;aAC7E,IAAI,CAAC,WAAW,CAAC,CAAC;QACrB,wFAAwF;QACxF,2EAA2E;QAC3E,IAAI,oBAAoB,CAAC,MAAM,EAAE;YAC/B,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;YAElE,wDAAwD;YACxD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aACrG;SACF;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '../types/ResolveMap.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { entrySorter } from './entrySorter.js';\n\n/**\n * Given a PackageMap and all root paths (appPath and linked paths), returns a ResolveMap.\n */\nexport function convertToResolveMap(options: { appMap: PackageMap; paths: string[] }): ResolveMap {\n const { paths, appMap } = options;\n const resolveMap: ResolveMap = {};\n\n for (const [packageName, packageEntries] of Object.entries(appMap)) {\n // Filter to root packages and packages which are required by other packages.\n const sortedPackageEntries = Object.values(packageEntries)\n .filter((e) => paths.indexOf(e.path) >= 0 || Object.keys(e.requiredBy).length)\n .sort(entrySorter);\n // Get the sorted package entries based on the most to least requiredBy references. This\n // ends up reducing the size of the resolve map by minimizing scoped cases.\n if (sortedPackageEntries.length) {\n const entry = (resolveMap[packageName] = sortedPackageEntries[0]);\n\n // Update scoped versions (version to resolve map entry)\n if (sortedPackageEntries.length > 1) {\n entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((e) => [e.version, e]));\n }\n }\n }\n\n return resolveMap;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolveMap.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"createResolveMap.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CAmBrB"}
|
|
@@ -12,12 +12,11 @@ import { linkPath } from './linkPath.js';
|
|
|
12
12
|
* which aren't already in the resolve map are added as scoped versions.
|
|
13
13
|
*/
|
|
14
14
|
export async function createResolveMap(options, context) {
|
|
15
|
-
const { appPath, additionalPaths = [], linkedPaths = [],
|
|
15
|
+
const { appPath, additionalPaths = [], linkedPaths = [], gitRootPath } = options;
|
|
16
16
|
// First we discover the dependencies for the app.
|
|
17
17
|
const appMap = await findPackagesFromPath({
|
|
18
18
|
paths: [appPath, ...additionalPaths],
|
|
19
19
|
gitRootPath,
|
|
20
|
-
useStrictVersioning,
|
|
21
20
|
}, context);
|
|
22
21
|
// Next, we iterate through linked paths to inject them into the packageMap.
|
|
23
22
|
for (const linkedPath of linkedPaths) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,
|
|
1
|
+
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAOC,EACD,OAEC;IAED,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEjF,kDAAkD;IAClD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CACvC;QACE,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC;QACpC,WAAW;KACZ,EACD,OAAO,CACR,CAAC;IAEF,4EAA4E;IAC5E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;KACjD;IAED,0CAA0C;IAC1C,OAAO,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import type { LinkedPath } from '../types/LinkedPath.js';\nimport type { ResolveMap } from '../types/ResolveMap.js';\nimport { convertToResolveMap } from './convertToResolveMap.js';\nimport { findPackagesFromPath } from './findPackagesFromPath.js';\nimport { linkPath } from './linkPath.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\n/**\n * Create a resolve map for a given app path. We do this by walking the dependency tree\n * of the app to build a map of all packages and their dependencies. We then sort the\n * dependencies by the number of other packages that depend on them. The package with the\n * most dependencies is considered the dominant version and is the one that will be used\n * by the bundler. Once this has been resolved, linkedPaths are evaluated separately by\n * discovering their dependencies and redirecting any existing dependencies to the linked\n * package. Transitive dependencies of the linked package are validated and any dependencies\n * which aren't already in the resolve map are added as scoped versions.\n */\nexport async function createResolveMap(\n options: {\n appPath: string;\n additionalPaths?: string[];\n linkedPaths?: LinkedPath[];\n gitRootPath?: string;\n /** @deprecated Not used */\n useStrictVersioning?: boolean;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [], linkedPaths = [], gitRootPath } = options;\n\n // First we discover the dependencies for the app.\n const appMap = await findPackagesFromPath(\n {\n paths: [appPath, ...additionalPaths],\n gitRootPath,\n },\n context,\n );\n\n // Next, we iterate through linked paths to inject them into the packageMap.\n for (const linkedPath of linkedPaths) {\n await linkPath({ linkedPath, appMap }, context);\n }\n\n // Finally we condense into a resolve map.\n return convertToResolveMap({ appMap, paths: [appPath, ...additionalPaths] });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detachEntry.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;
|
|
1
|
+
{"version":3,"file":"detachEntry.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,QAkClF"}
|
|
@@ -3,8 +3,8 @@ import { parseRequiredBy } from './parseRequiredBy.js';
|
|
|
3
3
|
* Removes requiredBy references for an entry being removed.
|
|
4
4
|
*/
|
|
5
5
|
export function detachEntry(options) {
|
|
6
|
-
const { appMap, entry } = options;
|
|
7
|
-
const dependenciesToDetach = [
|
|
6
|
+
const { appMap, entry: entryToRemove } = options;
|
|
7
|
+
const dependenciesToDetach = [entryToRemove];
|
|
8
8
|
while (dependenciesToDetach.length) {
|
|
9
9
|
const entry = dependenciesToDetach.pop();
|
|
10
10
|
const { name, version, requiredBy } = entry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detachEntry.js","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;
|
|
1
|
+
{"version":3,"file":"detachEntry.js","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAuD;IACjF,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,oBAAoB,GAAsB,CAAC,aAAa,CAAC,CAAC;IAEhE,OAAO,oBAAoB,CAAC,MAAM,EAAE;QAClC,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAqB,CAAC;QAC5D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAE5C,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACnB,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;gBAC3B,uCAAuC;gBACvC,KAAK,MAAM,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;oBACpD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;oBACpE,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;oBAExD,IAAI,WAAW,EAAE;wBACf,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;qBACvC;iBACF;gBAED,0CAA0C;gBAC1C,KAAK,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;oBACpF,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;oBAEpE,IAAI,eAAe,EAAE;wBACnB,OAAO,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;wBACxD,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;4BACxD,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;yBAC5C;qBACF;iBACF;aACF;SACF;KACF;AACH,CAAC","sourcesContent":["import type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\n\n/**\n * Removes requiredBy references for an entry being removed.\n */\nexport function detachEntry(options: { appMap: PackageMap; entry: ResolveMapEntry }) {\n const { appMap, entry: entryToRemove } = options;\n const dependenciesToDetach: ResolveMapEntry[] = [entryToRemove];\n\n while (dependenciesToDetach.length) {\n const entry = dependenciesToDetach.pop() as ResolveMapEntry;\n const { name, version, requiredBy } = entry;\n\n if (!entry.isLinked) {\n if (appMap[name]?.[version]) {\n // Disconnect the entry from consumers.\n for (const requiredByName of Object.keys(requiredBy)) {\n const [parentName, parentVersion] = parseRequiredBy(requiredByName);\n const parentEntry = appMap[parentName]?.[parentVersion];\n\n if (parentEntry) {\n delete parentEntry.dependencies[name];\n }\n }\n\n // Disconnect dependencies from the entry.\n for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {\n const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];\n\n if (dependencyEntry) {\n delete dependencyEntry.requiredBy[`${name}@${version}`];\n if (Object.keys(dependencyEntry.requiredBy).length === 0) {\n dependenciesToDetach.push(dependencyEntry);\n }\n }\n }\n }\n }\n }\n}\n"]}
|
|
@@ -15,14 +15,8 @@ export declare function findPackagesFromPath(options: {
|
|
|
15
15
|
*/
|
|
16
16
|
gitRootPath?: string;
|
|
17
17
|
/**
|
|
18
|
-
* If true will
|
|
19
|
-
|
|
20
|
-
* TODO: read resolutions from package.json and use them to allow mismatches.
|
|
21
|
-
**/
|
|
22
|
-
useStrictVersioning?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* If true will glob for all package.json files in the path and add them to the map.
|
|
25
|
-
**/
|
|
18
|
+
* If true will glob for all package.json files in the path and add them to the map.
|
|
19
|
+
*/
|
|
26
20
|
discoverPackages?: boolean;
|
|
27
21
|
}, context: {
|
|
28
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findPackagesFromPath.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/findPackagesFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAe,MAAM,6BAA6B,CAAC;AAOxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IACP;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB
|
|
1
|
+
{"version":3,"file":"findPackagesFromPath.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/findPackagesFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAe,MAAM,6BAA6B,CAAC;AAOxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IACP;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,EACD,OAAO,EAAE;IACP;;OAEG;IACH,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CA0FrB"}
|
|
@@ -9,7 +9,7 @@ import { isExternalPackage } from '../isExternalPackage.js';
|
|
|
9
9
|
* of the app to build a map of all packages and their dependencies.
|
|
10
10
|
*/
|
|
11
11
|
export async function findPackagesFromPath(options, context) {
|
|
12
|
-
const { paths, discoverPackages
|
|
12
|
+
const { paths, discoverPackages } = options;
|
|
13
13
|
const { packages } = context;
|
|
14
14
|
const packageMap = {};
|
|
15
15
|
const visitedPaths = new Set();
|
|
@@ -54,8 +54,7 @@ export async function findPackagesFromPath(options, context) {
|
|
|
54
54
|
const isPeerDependency = !!packageDefinition.peerDependencies?.[dependencyName];
|
|
55
55
|
const dependencyPath = await findPackagePath({
|
|
56
56
|
dependencyName,
|
|
57
|
-
|
|
58
|
-
cwd: packagePath,
|
|
57
|
+
startPath: packagePath,
|
|
59
58
|
gitRootPath,
|
|
60
59
|
}, context);
|
|
61
60
|
if (dependencyPath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findPackagesFromPath.js","sourceRoot":"","sources":["../../src/createResolveMap/findPackagesFromPath.ts"],"names":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,CAAC;AACpB,CAAC;AAED,SAAS,gBAAgB,CAAC,OAA0E;IAClG,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACtD,MAAM,EAAE,IAAI,GAAG,WAAW,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,UAAU,CAAC;IAEzD,MAAM,QAAQ,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,CAAoC,CAAC;IAC9E,MAAM,KAAK,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK;QACnC,IAAI;QACJ,OAAO;QACP,IAAI;QACJ,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE,EAAE;KACf,CAAC,CAAC;IAEH,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE;QAC3B,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;KACzB;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/bundler-types';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport glob from 'fast-glob';\nimport { dirname, join } from 'path';\nimport { findGitRoot } from 'workspace-tools';\nimport { findPackagePath } from '../findPackagePath.js';\nimport { isExternalPackage } from '../isExternalPackage.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\n\n/**\n * Find all packages from a given path. We do this by walking the dependency tree\n * of the app to build a map of all packages and their dependencies.\n */\nexport async function findPackagesFromPath(\n options: {\n /**\n * Paths to search for package.json files and traverse their dependencies to build a PackageMap.\n */\n paths: string[];\n\n /**\n * Where to stop looking for packages. If not specified, will look for a git root. If one is not\n * found, will use the first path in the paths array.\n */\n gitRootPath?: string;\n\n /**\n * If true will glob for all package.json files in the path and add them to the map.\n */\n discoverPackages?: boolean;\n },\n context: {\n /**\n * Package cache.\n */\n packages: PackageDefinitionsCache;\n },\n): Promise<PackageMap> {\n const { paths, discoverPackages } = options;\n const { packages } = context;\n const packageMap: PackageMap = {};\n const visitedPaths = new Set<string>();\n const pathsToVisit: string[] = [];\n\n for (const path of paths) {\n if (!(await isFolder(path))) {\n throw new Error(`Path ${path} is not a folder.`);\n }\n\n let { gitRootPath } = options;\n\n if (!gitRootPath) {\n try {\n gitRootPath = findGitRoot(path);\n } catch (e) {\n /* ignore */\n }\n }\n\n if (discoverPackages) {\n const packagePaths = await glob('**/package.json', { cwd: path, ignore: ['**/node_modules/**'] });\n\n pathsToVisit.push(...packagePaths.map((p) => dirname(join(path, p))));\n } else {\n pathsToVisit.push(path);\n }\n\n while (pathsToVisit.length) {\n const packagePath = pathsToVisit.shift();\n\n if (packagePath && !visitedPaths.has(packagePath)) {\n visitedPaths.add(packagePath);\n\n const packageDefinition = await packages.get(packagePath);\n\n if (!packageDefinition) {\n throw new Error(`Could not find package definition at \"${packagePath}\".`);\n }\n\n if (packageDefinition?.name && packageDefinition.version) {\n const { name, version } = packageDefinition;\n const entry = initPackageEntry({ path: packagePath, packageMap, definition: packageDefinition });\n\n // Add all dependencies to the list of paths to visit.\n const dependencies = {\n ...(packageDefinition.dependencies || {}),\n ...(packageDefinition.peerDependencies || {}),\n } as Record<string, string>;\n\n for (const [dependencyName, versionRequirement] of Object.entries(dependencies)) {\n const isPeerDependency = !!packageDefinition.peerDependencies?.[dependencyName];\n\n const dependencyPath = await findPackagePath(\n {\n dependencyName,\n startPath: packagePath,\n gitRootPath,\n },\n context,\n );\n\n if (dependencyPath) {\n const dependencyDefinition = await packages.get(dependencyPath);\n if (dependencyDefinition?.name && dependencyDefinition.version) {\n const dependencyEntry = initPackageEntry({\n path: dependencyPath,\n packageMap,\n definition: dependencyDefinition,\n });\n\n entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;\n dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;\n\n pathsToVisit.push(dependencyPath);\n }\n } else if (!isPeerDependency) {\n throw new Error(\n `Could not find dependency \"${dependencyName}\" at \"${packagePath}\" with version requirement \"${versionRequirement}\".`,\n );\n }\n }\n }\n }\n }\n }\n\n return packageMap;\n}\n\nfunction initPackageEntry(options: { path: string; packageMap: PackageMap; definition: PackageJson }): ResolveMapEntry {\n const { path = '', packageMap, definition } = options;\n const { name = '_no_name_', version = '*' } = definition;\n\n const mapEntry = (packageMap[name] ??= {}) as Record<string, ResolveMapEntry>;\n const entry = (mapEntry[version] ??= {\n name,\n version,\n path,\n dependencies: {},\n requiredBy: {},\n });\n\n if (isExternalPackage(path)) {\n entry.isExternal = true;\n }\n\n return entry;\n}\n"]}
|
package/lib/findPackagePath.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param options
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
2
|
export declare function findPackagePath(options: {
|
|
8
3
|
dependencyName: string;
|
|
9
|
-
|
|
10
|
-
cwd: string;
|
|
4
|
+
startPath: string;
|
|
11
5
|
gitRootPath?: string;
|
|
12
6
|
}, context: {
|
|
13
7
|
packages: PackageDefinitionsCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findPackagePath.d.ts","sourceRoot":"","sources":["../src/findPackagePath.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"findPackagePath.d.ts","sourceRoot":"","sources":["../src/findPackagePath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,wBAAsB,eAAe,CACnC,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA6B7B"}
|
package/lib/findPackagePath.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fsPromises from 'fs/promises';
|
|
3
|
-
import semver from 'semver';
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param options
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
3
|
export async function findPackagePath(options, context) {
|
|
10
|
-
const { dependencyName,
|
|
4
|
+
const { dependencyName, gitRootPath, startPath } = options;
|
|
11
5
|
const { packages } = context;
|
|
12
|
-
let packagePath =
|
|
6
|
+
let packagePath = startPath;
|
|
13
7
|
do {
|
|
14
8
|
const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);
|
|
15
9
|
const definition = await packages.get(resolvedPath);
|
|
16
|
-
if (definition
|
|
10
|
+
if (definition) {
|
|
17
11
|
return fsPromises.realpath(resolvedPath);
|
|
18
12
|
}
|
|
19
13
|
// We haven't found it. Try to move up a directory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findPackagePath.js","sourceRoot":"","sources":["../src/findPackagePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"findPackagePath.js","sourceRoot":"","sources":["../src/findPackagePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAIC,EACD,OAEC;IAED,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,IAAI,WAAW,GAAG,SAAS,CAAC;IAE5B,GAAG;QACD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAEpD,IAAI,UAAU,EAAE;YACd,OAAO,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;SAC1C;QAED,mDAAmD;QACnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExC,oDAAoD;QACpD,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC9C,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SACzC;QAED,yCAAyC;QACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;YACxC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SACzC;KACF,QAAQ,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,WAAW,EAAE;IAElH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport fsPromises from 'fs/promises';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport async function findPackagePath(\n options: {\n dependencyName: string;\n startPath: string;\n gitRootPath?: string;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<string | undefined> {\n const { dependencyName, gitRootPath, startPath } = options;\n const { packages } = context;\n\n let packagePath = startPath;\n\n do {\n const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);\n const definition = await packages.get(resolvedPath);\n\n if (definition) {\n return fsPromises.realpath(resolvedPath);\n }\n\n // We haven't found it. Try to move up a directory.\n packagePath = path.dirname(packagePath);\n\n // If we moved up into a scope folder, skip over it.\n if (path.basename(packagePath).startsWith('@')) {\n packagePath = path.dirname(packagePath);\n }\n\n // Skip over nested node_modules folders.\n if (packagePath.endsWith('node_modules')) {\n packagePath = path.dirname(packagePath);\n }\n } while ((!gitRootPath || packagePath.length >= gitRootPath.length) && path.dirname(packagePath) !== packagePath);\n\n return undefined;\n}\n"]}
|
package/lib/getExportsMap.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';
|
|
2
2
|
export declare function getExportsMap(options: {
|
|
3
3
|
packagePath: string;
|
|
4
|
+
disableTransforms?: boolean;
|
|
4
5
|
}, context: {
|
|
5
6
|
packages: PackageDefinitionsCache;
|
|
6
7
|
}): Promise<PackageJsonExports>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportsMap.d.ts","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,wBAAsB,aAAa,CACjC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"getExportsMap.d.ts","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,wBAAsB,aAAa,CACjC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,EAC7D,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAY7B"}
|
package/lib/getExportsMap.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createExportsMap } from './createExportsMap.js';
|
|
|
2
2
|
export async function getExportsMap(options, context) {
|
|
3
3
|
const { packagePath } = options;
|
|
4
4
|
const { packages } = context;
|
|
5
|
-
const packageDefinition = await packages.get(packagePath);
|
|
5
|
+
const packageDefinition = await packages.get(packagePath, options);
|
|
6
6
|
if (!packageDefinition) {
|
|
7
7
|
throw new Error(`Package definition not found for ${packagePath}`);
|
|
8
8
|
}
|
package/lib/getExportsMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportsMap.js","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,
|
|
1
|
+
{"version":3,"file":"getExportsMap.js","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6D,EAC7D,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oCAAoC,WAAW,EAAE,CAAC,CAAC;KACpE;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC;IAEtC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACpF,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { createExportsMap } from './createExportsMap.js';\n\nexport async function getExportsMap(\n options: { packagePath: string; disableTransforms?: boolean },\n context: { packages: PackageDefinitionsCache },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const packageDefinition = await packages.get(packagePath, options);\n\n if (!packageDefinition) {\n throw new Error(`Package definition not found for ${packagePath}`);\n }\n\n const { exports } = packageDefinition;\n\n return exports === undefined ? await createExportsMap(options, context) : exports;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ms-cloudpack/bundler-types": "^0.
|
|
16
|
+
"@ms-cloudpack/bundler-types": "^0.17.0",
|
|
17
17
|
"@ms-cloudpack/json-utilities": "^0.0.7",
|
|
18
|
-
"@ms-cloudpack/package-overrides": "^0.
|
|
19
|
-
"@ms-cloudpack/path-utilities": "^2.3.
|
|
18
|
+
"@ms-cloudpack/package-overrides": "^0.4.0",
|
|
19
|
+
"@ms-cloudpack/path-utilities": "^2.3.2",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.0.3",
|
|
21
21
|
"fast-glob": "^3.2.12",
|
|
22
22
|
"merge": "^2.1.1",
|