@ast-grep/setup-lang 0.0.2 → 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
@@ -1,11 +1,13 @@
1
1
  interface SetupConfig {
2
2
  /** Directory of the lang package. e.g. __dirname */
3
3
  dirname: string;
4
- /** Package name of tree-sitter package. e.g. tree-sitter-css */
5
- treeSitterPackage: string;
6
4
  }
7
5
  /**
8
6
  * Move prebuild or build parser
9
7
  */
10
8
  declare function postinstall(config: SetupConfig): void;
11
- 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"));
@@ -11,22 +12,16 @@ const node_path_1 = __importDefault(require("node:path"));
11
12
  * Log to console
12
13
  */
13
14
  function log(...args) {
14
- console.debug(`@ast-grep/lang:`, ...args);
15
+ console.debug('@ast-grep/lang:', ...args);
15
16
  }
16
17
  /**
17
18
  * Move prebuild or build parser
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 {
@@ -53,7 +48,7 @@ const PLATFORM_MAP = {
53
48
  win32: 'Windows',
54
49
  };
55
50
  const ARCH_MAP = {
56
- x64: 'x64',
51
+ x64: 'X64',
57
52
  arm64: 'ARM64',
58
53
  };
59
54
  /**
package/index.ts CHANGED
@@ -6,14 +6,12 @@ import path from 'node:path'
6
6
  * Log to console
7
7
  */
8
8
  function log(...args: unknown[]) {
9
- console.debug(`@ast-grep/lang:`, ...args)
9
+ console.debug('@ast-grep/lang:', ...args)
10
10
  }
11
11
 
12
12
  interface SetupConfig {
13
13
  /** Directory of the lang package. e.g. __dirname */
14
14
  dirname: string
15
- /** Package name of tree-sitter package. e.g. tree-sitter-css */
16
- treeSitterPackage: string
17
15
  }
18
16
 
19
17
  /**
@@ -21,21 +19,17 @@ interface SetupConfig {
21
19
  */
22
20
  function postinstall(config: SetupConfig) {
23
21
  const dir = config.dirname
24
- const parser = path.join(dir, 'parser.so')
25
- if (fs.existsSync(parser)) {
26
- log('parser already exists, skipping build')
27
- return
28
- }
29
22
  const prebuild = resolvePrebuild(dir)
30
23
  if (prebuild) {
31
- log('copying prebuild parser')
32
- fs.copyFileSync(prebuild, parser)
24
+ log('prebuild found, do not need to build')
33
25
  return
34
26
  }
35
27
  try {
36
28
  buildSrc(config)
37
29
  } catch (e: unknown) {
38
- 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
+ )
39
33
  log(e)
40
34
  }
41
35
  }
@@ -44,7 +38,9 @@ function buildSrc(config: SetupConfig) {
44
38
  const { dirname } = config
45
39
  const existing = path.join(dirname, 'src')
46
40
  if (!fs.existsSync(existing)) {
47
- 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
+ )
48
44
  return
49
45
  }
50
46
  log('building parser from source')
@@ -58,7 +54,7 @@ const PLATFORM_MAP: Record<string, string> = {
58
54
  }
59
55
 
60
56
  const ARCH_MAP: Record<string, string> = {
61
- x64: 'x64',
57
+ x64: 'X64',
62
58
  arm64: 'ARM64',
63
59
  }
64
60
 
@@ -68,7 +64,12 @@ const ARCH_MAP: Record<string, string> = {
68
64
  function resolvePrebuild(dir: string) {
69
65
  const os = PLATFORM_MAP[process.platform]
70
66
  const arch = ARCH_MAP[process.arch]
71
- 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
+ )
72
73
  if (!os || !arch || !fs.existsSync(prebuild)) {
73
74
  log(`no prebuild for ${os} ${arch}`)
74
75
  return undefined
@@ -77,4 +78,4 @@ function resolvePrebuild(dir: string) {
77
78
  return prebuild
78
79
  }
79
80
 
80
- 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.2",
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.10.5"
16
+ "@types/node": "22.17.1"
17
17
  },
18
18
  "scripts": {
19
19
  "compile-ts": "tsc"