@effect/language-service 0.23.3 → 0.23.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/README.md CHANGED
@@ -87,7 +87,7 @@ Few options can be provided alongside the initialization of the Language Service
87
87
  "goto": true, // controls Effect goto references (default: true)
88
88
  "allowedDuplicatedPackages": [], // list of package names that has effect in peer dependencies and are allowed to be duplicated (default: [])
89
89
  "barrelImportPackages": [], // package names that should be preferred as imported from the top level barrel file (default: [])
90
- "namespaceImportPackages": [] // package names that should be preferred as imported with namespace imports e.g. ["effect"] (default: [])
90
+ "namespaceImportPackages": [] // package names that should be preferred as imported with namespace imports e.g. ["effect", "@effect/*"] (default: [])
91
91
  }
92
92
  ]
93
93
  }
package/index.js CHANGED
@@ -831,6 +831,7 @@ var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
831
831
  }
832
832
  return [];
833
833
  });
834
+ var dedupe = (self) => dedupeWith(self, equivalence());
834
835
 
835
836
  // src/core/Nano.ts
836
837
  function makeInternalSuccess(value) {
@@ -1029,14 +1030,43 @@ function parsePackageContentNameAndVersionFromScope(v) {
1029
1030
  if (!isString(name)) return;
1030
1031
  if (!isString(version)) return;
1031
1032
  const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
1033
+ const referencedPackages = Object.keys({
1034
+ ...hasProperty(packageJsonContent, "dependencies") && isObject(packageJsonContent.dependencies) ? packageJsonContent.dependencies : {},
1035
+ ...hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) ? packageJsonContent.peerDependencies : {},
1036
+ ...hasProperty(packageJsonContent, "devDependencies") && isObject(packageJsonContent.devDependencies) ? packageJsonContent.devDependencies : {}
1037
+ });
1032
1038
  return {
1033
1039
  name: name.toLowerCase(),
1034
1040
  version: version.toLowerCase(),
1035
1041
  hasEffectInPeerDependencies,
1036
1042
  contents: packageJsonContent,
1037
- packageDirectory: packageJsonScope.packageDirectory
1043
+ packageDirectory: packageJsonScope.packageDirectory,
1044
+ referencedPackages
1038
1045
  };
1039
1046
  }
