@marko/language-tools 2.1.0 → 2.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/dist/index.js CHANGED
@@ -2932,24 +2932,12 @@ __export(project_exports, {
2932
2932
  });
2933
2933
  var import_path2 = __toESM(require("path"));
2934
2934
  var import_module = require("module");
2935
- var defaultCompiler = __toESM(require("@marko/compiler"));
2936
- var defaultConfig = __toESM(require("@marko/compiler/config"));
2937
- var defaultTranslator = __toESM(require("@marko/translator-default"));
2938
2935
  var import_strip_json_comments = __toESM(require("strip-json-comments"));
2939
2936
  var defaultTypeLibs = {};
2940
2937
  var ignoreErrors = (_err) => {
2941
2938
  };
2942
2939
  var metaByDir = /* @__PURE__ */ new Map();
2943
2940
  var metaByCompiler = /* @__PURE__ */ new Map();
2944
- var defaultMeta = {
2945
- compiler: defaultCompiler,
2946
- config: {
2947
- ...defaultConfig,
2948
- cache: /* @__PURE__ */ new Map(),
2949
- translator: defaultTranslator
2950
- }
2951
- };
2952
- defaultCompiler.configure(defaultMeta.config);
2953
2941
  function getCompiler(dir) {
2954
2942
  return getMeta(dir).compiler;
2955
2943
  }
@@ -3051,7 +3039,6 @@ function getScriptLang(fileName, defaultScriptLang, ts, host) {
3051
3039
  return scriptLang;
3052
3040
  }
