@wp-blocks/make-pot 1.2.0 → 1.3.0

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 (96) hide show
  1. package/biome.json +12 -0
  2. package/lib/assets/block-i18n.js +1 -0
  3. package/lib/assets/package-i18n.js +1 -0
  4. package/lib/assets/theme-i18n.js +1 -0
  5. package/lib/assets/wp-plugin-i18n.js +1 -0
  6. package/lib/assets/wp-theme-i18n.js +1 -0
  7. package/lib/cli/getArgs.js +1 -0
  8. package/lib/cli/parseCli.js +1 -110
  9. package/lib/const.js +1 -82
  10. package/lib/extractors/css.js +1 -42
  11. package/lib/extractors/headers.js +1 -73
  12. package/lib/extractors/json.js +1 -69
  13. package/lib/extractors/php.js +2 -49
  14. package/lib/extractors/schema.js +1 -100
  15. package/lib/extractors/text.js +1 -18
  16. package/lib/extractors/utils.js +1 -55
  17. package/lib/fs/fs.js +1 -0
  18. package/lib/fs/glob.js +3 -83
  19. package/lib/index.js +1 -26
  20. package/lib/parser/exec.js +3 -49
  21. package/lib/parser/makePot.js +1 -0
  22. package/lib/parser/patterns.js +1 -33
  23. package/lib/parser/process.js +1 -38
  24. package/lib/parser/progress.js +1 -21
  25. package/lib/parser/taskRunner.js +1 -33
  26. package/lib/parser/tree.js +1 -104
  27. package/lib/run.js +1 -0
  28. package/lib/types.js +1 -3
  29. package/lib/utils/common.js +2 -0
  30. package/package.json +68 -75
  31. package/tsconfig.json +4 -20
  32. package/ .prettierignore +0 -3
  33. package/.editorconfig +0 -15
  34. package/.eslintrc.json +0 -12
  35. package/jest.config.json +0 -18
  36. package/lib/assets/block-i18n.json +0 -17
  37. package/lib/assets/package-i18n.json +0 -13
  38. package/lib/assets/theme-i18n.json +0 -86
  39. package/lib/assets/wp-plugin-i18n.json +0 -14
  40. package/lib/assets/wp-theme-i18n.json +0 -13
  41. package/lib/cli/index.d.ts +0 -1
  42. package/lib/cli/index.js +0 -114
  43. package/lib/cli/index.js.map +0 -1
  44. package/lib/cli/parseCli.d.ts +0 -3
  45. package/lib/cli/parseCli.js.map +0 -1
  46. package/lib/const.d.ts +0 -140
  47. package/lib/const.js.map +0 -1
  48. package/lib/extractors/css.d.ts +0 -2
  49. package/lib/extractors/css.js.map +0 -1
  50. package/lib/extractors/headers.d.ts +0 -5
  51. package/lib/extractors/headers.js.map +0 -1
  52. package/lib/extractors/index.d.ts +0 -2
  53. package/lib/extractors/index.js +0 -50
  54. package/lib/extractors/index.js.map +0 -1
  55. package/lib/extractors/json.d.ts +0 -10
  56. package/lib/extractors/json.js.map +0 -1
  57. package/lib/extractors/php.d.ts +0 -3
  58. package/lib/extractors/php.js.map +0 -1
  59. package/lib/extractors/schema.d.ts +0 -84
  60. package/lib/extractors/schema.js.map +0 -1
  61. package/lib/extractors/text.d.ts +0 -1
  62. package/lib/extractors/text.js.map +0 -1
  63. package/lib/extractors/utils.d.ts +0 -5
  64. package/lib/extractors/utils.js.map +0 -1
  65. package/lib/fs/glob.d.ts +0 -13
  66. package/lib/fs/glob.js.map +0 -1
  67. package/lib/fs/index.d.ts +0 -2
  68. package/lib/fs/index.js +0 -58
  69. package/lib/fs/index.js.map +0 -1
  70. package/lib/index.d.ts +0 -2
  71. package/lib/index.js.map +0 -1
  72. package/lib/parser/exec.d.ts +0 -2
  73. package/lib/parser/exec.js.map +0 -1
  74. package/lib/parser/index.d.ts +0 -2
  75. package/lib/parser/index.js +0 -30
  76. package/lib/parser/index.js.map +0 -1
  77. package/lib/parser/patterns.d.ts +0 -2
  78. package/lib/parser/patterns.js.map +0 -1
  79. package/lib/parser/process.d.ts +0 -4
  80. package/lib/parser/process.js.map +0 -1
  81. package/lib/parser/progress.d.ts +0 -3
  82. package/lib/parser/progress.js.map +0 -1
  83. package/lib/parser/taskRunner.d.ts +0 -4
  84. package/lib/parser/taskRunner.js.map +0 -1
  85. package/lib/parser/tree.d.ts +0 -2
  86. package/lib/parser/tree.js.map +0 -1
  87. package/lib/types.d.ts +0 -50
  88. package/lib/types.js.map +0 -1
  89. package/lib/utils/index.d.ts +0 -9
  90. package/lib/utils/index.js +0 -83
  91. package/lib/utils/index.js.map +0 -1
  92. package/tests/extract.test.ts +0 -382
  93. package/tests/getFiles.test.ts +0 -114
  94. package/tests/ignoreFunction.test.ts +0 -102
  95. package/tests/jsonParse.ts +0 -51
  96. package/tests/tree.test.ts +0 -151
