Closed sastan closed 2 years ago
It's amazing how many little details you've pulled in one go!
This this package gaining so many features (it used to be a very simple reexport of precompile-intl-runtime
) it's time to create a test suite, but that's beyond the scope of this PR. I'll merge it now!
Thank you for the fast merge. About testing I'm eager to try vitest. I think this could be a good fit as this is basically a vite plugin. If you want I could give it a try.
I’ve been meaning to try it too so go ahead 👍
Hello @cibernox,
sorry for such a big PR. I've added a lot of things. If you like I can create separate PRs for some of the features or remove them completely if you don't see them as part of this library.
Here is a list of things I've added or changed with links to the lines in the source.
Support all i18n-ally file formats
.json5
and.json
) and yaml (.yaml
and.yml
) — https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L26:L39 and https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L126-L139.js
,.ts
, and.mjs
files — https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L29-L31$locales/en
instead of$locales/en.js
) — https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L183-L195 and https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L205-L217Loading of sveltekit-plugin
These changes allow to use
import precompileIntl from "svelte-intl-precompile/sveltekit-plugin"
andconst precompileIntl = require("svelte-intl-precompile/sveltekit-plugin")
without an extension.
The legacy
svelte-intl-precompile/sveltekit-plugin.js
andsvelte-intl-precompile/sveltekit-plugin.cjs
do still work. In the future, I would suggest deprecating these becausesvelte-intl-precompile/sveltekit-plugin
works forimport
andrequire
since Node.js v12.7.0This structure and content of
package.json
fieldsexports
,main
, andtype
are based on the recommendations given in https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#conditional-exports.exports
field topackage.json
with legacy./sveltekit-plugin.js
and./sveltekit-plugin.cjs
exports — https://github.com/sastan/svelte-intl-precompile/blob/main/package.json#L5-L26svelte-intl-precompile/sveltekit-plugin
— https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.d.ts./sveltekit-plugin.cjs
from./sveltekit-plugin.js
during publishing — https://github.com/sastan/svelte-intl-precompile/blob/main/package.json#L26-L27 and https://github.com/sastan/svelte-intl-precompile/blob/main/.gitignore#L2Windows file path handling
This is done by using path-starts-with to check it a file is within the locales directory.
Misc
availableLocales
export of$locales
module that more specific locales come firsten-US
comes beforeen
— https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L86-L94filename
to babel transform for better debugging — https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L115 and https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L10-L12$locales
module in HMR mode if a file within the locales directory has changed — https://github.com/sastan/svelte-intl-precompile/blob/main/sveltekit-plugin.js#L168-L172index.cjs
to re-exportprecompile-intl-runtime
for cjs compat loading — https://github.com/sastan/svelte-intl-precompile/blob/main/package.json#L10 and https://github.com/sastan/svelte-intl-precompile/blob/main/index.cjs