@qiankunjs/shared 0.0.1-beta.0 → 0.0.1-rc.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.
@@ -1,7 +1,7 @@
1
1
  import type { MatchResult } from './types';
2
2
  declare global {
3
3
  interface HTMLElement {
4
- __cached_deps__?: string[];
4
+ __matched_deps__?: string[];
5
5
  }
6
6
  }
7
7
  export type { MatchResult } from './types';
@@ -24,10 +24,10 @@ function moduleResolver(url, microAppContainer, mainAppContainer) {
24
24
  if (mainAppDependencyMapString) {
25
25
  var _microAppContainer$__;
26
26
  var mainAppDependencyMap = JSON.parse(mainAppDependencyMapString);
27
- var cachedDeps = (_microAppContainer$__ = microAppContainer.__cached_deps__) !== null && _microAppContainer$__ !== void 0 ? _microAppContainer$__ : microAppContainer.__cached_deps__ = [];
28
- var matchedDep = findDependency(microAppDependency, normalizeDependencies(mainAppDependencyMap.dependencies), cachedDeps);
27
+ var matchedDeps = (_microAppContainer$__ = microAppContainer.__matched_deps__) !== null && _microAppContainer$__ !== void 0 ? _microAppContainer$__ : microAppContainer.__matched_deps__ = [];
28
+ var matchedDep = findDependency(microAppDependency, normalizeDependencies(mainAppDependencyMap.dependencies), matchedDeps);
29
29
  if (matchedDep) {
30
- cachedDeps.push(matchedDep.name);
30
+ matchedDeps.push(matchedDep.name);
31
31
  return matchedDep;
32
32
  }
33
33
  }
@@ -35,13 +35,13 @@ function moduleResolver(url, microAppContainer, mainAppContainer) {
35
35
  }
36
36
  return undefined;
37
37
  }