1047
+ var resolveModulePattern = fn("resolveModulePattern")(
1048
+ function* (sourceFile, pattern) {
1049
+ if (pattern.indexOf("*") === -1) return [pattern.toLowerCase()];
1050
+ const ts = yield* service(TypeScriptApi);
1051
+ const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile);
1052
+ const referencedPackages = [];
1053
+ for (const statement of sourceFile.statements) {
1054
+ if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
1055
+ const moduleSpecifier = statement.moduleSpecifier.text.toLowerCase();
1056
+ const packageName = moduleSpecifier.startsWith("@") ? moduleSpecifier.split("/", 2).join("/") : moduleSpecifier.split("/", 1).join("/");
1057
+ referencedPackages.push(packageName);
1058
+ }
1059
+ }
1060
+ return pipe(
1061
+ referencedPackages.concat(packageJsonScope?.referencedPackages || []),
1062
+ dedupe,
1063
+ map3((packageName) => packageName.toLowerCase()),
1064
+ filter(
1065
+ (packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
1066
+ )
1067
+ );
1068
+ }
1069
+ );
1040
1070
  function makeGetModuleSpecifier(ts) {
1041
1071
  if (!(hasProperty(ts, "moduleSpecifiers") && hasProperty(ts.moduleSpecifiers, "getModuleSpecifier") && isFunction2(ts.moduleSpecifiers.getModuleSpecifier))) return;
1042
1072
  const _internal = ts.moduleSpecifiers.getModuleSpecifier;
@@ -2631,7 +2661,14 @@ var importFromBarrel = createDiagnostic({
2631
2661
  const ts = yield* service(TypeScriptApi);
2632
2662
  const typeChecker = yield* service(TypeCheckerApi);
2633
2663
  const program = yield* service(TypeScriptProgram);
2634
- const isImportedFromBarrelExport = (element, languageServicePluginOptions2) => {
2664
+ const packageNamesToCheck = flatten(
2665
+ yield* all(
2666
+ ...languageServicePluginOptions.namespaceImportPackages.map(
2667
+ (packageName) => resolveModulePattern(sourceFile, packageName)
2668
+ )
2669
+ )
2670
+ );
2671
+ const isImportedFromBarrelExport = (element) => {
2635
2672
  const getModuleSpecifier = makeGetModuleSpecifier(ts);
2636
2673
  const resolveExternalModuleName = makeResolveExternalModuleName(typeChecker);
2637
2674
  if (!(getModuleSpecifier && resolveExternalModuleName)) return;
@@ -2644,7 +2681,7 @@ var importFromBarrel = createDiagnostic({
2644
2681
  if (!namedBindings) return;
2645
2682
  if (!ts.isNamedImports(namedBindings)) return;
2646
2683
  const barrelModuleName = importDeclaration.moduleSpecifier.text;
2647
- if (languageServicePluginOptions2.namespaceImportPackages.indexOf(barrelModuleName.toLowerCase()) === -1) return;
2684
+ if (packageNamesToCheck.indexOf(barrelModuleName.toLowerCase()) === -1) return;
2648
2685
  const moduleSymbol = resolveExternalModuleName(importDeclaration.moduleSpecifier);
2649
2686
  if (!moduleSymbol) return;
2650
2687
  if (!moduleSymbol.exports) return;
@@ -2687,7 +2724,7 @@ var importFromBarrel = createDiagnostic({
2687
2724
  ts.forEachChild(node, appendNodeToVisit);
2688
2725
  continue;
2689
2726
  }
2690
- const result = isImportedFromBarrelExport(node, languageServicePluginOptions);
2727
+ const result = isImportedFromBarrelExport(node);
2691
2728
  if (!result) continue;
2692
2729
  const { barrelModuleName, importClause, importDeclaration, importedName, namedBindings, unbarrelledFileName } = result;
2693
2730
  report({
@@ -3498,69 +3535,71 @@ var makeImportablePackagesMetadata = fn("makeImportablePackagesMetadata")(functi
3498
3535
  const barreledModulePathByFileName = /* @__PURE__ */ new Map();
3499
3536
  const barreledFunctionPathByFileName = /* @__PURE__ */ new Map();
3500
3537
  const packages = [
3501
- ...languageServicePluginOptions.namespaceImportPackages.map((packageName) => ({
3502
- packageName,
3538
+ ...languageServicePluginOptions.namespaceImportPackages.map((packagePattern) => ({
3539
+ packagePattern,
3503
3540
  kind: "namespace"
3504
3541
  })),
3505
- ...languageServicePluginOptions.barrelImportPackages.map((packageName) => ({
3506
- packageName,
3542
+ ...languageServicePluginOptions.barrelImportPackages.map((packagePattern) => ({
3543
+ packagePattern,
3507
3544
  kind: "barrel"
3508
3545
  }))
3509
3546
  ];
3510
- for (const { kind, packageName } of packages) {
3511
- const barrelModule = ts.resolveModuleName(packageName, sourceFile.fileName, program.getCompilerOptions(), host);
3512
- if (barrelModule.resolvedModule) {
3513
- const barrelPath = barrelModule.resolvedModule.resolvedFileName;
3514
- const barrelSource = program.getSourceFile(barrelPath) || ts.createSourceFile(barrelPath, host.readFile(barrelPath) || "", sourceFile.languageVersion, true);
3515
- if (barrelSource) {
3516
- for (const statement of barrelSource.statements) {
3517
- if (ts.isExportDeclaration(statement)) {
3518
- const exportClause = statement.exportClause;
3519
- const moduleSpecifier = statement.moduleSpecifier;
3520
- if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier)) {
3521
- const unbarreledModulePathResolved = ts.resolveModuleName(
3522
- moduleSpecifier.text,
3523
- barrelSource.fileName,
3524
- program.getCompilerOptions(),
3525
- host
3526
- );
3527
- if (unbarreledModulePathResolved.resolvedModule) {
3528
- const unbarreledModulePath = unbarreledModulePathResolved.resolvedModule.resolvedFileName;
3529
- if (exportClause && ts.isNamespaceExport(exportClause) && ts.isIdentifier(exportClause.name)) {
3530
- if (kind === "namespace") {
3531
- namespaceByFileName.set(unbarreledModulePath, exportClause.name.text);
3532
- const existingUnbarreledModulePath = unbarreledModulePathByFileName.get(barrelSource.fileName) || [];
3533
- existingUnbarreledModulePath.push({
3534
- fileName: unbarreledModulePath,
3535
- exportName: exportClause.name.text
3536
- });
3537
- unbarreledModulePathByFileName.set(barrelSource.fileName, existingUnbarreledModulePath);
3538
- }
3539
- if (kind === "barrel") {
3540
- barreledModulePathByFileName.set(unbarreledModulePath, {
3541
- fileName: barrelSource.fileName,
3542
- exportName: exportClause.name.text,
3543
- packageName
3544
- });
3545
- }
3546
- }
3547
- if (exportClause && ts.isNamedExports(exportClause)) {
3548
- for (const element of exportClause.elements) {
3549
- if (!ts.isIdentifier(element.name)) continue;
3550
- const methodName = element.name.text;
3547
+ for (const { kind, packagePattern } of packages) {
3548
+ for (const packageName of yield* resolveModulePattern(sourceFile, packagePattern)) {
3549
+ const barrelModule = ts.resolveModuleName(packageName, sourceFile.fileName, program.getCompilerOptions(), host);
3550
+ if (barrelModule.resolvedModule) {
3551
+ const barrelPath = barrelModule.resolvedModule.resolvedFileName;
3552
+ const barrelSource = program.getSourceFile(barrelPath) || ts.createSourceFile(barrelPath, host.readFile(barrelPath) || "", sourceFile.languageVersion, true);
3553
+ if (barrelSource) {
3554
+ for (const statement of barrelSource.statements) {
3555
+ if (ts.isExportDeclaration(statement)) {
3556
+ const exportClause = statement.exportClause;
3557
+ const moduleSpecifier = statement.moduleSpecifier;
3558
+ if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier)) {
3559
+ const unbarreledModulePathResolved = ts.resolveModuleName(
3560
+ moduleSpecifier.text,
3561
+ barrelSource.fileName,
3562
+ program.getCompilerOptions(),
3563
+ host
3564
+ );
3565
+ if (unbarreledModulePathResolved.resolvedModule) {
3566
+ const unbarreledModulePath = unbarreledModulePathResolved.resolvedModule.resolvedFileName;
3567
+ if (exportClause && ts.isNamespaceExport(exportClause) && ts.isIdentifier(exportClause.name)) {
3551
3568
  if (kind === "namespace") {
3552
- const excludedMethods = excludedByFileName.get(methodName) || [];
3553
- excludedMethods.push(unbarreledModulePath);
3554
- excludedByFileName.set(methodName, excludedMethods);
3569
+ namespaceByFileName.set(unbarreledModulePath, exportClause.name.text);
3570
+ const existingUnbarreledModulePath = unbarreledModulePathByFileName.get(barrelSource.fileName) || [];
3571
+ existingUnbarreledModulePath.push({
3572
+ fileName: unbarreledModulePath,
3573
+ exportName: exportClause.name.text
3574
+ });
3575
+ unbarreledModulePathByFileName.set(barrelSource.fileName, existingUnbarreledModulePath);
3555
3576
  }
3556
3577
  if (kind === "barrel") {
3557
- const previousBarreledFunctionPath = barreledFunctionPathByFileName.get(unbarreledModulePath) || [];
3558
- previousBarreledFunctionPath.push({
3578
+ barreledModulePathByFileName.set(unbarreledModulePath, {
3559
3579
  fileName: barrelSource.fileName,
3560
- exportName: methodName,
3580
+ exportName: exportClause.name.text,
3561
3581
  packageName
3562
3582
  });
3563
- barreledFunctionPathByFileName.set(unbarreledModulePath, previousBarreledFunctionPath);
3583
+ }
3584
+ }
3585
+ if (exportClause && ts.isNamedExports(exportClause)) {
3586
+ for (const element of exportClause.elements) {
3587
+ if (!ts.isIdentifier(element.name)) continue;
3588
+ const methodName = element.name.text;
3589
+ if (kind === "namespace") {
3590
+ const excludedMethods = excludedByFileName.get(methodName) || [];
3591
+ excludedMethods.push(unbarreledModulePath);
3592
+ excludedByFileName.set(methodName, excludedMethods);
3593
+ }
3594
+ if (kind === "barrel") {
3595
+ const previousBarreledFunctionPath = barreledFunctionPathByFileName.get(unbarreledModulePath) || [];
3596
+ previousBarreledFunctionPath.push({
3597
+ fileName: barrelSource.fileName,
3598
+ exportName: methodName,
3599
+ packageName
3600
+ });
3601
+ barreledFunctionPathByFileName.set(unbarreledModulePath, previousBarreledFunctionPath);
3602
+ }
3564
3603
  }
3565
3604
  }
3566
3605
  }