@ast-grep/setup-lang 0.0.3 → 0.0.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @ast-grep/setup-lang
2
+
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - bb52937: skip logging when running
package/index.d.ts CHANGED
@@ -6,4 +6,8 @@ interface SetupConfig {
6
6
  * Move prebuild or build parser
7
7
  */
8
8
  declare function postinstall(config: SetupConfig): void;
9
- export { postinstall };
9
+ /**
10
+ * Resolve prebuild path
11
+ */
12
+ declare function resolvePrebuild(dir: string, needLog?: boolean): string | undefined;
13
+ export { postinstall, resolvePrebuild };
package/index.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.postinstall = postinstall;
7
+ exports.resolvePrebuild = resolvePrebuild;
7
8
  const node_child_process_1 = require("node:child_process");
8
9
  const node_fs_1 = __importDefault(require("node:fs"));
9
10
  const node_path_1 = __importDefault(require("node:path"));
@@ -18,15 +19,9 @@ function log(...args) {
18
19
  */
19
20
  function postinstall(config) {
20
21
  const dir = config.dirname;
21
- const parser = node_path_1.default.join(dir, 'parser.so');
22
- if (node_fs_1.default.existsSync(parser)) {
23
- log('parser already exists, skipping build');
24
- return;
25
- }
26
- const prebuild = resolvePrebuild(dir);
22
+ const prebuild = resolvePrebuild(dir, true);
27
23
  if (prebuild) {
28
- log('copying prebuild parser');
29
- node_fs_1.default.copyFileSync(prebuild, parser);
24
+ log('prebuild found, do not need to build');
30
25
  return;
31
26
  }
32
27
  try {
@@ -59,14 +54,18 @@ const ARCH_MAP = {
59
54
  /**
60
55
  * Resolve prebuild path
61
56
  */
62
- function resolvePrebuild(dir) {
57
+ function resolvePrebuild(dir, needLog = false) {
63
58
  const os = PLATFORM_MAP[process.platform];
64
59
  const arch = ARCH_MAP[process.arch];
65
60
  const prebuild = node_path_1.default.join(dir, 'prebuilds', `prebuild-${os}-${arch}`, 'parser.so');
66
61
  if (!os || !arch || !node_fs_1.default.existsSync(prebuild)) {
67
- log(`no prebuild for ${os} ${arch}`);
62
+ if (needLog) {
63
+ log(`no prebuild for ${os} ${arch}`);
64
+ }
68
65
  return undefined;
69
66
  }
70
- log(`found prebuild for ${os} ${arch}`);
67
+ if (needLog) {
68
+ log(`found prebuild for ${os} ${arch}`);
69
+ }
71
70
  return prebuild;
72
71
  }
package/index.ts CHANGED
@@ -19,21 +19,17 @@ interface SetupConfig {
19
19
  */
20
20
  function postinstall(config: SetupConfig) {
21
21
  const dir = config.dirname
22
- const parser = path.join(dir, 'parser.so')
23
- if (fs.existsSync(parser)) {
24
- log('parser already exists, skipping build')
25
- return
26
- }
27
- const prebuild = resolvePrebuild(dir)
22
+ const prebuild = resolvePrebuild(dir, true)
28
23
  if (prebuild) {
29
- log('copying prebuild parser')
30
- fs.copyFileSync(prebuild, parser)
24
+ log('prebuild found, do not need to build')
31
25
  return
32
26
  }
33
27
  try {
34
28
  buildSrc(config)
35
29
  } catch (e: unknown) {
36
- log('build failed, please ensure tree-sitter-cli is installed as peer dependency')
30
+ log(
31
+ 'build failed, please ensure tree-sitter-cli is installed as peer dependency',
32
+ )
37
33
  log(e)
38
34
  }
39
35
  }
@@ -42,7 +38,9 @@ function buildSrc(config: SetupConfig) {
42
38
  const { dirname } = config
43
39
  const existing = path.join(dirname, 'src')
44
40
  if (!fs.existsSync(existing)) {
45
- log('tree-sitter src not found. If you are making a lang package, please run `pnpm source`.')
41
+ log(
42
+ 'tree-sitter src not found. If you are making a lang package, please run `pnpm source`.',
43
+ )
46
44
  return
47
45
  }
48
46
  log('building parser from source')
@@ -63,16 +61,25 @@ const ARCH_MAP: Record<string, string> = {
63
61
  /**
64
62
  * Resolve prebuild path
65
63
  */
66
- function resolvePrebuild(dir: string) {
64
+ function resolvePrebuild(dir: string, needLog = false) {
67
65
  const os = PLATFORM_MAP[process.platform]
68
66
  const arch = ARCH_MAP[process.arch]
69
- const prebuild = path.join(dir, 'prebuilds', `prebuild-${os}-${arch}`, 'parser.so')
67
+ const prebuild = path.join(
68
+ dir,
69
+ 'prebuilds',
70
+ `prebuild-${os}-${arch}`,
71
+ 'parser.so',
72
+ )
70
73
  if (!os || !arch || !fs.existsSync(prebuild)) {
71
- log(`no prebuild for ${os} ${arch}`)
74
+ if (needLog) {
75
+ log(`no prebuild for ${os} ${arch}`)
76
+ }
72
77
  return undefined
73
78
  }
74
- log(`found prebuild for ${os} ${arch}`)
79
+ if (needLog) {
80
+ log(`found prebuild for ${os} ${arch}`)
81
+ }
75
82
  return prebuild
76
83
  }
77
84
 
78
- export { postinstall }
85
+ export { postinstall, resolvePrebuild }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ast-grep/setup-lang",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "typescript": "^5.7.3",
16
- "@types/node": "22.13.4"
16
+ "@types/node": "22.19.2"
17
17
  },
18
18
  "scripts": {
19
19
  "compile-ts": "tsc"