@ast-grep/setup-lang 0.0.3 → 0.0.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/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): 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
22
  const prebuild = resolvePrebuild(dir);
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 {
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
22
  const prebuild = resolvePrebuild(dir)
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')
@@ -66,7 +64,12 @@ const ARCH_MAP: Record<string, string> = {
66
64
  function resolvePrebuild(dir: string) {
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
74
  log(`no prebuild for ${os} ${arch}`)
72
75
  return undefined
@@ -75,4 +78,4 @@ function resolvePrebuild(dir: string) {
75
78
  return prebuild
76
79
  }
77
80
 
78
- export { postinstall }
81
+ 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.4",
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.17.1"
17
17
  },
18
18
  "scripts": {
19
19
  "compile-ts": "tsc"