@@ -1,382 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { doTree } from '../src/parser/tree'
3
- import { Block } from 'gettext-merger'
4
-
5
- describe('getStrings', () => {
6
- it('should extract translations from js', () => {
7
- const content = `var foo = __('Hello World', 'greeting');`
8
- const filename = 'filename.js'
9
-
10
- const result = doTree(content, filename)
11
- const expected = new Block([])
12
- expected.msgid = 'Hello World'
13
- expected.comments = {
14
- reference: ['filename.js:1'],
15
- translator: [''],
16
- }
17
-
18
- expect(result.blocks[0].msgid).toBe(expected.msgid)
19
- })
20
-
21
- it('should extract translations from ts', () => {
22
- const content = `__('Hello World', 'greeting');`
23
- const filename = 'filename.ts'
24
-
25
- const result = doTree(content, filename).blocks[0].toJson()
26
-
27
- const expected = new Block([])
28
- expected.msgid = 'Hello World'
29
- expected.comments = {
30
- reference: ['filename.ts:1'],
31
- translator: [''],
32
- }
33
-
34
- expect(result.msgid).toBe(expected.msgid)
35
- expect(expected.comments?.reference).toHaveLength(1)
36
- expect([result.comments?.reference]).toEqual(
37
- expected.comments?.reference
38
- )
39
- })
40
- it('should extract translations from tsx', () => {
41
- const content = `const element = <h1>{ __('Hello World', 'greeting')}</h1>;`
42
-
43
- const filename = 'filename.tsx'
44
-
45
- const result = doTree(content, filename)
46
-
47
- const expected = new Block([])
48
- expected.msgid = 'Hello World'
49
- expected.msgstr = ['']
50
- expected.comments = {
51
- reference: ['filename.tsx:1'],
52
- translator: [''],
53
- }
54
-
55
- expect(result.blocks[0].toJson()).toEqual(expected.toJson())
56
- })
57
- it('should extract translations with context', () => {
58
- const content = `<?php __('Hello World', 'greeting'); ?>`
59
- const filename = 'filename.php'
60
-
61
- const result = doTree(content, filename)
62
-
63
- const expected = new Block([])
64
- expected.msgid = 'Hello World'
65
- expected.msgstr = ['']
66
- expected.comments = {
67
- reference: ['filename.php:1'],
68
- translator: [''],
69
- }
70
-
71
- expect(result.blocks[0].toJson()).toEqual(expected.toJson())
72
- })
73
- it('should extract translations from code content with no context or translator comments', () => {
74
- const content = `<?php _e('Hello World'); ?>`
75
- const expected = new Block([])
76
- expected.msgid = 'Hello World'
77
- expected.msgstr = ['']
78
- expected.comments = {
79
- translator: undefined,
80
- reference: ['filename.php:1'],
81
- }
82
- const filename = 'filename.php'
83
-
84
- const result = doTree(content, filename)
85
-
86
- expect(result.blocks[0]).toEqual(expected)
87
- })
88
-
89
- it('should extract translations with comments', () => {
90
- const filename = 'filename.php'
91
- const content = `
92
- <?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`
93
- const expected = {
94
- blocks: [
95
- {
96
- comments: {
97
- reference: ['filename.php:2'],
98
- translator: ['ciao!'],
99
- },
100
- msgctxt: 'greeting',
101
- msgid: 'Hello World',
102
- msgstr: [''],
103
- },
104
- ],
105
- path: 'filename.php',
106
- }
107
-
108
- const result = doTree(content, filename)
109
-
110
- expect(result).toEqual(expected)
111
- })
112
-
113
- it('should extract translations with comments reporting the right position', () => {
114
- const filename = 'filename.php'
115
- const content = `
116
-
117
-
118
-
119
- /** line 5*/
120
-
121
-
122
-
123
-
124
- <?php echo _x('Hello World', 'greeting'); ?>`
125
- const expected = `#: filename.php:10
126
- msgctxt "greeting"
127
- msgid "Hello World"
128
- msgstr ""`
129
-
130
- const result = doTree(content, filename)
131
-
132
- expect(result.blocks[0].toStr()).toBe(expected)
133
- })
134
-
135
- it('should extract translations inside a sprint', () => {
136
- const filename = 'filename.php'
137
- const content = ` <?php
138
- $url = 'http://example.com';
139
- $link = sprintf( wp_kses( __( 'Check out this link to my <a href="%s">website</a> made with WordPress.', 'my-text-domain' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
140
- echo $link;`
141
- const expected = {
142
- '': {
143
- 'Check out this link to my <a href="%s">website</a> made with WordPress.':
144
- {
145
- comments: {
146
- extracted: '',
147
- flag: '',
148
- previous: '',
149
- reference: 'filename.php:3',
150
- translator: '',
151
- },
152
- msgctxt: '',
153
- msgid: 'Check out this link to my <a href="%s">website</a> made with WordPress.',
154
- msgid_plural: undefined,
155
- msgstr: [''],
156
- },
157
- },
158
- }
159
-
160
- const result = doTree(content, filename)
161
-
162
- expect(result.toJson()).toMatchObject(expected)
163
- })
164
- })
165
-
166
- describe('getStrings wp cli', () => {
167
- it('should extract from an array of translations', () => {
168
- const filename = 'filename.php'
169
- const content = `<?php $var = 'don't do this'; $instructions = array(
170
- "Overview" => array(
171
- "title" => __( 'Overview', '3d-product-viewer' ),
172
- "text" => __( "Hold down the right button to move the model", '3d-product-viewer' ),
173
- "icon" => 'icon-book'
174
- ),
175
- "Rotation" => array(
176
- "title" => __( 'Rotation', '3d-product-viewer' ),
177
- "text" => __( "Left-click and drag to change the angle", '3d-product-viewer' ),
178
- "icon" => 'icon-rotation'
179
- ),
180
- "Zoom" => array(
181
- "title" => __( 'Zoom', '3d-product-viewer' ),
182
- "text" => __( "Variable is % and not {$var}", '3d-product-viewer' ),
183
- "icon" => 'icon-zoom'
184
- )
185
- );
186
- `
187
-
188
- const result = doTree(content, filename)
189
- expect(result).toMatchSnapshot()
190
- })
191
-
192
- it('should extract translations with translator comments inside the formatting hell', () => {
193
- const filename = 'filename.php'
194
- const content = `<?php if ( count( $errors_in_remigrate_batch ) > 0 ) {
195
- $formatted_errors = wp_json_encode( $errors_in_remigrate_batch, JSON_PRETTY_PRINT );
196
- WP_CLI::warning(
197
- sprintf(
198
- /* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
199
- _n(
200
- '%1$d error found: %2$s when re-migrating order. Please review the error above.',
201
- '%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
202
- count( %s ),
203
- 'woocommerce'
204
- ),
205
- count( $errors_in_remigrate_batch ),
206
- $formatted_errors
207
- )
208
- );
209
- } else {
210
- WP_CLI::warning( 'Re-migration successful.', 'woocommerce' );
211
- }
212
- `
213
-
214
- const result = doTree(content, filename)
215
- expect(
216
- '%1$d error found: %2$s when re-migrating order. Please review the error above.'
217
- ).toBe(result.blocks[0].msgid)
218
- })
219
-
220
- /** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
221
- it('should extract translations and comments from code content', () => {
222
- const content = `<?php
223
-
224
- And a foo-plugin/foo-plugin.php file:
225
- """
226
- <?php
227
- /**
228
- */
229
- __( 'Hello World', 'foo-plugin' );
230
- """
231
- And a foo-plugin/vendor/ignored.php file:
232
- """
233
- <?php
234
- __( 'I am being ignored', 'foo-plugin' );
235
- """
236
- __( '__', 'foo-plugin' );
237
- esc_attr__( 'esc_attr__', 'foo-plugin' );
238
- esc_html__( 'esc_html__', 'foo-plugin' );
239
- esc_xml__( 'esc_xml__', 'foo-plugin' );
240
- _e( '_e', 'foo-plugin' );
241
- esc_attr_e( 'esc_attr_e', 'foo-plugin' );
242
- esc_html_e( 'esc_html_e', 'foo-plugin' );
243
- esc_xml_e( 'esc_xml_e', 'foo-plugin' );
244
- _x( '_x', '_x_context', 'foo-plugin' );
245
- _ex( '_ex', '_ex_context', 'foo-plugin' );
246
- esc_attr_x( 'esc_attr_x', 'esc_attr_x_context', 'foo-plugin' );
247
- esc_html_x( 'esc_html_x', 'esc_html_x_context', 'foo-plugin' );
248
- esc_xml_x( 'esc_xml_x', 'esc_xml_x_context', 'foo-plugin' );
249
- _n( '_n_single', '_n_plural', $number, 'foo-plugin' );
250
- _nx( '_nx_single', '_nx_plural', $number, '_nx_context', 'foo-plugin' );
251
- _n_noop( '_n_noop_single', '_n_noop_plural', 'foo-plugin' );
252
- _nx_noop( '_nx_noop_single', '_nx_noop_plural', '_nx_noop_context', 'foo-plugin' );
253
-
254
- // Compat.
255
- _( '_', 'foo-plugin' );
256
-
257
- // Deprecated.
258
- _c( '_c', 'foo-plugin' );
259
- _nc( '_nc_single', '_nc_plural', $number, 'foo-plugin' );
260
- __ngettext( '__ngettext_single', '__ngettext_plural', $number, 'foo-plugin' );
261
- __ngettext_noop( '__ngettext_noop_single', '__ngettext_noop_plural', 'foo-plugin' );
262
-
263
- __unsupported_func( '__unsupported_func', 'foo-plugin' );
264
- __( 'wrong-domain', 'wrong-domain' );
265
-
266
- // See https://github.com/wp-cli/i18n-command/issues/344
267
- \\__( '\\__', 'foo-plugin' );
268
- \\_e( '\\_e', 'foo-plugin' );
269
- // Included to test if peast correctly parses regexes containing a quote.
270
- // See: https://github.com/wp-cli/i18n-command/issues/98
271
- n = n.replace(/"/g, '&quot;');
272
- n = n.replace(/"|'/g, '&quot;');
273
-
274
- __( '__', 'foo-plugin' );
275
- _x( '_x', '_x_context', 'foo-plugin' );
276
- _n( '_n_single', '_n_plural', number, 'foo-plugin' );
277
- _nx( '_nx_single', '_nx_plural', number, '_nx_context', 'foo-plugin' );
278
-
279
- __( 'wrong-domain', 'wrong-domain' );
280
-
281
- __( 'Hello world' ); // translators: Greeting`
282
-
283
- const filename = 'filename.php'
284
-
285
- const result = doTree(content, filename)
286
-
287
- expect(result).toMatchSnapshot()
288
- })
289
-
290
- /** see wp cli tests */
291
- it('should extract translations and comments from code content', () => {
292
- const content = `<?php
293
-
294
- // translators: Foo Bar Comment
295
- __( 'Foo Bar', 'foo-plugin' );
296
-
297
- // TrANslAtORs: Bar Baz Comment
298
- __( 'Bar Baz', 'foo-plugin' );
299
-
300
- // translators: Software name
301
- const string = __( 'WordPress', 'foo-plugin' );
302
-
303
- // translators: So much space
304
-
305
- __( 'Spacey text', 'foo-plugin' );
306
-
307
- /* translators: Long comment
308
- spanning multiple
309
- lines */
310
- const string = __( 'Short text', 'foo-plugin' );
311
-
312
- ReactDOM.render(
313
- <h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
314
- document.getElementById('root')
315
- );
316
-
317
- wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
318
- wp.i18n._n( 'wp.i18n._n_single', 'wp.i18n._n_plural', number, 'foo-plugin' );
319
-
320
- const translate = wp.i18n;
321
- translate.__( 'translate.__', 'foo-plugin' );
322
-
323
- Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
324
- Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
325
-
326
- Object(u.__)( 'minified.__', 'foo-plugin' );
327
- Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
328
-
329
- /* translators: babel */
330
- (0, __)( 'babel.__', 'foo-plugin' );
331
- (0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
332
- (0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
333
-
334
- eval( "__( 'Hello Eval World', 'foo-plugin' );" );
335
-
336
- __( \`This is a \${bug}\`, 'foo-plugin' );
337
-
338
- /**
339
- * Plugin Name: Plugin name
340
- */
341
-
342
- /* translators: Translators 1! */
343
- _e( 'hello world', 'foo-plugin' );
344
-
345
- /* Translators: Translators 2! */
346
- $foo = __( 'foo', 'foo-plugin' );
347
-
348
- /* translators: localized date and time format, see https://secure.php.net/date */
349
- __( 'F j, Y g:i a', 'foo-plugin' );
350
-
351
- // translators: let your ears fly!
352
- __( 'on', 'foo-plugin' );
353
-
354
- /*
355
- * Translators: If there are characters in your language that are not supported
356
- * by Lato, translate this to 'off'. Do not translate into your own language.
357
- */
358
- __( 'off', 'foo-plugin' );
359
-
360
- /* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
361
-
362
- /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
363
-
364
- {TAB}/*
365
- {TAB} * translators: this comment block is indented with a tab and should get extracted too.
366
- {TAB} */
367
- {TAB}__( 'yolo', 'foo-plugin' );
368
-
369
- /* translators: This is a comment */
370
- __( 'Plugin name', 'foo-plugin' );
371
-
372
- /* Translators: This is another comment! */
373
- __( 'https://example.com', 'foo-plugin' );
374
- `
375
-
376
- const filename = 'filename.php'
377
-
378
- const result = doTree(content, filename)
379
-
380
- expect(result).toMatchSnapshot()
381
- })
382
- })
@@ -1,114 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { getFiles } from '../src/fs/glob'
3
- import { Args, DomainType } from '../src/types'
4
- import path from 'path'
5
- import { parseCliArgs } from '../src/cli/parseCli'
6
-
7
- describe('getFiles', () => {
8
- const DEFAULTS = parseCliArgs({
9
- domain: 'plugin' as DomainType,
10
- slug: 'plugin-slug',
11
- paths: { cwd: 'tests/fixtures/', out: 'tests/fixtures/' },
12
- options: {
13
- silent: true,
14
- },
15
- $0: 'makepot',
16
- _: [0, 1],
17
- })
18
-
19
- it('should retrieve a all files', async () => {
20
- const args = { ...DEFAULTS, domain: 'theme' } as Args
21
- const pattern = { include: ['**'], exclude: [] }
22
-
23
- const files = await getFiles(args, pattern)
24
- const collected: string[] = []
25
- for (const file of files) {
26
- expect(file).toBeTruthy()
27
- collected.push(file)
28
- }
29
- expect(collected.length).toBeGreaterThan(2)
30
- expect(collected.find((e) => e.includes('theme.json'))).toBeTruthy()
31
- })
32
- it('Should retrieve a list of txt files based on the provided plugin pattern', async () => {
33
- const args = {
34
- ...DEFAULTS,
35
- }
36
- const pattern = {
37
- include: ['**/*.txt'],
38
- exclude: ['node_modules', 'dist'],
39
- }
40
- const expectedFiles = [
41
- 'tests' + path.sep + 'fixtures' + path.sep + 'file1.txt',
42
- 'tests' +
43
- path.sep +
44
- 'fixtures' +
45
- path.sep +
46
- 'sourcedir' +
47
- path.sep +
48
- 'file2.txt',
49
- 'tests' +
50
- path.sep +
51
- 'fixtures' +
52
- path.sep +
53
- 'block' +
54
- path.sep +
55
- 'readme.txt',
56
- ]
57
-
58
- const files = await getFiles(args, pattern)
59
- const collected: string[] = []
60
- for (const file of files) {
61
- expect(file).toBeTruthy()
62
- collected.push(file)
63
- }
64
-
65
- expect(collected).toEqual(expectedFiles)
66
- })
67
- it('should retrieve a list of theme.json files based on the provided theme pattern', async () => {
68
- const args = {
69
- ...DEFAULTS,
70
- }
71
- const pattern = {
72
- include: ['**/*.json'],
73
- exclude: [],
74
- }
75
- const expectedFiles = [
76
- `sourcedir${path.sep}theme.json`,
77
- `sourcedir${path.sep}package.json`,
78
- `sourcedir${path.sep}node_modules${path.sep}module${path.sep}block.json`,
79
- `node_modules${path.sep}block.json`,
80
- `fse${path.sep}theme.json`,
81
- `block${path.sep}block.json`,
82
- ]
83
-
84
- const files = await getFiles(args, pattern)
85
- const collected = []
86
- for (const file of files) {
87
- expect(file).toBeTruthy()
88
- collected.push(file)
89
- }
90
- expect(
91
- collected.filter((file) => !expectedFiles.includes(file))
92
- ).toBeTruthy()
93
- })
94
- it('Should retrieve a list of files without any node_modules folder', async () => {
95
- const args = {
96
- ...DEFAULTS,
97
- }
98
- const pattern = {
99
- include: ['**'],
100
- exclude: ['node_modules'],
101
- }
102
-
103
- const files = await getFiles(args, pattern)
104
- const collected = []
105
- for (const file of files) {
106
- expect(file).toBeTruthy()
107
- collected.push(file)
108
- }
109
-
110
- // for each file check if that strings contains the node_modules folder
111
- expect(collected.find((e) => e.includes('node_modules'))).toBeFalsy()
112
- expect(collected.length).toBeGreaterThan(10)
113
- })
114
- })
@@ -1,102 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { Glob, Path } from 'glob'
3
- import path from 'path'
4
- import { ignoreFunc } from '../src/fs/glob'
5
-
6
- const tests = [
7
- {
8
- title: 'defaults',
9
- src: '.',
10
- exclude: [
11
- '.git',
12
- 'node_modules',
13
- 'vendor',
14
- 'build',
15
- 'dist',
16
- 'uploads',
17
- 'Gruntfile.js',
18
- 'webpack.config.js',
19
- '**/*.min.js',
20
- 'tsconfig.js',
21
- '**.test.**',
22
- 'tests',
23
- 'coverage',
24
- '**/extractors**',
25
- '**/*.js.map',
26
- '**/lib/c**.d.ts',
27
- '**/**tt**',
28
- ],
29
- result: 20,
30
- },
31
- {
32
- title: 'exclude file.php',
33
- src: 'tests/fixtures/sourcedir',
34
- exclude: ['file.php'],
35
- result: [
36
- 'theme.json',
37
- 'svgTools.ts',
38
- 'sourcedir.php',
39
- 'package.json',
40
- 'file2.txt',
41
- 'vendor' + path.sep + 'index.php',
42
- 'node_modules' + path.sep + 'module' + path.sep + 'block.json',
43
- ],
44
- },
45
- {
46
- title: 'exclude node_modules and vendor',
47
- src: 'tests/fixtures/sourcedir',
48
- exclude: ['node_modules', 'vendor'],
49
- result: [
50
- 'theme.json',
51
- 'svgTools.ts',
52
- 'sourcedir.php',
53
- 'package.json',
54
- 'file2.txt',
55
- 'file.php',
56
- ],
57
- },
58
- {
59
- title: 'globstar path',
60
- src: 'tests/fixtures',
61
- exclude: ['**/*.php', '**/*.json', 'block/**'],
62
- result: 15,
63
- },
64
- {
65
- title: 'should exclude globstar',
66
- src: 'tests/fixtures/',
67
- exclude: ['**'],
68
- result: [],
69
- },
70
- {
71
- title: 'should remove excluded patterns',
72
- src: 'tests/fixtures/node_modules',
73
- exclude: [],
74
- result: ['block.json'],
75
- },
76
- ]
77
-
78
- describe('testing the ignoreFunc used to ignore files', () => {
79
- tests.forEach((test) => {
80
- it('should ignore files ' + test.title, () => {
81
- const foundDirs: string[] = []
82
-
83
- const dirs = new Glob('**', {
84
- ignore: {
85
- ignored: (p: Path) => ignoreFunc(p, test.exclude),
86
- },
87
- nodir: true,
88
- cwd: path.join(test.src),
89
- })
90
-
91
- for (const dir of dirs) {
92
- foundDirs.push(dir)
93
- }
94
-
95
- if (typeof test.result === 'number') {
96
- expect(foundDirs.length).toBeGreaterThanOrEqual(test.result)
97
- } else {
98
- expect(foundDirs).toStrictEqual(test.result)
99
- }
100
- })
101
- })
102
- })
@@ -1,51 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { parseJsonFile } from '../src/extractors/json'
3
- import fs from 'fs'
4
-
5
- describe('should parse json', () => {
6
- it('theme.json', async () => {
7
- const expected = {
8
- 'block style label': {
9
- label: {
10
- comments: {
11
- reference: 'block/block.json',
12
- },
13
- msgctxt: 'block style label',
14
- msgid: 'label',
15
- msgstr: [],
16
- },
17
- },
18
- 'block description': {
19
- description: {
20
- comments: {
21
- reference: 'block/block.json',
22
- },
23
- msgctxt: 'block description',
24
- msgid: 'description',
25
- msgstr: [],
26
- },
27
- },
28
- 'block keyword': {
29
- undefined: {
30
- comments: {
31
- reference: 'block/block.json',
32
- },
33
- msgctxt: 'block keyword',
34
- msgid: undefined,
35
- msgstr: [],
36
- },
37
- },
38
- }
39
-
40
- const result = await parseJsonFile({
41
- fileContent: fs.readFileSync(
42
- 'tests/fixtures/block/block.json',
43
- 'utf8'
44
- ),
45
- filename: 'block.json',
46
- filepath: 'block/block.json',
47
- })
48
-
49
- expect(result).toEqual(expected)
50
- })
51
- })