Skip to content
This repository was archived by the owner on May 4, 2020. It is now read-only.

Commit c7e1a6a

Browse files
committed
fix(@formatjs/cli): glob files instead of relying on shell, fix #383
1 parent 92fb9b6 commit c7e1a6a

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"babel-plugin-react-intl": "^5.1.12",
5151
"commander": "4.0.0-1",
5252
"fs-extra": "^8.1.0",
53+
"glob": "^7.0.0",
5354
"loader-utils": "^1.2.3",
5455
"lodash": "^4.17.15",
5556
"loud-rejection": "^2.1.0"

packages/cli/src/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import commander from 'commander';
22
import loudRejection from 'loud-rejection';
33
import extract, {ExtractCLIOptions} from './extract';
4+
import {sync as globSync} from 'glob';
45

56
const KNOWN_COMMANDS = ['extract'];
67

@@ -98,6 +99,15 @@ async function main(argv: string[]) {
9899
false
99100
)
100101
.action(async (files: readonly string[], cmdObj: ExtractCLIOptions) => {
102+
files = files.reduce(
103+
(all: string[], f) =>
104+
all.concat(
105+
globSync(f, {
106+
cwd: process.cwd(),
107+
})
108+
),
109+
[]
110+
);
101111
await extract(files, {
102112
outFile: cmdObj.outFile,
103113
idInterpolationPattern:

packages/cli/tests/extract/integration_tests/__snapshots__/index.test.ts.snap

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`[glob] basic case: defineMessages -> stdout 1`] = `
4+
Array [
5+
Object {
6+
"defaultMessage": "Hello World!",
7+
"description": "The default message",
8+
"id": "foo.bar.baz",
9+
},
10+
Object {
11+
"defaultMessage": "Hello Nurse!",
12+
"description": "Another message",
13+
"id": "foo.bar.biff",
14+
},
15+
Object {
16+
"defaultMessage": "{count, plural, =0 {😭} one {# kitten} other {# kittens}}",
17+
"description": "Counts kittens",
18+
"id": "app.home.kittens",
19+
},
20+
Object {
21+
"defaultMessage": " Some whitespace ",
22+
"description": "Whitespace",
23+
"id": "trailing.ws",
24+
},
25+
Object {
26+
"defaultMessage": "A quoted value ''{value}'",
27+
"description": "Escaped apostrophe",
28+
"id": "escaped.apostrophe",
29+
},
30+
Object {
31+
"defaultMessage": "No ID",
32+
"description": "no ID",
33+
"id": "ae494",
34+
},
35+
]
36+
`;
37+
338
exports[`basic case: defineMessages -> directory 1`] = `
439
Array [
540
"actual.json",

packages/cli/tests/extract/integration_tests/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ test('basic case: defineMessages -> stdout', async () => {
2828
expect(stderr).toBe('');
2929
}, 10000);
3030

31+
test('[glob] basic case: defineMessages -> stdout', async () => {
32+
const {stdout, stderr} = await exec(
33+
`${BIN_PATH} extract ${path.join(__dirname, 'defineMessages/*.js')}`
34+
);
35+
expect(JSON.parse(stdout)).toMatchSnapshot();
36+
expect(stderr).toBe('');
37+
}, 10000);
38+
3139
test('basic case: defineMessages -> directory', async () => {
3240
process.chdir(__dirname);
3341
const {stdout, stderr} = await exec(

packages/cli/tests/extract/unit.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const babel = require('@babel/core');
1818
// Commander.js will call this.
1919
jest.spyOn(process, 'exit').mockImplementation((() => null) as any);
2020

21+
jest.mock('glob', () => ({
22+
sync: (p: string) => [p],
23+
}));
24+
2125
beforeEach(() => {
2226
jest.clearAllMocks();
2327
});

0 commit comments

Comments
 (0)