@ast-grep/nursery 0.0.2 → 0.0.3

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/nursery
2
+
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 597f386: Add @ast-grep/lang-php
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SgRoot, DynamicLangRegistrations } from '@ast-grep/napi';
1
+ import type { DynamicLangRegistrations, SgRoot } from '@ast-grep/napi';
2
2
  /** Setup ast-grep/lang package's pre-release */
3
3
  interface SetupConfig {
4
4
  /** the root directory of the package */
@@ -11,6 +11,10 @@ interface SetupConfig {
11
11
  treeSitterPackage: string;
12
12
  /** Test cases running in CI */
13
13
  testRunner: (parse: (c: string) => SgRoot) => void;
14
+ /** Path of the `src` directory inside the `tree-sitter-*` package. Useful for
15
+ * `tree-sitter-php`, `tree-sitter-typescript` and `tree-sitter-yaml`.
16
+ * @default "src" */
17
+ src?: string;
14
18
  }
15
19
  /** Setup ast-grep/lang package's pre-release build and test */
16
20
  export declare function setup(setupConfig: SetupConfig): void;
package/index.js CHANGED
@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.setup = setup;
7
+ const napi_1 = require("@ast-grep/napi");
7
8
  const node_fs_1 = __importDefault(require("node:fs"));
8
9
  const node_path_1 = __importDefault(require("node:path"));
9
- const napi_1 = require("@ast-grep/napi");
10
10
  /**
11
11
  * Log to console
12
12
  */
13
13
  function log(...args) {
14
- console.debug(`@ast-grep/lang:`, ...args);
14
+ console.debug('@ast-grep/lang:', ...args);
15
15
  }
16
16
  function test(setupConfig) {
17
17
  const { name, languageRegistration, testRunner } = setupConfig;
18
18
  (0, napi_1.registerDynamicLanguage)({ [name]: languageRegistration });
19
- testRunner((code) => (0, napi_1.parse)(name, code));
19
+ testRunner(code => (0, napi_1.parse)(name, code));
20
20
  }
21
21
  /** Setup ast-grep/lang package's pre-release build and test */
22
22
  function setup(setupConfig) {
@@ -32,13 +32,14 @@ function setup(setupConfig) {
32
32
  function copySrcIfNeeded(config) {
33
33
  const { dirname, treeSitterPackage } = config;
34
34
  const existing = node_path_1.default.join(dirname, 'src');
35
- const src = node_path_1.default.join(dirname, 'node_modules', treeSitterPackage, 'src');
35
+ const src = config.src || 'src';
36
+ const source = node_path_1.default.join(dirname, 'node_modules', treeSitterPackage, src);
36
37
  if (node_fs_1.default.existsSync(existing)) {
37
38
  log('src exists, skipping copy');
38
39
  return;
39
40
  }
40
41
  log('copying tree-sitter src');
41
- node_fs_1.default.cpSync(src, 'src', { recursive: true });
42
+ node_fs_1.default.cpSync(source, 'src', { recursive: true });
42
43
  }
43
44
  function filterOutUnNamedNode(node) {
44
45
  if (!node.named) {
@@ -79,7 +80,7 @@ function generateLangNodeTypes(setupConfig) {
79
80
  `type ${lang}Types = ${JSON.stringify(nodeTypeMap, null, 2)};` +
80
81
  '\n' +
81
82
  `export default ${lang}Types;`;
82
- node_fs_1.default.writeFileSync(node_path_1.default.join(dirname, `type.d.ts`), fileContent);
83
+ node_fs_1.default.writeFileSync(node_path_1.default.join(dirname, 'type.d.ts'), fileContent);
83
84
  }
84
85
  catch (e) {
85
86
  console.error(`Error while generating node types for ${lang}`);
package/index.ts CHANGED
@@ -1,12 +1,13 @@
1
+ import type { DynamicLangRegistrations, SgRoot } from '@ast-grep/napi'
2
+ import { parse, registerDynamicLanguage } from '@ast-grep/napi'
1
3
  import fs from 'node:fs'
2
4
  import path from 'node:path'
3
- import { parse, registerDynamicLanguage, SgRoot, DynamicLangRegistrations } from '@ast-grep/napi'
4
5
 
5
6
  /**
6
7
  * Log to console
7
8
  */
8
9
  function log(...args: unknown[]) {
9
- console.debug(`@ast-grep/lang:`, ...args)
10
+ console.debug('@ast-grep/lang:', ...args)
10
11
  }
11
12
 
12
13
  /** Setup ast-grep/lang package's pre-release */
@@ -21,12 +22,16 @@ interface SetupConfig {
21
22
  treeSitterPackage: string
22
23
  /** Test cases running in CI */
23
24
  testRunner: (parse: (c: string) => SgRoot) => void
25
+ /** Path of the `src` directory inside the `tree-sitter-*` package. Useful for
26
+ * `tree-sitter-php`, `tree-sitter-typescript` and `tree-sitter-yaml`.
27
+ * @default "src" */
28
+ src?: string
24
29
  }
25
30
 
26
31
  function test(setupConfig: SetupConfig) {
27
32
  const { name, languageRegistration, testRunner } = setupConfig
28
33
  registerDynamicLanguage({ [name]: languageRegistration })
29
- testRunner((code) => parse(name, code))
34
+ testRunner(code => parse(name, code))
30
35
  }
31
36
 
32
37
  /** Setup ast-grep/lang package's pre-release build and test */
@@ -43,13 +48,15 @@ export function setup(setupConfig: SetupConfig) {
43
48
  function copySrcIfNeeded(config: SetupConfig) {
44
49
  const { dirname, treeSitterPackage } = config
45
50
  const existing = path.join(dirname, 'src')
46
- const src = path.join(dirname, 'node_modules', treeSitterPackage, 'src')
51
+ const src = config.src || 'src'
52
+ const source = path.join(dirname, 'node_modules', treeSitterPackage, src)
47
53
  if (fs.existsSync(existing)) {
48
54
  log('src exists, skipping copy')
49
55
  return
50
56
  }
57
+
51
58
  log('copying tree-sitter src')
52
- fs.cpSync(src, 'src', { recursive: true })
59
+ fs.cpSync(source, 'src', { recursive: true })
53
60
  }
54
61
 
55
62
  interface NodeBasicInfo {
@@ -117,7 +124,7 @@ function generateLangNodeTypes(setupConfig: SetupConfig) {
117
124
  `type ${lang}Types = ${JSON.stringify(nodeTypeMap, null, 2)};` +
118
125
  '\n' +
119
126
  `export default ${lang}Types;`
120
- fs.writeFileSync(path.join(dirname, `type.d.ts`), fileContent)
127
+ fs.writeFileSync(path.join(dirname, 'type.d.ts'), fileContent)
121
128
  } catch (e) {
122
129
  console.error(`Error while generating node types for ${lang}`)
123
130
  throw e
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ast-grep/nursery",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -8,7 +8,7 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "@ast-grep/napi": "0.33.0"
11
+ "@ast-grep/napi": "0.36.2"
12
12
  },
13
13
  "publishConfig": {
14
14
  "access": "public",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "typescript": "^5.7.3",
19
- "@types/node": "22.10.5"
19
+ "@types/node": "22.14.0"
20
20
  },
21
21
  "scripts": {
22
22
  "compile-ts": "tsc"