Skip to content

Commit

Permalink
fix(build): create a commonJs bundle (#427)
Browse files Browse the repository at this point in the history
* fix: remove json assertions

* Revert "fix: remove json assertions"

This reverts commit 4b68cae.

* fix: build both packages

* fix: use unbuild with tsc

* fix: use unbuild with tsc

* fix: cleanup

* fix: add unbunild to package

* fix: remove unused dependencies
  • Loading branch information
spaenleh authored Jun 21, 2024
1 parent 7b87481 commit 4056d62
Show file tree
Hide file tree
Showing 9 changed files with 2,274 additions and 87 deletions.
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
30 changes: 24 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 @@ -59,7 +71,13 @@
"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": "yarn@4.3.0"
"packageManager": "yarn@4.3.0",
"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
"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
"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 */
"moduleResolution": "NodeNext",
"resolveJsonModule": true
"resolveJsonModule": true,
"esModuleInterop": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"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

0 comments on commit 4056d62

Please sign in to comment.