3053
3041
  function clearCaches() {
3054
- clearCacheForMeta(defaultMeta);
3055
3042
  for (const project of metaByCompiler.values()) {
3056
3043
  clearCacheForMeta(project);
3057
3044
  }
@@ -3059,24 +3046,22 @@ function clearCaches() {
3059
3046
  function setDefaultTypePaths(defaults) {
3060
3047
  Object.assign(defaultTypeLibs, defaults);
3061
3048
  }
3062
- function getMeta(dir) {
3063
- if (!dir)
3064
- return defaultMeta;
3049
+ function getMeta(dir = __dirname) {
3065
3050
  let cached = metaByDir.get(dir);
3066
3051
  if (!cached) {
3052
+ const fallback = dir === __dirname;
3067
3053
  try {
3068
3054
  const require2 = (0, import_module.createRequire)(dir);
3069
- const compilerConfigPath = require2.resolve("@marko/compiler/config");
3070
- cached = metaByCompiler.get(compilerConfigPath);
3055
+ const configPath = require2.resolve("@marko/compiler/config");
3056
+ cached = metaByCompiler.get(configPath);
3071
3057
  if (!cached) {
3072
3058
  const compiler = require2(import_path2.default.join(
3073
- compilerConfigPath,
3059
+ configPath,
3074
3060
  ".."
3075
3061
  ));
3076
- const config = interopDefault(
3077
- require2(compilerConfigPath)
3078
- );
3062
+ const config = interopDefault(require2(configPath));
3079
3063
  cached = {
3064
+ fallback,
3080
3065
  compiler,
3081
3066
  config: {
3082
3067
  ...config,
@@ -3085,10 +3070,12 @@ function getMeta(dir) {
3085
3070
  }
3086
3071
  };
3087
3072
  compiler.configure(cached.config);
3088
- metaByCompiler.set(compilerConfigPath, cached);
3073
+ metaByCompiler.set(configPath, cached);
3089
3074
  }
3090
- } catch {
3091
- cached = defaultMeta;
3075
+ } catch (err) {
3076
+ if (fallback)
3077
+ throw err;
3078
+ cached = getMeta();
3092
3079
  }
3093
3080
  metaByDir.set(dir, cached);
3094
3081
  }
@@ -3105,8 +3092,8 @@ function getTagLookupForProject(meta, dir) {
3105
3092
  ignoreErrors
3106
3093
  );
3107
3094
  } catch {
3108
- if (meta !== defaultMeta) {
3109
- lookup = getTagLookupForProject(defaultMeta, dir);
3095
+ if (!meta.fallback) {
3096
+ lookup = getTagLookupForProject(getMeta(), dir);
3110
3097
  }
3111
3098
  }
3112
3099
  if (cache) {
package/dist/index.mjs CHANGED
@@ -2900,24 +2900,12 @@ __export(project_exports, {
2900
2900
  });
2901
2901
  import path2 from "path";
2902
2902
  import { createRequire } from "module";
2903
- import * as defaultCompiler from "@marko/compiler";
2904
- import * as defaultConfig from "@marko/compiler/config";
2905
- import * as defaultTranslator from "@marko/translator-default";
2906
2903
  import stripJSONComments from "strip-json-comments";
2907
2904
  var defaultTypeLibs = {};
2908
2905
  var ignoreErrors = (_err) => {
2909
2906
  };
2910
2907
  var metaByDir = /* @__PURE__ */ new Map();
2911
2908
  var metaByCompiler = /* @__PURE__ */ new Map();
2912
- var defaultMeta = {
2913
- compiler: defaultCompiler,
2914
- config: {
2915
- ...defaultConfig,
2916
- cache: /* @__PURE__ */ new Map(),
2917
- translator: defaultTranslator
2918
- }
2919
- };
2920
- defaultCompiler.configure(defaultMeta.config);
2921
2909
  function getCompiler(dir) {
2922
2910
  return getMeta(dir).compiler;
2923
2911
  }
@@ -3019,7 +3007,6 @@ function getScriptLang(fileName, defaultScriptLang, ts, host) {
3019
3007
  return scriptLang;
3020
3008
  }
3021
3009
  function clearCaches() {
3022
- clearCacheForMeta(defaultMeta);
3023
3010
  for (const project of metaByCompiler.values()) {
3024
3011
  clearCacheForMeta(project);
3025
3012
  }
@@ -3027,24 +3014,22 @@ function clearCaches() {
3027
3014
  function setDefaultTypePaths(defaults) {
3028
3015
  Object.assign(defaultTypeLibs, defaults);
3029
3016
  }
3030
- function getMeta(dir) {
3031
- if (!dir)
3032
- return defaultMeta;
3017
+ function getMeta(dir = __dirname) {
3033
3018
  let cached = metaByDir.get(dir);
3034
3019
  if (!cached) {
3020
+ const fallback = dir === __dirname;
3035
3021
  try {
3036
3022
  const require2 = createRequire(dir);
3037
- const compilerConfigPath = require2.resolve("@marko/compiler/config");
3038
- cached = metaByCompiler.get(compilerConfigPath);
3023
+ const configPath = require2.resolve("@marko/compiler/config");
3024
+ cached = metaByCompiler.get(configPath);
3039
3025
  if (!cached) {
3040
3026
  const compiler = require2(path2.join(
3041
- compilerConfigPath,
3027
+ configPath,
3042
3028
  ".."
3043
3029
  ));
3044
- const config = interopDefault(
3045
- require2(compilerConfigPath)
3046
- );
3030
+ const config = interopDefault(require2(configPath));
3047
3031
  cached = {
3032
+ fallback,
3048
3033
  compiler,
3049
3034
  config: {
3050
3035
  ...config,
@@ -3053,10 +3038,12 @@ function getMeta(dir) {
3053
3038
  }
3054
3039
  };
3055
3040
  compiler.configure(cached.config);
3056
- metaByCompiler.set(compilerConfigPath, cached);
3041
+ metaByCompiler.set(configPath, cached);
3057
3042
  }
3058
- } catch {
3059
- cached = defaultMeta;
3043
+ } catch (err) {
3044
+ if (fallback)
3045
+ throw err;
3046
+ cached = getMeta();
3060
3047
  }
3061
3048
  metaByDir.set(dir, cached);
3062
3049
  }
@@ -3073,8 +3060,8 @@ function getTagLookupForProject(meta, dir) {
3073
3060
  ignoreErrors
3074
3061
  );
3075
3062
  } catch {
3076
- if (meta !== defaultMeta) {
3077
- lookup = getTagLookupForProject(defaultMeta, dir);
3063
+ if (!meta.fallback) {
3064
+ lookup = getTagLookupForProject(getMeta(), dir);
3078
3065
  }
3079
3066
  }
3080
3067
  if (cache) {
@@ -1,11 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import type TS from "typescript/lib/tsserverlibrary";
3
3
  import type { TaglibLookup } from "@marko/babel-utils";
4
- import * as defaultCompiler from "@marko/compiler";
4
+ import type * as Compiler from "@marko/compiler";
5
5
  import { ScriptLang } from "../extractors/script";
6
6
  export interface Meta {
7
- compiler: typeof defaultCompiler;
8
- config: Omit<defaultCompiler.Config, "cache" | "translator"> & {
7
+ fallback: boolean;
8
+ compiler: typeof Compiler;
9
+ config: Omit<Compiler.Config, "cache" | "translator"> & {
9
10
  cache: Map<any, any>;
10
11
  translator: {
11
12
  runtimeTypes?: string;
@@ -21,7 +22,7 @@ interface TypeLibs {
21
22
  markoTypesCode: string | undefined;
22
23
  }
23
24
  declare const defaultTypeLibs: Partial<TypeLibs>;
24
- export declare function getCompiler(dir?: string): typeof defaultCompiler;
25
+ export declare function getCompiler(dir?: string): typeof Compiler;
25
26
  export declare function getCache(dir?: string): Map<any, any>;
26
27
  export declare function getConfig(dir?: string): Omit<{
27
28
  output?: "source" | "html" | "dom" | "hydrate" | "migrate" | undefined;
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "2.1.0",
4
+ "version": "2.1.1",
5
5
  "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
+ "peerDependencies": {
7
+ "@marko/compiler": "^5.28.4"
8
+ },
6
9
  "dependencies": {
7
10
  "@babel/helper-validator-identifier": "^7.22.5",
8
- "@babel/parser": "^7.22.5",
9
- "@marko/compiler": "5.28.4",
10
- "@marko/translator-default": "5.26.5",
11
+ "@babel/parser": "^7.22.7",
11
12
  "htmljs-parser": "^5.5.0",
12
13
  "relative-import-path": "^1.0.0"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@babel/code-frame": "^7.22.5",
16
- "@marko/compiler": "^5.28.5",
17
+ "@marko/compiler": "^5.31.1",
18
+ "@marko/translator-default": "^5.29.1",
17
19
  "@types/babel__code-frame": "^7.0.3",
18
20
  "@types/babel__helper-validator-identifier": "^7.15.0",
19
21
  "@typescript/vfs": "^1.4.0",
20
- "marko": "^5.26.5",
22
+ "marko": "^5.29.1",
21
23
  "mitata": "^0.1.6",
22
24
  "tsx": "^3.12.7"
23
25
  },