Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): create a commonJs bundle #427

Merged
merged 8 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ public
coverage
src/serviceWorker.js
cypress/integration/examples
dist
cjs
esm
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ node_modules
# production
/build
/dist
/cjs
/esm

# misc
.DS_Store
Expand Down
32 changes: 26 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
"engines": {
"node": ">=20.0.0"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
"exports": {
".": {
"require": {
"types": "./cjs/index.d.cts",
"default": "./cjs/index.cjs"
},
"import": {
"types": "./esm/index.d.ts",
"default": "./esm/index.js"
}
}
},
"description": "Graasp Translations",
"repository": {
"type": "git",
Expand All @@ -27,6 +37,9 @@
"scripts": {
"prepack": "yarn build",
"prepare": "yarn build && yarn hooks:install",
"build": "yarn build:esm && yarn build:cjs",
"build:cjs": "unbuild && echo '{\"type\": \"commonjs\"}' > cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > esm/package.json",
"prettier:check": "prettier --check {src,test}/**/*.{js,ts,tsx,json}",
"prettier:write": "prettier --write {src,test}/**/*.{js,ts,tsx,json}",
"hooks:uninstall": "husky uninstall",
Expand All @@ -37,8 +50,7 @@
"type-check": "yarn tsc --noEmit",
"check": "yarn prettier:check && yarn lint && yarn type-check",
"pre-commit": "yarn check",
"post-commit": "git status",
"build": "tsc"
"post-commit": "git status"
},
"peerDependencies": {
"i18next": "^23.8.1"
Expand All @@ -53,13 +65,21 @@
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"fs": "0.0.1-security",
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"glob": "10.4.2",
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"husky": "9.0.11",
"i18next": "23.11.5",
"jest": "29.7.0",
"prettier": "3.3.2",
"ts-jest": "29.1.4",
"ts-node": "10.9.2",
"typescript": "5.4.5"
"tsc-alias": "1.8.10",
"typescript": "5.4.5",
"unbuild": "2.0.0"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"unbuild": {
"outDir": "cjs",
"failOnWarn": false
}
}
11 changes: 5 additions & 6 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { ar, de, en, fr, it, namespaces } from './langs/index.js';

export const DEFAULT_LANG = 'en';

const buildI18n = (defaultNamespace = namespaces.messages, debug?: boolean) => {
export const buildI18n = (
defaultNamespace = namespaces.messages,
debug?: boolean,
) => {
i18n.init({
resources: {
en,
Expand All @@ -31,7 +34,7 @@ const buildI18n = (defaultNamespace = namespaces.messages, debug?: boolean) => {
return i18n;
};

const langs = {
export const langs = {
// bg: "български",
// ca: "Català",
// cs: "čeština",
Expand Down Expand Up @@ -63,7 +66,3 @@ const langs = {
// zh_tw: "繁體中文",
ar: 'العربية',
};

export { langs };

export default buildI18n;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { namespaces } from './langs/index.js';
export { default, langs, DEFAULT_LANG } from './i18n.js';
export { buildI18n, langs, DEFAULT_LANG } from './i18n.js';

export * from './constants/association.js';
export * from './constants/categories.js';
Expand Down
13 changes: 13 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./cjs",
"noEmit": false,
// declarations are emitted separately
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"declaration": true,
"target": "ES2015",
"module": "CommonJS",
"moduleResolution": "Node"
},
"exclude": ["src/**/*.test.ts"]
}
13 changes: 13 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./esm",
"noEmit": false,
// declarations are emitted separately
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"declaration": true,
"target": "ES2015",
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"exclude": ["src/**/*.test.ts"]
}
33 changes: 26 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
{
"compilerOptions": {
"target": "es2015",
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["ES2020", "ES2021.String", "ESNext", "DOM", "DOM.Iterable"],
"allowJs": false,
"module": "NodeNext",
"strict": true,
"outDir": "dist",
"skipLibCheck": true,
"declaration": true,

/* Bundler mode */
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"moduleResolution": "NodeNext",
"resolveJsonModule": true
"resolveJsonModule": true,
"esModuleInterop": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,

"paths": {
"@/*": ["./src/*"]
},

"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true
},
"include": ["src/**/*"],
"exclude": ["test", "src/**/*.test.ts"]
"include": ["src"]
}
Loading