Skip to content

Commit

Permalink
Merge pull request #10 - Update dependencies, remove non-working CJS …
Browse files Browse the repository at this point in the history
…artifact
  • Loading branch information
rosskevin committed Apr 29, 2023
2 parents 7f8ea13 + 59a9ede commit a533e0e
Show file tree
Hide file tree
Showing 9 changed files with 2,718 additions and 1,720 deletions.
801 changes: 0 additions & 801 deletions .yarn/releases/yarn-3.2.4.cjs

This file was deleted.

873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
nodeLinker: node-modules

npmRegistries:
'https://npm.pkg.github.com':
npmAuthToken: '${GITHUB_TOKEN}'
"https://npm.pkg.github.com":
npmAuthToken: "${GITHUB_TOKEN}"

npmScopes:
alienfast:
npmAlwaysAuth: true
npmRegistryServer: 'https://npm.pkg.github.com'
npmRegistryServer: "https://npm.pkg.github.com"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: '@yarnpkg/plugin-typescript'
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.2.4.cjs
yarnPath: .yarn/releases/yarn-3.5.0.cjs
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,34 @@ const resources = {
export default resources
```

## Vite typescript definitions

In order for the vite [virtual module](https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention) to be typechecked, you will need to a declaration. Below is an example of a common type file included in a project for vite:

```ts
// https://vitejs.dev/guide/api-hmr.html
interface ViteHotContext {
readonly data: any

// accept(): void
accept(cb?: (mod: ModuleNamespace | undefined) => void): void
accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
accept(deps: readonly string[], cb: (mods: Array<ModuleNamespace | undefined>) => void): void

dispose(cb: (data: any) => void): void
decline(): void
invalidate(): void

// `InferCustomEventPayload` provides types for built-in Vite events
on<T extends string>(event: T, cb: (payload: InferCustomEventPayload<T>) => void): void
send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
}

// Allow for virtual module imports
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
declare module 'virtual:*'
```
## Credit
This was forked from [@alienfast/i18next-loader](https://github.com/alienfast/i18next-loader/), converted to be a vite plugin and improved. Thanks to the original authors and contributors.
61 changes: 37 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
"import": "./dist/index.js"
}
},
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"main": "./dist/index.cjs",
"main-module-types-note": "vscode was not recognizing types without the top level module and types entries, storybook/vite wouldn't load without the cjs exports entry",
"sideEffects": false,
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -54,35 +49,53 @@
"vite": ">=3.1.6"
},
"dependencies": {
"glob-all": "^3.3.0",
"dot-prop": "^8.0.0",
"glob-all": "^3.3.1",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"marked": "^4.1.1",
"marked-terminal": "^5.1.1"
"marked": "^4.3.0",
"marked-terminal": "^5.1.1",
"ts-deepmerge": "^6.0.3"
},
"devDependencies": {
"@alienfast/eslint-config": "^4.0.5",
"@alienfast/eslint-config": "^4.0.6",
"@alienfast/tsconfig": "^1.0.1",
"@auto-it/all-contributors": "^10.46.0",
"@auto-it/first-time-contributor": "^10.46.0",
"@auto-it/released": "^10.46.0",
"@types/js-yaml": "^4.0.5",
"@types/lodash-es": "^4.17.6",
"@types/marked": "^4",
"@types/node": "^18.11.7",
"@types/node": "^18.16.1",
"@types/rimraf": "^3",
"auto": "^10.37.6",
"eslint": "^8.26.0",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"auto": "^10.46.0",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-storybook": "^0.6.11",
"eslint-plugin-unicorn": "^46.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"rollup": "^3.2.3",
"tsup": "^6.3.0",
"typescript": "^4.8.4",
"vite": "^3.2.1",
"vitest": "^0.24.3"
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"rollup": "^3.21.0",
"tsup": "^6.7.0",
"typescript": "^5.0.4",
"vite": "^4.3.3",
"vitest": "^0.30.1"
},
"author": "Kevin Ross <kevin.ross@alienfast.com>",
"auto": {
"plugins": [
"npm"
"npm",
"all-contributors",
"first-time-contributor",
"released"
]
},
"packageManager": "yarn@3.2.4"
"packageManager": "yarn@3.5.0"
}
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from 'node:path'

import { merge, set } from 'lodash-es'
import { setProperty } from 'dot-prop'
import { marked } from 'marked'
import TerminalRenderer from 'marked-terminal'
import merge from 'ts-deepmerge'
import { createLogger, LogLevel, Plugin } from 'vite'

import {
Expand Down Expand Up @@ -58,6 +59,10 @@ export interface Options {
namespaceResolution?: 'basename' | 'relativePath'
}

export interface ResBundle {
[key: string]: string | object
}

// for fast match on hot reloading check?
let loadedFiles: string[] = []
let allLangs: Set<string> = new Set()
Expand All @@ -70,7 +75,7 @@ const factory = (options: Options) => {
assertExistence(localeDirs)

//
let appResBundle = {}
let appResBundle: ResBundle = {}
loadedFiles = [] // reset
log.info('Bundling locales (ordered least specific to most):', {
timestamp: true,
Expand All @@ -80,7 +85,7 @@ const factory = (options: Options) => {
const langs = enumerateLangs(nextLocaleDir)
allLangs = new Set([...allLangs, ...langs])
for (const lang of langs) {
const resBundle = {}
const resBundle: ResBundle = {}
resBundle[lang] = {}

const langDir = path.join(nextLocaleDir, lang) // top level lang dir
Expand All @@ -107,7 +112,7 @@ const factory = (options: Options) => {
const extname = path.extname(langFile)
const namespaceParts = namespaceFilepath.replace(extname, '').split(path.sep)
const namespace = [lang].concat(namespaceParts).join('.')
set(resBundle, namespace, content)
setProperty(resBundle, namespace, content)
} else {
resBundle[lang] = content
}
Expand Down
46 changes: 2 additions & 44 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,11 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@alienfast/tsconfig/node.json",

"include": ["src", "./typings/**/*"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",

// af shared node base
"moduleResolution": "node",

// "module": "NodeNext",
"module": "esnext", // pulumi complains of es2022
"target": "esnext", // pulumi complains of es2022

// ----
// https://github.com/sindresorhus/tsconfig/blob/main/tsconfig.json
"lib": ["dom", "dom.iterable", "es2020"],

"allowSyntheticDefaultImports": true, // To provide backwards compatibility, Node.js allows you to import most CommonJS packages with a default import. This flag tells TypeScript that it's okay to use import on CommonJS modules.
"resolveJsonModule": true,

// ----
// from node18 base, but changed lib/module/target
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// ----
// Our alterations to the base
// "allowSyntheticDefaultImports": true,

// Ensure that .d.ts files are created by tsc
"declaration": true,
// Do not allow js
"allowJs": false,
// No js, ts, maps when errors are reported
"noEmitOnError": true,
// Do not allow inference to fall back to any type
"noImplicitAny": true,
// Ensure a return path
"noImplicitReturns": true,
// Report errors on unused local variables.
"noUnusedLocals": false,
// obj[foo] suppression
"suppressImplicitAnyIndexErrors": true,

// vite suggestions
"useDefineForClassFields": true
"rootDir": "src"
}
}
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default defineConfig({
sourcemap: true,
clean: true,
dts: true,
format: ['esm', 'cjs'],
format: ['esm'],
minify: true,
})

0 comments on commit a533e0e

Please sign in to comment.