Skip to content

Commit

Permalink
fix(@formatjs/intl-getcanonicallocales): rm json import to be more ES…
Browse files Browse the repository at this point in the history
…M-friendly, fix #2961
  • Loading branch information
longlho committed Jun 26, 2021
1 parent 2bfedbb commit 9d491e2
Show file tree
Hide file tree
Showing 7 changed files with 1,896 additions and 6 deletions.
13 changes: 11 additions & 2 deletions packages/intl-getcanonicallocales/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ jest_test(
# aliases
generate_src_file(
name = "aliases",
src = "src/data/aliases.ts",
src = "src/aliases.generated.ts",
data = [
"@npm//cldr-core",
],
entry_point = "scripts/aliases.ts",
visibility = ["//:__pkg__"],
)
generate_src_file(
name = "likelySubtags",
src = "src/likelySubtags.generated.ts",
data = [
"@npm//cldr-core",
],
entry_point = "scripts/likely-subtags.ts",
visibility = ["//:__pkg__"],
)

# karma tests
bundle_karma_tests(
Expand Down Expand Up @@ -101,7 +110,7 @@ check_format(
],
exclude = [
"CHANGELOG.md",
"src/data/aliases.ts",
"**/*.generated.*",
],
),
)
2 changes: 2 additions & 0 deletions packages/intl-getcanonicallocales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export {
} from './src/parser'
export * from './src/types'
export * from './src/emitter'

export * from './src/likelySubtags.generated'
1 change: 0 additions & 1 deletion packages/intl-getcanonicallocales/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"url": "https://github.com/formatjs/formatjs/issues"
},
"dependencies": {
"cldr-core": "38",
"tslib": "^2.1.0"
}
}
20 changes: 20 additions & 0 deletions packages/intl-getcanonicallocales/scripts/likely-subtags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {outputFileSync} from 'fs-extra'
import minimist from 'minimist'
import * as likelySubtags from 'cldr-core/supplemental/likelySubtags.json'
function main({out}: minimist.ParsedArgs) {
outputFileSync(
out,
`/* @generated */
// prettier-ignore
export const likelySubtags: Record<string, string> = ${JSON.stringify(
likelySubtags.supplemental.likelySubtags,
undefined,
2
)};
`
)
}

if (require.main === module) {
main(minimist(process.argv))
}
6 changes: 3 additions & 3 deletions packages/intl-getcanonicallocales/src/canonicalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
variantAlias,
scriptAlias,
territoryAlias,
} from './data/aliases'
} from './aliases.generated'
import {
parseUnicodeLanguageId,
isUnicodeVariantSubtag,
isUnicodeLanguageSubtag,
SEPARATOR,
} from './parser'
import * as likelySubtags from 'cldr-core/supplemental/likelySubtags.json'
import {likelySubtags} from './likelySubtags.generated'
import {emitUnicodeLanguageId} from './emitter'

function canonicalizeAttrs(strs: string[]): string[] {
Expand Down Expand Up @@ -186,7 +186,7 @@ export function canonicalizeUnicodeLanguageId(
const regions = regionAlias.split(' ')
replacedRegion = regions[0]
const likelySubtag =
likelySubtags.supplemental.likelySubtags[
likelySubtags[
emitUnicodeLanguageId({
lang: finalLangAst.lang,
script: finalLangAst.script,
Expand Down

0 comments on commit 9d491e2

Please sign in to comment.