forked from formatjs/formatjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "WIP: Use actual modules for the ember extractors -- however, …
…formatjs is" This reverts commit 57d6473. Have CI tell me what command was failaing
- Loading branch information
1 parent
57d6473
commit edb6b4f
Showing
11 changed files
with
646 additions
and
1,637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {parseFile as parseHbsFile} from './hbs_extractor' | ||
import {parseScript} from './parse_script' | ||
// We can't use an import here because the gts_extractor.ts file | ||
// is FAKE TS -- in that it's actually CJS. | ||
// | ||
// So we have to use require because content-tag is a real type=module package | ||
// and we need TypeScript to recognize that it has to choose the node/require | ||
// condition of package.json#exports | ||
// https://github.com/embroider-build/content-tag/blob/main/package.json#L18 | ||
let {Preprocessor} = require('content-tag') | ||
let p = new Preprocessor() | ||
|
||
export function parseFile(source: string, fileName: string, options: any) { | ||
const scriptParseFn = parseScript(options, fileName) | ||
const transformedSource = p.process(source, {filename: fileName}) | ||
|
||
scriptParseFn(transformedSource) | ||
|
||
// extract template from transformed source to then run through hbs processor | ||
const parseResult = p.parse(source, {filename: fileName}) | ||
|
||
for (let parsed of parseResult) { | ||
parseHbsFile(parsed.contents, fileName, options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {MessageDescriptor, interpolateName} from '@formatjs/ts-transformer' | ||
import {parseFile} from '../../src/gts_extractor' | ||
import {readFile} from 'fs-extra' | ||
import {join} from 'path' | ||
|
||
test('gts_extractor', async function () { | ||
let messages: MessageDescriptor[] = [] | ||
const fixturePath = join(__dirname, './fixtures/comp.gjs') | ||
parseFile(await readFile(fixturePath, 'utf8'), fixturePath, { | ||
onMsgExtracted(_: any, msgs: any) { | ||
messages = messages.concat(msgs) | ||
}, | ||
overrideIdFn: ( | ||
id: any, | ||
defaultMessage: any, | ||
description: any, | ||
fileName: any | ||
) => | ||
id || | ||
interpolateName( | ||
{ | ||
resourcePath: fileName, | ||
} as any, | ||
'[sha512:contenthash:base64:6]', | ||
{ | ||
content: description | ||
? `${defaultMessage}#${description}` | ||
: defaultMessage, | ||
} | ||
), | ||
}) | ||
expect(messages).toMatchSnapshot() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,33 @@ | ||
import { MessageDescriptor, interpolateName } from '@formatjs/ts-transformer' | ||
import { readFile } from 'fs-extra' | ||
import { join } from 'path' | ||
import {MessageDescriptor, interpolateName} from '@formatjs/ts-transformer' | ||
import {parseFile} from '../../src/gts_extractor' | ||
import {readFile} from 'fs-extra' | ||
import {join} from 'path' | ||
|
||
describe('gts_extractor', () => { | ||
test('gts files', async function() { | ||
const { parseFile } = await import('../../src/gts_extractor.mjs'); | ||
|
||
let messages: MessageDescriptor[] = [] | ||
const fixturePath = join(__dirname, './fixtures/comp.gts') | ||
parseFile(await readFile(fixturePath, 'utf8'), fixturePath, { | ||
onMsgExtracted(_: any, msgs: any) { | ||
messages = messages.concat(msgs) | ||
}, | ||
overrideIdFn: ( | ||
id: any, | ||
defaultMessage: any, | ||
description: any, | ||
fileName: any | ||
) => | ||
id || | ||
interpolateName( | ||
{ | ||
resourcePath: fileName, | ||
} as any, | ||
'[sha512:contenthash:base64:6]', | ||
{ | ||
content: description | ||
? `${defaultMessage}#${description}` | ||
: defaultMessage, | ||
} | ||
), | ||
}) | ||
expect(messages).toMatchSnapshot() | ||
test('gts_extractor', async function () { | ||
let messages: MessageDescriptor[] = [] | ||
const fixturePath = join(__dirname, './fixtures/comp.gts') | ||
parseFile(await readFile(fixturePath, 'utf8'), fixturePath, { | ||
onMsgExtracted(_: any, msgs: any) { | ||
messages = messages.concat(msgs) | ||
}, | ||
overrideIdFn: ( | ||
id: any, | ||
defaultMessage: any, | ||
description: any, | ||
fileName: any | ||
) => | ||
id || | ||
interpolateName( | ||
{ | ||
resourcePath: fileName, | ||
} as any, | ||
'[sha512:contenthash:base64:6]', | ||
{ | ||
content: description | ||
? `${defaultMessage}#${description}` | ||
: defaultMessage, | ||
} | ||
), | ||
}) | ||
|
||
test('gjs files', async function() { | ||
const { parseFile } = await import('../../src/gts_extractor.mjs'); | ||
|
||
let messages: MessageDescriptor[] = [] | ||
const fixturePath = join(__dirname, './fixtures/comp.gjs') | ||
parseFile(await readFile(fixturePath, 'utf8'), fixturePath, { | ||
onMsgExtracted(_: any, msgs: any) { | ||
messages = messages.concat(msgs) | ||
}, | ||
overrideIdFn: ( | ||
id: any, | ||
defaultMessage: any, | ||
description: any, | ||
fileName: any | ||
) => | ||
id || | ||
interpolateName( | ||
{ | ||
resourcePath: fileName, | ||
} as any, | ||
'[sha512:contenthash:base64:6]', | ||
{ | ||
content: description | ||
? `${defaultMessage}#${description}` | ||
: defaultMessage, | ||
} | ||
), | ||
}) | ||
expect(messages).toMatchSnapshot() | ||
}) | ||
|
||
expect(messages).toMatchSnapshot() | ||
}) |
Oops, something went wrong.