ms-types 0.11.5 → 0.11.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/ts-plugin/idea.cjs +14 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-types",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "types": "./types/index.d.ts",
@@ -2,25 +2,34 @@
2
2
 
3
3
  // IDEA 没有 typescriptServerPlugins,用 `-r` 预加载:在 JetBrains 的 tsc-ide-plugin 创建项目时,
4
4
  // 对快点JS项目调用 index.cjs 的 inject。tsserver 进程是所有工程共用的,所以要先判断是不是快点JS项目:
5
- // 从项目目录往上找带 `ms build` / `ms package` 脚本的 package.json。
5
+ // 从项目目录往上找快点JS项目:目录下有 package.json,并且 scripts 里有入口文件
6
+ // (main.js / main.ts / main.py / main.lua 之一)。不看 package.json 的内容。
7
+ // VS Code / IDEA 插件的项目识别也是这条规则,要一起改。
6
8
  const fs = require('fs');
7
9
  const path = require('path');
8
10
  const Module = require('module');
9
11
  const { inject } = require('./index.cjs');
10
12
 
11
- const MS_SCRIPT = /\bms\s+(build|package)\b/;
13
+ const MAIN_SCRIPT_BASENAMES = ['main.js', 'main.ts', 'main.py', 'main.lua'];
12
14
  const MAX_ASCEND = 4;
13
15
  const projectCache = new Map();
14
16
 
15
- function hasKuaiJsPackage(dir) {
17
+ // 路径存在并且是文件(同名目录不算)。
18
+ function isFile(file) {
16
19
  try {
17
- const scripts = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).scripts || {};
18
- return ['dev', 'build', 'package'].some((key) => MS_SCRIPT.test(String(scripts[key] || '')));
20
+ return fs.statSync(file).isFile();
19
21
  } catch (ignored) {
20
22
  return false;
21
23
  }
22
24
  }
23
25
 
26
+ function hasKuaiJsPackage(dir) {
27
+ return (
28
+ isFile(path.join(dir, 'package.json')) &&
29
+ MAIN_SCRIPT_BASENAMES.some((name) => isFile(path.join(dir, 'scripts', name)))
30
+ );
31
+ }
32
+
24
33
  function isKuaiJsProject(info) {
25
34
  let dir;
26
35
  try {