38
- function findDependency(dependency, mainAppDependencies, cachedDependencies) {
39
- var matched = mainAppDependencies.find(function (cachedDependency) {
40
- var _dependency$peerDeps;
41
- return cachedDependency.name === dependency.name && (0, _satisfies.default)(cachedDependency.version, dependency.range) && ( // peer dependencies must be cached before
42
- (_dependency$peerDeps = dependency.peerDeps) === null || _dependency$peerDeps === void 0 ? void 0 : _dependency$peerDeps.every(function (peerDep) {
43
- return cachedDependencies.indexOf(peerDep) !== -1;
44
- }));
38
+ function findDependency(dependency, mainAppDependencies, matchedDependencies) {
39
+ var matched = mainAppDependencies.find(function (mainAppDependency) {
40
+ return mainAppDependency.name === dependency.name && (0, _satisfies.default)(mainAppDependency.version, dependency.range) &&
41
+ // peer dependencies must be cached before
42
+ (dependency.peerDeps || []).every(function (peerDep) {
43
+ return matchedDependencies.indexOf(peerDep) !== -1;
44
+ });
45
45
  });
46
46
  if (matched) {
47
47
  return {
@@ -1 +1 @@
1
- {"version":3,"names":["_satisfies","_interopRequireDefault","require","moduleResolver","url","microAppContainer","mainAppContainer","_microAppContainer$qu","dependencyMapSelector","microAppDependenciesString","querySelector","innerHTML","_ref","JSON","parse","dependencies","normalizedDependencies","normalizeDependencies","microAppDependency","find","v","_mainAppContainer$que","mainAppDependencyMapString","_microAppContainer$__","mainAppDependencyMap","cachedDeps","__cached_deps__","matchedDep","findDependency","push","name","undefined","dependency","mainAppDependencies","cachedDependencies","matched","cachedDependency","_dependency$peerDeps","satisfies","version","range","peerDeps","every","peerDep","indexOf","Object","keys","map","_objectSpread2","default"],"sources":["../../../src/module-resolver/index.ts"],"sourcesContent":["import satisfies from 'semver/functions/satisfies';\nimport type { MatchResult } from './types';\n\ndeclare global {\n interface HTMLElement {\n __cached_deps__?: string[];\n }\n}\n\ntype Dependency = {\n url: string;\n version: string;\n range: string;\n peerDeps?: string[];\n};\n\ntype NormalizedDependency = {\n name: string;\n} & Dependency;\n\ntype DependencyMap = {\n dependencies: Record<string, Dependency>;\n};\n\nexport type { MatchResult } from './types';\n\nexport function moduleResolver(\n url: string,\n microAppContainer: HTMLElement,\n mainAppContainer: HTMLElement,\n): MatchResult | undefined {\n const dependencyMapSelector = 'script[type=dependencymap]';\n\n const microAppDependenciesString = microAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n if (microAppDependenciesString) {\n const { dependencies } = JSON.parse(microAppDependenciesString) as DependencyMap;\n const normalizedDependencies = normalizeDependencies(dependencies);\n const microAppDependency = normalizedDependencies.find((v) => v.url === url);\n\n if (microAppDependency) {\n const mainAppDependencyMapString = mainAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n\n if (mainAppDependencyMapString) {\n const mainAppDependencyMap = JSON.parse(mainAppDependencyMapString) as DependencyMap;\n const cachedDeps = (microAppContainer.__cached_deps__ ??= []);\n const matchedDep = findDependency(\n microAppDependency,\n normalizeDependencies(mainAppDependencyMap.dependencies),\n cachedDeps,\n );\n\n if (matchedDep) {\n cachedDeps.push(matchedDep.name);\n return matchedDep;\n }\n }\n }\n }\n\n return undefined;\n}\n\nfunction findDependency(\n dependency: NormalizedDependency,\n mainAppDependencies: NormalizedDependency[],\n cachedDependencies: string[],\n): MatchResult | undefined {\n const matched = mainAppDependencies.find(\n (cachedDependency) =>\n cachedDependency.name === dependency.name &&\n satisfies(cachedDependency.version, dependency.range) &&\n // peer dependencies must be cached before\n dependency.peerDeps?.every((peerDep) => cachedDependencies.indexOf(peerDep) !== -1),\n );\n\n if (matched) {\n return {\n name: matched.name,\n version: matched.version,\n url: matched.url,\n };\n }\n\n return undefined;\n}\n\nfunction normalizeDependencies(dependencies: DependencyMap['dependencies']): NormalizedDependency[] {\n return Object.keys(dependencies).map((name) => ({\n name,\n ...dependencies[name],\n }));\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AA0BO,SAASC,cAAcA,CAC5BC,GAAW,EACXC,iBAA8B,EAC9BC,gBAA6B,EACJ;EAAA,IAAAC,qBAAA;EACzB,IAAMC,qBAAqB,GAAG,4BAA4B;EAE1D,IAAMC,0BAA0B,IAAAF,qBAAA,GAAGF,iBAAiB,CAACK,aAAa,CAACF,qBAAqB,CAAC,cAAAD,qBAAA,uBAAtDA,qBAAA,CAAwDI,SAAS;EACpG,IAAIF,0BAA0B,EAAE;IAC9B,IAAAG,IAAA,GAAyBC,IAAI,CAACC,KAAK,CAACL,0BAA0B,CAAC;MAAvDM,YAAY,GAAAH,IAAA,CAAZG,Y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AJ,oBAAA,uBAAnBA,oBAAA,CAAqBK,KAAK,CAAC,UAACC,OAAO;MAAA,OAAKT,kBAAkB,CAACU,OAAO,CAACD,OAAO,CAAC,KAAK,CAAC,CAAC;IAAA,EAAC;EAAA,CACvF,CAAC;EAED,IAAIR,OAAO,EAAE;IACX,OAAO;MACLL,IAAI,EAAEK,OAAO,CAACL,IAAI;MAClBS,OAAO,EAAEJ,OAAO,CAACI,OAAO;MACxBnC,GAAG,EAAE+B,OAAO,CAAC/B;IACf,CAAC;EACH;EAEA,OAAO2B,SAAS;AAClB;AAEA,SAASd,qBAAqBA,CAACF,YAA2C,EAA0B;EAClG,OAAO8B,MAAM,CAACC,IAAI,CAAC/B,YAAY,CAAC,CAACgC,GAAG,CAAC,UAACjB,IAAI;IAAA,WAAAkB,cAAA,CAAAC,OAAA;MACxCnB,IAAI,EAAJA;IAAI,GACDf,YAAY,CAACe,IAAI,CAAC;EAAA,CACrB,CAAC;AACL"}
1
+ {"version":3,"names":["_satisfies","_interopRequireDefault","require","moduleResolver","url","microAppContainer","mainAppContainer","_microAppContainer$qu","dependencyMapSelector","microAppDependenciesString","querySelector","innerHTML","_ref","JSON","parse","dependencies","normalizedDependencies","normalizeDependencies","microAppDependency","find","v","_mainAppContainer$que","mainAppDependencyMapString","_microAppContainer$__","mainAppDependencyMap","matchedDeps","__matched_deps__","matchedDep","findDependency","push","name","undefined","dependency","mainAppDependencies","matchedDependencies","matched","mainAppDependency","satisfies","version","range","peerDeps","every","peerDep","indexOf","Object","keys","map","_objectSpread2","default"],"sources":["../../../src/module-resolver/index.ts"],"sourcesContent":["import satisfies from 'semver/functions/satisfies';\nimport type { MatchResult } from './types';\n\ndeclare global {\n interface HTMLElement {\n __matched_deps__?: string[];\n }\n}\n\ntype Dependency = {\n url: string;\n version: string;\n range: string;\n peerDeps?: string[];\n};\n\ntype NormalizedDependency = {\n name: string;\n} & Dependency;\n\ntype DependencyMap = {\n dependencies: Record<string, Dependency>;\n};\n\nexport type { MatchResult } from './types';\n\nexport function moduleResolver(\n url: string,\n microAppContainer: HTMLElement,\n mainAppContainer: HTMLElement,\n): MatchResult | undefined {\n const dependencyMapSelector = 'script[type=dependencymap]';\n\n const microAppDependenciesString = microAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n if (microAppDependenciesString) {\n const { dependencies } = JSON.parse(microAppDependenciesString) as DependencyMap;\n const normalizedDependencies = normalizeDependencies(dependencies);\n const microAppDependency = normalizedDependencies.find((v) => v.url === url);\n\n if (microAppDependency) {\n const mainAppDependencyMapString = mainAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n\n if (mainAppDependencyMapString) {\n const mainAppDependencyMap = JSON.parse(mainAppDependencyMapString) as DependencyMap;\n const matchedDeps = (microAppContainer.__matched_deps__ ??= []);\n const matchedDep = findDependency(\n microAppDependency,\n normalizeDependencies(mainAppDependencyMap.dependencies),\n matchedDeps,\n );\n\n if (matchedDep) {\n matchedDeps.push(matchedDep.name);\n return matchedDep;\n }\n }\n }\n }\n\n return undefined;\n}\n\nfunction findDependency(\n dependency: NormalizedDependency,\n mainAppDependencies: NormalizedDependency[],\n matchedDependencies: string[],\n): MatchResult | undefined {\n const matched = mainAppDependencies.find(\n (mainAppDependency) =>\n mainAppDependency.name === dependency.name &&\n satisfies(mainAppDependency.version, dependency.range) &&\n // peer dependencies must be cached before\n (dependency.peerDeps || []).every((peerDep) => matchedDependencies.indexOf(peerDep) !== -1),\n );\n\n if (matched) {\n return {\n name: matched.name,\n version: matched.version,\n url: matched.url,\n };\n }\n\n return undefined;\n}\n\nfunction normalizeDependencies(dependencies: DependencyMap['dependencies']): NormalizedDependency[] {\n return Object.keys(dependencies).map((name) => ({\n name,\n ...dependencies[name],\n }));\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AA0BO,SAASC,cAAcA,CAC5BC,GAAW,EACXC,iBAA8B,EAC9BC,gBAA6B,EACJ;EAAA,IAAAC,qBAAA;EACzB,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,mBAA6B,EACJ;EACzB,IAAMC,OAAO,GAAGF,mBAAmB,CAACd,IAAI,CACtC,UAACiB,iBAAiB;IAAA,OAChBA,iBAAiB,CAACN,IAAI,KAAKE,UAAU,CAACF,IAAI,IAC1C,IAAAO,kBAAS,EAACD,iBAAiB,CAACE,OAAO,EAAEN,UAAU,CAACO,KAAK,CAAC;IACtD;IACA,CAACP,UAAU,CAACQ,QAAQ,IAAI,EAAE,EAAEC,KAAK,CAAC,UAACC,OAAO;MAAA,OAAKR,mBAAmB,CAACS,OAAO,CAACD,OAAO,CAAC,KAAK,CAAC,CAAC;IAAA,EAAC;EAAA,CAC/F,CAAC;EAED,IAAIP,OAAO,EAAE;IACX,OAAO;MACLL,IAAI,EAAEK,OAAO,CAACL,IAAI;MAClBQ,OAAO,EAAEH,OAAO,CAACG,OAAO;MACxBlC,GAAG,EAAE+B,OAAO,CAAC/B;IACf,CAAC;EACH;EAEA,OAAO2B,SAAS;AAClB;AAEA,SAASd,qBAAqBA,CAACF,YAA2C,EAA0B;EAClG,OAAO6B,MAAM,CAACC,IAAI,CAAC9B,YAAY,CAAC,CAAC+B,GAAG,CAAC,UAAChB,IAAI;IAAA,WAAAiB,cAAA,CAAAC,OAAA;MACxClB,IAAI,EAAJA;IAAI,GACDf,YAAY,CAACe,IAAI,CAAC;EAAA,CACrB,CAAC;AACL"}
@@ -1,7 +1,7 @@
1
1
  import type { MatchResult } from './types';
2
2
  declare global {
3
3
  interface HTMLElement {
4
- __cached_deps__?: string[];
4
+ __matched_deps__?: string[];
5
5
  }
6
6
  }
7
7
  export type { MatchResult } from './types';
@@ -17,10 +17,10 @@ export function moduleResolver(url, microAppContainer, mainAppContainer) {
17
17
  if (mainAppDependencyMapString) {
18
18
  var _microAppContainer$__;
19
19
  var mainAppDependencyMap = JSON.parse(mainAppDependencyMapString);
20
- var cachedDeps = (_microAppContainer$__ = microAppContainer.__cached_deps__) !== null && _microAppContainer$__ !== void 0 ? _microAppContainer$__ : microAppContainer.__cached_deps__ = [];
21
- var matchedDep = findDependency(microAppDependency, normalizeDependencies(mainAppDependencyMap.dependencies), cachedDeps);
20
+ var matchedDeps = (_microAppContainer$__ = microAppContainer.__matched_deps__) !== null && _microAppContainer$__ !== void 0 ? _microAppContainer$__ : microAppContainer.__matched_deps__ = [];
21
+ var matchedDep = findDependency(microAppDependency, normalizeDependencies(mainAppDependencyMap.dependencies), matchedDeps);
22
22
  if (matchedDep) {
23
- cachedDeps.push(matchedDep.name);
23
+ matchedDeps.push(matchedDep.name);
24
24
  return matchedDep;
25
25
  }
26
26
  }
@@ -28,13 +28,13 @@ export function moduleResolver(url, microAppContainer, mainAppContainer) {
28
28
  }
29
29
  return undefined;
30
30
  }
31
- function findDependency(dependency, mainAppDependencies, cachedDependencies) {
32
- var matched = mainAppDependencies.find(function (cachedDependency) {
33
- var _dependency$peerDeps;
34
- return cachedDependency.name === dependency.name && satisfies(cachedDependency.version, dependency.range) && ( // peer dependencies must be cached before
35
- (_dependency$peerDeps = dependency.peerDeps) === null || _dependency$peerDeps === void 0 ? void 0 : _dependency$peerDeps.every(function (peerDep) {
36
- return cachedDependencies.indexOf(peerDep) !== -1;
37
- }));
31
+ function findDependency(dependency, mainAppDependencies, matchedDependencies) {
32
+ var matched = mainAppDependencies.find(function (mainAppDependency) {
33
+ return mainAppDependency.name === dependency.name && satisfies(mainAppDependency.version, dependency.range) &&
34
+ // peer dependencies must be cached before
35
+ (dependency.peerDeps || []).every(function (peerDep) {
36
+ return matchedDependencies.indexOf(peerDep) !== -1;
37
+ });
38
38
  });
39
39
  if (matched) {
40
40
  return {
@@ -1 +1 @@
1
- {"version":3,"names":["satisfies","moduleResolver","url","microAppContainer","mainAppContainer","_microAppContainer$qu","dependencyMapSelector","microAppDependenciesString","querySelector","innerHTML","_ref","JSON","parse","dependencies","normalizedDependencies","normalizeDependencies","microAppDependency","find","v","_mainAppContainer$que","mainAppDependencyMapString","_microAppContainer$__","mainAppDependencyMap","cachedDeps","__cached_deps__","matchedDep","findDependency","push","name","undefined","dependency","mainAppDependencies","cachedDependencies","matched","cachedDependency","_dependency$peerDeps","version","range","peerDeps","every","peerDep","indexOf","Object","keys","map","_objectSpread"],"sources":["../../../src/module-resolver/index.ts"],"sourcesContent":["import satisfies from 'semver/functions/satisfies';\nimport type { MatchResult } from './types';\n\ndeclare global {\n interface HTMLElement {\n __cached_deps__?: string[];\n }\n}\n\ntype Dependency = {\n url: string;\n version: string;\n range: string;\n peerDeps?: string[];\n};\n\ntype NormalizedDependency = {\n name: string;\n} & Dependency;\n\ntype DependencyMap = {\n dependencies: Record<string, Dependency>;\n};\n\nexport type { MatchResult } from './types';\n\nexport function moduleResolver(\n url: string,\n microAppContainer: HTMLElement,\n mainAppContainer: HTMLElement,\n): MatchResult | undefined {\n const dependencyMapSelector = 'script[type=dependencymap]';\n\n const microAppDependenciesString = microAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n if (microAppDependenciesString) {\n const { dependencies } = JSON.parse(microAppDependenciesString) as DependencyMap;\n const normalizedDependencies = normalizeDependencies(dependencies);\n const microAppDependency = normalizedDependencies.find((v) => v.url === url);\n\n if (microAppDependency) {\n const mainAppDependencyMapString = mainAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n\n if (mainAppDependencyMapString) {\n const mainAppDependencyMap = JSON.parse(mainAppDependencyMapString) as DependencyMap;\n const cachedDeps = (microAppContainer.__cached_deps__ ??= []);\n const matchedDep = findDependency(\n microAppDependency,\n normalizeDependencies(mainAppDependencyMap.dependencies),\n cachedDeps,\n );\n\n if (matchedDep) {\n cachedDeps.push(matchedDep.name);\n return matchedDep;\n }\n }\n }\n }\n\n return undefined;\n}\n\nfunction findDependency(\n dependency: NormalizedDependency,\n mainAppDependencies: NormalizedDependency[],\n cachedDependencies: string[],\n): MatchResult | undefined {\n const matched = mainAppDependencies.find(\n (cachedDependency) =>\n cachedDependency.name === dependency.name &&\n satisfies(cachedDependency.version, dependency.range) &&\n // peer dependencies must be cached before\n dependency.peerDeps?.every((peerDep) => cachedDependencies.indexOf(peerDep) !== -1),\n );\n\n if (matched) {\n return {\n name: matched.name,\n version: matched.version,\n url: matched.url,\n };\n }\n\n return undefined;\n}\n\nfunction normalizeDependencies(dependencies: DependencyMap['dependencies']): NormalizedDependency[] {\n return Object.keys(dependencies).map((name) => ({\n name,\n ...dependencies[name],\n }));\n}\n"],"mappings":";AAAA,OAAOA,SAAS,MAAM,4BAA4B;AA0BlD,OAAO,SAASC,cAAcA,CAC5BC,GAAW,EACXC,iBAA8B,EAC9BC,gBAA6B,EACJ;EAAA,IAAAC,qBAAA;EACzB,IAAMC,qBAAqB,GAAG,4BAA4B;EAE1D,IAAMC,0BAA0B,IAAAF,qBAAA,GAAGF,iBAAiB,CAACK,aAAa,CAACF,qBAAqB,CAAC,cAAAD,qBAAA,uBAAtDA,qBAAA,CAAwDI,SAAS;EACpG,IAAIF,0BAA0B,EAAE;IAC9B,IAAAG,IAAA,GAAyBC,IAAI,CAACC,KAAK,CAACL,0BAA0B,CAAC;MAAvDM,YAAY,GAAAH,IAAA,CAAZG,YAAY;IACpB,IAAMC,sBAAsB,GAAGC,qBAAqB,CAACF,YAAY,CAAC;IAClE,IAAMG,kBAAkB,GAAGF,sBAAsB,CAACG,IAAI,CAAC,UAACC,CAAC;MAAA,OAAKA,CAAC,CAAChB,GAAG,KAAKA,GAAG;IAAA,EAAC;IAE5E,IAAIc,kBAAkB,EAAE;MAAA,IAAAG,qBAAA;MACtB,IAAMC,0BAA0B,IAAAD,qBAAA,GAAGf,gBAAgB,CAACI,aAAa,CAACF,qBAAqB,CAAC,cAAAa,qBAAA,uBAArDA,qBAAA,CAAuDV,SAAS;MAEnG,IAAIW,0BAA0B,EAAE;QAAA,IAAAC,qBAAA;QAC9B,IAAMC,oBAAoB,GAAGX,IAAI,CAACC,KAAK,CAACQ,0BAA0B,CAAkB;QACpF,IAAMG,UAAU,IAAAF,qBAAA,GAAIlB,iBAAiB,CAACqB,eAAe,cAAAH,qBAAA,cAAAA,qB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ACL"}
1
+ {"version":3,"names":["satisfies","moduleResolver","url","microAppContainer","mainAppContainer","_microAppContainer$qu","dependencyMapSelector","microAppDependenciesString","querySelector","innerHTML","_ref","JSON","parse","dependencies","normalizedDependencies","normalizeDependencies","microAppDependency","find","v","_mainAppContainer$que","mainAppDependencyMapString","_microAppContainer$__","mainAppDependencyMap","matchedDeps","__matched_deps__","matchedDep","findDependency","push","name","undefined","dependency","mainAppDependencies","matchedDependencies","matched","mainAppDependency","version","range","peerDeps","every","peerDep","indexOf","Object","keys","map","_objectSpread"],"sources":["../../../src/module-resolver/index.ts"],"sourcesContent":["import satisfies from 'semver/functions/satisfies';\nimport type { MatchResult } from './types';\n\ndeclare global {\n interface HTMLElement {\n __matched_deps__?: string[];\n }\n}\n\ntype Dependency = {\n url: string;\n version: string;\n range: string;\n peerDeps?: string[];\n};\n\ntype NormalizedDependency = {\n name: string;\n} & Dependency;\n\ntype DependencyMap = {\n dependencies: Record<string, Dependency>;\n};\n\nexport type { MatchResult } from './types';\n\nexport function moduleResolver(\n url: string,\n microAppContainer: HTMLElement,\n mainAppContainer: HTMLElement,\n): MatchResult | undefined {\n const dependencyMapSelector = 'script[type=dependencymap]';\n\n const microAppDependenciesString = microAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n if (microAppDependenciesString) {\n const { dependencies } = JSON.parse(microAppDependenciesString) as DependencyMap;\n const normalizedDependencies = normalizeDependencies(dependencies);\n const microAppDependency = normalizedDependencies.find((v) => v.url === url);\n\n if (microAppDependency) {\n const mainAppDependencyMapString = mainAppContainer.querySelector(dependencyMapSelector)?.innerHTML;\n\n if (mainAppDependencyMapString) {\n const mainAppDependencyMap = JSON.parse(mainAppDependencyMapString) as DependencyMap;\n const matchedDeps = (microAppContainer.__matched_deps__ ??= []);\n const matchedDep = findDependency(\n microAppDependency,\n normalizeDependencies(mainAppDependencyMap.dependencies),\n matchedDeps,\n );\n\n if (matchedDep) {\n matchedDeps.push(matchedDep.name);\n return matchedDep;\n }\n }\n }\n }\n\n return undefined;\n}\n\nfunction findDependency(\n dependency: NormalizedDependency,\n mainAppDependencies: NormalizedDependency[],\n matchedDependencies: string[],\n): MatchResult | undefined {\n const matched = mainAppDependencies.find(\n (mainAppDependency) =>\n mainAppDependency.name === dependency.name &&\n satisfies(mainAppDependency.version, dependency.range) &&\n // peer dependencies must be cached before\n (dependency.peerDeps || []).every((peerDep) => matchedDependencies.indexOf(peerDep) !== -1),\n );\n\n if (matched) {\n return {\n name: matched.name,\n version: matched.version,\n url: matched.url,\n };\n }\n\n return undefined;\n}\n\nfunction normalizeDependencies(dependencies: DependencyMap['dependencies']): NormalizedDependency[] {\n return Object.keys(dependencies).map((name) => ({\n name,\n ...dependencies[name],\n }));\n}\n"],"mappings":";AAAA,OAAOA,SAAS,MAAM,4BAA4B;AA0BlD,OAAO,SAASC,cAAcA,CAC5BC,GAAW,EACXC,iBAA8B,EAC9BC,gBAA6B,EACJ;EAAA,IAAAC,qBAAA;EACzB,IAAMC,qBAAqB,GAAG,4BAA4B;EAE1D,IAAMC,0BAA0B,IAAAF,qBAAA,GAAGF,iBAAiB,CAACK,aAAa,CAACF,qBAAqB,CAAC,cAAAD,qBAAA,uBAAtDA,qBAAA,CAAwDI,SAAS;EACpG,IAAIF,0BAA0B,EAAE;IAC9B,IAAAG,IAAA,GAAyBC,IAAI,CAACC,KAAK,CAACL,0BAA0B,CAAC;MAAvDM,YAAY,GAAAH,IAAA,CAAZG,YAAY;IACpB,IAAMC,sBAAsB,GAAGC,qBAAqB,CAACF,YAAY,CAAC;IAClE,IAAMG,kBAAkB,GAAGF,sBAAsB,CAACG,IAAI,CAAC,UAACC,CAAC;MAAA,OAAKA,CAAC,CAAChB,GAAG,KAAKA,GAAG;IAAA,EAAC;IAE5E,IAAIc,kBAAkB,EAAE;MAAA,IAAAG,qBAAA;MACtB,IAAMC,0BAA0B,IAAAD,qBAAA,GAAGf,gBAAgB,CAACI,aAAa,CAACF,qBAAqB,CAAC,cAAAa,qBAAA,uBAAr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;EAClG,OAAO4B,MAAM,CAACC,IAAI,CAAC7B,YAAY,CAAC,CAAC8B,GAAG,CAAC,UAACf,IAAI;IAAA,OAAAgB,aAAA;MACxChB,IAAI,EAAJA;IAAI,GACDf,YAAY,CAACe,IAAI,CAAC;EAAA,CACrB,CAAC;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qiankunjs/shared",
3
- "version": "0.0.1-beta.0",
3
+ "version": "0.0.1-rc.1",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -12,7 +12,7 @@
12
12
  "@babel/runtime": "^7.10.5",
13
13
  "lodash": "^4.17.11",
14
14
  "semver": "^7.5.3",
15
- "@qiankunjs/sandbox": "^0.0.1-beta.0"
15
+ "@qiankunjs/sandbox": "^0.0.1-rc.1"
16
16
  },
17
17
  "files": [
18
18
  "dist",
@@ -3,7 +3,7 @@ import type { MatchResult } from './types';
3
3
 
4
4
  declare global {
5
5
  interface HTMLElement {
6
- __cached_deps__?: string[];
6
+ __matched_deps__?: string[];
7
7
  }
8
8
  }
9
9
 
@@ -42,15 +42,15 @@ export function moduleResolver(
42
42
 
43
43
  if (mainAppDependencyMapString) {
44
44
  const mainAppDependencyMap = JSON.parse(mainAppDependencyMapString) as DependencyMap;
45
- const cachedDeps = (microAppContainer.__cached_deps__ ??= []);
45
+ const matchedDeps = (microAppContainer.__matched_deps__ ??= []);
46
46
  const matchedDep = findDependency(
47
47
  microAppDependency,
48
48
  normalizeDependencies(mainAppDependencyMap.dependencies),
49
- cachedDeps,
49
+ matchedDeps,
50
50
  );
51
51
 
52
52
  if (matchedDep) {
53
- cachedDeps.push(matchedDep.name);
53
+ matchedDeps.push(matchedDep.name);
54
54
  return matchedDep;
55
55
  }
56
56
  }
@@ -63,14 +63,14 @@ export function moduleResolver(
63
63
  function findDependency(
64
64
  dependency: NormalizedDependency,
65
65
  mainAppDependencies: NormalizedDependency[],
66
- cachedDependencies: string[],
66
+ matchedDependencies: string[],
67
67
  ): MatchResult | undefined {
68
68
  const matched = mainAppDependencies.find(
69
- (cachedDependency) =>
70
- cachedDependency.name === dependency.name &&
71
- satisfies(cachedDependency.version, dependency.range) &&
69
+ (mainAppDependency) =>
70
+ mainAppDependency.name === dependency.name &&
71
+ satisfies(mainAppDependency.version, dependency.range) &&
72
72
  // peer dependencies must be cached before
73
- dependency.peerDeps?.every((peerDep) => cachedDependencies.indexOf(peerDep) !== -1),
73
+ (dependency.peerDeps || []).every((peerDep) => matchedDependencies.indexOf(peerDep) !== -1),
74
74
  );
75
75
 
76
76
  if (matched) {